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 #endif
00196 if (!Module)
00197 return -1;
00198
00199
00200 size_t Errors=0;
00201 MEDIAINFO_ASSIGN(New,"New")
00202 MEDIAINFO_ASSIGN(Delete,"Delete")
00203 MEDIAINFO_ASSIGN(Open,"Open")
00204 MEDIAINFO_ASSIGN(Close,"Close")
00205 MEDIAINFO_ASSIGN(Inform,"Inform")
00206 MEDIAINFO_ASSIGN(GetI,"GetI")
00207 MEDIAINFO_ASSIGN(Get,"Get")
00208 MEDIAINFO_ASSIGN(Option,"Option")
00209 MEDIAINFO_ASSIGN(State_Get,"State_Get")
00210 MEDIAINFO_ASSIGN(Count_Get,"Count_Get")
00211 MEDIAINFO_ASSIGN(Count_Get_Files,"Count_Get_Files")
00212 if (Errors>1)
00213 return -1;
00214
00215 Module_Count++;
00216 return 1;
00217 }
00218
00219 static size_t MediaInfoDLL_IsLoaded()
00220 {
00221 if (Module)
00222 return 1;
00223 else
00224 return 0;
00225 }
00226
00227 static void MediaInfoDLL_UnLoad()
00228 {
00229 Module_Count--;
00230 if (Module_Count>0)
00231 return;
00232
00233 #ifdef MEDIAINFO_GLIBC
00234 g_module_close(Module);
00235 #elif defined (_WIN32) || defined (WIN32)
00236 FreeLibrary(Module);
00237 #else
00238 dlclose(Module);
00239 #endif
00240 Module=NULL;
00241 }
00242
00243 #ifdef __cplusplus
00244 }
00245 #endif
00246
00247
00248
00249
00250
00251 #ifdef __cplusplus
00252
00253
00254
00255 #include <string>
00256 #include <sstream>
00257
00258
00259 namespace MediaInfoLib
00260 {
00261
00262
00263
00264 #undef _T
00265 #define _T(__x) __T(__x)
00266 #if defined(UNICODE) || defined (_UNICODE)
00267 typedef wchar_t Char;
00268 #undef __T
00269 #define __T(__x) L ## __x
00270 #else
00271 typedef char Char;
00272 #undef __T
00273 #define __T(__x) __x
00274 #endif
00275 typedef std::basic_string<Char> String;
00276 typedef std::basic_stringstream<Char> StringStream;
00277 typedef std::basic_istringstream<Char> tiStringStream;
00278 typedef std::basic_ostringstream<Char> toStringStream;
00279 const size_t Error=(size_t)(-1);
00280
00281
00282
00284 enum stream_t
00285 {
00286 Stream_General,
00287 Stream_Video,
00288 Stream_Audio,
00289 Stream_Text,
00290 Stream_Chapters,
00291 Stream_Image,
00292 Stream_Menu,
00293 Stream_Max,
00294 };
00295
00297 enum info_t
00298 {
00299 Info_Name,
00300 Info_Text,
00301 Info_Measure,
00302 Info_Options,
00303 Info_Name_Text,
00304 Info_Measure_Text,
00305 Info_Info,
00306 Info_HowTo,
00307 Info_Max
00308 };
00309
00314 enum infooptions_t
00315 {
00316 InfoOption_ShowInInform,
00317 InfoOption_Reserved,
00318 InfoOption_ShowInSupported,
00319 InfoOption_TypeOfValue,
00320 InfoOption_Max
00321 };
00322
00324 enum fileoptions_t
00325 {
00326 FileOption_Nothing =0x00,
00327 FileOption_Recursive =0x01,
00328 FileOption_CloseAll =0x02,
00329 FileOption_Max =0x04
00330 };
00331
00332 const String Unable_Load_DLL=_T("Unable to load ")_T(MEDIAINFODLL_NAME);
00333 #define MEDIAINFO_TEST_VOID \
00334 if (!IsReady()) return
00335 #define MEDIAINFO_TEST_INT \
00336 if (!IsReady()) return 0
00337 #define MEDIAINFO_TEST_STRING \
00338 if (!IsReady()) return Unable_Load_DLL
00339 #define MEDIAINFO_TEST_STRING_STATIC \
00340 if (!Module) return Unable_Load_DLL
00341
00342
00343 class MediaInfo
00344 {
00345 public :
00346 MediaInfo () {if (!Module) MediaInfoDLL_Load(); if (!Module) {Handle=NULL; return;}; Handle=MediaInfo_New();};
00347 ~MediaInfo () {MEDIAINFO_TEST_VOID; MediaInfo_Delete(Handle);};
00348
00349
00350 size_t Open (const String &File) {MEDIAINFO_TEST_INT; return MediaInfo_Open(Handle, File.c_str());};
00351
00352
00353 void Close () {MEDIAINFO_TEST_VOID; return MediaInfo_Close(Handle);};
00354
00355
00356 String Inform () {MEDIAINFO_TEST_STRING; return MediaInfo_Inform(Handle, 0);};
00357 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);};
00358 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);};
00359
00360
00361 String Option (const String &Option, const String &Value=_T("")) {MEDIAINFO_TEST_STRING; return MediaInfo_Option (Handle, Option.c_str(), Value.c_str());};
00362 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());};
00363 size_t State_Get () {MEDIAINFO_TEST_INT; return MediaInfo_State_Get(Handle);};
00364 size_t Count_Get (stream_t StreamKind, size_t StreamNumber=-1) {MEDIAINFO_TEST_INT; return MediaInfo_Count_Get(Handle, (MediaInfo_stream_C)StreamKind, StreamNumber);};
00365
00366 bool IsReady() {return (Handle && Module)?true:false;}
00367
00368 private :
00369 void* Handle;
00370 };
00371
00372 class MediaInfoList
00373 {
00374 public :
00375 MediaInfoList () {MediaInfoDLL_Load(); if (!MediaInfoDLL_IsLoaded()) {Handle=NULL; return;}; Handle=MediaInfoList_New();};
00376 ~MediaInfoList () {MEDIAINFO_TEST_VOID; MediaInfoList_Delete(Handle); MediaInfoDLL_UnLoad();};
00377
00378
00379 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);};
00380
00381
00382 void Close (size_t FilePos=(size_t)-1) {MEDIAINFO_TEST_VOID; return MediaInfoList_Close(Handle, FilePos);};
00383
00384
00385 String Inform (size_t FilePos=(size_t)-1) {MEDIAINFO_TEST_STRING; return MediaInfoList_Inform(Handle, FilePos, 0);};
00386 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);};
00387 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);};
00388
00389
00390 String Option (const String &Option, const String &Value=_T("")) {MEDIAINFO_TEST_STRING; return MediaInfoList_Option (Handle, Option.c_str(), Value.c_str());};
00391 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());};
00392 size_t State_Get () {MEDIAINFO_TEST_INT; return MediaInfoList_State_Get(Handle);};
00393 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);};
00394 size_t Count_Get () {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get_Files(Handle);};
00395
00396 bool IsReady() {return (Handle && Module)?true:false;}
00397
00398 private :
00399 void* Handle;
00400 };
00401
00402 }
00403 #endif
00404
00405 #endif