Shaka Packager SDK
es_descriptor.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PACKAGER_MEDIA_CODECS_ES_DESCRIPTOR_H_
6 #define PACKAGER_MEDIA_CODECS_ES_DESCRIPTOR_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <vector>
12 
13 namespace shaka {
14 namespace media {
15 
16 class BitReader;
17 class BufferWriter;
18 
19 // The following values are extracted from ISO 14496 Part 1 Table 5 -
20 // objectTypeIndication Values. Only values currently in use are included.
21 enum class ObjectType : uint8_t {
22  kForbidden = 0,
23  kISO_14496_3 = 0x40, // MPEG4 AAC
24  kISO_13818_7_AAC_LC = 0x67, // MPEG2 AAC-LC
25  kISO_13818_3_MPEG1 = 0x69, // MPEG1 ISO/IEC 13818-3, 16,22.05,24kHz
26  kISO_11172_3_MPEG1 = 0x6B, // MPEG1 ISO/IEC 11172-3, 32,44.1,48kHz
27  kDTSC = 0xA9, // DTS Coherent Acoustics audio
28  kDTSE = 0xAC, // DTS Express low bit rate audio
29  kDTSH = 0xAA, // DTS-HD High Resolution Audio
30  kDTSL = 0xAB, // DTS-HD Master Audio
31 };
32 
33 enum class DescriptorTag {
34  kForbidden = 0,
35  kES = 0x03,
36  kDecoderConfig = 0x04,
37  kDecoderSpecificInfo = 0x05,
38  kSLConfig = 0x06,
39 };
40 
44  public:
45  explicit BaseDescriptor(DescriptorTag tag) : tag_(tag) {}
46 
49  bool Parse(const std::vector<uint8_t>& data);
50 
53  bool Read(BitReader* reader);
54 
59  void Write(BufferWriter* writer);
60 
63  size_t ComputeSize();
64 
65  protected:
67  void WriteHeader(BufferWriter* writer);
68 
70  size_t data_size() const { return data_size_; }
71 
72  private:
73  // Read the descriptor data (header is already read).
74  virtual bool ReadData(BitReader* reader) = 0;
75  // Write the descriptor. The descriptor data size should already be updated.
76  virtual void WriteInternal(BufferWriter* writer) = 0;
77  // Compute the data size, with child descriptors included.
78  virtual size_t ComputeDataSize() = 0;
79 
80  DescriptorTag tag_ = DescriptorTag::kForbidden;
81  size_t data_size_ = 0;
82 };
83 
87  public:
89  : BaseDescriptor(DescriptorTag::kDecoderSpecificInfo) {}
90 
91  const std::vector<uint8_t>& data() const { return data_; }
92 
93  void set_data(const std::vector<uint8_t>& data) { data_ = data; }
94 
95  private:
96  bool ReadData(BitReader* reader) override;
97  void WriteInternal(BufferWriter* writer) override;
98  size_t ComputeDataSize() override;
99 
100  std::vector<uint8_t> data_;
101 };
102 
106  public:
107  DecoderConfigDescriptor() : BaseDescriptor(DescriptorTag::kDecoderConfig) {}
108 
109  uint32_t buffer_size_db() const { return buffer_size_db_; }
110  void set_buffer_size_db(uint32_t buffer_size_db) {
111  buffer_size_db_ = buffer_size_db;
112  }
113 
114  uint32_t max_bitrate() const { return max_bitrate_; }
115  void set_max_bitrate(uint32_t max_bitrate) { max_bitrate_ = max_bitrate; }
116 
117  uint32_t avg_bitrate() const { return avg_bitrate_; }
118  void set_avg_bitrate(uint32_t avg_bitrate) { avg_bitrate_ = avg_bitrate; }
119 
120  ObjectType object_type() const { return object_type_; }
121  void set_object_type(ObjectType object_type) { object_type_ = object_type; }
122 
124  bool IsAAC() const {
125  return object_type_ == ObjectType::kISO_14496_3 ||
126  object_type_ == ObjectType::kISO_13818_7_AAC_LC;
127  }
128 
130  bool IsDTS() const {
131  return object_type_ == ObjectType::kDTSC ||
132  object_type_ == ObjectType::kDTSE ||
133  object_type_ == ObjectType::kDTSH ||
134  object_type_ == ObjectType::kDTSL;
135  }
136 
137  const DecoderSpecificInfoDescriptor& decoder_specific_info_descriptor()
138  const {
139  return decoder_specific_info_descriptor_;
140  }
141 
142  DecoderSpecificInfoDescriptor* mutable_decoder_specific_info_descriptor() {
143  return &decoder_specific_info_descriptor_;
144  }
145 
146  private:
147  bool ReadData(BitReader* reader) override;
148  void WriteInternal(BufferWriter* writer) override;
149  size_t ComputeDataSize() override;
150 
151  ObjectType object_type_ = ObjectType::kForbidden;
152  uint32_t buffer_size_db_ = 0;
153  uint32_t max_bitrate_ = 0;
154  uint32_t avg_bitrate_ = 0;
155  DecoderSpecificInfoDescriptor decoder_specific_info_descriptor_;
156 };
157 
161  public:
162  SLConfigDescriptor() : BaseDescriptor(DescriptorTag::kSLConfig) {}
163 
164  private:
165  bool ReadData(BitReader* reader) override;
166  void WriteInternal(BufferWriter* writer) override;
167  size_t ComputeDataSize() override;
168 };
169 
173 class ESDescriptor : public BaseDescriptor {
174  public:
175  ESDescriptor() : BaseDescriptor(DescriptorTag::kES) {}
176 
177  uint16_t esid() const { return esid_; }
178 
179  const DecoderConfigDescriptor& decoder_config_descriptor() const {
180  return decoder_config_descriptor_;
181  }
182 
183  DecoderConfigDescriptor* mutable_decoder_config_descriptor() {
184  return &decoder_config_descriptor_;
185  }
186 
187  private:
188  bool ReadData(BitReader* reader) override;
189  void WriteInternal(BufferWriter* writer) override;
190  size_t ComputeDataSize() override;
191 
192  uint16_t esid_ = 0; // Elementary Stream ID.
193 
194  DecoderConfigDescriptor decoder_config_descriptor_;
195  SLConfigDescriptor sl_config_descriptor_;
196 };
197 
198 } // namespace media
199 } // namespace shaka
200 
201 #endif // PACKAGER_MEDIA_CODECS_ES_DESCRIPTOR_H_
shaka::media::BufferWriter
Definition: buffer_writer.h:23
shaka::media::SLConfigDescriptor
Definition: es_descriptor.h:160
shaka::media::ESDescriptor
Definition: es_descriptor.h:173
shaka::media::BaseDescriptor::Read
bool Read(BitReader *reader)
Definition: es_descriptor.cc:86
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::media::BitReader
A class to read bit streams.
Definition: bit_reader.h:17
shaka::media::DecoderConfigDescriptor::IsDTS
bool IsDTS() const
Definition: es_descriptor.h:130
shaka::media::BaseDescriptor::Parse
bool Parse(const std::vector< uint8_t > &data)
Definition: es_descriptor.cc:81
shaka::media::BaseDescriptor::WriteHeader
void WriteHeader(BufferWriter *writer)
Write descriptor header.
Definition: es_descriptor.cc:113
shaka::media::DecoderConfigDescriptor
Definition: es_descriptor.h:105
shaka::media::BaseDescriptor::ComputeSize
size_t ComputeSize()
Definition: es_descriptor.cc:108
shaka::media::DecoderSpecificInfoDescriptor
Definition: es_descriptor.h:86
shaka::media::BaseDescriptor::data_size
size_t data_size() const
Definition: es_descriptor.h:70
shaka::media::DecoderConfigDescriptor::IsAAC
bool IsAAC() const
Definition: es_descriptor.h:124
shaka::media::BaseDescriptor::Write
void Write(BufferWriter *writer)
Definition: es_descriptor.cc:98
shaka::media::BaseDescriptor
Definition: es_descriptor.h:43