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

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

Issue 2262443003: Delete VideoFrameFactory, CapturedFrame, and related code. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased. 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"
32 31
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
46 class VideoFrame; 45 class VideoFrame;
47 46
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
80 // VideoCapturer is an abstract class that defines the interfaces for video 47 // VideoCapturer is an abstract class that defines the interfaces for video
81 // capturing. The subclasses implement the video capturer for various types of 48 // capturing. The subclasses implement the video capturer for various types of
82 // capturers and various platforms. 49 // capturers and various platforms.
83 // 50 //
84 // The captured frames may need to be adapted (for example, cropping). 51 // 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 52 // 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 53 // been captured from the device, it is sent to the video adapter, then out to
87 // the sinks. 54 // the sinks.
88 // 55 //
89 // Programming model: 56 // Programming model:
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void set_enable_camera_list(bool enable_camera_list) { 152 void set_enable_camera_list(bool enable_camera_list) {
186 enable_camera_list_ = enable_camera_list; 153 enable_camera_list_ = enable_camera_list;
187 } 154 }
188 bool enable_camera_list() { 155 bool enable_camera_list() {
189 return enable_camera_list_; 156 return enable_camera_list_;
190 } 157 }
191 158
192 // Signal all capture state changes that are not a direct result of calling 159 // Signal all capture state changes that are not a direct result of calling
193 // Start(). 160 // Start().
194 sigslot::signal2<VideoCapturer*, CaptureState> SignalStateChange; 161 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 162
203 // If true, run video adaptation. By default, video adaptation is enabled 163 // If true, run video adaptation. By default, video adaptation is enabled
204 // and users must call video_adapter()->OnOutputFormatRequest() 164 // and users must call video_adapter()->OnOutputFormatRequest()
205 // to receive frames. 165 // to receive frames.
206 bool enable_video_adapter() const { return enable_video_adapter_; } 166 bool enable_video_adapter() const { return enable_video_adapter_; }
207 void set_enable_video_adapter(bool enable_video_adapter) { 167 void set_enable_video_adapter(bool enable_video_adapter) {
208 enable_video_adapter_ = enable_video_adapter; 168 enable_video_adapter_ = enable_video_adapter;
209 } 169 }
210 170
211 // Takes ownership.
212 void set_frame_factory(VideoFrameFactory* frame_factory);
213
214 bool GetInputSize(int* width, int* height); 171 bool GetInputSize(int* width, int* height);
215 172
216 // Implements VideoSourceInterface 173 // Implements VideoSourceInterface
217 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, 174 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
218 const rtc::VideoSinkWants& wants) override; 175 const rtc::VideoSinkWants& wants) override;
219 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; 176 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override;
220 177
221 protected: 178 protected:
222 // OnSinkWantsChanged can be overridden to change the default behavior 179 // OnSinkWantsChanged can be overridden to change the default behavior
223 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink. 180 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink.
(...skipping 20 matching lines...) Expand all
244 int64_t camera_time_us, 201 int64_t camera_time_us,
245 int64_t system_time_us, 202 int64_t system_time_us,
246 int* out_width, 203 int* out_width,
247 int* out_height, 204 int* out_height,
248 int* crop_width, 205 int* crop_width,
249 int* crop_height, 206 int* crop_height,
250 int* crop_x, 207 int* crop_x,
251 int* crop_y, 208 int* crop_y,
252 int64_t* translated_camera_time_us); 209 int64_t* translated_camera_time_us);
253 210
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 211 // Called when a frame has been captured and converted to a
259 // VideoFrame. OnFrame can be called directly by an implementation 212 // VideoFrame. OnFrame can be called directly by an implementation
260 // that does not use SignalFrameCaptured or OnFrameCaptured. The 213 // that does not use SignalFrameCaptured or OnFrameCaptured. The
261 // orig_width and orig_height are used only to produce stats. 214 // orig_width and orig_height are used only to produce stats.
262 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height); 215 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height);
263 216
264 VideoAdapter* video_adapter() { return &video_adapter_; } 217 VideoAdapter* video_adapter() { return &video_adapter_; }
265 218
266 void SetCaptureState(CaptureState state); 219 void SetCaptureState(CaptureState state);
267 220
268 // subclasses override this virtual method to provide a vector of fourccs, in 221 // subclasses override this virtual method to provide a vector of fourccs, in
269 // order of preference, that are expected by the media engine. 222 // order of preference, that are expected by the media engine.
270 virtual bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) = 0; 223 virtual bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) = 0;
271 224
272 // mutators to set private attributes 225 // mutators to set private attributes
273 void SetId(const std::string& id) { 226 void SetId(const std::string& id) {
274 id_ = id; 227 id_ = id;
275 } 228 }
276 229
277 void SetCaptureFormat(const VideoFormat* format) { 230 void SetCaptureFormat(const VideoFormat* format) {
278 capture_format_.reset(format ? new VideoFormat(*format) : NULL); 231 capture_format_.reset(format ? new VideoFormat(*format) : NULL);
279 } 232 }
280 233
281 void SetSupportedFormats(const std::vector<VideoFormat>& formats); 234 void SetSupportedFormats(const std::vector<VideoFormat>& formats);
282 VideoFrameFactory* frame_factory() { return frame_factory_.get(); }
283 235
284 private: 236 private:
285 void Construct(); 237 void Construct();
286 // Get the distance between the desired format and the supported format. 238 // Get the distance between the desired format and the supported format.
287 // Return the max distance if they mismatch. See the implementation for 239 // Return the max distance if they mismatch. See the implementation for
288 // details. 240 // details.
289 int64_t GetFormatDistance(const VideoFormat& desired, 241 int64_t GetFormatDistance(const VideoFormat& desired,
290 const VideoFormat& supported); 242 const VideoFormat& supported);
291 243
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 244 // Updates filtered_supported_formats_ so that it contains the formats in
296 // supported_formats_ that fulfill all applied restrictions. 245 // supported_formats_ that fulfill all applied restrictions.
297 void UpdateFilteredSupportedFormats(); 246 void UpdateFilteredSupportedFormats();
298 // Returns true if format doesn't fulfill all applied restrictions. 247 // Returns true if format doesn't fulfill all applied restrictions.
299 bool ShouldFilterFormat(const VideoFormat& format) const; 248 bool ShouldFilterFormat(const VideoFormat& format) const;
300 249
301 void UpdateInputSize(int width, int height); 250 void UpdateInputSize(int width, int height);
302 251
303 rtc::ThreadChecker thread_checker_; 252 rtc::ThreadChecker thread_checker_;
304 std::string id_; 253 std::string id_;
305 CaptureState capture_state_; 254 CaptureState capture_state_;
306 std::unique_ptr<VideoFrameFactory> frame_factory_;
307 std::unique_ptr<VideoFormat> capture_format_; 255 std::unique_ptr<VideoFormat> capture_format_;
308 std::vector<VideoFormat> supported_formats_; 256 std::vector<VideoFormat> supported_formats_;
309 std::unique_ptr<VideoFormat> max_format_; 257 std::unique_ptr<VideoFormat> max_format_;
310 std::vector<VideoFormat> filtered_supported_formats_; 258 std::vector<VideoFormat> filtered_supported_formats_;
311 259
312 bool enable_camera_list_; 260 bool enable_camera_list_;
313 int scaled_width_; // Current output size from ComputeScale. 261 int scaled_width_; // Current output size from ComputeScale.
314 int scaled_height_; 262 int scaled_height_;
315 263
316 rtc::VideoBroadcaster broadcaster_; 264 rtc::VideoBroadcaster broadcaster_;
317 bool enable_video_adapter_; 265 bool enable_video_adapter_;
318 VideoAdapter video_adapter_; 266 VideoAdapter video_adapter_;
319 267
320 rtc::CriticalSection frame_stats_crit_; 268 rtc::CriticalSection frame_stats_crit_;
321 // The captured frame size before potential adapation. 269 // The captured frame size before potential adapation.
322 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; 270 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false;
323 int input_width_ GUARDED_BY(frame_stats_crit_); 271 int input_width_ GUARDED_BY(frame_stats_crit_);
324 int input_height_ GUARDED_BY(frame_stats_crit_); 272 int input_height_ GUARDED_BY(frame_stats_crit_);
325 273
274 // TODO(nisse): Still needed?
pthatcher1 2016/09/07 18:03:03 It's still used here: https://cs.chromium.org/chr
nisse-webrtc 2016/09/14 07:58:15 I'm changing the comment to say that is is used by
326 // Whether capturer should apply rotation to the frame before signaling it. 275 // Whether capturer should apply rotation to the frame before signaling it.
327 bool apply_rotation_; 276 bool apply_rotation_;
328 277
329 // State for the timestamp translation. 278 // State for the timestamp translation.
330 rtc::TimestampAligner timestamp_aligner_; 279 rtc::TimestampAligner timestamp_aligner_;
331 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); 280 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer);
332 }; 281 };
333 282
334 } // namespace cricket 283 } // namespace cricket
335 284
336 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ 285 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698