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 <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 // Used for testing. This will make sure the next call to Create will | 23 // Used for testing. This will make sure the next call to Create will |
24 // return NULL; | 24 // return NULL; |
25 static void SetFailNextCreate(); | 25 static void SetFailNextCreate(); |
26 static void SetNumberOfFakeDevices(int num); | |
27 static int NumberOfFakeDevices(); | |
perkj_chrome
2013/11/27 17:53:12
Fyi- I am trying to do the same thing in https://c
mcasas
2013/12/03 14:28:41
First one wins! :)
Kidding: I'll rebase against yo
| |
26 | 28 |
27 static void GetDeviceNames(Names* device_names); | 29 static void GetDeviceNames(Names* device_names); |
28 static void GetDeviceSupportedFormats(const Name& device, | 30 static void GetDeviceSupportedFormats(const Name& device, |
29 VideoCaptureCapabilities* formats); | 31 VideoCaptureFormats* supported_formats); |
30 | 32 |
31 // VideoCaptureDevice implementation. | 33 // VideoCaptureDevice implementation. |
32 virtual void AllocateAndStart(const VideoCaptureParams& params, | 34 virtual void AllocateAndStart(const VideoCaptureParams& params, |
33 scoped_ptr<VideoCaptureDevice::Client> client) | 35 scoped_ptr<VideoCaptureDevice::Client> client) |
34 OVERRIDE; | 36 OVERRIDE; |
35 virtual void StopAndDeAllocate() OVERRIDE; | 37 virtual void StopAndDeAllocate() OVERRIDE; |
36 | 38 |
37 private: | 39 private: |
38 // Flag indicating the internal state. | 40 // Flag indicating the internal state. |
39 enum InternalState { | 41 enum InternalState { |
40 kIdle, | 42 kIdle, |
41 kCapturing, | 43 kCapturing, |
42 kError | 44 kError |
43 }; | 45 }; |
44 FakeVideoCaptureDevice(); | 46 FakeVideoCaptureDevice(); |
45 | 47 |
46 // Called on the capture_thread_. | 48 // Called on the capture_thread_. |
47 void OnCaptureTask(); | 49 void OnCaptureTask(); |
48 | |
49 // EXPERIMENTAL, similar to allocate, but changes resolution and calls | |
perkj_chrome
2013/11/27 17:53:12
And this - is this intentional?
mcasas
2013/12/03 14:28:41
Well, this code is not experimental anymore (I add
| |
50 // client->OnFrameInfoChanged(VideoCaptureCapability&) | |
51 void Reallocate(); | 50 void Reallocate(); |
52 void PopulateFormatRoster(); | 51 void PopulateFormatRoster(); |
53 | 52 |
54 scoped_ptr<VideoCaptureDevice::Client> client_; | 53 scoped_ptr<VideoCaptureDevice::Client> client_; |
55 InternalState state_; | 54 InternalState state_; |
56 base::Thread capture_thread_; | 55 base::Thread capture_thread_; |
57 scoped_ptr<uint8[]> fake_frame_; | 56 scoped_ptr<uint8[]> fake_frame_; |
58 int frame_count_; | 57 int frame_count_; |
59 VideoCaptureFormat capture_format_; | 58 VideoCaptureFormat capture_format_; |
60 | 59 |
61 // When the device is configured as mutating video captures, this vector | 60 // When the device is configured as mutating video captures, this vector |
62 // holds the available ones which are used in sequence, restarting at the end. | 61 // holds the available ones which are used in sequence, restarting at the end. |
63 std::vector<VideoCaptureFormat> format_roster_; | 62 std::vector<VideoCaptureFormat> format_roster_; |
64 int format_roster_index_; | 63 int format_roster_index_; |
65 | 64 |
65 static int number_of_fake_devices_; | |
perkj_chrome
2013/11/27 17:53:12
atomic32 if you touch this from several threads li
mcasas
2013/12/03 14:28:41
If you only have one setter and multiple getters,
| |
66 static bool fail_next_create_; | 66 static bool fail_next_create_; |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice); | 68 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice); |
69 }; | 69 }; |
70 | 70 |
71 } // namespace media | 71 } // namespace media |
72 | 72 |
73 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ | 73 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |