blob: 37f84d1de8e581f1f4f9e581ffddf72f0df40e55 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_VIDEO_SINK_H_
#define CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_VIDEO_SINK_H_
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "content/public/renderer/media_stream_sink.h"
namespace media {
class VideoCaptureFormat;
class VideoFrame;
}
namespace blink {
class WebMediaStreamTrack;
}
namespace content {
// This callback is used to deliver video frames.
// |estimated_capture_time| - An optional field to provide the capture time of
// the delivered video frame. This field usually means the local time when the
// video frame was generated. It is possible for this value to be null if this
// timing information cannot be determined. There is no gurantee that this
// value is accurate. For example video frames from a remote source can only
// provide this timing information as an estimate.
// |video_frame->timestamp()| gives the presentation timestamp of the video
// frame relative to the first frame generated by the corresponding source.
// Because a source can start generating frames before a subscriber is added,
// the first video frame delivered may not have timestamp equal to 0.
typedef base::Callback<
void(const scoped_refptr<media::VideoFrame>& video_frame,
const media::VideoCaptureFormat& format,
const base::TimeTicks& estimated_capture_time)>
VideoCaptureDeliverFrameCB;
// MediaStreamVideoSink is an interface used for receiving video frames from a
// Video Stream Track or a Video Source.
// http://dev.w3.org/2011/webrtc/editor/getusermedia.html
// All methods calls will be done from the main render thread.
class CONTENT_EXPORT MediaStreamVideoSink : public MediaStreamSink {
public:
// An implementation of MediaStreamVideoSink should call AddToVideoTrack when
// it is ready to receive data from a video track. Before the implementation
// is destroyed, RemoveFromVideoTrack must be called.
//
// Calls to these methods must be done on the main render thread.
// Note that |callback| for frame delivery happens on the IO thread.
//
// Calling RemoveFromVideoTrack also not stop frame delivery through the
// callback immediately because it may happen on another thread.
// The added callback will be reset on the render thread.
static void AddToVideoTrack(MediaStreamVideoSink* sink,
const VideoCaptureDeliverFrameCB& callback,
const blink::WebMediaStreamTrack& track);
static void RemoveFromVideoTrack(MediaStreamVideoSink* sink,
const blink::WebMediaStreamTrack& track);
protected:
~MediaStreamVideoSink() override {}
};
} // namespace content
#endif // CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_VIDEO_SINK_H_