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

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

Issue 23545029: EME: Handle NO_KEY and resume playback after key is added. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only 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 <limits>
8 #include <string>
9 #include <vector>
10
7 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
8 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
9 #include "content/renderer/media/android/webmediaplayer_proxy_android.h" 13 #include "content/renderer/media/android/webmediaplayer_proxy_android.h"
10 #include "content/renderer/media/webmediaplayer_util.h" 14 #include "content/renderer/media/webmediaplayer_util.h"
11 #include "content/renderer/media/webmediasource_impl.h" 15 #include "content/renderer/media/webmediasource_impl.h"
12 #include "media/base/android/demuxer_stream_player_params.h" 16 #include "media/base/android/demuxer_stream_player_params.h"
13 #include "media/base/bind_to_loop.h" 17 #include "media/base/bind_to_loop.h"
14 #include "media/base/demuxer_stream.h" 18 #include "media/base/demuxer_stream.h"
15 #include "media/base/media_log.h" 19 #include "media/base/media_log.h"
16 #include "media/filters/chunk_demuxer.h" 20 #include "media/filters/chunk_demuxer.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #endif 80 #endif
77 proxy_(proxy), 81 proxy_(proxy),
78 player_id_(player_id), 82 player_id_(player_id),
79 media_log_(media_log), 83 media_log_(media_log),
80 demuxer_(NULL), 84 demuxer_(NULL),
81 is_demuxer_ready_(false), 85 is_demuxer_ready_(false),
82 audio_stream_(NULL), 86 audio_stream_(NULL),
83 video_stream_(NULL), 87 video_stream_(NULL),
84 seeking_(false), 88 seeking_(false),
85 last_seek_request_id_(0), 89 last_seek_request_id_(0),
90 #if defined(GOOGLE_TV)
86 key_added_(false), 91 key_added_(false),
92 #endif
87 access_unit_size_(0) { 93 access_unit_size_(0) {
88 } 94 }
89 95
90 MediaSourceDelegate::~MediaSourceDelegate() { 96 MediaSourceDelegate::~MediaSourceDelegate() {
91 DCHECK(main_loop_->BelongsToCurrentThread()); 97 DCHECK(main_loop_->BelongsToCurrentThread());
92 DVLOG(1) << "~MediaSourceDelegate() : " << player_id_; 98 DVLOG(1) << "~MediaSourceDelegate() : " << player_id_;
93 DCHECK(!chunk_demuxer_); 99 DCHECK(!chunk_demuxer_);
94 DCHECK(!demuxer_); 100 DCHECK(!demuxer_);
95 DCHECK(!audio_decrypting_demuxer_stream_); 101 DCHECK(!audio_decrypting_demuxer_stream_);
96 DCHECK(!video_decrypting_demuxer_stream_); 102 DCHECK(!video_decrypting_demuxer_stream_);
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 media_loop_->PostTask(FROM_HERE, 631 media_loop_->PostTask(FROM_HERE,
626 base::Bind(&MediaSourceDelegate::OnMediaConfigRequest, 632 base::Bind(&MediaSourceDelegate::OnMediaConfigRequest,
627 base::Unretained(this))); 633 base::Unretained(this)));
628 return; 634 return;
629 } 635 }
630 #endif 636 #endif
631 if (CanNotifyDemuxerReady()) 637 if (CanNotifyDemuxerReady())
632 NotifyDemuxerReady(); 638 NotifyDemuxerReady();
633 } 639 }
634 640
641 #if defined(GOOGLE_TV)
642 // TODO(kjyoun): Enhance logic to detect when to call NotifyDemuxerReady()
643 // For now, we call it when the first key is added. See http://crbug.com/255781
635 void MediaSourceDelegate::NotifyKeyAdded(const std::string& key_system) { 644 void MediaSourceDelegate::NotifyKeyAdded(const std::string& key_system) {
636 #if defined(GOOGLE_TV)
637 if (!media_loop_->BelongsToCurrentThread()) { 645 if (!media_loop_->BelongsToCurrentThread()) {
638 media_loop_->PostTask(FROM_HERE, 646 media_loop_->PostTask(FROM_HERE,
639 base::Bind(&MediaSourceDelegate::NotifyKeyAdded, 647 base::Bind(&MediaSourceDelegate::NotifyKeyAdded,
640 base::Unretained(this), key_system)); 648 base::Unretained(this), key_system));
641 return; 649 return;
642 } 650 }
643 #endif
644 DVLOG(1) << "NotifyKeyAdded() : " << player_id_; 651 DVLOG(1) << "NotifyKeyAdded() : " << player_id_;
645 // TODO(kjyoun): Enhance logic to detect when to call NotifyDemuxerReady()
646 // For now, we calls it when the first key is added. See
647 // http://crbug.com/255781
648 if (key_added_) 652 if (key_added_)
649 return; 653 return;
650 key_added_ = true; 654 key_added_ = true;
651 key_system_ = key_system; 655 key_system_ = key_system;
652 if (!CanNotifyDemuxerReady()) 656 if (!CanNotifyDemuxerReady())
653 return; 657 return;
654 if (HasEncryptedStream()) 658 if (HasEncryptedStream())
655 NotifyDemuxerReady(); 659 NotifyDemuxerReady();
656 } 660 }
661 #endif // defined(GOOGLE_TV)
657 662
658 bool MediaSourceDelegate::CanNotifyDemuxerReady() { 663 bool MediaSourceDelegate::CanNotifyDemuxerReady() {
659 DCHECK_BELONG_TO_MEDIA_LOOP(); 664 DCHECK_BELONG_TO_MEDIA_LOOP();
660 // This can happen when a key is added before the demuxer is initialized. 665 // This can happen when a key is added before the demuxer is initialized.
661 // See NotifyKeyAdded(). 666 // See NotifyKeyAdded().
662 // TODO(kjyoun): Remove NotifyDemxuerReady() call from NotifyKeyAdded() so 667 // TODO(kjyoun): Remove NotifyDemxuerReady() call from NotifyKeyAdded() so
663 // that we can remove all is_demuxer_ready_/key_added_/key_system_ madness. 668 // that we can remove all is_demuxer_ready_/key_added_/key_system_ madness.
664 // See http://crbug.com/255781 669 // See http://crbug.com/255781
665 if (!is_demuxer_ready_) 670 if (!is_demuxer_ready_)
666 return false; 671 return false;
672 #if defined(GOOGLE_TV)
667 if (HasEncryptedStream() && !key_added_) 673 if (HasEncryptedStream() && !key_added_)
668 return false; 674 return false;
675 #endif // defined(GOOGLE_TV)
669 return true; 676 return true;
670 } 677 }
671 678
672 void MediaSourceDelegate::NotifyDemuxerReady() { 679 void MediaSourceDelegate::NotifyDemuxerReady() {
673 DCHECK_BELONG_TO_MEDIA_LOOP(); 680 DCHECK_BELONG_TO_MEDIA_LOOP();
674 DVLOG(1) << "NotifyDemuxerReady() : " << player_id_; 681 DVLOG(1) << "NotifyDemuxerReady() : " << player_id_;
675 DCHECK(CanNotifyDemuxerReady()); 682 DCHECK(CanNotifyDemuxerReady());
676 683
677 scoped_ptr<DemuxerConfigs> configs(new DemuxerConfigs()); 684 scoped_ptr<DemuxerConfigs> configs(new DemuxerConfigs());
678 if (audio_stream_) { 685 if (audio_stream_) {
679 media::AudioDecoderConfig config = audio_stream_->audio_decoder_config(); 686 media::AudioDecoderConfig config = audio_stream_->audio_decoder_config();
680 configs->audio_codec = config.codec(); 687 configs->audio_codec = config.codec();
681 configs->audio_channels = 688 configs->audio_channels =
682 media::ChannelLayoutToChannelCount(config.channel_layout()); 689 media::ChannelLayoutToChannelCount(config.channel_layout());
683 configs->audio_sampling_rate = config.samples_per_second(); 690 configs->audio_sampling_rate = config.samples_per_second();
684 configs->is_audio_encrypted = config.is_encrypted(); 691 configs->is_audio_encrypted = config.is_encrypted();
685 configs->audio_extra_data = std::vector<uint8>( 692 configs->audio_extra_data = std::vector<uint8>(
686 config.extra_data(), config.extra_data() + config.extra_data_size()); 693 config.extra_data(), config.extra_data() + config.extra_data_size());
687 } 694 }
688 if (video_stream_) { 695 if (video_stream_) {
689 media::VideoDecoderConfig config = video_stream_->video_decoder_config(); 696 media::VideoDecoderConfig config = video_stream_->video_decoder_config();
690 configs->video_codec = config.codec(); 697 configs->video_codec = config.codec();
691 configs->video_size = config.natural_size(); 698 configs->video_size = config.natural_size();
692 configs->is_video_encrypted = config.is_encrypted(); 699 configs->is_video_encrypted = config.is_encrypted();
693 configs->video_extra_data = std::vector<uint8>( 700 configs->video_extra_data = std::vector<uint8>(
694 config.extra_data(), config.extra_data() + config.extra_data_size()); 701 config.extra_data(), config.extra_data() + config.extra_data_size());
695 } 702 }
696 configs->duration_ms = GetDurationMs(); 703 configs->duration_ms = GetDurationMs();
697 configs->key_system = HasEncryptedStream() ? key_system_ : "";
698 704
699 #if defined(GOOGLE_TV) 705 #if defined(GOOGLE_TV)
706 configs->key_system = HasEncryptedStream() ? key_system_ : "";
700 send_demuxer_ready_cb_.Run(configs.Pass()); 707 send_demuxer_ready_cb_.Run(configs.Pass());
701 #else 708 #else
702 SendDemuxerReady(configs.Pass()); 709 SendDemuxerReady(configs.Pass());
703 #endif 710 #endif
704 } 711 }
705 712
706 void MediaSourceDelegate::SendDemuxerReady(scoped_ptr<DemuxerConfigs> configs) { 713 void MediaSourceDelegate::SendDemuxerReady(scoped_ptr<DemuxerConfigs> configs) {
707 DCHECK(main_loop_->BelongsToCurrentThread()); 714 DCHECK(main_loop_->BelongsToCurrentThread());
708 if (proxy_) 715 if (proxy_)
709 proxy_->DemuxerReady(player_id_, *configs); 716 proxy_->DemuxerReady(player_id_, *configs);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 base::AutoLock auto_lock(seeking_lock_); 768 base::AutoLock auto_lock(seeking_lock_);
762 seeking_ = seeking; 769 seeking_ = seeking;
763 } 770 }
764 771
765 bool MediaSourceDelegate::IsSeeking() const { 772 bool MediaSourceDelegate::IsSeeking() const {
766 base::AutoLock auto_lock(seeking_lock_); 773 base::AutoLock auto_lock(seeking_lock_);
767 return seeking_; 774 return seeking_;
768 } 775 }
769 776
770 } // namespace content 777 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/media_source_delegate.h ('k') | content/renderer/media/android/webmediaplayer_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698