From c1cd268532f8aa1e6869514569eb077cbc5ce56c Mon Sep 17 00:00:00 2001 From: derrod Date: Tue, 1 Aug 2023 09:02:04 +0200 Subject: [PATCH] UI: Fix matching FFmpeg formats/codecs --- UI/ffmpeg-utils.hpp | 27 ++++++++++++++++++++++++--- UI/window-basic-settings.cpp | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/UI/ffmpeg-utils.hpp b/UI/ffmpeg-utils.hpp index 5a5eeadf7..55bfd5c43 100644 --- a/UI/ffmpeg-utils.hpp +++ b/UI/ffmpeg-utils.hpp @@ -28,6 +28,25 @@ extern "C" { enum FFmpegCodecType { AUDIO, VIDEO, UNKNOWN }; +/* This needs to handle a few special cases due to how the format is used in the UI: + * - strequal(nullptr, "") must be true + * - strequal("", nullptr) must be true + * - strequal(nullptr, nullptr) must be true + */ +static bool strequal(const char *a, const char *b) +{ + if (!a && !b) + return true; + if (!a && *b == 0) + return true; + if (!b && *a == 0) + return true; + if (!a || !b) + return false; + + return strcmp(a, b) == 0; +} + struct FFmpegFormat { const char *name; const char *long_name; @@ -46,9 +65,10 @@ struct FFmpegFormat { bool operator==(const FFmpegFormat &format) const { - if (strcmp(name, format.name) != 0) + if (!strequal(name, format.name)) return false; - return strcmp(mime_type, format.mime_type) != 0; + + return strequal(mime_type, format.mime_type); } }; Q_DECLARE_METATYPE(FFmpegFormat) @@ -69,7 +89,8 @@ struct FFmpegCodec { { if (id != codec.id) return false; - return strcmp(name, codec.name) != 0; + + return strequal(name, codec.name); } }; Q_DECLARE_METATYPE(FFmpegCodec) diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index dc9f051fc..53fc7d447 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -2238,7 +2238,7 @@ void OBSBasicSettings::LoadAdvOutputRecordingEncoderProperties() static void SelectFormat(QComboBox *combo, const char *name, const char *mimeType) { - FFmpegFormat format{name, mimeType}; + FFmpegFormat format{name, nullptr, mimeType}; for (int i = 0; i < combo->count(); i++) { QVariant v = combo->itemData(i);