Shaka Packager SDK
subsample_generator.h
1 // Copyright 2018 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_CRYPTO_SUBSAMPLE_GENERATOR_H_
8 #define PACKAGER_MEDIA_CRYPTO_SUBSAMPLE_GENERATOR_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "packager/media/base/fourccs.h"
14 #include "packager/media/base/stream_info.h"
15 #include "packager/status.h"
16 
17 namespace shaka {
18 namespace media {
19 
20 class AV1Parser;
21 class VideoSliceHeaderParser;
22 class VPxParser;
23 struct SubsampleEntry;
24 
35  public:
38  explicit SubsampleGenerator(bool vp9_subsample_encryption);
39 
40  virtual ~SubsampleGenerator();
41 
48  virtual Status Initialize(FourCC protection_scheme,
49  const StreamInfo& stream_info);
50 
59  virtual Status GenerateSubsamples(const uint8_t* frame,
60  size_t frame_size,
61  std::vector<SubsampleEntry>* subsamples);
62 
63  // Testing injections.
64  void InjectVpxParserForTesting(std::unique_ptr<VPxParser> vpx_parser);
65  void InjectVideoSliceHeaderParserForTesting(
66  std::unique_ptr<VideoSliceHeaderParser> header_parser);
67  void InjectAV1ParserForTesting(std::unique_ptr<AV1Parser> av1_parser);
68 
69  private:
70  SubsampleGenerator(const SubsampleGenerator&) = delete;
71  SubsampleGenerator& operator=(const SubsampleGenerator&) = delete;
72 
73  Status GenerateSubsamplesFromVPxFrame(
74  const uint8_t* frame,
75  size_t frame_size,
76  std::vector<SubsampleEntry>* subsamples);
77  Status GenerateSubsamplesFromH26xFrame(
78  const uint8_t* frame,
79  size_t frame_size,
80  std::vector<SubsampleEntry>* subsamples);
81  Status GenerateSubsamplesFromAV1Frame(
82  const uint8_t* frame,
83  size_t frame_size,
84  std::vector<SubsampleEntry>* subsamples);
85 
86  const bool vp9_subsample_encryption_ = false;
87  // Whether the protected portion should be AES block (16 bytes) aligned.
88  bool align_protected_data_ = false;
89  Codec codec_ = kUnknownCodec;
90  // For NAL structured video only, the size of NAL unit length in bytes. Can be
91  // 1, 2 or 4 bytes.
92  uint8_t nalu_length_size_ = 0;
93  // For SAMPLE AES only, 32 bytes for Video and 16 bytes for audio.
94  size_t leading_clear_bytes_size_ = 0;
95  // For SAMPLE AES only, if the data size is less than this value, none of the
96  // bytes are encrypted. The size is 48+1 bytes for video NAL and 32 bytes for
97  // audio according to MPEG-2 Stream Encryption Format for HTTP Live Streaming.
98  size_t min_protected_data_size_ = 0;
99 
100  // VPx parser for VPx streams.
101  std::unique_ptr<VPxParser> vpx_parser_;
102  // Video slice header parser for NAL strucutred streams.
103  std::unique_ptr<VideoSliceHeaderParser> header_parser_;
104  // AV1 parser for AV1 streams.
105  std::unique_ptr<AV1Parser> av1_parser_;
106 };
107 
108 } // namespace media
109 } // namespace shaka
110 
111 #endif // PACKAGER_MEDIA_CRYPTO_SUBSAMPLE_GENERATOR_H_
Abstract class holds stream information.
Definition: stream_info.h:62
All the methods that are virtual are virtual for mocking.
virtual Status GenerateSubsamples(const uint8_t *frame, size_t frame_size, std::vector< SubsampleEntry > *subsamples)
SubsampleGenerator(bool vp9_subsample_encryption)
virtual Status Initialize(FourCC protection_scheme, const StreamInfo &stream_info)