chromium/services/video_capture/device_factory_impl.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/video_capture/device_factory_impl.h"

#include <sstream>
#include <utility>

#include "base/containers/contains.h"
#include "base/functional/bind.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/metrics/histogram_functions.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/notreached.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "media/capture/video/fake_video_capture_device.h"
#include "media/capture/video/video_capture_device_info.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/video_capture/device_media_to_mojo_adapter.h"
#include "services/video_capture/public/mojom/producer.mojom.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.
// A translation is needed, because the actual video frames, on their way
// from the VideoCaptureSystem to clients of the Video Capture Service, will
// pass through an instance of VideoCaptureDeviceClient, which performs certain
// format conversions.
// 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(
    video_capture::DeviceFactory::GetDeviceInfosCallback callback,
    const std::vector<media::VideoCaptureDeviceInfo>& device_infos) {}

static void DiscardDeviceInfosAndCallContinuation(
    base::OnceClosure continuation,
    const std::vector<media::VideoCaptureDeviceInfo>&) {}

}  // anonymous namespace

namespace video_capture {

#if BUILDFLAG(IS_CHROMEOS_ASH)
DeviceFactoryImpl::DeviceFactoryImpl(
    std::unique_ptr<media::VideoCaptureSystem> capture_system,
    media::MojoMjpegDecodeAcceleratorFactoryCB jpeg_decoder_factory_callback,
    scoped_refptr<base::SequencedTaskRunner> jpeg_decoder_task_runner)
    : capture_system_(std::move(capture_system)),
      jpeg_decoder_factory_callback_(std::move(jpeg_decoder_factory_callback)),
      jpeg_decoder_task_runner_(std::move(jpeg_decoder_task_runner)),
      collision_delay_timer_(FROM_HERE,
                             base::Seconds(3),
                             this,
                             &DeviceFactoryImpl::RecordCollision),
      has_called_get_device_infos_(false),
      weak_factory_(this) {}
#else
DeviceFactoryImpl::DeviceFactoryImpl(
    std::unique_ptr<media::VideoCaptureSystem> capture_system)
    :{}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

DeviceFactoryImpl::~DeviceFactoryImpl() = default;

void DeviceFactoryImpl::GetDeviceInfos(GetDeviceInfosCallback callback) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void DeviceFactoryImpl::RecordCollision() {
  base::UmaHistogramBoolean("ChromeOS.Camera.ConcurrentAccess", true);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

void DeviceFactoryImpl::CreateDevice(const std::string& device_id,
                                     CreateDeviceCallback create_callback) {}

void DeviceFactoryImpl::StopDevice(const std::string device_id) {}

void DeviceFactoryImpl::AddSharedMemoryVirtualDevice(
    const media::VideoCaptureDeviceInfo& device_info,
    mojo::PendingRemote<mojom::Producer> producer,
    mojo::PendingReceiver<mojom::SharedMemoryVirtualDevice>
        virtual_device_receiver) {}

void DeviceFactoryImpl::AddTextureVirtualDevice(
    const media::VideoCaptureDeviceInfo& device_info,
    mojo::PendingReceiver<mojom::TextureVirtualDevice>
        virtual_device_receiver) {}

void DeviceFactoryImpl::AddGpuMemoryBufferVirtualDevice(
    const media::VideoCaptureDeviceInfo& device_info,
    mojo::PendingReceiver<mojom::GpuMemoryBufferVirtualDevice>
        virtual_device_receiver) {}

void DeviceFactoryImpl::RegisterVirtualDevicesChangedObserver(
    mojo::PendingRemote<mojom::DevicesChangedObserver> observer,
    bool raise_event_if_virtual_devices_already_present) {}

void DeviceFactoryImpl::CreateAndAddNewDevice(
    const std::string& device_id,
    CreateDeviceCallback create_callback) {}

void DeviceFactoryImpl::OnClientConnectionErrorOrClose(
    const std::string& device_id) {}

#if BUILDFLAG(IS_WIN)
void DeviceFactoryImpl::OnGpuInfoUpdate(const CHROME_LUID& luid) {
  capture_system_->GetFactory()->OnGpuInfoUpdate(luid);
}
#endif

}  // namespace video_capture