//--------------------------------------------------------------------------- void File_Celt::Comment() { Element_Name("Comment?"); while (Element_Offset<Element_Size) { Ztring value; int32u size; Get_L4(size, "size"); if (size) Get_Local(size, value, "value"); //Filling if (value.find(__T("CELT "))!=std::string::npos) { Ztring Version=value.SubString(__T("CELT "), __T(" (")); Fill(Stream_Audio, 0, Audio_Encoded_Library, __T("CELT ")+Version); Fill(Stream_Audio, 0, Audio_Encoded_Library_Name, __T("CELT")); Fill(Stream_Audio, 0, Audio_Encoded_Library_Version, Version); } else if (!value.empty()) Fill(Stream_Audio, 0, "Comment", value); } Finish("CELT"); }
void MediaInfo_Config_MediaInfo::Event_Send (const int8u* Data_Content, size_t Data_Size, const Ztring &File_Name) { CriticalSectionLocker CSL(CS); if (Event_CallBackFunction) Event_CallBackFunction ((unsigned char*)Data_Content, Data_Size, Event_UserHandler); else { MediaInfo_Event_Generic* Event_Generic=(MediaInfo_Event_Generic*)Data_Content; if ((Event_Generic->EventCode&0x00FFFF00)==(MediaInfo_Event_Global_Demux<<8)) { if (!MediaInfoLib::Config.Demux_Get()) return; if (File_Name.empty()) return; MediaInfo_Event_Global_Demux_0* Event=(MediaInfo_Event_Global_Demux_0*)Data_Content; Ztring File_Name_Final(File_Name); for (size_t Pos=0; Pos<Event->StreamIDs_Size; Pos++) File_Name_Final+=_T(".")+Ztring().From_Number(Event->StreamIDs[Pos], 16); File_Name_Final+=_T(".raw"); File F; F.Open(File_Name_Final, File::Access_Write_Append); F.Write(Event->Content, Event->Content_Size); } } }
//--------------------------------------------------------------------------- // Open an item ZenLib::Ztring Enums_Create_Item(const Ztring &Directory, const Ztring &Name, Ztring &Contents) { Contents.clear(); Ztring Result; //Load header Ztring Partial; Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.2.txt", Partial); if (!Result.empty()) return Result; Partial.FindAndReplace(L"%Name%", Ztring(Name).MakeLowerCase()); Contents+=Partial; //Load line template Ztring Line; Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.5.txt", Line); if (!Result.empty()) return Result; //Read input file ZtringListListF ZLL; ZLL.Load(Ztring(L"../Source/Resource/Text/")+Directory+L"/"+Name+L".csv"); for (size_t Pos=0; Pos<ZLL.size(); Pos++) { Ztring Line_Temp=Line; Line_Temp.FindAndReplace(L"%Name%", Name); Ztring &ToAdd=ZLL(Pos, 0); ToAdd.FindAndReplace(__T("/"), __T("_"), 0, Ztring_Recursive); //C++ does not accept "/" in names ToAdd.FindAndReplace(__T("("), __T("_")); //C++ does not accept "(" in names ToAdd.FindAndReplace(__T(")"), __T("_")); //C++ does not accept ")" in names ToAdd.FindAndReplace(__T("*"), __T("_")); //C++ does not accept "*" in names ToAdd.FindAndReplace(__T("-"), __T("_")); //C++ does not accept "-" in names Line_Temp.FindAndReplace(L"%Line%", ToAdd); Contents+=Line_Temp; } //Load footer template Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.8.txt", Partial); if (!Result.empty()) return Result; Contents+=Partial; return L""; }
Ztring MediaInfo_Config_MediaInfo::File_Duplicate_Set (const Ztring &Value_In) { //Preparing for File__Duplicate... CS.Enter(); File__Duplicate_List.push_back(Value_In); //Handling Memory index Ztring ToReturn; ZtringList List=Value_In; for (size_t Pos=0; Pos<List.size(); Pos++) { //Form= "(-)Data", if "-" the value will be removed Ztring &Value=List[Pos]; bool ToRemove=false; if (Value.find(_T('-'))==0) { Value.erase(Value.begin()); ToRemove=true; } //Testing if this is information about a target if (List[Pos].find(_T("memory:"))==0 || List[Pos].find(_T("file:"))==0) { //Searching if already exist size_t Memory_Pos=File__Duplicate_Memory_Indexes.Find(List[Pos]); if (!ToRemove && Memory_Pos==Error) { //Does not exist yet (and adding is wanted) Memory_Pos=File__Duplicate_Memory_Indexes.Find(_T("")); if (Memory_Pos!=Error) File__Duplicate_Memory_Indexes[Memory_Pos]=List[Pos]; //A free place is found else { //Adding the place at the end Memory_Pos=File__Duplicate_Memory_Indexes.size(); File__Duplicate_Memory_Indexes.push_back(List[Pos]); } } else if (ToRemove) { //Exists yet but Removal is wanted File__Duplicate_Memory_Indexes[Memory_Pos].clear(); Memory_Pos=(size_t)-1; } ToReturn+=_T(";")+Ztring().From_Number(Memory_Pos); } } if (!ToReturn.empty()) ToReturn.erase(ToReturn.begin()); //Remove first ";" CS.Leave(); File_IsSeekable_Set(false); //If duplication, we can not seek anymore return ToReturn; }
//--------------------------------------------------------------------------- void File_Riff::TimeCode_Fill(const Ztring &Name, const Ztring &Value) { if (Value.empty()) return; for (size_t StreamPos=0; StreamPos<Count_Get(Stream_Video); StreamPos++) { Fill(Stream_Video, StreamPos, Video_TimeCode_FirstFrame, Value); Fill(Stream_Video, StreamPos, Video_TimeCode_Source, Name); } }
//--------------------------------------------------------------------------- // Write void ZtringList::Write(const Ztring &ToWrite) { clear(); if (ToWrite.empty()) return; size_type PosC=0; bool Fini=false; Ztring C1; Ztring DelimiterL; Ztring DelimiterR; do { //Searching quotes if (ToWrite[PosC]==Quote[0]) { size_t Pos_End=PosC+1; while (Pos_End<ToWrite.size()) { if (ToWrite[Pos_End]==Quote[0] && Pos_End+1<ToWrite.size() && ToWrite[Pos_End+1]==Quote[0]) Pos_End+=2; //Double quote, skipping else { if (ToWrite[Pos_End]==Quote[0]) break; Pos_End++; } } C1=ToWrite.substr(PosC+Quote.size(), Pos_End-PosC); PosC+=C1.size()+Quote.size(); if (C1.size()>0 && C1[C1.size()-1]==Quote[0]) { C1.resize(C1.size()-1); PosC+=Quote.size(); } } else //Normal { C1=ToWrite.SubString(tstring(), Separator[0], PosC, Ztring_AddLastItem); PosC+=C1.size()+Separator[0].size(); } C1.FindAndReplace(Quote+Quote, Quote, 0, Ztring_Recursive); if (size()<Max[0]) push_back(C1); if (PosC>=ToWrite.size()) Fini=true; } while (!Fini); return; }
//--------------------------------------------------------------------------- void PBCore_Transform__Common_End(Ztring &ToReturn, MediaInfo_Internal &MI, stream_t StreamKind, size_t StreamPos) { //essenceTrackAnnotation - all fields (except *_String*) separated by | Ztring Temp; for (size_t Pos=0; Pos<MI.Count_Get(StreamKind, StreamPos); Pos++) if (MI.Get(StreamKind, StreamPos, Pos, Info_Name).find(__T("String"))==std::string::npos && !MI.Get(StreamKind, StreamPos, Pos).empty()) Temp+=MI.Get(StreamKind, StreamPos, Pos, Info_Name)+__T(": ")+MI.Get(StreamKind, StreamPos, Pos)+__T('|'); if (!Temp.empty()) { Temp.resize(Temp.size()-1); ToReturn+=__T("\t\t\t<essenceTrackAnnotation>"); ToReturn+=Temp; ToReturn+=__T("</essenceTrackAnnotation>\n"); } }
void MediaInfo_Config_MediaInfo::Event_Send (const int8u* Data_Content, size_t Data_Size, const Ztring &File_Name) { CriticalSectionLocker CSL(CS); if (Event_CallBackFunction) Event_CallBackFunction ((unsigned char*)Data_Content, Data_Size, Event_UserHandler); else { MediaInfo_Event_Generic* Event_Generic=(MediaInfo_Event_Generic*)Data_Content; if ((Event_Generic->EventCode&0x00FFFF00)==(MediaInfo_Event_Global_Demux<<8)) { if (!MediaInfoLib::Config.Demux_Get()) return; if (File_Name.empty()) return; MediaInfo_Event_Global_Demux_0* Event=(MediaInfo_Event_Global_Demux_0*)Data_Content; Ztring File_Name_Final(File_Name); bool AddRawExtension=false; for (size_t Pos=0; Pos<Event->StreamIDs_Size; Pos++) { if (Event->StreamIDs_Width[Pos]==17) { Ztring ID; ID.From_CC4((int32u)Event->StreamIDs[Pos]); File_Name_Final+=_T('.')+ID; } else if (Event->StreamIDs_Width[Pos] && Event->StreamIDs_Width[Pos]<=16) { Ztring ID; ID.From_Number(Event->StreamIDs[Pos], 16); while (ID.size()<Event->StreamIDs_Width[Pos]) ID.insert(0, 1, _T('0')); if (ID.size()>Event->StreamIDs_Width[Pos]) ID.erase(0, ID.size()-Event->StreamIDs_Width[Pos]); File_Name_Final+=_T('.')+ID; } else AddRawExtension=true; } if (AddRawExtension) File_Name_Final+=_T(".raw"); File F; F.Open(File_Name_Final, File::Access_Write_Append); F.Write(Event->Content, Event->Content_Size); } } }
//--------------------------------------------------------------------------- void File_Cmml::Configuration() { Element_Name("Configuration"); //Parsing Ztring Data; Get_UTF8(Element_Size, Data, "Data"); FILLING_BEGIN(); Ztring Value; Value=Data.SubString(_T("<head>"), _T("</head>")); if (!Value.empty()) Fill(Stream_Text, 0, Text_Title, Value.SubString(_T("<title>"), _T("</title>"))); if (Data.find(_T("<clip"))!=string::npos) Finish("CMML"); FILLING_END(); }
//--------------------------------------------------------------------------- void File_Speex::Comment() { Element_Name("Comment?"); while (Element_Offset<Element_Size) { Ztring value; int32u size; Get_L4(size, "size"); if (size) Get_Local(size, value, "value"); //Filling if (!value.empty()) Fill(Stream_Audio, 0, "Comment", value); } Finish("Speex"); }
//--------------------------------------------------------------------------- // Load bool ZtringListListF::Load (const Ztring &NewFileName) { clear(); if (!NewFileName.empty()) Name=NewFileName; size_t I1=Error; if (Name.find(__T(".csv"))!=Error) I1=CSV_Charger(); if (Name.find(__T(".cfg"))!=Error) I1=CFG_Charger(); if (I1!=Error) { Backup_Nb=0; //mettre ici le code pour trouver le nb de backup return true; } else return false; }
//--------------------------------------------------------------------------- // 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 PBCore_Transform(Ztring &ToReturn, MediaInfo_Internal &MI, stream_t StreamKind, size_t StreamPos) { //Menu: only if TimeCode if (StreamKind==Stream_Menu && MI.Get(Stream_Menu, StreamPos, Menu_Format)!=__T("TimeCode")) return; //essenceTrackType Ztring essenceTrackType; switch (StreamKind) { case Stream_Video: essenceTrackType=__T("Video"); break; case Stream_Audio: essenceTrackType=__T("Audio"); break; case Stream_Text: { Ztring Format=MI.Get(Stream_Text, StreamPos, Text_Format); if (Format==__T("EIA-608") || Format==__T("EIA-708")) essenceTrackType=__T("CC"); else essenceTrackType=__T("Text"); } break; case Stream_Menu: if (MI.Get(Stream_Menu, StreamPos, Menu_Format)==__T("TimeCode")) { essenceTrackType=__T("TimeCode"); break; } else return; //Not supported default: return; //Not supported } ToReturn+=__T("\t\t<pbcoreEssenceTrack>\n"); ToReturn+=__T("\t\t\t<essenceTrackType>")+essenceTrackType+__T("</essenceTrackType>\n"); //essenceTrackIdentifier if (!MI.Get(StreamKind, StreamPos, __T("ID")).empty()) { ToReturn+=__T("\t\t\t<essenceTrackIdentifier>")+MI.Get(StreamKind, StreamPos, __T("ID"))+__T("</essenceTrackIdentifier>\n"); ToReturn+=__T("\t\t\t<essenceTrackIdentifierSource>ID (Mediainfo)</essenceTrackIdentifierSource>\n"); } else if (!MI.Get(StreamKind, StreamPos, __T("UniqueID")).empty()) { ToReturn+=__T("\t\t\t<essenceTrackIdentifier>")+MI.Get(StreamKind, StreamPos, __T("UniqueID"))+__T("</essenceTrackIdentifier>\n"); ToReturn+=__T("\t\t\t<essenceTrackIdentifierSource>UniqueID (Mediainfo)</essenceTrackIdentifierSource>\n"); } else if (!MI.Get(StreamKind, StreamPos, __T("StreamKindID")).empty()) { ToReturn+=__T("\t\t\t<essenceTrackIdentifier>")+MI.Get(StreamKind, StreamPos, __T("StreamKindID"))+__T("</essenceTrackIdentifier>\n"); ToReturn+=__T("\t\t\t<essenceTrackIdentifierSource>StreamKindID (Mediainfo)</essenceTrackIdentifierSource>\n"); } //essenceTrackStandard if (StreamKind==Stream_Video && !MI.Get(Stream_Video, StreamPos, Video_Standard).empty()) ToReturn+=__T("\t\t\t<essenceTrackStandard>")+MI.Get(Stream_Video, StreamPos, Video_Standard)+__T("</essenceTrackStandard>\n"); //essenceTrackEncoding if (!MI.Get(StreamKind, StreamPos, __T("Format")).empty()) { ToReturn+=__T("\t\t\t<essenceTrackEncoding>"); ToReturn+=MI.Get(StreamKind, StreamPos, __T("Format")); if (!MI.Get(StreamKind, StreamPos, __T("Format_Profile")).empty()) ToReturn+=__T(' ')+MI.Get(StreamKind, StreamPos, __T("Format_Profile")); if (!MI.Get(StreamKind, StreamPos, __T("CodecID")).empty()) ToReturn+=__T(" (")+MI.Get(StreamKind, StreamPos, __T("CodecID"))+__T(')'); ToReturn+=__T("</essenceTrackEncoding>\n"); } //essenceTrackDataRate if (!MI.Get(StreamKind, StreamPos, __T("BitRate")).empty()) { ToReturn+=__T("\t\t\t<essenceTrackDataRate>"); ToReturn+=MI.Get(StreamKind, StreamPos, __T("BitRate")); if (!MI.Get(StreamKind, StreamPos, __T("BitRate_Mode")).empty()) ToReturn+=__T(' ')+MI.Get(StreamKind, StreamPos, __T("BitRate_Mode")); ToReturn+=__T("</essenceTrackDataRate>\n"); } //essenceTrackFrameRate if (StreamKind==Stream_Video && !MI.Get(Stream_Video, StreamPos, Video_FrameRate).empty()) { ToReturn+=__T("\t\t\t<essenceTrackFrameRate>"); ToReturn+=MI.Get(Stream_Video, StreamPos, Video_FrameRate); if (!MI.Get(Stream_Video, StreamPos, Video_FrameRate_Mode).empty()) ToReturn+=__T(' ')+MI.Get(Stream_Video, StreamPos, Video_FrameRate_Mode); ToReturn+=__T("</essenceTrackFrameRate>\n"); } //essenceTrackSamplingRate if (StreamKind==Stream_Audio && !MI.Get(Stream_Audio, StreamPos, Audio_SamplingRate).empty()) ToReturn+=__T("\t\t\t<essenceTrackSamplingRate>")+MI.Get(Stream_Audio, StreamPos, Audio_SamplingRate)+__T("</essenceTrackSamplingRate>\n"); //essenceTrackBitDepth if (!MI.Get(StreamKind, StreamPos, __T("BitDepth")).empty()) ToReturn+=__T("\t\t\t<essenceTrackBitDepth version=\"PBCoreXSD_Ver_1.2_D1\">")+MI.Get(StreamKind, StreamPos, __T("BitDepth"))+__T("</essenceTrackBitDepth>\n"); //essenceTrackFrameSize if (StreamKind==Stream_Video && !MI.Get(Stream_Video, StreamPos, Video_Width).empty()) ToReturn+=__T("\t\t\t<essenceTrackFrameSize>")+MI.Get(Stream_Video, StreamPos, Video_Width)+__T('x')+MI.Get(Stream_Video, StreamPos, Video_Height)+__T("</essenceTrackFrameSize>\n"); //essenceTrackAspectRatio if (StreamKind==Stream_Video && !MI.Get(Stream_Video, StreamPos, Video_DisplayAspectRatio).empty()) ToReturn+=__T("\t\t\t<essenceTrackAspectRatio>")+MI.Get(Stream_Video, StreamPos, Video_DisplayAspectRatio)+__T("</essenceTrackAspectRatio>\n"); //essenceTrackDuration if (!MI.Get(StreamKind, StreamPos, __T("Duration")).empty()) ToReturn+=__T("\t\t\t<essenceTrackDuration>")+MI.Get(StreamKind, StreamPos, __T("Duration"))+__T("</essenceTrackDuration>\n"); //essenceTrackLanguage if (!MI.Get(StreamKind, StreamPos, __T("Language")).empty()) ToReturn+=__T("\t\t\t<essenceTrackLanguage>")+MediaInfoLib::Config.Iso639_2_Get(MI.Get(StreamKind, StreamPos, __T("Language")))+__T("</essenceTrackLanguage>\n"); //essenceTrackAnnotation - all fields (except *_String*) separated by | Ztring Temp; for (size_t Pos=0; Pos<MI.Count_Get(StreamKind, StreamPos); Pos++) if (MI.Get(StreamKind, StreamPos, Pos, Info_Name).find(__T("String"))==std::string::npos && !MI.Get(StreamKind, StreamPos, Pos).empty()) Temp+=MI.Get(StreamKind, StreamPos, Pos, Info_Name)+__T(": ")+MI.Get(StreamKind, StreamPos, Pos)+__T('|'); if (!Temp.empty()) { Temp.resize(Temp.size()-1); ToReturn+=__T("\t\t\t<essenceTrackAnnotation>"); ToReturn+=Temp; ToReturn+=__T("</essenceTrackAnnotation>\n"); } ToReturn+=__T("\t\t</pbcoreEssenceTrack>\n"); }
//--------------------------------------------------------------------------- bool File_SubRip::FileHeader_Begin() { if (!IsSub && (Buffer_Size<File_Size && Buffer_Size<65536)) { Element_WaitForMoreData(); return false; } ZtringListList List; List.Separator_Set(0, __T("\n\n")); List.Separator_Set(1, __T("\n")); if (Buffer[0]==0xEF && Buffer[1]==0xBB && Buffer[2]==0xBF) HasBOM=true; bool IsLocal=false; Ztring Temp; Temp.From_UTF8((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0)); if (Temp.empty()) { Temp.From_Local((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0)); // Trying from local code page IsLocal=true; } Temp.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive); Temp.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive); List.Write(Temp); if (List(0, 0)==__T("WEBVTT FILE") || List(0, 0)==__T("WEBVTT")) IsVTT=true; if (!IsVTT) { size_t IsOk=0; size_t IsNok=0; for (size_t Pos=0; Pos<List.size(); Pos++) { if (List(Pos, 0).To_int64u()==Pos+1) IsOk++; else IsNok++; if (List(Pos, 1).size()>22 && List(Pos, 1)[2]==__T(':') && List(Pos, 1)[5]==__T(':') && List(Pos, 1).find(__T(" --> "))!=string::npos) IsOk++; else IsNok++; } if (!IsOk || IsNok>IsOk/2) { Reject(); return true; } } if (!IsSub && File_Size!=(int64u)-1 && Buffer_Size!=File_Size) { Element_WaitForMoreData(); return false; } if (!Status[IsAccepted]) { Accept(); Fill(Stream_General, 0, General_Format, IsVTT?"WebVTT":"SubRip"); Stream_Prepare(Stream_Text); Fill(Stream_Text, 0, "Format", IsVTT?"WebVTT":"SubRip"); Fill(Stream_Text, 0, "Codec", IsVTT?"WebVTT":"SubRip"); } if (IsLocal) Temp.From_Local((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0)); else Temp.From_UTF8((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0)); Temp.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive); Temp.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive); List.Write(Temp); #if MEDIAINFO_DEMUX size_t Pos=0; for (;;) { if (Pos>=List.size()) break; if (List[Pos].size()>=3 || (IsVTT && List[Pos].size()>=2)) { Ztring PTS_Begin_String=List[Pos][IsVTT?0:1].SubString(Ztring(), __T(" --> ")); Ztring PTS_End_String=List[Pos][IsVTT?0:1].SubString(__T(" --> "), Ztring()); if (IsVTT) { size_t Extra_Pos=PTS_End_String.find(__T(' ')); if (Extra_Pos!=string::npos) PTS_End_String.resize(Extra_Pos); //Discarding positioning } item Item; Item.PTS_Begin=SubRip_str2timecode(PTS_Begin_String.To_UTF8().c_str()); Item.PTS_End=SubRip_str2timecode(PTS_End_String.To_UTF8().c_str()); for (size_t Pos2=IsVTT?1:2; Pos2<List[Pos].size(); Pos2++) { List[Pos][Pos2].Trim(); Item.Content+=List[Pos][Pos2]; if (Pos2+1<List[Pos].size()) Item.Content+=EOL; } Items.push_back(Item); } Pos++; } #endif //MEDIAINFO_DEMUX return true; }
//--------------------------------------------------------------------------- // Main ZenLib::Ztring Enums_Create() { Ztring Out; Ztring Result; Ztring Contents; //Load header Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.1.txt", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"Generic", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"General", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"Video", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"Audio", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"Text", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"Other", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"Image", Contents); if (!Result.empty()) return Result; Out+=Contents; Result=Enums_Create_Item(L"Stream", L"Menu", Contents); if (!Result.empty()) return Result; Out+=Contents; //Load footer Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.9.txt", Contents); if (!Result.empty()) return Result; Out+=Contents; //Write file Result=Enums_Create_Save(L"../Source/MediaInfo/File__Analyse_Automatic.h", Out); if (!Result.empty()) return Result; return Out; }
//--------------------------------------------------------------------------- void File_Id3::Read_Buffer_Continue() { //Buffer size if (Buffer_Size<128) return; int32u Magic; Peek_B4(Magic); Ztring TitleAddition; Ztring ArtistAddition; Ztring AlbumAddition; Ztring GenreAddition; if (Magic==0x5441472B) { if (Buffer_Size<227+128) return; Skip_C4 ( "ID"); Get_Local (60, TitleAddition, "Title"); Get_Local (60, ArtistAddition, "Artist"); Get_Local (60, AlbumAddition, "Album"); Skip_B1 ( "Speed"); Get_Local (30, GenreAddition, "Genre"); Skip_Local(6, "Start time"); //mmm:ss Skip_Local(6, "End time"); //mmm:ss TitleAddition.TrimRight(); ArtistAddition.TrimRight(); AlbumAddition.TrimRight(); GenreAddition.TrimRight(); } //Parsing Ztring Title, Artist, Album, Year, Comment; int8u Track=0, Genre; Skip_C3 ( "ID"); Get_Local (30, Title, "Title"); Get_Local (30, Artist, "Artist"); Get_Local (30, Album, "Album"); Get_Local ( 4, Year, "Year"); Get_Local (30, Comment, "Comment"); if (Comment.size()<29) //Id3v1.1 specifications : Track number addition { Element_Offset-=2; int8u Zero; Peek_B1(Zero); if (Zero==0) { Skip_B1( "Zero"); Get_B1 (Track, "Track"); } else Element_Offset+=2; } Get_B1 (Genre, "Genre"); FILLING_BEGIN(); if (TitleAddition.empty()) Title.TrimRight(); if (ArtistAddition.empty()) Artist.TrimRight(); if (AlbumAddition.empty()) Album.TrimRight(); Year.TrimRight(); Comment.TrimRight(); Accept("Id3"); Stream_Prepare(Stream_General); Fill(Stream_General, 0, General_Album, Album+AlbumAddition); Fill(Stream_General, 0, General_Track, Title+TitleAddition); Fill(Stream_General, 0, General_Performer, Artist+ArtistAddition); Fill(Stream_General, 0, General_Comment, Comment); Fill(Stream_General, 0, General_Recorded_Date, Year); if (GenreAddition.empty()) Fill(Stream_General, 0, General_Genre, GenreAddition); if (Genre && Genre!=(int8u)-1) Fill(Stream_General, 0, General_Genre, Genre); if (Track) Fill(Stream_General, 0, General_Track_Position, Track); Finish("Id3"); FILLING_END(); }
//--------------------------------------------------------------------------- void PBCore_Transform(Node *Parent, MediaInfo_Internal &MI, stream_t StreamKind, size_t StreamPos) { //Menu: only if TimeCode if (StreamKind==Stream_Menu && MI.Get(Stream_Menu, StreamPos, Menu_Format)!=__T("TimeCode")) return; //essenceTrackType Ztring essenceTrackType; switch (StreamKind) { case Stream_Video: essenceTrackType=__T("Video"); break; case Stream_Audio: essenceTrackType=__T("Audio"); break; case Stream_Text: { Ztring Format=MI.Get(Stream_Text, StreamPos, Text_Format); if (Format==__T("EIA-608") || Format==__T("EIA-708")) essenceTrackType=__T("CC"); else essenceTrackType=__T("Text"); } break; case Stream_Menu: if (MI.Get(Stream_Menu, StreamPos, Menu_Format)==__T("TimeCode")) { essenceTrackType=__T("TimeCode"); break; } else return; //Not supported default: return; //Not supported } Node* Node_EssenceTrack=Parent->Add_Child("pbcoreEssenceTrack"); Node_EssenceTrack->Add_Child("essenceTrackType", essenceTrackType); //essenceTrackIdentifier if (!MI.Get(StreamKind, StreamPos, __T("ID")).empty()) { Node_EssenceTrack->Add_Child("essenceTrackIdentifier", MI.Get(StreamKind, StreamPos, __T("ID"))); Node_EssenceTrack->Add_Child("essenceTrackIdentifierSource", "ID (Mediainfo)"); } else if (!MI.Get(StreamKind, StreamPos, __T("UniqueID")).empty()) { Node_EssenceTrack->Add_Child("essenceTrackIdentifier", MI.Get(StreamKind, StreamPos, __T("UniqueID"))); Node_EssenceTrack->Add_Child("essenceTrackIdentifierSource", "UniqueID (Mediainfo)"); } else if (!MI.Get(StreamKind, StreamPos, __T("StreamKindID")).empty()) { Node_EssenceTrack->Add_Child("essenceTrackIdentifier", MI.Get(StreamKind, StreamPos, __T("StreamKindID"))); Node_EssenceTrack->Add_Child("essenceTrackIdentifierSource", "StreamKindID (Mediainfo)"); } //essenceTrackStandard if (StreamKind==Stream_Video) Node_EssenceTrack->Add_Child_IfNotEmpty(MI, Stream_Video, StreamPos, Video_Standard, "essenceTrackStandard"); //essenceTrackEncoding if (!MI.Get(StreamKind, StreamPos, __T("Format")).empty()) { Ztring Format=MI.Get(StreamKind, StreamPos, __T("Format")); if (!MI.Get(StreamKind, StreamPos, __T("Format_Profile")).empty()) Format+=__T(' ')+MI.Get(StreamKind, StreamPos, __T("Format_Profile")); if (!MI.Get(StreamKind, StreamPos, __T("CodecID")).empty()) Format+=__T(" (")+MI.Get(StreamKind, StreamPos, __T("CodecID"))+__T(')'); Node_EssenceTrack->Add_Child("essenceTrackEncoding", Format); } //essenceTrackDataRate if (!MI.Get(StreamKind, StreamPos, __T("BitRate")).empty()) { Ztring BitRate=MI.Get(StreamKind, StreamPos, __T("BitRate")); if (!MI.Get(StreamKind, StreamPos, __T("BitRate_Mode")).empty()) BitRate+=__T(' ')+MI.Get(StreamKind, StreamPos, __T("BitRate_Mode")); Node_EssenceTrack->Add_Child("essenceTrackDataRate", BitRate); } //essenceTrackFrameRate if (StreamKind==Stream_Video && !MI.Get(Stream_Video, StreamPos, Video_FrameRate).empty()) { Ztring FrameRate=MI.Get(Stream_Video, StreamPos, Video_FrameRate); if (!MI.Get(Stream_Video, StreamPos, Video_FrameRate_Mode).empty()) FrameRate+=__T(' ')+MI.Get(Stream_Video, StreamPos, Video_FrameRate_Mode); Node_EssenceTrack->Add_Child("essenceTrackFrameRate", FrameRate); } //essenceTrackSamplingRate if (StreamKind==Stream_Audio) Node_EssenceTrack->Add_Child_IfNotEmpty(MI, Stream_Audio, StreamPos, Audio_SamplingRate, "essenceTrackSamplingRate"); //essenceTrackBitDepth Node_EssenceTrack->Add_Child_IfNotEmpty(MI, StreamKind, StreamPos, "BitDepth", "essenceTrackBitDepth", "version", std::string("PBCoreXSD_Ver_1.2_D1")); //essenceTrackFrameSize if (StreamKind==Stream_Video && !MI.Get(Stream_Video, StreamPos, Video_Width).empty()) Node_EssenceTrack->Add_Child("essenceTrackFrameSize", MI.Get(Stream_Video, StreamPos, Video_Width)+__T('x')+MI.Get(Stream_Video, StreamPos, Video_Height)); //essenceTrackAspectRatio if (StreamKind==Stream_Video) Node_EssenceTrack->Add_Child_IfNotEmpty(MI, Stream_Video, StreamPos, Video_DisplayAspectRatio, "essenceTrackAspectRatio"); //essenceTrackDuration Node_EssenceTrack->Add_Child_IfNotEmpty(MI, StreamKind, StreamPos, "Duration", "essenceTrackDuration"); //essenceTrackLanguage if (!MI.Get(StreamKind, StreamPos, __T("Language")).empty()) Node_EssenceTrack->Add_Child("essenceTrackLanguage", MediaInfoLib::Config.Iso639_2_Get(MI.Get(StreamKind, StreamPos, __T("Language")))); //essenceTrackAnnotation - all fields (except *_String*) separated by | Ztring Temp; for (size_t Pos=0; Pos<MI.Count_Get(StreamKind, StreamPos); Pos++) if (MI.Get(StreamKind, StreamPos, Pos, Info_Name).find(__T("String"))==std::string::npos && !MI.Get(StreamKind, StreamPos, Pos).empty()) Temp+=MI.Get(StreamKind, StreamPos, Pos, Info_Name)+__T(": ")+MI.Get(StreamKind, StreamPos, Pos)+__T('|'); if (!Temp.empty()) { Temp.resize(Temp.size()-1); Node_EssenceTrack->Add_Child("essenceTrackAnnotation", Temp); } }
//--------------------------------------------------------------------------- // Write void ZtringListList::Write(const Ztring &ToWrite) { clear(); if (ToWrite.empty()) return; size_type PosC=0; bool Fini=false; Ztring C1; ZtringList ZL1; ZL1.Separator_Set(0, Separator[1]); ZL1.Quote_Set(Quote); ZL1.Max_Set(0, Max[1]); //Detecting carriage return format Ztring WriteSeparator; if (Separator[0]==EOL) { size_t CarriageReturn_Pos=ToWrite.find_first_of(__T("\r\n")); if (CarriageReturn_Pos!=string::npos) { if (ToWrite[CarriageReturn_Pos]==__T('\r')) { if (CarriageReturn_Pos+1<ToWrite.size() && ToWrite[CarriageReturn_Pos+1]==__T('\n')) WriteSeparator=__T("\r\n"); else WriteSeparator=__T("\r"); } else WriteSeparator=__T("\n"); } else WriteSeparator=Separator[0]; } else WriteSeparator=Separator[0]; do { //Searching end of line, but it must not be in quotes bool InQuotes=false; Ztring CharsToFind=WriteSeparator+Quote; size_t Pos_End=PosC; while (Pos_End<ToWrite.size()) { Pos_End=ToWrite.find(WriteSeparator, Pos_End); if (Pos_End!=string::npos) { if (Pos_End+Quote.size()<ToWrite.size() && ToWrite[Pos_End]==Quote[0] && ToWrite[Pos_End+1]!=Quote[0]) { InQuotes=!InQuotes; //This is not double quotes, so this is a normal quote /*if (!InQuotes) { C1=ToWrite.substr(PosC, Pos_End-PosC); break; }*/ } if (!InQuotes && Pos_End+WriteSeparator.size()<=ToWrite.size() && ToWrite[Pos_End]==WriteSeparator[0]) { C1=ToWrite.substr(PosC, Pos_End-PosC); break; } if (InQuotes && Pos_End+Quote.size()*2<ToWrite.size() && ToWrite[Pos_End]==Quote[0] && ToWrite[Pos_End+1]==Quote[0]) Pos_End+=2; else Pos_End++; } } if (Pos_End>=ToWrite.size()) C1=ToWrite.substr(PosC, string::npos); ZL1.Write(C1); push_back(ZL1); PosC+=C1.size()+WriteSeparator.size(); if (PosC>=ToWrite.size()) Fini=true; } while (!Fini); }
//--------------------------------------------------------------------------- bool File_SubRip::FileHeader_Begin() { if (!IsSub && (Buffer_Size<File_Size && Buffer_Size<65536)) { Element_WaitForMoreData(); return false; } ZtringListList List; List.Separator_Set(0, __T("\n\n")); List.Separator_Set(1, __T("\n")); if (Buffer_Size>=3 && Buffer[0]==0xEF && Buffer[1]==0xBB && Buffer[2]==0xBF) HasBOM=true; bool IsLocal=false; Ztring Temp; Temp.From_UTF8((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0)); if (Temp.empty()) { #ifdef WINDOWS Temp.From_Local((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0)); // Trying from local code page #else //WINDOWS Temp.From_ISO_8859_1((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0)); #endif //WINDOWS IsLocal=true; } Temp.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive); Temp.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive); List.Write(Temp); if (List(0, 0)==__T("WEBVTT FILE") || List(0, 0)==__T("WEBVTT")) IsVTT=true; if (!IsVTT) { size_t IsOk=0; size_t IsNok=0; for (size_t Pos=0; Pos<List.size(); Pos++) { if (List(Pos, 0).To_int64u()==Pos+1) IsOk++; else IsNok++; if (List(Pos, 1).size()>22 && List(Pos, 1)[2]==__T(':') && List(Pos, 1)[5]==__T(':') && List(Pos, 1).find(__T(" --> "))!=string::npos) IsOk++; else IsNok++; } if (!IsOk || IsNok>IsOk/2) { Reject(); return true; } } if (!IsSub && File_Size!=(int64u)-1 && Buffer_Size!=File_Size) { Element_WaitForMoreData(); return false; } if (!Status[IsAccepted]) { Accept(); Fill(Stream_General, 0, General_Format, IsVTT?"WebVTT":"SubRip"); Stream_Prepare(Stream_Text); Fill(Stream_Text, 0, "Format", IsVTT?"WebVTT":"SubRip"); Fill(Stream_Text, 0, "Codec", IsVTT?"WebVTT":"SubRip"); } if (IsLocal) #ifdef WINDOWS Temp.From_Local((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0)); #else //WINDOWS Temp.From_ISO_8859_1((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0)); #endif //WINDOWS else
//--------------------------------------------------------------------------- void File_Jpeg::SIZ() { //Parsing vector<float> SamplingFactors; vector<int8u> BitDepths; int8u SamplingFactors_Max=0; int32u Xsiz, Ysiz; int16u Count; Skip_B2( "Rsiz - Capability of the codestream"); Get_B4 (Xsiz, "Xsiz - Image size X"); Get_B4 (Ysiz, "Ysiz - Image size Y"); Skip_B4( "XOsiz - Image offset X"); Skip_B4( "YOsiz - Image offset Y"); Skip_B4( "tileW - Size of tile W"); Skip_B4( "tileH - Size of tile H"); Skip_B4( "XTOsiz - Upper-left tile offset X"); Skip_B4( "YTOsiz - Upper-left tile offset Y"); Get_B2 (Count, "Components and initialize related arrays"); for (int16u Pos=0; Pos<Count; Pos++) { Element_Begin1("Initialize related array"); int8u BitDepth = 0, compSubsX = 0, compSubsY = 0; BS_Begin(); Skip_SB( "Signed"); Get_S1 (7, BitDepth, "BitDepth"); Param_Info1(1+BitDepth); Element_Info1(1+BitDepth); BS_End(); Get_B1 ( compSubsX, "compSubsX"); Element_Info1(compSubsX); Get_B1 ( compSubsY, "compSubsY"); Element_Info1(compSubsY); Element_End0(); //Filling list of HiVi if (compSubsX) { SamplingFactors.push_back(((float)compSubsY)/compSubsX); if (((float)compSubsY)/compSubsX>SamplingFactors_Max) SamplingFactors_Max=(int8u)((float)compSubsY)/compSubsX; } if (BitDepths.empty() || BitDepth!=BitDepths[0]) BitDepths.push_back(BitDepth); } FILLING_BEGIN_PRECISE(); if (Frame_Count==0 && Field_Count==0) { Accept("JPEG 2000"); if (Count_Get(StreamKind_Last)==0) Stream_Prepare(StreamKind_Last); Fill(StreamKind_Last, 0, Fill_Parameter(StreamKind_Last, Generic_Format), "JPEG 2000"); Fill(StreamKind_Last, 0, Fill_Parameter(StreamKind_Last, Generic_Codec), "JPEG 2000"); if (StreamKind_Last==Stream_Image) Fill(Stream_Image, 0, Image_Codec_String, "JPEG 2000", Unlimited, true, true); //To Avoid automatic filling Fill(StreamKind_Last, 0, StreamKind_Last==Stream_Image?(size_t)Image_Width:(size_t)Video_Width, Xsiz); Fill(StreamKind_Last, 0, StreamKind_Last==Stream_Image?(size_t)Image_Height:(size_t)Video_Height, Ysiz*(Interlaced?2:1)); //If image is from interlaced content, must multiply height by 2 if (BitDepths.size()==1) Fill(StreamKind_Last, 0, Fill_Parameter(StreamKind_Last, Generic_BitDepth), 1+BitDepths[0]); //Chroma subsampling if (SamplingFactors_Max) while (SamplingFactors_Max<4) { for (size_t Pos=0; Pos<SamplingFactors.size(); Pos++) SamplingFactors[Pos]*=2; SamplingFactors_Max*=2; } while (SamplingFactors.size()<3) SamplingFactors.push_back(0); Ztring ChromaSubsampling; for (size_t Pos=0; Pos<SamplingFactors.size(); Pos++) ChromaSubsampling+=Ztring::ToZtring(SamplingFactors[Pos], 0)+__T(':'); if (!ChromaSubsampling.empty()) { ChromaSubsampling.resize(ChromaSubsampling.size()-1); Fill(StreamKind_Last, 0, "ChromaSubsampling", ChromaSubsampling); } } FILLING_END(); }
//--------------------------------------------------------------------------- bool File_SequenceInfo::FileHeader_Begin() { XMLDocument document; if (!FileHeader_Begin_XML(document)) return false; { XMLElement* Root=document.FirstChildElement("SEQUENCEINFO"); if (Root) { Accept("SequenceInfo"); Fill(Stream_General, 0, General_Format, "SequenceInfo"); ReferenceFiles=new File__ReferenceFilesHelper(this, Config); sequence* Sequence=new sequence; Sequence->StreamKind=Stream_Video; FileName FN(File_Name); Ztring Base=FN.Path_Get(); size_t Pos=Base.rfind(PathSeparator); if (Pos!=string::npos) { Ztring ToAdd=Base.substr(Pos, string::npos); Ztring DirectoryBase=Base; DirectoryBase+=ToAdd; DirectoryBase+=__T('_'); size_t DirNumberCount=1; Ztring Directory=DirectoryBase; for (; DirNumberCount<9; DirNumberCount++) { Directory+=__T('0'); if (Dir::Exists(Directory)) break; } if (DirNumberCount<9) { int32u DirNumber=0; do { Ztring Number=Ztring::ToZtring(DirNumber); if (Number.size()<DirNumberCount) Number.insert(0, DirNumberCount-Number.size(), __T('0')); Directory=DirectoryBase; Directory+=Number; if (!Dir::Exists(Directory)) break; Ztring FileBase=Directory; FileBase+=ToAdd; FileBase+=__T('_'); FileBase+=__T('.'); size_t FileNumberCount=1; Ztring FullFile=FileBase; Ztring Extension; for (; FileNumberCount<10; FileNumberCount++) { FullFile.insert(FullFile.begin()+FullFile.size()-Extension.size()-1, __T('0')); if (Extension.empty()) { ZtringList List=Dir::GetAllFileNames(FullFile+__T('*')); if (List.size()>=2) { FileNumberCount=(size_t)-1; //Problem, which one to choose? break; } else if (List.size()==1) { FileName Temp(List[0]); Extension=Temp.Extension_Get(); FileBase+=Extension; FullFile=FileBase; break; } } else if (File::Exists(FullFile)) break; } bool FromZero=true; if (FileNumberCount>=9) { //Trying with consecutive file numbers betweens dirs Number=Ztring::ToZtring(Sequence->FileNames.size()); FullFile=FileBase; FullFile.insert(FullFile.size()-Extension.size()-1, Number); FileNumberCount=Number.size(); if (!File::Exists(FullFile)) { FileNumberCount++; for (; FileNumberCount<10; FileNumberCount++) { FullFile.insert(FullFile.begin()+FullFile.size()-Extension.size()-Number.size()-1, __T('0')); if (File::Exists(FullFile)) { FromZero=false; break; } } } else FromZero=false; } if (FileNumberCount<9) { size_t FileNumber=FromZero?0:Sequence->FileNames.size(); do { Number=Ztring::ToZtring(FileNumber); if (Number.size()<FileNumberCount) Number.insert(0, FileNumberCount-Number.size(), __T('0')); FullFile=FileBase; FullFile.insert(FullFile.size()-Extension.size()-1, Number); if (!File::Exists(FullFile)) break; Sequence->AddFileName(FullFile); FileNumber++; } while (FileNumber<1000000000); } DirNumber++; } while (DirNumber<1000000000); ReferenceFiles->AddSequence(Sequence); } } } else { Reject("SequenceInfo"); return false; } } Element_Offset=File_Size; //All should be OK... return true; }
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"); }
//--------------------------------------------------------------------------- void File_Dxw::Streams_Finish_ParseReference() { if (MI==NULL) { //Configuring file name Ztring Name=Reference->FileName; if (Name.find(_T("file:"))==0) { Name.erase(0, 5); //Removing "file:", this is the default behaviour and this makes comparison easier Name=ZenLib::Format::Http::URL_Encoded_Decode(Name); } Ztring AbsoluteName; if (Name.find(_T(':'))!=1 && Name.find(_T("/"))!=0 && Name.find(_T("\\\\"))!=0) //If absolute patch { AbsoluteName=ZenLib::FileName::Path_Get(File_Name); if (!AbsoluteName.empty()) AbsoluteName+=ZenLib::PathSeparator; } AbsoluteName+=Name; #ifdef __WINDOWS__ AbsoluteName.FindAndReplace(_T("/"), _T("\\"), 0, Ztring_Recursive); //Name normalization #endif //__WINDOWS__ if (AbsoluteName==File_Name) { if (StreamKind_Last!=Stream_Max) { Fill(StreamKind_Last, StreamPos_Last, "Source_Info", "Circular"); StreamKind_Last=Stream_Max; StreamPos_Last=(size_t)-1; } return; } //Configuration MI=new MediaInfo_Internal(); MI->Option(_T("File_KeepInfo"), _T("1")); #if MEDIAINFO_NEXTPACKET if (Config->NextPacket_Get()) MI->Option(_T("File_NextPacket"), _T("1")); #endif //MEDIAINFO_NEXTPACKET #if MEDIAINFO_EVENTS if (Config->Event_CallBackFunction_IsSet()) MI->Option(_T("File_Event_CallBackFunction"), Config->Event_CallBackFunction_Get()); MI->Option(_T("File_SubFile_StreamID_Set"), Ztring::ToZtring((size_t)(Reference-References.begin()+1))); #endif //MEDIAINFO_EVENTS #if MEDIAINFO_DEMUX if (Config->Demux_Unpacketize_Get()) MI->Option(_T("File_Demux_Unpacketize"), _T("1")); #endif //MEDIAINFO_DEMUX //Run if (!MI->Open(AbsoluteName)) { //Filling if (StreamKind_Last!=Stream_Max) { Fill(StreamKind_Last, StreamPos_Last, General_ID, Ztring::ToZtring((size_t)(Reference-References.begin()+1))); Fill(StreamKind_Last, StreamPos_Last, "Source", (*Reference).FileName); Fill(StreamKind_Last, StreamPos_Last, "Source_Info", "Missing"); } delete MI; MI=NULL; } } if (MI) { #if MEDIAINFO_NEXTPACKET while (MI->Open_NextPacket()[8]) { #if MEDIAINFO_DEMUX if (Config->Event_CallBackFunction_IsSet()) { Config->Demux_EventWasSent=true; return; } #endif //MEDIAINFO_DEMUX } #endif //MEDIAINFO_NEXTPACKET Streams_Finish_ParseReference_Finalize(); delete MI; MI=NULL; } }
//--------------------------------------------------------------------------- bool File_HdsF4m::FileHeader_Begin() { XMLDocument document; if (!FileHeader_Begin_XML(document)) return false; { XMLElement* Root=document.FirstChildElement("manifest"); if (Root) { const char* Attribute=Root->Attribute("xmlns"); if (Attribute==NULL || Ztring().From_UTF8(Attribute)!=__T("http://ns.adobe.com/f4m/1.0")) { Reject("HdsF4m"); return false; } Accept("HdsF4m"); Fill(Stream_General, 0, General_Format, "HDS F4M"); Config->File_ID_OnlyRoot_Set(false); ReferenceFiles_Accept(this, Config); #if defined(MEDIAINFO_REFERENCES_YES) //Parsing main elements Ztring BaseURL; for (XMLElement* Root_Item=Root->FirstChildElement(); Root_Item; Root_Item=Root_Item->NextSiblingElement()) { //Common information if (string(Root_Item->Value())=="BaseURL") { if (BaseURL.empty()) //Using the first one BaseURL=Root_Item->GetText(); } //Period if (string(Root_Item->Value())=="media") { sequence* Sequence=new sequence; //Attributes - mineType const char* Attribute=Root_Item->Attribute("url"); if (Attribute) Sequence->AddFileName(Ztring().From_UTF8(Attribute)+__T("Seg1.f4f")); Sequence->StreamID=ReferenceFiles->Sequences_Size()+1; ReferenceFiles->AddSequence(Sequence); } } #endif //MEDIAINFO_REFERENCES_YES } else { Reject("HdsF4m"); return false; } } Element_Offset=File_Size; //All should be OK... return true; }
//--------------------------------------------------------------------------- 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; } } }
//--------------------------------------------------------------------------- bool File_DcpCpl::FileHeader_Begin() { XMLDocument document; if (!FileHeader_Begin_XML(document)) return false; XMLElement* Root=document.FirstChildElement(); const char *NameSpace; if (!Root || strcmp(LocalName(Root, NameSpace), "CompositionPlaylist")) { Reject("DcpCpl"); return false; } bool IsDcp=false, IsImf=false; if (!strcmp(NameSpace, "http://www.digicine.com/PROTO-ASDCP-CPL-20040511#") || !strcmp(NameSpace, "http://www.smpte-ra.org/schemas/429-7/2006/CPL")) { IsDcp=true; } else if (IsSmpteSt2067_3(NameSpace)) { IsImf=true; } else { 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* CompositionPlaylist_Item=Root->FirstChildElement(); CompositionPlaylist_Item; CompositionPlaylist_Item=CompositionPlaylist_Item->NextSiblingElement()) { //CompositionTimecode if (IsImf && MatchQName(CompositionPlaylist_Item, "CompositionTimecode", NameSpace)) { sequence* Sequence=new sequence; Sequence->StreamKind=Stream_Other; Sequence->Infos["Type"]=__T("Time code"); Sequence->Infos["Format"]=__T("CPL TC"); Sequence->Infos["TimeCode_Striped"]=__T("Yes"); bool IsDropFrame=false; for (XMLElement* CompositionTimecode_Item=CompositionPlaylist_Item->FirstChildElement(); CompositionTimecode_Item; CompositionTimecode_Item=CompositionTimecode_Item->NextSiblingElement()) { const char* Text=CompositionTimecode_Item->GetText(); if (!Text) continue; const char *CtItemNs, *CtItemName = LocalName(CompositionTimecode_Item, CtItemNs); if (!CtItemNs || strcmp(CtItemNs, NameSpace)) continue; // item has wrong namespace //TimecodeDropFrame if (!strcmp(CtItemName, "TimecodeDropFrame")) { if (strcmp(Text, "") && strcmp(Text, "0")) IsDropFrame=true; } //TimecodeRate if (!strcmp(CtItemName, "TimecodeRate")) Sequence->Infos["FrameRate"].From_UTF8(Text); //TimecodeStartAddress if (!strcmp(CtItemName, "TimecodeStartAddress")) Sequence->Infos["TimeCode_FirstFrame"].From_UTF8(Text); } //Adaptation if (IsDropFrame) { std::map<string, Ztring>::iterator Info=Sequence->Infos.find("TimeCode_FirstFrame"); if (Info!=Sequence->Infos.end() && Info->second.size()>=11 && Info->second[8]!=__T(';')) Info->second[8]=__T(';'); } Sequence->StreamID=ReferenceFiles->Sequences_Size()+1; ReferenceFiles->AddSequence(Sequence); Stream_Prepare(Stream_Other); Fill(Stream_Other, StreamPos_Last, Other_ID, Sequence->StreamID); for (std::map<string, Ztring>::iterator Info=Sequence->Infos.begin(); Info!=Sequence->Infos.end(); ++Info) Fill(Stream_Other, StreamPos_Last, Info->first.c_str(), Info->second); } //ReelList / SegmentList if (MatchQName(CompositionPlaylist_Item, IsDcp?"ReelList":"SegmentList", NameSpace)) { for (XMLElement* ReelList_Item=CompositionPlaylist_Item->FirstChildElement(); ReelList_Item; ReelList_Item=ReelList_Item->NextSiblingElement()) { //Reel if (MatchQName(ReelList_Item, IsDcp?"Reel":"Segment", NameSpace)) { for (XMLElement* Reel_Item=ReelList_Item->FirstChildElement(); Reel_Item; Reel_Item=Reel_Item->NextSiblingElement()) { //AssetList if (MatchQName(Reel_Item, IsDcp?"AssetList":"SequenceList", NameSpace)) { for (XMLElement* AssetList_Item=Reel_Item->FirstChildElement(); AssetList_Item; AssetList_Item=AssetList_Item->NextSiblingElement()) { const char *AlItemNs, *AlItemName = LocalName(AssetList_Item, AlItemNs); if (!AlItemNs) continue; //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")))) if (strcmp(AlItemName, "MarkerSequence")) //Ignoring MarkerSequence for the moment. TODO: check what to do with MarkerSequence { sequence* Sequence=new sequence; Ztring Asset_Id; if (IsDcp && !strcmp(NameSpace, AlItemNs)) { if (!strcmp(AlItemName, "MainPicture")) Sequence->StreamKind=Stream_Video; else if (!strcmp(AlItemName, "MainSound")) Sequence->StreamKind=Stream_Audio; } else if (IsImf && IsSmpteSt2067_2(AlItemNs)) { if (!strcmp(AlItemName, "MainImageSequence")) Sequence->StreamKind=Stream_Video; else if (!strcmp(AlItemName, "MainAudioSequence")) Sequence->StreamKind=Stream_Audio; } for (XMLElement* File_Item=AssetList_Item->FirstChildElement(); File_Item; File_Item=File_Item->NextSiblingElement()) { //Id if (MatchQName(File_Item, "Id", NameSpace) && Asset_Id.empty()) Asset_Id.From_UTF8(File_Item->GetText()); //ResourceList if (IsImf && MatchQName(File_Item, "ResourceList", NameSpace)) { for (XMLElement* ResourceList_Item=File_Item->FirstChildElement(); ResourceList_Item; ResourceList_Item=ResourceList_Item->NextSiblingElement()) { //Resource if (MatchQName(ResourceList_Item, "Resource", NameSpace)) { Ztring Resource_Id; resource* Resource=new resource; for (XMLElement* Resource_Item=ResourceList_Item->FirstChildElement(); Resource_Item; Resource_Item=Resource_Item->NextSiblingElement()) { const char* ResText=Resource_Item->GetText(); if (!ResText) continue; const char *ResItemNs, *ResItemName = LocalName(Resource_Item, ResItemNs); if (!ResItemNs || strcmp(ResItemNs, NameSpace)) continue; // item has wrong namespace //EditRate if (!strcmp(ResItemName, "EditRate")) { Resource->EditRate=atof(ResText); const char* EditRate2=strchr(ResText, ' '); if (EditRate2!=NULL) { float64 EditRate2f=atof(EditRate2); if (EditRate2f) Resource->EditRate/=EditRate2f; } } //EntryPoint if (!strcmp(ResItemName, "EntryPoint")) { Resource->IgnoreEditsBefore=atoi(ResText); if (Resource->IgnoreEditsAfter!=(int64u)-1) Resource->IgnoreEditsAfter+=Resource->IgnoreEditsBefore; } //Id if (!strcmp(ResItemName, "Id") && Resource_Id.empty()) Resource_Id.From_UTF8(ResText); //SourceDuration if (!strcmp(ResItemName, "SourceDuration")) Resource->IgnoreEditsAfter=Resource->IgnoreEditsBefore+atoi(ResText); //TrackFileId if (!strcmp(ResItemName, "TrackFileId")) Resource->FileNames.push_back(Ztring().From_UTF8(ResText)); } if (Resource->FileNames.empty()) Resource->FileNames.push_back(Resource_Id); Sequence->AddResource(Resource); } } } } if (Sequence->Resources.empty()) { resource* Resource=new resource; Resource->FileNames.push_back(Asset_Id); Sequence->AddResource(Resource); } Sequence->StreamID=ReferenceFiles->Sequences_Size()+1; ReferenceFiles->AddSequence(Sequence); } } } } } } } } Element_Offset=File_Size; //Getting files names FileName Directory(File_Name); Ztring DirPath = Directory.Path_Get(); if (!DirPath.empty()) DirPath += PathSeparator; Ztring Assetmap_FileName=DirPath+__T("ASSETMAP.xml"); bool IsOk=false; if (File::Exists(Assetmap_FileName)) IsOk=true; else { Assetmap_FileName.resize(Assetmap_FileName.size()-4); //Old fashion, without ".xml" if (File::Exists(Assetmap_FileName)) IsOk=true; } if (IsOk) { 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(Assetmap_FileName); 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 && (MI.Get(Stream_General, 0, General_Format)==__T("DCP AM") || MI.Get(Stream_General, 0, General_Format)==__T("IMF AM"))) { MergeFromAm(((File_DcpAm*)MI.Info)->Streams); } } ReferenceFiles->FilesForStorage=true; //All should be OK... return true; }
//--------------------------------------------------------------------------- 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(); }