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" | |
9 #include "media/formats/webm/webm_constants.h" | 8 #include "media/formats/webm/webm_constants.h" |
10 | 9 |
11 namespace media { | 10 namespace media { |
12 | 11 |
13 WebMContentEncodingsClient::WebMContentEncodingsClient( | 12 WebMContentEncodingsClient::WebMContentEncodingsClient( |
14 const scoped_refptr<MediaLog>& media_log) | 13 const scoped_refptr<MediaLog>& media_log) |
15 : media_log_(media_log), | 14 : media_log_(media_log), |
16 content_encryption_encountered_(false), | 15 content_encryption_encountered_(false), |
17 content_encodings_ready_(false) { | 16 content_encodings_ready_(false) { |
18 } | 17 } |
19 | 18 |
20 WebMContentEncodingsClient::~WebMContentEncodingsClient() { | 19 WebMContentEncodingsClient::~WebMContentEncodingsClient() { |
21 base::STLDeleteElements(&content_encodings_); | |
22 } | 20 } |
23 | 21 |
24 const ContentEncodings& WebMContentEncodingsClient::content_encodings() const { | 22 const ContentEncodings& WebMContentEncodingsClient::content_encodings() const { |
25 DCHECK(content_encodings_ready_); | 23 DCHECK(content_encodings_ready_); |
26 return content_encodings_; | 24 return content_encodings_; |
27 } | 25 } |
28 | 26 |
29 WebMParserClient* WebMContentEncodingsClient::OnListStart(int id) { | 27 WebMParserClient* WebMContentEncodingsClient::OnListStart(int id) { |
30 if (id == kWebMIdContentEncodings) { | 28 if (id == kWebMIdContentEncodings) { |
31 DCHECK(!cur_content_encoding_.get()); | 29 DCHECK(!cur_content_encoding_.get()); |
32 DCHECK(!content_encryption_encountered_); | 30 DCHECK(!content_encryption_encountered_); |
33 base::STLDeleteElements(&content_encodings_); | 31 content_encodings_.clear(); |
34 content_encodings_ready_ = false; | 32 content_encodings_ready_ = false; |
35 return this; | 33 return this; |
36 } | 34 } |
37 | 35 |
38 if (id == kWebMIdContentEncoding) { | 36 if (id == kWebMIdContentEncoding) { |
39 DCHECK(!cur_content_encoding_.get()); | 37 DCHECK(!cur_content_encoding_.get()); |
40 DCHECK(!content_encryption_encountered_); | 38 DCHECK(!content_encryption_encountered_); |
41 cur_content_encoding_.reset(new ContentEncoding()); | 39 cur_content_encoding_.reset(new ContentEncoding()); |
42 return this; | 40 return this; |
43 } | 41 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 103 } |
106 | 104 |
107 // Enforce mandatory elements without default values. | 105 // Enforce mandatory elements without default values. |
108 DCHECK(cur_content_encoding_->type() == ContentEncoding::kTypeEncryption); | 106 DCHECK(cur_content_encoding_->type() == ContentEncoding::kTypeEncryption); |
109 if (!content_encryption_encountered_) { | 107 if (!content_encryption_encountered_) { |
110 MEDIA_LOG(ERROR, media_log_) << "ContentEncodingType is encryption but" | 108 MEDIA_LOG(ERROR, media_log_) << "ContentEncodingType is encryption but" |
111 << " ContentEncryption is missing."; | 109 << " ContentEncryption is missing."; |
112 return false; | 110 return false; |
113 } | 111 } |
114 | 112 |
115 content_encodings_.push_back(cur_content_encoding_.release()); | 113 content_encodings_.push_back(std::move(cur_content_encoding_)); |
116 content_encryption_encountered_ = false; | 114 content_encryption_encountered_ = false; |
117 return true; | 115 return true; |
118 } | 116 } |
119 | 117 |
120 if (id == kWebMIdContentEncryption) { | 118 if (id == kWebMIdContentEncryption) { |
121 DCHECK(cur_content_encoding_.get()); | 119 DCHECK(cur_content_encoding_.get()); |
122 // Specify default value for elements that are not present. | 120 // Specify default value for elements that are not present. |
123 if (cur_content_encoding_->encryption_algo() == | 121 if (cur_content_encoding_->encryption_algo() == |
124 ContentEncoding::kEncAlgoInvalid) { | 122 ContentEncoding::kEncAlgoInvalid) { |
125 cur_content_encoding_->set_encryption_algo( | 123 cur_content_encoding_->set_encryption_algo( |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 cur_content_encoding_->SetEncryptionKeyId(data, size); | 265 cur_content_encoding_->SetEncryptionKeyId(data, size); |
268 return true; | 266 return true; |
269 } | 267 } |
270 | 268 |
271 // This should not happen if WebMListParser is working properly. | 269 // This should not happen if WebMListParser is working properly. |
272 DCHECK(false); | 270 DCHECK(false); |
273 return false; | 271 return false; |
274 } | 272 } |
275 | 273 |
276 } // namespace media | 274 } // namespace media |
OLD | NEW |