| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "services/video_capture/video_capture_device_factory_impl.h" | |
| 6 | |
| 7 #include <sstream> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/strings/stringprintf.h" | |
| 11 #include "media/capture/video/fake_video_capture_device.h" | |
| 12 #include "services/video_capture/device_mock_to_media_adapter.h" | |
| 13 | |
| 14 namespace video_capture { | |
| 15 | |
| 16 VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( | |
| 17 const media::VideoCaptureDeviceDescriptor& descriptor, | |
| 18 std::unique_ptr<VideoCaptureDeviceProxyImpl> bindable_target) | |
| 19 : descriptor_(std::move(descriptor)), | |
| 20 binding_(base::MakeUnique<mojo::Binding<mojom::VideoCaptureDeviceProxy>>( | |
| 21 bindable_target.get())) { | |
| 22 device_proxy_ = std::move(bindable_target); | |
| 23 } | |
| 24 | |
| 25 VideoCaptureDeviceFactoryImpl::DeviceEntry::~DeviceEntry() = default; | |
| 26 | |
| 27 VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( | |
| 28 VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; | |
| 29 | |
| 30 VideoCaptureDeviceFactoryImpl::DeviceEntry& | |
| 31 VideoCaptureDeviceFactoryImpl::DeviceEntry::operator=( | |
| 32 VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; | |
| 33 | |
| 34 const media::VideoCaptureDeviceDescriptor& | |
| 35 VideoCaptureDeviceFactoryImpl::DeviceEntry::descriptor() const { | |
| 36 return descriptor_; | |
| 37 } | |
| 38 | |
| 39 bool VideoCaptureDeviceFactoryImpl::DeviceEntry::DescriptorEquals( | |
| 40 const media::VideoCaptureDeviceDescriptor& other) const { | |
| 41 return descriptor_ == other; | |
| 42 } | |
| 43 | |
| 44 bool VideoCaptureDeviceFactoryImpl::DeviceEntry::is_bound() const { | |
| 45 return binding_->is_bound(); | |
| 46 } | |
| 47 | |
| 48 void VideoCaptureDeviceFactoryImpl::DeviceEntry::Bind( | |
| 49 mojom::VideoCaptureDeviceProxyRequest request) { | |
| 50 binding_->Bind(std::move(request)); | |
| 51 binding_->set_connection_error_handler(base::Bind( | |
| 52 &VideoCaptureDeviceFactoryImpl::DeviceEntry::OnConnectionErrorOrClose, | |
| 53 base::Unretained(this))); | |
| 54 } | |
| 55 | |
| 56 void VideoCaptureDeviceFactoryImpl::DeviceEntry::Unbind() { | |
| 57 binding_->Unbind(); | |
| 58 device_proxy_->Stop(); | |
| 59 } | |
| 60 | |
| 61 void VideoCaptureDeviceFactoryImpl::DeviceEntry::OnConnectionErrorOrClose() { | |
| 62 Unbind(); | |
| 63 } | |
| 64 | |
| 65 VideoCaptureDeviceFactoryImpl::VideoCaptureDeviceFactoryImpl( | |
| 66 const media::VideoCaptureJpegDecoderFactoryCB& | |
| 67 jpeg_decoder_factory_callback) | |
| 68 : jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback) {} | |
| 69 | |
| 70 VideoCaptureDeviceFactoryImpl::~VideoCaptureDeviceFactoryImpl() = default; | |
| 71 | |
| 72 void VideoCaptureDeviceFactoryImpl::AddMojoDevice( | |
| 73 std::unique_ptr<VideoCaptureDeviceProxyImpl> device, | |
| 74 const media::VideoCaptureDeviceDescriptor& descriptor) { | |
| 75 devices_.emplace_back(std::move(descriptor), std::move(device)); | |
| 76 } | |
| 77 | |
| 78 void VideoCaptureDeviceFactoryImpl::AddMediaDevice( | |
| 79 std::unique_ptr<media::VideoCaptureDevice> device, | |
| 80 const media::VideoCaptureDeviceDescriptor& descriptor) { | |
| 81 AddMojoDevice(base::MakeUnique<VideoCaptureDeviceProxyImpl>( | |
| 82 std::move(device), jpeg_decoder_factory_callback_), | |
| 83 std::move(descriptor)); | |
| 84 } | |
| 85 | |
| 86 void VideoCaptureDeviceFactoryImpl::AddMockDevice( | |
| 87 mojom::MockVideoCaptureDevicePtr device, | |
| 88 const media::VideoCaptureDeviceDescriptor& descriptor) { | |
| 89 AddMediaDevice(base::MakeUnique<DeviceMockToMediaAdapter>(std::move(device)), | |
| 90 std::move(descriptor)); | |
| 91 } | |
| 92 | |
| 93 void VideoCaptureDeviceFactoryImpl::EnumerateDeviceDescriptors( | |
| 94 const EnumerateDeviceDescriptorsCallback& callback) { | |
| 95 std::vector<media::VideoCaptureDeviceDescriptor> descriptors; | |
| 96 for (const auto& entry : devices_) | |
| 97 descriptors.push_back(entry.descriptor()); | |
| 98 callback.Run(std::move(descriptors)); | |
| 99 } | |
| 100 | |
| 101 void VideoCaptureDeviceFactoryImpl::GetSupportedFormats( | |
| 102 const media::VideoCaptureDeviceDescriptor& device_descriptor, | |
| 103 const GetSupportedFormatsCallback& callback) { | |
| 104 NOTIMPLEMENTED(); | |
| 105 } | |
| 106 | |
| 107 void VideoCaptureDeviceFactoryImpl::CreateDeviceProxy( | |
| 108 const media::VideoCaptureDeviceDescriptor& device_descriptor, | |
| 109 mojom::VideoCaptureDeviceProxyRequest proxy_request, | |
| 110 const CreateDeviceProxyCallback& callback) { | |
| 111 for (auto& entry : devices_) { | |
| 112 if (entry.DescriptorEquals(device_descriptor)) { | |
| 113 if (entry.is_bound()) | |
| 114 entry.Unbind(); | |
| 115 entry.Bind(std::move(proxy_request)); | |
| 116 callback.Run(mojom::DeviceAccessResultCode::SUCCESS); | |
| 117 return; | |
| 118 } | |
| 119 } | |
| 120 callback.Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND); | |
| 121 } | |
| 122 | |
| 123 } // namespace video_capture | |
| OLD | NEW |