core/vidl/vidl_istream.h
Go to the documentation of this file.
00001 // This is core/vidl/vidl_istream.h
00002 #ifndef vidl_istream_h_
00003 #define vidl_istream_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief A base class for input video streams
00010 //
00011 // \author Matt Leotta
00012 // \date 19 Dec 2005
00013 
00014 #include "vidl_frame_sptr.h"
00015 #include "vidl_pixel_format.h"
00016 
00017 //: A base class for input video streams
00018 class vidl_istream
00019 {
00020  public:
00021   //: Constructor
00022   vidl_istream() : ref_count_(0) {}
00023   //: Destructor
00024   virtual ~vidl_istream() {}
00025 
00026   //: Return true if the stream is open for reading
00027   virtual bool is_open() const = 0;
00028 
00029   //: Return true if the stream is in a valid state
00030   // Streams open in an invalid state pointing to the frame
00031   // before the first valid frame.  The stream becomes valid when
00032   // it is first advanced.
00033   virtual bool is_valid() const = 0;
00034 
00035   //: Return true if the stream supports seeking
00036   virtual bool is_seekable() const = 0;
00037 
00038   //: Return the number of frames if known
00039   //  returns -1 for non-seekable streams
00040   virtual int num_frames() const = 0;
00041 
00042   //: Return the current frame number
00043   //  before the first call to advance() the frame number
00044   //  is static_cast<unsigned int>(-1)
00045   virtual unsigned int frame_number() const = 0;
00046 
00047   //: Return the width of each frame
00048   virtual unsigned int width() const = 0;
00049 
00050   //: Return the height of each frame
00051   virtual unsigned int height() const = 0;
00052 
00053   //: Return the pixel format
00054   virtual vidl_pixel_format format() const = 0;
00055 
00056   //: Return the frame rate (FPS, 0.0 if unspecified)
00057   virtual double frame_rate() const = 0;
00058   
00059   //: Return the duration in seconds (0.0 if unknown)
00060   virtual double duration() const = 0;
00061 
00062   //: Close the stream
00063   virtual void close() = 0;
00064 
00065   //: Advance to the next frame (but don't acquire an image)
00066   virtual bool advance() = 0 ;
00067 
00068   //: Read the next frame from the stream (advance and acquire)
00069   virtual vidl_frame_sptr read_frame() = 0;
00070 
00071   //: Return the current frame in the stream
00072   virtual vidl_frame_sptr current_frame() = 0;
00073 
00074   //: Seek to the given frame number
00075   // \returns true if successful
00076   virtual bool seek_frame(unsigned int frame_number) = 0;
00077 
00078  private:
00079   //: prevent deep copying a stream
00080   vidl_istream(const vidl_istream& /*other*/) : ref_count_(0) {}
00081 
00082  //-------------------------------------------------------
00083  // reference counting
00084  public:
00085 
00086   //: Increment reference count
00087   void ref() { ref_count_++; }
00088 
00089   //: Decrement reference count
00090   void unref() { if (--ref_count_ <= 0) delete this; }
00091 
00092   //: Number of objects referring to this data
00093   int ref_count() const { return ref_count_; }
00094 
00095  private:
00096   int ref_count_;
00097 };
00098 
00099 #endif // vidl_istream_h_