From 316161f6aacbe4851ebc629ce99f36d1e0981dfc Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 25 Jun 2025 11:02:21 -0400 Subject: [PATCH] MT#62571 add sink to decode_t Unused at this point except for the resampler Change-Id: I093d7924c0bcc42a9a5162e1f02a374ea97e1bf3 --- recording-daemon/decoder.c | 12 ++++++------ recording-daemon/output.c | 3 ++- recording-daemon/output.h | 1 + recording-daemon/packet.c | 2 ++ recording-daemon/types.h | 8 ++++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/recording-daemon/decoder.c b/recording-daemon/decoder.c index 2fa8f840e..183521960 100644 --- a/recording-daemon/decoder.c +++ b/recording-daemon/decoder.c @@ -26,6 +26,7 @@ int resample_audio; +// does not initialise the contained `sink` decode_t *decoder_new(const char *payload_str, const char *format, int ptime, const format_t *dec_format) { char *slash = strchr(payload_str, '/'); if (!slash) { @@ -87,7 +88,6 @@ decode_t *decoder_new(const char *payload_str, const char *format, int ptime, co return NULL; decode_t *deco = g_new0(decode_t, 1); deco->dec = dec; - deco->mixer_idx = (unsigned int) -1; return deco; } @@ -112,20 +112,20 @@ static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *sp, void *dp) pthread_mutex_lock(&metafile->mix_lock); if (metafile->mix_out) { dbg("adding packet from stream #%lu to mix output", stream->id); - if (G_UNLIKELY(deco->mixer_idx == (unsigned int) -1)) - deco->mixer_idx = mix_get_index(metafile->mix, ssrc, stream->media_sdp_id, stream->channel_slot); + if (G_UNLIKELY(deco->mix_sink.mixer_idx == (unsigned int) -1)) + deco->mix_sink.mixer_idx = mix_get_index(metafile->mix, ssrc, stream->media_sdp_id, stream->channel_slot); format_t actual_format; if (output_config(metafile->mix_out, &dec->dest_format, &actual_format)) goto no_mix_out; mix_config(metafile->mix, &actual_format); // XXX might be a second resampling to same format AVFrame *copy_frame = av_frame_clone(frame); - AVFrame *dec_frame = resample_frame(&deco->mix_resampler, copy_frame, &actual_format); + AVFrame *dec_frame = resample_frame(&deco->mix_sink.resampler, copy_frame, &actual_format); if (!dec_frame) { pthread_mutex_unlock(&metafile->mix_lock); goto err; } - if (mix_add(metafile->mix, dec_frame, deco->mixer_idx, ssrc, metafile->mix_out)) + if (mix_add(metafile->mix, dec_frame, deco->mix_sink.mixer_idx, ssrc, metafile->mix_out)) ilog(LOG_ERR, "Failed to add decoded packet to mixed output"); if (dec_frame != copy_frame) av_frame_free(©_frame); @@ -204,6 +204,6 @@ void decoder_free(decode_t *deco) { if (!deco) return; decoder_close(deco->dec); - resample_shutdown(&deco->mix_resampler); + sink_close(&deco->mix_sink); g_free(deco); } diff --git a/recording-daemon/output.c b/recording-daemon/output.c index c686a7e72..e4f12d10b 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -123,6 +123,7 @@ static void create_parent_dirs(char *dir) { void sink_init(sink_t *sink) { *sink = (__typeof(*sink)) { + .mixer_idx = -1u, }; } @@ -559,7 +560,7 @@ static bool output_shutdown(output_t *output, FILE **fp, GString **gs) { } -static void sink_close(sink_t *sink) { +void sink_close(sink_t *sink) { resample_shutdown(&sink->resampler); } diff --git a/recording-daemon/output.h b/recording-daemon/output.h index ff25126a2..44c376e4c 100644 --- a/recording-daemon/output.h +++ b/recording-daemon/output.h @@ -17,6 +17,7 @@ int output_config(output_t *output, const format_t *requested_format, format_t * void sink_init(sink_t *); +void sink_close(sink_t *sink); bool sink_add(sink_t *, AVFrame *frame, const format_t *requested_format); diff --git a/recording-daemon/packet.c b/recording-daemon/packet.c index e2fa5a096..58763b459 100644 --- a/recording-daemon/packet.c +++ b/recording-daemon/packet.c @@ -120,6 +120,8 @@ static void packet_decode(ssrc_t *ssrc, packet_t *packet) { else if (ssrc->output) dec_format = ssrc->output->requested_format; ssrc->decoders[payload_type] = decoder_new(payload_str, format, ptime, &dec_format); + sink_init(&ssrc->decoders[payload_type]->mix_sink); + ssrc->decoders[payload_type]->mix_sink.ssrc = ssrc; pthread_mutex_unlock(&mf->mix_lock); if (!ssrc->decoders[payload_type]) { ilog(LOG_WARN, "Cannot decode RTP payload type %u (%s)", diff --git a/recording-daemon/types.h b/recording-daemon/types.h index e50391893..8c0b9117c 100644 --- a/recording-daemon/types.h +++ b/recording-daemon/types.h @@ -51,9 +51,14 @@ struct sink_s { union { output_t *output; + ssrc_t *ssrc; }; resample_t resampler; + + union { + unsigned int mixer_idx; + }; }; @@ -197,8 +202,7 @@ struct output_s { struct decode_s { decoder_t *dec; - resample_t mix_resampler; - unsigned int mixer_idx; + sink_t mix_sink; };