#include "media/capture/video/linux/v4l2_capture_delegate.h"
#include <fcntl.h>
#include <linux/version.h>
#include <linux/videodev2.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <algorithm>
#include <utility>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/posix/eintr_wrapper.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "media/base/video_frame.h"
#include "media/base/video_types.h"
#include "media/capture/mojom/image_capture_types.h"
#include "media/capture/video/blob_utils.h"
#include "media/capture/video/linux/video_capture_device_linux.h"
#if BUILDFLAG(IS_LINUX)
#include "media/capture/capture_switches.h"
#include "media/capture/video/linux/v4l2_capture_delegate_gpu_helper.h"
#endif
MeteringMode;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
#define V4L2_PIX_FMT_Z16 …
#endif
#ifndef V4L2_PIX_FMT_INVZ
#define V4L2_PIX_FMT_INVZ …
#endif
namespace media {
namespace {
constexpr uint32_t kNumVideoBuffers = …;
constexpr int kCaptureTimeoutMs = …;
constexpr int kContinuousTimeoutLimit = …;
constexpr int kMjpegWidth = …;
constexpr int kMjpegHeight = …;
constexpr int kTypicalFramerate = …;
struct { … } constexpr kSupportedFormatsAndPlanarity[] = …;
constexpr int kMaxIOCtrlRetries = …;
struct { … } constexpr kControls[] = …;
void FillV4L2Format(v4l2_format* format,
uint32_t width,
uint32_t height,
uint32_t pixelformat_fourcc) { … }
void FillV4L2Buffer(v4l2_buffer* buffer, int index) { … }
void FillV4L2RequestBuffer(v4l2_requestbuffers* request_buffer, int count) { … }
int GetControllingSpecialControl(int control_id) { … }
bool IsSpecialControl(int control_id) { … }
bool IsNonEmptyRange(const mojom::RangePtr& range) { … }
}
class V4L2CaptureDelegate::BufferTracker
: public base::RefCounted<BufferTracker> { … };
size_t V4L2CaptureDelegate::GetNumPlanesForFourCc(uint32_t fourcc) { … }
VideoPixelFormat V4L2CaptureDelegate::V4l2FourCcToChromiumPixelFormat(
uint32_t v4l2_fourcc) { … }
std::vector<uint32_t> V4L2CaptureDelegate::GetListOfUsableFourCcs(
bool prefer_mjpeg) { … }
#if !defined(V4L2_CID_PAN_SPEED)
#define V4L2_CID_PAN_SPEED …
#endif
#if !defined(V4L2_CID_TILT_SPEED)
#define V4L2_CID_TILT_SPEED …
#endif
#if !defined(V4L2_CID_PANTILT_CMD)
#define V4L2_CID_PANTILT_CMD …
#endif
bool V4L2CaptureDelegate::IsBlockedControl(int control_id) { … }
bool V4L2CaptureDelegate::IsControllableControl(
int control_id,
const base::RepeatingCallback<int(int, void*)>& do_ioctl) { … }
V4L2CaptureDelegate::V4L2CaptureDelegate(
V4L2CaptureDevice* v4l2,
const VideoCaptureDeviceDescriptor& device_descriptor,
const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner,
int power_line_frequency,
int rotation)
: … { … }
void V4L2CaptureDelegate::AllocateAndStart(
int width,
int height,
float frame_rate,
std::unique_ptr<VideoCaptureDevice::Client> client) { … }
void V4L2CaptureDelegate::StopAndDeAllocate() { … }
void V4L2CaptureDelegate::TakePhoto(
VideoCaptureDevice::TakePhotoCallback callback) { … }
void V4L2CaptureDelegate::GetPhotoState(
VideoCaptureDevice::GetPhotoStateCallback callback) { … }
void V4L2CaptureDelegate::SetPhotoOptions(
mojom::PhotoSettingsPtr settings,
VideoCaptureDevice::SetPhotoOptionsCallback callback) { … }
void V4L2CaptureDelegate::SetRotation(int rotation) { … }
base::WeakPtr<V4L2CaptureDelegate> V4L2CaptureDelegate::GetWeakPtr() { … }
void V4L2CaptureDelegate::SetGPUEnvironmentForTesting(
std::unique_ptr<gpu::GpuMemoryBufferSupport> gmb_support) { … }
V4L2CaptureDelegate::~V4L2CaptureDelegate() = default;
bool V4L2CaptureDelegate::RunIoctl(int request, void* argp) { … }
int V4L2CaptureDelegate::DoIoctl(int request, void* argp) { … }
bool V4L2CaptureDelegate::IsControllableControl(int control_id) { … }
void V4L2CaptureDelegate::ReplaceControlEventSubscriptions() { … }
mojom::RangePtr V4L2CaptureDelegate::RetrieveUserControlRange(int control_id) { … }
void V4L2CaptureDelegate::ResetUserAndCameraControlsToDefault() { … }
bool V4L2CaptureDelegate::MapAndQueueBuffer(int index) { … }
bool V4L2CaptureDelegate::StartStream() { … }
void V4L2CaptureDelegate::DoCapture() { … }
bool V4L2CaptureDelegate::StopStream() { … }
void V4L2CaptureDelegate::SetErrorState(VideoCaptureError error,
const base::Location& from_here,
const std::string& reason) { … }
#if BUILDFLAG(IS_LINUX)
gfx::ColorSpace V4L2CaptureDelegate::BuildColorSpaceFromv4l2() { … }
#endif
V4L2CaptureDelegate::BufferTracker::BufferTracker(V4L2CaptureDevice* v4l2)
: … { … }
V4L2CaptureDelegate::BufferTracker::~BufferTracker() { … }
bool V4L2CaptureDelegate::BufferTracker::Init(int fd,
const v4l2_buffer& buffer) { … }
}