7 #include "packager/media/filters/hevc_decoder_configuration.h"
9 #include "packager/base/strings/string_number_conversions.h"
10 #include "packager/base/strings/string_util.h"
11 #include "packager/media/base/buffer_reader.h"
12 #include "packager/media/formats/mp4/rcheck.h"
14 namespace edash_packager {
20 std::string GeneralProfileSpaceAsString(uint8_t general_profile_space) {
21 switch (general_profile_space) {
31 LOG(WARNING) <<
"Unexpected general_profile_space "
32 << general_profile_space;
37 std::string TrimLeadingZeros(
const std::string& str) {
38 DCHECK_GT(str.size(), 0u);
39 for (
size_t i = 0; i < str.size(); ++i) {
40 if (str[i] ==
'0')
continue;
51 std::string ReverseBitsAndHexEncode(uint32_t x) {
52 x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1);
53 x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2);
54 x = ((x & 0x0F0F0F0F) << 4) | ((x & 0xF0F0F0F0) >> 4);
55 const uint8_t bytes[] = {
static_cast<uint8_t
>(x & 0xFF),
56 static_cast<uint8_t>((x >> 8) & 0xFF),
57 static_cast<uint8_t>((x >> 16) & 0xFF),
58 static_cast<uint8_t>((x >> 24) & 0xFF)};
59 return TrimLeadingZeros(base::HexEncode(bytes, arraysize(bytes)));
62 std::string CodecAsString(VideoCodec codec) {
69 LOG(WARNING) <<
"Unknown codec: " << codec;
76 HEVCDecoderConfiguration::HEVCDecoderConfiguration()
78 general_profile_space_(0),
79 general_tier_flag_(false),
80 general_profile_idc_(0),
81 general_profile_compatibility_flags_(0),
82 general_level_idc_(0),
85 HEVCDecoderConfiguration::~HEVCDecoderConfiguration() {}
90 uint8_t profile_indication = 0;
91 uint8_t length_size_minus_one = 0;
92 uint8_t num_of_arrays = 0;
93 RCHECK(reader.Read1(&version_) && version_ == 1 &&
94 reader.Read1(&profile_indication) &&
95 reader.Read4(&general_profile_compatibility_flags_) &&
96 reader.ReadToVector(&general_constraint_indicator_flags_, 6) &&
97 reader.Read1(&general_level_idc_) &&
98 reader.SkipBytes(8) &&
99 reader.Read1(&length_size_minus_one) &&
100 reader.Read1(&num_of_arrays));
102 general_profile_space_ = profile_indication >> 6;
103 RCHECK(general_profile_space_ <= 3u);
104 general_tier_flag_ = ((profile_indication >> 5) & 1) == 1;
105 general_profile_idc_ = profile_indication & 0x1f;
107 length_size_ = (length_size_minus_one & 0x3) + 1;
115 std::vector<std::string> fields;
116 fields.push_back(CodecAsString(codec));
117 fields.push_back(GeneralProfileSpaceAsString(general_profile_space_) +
118 base::IntToString(general_profile_idc_));
120 ReverseBitsAndHexEncode(general_profile_compatibility_flags_));
121 fields.push_back((general_tier_flag_ ?
"H" :
"L") +
122 base::IntToString(general_level_idc_));
125 std::vector<uint8_t> constraints = general_constraint_indicator_flags_;
126 size_t size = constraints.size();
127 for (; size > 0; --size) {
128 if (constraints[size - 1] != 0)
break;
130 constraints.resize(size);
131 for (uint8_t constraint : constraints)
132 fields.push_back(TrimLeadingZeros(base::HexEncode(&constraint, 1)));
134 return base::JoinString(fields,
".");