5#include <packager/media/formats/webm/webm_content_encodings_client.h>
11#include <absl/log/check.h>
12#include <absl/log/log.h>
14#include <packager/media/formats/webm/webm_constants.h>
15#include <packager/media/formats/webm/webm_content_encodings.h>
16#include <packager/media/formats/webm/webm_parser.h>
21WebMContentEncodingsClient::WebMContentEncodingsClient()
22 : content_encryption_encountered_(false), content_encodings_ready_(false) {}
24WebMContentEncodingsClient::~WebMContentEncodingsClient() {}
26const ContentEncodings& WebMContentEncodingsClient::content_encodings()
const {
27 DCHECK(content_encodings_ready_);
28 return content_encodings_;
32 if (
id == kWebMIdContentEncodings) {
33 DCHECK(!cur_content_encoding_.get());
34 DCHECK(!content_encryption_encountered_);
35 content_encodings_.clear();
36 content_encodings_ready_ =
false;
40 if (
id == kWebMIdContentEncoding) {
41 DCHECK(!cur_content_encoding_.get());
42 DCHECK(!content_encryption_encountered_);
47 if (
id == kWebMIdContentEncryption) {
48 DCHECK(cur_content_encoding_.get());
49 if (content_encryption_encountered_) {
50 LOG(ERROR) <<
"Unexpected multiple ContentEncryption.";
53 content_encryption_encountered_ =
true;
57 if (
id == kWebMIdContentEncAESSettings) {
58 DCHECK(cur_content_encoding_.get());
69bool WebMContentEncodingsClient::OnListEnd(
int id) {
70 if (
id == kWebMIdContentEncodings) {
72 if (content_encodings_.empty()) {
73 LOG(ERROR) <<
"Missing ContentEncoding.";
76 content_encodings_ready_ =
true;
80 if (
id == kWebMIdContentEncoding) {
81 DCHECK(cur_content_encoding_.get());
87 if (cur_content_encoding_->order() == ContentEncoding::kOrderInvalid) {
90 if (!content_encodings_.empty()) {
91 LOG(ERROR) <<
"Missing ContentEncodingOrder.";
94 cur_content_encoding_->set_order(0);
97 if (cur_content_encoding_->scope() == ContentEncoding::kScopeInvalid)
98 cur_content_encoding_->set_scope(ContentEncoding::kScopeAllFrameContents);
100 if (cur_content_encoding_->type() == ContentEncoding::kTypeInvalid)
101 cur_content_encoding_->set_type(ContentEncoding::kTypeCompression);
104 if (cur_content_encoding_->type() == ContentEncoding::kTypeCompression) {
105 LOG(ERROR) <<
"ContentCompression not supported.";
110 DCHECK_EQ(cur_content_encoding_->type(), ContentEncoding::kTypeEncryption);
111 if (!content_encryption_encountered_) {
112 LOG(ERROR) <<
"ContentEncodingType is encryption but"
113 <<
" ContentEncryption is missing.";
117 content_encodings_.push_back(std::move(cur_content_encoding_));
118 content_encryption_encountered_ =
false;
122 if (
id == kWebMIdContentEncryption) {
123 DCHECK(cur_content_encoding_.get());
125 if (cur_content_encoding_->encryption_algo() ==
126 ContentEncoding::kEncAlgoInvalid) {
127 cur_content_encoding_->set_encryption_algo(
128 ContentEncoding::kEncAlgoNotEncrypted);
133 if (
id == kWebMIdContentEncAESSettings) {
134 if (cur_content_encoding_->cipher_mode() ==
135 ContentEncoding::kCipherModeInvalid)
136 cur_content_encoding_->set_cipher_mode(ContentEncoding::kCipherModeCtr);
147bool WebMContentEncodingsClient::OnUInt(
int id, int64_t val) {
148 DCHECK(cur_content_encoding_.get());
150 if (
id == kWebMIdContentEncodingOrder) {
151 if (cur_content_encoding_->order() != ContentEncoding::kOrderInvalid) {
152 LOG(ERROR) <<
"Unexpected multiple ContentEncodingOrder.";
156 if (val !=
static_cast<int64_t
>(content_encodings_.size())) {
158 LOG(ERROR) <<
"Unexpected ContentEncodingOrder.";
162 cur_content_encoding_->set_order(val);
166 if (
id == kWebMIdContentEncodingScope) {
167 if (cur_content_encoding_->scope() != ContentEncoding::kScopeInvalid) {
168 LOG(ERROR) <<
"Unexpected multiple ContentEncodingScope.";
172 if (val == ContentEncoding::kScopeInvalid ||
173 val > ContentEncoding::kScopeMax) {
174 LOG(ERROR) <<
"Unexpected ContentEncodingScope.";
178 if (val & ContentEncoding::kScopeNextContentEncodingData) {
179 LOG(ERROR) <<
"Encoded next ContentEncoding is not "
184 cur_content_encoding_->set_scope(
static_cast<ContentEncoding::Scope
>(val));
188 if (
id == kWebMIdContentEncodingType) {
189 if (cur_content_encoding_->type() != ContentEncoding::kTypeInvalid) {
190 LOG(ERROR) <<
"Unexpected multiple ContentEncodingType.";
194 if (val == ContentEncoding::kTypeCompression) {
195 LOG(ERROR) <<
"ContentCompression not supported.";
199 if (val != ContentEncoding::kTypeEncryption) {
200 LOG(ERROR) <<
"Unexpected ContentEncodingType " << val <<
".";
204 cur_content_encoding_->set_type(
static_cast<ContentEncoding::Type
>(val));
208 if (
id == kWebMIdContentEncAlgo) {
209 if (cur_content_encoding_->encryption_algo() !=
210 ContentEncoding::kEncAlgoInvalid) {
211 LOG(ERROR) <<
"Unexpected multiple ContentEncAlgo.";
215 if (val < ContentEncoding::kEncAlgoNotEncrypted ||
216 val > ContentEncoding::kEncAlgoAes) {
217 LOG(ERROR) <<
"Unexpected ContentEncAlgo " << val <<
".";
221 cur_content_encoding_->set_encryption_algo(
222 static_cast<ContentEncoding::EncryptionAlgo
>(val));
226 if (
id == kWebMIdAESSettingsCipherMode) {
227 if (cur_content_encoding_->cipher_mode() !=
228 ContentEncoding::kCipherModeInvalid) {
229 LOG(ERROR) <<
"Unexpected multiple AESSettingsCipherMode.";
233 if (val != ContentEncoding::kCipherModeCtr) {
234 LOG(ERROR) <<
"Unexpected AESSettingsCipherMode " << val <<
".";
238 cur_content_encoding_->set_cipher_mode(
239 static_cast<ContentEncoding::CipherMode
>(val));
250bool WebMContentEncodingsClient::OnBinary(
int id,
253 DCHECK(cur_content_encoding_.get());
257 if (
id == kWebMIdContentEncKeyID) {
258 if (!cur_content_encoding_->encryption_key_id().empty()) {
259 LOG(ERROR) <<
"Unexpected multiple ContentEncKeyID";
262 cur_content_encoding_->SetEncryptionKeyId(data, size);
All the methods that are virtual are virtual for mocking.