diff --git a/daemon/codec.c b/daemon/codec.c index 9a376cbf5..f6496be3a 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -4854,7 +4854,11 @@ static tc_code __rtp_decode_direct(struct codec_ssrc_handler *ch, struct codec_s } } else { - int ret = decoder_input_data_ptime(ch->decoder, packet->payload, packet->ts, &mp->ptime, + int ret = decoder_input_data_ptime(ch->decoder, + packet->payload, + packet->ts, + &mp->ptime, + packet->marker, ch->handler->packet_decoded, ch, mp); code = ret == 0 ? TCC_OK : TCC_ERR; @@ -5130,6 +5134,7 @@ static int handler_func_transcode(struct codec_handler *h, struct media_packet * static int handler_func_playback(struct codec_handler *h, struct media_packet *mp) { decoder_input_data(h->ssrc_handler->decoder, &mp->payload, mp->rtp->timestamp, + !!(mp->rtp->m_pt & 0x80), h->packet_decoded, h->ssrc_handler, mp); return 0; } @@ -5142,6 +5147,7 @@ static int handler_func_inject_dtmf(struct codec_handler *h, struct media_packet if (!ch) return 0; decoder_input_data(ch->decoder, &mp->payload, mp->rtp->timestamp, + false, // XXX move marker handling here? h->packet_decoded, ch, mp); ssrc_entry_release(ch); return 0; diff --git a/lib/amr.c b/lib/amr.c index f8144c564..b5d1c7e61 100644 --- a/lib/amr.c +++ b/lib/amr.c @@ -301,7 +301,7 @@ static void amr_bitrate_tracker(decoder_t *dec, unsigned int ft) { dec->avc.amr.bitrate_tracker[ft]++; } -static int amr_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +static int amr_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { const char *err = NULL; g_auto(GQueue) toc = G_QUEUE_INIT; @@ -426,7 +426,7 @@ static int amr_decoder_input(decoder_t *dec, const str *data, frame_q *out) { if (bits == 40) { // SID if (dec->dtx.method_id == DTX_NATIVE) { - if (avc_decoder_input(dec, &frame, out)) + if (avc_decoder_input(dec, &frame, out, mark)) goto err; } else { @@ -436,7 +436,7 @@ static int amr_decoder_input(decoder_t *dec, const str *data, frame_q *out) { } } else { - if (avc_decoder_input(dec, &frame, out)) + if (avc_decoder_input(dec, &frame, out, mark)) goto err; } @@ -625,7 +625,7 @@ static int amr_dtx(decoder_t *dec, frame_q *out, int ptime) { unsigned char frame_buf[1]; frame_buf[0] = 0xf << 3; // no data str frame = STR_CONST_BUF(frame_buf); - if (avc_decoder_input(dec, &frame, out)) + if (avc_decoder_input(dec, &frame, out, false)) ilog(LOG_WARN | LOG_FLAG_LIMIT, "Error while writing 'no data' frame to AMR decoder"); return 0; } diff --git a/lib/avc.c b/lib/avc.c index 204aab4c5..bdc4a2bc6 100644 --- a/lib/avc.c +++ b/lib/avc.c @@ -68,7 +68,7 @@ void avc_decoder_close(decoder_t *dec) { } -int avc_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +int avc_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { if (!dec->avc.avpkt) return -1; // decoder shut down diff --git a/lib/codeclib.c b/lib/codeclib.c index 076455ad7..21d25d0d0 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -229,6 +229,7 @@ void decoder_close(decoder_t *dec) { static int __decoder_input_data(decoder_t *dec, const str *data, unsigned long ts, int *ptime, + bool mark, int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2) { frame_q frames = TYPED_GQUEUE_INIT; @@ -263,7 +264,7 @@ static int __decoder_input_data(decoder_t *dec, const str *data, unsigned long t dec->rtp_ts = ts; if (data) - dec->def->codec_type->decoder_input(dec, data, &frames); + dec->def->codec_type->decoder_input(dec, data, &frames, mark); else dec->dtx.do_dtx(dec, &frames, *ptime); @@ -292,23 +293,25 @@ static int __decoder_input_data(decoder_t *dec, const str *data, unsigned long t return ret; } int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts, + bool mark, int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2) { if (!data || !data->s || !data->len) return 0; - return __decoder_input_data(dec, data, ts, NULL, callback, u1, u2); + return __decoder_input_data(dec, data, ts, NULL, mark, callback, u1, u2); } int decoder_input_data_ptime(decoder_t *dec, const str *data, unsigned long ts, int *ptime, + bool mark, int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2) { if (!data || !data->s || !data->len) return 0; - return __decoder_input_data(dec, data, ts, ptime, callback, u1, u2); + return __decoder_input_data(dec, data, ts, ptime, mark, callback, u1, u2); } int decoder_dtx(decoder_t *dec, unsigned long ts, int ptime, int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2) { - return __decoder_input_data(dec, NULL, ts, &ptime, callback, u1, u2); + return __decoder_input_data(dec, NULL, ts, &ptime, false, callback, u1, u2); } @@ -948,7 +951,8 @@ static int cn_append_frame(decoder_t *dec, AVFrame *f, void *u1, void *u2) { static int generic_cn_dtx(decoder_t *dec, frame_q *out, int ptime) { dec->dtx.cn.cn_dec->ptime = ptime; return decoder_input_data(dec->dtx.cn.cn_dec, dec->dtx.cn.cn_payload, - dec->rtp_ts, cn_append_frame, out, NULL); + dec->rtp_ts, false, + cn_append_frame, out, NULL); } static int generic_cn_dtx_init(decoder_t *dec) { diff --git a/lib/codeclib.h b/lib/codeclib.h index 3f3f06014..2b1977e6c 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -123,7 +123,7 @@ struct codec_type_s { void (*def_init)(struct codec_def_s *); const char *(*decoder_init)(decoder_t *, const str *); - int (*decoder_input)(decoder_t *, const str *data, frame_q *); + int (*decoder_input)(decoder_t *, const str *data, frame_q *, bool); void (*decoder_close)(decoder_t *); const char *(*encoder_init)(encoder_t *, const str *); @@ -418,8 +418,10 @@ decoder_t *decoder_new_fmtp(codec_def_t *def, int clockrate, int channels, int p struct rtp_codec_format *fmtp, const str *fmtp_string, const str *codec_opts); void decoder_close(decoder_t *dec); int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts, + bool mark, int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2); int decoder_input_data_ptime(decoder_t *dec, const str *data, unsigned long ts, int *ptime, + bool mark, int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2); gboolean decoder_has_dtx(decoder_t *); int decoder_switch_dtx(decoder_t *dec, enum dtx_method); diff --git a/lib/codecmod.h b/lib/codecmod.h index 031a3c541..80bd7466d 100644 --- a/lib/codecmod.h +++ b/lib/codecmod.h @@ -20,7 +20,7 @@ void avc_cleanup(void); void avc_def_init(struct codec_def_s *); const char *avc_decoder_init(decoder_t *, const str *); -int avc_decoder_input(decoder_t *dec, const str *data, frame_q *out); +int avc_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool); void avc_decoder_close(decoder_t *); const char *avc_encoder_init(encoder_t *enc, const str *); int avc_encoder_input(encoder_t *enc, AVFrame **frame); diff --git a/lib/evs.c b/lib/evs.c index e70d4bafb..cae51730c 100644 --- a/lib/evs.c +++ b/lib/evs.c @@ -291,7 +291,7 @@ static const int evs_mode_bits[2][16] = { }; -static int evs_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +static int evs_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { str input = *data; const char *err = NULL; diff --git a/lib/g729.c b/lib/g729.c index 4522a4952..ff37f04fa 100644 --- a/lib/g729.c +++ b/lib/g729.c @@ -48,7 +48,7 @@ static packetizer_f packetizer_g729; // aggregate some frames into packets static void bcg729_def_init(struct codec_def_s *); static const char *bcg729_decoder_init(decoder_t *, const str *); -static int bcg729_decoder_input(decoder_t *dec, const str *data, frame_q *out); +static int bcg729_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool); static void bcg729_decoder_close(decoder_t *); static const char *bcg729_encoder_init(encoder_t *enc, const str *); static int bcg729_encoder_input(encoder_t *enc, AVFrame **frame); @@ -127,7 +127,7 @@ static const char *bcg729_decoder_init(decoder_t *dec, const str *extra_opts) { return NULL; } -static int bcg729_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +static int bcg729_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { str input = *data; uint64_t pts = dec->pts; diff --git a/lib/ilbc.c b/lib/ilbc.c index 515c6b054..6ffede62c 100644 --- a/lib/ilbc.c +++ b/lib/ilbc.c @@ -67,7 +67,7 @@ static void ilbc_set_dec_options(decoder_t *dec, const str *codec_opts) { ilog(LOG_WARN, "Unsupported iLBC mode %i", mode); } -static int ilbc_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +static int ilbc_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { int mode = 0, block_align = 0; static const union codec_format_options mode_20 = { .ilbc = { 20 } }; static const union codec_format_options mode_30 = { .ilbc = { 30 } }; @@ -97,7 +97,7 @@ static int ilbc_decoder_input(decoder_t *dec, const str *data, frame_q *out) { avc_decoder_init(dec, NULL); } - return avc_decoder_input(dec, data, out); + return avc_decoder_input(dec, data, out, mark); } diff --git a/lib/opus.c b/lib/opus.c index cfd479f94..c46575307 100644 --- a/lib/opus.c +++ b/lib/opus.c @@ -80,7 +80,7 @@ static const char *libopus_decoder_init(decoder_t *dec, const str *extra_opts) { static void libopus_decoder_close(decoder_t *dec) { opus_decoder_destroy(dec->opus); } -static int libopus_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +static int libopus_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { // get frame with buffer large enough for the max AVFrame *frame = av_frame_alloc(); frame->nb_samples = 960; diff --git a/lib/pseudo.c b/lib/pseudo.c index 3ac4f3361..bd413a241 100644 --- a/lib/pseudo.c +++ b/lib/pseudo.c @@ -34,7 +34,7 @@ static AVFrame *dtmf_frame_int16_t_mono(unsigned long frame_ts, unsigned long nu } -static int dtmf_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +static int dtmf_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { struct telephone_event_payload *dtmf; if (data->len < sizeof(*dtmf)) { ilog(LOG_WARN | LOG_FLAG_LIMIT, "Short DTMF event packet (len %zu)", data->len); @@ -87,7 +87,7 @@ static const char *cn_decoder_init(decoder_t *dec, const str *opts) { dec->resampler.no_filter = true; return avc_decoder_init(dec, opts); } -static int cn_decoder_input(decoder_t *dec, const str *data, frame_q *out) { +static int cn_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark) { // generate one set of ptime worth of samples int ptime = dec->ptime; if (ptime <= 0) @@ -100,7 +100,7 @@ static int cn_decoder_input(decoder_t *dec, const str *data, frame_q *out) { do { if (samples < max_size) dec->avc.avcctx->frame_size = samples; - int ret = avc_decoder_input(dec, data, out); + int ret = avc_decoder_input(dec, data, out, mark); dec->avc.avcctx->frame_size = max_size; if (ret) diff --git a/perf-tester/main.c b/perf-tester/main.c index 1a596ed34..1d64be1b7 100644 --- a/perf-tester/main.c +++ b/perf-tester/main.c @@ -377,7 +377,7 @@ static void readable(int fd, void *o) { frame = STR_LEN(data->data, data->size); if (!s->chain) - decoder_input_data(s->decoder, &frame, s->input_ts, got_frame, s, NULL); + decoder_input_data(s->decoder, &frame, s->input_ts, false, got_frame, s, NULL); else { AVPacket *pkt = codec_cc_input_data(s->chain, &frame, s->input_ts, s, NULL, NULL); if (pkt) { diff --git a/recording-daemon/decoder.c b/recording-daemon/decoder.c index 1f8f99d85..54447f0ac 100644 --- a/recording-daemon/decoder.c +++ b/recording-daemon/decoder.c @@ -117,7 +117,7 @@ static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *sp, void *dp) int decoder_input(decode_t *deco, const str *data, unsigned long ts, ssrc_t *ssrc) { - return decoder_input_data(deco->dec, data, ts, decoder_got_frame, ssrc, deco); + return decoder_input_data(deco->dec, data, ts, false, decoder_got_frame, ssrc, deco); // XXX support mark } void decoder_free(decode_t *deco) { diff --git a/t/test-amr-decode.c b/t/test-amr-decode.c index 94a71594e..6a2a7fbbb 100644 --- a/t/test-amr-decode.c +++ b/t/test-amr-decode.c @@ -67,7 +67,7 @@ static void do_test_amr_xx(const char *file, int line, decoder_t *d = decoder_new_fmtp(def, clockrate, 1, 0, &fmt, NULL, NULL, &fmtp); assert(d); const str data = STR_LEN(data_s, data_len); - int ret = decoder_input_data(d, &data, 1, frame_cb, &args, NULL); + int ret = decoder_input_data(d, &data, 1, false, frame_cb, &args, NULL); assert(!ret); assert(args.done == true); decoder_close(d);