OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVideoImageSource.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 // OSSIM -- Open Source Software Image Map
3 //
4 // LICENSE: See top level LICENSE.txt file.
5 //
6 // AUTHOR: Oscar Kramer, SPADAC Inc.
7 //
8 // DESCRIPTION: Defines pure virtual base class for individual video frame image handler
9 //
10 //**************************************************************************************************
11 // $Id: ossimVideoImageSource.cpp 2695 2011-06-08 21:12:15Z oscar.kramer $
12 
18 
19 RTTI_DEF1(ossimVideoImageSource, "ossimVideoImageSource", ossimImageSource)
20 
21  //*************************************************************************************************
23 //*************************************************************************************************
25 : m_frameTime (-1.0)
26 {
27 }
28 
29 //*************************************************************************************************
32 //*************************************************************************************************
34  const double& frame_time_seconds)
35 : m_frameTime (-1.0)
36 {
37  initialize();
38  setFrameTime(frame_time_seconds);
39 }
40 
41 //*************************************************************************************************
43 //*************************************************************************************************
45 {
46  ossimVideoSource* video = dynamic_cast<ossimVideoSource*>(getInput());
47  if (!video)
48  return;
49 
50  // Establish the frame rect:
51  ossimIpt frame_size (video->frameSize());
52  m_frameRect = ossimIrect(0, 0, frame_size.x-1, frame_size.y-1);
53 
54  // Initialize the tile data buffer:
56  m_tile->setWidth(frame_size.x);
57 
58  m_tile->setHeight(frame_size.y);
59  m_tile->initialize();
60 }
61 
62 #if 0
63 /*
64 GARRETT: this is from when I derived this class from ossimImageHandler instead of ossimImageSource.
65 I'm leaving these out but it may be convenient to allow OSSIM to consider a video as a multi-entry
66 file. Give some thought to the merits of deriving from ossimImageHandler. What about reader factory
67 and registry? If a user specifies a video file, should the image handler registry pick it up?
68 */
69 //*************************************************************************************************
70 // Indirectly sets the frame time given a frame index from the start frame.
72 //*************************************************************************************************
73 bool ossimVideoImageSource::setCurrentEntry(ossim_uint32 frame_number)
74 {
75  if (!m_video)
76  return false;
77 
78  ossim_float64 frame_rate = m_video->videoFrameRate();
79  ossim_float64 frameTime = frame_number / frame_rate;
80  return setFrameTime(frameTime);
81 }
82 
83 //*************************************************************************************************
84 // Converts frame time to frame index using frame rate:
85 //*************************************************************************************************
86 ossim_uint32 ossimVideoImageSource::getCurrentEntry() const
87 {
88  if (!m_video)
89  return 0;
90 
91  ossim_float64 frame_rate = m_video->videoFrameRate();
92  if (frame_rate == 0.0)
93  return 0;
94 
95  ossim_uint32 current_frame = m_frameTime/frame_rate;
96  return current_frame;
97 }
98 
99 //*************************************************************************************************
100 // Determines total number of frames using frame rate and video duration:
101 //*************************************************************************************************
102 ossim_uint32 ossimVideoImageSource::getNumberOfEntries() const
103 {
104  if (!m_video)
105  return 0;
106 
107  ossim_float64 frames_per_sec = m_video->videoFrameRate();
108  if (frames_per_sec == 0.0)
109  return 0;
110 
111  ossim_float64 duration = m_video->duration();
112 
113  ossim_uint32 num_frames = (ossim_uint32) (duration * frames_per_sec);
114  return num_frames;
115 }
116 #endif
117 
118 //*************************************************************************************************
119 // Sets the time stamp (in seconds from start of video) for the frame of interest.
121 //*************************************************************************************************
122 bool ossimVideoImageSource::setFrameTime(const double& frameTime)
123 {
124  ossimVideoSource* video = dynamic_cast<ossimVideoSource*>(getInput());
125  if (!video)
126  return false;
127 
128  // If the requested frame number corresponds with the current active frame, we're done:
129  if (frameTime == m_frameTime)
130  return true;
131 
132  // Check that it is not past the last frame. Use video geometry's duration as it is more accurate
133  m_frameTime = frameTime;
134  if (m_frameTime > video->duration())
135  {
136  m_frameTime = 0;
137  return false;
138  }
139 
140  // Seek to that frame:
142 
143  return true;
144 }
145 
146 //*************************************************************************************************
147 // Returns number of lines per video frame.
148 //*************************************************************************************************
150 {
151  // Only full-image res level = 0 presently supported:
152  if (resLevel != 0)
153  return 0;
154 
155  return m_frameRect.height();
156 }
157 
158 //*************************************************************************************************
159 // Returns number of lines per video frame.
160 //*************************************************************************************************
162 {
163  // Only full-image res level = 0 presently supported:
164  if (resLevel != 0)
165  return 0;
166 
167  return m_frameRect.width();
168 }
169 
170 //*************************************************************************************************
171 // Returns the populated geometry for this frame
172 //*************************************************************************************************
174 {
175  ossimVideoSource* video = dynamic_cast<ossimVideoSource*>(getInput());
176  if (!video)
177  return NULL;
178 
179  ossimRefPtr<ossimVideoGeometry> video_geometry = video->getVideoGeometry();
180  if (!video_geometry.valid())
181  return NULL;
182 
183  return video_geometry->getImageGeometry(m_frameTime);
184 }
185 
186 //*************************************************************************************************
187 // From ossimConnectableObject base class. Returns true if object is an ossimVideoSource.
188 //*************************************************************************************************
190  const ossimConnectableObject* object) const
191 {
192  return ( (!object || PTR_CAST(ossimVideoSource, object)) && (inputIndex == 0) );
193 }
194 
195 //*************************************************************************************************
197 //*************************************************************************************************
199 {
200  result = ossimDpt(0.0, 0.0);
201  if (resLevel == 0)
202  result = ossimDpt(1.0, 1.0);
203 }
204 
205 //*************************************************************************************************
207 //*************************************************************************************************
208 void ossimVideoImageSource::getDecimationFactors(std::vector<ossimDpt>& decimations) const
209 {
210  decimations.clear();
211  decimations.push_back(ossimDpt(1.0, 1.0));
212 }
Contains class declaration for ossimVideoImageSource.
Pure virtual base class for all video sources – analogous to ossimImageSource.
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const
Changes the frame to the new index (frame count from start of video).
bool valid() const
Definition: ossimRefPtr.h:75
ossim_uint32 height() const
Definition: ossimIrect.h:487
const ossimIpt & frameSize() const
Nominal size of a frame in pixels.
virtual ossim_float64 duration() const
Total length of video in seconds.
virtual bool seek(ossim_float64 reference_time_sec, SeekType seekType)
Seeks to the frame at time specified, according to the seekType (relative to active frame or absolute...
virtual bool canConnectMyInputTo(ossim_int32 index, const ossimConnectableObject *object) const
From ossimConnectableObject base class. Returns true if object is an ossimVideoSource.
virtual void initialize()
Initialize the data buffer.
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
double ossim_float64
virtual void setHeight(ossim_uint32 height)
static ossimImageDataFactory * instance()
ossimRefPtr< ossimImageData > m_tile
ossimIrect m_frameRect
Always (0,0) based.
unsigned int ossim_uint32
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
ossimVideoImageSource()
Default Constructor.
virtual void setWidth(ossim_uint32 width)
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry(const double &t)=0
Provides an image geometry object for frame at specified time in seconds since start of sequence...
virtual const ossimRefPtr< ossimVideoGeometry > getVideoGeometry() const
Access to video geometry object.
double m_frameTime
seconds from start of video
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
virtual void initialize()
Common initialization code for all construction methods.
virtual void getDecimationFactor(ossim_uint32 resLevel, ossimDpt &result) const
Video frames have no overviews, only full-res.
virtual bool setFrameTime(const double &t)
Sets the time stamp (in seconds from start of video) for the frame of interest.
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual void getDecimationFactors(std::vector< ossimDpt > &decimations) const
Video frames have no overviews, only full-res.
int ossim_int32