Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/opus_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 13 additions & 7 deletions src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
Loading