OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 // Declaration of abstract class VideoCapturer | 11 // Declaration of abstract class VideoCapturer |
12 | 12 |
13 #ifndef WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ | 13 #ifndef WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ |
14 #define WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ | 14 #define WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <memory> | 17 #include <memory> |
18 #include <string> | 18 #include <string> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "webrtc/base/basictypes.h" | 21 #include "webrtc/base/basictypes.h" |
22 #include "webrtc/base/constructormagic.h" | 22 #include "webrtc/base/constructormagic.h" |
23 #include "webrtc/base/criticalsection.h" | 23 #include "webrtc/base/criticalsection.h" |
24 #include "webrtc/media/base/videosourceinterface.h" | 24 #include "webrtc/media/base/videosourceinterface.h" |
25 #include "webrtc/base/sigslot.h" | 25 #include "webrtc/base/sigslot.h" |
26 #include "webrtc/base/thread_checker.h" | 26 #include "webrtc/base/thread_checker.h" |
27 #include "webrtc/base/timestampaligner.h" | 27 #include "webrtc/media/base/adaptedvideosource.h" |
28 #include "webrtc/media/base/videoadapter.h" | |
29 #include "webrtc/media/base/videobroadcaster.h" | |
30 #include "webrtc/media/base/videocommon.h" | 28 #include "webrtc/media/base/videocommon.h" |
31 #include "webrtc/media/base/videoframefactory.h" | 29 #include "webrtc/media/base/videoframefactory.h" |
32 | 30 |
33 | 31 |
34 namespace cricket { | 32 namespace cricket { |
35 | 33 |
36 // Current state of the capturer. | 34 // Current state of the capturer. |
37 enum CaptureState { | 35 enum CaptureState { |
38 CS_STOPPED, // The capturer has been stopped or hasn't started yet. | 36 CS_STOPPED, // The capturer has been stopped or hasn't started yet. |
39 CS_STARTING, // The capturer is in the process of starting. Note, it may | 37 CS_STARTING, // The capturer is in the process of starting. Note, it may |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // called concurrently. It also ensures that it is safe to call disconnect | 194 // called concurrently. It also ensures that it is safe to call disconnect |
197 // at any time which is needed since the signal may be called from an | 195 // at any time which is needed since the signal may be called from an |
198 // unmarshalled thread owned by the VideoCapturer. | 196 // unmarshalled thread owned by the VideoCapturer. |
199 // Signal the captured frame to downstream. | 197 // Signal the captured frame to downstream. |
200 sigslot::signal2<VideoCapturer*, const CapturedFrame*, | 198 sigslot::signal2<VideoCapturer*, const CapturedFrame*, |
201 sigslot::multi_threaded_local> SignalFrameCaptured; | 199 sigslot::multi_threaded_local> SignalFrameCaptured; |
202 | 200 |
203 // If true, run video adaptation. By default, video adaptation is enabled | 201 // If true, run video adaptation. By default, video adaptation is enabled |
204 // and users must call video_adapter()->OnOutputFormatRequest() | 202 // and users must call video_adapter()->OnOutputFormatRequest() |
205 // to receive frames. | 203 // to receive frames. |
206 bool enable_video_adapter() const { return enable_video_adapter_; } | 204 bool enable_video_adapter() const; |
207 void set_enable_video_adapter(bool enable_video_adapter) { | 205 void set_enable_video_adapter(bool enable_video_adapter); |
208 enable_video_adapter_ = enable_video_adapter; | |
209 } | |
210 | 206 |
211 // Takes ownership. | 207 // Takes ownership. |
212 void set_frame_factory(VideoFrameFactory* frame_factory); | 208 void set_frame_factory(VideoFrameFactory* frame_factory); |
213 | 209 |
214 bool GetInputSize(int* width, int* height); | 210 bool GetInputSize(int* width, int* height); |
215 | 211 |
216 // Implements VideoSourceInterface | 212 // Implements VideoSourceInterface |
217 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | 213 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
218 const rtc::VideoSinkWants& wants) override; | 214 const rtc::VideoSinkWants& wants) override; |
219 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; | 215 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; |
220 | 216 |
221 protected: | 217 protected: |
222 // OnSinkWantsChanged can be overridden to change the default behavior | 218 // OnSinkWantsChanged can be overridden to change the default behavior |
223 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink. | 219 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink. |
224 virtual void OnSinkWantsChanged(const rtc::VideoSinkWants& wants); | 220 virtual void OnSinkWantsChanged(const rtc::VideoSinkWants& wants); |
225 | 221 |
226 // Reports the appropriate frame size after adaptation. Returns true | |
227 // if a frame is wanted. Returns false if there are no interested | |
228 // sinks, or if the VideoAdapter decides to drop the frame. | |
229 | |
230 // This function also implements timestamp translation/filtering. | |
231 // |camera_time_ns| is the camera's timestamp for the captured | |
232 // frame; it is expected to have good accuracy, but it may use an | |
233 // arbitrary epoch and a small possibly free-running with a frequency | |
234 // slightly different from the system clock. |system_time_us| is the | |
235 // monotonic system time (in the same scale as rtc::TimeMicros) when | |
236 // the frame was captured; the application is expected to read the | |
237 // system time as soon as possible after frame capture, but it may | |
238 // suffer scheduling jitter or poor system clock resolution. The | |
239 // output |translated_camera_time_us| is a combined timestamp, | |
240 // taking advantage of the supposedly higher accuracy in the camera | |
241 // timestamp, but using the same epoch and frequency as system time. | |
242 bool AdaptFrame(int width, | |
243 int height, | |
244 int64_t camera_time_us, | |
245 int64_t system_time_us, | |
246 int* out_width, | |
247 int* out_height, | |
248 int* crop_width, | |
249 int* crop_height, | |
250 int* crop_x, | |
251 int* crop_y, | |
252 int64_t* translated_camera_time_us); | |
253 | |
254 // Callback attached to SignalFrameCaptured where SignalVideoFrames is called. | 222 // Callback attached to SignalFrameCaptured where SignalVideoFrames is called. |
255 void OnFrameCaptured(VideoCapturer* video_capturer, | 223 void OnFrameCaptured(VideoCapturer* video_capturer, |
256 const CapturedFrame* captured_frame); | 224 const CapturedFrame* captured_frame); |
257 | 225 |
258 // Called when a frame has been captured and converted to a | 226 // Called when a frame has been captured and converted to a |
259 // VideoFrame. OnFrame can be called directly by an implementation | 227 // VideoFrame. OnFrame can be called directly by an implementation |
260 // that does not use SignalFrameCaptured or OnFrameCaptured. The | 228 // that does not use SignalFrameCaptured or OnFrameCaptured. The |
261 // orig_width and orig_height are used only to produce stats. | 229 // orig_width and orig_height are used only to produce stats. |
262 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height); | 230 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height); |
263 | 231 |
264 VideoAdapter* video_adapter() { return &video_adapter_; } | 232 VideoAdapter* video_adapter() { return adapted_source_.video_adapter(); } |
265 | 233 |
266 void SetCaptureState(CaptureState state); | 234 void SetCaptureState(CaptureState state); |
267 | 235 |
268 // subclasses override this virtual method to provide a vector of fourccs, in | 236 // subclasses override this virtual method to provide a vector of fourccs, in |
269 // order of preference, that are expected by the media engine. | 237 // order of preference, that are expected by the media engine. |
270 virtual bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) = 0; | 238 virtual bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) = 0; |
271 | 239 |
272 // mutators to set private attributes | 240 // mutators to set private attributes |
273 void SetId(const std::string& id) { | 241 void SetId(const std::string& id) { |
274 id_ = id; | 242 id_ = id; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 std::unique_ptr<VideoFrameFactory> frame_factory_; | 274 std::unique_ptr<VideoFrameFactory> frame_factory_; |
307 std::unique_ptr<VideoFormat> capture_format_; | 275 std::unique_ptr<VideoFormat> capture_format_; |
308 std::vector<VideoFormat> supported_formats_; | 276 std::vector<VideoFormat> supported_formats_; |
309 std::unique_ptr<VideoFormat> max_format_; | 277 std::unique_ptr<VideoFormat> max_format_; |
310 std::vector<VideoFormat> filtered_supported_formats_; | 278 std::vector<VideoFormat> filtered_supported_formats_; |
311 | 279 |
312 bool enable_camera_list_; | 280 bool enable_camera_list_; |
313 int scaled_width_; // Current output size from ComputeScale. | 281 int scaled_width_; // Current output size from ComputeScale. |
314 int scaled_height_; | 282 int scaled_height_; |
315 | 283 |
316 rtc::VideoBroadcaster broadcaster_; | 284 rtc::AdaptedVideoSource adapted_source_; |
317 bool enable_video_adapter_; | |
318 VideoAdapter video_adapter_; | |
319 | 285 |
320 rtc::CriticalSection frame_stats_crit_; | 286 rtc::CriticalSection frame_stats_crit_; |
321 // The captured frame size before potential adapation. | 287 // The captured frame size before potential adapation. |
322 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; | 288 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; |
323 int input_width_ GUARDED_BY(frame_stats_crit_); | 289 int input_width_ GUARDED_BY(frame_stats_crit_); |
324 int input_height_ GUARDED_BY(frame_stats_crit_); | 290 int input_height_ GUARDED_BY(frame_stats_crit_); |
325 | 291 |
326 // Whether capturer should apply rotation to the frame before signaling it. | 292 // Whether capturer should apply rotation to the frame before signaling it. |
327 bool apply_rotation_; | 293 bool apply_rotation_; |
328 | 294 |
329 // State for the timestamp translation. | 295 // State for the timestamp translation. |
330 rtc::TimestampAligner timestamp_aligner_; | 296 rtc::TimestampAligner timestamp_aligner_; |
331 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); | 297 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); |
332 }; | 298 }; |
333 | 299 |
334 } // namespace cricket | 300 } // namespace cricket |
335 | 301 |
336 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ | 302 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ |
OLD | NEW |