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

Side by Side Diff: webkit/media/webmediaplayer_impl.cc

Issue 10535101: Replace Pipeline::SetNetworkActivity() with BufferedDataSource -> WebMediaPlayerImpl callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | webkit/media/webmediaplayer_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 26 matching lines...) Expand all
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
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
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());
461 return network_state_; 463 return network_state_;
462 } 464 }
463 465
464 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { 466 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const {
467 DCHECK_EQ(main_loop_, MessageLoop::current());
465 return ready_state_; 468 return ready_state_;
466 } 469 }
467 470
468 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { 471 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() {
469 DCHECK_EQ(main_loop_, MessageLoop::current()); 472 DCHECK_EQ(main_loop_, MessageLoop::current());
470 media::Ranges<base::TimeDelta> buffered_time_ranges = 473 media::Ranges<base::TimeDelta> buffered_time_ranges =
471 pipeline_->GetBufferedTimeRanges(); 474 pipeline_->GetBufferedTimeRanges();
472 WebKit::WebTimeRanges web_ranges(buffered_time_ranges.size()); 475 WebKit::WebTimeRanges web_ranges(buffered_time_ranges.size());
473 for (size_t i = 0; i < buffered_time_ranges.size(); ++i) { 476 for (size_t i = 0; i < buffered_time_ranges.size(); ++i) {
474 web_ranges[i].start = buffered_time_ranges.start(i).InSecondsF(); 477 web_ranges[i].start = buffered_time_ranges.start(i).InSecondsF();
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in 913 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in
911 // Webkit (see http://crbug.com/124486). 914 // Webkit (see http://crbug.com/124486).
912 SetNetworkState(WebMediaPlayer::NetworkStateDecodeError); 915 SetNetworkState(WebMediaPlayer::NetworkStateDecodeError);
913 break; 916 break;
914 } 917 }
915 918
916 // Repaint to trigger UI update. 919 // Repaint to trigger UI update.
917 Repaint(); 920 Repaint();
918 } 921 }
919 922
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() { 923 void WebMediaPlayerImpl::OnDemuxerOpened() {
941 DCHECK_EQ(main_loop_, MessageLoop::current()); 924 DCHECK_EQ(main_loop_, MessageLoop::current());
942 925
943 GetClient()->sourceOpened(); 926 GetClient()->sourceOpened();
944 } 927 }
945 928
946 void WebMediaPlayerImpl::OnKeyNeeded(scoped_array<uint8> init_data, 929 void WebMediaPlayerImpl::OnKeyNeeded(scoped_array<uint8> init_data,
947 int init_data_size) { 930 int init_data_size) {
948 DCHECK_EQ(main_loop_, MessageLoop::current()); 931 DCHECK_EQ(main_loop_, MessageLoop::current());
949 932
(...skipping 14 matching lines...) Expand all
964 if (status != media::PIPELINE_OK) { 947 if (status != media::PIPELINE_OK) {
965 DVLOG(1) << "DataSourceInitialized status: " << status; 948 DVLOG(1) << "DataSourceInitialized status: " << status;
966 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); 949 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
967 Repaint(); 950 Repaint();
968 return; 951 return;
969 } 952 }
970 953
971 StartPipeline(); 954 StartPipeline();
972 } 955 }
973 956
957 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) {
958 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading)
959 SetNetworkState(WebMediaPlayer::NetworkStateIdle);
960 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle)
961 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
962 media_log_->AddEvent(
963 media_log_->CreateBooleanEvent(
964 media::MediaLogEvent::NETWORK_ACTIVITY_SET,
965 "is_downloading_data", is_downloading));
966 }
967
974 void WebMediaPlayerImpl::StartPipeline() { 968 void WebMediaPlayerImpl::StartPipeline() {
975 started_ = true; 969 started_ = true;
976 pipeline_->Start( 970 pipeline_->Start(
977 filter_collection_.Pass(), 971 filter_collection_.Pass(),
978 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), 972 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()),
979 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), 973 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()),
980 base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, proxy_.get()),
981 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, 974 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback,
982 proxy_.get())); 975 proxy_.get()));
983 } 976 }
984 977
985 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 978 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
986 DCHECK_EQ(main_loop_, MessageLoop::current()); 979 DCHECK_EQ(main_loop_, MessageLoop::current());
987 DVLOG(1) << "SetNetworkState: " << state; 980 DVLOG(1) << "SetNetworkState: " << state;
988 network_state_ = state; 981 network_state_ = state;
989 // Always notify to ensure client has the latest value. 982 // Always notify to ensure client has the latest value.
990 GetClient()->networkStateChanged(); 983 GetClient()->networkStateChanged();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 return audio_source_provider_; 1037 return audio_source_provider_;
1045 } 1038 }
1046 1039
1047 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1040 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1048 DCHECK_EQ(main_loop_, MessageLoop::current()); 1041 DCHECK_EQ(main_loop_, MessageLoop::current());
1049 incremented_externally_allocated_memory_ = true; 1042 incremented_externally_allocated_memory_ = true;
1050 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1043 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1051 } 1044 }
1052 1045
1053 } // namespace webkit_media 1046 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | webkit/media/webmediaplayer_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698