Shaka Packager SDK
Loading...
Searching...
No Matches
h26x_byte_to_unit_stream_converter.h
1// Copyright 2016 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#ifndef PACKAGER_MEDIA_CODECS_H26X_BYTE_TO_UNIT_STREAM_CONVERTER_H_
8#define PACKAGER_MEDIA_CODECS_H26X_BYTE_TO_UNIT_STREAM_CONVERTER_H_
9
10#include <cstddef>
11#include <cstdint>
12#include <vector>
13
14#include <packager/macros/classes.h>
15#include <packager/media/base/video_stream_info.h>
16#include <packager/media/codecs/nalu_reader.h>
17
18namespace shaka {
19namespace media {
20
21class BufferWriter;
22
25 public:
26 static constexpr size_t kUnitStreamNaluLengthSize = 4;
27
30 explicit H26xByteToUnitStreamConverter(Nalu::CodecType type);
31
34 H26xByteToUnitStreamConverter(Nalu::CodecType type,
35 H26xStreamFormat stream_format);
36
38
47 bool ConvertByteStreamToNalUnitStream(const uint8_t* input_frame,
48 size_t input_frame_size,
49 std::vector<uint8_t>* output_frame);
50
58 std::vector<uint8_t>* decoder_config) const = 0;
59
60 H26xStreamFormat stream_format() const { return stream_format_; }
61
62 protected:
63 bool strip_parameter_set_nalus() const {
64 return stream_format_ ==
65 H26xStreamFormat::kNalUnitStreamWithoutParameterSetNalus;
66 }
67
68 // Warn if (nalu_ptr, nalu_size) does not match with |vector|.
69 void WarnIfNotMatch(int nalu_type,
70 const uint8_t* nalu_ptr,
71 size_t nalu_size,
72 const std::vector<uint8_t>& vector);
73
74 private:
75 // Process the given Nalu. If this returns true, it was handled and should
76 // not be copied to the buffer.
77 virtual bool ProcessNalu(const Nalu& nalu) = 0;
78
79 Nalu::CodecType type_;
80 H26xStreamFormat stream_format_;
81
82 DISALLOW_COPY_AND_ASSIGN(H26xByteToUnitStreamConverter);
83};
84
85} // namespace media
86} // namespace shaka
87
88#endif // PACKAGER_MEDIA_CODECS_H26x_BYTE_TO_UNIT_STREAM_CONVERTER_H_
A base class that is used to convert H.26x byte streams to NAL unit streams.
virtual bool GetDecoderConfigurationRecord(std::vector< uint8_t > *decoder_config) const =0
bool ConvertByteStreamToNalUnitStream(const uint8_t *input_frame, size_t input_frame_size, std::vector< uint8_t > *output_frame)
All the methods that are virtual are virtual for mocking.