status_t ESDS::parseDecoderConfigDescriptor(size_t offset, size_t size) { if (size < 13) { return ERROR_MALFORMED; } mObjectTypeIndication = mData[offset]; offset += 13; size -= 13; if (size == 0) { mDecoderSpecificOffset = 0; mDecoderSpecificLength = 0; return OK; } uint8_t tag; size_t sub_offset, sub_size; status_t err = skipDescriptorHeader( offset, size, &tag, &sub_offset, &sub_size); if (err != OK) { return err; } if (tag != kTag_DecoderSpecificInfo) { return ERROR_MALFORMED; } mDecoderSpecificOffset = sub_offset; mDecoderSpecificLength = sub_size; return OK; }
status_t ESDS::parseESDescriptor(size_t offset, size_t size) { if (size < 3) { return ERROR_MALFORMED; } offset += 2; // skip ES_ID size -= 2; unsigned streamDependenceFlag = mData[offset] & 0x80; unsigned URL_Flag = mData[offset] & 0x40; unsigned OCRstreamFlag = mData[offset] & 0x20; ++offset; --size; if (streamDependenceFlag) { offset += 2; size -= 2; } if (URL_Flag) { if (offset >= size) { return ERROR_MALFORMED; } unsigned URLlength = mData[offset]; offset += URLlength + 1; size -= URLlength + 1; } if (OCRstreamFlag) { offset += 2; size -= 2; } if (offset >= size) { return ERROR_MALFORMED; } uint8_t tag; size_t sub_offset, sub_size; status_t err = skipDescriptorHeader( offset, size, &tag, &sub_offset, &sub_size); if (err != OK) { return err; } if (tag != kTag_DecoderConfigDescriptor) { return ERROR_MALFORMED; } err = parseDecoderConfigDescriptor(sub_offset, sub_size); return err; }
status_t ESDS::parseESDescriptor(size_t offset, size_t size) { if (size < 3) { return ERROR_MALFORMED; } offset += 2; // skip ES_ID size -= 2; unsigned streamDependenceFlag = mData[offset] & 0x80; unsigned URL_Flag = mData[offset] & 0x40; unsigned OCRstreamFlag = mData[offset] & 0x20; ++offset; --size; if (streamDependenceFlag) { offset += 2; size -= 2; } if (URL_Flag) { if (offset >= size) { return ERROR_MALFORMED; } unsigned URLlength = mData[offset]; offset += URLlength + 1; size -= URLlength + 1; } if (OCRstreamFlag) { offset += 2; size -= 2; if ((offset >= size || mData[offset] != kTag_DecoderConfigDescriptor) && offset - 2 < size && mData[offset - 2] == kTag_DecoderConfigDescriptor) { // Content found "in the wild" had OCRstreamFlag set but was // missing OCR_ES_Id, the decoder config descriptor immediately // followed instead. offset -= 2; size += 2; LOGW("Found malformed 'esds' atom, ignoring missing OCR_ES_Id."); } } if (offset >= size) { return ERROR_MALFORMED; } uint8_t tag; size_t sub_offset, sub_size; status_t err = skipDescriptorHeader( offset, size, &tag, &sub_offset, &sub_size); if (err != OK) { return err; } if (tag != kTag_DecoderConfigDescriptor) { return ERROR_MALFORMED; } err = parseDecoderConfigDescriptor(sub_offset, sub_size); return err; }
status_t ESDS::parse() { uint8_t tag; size_t data_offset; size_t data_size; status_t err = skipDescriptorHeader(0, mSize, &tag, &data_offset, &data_size); if (err != OK) { return err; } if (tag != kTag_ESDescriptor) { return ERROR_MALFORMED; } return parseESDescriptor(data_offset, data_size); }
status_t ESDS::parseDecoderConfigDescriptor(size_t offset, size_t size) { if (size < 13) { return ERROR_MALFORMED; } mObjectTypeIndication = mData[offset]; offset += 13; size -= 13; if (size == 0) { mDecoderSpecificOffset = 0; mDecoderSpecificLength = 0; return OK; } uint8_t tag; size_t sub_offset, sub_size; status_t err = skipDescriptorHeader( offset, size, &tag, &sub_offset, &sub_size); if (err != OK) { return err; } if (tag != kTag_DecoderSpecificInfo) { #ifdef MTK_AOSP_ENHANCEMENT ALOGW("No Decoder Specific Info(0x05) in esds"); if (mObjectTypeIndication != 0x6B && mObjectTypeIndication != 0x69) return ERROR_UNSUPPORTED; #else return ERROR_MALFORMED; #endif } mDecoderSpecificOffset = sub_offset; mDecoderSpecificLength = sub_size; return OK; }