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 
00020 #include <vcl_string.h>
00021 #include <vcl_vector.h>
00022 #include <vcl_iostream.h>
00023 
00024 #include <atlbase.h>
00025 #include <dshow.h>
00026 #include <qedit.h>
00027 
00028 enum vidl_pixel_format;
00029 
00030 struct vidl_dshow
00031 {
00032   //: Initialize COM (must be called before using any of these functions).
00033   static void initialize_com();
00034 
00035   //: Get an error description for the given HRESULT.
00036   static vcl_string get_error_text(const char* file, int line, HRESULT hr);
00037 
00038   //: Register object in Running Object Table (ROT)
00039   static void register_in_rot(IUnknown* unknown, DWORD& reg);
00040 
00041   //: Remove object from Running Object Table (ROT)
00042   static void remove_from_rot(DWORD reg);
00043 
00044   //: Save filter graph to a *.grf file.
00045   static void save_graph_to_file(const CComPtr<IFilterGraph2>& filter_graph,
00046                                  const vcl_string& filename);
00047 
00048   //: Load filter graph from a *.grf file.
00049   static void load_graph_from_file(const CComPtr<IFilterGraph2>& filter_graph,
00050                                    const vcl_wstring& filename);
00051 
00052   //: Get GUID name or FOURCC.
00053   static vcl_string get_guid_name(const GUID& guid);
00054 
00055   //: Get multimedia subtype GUID from FOURCC.
00056   static GUID get_guid_from_fourcc(const vcl_string& fourcc);
00057 
00058   //: Extract information from AM_MEDIA_TYPE object.
00059   static void get_media_info(const AM_MEDIA_TYPE& amt,
00060                              unsigned int& width,
00061                              unsigned int& height,
00062                              vidl_pixel_format& pixel_format);
00063 
00064   //: Delete AM_MEDIA_TYPE memory.
00065   static void delete_media_type(AM_MEDIA_TYPE& amt);
00066 
00067   //: Print a list of capture device names (i.e., FriendlyName).
00068   static void print_capture_device_names();
00069 
00070   //: Get a list of capture device names (i.e., FriendlyName).
00071   static vcl_vector<vcl_string> get_capture_device_names();
00072 
00073   //: Get IMoniker associated with name.
00074   static CComPtr<IMoniker> get_capture_device_moniker(const vcl_string& name);
00075 
00076 #if 0
00077   static void build_filter_graph(/*CComPtr<ICaptureGraphBuilder2>& graph_builder,*/
00078                                  CComPtr<IFilterGraph2>& filter_graph,
00079                                  CComPtr<IMoniker>& moniker,
00080                                  CComPtr<ISampleGrabber>& sample_grabber);
00081 #endif
00082 
00083   static void connect_filters(CComPtr<IFilterGraph2>& filter_graph,
00084                               CComPtr<IBaseFilter>& source,
00085                               CComPtr<IBaseFilter>& target);
00086 };
00087 
00088 // Some macros to help with error reporting.
00089 #define DSHOW_GET_ERROR_TEXT(hr) \
00090   vidl_dshow::get_error_text(__FILE__,__LINE__,(hr))
00091 
00092 #define DSHOW_WARN_IF_FAILED(stm) {                                       \
00093   HRESULT hr = (stm);                                                     \
00094   if FAILED(hr) {                                                         \
00095     vcl_cerr << vidl_dshow_exception(                                    \
00096                 vidl_dshow::get_error_text(__FILE__,__LINE__,hr)).what() \
00097              << vcl_endl;                                                 \
00098   }}
00099 
00100 #define DSHOW_ERROR_IF_FAILED(stm) {                         \
00101   HRESULT hr = (stm);                                        \
00102   if FAILED(hr) {                                            \
00103     vidl_exception_error(vidl_dshow_exception(             \
00104       vidl_dshow::get_error_text(__FILE__,__LINE__,hr)));   \
00105   }}
00106 
00107 #endif // vidl_dshow_h_

Generated on Mon Mar 8 05:10:34 2010 for core/vidl by  doxygen 1.5.1