OLD | NEW |
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 | 5 // Implementation of a fake VideoCaptureDevice class. Used for testing other |
6 // video capture classes when no real hardware is available. | 6 // video capture classes when no real hardware is available. |
7 | 7 |
8 #ifndef MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ | 8 #ifndef MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ |
9 #define MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ | 9 #define MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ |
10 | 10 |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/atomicops.h" | 15 #include "base/atomicops.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/threading/thread.h" | |
20 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
21 #include "base/time/time.h" | 20 #include "base/time/time.h" |
22 #include "media/capture/video/video_capture_device.h" | 21 #include "media/capture/video/video_capture_device.h" |
23 | 22 |
24 namespace media { | 23 namespace media { |
25 | 24 |
26 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { | 25 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { |
27 public: | 26 public: |
28 enum class BufferOwnership { | 27 enum class BufferOwnership { |
29 OWN_BUFFERS, | 28 OWN_BUFFERS, |
30 CLIENT_BUFFERS, | 29 CLIENT_BUFFERS, |
31 }; | 30 }; |
32 | 31 |
33 enum class BufferPlanarity { | |
34 PACKED, | |
35 TRIPLANAR, | |
36 }; | |
37 | |
38 FakeVideoCaptureDevice(BufferOwnership buffer_ownership, | 32 FakeVideoCaptureDevice(BufferOwnership buffer_ownership, |
39 BufferPlanarity planarity); | |
40 FakeVideoCaptureDevice(BufferOwnership buffer_ownership, | |
41 BufferPlanarity planarity, | |
42 float fake_capture_rate); | 33 float fake_capture_rate); |
43 ~FakeVideoCaptureDevice() override; | 34 ~FakeVideoCaptureDevice() override; |
44 | 35 |
45 // VideoCaptureDevice implementation. | 36 // VideoCaptureDevice implementation. |
46 void AllocateAndStart(const VideoCaptureParams& params, | 37 void AllocateAndStart(const VideoCaptureParams& params, |
47 scoped_ptr<Client> client) override; | 38 scoped_ptr<Client> client) override; |
48 void StopAndDeAllocate() override; | 39 void StopAndDeAllocate() override; |
49 | 40 |
50 private: | 41 private: |
51 void CaptureUsingOwnBuffers(base::TimeTicks expected_execution_time); | 42 void CaptureUsingOwnBuffers(base::TimeTicks expected_execution_time); |
52 void CaptureUsingClientBuffers(base::TimeTicks expected_execution_time); | 43 void CaptureUsingClientBuffers(base::TimeTicks expected_execution_time); |
53 void BeepAndScheduleNextCapture( | 44 void BeepAndScheduleNextCapture( |
54 base::TimeTicks expected_execution_time, | 45 base::TimeTicks expected_execution_time, |
55 const base::Callback<void(base::TimeTicks)>& next_capture); | 46 const base::Callback<void(base::TimeTicks)>& next_capture); |
56 | 47 |
57 // |thread_checker_| is used to check that all methods are called in the | 48 // |thread_checker_| is used to check that all methods are called in the |
58 // correct thread that owns the object. | 49 // correct thread that owns the object. |
59 base::ThreadChecker thread_checker_; | 50 base::ThreadChecker thread_checker_; |
60 | 51 |
61 const BufferOwnership buffer_ownership_; | 52 const BufferOwnership buffer_ownership_; |
62 const BufferPlanarity planarity_; | |
63 // Frame rate of the fake video device. | 53 // Frame rate of the fake video device. |
64 const float fake_capture_rate_; | 54 const float fake_capture_rate_; |
65 | 55 |
66 scoped_ptr<VideoCaptureDevice::Client> client_; | 56 scoped_ptr<VideoCaptureDevice::Client> client_; |
67 // |fake_frame_| is used for capturing on Own Buffers. | 57 // |fake_frame_| is used for capturing on Own Buffers. |
68 scoped_ptr<uint8_t[]> fake_frame_; | 58 scoped_ptr<uint8_t[]> fake_frame_; |
69 // Time when the next beep occurs. | 59 // Time when the next beep occurs. |
70 base::TimeDelta beep_time_; | 60 base::TimeDelta beep_time_; |
71 // Time since the fake video started rendering frames. | 61 // Time since the fake video started rendering frames. |
72 base::TimeDelta elapsed_time_; | 62 base::TimeDelta elapsed_time_; |
73 VideoCaptureFormat capture_format_; | 63 VideoCaptureFormat capture_format_; |
74 | 64 |
75 // FakeVideoCaptureDevice post tasks to itself for frame construction and | 65 // FakeVideoCaptureDevice post tasks to itself for frame construction and |
76 // needs to deal with asynchronous StopAndDeallocate(). | 66 // needs to deal with asynchronous StopAndDeallocate(). |
77 base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_; | 67 base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_; |
78 | 68 |
79 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice); | 69 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice); |
80 }; | 70 }; |
81 | 71 |
82 } // namespace media | 72 } // namespace media |
83 | 73 |
84 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ | 74 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |