From 7da2b523a7426a54d9af62dace4413c92606da47 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 5 Mar 2019 09:03:20 -0500 Subject: [PATCH] TT#50652 return media duration to SIP proxy in play_media response Change-Id: Ib09519f960b37ca41a554aa2779f71c91ef9b49d --- daemon/call_interfaces.c | 3 +++ daemon/media_player.c | 5 +++++ include/media_player.h | 1 + 3 files changed, 9 insertions(+) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 6fdeecdb8..d917b039e 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -1778,6 +1778,9 @@ const char *call_play_media_ng(bencode_item_t *input, bencode_item_t *output) { else goto out; + if (monologue->player->duration) + bencode_dictionary_add_integer(output, "duration", monologue->player->duration); + err = NULL; out: diff --git a/daemon/media_player.c b/daemon/media_player.c index a4a4312cb..f7427e504 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -220,6 +220,8 @@ found: if (!mp->ssrc_out) return -1; + mp->duration = avs->duration * 1000 * avs->time_base.num / avs->time_base.den; + return 0; } @@ -334,6 +336,9 @@ found: // call->master_lock held in W static void media_player_play_start(struct media_player *mp) { + // needed to have usable duration for some formats. ignore errors. + avformat_find_stream_info(mp->fmtctx, NULL); + mp->next_run = rtpe_now; // give ourselves a bit of a head start with decoding timeval_add_usec(&mp->next_run, -50000); diff --git a/include/media_player.h b/include/media_player.h index d08bceaf2..8546447e7 100644 --- a/include/media_player.h +++ b/include/media_player.h @@ -33,6 +33,7 @@ struct media_player { struct timeval next_run; AVFormatContext *fmtctx; + unsigned long duration; // in milliseconds AVPacket pkt; struct codec_handler *handler; struct ssrc_ctx *ssrc_out;