7 #include <packager/media/codecs/h265_byte_to_unit_stream_converter.h>
11 #include <absl/log/check.h>
12 #include <absl/log/log.h>
14 #include <packager/media/base/buffer_writer.h>
15 #include <packager/media/base/rcheck.h>
16 #include <packager/media/codecs/h265_parser.h>
25 H26xStreamFormat stream_format)
28 H265ByteToUnitStreamConverter::~H265ByteToUnitStreamConverter() {}
31 std::vector<uint8_t>* decoder_config)
const {
32 DCHECK(decoder_config);
34 if (last_sps_.empty() || last_pps_.empty() || last_vps_.empty()) {
43 RCHECK(nalu.Initialize(Nalu::kH265, last_sps_.data(), last_sps_.size()));
44 RCHECK(parser.
ParseSps(nalu, &
id) == H265Parser::kOk);
49 BufferWriter buffer(last_sps_.size() + last_pps_.size() + last_vps_.size() +
51 buffer.
AppendInt(
static_cast<uint8_t
>(1) );
56 for (
int byte : sps->general_profile_tier_level_data)
57 buffer.
AppendInt(
static_cast<uint8_t
>(
byte));
60 int min_spatial_segmentation_idc =
61 sps->vui_parameters.min_spatial_segmentation_idc;
64 static_cast<uint16_t
>(0xf000 | min_spatial_segmentation_idc));
65 buffer.
AppendInt(
static_cast<uint8_t
>(0xfc) );
66 buffer.
AppendInt(
static_cast<uint8_t
>(0xfc | sps->chroma_format_idc));
67 buffer.
AppendInt(
static_cast<uint8_t
>(0xf8 | sps->bit_depth_luma_minus8));
68 buffer.
AppendInt(
static_cast<uint8_t
>(0xf8 | sps->bit_depth_chroma_minus8));
69 buffer.
AppendInt(
static_cast<uint16_t
>(0) );
74 buffer.
AppendInt(
static_cast<uint8_t
>(kUnitStreamNaluLengthSize - 1));
75 buffer.
AppendInt(
static_cast<uint8_t
>(3) );
79 const uint8_t array_completeness = strip_parameter_set_nalus() ? 0x80 : 0;
82 buffer.
AppendInt(
static_cast<uint8_t
>(array_completeness | Nalu::H265_VPS));
83 buffer.
AppendInt(
static_cast<uint16_t
>(1) );
84 buffer.
AppendInt(
static_cast<uint16_t
>(last_vps_.size()));
85 buffer.AppendVector(last_vps_);
88 buffer.
AppendInt(
static_cast<uint8_t
>(array_completeness | Nalu::H265_SPS));
89 buffer.
AppendInt(
static_cast<uint16_t
>(1) );
90 buffer.
AppendInt(
static_cast<uint16_t
>(last_sps_.size()));
91 buffer.AppendVector(last_sps_);
94 buffer.
AppendInt(
static_cast<uint8_t
>(array_completeness | Nalu::H265_PPS));
95 buffer.
AppendInt(
static_cast<uint16_t
>(1) );
96 buffer.
AppendInt(
static_cast<uint16_t
>(last_pps_.size()));
97 buffer.AppendVector(last_pps_);
99 buffer.SwapBuffer(decoder_config);
103 bool H265ByteToUnitStreamConverter::ProcessNalu(
const Nalu& nalu) {
107 const uint8_t* nalu_ptr = nalu.
data();
110 switch (nalu.
type()) {
112 if (strip_parameter_set_nalus())
113 WarnIfNotMatch(nalu.
type(), nalu_ptr, nalu_size, last_sps_);
115 last_sps_.assign(nalu_ptr, nalu_ptr + nalu_size);
116 return strip_parameter_set_nalus();
118 if (strip_parameter_set_nalus())
119 WarnIfNotMatch(nalu.
type(), nalu_ptr, nalu_size, last_pps_);
121 last_pps_.assign(nalu_ptr, nalu_ptr + nalu_size);
122 return strip_parameter_set_nalus();
124 if (strip_parameter_set_nalus())
125 WarnIfNotMatch(nalu.
type(), nalu_ptr, nalu_size, last_vps_);
127 last_vps_.assign(nalu_ptr, nalu_ptr + nalu_size);
128 return strip_parameter_set_nalus();
All the methods that are virtual are virtual for mocking.