Chromium Code Reviews| 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" |
| 11 #include "media/ffmpeg/ffmpeg_common.h" | 11 #include "media/ffmpeg/ffmpeg_common.h" |
| 12 #include "media/filters/ffmpeg_glue.h" | 12 #include "media/filters/ffmpeg_glue.h" |
| 13 #include "media/filters/in_memory_url_protocol.h" | 13 #include "media/filters/in_memory_url_protocol.h" |
| 14 #include "media/webm/webm_cluster_parser.h" | 14 #include "media/webm/webm_cluster_parser.h" |
| 15 #include "media/webm/webm_constants.h" | 15 #include "media/webm/webm_constants.h" |
| 16 #include "media/webm/webm_content_encodings.h" | 16 #include "media/webm/webm_content_encodings.h" |
| 17 #include "media/webm/webm_info_parser.h" | 17 #include "media/webm/webm_info_parser.h" |
| 18 #include "media/webm/webm_tracks_parser.h" | 18 #include "media/webm/webm_tracks_parser.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 // Fire needkey event through the |need_key_cb|. | |
| 23 static void FireNeedKey(const StreamParser::NeedKeyCB& need_key_cb, | |
| 24 const std::string& key_id) { | |
| 25 int key_id_size = key_id.size(); | |
| 26 DCHECK_GT(key_id_size, 0); | |
| 27 scoped_array<uint8> key_id_array(new uint8[key_id_size]); | |
| 28 memcpy(key_id_array.get(), key_id.data(), key_id_size); | |
| 29 need_key_cb.Run(key_id_array.Pass(), key_id_size); | |
| 30 } | |
| 31 | |
| 22 // Helper class that uses FFmpeg to create AudioDecoderConfig & | 32 // Helper class that uses FFmpeg to create AudioDecoderConfig & |
| 23 // VideoDecoderConfig objects. | 33 // VideoDecoderConfig objects. |
| 24 // | 34 // |
| 25 // This dependency on FFmpeg can be removed once we update WebMTracksParser | 35 // This dependency on FFmpeg can be removed once we update WebMTracksParser |
| 26 // to parse the necessary data to construct AudioDecoderConfig & | 36 // to parse the necessary data to construct AudioDecoderConfig & |
| 27 // VideoDecoderConfig objects. http://crbug.com/108756 | 37 // VideoDecoderConfig objects. http://crbug.com/108756 |
| 28 class FFmpegConfigHelper { | 38 class FFmpegConfigHelper { |
| 29 public: | 39 public: |
| 30 FFmpegConfigHelper(); | 40 FFmpegConfigHelper(); |
| 31 ~FFmpegConfigHelper(); | 41 ~FFmpegConfigHelper(); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 int64 duration_in_us = info_parser.duration() * mult; | 354 int64 duration_in_us = info_parser.duration() * mult; |
| 345 duration = base::TimeDelta::FromMicroseconds(duration_in_us); | 355 duration = base::TimeDelta::FromMicroseconds(duration_in_us); |
| 346 } | 356 } |
| 347 | 357 |
| 348 FFmpegConfigHelper config_helper; | 358 FFmpegConfigHelper config_helper; |
| 349 if (!config_helper.Parse(data, bytes_parsed)) { | 359 if (!config_helper.Parse(data, bytes_parsed)) { |
| 350 DVLOG(1) << "Failed to parse config data."; | 360 DVLOG(1) << "Failed to parse config data."; |
| 351 return -1; | 361 return -1; |
| 352 } | 362 } |
| 353 | 363 |
| 364 bool is_audio_encrypted = !tracks_parser.audio_encryption_key_id().empty(); | |
| 365 AudioDecoderConfig audio_config; | |
| 366 if (is_audio_encrypted) { | |
| 367 const AudioDecoderConfig& original_audio_config = | |
| 368 config_helper.audio_config(); | |
| 369 | |
| 370 audio_config.Initialize(original_audio_config.codec(), | |
| 371 original_audio_config.bits_per_channel(), | |
| 372 original_audio_config.channel_layout(), | |
| 373 original_audio_config.samples_per_second(), | |
| 374 original_audio_config.extra_data(), | |
| 375 original_audio_config.extra_data_size(), | |
| 376 is_audio_encrypted, false); | |
| 377 | |
| 378 FireNeedKey(need_key_cb_, tracks_parser.audio_encryption_key_id()); | |
|
acolwell GONE FROM CHROMIUM
2012/10/11 01:11:24
nit: Why are you using a static function here inst
xhwang
2012/10/11 16:36:10
Done.
| |
| 379 } else { | |
| 380 audio_config.CopyFrom(config_helper.audio_config()); | |
| 381 } | |
| 382 | |
| 354 // TODO(xhwang): Support decryption of audio (see http://crbug.com/123421). | 383 // TODO(xhwang): Support decryption of audio (see http://crbug.com/123421). |
| 355 bool is_video_encrypted = !tracks_parser.video_encryption_key_id().empty(); | 384 bool is_video_encrypted = !tracks_parser.video_encryption_key_id().empty(); |
| 356 | 385 |
| 357 VideoDecoderConfig video_config; | 386 VideoDecoderConfig video_config; |
| 358 if (is_video_encrypted) { | 387 if (is_video_encrypted) { |
| 359 const VideoDecoderConfig& original_video_config = | 388 const VideoDecoderConfig& original_video_config = |
| 360 config_helper.video_config(); | 389 config_helper.video_config(); |
| 361 video_config.Initialize(original_video_config.codec(), | 390 video_config.Initialize(original_video_config.codec(), |
| 362 original_video_config.profile(), | 391 original_video_config.profile(), |
| 363 original_video_config.format(), | 392 original_video_config.format(), |
| 364 original_video_config.coded_size(), | 393 original_video_config.coded_size(), |
| 365 original_video_config.visible_rect(), | 394 original_video_config.visible_rect(), |
| 366 original_video_config.natural_size(), | 395 original_video_config.natural_size(), |
| 367 original_video_config.extra_data(), | 396 original_video_config.extra_data(), |
| 368 original_video_config.extra_data_size(), | 397 original_video_config.extra_data_size(), |
| 369 is_video_encrypted, false); | 398 is_video_encrypted, false); |
| 370 | 399 |
| 371 // Fire needkey event. | 400 FireNeedKey(need_key_cb_, 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 { | 401 } else { |
| 379 video_config.CopyFrom(config_helper.video_config()); | 402 video_config.CopyFrom(config_helper.video_config()); |
| 380 } | 403 } |
| 381 | 404 |
| 382 if (!config_cb_.Run(config_helper.audio_config(), video_config)) { | 405 if (!config_cb_.Run(audio_config, video_config)) { |
| 383 DVLOG(1) << "New config data isn't allowed."; | 406 DVLOG(1) << "New config data isn't allowed."; |
| 384 return -1; | 407 return -1; |
| 385 } | 408 } |
| 386 | 409 |
| 387 cluster_parser_.reset(new WebMClusterParser( | 410 cluster_parser_.reset(new WebMClusterParser( |
| 388 info_parser.timecode_scale(), | 411 info_parser.timecode_scale(), |
| 389 tracks_parser.audio_track_num(), | 412 tracks_parser.audio_track_num(), |
| 390 tracks_parser.video_track_num(), | 413 tracks_parser.video_track_num(), |
| 414 tracks_parser.audio_encryption_key_id(), | |
| 391 tracks_parser.video_encryption_key_id())); | 415 tracks_parser.video_encryption_key_id())); |
| 392 | 416 |
| 393 ChangeState(kParsingClusters); | 417 ChangeState(kParsingClusters); |
| 394 | 418 |
| 395 if (!init_cb_.is_null()) { | 419 if (!init_cb_.is_null()) { |
| 396 init_cb_.Run(true, duration); | 420 init_cb_.Run(true, duration); |
| 397 init_cb_.Reset(); | 421 init_cb_.Reset(); |
| 398 } | 422 } |
| 399 | 423 |
| 400 return bytes_parsed; | 424 return bytes_parsed; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) | 473 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) |
| 450 return -1; | 474 return -1; |
| 451 | 475 |
| 452 if (cluster_ended) | 476 if (cluster_ended) |
| 453 end_of_segment_cb_.Run(); | 477 end_of_segment_cb_.Run(); |
| 454 | 478 |
| 455 return bytes_parsed; | 479 return bytes_parsed; |
| 456 } | 480 } |
| 457 | 481 |
| 458 } // namespace media | 482 } // namespace media |
| OLD | NEW |