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_stream_parser.h" | 5 #include "media/webm/webm_stream_parser.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 | 180 |
181 WebMStreamParser::~WebMStreamParser() {} | 181 WebMStreamParser::~WebMStreamParser() {} |
182 | 182 |
183 void WebMStreamParser::Init(const InitCB& init_cb, | 183 void WebMStreamParser::Init(const InitCB& init_cb, |
184 const NewConfigCB& config_cb, | 184 const NewConfigCB& config_cb, |
185 const NewBuffersCB& audio_cb, | 185 const NewBuffersCB& audio_cb, |
186 const NewBuffersCB& video_cb, | 186 const NewBuffersCB& video_cb, |
187 const NeedKeyCB& need_key_cb, | 187 const NeedKeyCB& need_key_cb, |
188 const NewMediaSegmentCB& new_segment_cb, | 188 const NewMediaSegmentCB& new_segment_cb, |
189 const base::Closure& end_of_segment_cb) { | 189 const base::Closure& end_of_segment_cb, |
| 190 const LogCB& log_cb) { |
190 DCHECK_EQ(state_, kWaitingForInit); | 191 DCHECK_EQ(state_, kWaitingForInit); |
191 DCHECK(init_cb_.is_null()); | 192 DCHECK(init_cb_.is_null()); |
192 DCHECK(!init_cb.is_null()); | 193 DCHECK(!init_cb.is_null()); |
193 DCHECK(!config_cb.is_null()); | 194 DCHECK(!config_cb.is_null()); |
194 DCHECK(!audio_cb.is_null() || !video_cb.is_null()); | 195 DCHECK(!audio_cb.is_null() || !video_cb.is_null()); |
195 DCHECK(!need_key_cb.is_null()); | 196 DCHECK(!need_key_cb.is_null()); |
196 DCHECK(!new_segment_cb.is_null()); | 197 DCHECK(!new_segment_cb.is_null()); |
197 DCHECK(!end_of_segment_cb.is_null()); | 198 DCHECK(!end_of_segment_cb.is_null()); |
198 | 199 |
199 ChangeState(kParsingHeaders); | 200 ChangeState(kParsingHeaders); |
200 init_cb_ = init_cb; | 201 init_cb_ = init_cb; |
201 config_cb_ = config_cb; | 202 config_cb_ = config_cb; |
202 audio_cb_ = audio_cb; | 203 audio_cb_ = audio_cb; |
203 video_cb_ = video_cb; | 204 video_cb_ = video_cb; |
204 need_key_cb_ = need_key_cb; | 205 need_key_cb_ = need_key_cb; |
205 new_segment_cb_ = new_segment_cb; | 206 new_segment_cb_ = new_segment_cb; |
206 end_of_segment_cb_ = end_of_segment_cb; | 207 end_of_segment_cb_ = end_of_segment_cb; |
| 208 log_cb_ = log_cb; |
207 } | 209 } |
208 | 210 |
209 void WebMStreamParser::Flush() { | 211 void WebMStreamParser::Flush() { |
210 DCHECK_NE(state_, kWaitingForInit); | 212 DCHECK_NE(state_, kWaitingForInit); |
211 | 213 |
212 byte_queue_.Reset(); | 214 byte_queue_.Reset(); |
213 | 215 |
214 if (state_ != kParsingClusters) | 216 if (state_ != kParsingClusters) |
215 return; | 217 return; |
216 | 218 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 // Skip the element. | 300 // Skip the element. |
299 return result + element_size; | 301 return result + element_size; |
300 break; | 302 break; |
301 case kWebMIdSegment: | 303 case kWebMIdSegment: |
302 // Just consume the segment header. | 304 // Just consume the segment header. |
303 return result; | 305 return result; |
304 break; | 306 break; |
305 case kWebMIdInfo: | 307 case kWebMIdInfo: |
306 // We've found the element we are looking for. | 308 // We've found the element we are looking for. |
307 break; | 309 break; |
308 default: | 310 default: { |
309 DVLOG(1) << "Unexpected ID 0x" << std::hex << id; | 311 MEDIA_LOG(log_cb_) << "Unexpected element ID 0x" << std::hex << id; |
310 return -1; | 312 return -1; |
| 313 } |
311 } | 314 } |
312 | 315 |
313 WebMInfoParser info_parser; | 316 WebMInfoParser info_parser; |
314 result = info_parser.Parse(cur, cur_size); | 317 result = info_parser.Parse(cur, cur_size); |
315 | 318 |
316 if (result <= 0) | 319 if (result <= 0) |
317 return result; | 320 return result; |
318 | 321 |
319 cur += result; | 322 cur += result; |
320 cur_size -= result; | 323 cur_size -= result; |
321 bytes_parsed += result; | 324 bytes_parsed += result; |
322 | 325 |
323 WebMTracksParser tracks_parser; | 326 WebMTracksParser tracks_parser(log_cb_); |
324 result = tracks_parser.Parse(cur, cur_size); | 327 result = tracks_parser.Parse(cur, cur_size); |
325 | 328 |
326 if (result <= 0) | 329 if (result <= 0) |
327 return result; | 330 return result; |
328 | 331 |
329 bytes_parsed += result; | 332 bytes_parsed += result; |
330 | 333 |
331 base::TimeDelta duration = kInfiniteDuration(); | 334 base::TimeDelta duration = kInfiniteDuration(); |
332 | 335 |
333 if (info_parser.duration() > 0) { | 336 if (info_parser.duration() > 0) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 if (!config_cb_.Run(audio_config, video_config)) { | 389 if (!config_cb_.Run(audio_config, video_config)) { |
387 DVLOG(1) << "New config data isn't allowed."; | 390 DVLOG(1) << "New config data isn't allowed."; |
388 return -1; | 391 return -1; |
389 } | 392 } |
390 | 393 |
391 cluster_parser_.reset(new WebMClusterParser( | 394 cluster_parser_.reset(new WebMClusterParser( |
392 info_parser.timecode_scale(), | 395 info_parser.timecode_scale(), |
393 tracks_parser.audio_track_num(), | 396 tracks_parser.audio_track_num(), |
394 tracks_parser.video_track_num(), | 397 tracks_parser.video_track_num(), |
395 tracks_parser.audio_encryption_key_id(), | 398 tracks_parser.audio_encryption_key_id(), |
396 tracks_parser.video_encryption_key_id())); | 399 tracks_parser.video_encryption_key_id(), |
| 400 log_cb_)); |
397 | 401 |
398 ChangeState(kParsingClusters); | 402 ChangeState(kParsingClusters); |
399 | 403 |
400 if (!init_cb_.is_null()) { | 404 if (!init_cb_.is_null()) { |
401 init_cb_.Run(true, duration); | 405 init_cb_.Run(true, duration); |
402 init_cb_.Reset(); | 406 init_cb_.Reset(); |
403 } | 407 } |
404 | 408 |
405 return bytes_parsed; | 409 return bytes_parsed; |
406 } | 410 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 466 |
463 void WebMStreamParser::FireNeedKey(const std::string& key_id) { | 467 void WebMStreamParser::FireNeedKey(const std::string& key_id) { |
464 int key_id_size = key_id.size(); | 468 int key_id_size = key_id.size(); |
465 DCHECK_GT(key_id_size, 0); | 469 DCHECK_GT(key_id_size, 0); |
466 scoped_array<uint8> key_id_array(new uint8[key_id_size]); | 470 scoped_array<uint8> key_id_array(new uint8[key_id_size]); |
467 memcpy(key_id_array.get(), key_id.data(), key_id_size); | 471 memcpy(key_id_array.get(), key_id.data(), key_id_size); |
468 need_key_cb_.Run(kWebMInitDataType, key_id_array.Pass(), key_id_size); | 472 need_key_cb_.Run(kWebMInitDataType, key_id_array.Pass(), key_id_size); |
469 } | 473 } |
470 | 474 |
471 } // namespace media | 475 } // namespace media |
OLD | NEW |