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