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

Side by Side Diff: webkit/renderer/media/webmediaplayer_impl.cc

Issue 17289006: Separate CDM initialization from GenerateKeyRequest & remove key_system parameters. (Closed) Base URL: master
Patch Set: rebase only Created 7 years, 6 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
« no previous file with comments | « webkit/renderer/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/renderer/media/webmediaplayer_impl.h" 5 #include "webkit/renderer/media/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 28 matching lines...) Expand all
39 #include "third_party/WebKit/public/platform/WebSize.h" 39 #include "third_party/WebKit/public/platform/WebSize.h"
40 #include "third_party/WebKit/public/platform/WebString.h" 40 #include "third_party/WebKit/public/platform/WebString.h"
41 #include "third_party/WebKit/public/platform/WebURL.h" 41 #include "third_party/WebKit/public/platform/WebURL.h"
42 #include "third_party/WebKit/public/web/WebMediaSource.h" 42 #include "third_party/WebKit/public/web/WebMediaSource.h"
43 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 43 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
44 #include "third_party/WebKit/public/web/WebView.h" 44 #include "third_party/WebKit/public/web/WebView.h"
45 #include "v8/include/v8.h" 45 #include "v8/include/v8.h"
46 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" 46 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
47 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" 47 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
48 #include "webkit/renderer/media/buffered_data_source.h" 48 #include "webkit/renderer/media/buffered_data_source.h"
49 #include "webkit/renderer/media/crypto/key_systems.h"
49 #include "webkit/renderer/media/texttrack_impl.h" 50 #include "webkit/renderer/media/texttrack_impl.h"
50 #include "webkit/renderer/media/webaudiosourceprovider_impl.h" 51 #include "webkit/renderer/media/webaudiosourceprovider_impl.h"
51 #include "webkit/renderer/media/webinbandtexttrack_impl.h" 52 #include "webkit/renderer/media/webinbandtexttrack_impl.h"
52 #include "webkit/renderer/media/webmediaplayer_delegate.h" 53 #include "webkit/renderer/media/webmediaplayer_delegate.h"
53 #include "webkit/renderer/media/webmediaplayer_params.h" 54 #include "webkit/renderer/media/webmediaplayer_params.h"
54 #include "webkit/renderer/media/webmediaplayer_util.h" 55 #include "webkit/renderer/media/webmediaplayer_util.h"
55 #include "webkit/renderer/media/webmediasourceclient_impl.h" 56 #include "webkit/renderer/media/webmediasourceclient_impl.h"
56 57
57 using WebKit::WebCanvas; 58 using WebKit::WebCanvas;
58 using WebKit::WebMediaPlayer; 59 using WebKit::WebMediaPlayer;
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 GenerateKeyRequestInternal(key_system, init_data, init_data_length); 684 GenerateKeyRequestInternal(key_system, init_data, init_data_length);
684 ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e); 685 ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e);
685 return e; 686 return e;
686 } 687 }
687 688
688 WebMediaPlayer::MediaKeyException 689 WebMediaPlayer::MediaKeyException
689 WebMediaPlayerImpl::GenerateKeyRequestInternal( 690 WebMediaPlayerImpl::GenerateKeyRequestInternal(
690 const WebString& key_system, 691 const WebString& key_system,
691 const unsigned char* init_data, 692 const unsigned char* init_data,
692 unsigned init_data_length) { 693 unsigned init_data_length) {
694 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
695 << std::string(reinterpret_cast<const char*>(init_data),
696 static_cast<size_t>(init_data_length));
697
693 if (!IsSupportedKeySystem(key_system)) 698 if (!IsSupportedKeySystem(key_system))
694 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 699 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
695 700
696 // We do not support run-time switching between key systems for now. 701 // We do not support run-time switching between key systems for now.
697 if (current_key_system_.isEmpty()) 702 if (current_key_system_.isEmpty()) {
703 if (!decryptor_->InitializeCDM(key_system.utf8()))
704 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
698 current_key_system_ = key_system; 705 current_key_system_ = key_system;
699 else if (key_system != current_key_system_) 706 }
707 else if (key_system != current_key_system_) {
700 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 708 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
701 709 }
702 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
703 << std::string(reinterpret_cast<const char*>(init_data),
704 static_cast<size_t>(init_data_length));
705 710
706 // TODO(xhwang): We assume all streams are from the same container (thus have 711 // TODO(xhwang): We assume all streams are from the same container (thus have
707 // the same "type") for now. In the future, the "type" should be passed down 712 // the same "type") for now. In the future, the "type" should be passed down
708 // from the application. 713 // from the application.
709 if (!decryptor_->GenerateKeyRequest(key_system.utf8(), 714 if (!decryptor_->GenerateKeyRequest(init_data_type_,
710 init_data_type_,
711 init_data, init_data_length)) { 715 init_data, init_data_length)) {
712 current_key_system_.reset(); 716 current_key_system_.reset();
713 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 717 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
714 } 718 }
715 719
716 return WebMediaPlayer::MediaKeyExceptionNoError; 720 return WebMediaPlayer::MediaKeyExceptionNoError;
717 } 721 }
718 722
719 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( 723 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
720 const WebString& key_system, 724 const WebString& key_system,
(...skipping 10 matching lines...) Expand all
731 735
732 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::AddKeyInternal( 736 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::AddKeyInternal(
733 const WebString& key_system, 737 const WebString& key_system,
734 const unsigned char* key, 738 const unsigned char* key,
735 unsigned key_length, 739 unsigned key_length,
736 const unsigned char* init_data, 740 const unsigned char* init_data,
737 unsigned init_data_length, 741 unsigned init_data_length,
738 const WebString& session_id) { 742 const WebString& session_id) {
739 DCHECK(key); 743 DCHECK(key);
740 DCHECK_GT(key_length, 0u); 744 DCHECK_GT(key_length, 0u);
741
742 if (!IsSupportedKeySystem(key_system))
743 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
744
745 if (current_key_system_.isEmpty() || key_system != current_key_system_)
746 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
747
748 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " 745 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": "
749 << std::string(reinterpret_cast<const char*>(key), 746 << std::string(reinterpret_cast<const char*>(key),
750 static_cast<size_t>(key_length)) << ", " 747 static_cast<size_t>(key_length)) << ", "
751 << std::string(reinterpret_cast<const char*>(init_data), 748 << std::string(reinterpret_cast<const char*>(init_data),
752 static_cast<size_t>(init_data_length)) 749 static_cast<size_t>(init_data_length))
753 << " [" << session_id.utf8().data() << "]"; 750 << " [" << session_id.utf8().data() << "]";
754 751
755 decryptor_->AddKey(key_system.utf8(), key, key_length, 752
753 if (!IsSupportedKeySystem(key_system))
754 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
755
756 if (current_key_system_.isEmpty() || key_system != current_key_system_)
757 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
758
759 decryptor_->AddKey(key, key_length,
756 init_data, init_data_length, session_id.utf8()); 760 init_data, init_data_length, session_id.utf8());
757 return WebMediaPlayer::MediaKeyExceptionNoError; 761 return WebMediaPlayer::MediaKeyExceptionNoError;
758 } 762 }
759 763
760 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( 764 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
761 const WebString& key_system, 765 const WebString& key_system,
762 const WebString& session_id) { 766 const WebString& session_id) {
763 WebMediaPlayer::MediaKeyException e = 767 WebMediaPlayer::MediaKeyException e =
764 CancelKeyRequestInternal(key_system, session_id); 768 CancelKeyRequestInternal(key_system, session_id);
765 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); 769 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e);
766 return e; 770 return e;
767 } 771 }
768 772
769 WebMediaPlayer::MediaKeyException 773 WebMediaPlayer::MediaKeyException
770 WebMediaPlayerImpl::CancelKeyRequestInternal( 774 WebMediaPlayerImpl::CancelKeyRequestInternal(
771 const WebString& key_system, 775 const WebString& key_system,
772 const WebString& session_id) { 776 const WebString& session_id) {
773 if (!IsSupportedKeySystem(key_system)) 777 if (!IsSupportedKeySystem(key_system))
774 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 778 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
775 779
776 if (current_key_system_.isEmpty() || key_system != current_key_system_) 780 if (current_key_system_.isEmpty() || key_system != current_key_system_)
777 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 781 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
778 782
779 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); 783 decryptor_->CancelKeyRequest(session_id.utf8());
780 return WebMediaPlayer::MediaKeyExceptionNoError; 784 return WebMediaPlayer::MediaKeyExceptionNoError;
781 } 785 }
782 786
783 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { 787 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
784 Destroy(); 788 Destroy();
785 } 789 }
786 790
787 void WebMediaPlayerImpl::Repaint() { 791 void WebMediaPlayerImpl::Repaint() {
788 DCHECK(main_loop_->BelongsToCurrentThread()); 792 DCHECK(main_loop_->BelongsToCurrentThread());
789 793
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 Repaint(); 876 Repaint();
873 } 877 }
874 878
875 void WebMediaPlayerImpl::OnDemuxerOpened( 879 void WebMediaPlayerImpl::OnDemuxerOpened(
876 scoped_ptr<WebKit::WebMediaSource> media_source) { 880 scoped_ptr<WebKit::WebMediaSource> media_source) {
877 DCHECK(main_loop_->BelongsToCurrentThread()); 881 DCHECK(main_loop_->BelongsToCurrentThread());
878 media_source->open(new WebMediaSourceClientImpl( 882 media_source->open(new WebMediaSourceClientImpl(
879 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); 883 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_)));
880 } 884 }
881 885
882 void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system, 886 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) {
883 const std::string& session_id) {
884 DCHECK(main_loop_->BelongsToCurrentThread()); 887 DCHECK(main_loop_->BelongsToCurrentThread());
885 EmeUMAHistogramCounts(key_system, "KeyAdded", 1); 888 EmeUMAHistogramCounts(current_key_system_.utf8(), "KeyAdded", 1);
886 GetClient()->keyAdded(WebString::fromUTF8(key_system), 889 GetClient()->keyAdded(current_key_system_,
887 WebString::fromUTF8(session_id)); 890 WebString::fromUTF8(session_id));
888 } 891 }
889 892
890 void WebMediaPlayerImpl::OnNeedKey(const std::string& key_system, 893 void WebMediaPlayerImpl::OnNeedKey(const std::string& session_id,
891 const std::string& session_id,
892 const std::string& type, 894 const std::string& type,
893 scoped_ptr<uint8[]> init_data, 895 scoped_ptr<uint8[]> init_data,
894 int init_data_size) { 896 int init_data_size) {
895 DCHECK(main_loop_->BelongsToCurrentThread()); 897 DCHECK(main_loop_->BelongsToCurrentThread());
896 898
897 // Do not fire NeedKey event if encrypted media is not enabled. 899 // Do not fire NeedKey event if encrypted media is not enabled.
898 if (!decryptor_) 900 if (!decryptor_)
899 return; 901 return;
900 902
901 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); 903 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1);
902 904
903 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); 905 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_);
904 if (init_data_type_.empty()) 906 if (init_data_type_.empty())
905 init_data_type_ = type; 907 init_data_type_ = type;
906 908
907 GetClient()->keyNeeded(WebString::fromUTF8(key_system), 909 GetClient()->keyNeeded(WebString(),
908 WebString::fromUTF8(session_id), 910 WebString::fromUTF8(session_id),
909 init_data.get(), 911 init_data.get(),
910 init_data_size); 912 init_data_size);
911 } 913 }
912 914
913 scoped_ptr<media::TextTrack> 915 scoped_ptr<media::TextTrack>
914 WebMediaPlayerImpl::OnTextTrack(media::TextKind kind, 916 WebMediaPlayerImpl::OnTextTrack(media::TextKind kind,
915 const std::string& label, 917 const std::string& label,
916 const std::string& language) { 918 const std::string& language) {
917 typedef WebInbandTextTrackImpl::Kind webkind_t; 919 typedef WebInbandTextTrackImpl::Kind webkind_t;
918 const webkind_t webkind = static_cast<webkind_t>(kind); 920 const webkind_t webkind = static_cast<webkind_t>(kind);
919 const WebKit::WebString weblabel = WebKit::WebString::fromUTF8(label); 921 const WebKit::WebString weblabel = WebKit::WebString::fromUTF8(label);
920 const WebKit::WebString weblanguage = WebKit::WebString::fromUTF8(language); 922 const WebKit::WebString weblanguage = WebKit::WebString::fromUTF8(language);
921 923
922 WebInbandTextTrackImpl* const text_track = 924 WebInbandTextTrackImpl* const text_track =
923 new WebInbandTextTrackImpl(webkind, weblabel, weblanguage, 925 new WebInbandTextTrackImpl(webkind, weblabel, weblanguage,
924 text_track_index_++); 926 text_track_index_++);
925 GetClient()->addTextTrack(text_track); 927 GetClient()->addTextTrack(text_track);
926 928
927 return scoped_ptr<media::TextTrack>(new TextTrackImpl(text_track)); 929 return scoped_ptr<media::TextTrack>(new TextTrackImpl(text_track));
928 } 930 }
929 931
930 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system, 932 void WebMediaPlayerImpl::OnKeyError(const std::string& session_id,
931 const std::string& session_id,
932 media::MediaKeys::KeyError error_code, 933 media::MediaKeys::KeyError error_code,
933 int system_code) { 934 int system_code) {
934 DCHECK(main_loop_->BelongsToCurrentThread()); 935 DCHECK(main_loop_->BelongsToCurrentThread());
935 936
936 EmeUMAHistogramEnumeration( 937 EmeUMAHistogramEnumeration(current_key_system_.utf8(), "KeyError",
937 key_system, "KeyError", error_code, media::MediaKeys::kMaxKeyError); 938 error_code, media::MediaKeys::kMaxKeyError);
938 939
939 GetClient()->keyError( 940 GetClient()->keyError(
940 WebString::fromUTF8(key_system), 941 current_key_system_,
941 WebString::fromUTF8(session_id), 942 WebString::fromUTF8(session_id),
942 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), 943 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
943 system_code); 944 system_code);
944 } 945 }
945 946
946 void WebMediaPlayerImpl::OnKeyMessage(const std::string& key_system, 947 void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id,
947 const std::string& session_id,
948 const std::string& message, 948 const std::string& message,
949 const std::string& default_url) { 949 const std::string& default_url) {
950 DCHECK(main_loop_->BelongsToCurrentThread()); 950 DCHECK(main_loop_->BelongsToCurrentThread());
951 951
952 const GURL default_url_gurl(default_url); 952 const GURL default_url_gurl(default_url);
953 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid()) 953 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid())
954 << "Invalid URL in default_url: " << default_url; 954 << "Invalid URL in default_url: " << default_url;
955 955
956 GetClient()->keyMessage(WebString::fromUTF8(key_system), 956 GetClient()->keyMessage(current_key_system_,
957 WebString::fromUTF8(session_id), 957 WebString::fromUTF8(session_id),
958 reinterpret_cast<const uint8*>(message.data()), 958 reinterpret_cast<const uint8*>(message.data()),
959 message.size(), 959 message.size(),
960 default_url_gurl); 960 default_url_gurl);
961 } 961 }
962 962
963 void WebMediaPlayerImpl::SetOpaque(bool opaque) { 963 void WebMediaPlayerImpl::SetOpaque(bool opaque) {
964 DCHECK(main_loop_->BelongsToCurrentThread()); 964 DCHECK(main_loop_->BelongsToCurrentThread());
965 965
966 GetClient()->setOpaque(opaque); 966 GetClient()->setOpaque(opaque);
(...skipping 29 matching lines...) Expand all
996 // Keep track if this is a MSE or non-MSE playback. 996 // Keep track if this is a MSE or non-MSE playback.
997 UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", (media_source != NULL)); 997 UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", (media_source != NULL));
998 998
999 // Figure out which demuxer to use. 999 // Figure out which demuxer to use.
1000 if (!media_source) { 1000 if (!media_source) {
1001 DCHECK(!chunk_demuxer_); 1001 DCHECK(!chunk_demuxer_);
1002 DCHECK(data_source_); 1002 DCHECK(data_source_);
1003 1003
1004 demuxer_.reset(new media::FFmpegDemuxer( 1004 demuxer_.reset(new media::FFmpegDemuxer(
1005 media_loop_, data_source_.get(), 1005 media_loop_, data_source_.get(),
1006 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", ""))); 1006 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnNeedKey, "")));
1007 } else { 1007 } else {
1008 DCHECK(!chunk_demuxer_); 1008 DCHECK(!chunk_demuxer_);
1009 DCHECK(!data_source_); 1009 DCHECK(!data_source_);
1010 1010
1011 scoped_ptr<WebKit::WebMediaSource> ms(media_source); 1011 scoped_ptr<WebKit::WebMediaSource> ms(media_source);
1012 chunk_demuxer_ = new media::ChunkDemuxer( 1012 chunk_demuxer_ = new media::ChunkDemuxer(
1013 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnDemuxerOpened, 1013 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnDemuxerOpened,
1014 base::Passed(&ms)), 1014 base::Passed(&ms)),
1015 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", ""), 1015 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnNeedKey, ""),
1016 base::Bind(&WebMediaPlayerImpl::OnTextTrack, base::Unretained(this)), 1016 base::Bind(&WebMediaPlayerImpl::OnTextTrack, base::Unretained(this)),
1017 base::Bind(&LogMediaSourceError, media_log_)); 1017 base::Bind(&LogMediaSourceError, media_log_));
1018 demuxer_.reset(chunk_demuxer_); 1018 demuxer_.reset(chunk_demuxer_);
1019 1019
1020 // Disable GpuVideoDecoder creation until it supports codec config changes. 1020 // Disable GpuVideoDecoder creation until it supports codec config changes.
1021 // TODO(acolwell): Remove this once http://crbug.com/151045 is fixed. 1021 // TODO(acolwell): Remove this once http://crbug.com/151045 is fixed.
1022 gpu_factories_ = NULL; 1022 gpu_factories_ = NULL;
1023 1023
1024 // Disable preroll increases on underflow since the web application has no 1024 // Disable preroll increases on underflow since the web application has no
1025 // way to detect that this is happening and runs the risk of triggering 1025 // way to detect that this is happening and runs the risk of triggering
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 1196
1197 if (pending_repaint_) 1197 if (pending_repaint_)
1198 return; 1198 return;
1199 1199
1200 pending_repaint_ = true; 1200 pending_repaint_ = true;
1201 main_loop_->PostTask(FROM_HERE, base::Bind( 1201 main_loop_->PostTask(FROM_HERE, base::Bind(
1202 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); 1202 &WebMediaPlayerImpl::Repaint, AsWeakPtr()));
1203 } 1203 }
1204 1204
1205 } // namespace webkit_media 1205 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/renderer/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698