00001 // This is brl/bbas/vidl2/vidl2_dshow_file_istream.h 00002 #ifndef vidl2_dshow_file_istream_h_ 00003 #define vidl2_dshow_file_istream_h_ 00004 //========================================================================= 00005 //: 00006 // \file 00007 // \brief DirectShow file input stream support. 00008 // \author Paul Crane 00009 // \author Miguel A. Figueroa-Villanueva (miguelf at ieee dot org) 00010 // 00011 // This file includes experimental support for DirectShow file input in vidl2. 00012 // 00013 // \verbatim 00014 // TODO 00015 // - A few things... write them down! 00016 // \endverbatim 00017 // 00018 // \verbatim 00019 // Modifications 00020 // 01/19/2006 - DirectShow code contributed by Paul Crane. (miguelfv) 00021 // 03/07/2006 - File imported to vxl repository with some modifications 00022 // and extensions to Paul's code. (miguelfv) 00023 // \endverbatim 00024 // 00025 //========================================================================= 00026 00027 #include <vidl2/vidl2_istream.h> 00028 #include <vidl2/vidl2_frame_sptr.h> 00029 #include <vidl2/vidl2_pixel_format.h> 00030 00031 #include <vcl_string.h> 00032 #include <vcl_vector.h> 00033 00034 #include <atlbase.h> 00035 #include <dshow.h> 00036 #include <qedit.h> 00037 00038 //------------------------------------------------------------------------- 00039 //: DirectShow file input stream object. 00040 // 00041 // This is still in an experimental stage, but should be usable. It should 00042 // be able to open avi and wmv files as long as the system has the 00043 // available decoder, in the case of compressed video. 00044 // 00045 // DirectShow is very flexible and complex. Therefore we have taken the 00046 // approach to throw an exception or abort in the case where something 00047 // that is not supported fails, rather than try to parse through every 00048 // error and provide an alternative. However, we welcome any feedback on 00049 // desired features to make vidl2_dshow_file_istream more usable in the 00050 // VXL context. 00051 //------------------------------------------------------------------------- 00052 class vidl2_dshow_file_istream : public vidl2_istream 00053 { 00054 public: 00055 //: Constructor - from a string containing the file name. 00056 vidl2_dshow_file_istream(const vcl_string& name); 00057 00058 //: Destructor. 00059 virtual ~vidl2_dshow_file_istream(); 00060 00061 //: Return true if the stream is open for reading. 00062 // ***** if closed, should return false 00063 virtual bool is_open() const { return true; } 00064 00065 //: Return true if the stream is in a valid state. 00066 virtual bool is_valid() const { return is_valid_; } 00067 00068 //: Return true if the stream supports seeking. 00069 virtual bool is_seekable() const { return true; } 00070 00071 //: Return the current frame number. 00072 virtual unsigned int frame_number() const { return frame_index_; } 00073 00074 //: Close the stream. 00075 virtual void close(); 00076 00077 // ***** did we decide to keep the alias? 00078 00079 //: Advance to the next frame (but don't acquire an image). 00080 virtual bool advance() { return advance_wait(); } 00081 00082 //: Initiate advance and wait for completion; synchronous advance. 00083 virtual bool advance_wait(); 00084 00085 //: Initiate advance and return immediately; asynchronous advance. 00086 virtual bool advance_start(); 00087 00088 //: Returns true if the advance has finished and a frame is available. 00089 virtual bool is_frame_available() const; 00090 00091 //: Read the next frame from the stream (advance and acquire). 00092 virtual vidl2_frame_sptr read_frame(); 00093 00094 //: Return the current frame in the stream. 00095 virtual vidl2_frame_sptr current_frame(); 00096 00097 //: Seek to the given frame number 00098 // \returns true if successful 00099 virtual bool seek_frame(unsigned int frame_number); 00100 00101 private: 00102 // Disable assignment and copy-construction. 00103 vidl2_dshow_file_istream(const vidl2_dshow_file_istream&); 00104 vidl2_dshow_file_istream& operator=(const vidl2_dshow_file_istream&); 00105 00106 //: Open a video file. 00107 void open(const vcl_string& filename); 00108 00109 // Handles to the COM interfaces. 00110 CComPtr<IFilterGraph2> filter_graph_; 00111 CComPtr<IMediaControl> media_control_; 00112 CComPtr<IMediaSeeking> media_seeking_; 00113 CComPtr<IMediaEventEx> media_event_; 00114 CComPtr<ISampleGrabber> sample_grabber_; 00115 00116 // Internal frame buffer information. 00117 vcl_vector<unsigned char> buffer_[2]; 00118 double buffer_time_[2]; 00119 unsigned char buffer_index_; 00120 unsigned int buffer_width_; 00121 unsigned int buffer_height_; 00122 vidl2_pixel_format buffer_pixel_format_; 00123 00124 // Some status checking flags and counters. 00125 unsigned int frame_index_; 00126 REFERENCE_TIME end_position_; 00127 bool is_time_format_frame_; 00128 bool is_valid_; 00129 00130 //: ID in Running Object Table (ROT), for debugging with GraphEdit. 00131 DWORD register_; 00132 }; 00133 00134 #endif // vidl2_dshow_file_istream_h_
1.4.4