Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

MediaInfoDLL.h

Go to the documentation of this file.
00001 /* MediaInfoDLL - All info about media files, for DLL
00002 // Copyright (C) 2002-2006 Jerome Martinez, Zen@MediaArea.net
00003 //
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 //
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00019 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00020 //
00021 // Public DLL interface implementation
00022 // Wrapper for MediaInfo Library
00023 // See MediaInfo.h for help
00024 //
00025 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
00026 
00027 #ifndef MediaInfoDLLH
00028 #define MediaInfoDLLH
00029 
00030 /*-------------------------------------------------------------------------*/
00031 /*Char types                                                               */
00032 #undef  _T
00033 #define _T(__x)     __T(__x)
00034 #if defined(UNICODE) || defined (_UNICODE)
00035     typedef wchar_t MediaInfo_Char;
00036     #undef  __T
00037     #define __T(__x) L ## __x
00038     #define MEDIAINFO_Ansi ""
00039 #else
00040     typedef char MediaInfo_Char;
00041     #undef  __T
00042     #define __T(__x) __x
00043     #define MEDIAINFO_Ansi "A"
00044 #endif
00045 //---------------------------------------------------------------------------
00046 
00047 /** @brief Kinds of Stream */
00048 typedef enum MediaInfo_stream_t
00049 {
00050     MediaInfo_Stream_General,
00051     MediaInfo_Stream_Video,
00052     MediaInfo_Stream_Audio,
00053     MediaInfo_Stream_Text,
00054     MediaInfo_Stream_Chapters,
00055     MediaInfo_Stream_Image,
00056     MediaInfo_Stream_Menu,
00057     MediaInfo_Stream_Max
00058 } MediaInfo_stream_C;
00059 
00060 /** @brief Kinds of Info */
00061 typedef enum MediaInfo_info_t
00062 {
00063     MediaInfo_Info_Name,
00064     MediaInfo_Info_Text,
00065     MediaInfo_Info_Measure,
00066     MediaInfo_Info_Options,
00067     MediaInfo_Info_Name_Text,
00068     MediaInfo_Info_Measure_Text,
00069     MediaInfo_Info_Info,
00070     MediaInfo_Info_HowTo,
00071     MediaInfo_Info_Max
00072 } MediaInfo_info_C;
00073 
00074 /** @brief Option if InfoKind = Info_Options */
00075 typedef enum MediaInfo_infooptions_t
00076 {
00077     MediaInfo_InfoOption_ShowInInform,
00078     MediaInfo_InfoOption_Reserved,
00079     MediaInfo_InfoOption_ShowInSupported,
00080     MediaInfo_InfoOption_TypeOfValue,
00081     MediaInfo_InfoOption_Max
00082 } MediaInfo_infooptions_C;
00083 
00084 /** @brief File opening options */
00085 typedef enum MediaInfo_fileoptions_t
00086 {
00087     MediaInfo_FileOption_Nothing        =0x00,
00088     MediaInfo_FileOption_Recursive      =0x01,
00089     MediaInfo_FileOption_CloseAll       =0x02,
00090     MediaInfo_FileOption_Max            =0x04
00091 } MediaInfo_fileoptions_C;
00092 
00093 
00094 #ifdef MEDIAINFO_GLIBC
00095     #include <gmodule.h>
00096     static GModule *Module=NULL;
00097 #else //MEDIAINFO_GLIBC
00098     #include <windows.h>
00099     static HMODULE Module=NULL;
00100 #endif //MEDIAINFO_GLIBC
00101 
00102 #ifdef MEDIAINFO_GLIBC
00103 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00104     if (!g_module_symbol (Module, "MediaInfo"MEDIAINFO_Ansi"_"_Name2, (gpointer*)&MediaInfo_##_Name)) \
00105         Errors++; \
00106     if (!g_module_symbol (Module, "MediaInfoList"MEDIAINFO_Ansi"_"_Name2, (gpointer*)&MediaInfoList_##_Name)) \
00107         Errors++;
00108 #else //MEDIAINFO_GLIBC
00109 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00110     MediaInfo_##_Name=(MEDIAINFO_##_Name)GetProcAddress(Module, "MediaInfo"MEDIAINFO_Ansi"_"_Name2); \
00111     if (MediaInfo_##_Name==NULL) Errors++; \
00112     MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)GetProcAddress(Module, "MediaInfoList"MEDIAINFO_Ansi"_"_Name2); \
00113     if (MediaInfoList_##_Name==NULL) Errors++;
00114 #endif //MEDIAINFO_GLIBC
00115 
00116 typedef void* (__stdcall *MEDIAINFO_New)(); static MEDIAINFO_New MediaInfo_New;
00117 typedef void* (__stdcall *MEDIAINFOLIST_New)(); static MEDIAINFOLIST_New MediaInfoList_New;
00118 typedef void (__stdcall *MEDIAINFO_Delete)(void*); static MEDIAINFO_Delete MediaInfo_Delete;
00119 typedef void (__stdcall *MEDIAINFOLIST_Delete)(void*); static MEDIAINFOLIST_Delete MediaInfoList_Delete;
00120 typedef int (__stdcall *MEDIAINFO_Open)(void*, const MediaInfo_Char*); static MEDIAINFO_Open MediaInfo_Open;
00121 typedef int (__stdcall *MEDIAINFOLIST_Open)(void*, const MediaInfo_Char*, const MediaInfo_fileoptions_C); static MEDIAINFOLIST_Open MediaInfoList_Open;
00122 typedef void (__stdcall *MEDIAINFO_Close)(void*); static MEDIAINFO_Close MediaInfo_Close;
00123 typedef void (__stdcall *MEDIAINFOLIST_Close)(void*, unsigned int); static MEDIAINFOLIST_Close MediaInfoList_Close;
00124 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Inform)(void*, int Reserved); static MEDIAINFO_Inform MediaInfo_Inform;
00125 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Inform)(void*, unsigned int, int Reserved); static MEDIAINFOLIST_Inform MediaInfoList_Inform;
00126 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_GetI)(void*, MediaInfo_stream_C StreamKind, int StreamNumber, int Parameter, MediaInfo_info_C KindOfInfo); static MEDIAINFO_GetI MediaInfo_GetI;
00127 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_GetI)(void*, unsigned int, MediaInfo_stream_C StreamKind, int StreamNumber, int Parameter, MediaInfo_info_C KindOfInfo); static MEDIAINFOLIST_GetI MediaInfoList_GetI;
00128 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Get)(void*, MediaInfo_stream_C StreamKind, int StreamNumber, const MediaInfo_Char* Parameter, MediaInfo_info_C KindOfInfo, MediaInfo_info_C KindOfSearch); static MEDIAINFO_Get MediaInfo_Get;
00129 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Get)(void*, unsigned int, MediaInfo_stream_C StreamKind, int StreamNumber, const MediaInfo_Char* Parameter, MediaInfo_info_C KindOfInfo, MediaInfo_info_C KindOfSearch); static MEDIAINFOLIST_Get MediaInfoList_Get;
00130 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value); static MEDIAINFO_Option MediaInfo_Option;
00131 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value); static MEDIAINFOLIST_Option MediaInfoList_Option;
00132 typedef int (__stdcall *MEDIAINFO_State_Get)(void*); static MEDIAINFO_State_Get MediaInfo_State_Get;
00133 typedef int (__stdcall *MEDIAINFOLIST_State_Get)(void*); static MEDIAINFOLIST_State_Get MediaInfoList_State_Get;
00134 typedef int (__stdcall *MEDIAINFO_Count_Get)(void*, MediaInfo_stream_C StreamKind, int StreamNumber); static MEDIAINFO_Count_Get MediaInfo_Count_Get;
00135 typedef int (__stdcall *MEDIAINFOLIST_Count_Get)(void*, unsigned int, MediaInfo_stream_C StreamKind, int StreamNumber); static MEDIAINFOLIST_Count_Get MediaInfoList_Count_Get;
00136 typedef int (__stdcall *MEDIAINFO_Count_Get_Files)(void*); static MEDIAINFO_Count_Get_Files MediaInfo_Count_Get_Files;
00137 typedef int (__stdcall *MEDIAINFOLIST_Count_Get_Files)(void*); static MEDIAINFOLIST_Count_Get_Files MediaInfoList_Count_Get_Files;
00138 
00139 static int MediaInfoDLL_Load()
00140 {
00141     /* Load library */
00142     #ifdef MEDIAINFO_GLIBC
00143         Module=g_module_open("MediaInfo.dll", G_MODULE_BIND_LAZY);
00144     #else //MEDIAINFO_GLIBC
00145         Module=LoadLibrary(_T("MediaInfo.dll"));
00146     #endif //MEDIAINFO_GLIBC
00147     if (!Module)
00148         return -1;
00149 
00150     /* Load methods */
00151     int Errors=0;
00152     MEDIAINFO_ASSIGN(New,"New")
00153     MEDIAINFO_ASSIGN(Delete,"Delete")
00154     MEDIAINFO_ASSIGN(Open,"Open")
00155     MEDIAINFO_ASSIGN(Close,"Close")
00156     MEDIAINFO_ASSIGN(Inform,"Inform")
00157     MEDIAINFO_ASSIGN(GetI,"GetI")
00158     MEDIAINFO_ASSIGN(Get,"Get")
00159     MEDIAINFO_ASSIGN(Option,"Option")
00160     MEDIAINFO_ASSIGN(State_Get,"State_Get")
00161     MEDIAINFO_ASSIGN(Count_Get,"Count_Get")
00162     MEDIAINFO_ASSIGN(Count_Get_Files,"Count_Get_Files")
00163     if (Errors>1)
00164        return -1;
00165 
00166     return 1;
00167 }
00168 
00169 static int MediaInfoDLL_IsLoaded()
00170 {
00171     if (Module)
00172         return 1;
00173     else
00174         return 0;
00175 }
00176 
00177 static void MediaInfoDLL_Free()
00178 {
00179     #ifdef MEDIAINFO_GLIBC
00180         g_module_close(Module);
00181     #else //MEDIAINFO_GLIBC
00182         FreeLibrary(Module);
00183     #endif //MEDIAINFO_GLIBC
00184     Module=NULL;
00185 }
00186 
00187 #ifdef __cplusplus
00188 //DLL C++ wrapper for C functions
00189 
00190 //---------------------------------------------------------------------------
00191 #include <string>
00192 //---------------------------------------------------------------------------
00193 
00194 namespace MediaInfoLib
00195 {
00196 
00197 //---------------------------------------------------------------------------
00198 //MediaInfo_Char types
00199 #undef  _T
00200 #define _T(__x)     __T(__x)
00201 #if defined(UNICODE) || defined (_UNICODE)
00202     typedef wchar_t MediaInfo_Char;
00203     #undef  __T
00204     #define __T(__x) L ## __x
00205 #else
00206     typedef char MediaInfo_Char;
00207     #undef  __T
00208     #define __T(__x) __x
00209 #endif
00210 typedef std::basic_string<MediaInfo_Char, std::char_traits<MediaInfo_Char>, std::allocator<MediaInfo_Char> > MediaInfo_String;
00211 //---------------------------------------------------------------------------
00212 
00213 //---------------------------------------------------------------------------
00214 /// @brief Kinds of Stream
00215 enum stream_t
00216 {
00217     Stream_General,                 ///< StreamKind = General
00218     Stream_Video,                   ///< StreamKind = Video
00219     Stream_Audio,                   ///< StreamKind = Audio
00220     Stream_Text,                    ///< StreamKind = Text
00221     Stream_Chapters,                ///< StreamKind = Chapters
00222     Stream_Image,                   ///< StreamKind = Image
00223     Stream_Menu,                    ///< StreamKind = Menu
00224     Stream_Max,
00225 };
00226 
00227 /// @brief Kind of information
00228 enum info_t
00229 {
00230     Info_Name,                      ///< InfoKind = Unique name of parameter
00231     Info_Text,                      ///< InfoKind = Value of parameter
00232     Info_Measure,                   ///< InfoKind = Unique name of measure unit of parameter
00233     Info_Options,                   ///< InfoKind = See infooptions_t
00234     Info_Name_Text,                 ///< InfoKind = Translated name of parameter
00235     Info_Measure_Text,              ///< InfoKind = Translated name of measure unit
00236     Info_Info,                      ///< InfoKind = More information about the parameter
00237     Info_HowTo,                     ///< InfoKind = Information : how data is found
00238     Info_Max
00239 };
00240 
00241 /// Get(...)[infooptions_t] return a string like "YNYN..." \n
00242 /// Use this enum to know at what correspond the Y (Yes) or N (No)
00243 /// If Get(...)[0]==Y, then :
00244 /// @brief Option if InfoKind = Info_Options
00245 enum infooptions_t
00246 {
00247     InfoOption_ShowInInform,        ///< Show this parameter in Inform()
00248     InfoOption_Reserved,            ///<
00249     InfoOption_ShowInSupported,        ///< Internal use only (info : Must be showed in Info_Capacities() )
00250     InfoOption_TypeOfValue,         ///< Value return by a standard Get() can be : T (Text), I (Integer, warning up to 64 bits), F (Float), D (Date), B (Binary datas coded Base64) (Numbers are in Base 10)
00251     InfoOption_Max
00252 };
00253 
00254 /// @brief File opening options
00255 enum fileoptions_t
00256 {
00257     FileOption_Nothing      =0x00,
00258     FileOption_Recursive    =0x01,  ///< Browse folders recursively
00259     FileOption_CloseAll     =0x02,  ///< Close all files before open
00260     FileOption_Max          =0x04
00261 };
00262 
00263 const MediaInfo_String Unable_Load_DLL=_T("Unable to load MediaInfo.dll");
00264 #define MEDIAINFO_TEST_VOID \
00265     if (!IsReady()) return
00266 #define MEDIAINFO_TEST_INT \
00267     if (!IsReady()) return 0
00268 #define MEDIAINFO_TEST_STRING \
00269     if (!IsReady()) return Unable_Load_DLL
00270 #define MEDIAINFO_TEST_STRING_STATIC \
00271     if (!Module) return Unable_Load_DLL
00272 
00273 //---------------------------------------------------------------------------
00274 class MediaInfo
00275 {
00276 public :
00277     MediaInfo ()                {if (!Module) MediaInfoDLL_Load(); if (!Module) {Handle=NULL; return;}; Handle=MediaInfo_New();};
00278     ~MediaInfo ()               {MEDIAINFO_TEST_VOID; MediaInfo_Delete(Handle);};
00279 
00280     //File
00281     int Open (const MediaInfo_String &File) {MEDIAINFO_TEST_INT; return MediaInfo_Open(Handle, File.c_str());};
00282     //int Open (const unsigned char* Begin, size_t Begin_Size, const unsigned char* End=NULL, size_t End_Size=NULL) {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer(Handle, Begin, Begin_Size, End, End_Size);};
00283     //int Save () {MEDIAINFO_TEST_INT; return MediaInfo_Save(Handle);};
00284     void Close () {MEDIAINFO_TEST_VOID; return MediaInfo_Close(Handle);};
00285 
00286     //General information
00287     MediaInfo_String Inform ()  {MEDIAINFO_TEST_STRING; return MediaInfo_Inform(Handle, 0);};
00288     MediaInfo_String Get (stream_t StreamKind, int StreamNumber, int Parameter, info_t InfoKind=Info_Text)  {MEDIAINFO_TEST_STRING; return MediaInfo_GetI (Handle, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, (MediaInfo_info_C)InfoKind);};
00289     MediaInfo_String Get (stream_t StreamKind, int StreamNumber, const MediaInfo_String &Parameter, info_t InfoKind=Info_Text, info_t SearchKind=Info_Name)  {MEDIAINFO_TEST_STRING; return MediaInfo_Get (Handle, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter.c_str(), (MediaInfo_info_C)InfoKind, (MediaInfo_info_C)SearchKind);};
00290     //int Set (const MediaInfo_String &ToSet, stream_t StreamKind, int StreamNumber, int Parameter, const MediaInfo_String &OldValue=_T(""))  {MEDIAINFO_TEST_INT; return MediaInfo_SetI (Handle, ToSet.c_str(), (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, OldValue.c_str());};
00291     //int Set (const MediaInfo_String &ToSet, stream_t StreamKind, int StreamNumber, const MediaInfo_String &Parameter, const MediaInfo_String &OldValue=_T(""))  {MEDIAINFO_TEST_INT; return MediaInfo_Set (Handle, ToSet.c_str(), (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter.c_str(), OldValue.c_str());};
00292     MediaInfo_String        Option (const MediaInfo_String &Option, const MediaInfo_String &Value=_T(""))  {MEDIAINFO_TEST_STRING; return MediaInfo_Option (Handle, Option.c_str(), Value.c_str());};
00293     static MediaInfo_String Option_Static (const MediaInfo_String &Option, const MediaInfo_String &Value=_T(""))  {MEDIAINFO_TEST_STRING_STATIC; return MediaInfo_Option (NULL, Option.c_str(), Value.c_str());};
00294     int                     State_Get ()  {MEDIAINFO_TEST_INT; return MediaInfo_State_Get(Handle);};
00295     int                     Count_Get (stream_t StreamKind, int StreamNumber=-1)  {MEDIAINFO_TEST_INT; return MediaInfo_Count_Get(Handle, (MediaInfo_stream_C)StreamKind, StreamNumber);};
00296 
00297     bool IsReady() {return (Handle && Module)?true:false;}
00298 
00299 private :
00300     void* Handle;
00301 };
00302 
00303 class MediaInfoList
00304 {
00305 public :
00306     MediaInfoList ()                {if (!MediaInfoDLL_IsLoaded()) MediaInfoDLL_Load(); if (!MediaInfoDLL_IsLoaded()) {Handle=NULL; return;}; Handle=MediaInfoList_New();};
00307     ~MediaInfoList ()               {MEDIAINFO_TEST_VOID; MediaInfoList_Delete(Handle);};
00308 
00309     //File
00310     int Open (const MediaInfo_String &File, const fileoptions_t Options=FileOption_Nothing) {MEDIAINFO_TEST_INT; return MediaInfoList_Open(Handle, File.c_str(), (MediaInfo_fileoptions_C)Options);};
00311     //int Open (const unsigned char* Begin, size_t Begin_Size, const unsigned char* End=NULL, size_t End_Size=NULL) {MEDIAINFO_TEST_INT; return MediaInfoList_Open_Buffer(Handle, Begin, Begin_Size, End, End_Size);};
00312     //int Save (unsigned int FilePos) {MEDIAINFO_TEST_INT; return MediaInfoList_Save(Handle, FilePos);};
00313     void Close (unsigned int FilePos) {MEDIAINFO_TEST_VOID; return MediaInfoList_Close(Handle, FilePos);};
00314 
00315     //General information
00316     MediaInfo_String Inform (unsigned int FilePos=(unsigned int)-1)  {MEDIAINFO_TEST_STRING; return MediaInfoList_Inform(Handle, FilePos, 0);};
00317     MediaInfo_String Get (unsigned int FilePos, stream_t StreamKind, int StreamNumber, int Parameter, info_t InfoKind=Info_Text)  {MEDIAINFO_TEST_STRING; return MediaInfoList_GetI (Handle, FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, (MediaInfo_info_C)InfoKind);};
00318     MediaInfo_String Get (unsigned int FilePos, stream_t StreamKind, int StreamNumber, const MediaInfo_String &Parameter, info_t InfoKind=Info_Text, info_t SearchKind=Info_Name)  {MEDIAINFO_TEST_STRING; return MediaInfoList_Get (Handle, FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter.c_str(), (MediaInfo_info_C)InfoKind, (MediaInfo_info_C)SearchKind);};
00319     //int Set (const MediaInfo_String &ToSet, unsigned int FilePos, stream_t StreamKind, int StreamNumber, int Parameter, const MediaInfo_String &OldValue=_T(""))  {MEDIAINFO_TEST_INT; return MediaInfoList_SetI (Handle, ToSet.c_str(), FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, OldValue.c_str());};
00320     //int Set (const MediaInfo_String &ToSet, unsigned int FilePos, stream_t StreamKind, int StreamNumber, const MediaInfo_String &Parameter, const MediaInfo_String &OldValue=_T(""))  {MEDIAINFO_TEST_INT; return MediaInfoList_Set (Handle, ToSet.c_str(), FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter.c_str(), OldValue.c_str());};
00321     MediaInfo_String        Option (const MediaInfo_String &Option, const MediaInfo_String &Value=_T(""))  {MEDIAINFO_TEST_STRING; return MediaInfoList_Option (Handle, Option.c_str(), Value.c_str());};
00322     static MediaInfo_String Option_Static (const MediaInfo_String &Option, const MediaInfo_String &Value=_T(""))  {MEDIAINFO_TEST_STRING_STATIC; return MediaInfoList_Option (NULL, Option.c_str(), Value.c_str());};
00323     int                     State_Get ()  {MEDIAINFO_TEST_INT; return MediaInfoList_State_Get(Handle);};
00324     int                     Count_Get (unsigned int FilePos, stream_t StreamKind, int StreamNumber=-1)  {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get(Handle, FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber);};
00325     int                     Count_Get ()  {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get_Files(Handle);};
00326 
00327     bool IsReady() {return (Handle && Module)?true:false;}
00328 
00329 private :
00330     void* Handle;
00331 };
00332 
00333 } //NameSpace
00334 #endif /*__cplusplus*/
00335 
00336 #endif

Generated on Mon Jul 31 00:08:10 2006 for MediaInfoLib by doxygen1.3-rc3