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