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

Side by Side Diff: services/video_capture/device_factory_media_to_mojo_adapter.cc

Issue 2386183002: Replace manual conversions with Mojo type mappings
Patch Set: 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/video_capture/device_factory_media_to_mojo_adapter.h" 5 #include "services/video_capture/device_factory_media_to_mojo_adapter.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "media/capture/video/fake_video_capture_device.h" 11 #include "media/capture/video/fake_video_capture_device.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h" 12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 #include "services/video_capture/device_mock_to_media_adapter.h" 13 #include "services/video_capture/device_mock_to_media_adapter.h"
14 #include "services/video_capture/mojo_media_conversions.h"
15 #include "services/video_capture/video_capture_device_proxy_impl.h" 14 #include "services/video_capture/video_capture_device_proxy_impl.h"
16 15
17 namespace video_capture { 16 namespace video_capture {
18 17
19 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::ActiveDeviceEntry() = 18 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::ActiveDeviceEntry() =
20 default; 19 default;
21 20
22 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::~ActiveDeviceEntry() = 21 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::~ActiveDeviceEntry() =
23 default; 22 default;
24 23
25 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::ActiveDeviceEntry( 24 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::ActiveDeviceEntry(
26 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry&& other) = default; 25 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry&& other) = default;
27 26
28 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry& 27 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry&
29 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::operator=( 28 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::operator=(
30 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry&& other) = default; 29 DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry&& other) = default;
31 30
32 DeviceFactoryMediaToMojoAdapter::DeviceFactoryMediaToMojoAdapter( 31 DeviceFactoryMediaToMojoAdapter::DeviceFactoryMediaToMojoAdapter(
33 std::unique_ptr<media::VideoCaptureDeviceFactory> device_factory, 32 std::unique_ptr<media::VideoCaptureDeviceFactory> device_factory,
34 const media::VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory_callback ) 33 const media::VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory_callback )
35 : device_factory_(std::move(device_factory)), 34 : device_factory_(std::move(device_factory)),
36 jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback) {} 35 jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback) {}
37 36
38 DeviceFactoryMediaToMojoAdapter::~DeviceFactoryMediaToMojoAdapter() = default; 37 DeviceFactoryMediaToMojoAdapter::~DeviceFactoryMediaToMojoAdapter() = default;
39 38
40 void DeviceFactoryMediaToMojoAdapter::EnumerateDeviceDescriptors( 39 void DeviceFactoryMediaToMojoAdapter::EnumerateDeviceDescriptors(
41 const EnumerateDeviceDescriptorsCallback& callback) { 40 const EnumerateDeviceDescriptorsCallback& callback) {
42 std::vector<mojom::VideoCaptureDeviceDescriptorPtr> result; 41 std::vector<media::VideoCaptureDeviceDescriptor> descriptors;
43 media::VideoCaptureDeviceDescriptors descriptors;
44 device_factory_->GetDeviceDescriptors(&descriptors); 42 device_factory_->GetDeviceDescriptors(&descriptors);
45 for (const auto& entry : descriptors) { 43 callback.Run(std::move(descriptors));
46 result.push_back(ConvertFromMediaToMojo(entry));
47 }
48 callback.Run(std::move(result));
49 } 44 }
50 45
51 void DeviceFactoryMediaToMojoAdapter::GetSupportedFormats( 46 void DeviceFactoryMediaToMojoAdapter::GetSupportedFormats(
52 mojom::VideoCaptureDeviceDescriptorPtr device_descriptor, 47 const media::VideoCaptureDeviceDescriptor& descriptor,
53 const GetSupportedFormatsCallback& callback) { 48 const GetSupportedFormatsCallback& callback) {
54 std::vector<mojom::VideoCaptureFormatPtr> result;
55 media::VideoCaptureFormats formats; 49 media::VideoCaptureFormats formats;
56 device_factory_->GetSupportedFormats( 50 device_factory_->GetSupportedFormats(std::move(descriptor), &formats);
57 ConvertFromMojoToMedia(std::move(device_descriptor)), &formats); 51 callback.Run(std::move(formats));
58 for (const auto& entry : formats) {
59 result.push_back(
60 ConvertFromMediaToMojo(entry));
61 }
62 callback.Run(std::move(result));
63 } 52 }
64 53
65 void DeviceFactoryMediaToMojoAdapter::CreateDeviceProxy( 54 void DeviceFactoryMediaToMojoAdapter::CreateDeviceProxy(
66 mojom::VideoCaptureDeviceDescriptorPtr device_descriptor, 55 const media::VideoCaptureDeviceDescriptor& descriptor,
67 mojom::VideoCaptureDeviceProxyRequest proxy_request, 56 mojom::VideoCaptureDeviceProxyRequest proxy_request,
68 const CreateDeviceProxyCallback& callback) { 57 const CreateDeviceProxyCallback& callback) {
69 auto media_descriptor = ConvertFromMojoToMedia(std::move(device_descriptor)); 58 if (active_devices_.find(descriptor) != active_devices_.end()) {
70 if (active_devices_.find(media_descriptor) != active_devices_.end()) {
71 // The requested device is already in use. 59 // The requested device is already in use.
72 // Revoke the access and close the device, then bind to the new request. 60 // Revoke the access and close the device, then bind to the new request.
73 ActiveDeviceEntry& device_entry = active_devices_[media_descriptor]; 61 ActiveDeviceEntry& device_entry = active_devices_[descriptor];
74 device_entry.binding->Unbind(); 62 device_entry.binding->Unbind();
75 device_entry.device_proxy->Stop(); 63 device_entry.device_proxy->Stop();
76 device_entry.binding->Bind(std::move(proxy_request)); 64 device_entry.binding->Bind(std::move(proxy_request));
77 device_entry.binding->set_connection_error_handler(base::Bind( 65 device_entry.binding->set_connection_error_handler(base::Bind(
78 &DeviceFactoryMediaToMojoAdapter::OnClientConnectionErrorOrClose, 66 &DeviceFactoryMediaToMojoAdapter::OnClientConnectionErrorOrClose,
79 base::Unretained(this), 67 base::Unretained(this),
80 media_descriptor)); 68 descriptor));
81 callback.Run(mojom::DeviceAccessResultCode::SUCCESS); 69 callback.Run(mojom::DeviceAccessResultCode::SUCCESS);
82 return; 70 return;
83 } 71 }
84 72
85 // Create device 73 // Create device
86 std::unique_ptr<media::VideoCaptureDevice> media_device = 74 std::unique_ptr<media::VideoCaptureDevice> media_device =
87 device_factory_->CreateDevice( 75 device_factory_->CreateDevice(descriptor);
88 media_descriptor);
89 if (media_device == nullptr) { 76 if (media_device == nullptr) {
90 callback.Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND); 77 callback.Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND);
91 return; 78 return;
92 } 79 }
93 80
94 // Add entry to active_devices to keep track of it 81 // Add entry to active_devices to keep track of it
95 ActiveDeviceEntry device_entry; 82 ActiveDeviceEntry device_entry;
96 device_entry.device_proxy = base::MakeUnique<VideoCaptureDeviceProxyImpl>( 83 device_entry.device_proxy = base::MakeUnique<VideoCaptureDeviceProxyImpl>(
97 std::move(media_device), jpeg_decoder_factory_callback_); 84 std::move(media_device), jpeg_decoder_factory_callback_);
98 device_entry.binding = 85 device_entry.binding =
99 base::MakeUnique<mojo::Binding<mojom::VideoCaptureDeviceProxy>>( 86 base::MakeUnique<mojo::Binding<mojom::VideoCaptureDeviceProxy>>(
100 device_entry.device_proxy.get(), std::move(proxy_request)); 87 device_entry.device_proxy.get(), std::move(proxy_request));
101 device_entry.binding->set_connection_error_handler(base::Bind( 88 device_entry.binding->set_connection_error_handler(base::Bind(
102 &DeviceFactoryMediaToMojoAdapter::OnClientConnectionErrorOrClose, 89 &DeviceFactoryMediaToMojoAdapter::OnClientConnectionErrorOrClose,
103 base::Unretained(this), media_descriptor)); 90 base::Unretained(this), descriptor));
104 active_devices_[media_descriptor] = std::move(device_entry); 91 active_devices_[descriptor] = std::move(device_entry);
105 92
106 callback.Run(mojom::DeviceAccessResultCode::SUCCESS); 93 callback.Run(mojom::DeviceAccessResultCode::SUCCESS);
107 } 94 }
108 95
109 void DeviceFactoryMediaToMojoAdapter::OnClientConnectionErrorOrClose( 96 void DeviceFactoryMediaToMojoAdapter::OnClientConnectionErrorOrClose(
110 media::VideoCaptureDeviceDescriptor descriptor) { 97 media::VideoCaptureDeviceDescriptor descriptor) {
111 active_devices_[descriptor].device_proxy->Stop(); 98 active_devices_[descriptor].device_proxy->Stop();
112 active_devices_.erase(descriptor); 99 active_devices_.erase(descriptor);
113 } 100 }
114 101
115 } // namespace video_capture 102 } // namespace video_capture
OLDNEW
« no previous file with comments | « services/video_capture/device_factory_media_to_mojo_adapter.h ('k') | services/video_capture/fake_device_descriptor_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698