예제 #1
0
void MemoryDebug::ReportLeaks()
{
    Ztring m_File;
    //std::ofstream      m_File ("Debug_MemoryLeak.txt");        // Fichier de sortie

    // Détail des fuites
    std::size_t TotalSize = 0;
    for (TBlockMap::iterator i = m_Blocks.begin(); i != m_Blocks.end(); ++i)
    {
        // Ajout de la taille du bloc au cumul
        TotalSize += i->second.Size;

        // Inscription dans le fichier des informations sur le bloc courant
        /*
        m_File << "-> 0x" << std::hex << i->first << std::dec
               << " | "   << std::setw(7) << std::setfill(' ') << static_cast<int>(i->second.Size) << " bytes"
               << " | "   << i->second.File.c_str() << " (" << i->second.Line << ")" << std::endl;
        */
        m_File.append(_T("-> 0x"));
        m_File.append(Ztring::ToZtring((size_t)i->first, 16));
        m_File.append(_T(" | "));
        Ztring Temp;
        Temp.From_Number(static_cast<int>(i->second.Size));
        while(Temp.size()<7)
            Temp=_T(" ")+Temp;
        m_File.append(Temp);
        m_File.append(_T(" bytes"));
        m_File.append(_T(" | "));
        m_File.append(Ztring().From_Local(i->second.File.c_str()));
        m_File.append(_T(" ("));
        m_File.append(Ztring::ToZtring(i->second.Line));
        m_File.append(_T(")"));
        m_File.append(EOL);
    }

    // Affichage du cumul des fuites
    /*
    m_File << std::endl << std::endl << "-- "
           << static_cast<int>(m_Blocks.size()) << " non-released blocs, "
           << static_cast<int>(TotalSize)       << " bytes --"
           << std::endl;
    */
    m_File.append(EOL);
    m_File.append(EOL);
    m_File.append(_T("-- "));
    m_File.append(Ztring::ToZtring(static_cast<int>(m_Blocks.size())));
    m_File.append(_T(" non-released blocs, "));
    m_File.append(Ztring::ToZtring(static_cast<int>(TotalSize)));
    m_File.append(_T(" bytes --"));
    m_File.append(EOL);

    std::string ToWrite=m_File.To_Local().c_str();
    int m_File_sav=open("Debug_MemoryLeak.txt", O_BINARY|O_RDWR  |O_CREAT);        // Fichier de sortie
    write(m_File_sav, (int8u*)ToWrite.c_str(), ToWrite.size());
    close(m_File_sav);
}
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);
        }
    }
}
예제 #3
0
//---------------------------------------------------------------------------
// Write a file
ZenLib::Ztring Enums_Create_Save(Ztring FileName, Ztring &Contents)
{
    File F;
    if (F.Create(FileName.c_str(), true)==false)
    {
        Ztring ToReturn=L"Problems to create ";
        ToReturn+=FileName;
        ToReturn+=L"\r\n";
        return ToReturn;
    }

    std::string S1=Contents.To_UTF8();
    size_t Size=F.Write((const int8u*)S1.c_str(), S1.size());
    Contents.From_Number(Size);
    Contents+=L" bytes written";
    return L"";
}
예제 #4
0
//---------------------------------------------------------------------------
void File_Mpc::FileHeader_Parse()
{
    //Parsing
    Element_Begin("SV7 header", 21);
    Ztring Encoder;
    int32u FrameCount;
    int16u TitleGain, AlbumGain;
    int8u  Profile, Link, SampleFreq, EncoderVersion;

    Skip_C3(                                                    "Signature");
    BS_Begin();
    Skip_S1(4,                                                  "PNS");
    Skip_S1(4,                                                  "Version");
    BS_End();

    Get_L4 (FrameCount,                                         "FrameCount");

    Skip_L2(                                                    "MaxLevel");
    BS_Begin();
    Get_S1 (4, Profile,                                         "Profile"); Param_Info(Mpc_Profile[Profile]);
    Get_S1 (2, Link,                                            "Link"); Param_Info(Mpc_Link[Link]);
    Get_S1 (2, SampleFreq,                                      "SampleFreq"); Param_Info(Mpc_SampleFreq[SampleFreq]);
    Skip_SB(                                                    "IntensityStereo");
    Skip_SB(                                                    "MidSideStereo");
    Skip_S1(6,                                                  "MaxBand");
    BS_End();

    Skip_L2(                                                    "TitlePeak");
    Get_L2 (TitleGain,                                          "TitleGain"); Param_Info(((float32)((int16s)TitleGain))/1000, 2, " dB");

    Skip_L2(                                                    "AlbumPeak");
    Get_L2 (AlbumGain,                                          "AlbumGain"); Param_Info(((float32)((int16s)TitleGain))/1000, 2, " dB");

    BS_Begin();
    Skip_S2(16,                                                 "unused");
    Skip_S1( 4,                                                 "LastFrameLength (part 1)");
    Skip_SB(                                                    "FastSeekingSafe");
    Skip_S1( 3,                                                 "unused");
    Skip_SB(                                                    "TrueGapless");
    Skip_S1( 7,                                                 "LastFrameLength (part 2)");
    BS_End();

    Get_L1 (EncoderVersion,                                     "EncoderVersion");
    Encoder.From_Number(((float)EncoderVersion)/100, 2); if (EncoderVersion%10==0); else if (EncoderVersion%2==0) Encoder+=_T(" Beta"); else if (EncoderVersion%2==1) Encoder+=_T(" Alpha"); Param_Info(Encoder);

    Element_End();

    FILLING_BEGIN();
        File__Tags_Helper::Accept("Musepack SV7");

        File__Tags_Helper::Stream_Prepare(Stream_Audio);
        Fill(Stream_Audio, 0, Audio_SamplingRate, Mpc_SampleFreq[SampleFreq]);
        Fill(Stream_Audio, 0, Audio_SamplingCount, FrameCount*1152);
        Fill(Stream_Audio, 0, Audio_Format, "Musepack SV7");
        Fill(Stream_Audio, 0, Audio_Codec, "SV7");
        Fill(Stream_Audio, 0, Audio_Codec_Settings, Mpc_Profile[Profile]);
        Fill(Stream_Audio, 0, Audio_Encoded_Library, Encoder);
        Fill(Stream_Audio, 0, Audio_Resolution, 16); //MPC support only 16 bits
        Fill(Stream_Audio, 0, Audio_Duration, ((int64u)FrameCount)*1152*1000/Mpc_SampleFreq[SampleFreq]);
        if (FrameCount)
            Fill(Stream_Audio, 0, Audio_BitRate, (File_Size-25)*8*Mpc_SampleFreq[SampleFreq]/FrameCount/1152);

        //No more need data
        File__Tags_Helper::Finish("Musepack SV7");
    FILLING_END();
}
예제 #5
0
//---------------------------------------------------------------------------
void File_Rm::RJMD_property(std::string Name)
{
    //Element_Name("Property");

    //Parsing
    Ztring value;
    std::string name;
    int32u type, flags, num_subproperties, name_length, value_length;
    Element_Begin1("MetadataProperty");
    Skip_B4(                                                    "size");
    Get_B4 (type,                                               "type");
    Get_B4 (flags,                                              "flags");
        Skip_Flags(flags, 0,                                    "readonly"); //Read only, cannot be modified.
        Skip_Flags(flags, 1,                                    "private"); //Private, do not expose to users.
        Skip_Flags(flags, 2,                                    "type_dexcriptor"); //Type descriptor used to further define type of value.
    Skip_B4(                                                    "value_offset"); //The offset to the value_length , relative to the beginning of the MetadataProperty  structure.
    Skip_B4(                                                    "subproperties_offset"); //The offset to the subproperties_list , relative to the beginning of the MetadataProperty  structure.
    Get_B4 (num_subproperties,                                  "num_subproperties"); //The number of subproperties for this MetadataProperty  structure.
    Get_B4 (name_length,                                        "name_length"); //The length of the name data, including the null-terminator.
    Get_String(name_length, name,                               "name"); //The name of the property (string data).
    Get_B4 (value_length,                                       "value_length"); //The length of the value data.
    switch(type)
    {
        case 0x00 : //Nothing
                    Skip_XX(value_length,                       "Junk");
                    break;
        case 0x01 : //String (text).
                    Get_Local(value_length, value,              "value"); //String.
                    break;
        case 0x02 : //Separated list of strings, separator specified as sub-property/type descriptor.
                    Get_Local(value_length, value,              "value"); //String.
                    break;
        case 0x03 : //Boolean flag—either 1 byte or 4 bytes, check size value.
                    switch(value_length)
                    {
                    case 1 : {
                                 int8u valueI;
                                 Get_L1(valueI,                 "value"); //1-byte boolean.
                                 value.From_Number(valueI);
                             }
                             break;
                    case 4 : {
                                 int32u valueI;
                                 Get_L4(valueI,                 "value"); //4-byte boolean.
                                 value.From_Number(valueI);
                             }
                             break;
                        default: Skip_XX(value_length,          "Unknown");
                    }
                    break;
        case 0x04 : //Four-byte integer.
                    {
                    int32u valueI;
                    Get_L4(valueI,                              "value");
                    value.From_Number(valueI);
                    }
                    break;
        case 0x05 : //Byte stream.
                    Skip_XX(value_length,                       "Byte stream");
                    break;
        case 0x06 : //String (URL).
                    Get_Local(value_length, value,              "value"); //String.
                    break;
        case 0x07 : //String representation of the date in the form: YYYYmmDDHHMMSS (m = month, M = minutes).
                    Get_Local(value_length, value,              "value"); //String.
                    break;
        case 0x08 : //String (file name)
                    Get_Local(value_length, value,              "value"); //String.
                    break;
        case 0x09 : //This property has subproperties, but its own value is empty.
                    Skip_XX(value_length,                       "junk");
                    break;
        case 0x0A : //Large buffer of data, use sub-properties/type descriptors to identify mime-type.
                    Skip_XX(value_length,                       "data");
                    break;
        default   : //Unknown
                    Skip_XX(value_length,                       "unknown");
                    break;
    }

    //Filling
    if (!Name.empty())
        Name+='/';
    Name+=name;
    if (Name!="Track/Comments/DataSize"
     && Name!="Track/Comments/MimeType"
       )
    Fill(Stream_General, 0, Name.c_str(), value);

    //Parsing
    for (int32u Pos=0; Pos<num_subproperties; Pos++)
    {
        Element_Begin1("PropListEntry");
        Skip_B4(                                                "offset"); //The offset for this indexed sub-property, relative to the beginning of the containing MetadataProperty.
        Skip_B4(                                                "num_props_for_name"); //The number of sub-properties that share the same name. For example, a lyrics property could have multiple versions as differentiated by the language sub-property type descriptor.
        Element_End0();
    }
    for (int32u Pos=0; Pos<num_subproperties; Pos++)
    {
        RJMD_property(Name);
    }

    Element_End0();
}
void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_Size, void* UserHandle_Void)
{
    /*Retrieving UserHandle*/
    struct Events_UserHandle_struct*           UserHandle=(struct Events_UserHandle_struct*)UserHandle_Void;
    struct MediaInfo_Event_Generic*     Event_Generic=(struct MediaInfo_Event_Generic*) Data_Content;
    unsigned char                       ParserID;
    unsigned short                      EventID;
    unsigned char                       EventVersion;

    /*integrity tests*/
    if (Data_Size<4)
        return; //There is a problem

    if (UserHandle->PerEvent[Event_Generic->EventCode].F==NULL)
    {
        Ztring Number; Number.From_Number(Event_Generic->EventCode, 16);
        while (Number.size()<8)
            Number.insert(0, 1, __T('0'));
        Ztring Name=Ztring(UserHandle->DataBaseDirectory+__T("\\Events\\New\\")+Ztring::ToZtring(UserHandle->Scenario)+__T("\\")+Number+__T("\\")+UserHandle->Name.Name_Get()+__T(".txt"));
        if (!Dir::Exists(UserHandle->DataBaseDirectory+__T("\\Events\\New")))
            Dir::Create(UserHandle->DataBaseDirectory+__T("\\Events\\New"));
       if (!Dir::Exists(UserHandle->DataBaseDirectory+__T("\\Events\\New\\")+Ztring::ToZtring(UserHandle->Scenario)))
            Dir::Create(UserHandle->DataBaseDirectory+__T("\\Events\\New\\")+Ztring::ToZtring(UserHandle->Scenario));
       if (!Dir::Exists(UserHandle->DataBaseDirectory+__T("\\Events\\New\\")+Ztring::ToZtring(UserHandle->Scenario)+__T("\\")+Number))
            Dir::Create(UserHandle->DataBaseDirectory+__T("\\Events\\New\\")+Ztring::ToZtring(UserHandle->Scenario)+__T("\\")+Number);
        if (!Dir::Exists(FileName(Name).Path_Get()))
            Dir::Create(FileName(Name).Path_Get());
        UserHandle->PerEvent[Event_Generic->EventCode].F=fopen(Name.To_Local().c_str(), "w");
    }

    /*Retrieving EventID*/
    ParserID    =(unsigned char) ((Event_Generic->EventCode&0xFF000000)>>24);
    EventID     =(unsigned short)((Event_Generic->EventCode&0x00FFFF00)>>8 );
    EventVersion=(unsigned char) ( Event_Generic->EventCode&0x000000FF     );


    //*Global to all parsers
    switch (EventID)
    {
                    CASE (Global, Demux, 4)
                    CASE (Video, SliceInfo, 0)
                    default                                                                     : ;
    }

    switch (ParserID)
    {
        case MediaInfo_Parser_None :
                switch (EventID)
                {
                    case MediaInfo_Event_General_Start                                          : if (EventVersion==0 && Data_Size==sizeof(struct MediaInfo_Event_General_Start_0)) General_Start_0((struct MediaInfo_Event_General_Start_0*)Data_Content, UserHandle); break;
                    case MediaInfo_Event_General_End                                            : if (EventVersion==0 && Data_Size==sizeof(struct MediaInfo_Event_General_End_0)) General_End_0((struct MediaInfo_Event_General_End_0*)Data_Content, UserHandle); break;
                    case MediaInfo_Event_General_Parser_Selected                                : if (EventVersion==0 && Data_Size==sizeof(struct MediaInfo_Event_General_Parser_Selected_0)) General_Parser_Selected_0((struct MediaInfo_Event_General_Parser_Selected_0*)Data_Content, UserHandle); break;
                    case MediaInfo_Event_General_Move_Request                                   : if (EventVersion==0 && Data_Size==sizeof(struct MediaInfo_Event_General_Move_Request_0)) General_Move_Request_0((struct MediaInfo_Event_General_Move_Request_0*)Data_Content, UserHandle); break;
                    case MediaInfo_Event_General_Move_Done                                      : if (EventVersion==0 && Data_Size==sizeof(struct MediaInfo_Event_General_Move_Done_0)) General_Move_Done_0((struct MediaInfo_Event_General_Move_Done_0*)Data_Content, UserHandle); break;
                    case MediaInfo_Event_General_SubFile_Start                                  : if (EventVersion==0 && Data_Size==sizeof(struct MediaInfo_Event_General_SubFile_Start_0)) General_SubFile_Start_0((struct MediaInfo_Event_General_SubFile_Start_0*)Data_Content, UserHandle); break;
                    case MediaInfo_Event_General_SubFile_End                                    : if (EventVersion==0 && Data_Size==sizeof(struct MediaInfo_Event_General_SubFile_End_0)) General_SubFile_End_0((struct MediaInfo_Event_General_SubFile_End_0*)Data_Content, UserHandle); break;
                    default                                                                     : ;
                }
                break;
        default : ; //ParserID is unknown
    }
}