00001 // MediaInfo - All information about media files 00002 // Copyright (C) 2002-2006 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 //--------------------------------------------------------------------------- 00035 00036 namespace MediaInfoLib 00037 { 00038 00039 class File__Base; 00040 class Internet__Base; 00041 class WxThread; 00042 00043 //*************************************************************************** 00044 /// @brief MediaInfo 00045 /// @version 0.7 00046 //*************************************************************************** 00047 00048 class MediaInfo 00049 { 00050 public : 00051 //Constructor/Destructor 00052 MediaInfo (); 00053 ~MediaInfo (); 00054 //File 00055 /// Open a file and collect information about it (technical information and tags) 00056 /// @brief Open a file 00057 /// @param File_Name Full name of file to open 00058 /// @retval 0 File not opened 00059 /// @retval 1 File opened 00060 int Open (const MediaInfo_String &File_Name); 00061 /// Open a Buffer (Begin and end of the stream) and collect information about it (technical information and tags) 00062 /// @brief Open a buffer 00063 /// @param Begin First bytes of the buffer 00064 /// @param Begin_Size Size of Begin 00065 /// @param End Last bytes of the buffer 00066 /// @param End_Size Size of End 00067 /// @retval 0 File not opened 00068 /// @retval 1 File opened 00069 int Open (const unsigned char* Begin, size_t Begin_Size, const unsigned char* End=NULL, size_t End_Size=0, int64u FileSize=0); 00070 /// Open a stream and collect information about it (technical information and tags) 00071 /// @brief Open a stream (Init) 00072 /// @param File_Size Estimated file size 00073 /// @param File_Offset Offset of the file (if we don't have the beginning of the file) 00074 void Open_Buffer_Init (int64u File_Size=0, int64u File_Offset=0); 00075 /// Open a stream and collect information about it (technical information and tags) 00076 /// @brief Open a stream (Continue) 00077 /// @param Buffer pointer to the stream 00078 /// @param Buffer_Size Count of bytes to read 00079 void Open_Buffer_Continue (const int8u* Buffer, size_t Buffer_Size); 00080 /// Open a stream and collect information about it (technical information and tags) 00081 /// @brief Open a stream (Get the needed file Offset) 00082 /// @return the needed offset of the file \n 00083 /// File size if no more bytes are needed 00084 int64u Open_Buffer_Continue_GoTo_Get (); 00085 /// Open a stream and collect information about it (technical information and tags) 00086 /// @brief Open a stream (Finalize) 00087 void Open_Buffer_Finalize (); 00088 /// Save the file opened before with Open() (modifications of tags) 00089 /// @brief Save the file 00090 /// @retval 0 failed 00091 /// @retval 1 suceed 00092 int Save (); 00093 /// Close a file opened before with Open() (without saving) 00094 /// @brief Close a file 00095 /// @warning without have saved before, modifications are lost 00096 void Close (); 00097 00098 //General information 00099 /// Get all details about a file in one string 00100 /// @brief Get all details about a file 00101 /// @pre You can change default presentation with Inform_Set() 00102 MediaInfo_String Inform (size_t Reserved=0); 00103 00104 //Get 00105 /// Get a piece of information about a file (parameter is an integer) 00106 /// @brief Get a piece of information about a file (parameter is an integer) 00107 /// @param StreamKind Kind of stream (general, video, audio...) 00108 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00109 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in integer format (first parameter, second parameter...) 00110 /// @param InfoKind Kind of information you want about the parameter (the text, the measure, the help...) 00111 /// @return a string about information you search \n 00112 /// an empty string if there is a problem 00113 MediaInfo_String Get (stream_t StreamKind, int StreamNumber, int Parameter, info_t InfoKind=Info_Text); 00114 /// Get a piece of information about a file (parameter is a string) 00115 /// @brief Get a piece of information about a file (parameter is a string) 00116 /// @param StreamKind Kind of stream (general, video, audio...) 00117 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00118 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in string format ("Codec", "Width"...) \n 00119 /// See Option("Info_Parameters") to have the full list 00120 /// @param InfoKind Kind of information you want about the parameter (the text, the measure, the help...) 00121 /// @param SearchKind Where to look for the parameter 00122 /// @return a string about information you search \n 00123 /// an empty string if there is a problem 00124 MediaInfo_String Get (stream_t StreamKind, int StreamNumber, const MediaInfo_String &Parameter, info_t InfoKind=Info_Text, info_t SearchKind=Info_Name); 00125 00126 //Set 00127 /// Set a piece of information about a file (parameter is an integer) 00128 /// @brief Set a piece of information about a file (parameter is an int) 00129 /// @param StreamKind Kind of stream (general, video, audio...) 00130 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00131 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in integer format (first parameter, second parameter...) 00132 /// @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 00133 /// @retval >=0 suceed 00134 /// @retval <0 failed 00135 int Set (const MediaInfo_String &ToSet, stream_t StreamKind, int StreamNumber, int Parameter, const MediaInfo_String &OldValue=_T("")); 00136 /// Set a piece of information about a file (parameter is a string) 00137 /// @brief Set information about a file (parameter is a string) 00138 /// @param StreamKind Kind of stream (general, video, audio...) 00139 /// @param StreamNumber Stream number in Kind of stream (first, second...) 00140 /// @param Parameter Parameter you are looking for in the stream (Codec, width, bitrate...), in string format 00141 /// @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 00142 /// @retval >=0 suceed 00143 /// @retval <0 failed 00144 int Set (const MediaInfo_String &ToSet, stream_t StreamKind, int StreamNumber, const MediaInfo_String &Parameter, const MediaInfo_String &OldValue=_T("")); 00145 00146 //Info 00147 /// Configure or get information about MediaInfoLib 00148 /// @param Option The name of option 00149 /// @param Value The value of option 00150 /// @return Depend of the option : by default "" (nothing) means No, other means Yes 00151 /// @post Known options are : \n 00152 /// * (NOT IMPLEMENTED YET) "BlockMethod" : Configure when Open Method must return (default or not command not understood : "1") \n 00153 /// "0" : Immediatly \n 00154 /// "1" : After geting local information \n 00155 /// "2" : When user interaction is needed, or whan Internet information is get 00156 /// * "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 00157 /// * "Complete_Get" : return the state of "Complete" \n 00158 /// * "Language" : Configure language (default language, and this object); Value is Description of language (format : "Column1;Colum2\n...) \n 00159 /// Column 1 : Unique name ("Bytes", "Title") \n 00160 /// Column 2 : translation ("Octets", "Titre") \n 00161 /// * "Language_Get" : Get the language file in memory 00162 /// * "Language_Update" : Configure language of this object only (for optimisation); Value is Description of language (format : "Column1;Colum2\n...) \n 00163 /// Column 1 : Unique name ("Bytes", "Title") \n 00164 /// Column 2 : translation ("Octets", "Titre") \n 00165 /// * "Inform" : Configure custom text, See MediaInfoLib::Inform() function; Description of views (format : "Column1;Colum2...) \n 00166 /// Column 1 : code (11 lines : "General", "Video", "Audio", "Text", "Chapters", "Begin", "End", "Page_Begin", "Page_Middle", "Page_End") \n 00167 /// Column 2 : The text to show (exemple : "Audio : %FileName% is at %BitRate/String%") \n 00168 /// * "ParseUnknownExtensions" : Configure if MediaInfo parse files with unknown extension\n 00169 /// * "ParseUnknownExtensions_Get" : Get if MediaInfo parse files with unknown extension\n 00170 /// * "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 00171 /// 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 00172 /// Column 2 : "" (nothing) not keeping, other for keeping 00173 /// * (NOT IMPLEMENTED YET) "TagSeparator" : Configure the separator if there are multiple same tags (" | " by default)\n 00174 /// * (NOT IMPLEMENTED YET) "TagSeparator_Get" : return the state of "TagSeparator" \n 00175 /// * (NOT IMPLEMENTED YET) "Internet" : Authorize Internet connection (Yes by default) 00176 /// * (NOT IMPLEMENTED YET) "Internet_Title_Get" : When State=5000, give all possible titles for this file (one per line) \n 00177 /// Form : Author TagSeparator Title TagSeparator Year\n... 00178 /// * (NOT IMPLEMENTED YET) "Internet_Title_Set" : Set the Good title (same as given by Internet_Title_Get) \n 00179 /// Form : Author TagSeparator Title TagSeparator Year 00180 /// * "Info_Parameters" : Information about what are known unique names for parameters \n 00181 /// * "Info_Parameters_CSV" : Information about what are known unique names for parameters, in CSV format \n 00182 /// * "Info_Capacities" : Information about which parameters per format are supported \n 00183 /// * "Info_Codecs" : Information about which codec is known \n 00184 /// * "Info_Version" : Information about the version of MediaInfoLib 00185 /// * "Info_Url" : Information about where to find the last version 00186 MediaInfo_String Option (const MediaInfo_String &Option, const MediaInfo_String &Value=_T("")); 00187 static MediaInfo_String Option_Static (const MediaInfo_String &Option, const MediaInfo_String &Value=_T("")); 00188 /// @brief (NOT IMPLEMENTED YET) Get the state of the library 00189 /// @retval <1000 No information is available for the file yet 00190 /// @retval >=1000_<5000 Only local (into the file) information is available, getting Internet information (titles only) is no finished yet 00191 /// @retval 5000 (only if Internet connection is accepted) User interaction is needed (use Option() with "Internet_Title_Get") \n 00192 /// Warning : even there is only one possible, user interaction (or the software) is needed 00193 /// @retval >5000<=10000 Only local (into the file) information is available, getting Internet information (all) is no finished yet 00194 /// @retval <10000 Done 00195 int State_Get (); 00196 /// @brief Count of streams of a stream kind (StreamNumber not filled), or count of piece of information in this stream 00197 /// @param StreamKind Kind of stream (general, video, audio...) 00198 /// @param StreamNumber Stream number in this kind of stream (first, second...) 00199 int Count_Get (stream_t StreamKind, int StreamNumber=-1); 00200 00201 private : 00202 friend class File_Cdxa; //Theses classes need access to internal structure for optimization. There is recursivity with theses formats 00203 00204 //Format testing 00205 int Format_Test(); 00206 int Format_Test_Buffer(); 00207 int Format_Test_FillBuffer_Init(); 00208 int Format_Test_FillBuffer_Continue(); 00209 int Format_Test_FillBuffer_Close(); 00210 00211 //File 00212 MediaInfo_String File_Name; 00213 void* File_Handle; //Handle of the opened file 00214 int64u File_Size; 00215 int64u File_Offset; 00216 bool File_AlreadyBuffered; 00217 00218 //Buffer 00219 unsigned char* Buffer; 00220 size_t Buffer_Size; 00221 size_t Buffer_Size_Max; 00222 00223 //Parsing handles 00224 File__Base* Info; 00225 Internet__Base* Internet; 00226 00227 //Thread 00228 WxThread* Thread; 00229 blockmethod_t BlockMethod; //Open() returns when? 00230 00231 //Helpers 00232 int InternalMethod; //1=Open file, 3=Supported formats 00233 int ApplyMethod(); 00234 int ListFormats(); 00235 void Buffer_Clear(); //Clear the buffer 00236 void SelectFromExtension (const Ztring &Parser); //Select File_* from the parser name 00237 bool LibraryIsModified(); //Is the library has been modified? (#defines...) 00238 void CreateDummy (const MediaInfo_String& Value); //Create dummy Information 00239 00240 MediaInfo(const MediaInfo&); // Copy Constructor 00241 }; 00242 00243 } //NameSpace 00244 #endif