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

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: Revise on comments. Created 8 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 | 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), 148 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_),
149 base::Bind(&WebMediaPlayerProxy::SetOpaque, proxy_.get()), 149 base::Bind(&WebMediaPlayerProxy::SetOpaque, proxy_.get()),
150 true); 150 true);
151 filter_collection_->AddVideoRenderer(video_renderer); 151 filter_collection_->AddVideoRenderer(video_renderer);
152 proxy_->set_frame_provider(video_renderer); 152 proxy_->set_frame_provider(video_renderer);
153 153
154 // Create default audio renderer. 154 // Create default audio renderer.
155 filter_collection_->AddAudioRenderer( 155 filter_collection_->AddAudioRenderer(
156 new media::AudioRendererImpl(new media::NullAudioSink())); 156 new media::AudioRendererImpl(new media::NullAudioSink()));
157 157
158 decryptor_.reset(new media::AesDecryptor(proxy_.get())); 158 decryptor_.reset(new ProxyDecryptor(proxy_.get()));
159 } 159 }
160 160
161 WebMediaPlayerImpl::~WebMediaPlayerImpl() { 161 WebMediaPlayerImpl::~WebMediaPlayerImpl() {
162 DCHECK_EQ(main_loop_, MessageLoop::current()); 162 DCHECK_EQ(main_loop_, MessageLoop::current());
163 Destroy(); 163 Destroy();
164 media_log_->AddEvent( 164 media_log_->AddEvent(
165 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); 165 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
166 166
167 if (delegate_) 167 if (delegate_)
168 delegate_->PlayerGone(this); 168 delegate_->PlayerGone(this);
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 proxy_->DemuxerEndOfStream(pipeline_status); 707 proxy_->DemuxerEndOfStream(pipeline_status);
708 } 708 }
709 709
710 WebKit::WebMediaPlayer::MediaKeyException 710 WebKit::WebMediaPlayer::MediaKeyException
711 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, 711 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system,
712 const unsigned char* init_data, 712 const unsigned char* init_data,
713 unsigned init_data_length) { 713 unsigned init_data_length) {
714 if (!IsSupportedKeySystem(key_system)) 714 if (!IsSupportedKeySystem(key_system))
715 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 715 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
716 716
717 // We do not support run-time switching between key systems for now.
718 if (!current_key_system_.isEmpty() && key_system != current_key_system_)
scherkus (not reviewing) 2012/06/27 01:10:18 you can move this into a helper of ProxyDecryptor
ddorwin 2012/06/27 04:00:08 Or even is_current_key_system(string) and is_key_s
xhwang 2012/06/27 21:41:26 As discussed, ProxyDecryptor will know nothing abo
719 return WebKit::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
720
717 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " 721 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
718 << std::string(reinterpret_cast<const char*>(init_data), 722 << std::string(reinterpret_cast<const char*>(init_data),
719 static_cast<size_t>(init_data_length)); 723 static_cast<size_t>(init_data_length));
720 724
725 if (current_key_system_.isEmpty())
726 current_key_system_ = key_system;
727
721 decryptor_->GenerateKeyRequest(key_system.utf8(), 728 decryptor_->GenerateKeyRequest(key_system.utf8(),
722 init_data, init_data_length); 729 init_data, init_data_length);
723 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; 730 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
724 } 731 }
725 732
726 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( 733 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
727 const WebString& key_system, 734 const WebString& key_system,
728 const unsigned char* key, 735 const unsigned char* key,
729 unsigned key_length, 736 unsigned key_length,
730 const unsigned char* init_data, 737 const unsigned char* init_data,
731 unsigned init_data_length, 738 unsigned init_data_length,
732 const WebString& session_id) { 739 const WebString& session_id) {
733 DCHECK(key); 740 DCHECK(key);
734 DCHECK_GT(key_length, 0u); 741 DCHECK_GT(key_length, 0u);
735 742
736 if (!IsSupportedKeySystem(key_system)) 743 if (!IsSupportedKeySystem(key_system))
737 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 744 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
738 745
746 if (current_key_system_.isEmpty() || key_system != current_key_system_)
747 return WebKit::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
748
739 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " 749 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": "
740 << std::string(reinterpret_cast<const char*>(key), 750 << std::string(reinterpret_cast<const char*>(key),
741 static_cast<size_t>(key_length)) << ", " 751 static_cast<size_t>(key_length)) << ", "
742 << std::string(reinterpret_cast<const char*>(init_data), 752 << std::string(reinterpret_cast<const char*>(init_data),
743 static_cast<size_t>(init_data_length)) 753 static_cast<size_t>(init_data_length))
744 << " [" << session_id.utf8().data() << "]"; 754 << " [" << session_id.utf8().data() << "]";
745 755
746 decryptor_->AddKey(key_system.utf8(), key, key_length, 756 decryptor_->AddKey(key_system.utf8(), key, key_length,
747 init_data, init_data_length, session_id.utf8()); 757 init_data, init_data_length, session_id.utf8());
748 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; 758 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
749 } 759 }
750 760
751 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( 761 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
752 const WebString& key_system, 762 const WebString& key_system,
753 const WebString& session_id) { 763 const WebString& session_id) {
754 if (!IsSupportedKeySystem(key_system)) 764 if (!IsSupportedKeySystem(key_system))
755 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 765 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
756 766
767 if (current_key_system_.isEmpty() || key_system != current_key_system_)
768 return WebKit::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
769
757 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); 770 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8());
758 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; 771 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError;
759 } 772 }
760 773
761 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { 774 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
762 Destroy(); 775 Destroy();
763 main_loop_ = NULL; 776 main_loop_ = NULL;
764 } 777 }
765 778
766 void WebMediaPlayerImpl::Repaint() { 779 void WebMediaPlayerImpl::Repaint() {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 scoped_array<uint8> init_data, 897 scoped_array<uint8> init_data,
885 int init_data_size) { 898 int init_data_size) {
886 DCHECK_EQ(main_loop_, MessageLoop::current()); 899 DCHECK_EQ(main_loop_, MessageLoop::current());
887 900
888 GetClient()->keyNeeded(WebString::fromUTF8(key_system), 901 GetClient()->keyNeeded(WebString::fromUTF8(key_system),
889 WebString::fromUTF8(session_id), 902 WebString::fromUTF8(session_id),
890 init_data.get(), 903 init_data.get(),
891 init_data_size); 904 init_data_size);
892 } 905 }
893 906
907 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
ddorwin 2012/06/27 04:00:08 Should all these be at the top of the file togethe
xhwang 2012/06/27 21:41:26 I am following the current style (at least in webk
908 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayerClient::name) == \
909 static_cast<int>(media::Decryptor::k ## name), \
910 mismatching_enums)
911 COMPILE_ASSERT_MATCHING_ENUM(UnknownError);
912 COMPILE_ASSERT_MATCHING_ENUM(ClientError);
913 COMPILE_ASSERT_MATCHING_ENUM(ServiceError);
914 COMPILE_ASSERT_MATCHING_ENUM(OutputError);
915 COMPILE_ASSERT_MATCHING_ENUM(HardwareChangeError);
916 COMPILE_ASSERT_MATCHING_ENUM(DomainError);
917 #undef COMPILE_ASSERT_MATCHING_ENUM
918
894 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system, 919 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system,
895 const std::string& session_id, 920 const std::string& session_id,
896 media::Decryptor::KeyError error_code, 921 media::Decryptor::KeyError error_code,
897 int system_code) { 922 int system_code) {
898 DCHECK_EQ(main_loop_, MessageLoop::current()); 923 DCHECK_EQ(main_loop_, MessageLoop::current());
899 924
900 GetClient()->keyError( 925 GetClient()->keyError(
901 WebString::fromUTF8(key_system), 926 WebString::fromUTF8(key_system),
902 WebString::fromUTF8(session_id), 927 WebString::fromUTF8(session_id),
903 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), 928 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 return audio_source_provider_; 1046 return audio_source_provider_;
1022 } 1047 }
1023 1048
1024 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1049 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1025 DCHECK_EQ(main_loop_, MessageLoop::current()); 1050 DCHECK_EQ(main_loop_, MessageLoop::current());
1026 incremented_externally_allocated_memory_ = true; 1051 incremented_externally_allocated_memory_ = true;
1027 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1052 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1028 } 1053 }
1029 1054
1030 } // namespace webkit_media 1055 } // 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