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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 int64 duration_in_us = info_parser.duration() * mult; | 344 int64 duration_in_us = info_parser.duration() * mult; |
345 duration = base::TimeDelta::FromMicroseconds(duration_in_us); | 345 duration = base::TimeDelta::FromMicroseconds(duration_in_us); |
346 } | 346 } |
347 | 347 |
348 FFmpegConfigHelper config_helper; | 348 FFmpegConfigHelper config_helper; |
349 if (!config_helper.Parse(data, bytes_parsed)) { | 349 if (!config_helper.Parse(data, bytes_parsed)) { |
350 DVLOG(1) << "Failed to parse config data."; | 350 DVLOG(1) << "Failed to parse config data."; |
351 return -1; | 351 return -1; |
352 } | 352 } |
353 | 353 |
| 354 bool is_audio_encrypted = !tracks_parser.audio_encryption_key_id().empty(); |
| 355 AudioDecoderConfig audio_config; |
| 356 if (is_audio_encrypted) { |
| 357 const AudioDecoderConfig& original_audio_config = |
| 358 config_helper.audio_config(); |
| 359 |
| 360 audio_config.Initialize(original_audio_config.codec(), |
| 361 original_audio_config.bits_per_channel(), |
| 362 original_audio_config.channel_layout(), |
| 363 original_audio_config.samples_per_second(), |
| 364 original_audio_config.extra_data(), |
| 365 original_audio_config.extra_data_size(), |
| 366 is_audio_encrypted, false); |
| 367 |
| 368 FireNeedKey(tracks_parser.audio_encryption_key_id()); |
| 369 } else { |
| 370 audio_config.CopyFrom(config_helper.audio_config()); |
| 371 } |
| 372 |
354 // TODO(xhwang): Support decryption of audio (see http://crbug.com/123421). | 373 // TODO(xhwang): Support decryption of audio (see http://crbug.com/123421). |
355 bool is_video_encrypted = !tracks_parser.video_encryption_key_id().empty(); | 374 bool is_video_encrypted = !tracks_parser.video_encryption_key_id().empty(); |
356 | 375 |
357 VideoDecoderConfig video_config; | 376 VideoDecoderConfig video_config; |
358 if (is_video_encrypted) { | 377 if (is_video_encrypted) { |
359 const VideoDecoderConfig& original_video_config = | 378 const VideoDecoderConfig& original_video_config = |
360 config_helper.video_config(); | 379 config_helper.video_config(); |
361 video_config.Initialize(original_video_config.codec(), | 380 video_config.Initialize(original_video_config.codec(), |
362 original_video_config.profile(), | 381 original_video_config.profile(), |
363 original_video_config.format(), | 382 original_video_config.format(), |
364 original_video_config.coded_size(), | 383 original_video_config.coded_size(), |
365 original_video_config.visible_rect(), | 384 original_video_config.visible_rect(), |
366 original_video_config.natural_size(), | 385 original_video_config.natural_size(), |
367 original_video_config.extra_data(), | 386 original_video_config.extra_data(), |
368 original_video_config.extra_data_size(), | 387 original_video_config.extra_data_size(), |
369 is_video_encrypted, false); | 388 is_video_encrypted, false); |
370 | 389 |
371 // Fire needkey event. | 390 FireNeedKey(tracks_parser.video_encryption_key_id()); |
372 std::string key_id = tracks_parser.video_encryption_key_id(); | |
373 int key_id_size = key_id.size(); | |
374 DCHECK_GT(key_id_size, 0); | |
375 scoped_array<uint8> key_id_array(new uint8[key_id_size]); | |
376 memcpy(key_id_array.get(), key_id.data(), key_id_size); | |
377 need_key_cb_.Run(key_id_array.Pass(), key_id_size); | |
378 } else { | 391 } else { |
379 video_config.CopyFrom(config_helper.video_config()); | 392 video_config.CopyFrom(config_helper.video_config()); |
380 } | 393 } |
381 | 394 |
382 if (!config_cb_.Run(config_helper.audio_config(), video_config)) { | 395 if (!config_cb_.Run(audio_config, video_config)) { |
383 DVLOG(1) << "New config data isn't allowed."; | 396 DVLOG(1) << "New config data isn't allowed."; |
384 return -1; | 397 return -1; |
385 } | 398 } |
386 | 399 |
387 cluster_parser_.reset(new WebMClusterParser( | 400 cluster_parser_.reset(new WebMClusterParser( |
388 info_parser.timecode_scale(), | 401 info_parser.timecode_scale(), |
389 tracks_parser.audio_track_num(), | 402 tracks_parser.audio_track_num(), |
390 tracks_parser.video_track_num(), | 403 tracks_parser.video_track_num(), |
| 404 tracks_parser.audio_encryption_key_id(), |
391 tracks_parser.video_encryption_key_id())); | 405 tracks_parser.video_encryption_key_id())); |
392 | 406 |
393 ChangeState(kParsingClusters); | 407 ChangeState(kParsingClusters); |
394 | 408 |
395 if (!init_cb_.is_null()) { | 409 if (!init_cb_.is_null()) { |
396 init_cb_.Run(true, duration); | 410 init_cb_.Run(true, duration); |
397 init_cb_.Reset(); | 411 init_cb_.Reset(); |
398 } | 412 } |
399 | 413 |
400 return bytes_parsed; | 414 return bytes_parsed; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 462 |
449 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) | 463 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) |
450 return -1; | 464 return -1; |
451 | 465 |
452 if (cluster_ended) | 466 if (cluster_ended) |
453 end_of_segment_cb_.Run(); | 467 end_of_segment_cb_.Run(); |
454 | 468 |
455 return bytes_parsed; | 469 return bytes_parsed; |
456 } | 470 } |
457 | 471 |
| 472 void WebMStreamParser::FireNeedKey(const std::string& key_id) { |
| 473 int key_id_size = key_id.size(); |
| 474 DCHECK_GT(key_id_size, 0); |
| 475 scoped_array<uint8> key_id_array(new uint8[key_id_size]); |
| 476 memcpy(key_id_array.get(), key_id.data(), key_id_size); |
| 477 need_key_cb_.Run(key_id_array.Pass(), key_id_size); |
| 478 } |
| 479 |
458 } // namespace media | 480 } // namespace media |
OLD | NEW |