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

Side by Side Diff: media/capture/video/fake_video_capture_device.h

Issue 2715513008: Make FakeVideoCaptureDeviceFactory configurable to arbitrary fake device configurations (Closed)
Patch Set: Fix compiler warning. Fix WebRtcDepthCaptureBrowserTest. Created 3 years, 9 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 // 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 #ifndef MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_ 5 #ifndef MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_
6 #define MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_ 6 #define MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "media/capture/video/video_capture_device.h" 13 #include "media/capture/video/video_capture_device.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 // Encapsulates factory logic to make a working FakeVideoCaptureDevice based 17 class FrameDeliverer;
18 // on a given target OutputMode and frame rate. 18 class FrameDelivererFactory;
19 class CAPTURE_EXPORT FakeVideoCaptureDeviceMaker { 19
20 // Represents the current state of a FakeVideoCaptureDevice.
21 // This is a separate struct because read-access to it is shared with several
22 // collaborating classes.
23 struct FakeDeviceState {
24 FakeDeviceState(float zoom, float frame_rate, VideoPixelFormat pixel_format)
25 : zoom(zoom),
26 format(gfx::Size(), frame_rate, pixel_format, PIXEL_STORAGE_CPU) {}
27
28 uint32_t zoom;
29 VideoCaptureFormat format;
30 };
31
32 // Paints a "pacman-like" animated circle including textual information such
33 // as a frame count and timer.
34 class PacmanFramePainter {
20 public: 35 public:
21 enum class PixelFormat { 36 enum class Format { I420, SK_N32, Y16 };
22 I420 = media::PIXEL_FORMAT_I420, 37
23 Y16 = media::PIXEL_FORMAT_Y16, 38 PacmanFramePainter(Format pixel_format,
24 MJPEG = media::PIXEL_FORMAT_MJPEG 39 const FakeDeviceState* fake_device_state);
25 }; 40
41 void PaintFrame(base::TimeDelta elapsed_time, uint8_t* target_buffer);
emircan 2017/03/01 18:58:58 const base::TimeDelta&
chfremer 2017/03/01 21:55:48 Doing so raises a build warning that says this typ
42
43 private:
44 void DrawGradientSquares(base::TimeDelta elapsed_time,
emircan 2017/03/01 18:58:58 const base::TimeDelta&
chfremer 2017/03/01 21:55:48 same
45 uint8_t* target_buffer);
46
47 void DrawPacman(base::TimeDelta elapsed_time, uint8_t* target_buffer);
48
49 const Format pixel_format_;
50 const FakeDeviceState* fake_device_state_ = nullptr;
51 };
52
53 // Implements the photo functionality of a VideoCaptureDevice
54 class FakePhotoDevice {
55 public:
56 FakePhotoDevice(std::unique_ptr<PacmanFramePainter> sk_n32_painter,
57 const FakeDeviceState* fake_device_state);
58 ~FakePhotoDevice();
59
60 void GetPhotoCapabilities(
61 VideoCaptureDevice::GetPhotoCapabilitiesCallback callback);
62 void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback,
63 base::TimeDelta elapsed_time);
64
65 private:
66 const std::unique_ptr<PacmanFramePainter> sk_n32_painter_;
67 const FakeDeviceState* const fake_device_state_;
68 };
69
70 // Implementation of VideoCaptureDevice that generates test frames. This is
71 // useful for testing the video capture components without having to use real
72 // devices. The implementation schedules delayed tasks to itself to generate and
73 // deliver frames at the requested rate.
74 class FakeVideoCaptureDevice : public VideoCaptureDevice {
emircan 2017/03/01 18:58:58 Can you reorder these classes in a way that would
chfremer 2017/03/01 21:55:48 Done. I kept the current order in the .cc file, s
75 public:
26 enum class DeliveryMode { 76 enum class DeliveryMode {
27 USE_DEVICE_INTERNAL_BUFFERS, 77 USE_DEVICE_INTERNAL_BUFFERS,
28 USE_CLIENT_PROVIDED_BUFFERS 78 USE_CLIENT_PROVIDED_BUFFERS
29 }; 79 };
30 80
81 FakeVideoCaptureDevice(
82 const VideoCaptureFormats& supported_formats,
83 std::unique_ptr<FrameDelivererFactory> frame_deliverer_factory,
84 std::unique_ptr<FakePhotoDevice> photo_device,
85 std::unique_ptr<FakeDeviceState> device_state);
86 ~FakeVideoCaptureDevice() override;
87
31 static void GetSupportedSizes(std::vector<gfx::Size>* supported_sizes); 88 static void GetSupportedSizes(std::vector<gfx::Size>* supported_sizes);
32 89
33 static std::unique_ptr<VideoCaptureDevice> MakeInstance( 90 // VideoCaptureDevice implementation.
34 PixelFormat pixel_format, 91 void AllocateAndStart(const VideoCaptureParams& params,
35 DeliveryMode delivery_mode, 92 std::unique_ptr<Client> client) override;
36 float frame_rate); 93 void StopAndDeAllocate() override;
94 void GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) override;
95 void SetPhotoOptions(mojom::PhotoSettingsPtr settings,
96 SetPhotoOptionsCallback callback) override;
97 void TakePhoto(TakePhotoCallback callback) override;
98
99 private:
100 void BeepAndScheduleNextCapture(base::TimeTicks expected_execution_time);
101 void OnNextFrameDue(base::TimeTicks expected_execution_time, int session_id);
102
103 const VideoCaptureFormats supported_formats_;
104 const std::unique_ptr<FrameDelivererFactory> frame_deliverer_factory_;
105 const std::unique_ptr<FakePhotoDevice> photo_device_;
106 const std::unique_ptr<FakeDeviceState> device_state_;
107 std::unique_ptr<FrameDeliverer> frame_deliverer_;
108 int current_session_id_ = 0;
109
110 // Time when the next beep occurs.
111 base::TimeDelta beep_time_;
112 // Time since the fake video started rendering frames.
113 base::TimeDelta elapsed_time_;
114
115 base::ThreadChecker thread_checker_;
116
117 // FakeVideoCaptureDevice post tasks to itself for frame construction and
118 // needs to deal with asynchronous StopAndDeallocate().
119 base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_;
120
121 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
122 };
123
124 class FrameDelivererFactory {
125 public:
126 FrameDelivererFactory(FakeVideoCaptureDevice::DeliveryMode delivery_mode,
127 const FakeDeviceState* device_state);
128
129 std::unique_ptr<FrameDeliverer> CreateFrameDeliverer(
130 const VideoCaptureFormat& format);
131
132 private:
133 const FakeVideoCaptureDevice::DeliveryMode delivery_mode_;
134 const FakeDeviceState* device_state_ = nullptr;
37 }; 135 };
38 136
39 } // namespace media 137 } // namespace media
40 138
41 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_ 139 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698