5 #include <packager/media/formats/webm/webm_content_encodings_client.h>
7 #include <absl/log/check.h>
8 #include <absl/log/log.h>
10 #include <packager/media/formats/webm/webm_constants.h>
15 WebMContentEncodingsClient::WebMContentEncodingsClient()
16 : content_encryption_encountered_(false), content_encodings_ready_(false) {}
18 WebMContentEncodingsClient::~WebMContentEncodingsClient() {}
20 const ContentEncodings& WebMContentEncodingsClient::content_encodings()
const {
21 DCHECK(content_encodings_ready_);
22 return content_encodings_;
26 if (
id == kWebMIdContentEncodings) {
27 DCHECK(!cur_content_encoding_.get());
28 DCHECK(!content_encryption_encountered_);
29 content_encodings_.clear();
30 content_encodings_ready_ =
false;
34 if (
id == kWebMIdContentEncoding) {
35 DCHECK(!cur_content_encoding_.get());
36 DCHECK(!content_encryption_encountered_);
41 if (
id == kWebMIdContentEncryption) {
42 DCHECK(cur_content_encoding_.get());
43 if (content_encryption_encountered_) {
44 LOG(ERROR) <<
"Unexpected multiple ContentEncryption.";
47 content_encryption_encountered_ =
true;
51 if (
id == kWebMIdContentEncAESSettings) {
52 DCHECK(cur_content_encoding_.get());
63 bool WebMContentEncodingsClient::OnListEnd(
int id) {
64 if (
id == kWebMIdContentEncodings) {
66 if (content_encodings_.empty()) {
67 LOG(ERROR) <<
"Missing ContentEncoding.";
70 content_encodings_ready_ =
true;
74 if (
id == kWebMIdContentEncoding) {
75 DCHECK(cur_content_encoding_.get());
81 if (cur_content_encoding_->order() == ContentEncoding::kOrderInvalid) {
84 if (!content_encodings_.empty()) {
85 LOG(ERROR) <<
"Missing ContentEncodingOrder.";
88 cur_content_encoding_->set_order(0);
91 if (cur_content_encoding_->scope() == ContentEncoding::kScopeInvalid)
92 cur_content_encoding_->set_scope(ContentEncoding::kScopeAllFrameContents);
94 if (cur_content_encoding_->type() == ContentEncoding::kTypeInvalid)
95 cur_content_encoding_->set_type(ContentEncoding::kTypeCompression);
98 if (cur_content_encoding_->type() == ContentEncoding::kTypeCompression) {
99 LOG(ERROR) <<
"ContentCompression not supported.";
104 DCHECK_EQ(cur_content_encoding_->type(), ContentEncoding::kTypeEncryption);
105 if (!content_encryption_encountered_) {
106 LOG(ERROR) <<
"ContentEncodingType is encryption but"
107 <<
" ContentEncryption is missing.";
111 content_encodings_.push_back(std::move(cur_content_encoding_));
112 content_encryption_encountered_ =
false;
116 if (
id == kWebMIdContentEncryption) {
117 DCHECK(cur_content_encoding_.get());
119 if (cur_content_encoding_->encryption_algo() ==
120 ContentEncoding::kEncAlgoInvalid) {
121 cur_content_encoding_->set_encryption_algo(
122 ContentEncoding::kEncAlgoNotEncrypted);
127 if (
id == kWebMIdContentEncAESSettings) {
128 if (cur_content_encoding_->cipher_mode() ==
129 ContentEncoding::kCipherModeInvalid)
130 cur_content_encoding_->set_cipher_mode(ContentEncoding::kCipherModeCtr);
141 bool WebMContentEncodingsClient::OnUInt(
int id, int64_t val) {
142 DCHECK(cur_content_encoding_.get());
144 if (
id == kWebMIdContentEncodingOrder) {
145 if (cur_content_encoding_->order() != ContentEncoding::kOrderInvalid) {
146 LOG(ERROR) <<
"Unexpected multiple ContentEncodingOrder.";
150 if (val !=
static_cast<int64_t
>(content_encodings_.size())) {
152 LOG(ERROR) <<
"Unexpected ContentEncodingOrder.";
156 cur_content_encoding_->set_order(val);
160 if (
id == kWebMIdContentEncodingScope) {
161 if (cur_content_encoding_->scope() != ContentEncoding::kScopeInvalid) {
162 LOG(ERROR) <<
"Unexpected multiple ContentEncodingScope.";
166 if (val == ContentEncoding::kScopeInvalid ||
167 val > ContentEncoding::kScopeMax) {
168 LOG(ERROR) <<
"Unexpected ContentEncodingScope.";
172 if (val & ContentEncoding::kScopeNextContentEncodingData) {
173 LOG(ERROR) <<
"Encoded next ContentEncoding is not "
178 cur_content_encoding_->set_scope(
static_cast<ContentEncoding::Scope
>(val));
182 if (
id == kWebMIdContentEncodingType) {
183 if (cur_content_encoding_->type() != ContentEncoding::kTypeInvalid) {
184 LOG(ERROR) <<
"Unexpected multiple ContentEncodingType.";
188 if (val == ContentEncoding::kTypeCompression) {
189 LOG(ERROR) <<
"ContentCompression not supported.";
193 if (val != ContentEncoding::kTypeEncryption) {
194 LOG(ERROR) <<
"Unexpected ContentEncodingType " << val <<
".";
198 cur_content_encoding_->set_type(
static_cast<ContentEncoding::Type
>(val));
202 if (
id == kWebMIdContentEncAlgo) {
203 if (cur_content_encoding_->encryption_algo() !=
204 ContentEncoding::kEncAlgoInvalid) {
205 LOG(ERROR) <<
"Unexpected multiple ContentEncAlgo.";
209 if (val < ContentEncoding::kEncAlgoNotEncrypted ||
210 val > ContentEncoding::kEncAlgoAes) {
211 LOG(ERROR) <<
"Unexpected ContentEncAlgo " << val <<
".";
215 cur_content_encoding_->set_encryption_algo(
216 static_cast<ContentEncoding::EncryptionAlgo
>(val));
220 if (
id == kWebMIdAESSettingsCipherMode) {
221 if (cur_content_encoding_->cipher_mode() !=
222 ContentEncoding::kCipherModeInvalid) {
223 LOG(ERROR) <<
"Unexpected multiple AESSettingsCipherMode.";
227 if (val != ContentEncoding::kCipherModeCtr) {
228 LOG(ERROR) <<
"Unexpected AESSettingsCipherMode " << val <<
".";
232 cur_content_encoding_->set_cipher_mode(
233 static_cast<ContentEncoding::CipherMode
>(val));
244 bool WebMContentEncodingsClient::OnBinary(
int id,
247 DCHECK(cur_content_encoding_.get());
251 if (
id == kWebMIdContentEncKeyID) {
252 if (!cur_content_encoding_->encryption_key_id().empty()) {
253 LOG(ERROR) <<
"Unexpected multiple ContentEncKeyID";
256 cur_content_encoding_->SetEncryptionKeyId(data, size);
All the methods that are virtual are virtual for mocking.