diff --git a/frontend/utility/FFmpegCodec.cpp b/frontend/utility/FFmpegCodec.cpp
index 88e9b0eab..b93edb56b 100644
--- a/frontend/utility/FFmpegCodec.cpp
+++ b/frontend/utility/FFmpegCodec.cpp
@@ -15,15 +15,12 @@
along with this program. If not, see .
******************************************************************************/
-#include "ffmpeg-utils.hpp"
+#include "FFmpegCodec.hpp"
+#include "FFmpegFormat.hpp"
#include
#include
-extern "C" {
-#include
-}
-
using namespace std;
vector GetFormatCodecs(const FFmpegFormat &format, bool ignore_compatibility)
@@ -47,51 +44,6 @@ vector GetFormatCodecs(const FFmpegFormat &format, bool ignore_comp
return codecs;
}
-static bool is_output_device(const AVClass *avclass)
-{
- if (!avclass)
- return false;
-
- switch (avclass->category) {
- case AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT:
- case AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT:
- case AV_CLASS_CATEGORY_DEVICE_OUTPUT:
- return true;
- default:
- return false;
- }
-}
-
-vector GetSupportedFormats()
-{
- vector formats;
- const AVOutputFormat *output_format;
-
- void *i = 0;
- while ((output_format = av_muxer_iterate(&i)) != nullptr) {
- if (is_output_device(output_format->priv_class))
- continue;
-
- formats.emplace_back(output_format);
- }
-
- return formats;
-}
-
-FFmpegCodec FFmpegFormat::GetDefaultEncoder(FFmpegCodecType codec_type) const
-{
- const AVCodecID codec_id = codec_type == VIDEO ? video_codec : audio_codec;
- if (codec_type == UNKNOWN || codec_id == AV_CODEC_ID_NONE)
- return {};
-
- if (auto codec = avcodec_find_encoder(codec_id))
- return {codec};
-
- /* Fall back to using the format name as the encoder,
- * this works for some formats such as FLV. */
- return FFmpegCodec{name, codec_id, codec_type};
-}
-
bool FFCodecAndFormatCompatible(const char *codec, const char *format)
{
if (!codec || !format)
diff --git a/frontend/utility/FFmpegCodec.hpp b/frontend/utility/FFmpegCodec.hpp
index 4a0ef5eba..27893fd8e 100644
--- a/frontend/utility/FFmpegCodec.hpp
+++ b/frontend/utility/FFmpegCodec.hpp
@@ -17,85 +17,15 @@
#pragma once
-#include
-#include
-#include
+#include "FFmpegShared.hpp"
extern "C" {
#include
#include
}
+#include
-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 FFmpegCodec;
-
-struct FFmpegFormat {
- const char *name;
- const char *long_name;
- const char *mime_type;
- const char *extensions;
- AVCodecID audio_codec;
- AVCodecID video_codec;
- const AVCodecTag *const *codec_tags;
-
- FFmpegFormat() = default;
-
- FFmpegFormat(const char *name, const char *mime_type)
- : name(name),
- long_name(nullptr),
- mime_type(mime_type),
- extensions(nullptr),
- audio_codec(AV_CODEC_ID_NONE),
- video_codec(AV_CODEC_ID_NONE),
- codec_tags(nullptr)
- {
- }
-
- FFmpegFormat(const AVOutputFormat *av_format)
- : name(av_format->name),
- long_name(av_format->long_name),
- mime_type(av_format->mime_type),
- extensions(av_format->extensions),
- audio_codec(av_format->audio_codec),
- video_codec(av_format->video_codec),
- codec_tags(av_format->codec_tag)
- {
- }
-
- FFmpegCodec GetDefaultEncoder(FFmpegCodecType codec_type) const;
-
- bool HasAudio() const { return audio_codec != AV_CODEC_ID_NONE; }
- bool HasVideo() const { return video_codec != AV_CODEC_ID_NONE; }
-
- bool operator==(const FFmpegFormat &format) const
- {
- if (!strequal(name, format.name))
- return false;
-
- return strequal(mime_type, format.mime_type);
- }
-};
-Q_DECLARE_METATYPE(FFmpegFormat)
+struct FFmpegFormat;
struct FFmpegCodec {
const char *name;
@@ -138,7 +68,6 @@ struct FFmpegCodec {
};
Q_DECLARE_METATYPE(FFmpegCodec)
-std::vector GetSupportedFormats();
std::vector GetFormatCodecs(const FFmpegFormat &format, bool ignore_compatibility);
bool FFCodecAndFormatCompatible(const char *codec, const char *format);
diff --git a/frontend/utility/FFmpegFormat.cpp b/frontend/utility/FFmpegFormat.cpp
index 88e9b0eab..8d8c4e606 100644
--- a/frontend/utility/FFmpegFormat.cpp
+++ b/frontend/utility/FFmpegFormat.cpp
@@ -15,38 +15,11 @@
along with this program. If not, see .
******************************************************************************/
-#include "ffmpeg-utils.hpp"
-
-#include
-#include
-
-extern "C" {
-#include
-}
+#include "FFmpegFormat.hpp"
+#include "FFmpegCodec.hpp"
using namespace std;
-vector GetFormatCodecs(const FFmpegFormat &format, bool ignore_compatibility)
-{
- vector codecs;
- const AVCodec *codec;
- void *i = 0;
-
- while ((codec = av_codec_iterate(&i)) != nullptr) {
- // Not an encoding codec
- if (!av_codec_is_encoder(codec))
- continue;
- // Skip if not supported and compatibility check not disabled
- if (!ignore_compatibility && !av_codec_get_tag(format.codec_tags, codec->id)) {
- continue;
- }
-
- codecs.emplace_back(codec);
- }
-
- return codecs;
-}
-
static bool is_output_device(const AVClass *avclass)
{
if (!avclass)
@@ -91,129 +64,3 @@ FFmpegCodec FFmpegFormat::GetDefaultEncoder(FFmpegCodecType codec_type) const
* this works for some formats such as FLV. */
return FFmpegCodec{name, codec_id, codec_type};
}
-
-bool FFCodecAndFormatCompatible(const char *codec, const char *format)
-{
- if (!codec || !format)
- return false;
-
- const AVOutputFormat *output_format = av_guess_format(format, nullptr, nullptr);
- if (!output_format)
- return false;
-
- const AVCodecDescriptor *codec_desc = avcodec_descriptor_get_by_name(codec);
- if (!codec_desc)
- return false;
-
- return avformat_query_codec(output_format, codec_desc->id, FF_COMPLIANCE_NORMAL) == 1;
-}
-
-static const unordered_set builtin_codecs = {
- "h264", "hevc", "av1", "prores", "aac", "opus", "alac", "flac", "pcm_s16le", "pcm_s24le", "pcm_f32le",
-};
-
-bool IsBuiltinCodec(const char *codec)
-{
- return builtin_codecs.count(codec) > 0;
-}
-
-static const unordered_map> codec_compat = {
- // Technically our muxer supports HEVC and AV1 as well, but nothing else does
- {"flv",
- {
- "h264",
- "aac",
- }},
- {"mpegts",
- {
- "h264",
- "hevc",
- "aac",
- "opus",
- }},
- {"hls",
- // Also using MPEG-TS in our case, but no Opus support
- {
- "h264",
- "hevc",
- "aac",
- }},
- {"mp4",
- {
- "h264",
- "hevc",
- "av1",
- "aac",
- "opus",
- "alac",
- "flac",
- "pcm_s16le",
- "pcm_s24le",
- "pcm_f32le",
- }},
- {"fragmented_mp4",
- {
- "h264",
- "hevc",
- "av1",
- "aac",
- "opus",
- "alac",
- "flac",
- "pcm_s16le",
- "pcm_s24le",
- "pcm_f32le",
- }},
- // Not part of FFmpeg, see obs-outputs module
- {"hybrid_mp4",
- {
- "h264",
- "hevc",
- "av1",
- "aac",
- "opus",
- "alac",
- "flac",
- "pcm_s16le",
- "pcm_s24le",
- "pcm_f32le",
- }},
- {"mov",
- {
- "h264",
- "hevc",
- "prores",
- "aac",
- "alac",
- "pcm_s16le",
- "pcm_s24le",
- "pcm_f32le",
- }},
- {"fragmented_mov",
- {
- "h264",
- "hevc",
- "prores",
- "aac",
- "alac",
- "pcm_s16le",
- "pcm_s24le",
- "pcm_f32le",
- }},
- // MKV supports everything
- {"mkv", {}},
-};
-
-bool ContainerSupportsCodec(const string &container, const string &codec)
-{
- auto iter = codec_compat.find(container);
- if (iter == codec_compat.end())
- return false;
-
- auto codecs = iter->second;
- // Assume everything is supported
- if (codecs.empty())
- return true;
-
- return codecs.count(codec) > 0;
-}
diff --git a/frontend/utility/FFmpegFormat.hpp b/frontend/utility/FFmpegFormat.hpp
index 4a0ef5eba..6c44bcd59 100644
--- a/frontend/utility/FFmpegFormat.hpp
+++ b/frontend/utility/FFmpegFormat.hpp
@@ -17,35 +17,13 @@
#pragma once
-#include
-#include
-#include
+#include "FFmpegShared.hpp"
extern "C" {
#include
#include
}
-
-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;
-}
+#include
struct FFmpegCodec;
@@ -95,52 +73,7 @@ struct FFmpegFormat {
return strequal(mime_type, format.mime_type);
}
};
+
Q_DECLARE_METATYPE(FFmpegFormat)
-struct FFmpegCodec {
- const char *name;
- const char *long_name;
- int id;
-
- FFmpegCodecType type;
-
- FFmpegCodec() = default;
-
- FFmpegCodec(const char *name, int id, FFmpegCodecType type = UNKNOWN)
- : name(name),
- long_name(nullptr),
- id(id),
- type(type)
- {
- }
-
- FFmpegCodec(const AVCodec *codec) : name(codec->name), long_name(codec->long_name), id(codec->id)
- {
- switch (codec->type) {
- case AVMEDIA_TYPE_AUDIO:
- type = AUDIO;
- break;
- case AVMEDIA_TYPE_VIDEO:
- type = VIDEO;
- break;
- default:
- type = UNKNOWN;
- }
- }
-
- bool operator==(const FFmpegCodec &codec) const
- {
- if (id != codec.id)
- return false;
-
- return strequal(name, codec.name);
- }
-};
-Q_DECLARE_METATYPE(FFmpegCodec)
-
std::vector GetSupportedFormats();
-std::vector GetFormatCodecs(const FFmpegFormat &format, bool ignore_compatibility);
-
-bool FFCodecAndFormatCompatible(const char *codec, const char *format);
-bool IsBuiltinCodec(const char *codec);
-bool ContainerSupportsCodec(const std::string &container, const std::string &codec);
diff --git a/frontend/utility/FFmpegShared.hpp b/frontend/utility/FFmpegShared.hpp
index 4a0ef5eba..c0a3a573e 100644
--- a/frontend/utility/FFmpegShared.hpp
+++ b/frontend/utility/FFmpegShared.hpp
@@ -17,14 +17,7 @@
#pragma once
-#include
-#include
-#include
-
-extern "C" {
-#include
-#include
-}
+#include
enum FFmpegCodecType { AUDIO, VIDEO, UNKNOWN };
@@ -46,101 +39,3 @@ static bool strequal(const char *a, const char *b)
return strcmp(a, b) == 0;
}
-
-struct FFmpegCodec;
-
-struct FFmpegFormat {
- const char *name;
- const char *long_name;
- const char *mime_type;
- const char *extensions;
- AVCodecID audio_codec;
- AVCodecID video_codec;
- const AVCodecTag *const *codec_tags;
-
- FFmpegFormat() = default;
-
- FFmpegFormat(const char *name, const char *mime_type)
- : name(name),
- long_name(nullptr),
- mime_type(mime_type),
- extensions(nullptr),
- audio_codec(AV_CODEC_ID_NONE),
- video_codec(AV_CODEC_ID_NONE),
- codec_tags(nullptr)
- {
- }
-
- FFmpegFormat(const AVOutputFormat *av_format)
- : name(av_format->name),
- long_name(av_format->long_name),
- mime_type(av_format->mime_type),
- extensions(av_format->extensions),
- audio_codec(av_format->audio_codec),
- video_codec(av_format->video_codec),
- codec_tags(av_format->codec_tag)
- {
- }
-
- FFmpegCodec GetDefaultEncoder(FFmpegCodecType codec_type) const;
-
- bool HasAudio() const { return audio_codec != AV_CODEC_ID_NONE; }
- bool HasVideo() const { return video_codec != AV_CODEC_ID_NONE; }
-
- bool operator==(const FFmpegFormat &format) const
- {
- if (!strequal(name, format.name))
- return false;
-
- return strequal(mime_type, format.mime_type);
- }
-};
-Q_DECLARE_METATYPE(FFmpegFormat)
-
-struct FFmpegCodec {
- const char *name;
- const char *long_name;
- int id;
-
- FFmpegCodecType type;
-
- FFmpegCodec() = default;
-
- FFmpegCodec(const char *name, int id, FFmpegCodecType type = UNKNOWN)
- : name(name),
- long_name(nullptr),
- id(id),
- type(type)
- {
- }
-
- FFmpegCodec(const AVCodec *codec) : name(codec->name), long_name(codec->long_name), id(codec->id)
- {
- switch (codec->type) {
- case AVMEDIA_TYPE_AUDIO:
- type = AUDIO;
- break;
- case AVMEDIA_TYPE_VIDEO:
- type = VIDEO;
- break;
- default:
- type = UNKNOWN;
- }
- }
-
- bool operator==(const FFmpegCodec &codec) const
- {
- if (id != codec.id)
- return false;
-
- return strequal(name, codec.name);
- }
-};
-Q_DECLARE_METATYPE(FFmpegCodec)
-
-std::vector GetSupportedFormats();
-std::vector GetFormatCodecs(const FFmpegFormat &format, bool ignore_compatibility);
-
-bool FFCodecAndFormatCompatible(const char *codec, const char *format);
-bool IsBuiltinCodec(const char *codec);
-bool ContainerSupportsCodec(const std::string &container, const std::string &codec);
diff --git a/frontend/utility/MacUpdateThread.cpp b/frontend/utility/MacUpdateThread.cpp
index 33fca9430..ffaa3881d 100644
--- a/frontend/utility/MacUpdateThread.cpp
+++ b/frontend/utility/MacUpdateThread.cpp
@@ -1,20 +1,15 @@
-#include "update-helpers.hpp"
-#include "shared-update.hpp"
-#include "moc_mac-update.cpp"
-#include "obs-app.hpp"
+#include "MacUpdateThread.hpp"
-#include
+#include
+#include
#include
-#include
-/* ------------------------------------------------------------------------ */
+#include "moc_MacUpdateThread.cpp"
static const char *MAC_BRANCHES_URL = "https://obsproject.com/update_studio/branches.json";
static const char *MAC_DEFAULT_BRANCH = "stable";
-/* ------------------------------------------------------------------------ */
-
bool GetBranch(std::string &selectedBranch)
{
const char *config_branch = config_get_string(App()->GetAppConfig(), "General", "UpdateBranch");
@@ -39,8 +34,6 @@ bool GetBranch(std::string &selectedBranch)
return found;
}
-/* ------------------------------------------------------------------------ */
-
void MacUpdateThread::infoMsg(const QString &title, const QString &text)
{
OBSMessageBox::information(App()->GetMainWindow(), title, text);
diff --git a/frontend/utility/MacUpdateThread.hpp b/frontend/utility/MacUpdateThread.hpp
index cedac60eb..c4bddbd10 100644
--- a/frontend/utility/MacUpdateThread.hpp
+++ b/frontend/utility/MacUpdateThread.hpp
@@ -1,13 +1,6 @@
-#ifndef MAC_UPDATER_H
-#define MAC_UPDATER_H
-
-#include
+#pragma once
#include
-#include
-#include
-
-class QAction;
class MacUpdateThread : public QThread {
Q_OBJECT
@@ -27,25 +20,3 @@ private slots:
public:
MacUpdateThread(bool manual) : manualUpdate(manual) {}
};
-
-#ifdef __OBJC__
-@class OBSUpdateDelegate;
-#endif
-
-class OBSSparkle : public QObject {
- Q_OBJECT
-
-public:
- OBSSparkle(const char *branch, QAction *checkForUpdatesAction);
- void setBranch(const char *branch);
- void checkForUpdates(bool manualCheck);
-
-private:
-#ifdef __OBJC__
- OBSUpdateDelegate *updaterDelegate;
-#else
- void *updaterDelegate;
-#endif
-};
-
-#endif
diff --git a/frontend/utility/OBSSparkle.hpp b/frontend/utility/OBSSparkle.hpp
index cedac60eb..3f4cffc3c 100644
--- a/frontend/utility/OBSSparkle.hpp
+++ b/frontend/utility/OBSSparkle.hpp
@@ -1,33 +1,8 @@
-#ifndef MAC_UPDATER_H
-#define MAC_UPDATER_H
+#pragma once
-#include
-
-#include
-#include
-#include
+#import
class QAction;
-
-class MacUpdateThread : public QThread {
- Q_OBJECT
-
- bool manualUpdate;
-
- virtual void run() override;
-
- void info(const QString &title, const QString &text);
-
-signals:
- void Result(const QString &branch, bool manual);
-
-private slots:
- void infoMsg(const QString &title, const QString &text);
-
-public:
- MacUpdateThread(bool manual) : manualUpdate(manual) {}
-};
-
#ifdef __OBJC__
@class OBSUpdateDelegate;
#endif
@@ -47,5 +22,3 @@ private:
void *updaterDelegate;
#endif
};
-
-#endif
diff --git a/frontend/utility/OBSSparkle.mm b/frontend/utility/OBSSparkle.mm
index 2afc7e83c..bfb1911aa 100644
--- a/frontend/utility/OBSSparkle.mm
+++ b/frontend/utility/OBSSparkle.mm
@@ -1,54 +1,5 @@
-#include "mac-update.hpp"
-
-#include
-
-#import
-#import
-
-@interface OBSUpdateDelegate : NSObject {
-}
-@property (copy) NSString *branch;
-@property (nonatomic) SPUStandardUpdaterController *updaterController;
-@end
-
-@implementation OBSUpdateDelegate {
-}
-
-@synthesize branch;
-
-- (nonnull NSSet *)allowedChannelsForUpdater:(nonnull SPUUpdater *)updater
-{
- return [NSSet setWithObject:branch];
-}
-
-- (void)observeCanCheckForUpdatesWithAction:(QAction *)action
-{
- [_updaterController.updater addObserver:self forKeyPath:NSStringFromSelector(@selector(canCheckForUpdates))
- options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew)
- context:(void *) action];
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath
- ofObject:(id)object
- change:(NSDictionary *)change
- context:(void *)context
-{
- if ([keyPath isEqualToString:NSStringFromSelector(@selector(canCheckForUpdates))]) {
- QAction *menuAction = (QAction *) context;
- menuAction->setEnabled(_updaterController.updater.canCheckForUpdates);
- } else {
- [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
- }
-}
-
-- (void)dealloc
-{
- @autoreleasepool {
- [_updaterController.updater removeObserver:self forKeyPath:NSStringFromSelector(@selector(canCheckForUpdates))];
- }
-}
-
-@end
+#import "OBSSparkle.hpp"
+#import "OBSUpdateDelegate.h"
OBSSparkle::OBSSparkle(const char *branch, QAction *checkForUpdatesAction)
{
diff --git a/frontend/utility/OBSUpdateDelegate.h b/frontend/utility/OBSUpdateDelegate.h
index 2afc7e83c..1e6f68306 100644
--- a/frontend/utility/OBSUpdateDelegate.h
+++ b/frontend/utility/OBSUpdateDelegate.h
@@ -1,79 +1,37 @@
-#include "mac-update.hpp"
+/******************************************************************************
+ Copyright (C) 2024 by Patrick Heyer
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ ******************************************************************************/
-#include
+#pragma once
-#import
+#import
#import
+#import
+
@interface OBSUpdateDelegate : NSObject {
}
-@property (copy) NSString *branch;
-@property (nonatomic) SPUStandardUpdaterController *updaterController;
-@end
+@property (copy) NSString *_Nonnull branch;
+@property (nonatomic) SPUStandardUpdaterController *_Nonnull updaterController;
-@implementation OBSUpdateDelegate {
-}
-
-@synthesize branch;
-
-- (nonnull NSSet *)allowedChannelsForUpdater:(nonnull SPUUpdater *)updater
-{
- return [NSSet setWithObject:branch];
-}
-
-- (void)observeCanCheckForUpdatesWithAction:(QAction *)action
-{
- [_updaterController.updater addObserver:self forKeyPath:NSStringFromSelector(@selector(canCheckForUpdates))
- options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew)
- context:(void *) action];
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath
- ofObject:(id)object
- change:(NSDictionary *)change
- context:(void *)context
-{
- if ([keyPath isEqualToString:NSStringFromSelector(@selector(canCheckForUpdates))]) {
- QAction *menuAction = (QAction *) context;
- menuAction->setEnabled(_updaterController.updater.canCheckForUpdates);
- } else {
- [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
- }
-}
-
-- (void)dealloc
-{
- @autoreleasepool {
- [_updaterController.updater removeObserver:self forKeyPath:NSStringFromSelector(@selector(canCheckForUpdates))];
- }
-}
+- (nonnull NSSet *)allowedChannelsForUpdater:(nonnull SPUUpdater *)updater;
+- (void)observeCanCheckForUpdatesWithAction:(nonnull QAction *)action;
+- (void)observeValueForKeyPath:(NSString *_Nullable)keyPath
+ ofObject:(id _Nullable)object
+ change:(NSDictionary *_Nullable)change
+ context:(void *_Nullable)context;
@end
-
-OBSSparkle::OBSSparkle(const char *branch, QAction *checkForUpdatesAction)
-{
- @autoreleasepool {
- updaterDelegate = [[OBSUpdateDelegate alloc] init];
- updaterDelegate.branch = [NSString stringWithUTF8String:branch];
- updaterDelegate.updaterController =
- [[SPUStandardUpdaterController alloc] initWithStartingUpdater:YES updaterDelegate:updaterDelegate
- userDriverDelegate:nil];
- [updaterDelegate observeCanCheckForUpdatesWithAction:checkForUpdatesAction];
- }
-}
-
-void OBSSparkle::setBranch(const char *branch)
-{
- updaterDelegate.branch = [NSString stringWithUTF8String:branch];
-}
-
-void OBSSparkle::checkForUpdates(bool manualCheck)
-{
- @autoreleasepool {
- if (manualCheck) {
- [updaterDelegate.updaterController checkForUpdates:nil];
- } else {
- [updaterDelegate.updaterController.updater checkForUpdatesInBackground];
- }
- }
-}
diff --git a/frontend/utility/OBSUpdateDelegate.mm b/frontend/utility/OBSUpdateDelegate.mm
index 2afc7e83c..734091e8b 100644
--- a/frontend/utility/OBSUpdateDelegate.mm
+++ b/frontend/utility/OBSUpdateDelegate.mm
@@ -1,15 +1,4 @@
-#include "mac-update.hpp"
-
-#include
-
-#import
-#import
-
-@interface OBSUpdateDelegate : NSObject {
-}
-@property (copy) NSString *branch;
-@property (nonatomic) SPUStandardUpdaterController *updaterController;
-@end
+#import "OBSUpdateDelegate.h"
@implementation OBSUpdateDelegate {
}
@@ -21,7 +10,7 @@
return [NSSet setWithObject:branch];
}
-- (void)observeCanCheckForUpdatesWithAction:(QAction *)action
+- (void)observeCanCheckForUpdatesWithAction:(nonnull QAction *)action;
{
[_updaterController.updater addObserver:self forKeyPath:NSStringFromSelector(@selector(canCheckForUpdates))
options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew)
@@ -49,31 +38,3 @@
}
@end
-
-OBSSparkle::OBSSparkle(const char *branch, QAction *checkForUpdatesAction)
-{
- @autoreleasepool {
- updaterDelegate = [[OBSUpdateDelegate alloc] init];
- updaterDelegate.branch = [NSString stringWithUTF8String:branch];
- updaterDelegate.updaterController =
- [[SPUStandardUpdaterController alloc] initWithStartingUpdater:YES updaterDelegate:updaterDelegate
- userDriverDelegate:nil];
- [updaterDelegate observeCanCheckForUpdatesWithAction:checkForUpdatesAction];
- }
-}
-
-void OBSSparkle::setBranch(const char *branch)
-{
- updaterDelegate.branch = [NSString stringWithUTF8String:branch];
-}
-
-void OBSSparkle::checkForUpdates(bool manualCheck)
-{
- @autoreleasepool {
- if (manualCheck) {
- [updaterDelegate.updaterController checkForUpdates:nil];
- } else {
- [updaterDelegate.updaterController.updater checkForUpdatesInBackground];
- }
- }
-}
diff --git a/frontend/utility/WhatsNewBrowserInitThread.cpp b/frontend/utility/WhatsNewBrowserInitThread.cpp
index 0aedd8d95..200cf285f 100644
--- a/frontend/utility/WhatsNewBrowserInitThread.cpp
+++ b/frontend/utility/WhatsNewBrowserInitThread.cpp
@@ -1,291 +1,16 @@
-#include "moc_shared-update.cpp"
-#include "crypto-helpers.hpp"
-#include "update-helpers.hpp"
-#include "obs-app.hpp"
-#include "remote-text.hpp"
-#include "platform.hpp"
-
-#include
-#include
-
-#include
-#include
-#include
-
-#include
-#include
-#include
+#include "WhatsNewBrowserInitThread.hpp"
#ifdef BROWSER_AVAILABLE
#include
+#endif
+#include "moc_WhatsNewBrowserInitThread.cpp"
+
+#ifdef BROWSER_AVAILABLE
struct QCef;
extern QCef *cef;
#endif
-#ifndef MAC_WHATSNEW_URL
-#define MAC_WHATSNEW_URL "https://obsproject.com/update_studio/whatsnew.json"
-#endif
-
-#ifndef WIN_WHATSNEW_URL
-#define WIN_WHATSNEW_URL "https://obsproject.com/update_studio/whatsnew.json"
-#endif
-
-#ifndef LINUX_WHATSNEW_URL
-#define LINUX_WHATSNEW_URL "https://obsproject.com/update_studio/whatsnew.json"
-#endif
-
-#ifdef __APPLE__
-#define WHATSNEW_URL MAC_WHATSNEW_URL
-#elif defined(_WIN32)
-#define WHATSNEW_URL WIN_WHATSNEW_URL
-#else
-#define WHATSNEW_URL LINUX_WHATSNEW_URL
-#endif
-
-#define HASH_READ_BUF_SIZE 65536
-#define BLAKE2_HASH_LENGTH 20
-
-/* ------------------------------------------------------------------------ */
-
-static bool QuickWriteFile(const char *file, const std::string &data)
-try {
- std::ofstream fileStream(std::filesystem::u8path(file), std::ios::binary);
- if (fileStream.fail())
- throw strprintf("Failed to open file '%s': %s", file, strerror(errno));
-
- fileStream.write(data.data(), data.size());
- if (fileStream.fail())
- throw strprintf("Failed to write file '%s': %s", file, strerror(errno));
-
- return true;
-
-} catch (std::string &text) {
- blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
- return false;
-}
-
-static bool QuickReadFile(const char *file, std::string &data)
-try {
- std::ifstream fileStream(std::filesystem::u8path(file), std::ios::binary);
- if (!fileStream.is_open() || fileStream.fail())
- throw strprintf("Failed to open file '%s': %s", file, strerror(errno));
-
- fileStream.seekg(0, fileStream.end);
- size_t size = fileStream.tellg();
- fileStream.seekg(0);
-
- data.resize(size);
- fileStream.read(&data[0], size);
-
- if (fileStream.fail())
- throw strprintf("Failed to write file '%s': %s", file, strerror(errno));
-
- return true;
-
-} catch (std::string &text) {
- blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
- return false;
-}
-
-static bool CalculateFileHash(const char *path, uint8_t *hash)
-try {
- blake2b_state blake2;
- if (blake2b_init(&blake2, BLAKE2_HASH_LENGTH) != 0)
- return false;
-
- std::ifstream file(std::filesystem::u8path(path), std::ios::binary);
- if (!file.is_open() || file.fail())
- return false;
-
- char buf[HASH_READ_BUF_SIZE];
-
- for (;;) {
- file.read(buf, HASH_READ_BUF_SIZE);
- size_t read = file.gcount();
- if (blake2b_update(&blake2, &buf, read) != 0)
- return false;
- if (file.eof())
- break;
- }
-
- if (blake2b_final(&blake2, hash, BLAKE2_HASH_LENGTH) != 0)
- return false;
-
- return true;
-
-} catch (std::string &text) {
- blog(LOG_DEBUG, "%s: %s", __FUNCTION__, text.c_str());
- return false;
-}
-
-/* ------------------------------------------------------------------------ */
-
-void GenerateGUID(std::string &guid)
-{
- const char alphabet[] = "0123456789abcdef";
- QRandomGenerator *rng = QRandomGenerator::system();
-
- guid.resize(40);
-
- for (size_t i = 0; i < 40; i++) {
- guid[i] = alphabet[rng->bounded(0, 16)];
- }
-}
-
-std::string GetProgramGUID()
-{
- static std::mutex m;
- std::lock_guard lock(m);
-
- /* NOTE: this is an arbitrary random number that we use to count the
- * number of unique OBS installations and is not associated with any
- * kind of identifiable information */
- const char *pguid = config_get_string(App()->GetAppConfig(), "General", "InstallGUID");
- std::string guid;
- if (pguid)
- guid = pguid;
-
- if (guid.empty()) {
- GenerateGUID(guid);
-
- if (!guid.empty())
- config_set_string(App()->GetAppConfig(), "General", "InstallGUID", guid.c_str());
- }
-
- return guid;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static void LoadPublicKey(std::string &pubkey)
-{
- std::string pemFilePath;
-
- if (!GetDataFilePath("OBSPublicRSAKey.pem", pemFilePath))
- throw std::string("Could not find OBS public key file!");
- if (!QuickReadFile(pemFilePath.c_str(), pubkey))
- throw std::string("Could not read OBS public key file!");
-}
-
-static bool CheckDataSignature(const char *name, const std::string &data, const std::string &hexSig)
-try {
- static std::mutex pubkey_mutex;
- static std::string obsPubKey;
-
- if (hexSig.empty() || hexSig.length() > 0xFFFF || (hexSig.length() & 1) != 0)
- throw strprintf("Missing or invalid signature for %s: %s", name, hexSig.c_str());
-
- std::scoped_lock lock(pubkey_mutex);
- if (obsPubKey.empty())
- LoadPublicKey(obsPubKey);
-
- // Convert hex string to bytes
- auto signature = QByteArray::fromHex(hexSig.data());
-
- if (!VerifySignature((uint8_t *)obsPubKey.data(), obsPubKey.size(), (uint8_t *)data.data(), data.size(),
- (uint8_t *)signature.data(), signature.size()))
- throw strprintf("Signature check failed for %s", name);
-
- return true;
-
-} catch (std::string &text) {
- blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
- return false;
-}
-
-/* ------------------------------------------------------------------------ */
-
-bool FetchAndVerifyFile(const char *name, const char *file, const char *url, std::string *out,
- const std::vector &extraHeaders)
-{
- long responseCode;
- std::vector headers;
- std::string error;
- std::string signature;
- std::string data;
- uint8_t fileHash[BLAKE2_HASH_LENGTH];
- bool success;
-
- BPtr filePath = GetAppConfigPathPtr(file);
-
- if (!extraHeaders.empty()) {
- headers.insert(headers.end(), extraHeaders.begin(), extraHeaders.end());
- }
-
- /* ----------------------------------- *
- * avoid downloading file again */
-
- if (CalculateFileHash(filePath, fileHash)) {
- auto hash = QByteArray::fromRawData((const char *)fileHash, BLAKE2_HASH_LENGTH);
-
- QString header = "If-None-Match: " + hash.toHex();
- headers.push_back(header.toStdString());
- }
-
- /* ----------------------------------- *
- * get current install GUID */
-
- std::string guid = GetProgramGUID();
-
- if (!guid.empty()) {
- std::string header = "X-OBS2-GUID: " + guid;
- headers.push_back(std::move(header));
- }
-
- /* ----------------------------------- *
- * get file from server */
-
- success = GetRemoteFile(url, data, error, &responseCode, nullptr, "", nullptr, headers, &signature);
-
- if (!success || (responseCode != 200 && responseCode != 304)) {
- if (responseCode == 404)
- return false;
-
- throw strprintf("Failed to fetch %s file: %s", name, error.c_str());
- }
-
- /* ----------------------------------- *
- * verify file signature */
-
- if (responseCode == 200) {
- success = CheckDataSignature(name, data, signature);
- if (!success)
- throw strprintf("Invalid %s signature", name);
- }
-
- /* ----------------------------------- *
- * write or load file */
-
- if (responseCode == 200) {
- if (!QuickWriteFile(filePath, data))
- throw strprintf("Could not write file '%s'", filePath.Get());
- } else if (out) { /* Only read file if caller wants data */
- if (!QuickReadFile(filePath, data))
- throw strprintf("Could not read file '%s'", filePath.Get());
- }
-
- if (out)
- *out = data;
-
- /* ----------------------------------- *
- * success */
- return true;
-}
-
-void WhatsNewInfoThread::run()
-try {
- std::string text;
-
- if (FetchAndVerifyFile("whatsnew", "obs-studio/updates/whatsnew.json", WHATSNEW_URL, &text)) {
- emit Result(QString::fromStdString(text));
- }
-} catch (std::string &text) {
- blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
-}
-
-/* ------------------------------------------------------------------------ */
-
void WhatsNewBrowserInitThread::run()
{
#ifdef BROWSER_AVAILABLE
diff --git a/frontend/utility/WhatsNewBrowserInitThread.hpp b/frontend/utility/WhatsNewBrowserInitThread.hpp
index c33b8823d..6fd28acb7 100644
--- a/frontend/utility/WhatsNewBrowserInitThread.hpp
+++ b/frontend/utility/WhatsNewBrowserInitThread.hpp
@@ -1,25 +1,6 @@
#pragma once
#include
-#include
-
-#include
-#include
-
-bool FetchAndVerifyFile(const char *name, const char *file, const char *url, std::string *out,
- const std::vector &extraHeaders = std::vector());
-
-class WhatsNewInfoThread : public QThread {
- Q_OBJECT
-
- virtual void run() override;
-
-signals:
- void Result(const QString &text);
-
-public:
- inline WhatsNewInfoThread() {}
-};
class WhatsNewBrowserInitThread : public QThread {
Q_OBJECT
diff --git a/frontend/utility/WhatsNewInfoThread.cpp b/frontend/utility/WhatsNewInfoThread.cpp
index 0aedd8d95..24ebd010f 100644
--- a/frontend/utility/WhatsNewInfoThread.cpp
+++ b/frontend/utility/WhatsNewInfoThread.cpp
@@ -1,27 +1,17 @@
-#include "moc_shared-update.cpp"
-#include "crypto-helpers.hpp"
-#include "update-helpers.hpp"
-#include "obs-app.hpp"
-#include "remote-text.hpp"
-#include "platform.hpp"
+#include "WhatsNewInfoThread.hpp"
-#include
-#include
-
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
#include
-#include
-#include
+#include
-#ifdef BROWSER_AVAILABLE
-#include
+#include
-struct QCef;
-extern QCef *cef;
-#endif
+#include "moc_WhatsNewInfoThread.cpp"
#ifndef MAC_WHATSNEW_URL
#define MAC_WHATSNEW_URL "https://obsproject.com/update_studio/whatsnew.json"
@@ -283,13 +273,3 @@ try {
} catch (std::string &text) {
blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
}
-
-/* ------------------------------------------------------------------------ */
-
-void WhatsNewBrowserInitThread::run()
-{
-#ifdef BROWSER_AVAILABLE
- cef->wait_for_browser_init();
-#endif
- emit Result(url);
-}
diff --git a/frontend/utility/WhatsNewInfoThread.hpp b/frontend/utility/WhatsNewInfoThread.hpp
index c33b8823d..d384eeb58 100644
--- a/frontend/utility/WhatsNewInfoThread.hpp
+++ b/frontend/utility/WhatsNewInfoThread.hpp
@@ -1,10 +1,6 @@
#pragma once
#include
-#include
-
-#include
-#include
bool FetchAndVerifyFile(const char *name, const char *file, const char *url, std::string *out,
const std::vector &extraHeaders = std::vector());
@@ -20,17 +16,3 @@ signals:
public:
inline WhatsNewInfoThread() {}
};
-
-class WhatsNewBrowserInitThread : public QThread {
- Q_OBJECT
-
- QString url;
-
- virtual void run() override;
-
-signals:
- void Result(const QString &url);
-
-public:
- inline WhatsNewBrowserInitThread(const QString &url_) : url(url_) {}
-};