7 #include "packager/media/formats/mp2t/es_parser_h265.h"
11 #include "packager/base/logging.h"
12 #include "packager/media/base/media_sample.h"
13 #include "packager/media/base/offset_byte_queue.h"
14 #include "packager/media/base/timestamp.h"
15 #include "packager/media/base/video_stream_info.h"
16 #include "packager/media/filters/hevc_decoder_configuration.h"
17 #include "packager/media/filters/h265_parser.h"
18 #include "packager/media/filters/h26x_byte_to_unit_stream_converter.h"
19 #include "packager/media/formats/mp2t/mp2t_common.h"
21 namespace edash_packager {
25 EsParserH265::EsParserH265(uint32_t pid,
26 const NewStreamInfoCB& new_stream_info_cb,
27 const EmitSampleCB& emit_sample_cb)
28 : EsParserH26x(Nalu::kH265, pid, emit_sample_cb),
29 new_stream_info_cb_(new_stream_info_cb),
30 decoder_config_check_pending_(false),
31 h265_parser_(new H265Parser()) {}
33 EsParserH265::~EsParserH265() {}
35 void EsParserH265::Reset() {
36 DVLOG(1) <<
"EsParserH265::Reset";
37 h265_parser_.reset(
new H265Parser());
38 last_video_decoder_config_ = scoped_refptr<StreamInfo>();
39 decoder_config_check_pending_ =
false;
40 EsParserH26x::Reset();
43 bool EsParserH265::ProcessNalu(
const Nalu& nalu,
45 int* pps_id_for_access_unit) {
46 switch (nalu.type()) {
47 case Nalu::H265_AUD: {
48 DVLOG(LOG_LEVEL_ES) <<
"Nalu: AUD";
51 case Nalu::H265_SPS: {
52 DVLOG(LOG_LEVEL_ES) <<
"Nalu: SPS";
54 if (h265_parser_->ParseSps(nalu, &sps_id) != H265Parser::kOk)
56 decoder_config_check_pending_ =
true;
59 case Nalu::H265_PPS: {
60 DVLOG(LOG_LEVEL_ES) <<
"Nalu: PPS";
62 if (h265_parser_->ParsePps(nalu, &pps_id) != H265Parser::kOk) {
64 if (last_video_decoder_config_)
67 decoder_config_check_pending_ =
true;
72 if (nalu.is_video_slice()) {
73 *is_key_frame = nalu.type() == Nalu::H265_IDR_W_RADL ||
74 nalu.type() == Nalu::H265_IDR_N_LP;
75 DVLOG(LOG_LEVEL_ES) <<
"Nalu: slice KeyFrame=" << is_key_frame;
77 if (h265_parser_->ParseSliceHeader(nalu, &shdr) != H265Parser::kOk) {
80 if (last_video_decoder_config_)
83 *pps_id_for_access_unit = shdr.pic_parameter_set_id;
86 DVLOG(LOG_LEVEL_ES) <<
"Nalu: " << nalu.type();
94 bool EsParserH265::UpdateVideoDecoderConfig(
int pps_id) {
96 if (!decoder_config_check_pending_)
99 const H265Pps* pps = h265_parser_->GetPps(pps_id);
107 return last_video_decoder_config_ ==
nullptr;
109 sps = h265_parser_->GetSps(pps->seq_parameter_set_id);
112 decoder_config_check_pending_ =
false;
115 std::vector<uint8_t> decoder_config_record;
116 HEVCDecoderConfiguration decoder_config;
117 if (!stream_converter()->GetDecoderConfigurationRecord(
118 &decoder_config_record) ||
119 !decoder_config.Parse(decoder_config_record)) {
120 DLOG(ERROR) <<
"Failure to construct an HEVCDecoderConfigurationRecord";
124 if (last_video_decoder_config_) {
125 if (last_video_decoder_config_->extra_data() != decoder_config_record) {
131 LOG(WARNING) <<
"H.265 decoder configuration has changed.";
132 last_video_decoder_config_->set_extra_data(decoder_config_record);
137 uint32_t coded_width = 0;
138 uint32_t coded_height = 0;
139 uint32_t pixel_width = 0;
140 uint32_t pixel_height = 0;
141 if (!ExtractResolutionFromSps(*sps, &coded_width, &coded_height, &pixel_width,
143 LOG(ERROR) <<
"Failed to parse SPS.";
147 last_video_decoder_config_ = scoped_refptr<StreamInfo>(
153 decoder_config.GetCodecString(kCodecHVC1),
160 H26xByteToUnitStreamConverter::kUnitStreamNaluLengthSize,
161 decoder_config_record.data(),
162 decoder_config_record.size(),
166 new_stream_info_cb_.Run(last_video_decoder_config_);