void Reader_Directory::Xdcam_Directory_Cleanup(ZtringList &List) { //if there is a XDCAM/Clip folder, this is Xdcam Ztring ToSearch=Ztring(1, PathSeparator)+_T("Clip")+PathSeparator; //"/Clip/" for (size_t File_Pos=0; File_Pos<List.size(); File_Pos++) { size_t Xdcam_Pos=List[File_Pos].find(ToSearch); if (Xdcam_Pos!=string::npos && Xdcam_Pos!=0 && Xdcam_Pos+1+4+1+12==List[File_Pos].size()) { //This is a XDCAM CLIP Ztring Path_Begin=List[File_Pos]; Path_Begin.resize(Path_Begin.size()-(1+4+1+12)); Path_Begin+=Ztring(1, PathSeparator); if (Dir::Exists(Path_Begin+_T("Edit")) && Dir::Exists(Path_Begin+_T("General")) && Dir::Exists(Path_Begin+_T("Sub"))) { bool HasChanged=false; for (size_t Pos=0; Pos<List.size(); Pos++) { if (List[Pos].find(Path_Begin)==0 && (List[Pos].find(Path_Begin+_T("Clip")+PathSeparator)==string::npos || (List[Pos].find(_T(".XML"))!=List[Pos].size()-4))) //Remove all subdirs of Path_Begin but not with the right XML { //Removing the file in the XDCAM directory List.erase(List.begin()+Pos); Pos--; HasChanged=true; } } if (HasChanged) File_Pos=0; } } } }
void Reader_Directory::P2_Directory_Cleanup(ZtringList &List) { //if there is a CONTENTS/CLIP folder, this is P2 Ztring ToSearch=Ztring(1, PathSeparator)+_T("CONTENTS")+PathSeparator+_T("CLIP")+PathSeparator; //"/CONTENTS/CLIP/" for (size_t File_Pos=0; File_Pos<List.size(); File_Pos++) { size_t P2_Pos=List[File_Pos].find(ToSearch); if (P2_Pos!=string::npos && P2_Pos!=0 && P2_Pos+1+8+1+4+1+10==List[File_Pos].size()) { //This is a P2 CLIP Ztring Path_Begin=List[File_Pos]; Path_Begin.resize(Path_Begin.size()-(1+8+1+4+1+10)); Path_Begin+=Ztring(1, PathSeparator); bool HasChanged=false; for (size_t Pos=0; Pos<List.size(); Pos++) { if (List[Pos].find(Path_Begin)==0 && List[Pos].find(Path_Begin+_T("CONTENTS")+PathSeparator+_T("CLIP")+PathSeparator)==string::npos) //Remove all subdirs of Path_Begin but not with CLIP { //Removing the file in the P2 directory List.erase(List.begin()+Pos); Pos--; HasChanged=true; } } if (HasChanged) File_Pos=0; } } }
void Reader_Directory::Bdmv_Directory_Cleanup(ZtringList &List) { //if there is a BDMV folder, this is blu-ray Ztring ToSearch=Ztring(1, PathSeparator)+_T("BDMV")+PathSeparator+_T("index.bdmv"); //"\BDMV\index.bdmv" for (size_t File_Pos=0; File_Pos<List.size(); File_Pos++) { size_t BDMV_Pos=List[File_Pos].find(ToSearch); if (BDMV_Pos!=string::npos && BDMV_Pos!=0 && BDMV_Pos+16==List[File_Pos].size()) { //This is a BDMV index, parsing the directory only if index and movie objects are BOTH present ToSearch=List[File_Pos]; ToSearch.resize(ToSearch.size()-10); ToSearch+=_T("MovieObject.bdmv"); //"%CompletePath%\BDMV\MovieObject.bdmv" if (List.Find(ToSearch)!=string::npos) { //We want the folder instead of the files List[File_Pos].resize(List[File_Pos].size()-11); //only %CompletePath%\BDMV ToSearch=List[File_Pos]; for (size_t Pos=0; Pos<List.size(); Pos++) { if (List[Pos].find(ToSearch)==0 && List[Pos]!=ToSearch) //Remove all subdirs of ToSearch but not ToSearch { //Removing the file in the blu-ray directory List.erase(List.begin()+Pos); Pos--; } } } } } }
ZtringList::ZtringList(const ZtringList &Source) { Separator[0]=Source.Separator[0]; Quote=Source.Quote; reserve(Source.size()); for (intu Pos=0; Pos<Source.size(); Pos++) push_back(Source[Pos]); }
ZtringList::ZtringList(const ZtringList &Source) : std::vector<ZenLib::Ztring, std::allocator<ZenLib::Ztring> > () { Separator[0]=Source.Separator[0]; Quote=Source.Quote; reserve(Source.size()); for (intu Pos=0; Pos<Source.size(); Pos++) push_back(Source[Pos]); }
//--------------------------------------------------------------------------- // Chargement CFG bool ZtringListListF::CFG_Charger () { //Read file File F(Name); int8u* Buffer=new int8u[(size_t)F.Size_Get()+1]; size_t BytesCount=F.Read(Buffer, (size_t)F.Size_Get()); F.Close(); if (BytesCount==Error) { delete[] Buffer; //Buffer=NULL; return false; } Buffer[(int32u)BytesCount]=(int8u)'\0'; //Convert File --> ZtringList ZtringList List; List.Separator_Set(0, EOL); Ztring Z1; Z1.From_UTF8((char*)Buffer, 0, BytesCount); List.Write(Z1); Ztring SeparatorT=Separator[1]; Separator[1]=__T(";"); Ztring Propriete, Valeur, Commentaire; for (size_t Pos=0; Pos<List.size(); Pos++) { Ztring &Lu=List(Pos); if (Lu.find(__T("="))>0) { //Obtention du Name Propriete=Lu.SubString(Ztring(), __T("=")); NettoyerEspaces(Propriete); //Obtention de la valeur Valeur=Lu.SubString(__T("="), __T(";"), 0, Ztring_AddLastItem); NettoyerEspaces(Valeur); } //Obtention du commentaire Commentaire=Lu.SubString(__T(";"), Ztring(), 0, Ztring_AddLastItem); NettoyerEspaces(Commentaire); //Ecriture push_back((Propriete+__T(";")+Valeur+__T(";")+Commentaire).c_str()); //Visual C++ 6 is old... } Separator[1]=SeparatorT; delete[] Buffer; //Buffer=NULL; return true; }
//--------------------------------------------------------------------------- size_t Reader_libcurl::Format_Test_PerParser(MediaInfo_Internal* MI, const String &File_Name) { #if defined MEDIAINFO_LIBCURL_DLL_RUNTIME if (libcurl_Module_Count==0) return 0; //No libcurl library #endif //defined MEDIAINFO_LIBCURL_DLL_RUNTIME Curl_Data=new curl_data(); Curl_Data->Curl=curl_easy_init(); if (Curl_Data->Curl==NULL) return 0; #if MEDIAINFO_NEXTPACKET if (MI->Config.NextPacket_Get()) { Curl_Data->CurlM=curl_multi_init( ); if (Curl_Data->CurlM==NULL) return 0; CURLMcode CodeM=curl_multi_add_handle(Curl_Data->CurlM, Curl_Data->Curl); if (CodeM!=CURLM_OK) return 0; Curl_Data->NextPacket=true; } #endif //MEDIAINFO_NEXTPACKET Curl_Data->MI=MI; Curl_Data->File_Name=File_Name; string FileName_String=Ztring(Curl_Data->File_Name).To_Local(); if (MI->Config.File_TimeToLive_Get()) Curl_Data->Time_Max=time(0)+(time_t)MI->Config.File_TimeToLive_Get(); if (!MI->Config.File_Curl_Get(_T("UserAgent")).empty()) curl_easy_setopt(Curl_Data->Curl, CURLOPT_USERAGENT, MI->Config.File_Curl_Get(_T("UserAgent")).To_Local().c_str()); if (!MI->Config.File_Curl_Get(_T("Proxy")).empty()) curl_easy_setopt(Curl_Data->Curl, CURLOPT_PROXY, MI->Config.File_Curl_Get(_T("Proxy")).To_Local().c_str()); if (!MI->Config.File_Curl_Get(_T("HttpHeader")).empty()) { ZtringList HttpHeaderStrings; HttpHeaderStrings.Separator_Set(0, EOL); //End of line is set depending of the platform: \n on Linux, \r on Mac, or \r\n on Windows HttpHeaderStrings.Write(MI->Config.File_Curl_Get(_T("HttpHeader"))); for (size_t Pos=0; Pos<HttpHeaderStrings.size(); Pos++) curl_slist_append(Curl_Data->HttpHeader, HttpHeaderStrings[Pos].To_Local().c_str()); curl_easy_setopt(Curl_Data->Curl, CURLOPT_HTTPHEADER, Curl_Data->HttpHeader); } curl_easy_setopt(Curl_Data->Curl, CURLOPT_URL, FileName_String.c_str()); curl_easy_setopt(Curl_Data->Curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(Curl_Data->Curl, CURLOPT_MAXREDIRS, 3); curl_easy_setopt(Curl_Data->Curl, CURLOPT_WRITEFUNCTION, &libcurl_WriteData_CallBack); curl_easy_setopt(Curl_Data->Curl, CURLOPT_WRITEDATA, Curl_Data); //Test the format with buffer return Format_Test_PerParser_Continue(MI); }
//--------------------------------------------------------------------------- void File_Dsdiff::DSD__PROP_CHNL() { Element_Name("Channels"); //Parsing int16u numChannels; vector<int32u> chIDs; Get_B2 (numChannels, "numChannels"); while (Element_Offset<Element_Size) { int32u chID; Get_C4 (chID, "chID"); chIDs.push_back(chID); } FILLING_BEGIN(); Fill(Stream_Audio, 0, Audio_Channel_s_, numChannels); int32u ChannelPositions=0; int32u ChannelPositions2=0; ZtringList ChannelLayout; ChannelLayout.Separator_Set(0, __T(" ")); for (size_t i=0; i<chIDs.size(); i++) { DSDIFF_CHNL_chID_ChannelPositions(chIDs[i], ChannelPositions); DSDIFF_CHNL_chID_ChannelPositions2(chIDs[i], ChannelPositions2); ChannelLayout.push_back(DSDIFF_CHNL_chID(chIDs[i])); } Ztring ChannelPositions_New=DSDIFF_CHNL_chID_ChannelPositions(ChannelPositions); const Ztring& ChannelPositions_Old=Retrieve_Const(Stream_Audio, 0, Audio_ChannelPositions); if (ChannelPositions_New!=ChannelPositions_Old) Fill(Stream_Audio, 0, Audio_ChannelPositions, ChannelPositions_New); Ztring ChannelPositions2_New=DSDIFF_CHNL_chID_ChannelPositions2(ChannelPositions2); const Ztring& ChannelPositions2_Old=Retrieve_Const(Stream_Audio, 0, Audio_ChannelPositions_String2); if (ChannelPositions2_New!=ChannelPositions2_Old) Fill(Stream_Audio, 0, Audio_ChannelPositions_String2, ChannelPositions2_New); const Ztring& ChannelLayout_New=ChannelLayout.Read(); const Ztring& ChannelLayout_Old=Retrieve_Const(Stream_Audio, 0, Audio_ChannelLayout); if (ChannelLayout_New!=ChannelLayout_Old) Fill(Stream_Audio, 0, Audio_ChannelLayout, ChannelLayout_New); FILLING_END(); }
//--------------------------------------------------------------------------- // Set void InfoMap::Write(const Ztring &NewInfoMap) { clear(); if (NewInfoMap.empty()) return; size_t Pos1=0, Pos2_EOL=0, Pos2_Separator=0; while (Pos2_EOL!=(size_t)-1) { Pos2_EOL=NewInfoMap.find(__T('\n'), Pos1); Pos2_Separator=NewInfoMap.find(__T(';'), Pos1); if (Pos2_Separator<Pos2_EOL) { ZtringList List; List.Write(NewInfoMap.substr(Pos1, Pos2_EOL-Pos1)); insert (pair<Ztring, ZtringList>(NewInfoMap.substr(Pos1, Pos2_Separator-Pos1), List)); } Pos1=Pos2_EOL+1; } }
//--------------------------------------------------------------------------- void File__Analyze::Fill (stream_t StreamKind, size_t StreamPos, size_t Parameter, const Ztring &Value, bool Replace) { //Integrity if (StreamKind>Stream_Max) return; //Handling values with \r\n inside if (Value.find(_T('\r'))!=string::npos || Value.find(_T('\n'))!=string::npos) { Ztring NewValue=Value; NewValue.FindAndReplace(_T("\r\n"), _T(" / "), 0, Ztring_Recursive); NewValue.FindAndReplace(_T("\r"), _T(" / "), 0, Ztring_Recursive); NewValue.FindAndReplace(_T("\n"), _T(" / "), 0, Ztring_Recursive); if (NewValue.size()>=3 && NewValue.rfind(_T(" / "))==NewValue.size()-3) NewValue.resize(NewValue.size()-3); Fill(StreamKind, StreamPos, Parameter, NewValue, Replace); return; } //Handle Value before StreamKind if (StreamKind==Stream_Max || StreamPos>=(*Stream)[StreamKind].size()) { ZtringList NewList; NewList.push_back(Ztring().From_Number(Parameter)); NewList.push_back(Value); Fill_Temp.push_back(NewList); return; //No streams } Ztring &Target=(*Stream)[StreamKind][StreamPos](Parameter); if (Target.empty() || Replace) Target=Value; //First value else if (Value.empty()) Target.clear(); //Empty value --> clear other values else { Target+=MediaInfoLib::Config.TagSeparator_Get(); Target+=Value; } }
void File_OtherText::Read_Buffer_Continue() { if (Buffer_Size<0x200) { Element_WaitForMoreData(); return; } Element_Offset=File_Size-(File_Offset+Buffer_Offset); Ztring Format, FormatMore, Codec; Ztring File; ZtringList Lines; //Feed File and Lines File.From_UTF8((const char*)Buffer, Buffer_Size>65536?65536:Buffer_Size); if (File.empty()) File.From_Local((const char*)Buffer, Buffer_Size>65536?65536:Buffer_Size); // Trying from local code page if (File.size()<0x100) { File.From_Unicode((wchar_t*)Buffer, 0, Buffer_Size/sizeof(wchar_t)); //Unicode with BOM //TODO: Order of bytes (big or Little endian) if (File.size()<0x100) { Reject("Other text"); return; } } if (File.size()>0x1000) File.resize(0x1000); //Do not work on too big File.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive); File.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive); Lines.Separator_Set(0, __T("\n")); Lines.Write(File); Lines.resize(0x20); if (Lines[0]==__T("[Script Info]") && (Lines.Find(__T("ScriptType: v4.00"))!=Error || Lines.Find(__T("Script Type: V4.00"))!=Error) && Lines.Find(__T("[V4 Styles]"))!=Error ) { Format=__T("SSA"); FormatMore=__T("SubStation Alpha"); Codec=__T("SSA"); } else if (Lines[0]==__T("[Script Info]") && (Lines.Find(__T("ScriptType: v4.00+"))!=Error || Lines.Find(__T("Script Type: V4.00+"))!=Error) && Lines.Find(__T("[V4+ Styles]"))!=Error ) { Format=__T("ASS"); FormatMore=__T("Advanced SubStation Alpha"); Codec=__T("ASS"); } else if (Lines[0].size()>24 && Lines[0][ 0]==__T('0') && Lines[0][ 1]==__T('0') && Lines[0][ 2]==__T(':') && Lines[0][ 5]==__T(':') && Lines[0][ 8]==__T(':') && Lines[0][11]==__T(' ') && Lines[0][12]==__T('0') && Lines[0][13]==__T('0') && Lines[0][14]==__T(':') && Lines[0][17]==__T(':') && Lines[0][20]==__T(':') && Lines[0][23]==__T(' ') ) { Format=__T("Adobe encore DVD"); Codec=__T("Adobe"); } else if (Lines[0].size()==11 && Lines[0][0]==__T('-') && Lines[0][1]==__T('-') && Lines[0][2]==__T('>') && Lines[0][3]==__T('>') && Lines[0][4]==__T(' ') && Lines[0][5]==__T('0') && Lines[1].empty()!=true ) { Format=__T("AQTitle"); Codec=__T("AQTitle"); } else if (Lines[0].size()>28 && Lines[0][ 0]==__T('0') && Lines[0][ 1]==__T('0') && Lines[0][ 2]==__T(':') && Lines[0][ 5]==__T(':') && Lines[0][ 8]==__T(':') && Lines[0][11]==__T(' ') && Lines[0][12]==__T(',') && Lines[0][13]==__T(' ') && Lines[0][14]==__T('0') && Lines[0][15]==__T('0') && Lines[0][16]==__T(':') && Lines[0][19]==__T(':') && Lines[0][22]==__T(':') && Lines[0][25]==__T(' ') && Lines[0][16]==__T(',') && Lines[0][27]==__T(' ') ) { Format=__T("Captions 32"); Codec=__T("Caption 32"); } else if (Lines[0].size()==23 && Lines[0]==__T("*Timecode type: PAL/EBU") && Lines[1].empty() && Lines[2].size()==23 && Lines[2][ 0]==__T('0') && Lines[2][ 1]==__T('0') && Lines[2][ 2]==__T(':') && Lines[2][ 5]==__T(':') && Lines[2][ 8]==__T(':') && Lines[2][11]==__T(' ') && Lines[2][12]==__T('0') && Lines[2][13]==__T('0') && Lines[2][14]==__T(':') && Lines[2][17]==__T(':') && Lines[2][20]==__T(':') && Lines[2].size()>0 ) { Format=__T("Captions Inc"); Codec=__T("Captions inc"); } else if (Lines[0].size()>1 && Lines[0][0]==__T('*') && Lines.Find(__T("** Caption Number 1"))!=Error ) { Format=__T("Cheeta"); } else if (Lines[0].size()>10 && Lines[0][0]==__T('~') && Lines[0][1]==__T('C') && Lines[0][2]==__T('P') && Lines[0][3]==__T('C') && Lines[0][9]==__T('~') && Lines[1][ 0]==__T('0') && Lines[1][ 1]==__T('0') && Lines[1][ 2]==__T(':') && Lines[1][ 5]==__T(':') && Lines[1][ 8]==__T(':') ) { Format=__T("CPC Captioning"); Codec=__T("CPC Captioning"); } else if (Lines[0].find(__T("<SAMI>"))==0) { Format=__T("SAMI"); } else return; if (Format.empty()) return; Accept("Other text"); if (!IsSub) { Fill(Stream_General, 0, General_Format, Format); Fill(Stream_General, 0, General_Format_Info, FormatMore, true); } Stream_Prepare(Stream_Text); Fill(Stream_Text, 0, Text_Format, Format); Fill(Stream_Text, 0, Text_Codec, Codec); //No more need data Element_Begin1(Format); Element_End0(); Finish("Other text"); }
//--------------------------------------------------------------------------- bool File_Hls::FileHeader_Begin() { //Element_Size if (File_Size>1024*1024 || File_Size<10) { Reject("HLS"); return false; //HLS files are not big } if (Buffer_Size<File_Size) return false; //Wait for complete file Ztring Document; Document.From_UTF8((char*)Buffer, Buffer_Size); ZtringList Lines; size_t LinesSeparator_Pos=Document.find_first_of(__T("\r\n")); if (LinesSeparator_Pos>File_Size-1) { Reject("HLS"); return false; } Ztring LinesSeparator; if (Document[LinesSeparator_Pos]==__T('\r') && LinesSeparator_Pos+1<Document.size() && Document[LinesSeparator_Pos+1]==__T('\n')) LinesSeparator=__T("\r\n"); else if (Document[LinesSeparator_Pos]==__T('\r')) LinesSeparator=__T("\r"); else if (Document[LinesSeparator_Pos]==__T('\n')) LinesSeparator=__T("\n"); else { Reject("HLS"); return false; } Lines.Separator_Set(0, LinesSeparator); Lines.Write(Document); if (Lines(0)!=__T("#EXTM3U")) { Reject("HLS"); return false; } Accept("HLS"); Fill(Stream_General, 0, General_Format, "HLS"); ReferenceFiles=new File__ReferenceFilesHelper(this, Config); if (!IsSub) ReferenceFiles->ContainerHasNoId=true; File__ReferenceFilesHelper::reference ReferenceFile; bool IsGroup=false; for (size_t Line=0; Line<Lines.size(); Line++) { if (!Lines[Line].empty()) { if (Lines[Line].find(__T("#EXT-X-STREAM-INF"))==0) IsGroup=true; else if (Lines[Line][0]==__T('#')) ; else { if (IsGroup) { File__ReferenceFilesHelper::reference ReferenceStream; ReferenceStream.FileNames.push_back(Lines[Line]); ReferenceStream.StreamID=ReferenceFiles->References.size()+1; ReferenceFiles->References.push_back(ReferenceStream); IsGroup=false; #if MEDIAINFO_EVENTS ParserIDs[0]=MediaInfo_Parser_HlsIndex; StreamIDs_Width[0]=sizeof(size_t)*2; #endif //MEDIAINFO_EVENTS } else ReferenceFile.FileNames.push_back(Lines[Line]); } } } if (ReferenceFiles->References.empty()) { ReferenceFiles->References.push_back(ReferenceFile); ReferenceFiles->TestContinuousFileNames=true; } Element_Offset=File_Size; //All should be OK... return true; }
ZtringList Dir::GetAllFileNames(const Ztring &Dir_Name_, dirlist_t Options) { ZtringList ToReturn; Ztring Dir_Name=Dir_Name_; #ifdef ZENLIB_USEWX int Flags=wxDIR_FILES | wxDIR_DIRS; //Search for files wxArrayString Liste; wxFileName FullPath; FullPath=Dir_Name.c_str(); //-File if (FullPath.FileExists()) { FullPath.Normalize(); Liste.Add(FullPath.GetFullPath()); } //-Directory else if (FullPath.DirExists()) { FullPath.Normalize(); wxDir::GetAllFiles(FullPath.GetFullPath(), &Liste, Ztring(), Flags); } //-WildCards else { wxString FileName=FullPath.GetFullName(); FullPath.SetFullName(Ztring()); //Supress filename FullPath.Normalize(); if (FullPath.DirExists()) wxDir::GetAllFiles(FullPath.GetPath(), &Liste, FileName, Flags); } //Compatible array ToReturn.reserve(Liste.GetCount()); for (size_t Pos=0; Pos<Liste.GetCount(); Pos++) ToReturn.push_back(Liste[Pos].c_str()); #else //ZENLIB_USEWX #ifdef WINDOWS //Is a dir? if (Exists(Dir_Name)) Dir_Name+=_T("\\*"); //Path Ztring Path=FileName::Path_Get(Dir_Name); if (Path.empty()) { #ifdef UNICODE #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) { DWORD Path_Size=GetFullPathNameA(Dir_Name.To_Local().c_str(), 0, NULL, NULL); char* PathTemp=new char[Path_Size+1]; if (GetFullPathNameA(Dir_Name.To_Local().c_str(), Path_Size+1, PathTemp, NULL)) Path=FileName::Path_Get(PathTemp); delete [] PathTemp; //PathTemp=NULL; } else #endif //ZENLIB_NO_WIN9X_SUPPORT { DWORD Path_Size=GetFullPathName(Dir_Name.c_str(), 0, NULL, NULL); Char* PathTemp=new Char[Path_Size+1]; if (GetFullPathNameW(Dir_Name.c_str(), Path_Size+1, PathTemp, NULL)) Path=FileName::Path_Get(PathTemp); delete [] PathTemp; //PathTemp=NULL; } #else DWORD Path_Size=GetFullPathName(Dir_Name.c_str(), 0, NULL, NULL); Char* PathTemp=new Char[Path_Size+1]; if (GetFullPathName(Dir_Name.c_str(), Path_Size+1, PathTemp, NULL)) Path=FileName::Path_Get(PathTemp); delete [] PathTemp; //PathTemp=NULL; #endif //UNICODE } #ifdef UNICODE WIN32_FIND_DATAW FindFileDataW; HANDLE hFind; #ifndef ZENLIB_NO_WIN9X_SUPPORT WIN32_FIND_DATAA FindFileDataA; if (IsWin9X_Fast()) hFind=FindFirstFileA(Dir_Name.To_Local().c_str(), &FindFileDataA); else #endif //ZENLIB_NO_WIN9X_SUPPORT hFind=FindFirstFileW(Dir_Name.c_str(), &FindFileDataW); #else WIN32_FIND_DATA FindFileData; HANDLE hFind=FindFirstFile(Dir_Name.c_str(), &FindFileData); #endif //UNICODE if (hFind==INVALID_HANDLE_VALUE) return ZtringList(); BOOL ReturnValue; do { #ifdef UNICODE Ztring File_Name; #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) File_Name=FindFileDataA.cFileName; else #endif //ZENLIB_NO_WIN9X_SUPPORT File_Name=FindFileDataW.cFileName; #else Ztring File_Name(FindFileData.cFileName); #endif //UNICODE if (File_Name!=_T(".") && File_Name!=_T("..")) //Avoid . an .. { Ztring File_Name_Complete=Path+_T("\\")+File_Name; if (Exists(File_Name_Complete)) { if (Options&Parse_SubDirs) ToReturn+=GetAllFileNames(File_Name_Complete, Options); //A SubDir } else if ((Options&Include_Hidden) || (!File_Name.empty() && File_Name[0]!=_T('.'))) ToReturn.push_back(File_Name_Complete); //A file } #ifdef UNICODE #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) ReturnValue=FindNextFileA(hFind, &FindFileDataA); else #endif //ZENLIB_NO_WIN9X_SUPPORT ReturnValue=FindNextFileW(hFind, &FindFileDataW); #else ReturnValue=FindNextFile(hFind, &FindFileData); #endif //UNICODE } while (ReturnValue); FindClose(hFind); #else //WINDOWS //A file? if (File::Exists(Dir_Name)) { ToReturn.push_back(Dir_Name); //TODO return ToReturn; } //A dir? if (!Dir::Exists(Dir_Name)) return ToReturn; //Does not exist //open #ifdef UNICODE DIR* Dir=opendir(Dir_Name.To_Local().c_str()); #else DIR* Dir=opendir(Dir_Name.c_str()); #endif //UNICODE if (Dir) { //This is a dir //Normalizing dir (the / at the end) size_t Dir_Pos=Dir_Name.rfind(FileName_PathSeparator); if (Dir_Pos==std::string::npos) Dir_Name+=FileName_PathSeparator; else if (Dir_Pos+Ztring(FileName_PathSeparator).size()!=Dir_Name.size()) Dir_Name+=FileName_PathSeparator; struct dirent *DirEnt; while((DirEnt=readdir(Dir))!=NULL) { //A file Ztring File_Name(DirEnt->d_name); if (File_Name!=_T(".") && File_Name!=_T("..")) //Avoid . an .. { Ztring File_Name_Complete=Dir_Name+File_Name; if (Exists(File_Name_Complete)) { if (Options&Parse_SubDirs) ToReturn+=GetAllFileNames(File_Name_Complete, Options); //A SubDir } else if ((Options&Include_Hidden) || (!File_Name.empty() && File_Name[0]!=_T('.'))) ToReturn.push_back(File_Name_Complete); //A file } } //Close it closedir(Dir); } else { glob_t globbuf; if (glob(Dir_Name.To_Local().c_str(), GLOB_NOSORT, NULL, &globbuf)==0) { for (int Pos=0; Pos<globbuf.gl_pathc; Pos++) ToReturn.push_back(Ztring().From_Local(globbuf.gl_pathv[Pos])); } } #endif #endif //ZENLIB_USEWX return ToReturn; }
//--------------------------------------------------------------------------- bool File_DcpCpl::FileHeader_Begin() { XMLDocument document; if (!FileHeader_Begin_XML(document)) return false; bool IsDcp=false, IsImf=false; XMLElement* Root=document.FirstChildElement("CompositionPlaylist"); if (!Root) { Reject("DcpCpl"); return false; } const char* Attribute=Root->Attribute("xmlns"); if (!Attribute) { Reject("DcpCpl"); return false; } if (!strcmp(Attribute, "http://www.digicine.com/PROTO-ASDCP-CPL-20040511#")) IsDcp=true; if (!strcmp(Attribute, "http://www.smpte-ra.org/schemas/2067-3/XXXX") //Some muxers use XXXX instead of year || !strcmp(Attribute, "http://www.smpte-ra.org/schemas/2067-3/2013")) IsImf=true; if (!IsDcp && !IsImf) { Reject("DcpCpl"); return false; } Accept("DcpCpl"); Fill(Stream_General, 0, General_Format, IsDcp?"DCP CPL":"IMF CPL"); Config->File_ID_OnlyRoot_Set(false); ReferenceFiles=new File__ReferenceFilesHelper(this, Config); //Parsing main elements for (XMLElement* Root_Item=Root->FirstChildElement(); Root_Item; Root_Item=Root_Item->NextSiblingElement()) { //ReelList / SegmentList if ((IsDcp && !strcmp(Root_Item->Value(), "ReelList")) || (IsImf && !strcmp(Root_Item->Value(), "SegmentList"))) { for (XMLElement* ReelList_Item=Root_Item->FirstChildElement(); ReelList_Item; ReelList_Item=ReelList_Item->NextSiblingElement()) { //Reel if ((IsDcp && !strcmp(ReelList_Item->Value(), "Reel")) || (IsImf && !strcmp(ReelList_Item->Value(), "Segment"))) { for (XMLElement* Reel_Item=ReelList_Item->FirstChildElement(); Reel_Item; Reel_Item=Reel_Item->NextSiblingElement()) { //AssetList if ((IsDcp && !strcmp(Reel_Item->Value(), "AssetList")) || (IsImf && !strcmp(Reel_Item->Value(), "SequenceList"))) { for (XMLElement* AssetList_Item=Reel_Item->FirstChildElement(); AssetList_Item; AssetList_Item=AssetList_Item->NextSiblingElement()) { //File //if ((IsDcp && (!strcmp(AssetList_Item->Value(), "MainPicture") || !strcmp(AssetList_Item->Value(), "MainSound"))) // || (IsImf && (!strcmp(AssetList_Item->Value(), "cc:MainImageSequence") || !strcmp(AssetList_Item->Value(), "cc:MainImage")))) { File__ReferenceFilesHelper::reference ReferenceFile; Ztring Asset_Id; if ((IsDcp && !strcmp(AssetList_Item->Value(), "MainPicture")) || (IsImf && !strcmp(AssetList_Item->Value(), "cc:MainImageSequence"))) ReferenceFile.StreamKind=Stream_Video; if ((IsDcp && !strcmp(AssetList_Item->Value(), "MainSound")) || (IsImf && !strcmp(AssetList_Item->Value(), "cc:MainAudioSequence"))) ReferenceFile.StreamKind=Stream_Audio; for (XMLElement* File_Item=AssetList_Item->FirstChildElement(); File_Item; File_Item=File_Item->NextSiblingElement()) { //Id if (!strcmp(File_Item->Value(), "Id") && Asset_Id.empty()) Asset_Id.From_UTF8(File_Item->GetText()); //ResourceList if (IsImf && !strcmp(File_Item->Value(), "ResourceList")) { for (XMLElement* ResourceList_Item=File_Item->FirstChildElement(); ResourceList_Item; ResourceList_Item=ResourceList_Item->NextSiblingElement()) { //Resource if (!strcmp(ResourceList_Item->Value(), "Resource")) { Ztring Resource_Id; File__ReferenceFilesHelper::reference::completeduration Resource; for (XMLElement* Resource_Item=ResourceList_Item->FirstChildElement(); Resource_Item; Resource_Item=Resource_Item->NextSiblingElement()) { //EditRate if (!strcmp(Resource_Item->Value(), "EditRate")) { const char* EditRate=Resource_Item->GetText(); Resource.IgnoreFramesRate=atof(EditRate); const char* EditRate2=strchr(EditRate, ' '); if (EditRate2!=NULL) { float64 EditRate2f=atof(EditRate2); if (EditRate2f) Resource.IgnoreFramesRate/=EditRate2f; } } //EntryPoint if (!strcmp(Resource_Item->Value(), "EntryPoint")) Resource.IgnoreFramesBefore=atoi(Resource_Item->GetText()); //Id if (!strcmp(File_Item->Value(), "Id") && Resource_Id.empty()) Resource_Id.From_UTF8(File_Item->GetText()); //SourceDuration if (!strcmp(Resource_Item->Value(), "SourceDuration")) Resource.IgnoreFramesAfterDuration=atoi(Resource_Item->GetText()); //TrackFileId if (!strcmp(Resource_Item->Value(), "TrackFileId")) Resource.FileName.From_UTF8(Resource_Item->GetText()); } if (Resource.FileName.empty()) Resource.FileName=Resource_Id; ReferenceFile.CompleteDuration.push_back(Resource); } } } } if (ReferenceFile.CompleteDuration.empty()) { File__ReferenceFilesHelper::reference::completeduration Resource; Resource.FileName=Asset_Id; ReferenceFile.CompleteDuration.push_back(Resource); } ReferenceFile.StreamID=ReferenceFiles->References.size()+1; ReferenceFiles->References.push_back(ReferenceFile); } } } } } } } } Element_Offset=File_Size; //Getting files names if (!Config->File_IsReferenced_Get()) { FileName Directory(File_Name); ZtringList List; if (IsImf) List=Dir::GetAllFileNames(Directory.Path_Get()+PathSeparator+__T("PKL_*.xml"), Dir::Include_Files); if (IsDcp || List.empty()) List=Dir::GetAllFileNames(Directory.Path_Get()+PathSeparator+__T("*_pkl.xml"), Dir::Include_Files); for (size_t Pos=0; Pos<List.size(); Pos++) { MediaInfo_Internal MI; MI.Option(__T("File_KeepInfo"), __T("1")); Ztring ParseSpeed_Save=MI.Option(__T("ParseSpeed_Get"), __T("")); Ztring Demux_Save=MI.Option(__T("Demux_Get"), __T("")); MI.Option(__T("ParseSpeed"), __T("0")); MI.Option(__T("Demux"), Ztring()); MI.Option(__T("File_IsReferenced"), __T("1")); size_t MiOpenResult=MI.Open(List[Pos]); MI.Option(__T("ParseSpeed"), ParseSpeed_Save); //This is a global value, need to reset it. TODO: local value MI.Option(__T("Demux"), Demux_Save); //This is a global value, need to reset it. TODO: local value if (MiOpenResult && ((IsDcp && MI.Get(Stream_General, 0, General_Format)==__T("DCP PKL")) || (IsImf && MI.Get(Stream_General, 0, General_Format)==__T("IMF PKL")))) { DcpCpl_MergeFromPkl(ReferenceFiles, ((File_DcpCpl*)MI.Info)->ReferenceFiles); } } } ReferenceFiles->FilesForStorage=true; //All should be OK... return true; }
//--------------------------------------------------------------------------- size_t MediaInfoList_Internal::Open(const String &File_Name, const fileoptions_t Options) { //Option FileOption_Close if (Options & FileOption_CloseAll) Close(All); //Option Recursive //TODO //Get all filenames ZtringList List; if ((File_Name.size()>=7 && File_Name[0]==_T('h') && File_Name[1]==_T('t') && File_Name[2]==_T('t') && File_Name[3]==_T('p') && File_Name[4]==_T(':') && File_Name[5]==_T('/') && File_Name[6]==_T('/')) || (File_Name.size()>=6 && File_Name[0]==_T('f') && File_Name[1]==_T('t') && File_Name[2]==_T('p') && File_Name[3]==_T(':') && File_Name[4]==_T('/') && File_Name[5]==_T('/')) || (File_Name.size()>=6 && File_Name[0]==_T('m') && File_Name[1]==_T('m') && File_Name[2]==_T('s') && File_Name[3]==_T(':') && File_Name[4]==_T('/') && File_Name[5]==_T('/')) || (File_Name.size()>=7 && File_Name[0]==_T('m') && File_Name[1]==_T('m') && File_Name[2]==_T('s') && File_Name[3]==_T('h') && File_Name[4]==_T(':') && File_Name[5]==_T('/') && File_Name[6]==_T('/'))) List.push_back(File_Name); else if (File::Exists(File_Name)) List.push_back(File_Name); else List=Dir::GetAllFileNames(File_Name, (Options&FileOption_NoRecursive)?Dir::Nothing:Dir::Parse_SubDirs); Reader_Directory::Directory_Cleanup(List); //Registering files CS.Enter(); if (ToParse.empty()) CountValid=0; for (ZtringList::iterator L=List.begin(); L!=List.end(); L++) ToParse.push(*L); ToParse_Total+=List.size(); if (ToParse_Total) State=ToParse_AlreadyDone*10000/ToParse_Total; else State=10000; CS.Leave(); //Parsing if (BlockMethod==1) { CS.Enter(); if (!IsRunning()) //If already created, the routine will read the new files { RunAgain(); IsInThread=true; } CS.Leave(); return 0; } else { Entry(); //Normal parsing return Count_Get(); } }
//--------------------------------------------------------------------------- void File_Y4m::FileHeader_Parse() { //Parsing Ztring Header; Get_Local(HeaderEnd, Header, "Data"); ZtringList List; List.Separator_Set(0, " "); List.Write(Header); int64u Width=0, Height=0, Multiplier=0, Divisor=1; float64 FrameRate=0; for (size_t Pos=1; Pos<List.size(); Pos++) { if (!List[Pos].empty()) { switch (List[Pos][0]) { case 'A' : //Pixel aspect ratio { ZtringList Value; Value.Separator_Set(0, ":"); Value.Write(List[Pos].substr(1)); if (Value.size()==2) { float64 x=Value[0].To_float64(); float64 y=Value[1].To_float64(); if (x && y) Fill(Stream_Video, 0, Video_PixelAspectRatio, x/y, 3); } } break; case 'C' : //Color space if (List[Pos]==__T("C420jpeg") || List[Pos]==__T("C420paldv") || List[Pos]==__T("C420")) { Fill(Stream_Video, 0, Video_ChromaSubsampling, "4:2:0"); Multiplier=3; Divisor=2; } if (List[Pos]==__T("C422")) { Fill(Stream_Video, 0, Video_ChromaSubsampling, "4:2:2"); Multiplier=2; } if (List[Pos]==__T("C444")) { Fill(Stream_Video, 0, Video_ChromaSubsampling, "4:4:4"); Multiplier=3; } break; case 'F' : //Frame rate { ZtringList Value; Value.Separator_Set(0, ":"); Value.Write(List[Pos].substr(1)); if (Value.size()==2) { float64 N=Value[0].To_float64(); float64 D=Value[1].To_float64(); if (N && D) { FrameRate=N/D; Fill(Stream_Video, 0, Video_FrameRate, FrameRate, 3); } } } break; case 'H' : //Height { Ztring Value=List[Pos].substr(1); Height=Value.To_int64u(); Fill(Stream_Video, 0, Video_Height, Height); break; } break; case 'I' : //Interlacing if (List[Pos].size()==2) switch (List[Pos][1]) { case 'p' : Fill(Stream_Video, 0, Video_ScanType, "Progressive"); break; case 't' : Fill(Stream_Video, 0, Video_ScanType, "Progressive"); Fill(Stream_Video, 0, Video_ScanOrder, "TFF"); break; case 'b' : Fill(Stream_Video, 0, Video_ScanType, "Progressive"); Fill(Stream_Video, 0, Video_ScanOrder, "BFF"); break; case 'm' : Fill(Stream_Video, 0, Video_ScanType, "Mixed"); break; default : ; } break; case 'W' : //Width { Ztring Value=List[Pos].substr(1); Width=Value.To_int64u(); Fill(Stream_Video, 0, Video_Width, Width); break; } break; default : ; } } } //Duration (we expect no meta per frame) if (Width && Height && Multiplier) { int64u Frame_ByteSize=6+Width*Height*Multiplier/Divisor; //5 for "FRAME\0" Fill(Stream_Video, 0, Video_FrameCount, File_Size/Frame_ByteSize); if (FrameRate) Fill(Stream_Video, 0, Video_BitRate, Width*Height*Multiplier/Divisor*8*FrameRate); } Finish(); }
//--------------------------------------------------------------------------- void File__Analyze::Fill (stream_t StreamKind, size_t StreamPos, const char* Parameter, const Ztring &Value, bool Replace) { //Integrity if (StreamKind>Stream_Max || Parameter==NULL || Parameter[0]=='\0') return; //Handling values with \r\n inside if (Value.find(_T('\r'))!=string::npos || Value.find(_T('\n'))!=string::npos) { Ztring NewValue=Value; NewValue.FindAndReplace(_T("\r\n"), _T(" / "), 0, Ztring_Recursive); NewValue.FindAndReplace(_T("\r"), _T(" / "), 0, Ztring_Recursive); NewValue.FindAndReplace(_T("\n"), _T(" / "), 0, Ztring_Recursive); if (NewValue.size()>=3 && NewValue.rfind(_T(" / "))==NewValue.size()-3) NewValue.resize(NewValue.size()-3); Fill(StreamKind, StreamPos, Parameter, NewValue, Replace); return; } //Handle Value before StreamKind if (StreamKind==Stream_Max || StreamPos>=(*Stream)[StreamKind].size()) { ZtringList NewList; NewList.push_back(Ztring().From_UTF8(Parameter)); NewList.push_back(Value); Fill_Temp.push_back(NewList); return; //No streams } //Handling of well known parameters size_t Pos=MediaInfoLib::Config.Info_Get(StreamKind).Find(Ztring().From_Local(Parameter)); if (Pos!=Error) { Fill(StreamKind, StreamPos, Pos, Value, Replace); return; } //Handling of unknown parameters if (Value.empty()) { if (!Replace) { size_t Pos=(*Stream_More)[StreamKind][StreamPos].Find(Ztring().From_UTF8(Parameter), Info_Name); if (Pos!=(size_t)-1) (*Stream_More)[StreamKind][StreamPos][Pos].clear(); //Empty value --> clear other values } } else { Ztring &Target=(*Stream_More)[StreamKind][StreamPos](Ztring().From_UTF8(Parameter), Info_Text); if (Target.empty() || Replace) { Target=Value; //First value (*Stream_More)[StreamKind][StreamPos](Ztring().From_UTF8(Parameter), Info_Options)=_T("Y NT"); } else { Target+=MediaInfoLib::Config.TagSeparator_Get(); Target+=Value; } } }
//--------------------------------------------------------------------------- void File_Ptx::Read_Buffer_Continue() { if (File_Offset || Buffer_Offset) { if (Buffer_Size) Reject(); //Problem return; } //Parsing ZtringList Names; Ztring LibraryName, LibraryVersion, Format, Directory; int32u LibraryName_Length, LibraryVersion_Length, LibraryRelease_Length, Format_Length, Platform_Length, Info_Count, Names_Count, Info_Length, Name_Length, FileName_Count, Directory_Length; int32u Unknown_Length; int16u Audio_Count; Element_Begin1("Header"); Skip_B1( "Magic"); Skip_Local(16, "Magic"); Skip_L2( "0x0500"); Skip_L1( "Unknown"); Skip_L1( "0x5A"); Skip_L2( "0x0001"); Skip_L2( "0x0004"); Skip_L2( "0x0000"); Skip_L4( "Unknown"); Skip_L2( "0x035A"); Skip_L2( "0x6400"); Skip_L2( "0x0000"); Skip_L2( "0x0300"); Skip_L2( "0x0000"); Get_L4 (LibraryName_Length, "WritingLibrary name length"); Get_UTF8(LibraryName_Length, LibraryName, "Library name"); Skip_L4( "0x00000003"); Skip_L4( "Library version, major"); Skip_L4( "Library version, minor"); Skip_L4( "Library version, revision"); Get_L4 (LibraryVersion_Length, "Library version length"); Get_UTF8(LibraryVersion_Length, LibraryVersion, "Library version"); Skip_L1( "0x01"); Get_L4 (LibraryRelease_Length, "Library release length"); Skip_UTF8(LibraryRelease_Length, "Library release"); Skip_L1( "0x00"); Get_L4 (Format_Length, "Format length"); Get_UTF8(Format_Length, Format, "Format"); if (Format!=__T("Pro Tools Session File")) { Element_End(); Reject("Ptx"); return; } Skip_L2( "0x0006"); Get_L4 (Platform_Length, "Platform length"); Skip_UTF8(Platform_Length, "Platform"); Skip_L4( "0x00000000"); Skip_L4( "0x00085A05"); Skip_L4( "Unknown"); Skip_L4( "0x00002067"); Skip_L4( "0x002A0000"); Skip_L4( "Unknown"); Skip_L4( "Unknown"); Skip_L4( "Unknown"); Element_End(); Element_Begin1("Info list"); Get_L4 (Info_Count, "Info count"); if (4*Info_Count>Element_Size) { Element_End(); Reject(); return; } for (int32u Pos=0; Pos<Info_Count; Pos++) { Element_Begin1("Info"); Get_L4 (Info_Length, "Info length"); if (Info_Length) { Info_UTF8(Info_Length, Info, "Name"); Element_Info1(Info); } Element_End(); } Element_End(); Element_Begin1("Unknown"); Skip_L4( "0x00000000"); Element_Begin1("Names list 1"); Get_L4 (Names_Count, "Names count minus 1"); if (4*Names_Count>Element_Size) { Element_End(); Reject(); return; } for (int16u Pos=0; Pos<1+Names_Count; Pos++) { Element_Begin1("Name"); Get_L4 (Name_Length, "Name length"); if (Name_Length) { Info_UTF8(Name_Length, Name, "Name"); Element_Name(Name); } Element_End(); } Element_End(); Skip_L4( "0x00000000"); Skip_L4( "0x0000002A"); Skip_L4( "Unknown"); Skip_L4( "Unknown"); Element_Begin1("Names list 2"); Get_L4 (Names_Count, "Names count"); if (4*Names_Count>Element_Size) { Element_End(); Reject(); return; } for (int16u Pos=0; Pos<Names_Count; Pos++) { Element_Begin1("Name"); Get_L4 (Name_Length, "Name length"); if (Name_Length) { Info_UTF8(Name_Length, Name, "Name"); Element_Name(Name); } Element_End(); } Element_End(); Skip_L4( "0x00000000"); Skip_L4( "0x0000002A"); Skip_L4( "Unknown"); Skip_L4( "Unknown"); Skip_L4( "0x00000000"); Skip_L4( "Unknown"); Skip_L4( "0x00000101"); Skip_L4( "0x00055A00"); Skip_L4( "Unknown"); Skip_L4( "0x00012519"); Skip_L4( "0x00000000"); Skip_L4( "0x00000000"); Skip_L4( "0x00000001"); Skip_L2( "0x0003"); Element_End(); Get_L2 (Audio_Count, "Audio count"); if (111*Audio_Count>Element_Size) { Reject(); return; } Element_Begin1("Audio tracks list 1"); for (int16u Pos=0; Pos<Audio_Count; Pos++) { Element_Begin1("Name"); Skip_L4( "0x00000000"); Get_L4 (Unknown_Length, "Name length"); Info_UTF8(Unknown_Length, Name, "Name"); Skip_L2( "0x0000"); Skip_L4( "0x00000000"); Skip_L4( "0x0000002A"); Skip_L4( "Unknown (same 1/2/3)"); Skip_L4( "Unknown (same 1/2/3)"); Info_L1(Number, "Ordered number"); Element_Info1(Number); Element_Info1(Name); Element_End(); Names.push_back(Name); } Element_End(); Skip_L2( "0x0000"); Element_Begin1("Audio tracks list 2"); for (int16u Pos=0; Pos<Audio_Count; Pos++) { Element_Begin1("Name"); int32u Size; Skip_L3( "0x00025A"); Get_L4 (Size, "Size"); Skip_L4( "0x0000251A"); Get_L4 (Unknown_Length, "Name length"); Info_UTF8(Unknown_Length, Name, "Name"); Skip_L2( "0x0000"); Skip_L4( "0x00000000"); Skip_L4( "0x0000002A"); Skip_L4( "Unknown (same 1/2/3)"); Skip_L4( "Unknown (same 1/2/3)"); Info_L1(Number, "Ordered number"); Element_Info1(Number); Skip_L4( "0x00000000"); Element_Info1(Name); if (Unknown_Length+31!=Size) { Reject(); return; } Element_End(); } Element_End(); Get_L2 (Audio_Count, "Audio count"); if (4*Audio_Count>Element_Size) { Reject(); return; } Skip_L2( "0x00"); Element_Begin1("Audio tracks list 3"); for (int16u Pos=0; Pos<Audio_Count; Pos++) { Element_Begin1("Name"); int32u Size; Skip_L3( "0x00025A"); Get_L4 (Size, "Size"); Skip_L4( "0x0000251A"); Get_L4 (Unknown_Length, "Name length"); Info_UTF8(Unknown_Length, Name, "Name"); Skip_L2( "0x0000"); Skip_L4( "0x00000000"); Skip_L4( "0x0000002A"); Skip_L4( "Unknown (same 1/2/3)"); Skip_L4( "Unknown (same 1/2/3)"); Info_L1(Number, "Ordered number"); Element_Info1(Number); Skip_L4( "0x00000000"); Element_Info1(Name); if (Unknown_Length+31!=Size) { Reject(); return; } Element_End(); } Element_End(); Skip_L2( "0x0000"); Skip_L2( "0x0018"); Skip_L4( "0x00000001"); Skip_L2( "0x0018"); Skip_L4( "0x00000001"); Skip_L2( "0x0001"); Skip_L3( "0x00095A"); Get_L4 (Unknown_Length, "Opaque length"); Skip_XX(Unknown_Length, "Opaque"); Skip_L3( "0x00045A"); Skip_L4( "0x00000016"); Skip_L4( "0x06002026"); Skip_L4( "0x00000000"); Skip_L2( "0x0000"); Skip_L4( "Unknown"); Skip_L4( "Unknown"); Skip_L4( "0x00000000"); Skip_L3( "0x00025A"); Skip_L4( "0x00000015"); Skip_L4( "0x075A2032"); Skip_L4( "0x00000C00"); Skip_L4( "0x01204200"); Skip_L4( "0x01000000"); Skip_L4( "Unknown"); Skip_L4( "0x00025A00"); Skip_L4( "Unknown"); Skip_L4( "Unknown"); Skip_L4( "0x015A0000"); Skip_L4( "Unknown"); Skip_L4( "Unknown"); Skip_L4( "0x01000000"); Get_L4 (FileName_Count, "File name count"); if (13*FileName_Count>Element_Size) { Reject(); return; } Get_L4 (Directory_Length, "Directory length"); Get_UTF8(Directory_Length, Directory, "Directory"); Skip_L4( "0x00000000"); Element_Begin1("File names"); size_t Pos_Offset=0; for (int32u Pos=0; Pos<FileName_Count; Pos++) { Ztring Name; int32u Name_Length, Purpose; Element_Begin1("File names"); Skip_L1( "0x0002"); Skip_L4( "Ordered number except WAV files and -1"); Get_L4 (Name_Length, "Name length"); Get_UTF8(Name_Length, Name, "Name"); Element_Name(Name); Get_C4 (Purpose, "Purpose (e.g. EVAW for .wav files)"); Element_End(); switch (Purpose) { case 0x45564157: if (Pos-Pos_Offset<Names.size() && (Name.find(Names[Pos-Pos_Offset])==0 || Name.find(Names[Pos-Pos_Offset]+__T(".wav"))+5==Name.size())) { File__ReferenceFilesHelper::reference ReferenceFile; ReferenceFile.StreamKind=Stream_Audio; ReferenceFile.FileNames.push_back(Directory+PathSeparator+Name); ReferenceFiles->References.push_back(ReferenceFile); } else if (ReferenceFiles->References.empty()) Pos_Offset++; default: ; } } Element_End(); Skip_XX(Element_Size-Element_Offset, "Unknown"); FILLING_BEGIN(); Accept("Ptx"); //Could be Ptf (former formatn but not supported, so we don't care currently Fill("Ptx"); Fill(Stream_General, 0, General_Format, "Pro Tools Session"); Fill(Stream_General, 0, General_Format_Version, "Version 10"); Fill(Stream_General, 0, General_Encoded_Library_Name, LibraryName); Fill(Stream_General, 0, General_Encoded_Library_Version, LibraryVersion); FILLING_END(); }
//--------------------------------------------------------------------------- void GUI_Main_Core_Table::contextMenuEvent (QContextMenuEvent* Event) { //Retrieving data QTableWidgetItem* Item=itemAt(Event->pos()); if (Item==NULL) return; string FileName=FileName_Before+item(Item->row(), 0)->text().toLocal8Bit().data(); string Field=horizontalHeaderItem(Item->column())->text().toLocal8Bit().data(); ZtringList History; History.Write(C->History(FileName, Field)); Ztring Date; if (Field=="OriginationDate" || Field=="OriginationTime" || Field=="ICRD") { Date=C->FileDate_Get(FileName); if (Date.size()>=10+1+8) { if (Date.size()>=10+1+8) Date.resize(10+1+8); if (Field=="ICRD") Date.insert(0, "&Set ICRD to file creation timestamp ("); //If you change this, change at the end of method too else Date.insert(0, "&Set originationDate and Time to file creation timestamp ("); //If you change this, change at the end of method too Date.append(")"); } else Date.clear(); } //Creating menu QMenu menu(this); //Handling AllFiles display { menu.addAction(new QAction("Fill all open files with this field value", this)); //If you change this, change the test text too menu.addSeparator(); } //Handling Clear display if (!item(Item->row(), Item->column())->text().isEmpty() && C->IsValid(FileName, Field, string())) { menu.addAction(new QAction("Clear this value", this)); //If you change this, change the test text too menu.addSeparator(); } //Handling date display if (!Date.empty()) { menu.addAction(new QAction(QString().fromUtf8(Date.To_Local().c_str()), this)); menu.addSeparator(); } //Handling history display size_t Pos=History.size(); if (!History.empty()) do { Pos--; QString Text=QString().fromUtf8(History[Pos].To_Local().c_str()); if (!Text.isEmpty()) { QAction* Action=new QAction(Text, this); menu.addAction(Action); } } while (Pos>0); //Displaying QAction* Action=menu.exec(Event->globalPos()); if (Action==NULL) return; //Retrieving data QString Text=Action->text(); //Special cases if (Text=="Fill all open files with this field value") //If you change this, change the creation text too { for (int Row=0; Row<rowCount(); Row++) { item(Row, Item->column())->setText(QString().fromUtf8(Ztring(C->Get(FileName, Field)).To_Local().c_str())); dataChanged(indexFromItem(item(Row, Item->column())), indexFromItem(item(Row, Item->column()))); //Special cases if (Field=="UMID" || Field=="LoudnessValue" || Field=="LoudnessRange" || Field=="MaxTruePeakLevel" || Field=="MaxMomentaryLoudness" || Field=="MaxShortTermLoudness") { //Changing BextVersion Enabled value SetText (*Item, "BextVersion"); SetEnabled(*Item, "BextVersion"); } } return; } if (Text=="Clear this value") //If you change this, change the creation text too Text.clear(); //Filling if (Text.contains("&Set ")) //If you change this, change the creation text too { Text=Text.remove("&Set ICRD to file creation timestamp ("); //If you change this, change the creation text too Text=Text.remove("&Set originationDate and Time to file creation timestamp ("); //If you change this, change the creation text too Text=Text.remove(")"); //If you change this, change the creation text too if (horizontalHeaderItem(Item->column())->text()==QString().fromUtf8("ICRD")) { item(Item->row(), Item->column())->setText(Text); dataChanged(indexFromItem(item(Item->row(), Item->column())), indexFromItem(item(Item->row(), Item->column()))); } else { QString Date=Text; Date.remove(10, 1+12); QString Time=Text; Time.remove(0, 10+1); Time.remove(8, 4); int Date_Pos=Item->column()+(horizontalHeaderItem(Item->column())->text()==QString().fromUtf8("OriginationDate")?0:-1); int Time_Pos=Item->column()+(horizontalHeaderItem(Item->column())->text()==QString().fromUtf8("OriginationTime")?0:1); item(Item->row(), Date_Pos)->setText(Date); dataChanged(indexFromItem(item(Item->row(), Date_Pos)), indexFromItem(item(Item->row(), Date_Pos))); item(Item->row(), Time_Pos)->setText(Time); dataChanged(indexFromItem(item(Item->row(), Time_Pos)), indexFromItem(item(Item->row(), Time_Pos))); } } else { item(Item->row(), Item->column())->setText(Text); dataChanged(indexFromItem(item(Item->row(), Item->column())), indexFromItem(item(Item->row(), Item->column()))); } //Menu Main->Menu_Update(); }
//--------------------------------------------------------------------------- size_t Reader_libcurl::Format_Test(MediaInfo_Internal* MI, const String &File_Name) { #if defined MEDIAINFO_LIBCURL_DLL_RUNTIME if (libcurl_Module_Count==0) return 0; //No libcurl library #endif //defined MEDIAINFO_LIBCURL_DLL_RUNTIME //Configuring curl_data Curl_Data; Curl_Data.Curl=curl_easy_init(); Curl_Data.MI=MI; Curl_Data.File_Name=File_Name; string FileName_String=Ztring(Curl_Data.File_Name).To_Local(); if (MI->Config.File_TimeToLive_Get()) Curl_Data.Time_Max=time(0)+(time_t)MI->Config.File_TimeToLive_Get(); if (!MI->Config.File_Curl_Get(_T("UserAgent")).empty()) curl_easy_setopt(Curl_Data.Curl, CURLOPT_USERAGENT, MI->Config.File_Curl_Get(_T("UserAgent")).To_Local().c_str()); if (!MI->Config.File_Curl_Get(_T("Proxy")).empty()) curl_easy_setopt(Curl_Data.Curl, CURLOPT_PROXY, MI->Config.File_Curl_Get(_T("Proxy")).To_Local().c_str()); struct curl_slist* HttpHeader=NULL; if (!MI->Config.File_Curl_Get(_T("HttpHeader")).empty()) { ZtringList HttpHeaderStrings; HttpHeaderStrings.Separator_Set(0, EOL); //End of line is set depending of the platform: \n on Linux, \r on Mac, or \r\n on Windows HttpHeaderStrings.Write(MI->Config.File_Curl_Get(_T("HttpHeader"))); for (size_t Pos=0; Pos<HttpHeaderStrings.size(); Pos++) curl_slist_append(HttpHeader, HttpHeaderStrings[Pos].To_Local().c_str()); curl_easy_setopt(Curl_Data.Curl, CURLOPT_HTTPHEADER, HttpHeader); } curl_easy_setopt(Curl_Data.Curl, CURLOPT_URL, FileName_String.c_str()); curl_easy_setopt(Curl_Data.Curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(Curl_Data.Curl, CURLOPT_MAXREDIRS, 3); curl_easy_setopt(Curl_Data.Curl, CURLOPT_WRITEFUNCTION, &libcurl_WriteData_CallBack); curl_easy_setopt(Curl_Data.Curl, CURLOPT_WRITEDATA, &Curl_Data); //Parsing CURLcode Result; do { //GoTo if (Curl_Data.File_GoTo!=(int64u)-1) { #ifdef MEDIAINFO_DEBUG std::cout<<std::hex<<Curl_Data.File_Offset-Curl_Data.Debug_BytesRead<<" - "<<Curl_Data.File_Offset<<" : "<<std::dec<<Curl_Data.Debug_BytesRead<<" bytes"<<std::endl; Curl_Data.Debug_BytesRead=0; Curl_Data.Debug_Count++; #endif //MEDIAINFO_DEBUG Curl_Data.File_Offset=Curl_Data.File_GoTo; if (Curl_Data.File_GoTo<0x80000000) { //We do NOT use large version if we can, because some version (tested: 7.15 linux) do NOT like large version (error code 18) long File_GoTo_Long=(long)Curl_Data.File_GoTo; curl_easy_setopt(Curl_Data.Curl, CURLOPT_RESUME_FROM, File_GoTo_Long); } else { curl_off_t File_GoTo_Off=(curl_off_t)Curl_Data.File_GoTo; curl_easy_setopt(Curl_Data.Curl, CURLOPT_RESUME_FROM_LARGE, File_GoTo_Off); } MI->Open_Buffer_Init((int64u)-1, Curl_Data.File_GoTo); Curl_Data.File_GoTo=(int64u)-1; } //Parsing Result=curl_easy_perform(Curl_Data.Curl); } while (Result==CURLE_WRITE_ERROR && Curl_Data.File_GoTo!=(int64u)-1); #ifdef MEDIAINFO_DEBUG std::cout<<std::hex<<Curl_Data.File_Offset-Curl_Data.Debug_BytesRead<<" - "<<Curl_Data.File_Offset<<" : "<<std::dec<<Curl_Data.Debug_BytesRead<<" bytes"<<std::endl; std::cout<<"Total: "<<std::dec<<Curl_Data.Debug_BytesRead_Total<<" bytes in "<<Curl_Data.Debug_Count<<" blocks"<<std::endl; #endif //MEDIAINFO_DEBUG MI->Open_Buffer_Finalize(); //Cleanup if (HttpHeader) curl_slist_free_all(HttpHeader); curl_easy_cleanup(Curl_Data.Curl); return 1; }
//--------------------------------------------------------------------------- bool File_Hls::FileHeader_Begin() { //Element_Size if (File_Size>1024*1024 || File_Size<10) { Reject("HLS"); return false; //HLS files are not big } if (Buffer_Size<File_Size) return false; //Wait for complete file Ztring Document; Document.From_UTF8((char*)Buffer, Buffer_Size); ZtringList Lines; size_t LinesSeparator_Pos=Document.find_first_of(__T("\r\n")); if (LinesSeparator_Pos>File_Size-1) { Reject("HLS"); return false; } Ztring LinesSeparator; if (Document[LinesSeparator_Pos]==__T('\r') && LinesSeparator_Pos+1<Document.size() && Document[LinesSeparator_Pos+1]==__T('\n')) LinesSeparator=__T("\r\n"); else if (Document[LinesSeparator_Pos]==__T('\r')) LinesSeparator=__T("\r"); else if (Document[LinesSeparator_Pos]==__T('\n')) LinesSeparator=__T("\n"); else { Reject("HLS"); return false; } Lines.Separator_Set(0, LinesSeparator); Lines.Write(Document); if (Lines(0)!=__T("#EXTM3U")) { Reject("HLS"); return false; } Accept("HLS"); Fill(Stream_General, 0, General_Format, "HLS"); ReferenceFiles=new File__ReferenceFilesHelper(this, Config); if (!IsSub) ReferenceFiles->ContainerHasNoId=true; File__ReferenceFilesHelper::reference ReferenceFile; bool IsGroup=false; for (size_t Line=0; Line<Lines.size(); Line++) { if (!Lines[Line].empty()) { if (Lines[Line].find(__T("#EXT-X-KEY:"))==0) { ZtringListList List; List.Separator_Set(0, __T(",")); List.Separator_Set(1, __T("=")); List.Write(Lines[Line].substr(11, string::npos)); for (size_t Pos=0; Pos<List.size(); ++Pos) { if (List[Pos](0)==__T("METHOD")) { if (List[Pos](1).find(__T("AES-128"))==0) { Fill(Stream_General, 0, General_Encryption_Format, "AES"); Fill(Stream_General, 0, General_Encryption_Length, "128"); Fill(Stream_General, 0, General_Encryption_Method, "Segment"); Fill(Stream_General, 0, General_Encryption_Mode, "CBC"); Fill(Stream_General, 0, General_Encryption_Padding, "PKCS7"); Fill(Stream_General, 0, General_Encryption_InitializationVector, "Sequence number"); #if MEDIAINFO_AES //Trying to get the key from FileName.FileExt.key if (Config->Encryption_Key_Get().empty()) { File KeyFile; if (KeyFile.Open(File_Name+__T(".key"))) { if (KeyFile.Size_Get()==16) { int8u Key[16]; if (KeyFile.Read(Key, 16)==16) Config->Encryption_Key_Set(Key, 16); } else Fill(Stream_General, 0, "Encryption_Key_Problem", KeyFile.Size_Get()); } } #endif } Fill(Stream_General, 0, General_Encryption, List[Pos](1)); } } } else if (Lines[Line].find(__T("#EXT-X-STREAM-INF:"))==0) { IsGroup=true; } else if (Lines[Line][0]==__T('#')) ; else { if (IsGroup) { ReferenceFile.FileNames.push_back(Lines[Line]); ReferenceFile.StreamID=ReferenceFiles->References.size()+1; ReferenceFiles->References.push_back(ReferenceFile); IsGroup=false; ReferenceFile=File__ReferenceFilesHelper::reference(); #if MEDIAINFO_EVENTS ParserIDs[0]=MediaInfo_Parser_HlsIndex; StreamIDs_Width[0]=sizeof(size_t); #endif //MEDIAINFO_EVENTS } else ReferenceFile.FileNames.push_back(Lines[Line]); } } } if (!ReferenceFile.FileNames.empty()) { ReferenceFiles->References.push_back(ReferenceFile); Fill(Stream_General, 0, General_Format_Profile, "Media"); } else { Fill(Stream_General, 0, General_Format_Profile, "Master"); } Element_Offset=File_Size; //All should be OK... return true; }
//--------------------------------------------------------------------------- // Operator == bool ZtringList::operator== (const ZtringList &Source) const { return (Read()==Source.Read()); }
//--------------------------------------------------------------------------- void File_Ptx::Read_Buffer_Continue() { if (File_Offset || Buffer_Offset) { if (Buffer_Size) Reject(); //Problem return; } //Parsing ZtringList Names; Ztring LibraryName, LibraryVersion, Format, Directory; int32u LibraryName_Length, LibraryVersion_Length, LibraryRelease_Length, Format_Length, Platform_Length, Info_Count, Names_Count, Info_Length, Name_Length, FileName_Count, Directory_Length; int32u Opaque2_Length, Audio_Count; int16u Opaque1_Length; Element_Begin1("Header"); Skip_B1( "Magic"); Skip_Local(16, "Magic"); Skip_L2( "0x0500"); Skip_L1( "Unknown [1]"); Skip_L1( "0x5A [1]"); Skip_L2( "0x0001"); Skip_L2( "0x0004"); Skip_L2( "0x0000 [1]"); Skip_L4( "Unknown [2]"); Skip_L2( "0x035A"); Skip_L2( "0x6400"); Skip_L2( "0x0000 [1]"); Skip_L2( "0x0300"); Skip_L2( "0x0000 [1]"); Get_L4 (LibraryName_Length, "WritingLibrary name length"); Get_UTF8(LibraryName_Length, LibraryName, "Library name"); Skip_L4( "0x00000003"); Skip_L4( "Library version, major"); Skip_L4( "Library version, minor"); Skip_L4( "Library version, revision"); Get_L4 (LibraryVersion_Length, "Library version length"); Get_UTF8(LibraryVersion_Length, LibraryVersion, "Library version"); Skip_L1( "0x01"); Get_L4 (LibraryRelease_Length, "Library release length"); Skip_UTF8(LibraryRelease_Length, "Library release"); Skip_L1( "0x00 [1]"); Get_L4 (Format_Length, "Format length"); Get_UTF8(Format_Length, Format, "Format"); if (Format!=__T("Pro Tools Session File")) { Element_End(); Reject(); return; } Skip_L2( "0x0006"); Get_L4 (Platform_Length, "Platform length"); Skip_UTF8(Platform_Length, "Platform"); Skip_L4( "0x00000000"); Skip_L2( "0x5A05"); Get_L2 (Opaque1_Length, "Info list, Opaque length"); //0x0006 (10.2-) or 0x0008 (10.3+) Skip_L4( "Unknown [3]"); Skip_L4( "0x00002067"); Skip_L2( "0x0000 [1]"); Skip_L2( "0x0000 (once) or 0x002A"); Skip_L2( "0x0000 [1]"); Skip_L2( "Unknown [4]"); Skip_L4( "Unknown [5]"); Skip_L4( "Unknown [6]"); Element_End(); Element_Begin1("Info list"); Get_L4 (Info_Count, "Info count"); if (4*Info_Count>Element_Size) { Element_End(); Reject(); return; } for (int32u Pos=0; Pos<Info_Count; Pos++) { Element_Begin1("Info"); Get_L4 (Info_Length, "Info length"); if (Info_Length) { Info_UTF8(Info_Length, Info, "Name"); Element_Info1(Info); } Element_End(); } Element_End(); Element_Begin1("Unknown"); Skip_L4( "0x00000000"); Element_Begin1("Names list 1"); Get_L4 (Names_Count, "Names count minus 1"); if (4*Names_Count>Element_Size) { Element_End(); Reject(); return; } for (int16u Pos=0; Pos<1+Names_Count; Pos++) { Element_Begin1("Name"); Get_L4 (Name_Length, "Name length"); if (Name_Length) { Info_UTF8(Name_Length, Name, "Name"); Element_Name(Name); } Element_End(); } Element_End(); Skip_L4( "0x00000000"); Skip_L4( "0x00000000 or 0x0000002A"); Skip_L4( "Unknown [7]"); Skip_L4( "Unknown [8]"); Element_Begin1("Names list 2"); Get_L4 (Names_Count, "Names count"); if (4*Names_Count>Element_Size) { Element_End(); Reject(); return; } for (int16u Pos=0; Pos<Names_Count; Pos++) { Element_Begin1("Name"); Get_L4 (Name_Length, "Name length"); if (Name_Length) { Info_UTF8(Name_Length, Name, "Name"); Element_Name(Name); } Element_End(); } Element_End(); Skip_L4( "0x00000000"); Skip_L4( "0x0000002A [1]"); Skip_L4( "Unknown [9]"); Skip_L4( "Unknown [10]"); Skip_L4( "0x00000000"); Skip_L1( "0x00 or 0x01 [2]"); Skip_L1( "0x01"); Skip_L1( "0x00 or 0x01 or 0x02"); Skip_L1( "0x00 [2]"); Skip_L1( "0x01"); Skip_L1( "0x00 (once) or 0x01"); Skip_L1( "0x00 or 0x01 (once)"); Skip_L1( "0x00 or 0x01 (once) or 0x5A"); if (Opaque1_Length<6) { if (Opaque1_Length) Skip_XX(Opaque1_Length, "Opaque1"); } else { Skip_L4( "Opaque1 - Unknown [1]"); Skip_L2( "Opaque1 - Unknown [2]"); if (Opaque1_Length<8) { if (Opaque1_Length-6) Skip_XX(Opaque1_Length-6, "Opaque1 - Unknown [3]"); } else { Skip_L2( "Opaque1 - 0x0000"); if (Opaque1_Length>8) Skip_XX(Opaque1_Length-8, "Opaque1 - Unknown [3]"); } } Skip_L2( "0x2519"); Skip_L2( "0x0001"); Skip_L4( "0x00000000 or B5112287"); Skip_L4( "0x00000000 or 4037F9DC"); Skip_L4( "0x00000001 [1]"); Skip_L2( "0x0003"); Element_End(); Get_L4 (Audio_Count, "Audio count"); if (111*Audio_Count>Element_Size) { Reject(); return; } Element_Begin1("Audio tracks list 1"); for (int16u Pos=0; Pos<Audio_Count; Pos++) { Element_Begin1("Name"); Skip_L2( "0x0000 [New]"); Get_L4 (Name_Length, "(Same 1/2/3) Name length"); Info_UTF8(Name_Length, Name, "(Same 1/2/3) Name"); Skip_L2( "(Same 1/2/3) 0x0000 "); Skip_L4( "(Same 1/2/3) 0x00000000"); Skip_L4( "(Same 1/2/3) 0x0000002A"); Skip_L4( "(Same 1/2/3) Unknown"); Skip_L4( "(Same 1/2/3) Unknown"); Info_L3(Number, "(Same 1/2/3) Ordered number"); Element_Info1(Number); Element_Info1(Name); Element_End(); if (Name==__T("Lf")) //Exception? Typo? Name=__T("Lfe"); Name.MakeLowerCase(); Names.push_back(Name); } Element_End(); Element_Begin1("Audio tracks list 2"); for (int16u Pos=0; Pos<Audio_Count; Pos++) { Element_Begin1("Name"); int32u Size; Skip_L3( "(Same 2/3) 0x00025A [1]"); Get_L4 (Size, "(Same 2/3) Size"); Skip_L4( "(Same 2/3) 0x0000251A"); Get_L4 (Name_Length, "(Same 1/2/3) Name length"); Info_UTF8(Name_Length, Name, "(Same 1/2/3) Name"); Skip_L2( "(Same 1/2/3) 0x0000 "); Skip_L4( "(Same 1/2/3) 0x00000000"); Skip_L4( "(Same 1/2/3) 0x0000002A"); Skip_L4( "(Same 1/2/3) Unknown"); Skip_L4( "(Same 1/2/3) Unknown"); Info_L3(Number, "(Same 1/2/3) Ordered number"); Element_Info1(Number); Skip_L2( "(Same 2/3) 0x0000"); Element_Info1(Name); if (Name_Length+31!=Size) { Element_End(); Element_End(); Reject(); return; } Element_End(); } Element_End(); Get_L4 (Audio_Count, "Audio count"); if (4*Audio_Count>Element_Size) { Reject(); return; } Element_Begin1("Audio tracks list 3"); for (int16u Pos=0; Pos<Audio_Count; Pos++) { Element_Begin1("Name"); int32u Size; Skip_L3( "(Same 2/3) 0x00025A [2]"); Get_L4 (Size, "(Same 2/3) Size"); if (Size>0x10000) { Element_End(); Element_End(); Reject(); return; } Skip_L4( "(Same 2/3) 0x0000251A"); Get_L4 (Name_Length, "(Same 1/2/3) Name length"); Info_UTF8(Name_Length, Name, "(Same 1/2/3) Name"); Skip_L2( "(Same 1/2/3) 0x0000 "); Skip_L4( "(Same 1/2/3) 0x00000000"); Skip_L4( "(Same 1/2/3) 0x0000002A"); Skip_L4( "(Same 1/2/3) Unknown"); Skip_L4( "(Same 1/2/3) Unknown"); Info_L3(Number, "(Same 1/2/3) Ordered number"); Element_Info1(Number); Skip_L2( "(Same 2/3) 0x0000"); Element_Info1(Name); if (Name_Length+31!=Size) { Element_End(); Element_End(); Reject(); return; } Element_End(); } Element_End(); Skip_L2( "0x0000 [4]"); Skip_L2( "0x0018"); Skip_L4( "0x00000001 [2]"); Skip_L2( "0x0018"); Skip_L4( "0x00000001 [2]"); Skip_L2( "0x0001 [3]"); Skip_L3( "0x00095A"); Get_L4 (Opaque2_Length, "Opaque2 length"); Skip_XX(Opaque2_Length, "Opaque2"); Skip_L1( "0x5A [2]"); Skip_L2( "0x0003 (10.0) or 0x0004 (10.2+)"); Get_L4 (Opaque2_Length, "Opaque3 length"); //0x0012 (10.0) or 0x0016 (10.2+) if (Opaque2_Length<0x12) Skip_XX(Opaque2_Length, "Opaque3"); else { Skip_L4( "Opaque3 - 0x06002026"); Skip_L4( "Opaque3 - 0x00000000 [1]"); Skip_L2( "Opaque3 - 0x0000"); Skip_L4( "Opaque3 - Unknown [1]"); Skip_L4( "Opaque3 - Unknown [2]"); if (Opaque2_Length<0x16) { if (Opaque2_Length-0x12) Skip_XX(Opaque2_Length-0x12, "Opaque3 - Unknown [3]"); } else { Skip_L4( "Opaque3 - 0x00000000 [2]"); if (Opaque2_Length>0x16) Skip_XX(Opaque2_Length-0x16, "Opaque3 - Unknown [4]"); } } Skip_L3( "0x00025A [3]"); Get_L4 (Opaque2_Length, "0x00000015 (Opaque4 length?) or something else"); if (Opaque2_Length==0x00000015) { Skip_L4( "0x075A2032"); Skip_L4( "0x00000C00"); Skip_L4( "0x01204200"); Skip_L4( "0x00000000 or 0x01000000"); Skip_L4( "Unknown [13]"); Skip_L1( "0x00 [3]"); Skip_L3( "0x00025A [4]"); Skip_L4( "Unknown [14]"); } Skip_L4( "Unknown [15]"); Skip_L4( "0x015A0000"); Skip_L4( "Unknown [16]"); Skip_L4( "Unknown [17]"); Skip_L4( "0x01000000"); Get_L4 (FileName_Count, "File name count"); if (13*FileName_Count>Element_Size) { Reject(); return; } Get_L4 (Directory_Length, "Directory length"); Get_UTF8(Directory_Length, Directory, "Directory"); Skip_L4( "0x00000000 [11]"); Element_Begin1("File names"); vector<int8u> Roles; vector<Ztring> FileNames; vector<Ztring> FileNamesLowerCase; vector<int32u> Purposes; for (int32u Pos=0; Pos<FileName_Count; Pos++) { Ztring FileName; int32u FileName_Length, Purpose; int8u Role; // Element_Begin1("File names"); Get_L1 (Role, "role? (0x02 for WAV files)"); Skip_L4( "Ordered number except WAV files and -1"); Get_L4 (FileName_Length, "File Name length"); Get_UTF8(FileName_Length, FileName, "File Name"); Element_Name(FileName); Get_C4 (Purpose, "Purpose (e.g. EVAW for .wav files)"); //Found 1 .wav file without "EWAV". Element_End(); Roles.push_back(Role); FileNames.push_back(FileName); FileName.MakeLowerCase(); FileNamesLowerCase.push_back(FileName); Purposes.push_back(Purpose); } Element_End(); Skip_XX(Element_Size-Element_Offset, "Unknown"); FILLING_BEGIN(); Accept("Ptx"); //Could be Ptf (former format but not supported, so we don't care currently) Fill("Ptx"); Fill(Stream_General, 0, General_Format, "Pro Tools Session"); Fill(Stream_General, 0, General_Format_Version, "Version 10"); Fill(Stream_General, 0, General_Encoded_Library_Name, LibraryName); Fill(Stream_General, 0, General_Encoded_Library_Version, LibraryVersion); // Role==2 + Purpose==EWAV + listed if (Names.size()>1 || FileNames.size()==1) { size_t Pos_Offset=0; for (int32u Pos=0; Pos<FileName_Count; Pos++) { if (Roles[Pos]==0x02 && Purposes[Pos]==0x45564157 //"EWAV" && Pos-Pos_Offset<Names.size() && FileNames[Pos]!=__T("1 kHz @ -20dB.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("1k@0vu -20.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos].find(__T(".1Khz.wav"))==string::npos //Exception? && FileNames[Pos].find(__T("_1KTONE_"))==string::npos //Exception? && FileNamesLowerCase[Pos].find(Names[Pos-Pos_Offset]+__T(".wav"))!=string::npos && FileNamesLowerCase[Pos].find(Names[Pos-Pos_Offset]+__T(".wav"))+Names[Pos-Pos_Offset].size()+4==FileNames[Pos].size()) { sequence* Sequence=new sequence; Sequence->StreamKind=Stream_Audio; Sequence->AddFileName(Directory+PathSeparator+FileNames[Pos]); ReferenceFiles->AddSequence(Sequence); } else if (!ReferenceFiles->Sequences_Size()) Pos_Offset++; } if (Names.size()!=ReferenceFiles->Sequences_Size()) ReferenceFiles->Clear(); //Failed to detect correctly } // Role==2 + listed if (!ReferenceFiles->Sequences_Size() && (Names.size()>1 || FileNames.size()==1)) { size_t Pos_Offset=0; for (int32u Pos=0; Pos<FileName_Count; Pos++) { if (Roles[Pos]==0x02 && Pos-Pos_Offset<Names.size() && FileNames[Pos]!=__T("1 kHz @ -20dB.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("1k@0vu -20.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos].find(__T(".1Khz.wav"))==string::npos //Exception? && FileNames[Pos].find(__T("_1KTONE_"))==string::npos) //Exception? { Ztring FileName=FileNames[Pos]; Ztring Name=Names[Pos-Pos_Offset]; FileName.MakeLowerCase(); Name.MakeLowerCase(); if (FileName.find(Name)==0 || FileName.find(Name+__T(".wav"))+5==Name.size()) { sequence* Sequence=new sequence; Sequence->StreamKind=Stream_Audio; Sequence->AddFileName(Directory+PathSeparator+FileNames[Pos]); ReferenceFiles->AddSequence(Sequence); } else if (!ReferenceFiles->Sequences_Size()) Pos_Offset++; } else if (!ReferenceFiles->Sequences_Size()) Pos_Offset++; } if (Names.size()!=ReferenceFiles->Sequences_Size()) ReferenceFiles->Clear(); //Failed to detect correctly } // Role==2 + Purpose==EWAV + listed, special case with specific file names if (!ReferenceFiles->Sequences_Size() && (Names.size()>1 || FileNames.size()==1)) { for (int32u Pos=0; Pos<FileName_Count; Pos++) { if (Roles[Pos]==0x02 && Purposes[Pos]==0x45564157 //"EWAV" && FileNames[Pos]!=__T("1 kHz @ -20dB.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("1k@0vu -20.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos].find(__T(".1Khz.wav"))==string::npos //Exception? && FileNames[Pos].find(__T("_1KTONE_"))==string::npos) //Exception? { for (int32u Pos2=0; Pos2<Names.size(); Pos2++) if (FileNamesLowerCase[Pos].find(Names[Pos2])==0) { sequence* Sequence=new sequence; Sequence->StreamKind=Stream_Audio; Sequence->AddFileName(Directory+PathSeparator+FileNames[Pos]); ReferenceFiles->AddSequence(Sequence); break; } } } } // Role==2 + Purpose==EWAV if (!ReferenceFiles->Sequences_Size()) { for (int32u Pos=0; Pos<FileName_Count; Pos++) { if (Roles[Pos]==0x02 && Purposes[Pos]==0x45564157 //"EWAV" && FileNames[Pos]!=__T("1 kHz @ -20dB.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("1k@0vu -20.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos].find(__T(".1Khz.wav"))==string::npos //Exception? && FileNames[Pos].find(__T("_1KTONE_"))==string::npos) //Exception? { sequence* Sequence=new sequence; Sequence->StreamKind=Stream_Audio; Sequence->AddFileName(Directory+PathSeparator+FileNames[Pos]); ReferenceFiles->AddSequence(Sequence); } } } // Role==2 if (!ReferenceFiles->Sequences_Size()) { for (int32u Pos=0; Pos<FileName_Count; Pos++) { if (Roles[Pos]==0x02 && FileNames[Pos]!=__T("1 kHz @ -20dB.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos]!=__T("1k@0vu -20.wav") //Exception? && FileNames[Pos]!=__T("*****@*****.**") //Exception? && FileNames[Pos].find(__T(".1Khz.wav"))==string::npos //Exception? && FileNames[Pos].find(__T("_1KTONE_"))==string::npos) //Exception? { sequence* Sequence=new sequence; Sequence->StreamKind=Stream_Audio; Sequence->AddFileName(Directory+PathSeparator+FileNames[Pos]); ReferenceFiles->AddSequence(Sequence); } } } FILLING_END(); }