core/vidl/vidl_dshow.h
Go to the documentation of this file.
00001 // This is core/vidl/vidl_dshow.h
00002 #ifndef vidl_dshow_h_
00003 #define vidl_dshow_h_
00004 //=========================================================================
00005 //:
00006 // \file
00007 // \brief  DirectShow helper functions used in vidl.
00008 // \author Miguel A. Figueroa-Villanueva (miguelf at ieee dot org)
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   02/03/2006 - File created. (miguelfv)
00013 //   03/07/2006 - File imported to vxl repository. (miguelfv)
00014 // \endverbatim
00015 //
00016 //=========================================================================
00017 
00018 #include <vidl/vidl_exception.h>
00019 #include <vidl/vidl_pixel_format.h>
00020 
00021 #include <vcl_string.h>
00022 #include <vcl_vector.h>
00023 #include <vcl_iostream.h>
00024 
00025 #include <atlbase.h>
00026 #include <dshow.h>
00027 #include <qedit.h>
00028 
00029 struct vidl_dshow
00030 {
00031   //: Initialize COM (must be called before using any of these functions).
00032   static void initialize_com();
00033 
00034   //: Get an error description for the given HRESULT.
00035   static vcl_string get_error_text(const char* file, int line, HRESULT hr);
00036 
00037   //: Register object in Running Object Table (ROT)
00038   static void register_in_rot(IUnknown* unknown, DWORD& reg);
00039 
00040   //: Remove object from Running Object Table (ROT)
00041   static void remove_from_rot(DWORD reg);
00042 
00043   //: Save filter graph to a *.grf file.
00044   static void save_graph_to_file(const CComPtr<IFilterGraph2>& filter_graph,
00045                                  const vcl_string& filename);
00046 
00047   //: Load filter graph from a *.grf file.
00048   static void load_graph_from_file(const CComPtr<IFilterGraph2>& filter_graph,
00049                                    const vcl_wstring& filename);
00050 
00051   //: Get GUID name or FOURCC.
00052   static vcl_string get_guid_name(const GUID& guid);
00053 
00054   //: Get multimedia subtype GUID from FOURCC.
00055   static GUID get_guid_from_fourcc(const vcl_string& fourcc);
00056 
00057   //: Extract information from AM_MEDIA_TYPE object.
00058   static void get_media_info(const AM_MEDIA_TYPE& amt,
00059                              unsigned int& width,
00060                              unsigned int& height,
00061                              vidl_pixel_format& pixel_format);
00062 
00063   //: Delete AM_MEDIA_TYPE memory.
00064   static void delete_media_type(AM_MEDIA_TYPE& amt);
00065 
00066   //: Print a list of capture device names (i.e., FriendlyName).
00067   static void print_capture_device_names();
00068 
00069   //: Get a list of capture device names (i.e., FriendlyName).
00070   static vcl_vector<vcl_string> get_capture_device_names();
00071 
00072   //: Get IMoniker associated with name.
00073   static CComPtr<IMoniker> get_capture_device_moniker(const vcl_string& name);
00074 
00075 #if 0
00076   static void build_filter_graph(/*CComPtr<ICaptureGraphBuilder2>& graph_builder,*/
00077                                  CComPtr<IFilterGraph2>& filter_graph,
00078                                  CComPtr<IMoniker>& moniker,
00079                                  CComPtr<ISampleGrabber>& sample_grabber);
00080 #endif
00081 
00082   static void connect_filters(CComPtr<IFilterGraph2>& filter_graph,
00083                               CComPtr<IBaseFilter>& source,
00084                               CComPtr<IBaseFilter>& target);
00085 };
00086 
00087 // Some macros to help with error reporting.
00088 #define DSHOW_GET_ERROR_TEXT(hr) \
00089   vidl_dshow::get_error_text(__FILE__,__LINE__,(hr))
00090 
00091 #define DSHOW_WARN_IF_FAILED(stm) {                                       \
00092   HRESULT hr = (stm);                                                     \
00093   if FAILED(hr) {                                                         \
00094     vcl_cerr << vidl_dshow_exception(                                     \
00095                   vidl_dshow::get_error_text(__FILE__,__LINE__,hr)).what()\
00096              << '\n';                                                     \
00097   }}
00098 
00099 #define DSHOW_ERROR_IF_FAILED(stm) {                     \
00100   HRESULT hr = (stm);                                    \
00101   if FAILED(hr) {                                        \
00102     vidl_exception_error(vidl_dshow_exception(           \
00103       vidl_dshow::get_error_text(__FILE__,__LINE__,hr)));\
00104   }}
00105 
00106 #endif // vidl_dshow_h_