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