Ztring MediaInfo_Config_MediaInfo::File_Duplicate_Set (const Ztring &Value) { //Preparing for File__Duplicate... CS.Enter(); File__Duplicate_List.push_back(Value); //Handling Memory index Ztring ToReturn; ZtringList List=Value; 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 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_Ttml::Read_Buffer_Continue() { tinyxml2::XMLDocument document; if (!FileHeader_Begin_XML(document)) return; XMLElement* Root=document.FirstChildElement("tt"); if (!Root) { Reject(); return; } if (!Status[IsAccepted]) { Accept(); #if MEDIAINFO_EVENTS MuxingMode=(int8u)-1; if (StreamIDs_Size>=2 && ParserIDs[StreamIDs_Size-2]==MediaInfo_Parser_Mpeg4) MuxingMode=11; //MPEG-4 if (StreamIDs_Size>2 && ParserIDs[StreamIDs_Size-2]==MediaInfo_Parser_Mxf) //Only if referenced MXF MuxingMode=13; //MXF #endif //MEDIAINFO_EVENTS #if MEDIAINFO_DEMUX && MEDIAINFO_NEXTPACKET if (Config->NextPacket_Get() && Config->Event_CallBackFunction_IsSet()) return; // Waiting for NextPacket #endif //MEDIAINFO_DEMUX && MEDIAINFO_NEXTPACKET } tinyxml2::XMLElement* div=NULL; #if MEDIAINFO_EVENTS tinyxml2::XMLElement* p=NULL; #endif //MEDIAINFO_EVENTS for (XMLElement* tt_element=Root->FirstChildElement(); tt_element; tt_element=tt_element->NextSiblingElement()) { //body if (!strcmp(tt_element->Value(), "body")) { for (XMLElement* body_element=tt_element->FirstChildElement(); body_element; body_element=body_element->NextSiblingElement()) { //div if (!strcmp(body_element->Value(), "div")) { for (XMLElement* div_element=body_element->FirstChildElement(); div_element; div_element=div_element->NextSiblingElement()) { //p if (!strcmp(div_element->Value(), "p")) { div=body_element; #if MEDIAINFO_EVENTS p=div_element; #endif //MEDIAINFO_EVENTS break; } } if (div) break; } } if (div) break; } } #if MEDIAINFO_DEMUX Demux(Buffer, Buffer_Size, ContentType_MainStream); #endif //MEDIAINFO_DEMUX // Output #if MEDIAINFO_EVENTS for (; p; p=p->NextSiblingElement()) { //p if (!strcmp(p->Value(), "p")) { int64u DTS_Begin=(int64u)-1; const char* Attribute=p->Attribute("begin"); if (Attribute) DTS_Begin=Ttml_str2timecode(Attribute); int64u DTS_End=(int64u)-1; Attribute=p->Attribute("end"); if (Attribute) DTS_End=Ttml_str2timecode(Attribute); string ContentUtf8; XMLPrinter printer; p->Accept(&printer); ContentUtf8+=printer.CStr(); while (!ContentUtf8.empty() && (ContentUtf8[ContentUtf8.size()-1]=='\r' || ContentUtf8[ContentUtf8.size()-1]=='\n')) ContentUtf8.resize(ContentUtf8.size()-1); Ztring Content; Content.From_UTF8(ContentUtf8.c_str()); Frame_Count_NotParsedIncluded=Frame_Count; EVENT_BEGIN (Global, SimpleText, 0) //Hack: remove "p", "span", "br" Content.FindAndReplace(__T("\r"), Ztring(), 0, ZenLib::Ztring_Recursive); Content.FindAndReplace(__T("\n"), Ztring(), 0, ZenLib::Ztring_Recursive); for (;;) { size_t Span_Begin=Content.find(__T("<p")); if (Span_Begin==string::npos) break; size_t Span_End=Content.find(__T(">"), Span_Begin+5); if (Span_End==string::npos) break; size_t ShlashSpan_Begin=Content.find(__T("</p>"), Span_End+1); if (ShlashSpan_Begin==string::npos) break; Content.erase(ShlashSpan_Begin, 7); Content.erase(Span_Begin, Span_End-Span_Begin+1); } for (;;) { size_t Span_Begin=Content.find(__T("<span")); if (Span_Begin==string::npos) break; size_t Span_End=Content.find(__T(">"), Span_Begin+5); if (Span_End==string::npos) break; size_t ShlashSpan_Begin=Content.find(__T("</span>"), Span_End+1); if (ShlashSpan_Begin==string::npos) break; Content.erase(ShlashSpan_Begin, 7); Content.erase(Span_Begin, Span_End-Span_Begin+1); } Content.FindAndReplace(__T("<br>"), EOL, 0, ZenLib::Ztring_Recursive); Content.FindAndReplace(__T("<br/>"), EOL, 0, ZenLib::Ztring_Recursive); Content.FindAndReplace(__T("<br />"), EOL, 0, ZenLib::Ztring_Recursive); Event.DTS=DTS_Begin; Event.PTS=Event.DTS; Event.DUR=DTS_End-DTS_Begin; Event.Content=Content.c_str(); Event.Flags=0; Event.MuxingMode=MuxingMode; Event.Service=(int8u)Element_Code; Event.Row_Max=0; Event.Column_Max=0; Event.Row_Values=NULL; Event.Row_Attributes=NULL; EVENT_END () EVENT_BEGIN (Global, SimpleText, 0) Event.DTS=DTS_End; Event.PTS=Event.DTS; Event.DUR=0; Event.Content=__T(""); Event.Flags=0; Event.MuxingMode=MuxingMode; Event.Service=(int8u)Element_Code; Event.Row_Max=0; Event.Column_Max=0; Event.Row_Values=NULL; Event.Row_Attributes=NULL; EVENT_END () Frame_Count++; } } #endif //MEDIAINFO_EVENTS Buffer_Offset=Buffer_Size; }