MediaInfoLib  0.7
MediaInfoDLL.h
1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  * Use of this source code is governed by a BSD-style license that can
4  * be found in the License.html file in the root of the source tree.
5  */
6 
7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 //
9 // Public DLL interface implementation
10 // Wrapper for MediaInfo Library
11 // See MediaInfo.h for help
12 //
13 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
14 
15 #ifndef MediaInfoDLLH
16 #define MediaInfoDLLH
17 
18 //***************************************************************************
19 // Platforms (from libzen)
20 //***************************************************************************
21 
22 /*---------------------------------------------------------------------------*/
23 /*Win32*/
24 #if defined(__NT__) || defined(_WIN32) || defined(WIN32)
25  #ifndef WIN32
26  #define WIN32
27  #endif
28  #ifndef _WIN32
29  #define _WIN32
30  #endif
31  #ifndef __WIN32__
32  #define __WIN32__ 1
33  #endif
34 #endif
35 
36 /*---------------------------------------------------------------------------*/
37 /*Win64*/
38 #if defined(_WIN64) || defined(WIN64)
39  #ifndef WIN64
40  #define WIN64
41  #endif
42  #ifndef _WIN64
43  #define _WIN64
44  #endif
45  #ifndef __WIN64__
46  #define __WIN64__ 1
47  #endif
48 #endif
49 
50 /*---------------------------------------------------------------------------*/
51 /*Windows*/
52 #if defined(WIN32) || defined(WIN64)
53  #ifndef WINDOWS
54  #define WINDOWS
55  #endif
56  #ifndef _WINDOWS
57  #define _WINDOWS
58  #endif
59  #ifndef __WINDOWS__
60  #define __WINDOWS__ 1
61  #endif
62 #endif
63 
64 /*---------------------------------------------------------------------------*/
65 /*Unix (Linux, HP, Sun, BeOS...)*/
66 #if defined(UNIX) || defined(_UNIX) || defined(__UNIX__) \
67  || defined(__unix) || defined(__unix__) \
68  || defined(____SVR4____) || defined(__LINUX__) || defined(__sgi) \
69  || defined(__hpux) || defined(sun) || defined(__SUN__) || defined(_AIX) \
70  || defined(__EMX__) || defined(__VMS) || defined(__BEOS__)
71  #ifndef UNIX
72  #define UNIX
73  #endif
74  #ifndef _UNIX
75  #define _UNIX
76  #endif
77  #ifndef __UNIX__
78  #define __UNIX__ 1
79  #endif
80 #endif
81 
82 /*---------------------------------------------------------------------------*/
83 /*MacOS Classic*/
84 #if defined(macintosh)
85  #ifndef MACOS
86  #define MACOS
87  #endif
88  #ifndef _MACOS
89  #define _MACOS
90  #endif
91  #ifndef __MACOS__
92  #define __MACOS__ 1
93  #endif
94 #endif
95 
96 /*---------------------------------------------------------------------------*/
97 /*MacOS X*/
98 #if defined(__APPLE__) && defined(__MACH__)
99  #ifndef MACOSX
100  #define MACOSX
101  #endif
102  #ifndef _MACOSX
103  #define _MACOSX
104  #endif
105  #ifndef __MACOSX__
106  #define __MACOSX__ 1
107  #endif
108 #endif
109 
110 /*Test of targets*/
111 #if defined(WINDOWS) && defined(UNIX) && defined(MACOS) && defined(MACOSX)
112  #pragma message Multiple platforms???
113 #endif
114 
115 #if !defined(WIN32) && !defined(UNIX) && !defined(MACOS) && !defined(MACOSX)
116  #pragma message No known platforms, assume default
117 #endif
118 
119 /*-------------------------------------------------------------------------*/
120 #if defined(_WIN32) || defined(WIN32)
121  #ifdef _UNICODE
122  #define MEDIAINFODLL_NAME L"MediaInfo.dll"
123  #else //_UNICODE
124  #define MEDIAINFODLL_NAME "MediaInfo.dll"
125  #endif //_UNICODE
126 #elif defined(__APPLE__) && defined(__MACH__)
127  #define MEDIAINFODLL_NAME "libmediainfo.0.dylib"
128  #define __stdcall
129  #include <new> //for size_t
130 #else
131  #define MEDIAINFODLL_NAME "libmediainfo.so.0"
132  #define __stdcall
133 #endif
134 
135 /*-------------------------------------------------------------------------*/
136 /*Char types */
137 #undef __T
138 #define __T(__x) __T(__x)
139 #if defined(UNICODE) || defined(_UNICODE)
140  typedef wchar_t MediaInfo_Char;
141  #undef __T
142  #define __T(__x) L ## __x
143  #define MEDIAINFO_Ansi ""
144 #else
145  typedef char MediaInfo_Char;
146  #undef __T
147  #define __T(__x) __x
148  #define MEDIAINFO_Ansi "A"
149 #endif
150 /*-------------------------------------------------------------------------*/
151 
152 /*-------------------------------------------------------------------------*/
153 /*8-bit int */
154 typedef unsigned char MediaInfo_int8u;
155 /*-------------------------------------------------------------------------*/
156 
157 /*-------------------------------------------------------------------------*/
158 /*64-bit int */
159 #if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(__UNIX__) || defined(__MACOSX__)
160  #undef MAXTYPE_INT
161  #define MAXTYPE_INT 64
162  typedef unsigned long long MediaInfo_int64u;
163 #elif defined(__WIN32__) || defined(_WIN32)
164  #undef MAXTYPE_INT
165  #define MAXTYPE_INT 64
166  typedef unsigned __int64 MediaInfo_int64u;
167 #else
168  #pragma message This machine has no 64-bit integer type?
169 #endif
170 /*-------------------------------------------------------------------------*/
171 
172 /*-------------------------------------------------------------------------*/
173 /*NULL */
174 #ifndef NULL
175  #define NULL 0
176 #endif
177 /*-------------------------------------------------------------------------*/
178 
180 typedef enum MediaInfo_stream_t {
181  MediaInfo_Stream_General,
182  MediaInfo_Stream_Video,
183  MediaInfo_Stream_Audio,
184  MediaInfo_Stream_Text,
185  MediaInfo_Stream_Other,
186  MediaInfo_Stream_Image,
187  MediaInfo_Stream_Menu,
188  MediaInfo_Stream_Max
189 } MediaInfo_stream_C;
190 
192 typedef enum MediaInfo_info_t {
193  MediaInfo_Info_Name,
194  MediaInfo_Info_Text,
195  MediaInfo_Info_Measure,
196  MediaInfo_Info_Options,
197  MediaInfo_Info_Name_Text,
198  MediaInfo_Info_Measure_Text,
199  MediaInfo_Info_Info,
200  MediaInfo_Info_HowTo,
201  MediaInfo_Info_Max
202 } MediaInfo_info_C;
203 
205 typedef enum MediaInfo_infooptions_t {
206  MediaInfo_InfoOption_ShowInInform,
207  MediaInfo_InfoOption_Reserved,
208  MediaInfo_InfoOption_ShowInSupported,
209  MediaInfo_InfoOption_TypeOfValue,
210  MediaInfo_InfoOption_Max
211 } MediaInfo_infooptions_C;
212 
214 typedef enum MediaInfo_fileoptions_t {
215  MediaInfo_FileOption_Nothing = 0x00,
216  MediaInfo_FileOption_NoRecursive = 0x01,
217  MediaInfo_FileOption_CloseAll = 0x02,
218  MediaInfo_FileOption_Max = 0x04
219 } MediaInfo_fileoptions_C;
220 
221 
222 #ifdef __cplusplus
223 extern "C"
224 {
225 #endif /* __cplusplus */
226 
227 #ifdef MEDIAINFO_GLIBC
228  #include <gmodule.h>
229  static GModule* MediaInfo_Module = NULL;
230 #elif defined(_WIN32) || defined(WIN32)
231  #include <windows.h>
232  static HMODULE MediaInfo_Module = NULL;
233 #else
234  #ifdef MACOSX
235  #include <CoreFoundation/CFBundle.h>
236  #endif
237 
238  #include <dlfcn.h>
239  static void* MediaInfo_Module = NULL;
240 #endif
241  static size_t Module_Count = 0;
242 
243 #ifdef MEDIAINFO_GLIBC
244 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
245  if (!g_module_symbol (MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2, (gpointer*)&MediaInfo_##_Name)) \
246  Errors++;
247 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
248  if (!g_module_symbol (MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2, (gpointer*)&MediaInfoList_##_Name)) \
249  Errors++;
250 #elif defined(_WIN32) || defined(WIN32)
251 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
252  MediaInfo_##_Name=(MEDIAINFO_##_Name)GetProcAddress(MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2); \
253  if (MediaInfo_##_Name==NULL) Errors++;
254 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
255  MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)GetProcAddress(MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2); \
256  if (MediaInfoList_##_Name==NULL) Errors++;
257 #else
258 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
259  MediaInfo_##_Name=(MEDIAINFO_##_Name)dlsym(MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2); \
260  if (MediaInfo_##_Name==NULL) Errors++;
261 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
262  MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)dlsym(MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2); \
263  if (MediaInfoList_##_Name==NULL) Errors++;
264 #endif
265 
266  typedef void* (__stdcall *MEDIAINFO_New)();
267  static MEDIAINFO_New MediaInfo_New;
268  typedef void* (__stdcall *MEDIAINFOLIST_New)();
269  static MEDIAINFOLIST_New MediaInfoList_New;
270  typedef void (__stdcall *MEDIAINFO_Delete)(void*);
271  static MEDIAINFO_Delete MediaInfo_Delete;
272  typedef void (__stdcall *MEDIAINFOLIST_Delete)(void*);
273  static MEDIAINFOLIST_Delete MediaInfoList_Delete;
274  typedef size_t (__stdcall *MEDIAINFO_Open)(void*, const MediaInfo_Char*);
275  static MEDIAINFO_Open MediaInfo_Open;
276  typedef size_t (__stdcall *MEDIAINFOLIST_Open)(void*, const MediaInfo_Char*, const MediaInfo_fileoptions_C);
277  static MEDIAINFOLIST_Open MediaInfoList_Open;
278  typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Init)(void*, MediaInfo_int64u File_Size, MediaInfo_int64u File_Offset);
279  static MEDIAINFO_Open_Buffer_Init MediaInfo_Open_Buffer_Init;
280  typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Continue)(void*, MediaInfo_int8u* Buffer, size_t Buffer_Size);
281  static MEDIAINFO_Open_Buffer_Continue MediaInfo_Open_Buffer_Continue;
282  typedef MediaInfo_int64u(__stdcall *MEDIAINFO_Open_Buffer_Continue_GoTo_Get)(void*);
283  static MEDIAINFO_Open_Buffer_Continue_GoTo_Get MediaInfo_Open_Buffer_Continue_GoTo_Get;
284  typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Finalize)(void*);
285  static MEDIAINFO_Open_Buffer_Finalize MediaInfo_Open_Buffer_Finalize;
286  typedef size_t (__stdcall *MEDIAINFO_Open_NextPacket)(void*);
287  static MEDIAINFO_Open_NextPacket MediaInfo_Open_NextPacket;
288  typedef void (__stdcall *MEDIAINFO_Close)(void*);
289  static MEDIAINFO_Close MediaInfo_Close;
290  typedef void (__stdcall *MEDIAINFOLIST_Close)(void*, size_t);
291  static MEDIAINFOLIST_Close MediaInfoList_Close;
292  typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Inform)(void*, size_t Reserved);
293  static MEDIAINFO_Inform MediaInfo_Inform;
294  typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Inform)(void*, size_t, size_t Reserved);
295  static MEDIAINFOLIST_Inform MediaInfoList_Inform;
296  typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_GetI)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
297  static MEDIAINFO_GetI MediaInfo_GetI;
298  typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_GetI)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
299  static MEDIAINFOLIST_GetI MediaInfoList_GetI;
300  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);
301  static MEDIAINFO_Get MediaInfo_Get;
302  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);
303  static MEDIAINFOLIST_Get MediaInfoList_Get;
304  typedef size_t (__stdcall *MEDIAINFO_Output_Buffer_Get)(void*, const MediaInfo_Char* Parameter);
305  static MEDIAINFO_Output_Buffer_Get MediaInfo_Output_Buffer_Get;
306  typedef size_t (__stdcall *MEDIAINFO_Output_Buffer_GetI)(void*, size_t Pos);
307  static MEDIAINFO_Output_Buffer_GetI MediaInfo_Output_Buffer_GetI;
308  typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value);
309  static MEDIAINFO_Option MediaInfo_Option;
310  typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value);
311  static MEDIAINFOLIST_Option MediaInfoList_Option;
312  typedef size_t (__stdcall *MEDIAINFO_State_Get)(void*);
313  static MEDIAINFO_State_Get MediaInfo_State_Get;
314  typedef size_t (__stdcall *MEDIAINFOLIST_State_Get)(void*);
315  static MEDIAINFOLIST_State_Get MediaInfoList_State_Get;
316  typedef size_t (__stdcall *MEDIAINFO_Count_Get)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber);
317  static MEDIAINFO_Count_Get MediaInfo_Count_Get;
318  typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber);
319  static MEDIAINFOLIST_Count_Get MediaInfoList_Count_Get;
320  typedef size_t (__stdcall *MEDIAINFO_Count_Get_Files)(void*);
321  static MEDIAINFO_Count_Get_Files MediaInfo_Count_Get_Files;
322  typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get_Files)(void*);
323  static MEDIAINFOLIST_Count_Get_Files MediaInfoList_Count_Get_Files;
324 
325  static size_t MediaInfoDLL_Load()
326  {
327  size_t Errors = 0;
328 
329  if (Module_Count > 0) {
330  Module_Count++;
331  return 1;
332  }
333 
334  /* Load library */
335  #ifdef MEDIAINFO_GLIBC
336  MediaInfo_Module = g_module_open(MEDIAINFODLL_NAME, G_MODULE_BIND_LAZY);
337  #elif defined(_WIN32) || defined(WIN32)
338  MediaInfo_Module = LoadLibrary(MEDIAINFODLL_NAME);
339  #else
340  #ifdef MACOSX
341  MediaInfo_Module = dlopen("@executable_path/" MEDIAINFODLL_NAME, RTLD_LAZY);
342  if (!MediaInfo_Module)
343  {
344  CFBundleRef mainBundle = CFBundleGetMainBundle();
345 
346  // get full app path and delete app name
347  CFURLRef app_url = CFBundleCopyExecutableURL(mainBundle);
348  CFURLRef app_path_url = CFURLCreateCopyDeletingLastPathComponent(NULL, app_url);
349 
350  CFStringRef app_path = CFURLCopyFileSystemPath(app_path_url, kCFURLPOSIXPathStyle);
351 
352  CFMutableStringRef mut_app_path = CFStringCreateMutableCopy(NULL, NULL, app_path);
353  CFStringAppend(mut_app_path, CFSTR("/"));
354  CFStringAppend(mut_app_path, CFSTR(MEDIAINFODLL_NAME));
355  CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
356  const char *fullPath = CFStringGetCStringPtr(mut_app_path, encodingMethod);
357 
358  MediaInfo_Module = dlopen(fullPath, RTLD_LAZY);
359 
360  CFRelease(app_url);
361  CFRelease(app_path_url);
362  CFRelease(app_path);
363  CFRelease(mut_app_path);
364  }
365  #endif /* MACOSX*/
366 
367  if (!MediaInfo_Module)
368  MediaInfo_Module = dlopen(MEDIAINFODLL_NAME, RTLD_LAZY);
369  if (!MediaInfo_Module)
370  MediaInfo_Module = dlopen("./" MEDIAINFODLL_NAME, RTLD_LAZY);
371  if (!MediaInfo_Module)
372  MediaInfo_Module = dlopen("/usr/local/lib/" MEDIAINFODLL_NAME, RTLD_LAZY);
373  if (!MediaInfo_Module)
374  MediaInfo_Module = dlopen("/usr/local/lib64/" MEDIAINFODLL_NAME, RTLD_LAZY);
375  if (!MediaInfo_Module)
376  MediaInfo_Module = dlopen("/usr/lib/" MEDIAINFODLL_NAME, RTLD_LAZY);
377  if (!MediaInfo_Module)
378  MediaInfo_Module = dlopen("/usr/lib64/" MEDIAINFODLL_NAME, RTLD_LAZY);
379  #endif
380  if (!MediaInfo_Module)
381  return (size_t) - 1;
382 
383  /* Load methods */
384  MEDIAINFO_ASSIGN(New, "New")
385  MEDIAINFOLIST_ASSIGN(New, "New")
386  MEDIAINFO_ASSIGN(Delete, "Delete")
387  MEDIAINFOLIST_ASSIGN(Delete, "Delete")
388  MEDIAINFO_ASSIGN(Open, "Open")
389  MEDIAINFOLIST_ASSIGN(Open, "Open")
390  MEDIAINFO_ASSIGN(Open_Buffer_Init, "Open_Buffer_Init")
391  MEDIAINFO_ASSIGN(Open_Buffer_Continue, "Open_Buffer_Continue")
392  MEDIAINFO_ASSIGN(Open_Buffer_Continue_GoTo_Get, "Open_Buffer_Continue_GoTo_Get")
393  MEDIAINFO_ASSIGN(Open_Buffer_Finalize, "Open_Buffer_Finalize")
394  MEDIAINFO_ASSIGN(Open_NextPacket, "Open_NextPacket")
395  MEDIAINFO_ASSIGN(Close, "Close")
396  MEDIAINFOLIST_ASSIGN(Close, "Close")
397  MEDIAINFO_ASSIGN(Inform, "Inform")
398  MEDIAINFOLIST_ASSIGN(Inform, "Inform")
399  MEDIAINFO_ASSIGN(GetI, "GetI")
400  MEDIAINFOLIST_ASSIGN(GetI, "GetI")
401  MEDIAINFO_ASSIGN(Get, "Get")
402  MEDIAINFOLIST_ASSIGN(Get, "Get")
403  MEDIAINFO_ASSIGN(Output_Buffer_Get, "Output_Buffer_Get")
404  MEDIAINFO_ASSIGN(Output_Buffer_GetI, "Output_Buffer_GetI")
405  MEDIAINFO_ASSIGN(Option, "Option")
406  MEDIAINFOLIST_ASSIGN(Option, "Option")
407  MEDIAINFO_ASSIGN(State_Get, "State_Get")
408  MEDIAINFOLIST_ASSIGN(State_Get, "State_Get")
409  MEDIAINFO_ASSIGN(Count_Get, "Count_Get")
410  MEDIAINFOLIST_ASSIGN(Count_Get, "Count_Get")
411  MEDIAINFOLIST_ASSIGN(Count_Get_Files, "Count_Get_Files")
412  if (Errors > 0) {
413  // Unload DLL with errors
414  #ifdef MEDIAINFO_GLIBC
415  g_module_close(MediaInfo_Module);
416  #elif defined(_WIN32) || defined(WIN32)
417  FreeLibrary(MediaInfo_Module);
418  #else
419  dlclose(MediaInfo_Module);
420  #endif
421  MediaInfo_Module = NULL;
422  return (size_t) - 1;
423  }
424 
425  Module_Count++;
426  return (size_t)1;
427  }
428 
429  static size_t MediaInfoDLL_IsLoaded()
430  {
431  if (MediaInfo_Module)
432  return 1;
433  else
434  return 0;
435  }
436 
437  static void MediaInfoDLL_UnLoad()
438  {
439  Module_Count--;
440  if (Module_Count > 0)
441  return;
442 
443  #ifdef MEDIAINFO_GLIBC
444  g_module_close(MediaInfo_Module);
445  #elif defined(_WIN32) || defined(WIN32)
446  FreeLibrary(MediaInfo_Module);
447  #else
448  dlclose(MediaInfo_Module);
449  #endif
450  MediaInfo_Module = NULL;
451  }
452 
453 #ifdef __cplusplus
454 }
455 #endif /*__cplusplus*/
456 
457 /***************************************************************************/
458 /***************************************************************************/
459 /***************************************************************************/
460 
461 #ifdef __cplusplus
462 //DLL C++ wrapper for C functions
463 
464 //---------------------------------------------------------------------------
465 #include <string>
466 #include <sstream>
467 //---------------------------------------------------------------------------
468 
469 namespace MediaInfoDLL
470 {
471 
472  //---------------------------------------------------------------------------
473  //MediaInfo_Char types
474 #undef __T
475 #define __T(__x) __T(__x)
476 #if defined(UNICODE) || defined(_UNICODE)
477  typedef wchar_t Char;
478  #undef __T
479  #define __T(__x) L ## __x
480 #else
481  typedef char Char;
482  #undef __T
483  #define __T(__x) __x
484 #endif
485  typedef std::basic_string<Char> String;
486  typedef std::basic_stringstream<Char> StringStream;
487  typedef std::basic_istringstream<Char> iStringStream;
488  typedef std::basic_ostringstream<Char> oStringStream;
489  typedef std::basic_istringstream<Char> tiStringStream; // Legacy
490  typedef std::basic_ostringstream<Char> toStringStream; //Legacy
491  const size_t Error = (size_t)(-1);
492  //---------------------------------------------------------------------------
493 
494  //---------------------------------------------------------------------------
496  enum stream_t {
498  Stream_Video,
499  Stream_Audio,
500  Stream_Text,
501  Stream_Other,
502  Stream_Image,
503  Stream_Menu,
504  Stream_Max
505  };
506 
508  enum info_t {
509  Info_Name,
510  Info_Text,
511  Info_Measure,
512  Info_Options,
515  Info_Info,
516  Info_HowTo,
517  Info_Max
518  };
519 
524  enum infooptions_t {
526  InfoOption_Reserved,
529  InfoOption_Max
530  };
531 
533  enum fileoptions_t {
534  FileOption_Nothing = 0x00,
535  FileOption_NoRecursive = 0x01,
536  FileOption_CloseAll = 0x02,
537  FileOption_Max = 0x04
538  };
539 
540  const String Unable_Load_DLL = __T("Unable to load ")MEDIAINFODLL_NAME;
541 #define MEDIAINFO_TEST_VOID \
542  if (!IsReady()) return
543 #define MEDIAINFO_TEST_INT \
544  if (!IsReady()) return 0
545 #define MEDIAINFO_TEST_STRING \
546  if (!IsReady()) return Unable_Load_DLL
547 #define MEDIAINFO_TEST_STRING_STATIC \
548  if (!MediaInfo_Module) return Unable_Load_DLL
549 
550  //---------------------------------------------------------------------------
551  class MediaInfo
552  {
553  public :
554  MediaInfo() {if (!MediaInfo_Module) MediaInfoDLL_Load(); if (!MediaInfo_Module) {Handle = NULL; return;}; Handle = MediaInfo_New();};
555  ~MediaInfo() {MEDIAINFO_TEST_VOID; MediaInfo_Delete(Handle);};
556 
557  //File
558  size_t Open(const String &File) {MEDIAINFO_TEST_INT; return MediaInfo_Open(Handle, File.c_str());};
559  size_t Open_Buffer_Init(MediaInfo_int64u File_Size = (MediaInfo_int64u) - 1, MediaInfo_int64u File_Offset = 0) {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Init(Handle, File_Size, File_Offset);};
560  size_t Open_Buffer_Continue(MediaInfo_int8u* Buffer, size_t Buffer_Size) {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Continue(Handle, Buffer, Buffer_Size);};
561  MediaInfo_int64u Open_Buffer_Continue_GoTo_Get() {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Continue_GoTo_Get(Handle);};
562  size_t Open_Buffer_Finalize() {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Finalize(Handle);};
563  size_t Open_NextPacket() {MEDIAINFO_TEST_INT; return MediaInfo_Open_NextPacket(Handle);};
564  //size_t Save () {MEDIAINFO_TEST_INT; return MediaInfo_Save(Handle);};
565  void Close() {MEDIAINFO_TEST_VOID; return MediaInfo_Close(Handle);};
566 
567  //General information
568  String Inform() {MEDIAINFO_TEST_STRING; return MediaInfo_Inform(Handle, 0);};
569  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);};
570  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);};
571  //size_t Set (const String &ToSet, stream_t StreamKind, size_t StreamNumber, size_t Parameter, const String &OldValue=__T("")) {MEDIAINFO_TEST_INT; return MediaInfo_SetI (Handle, ToSet.c_str(), (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, OldValue.c_str());};
572  //size_t Set (const String &ToSet, stream_t StreamKind, size_t StreamNumber, const String &Parameter, const String &OldValue=__T("")) {MEDIAINFO_TEST_INT; return MediaInfo_Set (Handle, ToSet.c_str(), (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter.c_str(), OldValue.c_str());};
573  size_t Output_Buffer_Get(const String &Value) {return MediaInfo_Output_Buffer_Get(Handle, Value.c_str());}
574  size_t Output_Buffer_Get(size_t Pos) {return MediaInfo_Output_Buffer_GetI(Handle, Pos);}
575  String Option(const String &Option, const String &Value = __T("")) {MEDIAINFO_TEST_STRING; return MediaInfo_Option(Handle, Option.c_str(), Value.c_str());};
576  static String Option_Static(const String &Option, const String &Value = __T("")) {if (!MediaInfo_Module) MediaInfoDLL_Load(); MEDIAINFO_TEST_STRING_STATIC; return MediaInfo_Option(NULL, Option.c_str(), Value.c_str());};
577  size_t State_Get() {MEDIAINFO_TEST_INT; return MediaInfo_State_Get(Handle);};
578  size_t Count_Get(stream_t StreamKind, size_t StreamNumber = (size_t) - 1) {MEDIAINFO_TEST_INT; return MediaInfo_Count_Get(Handle, (MediaInfo_stream_C)StreamKind, StreamNumber);};
579 
580  bool IsReady() {return (Handle && MediaInfo_Module) ? true : false;}
581 
582  private :
583  void* Handle;
584  };
585 
586  class MediaInfoList
587  {
588  public :
589  MediaInfoList() {MediaInfoDLL_Load(); if (!MediaInfoDLL_IsLoaded()) {Handle = NULL; return;}; Handle = MediaInfoList_New();};
590  ~MediaInfoList() {MEDIAINFO_TEST_VOID; MediaInfoList_Delete(Handle); MediaInfoDLL_UnLoad();};
591 
592  //File
593  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);};
594  //size_t Save (size_t FilePos) {MEDIAINFO_TEST_INT; return MediaInfoList_Save(Handle, FilePos);};
595  void Close(size_t FilePos = (size_t) - 1) {MEDIAINFO_TEST_VOID; return MediaInfoList_Close(Handle, FilePos);};
596 
597  //General information
598  String Inform(size_t FilePos = (size_t) - 1) {MEDIAINFO_TEST_STRING; return MediaInfoList_Inform(Handle, FilePos, 0);};
599  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);};
600  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);};
601  //size_t Set (const String &ToSet, size_t FilePos, stream_t StreamKind, size_t StreamNumber, size_t Parameter, const String &OldValue=__T("")) {MEDIAINFO_TEST_INT; return MediaInfoList_SetI (Handle, ToSet.c_str(), FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter, OldValue.c_str());};
602  //size_t Set (const String &ToSet, size_t FilePos, stream_t StreamKind, size_t StreamNumber, const String &Parameter, const String &OldValue=__T("")) {MEDIAINFO_TEST_INT; return MediaInfoList_Set (Handle, ToSet.c_str(), FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber, Parameter.c_str(), OldValue.c_str());};
603  String Option(const String &Option, const String &Value = __T("")) {MEDIAINFO_TEST_STRING; return MediaInfoList_Option(Handle, Option.c_str(), Value.c_str());};
604  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());};
605  size_t State_Get() {MEDIAINFO_TEST_INT; return MediaInfoList_State_Get(Handle);};
606  size_t Count_Get(size_t FilePos, stream_t StreamKind, size_t StreamNumber = (size_t) - 1) {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get(Handle, FilePos, (MediaInfo_stream_C)StreamKind, StreamNumber);};
607  size_t Count_Get() {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get_Files(Handle);};
608 
609  bool IsReady() {return (Handle && MediaInfo_Module) ? true : false;}
610 
611  private :
612  void* Handle;
613  };
614 
615 } //NameSpace
616 #endif /*__cplusplus*/
617 
618 #endif