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

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

Issue 91343002: Added supported formats caching to VideoCaptureManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perkj@ nits 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
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"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 #include "media/audio/fake_audio_input_stream.h" 12 #include "media/audio/fake_audio_input_stream.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
16 #include "third_party/skia/include/core/SkPaint.h" 15 #include "third_party/skia/include/core/SkPaint.h"
17 16
18 namespace media { 17 namespace media {
19 18
20 static const int kFakeCaptureTimeoutMs = 50; 19 static const int kFakeCaptureTimeoutMs = 50;
21 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s. 20 static const int kFakeCaptureBeepCycle = 20; // Visual beep every 1s.
22 static const int kFakeCaptureCapabilityChangePeriod = 30; 21 static const int kFakeCaptureCapabilityChangePeriod = 30;
23 enum { kNumberOfFakeDevices = 2 }; 22 enum { kNumberOfFakeDevices = 2 };
24 23
25 bool FakeVideoCaptureDevice::fail_next_create_ = false; 24 bool FakeVideoCaptureDevice::fail_next_create_ = false;
26 base::subtle::Atomic32 FakeVideoCaptureDevice::number_of_devices_ = 25 base::subtle::Atomic32 FakeVideoCaptureDevice::number_of_devices_ =
27 kNumberOfFakeDevices; 26 kNumberOfFakeDevices;
28 27
28 // static
29 size_t FakeVideoCaptureDevice::NumberOfFakeDevices(void) {
30 return number_of_devices_;
31 }
32
33 // static
29 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) { 34 void FakeVideoCaptureDevice::GetDeviceNames(Names* const device_names) {
30 // Empty the name list. 35 // Empty the name list.
31 device_names->erase(device_names->begin(), device_names->end()); 36 device_names->erase(device_names->begin(), device_names->end());
32 37
33 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_); 38 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_);
34 for (int32 n = 0; n < number_of_devices; n++) { 39 for (int32 n = 0; n < number_of_devices; n++) {
35 Name name("fake_device_" + base::IntToString(n), 40 Name name(base::StringPrintf("fake_device_%d", n),
36 "/dev/video" + base::IntToString(n)); 41 base::StringPrintf("/dev/video%d", n));
37 device_names->push_back(name); 42 device_names->push_back(name);
38 } 43 }
39 } 44 }
40 45
46 // static
41 void FakeVideoCaptureDevice::GetDeviceSupportedFormats( 47 void FakeVideoCaptureDevice::GetDeviceSupportedFormats(
42 const Name& device, 48 const Name& device,
43 VideoCaptureCapabilities* formats) { 49 VideoCaptureFormats* supported_formats) {
44 VideoCaptureCapability capture_format_640x480; 50
45 capture_format_640x480.supported_format.frame_size.SetSize(640, 480); 51 supported_formats->clear();
46 capture_format_640x480.supported_format.frame_rate = 52 VideoCaptureFormat capture_format_640x480;
47 1000 / kFakeCaptureTimeoutMs; 53 capture_format_640x480.pixel_format = media::PIXEL_FORMAT_I420;
48 capture_format_640x480.supported_format.pixel_format = 54 capture_format_640x480.frame_size.SetSize(640, 480);
49 media::PIXEL_FORMAT_I420; 55 capture_format_640x480.frame_rate = 1000 / kFakeCaptureTimeoutMs;
50 formats->push_back(capture_format_640x480); 56 supported_formats->push_back(capture_format_640x480);
57 VideoCaptureFormat capture_format_320x240;
58 capture_format_320x240.pixel_format = media::PIXEL_FORMAT_I420;
59 capture_format_320x240.frame_size.SetSize(320, 240);
60 capture_format_320x240.frame_rate = 1000 / kFakeCaptureTimeoutMs;
61 supported_formats->push_back(capture_format_320x240);
51 } 62 }
52 63
64 // static
53 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) { 65 VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) {
54 if (fail_next_create_) { 66 if (fail_next_create_) {
55 fail_next_create_ = false; 67 fail_next_create_ = false;
56 return NULL; 68 return NULL;
57 } 69 }
58 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_); 70 int number_of_devices = base::subtle::NoBarrier_Load(&number_of_devices_);
59 for (int32 n = 0; n < number_of_devices; ++n) { 71 for (int32 n = 0; n < number_of_devices; ++n) {
60 std::string possible_id = "/dev/video" + base::IntToString(n); 72 std::string possible_id = base::StringPrintf("/dev/video%d", n);
61 if (device_name.id().compare(possible_id) == 0) { 73 if (device_name.id().compare(possible_id) == 0) {
62 return new FakeVideoCaptureDevice(); 74 return new FakeVideoCaptureDevice();
63 } 75 }
64 } 76 }
65 return NULL; 77 return NULL;
66 } 78 }
67 79
80 // static
68 void FakeVideoCaptureDevice::SetFailNextCreate() { 81 void FakeVideoCaptureDevice::SetFailNextCreate() {
69 fail_next_create_ = true; 82 fail_next_create_ = true;
70 } 83 }
71 84
85 // static
72 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) { 86 void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) {
73 base::subtle::NoBarrier_AtomicExchange(&number_of_devices_, 87 base::subtle::NoBarrier_AtomicExchange(&number_of_devices_,
74 number_of_devices); 88 number_of_devices);
75 } 89 }
76 90
77 FakeVideoCaptureDevice::FakeVideoCaptureDevice() 91 FakeVideoCaptureDevice::FakeVideoCaptureDevice()
78 : capture_thread_("CaptureThread"), 92 : capture_thread_("CaptureThread"),
79 frame_count_(0), 93 frame_count_(0),
80 format_roster_index_(0) {} 94 format_roster_index_(0) {}
81 95
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420)); 252 media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420));
239 format_roster_.push_back( 253 format_roster_.push_back(
240 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420)); 254 media::VideoCaptureFormat(gfx::Size(640, 480), 30, PIXEL_FORMAT_I420));
241 format_roster_.push_back( 255 format_roster_.push_back(
242 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420)); 256 media::VideoCaptureFormat(gfx::Size(800, 600), 30, PIXEL_FORMAT_I420));
243 257
244 format_roster_index_ = 0; 258 format_roster_index_ = 0;
245 } 259 }
246 260
247 } // namespace media 261 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | media/video/capture/file_video_capture_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698