Chromium Code Reviews| 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..eaf3c10f8f8d6cf292fc61203c723896efe443c8 100644 |
| --- a/media/capture/video/fake_video_capture_device.h |
| +++ b/media/capture/video/fake_video_capture_device.h |
| @@ -14,26 +14,124 @@ |
| namespace media { |
| -// Encapsulates factory logic to make a working FakeVideoCaptureDevice based |
| -// on a given target OutputMode and frame rate. |
| -class CAPTURE_EXPORT FakeVideoCaptureDeviceMaker { |
| +class FrameDeliverer; |
| +class FrameDelivererFactory; |
| + |
| +// 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; |
| +}; |
| + |
| +// Paints a "pacman-like" animated circle including textual information such |
| +// as a frame count and timer. |
| +class PacmanFramePainter { |
| + 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); |
|
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
|
| + |
| + private: |
| + void DrawGradientSquares(base::TimeDelta elapsed_time, |
|
emircan
2017/03/01 18:58:58
const base::TimeDelta&
chfremer
2017/03/01 21:55:48
same
|
| + uint8_t* target_buffer); |
| + |
| + void DrawPacman(base::TimeDelta elapsed_time, uint8_t* target_buffer); |
| + |
| + const Format pixel_format_; |
| + const FakeDeviceState* fake_device_state_ = nullptr; |
| +}; |
| + |
| +// Implements the photo functionality of a VideoCaptureDevice |
| +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_; |
| +}; |
| + |
| +// 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 { |
|
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
|
| 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); |
| +}; |
| + |
| +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; |
| }; |
| } // namespace media |