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 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) 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 GNU 00012 // Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00017 // 00018 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00019 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00020 // 00021 // Give information about a lot of media files 00022 // Dispatch the file to be tested by all containers 00023 // 00024 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00025 00026 //--------------------------------------------------------------------------- 00027 #ifndef MediaInfoH 00028 #define MediaInfoH 00029 //--------------------------------------------------------------------------- 00030 00031 //--------------------------------------------------------------------------- 00032 #include <string> 00033 #include <MediaInfo/MediaInfo_Config.h> 00034 #include <ZenLib/File.h> 00035 //--------------------------------------------------------------------------- 00036 00037 namespace MediaInfoLib 00038 { 00039 00040 class File__Base; 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=0, 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 //Info 00148 /// Configure or get information about MediaInfoLib 00149 /// @param Option The name of option 00150 /// @param Value The value of option 00151 /// @return Depend of the option : by default "" (nothing) means No, other means Yes 00152 /// @post Known options are : \n 00153 /// * (NOT IMPLEMENTED YET) "BlockMethod" : Configure when Open Method must return (default or not command not understood : "1") \n 00154 /// "0" : Immediatly \n 00155 /// "1" : After geting local information \n 00156 /// "2" : When user interaction is needed, or whan Internet information is get 00157 /// * "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 00158 /// * "Complete_Get" : return the state of "Complete" \n 00159 /// * "Language" : Configure language (default language, and this object); Value is Description of language (format : "Column1;Colum2\n...) \n 00160 /// Column 1 : Unique name ("Bytes", "Title") \n 00161 /// Column 2 : translation ("Octets", "Titre") \n 00162 /// * "Language_Get" : Get the language file in memory 00163 /// * "Language_Update" : Configure language of this object only (for optimisation); Value is Description of language (format : "Column1;Colum2\n...) \n 00164 /// Column 1 : Unique name ("Bytes", "Title") \n 00165 /// Column 2 : translation ("Octets", "Titre") \n 00166 /// * "Inform" : Configure custom text, See MediaInfoLib::Inform() function; Description of views (format : "Column1;Colum2...) \n 00167 /// Column 1 : code (11 lines : "General", "Video", "Audio", "Text", "Chapters", "Begin", "End", "Page_Begin", "Page_Middle", "Page_End") \n 00168 /// Column 2 : The text to show (exemple : "Audio : %FileName% is at %BitRate/String%") \n 00169 /// * "ParseUnknownExtensions" : Configure if MediaInfo parse files with unknown extension\n 00170 /// * "ParseUnknownExtensions_Get" : Get if MediaInfo parse files with unknown extension\n 00171 /// * "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 00172 /// 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 00173 /// Column 2 : "" (nothing) not keeping, other for keeping 00174 /// * (NOT IMPLEMENTED YET) "TagSeparator" : Configure the separator if there are multiple same tags (" | " by default)\n 00175 /// * (NOT IMPLEMENTED YET) "TagSeparator_Get" : return the state of "TagSeparator" \n 00176 /// * (NOT IMPLEMENTED YET) "Internet" : Authorize Internet connection (Yes by default) 00177 /// * (NOT IMPLEMENTED YET) "Internet_Title_Get" : When State=5000, give all possible titles for this file (one per line) \n 00178 /// Form : Author TagSeparator Title TagSeparator Year\n... 00179 /// * (NOT IMPLEMENTED YET) "Internet_Title_Set" : Set the Good title (same as given by Internet_Title_Get) \n 00180 /// Form : Author TagSeparator Title TagSeparator Year 00181 /// * "Info_Parameters" : Information about what are known unique names for parameters \n 00182 /// * "Info_Parameters_CSV" : Information about what are known unique names for parameters, in CSV format \n 00183 /// * "Info_Capacities" : Information about which parameters per format are supported \n 00184 /// * "Info_Codecs" : Information about which codec is known \n 00185 /// * "Info_Version" : Information about the version of MediaInfoLib 00186 /// * "Info_Url" : Information about where to find the last version 00187 String Option (const String &Option, const String &Value=_T("")); 00188 static String Option_Static (const String &Option, const String &Value=_T("")); 00189 /// @brief (NOT IMPLEMENTED YET) Get the state of the library 00190 /// @retval <1000 No information is available for the file yet 00191 /// @retval >=1000_<5000 Only local (into the file) information is available, getting Internet information (titles only) is no finished yet 00192 /// @retval 5000 (only if Internet connection is accepted) User interaction is needed (use Option() with "Internet_Title_Get") \n 00193 /// Warning : even there is only one possible, user interaction (or the software) is needed 00194 /// @retval >5000<=10000 Only local (into the file) information is available, getting Internet information (all) is no finished yet 00195 /// @retval <10000 Done 00196 size_t State_Get (); 00197 /// @brief Count of streams of a stream kind (StreamNumber not filled), or count of piece of information in this stream 00198 /// @param StreamKind Kind of stream (general, video, audio...) 00199 /// @param StreamNumber Stream number in this kind of stream (first, second...) 00200 size_t Count_Get (stream_t StreamKind, size_t StreamNumber=(size_t)-1); 00201 00202 private : 00203 friend class File_Cdxa; //Theses classes need access to internal structure for optimization. There is recursivity with theses formats 00204 00205 //Format testing 00206 int Format_Test(); 00207 int Format_Test_Buffer(); 00208 int Format_Test_FillBuffer_Init(); 00209 int Format_Test_FillBuffer_Continue(); 00210 int Format_Test_FillBuffer_Close(); 00211 00212 //File 00213 String File_Name; 00214 ZenLib::File* File_Handle; 00215 int64u File_Size; 00216 int64u File_Offset; 00217 bool File_AlreadyBuffered; 00218 00219 //Buffer 00220 unsigned char* Buffer; 00221 size_t Buffer_Size; 00222 size_t Buffer_Size_Max; 00223 00224 //Parsing handles 00225 File__Base* Info; 00226 Internet__Base* Internet; 00227 00228 //Thread 00229 WxThread* Thread; 00230 blockmethod_t BlockMethod; //Open() returns when? 00231 00232 //Helpers 00233 int InternalMethod; //1=Open file, 3=Supported formats 00234 int ApplyMethod(); 00235 int ListFormats(); 00236 void Buffer_Clear(); //Clear the buffer 00237 void SelectFromExtension (const Ztring &Parser); //Select File_* from the parser name 00238 bool LibraryIsModified(); //Is the library has been modified? (#defines...) 00239 void CreateDummy (const String& Value); //Create dummy Information 00240 00241 MediaInfo(const MediaInfo&); // Copy Constructor 00242 }; 00243 00244 } //NameSpace 00245 #endif