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;