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

Unified Diff: media/blink/video_frame_compositor.h

Issue 1053113002: Prime the landing pad for the new video rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix cast. Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/video_renderer_sink.h ('k') | media/blink/video_frame_compositor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/video_frame_compositor.h
diff --git a/media/blink/video_frame_compositor.h b/media/blink/video_frame_compositor.h
index 9e46663e34f74ef3d51ba96269b03addac9259f2..02b6077f9605ff25029cfb08da5adefc8c3808e6 100644
--- a/media/blink/video_frame_compositor.h
+++ b/media/blink/video_frame_compositor.h
@@ -7,24 +7,45 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
+#include "base/single_thread_task_runner.h"
+#include "base/synchronization/lock.h"
#include "cc/layers/video_frame_provider.h"
#include "media/base/media_export.h"
+#include "media/base/video_renderer_sink.h"
#include "ui/gfx/geometry/size.h"
namespace media {
class VideoFrame;
-// VideoFrameCompositor handles incoming frames by notifying the compositor and
-// dispatching callbacks when detecting changes in video frames.
+// VideoFrameCompositor acts as a bridge between the media and cc layers for
+// rendering video frames. I.e. a media::VideoRenderer will talk to this class
+// from the media side, while a cc::VideoFrameProvider::Client will talk to it
+// from the cc side.
//
-// Typical usage is to deliver ready-to-be-displayed video frames to
-// UpdateCurrentFrame() so that VideoFrameCompositor can take care of tracking
-// changes in video frames and firing callbacks as needed.
+// This class is responsible for requesting new frames from a video renderer in
+// response to requests from the VFP::Client. Since the VFP::Client may stop
+// issuing requests in response to visibility changes it is also responsible for
+// ensuring the "freshness" of the current frame for programmatic frame
+// requests; e.g., Canvas.drawImage() requests
//
-// VideoFrameCompositor must live on the same thread as the compositor.
+// This class is also responsible for detecting frames dropped by the compositor
+// after rendering and signaling that information to a RenderCallback. It
+// detects frames not dropped by verifying each GetCurrentFrame() is followed
+// by a PutCurrentFrame() before the next UpdateCurrentFrame() call.
+//
+// VideoRenderSink::RenderCallback implementations must call Start() and Stop()
+// once new frames are expected or are no longer expected to be ready; this data
+// is relayed to the compositor to avoid extraneous callbacks.
+//
+// VideoFrameCompositor must live on the same thread as the compositor, though
+// it may be constructed on any thread.
class MEDIA_EXPORT VideoFrameCompositor
- : NON_EXPORTED_BASE(public cc::VideoFrameProvider) {
+ : public VideoRendererSink,
+ NON_EXPORTED_BASE(public cc::VideoFrameProvider) {
public:
+ // |compositor_task_runner| is the task runner on which this class will live,
+ // though it may be constructed on any thread.
+ //
// |natural_size_changed_cb| is run with the new natural size of the video
// frame whenever a change in natural size is detected. It is not called the
// first time UpdateCurrentFrame() is called. Run on the same thread as the
@@ -34,31 +55,62 @@ class MEDIA_EXPORT VideoFrameCompositor
// called the first time UpdateCurrentFrame() is called. Run on the same
// thread as the caller of UpdateCurrentFrame().
//
- // TODO(scherkus): Investigate the inconsistency between the callbacks with
+ // TODO(dalecurtis): Investigate the inconsistency between the callbacks with
// respect to why we don't call |natural_size_changed_cb| on the first frame.
// I suspect it was for historical reasons that no longer make sense.
VideoFrameCompositor(
+ const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner,
const base::Callback<void(gfx::Size)>& natural_size_changed_cb,
const base::Callback<void(bool)>& opacity_changed_cb);
+
+ // Destruction must happen on the compositor thread; Stop() must have been
+ // called before destruction starts.
~VideoFrameCompositor() override;
- // cc::VideoFrameProvider implementation.
+ // Returns |current_frame_| if it was refreshed recently; otherwise, if
+ // |callback_| is available, requests a new frame and returns that one.
+ //
+ // This is required for programmatic frame requests where the compositor may
+ // have stopped issuing UpdateCurrentFrame() callbacks in response to
+ // visibility changes in the output layer.
+ scoped_refptr<VideoFrame> GetCurrentFrameAndUpdateIfStale();
+
+ // cc::VideoFrameProvider implementation. These methods must be called on the
+ // |compositor_task_runner_|.
void SetVideoFrameProviderClient(
cc::VideoFrameProvider::Client* client) override;
+ bool UpdateCurrentFrame(base::TimeTicks deadline_min,
+ base::TimeTicks deadline_max) override;
scoped_refptr<VideoFrame> GetCurrentFrame() override;
- void PutCurrentFrame(const scoped_refptr<VideoFrame>& frame) override;
+ void PutCurrentFrame() override;
- // Updates the current frame and notifies the compositor.
- void UpdateCurrentFrame(const scoped_refptr<VideoFrame>& frame);
+ // VideoRendererSink implementation. These methods must be called from the
+ // same thread (typically the media thread).
+ void Start(RenderCallback* callback) override;
+ void Stop() override;
+ void PaintFrameUsingOldRenderingPath(
+ const scoped_refptr<VideoFrame>& frame) override;
private:
+ // Called on the compositor thread to start or stop rendering if rendering was
+ // previously started or stopped before we had a |callback_|.
+ void OnRendererStateUpdate();
+
+ scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
+
+ // These callbacks are executed on the compositor thread.
base::Callback<void(gfx::Size)> natural_size_changed_cb_;
base::Callback<void(bool)> opacity_changed_cb_;
+ // These values are only set and read on the compositor thread.
cc::VideoFrameProvider::Client* client_;
-
scoped_refptr<VideoFrame> current_frame_;
+ // These values are updated and read from the media and compositor threads.
+ base::Lock lock_;
+ bool rendering_;
+ VideoRendererSink::RenderCallback* callback_;
+
DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor);
};
« no previous file with comments | « media/base/video_renderer_sink.h ('k') | media/blink/video_frame_compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698