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