blob: 760530176d13ac0682a4ca5b1fb7821956652ee7 [file] [log] [blame]
mcasasbf728d72015-09-05 04:46:131// Copyright 2015 The Chromium Authors. All rights reserved.
hubbea5ed06c2015-02-25 00:01:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
mcasasbf728d72015-09-05 04:46:135#ifndef MEDIA_BASE_VIDEO_CAPTURER_SOURCE_H_
6#define MEDIA_BASE_VIDEO_CAPTURER_SOURCE_H_
hubbea5ed06c2015-02-25 00:01:257
8#include <string>
9#include <vector>
10
mcasasbf728d72015-09-05 04:46:1311#include "base/callback.h"
hubbea5ed06c2015-02-25 00:01:2512#include "base/memory/ref_counted.h"
mcasasbf728d72015-09-05 04:46:1313#include "base/time/time.h"
hubbea5ed06c2015-02-25 00:01:2514#include "media/base/media_export.h"
15#include "media/base/video_capture_types.h"
hubbea5ed06c2015-02-25 00:01:2516
17namespace media {
18
mcasasbf728d72015-09-05 04:46:1319class VideoFrame;
20
21// VideoCapturerSource is an interface representing the source for captured
22// video. An implementation will periodically call the frame callback with new
23// video frames.
hubbea5ed06c2015-02-25 00:01:2524class MEDIA_EXPORT VideoCapturerSource {
25 public:
26 virtual ~VideoCapturerSource();
27
28 // This callback is used to deliver video frames.
29 //
30 // |estimated_capture_time| - The capture time of the delivered video
31 // frame. This field represents the local time at which either: 1) the frame
32 // was generated, if it was done so locally; or 2) the targeted play-out time
33 // of the frame, if it was generated from a remote source. Either way, an
34 // implementation should not present the frame before this point-in-time. This
35 // value is NOT a high-resolution timestamp, and so it should not be used as a
36 // presentation time; but, instead, it should be used for buffering playback
37 // and for A/V synchronization purposes. NOTE: It is possible for this value
38 // to be null if the current implementation lacks this timing information.
39 //
40 // |video_frame->timestamp()| gives the presentation timestamp of the video
41 // frame relative to the first frame generated by the corresponding source.
42 // Because a source can start generating frames before a subscriber is added,
43 // the first video frame delivered may not have timestamp equal to 0.
mcasasbf728d72015-09-05 04:46:1344 using VideoCaptureDeliverFrameCB =
45 base::Callback<void(const scoped_refptr<media::VideoFrame>& video_frame,
46 base::TimeTicks estimated_capture_time)>;
hubbea5ed06c2015-02-25 00:01:2547
mcasasbf728d72015-09-05 04:46:1348 using VideoCaptureDeviceFormatsCB =
49 base::Callback<void(const media::VideoCaptureFormats&)>;
hubbea5ed06c2015-02-25 00:01:2550
mcasasbf728d72015-09-05 04:46:1351 using RunningCallback = base::Callback<void(bool)>;
hubbea5ed06c2015-02-25 00:01:2552
53 // Collects the formats that can currently be used.
54 // |max_requested_height|, |max_requested_width|, and
55 // |max_requested_frame_rate| is used by Tab and Screen capture to decide what
56 // resolution/framerate to generate. |callback| is triggered when the formats
57 // have been collected.
58 virtual void GetCurrentSupportedFormats(
59 int max_requested_width,
60 int max_requested_height,
61 double max_requested_frame_rate,
62 const VideoCaptureDeviceFormatsCB& callback) = 0;
63
mcasasbf728d72015-09-05 04:46:1364 // Starts capturing frames using the capture |params|. |new_frame_callback| is
65 // triggered when a new video frame is available.
hubbea5ed06c2015-02-25 00:01:2566 // If capturing is started successfully then |running_callback| will be
67 // called with a parameter of true. Note that some implementations may
68 // simply reject StartCapture (by calling running_callback with a false
69 // argument) if called with the wrong task runner.
70 // If capturing fails to start or stopped due to an external event then
71 // |running_callback| will be called with a parameter of false.
72 // |running_callback| will always be called on the same thread as the
73 // StartCapture.
74 virtual void StartCapture(
75 const media::VideoCaptureParams& params,
76 const VideoCaptureDeliverFrameCB& new_frame_callback,
hubbea5ed06c2015-02-25 00:01:2577 const RunningCallback& running_callback) = 0;
78
emircandbe511a2016-03-26 00:46:0179 // Asks source to send a refresh frame. In cases where source does not provide
80 // a continuous rate of new frames (e.g. canvas capture, screen capture where
81 // the screen's content has not changed in a while), consumers may request a
82 // "refresh frame" to be delivered. For instance, this would be needed when
83 // a new sink is added to a MediaStreamTrack.
miu1c98a2e2016-09-29 01:18:3584 //
emircandbe511a2016-03-26 00:46:0185 // The default implementation is a no-op and implementations are not required
86 // to honor this request. If they decide to and capturing is started
87 // successfully, then |new_frame_callback| should be called with a frame.
miu1c98a2e2016-09-29 01:18:3588 //
89 // Note: This should only be called after StartCapture() and before
90 // StopCapture(). Otherwise, its behavior is undefined.
emircandbe511a2016-03-26 00:46:0191 virtual void RequestRefreshFrame() {}
92
miu1c98a2e2016-09-29 01:18:3593 // Optionally suspends frame delivery. The source may or may not honor this
94 // request. Thus, the caller cannot assume frame delivery will actually
95 // stop. Even if frame delivery is suspended, this might not take effect
96 // immediately.
97 //
98 // The purpose of this is to allow minimizing resource usage while
99 // there are no frame consumers present.
100 //
101 // Note: This should only be called after StartCapture() and before
102 // StopCapture(). Otherwise, its behavior is undefined.
103 virtual void MaybeSuspend() {}
104
105 // Resumes frame delivery, if it was suspended. If frame delivery was not
106 // suspended, this is a no-op, and frame delivery will continue.
107 //
108 // Note: This should only be called after StartCapture() and before
109 // StopCapture(). Otherwise, its behavior is undefined.
110 virtual void Resume() {}
111
hubbea5ed06c2015-02-25 00:01:25112 // Stops capturing frames and clears all callbacks including the
113 // SupportedFormatsCallback callback. Note that queued frame callbacks
114 // may still occur after this call, so the caller must take care to
115 // use refcounted or weak references in |new_frame_callback|.
116 virtual void StopCapture() = 0;
117};
118
119} // namespace media
120
mcasasbf728d72015-09-05 04:46:13121#endif // MEDIA_BASE_VIDEO_CAPTURER_SOURCE_H_