Chromium Code Reviews| 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/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "media/audio/fake_audio_input_stream.h" | 13 #include "media/audio/fake_audio_input_stream.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
| 16 | 17 |
| 17 namespace media { | 18 namespace media { |
| 18 | 19 |
| 19 static const int kFakeCaptureTimeoutMs = 50; | 20 static const int kFakeCaptureTimeoutMs = 50; |
| 20 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s. | 21 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s. |
| 21 static const int kFakeCaptureCapabilityChangePeriod = 30; | 22 static const int kFakeCaptureCapabilityChangePeriod = 30; |
| 22 enum { kNumberOfFakeDevices = 2 }; | 23 enum { kNumberOfFakeDevices = 2 }; |
| 23 | 24 |
| 24 bool FakeVideoCaptureDevice::fail_next_create_ = false; | 25 bool FakeVideoCaptureDevice::fail_next_create_ = false; |
| 26 base::subtle::Atomic32 FakeVideoCaptureDevice::number_of_devices_ = | |
| 27 kNumberOfFakeDevices; | |
| 25 | 28 |
| 26 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { | 29 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { |
| 27 // Empty the name list. | 30 // Empty the name list. |
| 28 device_names->erase(device_names->begin(), device_names->end()); | 31 device_names->erase(device_names->begin(), device_names->end()); |
| 29 | 32 |
| 30 for (int n = 0; n < kNumberOfFakeDevices; n++) { | 33 for (int32 n = 0; n < number_of_devices_; n++) { |
|
tommi (sloooow) - chröme
2013/11/27 22:09:43
for atomic values you need to fetch/load their val
perkj_chrome
2013/11/28 09:46:43
Done.
| |
| 31 Name name(base::StringPrintf("fake_device_%d", n), | 34 Name name("fake_device_" + base::IntToString(n), |
| 32 base::StringPrintf("/dev/video%d", n)); | 35 "/dev/video" + base::IntToString(n)); |
| 33 device_names->push_back(name); | 36 device_names->push_back(name); |
| 34 } | 37 } |
| 35 } | 38 } |
| 36 | 39 |
| 37 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( | 40 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( |
| 38 const Name& device, | 41 const Name& device, |
| 39 VideoCaptureCapabilities* formats) { | 42 VideoCaptureCapabilities* formats) { |
| 40 VideoCaptureCapability capture_format_640x480; | 43 VideoCaptureCapability capture_format_640x480; |
| 41 capture_format_640x480.supported_format.frame_size.SetSize(640, 480); | 44 capture_format_640x480.supported_format.frame_size.SetSize(640, 480); |
| 42 capture_format_640x480.supported_format.frame_rate = | 45 capture_format_640x480.supported_format.frame_rate = |
| 43 1000 / kFakeCaptureTimeoutMs; | 46 1000 / kFakeCaptureTimeoutMs; |
| 44 capture_format_640x480.supported_format.pixel_format = | 47 capture_format_640x480.supported_format.pixel_format = |
| 45 media::PIXEL_FORMAT_I420; | 48 media::PIXEL_FORMAT_I420; |
| 46 formats->push_back(capture_format_640x480); | 49 formats->push_back(capture_format_640x480); |
| 47 } | 50 } |
| 48 | 51 |
| 49 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { | 52 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { |
| 50 if (fail_next_create_) { | 53 if (fail_next_create_) { |
| 51 fail_next_create_ = false; | 54 fail_next_create_ = false; |
| 52 return NULL; | 55 return NULL; |
| 53 } | 56 } |
| 54 for (int n = 0; n < kNumberOfFakeDevices; ++n) { | 57 for (int32 n = 0; n < number_of_devices_; ++n) { |
|
tommi (sloooow) - chröme
2013/11/27 22:09:43
atomic load
perkj_chrome
2013/11/28 09:46:43
Done.
| |
| 55 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 58 std::string possible_id = "/dev/video" + base::IntToString(n); |
| 56 if (device_name.id().compare(possible_id) == 0) { | 59 if (device_name.id().compare(possible_id) == 0) { |
| 57 return new FakeVideoCaptureDevice(); | 60 return new FakeVideoCaptureDevice(); |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 return NULL; | 63 return NULL; |
| 61 } | 64 } |
| 62 | 65 |
| 63 void FakeVideoCaptureDevice::SetFailNextCreate() { | 66 void FakeVideoCaptureDevice::SetFailNextCreate() { |
| 64 fail_next_create_ = true; | 67 fail_next_create_ = true; |
| 65 } | 68 } |
| 66 | 69 |
| 70 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) { | |
| 71 number_of_devices_ = number_of_devices; | |
|
tommi (sloooow) - chröme
2013/11/27 22:09:43
you need to use atomic operations on the Atomic32
perkj_chrome
2013/11/28 09:46:43
Done.
| |
| 72 } | |
| 73 | |
| 67 FakeVideoCaptureDevice::FakeVideoCaptureDevice() | 74 FakeVideoCaptureDevice::FakeVideoCaptureDevice() |
| 68 : state_(kIdle), | 75 : state_(kIdle), |
| 69 capture_thread_("CaptureThread"), | 76 capture_thread_("CaptureThread"), |
| 70 frame_count_(0), | 77 frame_count_(0), |
| 71 format_roster_index_(0) {} | 78 format_roster_index_(0) {} |
| 72 | 79 |
| 73 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { | 80 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { |
| 74 // Check if the thread is running. | 81 // Check if the thread is running. |
| 75 // This means that the device have not been DeAllocated properly. | 82 // This means that the device have not been DeAllocated properly. |
| 76 DCHECK(!capture_thread_.IsRunning()); | 83 DCHECK(!capture_thread_.IsRunning()); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); | 224 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); |
| 218 format_roster_.push_back( | 225 format_roster_.push_back( |
| 219 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); | 226 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); |
| 220 format_roster_.push_back( | 227 format_roster_.push_back( |
| 221 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); | 228 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); |
| 222 | 229 |
| 223 format_roster_index_ = 0; | 230 format_roster_index_ = 0; |
| 224 } | 231 } |
| 225 | 232 |
| 226 } // namespace media | 233 } // namespace media |
| OLD | NEW |