Shaka Packager SDK
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 <cstdint>
11 #include <vector>
12 
13 #include <packager/macros/classes.h>
14 #include <packager/media/base/video_stream_info.h>
15 #include <packager/media/codecs/nalu_reader.h>
16 
17 namespace shaka {
18 namespace media {
19 
20 class BufferWriter;
21 
24  public:
25  static constexpr size_t kUnitStreamNaluLengthSize = 4;
26 
29  explicit H26xByteToUnitStreamConverter(Nalu::CodecType type);
30 
33  H26xByteToUnitStreamConverter(Nalu::CodecType type,
34  H26xStreamFormat stream_format);
35 
37 
46  bool ConvertByteStreamToNalUnitStream(const uint8_t* input_frame,
47  size_t input_frame_size,
48  std::vector<uint8_t>* output_frame);
49 
57  std::vector<uint8_t>* decoder_config) const = 0;
58 
59  H26xStreamFormat stream_format() const { return stream_format_; }
60 
61  protected:
62  bool strip_parameter_set_nalus() const {
63  return stream_format_ ==
64  H26xStreamFormat::kNalUnitStreamWithoutParameterSetNalus;
65  }
66 
67  // Warn if (nalu_ptr, nalu_size) does not match with |vector|.
68  void WarnIfNotMatch(int nalu_type,
69  const uint8_t* nalu_ptr,
70  size_t nalu_size,
71  const std::vector<uint8_t>& vector);
72 
73  private:
74  // Process the given Nalu. If this returns true, it was handled and should
75  // not be copied to the buffer.
76  virtual bool ProcessNalu(const Nalu& nalu) = 0;
77 
78  Nalu::CodecType type_;
79  H26xStreamFormat stream_format_;
80 
81  DISALLOW_COPY_AND_ASSIGN(H26xByteToUnitStreamConverter);
82 };
83 
84 } // namespace media
85 } // namespace shaka
86 
87 #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.
Definition: crypto_flags.cc:66