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

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: minor changes 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
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/Source/WebKit/chromium/public/WebMediaSource.h" 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 44 #include "third_party/WebKit/Source/WebKit/chromium/public/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;
(...skipping 15 matching lines...) Expand all
933 static_cast<int>(media::MediaKeys::k ## name ## Error), \ 935 static_cast<int>(media::MediaKeys::k ## name ## Error), \
934 mismatching_enums) 936 mismatching_enums)
935 COMPILE_ASSERT_MATCHING_ENUM(Unknown); 937 COMPILE_ASSERT_MATCHING_ENUM(Unknown);
936 COMPILE_ASSERT_MATCHING_ENUM(Client); 938 COMPILE_ASSERT_MATCHING_ENUM(Client);
937 COMPILE_ASSERT_MATCHING_ENUM(Service); 939 COMPILE_ASSERT_MATCHING_ENUM(Service);
938 COMPILE_ASSERT_MATCHING_ENUM(Output); 940 COMPILE_ASSERT_MATCHING_ENUM(Output);
939 COMPILE_ASSERT_MATCHING_ENUM(HardwareChange); 941 COMPILE_ASSERT_MATCHING_ENUM(HardwareChange);
940 COMPILE_ASSERT_MATCHING_ENUM(Domain); 942 COMPILE_ASSERT_MATCHING_ENUM(Domain);
941 #undef COMPILE_ASSERT_MATCHING_ENUM 943 #undef COMPILE_ASSERT_MATCHING_ENUM
942 944
943 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system, 945 void WebMediaPlayerImpl::OnKeyError(const std::string& session_id,
944 const std::string& session_id,
945 media::MediaKeys::KeyError error_code, 946 media::MediaKeys::KeyError error_code,
946 int system_code) { 947 int system_code) {
947 DCHECK(main_loop_->BelongsToCurrentThread()); 948 DCHECK(main_loop_->BelongsToCurrentThread());
948 949
949 EmeUMAHistogramEnumeration( 950 EmeUMAHistogramEnumeration(
950 key_system, "KeyError", error_code, media::MediaKeys::kMaxKeyError); 951 current_key_system_.utf8(), "KeyError",
952 error_code, media::MediaKeys::kMaxKeyError);
951 953
952 GetClient()->keyError( 954 GetClient()->keyError(
953 WebString::fromUTF8(key_system), 955 current_key_system_,
954 WebString::fromUTF8(session_id), 956 WebString::fromUTF8(session_id),
955 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), 957 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
956 system_code); 958 system_code);
957 } 959 }
958 960
959 void WebMediaPlayerImpl::OnKeyMessage(const std::string& key_system, 961 void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id,
960 const std::string& session_id,
961 const std::string& message, 962 const std::string& message,
962 const std::string& default_url) { 963 const std::string& default_url) {
963 DCHECK(main_loop_->BelongsToCurrentThread()); 964 DCHECK(main_loop_->BelongsToCurrentThread());
964 965
965 const GURL default_url_gurl(default_url); 966 const GURL default_url_gurl(default_url);
966 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid()) 967 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid())
967 << "Invalid URL in default_url: " << default_url; 968 << "Invalid URL in default_url: " << default_url;
968 969
969 GetClient()->keyMessage(WebString::fromUTF8(key_system), 970 GetClient()->keyMessage(current_key_system_,
970 WebString::fromUTF8(session_id), 971 WebString::fromUTF8(session_id),
971 reinterpret_cast<const uint8*>(message.data()), 972 reinterpret_cast<const uint8*>(message.data()),
972 message.size(), 973 message.size(),
973 default_url_gurl); 974 default_url_gurl);
974 } 975 }
975 976
976 void WebMediaPlayerImpl::SetOpaque(bool opaque) { 977 void WebMediaPlayerImpl::SetOpaque(bool opaque) {
977 DCHECK(main_loop_->BelongsToCurrentThread()); 978 DCHECK(main_loop_->BelongsToCurrentThread());
978 979
979 GetClient()->setOpaque(opaque); 980 GetClient()->setOpaque(opaque);
(...skipping 29 matching lines...) Expand all
1009 // Keep track if this is a MSE or non-MSE playback. 1010 // Keep track if this is a MSE or non-MSE playback.
1010 UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", (media_source != NULL)); 1011 UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", (media_source != NULL));
1011 1012
1012 // Figure out which demuxer to use. 1013 // Figure out which demuxer to use.
1013 if (!media_source) { 1014 if (!media_source) {
1014 DCHECK(!chunk_demuxer_); 1015 DCHECK(!chunk_demuxer_);
1015 DCHECK(data_source_); 1016 DCHECK(data_source_);
1016 1017
1017 demuxer_.reset(new media::FFmpegDemuxer( 1018 demuxer_.reset(new media::FFmpegDemuxer(
1018 media_loop_, data_source_.get(), 1019 media_loop_, data_source_.get(),
1019 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", ""))); 1020 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnNeedKey, "")));
1020 } else { 1021 } else {
1021 DCHECK(!chunk_demuxer_); 1022 DCHECK(!chunk_demuxer_);
1022 DCHECK(!data_source_); 1023 DCHECK(!data_source_);
1023 1024
1024 scoped_ptr<WebKit::WebMediaSource> ms(media_source); 1025 scoped_ptr<WebKit::WebMediaSource> ms(media_source);
1025 chunk_demuxer_ = new media::ChunkDemuxer( 1026 chunk_demuxer_ = new media::ChunkDemuxer(
1026 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnDemuxerOpened, 1027 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnDemuxerOpened,
1027 base::Passed(&ms)), 1028 base::Passed(&ms)),
1028 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", ""), 1029 BIND_TO_RENDER_LOOP_1(&WebMediaPlayerImpl::OnNeedKey, ""),
1029 base::Bind(&WebMediaPlayerImpl::OnTextTrack, base::Unretained(this)), 1030 base::Bind(&WebMediaPlayerImpl::OnTextTrack, base::Unretained(this)),
1030 base::Bind(&LogMediaSourceError, media_log_)); 1031 base::Bind(&LogMediaSourceError, media_log_));
1031 demuxer_.reset(chunk_demuxer_); 1032 demuxer_.reset(chunk_demuxer_);
1032 1033
1033 // Disable GpuVideoDecoder creation until it supports codec config changes. 1034 // Disable GpuVideoDecoder creation until it supports codec config changes.
1034 // TODO(acolwell): Remove this once http://crbug.com/151045 is fixed. 1035 // TODO(acolwell): Remove this once http://crbug.com/151045 is fixed.
1035 gpu_factories_ = NULL; 1036 gpu_factories_ = NULL;
1036 1037
1037 // Disable preroll increases on underflow since the web application has no 1038 // Disable preroll increases on underflow since the web application has no
1038 // way to detect that this is happening and runs the risk of triggering 1039 // 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
1209 1210
1210 if (pending_repaint_) 1211 if (pending_repaint_)
1211 return; 1212 return;
1212 1213
1213 pending_repaint_ = true; 1214 pending_repaint_ = true;
1214 main_loop_->PostTask(FROM_HERE, base::Bind( 1215 main_loop_->PostTask(FROM_HERE, base::Bind(
1215 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); 1216 &WebMediaPlayerImpl::Repaint, AsWeakPtr()));
1216 } 1217 }
1217 1218
1218 } // namespace webkit_media 1219 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698