content/media/fmp4/demuxer/es_descriptor.cc

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "mp4_demuxer/es_descriptor.h"
michael@0 6 #include "mp4_demuxer/bit_reader.h"
michael@0 7
michael@0 8 namespace mp4_demuxer {
michael@0 9
michael@0 10 // The elementary stream size is specific by up to 4 bytes.
michael@0 11 // The MSB of a byte indicates if there are more bytes for the size.
michael@0 12 static bool ReadESSize(BitReader* reader, uint32_t* size) {
michael@0 13 uint8_t msb;
michael@0 14 uint8_t byte;
michael@0 15
michael@0 16 *size = 0;
michael@0 17
michael@0 18 for (size_t i = 0; i < 4; ++i) {
michael@0 19 RCHECK(reader->ReadBits(1, &msb));
michael@0 20 RCHECK(reader->ReadBits(7, &byte));
michael@0 21 *size = (*size << 7) + byte;
michael@0 22
michael@0 23 if (msb == 0)
michael@0 24 break;
michael@0 25 }
michael@0 26
michael@0 27 return true;
michael@0 28 }
michael@0 29
michael@0 30 ESDescriptor::ESDescriptor()
michael@0 31 : object_type_(kForbidden) {
michael@0 32 }
michael@0 33
michael@0 34 ESDescriptor::~ESDescriptor() {}
michael@0 35
michael@0 36 bool ESDescriptor::Parse(const std::vector<uint8_t>& data) {
michael@0 37 BitReader reader(&data[0], data.size());
michael@0 38 uint8_t tag;
michael@0 39 uint32_t size;
michael@0 40 uint8_t stream_dependency_flag;
michael@0 41 uint8_t url_flag;
michael@0 42 uint8_t ocr_stream_flag;
michael@0 43 uint16_t dummy;
michael@0 44
michael@0 45 RCHECK(reader.ReadBits(8, &tag));
michael@0 46 RCHECK(tag == kESDescrTag);
michael@0 47 RCHECK(ReadESSize(&reader, &size));
michael@0 48
michael@0 49 RCHECK(reader.ReadBits(16, &dummy)); // ES_ID
michael@0 50 RCHECK(reader.ReadBits(1, &stream_dependency_flag));
michael@0 51 RCHECK(reader.ReadBits(1, &url_flag));
michael@0 52 RCHECK(!url_flag); // We don't support url flag
michael@0 53 RCHECK(reader.ReadBits(1, &ocr_stream_flag));
michael@0 54 RCHECK(reader.ReadBits(5, &dummy)); // streamPriority
michael@0 55
michael@0 56 if (stream_dependency_flag)
michael@0 57 RCHECK(reader.ReadBits(16, &dummy)); // dependsOn_ES_ID
michael@0 58 if (ocr_stream_flag)
michael@0 59 RCHECK(reader.ReadBits(16, &dummy)); // OCR_ES_Id
michael@0 60
michael@0 61 RCHECK(ParseDecoderConfigDescriptor(&reader));
michael@0 62
michael@0 63 return true;
michael@0 64 }
michael@0 65
michael@0 66 uint8_t ESDescriptor::object_type() const {
michael@0 67 return object_type_;
michael@0 68 }
michael@0 69
michael@0 70 const std::vector<uint8_t>& ESDescriptor::decoder_specific_info() const {
michael@0 71 return decoder_specific_info_;
michael@0 72 }
michael@0 73
michael@0 74 bool ESDescriptor::ParseDecoderConfigDescriptor(BitReader* reader) {
michael@0 75 uint8_t tag;
michael@0 76 uint32_t size;
michael@0 77 uint64_t dummy;
michael@0 78
michael@0 79 RCHECK(reader->ReadBits(8, &tag));
michael@0 80 RCHECK(tag == kDecoderConfigDescrTag);
michael@0 81 RCHECK(ReadESSize(reader, &size));
michael@0 82
michael@0 83 RCHECK(reader->ReadBits(8, &object_type_));
michael@0 84 RCHECK(reader->ReadBits(64, &dummy));
michael@0 85 RCHECK(reader->ReadBits(32, &dummy));
michael@0 86 RCHECK(ParseDecoderSpecificInfo(reader));
michael@0 87
michael@0 88 return true;
michael@0 89 }
michael@0 90
michael@0 91 bool ESDescriptor::ParseDecoderSpecificInfo(BitReader* reader) {
michael@0 92 uint8_t tag;
michael@0 93 uint32_t size;
michael@0 94
michael@0 95 RCHECK(reader->ReadBits(8, &tag));
michael@0 96 RCHECK(tag == kDecoderSpecificInfoTag);
michael@0 97 RCHECK(ReadESSize(reader, &size));
michael@0 98
michael@0 99 decoder_specific_info_.resize(size);
michael@0 100 for (uint32_t i = 0; i < size; ++i)
michael@0 101 RCHECK(reader->ReadBits(8, &decoder_specific_info_[i]));
michael@0 102
michael@0 103 return true;
michael@0 104 }
michael@0 105
michael@0 106 } // namespace mp4_demuxer

mercurial