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

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

Issue 2619503003: Split FakeVideoCaptureDevice into classes with single responsibility (Closed)
Patch Set: mcasas comments & rebase Created 3 years, 11 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 // Implementation of a fake VideoCaptureDevice class. Used for testing other
6 // video capture classes when no real hardware is available.
7
8 #ifndef MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_ 5 #ifndef MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_
9 #define MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_ 6 #define MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_
10 7
11 #include <stdint.h> 8 #include <stdint.h>
12 9
13 #include <memory> 10 #include <memory>
14 #include <string> 11 #include <string>
15 12
16 #include "base/atomicops.h"
17 #include "base/macros.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/threading/thread_checker.h"
20 #include "base/time/time.h"
21 #include "media/capture/video/video_capture_device.h" 13 #include "media/capture/video/video_capture_device.h"
22 14
23 namespace media { 15 namespace media {
24 16
25 class CAPTURE_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { 17 // Encapsulates factory logic to make a working FakeVideoCaptureDevice based
18 // on a given target OutputMode and frame rate.
19 class CAPTURE_EXPORT FakeVideoCaptureDeviceMaker {
26 public: 20 public:
27 enum class BufferOwnership { 21 enum class DeliveryMode { USE_OWN_BUFFERS, USE_CLIENT_BUFFERS };
28 OWN_BUFFERS,
29 CLIENT_BUFFERS,
30 };
31 22
32 FakeVideoCaptureDevice(BufferOwnership buffer_ownership, 23 static void GetSupportedSizes(std::vector<gfx::Size>* supported_sizes);
33 float fake_capture_rate,
34 VideoPixelFormat pixel_format = PIXEL_FORMAT_I420);
35 ~FakeVideoCaptureDevice() override;
36 24
37 // VideoCaptureDevice implementation. 25 static std::unique_ptr<VideoCaptureDevice> MakeInstance(
38 void AllocateAndStart(const VideoCaptureParams& params, 26 VideoPixelFormat pixel_format,
39 std::unique_ptr<Client> client) override; 27 DeliveryMode delivery_mode,
40 void StopAndDeAllocate() override; 28 float frame_rate);
41 void GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) override;
42 void SetPhotoOptions(mojom::PhotoSettingsPtr settings,
43 SetPhotoOptionsCallback callback) override;
44 void TakePhoto(TakePhotoCallback callback) override;
45
46 private:
47 void CaptureUsingOwnBuffers(base::TimeTicks expected_execution_time);
48 void CaptureUsingClientBuffers(base::TimeTicks expected_execution_time);
49 void BeepAndScheduleNextCapture(
50 base::TimeTicks expected_execution_time,
51 const base::Callback<void(base::TimeTicks)>& next_capture);
52
53 // |thread_checker_| is used to check that all methods are called in the
54 // correct thread that owns the object.
55 base::ThreadChecker thread_checker_;
56
57 const BufferOwnership buffer_ownership_;
58 // Frame rate of the fake video device.
59 const float fake_capture_rate_;
60 // Pixel format of all device streams.
61 const VideoPixelFormat pixel_format_;
62
63 std::unique_ptr<VideoCaptureDevice::Client> client_;
64 // |fake_frame_| is used for capturing on Own Buffers.
65 std::unique_ptr<uint8_t[]> fake_frame_;
66 // Time when the next beep occurs.
67 base::TimeDelta beep_time_;
68 // Time since the fake video started rendering frames.
69 base::TimeDelta elapsed_time_;
70 VideoCaptureFormat capture_format_;
71
72 double current_zoom_;
73
74 // The system time when we receive the first frame.
75 base::TimeTicks first_ref_time_;
76 // FakeVideoCaptureDevice post tasks to itself for frame construction and
77 // needs to deal with asynchronous StopAndDeallocate().
78 base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_;
79
80 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
81 }; 29 };
82 30
83 } // namespace media 31 } // namespace media
84 32
85 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_ 33 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW
« no previous file with comments | « no previous file | media/capture/video/fake_video_capture_device.cc » ('j') | media/capture/video/fake_video_capture_device.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698