| 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/key_systems.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; |
| 43 using WebKit::WebString; |
| 40 using media::NetworkEvent; | 44 using media::NetworkEvent; |
| 41 using media::PipelineStatus; | 45 using media::PipelineStatus; |
| 42 | 46 |
| 43 namespace { | 47 namespace { |
| 44 | 48 |
| 45 // Amount of extra memory used by each player instance reported to V8. | 49 // Amount of extra memory used by each player instance reported to V8. |
| 46 // It is not exact number -- first, it differs on different platforms, | 50 // It is not exact number -- first, it differs on different platforms, |
| 47 // and second, it is very hard to calculate. Instead, use some arbitrary | 51 // and second, it is very hard to calculate. Instead, use some arbitrary |
| 48 // value that will cause garbage collection from time to time. We don't want | 52 // value that will cause garbage collection from time to time. We don't want |
| 49 // it to happen on every allocation, but don't want 5k players to sit in memory | 53 // it to happen on every allocation, but don't want 5k players to sit in memory |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 case WebKit::WebMediaPlayer::EosDecodeError: | 665 case WebKit::WebMediaPlayer::EosDecodeError: |
| 662 pipeline_status = media::PIPELINE_ERROR_DECODE; | 666 pipeline_status = media::PIPELINE_ERROR_DECODE; |
| 663 break; | 667 break; |
| 664 default: | 668 default: |
| 665 NOTIMPLEMENTED(); | 669 NOTIMPLEMENTED(); |
| 666 } | 670 } |
| 667 | 671 |
| 668 proxy_->DemuxerEndOfStream(pipeline_status); | 672 proxy_->DemuxerEndOfStream(pipeline_status); |
| 669 } | 673 } |
| 670 | 674 |
| 675 WebKit::WebMediaPlayer::MediaKeyException |
| 676 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
| 677 const unsigned char* init_data, |
| 678 unsigned init_data_length) { |
| 679 if (!IsSupportedKeySystem(key_system)) |
| 680 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 681 |
| 682 // Every request call creates a unique ID. |
| 683 // TODO(ddorwin): Move this to the CDM implementations since the CDMs may |
| 684 // create their own IDs and since CDMs supporting multiple renderer processes |
| 685 // need globally unique IDs. |
| 686 // Everything from here until the return should probably be handled by |
| 687 // the decrypter - see http://crbug.com/123260. |
| 688 static uint32_t next_available_session_id = 1; |
| 689 uint32_t session_id = next_available_session_id++; |
| 690 |
| 691 WebString session_id_string(base::UintToString16(session_id)); |
| 692 |
| 693 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " |
| 694 << std::string(reinterpret_cast<const char*>(init_data), |
| 695 static_cast<size_t>(init_data_length)) |
| 696 << " [" << session_id_string.utf8().data() << "]"; |
| 697 |
| 698 // TODO(ddorwin): Generate a key request in the decrypter and fire |
| 699 // keyMessage when it completes. |
| 700 // For now, just fire the event with the init_data as the request. |
| 701 const unsigned char* message = init_data; |
| 702 unsigned message_length = init_data_length; |
| 703 |
| 704 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 705 &WebKit::WebMediaPlayerClient::keyMessage, |
| 706 base::Unretained(GetClient()), |
| 707 key_system, |
| 708 session_id_string, |
| 709 message, |
| 710 message_length)); |
| 711 |
| 712 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; |
| 713 } |
| 714 |
| 715 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( |
| 716 const WebString& key_system, |
| 717 const unsigned char* key, |
| 718 unsigned key_length, |
| 719 const unsigned char* init_data, |
| 720 unsigned init_data_length, |
| 721 const WebString& session_id) { |
| 722 if (!IsSupportedKeySystem(key_system)) |
| 723 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 724 |
| 725 |
| 726 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " |
| 727 << std::string(reinterpret_cast<const char*>(key), |
| 728 static_cast<size_t>(key_length)) << ", " |
| 729 << std::string(reinterpret_cast<const char*>(init_data), |
| 730 static_cast<size_t>(init_data_length)) |
| 731 << " [" << session_id.utf8().data() << "]"; |
| 732 |
| 733 // TODO(ddorwin): Add the key to the decrypter and fire keyAdded when it |
| 734 // completes. Check the key length there. |
| 735 // Everything from here until the return should probably be handled by |
| 736 // the decrypter - see http://crbug.com/123260. |
| 737 // Temporarily, fire an error for invalid key length so we can test the error |
| 738 // event and fire the keyAdded event in all other cases. |
| 739 const unsigned kSupportedKeyLength = 16; // 128-bit key. |
| 740 if (key_length != kSupportedKeyLength) { |
| 741 DLOG(ERROR) << "addKey: invalid key length: " << key_length; |
| 742 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 743 &WebKit::WebMediaPlayerClient::keyError, |
| 744 base::Unretained(GetClient()), |
| 745 key_system, |
| 746 session_id, |
| 747 WebKit::WebMediaPlayerClient::MediaKeyErrorCodeUnknown, |
| 748 0)); |
| 749 } else { |
| 750 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 751 &WebKit::WebMediaPlayerClient::keyAdded, |
| 752 base::Unretained(GetClient()), |
| 753 key_system, |
| 754 session_id)); |
| 755 } |
| 756 |
| 757 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; |
| 758 } |
| 759 |
| 760 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( |
| 761 const WebString& key_system, |
| 762 const WebString& session_id) { |
| 763 if (!IsSupportedKeySystem(key_system)) |
| 764 return WebKit::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 765 |
| 766 // TODO(ddorwin): Cancel the key request in the decrypter. |
| 767 |
| 768 return WebKit::WebMediaPlayer::MediaKeyExceptionNoError; |
| 769 } |
| 770 |
| 671 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { | 771 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { |
| 672 Destroy(); | 772 Destroy(); |
| 673 main_loop_ = NULL; | 773 main_loop_ = NULL; |
| 674 } | 774 } |
| 675 | 775 |
| 676 void WebMediaPlayerImpl::Repaint() { | 776 void WebMediaPlayerImpl::Repaint() { |
| 677 DCHECK_EQ(main_loop_, MessageLoop::current()); | 777 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 678 GetClient()->repaint(); | 778 GetClient()->repaint(); |
| 679 } | 779 } |
| 680 | 780 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 return audio_source_provider_; | 1014 return audio_source_provider_; |
| 915 } | 1015 } |
| 916 | 1016 |
| 917 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1017 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 918 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1018 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 919 incremented_externally_allocated_memory_ = true; | 1019 incremented_externally_allocated_memory_ = true; |
| 920 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1020 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 921 } | 1021 } |
| 922 | 1022 |
| 923 } // namespace webkit_media | 1023 } // namespace webkit_media |
| OLD | NEW |