[go: nahoru, domu]

Fix processing of multiple stream status changes by renderer

Typically renderer needs to do Flush + StartPlaying in response to
stream status change (i.e. when stream gets enabled or disabled). But
since Flush is an async operation we might get another status change
of the same stream, while the renderer is still handling the previous
one. In the past renderer has simply ignored status changes while
another status change was processed. But that was problematic, since
we couldn't guarantee that the renderer status will be correct after
stream has been enabled/disabled very quickly a few times. This CL
fixes that issue by postponing status changes handling if necessary,
instead of dropping those notifications.

BUG=678031

Review-Url: https://codereview.chromium.org/2605473002
Cr-Commit-Position: refs/heads/master@{#442762}
diff --git a/media/renderers/renderer_impl.h b/media/renderers/renderer_impl.h
index 07ea224..46fb71c 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 <list>
 #include <memory>
 #include <vector>
 
@@ -60,7 +61,7 @@
   void SetVolume(float volume) final;
   base::TimeDelta GetMediaTime() final;
 
-  void RestartStreamPlayback(DemuxerStream* stream,
+  void OnStreamStatusChanged(DemuxerStream* stream,
                              bool enabled,
                              base::TimeDelta time);
 
@@ -146,6 +147,8 @@
   void OnVideoNaturalSizeChange(const gfx::Size& size);
   void OnVideoOpacityChange(bool opaque);
 
+  void OnStreamRestartCompleted();
+
   State state_;
 
   // Task runner used to execute pipeline tasks.
@@ -197,6 +200,7 @@
 
   bool restarting_audio_ = false;
   bool restarting_video_ = false;
+  std::list<base::Closure> pending_stream_status_notifications_;
 
   base::WeakPtr<RendererImpl> weak_this_;
   base::WeakPtrFactory<RendererImpl> weak_factory_;