F:/Programmation/MediaInfoLib/Source/MediaInfoDLL/MediaInfoDLL.h

Go to the documentation of this file.
00001 /* MediaInfoDLL - All info about media files, for DLL
00002 // Copyright (C) 2002-2007 Jerome Martinez, Zen@MediaArea.net
00003 //
00004 // This library is free software: you can redistribute it and/or modify it
00005 // under the terms of the GNU Lesser General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // 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
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this library. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00018 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00019 //
00020 // Public DLL interface implementation
00021 // Wrapper for MediaInfo Library
00022 // See MediaInfo.h for help
00023 //
00024 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
00025 
00026 #ifndef MediaInfoDLLH
00027 #define MediaInfoDLLH
00028 
00029 /*-------------------------------------------------------------------------*/
00030 #if defined(_WIN32)
00031     #define MEDIAINFODLL_NAME  "MediaInfo.dll"
00032 #else
00033     #define MEDIAINFODLL_NAME  "libmediainfo.so.0"
00034     #define __stdcall
00035 #endif 
00036 #ifdef __cplusplus
00037         #include <new> //For size_t in MacOS
00038 #endif //__cplusplus
00039 
00040 /*-------------------------------------------------------------------------*/
00041 /*Char types                                                               */
00042 #undef  _T
00043 #define _T(__x)     __T(__x)
00044 #if defined(UNICODE) || defined (_UNICODE)
00045     typedef wchar_t MediaInfo_Char;
00046     #undef  __T
00047     #define __T(__x) L ## __x
00048     #define MEDIAINFO_Ansi ""
00049 #else
00050     typedef char MediaInfo_Char;
00051     #undef  __T
00052     #define __T(__x) __x
00053     #define MEDIAINFO_Ansi "A"
00054 #endif
00055 /*-------------------------------------------------------------------------*/
00056 
00057 /*-------------------------------------------------------------------------*/
00058 /*NULL                                                                      */
00059 #ifndef NULL
00060     #define NULL 0
00061 #endif
00062 /*-------------------------------------------------------------------------*/
00063 
00065 typedef enum MediaInfo_stream_t
00066 {
00067     MediaInfo_Stream_General,
00068     MediaInfo_Stream_Video,
00069     MediaInfo_Stream_Audio,
00070     MediaInfo_Stream_Text,
00071     MediaInfo_Stream_Chapters,
00072     MediaInfo_Stream_Image,
00073     MediaInfo_Stream_Menu,
00074     MediaInfo_Stream_Max
00075 } MediaInfo_stream_C;
00076 
00078 typedef enum MediaInfo_info_t
00079 {
00080     MediaInfo_Info_Name,
00081     MediaInfo_Info_Text,
00082     MediaInfo_Info_Measure,
00083     MediaInfo_Info_Options,
00084     MediaInfo_Info_Name_Text,
00085     MediaInfo_Info_Measure_Text,
00086     MediaInfo_Info_Info,
00087     MediaInfo_Info_HowTo,
00088     MediaInfo_Info_Max
00089 } MediaInfo_info_C;
00090 
00092 typedef enum MediaInfo_infooptions_t
00093 {
00094     MediaInfo_InfoOption_ShowInInform,
00095     MediaInfo_InfoOption_Reserved,
00096     MediaInfo_InfoOption_ShowInSupported,
00097     MediaInfo_InfoOption_TypeOfValue,
00098     MediaInfo_InfoOption_Max
00099 } MediaInfo_infooptions_C;
00100 
00102 typedef enum MediaInfo_fileoptions_t
00103 {
00104     MediaInfo_FileOption_Nothing        =0x00,
00105     MediaInfo_FileOption_Recursive      =0x01,
00106     MediaInfo_FileOption_CloseAll       =0x02,
00107     MediaInfo_FileOption_Max            =0x04
00108 } MediaInfo_fileoptions_C;
00109 
00110 
00111 #ifdef __cplusplus
00112 extern "C"
00113 {
00114 #endif /* __cplusplus */
00115 
00116 #ifdef MEDIAINFO_GLIBC
00117     #include <gmodule.h>
00118     static GModule* Module=NULL;
00119 #elif defined (_WIN32) || defined (WIN32)
00120     #include <windows.h>
00121     static HMODULE  Module=NULL;
00122 #else
00123     #include <dlfcn.h>
00124     static void*    Module=NULL;
00125 #endif
00126 static size_t Module_Count=0;
00127 
00128 #ifdef MEDIAINFO_GLIBC
00129 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00130     if (!g_module_symbol (Module, "MediaInfo"MEDIAINFO_Ansi"_"_Name2, (gpointer*)&MediaInfo_##_Name)) \
00131         Errors++; \
00132     if (!g_module_symbol (Module, "MediaInfoList"MEDIAINFO_Ansi"_"_Name2, (gpointer*)&MediaInfoList_##_Name)) \
00133         Errors++;
00134 #elif defined (_WIN32) || defined (WIN32)
00135 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00136     MediaInfo_##_Name=(MEDIAINFO_##_Name)GetProcAddress(Module, "MediaInfo"MEDIAINFO_Ansi"_"_Name2); \
00137     if (MediaInfo_##_Name==NULL) Errors++; \
00138     MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)GetProcAddress(Module, "MediaInfoList"MEDIAINFO_Ansi"_"_Name2); \
00139     if (MediaInfoList_##_Name==NULL) Errors++;
00140 #else
00141 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00142     MediaInfo_##_Name=(MEDIAINFO_##_Name)dlsym(Module, "MediaInfo"MEDIAINFO_Ansi"_"_Name2); \
00143     if (MediaInfo_##_Name==NULL) Errors++; \
00144     MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)dlsym(Module, "MediaInfoList"MEDIAINFO_Ansi"_"_Name2); \
00145     if (MediaInfoList_##_Name==NULL) Errors++;
00146 #endif
00147 
00148 typedef void* (__stdcall *MEDIAINFO_New)(); static MEDIAINFO_New MediaInfo_New;
00149 typedef void* (__stdcall *MEDIAINFOLIST_New)(); static MEDIAINFOLIST_New MediaInfoList_New;
00150 typedef void (__stdcall *MEDIAINFO_Delete)(void*); static MEDIAINFO_Delete MediaInfo_Delete;
00151 typedef void (__stdcall *MEDIAINFOLIST_Delete)(void*); static MEDIAINFOLIST_Delete MediaInfoList_Delete;
00152 typedef size_t (__stdcall *MEDIAINFO_Open)(void*, const MediaInfo_Char*); static MEDIAINFO_Open MediaInfo_Open;
00153 typedef size_t (__stdcall *MEDIAINFOLIST_Open)(void*, const MediaInfo_Char*, const MediaInfo_fileoptions_C); static MEDIAINFOLIST_Open MediaInfoList_Open;
00154 typedef void (__stdcall *MEDIAINFO_Close)(void*); static MEDIAINFO_Close MediaInfo_Close;
00155 typedef void (__stdcall *MEDIAINFOLIST_Close)(void*, size_t); static MEDIAINFOLIST_Close MediaInfoList_Close;
00156 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Inform)(void*, size_t Reserved); static MEDIAINFO_Inform MediaInfo_Inform;
00157 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Inform)(void*, size_t, size_t Reserved); static MEDIAINFOLIST_Inform MediaInfoList_Inform;
00158 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_GetI)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo); static MEDIAINFO_GetI MediaInfo_GetI;
00159 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_GetI)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo); static MEDIAINFOLIST_GetI MediaInfoList_GetI;
00160 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Get)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber, const MediaInfo_Char* Parameter, MediaInfo_info_C KindOfInfo, MediaInfo_info_C KindOfSearch); static MEDIAINFO_Get MediaInfo_Get;
00161 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Get)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber, const MediaInfo_Char* Parameter, MediaInfo_info_C KindOfInfo, MediaInfo_info_C KindOfSearch); static MEDIAINFOLIST_Get MediaInfoList_Get;
00162 typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value); static MEDIAINFO_Option MediaInfo_Option;
00163 typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value); static MEDIAINFOLIST_Option MediaInfoList_Option;
00164 typedef size_t (__stdcall *MEDIAINFO_State_Get)(void*); static MEDIAINFO_State_Get MediaInfo_State_Get;
00165 typedef size_t (__stdcall *MEDIAINFOLIST_State_Get)(void*); static MEDIAINFOLIST_State_Get MediaInfoList_State_Get;
00166 typedef size_t (__stdcall *MEDIAINFO_Count_Get)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber); static MEDIAINFO_Count_Get MediaInfo_Count_Get;
00167 typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber); static MEDIAINFOLIST_Count_Get MediaInfoList_Count_Get;
00168 typedef size_t (__stdcall *MEDIAINFO_Count_Get_Files)(void*); static MEDIAINFO_Count_Get_Files MediaInfo_Count_Get_Files;
00169 typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get_Files)(void*); static MEDIAINFOLIST_Count_Get_Files MediaInfoList_Count_Get_Files;
00170 
00171 static size_t MediaInfoDLL_Load()
00172 {
00173     if (Module_Count>0)
00174     {
00175         Module_Count++;
00176         return 1;
00177     }
00178 
00179     /* Load library */
00180     #ifdef MEDIAINFO_GLIBC
00181         Module=g_module_open(MEDIAINFODLL_NAME, G_MODULE_BIND_LAZY);
00182     #elif defined (_WIN32) || defined (WIN32)
00183         Module=LoadLibrary(_T(MEDIAINFODLL_NAME));
00184     #else
00185         Module=dlopen(MEDIAINFODLL_NAME, RTLD_LAZY);
00186         if (!Module)
00187             Module=dlopen("./"MEDIAINFODLL_NAME, RTLD_LAZY);
00188     #endif
00189     if (!Module)
00190         return -1;
00191 
00192     /* Load methods */
00193     size_t Errors=0;
00194     MEDIAINFO_ASSIGN(New,"New")
00195     MEDIAINFO_ASSIGN(Delete,"Delete")
00196     MEDIAINFO_ASSIGN(Open,"Open")
00197     MEDIAINFO_ASSIGN(Close,"Close")
00198     MEDIAINFO_ASSIGN(Inform,"Inform")
00199     MEDIAINFO_ASSIGN(GetI,"GetI")
00200     MEDIAINFO_ASSIGN(Get,"Get")
00201     MEDIAINFO_ASSIGN(Option,"Option")
00202     MEDIAINFO_ASSIGN(State_Get,"State_Get")
00203     MEDIAINFO_ASSIGN(Count_Get,"Count_Get")
00204     MEDIAINFO_ASSIGN(Count_Get_Files,"Count_Get_Files")
00205     if (Errors>1) //Normal for Count_Get_Files, MediaInfo has no one.
00206        return -1;
00207 
00208     Module_Count++;
00209     return 1;
00210 }
00211 
00212 static size_t MediaInfoDLL_IsLoaded()
00213 {
00214     if (Module)
00215         return 1;
00216     else
00217         return 0;
00218 }
00219 
00220 static void MediaInfoDLL_UnLoad()
00221 {
00222     Module_Count--;
00223     if (Module_Count>0)
00224         return;
00225 
00226     #ifdef MEDIAINFO_GLIBC
00227         g_module_close(Module);
00228     #elif defined (_WIN32) || defined (WIN32)
00229         FreeLibrary(Module);
00230     #else
00231         dlclose(Module);
00232     #endif
00233     Module=NULL;
00234 }
00235 
00236 #ifdef __cplusplus
00237 }
00238 #endif /*__cplusplus*/
00239 
00240 /***************************************************************************/
00241 /***************************************************************************/
00242 /***************************************************************************/
00243 
00244 #ifdef __cplusplus
00245 //DLL C++ wrapper for C functions
00246 
00247 //---------------------------------------------------------------------------
00248 #include <string>
00249 #include <sstream>
00250 //---------------------------------------------------------------------------
00251 
00252 namespace MediaInfoLib
00253 {
00254 
00255 //---------------------------------------------------------------------------
00256 //MediaInfo_Char types
00257 #undef  _T
00258 #define _T(__x)     __T(__x)
00259 #if defined(UNICODE) || defined (_UNICODE)
00260     typedef wchar_t Char;
00261     #undef  __T
00262     #define __T(__x) L ## __x
00263 #else
00264     typedef char Char;
00265     #undef  __T
00266     #define __T(__x) __x
00267 #endif
00268 typedef std::basic_string<Char>        String;
00269 typedef std::basic_stringstream<Char>  StringStream;
00270 typedef std::basic_istringstream<Char> tiStringStream;
00271 typedef std::basic_ostringstream<Char> toStringStream;
00272 const size_t Error=(size_t)(-1);
00273 //---------------------------------------------------------------------------
00274 
00275 //---------------------------------------------------------------------------
00277 enum stream_t
00278 {
00279     Stream_General,                 
00280     Stream_Video,                   
00281     Stream_Audio,                   
00282     Stream_Text,                    
00283     Stream_Chapters,                
00284     Stream_Image,                   
00285     Stream_Menu,                    
00286     Stream_Max,
00287 };
00288 
00290 enum info_t
00291 {
00292     Info_Name,                      
00293     Info_Text,                      
00294     Info_Measure,                   
00295     Info_Options,                   
00296     Info_Name_Text,                 
00297     Info_Measure_Text,              
00298     Info_Info,                      
00299     Info_HowTo,                     
00300     Info_Max
00301 };
00302 
00307 enum infooptions_t
00308 {
00309     InfoOption_ShowInInform,        
00310     InfoOption_Reserved,            
00311     InfoOption_ShowInSupported,     
00312     InfoOption_TypeOfValue,         
00313     InfoOption_Max
00314 };
00315 
00317 enum fileoptions_t
00318 {
00319     FileOption_Nothing      =0x00,
00320     FileOption_Recursive    =0x01,  
00321     FileOption_CloseAll     =0x02,  
00322     FileOption_Max          =0x04
00323 };
00324 
00325 const String Unable_Load_DLL=_T("Unable to load ")_T(MEDIAINFODLL_NAME);
00326 #define MEDIAINFO_TEST_VOID \
00327     if (!IsReady()) return
00328 #define MEDIAINFO_TEST_INT \
00329     if (!IsReady()) return 0
00330 #define MEDIAINFO_TEST_STRING \
00331     if (!IsReady()) return Unable_Load_DLL
00332 #define MEDIAINFO_TEST_STRING_STATIC \
00333     if (!Module) return Unable_Load_DLL
00334 
00335 //---------------------------------------------------------------------------
00336 class MediaInfo
00337 {
00338 public :
00339     MediaInfo ()                {if (!Module) MediaInfoDLL_Load(); if (!Module) {Handle=NULL; return;}; Handle=MediaInfo_New();};
00340     ~MediaInfo ()               {MEDIAINFO_TEST_VOID; MediaInfo_Delete(Handle);};
00341 
00342     //File
00343     size_t Open (const String &File) {MEDIAINFO_TEST_INT; return MediaInfo_Open(Handle, File.c_str());};
00344     //size_t 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);};
00345     //size_t Save () {MEDIAINFO_TEST_INT; return MediaInfo_Save(Handle);};
00346     void Close () {MEDIAINFO_TEST_VOID; return MediaInfo_Close(Handle);};
00347 
00348     //General information
00349     String Inform ()  {MEDIAINFO_TEST_STRING; return MediaInfo_Inform(Handle, 0);};
00350     String Get (stream_t StreamKind, size_t StreamNumber, size_t Parameter, info_t InfoKind=Info_Text)  {MEDIAINFO_TEST_STRING; return MediaInfo_GetI (Handle, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, (MediaInfo_info_C)InfoKind);};
00351     String Get (stream_t StreamKind, size_t StreamNumber, const 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);};
00352     //size_t Set (const String &ToSet, stream_t StreamKind, size_t StreamNumber, size_t Parameter, const String &OldValue=_T(""))  {MEDIAINFO_TEST_INT; return MediaInfo_SetI (Handle, ToSet.c_str(), (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, OldValue.c_str());};
00353     //size_t Set (const String &ToSet, stream_t StreamKind, size_t StreamNumber, const String &Parameter, const String &OldValue=_T(""))  {MEDIAINFO_TEST_INT; return MediaInfo_Set (Handle, ToSet.c_str(), (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter.c_str(), OldValue.c_str());};
00354     String        Option (const String &Option, const String &Value=_T(""))  {MEDIAINFO_TEST_STRING; return MediaInfo_Option (Handle, Option.c_str(), Value.c_str());};
00355     static String Option_Static (const String &Option, const String &Value=_T(""))  {MEDIAINFO_TEST_STRING_STATIC; return MediaInfo_Option (NULL, Option.c_str(), Value.c_str());};
00356     size_t                  State_Get ()  {MEDIAINFO_TEST_INT; return MediaInfo_State_Get(Handle);};
00357     size_t                  Count_Get (stream_t StreamKind, size_t StreamNumber=-1)  {MEDIAINFO_TEST_INT; return MediaInfo_Count_Get(Handle, (MediaInfo_stream_C)StreamKind, StreamNumber);};
00358 
00359     bool IsReady() {return (Handle && Module)?true:false;}
00360 
00361 private :
00362     void* Handle;
00363 };
00364 
00365 class MediaInfoList
00366 {
00367 public :
00368     MediaInfoList ()                {MediaInfoDLL_Load(); if (!MediaInfoDLL_IsLoaded()) {Handle=NULL; return;}; Handle=MediaInfoList_New();};
00369     ~MediaInfoList ()               {MEDIAINFO_TEST_VOID; MediaInfoList_Delete(Handle); MediaInfoDLL_UnLoad();};
00370 
00371     //File
00372     size_t Open (const String &File, const fileoptions_t Options=FileOption_Nothing) {MEDIAINFO_TEST_INT; return MediaInfoList_Open(Handle, File.c_str(), (MediaInfo_fileoptions_C)Options);};
00373     //size_t 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);};
00374     //size_t Save (size_t FilePos) {MEDIAINFO_TEST_INT; return MediaInfoList_Save(Handle, FilePos);};
00375     void Close (size_t FilePos=(size_t)-1) {MEDIAINFO_TEST_VOID; return MediaInfoList_Close(Handle, FilePos);};
00376 
00377     //General information
00378     String Inform (size_t FilePos=(size_t)-1)  {MEDIAINFO_TEST_STRING; return MediaInfoList_Inform(Handle, FilePos, 0);};
00379     String Get (size_t FilePos, stream_t StreamKind, size_t StreamNumber, size_t Parameter, info_t InfoKind=Info_Text)  {MEDIAINFO_TEST_STRING; return MediaInfoList_GetI (Handle, FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, (MediaInfo_info_C)InfoKind);};
00380     String Get (size_t FilePos, stream_t StreamKind, size_t StreamNumber, const 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);};
00381     //size_t Set (const String &ToSet, size_t FilePos, stream_t StreamKind, size_t StreamNumber, size_t Parameter, const String &OldValue=_T(""))  {MEDIAINFO_TEST_INT; return MediaInfoList_SetI (Handle, ToSet.c_str(), FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, OldValue.c_str());};
00382     //size_t Set (const String &ToSet, size_t FilePos, stream_t StreamKind, size_t StreamNumber, const String &Parameter, const 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());};
00383     String        Option (const String &Option, const String &Value=_T(""))  {MEDIAINFO_TEST_STRING; return MediaInfoList_Option (Handle, Option.c_str(), Value.c_str());};
00384     static String Option_Static (const String &Option, const String &Value=_T(""))  {MEDIAINFO_TEST_STRING_STATIC; return MediaInfoList_Option (NULL, Option.c_str(), Value.c_str());};
00385     size_t        State_Get ()  {MEDIAINFO_TEST_INT; return MediaInfoList_State_Get(Handle);};
00386     size_t        Count_Get (size_t FilePos, stream_t StreamKind, size_t StreamNumber=-1)  {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get(Handle, FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber);};
00387     size_t        Count_Get ()  {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get_Files(Handle);};
00388 
00389     bool IsReady() {return (Handle && Module)?true:false;}
00390 
00391 private :
00392     void* Handle;
00393 };
00394 
00395 } //NameSpace
00396 #endif /*__cplusplus*/
00397 
00398 #endif

Generated on Mon Dec 10 14:07:11 2007 for MediaInfoLib by  doxygen 1.5.4