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

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: Changes since the revert. 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
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 size_t FakeVideoCaptureDevice::number_of_devices_ = kNumberOfFakeDevices;
25 27
26 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { 28 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) {
27 // Empty the name list. 29 // Empty the name list.
28 device_names->erase(device_names->begin(), device_names->end()); 30 device_names->erase(device_names->begin(), device_names->end());
29 31
30 for (int n = 0; n < kNumberOfFakeDevices; n++) { 32 for (size_t n = 0; n < number_of_devices_; n++) {
31 Name name(base::StringPrintf("fake_device_%d", n), 33 Name name("fake_device_" + base::IntToString(n),
32 base::StringPrintf("/dev/video%d", n)); 34 "/dev/video" + base::IntToString(n));
33 device_names->push_back(name); 35 device_names->push_back(name);
34 } 36 }
35 } 37 }
36 38
37 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( 39 void FakeVideoCaptureDevice::GetDeviceSupportedFormats(
38 const Name& device, 40 const Name& device,
39 VideoCaptureCapabilities* formats) { 41 VideoCaptureCapabilities* formats) {
40 VideoCaptureCapability capture_format_640x480; 42 VideoCaptureCapability capture_format_640x480;
41 capture_format_640x480.supported_format.frame_size.SetSize(640, 480); 43 capture_format_640x480.supported_format.frame_size.SetSize(640, 480);
42 capture_format_640x480.supported_format.frame_rate = 44 capture_format_640x480.supported_format.frame_rate =
43 1000 / kFakeCaptureTimeoutMs; 45 1000 / kFakeCaptureTimeoutMs;
44 capture_format_640x480.supported_format.pixel_format = 46 capture_format_640x480.supported_format.pixel_format =
45 media::PIXEL_FORMAT_I420; 47 media::PIXEL_FORMAT_I420;
46 formats->push_back(capture_format_640x480); 48 formats->push_back(capture_format_640x480);
47 } 49 }
48 50
49 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { 51 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) {
50 if (fail_next_create_) { 52 if (fail_next_create_) {
51 fail_next_create_ = false; 53 fail_next_create_ = false;
52 return NULL; 54 return NULL;
53 } 55 }
54 for (int n = 0; n < kNumberOfFakeDevices; ++n) { 56 for (size_t n = 0; n < number_of_devices_; ++n) {
55 std::string possible_id = base::StringPrintf("/dev/video%d", n); 57 std::string possible_id = "/dev/video" + base::IntToString(n);
56 if (device_name.id().compare(possible_id) == 0) { 58 if (device_name.id().compare(possible_id) == 0) {
57 return new FakeVideoCaptureDevice(); 59 return new FakeVideoCaptureDevice();
58 } 60 }
59 } 61 }
60 return NULL; 62 return NULL;
61 } 63 }
62 64
63 void FakeVideoCaptureDevice::SetFailNextCreate() { 65 void FakeVideoCaptureDevice::SetFailNextCreate() {
64 fail_next_create_ = true; 66 fail_next_create_ = true;
65 } 67 }
66 68
69 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) {
70 number_of_devices_ = number_of_devices;
tommi (sloooow) - chröme 2013/11/26 14:44:21 this looks like a candidate for tsan reports. is
perkj_chrome 2013/11/27 13:41:34 Right- I filed crbug/323913 to cleanup MSM to not
71 }
72
67 FakeVideoCaptureDevice::FakeVideoCaptureDevice() 73 FakeVideoCaptureDevice::FakeVideoCaptureDevice()
68 : state_(kIdle), 74 : state_(kIdle),
69 capture_thread_("CaptureThread"), 75 capture_thread_("CaptureThread"),
70 frame_count_(0), 76 frame_count_(0),
71 format_roster_index_(0) {} 77 format_roster_index_(0) {}
72 78
73 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { 79 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() {
74 // Check if the thread is running. 80 // Check if the thread is running.
75 // This means that the device have not been DeAllocated properly. 81 // This means that the device have not been DeAllocated properly.
76 DCHECK(!capture_thread_.IsRunning()); 82 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)); 223 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420));
218 format_roster_.push_back( 224 format_roster_.push_back(
219 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); 225 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420));
220 format_roster_.push_back( 226 format_roster_.push_back(
221 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); 227 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420));
222 228
223 format_roster_index_ = 0; 229 format_roster_index_ = 0;
224 } 230 }
225 231
226 } // namespace media 232 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698