7#include <packager/media/codecs/video_slice_header_parser.h>
13#include <absl/log/check.h>
14#include <absl/log/log.h>
16#include <packager/media/base/rcheck.h>
17#include <packager/media/codecs/avc_decoder_configuration_record.h>
18#include <packager/media/codecs/h264_parser.h>
19#include <packager/media/codecs/h265_parser.h>
20#include <packager/media/codecs/hevc_decoder_configuration_record.h>
21#include <packager/media/codecs/nalu_reader.h>
28size_t NumBitsToNumBytes(
size_t size_in_bits) {
30 return (size_in_bits + 7) >> 3;
35H264VideoSliceHeaderParser::H264VideoSliceHeaderParser() {}
36H264VideoSliceHeaderParser::~H264VideoSliceHeaderParser() {}
39 const std::vector<uint8_t>& decoder_configuration) {
41 RCHECK(config.
Parse(decoder_configuration));
43 for (
size_t i = 0; i < config.
nalu_count(); i++) {
46 if (nalu.
type() == Nalu::H264_SPS) {
47 RCHECK(parser_.ParseSps(nalu, &
id) == H264Parser::kOk);
48 }
else if (nalu.
type() == Nalu::H264_PPS) {
49 RCHECK(parser_.ParsePps(nalu, &
id) == H264Parser::kOk);
57 const std::vector<uint8_t>& layered_decoder_configuration) {
63 switch (nalu.
type()) {
65 return parser_.ParseSps(nalu, &
id) == H264Parser::kOk;
67 return parser_.ParsePps(nalu, &
id) == H264Parser::kOk;
76 if (parser_.ParseSliceHeader(nalu, &slice_header) != H264Parser::kOk)
79 return NumBitsToNumBytes(slice_header.header_bit_size);
82H265VideoSliceHeaderParser::H265VideoSliceHeaderParser() {}
83H265VideoSliceHeaderParser::~H265VideoSliceHeaderParser() {}
85bool H265VideoSliceHeaderParser::ParseParameterSets(
86 const HEVCDecoderConfigurationRecord& config) {
88 for (
size_t i = 0; i < config.nalu_count(); i++) {
89 const Nalu& nalu = config.nalu(i);
90 if (nalu.type() == Nalu::H265_SPS) {
91 RCHECK(parser_.
ParseSps(nalu, &
id) == H265Parser::kOk);
92 }
else if (nalu.type() == Nalu::H265_PPS) {
93 RCHECK(parser_.
ParsePps(nalu, &
id) == H265Parser::kOk);
94 }
else if (nalu.type() == Nalu::H265_VPS) {
95 RCHECK(parser_.
ParseVps(nalu, &
id) == H265Parser::kOk);
97 VLOG(1) <<
"Ignoring decoder configuration Nalu of unknown type "
106 const std::vector<uint8_t>& decoder_configuration) {
108 RCHECK(hevc_config.
Parse(decoder_configuration));
109 return ParseParameterSets(hevc_config);
113 const std::vector<uint8_t>& layered_decoder_configuration) {
114 if (layered_decoder_configuration.size() > 0) {
116 lhevc_config.SetParser(&parser_);
117 RCHECK(lhevc_config.ParseLHEVCConfig(layered_decoder_configuration));
118 return ParseParameterSets(lhevc_config);
126 switch (nalu.
type()) {
128 return parser_.
ParseSps(nalu, &
id) == H265Parser::kOk;
130 return parser_.
ParsePps(nalu, &
id) == H265Parser::kOk;
132 return parser_.
ParseVps(nalu, &
id) == H265Parser::kOk;
144 return NumBitsToNumBytes(slice_header.header_bit_size);
All the methods that are virtual are virtual for mocking.