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