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

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

Issue 164032: Disallow setting the rate to values that would cause busy loops (< 1/16x) or ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | « no previous file | no next file » | 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) 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"
11 #include "media/filters/ffmpeg_demuxer.h" 11 #include "media/filters/ffmpeg_demuxer.h"
12 #include "media/filters/ffmpeg_video_decoder.h" 12 #include "media/filters/ffmpeg_video_decoder.h"
13 #include "media/filters/null_audio_renderer.h" 13 #include "media/filters/null_audio_renderer.h"
14 #include "webkit/api/public/WebRect.h" 14 #include "webkit/api/public/WebRect.h"
15 #include "webkit/api/public/WebSize.h" 15 #include "webkit/api/public/WebSize.h"
16 #include "webkit/api/public/WebURL.h" 16 #include "webkit/api/public/WebURL.h"
17 #include "webkit/glue/media/video_renderer_impl.h" 17 #include "webkit/glue/media/video_renderer_impl.h"
18 18
19 using WebKit::WebCanvas; 19 using WebKit::WebCanvas;
20 using WebKit::WebRect; 20 using WebKit::WebRect;
21 using WebKit::WebSize; 21 using WebKit::WebSize;
22 22
23 namespace { 23 namespace {
24 24
25 // Limits the maximum outstanding repaints posted on render thread. 25 // Limits the maximum outstanding repaints posted on render thread.
26 // This number of 50 is a guess, it does not take too much memory on the task 26 // This number of 50 is a guess, it does not take too much memory on the task
27 // queue but gives up a pretty good latency on repaint. 27 // queue but gives up a pretty good latency on repaint.
28 const int kMaxOutstandingRepaints = 50; 28 const int kMaxOutstandingRepaints = 50;
29 29
30 // Limits the range of playback rate.
31 //
32 // TODO(kylep): Revisit these.
33 //
34 // Vista has substantially lower performance than XP or Windows7. If you speed
35 // up a video too much, it can't keep up, and rendering stops updating except on
36 // the time bar. For really high speeds, audio becomes a bottleneck and we just
37 // use up the data we have, which may not achieve the speed requested, but will
38 // not crash the tab.
39 //
40 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems
41 // like a busy loop). It gets unresponsive, although its not completely dead.
42 //
43 // Also our timers are not very accurate (especially for ogg), which becomes
44 // evident at low speeds and on Vista. Since other speeds are risky and outside
45 // the norms, we think 1/16x to 16x is a safe and useful range for now.
46 const float kMinRate = 0.0625f;
47 const float kMaxRate = 16.0f;
48
30 } // namespace 49 } // namespace
31 50
32 namespace webkit_glue { 51 namespace webkit_glue {
33 52
34 ///////////////////////////////////////////////////////////////////////////// 53 /////////////////////////////////////////////////////////////////////////////
35 // WebMediaPlayerImpl::Proxy implementation 54 // WebMediaPlayerImpl::Proxy implementation
36 55
37 WebMediaPlayerImpl::Proxy::Proxy(MessageLoop* render_loop, 56 WebMediaPlayerImpl::Proxy::Proxy(MessageLoop* render_loop,
38 WebMediaPlayerImpl* webmediaplayer) 57 WebMediaPlayerImpl* webmediaplayer)
39 : render_loop_(render_loop), 58 : render_loop_(render_loop),
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 void WebMediaPlayerImpl::setEndTime(float seconds) { 260 void WebMediaPlayerImpl::setEndTime(float seconds) {
242 DCHECK(MessageLoop::current() == main_loop_); 261 DCHECK(MessageLoop::current() == main_loop_);
243 262
244 // TODO(hclam): add method call when it has been implemented. 263 // TODO(hclam): add method call when it has been implemented.
245 return; 264 return;
246 } 265 }
247 266
248 void WebMediaPlayerImpl::setRate(float rate) { 267 void WebMediaPlayerImpl::setRate(float rate) {
249 DCHECK(MessageLoop::current() == main_loop_); 268 DCHECK(MessageLoop::current() == main_loop_);
250 269
270 // TODO(kylep): Remove when support for negatives is added. Also, modify the
271 // following checks so rewind uses reasonable values also.
272 if (rate < 0.0f)
273 return;
274
275 // Limit rates to reasonable values by clamping.
276 if (rate != 0.0f) {
277 if (rate < kMinRate)
278 rate = kMinRate;
279 else if (rate > kMaxRate)
280 rate = kMaxRate;
281 }
282
251 playback_rate_ = rate; 283 playback_rate_ = rate;
252 if (!paused_) { 284 if (!paused_) {
253 pipeline_->SetPlaybackRate(rate); 285 pipeline_->SetPlaybackRate(rate);
254 } 286 }
255 } 287 }
256 288
257 void WebMediaPlayerImpl::setVolume(float volume) { 289 void WebMediaPlayerImpl::setVolume(float volume) {
258 DCHECK(MessageLoop::current() == main_loop_); 290 DCHECK(MessageLoop::current() == main_loop_);
259 291
260 pipeline_->SetVolume(volume); 292 pipeline_->SetVolume(volume);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 519 }
488 } 520 }
489 521
490 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { 522 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() {
491 DCHECK(MessageLoop::current() == main_loop_); 523 DCHECK(MessageLoop::current() == main_loop_);
492 DCHECK(client_); 524 DCHECK(client_);
493 return client_; 525 return client_;
494 } 526 }
495 527
496 } // namespace webkit_glue 528 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698