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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/string_number_conversions.h" | |
| 15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 16 #include "media/audio/null_audio_sink.h" | 17 #include "media/audio/null_audio_sink.h" |
| 17 #include "media/base/filter_collection.h" | 18 #include "media/base/filter_collection.h" |
| 18 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
| 19 #include "media/base/media_log.h" | 20 #include "media/base/media_log.h" |
| 20 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
| 21 #include "media/base/pipeline.h" | 22 #include "media/base/pipeline.h" |
| 22 #include "media/base/video_frame.h" | 23 #include "media/base/video_frame.h" |
| 23 #include "media/filters/audio_renderer_impl.h" | 24 #include "media/filters/audio_renderer_impl.h" |
| 24 #include "media/filters/video_renderer_base.h" | 25 #include "media/filters/video_renderer_base.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 30 #include "v8/include/v8.h" | 32 #include "v8/include/v8.h" |
| 31 #include "webkit/media/buffered_data_source.h" | 33 #include "webkit/media/buffered_data_source.h" |
| 32 #include "webkit/media/filter_helpers.h" | 34 #include "webkit/media/filter_helpers.h" |
| 35 #include "webkit/media/mime_util.h" | |
| 33 #include "webkit/media/webmediaplayer_delegate.h" | 36 #include "webkit/media/webmediaplayer_delegate.h" |
| 34 #include "webkit/media/webmediaplayer_proxy.h" | 37 #include "webkit/media/webmediaplayer_proxy.h" |
| 35 #include "webkit/media/webvideoframe_impl.h" | 38 #include "webkit/media/webvideoframe_impl.h" |
| 36 | 39 |
| 37 using WebKit::WebCanvas; | 40 using WebKit::WebCanvas; |
| 38 using WebKit::WebRect; | 41 using WebKit::WebRect; |
| 39 using WebKit::WebSize; | 42 using WebKit::WebSize; |
| 40 using media::NetworkEvent; | 43 using media::NetworkEvent; |
| 41 using media::PipelineStatus; | 44 using media::PipelineStatus; |
| 42 | 45 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 case WebKit::WebMediaPlayer::EosDecodeError: | 664 case WebKit::WebMediaPlayer::EosDecodeError: |
| 662 pipeline_status = media::PIPELINE_ERROR_DECODE; | 665 pipeline_status = media::PIPELINE_ERROR_DECODE; |
| 663 break; | 666 break; |
| 664 default: | 667 default: |
| 665 NOTIMPLEMENTED(); | 668 NOTIMPLEMENTED(); |
| 666 } | 669 } |
| 667 | 670 |
| 668 proxy_->DemuxerEndOfStream(pipeline_status); | 671 proxy_->DemuxerEndOfStream(pipeline_status); |
| 669 } | 672 } |
| 670 | 673 |
| 674 WebKit::WebMediaPlayer::MediaKeyException | |
| 675 WebMediaPlayerImpl::generateKeyRequest(const WebKit::WebString& key_system, | |
| 676 const unsigned char* init_data, | |
| 677 unsigned init_data_length) { | |
| 678 if (!mime_util::isKeySystemSupported(key_system)) | |
| 679 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
| 680 | |
| 681 // Every request call creates a unique ID. | |
| 682 // TODO(ddorwin): Move this to the CDM implementations since the CDMs may | |
| 683 // create their own IDs and since CDMs supporting multiple renderer processes | |
| 684 // need globally unique IDs. | |
| 685 // Everything from here until the return should probably be handled by | |
| 686 // the decrypter - see http://crbug.com/123260. | |
| 687 static uint32_t next_available_session_id = 1; | |
| 688 uint32_t session_id = next_available_session_id++; | |
| 689 | |
| 690 WebKit::WebString session_id_string(base::UintToString16(session_id)); | |
| 691 | |
| 692 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " | |
| 693 << std::string(reinterpret_cast<const char*>(init_data), | |
| 694 static_cast<size_t>(init_data_length)) | |
| 695 << " [" << session_id_string.utf8().data() << "]"; | |
| 696 | |
| 697 // TODO(ddorwin): Generate a key request in the decrypter and fire | |
| 698 // keyMessage when it completes. | |
| 699 // For now, just fire the event with the init_data as the request. | |
| 700 const unsigned char* message = init_data; | |
| 701 unsigned message_length = init_data_length; | |
| 702 | |
| 703 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | |
| 704 &WebKit::WebMediaPlayerClient::keyMessage, | |
| 705 base::Unretained(GetClient()), | |
| 706 key_system, | |
| 707 session_id_string, | |
| 708 message, | |
| 709 message_length)); | |
| 710 | |
| 711 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; | |
| 712 } | |
| 713 | |
| 714 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( | |
| 715 const WebKit::WebString& key_system, | |
|
darin (slow to review)
2012/04/17 22:41:54
nit: consider adding using directives for WebKit A
ddorwin
2012/04/17 23:25:37
Done.
| |
| 716 const unsigned char* key, | |
| 717 unsigned key_length, | |
| 718 const unsigned char* init_data, | |
| 719 unsigned init_data_length, | |
| 720 const WebKit::WebString& session_id) { | |
| 721 if (!mime_util::isKeySystemSupported(key_system)) | |
| 722 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
| 723 | |
| 724 | |
| 725 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " | |
| 726 << std::string(reinterpret_cast<const char*>(key), | |
| 727 static_cast<size_t>(key_length)) << ", " | |
| 728 << std::string(reinterpret_cast<const char*>(init_data), | |
| 729 static_cast<size_t>(init_data_length)) | |
| 730 << " [" << session_id.utf8().data() << "]"; | |
| 731 | |
| 732 // TODO(ddorwin): Add the key to the decrypter and fire keyAdded when it | |
| 733 // completes. Check the key length there. | |
| 734 // Everything from here until the return should probably be handled by | |
| 735 // the decrypter - see http://crbug.com/123260. | |
| 736 // Temporarily, fire an error for invalid key length so we can test the error | |
| 737 // event and fire the keyAdded event in all other cases. | |
| 738 const unsigned kSupportedKeyLength = 16; // 128-bit key. | |
| 739 if (key_length != kSupportedKeyLength) { | |
| 740 DLOG(ERROR) << "addKey: invalid key length: " << key_length; | |
| 741 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | |
| 742 &WebKit::WebMediaPlayerClient::keyError, | |
| 743 base::Unretained(GetClient()), | |
| 744 key_system, | |
| 745 session_id, | |
| 746 WebKit::WebMediaPlayerClient::MediaKeyErrorCodeUnknown, | |
| 747 0)); | |
| 748 } else { | |
| 749 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | |
| 750 &WebKit::WebMediaPlayerClient::keyAdded, | |
| 751 base::Unretained(GetClient()), | |
| 752 key_system, | |
| 753 session_id)); | |
| 754 } | |
| 755 | |
| 756 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; | |
| 757 } | |
| 758 | |
| 759 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( | |
| 760 const WebKit::WebString& key_system, | |
| 761 const WebKit::WebString& session_id) { | |
| 762 if (!mime_util::isKeySystemSupported(key_system)) | |
| 763 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
| 764 | |
| 765 // TODO(ddorwin): Cancel the key request in the decrypter. | |
| 766 | |
| 767 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; | |
| 768 } | |
| 769 | |
| 671 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { | 770 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { |
| 672 Destroy(); | 771 Destroy(); |
| 673 main_loop_ = NULL; | 772 main_loop_ = NULL; |
| 674 } | 773 } |
| 675 | 774 |
| 676 void WebMediaPlayerImpl::Repaint() { | 775 void WebMediaPlayerImpl::Repaint() { |
| 677 DCHECK_EQ(main_loop_, MessageLoop::current()); | 776 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 678 GetClient()->repaint(); | 777 GetClient()->repaint(); |
| 679 } | 778 } |
| 680 | 779 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 return audio_source_provider_; | 1013 return audio_source_provider_; |
| 915 } | 1014 } |
| 916 | 1015 |
| 917 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1016 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 918 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1017 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 919 incremented_externally_allocated_memory_ = true; | 1018 incremented_externally_allocated_memory_ = true; |
| 920 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1019 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 921 } | 1020 } |
| 922 | 1021 |
| 923 } // namespace webkit_media | 1022 } // namespace webkit_media |
| OLD | NEW |