Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 36 #include "webkit/media/filter_helpers.h" | 35 #include "webkit/media/filter_helpers.h" |
| 37 #include "webkit/media/key_systems.h" | 36 #include "webkit/media/key_systems.h" |
| 37 #include "webkit/media/proxy_decryptor.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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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_) | |
| 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; | |
|
xhwang
2012/06/20 00:49:57
This will break all demos that call AddKey() befor
| |
| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 return audio_source_provider_; | 1034 return audio_source_provider_; |
| 1022 } | 1035 } |
| 1023 | 1036 |
| 1024 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1037 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 1025 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1038 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 1026 incremented_externally_allocated_memory_ = true; | 1039 incremented_externally_allocated_memory_ = true; |
| 1027 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1040 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 1028 } | 1041 } |
| 1029 | 1042 |
| 1030 } // namespace webkit_media | 1043 } // namespace webkit_media |
| OLD | NEW |