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/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
scherkus (not reviewing)
2013/12/03 22:04:48
I think you can remove this header file now that y
mcasas
2013/12/04 15:23:32
Done.
| |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "media/audio/fake_audio_input_stream.h" | 13 #include "media/audio/fake_audio_input_stream.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 | 19 |
20 static const int kFakeCaptureTimeoutMs = 50; | 20 static const int kFakeCaptureTimeoutMs = 50; |
21 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s. | 21 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s. |
22 static const int kFakeCaptureCapabilityChangePeriod = 30; | 22 static const int kFakeCaptureCapabilityChangePeriod = 30; |
23 enum { kNumberOfFakeDevices = 2 }; | 23 enum { kNumberOfFakeDevices = 2 }; |
24 | 24 |
25 bool FakeVideoCaptureDevice::fail_next_create_ = false; | 25 bool FakeVideoCaptureDevice::fail_next_create_ = false; |
26 base::subtle::Atomic32 FakeVideoCaptureDevice::number_of_devices_ = | 26 base::subtle::Atomic32 FakeVideoCaptureDevice::number_of_devices_ = |
27 kNumberOfFakeDevices; | 27 kNumberOfFakeDevices; |
28 | 28 |
29 // static | |
30 int FakeVideoCaptureDevice::NumberOfFakeDevices(void) { | |
31 return number_of_devices_; | |
32 } | |
33 | |
34 // static | |
29 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { | 35 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { |
30 // Empty the name list. | 36 // Empty the name list. |
31 device_names->erase(device_names->begin(), device_names->end()); | 37 device_names->erase(device_names->begin(), device_names->end()); |
32 | 38 |
33 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_); | 39 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_); |
34 for (int32 n = 0; n < number_of_devices; n++) { | 40 for (int32 n = 0; n < number_of_devices; n++) { |
35 Name name("fake_device_" + base::IntToString(n), | 41 Name name(base::StringPrintf("fake_device_%d", n), |
36 "/dev/video" + base::IntToString(n)); | 42 base::StringPrintf("/dev/video%d", n)); |
37 device_names->push_back(name); | 43 device_names->push_back(name); |
38 } | 44 } |
39 } | 45 } |
40 | 46 |
47 // static | |
41 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( | 48 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( |
42 const Name& device, | 49 const Name& device, |
43 VideoCaptureCapabilities* formats) { | 50 VideoCaptureFormats* supported_formats) { |
44 VideoCaptureCapability capture_format_640x480; | 51 |
45 capture_format_640x480.supported_format.frame_size.SetSize(640, 480); | 52 supported_formats->clear(); |
46 capture_format_640x480.supported_format.frame_rate = | 53 VideoCaptureFormat capture_format_640x480; |
47 1000 / kFakeCaptureTimeoutMs; | 54 capture_format_640x480.pixel_format = media::PIXEL_FORMAT_I420; |
48 capture_format_640x480.supported_format.pixel_format = | 55 capture_format_640x480.frame_size.SetSize(640, 480); |
49 media::PIXEL_FORMAT_I420; | 56 capture_format_640x480.frame_rate = 1000 / kFakeCaptureTimeoutMs; |
50 formats->push_back(capture_format_640x480); | 57 supported_formats->push_back(capture_format_640x480); |
58 VideoCaptureFormat capture_format_320x240; | |
59 capture_format_320x240.pixel_format = media::PIXEL_FORMAT_I420; | |
60 capture_format_320x240.frame_size.SetSize(320, 240); | |
61 capture_format_320x240.frame_rate = 1000 / kFakeCaptureTimeoutMs; | |
62 supported_formats->push_back(capture_format_320x240); | |
51 } | 63 } |
52 | 64 |
65 // static | |
53 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { | 66 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { |
54 if (fail_next_create_) { | 67 if (fail_next_create_) { |
55 fail_next_create_ = false; | 68 fail_next_create_ = false; |
56 return NULL; | 69 return NULL; |
57 } | 70 } |
58 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_); | 71 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_); |
59 for (int32 n = 0; n < number_of_devices; ++n) { | 72 for (int32 n = 0; n < number_of_devices; ++n) { |
60 std::string possible_id = "/dev/video" + base::IntToString(n); | 73 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
61 if (device_name.id().compare(possible_id) == 0) { | 74 if (device_name.id().compare(possible_id) == 0) { |
62 return new FakeVideoCaptureDevice(); | 75 return new FakeVideoCaptureDevice(); |
63 } | 76 } |
64 } | 77 } |
65 return NULL; | 78 return NULL; |
66 } | 79 } |
67 | 80 |
81 // static | |
68 void FakeVideoCaptureDevice::SetFailNextCreate() { | 82 void FakeVideoCaptureDevice::SetFailNextCreate() { |
69 fail_next_create_ = true; | 83 fail_next_create_ = true; |
70 } | 84 } |
71 | 85 |
86 // static | |
72 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) { | 87 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) { |
73 base::subtle::NoBarrier_AtomicExchange(&number_of_devices_, | 88 base::subtle::NoBarrier_AtomicExchange(&number_of_devices_, |
74 number_of_devices); | 89 number_of_devices); |
75 } | 90 } |
76 | 91 |
77 FakeVideoCaptureDevice::FakeVideoCaptureDevice() | 92 FakeVideoCaptureDevice::FakeVideoCaptureDevice() |
78 : state_(kIdle), | 93 : state_(kIdle), |
79 capture_thread_("CaptureThread"), | 94 capture_thread_("CaptureThread"), |
80 frame_count_(0), | 95 frame_count_(0), |
81 format_roster_index_(0) {} | 96 format_roster_index_(0) {} |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); | 242 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); |
228 format_roster_.push_back( | 243 format_roster_.push_back( |
229 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); | 244 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); |
230 format_roster_.push_back( | 245 format_roster_.push_back( |
231 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); | 246 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); |
232 | 247 |
233 format_roster_index_ = 0; | 248 format_roster_index_ = 0; |
234 } | 249 } |
235 | 250 |
236 } // namespace media | 251 } // namespace media |
OLD | NEW |