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

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

Issue 88283002: Reland review 34393006: Refactor MediaStreamManager to not output real device id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years 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
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_);
31 Name name(base::StringPrintf("fake_device_%d", n), 34 for (int32 n = 0; n < number_of_devices; n++) {
32 base::StringPrintf("/dev/video%d", n)); 35 Name name("fake_device_" + base::IntToString(n),
36 "/dev/video" + base::IntToString(n));
33 device_names->push_back(name); 37 device_names->push_back(name);
34 } 38 }
35 } 39 }
36 40
37 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( 41 void FakeVideoCaptureDevice::GetDeviceSupportedFormats(
38 const Name& device, 42 const Name& device,
39 VideoCaptureCapabilities* formats) { 43 VideoCaptureCapabilities* formats) {
40 VideoCaptureCapability capture_format_640x480; 44 VideoCaptureCapability capture_format_640x480;
41 capture_format_640x480.supported_format.frame_size.SetSize(640, 480); 45 capture_format_640x480.supported_format.frame_size.SetSize(640, 480);
42 capture_format_640x480.supported_format.frame_rate = 46 capture_format_640x480.supported_format.frame_rate =
43 1000 / kFakeCaptureTimeoutMs; 47 1000 / kFakeCaptureTimeoutMs;
44 capture_format_640x480.supported_format.pixel_format = 48 capture_format_640x480.supported_format.pixel_format =
45 media::PIXEL_FORMAT_I420; 49 media::PIXEL_FORMAT_I420;
46 formats->push_back(capture_format_640x480); 50 formats->push_back(capture_format_640x480);
47 } 51 }
48 52
49 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { 53 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) {
50 if (fail_next_create_) { 54 if (fail_next_create_) {
51 fail_next_create_ = false; 55 fail_next_create_ = false;
52 return NULL; 56 return NULL;
53 } 57 }
54 for (int n = 0; n < kNumberOfFakeDevices; ++n) { 58 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_);
55 std::string possible_id = base::StringPrintf("/dev/video%d", n); 59 for (int32 n = 0; n < number_of_devices; ++n) {
60 std::string possible_id = "/dev/video" + base::IntToString(n);
56 if (device_name.id().compare(possible_id) == 0) { 61 if (device_name.id().compare(possible_id) == 0) {
57 return new FakeVideoCaptureDevice(); 62 return new FakeVideoCaptureDevice();
58 } 63 }
59 } 64 }
60 return NULL; 65 return NULL;
61 } 66 }
62 67
63 void FakeVideoCaptureDevice::SetFailNextCreate() { 68 void FakeVideoCaptureDevice::SetFailNextCreate() {
64 fail_next_create_ = true; 69 fail_next_create_ = true;
65 } 70 }
66 71
72 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) {
73 base::subtle::NoBarrier_AtomicExchange(&number_of_devices_,
74 number_of_devices);
75 }
76
67 FakeVideoCaptureDevice::FakeVideoCaptureDevice() 77 FakeVideoCaptureDevice::FakeVideoCaptureDevice()
68 : state_(kIdle), 78 : state_(kIdle),
69 capture_thread_("CaptureThread"), 79 capture_thread_("CaptureThread"),
70 frame_count_(0), 80 frame_count_(0),
71 format_roster_index_(0) {} 81 format_roster_index_(0) {}
72 82
73 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { 83 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() {
74 // Check if the thread is running. 84 // Check if the thread is running.
75 // This means that the device have not been DeAllocated properly. 85 // This means that the device have not been DeAllocated properly.
76 DCHECK(!capture_thread_.IsRunning()); 86 DCHECK(!capture_thread_.IsRunning());
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); 227 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420));
218 format_roster_.push_back( 228 format_roster_.push_back(
219 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); 229 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420));
220 format_roster_.push_back( 230 format_roster_.push_back(
221 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); 231 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420));
222 232
223 format_roster_index_ = 0; 233 format_roster_index_ = 0;
224 } 234 }
225 235
226 } // namespace media 236 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698