diff options
author | Andreas Huber <andih@google.com> | 2010-08-19 10:39:47 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2010-08-19 10:39:47 -0700 |
commit | eef3c33e5604ae6304364b7aa6337616e2d4c61e (patch) | |
tree | 7b957473d745cf960a6d861cab1c0180b3be100e /media/libstagefright/mpeg2ts | |
parent | 54d41379357d1d800d0a7bd7c5dc56111710482a (diff) | |
download | frameworks_base-eef3c33e5604ae6304364b7aa6337616e2d4c61e.zip frameworks_base-eef3c33e5604ae6304364b7aa6337616e2d4c61e.tar.gz frameworks_base-eef3c33e5604ae6304364b7aa6337616e2d4c61e.tar.bz2 |
In the absence of width/height information in the sdp, extract the dimensions from the avc codec specific data.
Change-Id: I98c4194593c7e6e24f6fc339c862245111800293
Diffstat (limited to 'media/libstagefright/mpeg2ts')
-rw-r--r-- | media/libstagefright/mpeg2ts/ABitReader.cpp | 98 | ||||
-rw-r--r-- | media/libstagefright/mpeg2ts/ABitReader.h | 53 | ||||
-rw-r--r-- | media/libstagefright/mpeg2ts/ATSParser.cpp | 59 | ||||
-rw-r--r-- | media/libstagefright/mpeg2ts/Android.mk | 1 |
4 files changed, 3 insertions, 208 deletions
diff --git a/media/libstagefright/mpeg2ts/ABitReader.cpp b/media/libstagefright/mpeg2ts/ABitReader.cpp deleted file mode 100644 index 24c8df8..0000000 --- a/media/libstagefright/mpeg2ts/ABitReader.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ABitReader.h" - -#include <media/stagefright/foundation/ADebug.h> - -namespace android { - -ABitReader::ABitReader(const uint8_t *data, size_t size) - : mData(data), - mSize(size), - mReservoir(0), - mNumBitsLeft(0) { -} - -void ABitReader::fillReservoir() { - CHECK_GT(mSize, 0u); - - mReservoir = 0; - size_t i; - for (i = 0; mSize > 0 && i < 4; ++i) { - mReservoir = (mReservoir << 8) | *mData; - - ++mData; - --mSize; - } - - mNumBitsLeft = 8 * i; - mReservoir <<= 32 - mNumBitsLeft; -} - -uint32_t ABitReader::getBits(size_t n) { - CHECK_LE(n, 32u); - - uint32_t result = 0; - while (n > 0) { - if (mNumBitsLeft == 0) { - fillReservoir(); - } - - size_t m = n; - if (m > mNumBitsLeft) { - m = mNumBitsLeft; - } - - result = (result << m) | (mReservoir >> (32 - m)); - mReservoir <<= m; - mNumBitsLeft -= m; - - n -= m; - } - - return result; -} - -void ABitReader::skipBits(size_t n) { - while (n > 32) { - getBits(32); - n -= 32; - } - - if (n > 0) { - getBits(n); - } -} - -void ABitReader::putBits(uint32_t x, size_t n) { - CHECK_LE(mNumBitsLeft + n, 32u); - - mReservoir = (mReservoir >> n) | (x << (32 - n)); - mNumBitsLeft += n; -} - -size_t ABitReader::numBitsLeft() const { - return mSize * 8 + mNumBitsLeft; -} - -const uint8_t *ABitReader::data() const { - CHECK_EQ(mNumBitsLeft % 8, 0u); - - return mData - mNumBitsLeft / 8; -} - -} // namespace android diff --git a/media/libstagefright/mpeg2ts/ABitReader.h b/media/libstagefright/mpeg2ts/ABitReader.h deleted file mode 100644 index 5135211..0000000 --- a/media/libstagefright/mpeg2ts/ABitReader.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef A_BIT_READER_H_ - -#define A_BIT_READER_H_ - -#include <media/stagefright/foundation/ABase.h> - -#include <sys/types.h> -#include <stdint.h> - -namespace android { - -struct ABitReader { - ABitReader(const uint8_t *data, size_t size); - - uint32_t getBits(size_t n); - void skipBits(size_t n); - - size_t numBitsLeft() const; - - const uint8_t *data() const; - -private: - const uint8_t *mData; - size_t mSize; - - uint32_t mReservoir; // left-aligned bits - size_t mNumBitsLeft; - - void fillReservoir(); - void putBits(uint32_t x, size_t n); - - DISALLOW_EVIL_CONSTRUCTORS(ABitReader); -}; - -} // namespace android - -#endif // A_BIT_READER_H_ diff --git a/media/libstagefright/mpeg2ts/ATSParser.cpp b/media/libstagefright/mpeg2ts/ATSParser.cpp index d05975d..26a0fb3 100644 --- a/media/libstagefright/mpeg2ts/ATSParser.cpp +++ b/media/libstagefright/mpeg2ts/ATSParser.cpp @@ -16,9 +16,10 @@ #include "ATSParser.h" -#include "ABitReader.h" #include "AnotherPacketSource.h" +#include "include/avc_utils.h" +#include <media/stagefright/foundation/ABitReader.h> #include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/AMessage.h> @@ -473,60 +474,6 @@ static sp<ABuffer> FindNAL( } } -static unsigned parseUE(ABitReader *br) { - unsigned numZeroes = 0; - while (br->getBits(1) == 0) { - ++numZeroes; - } - - unsigned x = br->getBits(numZeroes); - - return x + (1u << numZeroes) - 1; -} - -// Determine video dimensions from the sequence parameterset. -static void FindDimensions( - const sp<ABuffer> seqParamSet, int32_t *width, int32_t *height) { - ABitReader br(seqParamSet->data() + 1, seqParamSet->size() - 1); - - unsigned profile_idc = br.getBits(8); - br.skipBits(16); - parseUE(&br); // seq_parameter_set_id - - if (profile_idc == 100 || profile_idc == 110 - || profile_idc == 122 || profile_idc == 144) { - TRESPASS(); - } - - parseUE(&br); // log2_max_frame_num_minus4 - unsigned pic_order_cnt_type = parseUE(&br); - - if (pic_order_cnt_type == 0) { - parseUE(&br); // log2_max_pic_order_cnt_lsb_minus4 - } else if (pic_order_cnt_type == 1) { - br.getBits(1); // delta_pic_order_always_zero_flag - parseUE(&br); // offset_for_non_ref_pic - parseUE(&br); // offset_for_top_to_bottom_field - - unsigned num_ref_frames_in_pic_order_cnt_cycle = parseUE(&br); - for (unsigned i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) { - parseUE(&br); // offset_for_ref_frame - } - } - - parseUE(&br); // num_ref_frames - br.getBits(1); // gaps_in_frame_num_value_allowed_flag - - unsigned pic_width_in_mbs_minus1 = parseUE(&br); - unsigned pic_height_in_map_units_minus1 = parseUE(&br); - unsigned frame_mbs_only_flag = br.getBits(1); - - *width = pic_width_in_mbs_minus1 * 16 + 16; - - *height = (2 - frame_mbs_only_flag) - * (pic_height_in_map_units_minus1 * 16 + 16); -} - static sp<ABuffer> MakeAVCCodecSpecificData( const sp<ABuffer> &buffer, int32_t *width, int32_t *height) { const uint8_t *data = buffer->data(); @@ -537,7 +484,7 @@ static sp<ABuffer> MakeAVCCodecSpecificData( return NULL; } - FindDimensions(seqParamSet, width, height); + FindAVCDimensions(seqParamSet, width, height); size_t stopOffset; sp<ABuffer> picParamSet = FindNAL(data, size, 8, &stopOffset); diff --git a/media/libstagefright/mpeg2ts/Android.mk b/media/libstagefright/mpeg2ts/Android.mk index b6772eb..3544b4c 100644 --- a/media/libstagefright/mpeg2ts/Android.mk +++ b/media/libstagefright/mpeg2ts/Android.mk @@ -3,7 +3,6 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - ABitReader.cpp \ AnotherPacketSource.cpp \ ATSParser.cpp \ MPEG2TSExtractor.cpp \ |