#include "media/capture/video/linux/video_capture_device_factory_v4l2.h"
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <algorithm>
#include <utility>
#include "base/containers/contains.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "media/capture/video/linux/scoped_v4l2_device_fd.h"
#include "media/capture/video/linux/video_capture_device_linux.h"
#if BUILDFLAG(IS_OPENBSD)
#include <sys/videoio.h>
#else
#include <linux/videodev2.h>
#endif
namespace media {
namespace {
bool CompareCaptureDevices(const VideoCaptureDeviceInfo& a,
const VideoCaptureDeviceInfo& b) { … }
const size_t kVidPidSize = …;
const size_t kMaxInterfaceNameSize = …;
const char kVidPathTemplate[] = …;
const char kPidPathTemplate[] = …;
const char kInterfacePathTemplate[] = …;
bool ReadIdFile(const std::string& path, std::string* id) { … }
std::string ExtractFileNameFromDeviceId(const std::string& device_id) { … }
class DevVideoFilePathsDeviceProvider
: public VideoCaptureDeviceFactoryV4L2::DeviceProvider { … };
}
VideoCaptureDeviceFactoryV4L2::VideoCaptureDeviceFactoryV4L2(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
: … { … }
VideoCaptureDeviceFactoryV4L2::~VideoCaptureDeviceFactoryV4L2() = default;
void VideoCaptureDeviceFactoryV4L2::SetV4L2EnvironmentForTesting(
scoped_refptr<V4L2CaptureDevice> v4l2,
std::unique_ptr<VideoCaptureDeviceFactoryV4L2::DeviceProvider>
device_provider) { … }
VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryV4L2::CreateDevice(
const VideoCaptureDeviceDescriptor& device_descriptor) { … }
void VideoCaptureDeviceFactoryV4L2::GetDevicesInfo(
GetDevicesInfoCallback callback) { … }
int VideoCaptureDeviceFactoryV4L2::DoIoctl(int fd, int request, void* argp) { … }
VideoCaptureControlSupport VideoCaptureDeviceFactoryV4L2::GetControlSupport(
int fd) { … }
bool VideoCaptureDeviceFactoryV4L2::GetControlSupport(int fd, int control_id) { … }
bool VideoCaptureDeviceFactoryV4L2::HasUsableFormats(int fd,
uint32_t capabilities) { … }
std::vector<float> VideoCaptureDeviceFactoryV4L2::GetFrameRateList(
int fd,
uint32_t fourcc,
uint32_t width,
uint32_t height) { … }
void VideoCaptureDeviceFactoryV4L2::GetSupportedFormatsForV4L2BufferType(
int fd,
VideoCaptureFormats* supported_formats) { … }
}