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

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

Issue 10575026: Add ProxyDecryptor which wraps concrete Decryptor implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add CreateDecryptor in key_system.* Created 8 years, 5 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 (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 "webkit/media/webmediaplayer_impl.h" 5 #include "webkit/media/webmediaplayer_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "media/audio/null_audio_sink.h" 18 #include "media/audio/null_audio_sink.h"
19 #include "media/base/filter_collection.h" 19 #include "media/base/filter_collection.h"
20 #include "media/base/limits.h" 20 #include "media/base/limits.h"
21 #include "media/base/media_log.h" 21 #include "media/base/media_log.h"
22 #include "media/base/media_switches.h" 22 #include "media/base/media_switches.h"
23 #include "media/base/pipeline.h" 23 #include "media/base/pipeline.h"
24 #include "media/base/video_frame.h" 24 #include "media/base/video_frame.h"
25 #include "media/crypto/aes_decryptor.h"
26 #include "media/filters/audio_renderer_impl.h" 25 #include "media/filters/audio_renderer_impl.h"
27 #include "media/filters/video_renderer_base.h" 26 #include "media/filters/video_renderer_base.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
34 #include "v8/include/v8.h" 33 #include "v8/include/v8.h"
35 #include "webkit/media/buffered_data_source.h" 34 #include "webkit/media/buffered_data_source.h"
35 #include "webkit/media/crypto/key_systems.h"
36 #include "webkit/media/crypto/proxy_decryptor.h"
36 #include "webkit/media/filter_helpers.h" 37 #include "webkit/media/filter_helpers.h"
37 #include "webkit/media/key_systems.h"
38 #include "webkit/media/webmediaplayer_delegate.h" 38 #include "webkit/media/webmediaplayer_delegate.h"
39 #include "webkit/media/webmediaplayer_proxy.h" 39 #include "webkit/media/webmediaplayer_proxy.h"
40 #include "webkit/media/webmediaplayer_util.h" 40 #include "webkit/media/webmediaplayer_util.h"
41 #include "webkit/media/webvideoframe_impl.h" 41 #include "webkit/media/webvideoframe_impl.h"
42 42
43 using WebKit::WebCanvas; 43 using WebKit::WebCanvas;
44 using WebKit::WebMediaPlayer; 44 using WebKit::WebMediaPlayer;
45 using WebKit::WebRect; 45 using WebKit::WebRect;
46 using WebKit::WebSize; 46 using WebKit::WebSize;
47 using WebKit::WebString; 47 using WebKit::WebString;
(...skipping 27 matching lines...) Expand all
75 // Also our timers are not very accurate (especially for ogg), which becomes 75 // Also our timers are not very accurate (especially for ogg), which becomes
76 // evident at low speeds and on Vista. Since other speeds are risky and outside 76 // evident at low speeds and on Vista. Since other speeds are risky and outside
77 // the norms, we think 1/16x to 16x is a safe and useful range for now. 77 // the norms, we think 1/16x to 16x is a safe and useful range for now.
78 const float kMinRate = 0.0625f; 78 const float kMinRate = 0.0625f;
79 const float kMaxRate = 16.0f; 79 const float kMaxRate = 16.0f;
80 80
81 } // namespace 81 } // namespace
82 82
83 namespace webkit_media { 83 namespace webkit_media {
84 84
85 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ 85 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
86 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::CORSMode ## name) == \ 86 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::CORSMode ## name) == \
87 static_cast<int>(BufferedResourceLoader::k ## name), \ 87 static_cast<int>(BufferedResourceLoader::k ## name), \
88 mismatching_enums) 88 mismatching_enums)
89 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); 89 COMPILE_ASSERT_MATCHING_ENUM(Unspecified);
90 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); 90 COMPILE_ASSERT_MATCHING_ENUM(Anonymous);
91 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); 91 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials);
92 #undef COMPILE_ASSERT_MATCHING_ENUM 92 #undef COMPILE_ASSERT_MATCHING_ENUM
93 93
94 WebMediaPlayerImpl::WebMediaPlayerImpl( 94 WebMediaPlayerImpl::WebMediaPlayerImpl(
95 WebKit::WebFrame* frame, 95 WebKit::WebFrame* frame,
96 WebKit::WebMediaPlayerClient* client, 96 WebKit::WebMediaPlayerClient* client,
97 base::WeakPtr<WebMediaPlayerDelegate> delegate, 97 base::WeakPtr<WebMediaPlayerDelegate> delegate,
(...skipping 15 matching lines...) Expand all
113 pending_seek_(false), 113 pending_seek_(false),
114 pending_seek_seconds_(0.0f), 114 pending_seek_seconds_(0.0f),
115 client_(client), 115 client_(client),
116 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)), 116 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)),
117 delegate_(delegate), 117 delegate_(delegate),
118 media_stream_client_(media_stream_client), 118 media_stream_client_(media_stream_client),
119 media_log_(media_log), 119 media_log_(media_log),
120 accelerated_compositing_reported_(false), 120 accelerated_compositing_reported_(false),
121 incremented_externally_allocated_memory_(false), 121 incremented_externally_allocated_memory_(false),
122 audio_source_provider_(audio_source_provider), 122 audio_source_provider_(audio_source_provider),
123 is_local_source_(false) { 123 is_local_source_(false),
124 decryptor_(new ProxyDecryptor(proxy_.get())) {
124 media_log_->AddEvent( 125 media_log_->AddEvent(
125 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 126 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
126 127
127 MessageLoop* pipeline_message_loop = 128 MessageLoop* pipeline_message_loop =
128 message_loop_factory_->GetMessageLoop("PipelineThread"); 129 message_loop_factory_->GetMessageLoop("PipelineThread");
129 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_); 130 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_);
130 131
131 // Let V8 know we started new thread if we did not did it yet. 132 // Let V8 know we started new thread if we did not did it yet.
132 // Made separate task to avoid deletion of player currently being created. 133 // Made separate task to avoid deletion of player currently being created.
133 // Also, delaying GC until after player starts gets rid of starting lag -- 134 // Also, delaying GC until after player starts gets rid of starting lag --
(...skipping 13 matching lines...) Expand all
147 new media::VideoRendererBase( 148 new media::VideoRendererBase(
148 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), 149 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_),
149 base::Bind(&WebMediaPlayerProxy::SetOpaque, proxy_.get()), 150 base::Bind(&WebMediaPlayerProxy::SetOpaque, proxy_.get()),
150 true); 151 true);
151 filter_collection_->AddVideoRenderer(video_renderer); 152 filter_collection_->AddVideoRenderer(video_renderer);
152 proxy_->set_frame_provider(video_renderer); 153 proxy_->set_frame_provider(video_renderer);
153 154
154 // Create default audio renderer. 155 // Create default audio renderer.
155 filter_collection_->AddAudioRenderer( 156 filter_collection_->AddAudioRenderer(
156 new media::AudioRendererImpl(new media::NullAudioSink())); 157 new media::AudioRendererImpl(new media::NullAudioSink()));
157
158 decryptor_.reset(new media::AesDecryptor(proxy_.get()));
159 } 158 }
160 159
161 WebMediaPlayerImpl::~WebMediaPlayerImpl() { 160 WebMediaPlayerImpl::~WebMediaPlayerImpl() {
162 DCHECK_EQ(main_loop_, MessageLoop::current()); 161 DCHECK_EQ(main_loop_, MessageLoop::current());
163 Destroy(); 162 Destroy();
164 media_log_->AddEvent( 163 media_log_->AddEvent(
165 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); 164 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
166 165
167 if (delegate_) 166 if (delegate_)
168 delegate_->PlayerGone(this); 167 delegate_->PlayerGone(this);
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 proxy_->DemuxerEndOfStream(pipeline_status); 706 proxy_->DemuxerEndOfStream(pipeline_status);
708 } 707 }
709 708
710 WebKit::WebMediaPlayer::MediaKeyException 709 WebKit::WebMediaPlayer::MediaKeyException
711 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, 710 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system,
712 const unsigned char* init_data, 711 const unsigned char* init_data,
713 unsigned init_data_length) { 712 unsigned init_data_length) {
714 if (!IsSupportedKeySystem(key_system)) 713 if (!IsSupportedKeySystem(key_system))
715 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 714 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
716 715
716 // We do not support run-time switching between key systems for now.
717 if (current_key_system_.isEmpty())
718 current_key_system_ = key_system;
719 else if (key_system != current_key_system_)
720 return WebKit::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
721
717 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " 722 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
718 << std::string(reinterpret_cast<const char*>(init_data), 723 << std::string(reinterpret_cast<const char*>(init_data),
719 static_cast<size_t>(init_data_length)); 724 static_cast<size_t>(init_data_length));
720 725
721 decryptor_->GenerateKeyRequest(key_system.utf8(), 726 decryptor_->GenerateKeyRequest(key_system.utf8(),
722 init_data, init_data_length); 727 init_data, init_data_length);
723 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; 728 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
724 } 729 }
725 730
726 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( 731 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
727 const WebString& key_system, 732 const WebString& key_system,
728 const unsigned char* key, 733 const unsigned char* key,
729 unsigned key_length, 734 unsigned key_length,
730 const unsigned char* init_data, 735 const unsigned char* init_data,
731 unsigned init_data_length, 736 unsigned init_data_length,
732 const WebString& session_id) { 737 const WebString& session_id) {
733 DCHECK(key); 738 DCHECK(key);
734 DCHECK_GT(key_length, 0u); 739 DCHECK_GT(key_length, 0u);
735 740
736 if (!IsSupportedKeySystem(key_system)) 741 if (!IsSupportedKeySystem(key_system))
737 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 742 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
738 743
744 if (current_key_system_.isEmpty() || key_system != current_key_system_)
745 return WebKit::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
746
739 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " 747 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": "
740 << std::string(reinterpret_cast<const char*>(key), 748 << std::string(reinterpret_cast<const char*>(key),
741 static_cast<size_t>(key_length)) << ", " 749 static_cast<size_t>(key_length)) << ", "
742 << std::string(reinterpret_cast<const char*>(init_data), 750 << std::string(reinterpret_cast<const char*>(init_data),
743 static_cast<size_t>(init_data_length)) 751 static_cast<size_t>(init_data_length))
744 << " [" << session_id.utf8().data() << "]"; 752 << " [" << session_id.utf8().data() << "]";
745 753
746 decryptor_->AddKey(key_system.utf8(), key, key_length, 754 decryptor_->AddKey(key_system.utf8(), key, key_length,
747 init_data, init_data_length, session_id.utf8()); 755 init_data, init_data_length, session_id.utf8());
748 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; 756 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
749 } 757 }
750 758
751 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( 759 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
752 const WebString& key_system, 760 const WebString& key_system,
753 const WebString& session_id) { 761 const WebString& session_id) {
754 if (!IsSupportedKeySystem(key_system)) 762 if (!IsSupportedKeySystem(key_system))
755 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 763 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
756 764
765 if (current_key_system_.isEmpty() || key_system != current_key_system_)
766 return WebKit::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
767
757 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); 768 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8());
758 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; 769 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
759 } 770 }
760 771
761 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { 772 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
762 Destroy(); 773 Destroy();
763 main_loop_ = NULL; 774 main_loop_ = NULL;
764 } 775 }
765 776
766 void WebMediaPlayerImpl::Repaint() { 777 void WebMediaPlayerImpl::Repaint() {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 scoped_array<uint8> init_data, 895 scoped_array<uint8> init_data,
885 int init_data_size) { 896 int init_data_size) {
886 DCHECK_EQ(main_loop_, MessageLoop::current()); 897 DCHECK_EQ(main_loop_, MessageLoop::current());
887 898
888 GetClient()->keyNeeded(WebString::fromUTF8(key_system), 899 GetClient()->keyNeeded(WebString::fromUTF8(key_system),
889 WebString::fromUTF8(session_id), 900 WebString::fromUTF8(session_id),
890 init_data.get(), 901 init_data.get(),
891 init_data_size); 902 init_data_size);
892 } 903 }
893 904
905 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
906 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayerClient::name) == \
907 static_cast<int>(media::Decryptor::k ## name), \
908 mismatching_enums)
909 COMPILE_ASSERT_MATCHING_ENUM(UnknownError);
910 COMPILE_ASSERT_MATCHING_ENUM(ClientError);
911 COMPILE_ASSERT_MATCHING_ENUM(ServiceError);
912 COMPILE_ASSERT_MATCHING_ENUM(OutputError);
913 COMPILE_ASSERT_MATCHING_ENUM(HardwareChangeError);
914 COMPILE_ASSERT_MATCHING_ENUM(DomainError);
915 #undef COMPILE_ASSERT_MATCHING_ENUM
916
894 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system, 917 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system,
895 const std::string& session_id, 918 const std::string& session_id,
896 media::Decryptor::KeyError error_code, 919 media::Decryptor::KeyError error_code,
897 int system_code) { 920 int system_code) {
898 DCHECK_EQ(main_loop_, MessageLoop::current()); 921 DCHECK_EQ(main_loop_, MessageLoop::current());
899 922
900 GetClient()->keyError( 923 GetClient()->keyError(
901 WebString::fromUTF8(key_system), 924 WebString::fromUTF8(key_system),
902 WebString::fromUTF8(session_id), 925 WebString::fromUTF8(session_id),
903 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), 926 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 return audio_source_provider_; 1044 return audio_source_provider_;
1022 } 1045 }
1023 1046
1024 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1047 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1025 DCHECK_EQ(main_loop_, MessageLoop::current()); 1048 DCHECK_EQ(main_loop_, MessageLoop::current());
1026 incremented_externally_allocated_memory_ = true; 1049 incremented_externally_allocated_memory_ = true;
1027 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1050 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1028 } 1051 }
1029 1052
1030 } // namespace webkit_media 1053 } // namespace webkit_media
OLDNEW
« webkit/media/webmediaplayer_impl.h ('K') | « webkit/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698