// Destructor
PVA_FF_MediaDataAtom::~PVA_FF_MediaDataAtom()
{
    if (_pofstream._filePtr != NULL && true == _oIsFileOpen)
    {
        PVA_FF_AtomUtils::closeFile(&_pofstream);
        _pofstream._filePtr = NULL;
    }

    // PVA_FF_TrackAtom *_ptrackReferencePtr - is taken care of by the movie atom
    // Delete vector<PVA_FF_Renderable*> *_prenderables
    if (_prenderables != NULL)
    {
        for (uint32 i = 0; i < _prenderables->size(); i++)
        {
            if ((*_prenderables)[i] != NULL)
            {
                OSCL_DELETE((*_prenderables)[i]);
                //PV_MP4_FF_DELETE(NULL,PVA_FF_Renderable,(*_prenderables)[i]);
                (*_prenderables)[i] = NULL;
            }
        }
        PV_MP4_FF_TEMPLATED_DELETE(NULL, PVA_FF_RenderableVecType, Oscl_Vector, _prenderables);
        _prenderables = NULL;
    }

    //Contents of this array are deleted in movie atom
    //OSCL_DELETE(_ptrackReferencePtrVec);

    PV_MP4_FF_TEMPLATED_DELETE(NULL, PVA_FF_TrackAtomVecType, Oscl_Vector, _ptrackReferencePtrVec);

    Oscl_FileServer fileServ;
    fileServ.Connect();
    fileServ.Oscl_DeleteFile(_tempFilename.get_cstr());
    fileServ.Close();
}
//==============================================================================
// InitializeReporting                                           PUBLIC STATIC
//==============================================================================
//
OSCL_EXPORT_REF void
UT::CM::InitializeReporting
(
    const char* a_pszTestname,
    OSCL_HeapString<OsclMemAllocator>& a_filename,
    FILE* a_pFileStreamParent,
    FILE*& a_pFileStreamChild
)
{
    a_pFileStreamChild = a_pFileStreamParent;

    if (0 == a_pszTestname || 0 >= a_filename.get_size() || 0 == a_pFileStreamParent)
        return;

    Oscl_FileServer fs;
    fs.Connect();

    Oscl_File f;
    if (0 == f.Open(a_filename.get_cstr(), Oscl_File::MODE_READWRITE | Oscl_File::MODE_TEXT, fs))
    {
        _STRING xfr = xml_test_interpreter::unexpected_termination_interpretation(a_pszTestname);
        f.Write(xfr.c_str(), sizeof(char), oscl_strlen(xfr.c_str()));
        f.Close();
    }
    else
    {
        fprintf(a_pFileStreamParent, "ERROR: Failed to open XML test summary log file (%s).\n", a_filename.get_cstr());
    }

    fs.Close();

    OSCL_HeapString<OsclMemAllocator> outFilename(a_filename);
    outFilename += ".out";
    // open a new stream to file and return it to client
    a_pFileStreamChild = fopen(outFilename.get_cstr(), "w");
}
void pv_metadata_engine_test::ReadClipsFile()
{

    char* iClip;
    char ClipsFileName[255];
    int32 err = 0;

    Oscl_FileServer fileServer;
    err = fileServer.Connect();

    if (0 == err)
    {
        Oscl_File *ClipsFile = new Oscl_File;
        // Full path of ClipsFile is: SOURCENAME_PREPEND_STRING + pvlogger.ini
        oscl_strncpy(ClipsFileName, SOURCENAME_PREPEND_STRING,
                     oscl_strlen(SOURCENAME_PREPEND_STRING) + 1);
        oscl_strcat(ClipsFileName, "Clips.txt");

        printf("\nPath for Clips File is %s\n", ClipsFileName);

        err = ClipsFile->Open(ClipsFileName, Oscl_File::MODE_READ, fileServer);

        if (0 == err)
        {
            int len = 0;
            if (0 == ClipsFile->Seek(0, Oscl_File::SEEKSET))
            {
                while (!ClipsFile->EndOfFile())
                {
                    iClip = (char*)oscl_malloc(200);
                    iClip[0] = '\0';
                    fgetline(ClipsFile, iClip, 127);
                    len = oscl_strlen(iClip);
                    if (len == 0 || iClip[0] == '\n' || (iClip[0] == '\r' && iClip[1] == '\n'))
                    {
                        numOfClips--;
                        oscl_free(iClip);
                    }
                    else if (iClip[len-1] == '\n' && iClip[len-2] == '\r')
                    {
                        iClip[len-2] = '\0';
                        iClips.push_back(iClip);
                    }
                    else if (iClip[len-1] == '\n' && iClip[len-2] != '\r')
                    {
                        iClip[len-1] = '\0';
                        iClips.push_back(iClip);
                    }
                    else
                    {
                        iClip[len] = '\0';
                        iClips.push_back(iClip);
                    }

                    numOfClips++;

                }

                ClipsFile->Close();

                printf("\nClips are\n");
                for (it = iClips.begin(); it < iClips.end(); it++)
                {
                    printf("\n%s\n", *it);
                }

                it = iClips.begin();
                iClipFilePresent = true;

            }
        }
        delete(ClipsFile);
    }
    fileServer.Close();

}
void pv_metadata_engine_test::ReadMetadataFile()
{
    Oscl_File *MetadataFile = new Oscl_File;
    const int numKeys = 40;
    char arr[numKeys][MAX_LEN];
    char *keys[numKeys];
    int count = 0;
    char KeysFileName[255];
    int32 err = 0;

    Oscl_FileServer fileServer;
    err = fileServer.Connect();

    // Full path of MetadataFile is: SOURCENAME_PREPEND_STRING + pvlogger.ini
    oscl_strncpy(KeysFileName, SOURCENAME_PREPEND_STRING,
                 oscl_strlen(SOURCENAME_PREPEND_STRING) + 1);
    oscl_strcat(KeysFileName, "MetadataKeys.txt");

    printf("\nPath for Keys File is %s\n", KeysFileName);

    err = MetadataFile->Open(KeysFileName, Oscl_File::MODE_READ, fileServer);

    if (0 == err)
    {
        int ii = 0;
        int len = 0;
        if (0 == MetadataFile->Seek(0, Oscl_File::SEEKSET))
        {
            while (!MetadataFile->EndOfFile())
            {
                arr[ii][0] = '\0';
                fgetline(MetadataFile, arr[ii], MAX_LEN);
                len = oscl_strlen(arr[ii]);

                if (len == 0 || arr[ii][0] == '\n' || (arr[ii][0] == '\r' && arr[ii][1] == '\n'))
                {
                    ii--;
                }
                else if (arr[ii][len-1] == '\n' && arr[ii][len-2] == '\r')
                {
                    arr[ii][len-2] = '\0';
                    keys[ii] = arr[ii];
                }
                else if (arr[ii][len-1] == '\n' && arr[ii][len-2] != '\r')
                {
                    arr[ii][len-1] = '\0';
                    keys[ii] = arr[ii];
                }
                else
                {
                    arr[ii][len] = '\0';
                    keys[ii] = arr[ii];
                }

                ii++;
            }
        }

        MetadataFile->Close();

        count = ii - 1;

        printf("\nKeys are\n");
        for (int j = 0; j <= ii - 1; j++)
        {
            printf("\n%s", keys[j]);
        }

        for (int i = 0; i <= count; i++)
        {
            iMetadataKeyList.push_front(keys[i]);
        }

    }
    fileServer.Close();
    delete(MetadataFile);
}
//==============================================================================
// FinalizeReporting                                             PUBLIC STATIC
//==============================================================================
//
OSCL_EXPORT_REF void
UT::CM::FinalizeReporting
(
    const char* a_pszTestname,
    OSCL_HeapString<OsclMemAllocator> &a_filename,
    const test_result& a_tr,
    FILE* a_pFileStreamParent,
    FILE* a_pFileStreamChild
)
{
    if (0 == a_pFileStreamChild)
        return;

    //                     report the textual representation of the test results
    text_test_interpreter interp;
    _STRING rs = interp.interpretation(a_tr);
    fprintf(a_pFileStreamChild, "%s", rs.c_str());

    if (0 == a_pszTestname || 0 >= a_filename.get_size() || 0 == a_pFileStreamParent)
        return;

    _STRING strChild;

    fclose(a_pFileStreamChild);                              // close the stream

    OSCL_HeapString<OsclMemAllocator> outFilename(a_filename);
    outFilename += ".out";

    FILE* pFile = fopen(outFilename.get_cstr(), "rb");
    if (0 == pFile)
        fprintf(a_pFileStreamParent, "ERROR: Failed to open file (%s) for capturing test output!\n", outFilename.get_cstr());
    else
    {
        fseek(pFile, 0, SEEK_END);
        long lSize = ftell(pFile);
        rewind(pFile);
        char* buffer = new char[lSize];
        fread(buffer, 1, lSize, pFile);
        strChild = _STRING(buffer, lSize);
        fprintf(a_pFileStreamParent, "%s", strChild.c_str()); // send the captured output back out the parent stream
        delete [] buffer;
        fclose(pFile);
    }

    Oscl_FileServer fs;
    fs.Connect();

    Oscl_File f;
    if (0 == f.Open(a_filename.get_str(), Oscl_File::MODE_READWRITE | Oscl_File::MODE_TEXT, fs))
    {
        _STRING xfr = xml_test_interpreter::interpretation(a_tr, a_pszTestname, &strChild);
        fprintf(a_pFileStreamParent, "\nWrote xml-formatted test results to file: %s\n", a_filename.get_cstr());
        f.Write(xfr.c_str(), sizeof(char), oscl_strlen(xfr.c_str()));
        f.Close();
    }
    else
    {
        fprintf(a_pFileStreamParent, "\nERROR: Failed to open file (%s) for xml-formatted test results\n", a_filename.get_cstr());
    }

    fs.Close();
}
Beispiel #6
0
    static PVMFStatus parseMP3(const char *filename,MediaScannerClient& client) {
        PVID3ParCom pvId3Param;
        PVFile fileHandle;
        Oscl_FileServer iFs;
        uint32 duration;
        //LOGD("c---> filename 好的 = %s", filename);
        if (iFs.Connect() != 0) {
            LOGD("=======iFs.Connect failed========>\n");
            return PVMFFailure;
        }

        oscl_wchar output[MAX_BUFF_SIZE];
        oscl_UTF8ToUnicode((const char *) filename, oscl_strlen((const char *) filename),
                           (oscl_wchar *) output, MAX_BUFF_SIZE);
        if (0 !=
            fileHandle.Open((oscl_wchar *) output, Oscl_File::MODE_READ | Oscl_File::MODE_BINARY,
                            iFs)) {
            //LOGE("Could not open the input file for reading(Test: parse id3).\n");
            return PVMFFailure;
        }

        fileHandle.Seek(0, Oscl_File::SEEKSET);
        pvId3Param.ParseID3Tag(&fileHandle);
        fileHandle.Close();
        iFs.Close();

        //Get the frames information from ID3 library
        PvmiKvpSharedPtrVector framevector;
        pvId3Param.GetID3Frames(framevector);

        uint32 num_frames = framevector.size();

        for (uint32 i = 0; i < num_frames; i++) {
            const char *key = framevector[i]->key;
            bool isUtf8 = false;
            bool isIso88591 = false;

            // type should follow first semicolon
            const char *type = strchr(key, ';');
            if (type == NULL) continue;
            type++;

            char tracknumkeybuf[100];
            if (strncmp(key, "track-info/track-number;", 24) == 0) {
                // Java expects the track number key to be called "tracknumber", so
                // construct a temporary one here.
                snprintf(tracknumkeybuf, sizeof(tracknumkeybuf), "tracknumber;%s", type);
                key = tracknumkeybuf;
            }

            const char *value = framevector[i]->value.pChar_value;

            // KVP_VALTYPE_UTF8_CHAR check must be first, since KVP_VALTYPE_ISO88591_CHAR
            // is a substring of KVP_VALTYPE_UTF8_CHAR.
            // Similarly, KVP_VALTYPE_UTF16BE_WCHAR must be checked before KVP_VALTYPE_UTF16_WCHAR
            if (oscl_strncmp(type, KVP_VALTYPE_UTF8_CHAR, KVP_VALTYPE_UTF8_CHAR_LEN) == 0) {
                isUtf8 = true;
            } else if (
                    oscl_strncmp(type, KVP_VALTYPE_ISO88591_CHAR, KVP_VALTYPE_ISO88591_CHAR_LEN) ==
                    0) {
                isIso88591 = true;
            }

            if (isUtf8) {
                // validate to make sure it is legal utf8
                uint32 valid_chars;
                if (oscl_str_is_valid_utf8((const uint8 *) value, valid_chars)) {
                    // utf8 can be passed through directly
                    //LOGD("c---> key(utf8) = %s  ; value = %s", key, value);
                    if (!client.handleStringTag(key, value)) goto failure;
                } else {
                    // treat as ISO-8859-1 if UTF-8 fails
                    isIso88591 = true;
                }
            }

            if (isIso88591) {
                size_t iInLen = strlen(value);
                char sOutBuf[100];
                size_t iOutLen = 100;
                memset(sOutBuf, 0x00, 100);
                ChangeCode("GBK", "UTF-8", value, &iInLen, sOutBuf, &iOutLen);
                //LOGD("c---> key(gbk) = %s  ; value = %s", key, sOutBuf);
                if (!client.handleStringTag(key, sOutBuf)) goto failure;
            }

            // treat it as iso-8859-1 and our native encoding detection will try to
            // figure out what it is
/*            if (isIso88591) {
                // convert ISO-8859-1 to utf8, worse case is 2x inflation
                const unsigned char *src = (const unsigned char *) value;
                char *temp = (char *) alloca(strlen(value) * 2 + 1);
                if (temp) {
                    char *dest = temp;
                    unsigned int uch;
                    while ((uch = *src++) != 0) {
                        if (uch & 0x80) {
                            *dest++ = (uch >> 6) | 0xc0;
                            *dest++ = (uch & 0x3f) | 0x80;
                        } else *dest++ = uch;
                    }
                    *dest = 0;
                    LOGD("c---> key(iso) = %s  ; value = %s", key, temp);
                    //if (!client.addStringTag(key, temp)) goto failure;
                }
            }*/

            // not UTF-8 or ISO-8859-1, try wide char formats
            if (!isUtf8 && !isIso88591 &&
                (oscl_strncmp(type, KVP_VALTYPE_UTF16BE_WCHAR, KVP_VALTYPE_UTF16BE_WCHAR_LEN) ==
                 0 ||
                 oscl_strncmp(type, KVP_VALTYPE_UTF16_WCHAR, KVP_VALTYPE_UTF16_WCHAR_LEN) == 0)) {
                // convert wchar to utf8
                // the id3parcom library has already taken care of byteswapping
                const oscl_wchar *src = framevector[i]->value.pWChar_value;
                int srcLen = oscl_strlen(src);
                // worse case is 3 bytes per character, plus zero termination
                int destLen = srcLen * 3 + 1;
                char *dest = (char *) alloca(destLen);

                if (oscl_UnicodeToUTF8(src, oscl_strlen(src), dest, destLen) > 0) {
                    //LOGD("c---> key(!utf8 && !iso) = %s  ; value = %s", key, dest);
                    if (!client.handleStringTag(key, dest)) goto failure;
                }
            } else if (oscl_strncmp(type, KVP_VALTYPE_UINT32, KVP_VALTYPE_UINT32_LEN) == 0) {
                char temp[20];
                snprintf(temp, sizeof(temp), "%d", (int) framevector[i]->value.uint32_value);
                //LOGD("c---> key() = %s  ; value = %s", key, temp);
                if (!client.handleStringTag(key, temp)) goto failure;
            } else {
                //LOGE("unknown tag type %s for key %s\n", type, key);
            }
        }

        // extract non-ID3 properties below
        {
            OSCL_wHeapString<OsclMemAllocator> mp3filename(output);
            MP3ErrorType err;
            IMpeg3File mp3File(mp3filename, err);
            if (err != MP3_SUCCESS) {
                //LOGE("IMpeg3File constructor returned %d for %s\n", err, filename);
                return err;
            }
            err = mp3File.ParseMp3File();
            if (err != MP3_SUCCESS) {
                //LOGE("IMpeg3File::ParseMp3File returned %d for %s\n", err, filename);
                return err;
            }

            char buffer[20];
            duration = mp3File.GetDuration();
            sprintf(buffer, "%d", duration);
            LOGD("c---> duration = %s", "duration");
            //if (!client.addStringTag("duration", buffer)) goto failure;
        }

        return PVMFSuccess;

        failure:
        return PVMFFailure;
    }
static PVMFStatus parseMP3(const char *filename, MediaScannerClient& client)
{
    PVID3ParCom pvId3Param;
    PVFile fileHandle;
    Oscl_FileServer iFs;
    uint32 duration;

    if (iFs.Connect() != 0)
    {
        LOGE("iFs.Connect failed\n");
        return PVMFFailure;
    }

    oscl_wchar output[MAX_BUFF_SIZE];
    oscl_UTF8ToUnicode((const char *)filename, oscl_strlen((const char *)filename), (oscl_wchar *)output, MAX_BUFF_SIZE);
    if (0 != fileHandle.Open((oscl_wchar *)output, Oscl_File::MODE_READ | Oscl_File::MODE_BINARY, iFs) )
    {
        LOGE("Could not open the input file for reading(Test: parse id3).\n");
        return PVMFFailure;
    }

    fileHandle.Seek(0, Oscl_File::SEEKSET);
    pvId3Param.ParseID3Tag(&fileHandle);
    fileHandle.Close();
    iFs.Close();

    //Get the frames information from ID3 library
    PvmiKvpSharedPtrVector framevector;
    pvId3Param.GetID3Frames(framevector);

    uint32 num_frames = framevector.size();

    for (uint32 i = 0; i < num_frames;i++)
    {
        const char* key = framevector[i]->key;
        bool validUtf8 = true;

        // type should follow first semicolon
        const char* type = strchr(key, ';') + 1;
        if (type == 0) continue;
        
        const char* value = framevector[i]->value.pChar_value;

        // KVP_VALTYPE_UTF8_CHAR check must be first, since KVP_VALTYPE_ISO88591_CHAR 
        // is a substring of KVP_VALTYPE_UTF8_CHAR.
        // Similarly, KVP_VALTYPE_UTF16BE_WCHAR must be checked before KVP_VALTYPE_UTF16_WCHAR
        if (oscl_strncmp(type, KVP_VALTYPE_UTF8_CHAR, KVP_VALTYPE_UTF8_CHAR_LEN) == 0) {
            // utf8 can be passed through directly
            // but first validate to make sure it is legal utf8
            uint32 valid_chars;
            validUtf8 = oscl_str_is_valid_utf8((const uint8 *)value, valid_chars);
            if (validUtf8 && !client.handleStringTag(key, value)) goto failure;
        } 

        // if the value is not valid utf8, then we will treat it as iso-8859-1 
        // and our native encoding detection will try to figure out what it is
        if (oscl_strncmp(type, KVP_VALTYPE_ISO88591_CHAR, KVP_VALTYPE_ISO88591_CHAR_LEN) == 0 
                || !validUtf8) {
            // iso-8859-1
            // convert to utf8
            // worse case is 2x inflation
            const unsigned char* src = (const unsigned char *)value;
            char* temp = (char *)alloca(strlen(value) * 2 + 1);
            if (temp) {
                char* dest = temp;
                unsigned int uch;
                while ((uch = *src++) != 0) {
                    if (uch & 0x80) {
                        *dest++ = (uch >> 6) | 0xc0;
                        *dest++ = (uch & 0x3f) | 0x80;
                    } else *dest++ = uch;
                }
                *dest = 0;
                if (!client.addStringTag(key, temp)) goto failure;           
            }
        } else if (oscl_strncmp(type, KVP_VALTYPE_UTF16BE_WCHAR, KVP_VALTYPE_UTF16BE_WCHAR_LEN) == 0 ||