Shaka Packager SDK
vp_codec_configuration_record.h
1 // Copyright 2015 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_CODECS_VP_CODEC_CONFIGURATION_RECORD_H_
8 #define PACKAGER_MEDIA_CODECS_VP_CODEC_CONFIGURATION_RECORD_H_
9 
10 #include <cstdint>
11 #include <optional>
12 #include <string>
13 #include <vector>
14 
15 #include <packager/macros/classes.h>
16 #include <packager/media/base/video_stream_info.h>
17 
18 namespace shaka {
19 namespace media {
20 
23 enum AVColorPrimaries {
24  AVCOL_PRI_RESERVED0 = 0,
26  AVCOL_PRI_BT709 = 1,
27  AVCOL_PRI_UNSPECIFIED = 2,
28  AVCOL_PRI_RESERVED = 3,
30  AVCOL_PRI_BT470M = 4,
32  AVCOL_PRI_BT470BG = 5,
34  AVCOL_PRI_SMPTE170M = 6,
36  AVCOL_PRI_SMPTE240M = 7,
38  AVCOL_PRI_FILM = 8,
40  AVCOL_PRI_BT2020 = 9,
42  AVCOL_PRI_SMPTE428 = 10,
43  AVCOL_PRI_SMPTEST428_1 = AVCOL_PRI_SMPTE428,
45  AVCOL_PRI_SMPTE431 = 11,
47  AVCOL_PRI_SMPTE432 = 12,
49  AVCOL_PRI_NB
50 };
51 
53 enum AVColorTransferCharacteristic {
54  AVCOL_TRC_RESERVED0 = 0,
56  AVCOL_TRC_BT709 = 1,
57  AVCOL_TRC_UNSPECIFIED = 2,
58  AVCOL_TRC_RESERVED = 3,
60  AVCOL_TRC_GAMMA22 = 4,
62  AVCOL_TRC_GAMMA28 = 5,
65  AVCOL_TRC_SMPTE170M = 6,
66  AVCOL_TRC_SMPTE240M = 7,
68  AVCOL_TRC_LINEAR = 8,
70  AVCOL_TRC_LOG = 9,
72  AVCOL_TRC_LOG_SQRT = 10,
74  AVCOL_TRC_IEC61966_2_4 = 11,
76  AVCOL_TRC_BT1361_ECG = 12,
78  AVCOL_TRC_IEC61966_2_1 = 13,
80  AVCOL_TRC_BT2020_10 = 14,
82  AVCOL_TRC_BT2020_12 = 15,
84  AVCOL_TRC_SMPTE2084 = 16,
85  AVCOL_TRC_SMPTEST2084 = AVCOL_TRC_SMPTE2084,
87  AVCOL_TRC_SMPTE428 = 17,
88  AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428,
90  AVCOL_TRC_ARIB_STD_B67 = 18,
92  AVCOL_TRC_NB
93 };
94 
96 enum AVColorSpace {
98  AVCOL_SPC_RGB = 0,
100  AVCOL_SPC_BT709 = 1,
101  AVCOL_SPC_UNSPECIFIED = 2,
102  AVCOL_SPC_RESERVED = 3,
104  AVCOL_SPC_FCC = 4,
107  AVCOL_SPC_BT470BG = 5,
109  AVCOL_SPC_SMPTE170M = 6,
111  AVCOL_SPC_SMPTE240M = 7,
113  AVCOL_SPC_YCOCG = 8,
115  AVCOL_SPC_BT2020_NCL = 9,
117  AVCOL_SPC_BT2020_CL = 10,
119  AVCOL_SPC_SMPTE2085 = 11,
121  AVCOL_SPC_NB
122 };
123 
137 enum AVChromaLocation {
138  AVCHROMA_LOC_UNSPECIFIED = 0,
140  AVCHROMA_LOC_LEFT = 1,
142  AVCHROMA_LOC_CENTER = 2,
144  AVCHROMA_LOC_TOPLEFT = 3,
145  AVCHROMA_LOC_TOP = 4,
146  AVCHROMA_LOC_BOTTOMLEFT = 5,
147  AVCHROMA_LOC_BOTTOM = 6,
149  AVCHROMA_LOC_NB
150 };
151 
154  public:
155  enum ChromaSubsampling {
156  CHROMA_420_VERTICAL = 0,
157  CHROMA_420_COLLOCATED_WITH_LUMA = 1,
158  CHROMA_422 = 2,
159  CHROMA_444 = 3,
160  CHROMA_440 = 4,
161  };
162  enum ChromaSitingValues {
163  kUnspecified = 0,
164  kLeftCollocated = 1,
165  kTopCollocated = kLeftCollocated,
166  kHalf = 2,
167  };
168 
171  uint8_t profile,
172  uint8_t level,
173  uint8_t bit_depth,
174  uint8_t chroma_subsampling,
175  bool video_full_range_flag,
176  uint8_t color_primaries,
177  uint8_t transfer_characteristics,
178  uint8_t matrix_coefficients,
179  const std::vector<uint8_t>& codec_initialization_data);
181 
184  bool ParseMP4(const std::vector<uint8_t>& data);
185 
188  bool ParseWebM(const std::vector<uint8_t>& data);
189 
191  void SetVP9Level(uint16_t width,
192  uint16_t height,
193  double sample_duration_seconds);
194 
197  void WriteMP4(std::vector<uint8_t>* data) const;
198 
201  void WriteWebM(std::vector<uint8_t>* data) const;
202 
204  std::string GetCodecString(Codec codec) const;
205 
208  void MergeFrom(const VPCodecConfigurationRecord& other);
209 
210  void SetChromaSubsampling(uint8_t subsampling_x, uint8_t subsampling_y);
211  void SetChromaSubsampling(ChromaSubsampling chroma_subsampling);
212  void SetChromaLocation(uint8_t chroma_siting_x, uint8_t chroma_siting_y);
213 
214  void set_profile(uint8_t profile) { profile_ = profile; }
215  void set_level(uint8_t level) { level_ = level; }
216  void set_bit_depth(uint8_t bit_depth) { bit_depth_ = bit_depth; }
217  void set_video_full_range_flag(bool video_full_range_flag) {
218  video_full_range_flag_ = video_full_range_flag;
219  }
220  void set_color_primaries(uint8_t color_primaries) {
221  color_primaries_ = color_primaries;
222  }
223  void set_transfer_characteristics(uint8_t transfer_characteristics) {
224  transfer_characteristics_ = transfer_characteristics;
225  }
226  void set_matrix_coefficients(uint8_t matrix_coefficients) {
227  matrix_coefficients_ = matrix_coefficients;
228  }
229 
230  bool is_profile_set() const { return static_cast<bool>(profile_); }
231  bool is_level_set() const { return static_cast<bool>(level_); }
232  bool is_bit_depth_set() const { return static_cast<bool>(bit_depth_); }
233  bool is_chroma_subsampling_set() const {
234  return static_cast<bool>(chroma_subsampling_);
235  }
236  bool is_video_full_range_flag_set() const {
237  return static_cast<bool>(video_full_range_flag_);
238  }
239  bool is_color_primaries_set() const {
240  return static_cast<bool>(color_primaries_);
241  }
242  bool is_transfer_characteristics_set() const {
243  return static_cast<bool>(transfer_characteristics_);
244  }
245  bool is_matrix_coefficients_set() const {
246  return static_cast<bool>(matrix_coefficients_);
247  }
248  bool is_chroma_location_set() const {
249  return static_cast<bool>(chroma_location_);
250  }
251 
252  uint8_t profile() const { return profile_.value_or(0); }
253  uint8_t level() const { return level_.value_or(10); }
254  uint8_t bit_depth() const { return bit_depth_.value_or(8); }
255  uint8_t chroma_subsampling() const {
256  return chroma_subsampling_.value_or(CHROMA_420_COLLOCATED_WITH_LUMA);
257  }
258  bool video_full_range_flag() const {
259  return video_full_range_flag_.value_or(false);
260  }
261  uint8_t color_primaries() const {
262  return color_primaries_.value_or(AVCOL_PRI_UNSPECIFIED);
263  }
264  uint8_t transfer_characteristics() const {
265  return transfer_characteristics_.value_or(AVCOL_TRC_UNSPECIFIED);
266  }
267  uint8_t matrix_coefficients() const {
268  return matrix_coefficients_.value_or(AVCOL_SPC_UNSPECIFIED);
269  }
270  uint8_t chroma_location() const {
271  return chroma_location_.value_or(AVCHROMA_LOC_UNSPECIFIED);
272  }
273 
274  private:
275  void UpdateChromaSubsamplingIfNeeded();
276 
277  std::optional<uint8_t> profile_;
278  std::optional<uint8_t> level_;
279  std::optional<uint8_t> bit_depth_;
280  std::optional<uint8_t> chroma_subsampling_;
281  std::optional<bool> video_full_range_flag_;
282  std::optional<uint8_t> color_primaries_;
283  std::optional<uint8_t> transfer_characteristics_;
284  std::optional<uint8_t> matrix_coefficients_;
285  std::vector<uint8_t> codec_initialization_data_;
286 
287  // Not in the decoder config. It is there to help determine chroma subsampling
288  // format.
289  std::optional<uint8_t> chroma_location_;
290  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
291  // generated copy constructor and assignment operator. Since the internal data
292  // is small, the performance impact is minimal.
293 };
294 
295 } // namespace media
296 } // namespace shaka
297 
298 #endif // PACKAGER_MEDIA_CODECS_VP_CODEC_CONFIGURATION_RECORD_H_
Class for parsing or writing VP codec configuration record.
void WriteMP4(std::vector< uint8_t > *data) const
void SetVP9Level(uint16_t width, uint16_t height, double sample_duration_seconds)
Compute and set VP9 Level based on the input attributes.
void MergeFrom(const VPCodecConfigurationRecord &other)
bool ParseWebM(const std::vector< uint8_t > &data)
void WriteWebM(std::vector< uint8_t > *data) const
bool ParseMP4(const std::vector< uint8_t > &data)
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66