OSDN Git Service

am 31626b30: am cb6fbc89: Merge "Report a runtime error instead of asserting on malfo...
authorAndreas Huber <andih@google.com>
Tue, 22 Nov 2011 16:43:28 +0000 (08:43 -0800)
committerAndroid Git Automerger <android-git-automerger@android.com>
Tue, 22 Nov 2011 16:43:28 +0000 (08:43 -0800)
* commit '31626b3075335f4cf579342e99436bb45870cf55':
  Report a runtime error instead of asserting on malformed avc configuration data.

1  2 
media/libstagefright/OMXCodec.cpp

@@@ -520,8 -520,87 +520,87 @@@ sp<MediaSource> OMXCodec::Create
      return NULL;
  }
  
+ status_t OMXCodec::parseAVCCodecSpecificData(
+         const void *data, size_t size,
+         unsigned *profile, unsigned *level) {
+     const uint8_t *ptr = (const uint8_t *)data;
+     // verify minimum size and configurationVersion == 1.
+     if (size < 7 || ptr[0] != 1) {
+         return ERROR_MALFORMED;
+     }
+     *profile = ptr[1];
+     *level = ptr[3];
+     // There is decodable content out there that fails the following
+     // assertion, let's be lenient for now...
+     // CHECK((ptr[4] >> 2) == 0x3f);  // reserved
+     size_t lengthSize = 1 + (ptr[4] & 3);
+     // commented out check below as H264_QVGA_500_NO_AUDIO.3gp
+     // violates it...
+     // CHECK((ptr[5] >> 5) == 7);  // reserved
+     size_t numSeqParameterSets = ptr[5] & 31;
+     ptr += 6;
+     size -= 6;
+     for (size_t i = 0; i < numSeqParameterSets; ++i) {
+         if (size < 2) {
+             return ERROR_MALFORMED;
+         }
+         size_t length = U16_AT(ptr);
+         ptr += 2;
+         size -= 2;
+         if (size < length) {
+             return ERROR_MALFORMED;
+         }
+         addCodecSpecificData(ptr, length);
+         ptr += length;
+         size -= length;
+     }
+     if (size < 1) {
+         return ERROR_MALFORMED;
+     }
+     size_t numPictureParameterSets = *ptr;
+     ++ptr;
+     --size;
+     for (size_t i = 0; i < numPictureParameterSets; ++i) {
+         if (size < 2) {
+             return ERROR_MALFORMED;
+         }
+         size_t length = U16_AT(ptr);
+         ptr += 2;
+         size -= 2;
+         if (size < length) {
+             return ERROR_MALFORMED;
+         }
+         addCodecSpecificData(ptr, length);
+         ptr += length;
+         size -= length;
+     }
+     return OK;
+ }
  status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {
 -    LOGV("configureCodec protected=%d",
 +    ALOGV("configureCodec protected=%d",
           (mFlags & kEnableGrallocUsageProtected) ? 1 : 0);
  
      if (!(mFlags & kIgnoreCodecSpecificData)) {