From dd75c761cc82bd2dffdcbd73466f80ed5e1a112b Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 23 Feb 2023 14:10:28 -0500 Subject: [PATCH] MT#56471 tie in play_media with audio_player Engage or disengage the audio_player as requested. Change-Id: Ibbc3d122e908c013ad2285c2253f13ae9790a852 --- daemon/call_interfaces.c | 15 +++++++++++++++ daemon/codec.c | 10 +++++++++- include/call.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 9a6b2522b..ce7d4ff11 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -3139,13 +3139,23 @@ const char *call_play_media_ng(bencode_item_t *input, bencode_item_t *output) { if (err) return err; + flags.opmode = OP_PLAY_MEDIA; + for (GList *l = monologues.head; l; l = l->next) { struct call_monologue *monologue = l->data; + // if mixing is enabled, codec handlers of all sources must be updated + codec_update_all_source_handlers(monologue, &flags); + // this starts the audio player if needed + update_init_subscribers(monologue, OP_PLAY_MEDIA); + // media_player_new() now knows that audio player is in use + + // TODO: player options can have changed if already exists if (!monologue->player) monologue->player = media_player_new(monologue); if (flags.repeat_times <= 0) flags.repeat_times = 1; + if (flags.file.len) { if (media_player_play_file(monologue->player, &flags.file, flags.repeat_times, flags.start_pos)) return "Failed to start media playback from file"; @@ -3163,6 +3173,7 @@ const char *call_play_media_ng(bencode_item_t *input, bencode_item_t *output) { if (l == monologues.head && monologue->player->coder.duration) bencode_dictionary_add_integer(output, "duration", monologue->player->coder.duration); + } return NULL; @@ -3190,6 +3201,10 @@ const char *call_stop_media_ng(bencode_item_t *input, bencode_item_t *output) { return "Not currently playing media"; last_frame_pos = media_player_stop(monologue->player); + + // restore to non-mixing if needed + codec_update_all_source_handlers(monologue, NULL); + update_init_subscribers(monologue, OP_OTHER); } bencode_dictionary_add_integer(output, "last-frame-pos", last_frame_pos); diff --git a/daemon/codec.c b/daemon/codec.c index 947390520..f040c4785 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -1063,6 +1063,7 @@ bool codec_handlers_update(struct call_media *receiver, struct call_media *sink, // default choice of audio player usage is based on whether it was in use previously, // overridden by signalling flags, overridden by global option bool use_audio_player = !!MEDIA_ISSET(sink, AUDIO_PLAYER); + bool implicit_audio_player = false; if (flags && flags->audio_player == AP_FORCE) use_audio_player = true; @@ -1070,6 +1071,13 @@ bool codec_handlers_update(struct call_media *receiver, struct call_media *sink, use_audio_player = false; else if (rtpe_config.use_audio_player == UAP_ALWAYS) use_audio_player = true; + else if (rtpe_config.use_audio_player == UAP_PLAY_MEDIA) { + // check for implicitly enabled player + if ((flags && flags->opmode == OP_PLAY_MEDIA) || (media_player_is_active(sink->monologue))) { + use_audio_player = true; + implicit_audio_player = true; + } + } // first gather info about what we can send AUTO_CLEANUP_NULL(GHashTable *supplemental_sinks, __g_hash_table_destroy); @@ -1377,7 +1385,7 @@ next: MEDIA_CLEAR(sink, AUDIO_PLAYER); audio_player_stop(sink); } - else + else if (!implicit_audio_player) MEDIA_SET(sink, AUDIO_PLAYER); if (is_transcoding) { diff --git a/include/call.h b/include/call.h index 65cdf3d24..3e02c3f12 100644 --- a/include/call.h +++ b/include/call.h @@ -60,6 +60,7 @@ enum call_opmode { OP_REQUEST, OP_REQ_ANSWER, OP_PUBLISH, + OP_PLAY_MEDIA, OP_OTHER, };