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>
21size_t NumBitsToNumBytes(
size_t size_in_bits) {
23 return (size_in_bits + 7) >> 3;
28H264VideoSliceHeaderParser::H264VideoSliceHeaderParser() {}
29H264VideoSliceHeaderParser::~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);
50 const std::vector<uint8_t>& layered_decoder_configuration) {
56 switch (nalu.
type()) {
58 return parser_.ParseSps(nalu, &
id) == H264Parser::kOk;
60 return parser_.ParsePps(nalu, &
id) == H264Parser::kOk;
69 if (parser_.ParseSliceHeader(nalu, &slice_header) != H264Parser::kOk)
72 return NumBitsToNumBytes(slice_header.header_bit_size);
75H265VideoSliceHeaderParser::H265VideoSliceHeaderParser() {}
76H265VideoSliceHeaderParser::~H265VideoSliceHeaderParser() {}
78bool H265VideoSliceHeaderParser::ParseParameterSets(
79 const HEVCDecoderConfigurationRecord& config) {
81 for (
size_t i = 0; i < config.nalu_count(); i++) {
82 const Nalu& nalu = config.nalu(i);
83 if (nalu.type() == Nalu::H265_SPS) {
84 RCHECK(parser_.
ParseSps(nalu, &
id) == H265Parser::kOk);
85 }
else if (nalu.type() == Nalu::H265_PPS) {
86 RCHECK(parser_.
ParsePps(nalu, &
id) == H265Parser::kOk);
87 }
else if (nalu.type() == Nalu::H265_VPS) {
88 RCHECK(parser_.
ParseVps(nalu, &
id) == H265Parser::kOk);
90 VLOG(1) <<
"Ignoring decoder configuration Nalu of unknown type "
99 const std::vector<uint8_t>& decoder_configuration) {
101 RCHECK(hevc_config.
Parse(decoder_configuration));
102 return ParseParameterSets(hevc_config);
106 const std::vector<uint8_t>& layered_decoder_configuration) {
107 if (layered_decoder_configuration.size() > 0) {
109 lhevc_config.SetParser(&parser_);
110 RCHECK(lhevc_config.ParseLHEVCConfig(layered_decoder_configuration));
111 return ParseParameterSets(lhevc_config);
119 switch (nalu.
type()) {
121 return parser_.
ParseSps(nalu, &
id) == H265Parser::kOk;
123 return parser_.
ParsePps(nalu, &
id) == H265Parser::kOk;
125 return parser_.
ParseVps(nalu, &
id) == H265Parser::kOk;
137 return NumBitsToNumBytes(slice_header.header_bit_size);
All the methods that are virtual are virtual for mocking.