OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webm/webm_content_encodings_client.h" | 5 #include "media/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/webm/webm_constants.h" | 9 #include "media/webm/webm_constants.h" |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 if (id == kWebMIdContentEncryption) { | 43 if (id == kWebMIdContentEncryption) { |
44 DCHECK(cur_content_encoding_.get()); | 44 DCHECK(cur_content_encoding_.get()); |
45 if (content_encryption_encountered_) { | 45 if (content_encryption_encountered_) { |
46 DVLOG(1) << "Unexpected multiple ContentEncryption."; | 46 DVLOG(1) << "Unexpected multiple ContentEncryption."; |
47 return NULL; | 47 return NULL; |
48 } | 48 } |
49 content_encryption_encountered_ = true; | 49 content_encryption_encountered_ = true; |
50 return this; | 50 return this; |
51 } | 51 } |
52 | 52 |
| 53 if (id == kWebMIdContentEncAESSettings) { |
| 54 DCHECK(cur_content_encoding_.get()); |
| 55 return this; |
| 56 } |
| 57 |
53 // This should not happen if WebMListParser is working properly. | 58 // This should not happen if WebMListParser is working properly. |
54 DCHECK(false); | 59 DCHECK(false); |
55 return NULL; | 60 return NULL; |
56 } | 61 } |
57 | 62 |
58 // Mandatory occurrence restriction is checked in this function. Multiple | 63 // Mandatory occurrence restriction is checked in this function. Multiple |
59 // occurrence restriction is checked in OnUInt and OnBinary. | 64 // occurrence restriction is checked in OnUInt and OnBinary. |
60 bool WebMContentEncodingsClient::OnListEnd(int id) { | 65 bool WebMContentEncodingsClient::OnListEnd(int id) { |
61 if (id == kWebMIdContentEncodings) { | 66 if (id == kWebMIdContentEncodings) { |
62 // ContentEncoding element is mandatory. Check this! | 67 // ContentEncoding element is mandatory. Check this! |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 DCHECK(cur_content_encoding_.get()); | 119 DCHECK(cur_content_encoding_.get()); |
115 // Specify default value for elements that are not present. | 120 // Specify default value for elements that are not present. |
116 if (cur_content_encoding_->encryption_algo() == | 121 if (cur_content_encoding_->encryption_algo() == |
117 ContentEncoding::kEncAlgoInvalid) { | 122 ContentEncoding::kEncAlgoInvalid) { |
118 cur_content_encoding_->set_encryption_algo( | 123 cur_content_encoding_->set_encryption_algo( |
119 ContentEncoding::kEncAlgoNotEncrypted); | 124 ContentEncoding::kEncAlgoNotEncrypted); |
120 } | 125 } |
121 return true; | 126 return true; |
122 } | 127 } |
123 | 128 |
| 129 if (id == kWebMIdContentEncAESSettings) { |
| 130 if (cur_content_encoding_->cipher_mode() == |
| 131 ContentEncoding::kCipherModeInvalid) |
| 132 cur_content_encoding_->set_cipher_mode(ContentEncoding::kCipherModeCtr); |
| 133 return true; |
| 134 } |
| 135 |
124 // This should not happen if WebMListParser is working properly. | 136 // This should not happen if WebMListParser is working properly. |
125 DCHECK(false); | 137 DCHECK(false); |
126 return false; | 138 return false; |
127 } | 139 } |
128 | 140 |
129 // Multiple occurrence restriction and range are checked in this function. | 141 // Multiple occurrence restriction and range are checked in this function. |
130 // Mandatory occurrence restriction is checked in OnListEnd. | 142 // Mandatory occurrence restriction is checked in OnListEnd. |
131 bool WebMContentEncodingsClient::OnUInt(int id, int64 val) { | 143 bool WebMContentEncodingsClient::OnUInt(int id, int64 val) { |
132 DCHECK(cur_content_encoding_.get()); | 144 DCHECK(cur_content_encoding_.get()); |
133 | 145 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 val > ContentEncoding::kEncAlgoAes) { | 211 val > ContentEncoding::kEncAlgoAes) { |
200 DVLOG(1) << "Unexpected ContentEncAlgo " << val << "."; | 212 DVLOG(1) << "Unexpected ContentEncAlgo " << val << "."; |
201 return false; | 213 return false; |
202 } | 214 } |
203 | 215 |
204 cur_content_encoding_->set_encryption_algo( | 216 cur_content_encoding_->set_encryption_algo( |
205 static_cast<ContentEncoding::EncryptionAlgo>(val)); | 217 static_cast<ContentEncoding::EncryptionAlgo>(val)); |
206 return true; | 218 return true; |
207 } | 219 } |
208 | 220 |
| 221 if (id == kWebMIdAESSettingsCipherMode) { |
| 222 if (cur_content_encoding_->cipher_mode() != |
| 223 ContentEncoding::kCipherModeInvalid) { |
| 224 DVLOG(1) << "Unexpected multiple AESSettingsCipherMode."; |
| 225 return false; |
| 226 } |
| 227 |
| 228 if (val != ContentEncoding::kCipherModeCtr) { |
| 229 DVLOG(1) << "Unexpected AESSettingsCipherMode " << val << "."; |
| 230 return false; |
| 231 } |
| 232 |
| 233 cur_content_encoding_->set_cipher_mode( |
| 234 static_cast<ContentEncoding::CipherMode>(val)); |
| 235 return true; |
| 236 } |
| 237 |
209 // This should not happen if WebMListParser is working properly. | 238 // This should not happen if WebMListParser is working properly. |
210 DCHECK(false); | 239 DCHECK(false); |
211 return false; | 240 return false; |
212 } | 241 } |
213 | 242 |
214 // Multiple occurrence restriction is checked in this function. Mandatory | 243 // Multiple occurrence restriction is checked in this function. Mandatory |
215 // restriction is checked in OnListEnd. | 244 // restriction is checked in OnListEnd. |
216 bool WebMContentEncodingsClient::OnBinary(int id, const uint8* data, int size) { | 245 bool WebMContentEncodingsClient::OnBinary(int id, const uint8* data, int size) { |
217 DCHECK(cur_content_encoding_.get()); | 246 DCHECK(cur_content_encoding_.get()); |
218 DCHECK(data); | 247 DCHECK(data); |
219 DCHECK_GT(size, 0); | 248 DCHECK_GT(size, 0); |
220 | 249 |
221 if (id == kWebMIdContentEncKeyID) { | 250 if (id == kWebMIdContentEncKeyID) { |
222 if (cur_content_encoding_->encryption_key_id() || | 251 if (cur_content_encoding_->encryption_key_id() || |
223 cur_content_encoding_->encryption_key_id_size()) { | 252 cur_content_encoding_->encryption_key_id_size()) { |
224 DVLOG(1) << "Unexpected multiple ContentEncKeyID"; | 253 DVLOG(1) << "Unexpected multiple ContentEncKeyID"; |
225 return false; | 254 return false; |
226 } | 255 } |
227 cur_content_encoding_->SetEncryptionKeyId(data, size); | 256 cur_content_encoding_->SetEncryptionKeyId(data, size); |
228 return true; | 257 return true; |
229 } | 258 } |
230 | 259 |
231 // This should not happen if WebMListParser is working properly. | 260 // This should not happen if WebMListParser is working properly. |
232 DCHECK(false); | 261 DCHECK(false); |
233 return false; | 262 return false; |
234 } | 263 } |
235 | 264 |
236 } // namespace media | 265 } // namespace media |
OLD | NEW |