00001 // MediaInfo - All information about media files 00002 // Copyright (C) 2002-2007 Jerome Martinez, Zen@MediaArea.net 00003 // 00004 // This library is free software: you can redistribute it and/or modify it 00005 // under the terms of the GNU Lesser General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // any later version. 00008 // 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this library. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00018 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00019 // 00020 // Give information about a lot of media files 00021 // Dispatch the file to be tested by all containers 00022 // 00023 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00024 00025 //--------------------------------------------------------------------------- 00026 #ifndef MediaInfoH 00027 #define MediaInfoH 00028 //--------------------------------------------------------------------------- 00029 00030 //--------------------------------------------------------------------------- 00031 #include <string> 00032 #include <MediaInfo/MediaInfo_Config.h> 00033 #include <ZenLib/File.h> 00034 //--------------------------------------------------------------------------- 00035 00036 namespace MediaInfoLib 00037 { 00038 00039 class File__Base; 00040 class File__Analyze; 00041 class Internet__Base; 00042 class WxThread; 00043 00044 //*************************************************************************** 00045 /// @brief MediaInfo 00046 /// @version 0.7 00047 //*************************************************************************** 00048 00049 class MediaInfo 00050 { 00051 public : 00052 //Constructor/Destructor 00053 MediaInfo (); 00054 ~MediaInfo (); 00055 //File 00056 /// Open a file and collect information about it (technical information and tags) 00057 /// @brief Open a file 00058 /// @param File_Name Full name of file to open 00059 /// @retval 0 File not opened 00060 /// @retval 1 File opened 00061 size_t Open (const String &File_Name); 00062 /// Open a Buffer (Begin and end of the stream) and collect information about it (technical information and tags) 00063 /// @brief Open a buffer 00064 /// @param Begin First bytes of the buffer 00065 /// @param Begin_Size Size of Begin 00066 /// @param End Last bytes of the buffer 00067 /// @param End_Size Size of End 00068 /// @retval 0 File not opened 00069 /// @retval 1 File opened 00070 size_t Open (const int8u* Begin, size_t Begin_Size, const int8u* End=NULL, size_t End_Size=0, int64u FileSize=0); 00071 /// Open a stream and collect information about it (technical information and tags) 00072 /// @brief Open a stream (Init) 00073 /// @param File_Size Estimated file size 00074 /// @param File_Offset Offset of the file (if we don't have the beginning of the file) 00075 size_t Open_Buffer_Init (int64u File_Size=(int64u)-1, int64u File_Offset=0); 00076 /// Open a stream and collect information about it (technical information and tags) 00077 /// @brief Open a stream (Continue) 00078 /// @param Buffer pointer to the stream 00079 /// @param Buffer_Size Count of bytes to read 00080 size_t Open_Buffer_Continue (const int8u* Buffer, size_t Buffer_Size); 00081 /// Open a stream and collect information about it (technical information and tags) 00082 /// @brief Open a stream (Get the needed file Offset) 00083 /// @return the needed offset of the file \n 00084 /// File size if no more bytes are needed 00085 int64u Open_Buffer_Continue_GoTo_Get (); 00086 /// Open a stream and collect information about it (technical information and tags) 00087 /// @brief Open a stream (Finalize) 00088 size_t Open_Buffer_Finalize (); 00089 /// Save the file opened before with Open() (modifications of tags) 00090 /// @brief Save the file 00091 /// @retval 0 failed 00092 /// @retval 1 suceed 00093 size_t Save (); 00094 /// Close a file opened before with Open() (without saving) 00095 /// @brief Close a file 00096 /// @warning without have saved before, modifications are lost 00097 void Close (); 00098 00099 //General information 00100 /// Get all details about a file in one string 00101 /// @brief Get all details about a file 00102 /// @pre You can change default presentation with Inform_Set() 00103 String Inform (size_t Reserved=0); 00104 00105 //Get 00106 /// Get a piece of information about a file (parameter is an integer) 00107 /// @brief Get a piece of information about a file (parameter is an integer) 00108 /// @param StreamKind Kind of stream (general, video, audio...) 00109 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00110 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in integer format (first parameter, second parameter...) 00111 /// @param InfoKind Kind of information you want about the parameter (the text, the measure, the help...) 00112 /// @return a string about information you search \n 00113 /// an empty string if there is a problem 00114 String Get (stream_t StreamKind, size_t StreamNumber, size_t Parameter, info_t InfoKind=Info_Text); 00115 /// Get a piece of information about a file (parameter is a string) 00116 /// @brief Get a piece of information about a file (parameter is a string) 00117 /// @param StreamKind Kind of stream (general, video, audio...) 00118 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00119 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in string format ("Codec", "Width"...) \n 00120 /// See Option("Info_Parameters") to have the full list 00121 /// @param InfoKind Kind of information you want about the parameter (the text, the measure, the help...) 00122 /// @param SearchKind Where to look for the parameter 00123 /// @return a string about information you search \n 00124 /// an empty string if there is a problem 00125 String Get (stream_t StreamKind, size_t StreamNumber, const String &Parameter, info_t InfoKind=Info_Text, info_t SearchKind=Info_Name); 00126 00127 //Set 00128 /// Set a piece of information about a file (parameter is an integer) 00129 /// @brief Set a piece of information about a file (parameter is an int) 00130 /// @param StreamKind Kind of stream (general, video, audio...) 00131 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00132 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in integer format (first parameter, second parameter...) 00133 /// @param OldValue The old value of the parameter \n if OldValue is empty and ToSet is filled : tag is added \n if OldValue is filled and ToSet is filled : tag is replaced \n if OldValue is filled and ToSet is empty : tag is deleted 00134 /// @retval >0 succeed 00135 /// @retval 0 failed 00136 size_t Set (const String &ToSet, stream_t StreamKind, size_t StreamNumber, size_t Parameter, const String &OldValue=_T("")); 00137 /// Set a piece of information about a file (parameter is a string) 00138 /// @brief Set information about a file (parameter is a string) 00139 /// @param StreamKind Kind of stream (general, video, audio...) 00140 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00141 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in string format 00142 /// @param OldValue The old value of the parameter \n if OldValue is empty and ToSet is filled : tag is added \n if OldValue is filled and ToSet is filled : tag is replaced \n if OldValue is filled and ToSet is empty : tag is deleted 00143 /// @retval >0 succeed 00144 /// @retval 0 failed 00145 size_t Set (const String &ToSet, stream_t StreamKind, size_t StreamNumber, const String &Parameter, const String &OldValue=_T("")); 00146 00147 //Output_Buffered 00148 /// Output buffer pointer and size retrieving, used for File_Duplicate option. 00149 /// @brief Output buffer pointer and size retrieving 00150 /// @param Value The name of the duplicated program 00151 /// @param Output_Buffer A pointer on the output buffer, NULL if there is nothing in the buffer \n 00152 /// Note: you must use all the size of the buffer before the next call to this procedure 00153 /// @return The size of the used buffer 00154 size_t Output_Buffer_Get (const Ztring &Value, unsigned char** Output_Buffer=NULL); 00155 00156 //Info 00157 /// Configure or get information about MediaInfoLib 00158 /// @param Option The name of option 00159 /// @param Value The value of option 00160 /// @return Depend of the option : by default "" (nothing) means No, other means Yes 00161 /// @post Known options are : \n 00162 /// * (NOT IMPLEMENTED YET) "BlockMethod" : Configure when Open Method must return (default or not command not understood : "1") \n 00163 /// "0" : Immediatly \n 00164 /// "1" : After geting local information \n 00165 /// "2" : When user interaction is needed, or whan Internet information is get 00166 /// * "Complete" : For debug, configure if MediaInfoLib::Inform() show all information (doesn't care of InfoOption_NoShow tag) : shows all information if true, shows only useful for user information if false (No by default)\n 00167 /// * "Complete_Get" : return the state of "Complete" \n 00168 /// * "Language" : Configure language (default language, and this object); Value is Description of language (format : "Column1;Colum2\n...) \n 00169 /// Column 1 : Unique name ("Bytes", "Title") \n 00170 /// Column 2 : translation ("Octets", "Titre") \n 00171 /// * "Language_Get" : Get the language file in memory 00172 /// * "Language_Update" : Configure language of this object only (for optimisation); Value is Description of language (format : "Column1;Colum2\n...) \n 00173 /// Column 1 : Unique name ("Bytes", "Title") \n 00174 /// Column 2 : translation ("Octets", "Titre") \n 00175 /// * "Inform" : Configure custom text, See MediaInfoLib::Inform() function; Description of views (format : "Column1;Colum2...) \n 00176 /// Column 1 : code (11 lines : "General", "Video", "Audio", "Text", "Chapters", "Begin", "End", "Page_Begin", "Page_Middle", "Page_End") \n 00177 /// Column 2 : The text to show (exemple : "Audio : %FileName% is at %BitRate/String%") \n 00178 /// * "ParseUnknownExtensions" : Configure if MediaInfo parse files with unknown extension\n 00179 /// * "ParseUnknownExtensions_Get" : Get if MediaInfo parse files with unknown extension\n 00180 /// * "ShowFiles" : Configure if MediaInfo keep in memory files with specific kind of streams (or no streams); Value is Description of components (format : "Column1;Colum2\n...) \n\n 00181 /// Column 1 : code (available : "Nothing" for unknown format, "VideoAudio" for at least 1 video and 1 audio, "VideoOnly" for video streams only, "AudioOnly", "TextOnly") \n 00182 /// Column 2 : "" (nothing) not keeping, other for keeping 00183 /// * (NOT IMPLEMENTED YET) "TagSeparator" : Configure the separator if there are multiple same tags (" | " by default)\n 00184 /// * (NOT IMPLEMENTED YET) "TagSeparator_Get" : return the state of "TagSeparator" \n 00185 /// * (NOT IMPLEMENTED YET) "Internet" : Authorize Internet connection (Yes by default) 00186 /// * (NOT IMPLEMENTED YET) "Internet_Title_Get" : When State=5000, give all possible titles for this file (one per line) \n 00187 /// Form : Author TagSeparator Title TagSeparator Year\n... 00188 /// * (NOT IMPLEMENTED YET) "Internet_Title_Set" : Set the Good title (same as given by Internet_Title_Get) \n 00189 /// Form : Author TagSeparator Title TagSeparator Year 00190 /// * "Info_Parameters" : Information about what are known unique names for parameters \n 00191 /// * "Info_Parameters_CSV" : Information about what are known unique names for parameters, in CSV format \n 00192 /// * "Info_Capacities" : Information about which parameters per format are supported \n 00193 /// * "Info_Codecs" : Information about which codec is known \n 00194 /// * "Info_Version" : Information about the version of MediaInfoLib 00195 /// * "Info_Url" : Information about where to find the last version 00196 String Option (const String &Option, const String &Value=_T("")); 00197 static String Option_Static (const String &Option, const String &Value=_T("")); 00198 /// @brief (NOT IMPLEMENTED YET) Get the state of the library 00199 /// @retval <1000 No information is available for the file yet 00200 /// @retval >=1000_<5000 Only local (into the file) information is available, getting Internet information (titles only) is no finished yet 00201 /// @retval 5000 (only if Internet connection is accepted) User interaction is needed (use Option() with "Internet_Title_Get") \n 00202 /// Warning : even there is only one possible, user interaction (or the software) is needed 00203 /// @retval >5000<=10000 Only local (into the file) information is available, getting Internet information (all) is no finished yet 00204 /// @retval <10000 Done 00205 size_t State_Get (); 00206 /// @brief Count of streams of a stream kind (StreamNumber not filled), or count of piece of information in this stream 00207 /// @param StreamKind Kind of stream (general, video, audio...) 00208 /// @param StreamNumber Stream number in this kind of stream (first, second...) 00209 size_t Count_Get (stream_t StreamKind, size_t StreamNumber=(size_t)-1); 00210 00211 private : 00212 friend class File_Cdxa; //Theses classes need access to internal structure for optimization. There is recursivity with theses formats 00213 00214 //Format testing 00215 int Format_Test(); 00216 int Format_Test_Buffer(); 00217 int Format_Test_FillBuffer_Init(); 00218 int Format_Test_FillBuffer_Continue(); 00219 int Format_Test_FillBuffer_Close(); 00220 00221 //File 00222 String File_Name; 00223 ZenLib::File* File_Handle; 00224 int64u File_Size; 00225 int64u File_Offset; 00226 bool File_AlreadyBuffered; 00227 00228 //Buffer 00229 unsigned char* Buffer; 00230 size_t Buffer_Size; 00231 size_t Buffer_Size_Max; 00232 const unsigned char* BufferConst; 00233 00234 //Parsing handles 00235 File__Base* Info; 00236 Internet__Base* Internet; 00237 00238 //Thread 00239 WxThread* Thread; 00240 blockmethod_t BlockMethod; //Open() returns when? 00241 00242 //Helpers 00243 int InternalMethod; //1=Open file, 3=Supported formats 00244 int ApplyMethod(); 00245 int ListFormats(); 00246 void Buffer_Clear(); //Clear the buffer 00247 void SelectFromExtension (const Ztring &Parser); //Select File_* from the parser name 00248 bool LibraryIsModified(); //Is the library has been modified? (#defines...) 00249 void CreateDummy (const String& Value); //Create dummy Information 00250 00251 MediaInfo(const MediaInfo&); // Copy Constructor 00252 00253 //Open Buffer 00254 bool MultipleParsing_IsDetected; 00255 }; 00256 00257 } //NameSpace 00258 #endif