Przeglądaj źródła

UI: Fix matching FFmpeg formats/codecs

derrod 2 lat temu
rodzic
commit
c1cd268532
2 zmienionych plików z 25 dodań i 4 usunięć
  1. 24 3
      UI/ffmpeg-utils.hpp
  2. 1 1
      UI/window-basic-settings.cpp

+ 24 - 3
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)

+ 1 - 1
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);