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