[go: nahoru, domu]

Move underflow threshold limits out of the video renderer.

The threshold logic is incorrect when there's no audio track, which
the VideoRendererImpl has no knowledge of, so this logic needs to
live in the RendererImpl.

As a consequence of this, the underflow threshold is now based on
wall clock time instead of media time; which means non-realtime
playback will allow more or less media time to elapse before
underflow occurs.

Exposes a new command line flag --video-underflow-threshold-ms to
allow for experiments varying the threshold for YouTube.

BUG=423801, 470940
TEST=new unittests.

Review URL: https://codereview.chromium.org/1034233002

Cr-Commit-Position: refs/heads/master@{#323599}
diff --git a/media/renderers/renderer_impl.h b/media/renderers/renderer_impl.h
index 03942d52..e0374fb5 100644
--- a/media/renderers/renderer_impl.h
+++ b/media/renderers/renderer_impl.h
@@ -5,6 +5,7 @@
 #ifndef MEDIA_RENDERERS_RENDERER_IMPL_H_
 #define MEDIA_RENDERERS_RENDERER_IMPL_H_
 
+#include "base/cancelable_callback.h"
 #include "base/memory/ref_counted.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/weak_ptr.h"
@@ -64,6 +65,12 @@
   // Helper functions for testing purposes. Must be called before Initialize().
   void DisableUnderflowForTesting();
   void EnableClocklessVideoPlaybackForTesting();
+  void set_time_source_for_testing(TimeSource* time_source) {
+    time_source_ = time_source;
+  }
+  void set_video_underflow_threshold_for_testing(base::TimeDelta threshold) {
+    video_underflow_threshold_ = threshold;
+  }
 
  private:
   enum State {
@@ -171,6 +178,13 @@
   bool underflow_disabled_for_testing_;
   bool clockless_video_playback_enabled_for_testing_;
 
+  // Used to defer underflow for video when audio is present.
+  base::CancelableClosure deferred_underflow_cb_;
+
+  // The amount of time to wait before declaring underflow if the video renderer
+  // runs out of data but the audio renderer still has enough.
+  base::TimeDelta video_underflow_threshold_;
+
   base::WeakPtr<RendererImpl> weak_this_;
   base::WeakPtrFactory<RendererImpl> weak_factory_;