From 9d3bb5bffc81aef27e69a7f6fdd3cea6c57b3831 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 13 Feb 2019 15:40:12 -0500 Subject: [PATCH] TT#52651 extract/move unrelated old legacy decoder struct members Change-Id: Iffd79b43180c30a9e128a460f7ba85ba49dedeaf --- daemon/codec.c | 4 ++-- lib/codeclib.c | 7 +++---- lib/codeclib.h | 8 +++----- recording-daemon/decoder.c | 31 ++++++++++++++++++++++--------- recording-daemon/decoder.h | 5 +++-- recording-daemon/packet.c | 2 +- recording-daemon/types.h | 11 ++++++++++- t/amr-decode-test.c | 4 ++-- 8 files changed, 46 insertions(+), 26 deletions(-) diff --git a/daemon/codec.c b/daemon/codec.c index 09fcd36bb..06caed979 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -975,7 +975,7 @@ static int __packet_encoded(encoder_t *enc, void *u1, void *u2) { return 0; } -static int __packet_decoded(decoder_t *decoder, AVFrame *frame, void *u1, void *u2) { +static int __packet_decoded(decoder_t *decoder, AVFrame *frame, void *u1, void *u2, void *u3) { struct codec_ssrc_handler *ch = u1; ilog(LOG_DEBUG, "RTP media successfully decoded: TS %llu, samples %u", @@ -989,7 +989,7 @@ static int __packet_decoded(decoder_t *decoder, AVFrame *frame, void *u1, void * static int packet_decode(struct codec_ssrc_handler *ch, struct transcode_packet *packet, struct media_packet *mp) { - return decoder_input_data(ch->decoder, packet->payload, packet->ts, __packet_decoded, ch, mp); + return decoder_input_data(ch->decoder, packet->payload, packet->ts, __packet_decoded, ch, mp, NULL); } static int handler_func_transcode(struct codec_handler *h, struct media_packet *mp) { diff --git a/lib/codeclib.c b/lib/codeclib.c index 35a36c3db..b9c8758f7 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -456,7 +456,6 @@ decoder_t *decoder_new_fmtp(const codec_def_t *def, int clockrate, int channels, ret->pts = (uint64_t) -1LL; ret->rtp_ts = (unsigned long) -1L; - ret->mixer_idx = (unsigned int) -1; return ret; @@ -488,7 +487,6 @@ void decoder_close(decoder_t *dec) { dec->def->codec_type->decoder_close(dec); resample_shutdown(&dec->resampler); - resample_shutdown(&dec->mix_resampler); g_slice_free1(sizeof(*dec), dec); } @@ -593,7 +591,8 @@ err: } int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts, - int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2) + int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2, void *u3), + void *u1, void *u2, void *u3) { GQueue frames = G_QUEUE_INIT; @@ -635,7 +634,7 @@ int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts, ret = -1; } else { - if (callback(dec, rsmp_frame, u1, u2)) + if (callback(dec, rsmp_frame, u1, u2, u3)) ret = -1; } av_frame_free(&frame); diff --git a/lib/codeclib.h b/lib/codeclib.h index 1261c29e8..eba039414 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -131,8 +131,7 @@ struct decoder_s { format_t in_format, out_format; - resample_t resampler, - mix_resampler; // XXX move this out of here - specific to recording-daemon + resample_t resampler; union { struct { @@ -146,8 +145,6 @@ struct decoder_s { unsigned long rtp_ts; uint64_t pts; - - unsigned int mixer_idx; }; struct encoder_s { @@ -202,7 +199,8 @@ decoder_t *decoder_new_fmtp(const codec_def_t *def, int clockrate, int channels, const str *fmtp); void decoder_close(decoder_t *dec); int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts, - int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2); + int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2, void *u3), + void *u1, void *u2, void *u3); encoder_t *encoder_new(); diff --git a/recording-daemon/decoder.c b/recording-daemon/decoder.c index 603683fef..668288231 100644 --- a/recording-daemon/decoder.c +++ b/recording-daemon/decoder.c @@ -21,7 +21,7 @@ int resample_audio; -decoder_t *decoder_new(const char *payload_str, output_t *outp) { +decode_t *decoder_new(const char *payload_str, output_t *outp) { str name; char *slash = strchr(payload_str, '/'); if (!slash) { @@ -69,13 +69,20 @@ decoder_t *decoder_new(const char *payload_str, output_t *outp) { outp->encoder->requested_format.format = out_format.format; } - return decoder_new_fmt(def, clockrate, channels, &out_format); + decoder_t *dec = decoder_new_fmt(def, clockrate, channels, &out_format); + if (!dec) + return NULL; + decode_t *deco = g_slice_alloc0(sizeof(decode_t)); + deco->dec = dec; + deco->mixer_idx = (unsigned int) -1; + return deco; } -static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *op, void *mp) { +static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *op, void *mp, void *dp) { metafile_t *metafile = mp; output_t *output = op; + decode_t *deco = dp; dbg("got frame pts %llu samples %u contents %02x%02x%02x%02x...", (unsigned long long) frame->pts, frame->nb_samples, (unsigned int) frame->extended_data[0][0], @@ -86,19 +93,19 @@ static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *op, void *mp) // handle mix output pthread_mutex_lock(&metafile->mix_lock); if (metafile->mix_out) { - if (G_UNLIKELY(dec->mixer_idx == (unsigned int) -1)) - dec->mixer_idx = mix_get_index(metafile->mix); + if (G_UNLIKELY(deco->mixer_idx == (unsigned int) -1)) + deco->mixer_idx = mix_get_index(metafile->mix); format_t actual_format; if (output_config(metafile->mix_out, &dec->out_format, &actual_format)) goto no_mix_out; mix_config(metafile->mix, &actual_format); // XXX might be a second resampling to same format - AVFrame *dec_frame = resample_frame(&dec->mix_resampler, frame, &actual_format); + AVFrame *dec_frame = resample_frame(&deco->mix_resampler, frame, &actual_format); if (!dec_frame) { pthread_mutex_unlock(&metafile->mix_lock); goto err; } - if (mix_add(metafile->mix, dec_frame, dec->mixer_idx, metafile->mix_out)) + if (mix_add(metafile->mix, dec_frame, deco->mixer_idx, metafile->mix_out)) ilog(LOG_ERR, "Failed to add decoded packet to mixed output"); } no_mix_out: @@ -120,6 +127,12 @@ err: } -int decoder_input(decoder_t *dec, const str *data, unsigned long ts, output_t *output, metafile_t *metafile) { - return decoder_input_data(dec, data, ts, decoder_got_frame, output, metafile); +int decoder_input(decode_t *deco, const str *data, unsigned long ts, output_t *output, metafile_t *metafile) { + return decoder_input_data(deco->dec, data, ts, decoder_got_frame, output, metafile, deco); +} + +void decoder_free(decode_t *deco) { + decoder_close(deco->dec); + resample_shutdown(&deco->mix_resampler); + g_slice_free1(sizeof(*deco), deco); } diff --git a/recording-daemon/decoder.h b/recording-daemon/decoder.h index 7f2ba6da4..e7b7a2a88 100644 --- a/recording-daemon/decoder.h +++ b/recording-daemon/decoder.h @@ -8,8 +8,9 @@ extern int resample_audio; -decoder_t *decoder_new(const char *payload_str, output_t *); -int decoder_input(decoder_t *, const str *, unsigned long ts, output_t *, metafile_t *); +decode_t *decoder_new(const char *payload_str, output_t *); +int decoder_input(decode_t *, const str *, unsigned long ts, output_t *, metafile_t *); +void decoder_free(decode_t *); #endif diff --git a/recording-daemon/packet.c b/recording-daemon/packet.c index 301ea3323..5af094605 100644 --- a/recording-daemon/packet.c +++ b/recording-daemon/packet.c @@ -29,7 +29,7 @@ void ssrc_free(void *p) { packet_sequencer_destroy(&s->sequencer); output_close(s->output); for (int i = 0; i < G_N_ELEMENTS(s->decoders); i++) - decoder_close(s->decoders[i]); + decoder_free(s->decoders[i]); g_slice_free1(sizeof(*s), s); } diff --git a/recording-daemon/types.h b/recording-daemon/types.h index 5215e5444..403609acd 100644 --- a/recording-daemon/types.h +++ b/recording-daemon/types.h @@ -28,6 +28,8 @@ struct output_s; typedef struct output_s output_t; struct mix_s; typedef struct mix_s mix_t; +struct decode_s; +typedef struct decode_s decode_t; typedef void handler_func(handler_t *); @@ -71,7 +73,7 @@ struct ssrc_s { metafile_t *metafile; unsigned long ssrc; packet_sequencer_t sequencer; - decoder_t *decoders[128]; + decode_t *decoders[128]; output_t *output; }; typedef struct ssrc_s ssrc_t; @@ -135,5 +137,12 @@ struct output_s { }; +struct decode_s { + decoder_t *dec; + resample_t mix_resampler; + unsigned int mixer_idx; +}; + + #endif diff --git a/t/amr-decode-test.c b/t/amr-decode-test.c index 315601be6..13851ef02 100644 --- a/t/amr-decode-test.c +++ b/t/amr-decode-test.c @@ -8,7 +8,7 @@ static void hexdump(const unsigned char *buf, int len) { printf("\n"); } -static int frame_cb(decoder_t *dec, AVFrame *frame, void *u1, void *u2) { +static int frame_cb(decoder_t *dec, AVFrame *frame, void *u1, void *u2, void *u3) { char **expect = u1; int *expect_len = u2; assert(expect); @@ -54,7 +54,7 @@ static void do_test_amr_xx(const char *file, int line, decoder_t *d = decoder_new_fmtp(def, clockrate, 1, &fmt, fmtp); assert(d); const str data = { data_s, data_len }; - int ret = decoder_input_data(d, &data, 1, frame_cb, &expect_s, &expect_len); + int ret = decoder_input_data(d, &data, 1, frame_cb, &expect_s, &expect_len, NULL); assert(!ret); assert(expect_s == NULL); decoder_close(d);