diff --git a/daemon/codec.c b/daemon/codec.c index 884500f23..e6d7c6b3f 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -178,6 +178,10 @@ static void __make_transcoder(struct codec_handler *handler, struct rtp_payload_ assert(dest->codec_def != NULL); assert(handler->source_pt.payload_type == handler->source_pt.payload_type); + // if we're just repacketising: + if (dtmf_payload_type == -1 && dest->codec_def && dest->codec_def->dtmf) + dtmf_payload_type = dest->payload_type; + // don't reset handler if it already matches what we want if (!handler->transcoder) goto reset; diff --git a/lib/codeclib.c b/lib/codeclib.c index 86fc1130c..ebd79ebcb 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -57,9 +57,6 @@ static int amr_decoder_input(decoder_t *dec, const str *data, GQueue *out); static const char *dtmf_decoder_init(decoder_t *, const str *); static int dtmf_decoder_input(decoder_t *dec, const str *data, GQueue *out); -static const char *dtmf_encoder_init(encoder_t *enc, const str *); -static int dtmf_encoder_input(encoder_t *enc, AVFrame **frame); -static void dtmf_encoder_close(encoder_t *enc); @@ -85,9 +82,6 @@ static const codec_type_t codec_type_amr = { static const codec_type_t codec_type_dtmf = { .decoder_init = dtmf_decoder_init, .decoder_input = dtmf_decoder_input, - .encoder_init = dtmf_encoder_init, - .encoder_input = dtmf_encoder_input, - .encoder_close = dtmf_encoder_close, }; #ifdef HAVE_BCG729 @@ -1043,7 +1037,7 @@ int encoder_config_fmtp(encoder_t *enc, const codec_def_t *def, int bitrate, int enc->ptime = ptime / def->clockrate_mult; enc->bitrate = bitrate; - err = def->codec_type->encoder_init(enc, fmtp); + err = def->codec_type->encoder_init ? def->codec_type->encoder_init(enc, fmtp) : 0; if (err) goto err; @@ -1051,19 +1045,24 @@ int encoder_config_fmtp(encoder_t *enc, const codec_def_t *def, int bitrate, int // output frame and fifo enc->frame = av_frame_alloc(); - enc->frame->nb_samples = enc->samples_per_frame ? : 256; - enc->frame->format = enc->actual_format.format; - enc->frame->sample_rate = enc->actual_format.clockrate; - enc->frame->channel_layout = av_get_default_channel_layout(enc->actual_format.channels); - //if (!enc->frame->channel_layout) - //enc->frame->channel_layout = av_get_default_channel_layout(enc->u.avc.avcctx->channels); - if (av_frame_get_buffer(enc->frame, 0) < 0) - abort(); - enc->fifo = av_audio_fifo_alloc(enc->frame->format, enc->actual_format.channels, - enc->frame->nb_samples); + if (enc->actual_format.format != -1 && enc->actual_format.clockrate > 0) { + enc->frame->nb_samples = enc->samples_per_frame ? : 256; + enc->frame->format = enc->actual_format.format; + enc->frame->sample_rate = enc->actual_format.clockrate; + enc->frame->channel_layout = av_get_default_channel_layout(enc->actual_format.channels); + //if (!enc->frame->channel_layout) + //enc->frame->channel_layout = av_get_default_channel_layout(enc->u.avc.avcctx->channels); + if (av_frame_get_buffer(enc->frame, 0) < 0) + abort(); + + enc->fifo = av_audio_fifo_alloc(enc->frame->format, enc->actual_format.channels, + enc->frame->nb_samples); - ilog(LOG_DEBUG, "Initialized encoder with frame size %u samples", enc->frame->nb_samples); + ilog(LOG_DEBUG, "Initialized encoder with frame size %u samples", enc->frame->nb_samples); + } + else + ilog(LOG_DEBUG, "Initialized encoder without frame buffer"); done: @@ -1185,6 +1184,9 @@ int encoder_input_data(encoder_t *enc, AVFrame *frame, enc->avpkt.size = 0; while (1) { + if (!enc->def->codec_type->encoder_input) + break; + int ret = enc->def->codec_type->encoder_input(enc, &frame); if (ret < 0) return -1; @@ -1791,14 +1793,3 @@ static int dtmf_decoder_input(decoder_t *dec, const str *data, GQueue *out) { return 0; } - -static const char *dtmf_encoder_init(encoder_t *enc, const str *fmtp) { - return NULL; -} - -static int dtmf_encoder_input(encoder_t *enc, AVFrame **frame) { - return 0; -} - -static void dtmf_encoder_close(encoder_t *enc) { -} diff --git a/t/auto-daemon-tests.pl b/t/auto-daemon-tests.pl index dd12e10a2..8c15af69b 100755 --- a/t/auto-daemon-tests.pl +++ b/t/auto-daemon-tests.pl @@ -3519,6 +3519,44 @@ rcv($sock_b, $port_a, rtpm(8, 1007, 3000+160*5, $ssrc, "\x2a" x 160)); +new_call; + +offer('DTMF repacketising', + { ICE => 'remove', replace => ['origin', 'session-connection'], + flags => ['strict-source'], + ptime => 20, 'ptime-reverse' => 60, 'rtcp-mux' => ['demux'], + }, <