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::number_of_fake_devices_ = 2; |
24 bool FakeVideoCaptureDevice::fail_next_create_ = false; | 24 bool FakeVideoCaptureDevice::fail_next_create_ = false; |
25 | 25 |
| 26 // static |
| 27 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(int num) { |
| 28 number_of_fake_devices_ = num; |
| 29 } |
| 30 |
| 31 // static |
| 32 int FakeVideoCaptureDevice::NumberOfFakeDevices(void) { |
| 33 return number_of_fake_devices_; |
| 34 } |
| 35 |
| 36 // static |
26 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { | 37 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { |
27 // Empty the name list. | 38 // Empty the name list. |
28 device_names->erase(device_names->begin(), device_names->end()); | 39 device_names->erase(device_names->begin(), device_names->end()); |
29 | 40 |
30 for (int n = 0; n < kNumberOfFakeDevices; n++) { | 41 for (int n = 0; n < number_of_fake_devices_; n++) { |
31 Name name(base::StringPrintf("fake_device_%d", n), | 42 Name name(base::StringPrintf("fake_device_%d", n), |
32 base::StringPrintf("/dev/video%d", n)); | 43 base::StringPrintf("/dev/video%d", n)); |
33 device_names->push_back(name); | 44 device_names->push_back(name); |
34 } | 45 } |
35 } | 46 } |
36 | 47 |
| 48 // static |
37 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( | 49 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( |
38 const Name& device, | 50 const Name& device, |
39 VideoCaptureCapabilities* formats) { | 51 VideoCaptureFormats* supported_formats) { |
40 VideoCaptureCapability capture_format_640x480; | 52 |
41 capture_format_640x480.supported_format.frame_size.SetSize(640, 480); | 53 supported_formats->clear(); |
42 capture_format_640x480.supported_format.frame_rate = | 54 VideoCaptureFormat capture_format_640x480; |
43 1000 / kFakeCaptureTimeoutMs; | 55 capture_format_640x480.pixel_format = media::PIXEL_FORMAT_I420; |
44 capture_format_640x480.supported_format.pixel_format = | 56 capture_format_640x480.frame_size.SetSize(640, 480); |
45 media::PIXEL_FORMAT_I420; | 57 capture_format_640x480.frame_rate = 1000 / kFakeCaptureTimeoutMs; |
46 formats->push_back(capture_format_640x480); | 58 supported_formats->push_back(capture_format_640x480); |
| 59 VideoCaptureFormat capture_format_320x240; |
| 60 capture_format_320x240.pixel_format = media::PIXEL_FORMAT_I420; |
| 61 capture_format_320x240.frame_size.SetSize(320, 240); |
| 62 capture_format_320x240.frame_rate = 1000 / kFakeCaptureTimeoutMs; |
| 63 supported_formats->push_back(capture_format_320x240); |
47 } | 64 } |
48 | 65 |
| 66 // static |
49 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { | 67 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { |
50 if (fail_next_create_) { | 68 if (fail_next_create_) { |
51 fail_next_create_ = false; | 69 fail_next_create_ = false; |
52 return NULL; | 70 return NULL; |
53 } | 71 } |
54 for (int n = 0; n < kNumberOfFakeDevices; ++n) { | 72 for (int n = 0; n < number_of_fake_devices_; ++n) { |
55 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 73 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
56 if (device_name.id().compare(possible_id) == 0) { | 74 if (device_name.id().compare(possible_id) == 0) { |
57 return new FakeVideoCaptureDevice(); | 75 return new FakeVideoCaptureDevice(); |
58 } | 76 } |
59 } | 77 } |
60 return NULL; | 78 return NULL; |
61 } | 79 } |
62 | 80 |
| 81 // static |
63 void FakeVideoCaptureDevice::SetFailNextCreate() { | 82 void FakeVideoCaptureDevice::SetFailNextCreate() { |
64 fail_next_create_ = true; | 83 fail_next_create_ = true; |
65 } | 84 } |
66 | 85 |
67 FakeVideoCaptureDevice::FakeVideoCaptureDevice() | 86 FakeVideoCaptureDevice::FakeVideoCaptureDevice() |
68 : state_(kIdle), | 87 : state_(kIdle), |
69 capture_thread_("CaptureThread"), | 88 capture_thread_("CaptureThread"), |
70 frame_count_(0), | 89 frame_count_(0), |
71 format_roster_index_(0) {} | 90 format_roster_index_(0) {} |
72 | 91 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); | 236 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); |
218 format_roster_.push_back( | 237 format_roster_.push_back( |
219 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); | 238 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); |
220 format_roster_.push_back( | 239 format_roster_.push_back( |
221 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); | 240 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); |
222 | 241 |
223 format_roster_index_ = 0; | 242 format_roster_index_ = 0; |
224 } | 243 } |
225 | 244 |
226 } // namespace media | 245 } // namespace media |
OLD | NEW |