diff --git a/daemon/codec.c b/daemon/codec.c index f6496be3a..1707b5e6b 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -4381,6 +4381,7 @@ static void async_chain_finish(AVPacket *pkt, void *async_cb_obj) { } static bool __ssrc_handler_decode_common(struct codec_ssrc_handler *ch, struct codec_handler *h, + const format_t *dec_format, const format_t *enc_format) { if (h->pcm_dtmf_detect) { @@ -4393,7 +4394,7 @@ static bool __ssrc_handler_decode_common(struct codec_ssrc_handler *ch, struct c dtmf_rx_set_realtime_callback(ch->dtmf_dsp, __dtmf_dsp_callback, ch); } - ch->decoder = decoder_new_fmtp(h->source_pt.codec_def, h->source_pt.clock_rate, h->source_pt.channels, + ch->decoder = decoder_new_fmtp(h->source_pt.codec_def, dec_format, h->source_pt.ptime, enc_format, &h->source_pt.format, &h->source_pt.format_parameters, &h->source_pt.codec_opts); @@ -4480,7 +4481,7 @@ static struct ssrc_entry *__ssrc_handler_transcode_new(void *p) { &h->dest_pt.codec_opts)) goto err; - if (!__ssrc_handler_decode_common(ch, h, &ch->encoder_format)) + if (!__ssrc_handler_decode_common(ch, h, &dec_format, &ch->encoder_format)) goto err; ch->bytes_per_packet = (ch->encoder->samples_per_packet ?: ch->encoder->samples_per_frame) @@ -4515,7 +4516,13 @@ static struct ssrc_entry *__ssrc_handler_decode_new(void *p) { .format = AV_SAMPLE_FMT_S16, }; - if (!__ssrc_handler_decode_common(ch, h, &dest_format)) + format_t dec_format = { + .clockrate = h->source_pt.clock_rate, + .channels = h->source_pt.channels, + .format = -1, + }; + + if (!__ssrc_handler_decode_common(ch, h, &dec_format, &dest_format)) goto err; return &ch->h; diff --git a/lib/codeclib.c b/lib/codeclib.c index 21d25d0d0..6c7481bc9 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -75,7 +75,12 @@ codec_def_t *codec_get_pcm16(void) { decoder_t *decoder_new_fmt(codec_def_t *def, int clockrate, int channels, int ptime, const format_t *resample_fmt) { - return decoder_new_fmtp(def, clockrate, channels, ptime, resample_fmt, NULL, NULL, NULL); + return decoder_new_fmtp(def, + &(format_t) { + .clockrate = clockrate, + .channels = channels, + }, + ptime, resample_fmt, NULL, NULL, NULL); } bool codec_parse_fmtp(codec_def_t *def, struct rtp_codec_format *fmtp, const str *fmtp_string, @@ -110,7 +115,7 @@ bool codec_parse_fmtp(codec_def_t *def, struct rtp_codec_format *fmtp, const str return ret; } -decoder_t *decoder_new_fmtp(codec_def_t *def, int clockrate, int channels, int ptime, +decoder_t *decoder_new_fmtp(codec_def_t *def, const format_t *src_fmt, int ptime, const format_t *resample_fmt, struct rtp_codec_format *fmtp, const str *fmtp_string, const str *extra_opts) @@ -126,9 +131,9 @@ decoder_t *decoder_new_fmtp(codec_def_t *def, int clockrate, int channels, int p ret->def = def; ret->clockrate_fact = def->default_clockrate_fact; - format_init(&ret->in_format); - ret->in_format.channels = channels; - ret->in_format.clockrate = clockrate; + + ret->in_format = *src_fmt; + ret->in_format.format = -1; // output defaults to same as input ret->dest_format = ret->in_format; diff --git a/lib/codeclib.h b/lib/codeclib.h index 2b1977e6c..66f753ec9 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -413,7 +413,7 @@ bool codec_parse_fmtp(codec_def_t *def, struct rtp_codec_format *fmtp, const str decoder_t *decoder_new_fmt(codec_def_t *def, int clockrate, int channels, int ptime, const format_t *resample_fmt); -decoder_t *decoder_new_fmtp(codec_def_t *def, int clockrate, int channels, int ptime, +decoder_t *decoder_new_fmtp(codec_def_t *def, const format_t *src_fmt, int ptime, const format_t *resample_fmt, struct rtp_codec_format *fmtp, const str *fmtp_string, const str *codec_opts); void decoder_close(decoder_t *dec); diff --git a/perf-tester/main.c b/perf-tester/main.c index 1d64be1b7..b68e7bbe1 100644 --- a/perf-tester/main.c +++ b/perf-tester/main.c @@ -523,7 +523,7 @@ static void new_stream_params( NULL, NULL, NULL); assert(res == 0); // TODO: handle failures gracefully - s->decoder = decoder_new_fmtp(in_def, dec_format.clockrate, dec_format.channels, 20, + s->decoder = decoder_new_fmtp(in_def, &dec_format, 20, &actual_enc_format, NULL, NULL, NULL); // TODO: support different options (fmtp etc) assert(s->decoder != NULL); // TODO: handle failures gracefully } diff --git a/recording-daemon/decoder.c b/recording-daemon/decoder.c index 54447f0ac..509caae34 100644 --- a/recording-daemon/decoder.c +++ b/recording-daemon/decoder.c @@ -66,10 +66,15 @@ decode_t *decoder_new(const char *payload_str, const char *format, int ptime) { .channels = channels, .format = AV_SAMPLE_FMT_S16, }; + format_t dec_format = (format_t) { + .clockrate = rtp_clockrate, + .channels = channels, + .format = -1, + }; str fmtp = STR(format); - decoder_t *dec = decoder_new_fmtp(def, rtp_clockrate, channels, ptime, &out_format, NULL, &fmtp, NULL); + decoder_t *dec = decoder_new_fmtp(def, &dec_format, ptime, &out_format, NULL, &fmtp, NULL); if (!dec) return NULL; decode_t *deco = g_new0(decode_t, 1); diff --git a/t/test-amr-decode.c b/t/test-amr-decode.c index 6a2a7fbbb..aea904c39 100644 --- a/t/test-amr-decode.c +++ b/t/test-amr-decode.c @@ -64,7 +64,7 @@ static void do_test_amr_xx(const char *file, int line, str fmtp = STR_NULL; if (fmtp_s) fmtp = STR(fmtp_s); - decoder_t *d = decoder_new_fmtp(def, clockrate, 1, 0, &fmt, NULL, NULL, &fmtp); + decoder_t *d = decoder_new_fmtp(def, &fmt, 0, &fmt, NULL, NULL, &fmtp); assert(d); const str data = STR_LEN(data_s, data_len); int ret = decoder_input_data(d, &data, 1, false, frame_cb, &args, NULL);