From 49915675ece2b1c77c8f9b00389a1dc5b8298547 Mon Sep 17 00:00:00 2001 From: infinityabundance <255699974+infinityabundance@users.noreply.github.com> Date: Fri, 6 Feb 2026 19:22:08 +0000 Subject: [PATCH] Polish audio settings and NVENC selection --- src/main.c | 20 +++++++++++++++++--- src/network.c | 3 +++ src/opus_codec.c | 8 +++++++- src/service.c | 20 +++++++++++++------- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 8022d45..a651f4b 100644 --- a/src/main.c +++ b/src/main.c @@ -197,9 +197,23 @@ static int run_host_mode(rootstream_ctx_t *ctx, int display_idx, bool no_discove } /* Use H.264 by default (host mode doesn't use settings file) */ - if (rootstream_encoder_init(ctx, ENCODER_VAAPI, CODEC_H264) < 0) { - fprintf(stderr, "ERROR: Encoder init failed\n"); - return -1; + { + extern bool rootstream_encoder_nvenc_available(void); + if (rootstream_encoder_nvenc_available()) { + printf("INFO: NVENC detected, trying NVIDIA encoder...\n"); + if (rootstream_encoder_init(ctx, ENCODER_NVENC, CODEC_H264) == 0) { + printf("✓ Using NVENC encoder\n"); + } else { + printf("WARNING: NVENC init failed, falling back to VA-API\n"); + if (rootstream_encoder_init(ctx, ENCODER_VAAPI, CODEC_H264) < 0) { + fprintf(stderr, "ERROR: Encoder init failed\n"); + return -1; + } + } + } else if (rootstream_encoder_init(ctx, ENCODER_VAAPI, CODEC_H264) < 0) { + fprintf(stderr, "ERROR: Encoder init failed\n"); + return -1; + } } if (rootstream_net_init(ctx, ctx->port) < 0) { diff --git a/src/network.c b/src/network.c index 92c35eb..91a1124 100644 --- a/src/network.c +++ b/src/network.c @@ -559,6 +559,9 @@ int rootstream_net_recv(rootstream_ctx_t *ctx, int timeout_ms) { } } else if (hdr->type == PKT_AUDIO) { + if (!ctx->settings.audio_enabled) { + break; + } /* Decode Opus audio and play immediately */ if (decrypted_len < sizeof(audio_packet_header_t)) { fprintf(stderr, "WARNING: Audio packet too small: %zu bytes\n", decrypted_len); diff --git a/src/opus_codec.c b/src/opus_codec.c index 6cc1ac5..ae27585 100644 --- a/src/opus_codec.c +++ b/src/opus_codec.c @@ -60,7 +60,10 @@ int rootstream_opus_encoder_init(rootstream_ctx_t *ctx) { opus->sample_rate = OPUS_SAMPLE_RATE; opus->channels = OPUS_CHANNELS; opus->frame_size = OPUS_FRAME_SIZE; - opus->bitrate = OPUS_BITRATE; + opus->bitrate = ctx->settings.audio_bitrate; + if (opus->bitrate == 0) { + opus->bitrate = OPUS_BITRATE; + } /* Create Opus encoder */ int error; @@ -116,7 +119,10 @@ int rootstream_opus_decoder_init(rootstream_ctx_t *ctx) { opus->sample_rate = OPUS_SAMPLE_RATE; opus->channels = OPUS_CHANNELS; opus->frame_size = OPUS_FRAME_SIZE; + opus->bitrate = ctx->settings.audio_bitrate; + if (opus->bitrate == 0) { opus->bitrate = OPUS_BITRATE; + } ctx->uinput_kbd_fd = (int)(intptr_t)opus; } diff --git a/src/service.c b/src/service.c index ba09a8c..0b29807 100644 --- a/src/service.c +++ b/src/service.c @@ -355,11 +355,15 @@ int service_run_client(rootstream_ctx_t *ctx) { } /* Initialize audio playback and Opus decoder */ - if (audio_playback_init(ctx) < 0) { - fprintf(stderr, "WARNING: Audio playback init failed (continuing without audio)\n"); - } else if (rootstream_opus_decoder_init(ctx) < 0) { - fprintf(stderr, "WARNING: Opus decoder init failed (continuing without audio)\n"); - audio_playback_cleanup(ctx); + if (ctx->settings.audio_enabled) { + if (audio_playback_init(ctx) < 0) { + fprintf(stderr, "WARNING: Audio playback init failed (continuing without audio)\n"); + } else if (rootstream_opus_decoder_init(ctx) < 0) { + fprintf(stderr, "WARNING: Opus decoder init failed (continuing without audio)\n"); + audio_playback_cleanup(ctx); + } + } else { + printf("INFO: Audio disabled in settings\n"); } printf("✓ Client initialized - ready to receive video and audio\n"); @@ -425,8 +429,10 @@ int service_run_client(rootstream_ctx_t *ctx) { free(decoded_frame.data); } - audio_playback_cleanup(ctx); - rootstream_opus_cleanup(ctx); + if (ctx->settings.audio_enabled) { + audio_playback_cleanup(ctx); + rootstream_opus_cleanup(ctx); + } display_cleanup(ctx); rootstream_decoder_cleanup(ctx);