OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 11 #include <string> |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "media/video/capture/video_capture_device.h" | 15 #include "media/video/capture/video_capture_device.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { | 19 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { |
20 public: | 20 public: |
21 static VideoCaptureDevice* Create(const Name& device_name); | 21 static VideoCaptureDevice* Create(const Name& device_name); |
22 virtual ~FakeVideoCaptureDevice(); | 22 virtual ~FakeVideoCaptureDevice(); |
23 | 23 |
24 static void GetDeviceNames(Names* device_names); | 24 static void GetDeviceNames(Names* device_names); |
25 | 25 |
26 // VideoCaptureDevice implementation. | 26 // VideoCaptureDevice implementation. |
27 virtual void Allocate(int width, | 27 virtual void Allocate(int width, |
28 int height, | 28 int height, |
29 int frame_rate, | 29 int frame_rate, |
30 VideoCaptureDevice::EventHandler* observer); | 30 VideoCaptureDevice::EventHandler* observer) OVERRIDE; |
31 virtual void Start(); | 31 virtual void Start() OVERRIDE; |
32 virtual void Stop(); | 32 virtual void Stop() OVERRIDE; |
33 virtual void DeAllocate(); | 33 virtual void DeAllocate() OVERRIDE; |
34 virtual const Name& device_name(); | 34 virtual const Name& device_name() OVERRIDE; |
35 | 35 |
36 private: | 36 private: |
37 // Flag indicating the internal state. | 37 // Flag indicating the internal state. |
38 enum InternalState { | 38 enum InternalState { |
39 kIdle, | 39 kIdle, |
40 kAllocated, | 40 kAllocated, |
41 kCapturing, | 41 kCapturing, |
42 kError | 42 kError |
43 }; | 43 }; |
44 explicit FakeVideoCaptureDevice(const Name& device_name); | 44 explicit FakeVideoCaptureDevice(const Name& device_name); |
45 | 45 |
46 // Called on the capture_thread_. | 46 // Called on the capture_thread_. |
47 void OnCaptureTask(); | 47 void OnCaptureTask(); |
48 | 48 |
49 Name device_name_; | 49 Name device_name_; |
50 VideoCaptureDevice::EventHandler* observer_; | 50 VideoCaptureDevice::EventHandler* observer_; |
51 InternalState state_; | 51 InternalState state_; |
52 base::Thread capture_thread_; | 52 base::Thread capture_thread_; |
53 scoped_array<uint8> fake_frame_; | 53 scoped_array<uint8> fake_frame_; |
54 | 54 |
55 DISALLOW_IMPLICIT_CONSTRUCTORS(FakeVideoCaptureDevice); | 55 DISALLOW_IMPLICIT_CONSTRUCTORS(FakeVideoCaptureDevice); |
56 }; | 56 }; |
57 | 57 |
58 } // namespace media | 58 } // namespace media |
59 | 59 |
60 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FakeVideoCaptureDevice); | 60 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FakeVideoCaptureDevice); |
61 | 61 |
62 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ | 62 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |