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 }; | |
23 | 22 |
| 23 int FakeVideoCaptureDevice::numberOfFakeDevices = 2; |
24 bool FakeVideoCaptureDevice::fail_next_create_ = false; | 24 bool FakeVideoCaptureDevice::fail_next_create_ = false; |
25 | 25 |
| 26 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(int num) { |
| 27 numberOfFakeDevices = num; |
| 28 } |
| 29 |
| 30 int FakeVideoCaptureDevice::NumberOfFakeDevices(void) { |
| 31 return numberOfFakeDevices; |
| 32 } |
| 33 |
26 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { | 34 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { |
27 // Empty the name list. | 35 // Empty the name list. |
28 device_names->erase(device_names->begin(), device_names->end()); | 36 device_names->erase(device_names->begin(), device_names->end()); |
29 | 37 |
30 for (int n = 0; n < kNumberOfFakeDevices; n++) { | 38 for (int n = 0; n < numberOfFakeDevices; n++) { |
31 Name name(base::StringPrintf("fake_device_%d", n), | 39 Name name(base::StringPrintf("fake_device_%d", n), |
32 base::StringPrintf("/dev/video%d", n)); | 40 base::StringPrintf("/dev/video%d", n)); |
33 device_names->push_back(name); | 41 device_names->push_back(name); |
34 } | 42 } |
35 } | 43 } |
36 | 44 |
37 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( | 45 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( |
38 const Name& device, | 46 const Name& device, |
39 VideoCaptureCapabilities* formats) { | 47 VideoCaptureCapabilities* formats) { |
40 VideoCaptureCapability capture_format; | 48 formats->clear(); |
41 capture_format.color = media::PIXEL_FORMAT_I420; | 49 VideoCaptureCapability capture_format_640x480; |
42 capture_format.width = 640; | 50 capture_format_640x480.color = media::PIXEL_FORMAT_I420; |
43 capture_format.height = 480; | 51 capture_format_640x480.width = 640; |
44 capture_format.frame_rate = 1000 / kFakeCaptureTimeoutMs; | 52 capture_format_640x480.height = 480; |
45 formats->push_back(capture_format); | 53 capture_format_640x480.frame_rate = 1000 / kFakeCaptureTimeoutMs; |
| 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); |
46 } | 61 } |
47 | 62 |
48 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { | 63 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { |
49 if (fail_next_create_) { | 64 if (fail_next_create_) { |
50 fail_next_create_ = false; | 65 fail_next_create_ = false; |
51 return NULL; | 66 return NULL; |
52 } | 67 } |
53 for (int n = 0; n < kNumberOfFakeDevices; ++n) { | 68 for (int n = 0; n < numberOfFakeDevices; ++n) { |
54 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 69 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
55 if (device_name.id().compare(possible_id) == 0) { | 70 if (device_name.id().compare(possible_id) == 0) { |
56 return new FakeVideoCaptureDevice(); | 71 return new FakeVideoCaptureDevice(); |
57 } | 72 } |
58 } | 73 } |
59 return NULL; | 74 return NULL; |
60 } | 75 } |
61 | 76 |
62 void FakeVideoCaptureDevice::SetFailNextCreate() { | 77 void FakeVideoCaptureDevice::SetFailNextCreate() { |
63 fail_next_create_ = true; | 78 fail_next_create_ = true; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 media::VideoCaptureCapability(800, | 247 media::VideoCaptureCapability(800, |
233 600, | 248 600, |
234 30, | 249 30, |
235 PIXEL_FORMAT_I420, | 250 PIXEL_FORMAT_I420, |
236 VariableResolutionVideoCaptureDevice)); | 251 VariableResolutionVideoCaptureDevice)); |
237 | 252 |
238 capabilities_roster_index_ = 0; | 253 capabilities_roster_index_ = 0; |
239 } | 254 } |
240 | 255 |
241 } // namespace media | 256 } // namespace media |
OLD | NEW |