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

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

Issue 2428263004: 16 bpp video stream capture, render and createImageBitmap(video) using (CPU) shared memory buffers (Closed)
Patch Set: fixes Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/capture/video/fake_video_capture_device_factory.h" 5 #include "media/capture/video/fake_video_capture_device_factory.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "media/base/media_switches.h" 14 #include "media/base/media_switches.h"
15 15
16 namespace {
17
18 media::VideoPixelFormat get_pixelformat(const std::string& device_id) {
19 if (device_id == "/dev/video1")
20 return media::PIXEL_FORMAT_Y16;
21 return media::PIXEL_FORMAT_I420;
mcasas 2016/10/21 00:10:50 Hmm, if you need this specific format type to be g
aleksandar.stojiljkovic 2016/10/21 22:11:10 If it is important that there is only one capture
22 }
23 }
mcasas 2016/10/21 00:10:50 nit: empty line between these }
aleksandar.stojiljkovic 2016/10/21 22:11:10 Done.
aleksandar.stojiljkovic 2016/10/25 21:14:59 git cl format media is just forcing no empty line
24
16 namespace media { 25 namespace media {
17 26
18 // Cap the frame rate command line input to reasonable values. 27 // Cap the frame rate command line input to reasonable values.
19 static const float kFakeCaptureMinFrameRate = 5.0f; 28 static const float kFakeCaptureMinFrameRate = 5.0f;
20 static const float kFakeCaptureMaxFrameRate = 60.0f; 29 static const float kFakeCaptureMaxFrameRate = 60.0f;
21 // Default rate if none is specified as part of the command line. 30 // Default rate if none is specified as part of the command line.
22 static const float kFakeCaptureDefaultFrameRate = 20.0f; 31 static const float kFakeCaptureDefaultFrameRate = 20.0f;
23 32
24 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() 33 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory()
34 #if defined(OS_ANDROID)
35 // TODO(astojilj): Support 16bpp depth video capture on Android.
25 : number_of_devices_(1), 36 : number_of_devices_(1),
37 #else
38 // First device is I420, second is Y16. See also get_pixelformat().
39 : number_of_devices_(2),
mcasas 2016/10/21 00:10:50 Some tests also set_numer_of_devices() to 2, and e
aleksandar.stojiljkovic 2016/10/21 22:11:10 Yes, that's why decided to set it to 2, first RGB,
40 #endif
26 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS), 41 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS),
27 frame_rate_(kFakeCaptureDefaultFrameRate) {} 42 frame_rate_(kFakeCaptureDefaultFrameRate) {}
28 43
29 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( 44 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice(
30 const VideoCaptureDeviceDescriptor& device_descriptor) { 45 const VideoCaptureDeviceDescriptor& device_descriptor) {
31 DCHECK(thread_checker_.CalledOnValidThread()); 46 DCHECK(thread_checker_.CalledOnValidThread());
32 47
33 parse_command_line(); 48 parse_command_line();
34 49
35 for (int n = 0; n < number_of_devices_; ++n) { 50 for (int n = 0; n < number_of_devices_; ++n) {
36 std::string possible_id = base::StringPrintf("/dev/video%d", n); 51 std::string possible_id = base::StringPrintf("/dev/video%d", n);
37 if (device_descriptor.device_id.compare(possible_id) == 0) { 52 if (device_descriptor.device_id.compare(possible_id) == 0) {
38 return std::unique_ptr<VideoCaptureDevice>( 53 return std::unique_ptr<VideoCaptureDevice>(new FakeVideoCaptureDevice(
39 new FakeVideoCaptureDevice(fake_vcd_ownership_, frame_rate_)); 54 fake_vcd_ownership_, frame_rate_, get_pixelformat(possible_id)));
40 } 55 }
41 } 56 }
42 return std::unique_ptr<VideoCaptureDevice>(); 57 return std::unique_ptr<VideoCaptureDevice>();
43 } 58 }
44 59
45 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( 60 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors(
46 VideoCaptureDeviceDescriptors* device_descriptors) { 61 VideoCaptureDeviceDescriptors* device_descriptors) {
47 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
48 DCHECK(device_descriptors->empty()); 63 DCHECK(device_descriptors->empty());
49 for (int n = 0; n < number_of_devices_; ++n) { 64 for (int n = 0; n < number_of_devices_; ++n) {
50 device_descriptors->emplace_back(base::StringPrintf("fake_device_%d", n), 65 device_descriptors->emplace_back(base::StringPrintf("fake_device_%d", n),
51 base::StringPrintf("/dev/video%d", n), 66 base::StringPrintf("/dev/video%d", n),
52 #if defined(OS_LINUX) 67 #if defined(OS_LINUX)
53 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE 68 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE
54 #elif defined(OS_MACOSX) 69 #elif defined(OS_MACOSX)
55 VideoCaptureApi::MACOSX_AVFOUNDATION 70 VideoCaptureApi::MACOSX_AVFOUNDATION
56 #elif defined(OS_WIN) 71 #elif defined(OS_WIN)
57 VideoCaptureApi::WIN_DIRECT_SHOW 72 VideoCaptureApi::WIN_DIRECT_SHOW
58 #elif defined(OS_ANDROID) 73 #elif defined(OS_ANDROID)
59 VideoCaptureApi::ANDROID_API2_LEGACY 74 VideoCaptureApi::ANDROID_API2_LEGACY
60 #endif 75 #endif
61 ); 76 );
62 } 77 }
63 } 78 }
64 79
65 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( 80 void FakeVideoCaptureDeviceFactory::GetSupportedFormats(
66 const VideoCaptureDeviceDescriptor& device_descriptor, 81 const VideoCaptureDeviceDescriptor& device_descriptor,
67 VideoCaptureFormats* supported_formats) { 82 VideoCaptureFormats* supported_formats) {
68 DCHECK(thread_checker_.CalledOnValidThread()); 83 DCHECK(thread_checker_.CalledOnValidThread());
69 const gfx::Size supported_sizes[] = {gfx::Size(320, 240), 84 const gfx::Size supported_sizes[] = {gfx::Size(96, 96), // To test cubemap.
70 gfx::Size(640, 480), 85 gfx::Size(320, 240), gfx::Size(640, 480),
mcasas 2016/10/21 00:10:50 nit: Indent is strange here.
aleksandar.stojiljkovic 2016/10/21 22:11:10 git cl format media is doing it and complaining if
71 gfx::Size(1280, 720), 86 gfx::Size(1280, 720),
72 gfx::Size(1920, 1080)}; 87 gfx::Size(1920, 1080)};
73 supported_formats->clear(); 88 supported_formats->clear();
74 for (const auto& size : supported_sizes) { 89 for (const auto& size : supported_sizes) {
75 supported_formats->push_back( 90 supported_formats->push_back(VideoCaptureFormat(
76 VideoCaptureFormat(size, frame_rate_, media::PIXEL_FORMAT_I420)); 91 size, frame_rate_, get_pixelformat(device_descriptor.device_id)));
77 } 92 }
78 } 93 }
79 94
80 // Optional comma delimited parameters to the command line can specify buffer 95 // Optional comma delimited parameters to the command line can specify buffer
81 // ownership, buffer planarity, and the fake video device FPS. 96 // ownership, buffer planarity, and the fake video device FPS.
82 // Examples: "ownership=client, planarity=triplanar, fps=60" "fps=30" 97 // Examples: "ownership=client, planarity=triplanar, fps=60" "fps=30"
83 void FakeVideoCaptureDeviceFactory::parse_command_line() { 98 void FakeVideoCaptureDeviceFactory::parse_command_line() {
84 const std::string option = 99 const std::string option =
85 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 100 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
86 switches::kUseFakeDeviceForMediaStream); 101 switches::kUseFakeDeviceForMediaStream);
(...skipping 20 matching lines...) Expand all
107 if (base::StringToDouble(param.back(), &fps)) { 122 if (base::StringToDouble(param.back(), &fps)) {
108 frame_rate_ = 123 frame_rate_ =
109 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); 124 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps));
110 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); 125 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_);
111 } 126 }
112 } 127 }
113 } 128 }
114 } 129 }
115 130
116 } // namespace media 131 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698