Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Side by Side Diff: media/video/capture/fake_video_capture_device.cc

Issue 17846002: Refactor the VideoCaptureDevice::Name struct. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 enum { kNumberOfFakeDevices = 2 }; 21 enum { kNumberOfFakeDevices = 2 };
22 22
23 bool FakeVideoCaptureDevice::fail_next_create_ = false; 23 bool FakeVideoCaptureDevice::fail_next_create_ = false;
24 24
25 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { 25 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) {
26 // Empty the name list. 26 // Empty the name list.
27 device_names->erase(device_names->begin(), device_names->end()); 27 device_names->erase(device_names->begin(), device_names->end());
28 28
29 for (int n = 0; n < kNumberOfFakeDevices; n++) { 29 for (int n = 0; n < kNumberOfFakeDevices; n++) {
30 Name name; 30 Name name(base::StringPrintf("fake_device_%d", n),
31 name.unique_id = base::StringPrintf("/dev/video%d", n); 31 base::StringPrintf("/dev/video%d", n));
32 name.device_name = base::StringPrintf("fake_device_%d", n);
33 device_names->push_back(name); 32 device_names->push_back(name);
34 } 33 }
35 } 34 }
36 35
37 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { 36 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) {
38 if (fail_next_create_) { 37 if (fail_next_create_) {
39 fail_next_create_ = false; 38 fail_next_create_ = false;
40 return NULL; 39 return NULL;
41 } 40 }
42 for (int n = 0; n < kNumberOfFakeDevices; ++n) { 41 for (int n = 0; n < kNumberOfFakeDevices; ++n) {
43 std::string possible_id = base::StringPrintf("/dev/video%d", n); 42 std::string possible_id = base::StringPrintf("/dev/video%d", n);
44 if (device_name.unique_id.compare(possible_id) == 0) { 43 if (device_name.id().compare(possible_id) == 0) {
45 return new FakeVideoCaptureDevice(device_name); 44 return new FakeVideoCaptureDevice(device_name);
46 } 45 }
47 } 46 }
48 return NULL; 47 return NULL;
49 } 48 }
50 49
51 void FakeVideoCaptureDevice::SetFailNextCreate() { 50 void FakeVideoCaptureDevice::SetFailNextCreate() {
52 fail_next_create_ = true; 51 fail_next_create_ = true;
53 } 52 }
54 53
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 fake_frame_.get(), frame_size_, base::Time::Now(), 0, false, false); 195 fake_frame_.get(), frame_size_, base::Time::Now(), 0, false, false);
197 // Reschedule next CaptureTask. 196 // Reschedule next CaptureTask.
198 capture_thread_.message_loop()->PostDelayedTask( 197 capture_thread_.message_loop()->PostDelayedTask(
199 FROM_HERE, 198 FROM_HERE,
200 base::Bind(&FakeVideoCaptureDevice::OnCaptureTask, 199 base::Bind(&FakeVideoCaptureDevice::OnCaptureTask,
201 base::Unretained(this)), 200 base::Unretained(this)),
202 base::TimeDelta::FromMilliseconds(kFakeCaptureTimeoutMs)); 201 base::TimeDelta::FromMilliseconds(kFakeCaptureTimeoutMs));
203 } 202 }
204 203
205 } // namespace media 204 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/android/video_capture_device_android.cc ('k') | media/video/capture/linux/video_capture_device_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698