| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/formats/webm/webm_content_encodings_client.h" | 5 #include "media/formats/webm/webm_content_encodings_client.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "media/formats/webm/webm_constants.h" | 9 #include "media/formats/webm/webm_constants.h" |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 if (id == kWebMIdContentEncoding) { | 37 if (id == kWebMIdContentEncoding) { |
| 38 DCHECK(!cur_content_encoding_.get()); | 38 DCHECK(!cur_content_encoding_.get()); |
| 39 DCHECK(!content_encryption_encountered_); | 39 DCHECK(!content_encryption_encountered_); |
| 40 cur_content_encoding_.reset(new ContentEncoding()); | 40 cur_content_encoding_.reset(new ContentEncoding()); |
| 41 return this; | 41 return this; |
| 42 } | 42 } |
| 43 | 43 |
| 44 if (id == kWebMIdContentEncryption) { | 44 if (id == kWebMIdContentEncryption) { |
| 45 DCHECK(cur_content_encoding_.get()); | 45 DCHECK(cur_content_encoding_.get()); |
| 46 if (content_encryption_encountered_) { | 46 if (content_encryption_encountered_) { |
| 47 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncryption."; | 47 MEDIA_LOG(log_cb_, ERROR) << "Unexpected multiple ContentEncryption."; |
| 48 return NULL; | 48 return NULL; |
| 49 } | 49 } |
| 50 content_encryption_encountered_ = true; | 50 content_encryption_encountered_ = true; |
| 51 return this; | 51 return this; |
| 52 } | 52 } |
| 53 | 53 |
| 54 if (id == kWebMIdContentEncAESSettings) { | 54 if (id == kWebMIdContentEncAESSettings) { |
| 55 DCHECK(cur_content_encoding_.get()); | 55 DCHECK(cur_content_encoding_.get()); |
| 56 return this; | 56 return this; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // This should not happen if WebMListParser is working properly. | 59 // This should not happen if WebMListParser is working properly. |
| 60 DCHECK(false); | 60 DCHECK(false); |
| 61 return NULL; | 61 return NULL; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Mandatory occurrence restriction is checked in this function. Multiple | 64 // Mandatory occurrence restriction is checked in this function. Multiple |
| 65 // occurrence restriction is checked in OnUInt and OnBinary. | 65 // occurrence restriction is checked in OnUInt and OnBinary. |
| 66 bool WebMContentEncodingsClient::OnListEnd(int id) { | 66 bool WebMContentEncodingsClient::OnListEnd(int id) { |
| 67 if (id == kWebMIdContentEncodings) { | 67 if (id == kWebMIdContentEncodings) { |
| 68 // ContentEncoding element is mandatory. Check this! | 68 // ContentEncoding element is mandatory. Check this! |
| 69 if (content_encodings_.empty()) { | 69 if (content_encodings_.empty()) { |
| 70 MEDIA_LOG(log_cb_) << "Missing ContentEncoding."; | 70 MEDIA_LOG(log_cb_, ERROR) << "Missing ContentEncoding."; |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 content_encodings_ready_ = true; | 73 content_encodings_ready_ = true; |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 if (id == kWebMIdContentEncoding) { | 77 if (id == kWebMIdContentEncoding) { |
| 78 DCHECK(cur_content_encoding_.get()); | 78 DCHECK(cur_content_encoding_.get()); |
| 79 | 79 |
| 80 // | 80 // |
| 81 // Specify default values to missing mandatory elements. | 81 // Specify default values to missing mandatory elements. |
| 82 // | 82 // |
| 83 | 83 |
| 84 if (cur_content_encoding_->order() == ContentEncoding::kOrderInvalid) { | 84 if (cur_content_encoding_->order() == ContentEncoding::kOrderInvalid) { |
| 85 // Default value of encoding order is 0, which should only be used on the | 85 // Default value of encoding order is 0, which should only be used on the |
| 86 // first ContentEncoding. | 86 // first ContentEncoding. |
| 87 if (!content_encodings_.empty()) { | 87 if (!content_encodings_.empty()) { |
| 88 MEDIA_LOG(log_cb_) << "Missing ContentEncodingOrder."; | 88 MEDIA_LOG(log_cb_, ERROR) << "Missing ContentEncodingOrder."; |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 cur_content_encoding_->set_order(0); | 91 cur_content_encoding_->set_order(0); |
| 92 } | 92 } |
| 93 | 93 |
| 94 if (cur_content_encoding_->scope() == ContentEncoding::kScopeInvalid) | 94 if (cur_content_encoding_->scope() == ContentEncoding::kScopeInvalid) |
| 95 cur_content_encoding_->set_scope(ContentEncoding::kScopeAllFrameContents); | 95 cur_content_encoding_->set_scope(ContentEncoding::kScopeAllFrameContents); |
| 96 | 96 |
| 97 if (cur_content_encoding_->type() == ContentEncoding::kTypeInvalid) | 97 if (cur_content_encoding_->type() == ContentEncoding::kTypeInvalid) |
| 98 cur_content_encoding_->set_type(ContentEncoding::kTypeCompression); | 98 cur_content_encoding_->set_type(ContentEncoding::kTypeCompression); |
| 99 | 99 |
| 100 // Check for elements valid in spec but not supported for now. | 100 // Check for elements valid in spec but not supported for now. |
| 101 if (cur_content_encoding_->type() == ContentEncoding::kTypeCompression) { | 101 if (cur_content_encoding_->type() == ContentEncoding::kTypeCompression) { |
| 102 MEDIA_LOG(log_cb_) << "ContentCompression not supported."; | 102 MEDIA_LOG(log_cb_, ERROR) << "ContentCompression not supported."; |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Enforce mandatory elements without default values. | 106 // Enforce mandatory elements without default values. |
| 107 DCHECK(cur_content_encoding_->type() == ContentEncoding::kTypeEncryption); | 107 DCHECK(cur_content_encoding_->type() == ContentEncoding::kTypeEncryption); |
| 108 if (!content_encryption_encountered_) { | 108 if (!content_encryption_encountered_) { |
| 109 MEDIA_LOG(log_cb_) << "ContentEncodingType is encryption but" | 109 MEDIA_LOG(log_cb_, ERROR) << "ContentEncodingType is encryption but" |
| 110 << " ContentEncryption is missing."; | 110 << " ContentEncryption is missing."; |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 | 113 |
| 114 content_encodings_.push_back(cur_content_encoding_.release()); | 114 content_encodings_.push_back(cur_content_encoding_.release()); |
| 115 content_encryption_encountered_ = false; | 115 content_encryption_encountered_ = false; |
| 116 return true; | 116 return true; |
| 117 } | 117 } |
| 118 | 118 |
| 119 if (id == kWebMIdContentEncryption) { | 119 if (id == kWebMIdContentEncryption) { |
| 120 DCHECK(cur_content_encoding_.get()); | 120 DCHECK(cur_content_encoding_.get()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 return false; | 139 return false; |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Multiple occurrence restriction and range are checked in this function. | 142 // Multiple occurrence restriction and range are checked in this function. |
| 143 // Mandatory occurrence restriction is checked in OnListEnd. | 143 // Mandatory occurrence restriction is checked in OnListEnd. |
| 144 bool WebMContentEncodingsClient::OnUInt(int id, int64 val) { | 144 bool WebMContentEncodingsClient::OnUInt(int id, int64 val) { |
| 145 DCHECK(cur_content_encoding_.get()); | 145 DCHECK(cur_content_encoding_.get()); |
| 146 | 146 |
| 147 if (id == kWebMIdContentEncodingOrder) { | 147 if (id == kWebMIdContentEncodingOrder) { |
| 148 if (cur_content_encoding_->order() != ContentEncoding::kOrderInvalid) { | 148 if (cur_content_encoding_->order() != ContentEncoding::kOrderInvalid) { |
| 149 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncodingOrder."; | 149 MEDIA_LOG(log_cb_, ERROR) << "Unexpected multiple ContentEncodingOrder."; |
| 150 return false; | 150 return false; |
| 151 } | 151 } |
| 152 | 152 |
| 153 if (val != static_cast<int64>(content_encodings_.size())) { | 153 if (val != static_cast<int64>(content_encodings_.size())) { |
| 154 // According to the spec, encoding order starts with 0 and counts upwards. | 154 // According to the spec, encoding order starts with 0 and counts upwards. |
| 155 MEDIA_LOG(log_cb_) << "Unexpected ContentEncodingOrder."; | 155 MEDIA_LOG(log_cb_, ERROR) << "Unexpected ContentEncodingOrder."; |
| 156 return false; | 156 return false; |
| 157 } | 157 } |
| 158 | 158 |
| 159 cur_content_encoding_->set_order(val); | 159 cur_content_encoding_->set_order(val); |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (id == kWebMIdContentEncodingScope) { | 163 if (id == kWebMIdContentEncodingScope) { |
| 164 if (cur_content_encoding_->scope() != ContentEncoding::kScopeInvalid) { | 164 if (cur_content_encoding_->scope() != ContentEncoding::kScopeInvalid) { |
| 165 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncodingScope."; | 165 MEDIA_LOG(log_cb_, ERROR) << "Unexpected multiple ContentEncodingScope."; |
| 166 return false; | 166 return false; |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (val == ContentEncoding::kScopeInvalid || | 169 if (val == ContentEncoding::kScopeInvalid || |
| 170 val > ContentEncoding::kScopeMax) { | 170 val > ContentEncoding::kScopeMax) { |
| 171 MEDIA_LOG(log_cb_) << "Unexpected ContentEncodingScope."; | 171 MEDIA_LOG(log_cb_, ERROR) << "Unexpected ContentEncodingScope."; |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 | 174 |
| 175 if (val & ContentEncoding::kScopeNextContentEncodingData) { | 175 if (val & ContentEncoding::kScopeNextContentEncodingData) { |
| 176 MEDIA_LOG(log_cb_) << "Encoded next ContentEncoding is not supported."; | 176 MEDIA_LOG(log_cb_, ERROR) << "Encoded next ContentEncoding is not " |
| 177 "supported."; |
| 177 return false; | 178 return false; |
| 178 } | 179 } |
| 179 | 180 |
| 180 cur_content_encoding_->set_scope(static_cast<ContentEncoding::Scope>(val)); | 181 cur_content_encoding_->set_scope(static_cast<ContentEncoding::Scope>(val)); |
| 181 return true; | 182 return true; |
| 182 } | 183 } |
| 183 | 184 |
| 184 if (id == kWebMIdContentEncodingType) { | 185 if (id == kWebMIdContentEncodingType) { |
| 185 if (cur_content_encoding_->type() != ContentEncoding::kTypeInvalid) { | 186 if (cur_content_encoding_->type() != ContentEncoding::kTypeInvalid) { |
| 186 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncodingType."; | 187 MEDIA_LOG(log_cb_, ERROR) << "Unexpected multiple ContentEncodingType."; |
| 187 return false; | 188 return false; |
| 188 } | 189 } |
| 189 | 190 |
| 190 if (val == ContentEncoding::kTypeCompression) { | 191 if (val == ContentEncoding::kTypeCompression) { |
| 191 MEDIA_LOG(log_cb_) << "ContentCompression not supported."; | 192 MEDIA_LOG(log_cb_, ERROR) << "ContentCompression not supported."; |
| 192 return false; | 193 return false; |
| 193 } | 194 } |
| 194 | 195 |
| 195 if (val != ContentEncoding::kTypeEncryption) { | 196 if (val != ContentEncoding::kTypeEncryption) { |
| 196 MEDIA_LOG(log_cb_) << "Unexpected ContentEncodingType " << val << "."; | 197 MEDIA_LOG(log_cb_, ERROR) << "Unexpected ContentEncodingType " << val |
| 198 << "."; |
| 197 return false; | 199 return false; |
| 198 } | 200 } |
| 199 | 201 |
| 200 cur_content_encoding_->set_type(static_cast<ContentEncoding::Type>(val)); | 202 cur_content_encoding_->set_type(static_cast<ContentEncoding::Type>(val)); |
| 201 return true; | 203 return true; |
| 202 } | 204 } |
| 203 | 205 |
| 204 if (id == kWebMIdContentEncAlgo) { | 206 if (id == kWebMIdContentEncAlgo) { |
| 205 if (cur_content_encoding_->encryption_algo() != | 207 if (cur_content_encoding_->encryption_algo() != |
| 206 ContentEncoding::kEncAlgoInvalid) { | 208 ContentEncoding::kEncAlgoInvalid) { |
| 207 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncAlgo."; | 209 MEDIA_LOG(log_cb_, ERROR) << "Unexpected multiple ContentEncAlgo."; |
| 208 return false; | 210 return false; |
| 209 } | 211 } |
| 210 | 212 |
| 211 if (val < ContentEncoding::kEncAlgoNotEncrypted || | 213 if (val < ContentEncoding::kEncAlgoNotEncrypted || |
| 212 val > ContentEncoding::kEncAlgoAes) { | 214 val > ContentEncoding::kEncAlgoAes) { |
| 213 MEDIA_LOG(log_cb_) << "Unexpected ContentEncAlgo " << val << "."; | 215 MEDIA_LOG(log_cb_, ERROR) << "Unexpected ContentEncAlgo " << val << "."; |
| 214 return false; | 216 return false; |
| 215 } | 217 } |
| 216 | 218 |
| 217 cur_content_encoding_->set_encryption_algo( | 219 cur_content_encoding_->set_encryption_algo( |
| 218 static_cast<ContentEncoding::EncryptionAlgo>(val)); | 220 static_cast<ContentEncoding::EncryptionAlgo>(val)); |
| 219 return true; | 221 return true; |
| 220 } | 222 } |
| 221 | 223 |
| 222 if (id == kWebMIdAESSettingsCipherMode) { | 224 if (id == kWebMIdAESSettingsCipherMode) { |
| 223 if (cur_content_encoding_->cipher_mode() != | 225 if (cur_content_encoding_->cipher_mode() != |
| 224 ContentEncoding::kCipherModeInvalid) { | 226 ContentEncoding::kCipherModeInvalid) { |
| 225 MEDIA_LOG(log_cb_) << "Unexpected multiple AESSettingsCipherMode."; | 227 MEDIA_LOG(log_cb_, ERROR) << "Unexpected multiple AESSettingsCipherMode."; |
| 226 return false; | 228 return false; |
| 227 } | 229 } |
| 228 | 230 |
| 229 if (val != ContentEncoding::kCipherModeCtr) { | 231 if (val != ContentEncoding::kCipherModeCtr) { |
| 230 MEDIA_LOG(log_cb_) << "Unexpected AESSettingsCipherMode " << val << "."; | 232 MEDIA_LOG(log_cb_, ERROR) << "Unexpected AESSettingsCipherMode " << val |
| 233 << "."; |
| 231 return false; | 234 return false; |
| 232 } | 235 } |
| 233 | 236 |
| 234 cur_content_encoding_->set_cipher_mode( | 237 cur_content_encoding_->set_cipher_mode( |
| 235 static_cast<ContentEncoding::CipherMode>(val)); | 238 static_cast<ContentEncoding::CipherMode>(val)); |
| 236 return true; | 239 return true; |
| 237 } | 240 } |
| 238 | 241 |
| 239 // This should not happen if WebMListParser is working properly. | 242 // This should not happen if WebMListParser is working properly. |
| 240 DCHECK(false); | 243 DCHECK(false); |
| 241 return false; | 244 return false; |
| 242 } | 245 } |
| 243 | 246 |
| 244 // Multiple occurrence restriction is checked in this function. Mandatory | 247 // Multiple occurrence restriction is checked in this function. Mandatory |
| 245 // restriction is checked in OnListEnd. | 248 // restriction is checked in OnListEnd. |
| 246 bool WebMContentEncodingsClient::OnBinary(int id, const uint8* data, int size) { | 249 bool WebMContentEncodingsClient::OnBinary(int id, const uint8* data, int size) { |
| 247 DCHECK(cur_content_encoding_.get()); | 250 DCHECK(cur_content_encoding_.get()); |
| 248 DCHECK(data); | 251 DCHECK(data); |
| 249 DCHECK_GT(size, 0); | 252 DCHECK_GT(size, 0); |
| 250 | 253 |
| 251 if (id == kWebMIdContentEncKeyID) { | 254 if (id == kWebMIdContentEncKeyID) { |
| 252 if (!cur_content_encoding_->encryption_key_id().empty()) { | 255 if (!cur_content_encoding_->encryption_key_id().empty()) { |
| 253 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncKeyID"; | 256 MEDIA_LOG(log_cb_, ERROR) << "Unexpected multiple ContentEncKeyID"; |
| 254 return false; | 257 return false; |
| 255 } | 258 } |
| 256 cur_content_encoding_->SetEncryptionKeyId(data, size); | 259 cur_content_encoding_->SetEncryptionKeyId(data, size); |
| 257 return true; | 260 return true; |
| 258 } | 261 } |
| 259 | 262 |
| 260 // This should not happen if WebMListParser is working properly. | 263 // This should not happen if WebMListParser is working properly. |
| 261 DCHECK(false); | 264 DCHECK(false); |
| 262 return false; | 265 return false; |
| 263 } | 266 } |
| 264 | 267 |
| 265 } // namespace media | 268 } // namespace media |
| OLD | NEW |