Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e933cb5a authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "Report a runtime error instead of asserting on malformed avc...

Merge "Report a runtime error instead of asserting on malformed avc configuration data." into ics-mr1
parents e8e5f86e 71b61a96
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -336,6 +336,10 @@ private:


    int64_t retrieveDecodingTimeUs(bool isCodecSpecific);
    int64_t retrieveDecodingTimeUs(bool isCodecSpecific);


    status_t parseAVCCodecSpecificData(
            const void *data, size_t size,
            unsigned *profile, unsigned *level);

    OMXCodec(const OMXCodec &);
    OMXCodec(const OMXCodec &);
    OMXCodec &operator=(const OMXCodec &);
    OMXCodec &operator=(const OMXCodec &);
};
};
+87 −57
Original line number Original line Diff line number Diff line
@@ -520,34 +520,18 @@ sp<MediaSource> OMXCodec::Create(
    return NULL;
    return NULL;
}
}


status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {
status_t OMXCodec::parseAVCCodecSpecificData(
    LOGV("configureCodec protected=%d",
        const void *data, size_t size,
         (mFlags & kEnableGrallocUsageProtected) ? 1 : 0);
        unsigned *profile, unsigned *level) {

    if (!(mFlags & kIgnoreCodecSpecificData)) {
        uint32_t type;
        const void *data;
        size_t size;
        if (meta->findData(kKeyESDS, &type, &data, &size)) {
            ESDS esds((const char *)data, size);
            CHECK_EQ(esds.InitCheck(), (status_t)OK);

            const void *codec_specific_data;
            size_t codec_specific_data_size;
            esds.getCodecSpecificInfo(
                    &codec_specific_data, &codec_specific_data_size);

            addCodecSpecificData(
                    codec_specific_data, codec_specific_data_size);
        } else if (meta->findData(kKeyAVCC, &type, &data, &size)) {
            // Parse the AVCDecoderConfigurationRecord

    const uint8_t *ptr = (const uint8_t *)data;
    const uint8_t *ptr = (const uint8_t *)data;


            CHECK(size >= 7);
    // verify minimum size and configurationVersion == 1.
            CHECK_EQ((unsigned)ptr[0], 1u);  // configurationVersion == 1
    if (size < 7 || ptr[0] != 1) {
            uint8_t profile = ptr[1];
        return ERROR_MALFORMED;
            uint8_t level = ptr[3];
    }

    *profile = ptr[1];
    *level = ptr[3];


    // There is decodable content out there that fails the following
    // There is decodable content out there that fails the following
    // assertion, let's be lenient for now...
    // assertion, let's be lenient for now...
@@ -565,13 +549,18 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {
    size -= 6;
    size -= 6;


    for (size_t i = 0; i < numSeqParameterSets; ++i) {
    for (size_t i = 0; i < numSeqParameterSets; ++i) {
                CHECK(size >= 2);
        if (size < 2) {
            return ERROR_MALFORMED;
        }

        size_t length = U16_AT(ptr);
        size_t length = U16_AT(ptr);


        ptr += 2;
        ptr += 2;
        size -= 2;
        size -= 2;


                CHECK(size >= length);
        if (size < length) {
            return ERROR_MALFORMED;
        }


        addCodecSpecificData(ptr, length);
        addCodecSpecificData(ptr, length);


@@ -579,19 +568,27 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {
        size -= length;
        size -= length;
    }
    }


            CHECK(size >= 1);
    if (size < 1) {
        return ERROR_MALFORMED;
    }

    size_t numPictureParameterSets = *ptr;
    size_t numPictureParameterSets = *ptr;
    ++ptr;
    ++ptr;
    --size;
    --size;


    for (size_t i = 0; i < numPictureParameterSets; ++i) {
    for (size_t i = 0; i < numPictureParameterSets; ++i) {
                CHECK(size >= 2);
        if (size < 2) {
            return ERROR_MALFORMED;
        }

        size_t length = U16_AT(ptr);
        size_t length = U16_AT(ptr);


        ptr += 2;
        ptr += 2;
        size -= 2;
        size -= 2;


                CHECK(size >= length);
        if (size < length) {
            return ERROR_MALFORMED;
        }


        addCodecSpecificData(ptr, length);
        addCodecSpecificData(ptr, length);


@@ -599,9 +596,42 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {
        size -= length;
        size -= length;
    }
    }


    return OK;
}

status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {
    LOGV("configureCodec protected=%d",
         (mFlags & kEnableGrallocUsageProtected) ? 1 : 0);

    if (!(mFlags & kIgnoreCodecSpecificData)) {
        uint32_t type;
        const void *data;
        size_t size;
        if (meta->findData(kKeyESDS, &type, &data, &size)) {
            ESDS esds((const char *)data, size);
            CHECK_EQ(esds.InitCheck(), (status_t)OK);

            const void *codec_specific_data;
            size_t codec_specific_data_size;
            esds.getCodecSpecificInfo(
                    &codec_specific_data, &codec_specific_data_size);

            addCodecSpecificData(
                    codec_specific_data, codec_specific_data_size);
        } else if (meta->findData(kKeyAVCC, &type, &data, &size)) {
            // Parse the AVCDecoderConfigurationRecord

            unsigned profile, level;
            status_t err;
            if ((err = parseAVCCodecSpecificData(
                            data, size, &profile, &level)) != OK) {
                LOGE("Malformed AVC codec specific data.");
                return err;
            }

            CODEC_LOGI(
            CODEC_LOGI(
                    "AVC profile = %d (%s), level = %d",
                    "AVC profile = %u (%s), level = %u",
                    (int)profile, AVCProfileToString(profile), level);
                    profile, AVCProfileToString(profile), level);


            if (!strcmp(mComponentName, "OMX.TI.Video.Decoder")
            if (!strcmp(mComponentName, "OMX.TI.Video.Decoder")
                && (profile != kAVCProfileBaseline || level > 30)) {
                && (profile != kAVCProfileBaseline || level > 30)) {