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;
24class AC4Parser;
25struct SubsampleEntry;
26
37 public:
41 explicit SubsampleGenerator(bool vp9_subsample_encryption, bool cencv1);
42
43 virtual ~SubsampleGenerator();
44
51 virtual Status Initialize(FourCC protection_scheme,
52 const StreamInfo& stream_info);
53
62 virtual Status GenerateSubsamples(const uint8_t* frame,
63 size_t frame_size,
64 std::vector<SubsampleEntry>* subsamples);
65
66 // Testing injections.
67 void InjectVpxParserForTesting(std::unique_ptr<VPxParser> vpx_parser);
68 void InjectVideoSliceHeaderParserForTesting(
69 std::unique_ptr<VideoSliceHeaderParser> header_parser);
70 void InjectAV1ParserForTesting(std::unique_ptr<AV1Parser> av1_parser);
71
72 private:
74 SubsampleGenerator& operator=(const SubsampleGenerator&) = delete;
75
76 Status GenerateSubsamplesFromVPxFrame(
77 const uint8_t* frame,
78 size_t frame_size,
79 std::vector<SubsampleEntry>* subsamples);
80 Status GenerateSubsamplesFromAC4Frame(
81 const uint8_t* frame,
82 size_t frame_size,
83 std::vector<SubsampleEntry>* subsamples);
84 Status GenerateSubsamplesFromH26xFrame(
85 const uint8_t* frame,
86 size_t frame_size,
87 std::vector<SubsampleEntry>* subsamples);
88 Status GenerateSubsamplesFromAV1Frame(
89 const uint8_t* frame,
90 size_t frame_size,
91 std::vector<SubsampleEntry>* subsamples);
92
93 const bool vp9_subsample_encryption_ = false;
94 const bool cencv1_ = false;
95 // Whether the protected portion should be AES block (16 bytes) aligned.
96 bool align_protected_data_ = false;
97 Codec codec_ = kUnknownCodec;
98 // For NAL structured video only, the size of NAL unit length in bytes. Can be
99 // 1, 2 or 4 bytes.
100 uint8_t nalu_length_size_ = 0;
101 // For SAMPLE AES only, 32 bytes for Video and 16 bytes for audio.
102 size_t leading_clear_bytes_size_ = 0;
103 // For SAMPLE AES only, if the data size is less than this value, none of the
104 // bytes are encrypted. The size is 48+1 bytes for video NAL and 32 bytes for
105 // audio according to MPEG-2 Stream Encryption Format for HTTP Live Streaming.
106 size_t min_protected_data_size_ = 0;
107
108 // VPx parser for VPx streams.
109 std::unique_ptr<VPxParser> vpx_parser_;
110 // Video slice header parser for NAL strucutred streams.
111 std::unique_ptr<VideoSliceHeaderParser> header_parser_;
112 // AV1 parser for AV1 streams.
113 std::unique_ptr<AV1Parser> av1_parser_;
114};
115
116} // namespace media
117} // namespace shaka
118
119#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.