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

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

Issue 269002: Report stalled event correctly for <video> (Closed)
Patch Set: comments Created 11 years, 2 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 (c) 2008-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008-2009 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/glue/webmediaplayer_impl.h" 5 #include "webkit/glue/webmediaplayer_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "media/base/media_format.h" 9 #include "media/base/media_format.h"
10 #include "media/filters/ffmpeg_audio_decoder.h" 10 #include "media/filters/ffmpeg_audio_decoder.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void WebMediaPlayerImpl::Proxy::PipelineEndedCallback() { 116 void WebMediaPlayerImpl::Proxy::PipelineEndedCallback() {
117 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 117 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
118 &WebMediaPlayerImpl::Proxy::PipelineEndedTask)); 118 &WebMediaPlayerImpl::Proxy::PipelineEndedTask));
119 } 119 }
120 120
121 void WebMediaPlayerImpl::Proxy::PipelineErrorCallback() { 121 void WebMediaPlayerImpl::Proxy::PipelineErrorCallback() {
122 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 122 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
123 &WebMediaPlayerImpl::Proxy::PipelineErrorTask)); 123 &WebMediaPlayerImpl::Proxy::PipelineErrorTask));
124 } 124 }
125 125
126 void WebMediaPlayerImpl::Proxy::NetworkEventCallback() {
127 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
128 &WebMediaPlayerImpl::Proxy::NetworkEventTask));
129 }
130
126 void WebMediaPlayerImpl::Proxy::RepaintTask() { 131 void WebMediaPlayerImpl::Proxy::RepaintTask() {
127 DCHECK(MessageLoop::current() == render_loop_); 132 DCHECK(MessageLoop::current() == render_loop_);
128 { 133 {
129 AutoLock auto_lock(lock_); 134 AutoLock auto_lock(lock_);
130 --outstanding_repaints_; 135 --outstanding_repaints_;
131 DCHECK_GE(outstanding_repaints_, 0); 136 DCHECK_GE(outstanding_repaints_, 0);
132 } 137 }
133 if (webmediaplayer_) { 138 if (webmediaplayer_) {
134 webmediaplayer_->Repaint(); 139 webmediaplayer_->Repaint();
135 } 140 }
(...skipping 20 matching lines...) Expand all
156 } 161 }
157 } 162 }
158 163
159 void WebMediaPlayerImpl::Proxy::PipelineErrorTask() { 164 void WebMediaPlayerImpl::Proxy::PipelineErrorTask() {
160 DCHECK(MessageLoop::current() == render_loop_); 165 DCHECK(MessageLoop::current() == render_loop_);
161 if (webmediaplayer_) { 166 if (webmediaplayer_) {
162 webmediaplayer_->OnPipelineError(); 167 webmediaplayer_->OnPipelineError();
163 } 168 }
164 } 169 }
165 170
171 void WebMediaPlayerImpl::Proxy::NetworkEventTask() {
172 DCHECK(MessageLoop::current() == render_loop_);
173 if (webmediaplayer_) {
174 webmediaplayer_->OnNetworkEvent();
175 }
176 }
177
166 ///////////////////////////////////////////////////////////////////////////// 178 /////////////////////////////////////////////////////////////////////////////
167 // WebMediaPlayerImpl implementation 179 // WebMediaPlayerImpl implementation
168 180
169 WebMediaPlayerImpl::WebMediaPlayerImpl(WebKit::WebMediaPlayerClient* client, 181 WebMediaPlayerImpl::WebMediaPlayerImpl(WebKit::WebMediaPlayerClient* client,
170 media::FilterFactoryCollection* factory) 182 media::FilterFactoryCollection* factory)
171 : network_state_(WebKit::WebMediaPlayer::Empty), 183 : network_state_(WebKit::WebMediaPlayer::Empty),
172 ready_state_(WebKit::WebMediaPlayer::HaveNothing), 184 ready_state_(WebKit::WebMediaPlayer::HaveNothing),
173 main_loop_(NULL), 185 main_loop_(NULL),
174 filter_factory_(factory), 186 filter_factory_(factory),
175 pipeline_thread_("PipelineThread"), 187 pipeline_thread_("PipelineThread"),
(...skipping 16 matching lines...) Expand all
192 main_loop_->AddDestructionObserver(this); 204 main_loop_->AddDestructionObserver(this);
193 205
194 // Creates the proxy. 206 // Creates the proxy.
195 proxy_ = new Proxy(main_loop_, this); 207 proxy_ = new Proxy(main_loop_, this);
196 208
197 // Set our pipeline callbacks. 209 // Set our pipeline callbacks.
198 pipeline_->SetPipelineEndedCallback(NewCallback(proxy_.get(), 210 pipeline_->SetPipelineEndedCallback(NewCallback(proxy_.get(),
199 &WebMediaPlayerImpl::Proxy::PipelineEndedCallback)); 211 &WebMediaPlayerImpl::Proxy::PipelineEndedCallback));
200 pipeline_->SetPipelineErrorCallback(NewCallback(proxy_.get(), 212 pipeline_->SetPipelineErrorCallback(NewCallback(proxy_.get(),
201 &WebMediaPlayerImpl::Proxy::PipelineErrorCallback)); 213 &WebMediaPlayerImpl::Proxy::PipelineErrorCallback));
214 pipeline_->SetNetworkEventCallback(NewCallback(proxy_.get(),
215 &WebMediaPlayerImpl::Proxy::NetworkEventCallback));
202 216
203 // Add in the default filter factories. 217 // Add in the default filter factories.
204 filter_factory_->AddFactory(media::FFmpegDemuxer::CreateFilterFactory()); 218 filter_factory_->AddFactory(media::FFmpegDemuxer::CreateFilterFactory());
205 filter_factory_->AddFactory(media::FFmpegAudioDecoder::CreateFactory()); 219 filter_factory_->AddFactory(media::FFmpegAudioDecoder::CreateFactory());
206 filter_factory_->AddFactory(media::FFmpegVideoDecoder::CreateFactory()); 220 filter_factory_->AddFactory(media::FFmpegVideoDecoder::CreateFactory());
207 filter_factory_->AddFactory(media::NullAudioRenderer::CreateFilterFactory()); 221 filter_factory_->AddFactory(media::NullAudioRenderer::CreateFilterFactory());
208 filter_factory_->AddFactory(VideoRendererImpl::CreateFactory(proxy_)); 222 filter_factory_->AddFactory(VideoRendererImpl::CreateFactory(proxy_));
209 } 223 }
210 224
211 WebMediaPlayerImpl::~WebMediaPlayerImpl() { 225 WebMediaPlayerImpl::~WebMediaPlayerImpl() {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 512
499 void WebMediaPlayerImpl::Repaint() { 513 void WebMediaPlayerImpl::Repaint() {
500 DCHECK(MessageLoop::current() == main_loop_); 514 DCHECK(MessageLoop::current() == main_loop_);
501 GetClient()->repaint(); 515 GetClient()->repaint();
502 } 516 }
503 517
504 void WebMediaPlayerImpl::OnPipelineInitialize() { 518 void WebMediaPlayerImpl::OnPipelineInitialize() {
505 DCHECK(MessageLoop::current() == main_loop_); 519 DCHECK(MessageLoop::current() == main_loop_);
506 if (pipeline_->GetError() == media::PIPELINE_OK) { 520 if (pipeline_->GetError() == media::PIPELINE_OK) {
507 // Only keep one time range starting from 0. 521 // Only keep one time range starting from 0.
508 WebKit::WebTimeRanges new_buffered(static_cast<size_t>(1)); 522 WebKit::WebTimeRanges new_buffered(1u);
509 new_buffered[0].start = 0.0f; 523 new_buffered[0].start = 0.0f;
510 new_buffered[0].end = 524 new_buffered[0].end =
511 static_cast<float>(pipeline_->GetBufferedTime().InSecondsF()); 525 static_cast<float>(pipeline_->GetDuration().InSecondsF());
512 buffered_.swap(new_buffered); 526 buffered_.swap(new_buffered);
513 527
514 // Since we have initialized the pipeline, say we have everything. 528 // Since we have initialized the pipeline, say we have everything.
515 // TODO(hclam): change this to report the correct status. 529 // TODO(hclam): change this to report the correct status.
516 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata); 530 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata);
517 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); 531 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData);
518 if (pipeline_->IsLoaded()) { 532 if (pipeline_->IsLoaded()) {
519 SetNetworkState(WebKit::WebMediaPlayer::Loaded); 533 SetNetworkState(WebKit::WebMediaPlayer::Loaded);
520 } else { 534 } else {
521 SetNetworkState(WebKit::WebMediaPlayer::Loading); 535 SetNetworkState(WebKit::WebMediaPlayer::Loading);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 case media::PIPELINE_ERROR_AUDIO_HARDWARE: 590 case media::PIPELINE_ERROR_AUDIO_HARDWARE:
577 // Decode error. 591 // Decode error.
578 SetNetworkState(WebMediaPlayer::DecodeError); 592 SetNetworkState(WebMediaPlayer::DecodeError);
579 break; 593 break;
580 } 594 }
581 595
582 // Repaint to trigger UI update. 596 // Repaint to trigger UI update.
583 Repaint(); 597 Repaint();
584 } 598 }
585 599
600 void WebMediaPlayerImpl::OnNetworkEvent() {
601 DCHECK(MessageLoop::current() == main_loop_);
602 if (pipeline_->GetError() == media::PIPELINE_OK) {
603 if (pipeline_->IsNetworkActive())
604 SetNetworkState(WebKit::WebMediaPlayer::Loading);
605 else
606 SetNetworkState(WebKit::WebMediaPlayer::Idle);
607 }
608 }
609
586 void WebMediaPlayerImpl::SetNetworkState( 610 void WebMediaPlayerImpl::SetNetworkState(
587 WebKit::WebMediaPlayer::NetworkState state) { 611 WebKit::WebMediaPlayer::NetworkState state) {
588 DCHECK(MessageLoop::current() == main_loop_); 612 DCHECK(MessageLoop::current() == main_loop_);
589 // Always notify to ensure client has the latest value. 613 // Always notify to ensure client has the latest value.
590 network_state_ = state; 614 network_state_ = state;
591 GetClient()->networkStateChanged(); 615 GetClient()->networkStateChanged();
592 } 616 }
593 617
594 void WebMediaPlayerImpl::SetReadyState( 618 void WebMediaPlayerImpl::SetReadyState(
595 WebKit::WebMediaPlayer::ReadyState state) { 619 WebKit::WebMediaPlayer::ReadyState state) {
(...skipping 19 matching lines...) Expand all
615 } 639 }
616 } 640 }
617 641
618 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { 642 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() {
619 DCHECK(MessageLoop::current() == main_loop_); 643 DCHECK(MessageLoop::current() == main_loop_);
620 DCHECK(client_); 644 DCHECK(client_);
621 return client_; 645 return client_;
622 } 646 }
623 647
624 } // namespace webkit_glue 648 } // namespace webkit_glue
OLDNEW
« webkit/glue/media/buffered_data_source.cc ('K') | « webkit/glue/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698