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