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  #ifndef MEDIAINFODLL_NAME
123  #define MEDIAINFODLL_NAME L"MediaInfo.dll"
124  #endif //MEDIAINFODLL_NAME
125  #else //_UNICODE
126  #ifndef MEDIAINFODLL_NAME
127  #define MEDIAINFODLL_NAME "MediaInfo.dll"
128  #endif //MEDIAINFODLL_NAME
129  #endif //_UNICODE
130 #elif defined(__APPLE__) && defined(__MACH__)
131  #ifndef MEDIAINFODLL_NAME
132  #define MEDIAINFODLL_NAME "libmediainfo.0.dylib"
133  #endif //MEDIAINFODLL_NAME
134  #define __stdcall
135  #ifdef __cplusplus
136  #include <new> //for size_t
137  #else /* __cplusplus */
138  #include <stddef.h> //for size_t
139  #endif /* __cplusplus */
140 #else
141  #ifndef MEDIAINFODLL_NAME
142  #ifdef __ANDROID__
143  #define MEDIAINFODLL_NAME "libmediainfo.so" /* Android libraries have no versioned name */
144  #else //__ANDROID__
145  #define MEDIAINFODLL_NAME "libmediainfo.so.0"
146  #endif //__ANDROID__
147  #endif //MEDIAINFODLL_NAME
148  #define __stdcall
149 #endif
150 
151 /*-------------------------------------------------------------------------*/
152 /*Char types */
153 #undef __T
154 #define __T(__x) __T(__x)
155 #if defined(UNICODE) || defined(_UNICODE)
156  typedef wchar_t MediaInfo_Char;
157  #undef __T
158  #define __T(__x) L ## __x
159  #define MEDIAINFO_Ansi ""
160 #else
161  typedef char MediaInfo_Char;
162  #undef __T
163  #define __T(__x) __x
164  #define MEDIAINFO_Ansi "A"
165 #endif
166 /*-------------------------------------------------------------------------*/
167 
168 /*-------------------------------------------------------------------------*/
169 /*8-bit int */
170 typedef unsigned char MediaInfo_int8u;
171 /*-------------------------------------------------------------------------*/
172 
173 /*-------------------------------------------------------------------------*/
174 /*64-bit int */
175 #if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(__UNIX__) || defined(__MACOSX__)
176  #undef MAXTYPE_INT
177  #define MAXTYPE_INT 64
178  typedef unsigned long long MediaInfo_int64u;
179 #elif defined(__WIN32__) || defined(_WIN32)
180  #undef MAXTYPE_INT
181  #define MAXTYPE_INT 64
182  typedef unsigned __int64 MediaInfo_int64u;
183 #else
184  #pragma message This machine has no 64-bit integer type?
185 #endif
186 /*-------------------------------------------------------------------------*/
187 
188 /*-------------------------------------------------------------------------*/
189 /*NULL */
190 #ifndef NULL
191  #define NULL 0
192 #endif
193 /*-------------------------------------------------------------------------*/
194 
196 typedef enum MediaInfo_stream_t {
197  MediaInfo_Stream_General,
198  MediaInfo_Stream_Video,
199  MediaInfo_Stream_Audio,
200  MediaInfo_Stream_Text,
201  MediaInfo_Stream_Other,
202  MediaInfo_Stream_Image,
203  MediaInfo_Stream_Menu,
204  MediaInfo_Stream_Max
205 } MediaInfo_stream_C;
206 
208 typedef enum MediaInfo_info_t {
209  MediaInfo_Info_Name,
210  MediaInfo_Info_Text,
211  MediaInfo_Info_Measure,
212  MediaInfo_Info_Options,
213  MediaInfo_Info_Name_Text,
214  MediaInfo_Info_Measure_Text,
215  MediaInfo_Info_Info,
216  MediaInfo_Info_HowTo,
217  MediaInfo_Info_Max
218 } MediaInfo_info_C;
219 
221 typedef enum MediaInfo_infooptions_t {
222  MediaInfo_InfoOption_ShowInInform,
223  MediaInfo_InfoOption_Reserved,
224  MediaInfo_InfoOption_ShowInSupported,
225  MediaInfo_InfoOption_TypeOfValue,
226  MediaInfo_InfoOption_Max
227 } MediaInfo_infooptions_C;
228 
230 typedef enum MediaInfo_fileoptions_t {
231  MediaInfo_FileOption_Nothing = 0x00,
232  MediaInfo_FileOption_NoRecursive = 0x01,
233  MediaInfo_FileOption_CloseAll = 0x02,
234  MediaInfo_FileOption_Max = 0x04
235 } MediaInfo_fileoptions_C;
236 
237 
238 #ifdef __cplusplus
239 extern "C"
240 {
241 #endif /* __cplusplus */
242 
243 #ifdef MEDIAINFO_GLIBC
244  #include <gmodule.h>
245  static GModule* MediaInfo_Module = NULL;
246 #elif defined(_WIN32) || defined(WIN32)
247  #include <windows.h>
248  static HMODULE MediaInfo_Module = NULL;
249 #else
250  #ifdef MACOSX
251  #include <CoreFoundation/CFBundle.h>
252  #endif
253 
254  #include <dlfcn.h>
255  static void* MediaInfo_Module = NULL;
256 #endif
257  static size_t Module_Count = 0;
258 
259 #ifdef MEDIAINFO_GLIBC
260 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
261  if (!g_module_symbol (MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2, (gpointer*)&MediaInfo_##_Name)) \
262  Errors++;
263 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
264  if (!g_module_symbol (MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2, (gpointer*)&MediaInfoList_##_Name)) \
265  Errors++;
266 #elif defined(_WIN32) || defined(WIN32)
267 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
268  MediaInfo_##_Name=(MEDIAINFO_##_Name)GetProcAddress(MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2); \
269  if (MediaInfo_##_Name==NULL) Errors++;
270 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
271  MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)GetProcAddress(MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2); \
272  if (MediaInfoList_##_Name==NULL) Errors++;
273 #else
274 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
275  MediaInfo_##_Name=(MEDIAINFO_##_Name)dlsym(MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2); \
276  if (MediaInfo_##_Name==NULL) Errors++;
277 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
278  MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)dlsym(MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2); \
279  if (MediaInfoList_##_Name==NULL) Errors++;
280 #endif
281 
282  typedef void* (__stdcall *MEDIAINFO_New)();
283  static MEDIAINFO_New MediaInfo_New;
284  typedef void* (__stdcall *MEDIAINFOLIST_New)();
285  static MEDIAINFOLIST_New MediaInfoList_New;
286  typedef void (__stdcall *MEDIAINFO_Delete)(void*);
287  static MEDIAINFO_Delete MediaInfo_Delete;
288  typedef void (__stdcall *MEDIAINFOLIST_Delete)(void*);
289  static MEDIAINFOLIST_Delete MediaInfoList_Delete;
290  typedef size_t (__stdcall *MEDIAINFO_Open)(void*, const MediaInfo_Char*);
291  static MEDIAINFO_Open MediaInfo_Open;
292  typedef size_t (__stdcall *MEDIAINFOLIST_Open)(void*, const MediaInfo_Char*, const MediaInfo_fileoptions_C);
293  static MEDIAINFOLIST_Open MediaInfoList_Open;
294  typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Init)(void*, MediaInfo_int64u File_Size, MediaInfo_int64u File_Offset);
295  static MEDIAINFO_Open_Buffer_Init MediaInfo_Open_Buffer_Init;
296  typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Continue)(void*, MediaInfo_int8u* Buffer, size_t Buffer_Size);
297  static MEDIAINFO_Open_Buffer_Continue MediaInfo_Open_Buffer_Continue;
298  typedef MediaInfo_int64u(__stdcall *MEDIAINFO_Open_Buffer_Continue_GoTo_Get)(void*);
299  static MEDIAINFO_Open_Buffer_Continue_GoTo_Get MediaInfo_Open_Buffer_Continue_GoTo_Get;
300  typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Finalize)(void*);
301  static MEDIAINFO_Open_Buffer_Finalize MediaInfo_Open_Buffer_Finalize;
302  typedef size_t (__stdcall *MEDIAINFO_Open_NextPacket)(void*);
303  static MEDIAINFO_Open_NextPacket MediaInfo_Open_NextPacket;
304  typedef void (__stdcall *MEDIAINFO_Close)(void*);
305  static MEDIAINFO_Close MediaInfo_Close;
306  typedef void (__stdcall *MEDIAINFOLIST_Close)(void*, size_t);
307  static MEDIAINFOLIST_Close MediaInfoList_Close;
308  typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Inform)(void*, size_t Reserved);
309  static MEDIAINFO_Inform MediaInfo_Inform;
310  typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Inform)(void*, size_t, size_t Reserved);
311  static MEDIAINFOLIST_Inform MediaInfoList_Inform;
312  typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_GetI)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
313  static MEDIAINFO_GetI MediaInfo_GetI;
314  typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_GetI)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
315  static MEDIAINFOLIST_GetI MediaInfoList_GetI;
316  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);
317  static MEDIAINFO_Get MediaInfo_Get;
318  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);
319  static MEDIAINFOLIST_Get MediaInfoList_Get;
320  typedef size_t (__stdcall *MEDIAINFO_Output_Buffer_Get)(void*, const MediaInfo_Char* Parameter);
321  static MEDIAINFO_Output_Buffer_Get MediaInfo_Output_Buffer_Get;
322  typedef size_t (__stdcall *MEDIAINFO_Output_Buffer_GetI)(void*, size_t Pos);
323  static MEDIAINFO_Output_Buffer_GetI MediaInfo_Output_Buffer_GetI;
324  typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value);
325  static MEDIAINFO_Option MediaInfo_Option;
326  typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value);
327  static MEDIAINFOLIST_Option MediaInfoList_Option;
328  typedef size_t (__stdcall *MEDIAINFO_State_Get)(void*);
329  static MEDIAINFO_State_Get MediaInfo_State_Get;
330  typedef size_t (__stdcall *MEDIAINFOLIST_State_Get)(void*);
331  static MEDIAINFOLIST_State_Get MediaInfoList_State_Get;
332  typedef size_t (__stdcall *MEDIAINFO_Count_Get)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber);
333  static MEDIAINFO_Count_Get MediaInfo_Count_Get;
334  typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber);
335  static MEDIAINFOLIST_Count_Get MediaInfoList_Count_Get;
336  typedef size_t (__stdcall *MEDIAINFO_Count_Get_Files)(void*);
337  static MEDIAINFO_Count_Get_Files MediaInfo_Count_Get_Files;
338  typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get_Files)(void*);
339  static MEDIAINFOLIST_Count_Get_Files MediaInfoList_Count_Get_Files;
340 
341  static size_t MediaInfoDLL_Load()
342  {
343  size_t Errors = 0;
344 
345  if (Module_Count > 0) {
346  Module_Count++;
347  return 1;
348  }
349 
350  /* Load library */
351  #ifdef MEDIAINFO_GLIBC
352  MediaInfo_Module = g_module_open(MEDIAINFODLL_NAME, G_MODULE_BIND_LAZY);
353  #elif defined(_WIN32) || defined(WIN32)
354  MediaInfo_Module = LoadLibrary(MEDIAINFODLL_NAME);
355  #else
356  #ifdef MACOSX
357  MediaInfo_Module = dlopen("@executable_path/" MEDIAINFODLL_NAME, RTLD_LAZY);
358  if (!MediaInfo_Module)
359  {
360  CFBundleRef mainBundle = CFBundleGetMainBundle();
361 
362  // get full app path and delete app name
363  CFURLRef app_url = CFBundleCopyExecutableURL(mainBundle);
364  CFURLRef app_path_url = CFURLCreateCopyDeletingLastPathComponent(NULL, app_url);
365 
366  CFStringRef app_path = CFURLCopyFileSystemPath(app_path_url, kCFURLPOSIXPathStyle);
367 
368  CFMutableStringRef mut_app_path = CFStringCreateMutableCopy(NULL, NULL, app_path);
369  CFStringAppend(mut_app_path, CFSTR("/"));
370  CFStringAppend(mut_app_path, CFSTR(MEDIAINFODLL_NAME));
371  CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
372  const char *fullPath = CFStringGetCStringPtr(mut_app_path, encodingMethod);
373 
374  MediaInfo_Module = dlopen(fullPath, RTLD_LAZY);
375 
376  CFRelease(app_url);
377  CFRelease(app_path_url);
378  CFRelease(app_path);
379  CFRelease(mut_app_path);
380  }
381  #endif /* MACOSX*/
382 
383  if (!MediaInfo_Module)
384  MediaInfo_Module = dlopen(MEDIAINFODLL_NAME, RTLD_LAZY);
385  if (!MediaInfo_Module)
386  MediaInfo_Module = dlopen("./" MEDIAINFODLL_NAME, RTLD_LAZY);
387  if (!MediaInfo_Module)
388  MediaInfo_Module = dlopen("/usr/local/lib/" MEDIAINFODLL_NAME, RTLD_LAZY);
389  if (!MediaInfo_Module)
390  MediaInfo_Module = dlopen("/usr/local/lib64/" MEDIAINFODLL_NAME, RTLD_LAZY);
391  if (!MediaInfo_Module)
392  MediaInfo_Module = dlopen("/usr/lib/" MEDIAINFODLL_NAME, RTLD_LAZY);
393  if (!MediaInfo_Module)
394  MediaInfo_Module = dlopen("/usr/lib64/" MEDIAINFODLL_NAME, RTLD_LAZY);
395  #endif
396  if (!MediaInfo_Module)
397  return (size_t) - 1;
398 
399  /* Load methods */
400  MEDIAINFO_ASSIGN(New, "New")
401  MEDIAINFOLIST_ASSIGN(New, "New")
402  MEDIAINFO_ASSIGN(Delete, "Delete")
403  MEDIAINFOLIST_ASSIGN(Delete, "Delete")
404  MEDIAINFO_ASSIGN(Open, "Open")
405  MEDIAINFOLIST_ASSIGN(Open, "Open")
406  MEDIAINFO_ASSIGN(Open_Buffer_Init, "Open_Buffer_Init")
407  MEDIAINFO_ASSIGN(Open_Buffer_Continue, "Open_Buffer_Continue")
408  MEDIAINFO_ASSIGN(Open_Buffer_Continue_GoTo_Get, "Open_Buffer_Continue_GoTo_Get")
409  MEDIAINFO_ASSIGN(Open_Buffer_Finalize, "Open_Buffer_Finalize")
410  MEDIAINFO_ASSIGN(Open_NextPacket, "Open_NextPacket")
411  MEDIAINFO_ASSIGN(Close, "Close")
412  MEDIAINFOLIST_ASSIGN(Close, "Close")
413  MEDIAINFO_ASSIGN(Inform, "Inform")
414  MEDIAINFOLIST_ASSIGN(Inform, "Inform")
415  MEDIAINFO_ASSIGN(GetI, "GetI")
416  MEDIAINFOLIST_ASSIGN(GetI, "GetI")
417  MEDIAINFO_ASSIGN(Get, "Get")
418  MEDIAINFOLIST_ASSIGN(Get, "Get")
419  MEDIAINFO_ASSIGN(Output_Buffer_Get, "Output_Buffer_Get")
420  MEDIAINFO_ASSIGN(Output_Buffer_GetI, "Output_Buffer_GetI")
421  MEDIAINFO_ASSIGN(Option, "Option")
422  MEDIAINFOLIST_ASSIGN(Option, "Option")
423  MEDIAINFO_ASSIGN(State_Get, "State_Get")
424  MEDIAINFOLIST_ASSIGN(State_Get, "State_Get")
425  MEDIAINFO_ASSIGN(Count_Get, "Count_Get")
426  MEDIAINFOLIST_ASSIGN(Count_Get, "Count_Get")
427  MEDIAINFOLIST_ASSIGN(Count_Get_Files, "Count_Get_Files")
428  if (Errors > 0) {
429  // Unload DLL with errors
430  #ifdef MEDIAINFO_GLIBC
431  g_module_close(MediaInfo_Module);
432  #elif defined(_WIN32) || defined(WIN32)
433  FreeLibrary(MediaInfo_Module);
434  #else
435  dlclose(MediaInfo_Module);
436  #endif
437  MediaInfo_Module = NULL;
438  return (size_t) - 1;
439  }
440 
441  Module_Count++;
442  return (size_t)1;
443  }
444 
445  static size_t MediaInfoDLL_IsLoaded()
446  {
447  if (MediaInfo_Module)
448  return 1;
449  else
450  return 0;
451  }
452 
453  static void MediaInfoDLL_UnLoad()
454  {
455  Module_Count--;
456  if (Module_Count > 0)
457  return;
458 
459  #ifdef MEDIAINFO_GLIBC
460  g_module_close(MediaInfo_Module);
461  #elif defined(_WIN32) || defined(WIN32)
462  FreeLibrary(MediaInfo_Module);
463  #else
464  dlclose(MediaInfo_Module);
465  #endif
466  MediaInfo_Module = NULL;
467  }
468 
469 #ifdef __cplusplus
470 }
471 #endif /*__cplusplus*/
472 
473 /***************************************************************************/
474 /***************************************************************************/
475 /***************************************************************************/
476 
477 #ifdef __cplusplus
478 //DLL C++ wrapper for C functions
479 
480 //---------------------------------------------------------------------------
481 #include <string>
482 #include <sstream>
483 //---------------------------------------------------------------------------
484 
485 namespace MediaInfoDLL
486 {
487 
488  //---------------------------------------------------------------------------
489  //MediaInfo_Char types
490 #undef __T
491 #define __T(__x) __T(__x)
492 #if defined(UNICODE) || defined(_UNICODE)
493  typedef wchar_t Char;
494  #undef __T
495  #define __T(__x) L ## __x
496 #else
497  typedef char Char;
498  #undef __T
499  #define __T(__x) __x
500 #endif
501  typedef std::basic_string<Char> String;
502  typedef std::basic_stringstream<Char> StringStream;
503  typedef std::basic_istringstream<Char> iStringStream;
504  typedef std::basic_ostringstream<Char> oStringStream;
505  typedef std::basic_istringstream<Char> tiStringStream; // Legacy
506  typedef std::basic_ostringstream<Char> toStringStream; //Legacy
507  const size_t Error = (size_t)(-1);
508  //---------------------------------------------------------------------------
509 
510  //---------------------------------------------------------------------------
512  enum stream_t {
514  Stream_Video,
515  Stream_Audio,
516  Stream_Text,
517  Stream_Other,
518  Stream_Image,
519  Stream_Menu,
520  Stream_Max
521  };
522 
524  enum info_t {
525  Info_Name,
526  Info_Text,
527  Info_Measure,
528  Info_Options,
531  Info_Info,
532  Info_HowTo,
533  Info_Max
534  };
535 
540  enum infooptions_t {
542  InfoOption_Reserved,
545  InfoOption_Max
546  };
547 
549  enum fileoptions_t {
550  FileOption_Nothing = 0x00,
551  FileOption_NoRecursive = 0x01,
552  FileOption_CloseAll = 0x02,
553  FileOption_Max = 0x04
554  };
555 
556  const String Unable_Load_DLL = __T("Unable to load ")MEDIAINFODLL_NAME;
557 #define MEDIAINFO_TEST_VOID \
558  if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return;}
559 #define MEDIAINFO_TEST_INT \
560  if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return 0;}
561 #define MEDIAINFO_TEST_STRING \
562  if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return Unable_Load_DLL;}
563 #define MEDIAINFO_TEST_STRING_STATIC \
564  if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return Unable_Load_DLL;}
565 
566  //---------------------------------------------------------------------------
567  class MediaInfo
568  {
569  public :
570  MediaInfo() {if (!MediaInfo_Module) MediaInfoDLL_Load(); if (!MediaInfo_Module) {Handle = NULL; return;}; Handle = MediaInfo_New();};
571  ~MediaInfo() {MEDIAINFO_TEST_VOID; MediaInfo_Delete(Handle);};
572 
573  //File
574  size_t Open(const String &File) {MEDIAINFO_TEST_INT; return MediaInfo_Open(Handle, File.c_str());};
575  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);};
576  size_t Open_Buffer_Continue(MediaInfo_int8u* Buffer, size_t Buffer_Size) {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Continue(Handle, Buffer, Buffer_Size);};
577  MediaInfo_int64u Open_Buffer_Continue_GoTo_Get() {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Continue_GoTo_Get(Handle);};
578  size_t Open_Buffer_Finalize() {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Finalize(Handle);};
579  size_t Open_NextPacket() {MEDIAINFO_TEST_INT; return MediaInfo_Open_NextPacket(Handle);};
580  //size_t Save () {MEDIAINFO_TEST_INT; return MediaInfo_Save(Handle);};
581  void Close() {MEDIAINFO_TEST_VOID; return MediaInfo_Close(Handle);};
582 
583  //General information
584  String Inform() {MEDIAINFO_TEST_STRING; return MediaInfo_Inform(Handle, 0);};
585  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);};
586  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);};
587  //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());};
588  //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());};
589  size_t Output_Buffer_Get(const String &Value) {return MediaInfo_Output_Buffer_Get(Handle, Value.c_str());}
590  size_t Output_Buffer_Get(size_t Pos) {return MediaInfo_Output_Buffer_GetI(Handle, Pos);}
591  String Option(const String &Option, const String &Value = __T("")) {MEDIAINFO_TEST_STRING; return MediaInfo_Option(Handle, Option.c_str(), Value.c_str());};
592  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());};
593  size_t State_Get() {MEDIAINFO_TEST_INT; return MediaInfo_State_Get(Handle);};
594  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);};
595 
596  bool IsReady() {return (Handle!=nullptr && MediaInfo_Module!=nullptr);}
597 
598  private :
599  void* Handle;
600  };
601 
602  class MediaInfoList
603  {
604  public :
605  MediaInfoList() {MediaInfoDLL_Load(); if (!MediaInfoDLL_IsLoaded()) {Handle = NULL; return;}; Handle = MediaInfoList_New();};
606  ~MediaInfoList() {MEDIAINFO_TEST_VOID; MediaInfoList_Delete(Handle); MediaInfoDLL_UnLoad();};
607 
608  //File
609  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);};
610  //size_t Save (size_t FilePos) {MEDIAINFO_TEST_INT; return MediaInfoList_Save(Handle, FilePos);};
611  void Close(size_t FilePos = (size_t) - 1) {MEDIAINFO_TEST_VOID; return MediaInfoList_Close(Handle, FilePos);};
612 
613  //General information
614  String Inform(size_t FilePos = (size_t) - 1) {MEDIAINFO_TEST_STRING; return MediaInfoList_Inform(Handle, FilePos, 0);};
615  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);};
616  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);};
617  //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());};
618  //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());};
619  String Option(const String &Option, const String &Value = __T("")) {MEDIAINFO_TEST_STRING; return MediaInfoList_Option(Handle, Option.c_str(), Value.c_str());};
620  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());};
621  size_t State_Get() {MEDIAINFO_TEST_INT; return MediaInfoList_State_Get(Handle);};
622  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);};
623  size_t Count_Get() {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get_Files(Handle);};
624 
625  bool IsReady() {return (Handle && MediaInfo_Module) ? true : false;}
626 
627  private :
628  void* Handle;
629  };
630 
631 } //NameSpace
632 #endif /*__cplusplus*/
633 
634 #endif
std::basic_string< MediaInfoLib::Char > String
Unicode/Ansi independant string.
info_t
Kind of information.
@ Info_Text
InfoKind = Value of parameter.
@ Info_Measure_Text
InfoKind = Translated name of measure unit.
@ Info_Name
InfoKind = Unique name of parameter.
@ Info_Options
InfoKind = See infooptions_t.
@ Info_Name_Text
InfoKind = Translated name of parameter.
@ Info_Measure
InfoKind = Unique name of measure unit of parameter.
@ Info_Info
InfoKind = More information about the parameter.
@ Info_HowTo
InfoKind = How this parameter is supported, could be N (No), B (Beta), R (Read only),...
std::basic_istringstream< MediaInfoLib::Char > tiStringStream
Unicode/Ansi independant istringstream.
char Char
Unicode/Ansi independant char.
std::basic_stringstream< MediaInfoLib::Char > StringStream
Unicode/Ansi independant stringstream.
fileoptions_t
File opening options.
@ FileOption_CloseAll
Close all files before open.
@ FileOption_NoRecursive
Do not browse folders recursively.
std::basic_ostringstream< MediaInfoLib::Char > toStringStream
Unicode/Ansi independant ostringstream.
infooptions_t
Option if InfoKind = Info_Options.
@ InfoOption_TypeOfValue
Value return by a standard Get() can be : T (Text), I (Integer, warning up to 64 bits),...
@ InfoOption_ShowInInform
Show this parameter in Inform()
@ InfoOption_ShowInSupported
Internal use only (info : Must be showed in Info_Capacities() )
stream_t
Kinds of Stream.
@ Stream_Image
StreamKind = Image.
@ Stream_General
StreamKind = General.
@ Stream_Menu
StreamKind = Menu.
@ Stream_Text
StreamKind = Text.
@ Stream_Audio
StreamKind = Audio.
@ Stream_Other
StreamKind = Chapters.
@ Stream_Video
StreamKind = Video.