MediaInfoDLL.h

00001 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
00002  *
00003  *  Use of this source code is governed by a BSD-style license that can
00004  *  be found in the License.html file in the root of the source tree.
00005  */
00006 
00007 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00008 //
00009 // Public DLL interface implementation
00010 // Wrapper for MediaInfo Library
00011 // See MediaInfo.h for help
00012 //
00013 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
00014 
00015 #ifndef MediaInfoDLLH
00016 #define MediaInfoDLLH
00017 
00018 //***************************************************************************
00019 // Platforms (from libzen)
00020 //***************************************************************************
00021 
00022 /*---------------------------------------------------------------------------*/
00023 /*Win32*/
00024 #if defined(__NT__) || defined(_WIN32) || defined(WIN32)
00025     #ifndef WIN32
00026         #define WIN32
00027     #endif
00028     #ifndef _WIN32
00029         #define _WIN32
00030     #endif
00031     #ifndef __WIN32__
00032         #define __WIN32__ 1
00033     #endif
00034 #endif
00035 
00036 /*---------------------------------------------------------------------------*/
00037 /*Win64*/
00038 #if defined(_WIN64) || defined(WIN64)
00039     #ifndef WIN64
00040         #define WIN64
00041     #endif
00042     #ifndef _WIN64
00043         #define _WIN64
00044     #endif
00045     #ifndef __WIN64__
00046         #define __WIN64__ 1
00047     #endif
00048 #endif
00049 
00050 /*---------------------------------------------------------------------------*/
00051 /*Windows*/
00052 #if defined(WIN32) || defined(WIN64)
00053     #ifndef WINDOWS
00054         #define WINDOWS
00055     #endif
00056     #ifndef _WINDOWS
00057         #define _WINDOWS
00058     #endif
00059     #ifndef __WINDOWS__
00060         #define __WINDOWS__ 1
00061     #endif
00062 #endif
00063 
00064 /*---------------------------------------------------------------------------*/
00065 /*Unix (Linux, HP, Sun, BeOS...)*/
00066 #if defined(UNIX) || defined(_UNIX) || defined(__UNIX__)                    \
00067     || defined(__unix) || defined(__unix__)                                 \
00068     || defined(____SVR4____) || defined(__LINUX__) || defined(__sgi)        \
00069     || defined(__hpux) || defined(sun) || defined(__SUN__) || defined(_AIX) \
00070     || defined(__EMX__) || defined(__VMS) || defined(__BEOS__)
00071     #ifndef UNIX
00072         #define UNIX
00073     #endif
00074     #ifndef _UNIX
00075         #define _UNIX
00076     #endif
00077     #ifndef __UNIX__
00078         #define __UNIX__ 1
00079     #endif
00080 #endif
00081 
00082 /*---------------------------------------------------------------------------*/
00083 /*MacOS Classic*/
00084 #if defined(macintosh)
00085     #ifndef MACOS
00086         #define MACOS
00087     #endif
00088     #ifndef _MACOS
00089         #define _MACOS
00090     #endif
00091     #ifndef __MACOS__
00092         #define __MACOS__ 1
00093     #endif
00094 #endif
00095 
00096 /*---------------------------------------------------------------------------*/
00097 /*MacOS X*/
00098 #if defined(__APPLE__) && defined(__MACH__)
00099     #ifndef MACOSX
00100         #define MACOSX
00101     #endif
00102     #ifndef _MACOSX
00103         #define _MACOSX
00104     #endif
00105     #ifndef __MACOSX__
00106         #define __MACOSX__ 1
00107     #endif
00108 #endif
00109 
00110 /*Test of targets*/
00111 #if defined(WINDOWS) && defined(UNIX) && defined(MACOS) && defined(MACOSX)
00112     #pragma message Multiple platforms???
00113 #endif
00114 
00115 #if !defined(WIN32) && !defined(UNIX) && !defined(MACOS) && !defined(MACOSX)
00116     #pragma message No known platforms, assume default
00117 #endif
00118 
00119 /*-------------------------------------------------------------------------*/
00120 #if defined(_WIN32) || defined(WIN32)
00121     #ifdef _UNICODE
00122         #define MEDIAINFODLL_NAME L"MediaInfo.dll"
00123     #else //_UNICODE
00124         #define MEDIAINFODLL_NAME "MediaInfo.dll"
00125     #endif //_UNICODE
00126 #elif defined(__APPLE__) && defined(__MACH__)
00127     #define MEDIAINFODLL_NAME "libmediainfo.0.dylib"
00128     #define __stdcall
00129     #ifdef __cplusplus
00130         #include <new> //for size_t
00131     #else /* __cplusplus */
00132         #include <stddef.h> //for size_t
00133     #endif /* __cplusplus */
00134 #else
00135     #define MEDIAINFODLL_NAME "libmediainfo.so.0"
00136     #define __stdcall
00137 #endif 
00138 
00139 /*-------------------------------------------------------------------------*/
00140 /*Char types                                                               */
00141 #undef  __T
00142 #define __T(__x)    __T(__x)
00143 #if defined(UNICODE) || defined(_UNICODE)
00144     typedef wchar_t MediaInfo_Char;
00145     #undef  __T
00146     #define __T(__x) L ## __x
00147     #define MEDIAINFO_Ansi ""
00148 #else
00149     typedef char MediaInfo_Char;
00150     #undef  __T
00151     #define __T(__x) __x
00152     #define MEDIAINFO_Ansi "A"
00153 #endif
00154 /*-------------------------------------------------------------------------*/
00155 
00156 /*-------------------------------------------------------------------------*/
00157 /*8-bit int                                                                */
00158 typedef unsigned char MediaInfo_int8u;
00159 /*-------------------------------------------------------------------------*/
00160 
00161 /*-------------------------------------------------------------------------*/
00162 /*64-bit int                                                               */
00163 #if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(__UNIX__) || defined(__MACOSX__)
00164     #undef  MAXTYPE_INT
00165     #define MAXTYPE_INT 64
00166     typedef unsigned long long MediaInfo_int64u;
00167 #elif defined(__WIN32__) || defined(_WIN32)
00168     #undef  MAXTYPE_INT
00169     #define MAXTYPE_INT 64
00170     typedef unsigned __int64   MediaInfo_int64u;
00171 #else
00172     #pragma message This machine has no 64-bit integer type?
00173 #endif
00174 /*-------------------------------------------------------------------------*/
00175 
00176 /*-------------------------------------------------------------------------*/
00177 /*NULL                                                                     */
00178 #ifndef NULL
00179     #define NULL 0
00180 #endif
00181 /*-------------------------------------------------------------------------*/
00182 
00184 typedef enum MediaInfo_stream_t {
00185     MediaInfo_Stream_General,
00186     MediaInfo_Stream_Video,
00187     MediaInfo_Stream_Audio,
00188     MediaInfo_Stream_Text,
00189     MediaInfo_Stream_Other,
00190     MediaInfo_Stream_Image,
00191     MediaInfo_Stream_Menu,
00192     MediaInfo_Stream_Max
00193 } MediaInfo_stream_C;
00194 
00196 typedef enum MediaInfo_info_t {
00197     MediaInfo_Info_Name,
00198     MediaInfo_Info_Text,
00199     MediaInfo_Info_Measure,
00200     MediaInfo_Info_Options,
00201     MediaInfo_Info_Name_Text,
00202     MediaInfo_Info_Measure_Text,
00203     MediaInfo_Info_Info,
00204     MediaInfo_Info_HowTo,
00205     MediaInfo_Info_Max
00206 } MediaInfo_info_C;
00207 
00209 typedef enum MediaInfo_infooptions_t {
00210     MediaInfo_InfoOption_ShowInInform,
00211     MediaInfo_InfoOption_Reserved,
00212     MediaInfo_InfoOption_ShowInSupported,
00213     MediaInfo_InfoOption_TypeOfValue,
00214     MediaInfo_InfoOption_Max
00215 } MediaInfo_infooptions_C;
00216 
00218 typedef enum MediaInfo_fileoptions_t {
00219     MediaInfo_FileOption_Nothing     = 0x00,
00220     MediaInfo_FileOption_NoRecursive = 0x01,
00221     MediaInfo_FileOption_CloseAll    = 0x02,
00222     MediaInfo_FileOption_Max         = 0x04
00223 } MediaInfo_fileoptions_C;
00224 
00225 
00226 #ifdef __cplusplus
00227 extern "C"
00228 {
00229 #endif /* __cplusplus */
00230 
00231 #ifdef MEDIAINFO_GLIBC
00232     #include <gmodule.h>
00233     static GModule* MediaInfo_Module = NULL;
00234 #elif defined(_WIN32) || defined(WIN32)
00235     #include <windows.h>
00236     static HMODULE MediaInfo_Module = NULL;
00237 #else
00238     #ifdef MACOSX
00239         #include <CoreFoundation/CFBundle.h>
00240     #endif
00241 
00242     #include <dlfcn.h>
00243     static void* MediaInfo_Module = NULL;
00244 #endif
00245     static size_t Module_Count = 0;
00246 
00247 #ifdef MEDIAINFO_GLIBC
00248 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00249     if (!g_module_symbol (MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2, (gpointer*)&MediaInfo_##_Name)) \
00250         Errors++;
00251 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
00252     if (!g_module_symbol (MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2, (gpointer*)&MediaInfoList_##_Name)) \
00253         Errors++;
00254 #elif defined(_WIN32) || defined(WIN32)
00255 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00256     MediaInfo_##_Name=(MEDIAINFO_##_Name)GetProcAddress(MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2); \
00257     if (MediaInfo_##_Name==NULL) Errors++;
00258 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
00259     MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)GetProcAddress(MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2); \
00260     if (MediaInfoList_##_Name==NULL) Errors++;
00261 #else
00262 #define MEDIAINFO_ASSIGN(_Name,_Name2) \
00263     MediaInfo_##_Name=(MEDIAINFO_##_Name)dlsym(MediaInfo_Module, "MediaInfo" MEDIAINFO_Ansi "_" _Name2); \
00264     if (MediaInfo_##_Name==NULL) Errors++;
00265 #define MEDIAINFOLIST_ASSIGN(_Name,_Name2) \
00266     MediaInfoList_##_Name=(MEDIAINFOLIST_##_Name)dlsym(MediaInfo_Module, "MediaInfoList" MEDIAINFO_Ansi "_" _Name2); \
00267     if (MediaInfoList_##_Name==NULL) Errors++;
00268 #endif
00269 
00270     typedef void* (__stdcall *MEDIAINFO_New)();
00271     static MEDIAINFO_New MediaInfo_New;
00272     typedef void* (__stdcall *MEDIAINFOLIST_New)();
00273     static MEDIAINFOLIST_New MediaInfoList_New;
00274     typedef void (__stdcall *MEDIAINFO_Delete)(void*);
00275     static MEDIAINFO_Delete MediaInfo_Delete;
00276     typedef void (__stdcall *MEDIAINFOLIST_Delete)(void*);
00277     static MEDIAINFOLIST_Delete MediaInfoList_Delete;
00278     typedef size_t (__stdcall *MEDIAINFO_Open)(void*, const MediaInfo_Char*);
00279     static MEDIAINFO_Open MediaInfo_Open;
00280     typedef size_t (__stdcall *MEDIAINFOLIST_Open)(void*, const MediaInfo_Char*, const MediaInfo_fileoptions_C);
00281     static MEDIAINFOLIST_Open MediaInfoList_Open;
00282     typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Init)(void*, MediaInfo_int64u File_Size, MediaInfo_int64u File_Offset);
00283     static MEDIAINFO_Open_Buffer_Init MediaInfo_Open_Buffer_Init;
00284     typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Continue)(void*, MediaInfo_int8u* Buffer, size_t Buffer_Size);
00285     static MEDIAINFO_Open_Buffer_Continue MediaInfo_Open_Buffer_Continue;
00286     typedef MediaInfo_int64u(__stdcall *MEDIAINFO_Open_Buffer_Continue_GoTo_Get)(void*);
00287     static MEDIAINFO_Open_Buffer_Continue_GoTo_Get MediaInfo_Open_Buffer_Continue_GoTo_Get;
00288     typedef size_t (__stdcall *MEDIAINFO_Open_Buffer_Finalize)(void*);
00289     static MEDIAINFO_Open_Buffer_Finalize MediaInfo_Open_Buffer_Finalize;
00290     typedef size_t (__stdcall *MEDIAINFO_Open_NextPacket)(void*);
00291     static MEDIAINFO_Open_NextPacket MediaInfo_Open_NextPacket;
00292     typedef void (__stdcall *MEDIAINFO_Close)(void*);
00293     static MEDIAINFO_Close MediaInfo_Close;
00294     typedef void (__stdcall *MEDIAINFOLIST_Close)(void*, size_t);
00295     static MEDIAINFOLIST_Close MediaInfoList_Close;
00296     typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Inform)(void*, size_t Reserved);
00297     static MEDIAINFO_Inform MediaInfo_Inform;
00298     typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Inform)(void*, size_t, size_t Reserved);
00299     static MEDIAINFOLIST_Inform MediaInfoList_Inform;
00300     typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_GetI)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
00301     static MEDIAINFO_GetI MediaInfo_GetI;
00302     typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_GetI)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
00303     static MEDIAINFOLIST_GetI MediaInfoList_GetI;
00304     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);
00305     static MEDIAINFO_Get MediaInfo_Get;
00306     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);
00307     static MEDIAINFOLIST_Get MediaInfoList_Get;
00308     typedef size_t (__stdcall *MEDIAINFO_Output_Buffer_Get)(void*, const MediaInfo_Char* Parameter);
00309     static MEDIAINFO_Output_Buffer_Get MediaInfo_Output_Buffer_Get;
00310     typedef size_t (__stdcall *MEDIAINFO_Output_Buffer_GetI)(void*, size_t Pos);
00311     static MEDIAINFO_Output_Buffer_GetI MediaInfo_Output_Buffer_GetI;
00312     typedef const MediaInfo_Char* (__stdcall *MEDIAINFO_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value);
00313     static MEDIAINFO_Option MediaInfo_Option;
00314     typedef const MediaInfo_Char* (__stdcall *MEDIAINFOLIST_Option)(void*, const MediaInfo_Char* Parameter, const MediaInfo_Char* Value);
00315     static MEDIAINFOLIST_Option MediaInfoList_Option;
00316     typedef size_t (__stdcall *MEDIAINFO_State_Get)(void*);
00317     static MEDIAINFO_State_Get MediaInfo_State_Get;
00318     typedef size_t (__stdcall *MEDIAINFOLIST_State_Get)(void*);
00319     static MEDIAINFOLIST_State_Get MediaInfoList_State_Get;
00320     typedef size_t (__stdcall *MEDIAINFO_Count_Get)(void*, MediaInfo_stream_C StreamKind, size_t StreamNumber);
00321     static MEDIAINFO_Count_Get MediaInfo_Count_Get;
00322     typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get)(void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber);
00323     static MEDIAINFOLIST_Count_Get MediaInfoList_Count_Get;
00324     typedef size_t (__stdcall *MEDIAINFO_Count_Get_Files)(void*);
00325     static MEDIAINFO_Count_Get_Files MediaInfo_Count_Get_Files;
00326     typedef size_t (__stdcall *MEDIAINFOLIST_Count_Get_Files)(void*);
00327     static MEDIAINFOLIST_Count_Get_Files MediaInfoList_Count_Get_Files;
00328 
00329     static size_t MediaInfoDLL_Load()
00330     {
00331         size_t Errors = 0;
00332 
00333         if (Module_Count > 0) {
00334             Module_Count++;
00335             return 1;
00336         }
00337 
00338     /* Load library */
00339     #ifdef MEDIAINFO_GLIBC
00340         MediaInfo_Module = g_module_open(MEDIAINFODLL_NAME, G_MODULE_BIND_LAZY);
00341     #elif defined(_WIN32) || defined(WIN32)
00342         MediaInfo_Module = LoadLibrary(MEDIAINFODLL_NAME);
00343     #else
00344         #ifdef MACOSX
00345             MediaInfo_Module = dlopen("@executable_path/" MEDIAINFODLL_NAME, RTLD_LAZY);
00346             if (!MediaInfo_Module)
00347             {
00348                 CFBundleRef mainBundle = CFBundleGetMainBundle();
00349 
00350                 // get full app path and delete app name
00351                 CFURLRef app_url = CFBundleCopyExecutableURL(mainBundle);
00352                 CFURLRef app_path_url = CFURLCreateCopyDeletingLastPathComponent(NULL, app_url);
00353 
00354                 CFStringRef app_path = CFURLCopyFileSystemPath(app_path_url, kCFURLPOSIXPathStyle);
00355 
00356                 CFMutableStringRef mut_app_path = CFStringCreateMutableCopy(NULL, NULL, app_path);
00357                 CFStringAppend(mut_app_path, CFSTR("/"));
00358                 CFStringAppend(mut_app_path, CFSTR(MEDIAINFODLL_NAME));
00359                 CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
00360                 const char *fullPath = CFStringGetCStringPtr(mut_app_path, encodingMethod);
00361 
00362                 MediaInfo_Module = dlopen(fullPath, RTLD_LAZY);
00363 
00364                 CFRelease(app_url);
00365                 CFRelease(app_path_url);
00366                 CFRelease(app_path);
00367                 CFRelease(mut_app_path);
00368             }
00369         #endif /* MACOSX*/
00370 
00371         if (!MediaInfo_Module)
00372             MediaInfo_Module = dlopen(MEDIAINFODLL_NAME, RTLD_LAZY);
00373         if (!MediaInfo_Module)
00374             MediaInfo_Module = dlopen("./" MEDIAINFODLL_NAME, RTLD_LAZY);
00375         if (!MediaInfo_Module)
00376             MediaInfo_Module = dlopen("/usr/local/lib/" MEDIAINFODLL_NAME, RTLD_LAZY);
00377         if (!MediaInfo_Module)
00378             MediaInfo_Module = dlopen("/usr/local/lib64/" MEDIAINFODLL_NAME, RTLD_LAZY);
00379         if (!MediaInfo_Module)
00380             MediaInfo_Module = dlopen("/usr/lib/" MEDIAINFODLL_NAME, RTLD_LAZY);
00381         if (!MediaInfo_Module)
00382             MediaInfo_Module = dlopen("/usr/lib64/" MEDIAINFODLL_NAME, RTLD_LAZY);
00383     #endif
00384         if (!MediaInfo_Module)
00385             return (size_t) - 1;
00386 
00387         /* Load methods */
00388         MEDIAINFO_ASSIGN(New, "New")
00389         MEDIAINFOLIST_ASSIGN(New, "New")
00390         MEDIAINFO_ASSIGN(Delete, "Delete")
00391         MEDIAINFOLIST_ASSIGN(Delete, "Delete")
00392         MEDIAINFO_ASSIGN(Open, "Open")
00393         MEDIAINFOLIST_ASSIGN(Open, "Open")
00394         MEDIAINFO_ASSIGN(Open_Buffer_Init, "Open_Buffer_Init")
00395         MEDIAINFO_ASSIGN(Open_Buffer_Continue, "Open_Buffer_Continue")
00396         MEDIAINFO_ASSIGN(Open_Buffer_Continue_GoTo_Get, "Open_Buffer_Continue_GoTo_Get")
00397         MEDIAINFO_ASSIGN(Open_Buffer_Finalize, "Open_Buffer_Finalize")
00398         MEDIAINFO_ASSIGN(Open_NextPacket, "Open_NextPacket")
00399         MEDIAINFO_ASSIGN(Close, "Close")
00400         MEDIAINFOLIST_ASSIGN(Close, "Close")
00401         MEDIAINFO_ASSIGN(Inform, "Inform")
00402         MEDIAINFOLIST_ASSIGN(Inform, "Inform")
00403         MEDIAINFO_ASSIGN(GetI, "GetI")
00404         MEDIAINFOLIST_ASSIGN(GetI, "GetI")
00405         MEDIAINFO_ASSIGN(Get, "Get")
00406         MEDIAINFOLIST_ASSIGN(Get, "Get")
00407         MEDIAINFO_ASSIGN(Output_Buffer_Get, "Output_Buffer_Get")
00408         MEDIAINFO_ASSIGN(Output_Buffer_GetI, "Output_Buffer_GetI")
00409         MEDIAINFO_ASSIGN(Option, "Option")
00410         MEDIAINFOLIST_ASSIGN(Option, "Option")
00411         MEDIAINFO_ASSIGN(State_Get, "State_Get")
00412         MEDIAINFOLIST_ASSIGN(State_Get, "State_Get")
00413         MEDIAINFO_ASSIGN(Count_Get, "Count_Get")
00414         MEDIAINFOLIST_ASSIGN(Count_Get, "Count_Get")
00415         MEDIAINFOLIST_ASSIGN(Count_Get_Files, "Count_Get_Files")
00416         if (Errors > 0) {
00417         // Unload DLL with errors
00418         #ifdef MEDIAINFO_GLIBC
00419             g_module_close(MediaInfo_Module);
00420         #elif defined(_WIN32) || defined(WIN32)
00421             FreeLibrary(MediaInfo_Module);
00422         #else
00423             dlclose(MediaInfo_Module);
00424        #endif
00425             MediaInfo_Module = NULL;
00426             return (size_t) - 1;
00427         }
00428 
00429         Module_Count++;
00430         return (size_t)1;
00431     }
00432 
00433     static size_t MediaInfoDLL_IsLoaded()
00434     {
00435         if (MediaInfo_Module)
00436             return 1;
00437         else
00438             return 0;
00439     }
00440 
00441     static void MediaInfoDLL_UnLoad()
00442     {
00443         Module_Count--;
00444         if (Module_Count > 0)
00445             return;
00446 
00447     #ifdef MEDIAINFO_GLIBC
00448         g_module_close(MediaInfo_Module);
00449     #elif defined(_WIN32) || defined(WIN32)
00450         FreeLibrary(MediaInfo_Module);
00451     #else
00452         dlclose(MediaInfo_Module);
00453     #endif
00454         MediaInfo_Module = NULL;
00455     }
00456 
00457 #ifdef __cplusplus
00458 }
00459 #endif /*__cplusplus*/
00460 
00461 /***************************************************************************/
00462 /***************************************************************************/
00463 /***************************************************************************/
00464 
00465 #ifdef __cplusplus
00466 //DLL C++ wrapper for C functions
00467 
00468 //---------------------------------------------------------------------------
00469 #include <string>
00470 #include <sstream>
00471 //---------------------------------------------------------------------------
00472 
00473 namespace MediaInfoDLL
00474 {
00475 
00476     //---------------------------------------------------------------------------
00477     //MediaInfo_Char types
00478 #undef  __T
00479 #define __T(__x)    __T(__x)
00480 #if defined(UNICODE) || defined(_UNICODE)
00481     typedef wchar_t Char;
00482     #undef  __T
00483     #define __T(__x) L ## __x
00484 #else
00485     typedef char Char;
00486     #undef  __T
00487     #define __T(__x) __x
00488 #endif
00489     typedef std::basic_string<Char>        String;
00490     typedef std::basic_stringstream<Char>  StringStream;
00491     typedef std::basic_istringstream<Char> iStringStream;
00492     typedef std::basic_ostringstream<Char> oStringStream;
00493     typedef std::basic_istringstream<Char> tiStringStream; // Legacy
00494     typedef std::basic_ostringstream<Char> toStringStream; //Legacy
00495     const size_t Error = (size_t)(-1);
00496     //---------------------------------------------------------------------------
00497 
00498     //---------------------------------------------------------------------------
00500     enum stream_t {
00501         Stream_General,                 
00502         Stream_Video,                   
00503         Stream_Audio,                   
00504         Stream_Text,                    
00505         Stream_Other,                   
00506         Stream_Image,                   
00507         Stream_Menu,                    
00508         Stream_Max
00509     };
00510 
00512     enum info_t {
00513         Info_Name,                      
00514         Info_Text,                      
00515         Info_Measure,                   
00516         Info_Options,                   
00517         Info_Name_Text,                 
00518         Info_Measure_Text,              
00519         Info_Info,                      
00520         Info_HowTo,                     
00521         Info_Max
00522     };
00523 
00528     enum infooptions_t {
00529         InfoOption_ShowInInform,        
00530         InfoOption_Reserved,            
00531         InfoOption_ShowInSupported,     
00532         InfoOption_TypeOfValue,         
00533         InfoOption_Max
00534     };
00535 
00537     enum fileoptions_t {
00538         FileOption_Nothing      = 0x00,
00539         FileOption_NoRecursive  = 0x01, 
00540         FileOption_CloseAll     = 0x02, 
00541         FileOption_Max          = 0x04
00542     };
00543 
00544     const String Unable_Load_DLL = __T("Unable to load ")MEDIAINFODLL_NAME;
00545 #define MEDIAINFO_TEST_VOID \
00546     if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return;}
00547 #define MEDIAINFO_TEST_INT \
00548     if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return 0;}
00549 #define MEDIAINFO_TEST_STRING \
00550     if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return Unable_Load_DLL;}
00551 #define MEDIAINFO_TEST_STRING_STATIC \
00552     if (!MediaInfo_Module) {MediaInfoDLL_Load(); if (!MediaInfo_Module) return Unable_Load_DLL;}
00553 
00554     //---------------------------------------------------------------------------
00555     class MediaInfo
00556     {
00557     public :
00558         MediaInfo()        {if (!MediaInfo_Module) MediaInfoDLL_Load(); if (!MediaInfo_Module) {Handle = NULL; return;}; Handle = MediaInfo_New();};
00559         ~MediaInfo()       {MEDIAINFO_TEST_VOID; MediaInfo_Delete(Handle);};
00560 
00561         //File
00562         size_t Open(const String &File) {MEDIAINFO_TEST_INT; return MediaInfo_Open(Handle, File.c_str());};
00563         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);};
00564         size_t Open_Buffer_Continue(MediaInfo_int8u* Buffer, size_t Buffer_Size) {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Continue(Handle, Buffer, Buffer_Size);};
00565         MediaInfo_int64u Open_Buffer_Continue_GoTo_Get() {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Continue_GoTo_Get(Handle);};
00566         size_t Open_Buffer_Finalize() {MEDIAINFO_TEST_INT; return MediaInfo_Open_Buffer_Finalize(Handle);};
00567         size_t Open_NextPacket() {MEDIAINFO_TEST_INT; return MediaInfo_Open_NextPacket(Handle);};
00568         //size_t Save () {MEDIAINFO_TEST_INT; return MediaInfo_Save(Handle);};
00569         void Close() {MEDIAINFO_TEST_VOID; return MediaInfo_Close(Handle);};
00570 
00571         //General information
00572         String Inform()  {MEDIAINFO_TEST_STRING; return MediaInfo_Inform(Handle, 0);};
00573         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);};
00574         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);};
00575         //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());};
00576         //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());};
00577         size_t Output_Buffer_Get(const String &Value) {return MediaInfo_Output_Buffer_Get(Handle, Value.c_str());}
00578         size_t Output_Buffer_Get(size_t Pos) {return MediaInfo_Output_Buffer_GetI(Handle, Pos);}
00579         String        Option(const String &Option, const String &Value = __T(""))  {MEDIAINFO_TEST_STRING; return MediaInfo_Option(Handle, Option.c_str(), Value.c_str());};
00580         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());};
00581         size_t        State_Get() {MEDIAINFO_TEST_INT; return MediaInfo_State_Get(Handle);};
00582         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);};
00583 
00584         bool IsReady() {return (Handle && MediaInfo_Module) ? true : false;}
00585 
00586     private :
00587         void* Handle;
00588     };
00589 
00590     class MediaInfoList
00591     {
00592     public :
00593         MediaInfoList()        {MediaInfoDLL_Load(); if (!MediaInfoDLL_IsLoaded()) {Handle = NULL; return;}; Handle = MediaInfoList_New();};
00594         ~MediaInfoList()       {MEDIAINFO_TEST_VOID; MediaInfoList_Delete(Handle); MediaInfoDLL_UnLoad();};
00595 
00596         //File
00597         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);};
00598         //size_t Save (size_t FilePos) {MEDIAINFO_TEST_INT; return MediaInfoList_Save(Handle, FilePos);};
00599         void Close(size_t FilePos = (size_t) - 1) {MEDIAINFO_TEST_VOID; return MediaInfoList_Close(Handle, FilePos);};
00600 
00601         //General information
00602         String Inform(size_t FilePos = (size_t) - 1)  {MEDIAINFO_TEST_STRING; return MediaInfoList_Inform(Handle, FilePos, 0);};
00603         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);};
00604         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);};
00605         //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());};
00606         //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());};
00607         String        Option(const String &Option, const String &Value = __T(""))  {MEDIAINFO_TEST_STRING; return MediaInfoList_Option(Handle, Option.c_str(), Value.c_str());};
00608         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());};
00609         size_t        State_Get()  {MEDIAINFO_TEST_INT; return MediaInfoList_State_Get(Handle);};
00610         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);};
00611         size_t        Count_Get()  {MEDIAINFO_TEST_INT; return MediaInfoList_Count_Get_Files(Handle);};
00612 
00613         bool IsReady() {return (Handle && MediaInfo_Module) ? true : false;}
00614 
00615     private :
00616         void* Handle;
00617     };
00618 
00619 } //NameSpace
00620 #endif /*__cplusplus*/
00621 
00622 #endif

Generated on Thu Apr 9 06:03:58 2015 for MediaInfoLib by  doxygen 1.4.7