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" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #include "webkit/media/webmediaplayer_delegate.h" | 37 #include "webkit/media/webmediaplayer_delegate.h" |
38 #include "webkit/media/webmediaplayer_proxy.h" | 38 #include "webkit/media/webmediaplayer_proxy.h" |
39 #include "webkit/media/webmediaplayer_util.h" | 39 #include "webkit/media/webmediaplayer_util.h" |
40 #include "webkit/media/webvideoframe_impl.h" | 40 #include "webkit/media/webvideoframe_impl.h" |
41 | 41 |
42 using WebKit::WebCanvas; | 42 using WebKit::WebCanvas; |
43 using WebKit::WebMediaPlayer; | 43 using WebKit::WebMediaPlayer; |
44 using WebKit::WebRect; | 44 using WebKit::WebRect; |
45 using WebKit::WebSize; | 45 using WebKit::WebSize; |
46 using WebKit::WebString; | 46 using WebKit::WebString; |
47 using media::NetworkEvent; | |
48 using media::PipelineStatus; | 47 using media::PipelineStatus; |
49 | 48 |
50 namespace { | 49 namespace { |
51 | 50 |
52 // Amount of extra memory used by each player instance reported to V8. | 51 // Amount of extra memory used by each player instance reported to V8. |
53 // It is not exact number -- first, it differs on different platforms, | 52 // It is not exact number -- first, it differs on different platforms, |
54 // and second, it is very hard to calculate. Instead, use some arbitrary | 53 // and second, it is very hard to calculate. Instead, use some arbitrary |
55 // value that will cause garbage collection from time to time. We don't want | 54 // value that will cause garbage collection from time to time. We don't want |
56 // it to happen on every allocation, but don't want 5k players to sit in memory | 55 // it to happen on every allocation, but don't want 5k players to sit in memory |
57 // either. Looks that chosen constant achieves both goals, at least for audio | 56 // either. Looks that chosen constant achieves both goals, at least for audio |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 filter_collection_.get(), | 236 filter_collection_.get(), |
238 decryptor_.get(), | 237 decryptor_.get(), |
239 &video_decoder)) { | 238 &video_decoder)) { |
240 proxy_->set_video_decoder(video_decoder); | 239 proxy_->set_video_decoder(video_decoder); |
241 StartPipeline(); | 240 StartPipeline(); |
242 return; | 241 return; |
243 } | 242 } |
244 | 243 |
245 // Otherwise it's a regular request which requires resolving the URL first. | 244 // Otherwise it's a regular request which requires resolving the URL first. |
246 proxy_->set_data_source( | 245 proxy_->set_data_source( |
247 new BufferedDataSource(main_loop_, frame_, media_log_)); | 246 new BufferedDataSource(main_loop_, frame_, media_log_, |
247 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, | |
248 base::Unretained(this)))); | |
248 proxy_->data_source()->Initialize( | 249 proxy_->data_source()->Initialize( |
249 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 250 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
250 base::Bind( | 251 base::Bind( |
251 &WebMediaPlayerImpl::DataSourceInitialized, | 252 &WebMediaPlayerImpl::DataSourceInitialized, |
252 base::Unretained(this), gurl)); | 253 base::Unretained(this), gurl)); |
253 | 254 |
254 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); | 255 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
255 | 256 |
256 BuildDefaultCollection(proxy_->data_source(), | 257 BuildDefaultCollection(proxy_->data_source(), |
257 message_loop_factory_.get(), | 258 message_loop_factory_.get(), |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 } | 452 } |
452 | 453 |
453 int WebMediaPlayerImpl::dataRate() const { | 454 int WebMediaPlayerImpl::dataRate() const { |
454 DCHECK_EQ(main_loop_, MessageLoop::current()); | 455 DCHECK_EQ(main_loop_, MessageLoop::current()); |
455 | 456 |
456 // TODO(hclam): Add this method call if pipeline has it in the interface. | 457 // TODO(hclam): Add this method call if pipeline has it in the interface. |
457 return 0; | 458 return 0; |
458 } | 459 } |
459 | 460 |
460 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { | 461 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
462 DCHECK_EQ(main_loop_, MessageLoop::current()); | |
scherkus (not reviewing)
2012/06/12 02:55:04
left over debugging code?
it's fine to leave it i
Ami GONE FROM CHROMIUM
2012/06/12 03:42:43
No, copying from dataRate() above, I think.
| |
461 return network_state_; | 463 return network_state_; |
462 } | 464 } |
463 | 465 |
464 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { | 466 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
465 return ready_state_; | 467 return ready_state_; |
466 } | 468 } |
467 | 469 |
468 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { | 470 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { |
469 DCHECK_EQ(main_loop_, MessageLoop::current()); | 471 DCHECK_EQ(main_loop_, MessageLoop::current()); |
470 media::Ranges<base::TimeDelta> buffered_time_ranges = | 472 media::Ranges<base::TimeDelta> buffered_time_ranges = |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
910 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in | 912 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in |
911 // Webkit (see http://crbug.com/124486). | 913 // Webkit (see http://crbug.com/124486). |
912 SetNetworkState(WebMediaPlayer::NetworkStateDecodeError); | 914 SetNetworkState(WebMediaPlayer::NetworkStateDecodeError); |
913 break; | 915 break; |
914 } | 916 } |
915 | 917 |
916 // Repaint to trigger UI update. | 918 // Repaint to trigger UI update. |
917 Repaint(); | 919 Repaint(); |
918 } | 920 } |
919 | 921 |
920 void WebMediaPlayerImpl::OnNetworkEvent(NetworkEvent type) { | |
921 DCHECK_EQ(main_loop_, MessageLoop::current()); | |
922 switch(type) { | |
923 case media::DOWNLOAD_CONTINUED: | |
924 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | |
925 break; | |
926 case media::DOWNLOAD_PAUSED: | |
927 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | |
928 break; | |
929 case media::CAN_PLAY_THROUGH: | |
930 // Temporarily disable delayed firing of CAN_PLAY_THROUGH due to | |
931 // crbug.com/106480. | |
932 // TODO(vrk): uncomment code below when bug above is fixed. | |
933 // SetReadyState(WebMediaPlayer::NetworkStateHaveEnoughData); | |
934 break; | |
935 default: | |
936 NOTREACHED(); | |
937 } | |
938 } | |
939 | |
940 void WebMediaPlayerImpl::OnDemuxerOpened() { | 922 void WebMediaPlayerImpl::OnDemuxerOpened() { |
941 DCHECK_EQ(main_loop_, MessageLoop::current()); | 923 DCHECK_EQ(main_loop_, MessageLoop::current()); |
942 | 924 |
943 GetClient()->sourceOpened(); | 925 GetClient()->sourceOpened(); |
944 } | 926 } |
945 | 927 |
946 void WebMediaPlayerImpl::OnKeyNeeded(scoped_array<uint8> init_data, | 928 void WebMediaPlayerImpl::OnKeyNeeded(scoped_array<uint8> init_data, |
947 int init_data_size) { | 929 int init_data_size) { |
948 DCHECK_EQ(main_loop_, MessageLoop::current()); | 930 DCHECK_EQ(main_loop_, MessageLoop::current()); |
949 | 931 |
(...skipping 14 matching lines...) Expand all Loading... | |
964 if (status != media::PIPELINE_OK) { | 946 if (status != media::PIPELINE_OK) { |
965 DVLOG(1) << "DataSourceInitialized status: " << status; | 947 DVLOG(1) << "DataSourceInitialized status: " << status; |
966 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); | 948 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
967 Repaint(); | 949 Repaint(); |
968 return; | 950 return; |
969 } | 951 } |
970 | 952 |
971 StartPipeline(); | 953 StartPipeline(); |
972 } | 954 } |
973 | 955 |
956 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { | |
957 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) | |
958 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | |
959 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) | |
960 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | |
961 media_log_->AddEvent( | |
962 media_log_->CreateBooleanEvent( | |
963 media::MediaLogEvent::NETWORK_ACTIVITY_SET, | |
964 "is_downloading_data", is_downloading)); | |
965 } | |
966 | |
974 void WebMediaPlayerImpl::StartPipeline() { | 967 void WebMediaPlayerImpl::StartPipeline() { |
975 started_ = true; | 968 started_ = true; |
976 pipeline_->Start( | 969 pipeline_->Start( |
977 filter_collection_.Pass(), | 970 filter_collection_.Pass(), |
978 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), | 971 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), |
979 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), | 972 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), |
980 base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, proxy_.get()), | |
981 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, | 973 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, |
982 proxy_.get())); | 974 proxy_.get())); |
983 } | 975 } |
984 | 976 |
985 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 977 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
986 DCHECK_EQ(main_loop_, MessageLoop::current()); | 978 DCHECK_EQ(main_loop_, MessageLoop::current()); |
987 DVLOG(1) << "SetNetworkState: " << state; | 979 DVLOG(1) << "SetNetworkState: " << state; |
988 network_state_ = state; | 980 network_state_ = state; |
989 // Always notify to ensure client has the latest value. | 981 // Always notify to ensure client has the latest value. |
990 GetClient()->networkStateChanged(); | 982 GetClient()->networkStateChanged(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 return audio_source_provider_; | 1036 return audio_source_provider_; |
1045 } | 1037 } |
1046 | 1038 |
1047 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1039 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
1048 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1040 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1049 incremented_externally_allocated_memory_ = true; | 1041 incremented_externally_allocated_memory_ = true; |
1050 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1042 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
1051 } | 1043 } |
1052 | 1044 |
1053 } // namespace webkit_media | 1045 } // namespace webkit_media |
OLD | NEW |