1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_VIDEO_RENDERER_SINK_H_
6 #define MEDIA_BASE_VIDEO_RENDERER_SINK_H_
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/time/time.h"
12 #include "media/base/media_export.h"
13 #include "media/base/video_frame.h"
17 // VideoRendererSink is an interface representing the end-point for rendered
18 // video frames. An implementation is expected to periodically call Render() on
20 class MEDIA_EXPORT VideoRendererSink
{
22 class RenderCallback
{
24 // Returns a VideoFrame for rendering which should be displayed within the
25 // presentation interval [|deadline_min|, |deadline_max|]. Returns NULL if
26 // no frame or no new frame (since the last Render() call) is available for
27 // rendering within the requested interval. Intervals are expected to be
28 // regular, contiguous, and monotonically increasing. Irregular intervals
29 // may affect the rendering decisions made by the underlying callback.
31 // If |background_rendering| is true, the VideoRenderSink is pumping
32 // callbacks at a lower frequency than normal and the results of the
33 // Render() call may not be used.
34 virtual scoped_refptr
<VideoFrame
> Render(base::TimeTicks deadline_min
,
35 base::TimeTicks deadline_max
,
36 bool background_rendering
) = 0;
38 // Called by the sink when a VideoFrame previously returned via Render() was
39 // not actually rendered. Must be called before the next Render() call.
40 virtual void OnFrameDropped() = 0;
42 virtual ~RenderCallback() {}
45 // Starts video rendering. See RenderCallback for more details. Must be
46 // called to receive Render() callbacks. Callbacks may start immediately, so
47 // |callback| must be ready to receive callbacks before calling Start().
48 virtual void Start(RenderCallback
* callback
) = 0;
50 // Stops video rendering, waits for any outstanding calls to the |callback|
51 // given to Start() to complete before returning. No new calls to |callback|
52 // will be issued after this method returns. May be used as a means of power
53 // conservation by the sink implementation, so clients should call this
54 // liberally if no new frames are expected.
55 virtual void Stop() = 0;
57 // Instead of using a callback driven rendering path, allow clients to paint
58 // frames as they see fit without regard for the compositor.
59 // TODO(dalecurtis): This should be nuked once experiments show the new path
60 // is amazing and the old path is not! http://crbug.com/439548
61 virtual void PaintFrameUsingOldRenderingPath(
62 const scoped_refptr
<VideoFrame
>& frame
) = 0;
64 // TODO(dalecurtis): We may need OnSizeChanged() and OnOpacityChanged()
65 // methods on this interface if background rendering is handled inside of
66 // the media layer instead of by VideoFrameCompositor.
68 virtual ~VideoRendererSink() {}
73 #endif // MEDIA_BASE_VIDEO_RENDERER_SINK_H_