Index: media/capture/video/fake_video_capture_device.h |
diff --git a/media/capture/video/fake_video_capture_device.h b/media/capture/video/fake_video_capture_device.h |
index 7919e9f666b095f512a185f3fca1e3e65ebc8e85..0b716df8fa0612da37769a63597b472423d7ec66 100644 |
--- a/media/capture/video/fake_video_capture_device.h |
+++ b/media/capture/video/fake_video_capture_device.h |
@@ -14,26 +14,127 @@ |
namespace media { |
-// Encapsulates factory logic to make a working FakeVideoCaptureDevice based |
-// on a given target OutputMode and frame rate. |
-class CAPTURE_EXPORT FakeVideoCaptureDeviceMaker { |
+struct FakeDeviceState; |
+class FakePhotoDevice; |
+class FrameDeliverer; |
+class FrameDelivererFactory; |
+ |
+// Paints a "pacman-like" animated circle including textual information such |
+// as a frame count and timer. |
+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
|
+ public: |
+ enum class Format { I420, SK_N32, Y16 }; |
+ |
+ PacmanFramePainter(Format pixel_format, |
+ const FakeDeviceState* fake_device_state); |
+ |
+ void PaintFrame(base::TimeDelta elapsed_time, uint8_t* target_buffer); |
+ |
+ private: |
+ void DrawGradientSquares(base::TimeDelta elapsed_time, |
+ uint8_t* target_buffer); |
+ |
+ void DrawPacman(base::TimeDelta elapsed_time, uint8_t* target_buffer); |
+ |
+ const Format pixel_format_; |
+ const FakeDeviceState* fake_device_state_ = nullptr; |
+}; |
+ |
+// Implementation of VideoCaptureDevice that generates test frames. This is |
+// useful for testing the video capture components without having to use real |
+// devices. The implementation schedules delayed tasks to itself to generate and |
+// deliver frames at the requested rate. |
+class FakeVideoCaptureDevice : public VideoCaptureDevice { |
public: |
- enum class PixelFormat { |
- I420 = media::PIXEL_FORMAT_I420, |
- Y16 = media::PIXEL_FORMAT_Y16, |
- MJPEG = media::PIXEL_FORMAT_MJPEG |
- }; |
enum class DeliveryMode { |
USE_DEVICE_INTERNAL_BUFFERS, |
USE_CLIENT_PROVIDED_BUFFERS |
}; |
+ FakeVideoCaptureDevice( |
+ const VideoCaptureFormats& supported_formats, |
+ std::unique_ptr<FrameDelivererFactory> frame_deliverer_factory, |
+ std::unique_ptr<FakePhotoDevice> photo_device, |
+ std::unique_ptr<FakeDeviceState> device_state); |
+ ~FakeVideoCaptureDevice() override; |
+ |
static void GetSupportedSizes(std::vector<gfx::Size>* supported_sizes); |
- static std::unique_ptr<VideoCaptureDevice> MakeInstance( |
- PixelFormat pixel_format, |
- DeliveryMode delivery_mode, |
- float frame_rate); |
+ // VideoCaptureDevice implementation. |
+ void AllocateAndStart(const VideoCaptureParams& params, |
+ std::unique_ptr<Client> client) override; |
+ void StopAndDeAllocate() override; |
+ void GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) override; |
+ void SetPhotoOptions(mojom::PhotoSettingsPtr settings, |
+ SetPhotoOptionsCallback callback) override; |
+ void TakePhoto(TakePhotoCallback callback) override; |
+ |
+ private: |
+ void BeepAndScheduleNextCapture(base::TimeTicks expected_execution_time); |
+ void OnNextFrameDue(base::TimeTicks expected_execution_time, int session_id); |
+ |
+ const VideoCaptureFormats supported_formats_; |
+ const std::unique_ptr<FrameDelivererFactory> frame_deliverer_factory_; |
+ const std::unique_ptr<FakePhotoDevice> photo_device_; |
+ const std::unique_ptr<FakeDeviceState> device_state_; |
+ std::unique_ptr<FrameDeliverer> frame_deliverer_; |
+ int current_session_id_ = 0; |
+ |
+ // Time when the next beep occurs. |
+ base::TimeDelta beep_time_; |
+ // Time since the fake video started rendering frames. |
+ base::TimeDelta elapsed_time_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ // FakeVideoCaptureDevice post tasks to itself for frame construction and |
+ // needs to deal with asynchronous StopAndDeallocate(). |
+ base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice); |
+}; |
+ |
+// Represents the current state of a FakeVideoCaptureDevice. |
+// This is a separate struct because read-access to it is shared with several |
+// collaborating classes. |
+struct FakeDeviceState { |
+ FakeDeviceState(float zoom, float frame_rate, VideoPixelFormat pixel_format) |
+ : zoom(zoom), |
+ format(gfx::Size(), frame_rate, pixel_format, PIXEL_STORAGE_CPU) {} |
+ |
+ uint32_t zoom; |
+ VideoCaptureFormat format; |
+}; |
+ |
+// A dependency needed by FakeVideoCaptureDevice. |
+class FrameDelivererFactory { |
+ public: |
+ FrameDelivererFactory(FakeVideoCaptureDevice::DeliveryMode delivery_mode, |
+ const FakeDeviceState* device_state); |
+ |
+ std::unique_ptr<FrameDeliverer> CreateFrameDeliverer( |
+ const VideoCaptureFormat& format); |
+ |
+ private: |
+ const FakeVideoCaptureDevice::DeliveryMode delivery_mode_; |
+ const FakeDeviceState* device_state_ = nullptr; |
+}; |
+ |
+// Implements the photo functionality of a FakeVideoCaptureDevice |
+class FakePhotoDevice { |
+ public: |
+ FakePhotoDevice(std::unique_ptr<PacmanFramePainter> sk_n32_painter, |
+ const FakeDeviceState* fake_device_state); |
+ ~FakePhotoDevice(); |
+ |
+ void GetPhotoCapabilities( |
+ VideoCaptureDevice::GetPhotoCapabilitiesCallback callback); |
+ void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback, |
+ base::TimeDelta elapsed_time); |
+ |
+ private: |
+ const std::unique_ptr<PacmanFramePainter> sk_n32_painter_; |
+ const FakeDeviceState* const fake_device_state_; |
}; |
} // namespace media |