From 9ee56da6b01ee1867ac9c40f5b2729076809f896 Mon Sep 17 00:00:00 2001 From: Jesse Talavera Date: Wed, 18 Dec 2024 20:31:44 -0500 Subject: [PATCH] Prioritize certain backends --- camera/drivers/ffmpeg.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/camera/drivers/ffmpeg.c b/camera/drivers/ffmpeg.c index 5d344047d4..b28b54cb4d 100644 --- a/camera/drivers/ffmpeg.c +++ b/camera/drivers/ffmpeg.c @@ -106,11 +106,21 @@ typedef struct ffmpeg_camera static void ffmpeg_camera_free(void *data); -static const AVInputFormat *ffmpeg_camera_choose_format(const char *device) +// TODO: Pick a backend based on the settings, too +static const AVInputFormat *ffmpeg_camera_get_default_backend(void) { - // TODO: If `device` is not NULL or empty, parse it to get the backend and device name - // TODO: Pick the best backend for the current platform, don't just return the first - return av_input_video_device_next(NULL); + const AVInputFormat *format = NULL; + for (unsigned i = 0; FFMPEG_CAMERA_DEVICE_TYPE_PRIORITIES[i]; i++) + { + format = av_find_input_format(FFMPEG_CAMERA_DEVICE_TYPE_PRIORITIES[i]); + if (format) + break; + } + + if (!format) + format = av_input_video_device_next(NULL); + + return format; } // TODO: device format shall be: "/" @@ -140,10 +150,10 @@ static void *ffmpeg_camera_init(const char *device, uint64_t caps, unsigned widt avdevice_register_all(); RARCH_LOG("[FFMPEG]: Initialized libavdevice.\n"); - ffmpeg->input_format = ffmpeg_camera_choose_format(device); + ffmpeg->input_format = ffmpeg_camera_get_default_backend(); if (!ffmpeg->input_format) { - RARCH_ERR("[FFMPEG]: No suitable video input devices found.\n"); + RARCH_ERR("[FFMPEG]: No suitable video input backend found.\n"); goto error; }