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

Side by Side Diff: content/renderer/media/android/media_source_delegate.cc

Issue 23787002: Rename MediaPlayerHostMsg_{DemuxerReady,ReadFromDemuxerAck}_Params to Media{Configs,Data}. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/android/media_source_delegate.h" 5 #include "content/renderer/media/android/media_source_delegate.h"
6 6
7 #include "base/message_loop/message_loop_proxy.h" 7 #include "base/message_loop/message_loop_proxy.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "content/renderer/media/android/webmediaplayer_proxy_android.h" 9 #include "content/renderer/media/android/webmediaplayer_proxy_android.h"
10 #include "content/renderer/media/webmediaplayer_util.h" 10 #include "content/renderer/media/webmediaplayer_util.h"
11 #include "content/renderer/media/webmediasource_impl.h" 11 #include "content/renderer/media/webmediasource_impl.h"
12 #include "media/base/android/demuxer_stream_player_params.h" 12 #include "media/base/android/demuxer_stream_player_params.h"
13 #include "media/base/bind_to_loop.h" 13 #include "media/base/bind_to_loop.h"
14 #include "media/base/demuxer_stream.h" 14 #include "media/base/demuxer_stream.h"
15 #include "media/base/media_log.h" 15 #include "media/base/media_log.h"
16 #include "media/filters/chunk_demuxer.h" 16 #include "media/filters/chunk_demuxer.h"
17 #include "media/filters/decrypting_demuxer_stream.h" 17 #include "media/filters/decrypting_demuxer_stream.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 19 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
20 20
21 using media::DemuxerStream; 21 using media::DemuxerStream;
22 using media::MediaPlayerHostMsg_DemuxerReady_Params; 22 using media::DemuxerConfigs;
23 using media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params; 23 using media::DemuxerData;
24 using WebKit::WebMediaPlayer; 24 using WebKit::WebMediaPlayer;
25 using WebKit::WebString; 25 using WebKit::WebString;
26 26
27 namespace { 27 namespace {
28 28
29 // The size of the access unit to transfer in an IPC in case of MediaSource. 29 // The size of the access unit to transfer in an IPC in case of MediaSource.
30 // 16: approximately 250ms of content in 60 fps movies. 30 // 16: approximately 250ms of content in 60 fps movies.
31 const size_t kAccessUnitSizeForMediaSource = 16; 31 const size_t kAccessUnitSizeForMediaSource = 16;
32 32
33 const uint8 kVorbisPadding[] = { 0xff, 0xff, 0xff, 0xff }; 33 const uint8 kVorbisPadding[] = { 0xff, 0xff, 0xff, 0xff };
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 void MediaSourceDelegate::OnReadFromDemuxerInternal( 301 void MediaSourceDelegate::OnReadFromDemuxerInternal(
302 media::DemuxerStream::Type type) { 302 media::DemuxerStream::Type type) {
303 DCHECK_BELONG_TO_MEDIA_LOOP(); 303 DCHECK_BELONG_TO_MEDIA_LOOP();
304 DVLOG(1) << "OnReadFromDemuxer(" << type << ") : " << player_id_; 304 DVLOG(1) << "OnReadFromDemuxer(" << type << ") : " << player_id_;
305 if (IsSeeking()) 305 if (IsSeeking())
306 return; // Drop the request during seeking. 306 return; // Drop the request during seeking.
307 307
308 DCHECK(type == DemuxerStream::AUDIO || type == DemuxerStream::VIDEO); 308 DCHECK(type == DemuxerStream::AUDIO || type == DemuxerStream::VIDEO);
309 // The access unit size should have been initialized properly at this stage. 309 // The access unit size should have been initialized properly at this stage.
310 DCHECK_GT(access_unit_size_, 0u); 310 DCHECK_GT(access_unit_size_, 0u);
311 scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params( 311 scoped_ptr<DemuxerData> data(new DemuxerData());
312 new MediaPlayerHostMsg_ReadFromDemuxerAck_Params()); 312 data->type = type;
313 params->type = type; 313 data->access_units.resize(access_unit_size_);
314 params->access_units.resize(access_unit_size_); 314 ReadFromDemuxerStream(type, data.Pass(), 0);
315 ReadFromDemuxerStream(type, params.Pass(), 0);
316 } 315 }
317 316
318 void MediaSourceDelegate::ReadFromDemuxerStream( 317 void MediaSourceDelegate::ReadFromDemuxerStream(media::DemuxerStream::Type type,
319 media::DemuxerStream::Type type, 318 scoped_ptr<DemuxerData> data,
320 scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params, 319 size_t index) {
321 size_t index) {
322 DCHECK_BELONG_TO_MEDIA_LOOP(); 320 DCHECK_BELONG_TO_MEDIA_LOOP();
323 // DemuxerStream::Read() always returns the read callback asynchronously. 321 // DemuxerStream::Read() always returns the read callback asynchronously.
324 DemuxerStream* stream = 322 DemuxerStream* stream =
325 (type == DemuxerStream::AUDIO) ? audio_stream_ : video_stream_; 323 (type == DemuxerStream::AUDIO) ? audio_stream_ : video_stream_;
326 stream->Read(base::Bind( 324 stream->Read(base::Bind(
327 &MediaSourceDelegate::OnBufferReady, 325 &MediaSourceDelegate::OnBufferReady,
328 media_weak_this_.GetWeakPtr(), type, base::Passed(&params), index)); 326 media_weak_this_.GetWeakPtr(), type, base::Passed(&data), index));
329 } 327 }
330 328
331 void MediaSourceDelegate::OnBufferReady( 329 void MediaSourceDelegate::OnBufferReady(
332 media::DemuxerStream::Type type, 330 media::DemuxerStream::Type type,
333 scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params, 331 scoped_ptr<DemuxerData> data,
334 size_t index, 332 size_t index,
335 DemuxerStream::Status status, 333 DemuxerStream::Status status,
336 const scoped_refptr<media::DecoderBuffer>& buffer) { 334 const scoped_refptr<media::DecoderBuffer>& buffer) {
337 DCHECK_BELONG_TO_MEDIA_LOOP(); 335 DCHECK_BELONG_TO_MEDIA_LOOP();
338 DVLOG(1) << "OnBufferReady(" << index << ", " << status << ", " 336 DVLOG(1) << "OnBufferReady(" << index << ", " << status << ", "
339 << ((!buffer || buffer->end_of_stream()) ? 337 << ((!buffer || buffer->end_of_stream()) ?
340 -1 : buffer->timestamp().InMilliseconds()) 338 -1 : buffer->timestamp().InMilliseconds())
341 << ") : " << player_id_; 339 << ") : " << player_id_;
342 DCHECK(demuxer_); 340 DCHECK(demuxer_);
343 341
344 // No new OnReadFromDemuxer() will be called during seeking. So this callback 342 // No new OnReadFromDemuxer() will be called during seeking. So this callback
345 // must be from previous OnReadFromDemuxer() call and should be ignored. 343 // must be from previous OnReadFromDemuxer() call and should be ignored.
346 if (IsSeeking()) { 344 if (IsSeeking()) {
347 DVLOG(1) << "OnBufferReady(): Ignore previous read during seeking."; 345 DVLOG(1) << "OnBufferReady(): Ignore previous read during seeking.";
348 return; 346 return;
349 } 347 }
350 348
351 bool is_audio = (type == DemuxerStream::AUDIO); 349 bool is_audio = (type == DemuxerStream::AUDIO);
352 if (status != DemuxerStream::kAborted && 350 if (status != DemuxerStream::kAborted &&
353 index >= params->access_units.size()) { 351 index >= data->access_units.size()) {
354 LOG(ERROR) << "The internal state inconsistency onBufferReady: " 352 LOG(ERROR) << "The internal state inconsistency onBufferReady: "
355 << (is_audio ? "Audio" : "Video") << ", index " << index 353 << (is_audio ? "Audio" : "Video") << ", index " << index
356 <<", size " << params->access_units.size() 354 << ", size " << data->access_units.size()
357 << ", status " << static_cast<int>(status); 355 << ", status " << static_cast<int>(status);
358 NOTREACHED(); 356 NOTREACHED();
359 return; 357 return;
360 } 358 }
361 359
362 switch (status) { 360 switch (status) {
363 case DemuxerStream::kAborted: 361 case DemuxerStream::kAborted:
364 DVLOG(1) << "OnBufferReady() : Aborted"; 362 DVLOG(1) << "OnBufferReady() : Aborted";
365 params->access_units[index].status = status; 363 data->access_units[index].status = status;
366 params->access_units.resize(index + 1); 364 data->access_units.resize(index + 1);
367 break; 365 break;
368 366
369 case DemuxerStream::kConfigChanged: 367 case DemuxerStream::kConfigChanged:
370 // In case of kConfigChanged, need to read decoder_config once 368 // In case of kConfigChanged, need to read decoder_config once
371 // for the next reads. 369 // for the next reads.
372 // TODO(kjyoun): Investigate if we need to use this new config. See 370 // TODO(kjyoun): Investigate if we need to use this new config. See
373 // http://crbug.com/255783 371 // http://crbug.com/255783
374 if (is_audio) { 372 if (is_audio) {
375 audio_stream_->audio_decoder_config(); 373 audio_stream_->audio_decoder_config();
376 } else { 374 } else {
377 gfx::Size size = video_stream_->video_decoder_config().coded_size(); 375 gfx::Size size = video_stream_->video_decoder_config().coded_size();
378 DVLOG(1) << "Video config is changed: " << size.width() << "x" 376 DVLOG(1) << "Video config is changed: " << size.width() << "x"
379 << size.height(); 377 << size.height();
380 } 378 }
381 params->access_units[index].status = status; 379 data->access_units[index].status = status;
382 params->access_units.resize(index + 1); 380 data->access_units.resize(index + 1);
383 break; 381 break;
384 382
385 case DemuxerStream::kOk: 383 case DemuxerStream::kOk:
386 params->access_units[index].status = status; 384 data->access_units[index].status = status;
387 if (buffer->end_of_stream()) { 385 if (buffer->end_of_stream()) {
388 params->access_units[index].end_of_stream = true; 386 data->access_units[index].end_of_stream = true;
389 params->access_units.resize(index + 1); 387 data->access_units.resize(index + 1);
390 break; 388 break;
391 } 389 }
392 // TODO(ycheo): We assume that the inputed stream will be decoded 390 // TODO(ycheo): We assume that the inputed stream will be decoded
393 // right away. 391 // right away.
394 // Need to implement this properly using MediaPlayer.OnInfoListener. 392 // Need to implement this properly using MediaPlayer.OnInfoListener.
395 if (is_audio) { 393 if (is_audio) {
396 statistics_.audio_bytes_decoded += buffer->data_size(); 394 statistics_.audio_bytes_decoded += buffer->data_size();
397 } else { 395 } else {
398 statistics_.video_bytes_decoded += buffer->data_size(); 396 statistics_.video_bytes_decoded += buffer->data_size();
399 statistics_.video_frames_decoded++; 397 statistics_.video_frames_decoded++;
400 } 398 }
401 params->access_units[index].timestamp = buffer->timestamp(); 399 data->access_units[index].timestamp = buffer->timestamp();
402 params->access_units[index].data = std::vector<uint8>( 400 data->access_units[index].data = std::vector<uint8>(
403 buffer->data(), 401 buffer->data(),
404 buffer->data() + buffer->data_size()); 402 buffer->data() + buffer->data_size());
405 #if !defined(GOOGLE_TV) 403 #if !defined(GOOGLE_TV)
406 // Vorbis needs 4 extra bytes padding on Android. Check 404 // Vorbis needs 4 extra bytes padding on Android. Check
407 // NuMediaExtractor.cpp in Android source code. 405 // NuMediaExtractor.cpp in Android source code.
408 if (is_audio && media::kCodecVorbis == 406 if (is_audio && media::kCodecVorbis ==
409 audio_stream_->audio_decoder_config().codec()) { 407 audio_stream_->audio_decoder_config().codec()) {
410 params->access_units[index].data.insert( 408 data->access_units[index].data.insert(
411 params->access_units[index].data.end(), kVorbisPadding, 409 data->access_units[index].data.end(), kVorbisPadding,
412 kVorbisPadding + 4); 410 kVorbisPadding + 4);
413 } 411 }
414 #endif 412 #endif
415 if (buffer->decrypt_config()) { 413 if (buffer->decrypt_config()) {
416 params->access_units[index].key_id = std::vector<char>( 414 data->access_units[index].key_id = std::vector<char>(
417 buffer->decrypt_config()->key_id().begin(), 415 buffer->decrypt_config()->key_id().begin(),
418 buffer->decrypt_config()->key_id().end()); 416 buffer->decrypt_config()->key_id().end());
419 params->access_units[index].iv = std::vector<char>( 417 data->access_units[index].iv = std::vector<char>(
420 buffer->decrypt_config()->iv().begin(), 418 buffer->decrypt_config()->iv().begin(),
421 buffer->decrypt_config()->iv().end()); 419 buffer->decrypt_config()->iv().end());
422 params->access_units[index].subsamples = 420 data->access_units[index].subsamples =
423 buffer->decrypt_config()->subsamples(); 421 buffer->decrypt_config()->subsamples();
424 } 422 }
425 if (++index < params->access_units.size()) { 423 if (++index < data->access_units.size()) {
426 ReadFromDemuxerStream(type, params.Pass(), index); 424 ReadFromDemuxerStream(type, data.Pass(), index);
427 return; 425 return;
428 } 426 }
429 break; 427 break;
430 428
431 default: 429 default:
432 NOTREACHED(); 430 NOTREACHED();
433 } 431 }
434 432
435 #if defined(GOOGLE_TV) 433 #if defined(GOOGLE_TV)
436 send_read_from_demuxer_ack_cb_.Run(params.Pass()); 434 send_read_from_demuxer_ack_cb_.Run(data.Pass());
437 #else 435 #else
438 SendReadFromDemuxerAck(params.Pass()); 436 SendReadFromDemuxerAck(data.Pass());
439 #endif 437 #endif
440 } 438 }
441 439
442 void MediaSourceDelegate::SendReadFromDemuxerAck( 440 void MediaSourceDelegate::SendReadFromDemuxerAck(scoped_ptr<DemuxerData> data) {
443 scoped_ptr<MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params) {
444 DCHECK(main_loop_->BelongsToCurrentThread()); 441 DCHECK(main_loop_->BelongsToCurrentThread());
445 if (!IsSeeking() && proxy_) 442 if (!IsSeeking() && proxy_)
446 proxy_->ReadFromDemuxerAck(player_id_, *params); 443 proxy_->ReadFromDemuxerAck(player_id_, *data);
447 } 444 }
448 445
449 void MediaSourceDelegate::OnDemuxerError(media::PipelineStatus status) { 446 void MediaSourceDelegate::OnDemuxerError(media::PipelineStatus status) {
450 DVLOG(1) << "OnDemuxerError(" << status << ") : " << player_id_; 447 DVLOG(1) << "OnDemuxerError(" << status << ") : " << player_id_;
451 // |update_network_state_cb_| is bound to the main thread. 448 // |update_network_state_cb_| is bound to the main thread.
452 if (status != media::PIPELINE_OK && !update_network_state_cb_.is_null()) 449 if (status != media::PIPELINE_OK && !update_network_state_cb_.is_null())
453 update_network_state_cb_.Run(PipelineErrorToNetworkState(status)); 450 update_network_state_cb_.Run(PipelineErrorToNetworkState(status));
454 } 451 }
455 452
456 void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) { 453 void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 if (HasEncryptedStream() && !key_added_) 667 if (HasEncryptedStream() && !key_added_)
671 return false; 668 return false;
672 return true; 669 return true;
673 } 670 }
674 671
675 void MediaSourceDelegate::NotifyDemuxerReady() { 672 void MediaSourceDelegate::NotifyDemuxerReady() {
676 DCHECK_BELONG_TO_MEDIA_LOOP(); 673 DCHECK_BELONG_TO_MEDIA_LOOP();
677 DVLOG(1) << "NotifyDemuxerReady() : " << player_id_; 674 DVLOG(1) << "NotifyDemuxerReady() : " << player_id_;
678 DCHECK(CanNotifyDemuxerReady()); 675 DCHECK(CanNotifyDemuxerReady());
679 676
680 scoped_ptr<MediaPlayerHostMsg_DemuxerReady_Params> params( 677 scoped_ptr<DemuxerConfigs> configs(new DemuxerConfigs());
681 new MediaPlayerHostMsg_DemuxerReady_Params());
682 if (audio_stream_) { 678 if (audio_stream_) {
683 media::AudioDecoderConfig config = audio_stream_->audio_decoder_config(); 679 media::AudioDecoderConfig config = audio_stream_->audio_decoder_config();
684 params->audio_codec = config.codec(); 680 configs->audio_codec = config.codec();
685 params->audio_channels = 681 configs->audio_channels =
686 media::ChannelLayoutToChannelCount(config.channel_layout()); 682 media::ChannelLayoutToChannelCount(config.channel_layout());
687 params->audio_sampling_rate = config.samples_per_second(); 683 configs->audio_sampling_rate = config.samples_per_second();
688 params->is_audio_encrypted = config.is_encrypted(); 684 configs->is_audio_encrypted = config.is_encrypted();
689 params->audio_extra_data = std::vector<uint8>( 685 configs->audio_extra_data = std::vector<uint8>(
690 config.extra_data(), config.extra_data() + config.extra_data_size()); 686 config.extra_data(), config.extra_data() + config.extra_data_size());
691 } 687 }
692 if (video_stream_) { 688 if (video_stream_) {
693 media::VideoDecoderConfig config = video_stream_->video_decoder_config(); 689 media::VideoDecoderConfig config = video_stream_->video_decoder_config();
694 params->video_codec = config.codec(); 690 configs->video_codec = config.codec();
695 params->video_size = config.natural_size(); 691 configs->video_size = config.natural_size();
696 params->is_video_encrypted = config.is_encrypted(); 692 configs->is_video_encrypted = config.is_encrypted();
697 params->video_extra_data = std::vector<uint8>( 693 configs->video_extra_data = std::vector<uint8>(
698 config.extra_data(), config.extra_data() + config.extra_data_size()); 694 config.extra_data(), config.extra_data() + config.extra_data_size());
699 } 695 }
700 params->duration_ms = GetDurationMs(); 696 configs->duration_ms = GetDurationMs();
701 params->key_system = HasEncryptedStream() ? key_system_ : ""; 697 configs->key_system = HasEncryptedStream() ? key_system_ : "";
702 698
703 #if defined(GOOGLE_TV) 699 #if defined(GOOGLE_TV)
704 send_demuxer_ready_cb_.Run(params.Pass()); 700 send_demuxer_ready_cb_.Run(configs.Pass());
705 #else 701 #else
706 SendDemuxerReady(params.Pass()); 702 SendDemuxerReady(configs.Pass());
707 #endif 703 #endif
708 } 704 }
709 705
710 void MediaSourceDelegate::SendDemuxerReady( 706 void MediaSourceDelegate::SendDemuxerReady(scoped_ptr<DemuxerConfigs> configs) {
711 scoped_ptr<MediaPlayerHostMsg_DemuxerReady_Params> params) {
712 DCHECK(main_loop_->BelongsToCurrentThread()); 707 DCHECK(main_loop_->BelongsToCurrentThread());
713 if (proxy_) 708 if (proxy_)
714 proxy_->DemuxerReady(player_id_, *params); 709 proxy_->DemuxerReady(player_id_, *configs);
715 } 710 }
716 711
717 int MediaSourceDelegate::GetDurationMs() { 712 int MediaSourceDelegate::GetDurationMs() {
718 DCHECK_BELONG_TO_MEDIA_LOOP(); 713 DCHECK_BELONG_TO_MEDIA_LOOP();
719 if (!chunk_demuxer_) 714 if (!chunk_demuxer_)
720 return -1; 715 return -1;
721 716
722 double duration_ms = chunk_demuxer_->GetDuration() * 1000; 717 double duration_ms = chunk_demuxer_->GetDuration() * 1000;
723 if (duration_ms > std::numeric_limits<int32>::max()) { 718 if (duration_ms > std::numeric_limits<int32>::max()) {
724 LOG(WARNING) << "Duration from ChunkDemuxer is too large; probably " 719 LOG(WARNING) << "Duration from ChunkDemuxer is too large; probably "
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 base::AutoLock auto_lock(seeking_lock_); 761 base::AutoLock auto_lock(seeking_lock_);
767 seeking_ = seeking; 762 seeking_ = seeking;
768 } 763 }
769 764
770 bool MediaSourceDelegate::IsSeeking() const { 765 bool MediaSourceDelegate::IsSeeking() const {
771 base::AutoLock auto_lock(seeking_lock_); 766 base::AutoLock auto_lock(seeking_lock_);
772 return seeking_; 767 return seeking_;
773 } 768 }
774 769
775 } // namespace content 770 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/media_source_delegate.h ('k') | content/renderer/media/android/webmediaplayer_proxy_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698