MediaInfoLib: MediaInfoDLL.h Source File

MediaInfoLib 0.7

- Main Page
- Namespaces
- Classes
- Files

- File List

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