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 #include "media/video/capture/fake_video_capture_device.h" | 5 #include "media/video/capture/fake_video_capture_device.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "media/audio/fake_audio_input_stream.h" | 12 #include "media/audio/fake_audio_input_stream.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
15 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 static const int kFakeCaptureTimeoutMs = 50; | 19 static const int kFakeCaptureTimeoutMs = 50; |
20 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s. | 20 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s. |
21 static const int kFakeCaptureCapabilityChangePeriod = 30; | 21 static const int kFakeCaptureCapabilityChangePeriod = 30; |
| 22 enum { kNumberOfFakeDevices = 2 }; |
22 | 23 |
23 int FakeVideoCaptureDevice::number_of_fake_devices_ = 2; | |
24 bool FakeVideoCaptureDevice::fail_next_create_ = false; | 24 bool FakeVideoCaptureDevice::fail_next_create_ = false; |
25 | 25 |
26 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(int num) { | |
27 number_of_fake_devices_ = num; | |
28 } | |
29 | |
30 int FakeVideoCaptureDevice::NumberOfFakeDevices(void) { | |
31 return number_of_fake_devices_; | |
32 } | |
33 | |
34 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { | 26 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { |
35 // Empty the name list. | 27 // Empty the name list. |
36 device_names->erase(device_names->begin(), device_names->end()); | 28 device_names->erase(device_names->begin(), device_names->end()); |
37 | 29 |
38 for (int n = 0; n < number_of_fake_devices_; n++) { | 30 for (int n = 0; n < kNumberOfFakeDevices; n++) { |
39 Name name(base::StringPrintf("fake_device_%d", n), | 31 Name name(base::StringPrintf("fake_device_%d", n), |
40 base::StringPrintf("/dev/video%d", n)); | 32 base::StringPrintf("/dev/video%d", n)); |
41 device_names->push_back(name); | 33 device_names->push_back(name); |
42 } | 34 } |
43 } | 35 } |
44 | 36 |
45 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( | 37 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( |
46 const Name& device, | 38 const Name& device, |
47 VideoCaptureCapabilities* formats) { | 39 VideoCaptureCapabilities* formats) { |
48 formats->clear(); | 40 VideoCaptureCapability capture_format; |
49 VideoCaptureCapability capture_format_640x480; | 41 capture_format.color = media::PIXEL_FORMAT_I420; |
50 capture_format_640x480.color = media::PIXEL_FORMAT_I420; | 42 capture_format.width = 640; |
51 capture_format_640x480.width = 640; | 43 capture_format.height = 480; |
52 capture_format_640x480.height = 480; | 44 capture_format.frame_rate = 1000 / kFakeCaptureTimeoutMs; |
53 capture_format_640x480.frame_rate = 1000 / kFakeCaptureTimeoutMs; | 45 formats->push_back(capture_format); |
54 formats->push_back(capture_format_640x480); | |
55 VideoCaptureCapability capture_format_320x240; | |
56 capture_format_320x240.color = media::PIXEL_FORMAT_I420; | |
57 capture_format_320x240.width = 320; | |
58 capture_format_320x240.height = 240; | |
59 capture_format_320x240.frame_rate = 1000 / kFakeCaptureTimeoutMs; | |
60 formats->push_back(capture_format_320x240); | |
61 } | 46 } |
62 | 47 |
63 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { | 48 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { |
64 if (fail_next_create_) { | 49 if (fail_next_create_) { |
65 fail_next_create_ = false; | 50 fail_next_create_ = false; |
66 return NULL; | 51 return NULL; |
67 } | 52 } |
68 for (int n = 0; n < number_of_fake_devices_; ++n) { | 53 for (int n = 0; n < kNumberOfFakeDevices; ++n) { |
69 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 54 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
70 if (device_name.id().compare(possible_id) == 0) { | 55 if (device_name.id().compare(possible_id) == 0) { |
71 return new FakeVideoCaptureDevice(); | 56 return new FakeVideoCaptureDevice(); |
72 } | 57 } |
73 } | 58 } |
74 return NULL; | 59 return NULL; |
75 } | 60 } |
76 | 61 |
77 void FakeVideoCaptureDevice::SetFailNextCreate() { | 62 void FakeVideoCaptureDevice::SetFailNextCreate() { |
78 fail_next_create_ = true; | 63 fail_next_create_ = true; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 media::VideoCaptureCapability(800, | 232 media::VideoCaptureCapability(800, |
248 600, | 233 600, |
249 30, | 234 30, |
250 PIXEL_FORMAT_I420, | 235 PIXEL_FORMAT_I420, |
251 VariableResolutionVideoCaptureDevice)); | 236 VariableResolutionVideoCaptureDevice)); |
252 | 237 |
253 capabilities_roster_index_ = 0; | 238 capabilities_roster_index_ = 0; |
254 } | 239 } |
255 | 240 |
256 } // namespace media | 241 } // namespace media |
OLD | NEW |