Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: webrtc/media/base/videocapturer.h

Issue 2315663002: Make cricket::VideoFrame inherit webrtc::VideoFrame. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 10 matching lines...) Expand all
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/base/timestampaligner.h"
28 #include "webrtc/media/base/videoadapter.h" 28 #include "webrtc/media/base/videoadapter.h"
29 #include "webrtc/media/base/videobroadcaster.h" 29 #include "webrtc/media/base/videobroadcaster.h"
30 #include "webrtc/media/base/videocommon.h" 30 #include "webrtc/media/base/videocommon.h"
31 #include "webrtc/media/base/videoframefactory.h" 31 #include "webrtc/media/base/videoframe.h"
32
33 32
34 namespace cricket { 33 namespace cricket {
35 34
36 // Current state of the capturer. 35 // Current state of the capturer.
37 enum CaptureState { 36 enum CaptureState {
38 CS_STOPPED, // The capturer has been stopped or hasn't started yet. 37 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 38 CS_STARTING, // The capturer is in the process of starting. Note, it may
40 // still fail to start. 39 // still fail to start.
41 CS_RUNNING, // The capturer has been started successfully and is now 40 CS_RUNNING, // The capturer has been started successfully and is now
42 // capturing. 41 // capturing.
43 CS_FAILED, // The capturer failed to start. 42 CS_FAILED, // The capturer failed to start.
44 }; 43 };
45 44
45 // TODO(nisse): For some reason, forward declaration doens't work when
46 // the definition is a "using" alias.
47 #if 0
46 class VideoFrame; 48 class VideoFrame;
47 49 #endif
48 struct CapturedFrame {
49 static const uint32_t kFrameHeaderSize = 40; // Size from width to data_size.
50 static const uint32_t kUnknownDataSize = 0xFFFFFFFF;
51
52 CapturedFrame();
53
54 // Get the number of bytes of the frame data. If data_size is known, return
55 // it directly. Otherwise, calculate the size based on width, height, and
56 // fourcc. Return true if succeeded.
57 bool GetDataSize(uint32_t* size) const;
58
59 // The width and height of the captured frame could be different from those
60 // of VideoFormat. Once the first frame is captured, the width, height,
61 // fourcc, pixel_width, and pixel_height should keep the same over frames.
62 int width; // in number of pixels
63 int height; // in number of pixels
64 uint32_t fourcc; // compression
65 uint32_t pixel_width; // width of a pixel, default is 1
66 uint32_t pixel_height; // height of a pixel, default is 1
67 int64_t time_stamp; // timestamp of when the frame was captured, in unix
68 // time with nanosecond units.
69 uint32_t data_size; // number of bytes of the frame data
70
71 webrtc::VideoRotation rotation; // rotation in degrees of the frame.
72
73 void* data; // pointer to the frame data. This object allocates the
74 // memory or points to an existing memory.
75
76 private:
77 RTC_DISALLOW_COPY_AND_ASSIGN(CapturedFrame);
78 };
79 50
80 // VideoCapturer is an abstract class that defines the interfaces for video 51 // VideoCapturer is an abstract class that defines the interfaces for video
81 // capturing. The subclasses implement the video capturer for various types of 52 // capturing. The subclasses implement the video capturer for various types of
82 // capturers and various platforms. 53 // capturers and various platforms.
83 // 54 //
84 // The captured frames may need to be adapted (for example, cropping). 55 // The captured frames may need to be adapted (for example, cropping).
85 // Video adaptation is built into and enabled by default. After a frame has 56 // Video adaptation is built into and enabled by default. After a frame has
86 // been captured from the device, it is sent to the video adapter, then out to 57 // been captured from the device, it is sent to the video adapter, then out to
87 // the sinks. 58 // the sinks.
88 // 59 //
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void set_enable_camera_list(bool enable_camera_list) { 156 void set_enable_camera_list(bool enable_camera_list) {
186 enable_camera_list_ = enable_camera_list; 157 enable_camera_list_ = enable_camera_list;
187 } 158 }
188 bool enable_camera_list() { 159 bool enable_camera_list() {
189 return enable_camera_list_; 160 return enable_camera_list_;
190 } 161 }
191 162
192 // Signal all capture state changes that are not a direct result of calling 163 // Signal all capture state changes that are not a direct result of calling
193 // Start(). 164 // Start().
194 sigslot::signal2<VideoCapturer*, CaptureState> SignalStateChange; 165 sigslot::signal2<VideoCapturer*, CaptureState> SignalStateChange;
195 // Frame callbacks are multithreaded to allow disconnect and connect to be
196 // 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
198 // unmarshalled thread owned by the VideoCapturer.
199 // Signal the captured frame to downstream.
200 sigslot::signal2<VideoCapturer*, const CapturedFrame*,
201 sigslot::multi_threaded_local> SignalFrameCaptured;
202 166
203 // If true, run video adaptation. By default, video adaptation is enabled 167 // If true, run video adaptation. By default, video adaptation is enabled
204 // and users must call video_adapter()->OnOutputFormatRequest() 168 // and users must call video_adapter()->OnOutputFormatRequest()
205 // to receive frames. 169 // to receive frames.
206 bool enable_video_adapter() const { return enable_video_adapter_; } 170 bool enable_video_adapter() const { return enable_video_adapter_; }
207 void set_enable_video_adapter(bool enable_video_adapter) { 171 void set_enable_video_adapter(bool enable_video_adapter) {
208 enable_video_adapter_ = enable_video_adapter; 172 enable_video_adapter_ = enable_video_adapter;
209 } 173 }
210 174
211 // Takes ownership.
212 void set_frame_factory(VideoFrameFactory* frame_factory);
213
214 bool GetInputSize(int* width, int* height); 175 bool GetInputSize(int* width, int* height);
215 176
216 // Implements VideoSourceInterface 177 // Implements VideoSourceInterface
217 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, 178 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
218 const rtc::VideoSinkWants& wants) override; 179 const rtc::VideoSinkWants& wants) override;
219 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; 180 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override;
220 181
221 protected: 182 protected:
222 // OnSinkWantsChanged can be overridden to change the default behavior 183 // OnSinkWantsChanged can be overridden to change the default behavior
223 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink. 184 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink.
(...skipping 20 matching lines...) Expand all
244 int64_t camera_time_us, 205 int64_t camera_time_us,
245 int64_t system_time_us, 206 int64_t system_time_us,
246 int* out_width, 207 int* out_width,
247 int* out_height, 208 int* out_height,
248 int* crop_width, 209 int* crop_width,
249 int* crop_height, 210 int* crop_height,
250 int* crop_x, 211 int* crop_x,
251 int* crop_y, 212 int* crop_y,
252 int64_t* translated_camera_time_us); 213 int64_t* translated_camera_time_us);
253 214
254 // Callback attached to SignalFrameCaptured where SignalVideoFrames is called.
255 void OnFrameCaptured(VideoCapturer* video_capturer,
256 const CapturedFrame* captured_frame);
257
258 // Called when a frame has been captured and converted to a 215 // Called when a frame has been captured and converted to a
259 // VideoFrame. OnFrame can be called directly by an implementation 216 // VideoFrame. OnFrame can be called directly by an implementation
260 // that does not use SignalFrameCaptured or OnFrameCaptured. The 217 // that does not use SignalFrameCaptured or OnFrameCaptured. The
261 // orig_width and orig_height are used only to produce stats. 218 // orig_width and orig_height are used only to produce stats.
262 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height); 219 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height);
263 220
264 VideoAdapter* video_adapter() { return &video_adapter_; } 221 VideoAdapter* video_adapter() { return &video_adapter_; }
265 222
266 void SetCaptureState(CaptureState state); 223 void SetCaptureState(CaptureState state);
267 224
268 // subclasses override this virtual method to provide a vector of fourccs, in 225 // subclasses override this virtual method to provide a vector of fourccs, in
269 // order of preference, that are expected by the media engine. 226 // order of preference, that are expected by the media engine.
270 virtual bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) = 0; 227 virtual bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) = 0;
271 228
272 // mutators to set private attributes 229 // mutators to set private attributes
273 void SetId(const std::string& id) { 230 void SetId(const std::string& id) {
274 id_ = id; 231 id_ = id;
275 } 232 }
276 233
277 void SetCaptureFormat(const VideoFormat* format) { 234 void SetCaptureFormat(const VideoFormat* format) {
278 capture_format_.reset(format ? new VideoFormat(*format) : NULL); 235 capture_format_.reset(format ? new VideoFormat(*format) : NULL);
279 } 236 }
280 237
281 void SetSupportedFormats(const std::vector<VideoFormat>& formats); 238 void SetSupportedFormats(const std::vector<VideoFormat>& formats);
282 VideoFrameFactory* frame_factory() { return frame_factory_.get(); }
283 239
284 private: 240 private:
285 void Construct(); 241 void Construct();
286 // Get the distance between the desired format and the supported format. 242 // Get the distance between the desired format and the supported format.
287 // Return the max distance if they mismatch. See the implementation for 243 // Return the max distance if they mismatch. See the implementation for
288 // details. 244 // details.
289 int64_t GetFormatDistance(const VideoFormat& desired, 245 int64_t GetFormatDistance(const VideoFormat& desired,
290 const VideoFormat& supported); 246 const VideoFormat& supported);
291 247
292 // Convert captured frame to readable string for LOG messages.
293 std::string ToString(const CapturedFrame* frame) const;
294
295 // Updates filtered_supported_formats_ so that it contains the formats in 248 // Updates filtered_supported_formats_ so that it contains the formats in
296 // supported_formats_ that fulfill all applied restrictions. 249 // supported_formats_ that fulfill all applied restrictions.
297 void UpdateFilteredSupportedFormats(); 250 void UpdateFilteredSupportedFormats();
298 // Returns true if format doesn't fulfill all applied restrictions. 251 // Returns true if format doesn't fulfill all applied restrictions.
299 bool ShouldFilterFormat(const VideoFormat& format) const; 252 bool ShouldFilterFormat(const VideoFormat& format) const;
300 253
301 void UpdateInputSize(int width, int height); 254 void UpdateInputSize(int width, int height);
302 255
303 rtc::ThreadChecker thread_checker_; 256 rtc::ThreadChecker thread_checker_;
304 std::string id_; 257 std::string id_;
305 CaptureState capture_state_; 258 CaptureState capture_state_;
306 std::unique_ptr<VideoFrameFactory> frame_factory_;
307 std::unique_ptr<VideoFormat> capture_format_; 259 std::unique_ptr<VideoFormat> capture_format_;
308 std::vector<VideoFormat> supported_formats_; 260 std::vector<VideoFormat> supported_formats_;
309 std::unique_ptr<VideoFormat> max_format_; 261 std::unique_ptr<VideoFormat> max_format_;
310 std::vector<VideoFormat> filtered_supported_formats_; 262 std::vector<VideoFormat> filtered_supported_formats_;
311 263
312 bool enable_camera_list_; 264 bool enable_camera_list_;
313 int scaled_width_; // Current output size from ComputeScale. 265 int scaled_width_; // Current output size from ComputeScale.
314 int scaled_height_; 266 int scaled_height_;
315 267
316 rtc::VideoBroadcaster broadcaster_; 268 rtc::VideoBroadcaster broadcaster_;
317 bool enable_video_adapter_; 269 bool enable_video_adapter_;
318 VideoAdapter video_adapter_; 270 VideoAdapter video_adapter_;
319 271
320 rtc::CriticalSection frame_stats_crit_; 272 rtc::CriticalSection frame_stats_crit_;
321 // The captured frame size before potential adapation. 273 // The captured frame size before potential adapation.
322 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; 274 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false;
323 int input_width_ GUARDED_BY(frame_stats_crit_); 275 int input_width_ GUARDED_BY(frame_stats_crit_);
324 int input_height_ GUARDED_BY(frame_stats_crit_); 276 int input_height_ GUARDED_BY(frame_stats_crit_);
325 277
278 // TODO(nisse): Still needed?
326 // Whether capturer should apply rotation to the frame before signaling it. 279 // Whether capturer should apply rotation to the frame before signaling it.
327 bool apply_rotation_; 280 bool apply_rotation_;
328 281
329 // State for the timestamp translation. 282 // State for the timestamp translation.
330 rtc::TimestampAligner timestamp_aligner_; 283 rtc::TimestampAligner timestamp_aligner_;
331 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); 284 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer);
332 }; 285 };
333 286
334 } // namespace cricket 287 } // namespace cricket
335 288
336 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ 289 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698