7 #include <packager/media/codecs/video_slice_header_parser.h>
9 #include <absl/log/check.h>
11 #include <packager/macros/logging.h>
12 #include <packager/media/base/rcheck.h>
13 #include <packager/media/codecs/avc_decoder_configuration_record.h>
14 #include <packager/media/codecs/hevc_decoder_configuration_record.h>
21 size_t NumBitsToNumBytes(
size_t size_in_bits) {
23 return (size_in_bits + 7) >> 3;
28 H264VideoSliceHeaderParser::H264VideoSliceHeaderParser() {}
29 H264VideoSliceHeaderParser::~H264VideoSliceHeaderParser() {}
32 const std::vector<uint8_t>& decoder_configuration) {
34 RCHECK(config.
Parse(decoder_configuration));
36 for (
size_t i = 0; i < config.
nalu_count(); i++) {
39 if (nalu.
type() == Nalu::H264_SPS) {
40 RCHECK(parser_.ParseSps(nalu, &
id) == H264Parser::kOk);
41 }
else if (nalu.
type() == Nalu::H264_PPS) {
42 RCHECK(parser_.ParsePps(nalu, &
id) == H264Parser::kOk);
51 switch (nalu.
type()) {
53 return parser_.ParseSps(nalu, &
id) == H264Parser::kOk;
55 return parser_.ParsePps(nalu, &
id) == H264Parser::kOk;
64 if (parser_.ParseSliceHeader(nalu, &slice_header) != H264Parser::kOk)
67 return NumBitsToNumBytes(slice_header.header_bit_size);
70 H265VideoSliceHeaderParser::H265VideoSliceHeaderParser() {}
71 H265VideoSliceHeaderParser::~H265VideoSliceHeaderParser() {}
74 const std::vector<uint8_t>& decoder_configuration) {
77 RCHECK(hevc_config.
Parse(decoder_configuration));
79 for (
size_t i = 0; i < hevc_config.
nalu_count(); i++) {
80 const Nalu& nalu = hevc_config.
nalu(i);
81 if (nalu.
type() == Nalu::H265_SPS) {
82 RCHECK(parser_.
ParseSps(nalu, &
id) == H265Parser::kOk);
83 }
else if (nalu.
type() == Nalu::H265_PPS) {
84 RCHECK(parser_.
ParsePps(nalu, &
id) == H265Parser::kOk);
85 }
else if (nalu.
type() == Nalu::H265_VPS) {
88 VLOG(1) <<
"Ignoring decoder configuration Nalu of unknown type "
98 switch (nalu.
type()) {
100 return parser_.
ParseSps(nalu, &
id) == H265Parser::kOk;
102 return parser_.
ParsePps(nalu, &
id) == H265Parser::kOk;
117 return NumBitsToNumBytes(slice_header.header_bit_size);
All the methods that are virtual are virtual for mocking.