7 #include "packager/media/filters/vp_codec_configuration.h"
9 #include "packager/base/strings/string_number_conversions.h"
10 #include "packager/base/strings/string_util.h"
11 #include "packager/media/base/bit_reader.h"
12 #include "packager/media/base/buffer_writer.h"
13 #include "packager/media/base/rcheck.h"
14 #include "packager/base/strings/stringprintf.h"
20 std::string VPCodecAsString(VideoCodec codec) {
29 LOG(WARNING) <<
"Unknown VP codec: " << codec;
36 VPCodecConfiguration::VPCodecConfiguration()
41 chroma_subsampling_(0),
42 transfer_function_(0),
43 video_full_range_flag_(false) {}
45 VPCodecConfiguration::VPCodecConfiguration(
50 uint8_t chroma_subsampling,
51 uint8_t transfer_function,
52 bool video_full_range_flag,
53 const std::vector<uint8_t>& codec_initialization_data)
56 bit_depth_(bit_depth),
57 color_space_(color_space),
58 chroma_subsampling_(chroma_subsampling),
59 transfer_function_(transfer_function),
60 video_full_range_flag_(video_full_range_flag),
61 codec_initialization_data_(codec_initialization_data) {}
63 VPCodecConfiguration::~VPCodecConfiguration(){};
66 BitReader reader(data.data(), data.size());
67 RCHECK(reader.ReadBits(8, &profile_));
68 RCHECK(reader.ReadBits(8, &level_));
69 RCHECK(reader.ReadBits(4, &bit_depth_));
70 RCHECK(reader.ReadBits(4, &color_space_));
71 RCHECK(reader.ReadBits(4, &chroma_subsampling_));
72 RCHECK(reader.ReadBits(3, &transfer_function_));
73 RCHECK(reader.ReadBits(1, &video_full_range_flag_));
74 uint16_t codec_initialization_data_size = 0;
75 RCHECK(reader.ReadBits(16, &codec_initialization_data_size));
76 RCHECK(reader.bits_available() >= codec_initialization_data_size * 8);
77 const size_t header_size = data.size() - reader.bits_available() / 8;
78 codec_initialization_data_.assign(
79 data.begin() + header_size,
80 data.begin() + header_size + codec_initialization_data_size);
88 uint8_t bit_depth_color_space = (bit_depth_ << 4) | color_space_;
90 uint8_t chroma = (chroma_subsampling_ << 4) | (transfer_function_ << 1) |
91 (video_full_range_flag_ ? 1 : 0);
93 uint16_t codec_initialization_data_size = codec_initialization_data_.size();
94 writer.
AppendInt(codec_initialization_data_size);
95 writer.AppendVector(codec_initialization_data_);
96 writer.SwapBuffer(data);
100 const std::string fields[] = {
101 base::IntToString(profile_),
102 base::IntToString(level_),
103 base::IntToString(bit_depth_),
104 base::IntToString(color_space_),
105 base::IntToString(chroma_subsampling_),
106 base::IntToString(transfer_function_),
107 (video_full_range_flag_ ?
"01" :
"00"),
110 std::string codec_string = VPCodecAsString(codec);
111 for (
const std::string& field : fields) {
114 base::StringAppendF(&codec_string,
".%2s", field.c_str());
116 base::ReplaceChars(codec_string,
" ",
"0", &codec_string);