| Index: services/video_capture/device_factory_media_to_mojo_adapter.cc
|
| diff --git a/services/video_capture/device_factory_media_to_mojo_adapter.cc b/services/video_capture/device_factory_media_to_mojo_adapter.cc
|
| index 07f6db53a083b031d6328c789efc2a6160952d78..12b3a0083c4abe9265745da573b968be3e3be1f1 100644
|
| --- a/services/video_capture/device_factory_media_to_mojo_adapter.cc
|
| +++ b/services/video_capture/device_factory_media_to_mojo_adapter.cc
|
| @@ -15,6 +15,54 @@
|
| #include "mojo/public/cpp/bindings/strong_binding.h"
|
| #include "services/video_capture/device_media_to_mojo_adapter.h"
|
|
|
| +namespace {
|
| +
|
| +// Translates a set of device infos reported by a VideoCaptureSystem to a set
|
| +// of device infos that the video capture service exposes to its client.
|
| +// The Video Capture Service instances of VideoCaptureDeviceClient to
|
| +// convert the formats provided by the VideoCaptureDevice instances. Here, we
|
| +// translate the set of supported formats as reported by the |device_factory_|
|
| +// to what will be output by the VideoCaptureDeviceClient we connect to it.
|
| +// TODO(chfremer): A cleaner design would be to have this translation
|
| +// happen in VideoCaptureDeviceClient, and talk only to VideoCaptureDeviceClient
|
| +// instead of VideoCaptureSystem.
|
| +static void TranslateDeviceInfos(
|
| + const video_capture::mojom::DeviceFactory::GetDeviceInfosCallback& callback,
|
| + const std::vector<media::VideoCaptureDeviceInfo>& device_infos) {
|
| + std::vector<media::VideoCaptureDeviceInfo> translated_device_infos;
|
| + for (const auto& device_info : device_infos) {
|
| + media::VideoCaptureDeviceInfo translated_device_info;
|
| + translated_device_info.descriptor = device_info.descriptor;
|
| + for (const auto& format : device_info.supported_formats) {
|
| + media::VideoCaptureFormat translated_format;
|
| + switch (format.pixel_format) {
|
| + case media::PIXEL_FORMAT_I420:
|
| + case media::PIXEL_FORMAT_MJPEG:
|
| + translated_format.pixel_format = media::PIXEL_FORMAT_I420;
|
| + break;
|
| + case media::PIXEL_FORMAT_Y16:
|
| + translated_format.pixel_format = media::PIXEL_FORMAT_Y16;
|
| + default:
|
| + // Any other format cannot be consumed by VideoCaptureDeviceClient.
|
| + continue;
|
| + }
|
| + translated_format.frame_size = format.frame_size;
|
| + translated_format.frame_rate = format.frame_rate;
|
| + translated_format.pixel_storage = media::PIXEL_STORAGE_CPU;
|
| + if (base::ContainsValue(translated_device_info.supported_formats,
|
| + translated_format))
|
| + continue;
|
| + translated_device_info.supported_formats.push_back(translated_format);
|
| + }
|
| + if (translated_device_info.supported_formats.empty())
|
| + continue;
|
| + translated_device_infos.push_back(translated_device_info);
|
| + }
|
| + callback.Run(translated_device_infos);
|
| +}
|
| +
|
| +} // anonymous namespace
|
| +
|
| namespace video_capture {
|
|
|
| DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::ActiveDeviceEntry() =
|
| @@ -31,17 +79,18 @@ DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry::operator=(
|
| DeviceFactoryMediaToMojoAdapter::ActiveDeviceEntry&& other) = default;
|
|
|
| DeviceFactoryMediaToMojoAdapter::DeviceFactoryMediaToMojoAdapter(
|
| - std::unique_ptr<media::VideoCaptureDeviceFactory> device_factory,
|
| + std::unique_ptr<media::VideoCaptureSystem> capture_system,
|
| const media::VideoCaptureJpegDecoderFactoryCB&
|
| jpeg_decoder_factory_callback)
|
| - : device_factory_(std::move(device_factory)),
|
| + : capture_system_(std::move(capture_system)),
|
| jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback) {}
|
|
|
| DeviceFactoryMediaToMojoAdapter::~DeviceFactoryMediaToMojoAdapter() = default;
|
|
|
| void DeviceFactoryMediaToMojoAdapter::GetDeviceInfos(
|
| const GetDeviceInfosCallback& callback) {
|
| - NOTIMPLEMENTED();
|
| + capture_system_->GetDeviceInfosAsync(
|
| + base::Bind(&TranslateDeviceInfos, callback));
|
| }
|
|
|
| void DeviceFactoryMediaToMojoAdapter::CreateDevice(
|
| @@ -63,14 +112,8 @@ void DeviceFactoryMediaToMojoAdapter::CreateDevice(
|
| return;
|
| }
|
|
|
| - // Create device
|
| - media::VideoCaptureDeviceDescriptor descriptor;
|
| - if (LookupDescriptorFromId(device_id, &descriptor) == false) {
|
| - callback.Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND);
|
| - return;
|
| - }
|
| std::unique_ptr<media::VideoCaptureDevice> media_device =
|
| - device_factory_->CreateDevice(descriptor);
|
| + capture_system_->CreateDevice(device_id);
|
| if (media_device == nullptr) {
|
| callback.Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND);
|
| return;
|
| @@ -96,20 +139,4 @@ void DeviceFactoryMediaToMojoAdapter::OnClientConnectionErrorOrClose(
|
| active_devices_by_id_.erase(device_id);
|
| }
|
|
|
| -bool DeviceFactoryMediaToMojoAdapter::LookupDescriptorFromId(
|
| - const std::string& device_id,
|
| - media::VideoCaptureDeviceDescriptor* descriptor) {
|
| - media::VideoCaptureDeviceDescriptors descriptors;
|
| - device_factory_->GetDeviceDescriptors(&descriptors);
|
| - auto descriptor_iter = std::find_if(
|
| - descriptors.begin(), descriptors.end(),
|
| - [&device_id](const media::VideoCaptureDeviceDescriptor& descriptor) {
|
| - return descriptor.device_id == device_id;
|
| - });
|
| - if (descriptor_iter == descriptors.end())
|
| - return false;
|
| - *descriptor = *descriptor_iter;
|
| - return true;
|
| -}
|
| -
|
| } // namespace video_capture
|
|
|