#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
#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 {
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>&) { … }
}
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
DeviceFactoryImpl::~DeviceFactoryImpl() = default;
void DeviceFactoryImpl::GetDeviceInfos(GetDeviceInfosCallback callback) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void DeviceFactoryImpl::RecordCollision() {
base::UmaHistogramBoolean("ChromeOS.Camera.ConcurrentAccess", true);
}
#endif
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
}