Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: media/webm/webm_content_encodings_client.cc

Issue 11471006: Log MediaSource parsing errors to the MediaLog so they can appear in chrome:media-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 namespace media { 11 namespace media {
12 12
13 WebMContentEncodingsClient::WebMContentEncodingsClient() 13 WebMContentEncodingsClient::WebMContentEncodingsClient(const LogCB& log_cb)
14 : content_encryption_encountered_(false), 14 : log_cb_(log_cb),
15 content_encryption_encountered_(false),
15 content_encodings_ready_(false) { 16 content_encodings_ready_(false) {
16 } 17 }
17 18
18 WebMContentEncodingsClient::~WebMContentEncodingsClient() { 19 WebMContentEncodingsClient::~WebMContentEncodingsClient() {
19 STLDeleteElements(&content_encodings_); 20 STLDeleteElements(&content_encodings_);
20 } 21 }
21 22
22 const ContentEncodings& WebMContentEncodingsClient::content_encodings() const { 23 const ContentEncodings& WebMContentEncodingsClient::content_encodings() const {
23 DCHECK(content_encodings_ready_); 24 DCHECK(content_encodings_ready_);
24 return content_encodings_; 25 return content_encodings_;
(...skipping 11 matching lines...) Expand all
36 if (id == kWebMIdContentEncoding) { 37 if (id == kWebMIdContentEncoding) {
37 DCHECK(!cur_content_encoding_.get()); 38 DCHECK(!cur_content_encoding_.get());
38 DCHECK(!content_encryption_encountered_); 39 DCHECK(!content_encryption_encountered_);
39 cur_content_encoding_.reset(new ContentEncoding()); 40 cur_content_encoding_.reset(new ContentEncoding());
40 return this; 41 return this;
41 } 42 }
42 43
43 if (id == kWebMIdContentEncryption) { 44 if (id == kWebMIdContentEncryption) {
44 DCHECK(cur_content_encoding_.get()); 45 DCHECK(cur_content_encoding_.get());
45 if (content_encryption_encountered_) { 46 if (content_encryption_encountered_) {
46 DVLOG(1) << "Unexpected multiple ContentEncryption."; 47 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncryption.";
47 return NULL; 48 return NULL;
48 } 49 }
49 content_encryption_encountered_ = true; 50 content_encryption_encountered_ = true;
50 return this; 51 return this;
51 } 52 }
52 53
53 if (id == kWebMIdContentEncAESSettings) { 54 if (id == kWebMIdContentEncAESSettings) {
54 DCHECK(cur_content_encoding_.get()); 55 DCHECK(cur_content_encoding_.get());
55 return this; 56 return this;
56 } 57 }
57 58
58 // This should not happen if WebMListParser is working properly. 59 // This should not happen if WebMListParser is working properly.
59 DCHECK(false); 60 DCHECK(false);
60 return NULL; 61 return NULL;
61 } 62 }
62 63
63 // Mandatory occurrence restriction is checked in this function. Multiple 64 // Mandatory occurrence restriction is checked in this function. Multiple
64 // occurrence restriction is checked in OnUInt and OnBinary. 65 // occurrence restriction is checked in OnUInt and OnBinary.
65 bool WebMContentEncodingsClient::OnListEnd(int id) { 66 bool WebMContentEncodingsClient::OnListEnd(int id) {
66 if (id == kWebMIdContentEncodings) { 67 if (id == kWebMIdContentEncodings) {
67 // ContentEncoding element is mandatory. Check this! 68 // ContentEncoding element is mandatory. Check this!
68 if (content_encodings_.empty()) { 69 if (content_encodings_.empty()) {
69 DVLOG(1) << "Missing ContentEncoding."; 70 MEDIA_LOG(log_cb_) << "Missing ContentEncoding.";
70 return false; 71 return false;
71 } 72 }
72 content_encodings_ready_ = true; 73 content_encodings_ready_ = true;
73 return true; 74 return true;
74 } 75 }
75 76
76 if (id == kWebMIdContentEncoding) { 77 if (id == kWebMIdContentEncoding) {
77 DCHECK(cur_content_encoding_.get()); 78 DCHECK(cur_content_encoding_.get());
78 79
79 // 80 //
80 // Specify default values to missing mandatory elements. 81 // Specify default values to missing mandatory elements.
81 // 82 //
82 83
83 if (cur_content_encoding_->order() == ContentEncoding::kOrderInvalid) { 84 if (cur_content_encoding_->order() == ContentEncoding::kOrderInvalid) {
84 // 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
85 // first ContentEncoding. 86 // first ContentEncoding.
86 if (!content_encodings_.empty()) { 87 if (!content_encodings_.empty()) {
87 DVLOG(1) << "Missing ContentEncodingOrder."; 88 MEDIA_LOG(log_cb_) << "Missing ContentEncodingOrder.";
88 return false; 89 return false;
89 } 90 }
90 cur_content_encoding_->set_order(0); 91 cur_content_encoding_->set_order(0);
91 } 92 }
92 93
93 if (cur_content_encoding_->scope() == ContentEncoding::kScopeInvalid) 94 if (cur_content_encoding_->scope() == ContentEncoding::kScopeInvalid)
94 cur_content_encoding_->set_scope(ContentEncoding::kScopeAllFrameContents); 95 cur_content_encoding_->set_scope(ContentEncoding::kScopeAllFrameContents);
95 96
96 if (cur_content_encoding_->type() == ContentEncoding::kTypeInvalid) 97 if (cur_content_encoding_->type() == ContentEncoding::kTypeInvalid)
97 cur_content_encoding_->set_type(ContentEncoding::kTypeCompression); 98 cur_content_encoding_->set_type(ContentEncoding::kTypeCompression);
98 99
99 // Check for elements valid in spec but not supported for now. 100 // Check for elements valid in spec but not supported for now.
100 if (cur_content_encoding_->type() == ContentEncoding::kTypeCompression) { 101 if (cur_content_encoding_->type() == ContentEncoding::kTypeCompression) {
101 DVLOG(1) << "ContentCompression not supported."; 102 MEDIA_LOG(log_cb_) << "ContentCompression not supported.";
102 return false; 103 return false;
103 } 104 }
104 105
105 // Enforce mandatory elements without default values. 106 // Enforce mandatory elements without default values.
106 DCHECK(cur_content_encoding_->type() == ContentEncoding::kTypeEncryption); 107 DCHECK(cur_content_encoding_->type() == ContentEncoding::kTypeEncryption);
107 if (!content_encryption_encountered_) { 108 if (!content_encryption_encountered_) {
108 DVLOG(1) << "ContentEncodingType is encryption but ContentEncryption " 109 MEDIA_LOG(log_cb_) << "ContentEncodingType is encryption but"
109 "is missing."; 110 << " ContentEncryption is missing.";
110 return false; 111 return false;
111 } 112 }
112 113
113 content_encodings_.push_back(cur_content_encoding_.release()); 114 content_encodings_.push_back(cur_content_encoding_.release());
114 content_encryption_encountered_ = false; 115 content_encryption_encountered_ = false;
115 return true; 116 return true;
116 } 117 }
117 118
118 if (id == kWebMIdContentEncryption) { 119 if (id == kWebMIdContentEncryption) {
119 DCHECK(cur_content_encoding_.get()); 120 DCHECK(cur_content_encoding_.get());
(...skipping 18 matching lines...) Expand all
138 return false; 139 return false;
139 } 140 }
140 141
141 // Multiple occurrence restriction and range are checked in this function. 142 // Multiple occurrence restriction and range are checked in this function.
142 // Mandatory occurrence restriction is checked in OnListEnd. 143 // Mandatory occurrence restriction is checked in OnListEnd.
143 bool WebMContentEncodingsClient::OnUInt(int id, int64 val) { 144 bool WebMContentEncodingsClient::OnUInt(int id, int64 val) {
144 DCHECK(cur_content_encoding_.get()); 145 DCHECK(cur_content_encoding_.get());
145 146
146 if (id == kWebMIdContentEncodingOrder) { 147 if (id == kWebMIdContentEncodingOrder) {
147 if (cur_content_encoding_->order() != ContentEncoding::kOrderInvalid) { 148 if (cur_content_encoding_->order() != ContentEncoding::kOrderInvalid) {
148 DVLOG(1) << "Unexpected multiple ContentEncodingOrder."; 149 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncodingOrder.";
149 return false; 150 return false;
150 } 151 }
151 152
152 if (val != static_cast<int64>(content_encodings_.size())) { 153 if (val != static_cast<int64>(content_encodings_.size())) {
153 // 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.
154 DVLOG(1) << "Unexpected ContentEncodingOrder."; 155 MEDIA_LOG(log_cb_) << "Unexpected ContentEncodingOrder.";
155 return false; 156 return false;
156 } 157 }
157 158
158 cur_content_encoding_->set_order(val); 159 cur_content_encoding_->set_order(val);
159 return true; 160 return true;
160 } 161 }
161 162
162 if (id == kWebMIdContentEncodingScope) { 163 if (id == kWebMIdContentEncodingScope) {
163 if (cur_content_encoding_->scope() != ContentEncoding::kScopeInvalid) { 164 if (cur_content_encoding_->scope() != ContentEncoding::kScopeInvalid) {
164 DVLOG(1) << "Unexpected multiple ContentEncodingScope."; 165 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncodingScope.";
165 return false; 166 return false;
166 } 167 }
167 168
168 if (val == ContentEncoding::kScopeInvalid || 169 if (val == ContentEncoding::kScopeInvalid ||
169 val > ContentEncoding::kScopeMax) { 170 val > ContentEncoding::kScopeMax) {
170 DVLOG(1) << "Unexpected ContentEncodingScope."; 171 MEDIA_LOG(log_cb_) << "Unexpected ContentEncodingScope.";
171 return false; 172 return false;
172 } 173 }
173 174
174 if (val & ContentEncoding::kScopeNextContentEncodingData) { 175 if (val & ContentEncoding::kScopeNextContentEncodingData) {
175 DVLOG(1) << "Encoded next ContentEncoding is not supported."; 176 MEDIA_LOG(log_cb_) << "Encoded next ContentEncoding is not supported.";
176 return false; 177 return false;
177 } 178 }
178 179
179 cur_content_encoding_->set_scope(static_cast<ContentEncoding::Scope>(val)); 180 cur_content_encoding_->set_scope(static_cast<ContentEncoding::Scope>(val));
180 return true; 181 return true;
181 } 182 }
182 183
183 if (id == kWebMIdContentEncodingType) { 184 if (id == kWebMIdContentEncodingType) {
184 if (cur_content_encoding_->type() != ContentEncoding::kTypeInvalid) { 185 if (cur_content_encoding_->type() != ContentEncoding::kTypeInvalid) {
185 DVLOG(1) << "Unexpected multiple ContentEncodingType."; 186 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncodingType.";
186 return false; 187 return false;
187 } 188 }
188 189
189 if (val == ContentEncoding::kTypeCompression) { 190 if (val == ContentEncoding::kTypeCompression) {
190 DVLOG(1) << "ContentCompression not supported."; 191 MEDIA_LOG(log_cb_) << "ContentCompression not supported.";
191 return false; 192 return false;
192 } 193 }
193 194
194 if (val != ContentEncoding::kTypeEncryption) { 195 if (val != ContentEncoding::kTypeEncryption) {
195 DVLOG(1) << "Unexpected ContentEncodingType " << val << "."; 196 MEDIA_LOG(log_cb_) << "Unexpected ContentEncodingType " << val << ".";
196 return false; 197 return false;
197 } 198 }
198 199
199 cur_content_encoding_->set_type(static_cast<ContentEncoding::Type>(val)); 200 cur_content_encoding_->set_type(static_cast<ContentEncoding::Type>(val));
200 return true; 201 return true;
201 } 202 }
202 203
203 if (id == kWebMIdContentEncAlgo) { 204 if (id == kWebMIdContentEncAlgo) {
204 if (cur_content_encoding_->encryption_algo() != 205 if (cur_content_encoding_->encryption_algo() !=
205 ContentEncoding::kEncAlgoInvalid) { 206 ContentEncoding::kEncAlgoInvalid) {
206 DVLOG(1) << "Unexpected multiple ContentEncAlgo."; 207 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncAlgo.";
207 return false; 208 return false;
208 } 209 }
209 210
210 if (val < ContentEncoding::kEncAlgoNotEncrypted || 211 if (val < ContentEncoding::kEncAlgoNotEncrypted ||
211 val > ContentEncoding::kEncAlgoAes) { 212 val > ContentEncoding::kEncAlgoAes) {
212 DVLOG(1) << "Unexpected ContentEncAlgo " << val << "."; 213 MEDIA_LOG(log_cb_) << "Unexpected ContentEncAlgo " << val << ".";
213 return false; 214 return false;
214 } 215 }
215 216
216 cur_content_encoding_->set_encryption_algo( 217 cur_content_encoding_->set_encryption_algo(
217 static_cast<ContentEncoding::EncryptionAlgo>(val)); 218 static_cast<ContentEncoding::EncryptionAlgo>(val));
218 return true; 219 return true;
219 } 220 }
220 221
221 if (id == kWebMIdAESSettingsCipherMode) { 222 if (id == kWebMIdAESSettingsCipherMode) {
222 if (cur_content_encoding_->cipher_mode() != 223 if (cur_content_encoding_->cipher_mode() !=
223 ContentEncoding::kCipherModeInvalid) { 224 ContentEncoding::kCipherModeInvalid) {
224 DVLOG(1) << "Unexpected multiple AESSettingsCipherMode."; 225 MEDIA_LOG(log_cb_) << "Unexpected multiple AESSettingsCipherMode.";
225 return false; 226 return false;
226 } 227 }
227 228
228 if (val != ContentEncoding::kCipherModeCtr) { 229 if (val != ContentEncoding::kCipherModeCtr) {
229 DVLOG(1) << "Unexpected AESSettingsCipherMode " << val << "."; 230 MEDIA_LOG(log_cb_) << "Unexpected AESSettingsCipherMode " << val << ".";
230 return false; 231 return false;
231 } 232 }
232 233
233 cur_content_encoding_->set_cipher_mode( 234 cur_content_encoding_->set_cipher_mode(
234 static_cast<ContentEncoding::CipherMode>(val)); 235 static_cast<ContentEncoding::CipherMode>(val));
235 return true; 236 return true;
236 } 237 }
237 238
238 // This should not happen if WebMListParser is working properly. 239 // This should not happen if WebMListParser is working properly.
239 DCHECK(false); 240 DCHECK(false);
240 return false; 241 return false;
241 } 242 }
242 243
243 // Multiple occurrence restriction is checked in this function. Mandatory 244 // Multiple occurrence restriction is checked in this function. Mandatory
244 // restriction is checked in OnListEnd. 245 // restriction is checked in OnListEnd.
245 bool WebMContentEncodingsClient::OnBinary(int id, const uint8* data, int size) { 246 bool WebMContentEncodingsClient::OnBinary(int id, const uint8* data, int size) {
246 DCHECK(cur_content_encoding_.get()); 247 DCHECK(cur_content_encoding_.get());
247 DCHECK(data); 248 DCHECK(data);
248 DCHECK_GT(size, 0); 249 DCHECK_GT(size, 0);
249 250
250 if (id == kWebMIdContentEncKeyID) { 251 if (id == kWebMIdContentEncKeyID) {
251 if (!cur_content_encoding_->encryption_key_id().empty()) { 252 if (!cur_content_encoding_->encryption_key_id().empty()) {
252 DVLOG(1) << "Unexpected multiple ContentEncKeyID"; 253 MEDIA_LOG(log_cb_) << "Unexpected multiple ContentEncKeyID";
253 return false; 254 return false;
254 } 255 }
255 cur_content_encoding_->SetEncryptionKeyId(data, size); 256 cur_content_encoding_->SetEncryptionKeyId(data, size);
256 return true; 257 return true;
257 } 258 }
258 259
259 // This should not happen if WebMListParser is working properly. 260 // This should not happen if WebMListParser is working properly.
260 DCHECK(false); 261 DCHECK(false);
261 return false; 262 return false;
262 } 263 }
263 264
264 } // namespace media 265 } // namespace media
OLDNEW
« no previous file with comments | « media/webm/webm_content_encodings_client.h ('k') | media/webm/webm_content_encodings_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698