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