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 <string> | 17 #include <string> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/basictypes.h" | 20 #include "webrtc/base/basictypes.h" |
21 #include "webrtc/base/criticalsection.h" | 21 #include "webrtc/base/criticalsection.h" |
22 #include "webrtc/media/base/videosourceinterface.h" | |
23 #include "webrtc/base/messagehandler.h" | 22 #include "webrtc/base/messagehandler.h" |
24 #include "webrtc/base/rollingaccumulator.h" | 23 #include "webrtc/base/rollingaccumulator.h" |
25 #include "webrtc/base/scoped_ptr.h" | 24 #include "webrtc/base/scoped_ptr.h" |
26 #include "webrtc/base/sigslot.h" | 25 #include "webrtc/base/sigslot.h" |
27 #include "webrtc/base/thread.h" | 26 #include "webrtc/base/thread.h" |
28 #include "webrtc/base/timing.h" | 27 #include "webrtc/base/timing.h" |
29 #include "webrtc/media/base/mediachannel.h" | 28 #include "webrtc/media/base/mediachannel.h" |
30 #include "webrtc/media/base/videoadapter.h" | 29 #include "webrtc/media/base/videoadapter.h" |
31 #include "webrtc/media/base/videobroadcaster.h" | |
32 #include "webrtc/media/base/videocommon.h" | 30 #include "webrtc/media/base/videocommon.h" |
33 #include "webrtc/media/base/videoframefactory.h" | 31 #include "webrtc/media/base/videoframefactory.h" |
34 #include "webrtc/media/devices/devicemanager.h" | 32 #include "webrtc/media/devices/devicemanager.h" |
35 | 33 |
36 | 34 |
37 namespace cricket { | 35 namespace cricket { |
38 | 36 |
39 // Current state of the capturer. | 37 // Current state of the capturer. |
40 // TODO(hellner): CS_NO_DEVICE is an error code not a capture state. Separate | 38 // TODO(hellner): CS_NO_DEVICE is an error code not a capture state. Separate |
41 // error codes and states. | 39 // error codes and states. |
(...skipping 26 matching lines...) Expand all Loading... |
68 // fourcc, pixel_width, and pixel_height should keep the same over frames. | 66 // fourcc, pixel_width, and pixel_height should keep the same over frames. |
69 int width; // in number of pixels | 67 int width; // in number of pixels |
70 int height; // in number of pixels | 68 int height; // in number of pixels |
71 uint32_t fourcc; // compression | 69 uint32_t fourcc; // compression |
72 uint32_t pixel_width; // width of a pixel, default is 1 | 70 uint32_t pixel_width; // width of a pixel, default is 1 |
73 uint32_t pixel_height; // height of a pixel, default is 1 | 71 uint32_t pixel_height; // height of a pixel, default is 1 |
74 int64_t time_stamp; // timestamp of when the frame was captured, in unix | 72 int64_t time_stamp; // timestamp of when the frame was captured, in unix |
75 // time with nanosecond units. | 73 // time with nanosecond units. |
76 uint32_t data_size; // number of bytes of the frame data | 74 uint32_t data_size; // number of bytes of the frame data |
77 | 75 |
78 webrtc::VideoRotation rotation; // rotation in degrees of the frame. | 76 webrtc::VideoRotation rotation; // rotation in degrees of the frame. |
79 | 77 |
80 void* data; // pointer to the frame data. This object allocates the | 78 void* data; // pointer to the frame data. This object allocates the |
81 // memory or points to an existing memory. | 79 // memory or points to an existing memory. |
82 | 80 |
83 private: | 81 private: |
84 RTC_DISALLOW_COPY_AND_ASSIGN(CapturedFrame); | 82 RTC_DISALLOW_COPY_AND_ASSIGN(CapturedFrame); |
85 }; | 83 }; |
86 | 84 |
87 // VideoCapturer is an abstract class that defines the interfaces for video | 85 // VideoCapturer is an abstract class that defines the interfaces for video |
88 // capturing. The subclasses implement the video capturer for various types of | 86 // capturing. The subclasses implement the video capturer for various types of |
(...skipping 14 matching lines...) Expand all Loading... |
103 // video_adapter()->OnOutputFormatRequest(desired_encoding_format) | 101 // video_adapter()->OnOutputFormatRequest(desired_encoding_format) |
104 // Start() | 102 // Start() |
105 // GetCaptureFormat() optionally | 103 // GetCaptureFormat() optionally |
106 // Stop() | 104 // Stop() |
107 // | 105 // |
108 // Assumption: | 106 // Assumption: |
109 // The Start() and Stop() methods are called by a single thread (E.g., the | 107 // The Start() and Stop() methods are called by a single thread (E.g., the |
110 // media engine thread). Hence, the VideoCapture subclasses dont need to be | 108 // media engine thread). Hence, the VideoCapture subclasses dont need to be |
111 // thread safe. | 109 // thread safe. |
112 // | 110 // |
113 class VideoCapturer : public sigslot::has_slots<>, | 111 class VideoCapturer |
114 public rtc::MessageHandler, | 112 : public sigslot::has_slots<>, |
115 public rtc::VideoSourceInterface<cricket::VideoFrame> { | 113 public rtc::MessageHandler { |
116 public: | 114 public: |
117 // All signals are marshalled to |thread| or the creating thread if | 115 // All signals are marshalled to |thread| or the creating thread if |
118 // none is provided. | 116 // none is provided. |
119 VideoCapturer(); | 117 VideoCapturer(); |
120 explicit VideoCapturer(rtc::Thread* thread); | 118 explicit VideoCapturer(rtc::Thread* thread); |
121 virtual ~VideoCapturer() {} | 119 virtual ~VideoCapturer() {} |
122 | 120 |
123 // Gets the id of the underlying device, which is available after the capturer | 121 // Gets the id of the underlying device, which is available after the capturer |
124 // is initialized. Can be used to determine if two capturers reference the | 122 // is initialized. Can be used to determine if two capturers reference the |
125 // same device. | 123 // same device. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // When muting, produce black frames then pause the camera. | 190 // When muting, produce black frames then pause the camera. |
193 // When unmuting, start the camera. Camera starts unmuted. | 191 // When unmuting, start the camera. Camera starts unmuted. |
194 virtual bool MuteToBlackThenPause(bool muted); | 192 virtual bool MuteToBlackThenPause(bool muted); |
195 virtual bool IsMuted() const { | 193 virtual bool IsMuted() const { |
196 return muted_; | 194 return muted_; |
197 } | 195 } |
198 CaptureState capture_state() const { | 196 CaptureState capture_state() const { |
199 return capture_state_; | 197 return capture_state_; |
200 } | 198 } |
201 | 199 |
| 200 // Tells videocapturer whether to apply the pending rotation. By default, the |
| 201 // rotation is applied and the generated frame is up right. When set to false, |
| 202 // generated frames will carry the rotation information from |
| 203 // SetCaptureRotation. Return value indicates whether this operation succeeds. |
| 204 virtual bool SetApplyRotation(bool enable); |
202 virtual bool GetApplyRotation() { return apply_rotation_; } | 205 virtual bool GetApplyRotation() { return apply_rotation_; } |
203 | 206 |
204 // Returns true if the capturer is screencasting. This can be used to | 207 // Returns true if the capturer is screencasting. This can be used to |
205 // implement screencast specific behavior. | 208 // implement screencast specific behavior. |
206 virtual bool IsScreencast() const = 0; | 209 virtual bool IsScreencast() const = 0; |
207 | 210 |
208 // Caps the VideoCapturer's format according to max_format. It can e.g. be | 211 // Caps the VideoCapturer's format according to max_format. It can e.g. be |
209 // used to prevent cameras from capturing at a resolution or framerate that | 212 // used to prevent cameras from capturing at a resolution or framerate that |
210 // the capturer is capable of but not performing satisfactorily at. | 213 // the capturer is capable of but not performing satisfactorily at. |
211 // The capping is an upper bound for each component of the capturing format. | 214 // The capping is an upper bound for each component of the capturing format. |
(...skipping 18 matching lines...) Expand all Loading... |
230 // Signal all capture state changes that are not a direct result of calling | 233 // Signal all capture state changes that are not a direct result of calling |
231 // Start(). | 234 // Start(). |
232 sigslot::signal2<VideoCapturer*, CaptureState> SignalStateChange; | 235 sigslot::signal2<VideoCapturer*, CaptureState> SignalStateChange; |
233 // Frame callbacks are multithreaded to allow disconnect and connect to be | 236 // Frame callbacks are multithreaded to allow disconnect and connect to be |
234 // called concurrently. It also ensures that it is safe to call disconnect | 237 // called concurrently. It also ensures that it is safe to call disconnect |
235 // at any time which is needed since the signal may be called from an | 238 // at any time which is needed since the signal may be called from an |
236 // unmarshalled thread owned by the VideoCapturer. | 239 // unmarshalled thread owned by the VideoCapturer. |
237 // Signal the captured frame to downstream. | 240 // Signal the captured frame to downstream. |
238 sigslot::signal2<VideoCapturer*, const CapturedFrame*, | 241 sigslot::signal2<VideoCapturer*, const CapturedFrame*, |
239 sigslot::multi_threaded_local> SignalFrameCaptured; | 242 sigslot::multi_threaded_local> SignalFrameCaptured; |
| 243 // Signal the captured and possibly adapted frame to downstream consumers |
| 244 // such as the encoder. |
| 245 sigslot::signal2<VideoCapturer*, const VideoFrame*, |
| 246 sigslot::multi_threaded_local> SignalVideoFrame; |
240 | 247 |
241 // If true, run video adaptation. By default, video adaptation is enabled | 248 // If true, run video adaptation. By default, video adaptation is enabled |
242 // and users must call video_adapter()->OnOutputFormatRequest() | 249 // and users must call video_adapter()->OnOutputFormatRequest() |
243 // to receive frames. | 250 // to receive frames. |
244 bool enable_video_adapter() const { return enable_video_adapter_; } | 251 bool enable_video_adapter() const { return enable_video_adapter_; } |
245 void set_enable_video_adapter(bool enable_video_adapter) { | 252 void set_enable_video_adapter(bool enable_video_adapter) { |
246 enable_video_adapter_ = enable_video_adapter; | 253 enable_video_adapter_ = enable_video_adapter; |
247 } | 254 } |
248 | 255 |
249 CoordinatedVideoAdapter* video_adapter() { return &video_adapter_; } | 256 CoordinatedVideoAdapter* video_adapter() { return &video_adapter_; } |
250 const CoordinatedVideoAdapter* video_adapter() const { | 257 const CoordinatedVideoAdapter* video_adapter() const { |
251 return &video_adapter_; | 258 return &video_adapter_; |
252 } | 259 } |
253 | 260 |
254 // Takes ownership. | 261 // Takes ownership. |
255 void set_frame_factory(VideoFrameFactory* frame_factory); | 262 void set_frame_factory(VideoFrameFactory* frame_factory); |
256 | 263 |
257 // Gets statistics for tracked variables recorded since the last call to | 264 // Gets statistics for tracked variables recorded since the last call to |
258 // GetStats. Note that calling GetStats resets any gathered data so it | 265 // GetStats. Note that calling GetStats resets any gathered data so it |
259 // should be called only periodically to log statistics. | 266 // should be called only periodically to log statistics. |
260 void GetStats(VariableInfo<int>* adapt_drop_stats, | 267 void GetStats(VariableInfo<int>* adapt_drop_stats, |
261 VariableInfo<int>* effect_drop_stats, | 268 VariableInfo<int>* effect_drop_stats, |
262 VariableInfo<double>* frame_time_stats, | 269 VariableInfo<double>* frame_time_stats, |
263 VideoFormat* last_captured_frame_format); | 270 VideoFormat* last_captured_frame_format); |
264 | 271 |
265 // Implements VideoSourceInterface | |
266 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | |
267 const rtc::VideoSinkWants& wants) override; | |
268 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; | |
269 | |
270 protected: | 272 protected: |
271 // OnSinkWantsChanged can be overridden to change the default behavior | |
272 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink. | |
273 virtual void OnSinkWantsChanged(const rtc::VideoSinkWants& wants); | |
274 | |
275 // Callback attached to SignalFrameCaptured where SignalVideoFrames is called. | 273 // Callback attached to SignalFrameCaptured where SignalVideoFrames is called. |
276 void OnFrameCaptured(VideoCapturer* video_capturer, | 274 void OnFrameCaptured(VideoCapturer* video_capturer, |
277 const CapturedFrame* captured_frame); | 275 const CapturedFrame* captured_frame); |
278 void SetCaptureState(CaptureState state); | 276 void SetCaptureState(CaptureState state); |
279 | 277 |
280 // Marshals SignalStateChange onto thread_. | 278 // Marshals SignalStateChange onto thread_. |
281 void OnMessage(rtc::Message* message); | 279 void OnMessage(rtc::Message* message); |
282 | 280 |
283 // subclasses override this virtual method to provide a vector of fourccs, in | 281 // subclasses override this virtual method to provide a vector of fourccs, in |
284 // order of preference, that are expected by the media engine. | 282 // order of preference, that are expected by the media engine. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 337 |
340 int ratio_w_; // View resolution. e.g. 1280 x 720. | 338 int ratio_w_; // View resolution. e.g. 1280 x 720. |
341 int ratio_h_; | 339 int ratio_h_; |
342 bool enable_camera_list_; | 340 bool enable_camera_list_; |
343 bool square_pixel_aspect_ratio_; // Enable scaling to square pixels. | 341 bool square_pixel_aspect_ratio_; // Enable scaling to square pixels. |
344 int scaled_width_; // Current output size from ComputeScale. | 342 int scaled_width_; // Current output size from ComputeScale. |
345 int scaled_height_; | 343 int scaled_height_; |
346 bool muted_; | 344 bool muted_; |
347 int black_frame_count_down_; | 345 int black_frame_count_down_; |
348 | 346 |
349 rtc::VideoBroadcaster broadcaster_; | |
350 bool enable_video_adapter_; | 347 bool enable_video_adapter_; |
351 CoordinatedVideoAdapter video_adapter_; | 348 CoordinatedVideoAdapter video_adapter_; |
352 | 349 |
353 rtc::Timing frame_length_time_reporter_; | 350 rtc::Timing frame_length_time_reporter_; |
354 rtc::CriticalSection frame_stats_crit_; | 351 rtc::CriticalSection frame_stats_crit_; |
355 | 352 |
356 int adapt_frame_drops_; | 353 int adapt_frame_drops_; |
357 rtc::RollingAccumulator<int> adapt_frame_drops_data_; | 354 rtc::RollingAccumulator<int> adapt_frame_drops_data_; |
358 double previous_frame_time_; | 355 double previous_frame_time_; |
359 rtc::RollingAccumulator<double> frame_time_data_; | 356 rtc::RollingAccumulator<double> frame_time_data_; |
360 // The captured frame format before potential adapation. | 357 // The captured frame format before potential adapation. |
361 VideoFormat last_captured_frame_format_; | 358 VideoFormat last_captured_frame_format_; |
362 | 359 |
363 // Whether capturer should apply rotation to the frame before signaling it. | 360 // Whether capturer should apply rotation to the frame before signaling it. |
364 bool apply_rotation_; | 361 bool apply_rotation_; |
365 | 362 |
366 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); | 363 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); |
367 }; | 364 }; |
368 | 365 |
369 } // namespace cricket | 366 } // namespace cricket |
370 | 367 |
371 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ | 368 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ |
OLD | NEW |