2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "include/ESDS.h"
23 ESDS::ESDS(const void *data, size_t size)
24 : mData(new uint8_t[size]),
27 mDecoderSpecificOffset(0),
28 mDecoderSpecificLength(0),
29 mObjectTypeIndication(0) {
30 memcpy(mData, data, size);
40 status_t ESDS::InitCheck() const {
44 status_t ESDS::getObjectTypeIndication(uint8_t *objectTypeIndication) const {
45 if (mInitCheck != OK) {
49 *objectTypeIndication = mObjectTypeIndication;
54 status_t ESDS::getCodecSpecificInfo(const void **data, size_t *size) const {
55 if (mInitCheck != OK) {
59 *data = &mData[mDecoderSpecificOffset];
60 *size = mDecoderSpecificLength;
65 status_t ESDS::skipDescriptorHeader(
66 size_t offset, size_t size,
67 uint8_t *tag, size_t *data_offset, size_t *data_size) const {
69 return ERROR_MALFORMED;
72 *tag = mData[offset++];
79 return ERROR_MALFORMED;
82 uint8_t x = mData[offset++];
85 *data_size = (*data_size << 7) | (x & 0x7f);
86 more = (x & 0x80) != 0;
90 if (*data_size > size) {
91 return ERROR_MALFORMED;
94 *data_offset = offset;
99 status_t ESDS::parse() {
104 skipDescriptorHeader(0, mSize, &tag, &data_offset, &data_size);
110 if (tag != kTag_ESDescriptor) {
111 return ERROR_MALFORMED;
114 return parseESDescriptor(data_offset, data_size);
117 status_t ESDS::parseESDescriptor(size_t offset, size_t size) {
119 return ERROR_MALFORMED;
122 offset += 2; // skip ES_ID
125 unsigned streamDependenceFlag = mData[offset] & 0x80;
126 unsigned URL_Flag = mData[offset] & 0x40;
127 unsigned OCRstreamFlag = mData[offset] & 0x20;
132 if (streamDependenceFlag) {
138 if (offset >= size) {
139 return ERROR_MALFORMED;
141 unsigned URLlength = mData[offset];
142 offset += URLlength + 1;
143 size -= URLlength + 1;
151 if (offset >= size) {
152 return ERROR_MALFORMED;
156 size_t sub_offset, sub_size;
157 status_t err = skipDescriptorHeader(
158 offset, size, &tag, &sub_offset, &sub_size);
164 if (tag != kTag_DecoderConfigDescriptor) {
165 return ERROR_MALFORMED;
168 err = parseDecoderConfigDescriptor(sub_offset, sub_size);
173 status_t ESDS::parseDecoderConfigDescriptor(size_t offset, size_t size) {
175 return ERROR_MALFORMED;
178 mObjectTypeIndication = mData[offset];
184 mDecoderSpecificOffset = 0;
185 mDecoderSpecificLength = 0;
190 size_t sub_offset, sub_size;
191 status_t err = skipDescriptorHeader(
192 offset, size, &tag, &sub_offset, &sub_size);
198 if (tag != kTag_DecoderSpecificInfo) {
199 return ERROR_MALFORMED;
202 mDecoderSpecificOffset = sub_offset;
203 mDecoderSpecificLength = sub_size;
208 } // namespace android