OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // VideoCaptureDevice is the abstract base class for realizing video capture | 5 // VideoCaptureDevice is the abstract base class for realizing video capture |
6 // device support in Chromium. It provides the interface for OS dependent | 6 // device support in Chromium. It provides the interface for OS dependent |
7 // implementations. | 7 // implementations. |
8 // The class is created and functions are invoked on a thread owned by | 8 // The class is created and functions are invoked on a thread owned by |
9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS | 9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS |
10 // specific implementation. | 10 // specific implementation. |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "media/mojo/interfaces/image_capture.mojom.h" | 34 #include "media/mojo/interfaces/image_capture.mojom.h" |
35 #include "mojo/public/cpp/bindings/array.h" | 35 #include "mojo/public/cpp/bindings/array.h" |
36 #include "ui/gfx/gpu_memory_buffer.h" | 36 #include "ui/gfx/gpu_memory_buffer.h" |
37 | 37 |
38 namespace tracked_objects { | 38 namespace tracked_objects { |
39 class Location; | 39 class Location; |
40 } // namespace tracked_objects | 40 } // namespace tracked_objects |
41 | 41 |
42 namespace media { | 42 namespace media { |
43 | 43 |
44 class CAPTURE_EXPORT VideoCaptureDevice { | 44 class CAPTURE_EXPORT ConsumerFeedbackObserver { |
mcasas
2016/12/03 01:35:48
As a general naming comment, "ConsumerFeedbackObse
chfremer
2016/12/05 18:17:00
Excellent point.
miu@ suggested "feedback" instead
| |
45 public: | |
46 virtual ~ConsumerFeedbackObserver() {} | |
47 | |
48 // During processing of a video frame, consumers may report back their | |
49 // utilization level to the source device. The device may use this information | |
50 // to adjust the rate of data it pushes out. Values are interpreted as | |
51 // follows: | |
52 // Less than 0.0 is meaningless and should be ignored. 1.0 indicates a | |
53 // maximum sustainable utilization. Greater than 1.0 indicates the consumer | |
54 // is likely to stall or drop frames if the data volume is not reduced. | |
55 // | |
56 // Example: In a system that encodes and transmits video frames over the | |
57 // network, this value can be used to indicate whether sufficient CPU | |
58 // is available for encoding and/or sufficient bandwidth is available for | |
59 // transmission over the network. The maximum of the two utilization | |
60 // measurements would be used as feedback. | |
61 // | |
62 // The parameter |frame_feedback_id| must match a |frame_feedback_id| | |
63 // previously sent out by the VideoCaptureDevice we are giving feedback about. | |
64 // It is used to indicate which particular frame the reported utilization | |
65 // corresponds to. | |
66 virtual void OnConsumerReportingUtilization(int frame_feedback_id, | |
67 double utilization) {} | |
mcasas
2016/12/03 01:35:48
I'm dubious as to |frame_feedback_id|. Although
I
chfremer
2016/12/05 18:17:00
Good point. And I share the feeling.
I also agree
mcasas
2016/12/05 18:26:44
Yup.
| |
68 | |
69 static constexpr double kNoUtilizationRecorded = -1.0; | |
70 }; | |
71 | |
72 class CAPTURE_EXPORT VideoCaptureDevice : public ConsumerFeedbackObserver { | |
45 public: | 73 public: |
46 | 74 |
47 // Interface defining the methods that clients of VideoCapture must have. It | 75 // Interface defining the methods that clients of VideoCapture must have. It |
48 // is actually two-in-one: clients may implement OnIncomingCapturedData() or | 76 // is actually two-in-one: clients may implement OnIncomingCapturedData() or |
49 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. | 77 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. |
50 // All clients must implement OnError(). | 78 // All clients must implement OnError(). |
51 class CAPTURE_EXPORT Client { | 79 class CAPTURE_EXPORT Client { |
52 public: | 80 public: |
53 // Memory buffer returned by Client::ReserveOutputBuffer(). | 81 // Memory buffer returned by Client::ReserveOutputBuffer(). |
54 class CAPTURE_EXPORT Buffer { | 82 class CAPTURE_EXPORT Buffer { |
55 public: | 83 public: |
56 virtual ~Buffer() = 0; | 84 virtual ~Buffer() = 0; |
57 virtual int id() const = 0; | 85 virtual int id() const = 0; |
86 virtual int frame_feedback_id() const = 0; | |
58 virtual gfx::Size dimensions() const = 0; | 87 virtual gfx::Size dimensions() const = 0; |
59 virtual size_t mapped_size() const = 0; | 88 virtual size_t mapped_size() const = 0; |
60 virtual void* data(int plane) = 0; | 89 virtual void* data(int plane) = 0; |
61 void* data() { return data(0); } | 90 void* data() { return data(0); } |
62 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) | 91 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) |
63 virtual base::FileDescriptor AsPlatformFile() = 0; | 92 virtual base::FileDescriptor AsPlatformFile() = 0; |
64 #endif | 93 #endif |
65 virtual bool IsBackedByVideoFrame() const = 0; | 94 virtual bool IsBackedByVideoFrame() const = 0; |
66 virtual scoped_refptr<VideoFrame> GetVideoFrame() = 0; | 95 virtual scoped_refptr<VideoFrame> GetVideoFrame() = 0; |
67 }; | 96 }; |
68 | 97 |
69 virtual ~Client() {} | 98 virtual ~Client() {} |
70 | 99 |
71 // Captured a new video frame, data for which is pointed to by |data|. | 100 // Captured a new video frame, data for which is pointed to by |data|. |
72 // | 101 // |
73 // The format of the frame is described by |frame_format|, and is assumed to | 102 // The format of the frame is described by |frame_format|, and is assumed to |
74 // be tightly packed. This method will try to reserve an output buffer and | 103 // be tightly packed. This method will try to reserve an output buffer and |
75 // copy from |data| into the output buffer. If no output buffer is | 104 // copy from |data| into the output buffer. If no output buffer is |
76 // available, the frame will be silently dropped. |reference_time| is | 105 // available, the frame will be silently dropped. |reference_time| is |
77 // system clock time when we detect the capture happens, it is used for | 106 // system clock time when we detect the capture happens, it is used for |
78 // Audio/Video sync, not an exact presentation time for playout, because it | 107 // Audio/Video sync, not an exact presentation time for playout, because it |
79 // could contain noise. |timestamp| measures the ideal time span between the | 108 // could contain noise. |timestamp| measures the ideal time span between the |
80 // first frame in the stream and the current frame; however, the time source | 109 // first frame in the stream and the current frame; however, the time source |
81 // is determined by the platform's device driver and is often not the system | 110 // is determined by the platform's device driver and is often not the system |
82 // clock, or even has a drift with respect to system clock. | 111 // clock, or even has a drift with respect to system clock. |
112 // |frame_feedback_id| is an identifier that allows clients to refer back to | |
113 // this particular frame when reporting consumer feedback via | |
114 // OnConsumerReportingUtilization(). This identifier is needed because | |
115 // frames are consumed asynchronously and multiple frames can be "in flight" | |
116 // at the same time. | |
83 virtual void OnIncomingCapturedData(const uint8_t* data, | 117 virtual void OnIncomingCapturedData(const uint8_t* data, |
84 int length, | 118 int length, |
85 const VideoCaptureFormat& frame_format, | 119 const VideoCaptureFormat& frame_format, |
86 int clockwise_rotation, | 120 int clockwise_rotation, |
87 base::TimeTicks reference_time, | 121 base::TimeTicks reference_time, |
88 base::TimeDelta timestamp) = 0; | 122 base::TimeDelta timestamp, |
123 int frame_feedback_id = 0) = 0; | |
89 | 124 |
90 // Reserve an output buffer into which contents can be captured directly. | 125 // Reserve an output buffer into which contents can be captured directly. |
91 // The returned Buffer will always be allocated with a memory size suitable | 126 // The returned Buffer will always be allocated with a memory size suitable |
92 // for holding a packed video frame with pixels of |format| format, of | 127 // for holding a packed video frame with pixels of |format| format, of |
93 // |dimensions| frame dimensions. It is permissible for |dimensions| to be | 128 // |dimensions| frame dimensions. It is permissible for |dimensions| to be |
94 // zero; in which case the returned Buffer does not guarantee memory | 129 // zero; in which case the returned Buffer does not guarantee memory |
95 // backing, but functions as a reservation for external input for the | 130 // backing, but functions as a reservation for external input for the |
96 // purposes of buffer throttling. | 131 // purposes of buffer throttling. |
97 // | 132 // |
98 // The output buffer stays reserved and mapped for use until the Buffer | 133 // The output buffer stays reserved and mapped for use until the Buffer |
99 // object is destroyed or returned. | 134 // object is destroyed or returned. |
100 virtual std::unique_ptr<Buffer> ReserveOutputBuffer( | 135 virtual std::unique_ptr<Buffer> ReserveOutputBuffer( |
101 const gfx::Size& dimensions, | 136 const gfx::Size& dimensions, |
102 VideoPixelFormat format, | 137 VideoPixelFormat format, |
103 VideoPixelStorage storage) = 0; | 138 VideoPixelStorage storage, |
139 int frame_feedback_id) = 0; | |
104 | 140 |
105 // Captured new video data, held in |frame| or |buffer|, respectively for | 141 // Captured new video data, held in |frame| or |buffer|, respectively for |
106 // OnIncomingCapturedVideoFrame() and OnIncomingCapturedBuffer(). | 142 // OnIncomingCapturedVideoFrame() and OnIncomingCapturedBuffer(). |
107 // | 143 // |
108 // In both cases, as the frame is backed by a reservation returned by | 144 // In both cases, as the frame is backed by a reservation returned by |
109 // ReserveOutputBuffer(), delivery is guaranteed and will require no | 145 // ReserveOutputBuffer(), delivery is guaranteed and will require no |
110 // additional copies in the browser process. | 146 // additional copies in the browser process. |
111 // See OnIncomingCapturedData for details of |reference_time| and | 147 // See OnIncomingCapturedData for details of |reference_time| and |
112 // |timestamp|. | 148 // |timestamp|. |
113 // TODO(chfremer): Consider removing one of the two in order to simplify the | 149 // TODO(chfremer): Consider removing one of the two in order to simplify the |
114 // interface. | 150 // interface. |
115 virtual void OnIncomingCapturedBuffer( | 151 virtual void OnIncomingCapturedBuffer( |
116 std::unique_ptr<Buffer> buffer, | 152 std::unique_ptr<Buffer> buffer, |
117 const VideoCaptureFormat& frame_format, | 153 const VideoCaptureFormat& frame_format, |
118 base::TimeTicks reference_time, | 154 base::TimeTicks reference_time, |
119 base::TimeDelta timestamp) = 0; | 155 base::TimeDelta timestamp) = 0; |
120 virtual void OnIncomingCapturedVideoFrame( | 156 virtual void OnIncomingCapturedVideoFrame( |
121 std::unique_ptr<Buffer> buffer, | 157 std::unique_ptr<Buffer> buffer, |
122 scoped_refptr<VideoFrame> frame) = 0; | 158 scoped_refptr<VideoFrame> frame) = 0; |
123 | 159 |
124 // Attempts to reserve the same Buffer provided in the last call to one of | 160 // Attempts to reserve the same Buffer provided in the last call to one of |
125 // the OnIncomingCapturedXXX() methods. This will fail if the content of the | 161 // the OnIncomingCapturedXXX() methods. This will fail if the content of the |
126 // Buffer has not been preserved, or if the |dimensions|, |format|, or | 162 // Buffer has not been preserved, or if the |dimensions|, |format|, or |
127 // |storage| disagree with how it was reserved via ReserveOutputBuffer(). | 163 // |storage| disagree with how it was reserved via ReserveOutputBuffer(). |
128 // When this operation fails, nullptr will be returned. | 164 // When this operation fails, nullptr will be returned. |
129 virtual std::unique_ptr<Buffer> ResurrectLastOutputBuffer( | 165 virtual std::unique_ptr<Buffer> ResurrectLastOutputBuffer( |
130 const gfx::Size& dimensions, | 166 const gfx::Size& dimensions, |
131 VideoPixelFormat format, | 167 VideoPixelFormat format, |
132 VideoPixelStorage storage) = 0; | 168 VideoPixelStorage storage, |
169 int new_frame_feedback_id) = 0; | |
133 | 170 |
134 // An error has occurred that cannot be handled and VideoCaptureDevice must | 171 // An error has occurred that cannot be handled and VideoCaptureDevice must |
135 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. | 172 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. |
136 virtual void OnError(const tracked_objects::Location& from_here, | 173 virtual void OnError(const tracked_objects::Location& from_here, |
137 const std::string& reason) = 0; | 174 const std::string& reason) = 0; |
138 | 175 |
139 // VideoCaptureDevice requests the |message| to be logged. | 176 // VideoCaptureDevice requests the |message| to be logged. |
140 virtual void OnLog(const std::string& message) {} | 177 virtual void OnLog(const std::string& message) {} |
141 | 178 |
142 // Returns the current buffer pool utilization, in the range 0.0 (no buffers | 179 // Returns the current buffer pool utilization, in the range 0.0 (no buffers |
143 // are in use by producers or consumers) to 1.0 (all buffers are in use). | 180 // are in use by producers or consumers) to 1.0 (all buffers are in use). |
144 virtual double GetBufferPoolUtilization() const = 0; | 181 virtual double GetBufferPoolUtilization() const = 0; |
145 }; | 182 }; |
146 | 183 |
147 virtual ~VideoCaptureDevice(); | 184 ~VideoCaptureDevice() override; |
148 | 185 |
149 // Prepares the video capturer for use. StopAndDeAllocate() must be called | 186 // Prepares the video capturer for use. StopAndDeAllocate() must be called |
150 // before the object is deleted. | 187 // before the object is deleted. |
151 virtual void AllocateAndStart(const VideoCaptureParams& params, | 188 virtual void AllocateAndStart(const VideoCaptureParams& params, |
152 std::unique_ptr<Client> client) = 0; | 189 std::unique_ptr<Client> client) = 0; |
153 | 190 |
154 // In cases where the video capturer self-pauses (e.g., a screen capturer | 191 // In cases where the video capturer self-pauses (e.g., a screen capturer |
155 // where the screen's content has not changed in a while), consumers may call | 192 // where the screen's content has not changed in a while), consumers may call |
156 // this to request a "refresh frame" be delivered to the Client. This is used | 193 // this to request a "refresh frame" be delivered to the Client. This is used |
157 // in a number of circumstances, such as: | 194 // in a number of circumstances, such as: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 267 |
231 private: | 268 private: |
232 // Gets the power line frequency from the current system time zone if this is | 269 // Gets the power line frequency from the current system time zone if this is |
233 // defined, otherwise returns 0. | 270 // defined, otherwise returns 0. |
234 PowerLineFrequency GetPowerLineFrequencyForLocation() const; | 271 PowerLineFrequency GetPowerLineFrequencyForLocation() const; |
235 }; | 272 }; |
236 | 273 |
237 } // namespace media | 274 } // namespace media |
238 | 275 |
239 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ | 276 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |