From 3c0c2c3d5af915b7e638a9b1d801bae84ef20a73 Mon Sep 17 00:00:00 2001 From: Goldenkrew3000 Date: Fri, 24 Oct 2025 15:18:55 +1000 Subject: [PATCH] Added error handling to discord RPC and made user agent consistent --- src/discordrpc.c | 13 +++++++++---- src/discordrpc.h | 2 +- src/main.c | 8 +++++--- src/player/player.c | 19 +++++++++++++++---- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/discordrpc.c b/src/discordrpc.c index a0916c2..11c748c 100644 --- a/src/discordrpc.c +++ b/src/discordrpc.c @@ -6,6 +6,7 @@ * Note: This provides server auth creds (encoded) directly to Discord, could use Spotify's API instead?? */ +#include #include #include #include @@ -57,7 +58,7 @@ static void handleDiscordError(int errcode, const char* message) printf("\nDiscord: error (%d: %s)\n", errcode, message); } -void discordrpc_init() { +int discordrpc_init() { printf("[DiscordRPC] Initializing...\n"); DiscordEventHandlers handlers; memset(&handlers, 0, sizeof(handlers)); @@ -67,8 +68,12 @@ void discordrpc_init() { Discord_Initialize(discordrpc_appid, &handlers, 1, NULL); // Fetch OS String for RPC (Heap-allocated) - // TODO: Check if failed discordrpc_osString = discordrpc_getOS(); + if (discordrpc_osString == NULL) { + logger_log_error(__func__, "asprintf() or strdup() failed."); + return 1; + } + return 0; } void discordrpc_update(discordrpc_data** discordrpc_struct) { @@ -104,8 +109,6 @@ void discordrpc_update(discordrpc_data** discordrpc_struct) { char* discordrpc_getOS() { #if defined(__linux__) // NOTE: Could have made a sysctl function, but this is literally only done here, not worth it - // TODO: This is ONLY linux compatible at this point - FILE* fp_ostype = fopen("/proc/sys/kernel/ostype", "r"); char buf_ostype[16]; if (!fp_ostype) { @@ -211,6 +214,8 @@ char* discordrpc_getOS() { } return osString; #else + // NOTE: This is not a critical error, just let the user know + logger_log_error(__func__, "Could not fetch OS details."); return strdup("on Unknown"); #endif } diff --git a/src/discordrpc.h b/src/discordrpc.h index 424937a..634b9e9 100644 --- a/src/discordrpc.h +++ b/src/discordrpc.h @@ -22,7 +22,7 @@ typedef struct { void discordrpc_struct_init(discordrpc_data** discordrpc_struct); void discordrpc_struct_deinit(discordrpc_data** discordrpc_struct); -void discordrpc_init(); +int discordrpc_init(); void discordrpc_update(discordrpc_data** discordrpc_struct); char* discordrpc_getOS(); diff --git a/src/main.c b/src/main.c index 2f8b9ed..785ec3b 100644 --- a/src/main.c +++ b/src/main.c @@ -17,13 +17,12 @@ #include "player/player.h" #include "discordrpc.h" +static int rc = 0; configHandler_config_t* configObj = NULL; int checkConfigFile(); int validateConnection(); int main(int argc, char** argv) { - int rc = 0; - // Read config file rc = configHandler_Read(&configObj); if (rc != 0) { @@ -61,7 +60,10 @@ int main(int argc, char** argv) { discordrpc_data* discordrpc = NULL; discordrpc_struct_init(&discordrpc); discordrpc->state = DISCORDRPC_STATE_IDLE; - discordrpc_init(); + rc = discordrpc_init(); + if (rc != 0) { + return 1; + } discordrpc_update(&discordrpc); discordrpc_struct_deinit(&discordrpc); diff --git a/src/player/player.c b/src/player/player.c index 1f07712..2ed41bd 100644 --- a/src/player/player.c +++ b/src/player/player.c @@ -29,6 +29,10 @@ guint bus_watch_id; GMainLoop* loop; bool isPlaying = false; +static void gst_playbin3_sourcesetup_callback(GstElement* playbin, GstElement* source, gpointer udata) { + g_object_set(G_OBJECT(source), "user-agent", "OSSP/1.0 (avery@hojuix.org)", NULL); +} + static gboolean gst_bus_call(GstBus* bus, GstMessage* message, gpointer data) { GMainLoop* loop = (GMainLoop*)data; @@ -148,7 +152,6 @@ void* OSSPlayer_ThrdInit(void*) { discordrpc_update(&discordrpc); discordrpc_struct_deinit(&discordrpc); - printf("%s\n", coverart_url->formedUrl); opensubsonic_httpClient_URL_cleanup(&coverart_url); opensubsonic_getSong_struct_free(&songStruct); @@ -235,13 +238,14 @@ int OSSPlayer_GstInit() { gst_object_unref(sink_pad); gst_object_unref(src_pad); - // TEST - Setup playbin + // Setup playbin3 (Configure audio plugins and set user agent) g_object_set(playbin, "audio-filter", filter_bin, NULL); + g_signal_connect (playbin, "source-setup", G_CALLBACK(gst_playbin3_sourcesetup_callback), NULL); - // 000 + // Add playbin3 to the pipeline gst_bin_add(GST_BIN(pipeline), playbin); - // Initialize in-volume + // Initialize in-volume (Volume before the audio reaches the plugins) g_object_set(in_volume, "volume", 0.175, NULL); // Initialize equalizer @@ -309,6 +313,13 @@ int OSSPlayer_GstInit() { g_object_set(equalizer, "enabled", true, NULL); } + + // Initialize pitch + + + + + // Initialize reverb } int OSSPlayer_GstDeInit() {