1 // Copyright 2013 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 CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_VIDEO_SINK_H_
6 #define CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_VIDEO_SINK_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/time/time.h"
12 #include "content/common/content_export.h"
13 #include "content/public/renderer/media_stream_sink.h"
16 class VideoCaptureFormat
;
21 class WebMediaStreamTrack
;
26 // This callback is used to deliver video frames.
27 // |estimated_capture_time| - An optional field to provide the capture time of
28 // the delivered video frame. This field usually means the local time when the
29 // video frame was generated. It is possible for this value to be null if this
30 // timing information cannot be determined. There is no gurantee that this
31 // value is accurate. For example video frames from a remote source can only
32 // provide this timing information as an estimate.
33 // |video_frame->timestamp()| gives the presentation timestamp of the video
34 // frame relative to the first frame generated by the corresponding source.
35 // Because a source can start generating frames before a subscriber is added,
36 // the first video frame delivered may not have timestamp equal to 0.
37 typedef base::Callback
<
38 void(const scoped_refptr
<media::VideoFrame
>& video_frame
,
39 const media::VideoCaptureFormat
& format
,
40 const base::TimeTicks
& estimated_capture_time
)>
41 VideoCaptureDeliverFrameCB
;
43 // MediaStreamVideoSink is an interface used for receiving video frames from a
44 // Video Stream Track or a Video Source.
45 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html
46 // All methods calls will be done from the main render thread.
47 class CONTENT_EXPORT MediaStreamVideoSink
: public MediaStreamSink
{
49 // An implementation of MediaStreamVideoSink should call AddToVideoTrack when
50 // it is ready to receive data from a video track. Before the implementation
51 // is destroyed, RemoveFromVideoTrack must be called.
53 // Calls to these methods must be done on the main render thread.
54 // Note that |callback| for frame delivery happens on the IO thread.
56 // Calling RemoveFromVideoTrack also not stop frame delivery through the
57 // callback immediately because it may happen on another thread.
58 // The added callback will be reset on the render thread.
59 static void AddToVideoTrack(MediaStreamVideoSink
* sink
,
60 const VideoCaptureDeliverFrameCB
& callback
,
61 const blink::WebMediaStreamTrack
& track
);
62 static void RemoveFromVideoTrack(MediaStreamVideoSink
* sink
,
63 const blink::WebMediaStreamTrack
& track
);
66 virtual ~MediaStreamVideoSink() {}
70 } // namespace content
72 #endif // CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_VIDEO_SINK_H_