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

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: emircan@ suggestions 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 struct FakeDeviceState;
18 // on a given target OutputMode and frame rate. 18 class FakePhotoDevice;
19 class CAPTURE_EXPORT FakeVideoCaptureDeviceMaker { 19 class FrameDeliverer;
20 class FrameDelivererFactory;
21
22 // Paints a "pacman-like" animated circle including textual information such
23 // as a frame count and timer.
24 class PacmanFramePainter {
mcasas 2017/03/02 21:07:09 This class can and should be forward declared here
chfremer 2017/03/02 23:03:04 They used to be forward-declared, but I had to mov
20 public: 25 public:
21 enum class PixelFormat { 26 enum class Format { I420, SK_N32, Y16 };
22 I420 = media::PIXEL_FORMAT_I420, 27
23 Y16 = media::PIXEL_FORMAT_Y16, 28 PacmanFramePainter(Format pixel_format,
24 MJPEG = media::PIXEL_FORMAT_MJPEG 29 const FakeDeviceState* fake_device_state);
25 }; 30
31 void PaintFrame(base::TimeDelta elapsed_time, uint8_t* target_buffer);
32
33 private:
34 void DrawGradientSquares(base::TimeDelta elapsed_time,
35 uint8_t* target_buffer);
36
37 void DrawPacman(base::TimeDelta elapsed_time, uint8_t* target_buffer);
38
39 const Format pixel_format_;
40 const FakeDeviceState* fake_device_state_ = nullptr;
41 };
42
43 // Implementation of VideoCaptureDevice that generates test frames. This is
44 // useful for testing the video capture components without having to use real
45 // devices. The implementation schedules delayed tasks to itself to generate and
46 // deliver frames at the requested rate.
47 class FakeVideoCaptureDevice : public VideoCaptureDevice {
48 public:
26 enum class DeliveryMode { 49 enum class DeliveryMode {
27 USE_DEVICE_INTERNAL_BUFFERS, 50 USE_DEVICE_INTERNAL_BUFFERS,
28 USE_CLIENT_PROVIDED_BUFFERS 51 USE_CLIENT_PROVIDED_BUFFERS
29 }; 52 };
30 53
54 FakeVideoCaptureDevice(
55 const VideoCaptureFormats& supported_formats,
56 std::unique_ptr<FrameDelivererFactory> frame_deliverer_factory,
57 std::unique_ptr<FakePhotoDevice> photo_device,
58 std::unique_ptr<FakeDeviceState> device_state);
59 ~FakeVideoCaptureDevice() override;
60
31 static void GetSupportedSizes(std::vector<gfx::Size>* supported_sizes); 61 static void GetSupportedSizes(std::vector<gfx::Size>* supported_sizes);
32 62
33 static std::unique_ptr<VideoCaptureDevice> MakeInstance( 63 // VideoCaptureDevice implementation.
34 PixelFormat pixel_format, 64 void AllocateAndStart(const VideoCaptureParams& params,
35 DeliveryMode delivery_mode, 65 std::unique_ptr<Client> client) override;
36 float frame_rate); 66 void StopAndDeAllocate() override;
67 void GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) override;
68 void SetPhotoOptions(mojom::PhotoSettingsPtr settings,
69 SetPhotoOptionsCallback callback) override;
70 void TakePhoto(TakePhotoCallback callback) override;
71
72 private:
73 void BeepAndScheduleNextCapture(base::TimeTicks expected_execution_time);
74 void OnNextFrameDue(base::TimeTicks expected_execution_time, int session_id);
75
76 const VideoCaptureFormats supported_formats_;
77 const std::unique_ptr<FrameDelivererFactory> frame_deliverer_factory_;
78 const std::unique_ptr<FakePhotoDevice> photo_device_;
79 const std::unique_ptr<FakeDeviceState> device_state_;
80 std::unique_ptr<FrameDeliverer> frame_deliverer_;
81 int current_session_id_ = 0;
82
83 // Time when the next beep occurs.
84 base::TimeDelta beep_time_;
85 // Time since the fake video started rendering frames.
86 base::TimeDelta elapsed_time_;
87
88 base::ThreadChecker thread_checker_;
89
90 // FakeVideoCaptureDevice post tasks to itself for frame construction and
91 // needs to deal with asynchronous StopAndDeallocate().
92 base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_;
93
94 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
95 };
96
97 // Represents the current state of a FakeVideoCaptureDevice.
98 // This is a separate struct because read-access to it is shared with several
99 // collaborating classes.
100 struct FakeDeviceState {
101 FakeDeviceState(float zoom, float frame_rate, VideoPixelFormat pixel_format)
102 : zoom(zoom),
103 format(gfx::Size(), frame_rate, pixel_format, PIXEL_STORAGE_CPU) {}
104
105 uint32_t zoom;
106 VideoCaptureFormat format;
107 };
108
109 // A dependency needed by FakeVideoCaptureDevice.
110 class FrameDelivererFactory {
111 public:
112 FrameDelivererFactory(FakeVideoCaptureDevice::DeliveryMode delivery_mode,
113 const FakeDeviceState* device_state);
114
115 std::unique_ptr<FrameDeliverer> CreateFrameDeliverer(
116 const VideoCaptureFormat& format);
117
118 private:
119 const FakeVideoCaptureDevice::DeliveryMode delivery_mode_;
120 const FakeDeviceState* device_state_ = nullptr;
121 };
122
123 // Implements the photo functionality of a FakeVideoCaptureDevice
124 class FakePhotoDevice {
125 public:
126 FakePhotoDevice(std::unique_ptr<PacmanFramePainter> sk_n32_painter,
127 const FakeDeviceState* fake_device_state);
128 ~FakePhotoDevice();
129
130 void GetPhotoCapabilities(
131 VideoCaptureDevice::GetPhotoCapabilitiesCallback callback);
132 void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback,
133 base::TimeDelta elapsed_time);
134
135 private:
136 const std::unique_ptr<PacmanFramePainter> sk_n32_painter_;
137 const FakeDeviceState* const fake_device_state_;
37 }; 138 };
38 139
39 } // namespace media 140 } // namespace media
40 141
41 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_ 142 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698