Shaka Packager SDK
Loading...
Searching...
No Matches
av1_codec_configuration_record.cc
1// Copyright 2018 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#include <packager/media/codecs/av1_codec_configuration_record.h>
8
9#include <absl/strings/str_format.h>
10
11#include <packager/media/base/bit_reader.h>
12#include <packager/media/base/rcheck.h>
13
14namespace shaka {
15namespace media {
16
17AV1CodecConfigurationRecord::AV1CodecConfigurationRecord() = default;
18
19AV1CodecConfigurationRecord::~AV1CodecConfigurationRecord() = default;
20
21// https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox-section
22// aligned (8) class AV1CodecConfigurationRecord {
23// unsigned int (1) marker = 1;
24// unsigned int (7) version = 1;
25// unsigned int (3) seq_profile;
26// unsigned int (5) seq_level_idx_0;
27// unsigned int (1) seq_tier_0;
28// unsigned int (1) high_bitdepth;
29// unsigned int (1) twelve_bit;
30// unsigned int (1) monochrome;
31// unsigned int (1) chroma_subsampling_x;
32// unsigned int (1) chroma_subsampling_y;
33// unsigned int (2) chroma_sample_position;
34// unsigned int (3) reserved = 0;
35//
36// unsigned int (1) initial_presentation_delay_present;
37// if (initial_presentation_delay_present) {
38// unsigned int (4) initial_presentation_delay_minus_one;
39// } else {
40// unsigned int (4) reserved = 0;
41// }
42//
43// unsigned int (8)[] configOBUs;
44// }
45bool AV1CodecConfigurationRecord::Parse(const uint8_t* data, size_t data_size) {
46 RCHECK(data_size > 0);
47
48 BitReader reader(data, data_size);
49
50 int marker;
51 RCHECK(reader.ReadBits(1, &marker));
52 RCHECK(marker == 1);
53
54 int version;
55 RCHECK(reader.ReadBits(7, &version));
56 RCHECK(version == 1);
57
58 RCHECK(reader.ReadBits(3, &profile_));
59 RCHECK(reader.ReadBits(5, &level_));
60 RCHECK(reader.ReadBits(1, &tier_));
61
62 int high_bitdepth;
63 int twelve_bit;
64 RCHECK(reader.ReadBits(1, &high_bitdepth));
65 RCHECK(reader.ReadBits(1, &twelve_bit));
66 bit_depth_ = twelve_bit ? 12 : (high_bitdepth ? 10 : 8);
67
68 RCHECK(reader.ReadBits(1, &mono_chrome_));
69 RCHECK(reader.ReadBits(1, &chroma_subsampling_x_));
70 RCHECK(reader.ReadBits(1, &chroma_subsampling_y_));
71 RCHECK(reader.ReadBits(2, &chroma_sample_position_));
72
73 // Skip other fields (e.g. initial_presentation_delay) which we do not need.
74 return true;
75}
76
77// https://aomediacodec.github.io/av1-isobmff/#codecsparam
78// <sample entry 4CC>.<profile>.<level><tier>.<bitDepth>.<monochrome>.
79// <chromaSubsampling>.<colorPrimaries>.<transferCharacteristics>.
80// <matrixCoefficients>.<videoFullRangeFlag>
81// The parameters sample entry 4CC, profile, level, tier, and bitDepth are all
82// mandatory fields.
83// All the other fields (including their leading '.') are optional, mutually
84// inclusive (all or none) fields.
85
86// When color info is NOT available, generate the basic codec string without the
87// optional fields
89 return absl::StrFormat("av01.%d.%02d%c.%02d", profile_, level_,
90 tier_ ? 'H' : 'M', bit_depth_);
91}
92
93// When color info IS available, generate the full codec string with optional
94// fields
96 uint16_t color_primaries,
97 uint16_t transfer_characteristics,
98 uint16_t matrix_coefficients,
99 uint8_t video_full_range_flag) const {
100 return absl::StrFormat(
101 "av01.%d.%02d%c.%02d.%d.%d%d%d.%02d.%02d.%02d.%d", profile_, level_,
102 tier_ ? 'H' : 'M', bit_depth_, mono_chrome_, chroma_subsampling_x_,
103 chroma_subsampling_y_, chroma_sample_position_, color_primaries,
104 transfer_characteristics, matrix_coefficients, video_full_range_flag);
105}
106
107} // namespace media
108} // namespace shaka
bool Parse(const std::vector< uint8_t > &data)
A class to read bit streams.
Definition bit_reader.h:20
bool ReadBits(size_t num_bits, T *out)
Definition bit_reader.h:38
All the methods that are virtual are virtual for mocking.