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

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

Issue 1904793002: Move Pipeline permanent callbacks into Pipeline::Client interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: restored lock during stop Created 4 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/callback_helpers.h" 16 #include "base/callback_helpers.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/debug/alias.h" 18 #include "base/debug/alias.h"
19 #include "base/debug/crash_logging.h" 19 #include "base/debug/crash_logging.h"
20 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/synchronization/waitable_event.h"
23 #include "base/task_runner_util.h" 22 #include "base/task_runner_util.h"
24 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
25 #include "base/trace_event/trace_event.h" 24 #include "base/trace_event/trace_event.h"
26 #include "build/build_config.h" 25 #include "build/build_config.h"
27 #include "cc/blink/web_layer_impl.h" 26 #include "cc/blink/web_layer_impl.h"
28 #include "cc/layers/video_layer.h" 27 #include "cc/layers/video_layer.h"
29 #include "media/audio/null_audio_sink.h" 28 #include "media/audio/null_audio_sink.h"
30 #include "media/base/bind_to_current_loop.h" 29 #include "media/base/bind_to_current_loop.h"
31 #include "media/base/cdm_context.h" 30 #include "media/base/cdm_context.h"
32 #include "media/base/limits.h" 31 #include "media/base/limits.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 media_task_runner_(params.media_task_runner()), 157 media_task_runner_(params.media_task_runner()),
159 worker_task_runner_(params.worker_task_runner()), 158 worker_task_runner_(params.worker_task_runner()),
160 media_log_(params.media_log()), 159 media_log_(params.media_log()),
161 pipeline_(media_task_runner_, media_log_.get()), 160 pipeline_(media_task_runner_, media_log_.get()),
162 pipeline_controller_( 161 pipeline_controller_(
163 &pipeline_, 162 &pipeline_,
164 base::Bind(&WebMediaPlayerImpl::CreateRenderer, 163 base::Bind(&WebMediaPlayerImpl::CreateRenderer,
165 base::Unretained(this)), 164 base::Unretained(this)),
166 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), 165 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()),
167 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), 166 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()),
168 base::Bind(&WebMediaPlayerImpl::OnPipelineError, AsWeakPtr())), 167 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())),
169 load_type_(LoadTypeURL), 168 load_type_(LoadTypeURL),
170 opaque_(false), 169 opaque_(false),
171 playback_rate_(0.0), 170 playback_rate_(0.0),
172 paused_(true), 171 paused_(true),
173 seeking_(false), 172 seeking_(false),
174 pending_suspend_resume_cycle_(false), 173 pending_suspend_resume_cycle_(false),
175 ended_(false), 174 ended_(false),
176 should_notify_time_changed_(false), 175 should_notify_time_changed_(false),
177 fullscreen_(false), 176 fullscreen_(false),
178 decoder_requires_restart_for_fullscreen_(false), 177 decoder_requires_restart_for_fullscreen_(false),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // Abort any pending IO so stopping the pipeline doesn't get blocked. 244 // Abort any pending IO so stopping the pipeline doesn't get blocked.
246 suppress_destruction_errors_ = true; 245 suppress_destruction_errors_ = true;
247 if (data_source_) 246 if (data_source_)
248 data_source_->Abort(); 247 data_source_->Abort();
249 if (chunk_demuxer_) { 248 if (chunk_demuxer_) {
250 chunk_demuxer_->Shutdown(); 249 chunk_demuxer_->Shutdown();
251 chunk_demuxer_ = nullptr; 250 chunk_demuxer_ = nullptr;
252 } 251 }
253 252
254 renderer_factory_.reset(); 253 renderer_factory_.reset();
255 254 // Pipeline must be stopped before it is destroyed.
sandersd (OOO until July 31) 2016/05/02 18:37:47 Newline before comment.
alokp 2016/05/02 22:25:17 Done.
256 // Make sure to kill the pipeline so there's no more media threads running. 255 pipeline_.Stop();
257 // Note: stopping the pipeline might block for a long time.
258 base::WaitableEvent waiter(false, false);
259 pipeline_.Stop(
260 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter)));
261 waiter.Wait();
262 256
263 if (last_reported_memory_usage_) 257 if (last_reported_memory_usage_)
264 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); 258 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_);
265 259
266 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); 260 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_);
267 261
268 media_log_->AddEvent( 262 media_log_->AddEvent(
269 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); 263 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
270 } 264 }
271 265
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // 2) For MSE. 427 // 2) For MSE.
434 // Because the buffers may have changed between seeks, MSE seeks are 428 // Because the buffers may have changed between seeks, MSE seeks are
435 // never elided. 429 // never elided.
436 if (paused_ && pipeline_controller_.IsStable() && paused_time_ == time && 430 if (paused_ && pipeline_controller_.IsStable() && paused_time_ == time &&
437 !chunk_demuxer_) { 431 !chunk_demuxer_) {
438 // If the ready state was high enough before, we can indicate that the seek 432 // If the ready state was high enough before, we can indicate that the seek
439 // completed just by restoring it. Otherwise we will just wait for the real 433 // completed just by restoring it. Otherwise we will just wait for the real
440 // ready state change to eventually happen. 434 // ready state change to eventually happen.
441 if (old_state == ReadyStateHaveEnoughData) { 435 if (old_state == ReadyStateHaveEnoughData) {
442 main_task_runner_->PostTask( 436 main_task_runner_->PostTask(
443 FROM_HERE, 437 FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnBufferingStateChange,
444 base::Bind(&WebMediaPlayerImpl::OnPipelineBufferingStateChanged, 438 AsWeakPtr(), BUFFERING_HAVE_ENOUGH));
445 AsWeakPtr(), BUFFERING_HAVE_ENOUGH));
446 } 439 }
447 return; 440 return;
448 } 441 }
449 442
450 // TODO(sandersd): Ideally we would not clear the idle state if 443 // TODO(sandersd): Ideally we would not clear the idle state if
451 // |pipeline_controller_| can elide the seek. 444 // |pipeline_controller_| can elide the seek.
452 is_idle_ = false; 445 is_idle_ = false;
453 ended_ = false; 446 ended_ = false;
454 447
455 seeking_ = true; 448 seeking_ = true;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 blink::WebString::fromUTF8(track->language()), 835 blink::WebString::fromUTF8(track->language()),
843 /*selected*/ true); 836 /*selected*/ true);
844 (void)track_id; 837 (void)track_id;
845 } else { 838 } else {
846 // Text tracks are not supported through this code path yet. 839 // Text tracks are not supported through this code path yet.
847 NOTREACHED(); 840 NOTREACHED();
848 } 841 }
849 } 842 }
850 } 843 }
851 844
852 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() {
853 encrypted_client_->didBlockPlaybackWaitingForKey();
854
855 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called
856 // when a key has been successfully added (e.g. OnSessionKeysChange() with
857 // |has_additional_usable_key| = true). http://crbug.com/461903
858 encrypted_client_->didResumePlaybackBlockedForKey();
859 }
860
861 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, 845 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb,
862 CdmContext* cdm_context) { 846 CdmContext* cdm_context) {
863 if (!cdm_context) { 847 if (!cdm_context) {
864 cdm_attached_cb.Run(false); 848 cdm_attached_cb.Run(false);
865 return; 849 return;
866 } 850 }
867 851
868 // If CDM initialization succeeded, tell the pipeline about it. 852 // If CDM initialization succeeded, tell the pipeline about it.
869 pipeline_.SetCdm(cdm_context, cdm_attached_cb); 853 pipeline_.SetCdm(cdm_context, cdm_attached_cb);
870 } 854 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 } 903 }
920 904
921 ReportMemoryUsage(); 905 ReportMemoryUsage();
922 906
923 if (pending_suspend_resume_cycle_) { 907 if (pending_suspend_resume_cycle_) {
924 pending_suspend_resume_cycle_ = false; 908 pending_suspend_resume_cycle_ = false;
925 UpdatePlayState(); 909 UpdatePlayState();
926 } 910 }
927 } 911 }
928 912
929 void WebMediaPlayerImpl::OnPipelineEnded() { 913 void WebMediaPlayerImpl::OnDemuxerOpened() {
914 DCHECK(main_task_runner_->BelongsToCurrentThread());
915 client_->mediaSourceOpened(
916 new WebMediaSourceImpl(chunk_demuxer_, media_log_));
917 }
918
919 void WebMediaPlayerImpl::OnError(PipelineStatus status) {
920 DVLOG(1) << __FUNCTION__;
921 DCHECK(main_task_runner_->BelongsToCurrentThread());
922 DCHECK_NE(status, PIPELINE_OK);
923
924 if (suppress_destruction_errors_)
925 return;
926
927 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status));
928
929 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) {
930 // Any error that occurs before reaching ReadyStateHaveMetadata should
931 // be considered a format error.
932 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
933 } else {
934 SetNetworkState(PipelineErrorToNetworkState(status));
935 }
936
937 UpdatePlayState();
938 }
939
940 void WebMediaPlayerImpl::OnEnded() {
930 DVLOG(1) << __FUNCTION__; 941 DVLOG(1) << __FUNCTION__;
931 DCHECK(main_task_runner_->BelongsToCurrentThread()); 942 DCHECK(main_task_runner_->BelongsToCurrentThread());
932 943
933 // Ignore state changes until we've completed all outstanding operations. 944 // Ignore state changes until we've completed all outstanding operations.
934 if (!pipeline_controller_.IsStable()) 945 if (!pipeline_controller_.IsStable())
935 return; 946 return;
936 947
937 ended_ = true; 948 ended_ = true;
938 client_->timeChanged(); 949 client_->timeChanged();
939 950
940 // We don't actually want this to run until |client_| calls seek() or pause(), 951 // We don't actually want this to run until |client_| calls seek() or pause(),
941 // but that should have already happened in timeChanged() and so this is 952 // but that should have already happened in timeChanged() and so this is
942 // expected to be a no-op. 953 // expected to be a no-op.
943 UpdatePlayState(); 954 UpdatePlayState();
944 } 955 }
945 956
946 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { 957 void WebMediaPlayerImpl::OnMetadata(PipelineMetadata metadata) {
947 DVLOG(1) << __FUNCTION__; 958 DVLOG(1) << __FUNCTION__;
948 DCHECK(main_task_runner_->BelongsToCurrentThread()); 959 DCHECK(main_task_runner_->BelongsToCurrentThread());
949 DCHECK_NE(error, PIPELINE_OK);
950
951 if (suppress_destruction_errors_)
952 return;
953
954 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(error));
955
956 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) {
957 // Any error that occurs before reaching ReadyStateHaveMetadata should
958 // be considered a format error.
959 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
960 } else {
961 SetNetworkState(PipelineErrorToNetworkState(error));
962 }
963
964 UpdatePlayState();
965 }
966
967 void WebMediaPlayerImpl::OnPipelineMetadata(
968 PipelineMetadata metadata) {
969 DVLOG(1) << __FUNCTION__;
970 960
971 pipeline_metadata_ = metadata; 961 pipeline_metadata_ = metadata;
972 962
973 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, 963 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation,
974 VIDEO_ROTATION_MAX + 1); 964 VIDEO_ROTATION_MAX + 1);
975 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); 965 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
976 966
977 if (hasVideo()) { 967 if (hasVideo()) {
978 DCHECK(!video_weblayer_); 968 DCHECK(!video_weblayer_);
979 scoped_refptr<cc::VideoLayer> layer = 969 scoped_refptr<cc::VideoLayer> layer =
980 cc::VideoLayer::Create(compositor_, pipeline_metadata_.video_rotation); 970 cc::VideoLayer::Create(compositor_, pipeline_metadata_.video_rotation);
981 971
982 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || 972 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 ||
983 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { 973 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) {
984 gfx::Size size = pipeline_metadata_.natural_size; 974 gfx::Size size = pipeline_metadata_.natural_size;
985 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); 975 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width());
986 } 976 }
987 977
988 video_weblayer_.reset(new cc_blink::WebLayerImpl(layer)); 978 video_weblayer_.reset(new cc_blink::WebLayerImpl(layer));
989 video_weblayer_->layer()->SetContentsOpaque(opaque_); 979 video_weblayer_->layer()->SetContentsOpaque(opaque_);
990 video_weblayer_->SetContentsOpaqueIsFixed(true); 980 video_weblayer_->SetContentsOpaqueIsFixed(true);
991 client_->setWebLayer(video_weblayer_.get()); 981 client_->setWebLayer(video_weblayer_.get());
992 } 982 }
993 983
994 UpdatePlayState(); 984 UpdatePlayState();
995 } 985 }
996 986
997 void WebMediaPlayerImpl::OnPipelineBufferingStateChanged( 987 void WebMediaPlayerImpl::OnBufferingStateChange(BufferingState state) {
998 BufferingState buffering_state) { 988 DVLOG(1) << __FUNCTION__ << "(" << state << ")";
999 DVLOG(1) << __FUNCTION__ << "(" << buffering_state << ")"; 989 DCHECK(main_task_runner_->BelongsToCurrentThread());
1000 990
1001 // Ignore buffering state changes until we've completed all outstanding 991 // Ignore buffering state changes until we've completed all outstanding
1002 // operations. 992 // operations.
1003 if (!pipeline_controller_.IsStable()) 993 if (!pipeline_controller_.IsStable())
1004 return; 994 return;
1005 995
1006 // TODO(scherkus): Handle other buffering states when Pipeline starts using 996 // TODO(scherkus): Handle other buffering states when Pipeline starts using
1007 // them and translate them ready state changes http://crbug.com/144683 997 // them and translate them ready state changes http://crbug.com/144683
1008 DCHECK_EQ(buffering_state, BUFFERING_HAVE_ENOUGH); 998 DCHECK_EQ(state, BUFFERING_HAVE_ENOUGH);
1009 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); 999 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
1010 1000
1011 // Let the DataSource know we have enough data. It may use this information to 1001 // Let the DataSource know we have enough data. It may use this information to
1012 // release unused network connections. 1002 // release unused network connections.
1013 if (data_source_) 1003 if (data_source_)
1014 data_source_->OnBufferingHaveEnough(false); 1004 data_source_->OnBufferingHaveEnough(false);
1015 1005
1016 // Blink expects a timeChanged() in response to a seek(). 1006 // Blink expects a timeChanged() in response to a seek().
1017 if (should_notify_time_changed_) 1007 if (should_notify_time_changed_)
1018 client_->timeChanged(); 1008 client_->timeChanged();
1019 1009
1020 // Once we have enough, start reporting the total memory usage. We'll also 1010 // Once we have enough, start reporting the total memory usage. We'll also
1021 // report once playback starts. 1011 // report once playback starts.
1022 ReportMemoryUsage(); 1012 ReportMemoryUsage();
1023 1013
1024 UpdatePlayState(); 1014 UpdatePlayState();
1025 } 1015 }
1026 1016
1027 void WebMediaPlayerImpl::OnDemuxerOpened() { 1017 void WebMediaPlayerImpl::OnDurationChange() {
1028 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1018 DCHECK(main_task_runner_->BelongsToCurrentThread());
1029 client_->mediaSourceOpened( 1019
1030 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); 1020 // TODO(sandersd): We should call delegate_->DidPlay() with the new duration,
1021 // especially if it changed from <5s to >5s.
1022 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
1023 return;
1024
1025 client_->durationChanged();
1031 } 1026 }
1032 1027
1033 void WebMediaPlayerImpl::OnAddTextTrack( 1028 void WebMediaPlayerImpl::OnAddTextTrack(const TextTrackConfig& config,
1034 const TextTrackConfig& config, 1029 const AddTextTrackDoneCB& done_cb) {
1035 const AddTextTrackDoneCB& done_cb) {
1036 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1030 DCHECK(main_task_runner_->BelongsToCurrentThread());
1037 1031
1038 const WebInbandTextTrackImpl::Kind web_kind = 1032 const WebInbandTextTrackImpl::Kind web_kind =
1039 static_cast<WebInbandTextTrackImpl::Kind>(config.kind()); 1033 static_cast<WebInbandTextTrackImpl::Kind>(config.kind());
1040 const blink::WebString web_label = 1034 const blink::WebString web_label =
1041 blink::WebString::fromUTF8(config.label()); 1035 blink::WebString::fromUTF8(config.label());
1042 const blink::WebString web_language = 1036 const blink::WebString web_language =
1043 blink::WebString::fromUTF8(config.language()); 1037 blink::WebString::fromUTF8(config.language());
1044 const blink::WebString web_id = 1038 const blink::WebString web_id =
1045 blink::WebString::fromUTF8(config.id()); 1039 blink::WebString::fromUTF8(config.id());
1046 1040
1047 std::unique_ptr<WebInbandTextTrackImpl> web_inband_text_track( 1041 std::unique_ptr<WebInbandTextTrackImpl> web_inband_text_track(
1048 new WebInbandTextTrackImpl(web_kind, web_label, web_language, web_id)); 1042 new WebInbandTextTrackImpl(web_kind, web_label, web_language, web_id));
1049 1043
1050 std::unique_ptr<media::TextTrack> text_track(new TextTrackImpl( 1044 std::unique_ptr<media::TextTrack> text_track(new TextTrackImpl(
1051 main_task_runner_, client_, std::move(web_inband_text_track))); 1045 main_task_runner_, client_, std::move(web_inband_text_track)));
1052 1046
1053 done_cb.Run(std::move(text_track)); 1047 done_cb.Run(std::move(text_track));
1054 } 1048 }
1055 1049
1050 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() {
1051 DCHECK(main_task_runner_->BelongsToCurrentThread());
1052
1053 encrypted_client_->didBlockPlaybackWaitingForKey();
1054 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called
1055 // when a key has been successfully added (e.g. OnSessionKeysChange() with
1056 // |has_additional_usable_key| = true). http://crbug.com/461903
1057 encrypted_client_->didResumePlaybackBlockedForKey();
1058 }
1059
1056 void WebMediaPlayerImpl::OnHidden() { 1060 void WebMediaPlayerImpl::OnHidden() {
1057 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1061 DCHECK(main_task_runner_->BelongsToCurrentThread());
1058 UpdatePlayState(); 1062 UpdatePlayState();
1059 } 1063 }
1060 1064
1061 void WebMediaPlayerImpl::OnShown() { 1065 void WebMediaPlayerImpl::OnShown() {
1062 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1066 DCHECK(main_task_runner_->BelongsToCurrentThread());
1063 must_suspend_ = false; 1067 must_suspend_ = false;
1064 UpdatePlayState(); 1068 UpdatePlayState();
1065 } 1069 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 DCHECK(data_source_); 1245 DCHECK(data_source_);
1242 1246
1243 #if !defined(MEDIA_DISABLE_FFMPEG) 1247 #if !defined(MEDIA_DISABLE_FFMPEG)
1244 Demuxer::MediaTracksUpdatedCB media_tracks_updated_cb = 1248 Demuxer::MediaTracksUpdatedCB media_tracks_updated_cb =
1245 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated); 1249 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated);
1246 1250
1247 demuxer_.reset(new FFmpegDemuxer(media_task_runner_, data_source_.get(), 1251 demuxer_.reset(new FFmpegDemuxer(media_task_runner_, data_source_.get(),
1248 encrypted_media_init_data_cb, 1252 encrypted_media_init_data_cb,
1249 media_tracks_updated_cb, media_log_)); 1253 media_tracks_updated_cb, media_log_));
1250 #else 1254 #else
1251 OnPipelineError(PipelineStatus::DEMUXER_ERROR_COULD_NOT_OPEN); 1255 OnError(PipelineStatus::DEMUXER_ERROR_COULD_NOT_OPEN);
1252 return; 1256 return;
1253 #endif 1257 #endif
1254 } else { 1258 } else {
1255 DCHECK(!chunk_demuxer_); 1259 DCHECK(!chunk_demuxer_);
1256 DCHECK(!data_source_); 1260 DCHECK(!data_source_);
1257 1261
1258 chunk_demuxer_ = new ChunkDemuxer( 1262 chunk_demuxer_ = new ChunkDemuxer(
1259 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), 1263 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened),
1260 encrypted_media_init_data_cb, media_log_, true); 1264 encrypted_media_init_data_cb, media_log_, true);
1261 demuxer_.reset(chunk_demuxer_); 1265 demuxer_.reset(chunk_demuxer_);
1262 } 1266 }
1263 1267
1264 // TODO(sandersd): FileSystem objects may also be non-static, but due to our 1268 // TODO(sandersd): FileSystem objects may also be non-static, but due to our
1265 // caching layer such situations are broken already. http://crbug.com/593159 1269 // caching layer such situations are broken already. http://crbug.com/593159
1266 bool is_static = !chunk_demuxer_; 1270 bool is_static = !chunk_demuxer_;
1267 1271
1268 // ... and we're ready to go! 1272 // ... and we're ready to go!
1269 seeking_ = true; 1273 seeking_ = true;
1270 1274
1271 // TODO(sandersd): On Android, defer Start() if the tab is not visible. 1275 // TODO(sandersd): On Android, defer Start() if the tab is not visible.
1272 bool is_streaming = (data_source_ && data_source_->IsStreaming()); 1276 bool is_streaming = (data_source_ && data_source_->IsStreaming());
1273 pipeline_controller_.Start( 1277 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static);
1274 demuxer_.get(), is_streaming, is_static,
1275 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded),
1276 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineMetadata),
1277 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingStateChanged),
1278 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChanged),
1279 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnAddTextTrack),
1280 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnWaitingForDecryptionKey));
1281 } 1278 }
1282 1279
1283 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 1280 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
1284 DVLOG(1) << __FUNCTION__ << "(" << state << ")"; 1281 DVLOG(1) << __FUNCTION__ << "(" << state << ")";
1285 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1282 DCHECK(main_task_runner_->BelongsToCurrentThread());
1286 network_state_ = state; 1283 network_state_ = state;
1287 // Always notify to ensure client has the latest value. 1284 // Always notify to ensure client has the latest value.
1288 client_->networkStateChanged(); 1285 client_->networkStateChanged();
1289 } 1286 }
1290 1287
(...skipping 21 matching lines...) Expand all
1312 base::TimeDelta duration = pipeline_.GetMediaDuration(); 1309 base::TimeDelta duration = pipeline_.GetMediaDuration();
1313 1310
1314 // Return positive infinity if the resource is unbounded. 1311 // Return positive infinity if the resource is unbounded.
1315 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom- media-duration 1312 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom- media-duration
1316 if (duration == kInfiniteDuration()) 1313 if (duration == kInfiniteDuration())
1317 return std::numeric_limits<double>::infinity(); 1314 return std::numeric_limits<double>::infinity();
1318 1315
1319 return duration.InSecondsF(); 1316 return duration.InSecondsF();
1320 } 1317 }
1321 1318
1322 void WebMediaPlayerImpl::OnDurationChanged() {
1323 // TODO(sandersd): We should call delegate_->DidPlay() with the new duration,
1324 // especially if it changed from <5s to >5s.
1325 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
1326 return;
1327
1328 client_->durationChanged();
1329 }
1330
1331 void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { 1319 void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) {
1332 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1320 DCHECK(main_task_runner_->BelongsToCurrentThread());
1333 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); 1321 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing);
1334 1322
1335 if (size == pipeline_metadata_.natural_size) 1323 if (size == pipeline_metadata_.natural_size)
1336 return; 1324 return;
1337 1325
1338 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); 1326 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged");
1339 media_log_->AddEvent( 1327 media_log_->AddEvent(
1340 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); 1328 media_log_->CreateVideoSizeSetEvent(size.width(), size.height()));
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 << ", Video: " << stats.video_memory_usage << ", DataSource: " 1582 << ", Video: " << stats.video_memory_usage << ", DataSource: "
1595 << (data_source_ ? data_source_->GetMemoryUsage() : 0) 1583 << (data_source_ ? data_source_->GetMemoryUsage() : 0)
1596 << ", Demuxer: " << demuxer_memory_usage; 1584 << ", Demuxer: " << demuxer_memory_usage;
1597 1585
1598 const int64_t delta = current_memory_usage - last_reported_memory_usage_; 1586 const int64_t delta = current_memory_usage - last_reported_memory_usage_;
1599 last_reported_memory_usage_ = current_memory_usage; 1587 last_reported_memory_usage_ = current_memory_usage;
1600 adjust_allocated_memory_cb_.Run(delta); 1588 adjust_allocated_memory_cb_.Run(delta);
1601 } 1589 }
1602 1590
1603 } // namespace media 1591 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698