diff --git a/daemon/call.c b/daemon/call.c index e7702f77d..48c95c7b3 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2871,9 +2871,9 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c .blob = flags->blob, .db_id = flags->db_id, ); - media_player_new(&ml->rec_player, ml, NULL, &opts); + media_player_new(&ml->players[MP_REC], ml, NULL, &opts); - if (!media_player_play(ml->rec_player, &opts)) + if (!media_player_play(ml->players[MP_REC], &opts)) ilog(LOG_WARN, "Failed to add media player for recording announcement"); } #endif @@ -5193,8 +5193,8 @@ static void __call_cleanup(call_t *c) { for (__auto_type l = c->monologues.head; l; l = l->next) { struct call_monologue *ml = l->data; __monologue_stop(ml); - media_player_put(&ml->player); - media_player_put(&ml->rec_player); + media_player_put(&ml->players[MP_DEFAULT]); + media_player_put(&ml->players[MP_REC]); if (ml->tone_freqs) g_array_free(ml->tone_freqs, true); obj_release(ml->janus_session); @@ -6436,8 +6436,8 @@ void call_media_stop(struct call_media *m) { * Stops media player of given monologue. */ static void __monologue_stop(struct call_monologue *ml) { - media_player_stop(ml->player); - media_player_stop(ml->rec_player); + media_player_stop(ml->players[MP_DEFAULT]); + media_player_stop(ml->players[MP_REC]); } /** * Stops media player and all medias of given monologue. diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 13c153807..81e6a6468 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2007,8 +2007,8 @@ const char *call_play_media_ng(ng_command_ctx_t *ctx) { if (err) return err; - if (l == monologues.head && monologue->player->coder.duration) - parser->dict_add_int(ctx->resp, "duration", monologue->player->coder.duration); + if (l == monologues.head && monologue->players[MP_DEFAULT]->coder.duration) + parser->dict_add_int(ctx->resp, "duration", monologue->players[MP_DEFAULT]->coder.duration); } @@ -2035,10 +2035,10 @@ const char *call_stop_media_ng(ng_command_ctx_t *ctx) { for (__auto_type l = monologues.head; l; l = l->next) { struct call_monologue *monologue = l->data; - if (!monologue->player) + if (!monologue->players[MP_DEFAULT]) return "Not currently playing media"; - if (monologue->player->opts.moh) + if (monologue->players[MP_DEFAULT]->opts.moh) return "Currently MoH ongoing, ignore stop media."; last_frame_pos = call_stop_media_for_ml(monologue); diff --git a/daemon/media_player.c b/daemon/media_player.c index 66e970822..dd55dbe28 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -1581,7 +1581,8 @@ static bool call_ml_stops_moh(struct call_monologue *from_ml, struct call_monolo enum ng_opmode opmode) { #ifdef WITH_TRANSCODING - if (opmode == OP_OFFER && !call_ml_sendonly_inactive(from_ml) && (to_ml->player && to_ml->player->opts.moh)) + if (opmode == OP_OFFER && !call_ml_sendonly_inactive(from_ml) + && (to_ml->players[MP_DEFAULT] && to_ml->players[MP_DEFAULT]->opts.moh)) { return true; } @@ -1604,13 +1605,13 @@ static void call_ml_moh_handle_flags(struct call_monologue *from_ml, struct call /* if from_ml not given, then it's a reflected MoH, use capabilities of to_ml */ struct call_monologue *moh_ml = from_ml ? : to_ml; - if (!to_ml->player || + if (!to_ml->players[MP_DEFAULT] || !ML_ISSET2(moh_ml, MOH_ZEROCONN, MOH_SENDRECV)) { return; } - struct call_media * media = to_ml->player->media; + struct call_media * media = to_ml->players[MP_DEFAULT]->media; if (media) { /* check zero-connection */ if (ML_ISSET(moh_ml, MOH_ZEROCONN)) { @@ -1681,7 +1682,7 @@ const char * call_check_moh(struct call_monologue *from_ml, struct call_monologu /* whom to play the moh audio */ errstr = call_play_media_for_ml(to_ml, &opts, NULL); if (errstr) { - to_ml->player->opts.moh = 0; /* initialization failed, mark accordingly */ + to_ml->players[MP_DEFAULT]->opts.moh = 0; /* initialization failed, mark accordingly */ return errstr; } @@ -1712,7 +1713,7 @@ const char *call_play_media_for_ml(struct call_monologue *ml, /* this starts the audio player if needed */ update_init_monologue_subscribers(ml, OP_PLAY_MEDIA); - if (ml->player && ml->player->opts.moh) { + if (ml->players[MP_DEFAULT] && ml->players[MP_DEFAULT]->opts.moh) { ilog(LOG_DEBUG, "There is already ongoing media playback for MoH. Ignore new one."); /* pretend that everything is good */ return NULL; @@ -1720,10 +1721,10 @@ const char *call_play_media_for_ml(struct call_monologue *ml, else { /* media_player_new() now knows that audio player is in use * TODO: player options can have changed if already exists */ - media_player_new(&ml->player, ml, NULL, opts); + media_player_new(&ml->players[MP_DEFAULT], ml, NULL, opts); } - if (!media_player_play(ml->player, opts)) + if (!media_player_play(ml->players[MP_DEFAULT], opts)) return "Failed to start media playback"; return NULL; @@ -1735,14 +1736,14 @@ const char *call_play_media_for_ml(struct call_monologue *ml, long long call_stop_media_for_ml(struct call_monologue *ml) { #ifdef WITH_TRANSCODING - if (!ml->player) + if (!ml->players[MP_DEFAULT]) return 0; - long long ret = media_player_stop(ml->player); + long long ret = media_player_stop(ml->players[MP_DEFAULT]); /* restore to non-mixing if needed */ codec_update_all_source_handlers(ml); update_init_monologue_subscribers(ml, OP_STOP_MEDIA); /* mark MoH as already not used (it can be unset now) */ - ml->player->opts.moh = 0; + ml->players[MP_DEFAULT]->opts.moh = 0; return ret; #else return 0; @@ -2054,9 +2055,9 @@ static void media_player_run(void *ptr) { bool media_player_is_active(struct call_monologue *ml) { if (!ml) return false; - if (!ml->player) + if (!ml->players[MP_DEFAULT]) return false; - if (!ml->player->next_run) + if (!ml->players[MP_DEFAULT]->next_run) return false; return true; } diff --git a/daemon/mqtt.c b/daemon/mqtt.c index 41e5b47dd..835c196cf 100644 --- a/daemon/mqtt.c +++ b/daemon/mqtt.c @@ -171,7 +171,7 @@ static void mqtt_monologue_stats(struct call_monologue *ml, JsonBuilder *json) { } #ifdef WITH_TRANSCODING - struct media_player *mp = ml->player; + struct media_player *mp = ml->players[MP_DEFAULT]; if (mp) { mutex_lock(&mp->lock); diff --git a/daemon/recording.c b/daemon/recording.c index 76b1e174b..54731ccd1 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -345,8 +345,8 @@ static void recording_update_flags(call_t *call, bool streams) { static void rec_setup_monologue(struct call_monologue *ml) { recording_setup_monologue(ml); - if (ml->rec_player) { - bool ret = media_player_start(ml->rec_player); + if (ml->players[MP_REC]) { + bool ret = media_player_start(ml->players[MP_REC]); if (!ret) ilog(LOG_WARN, "Failed to start media player for recording announcement"); } diff --git a/daemon/sdp.c b/daemon/sdp.c index 48f896ec1..6d423774c 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -3192,7 +3192,7 @@ static void sdp_out_add_other(GString *out, struct call_monologue *monologue, if (flags->loop_protect) append_attr_to_gstring(out, "rtpengine", &rtpe_instance_id, flags, media->type_id); #ifdef WITH_TRANSCODING - if (monologue->player && monologue->player->opts.moh && rtpe_config.moh_attr_name) { + if (monologue->players[MP_DEFAULT] && monologue->players[MP_DEFAULT]->opts.moh && rtpe_config.moh_attr_name) { append_null_attr_to_gstring(out, rtpe_config.moh_attr_name, flags, media->type_id); } #endif diff --git a/include/call.h b/include/call.h index 067437b57..bc359a87e 100644 --- a/include/call.h +++ b/include/call.h @@ -494,6 +494,13 @@ struct media_subscription { typedef IQUEUE(struct media_subscription, link) subscription_q; +enum { + MP_DEFAULT = 0, + MP_REC, + + MP_COUNT +}; + /** @@ -625,8 +632,7 @@ struct call_monologue { GHashTable *subscribers_ht; /* for quick lookup */ medias_arr *medias; media_id_ht media_ids; - struct media_player *player; - struct media_player *rec_player; + struct media_player *players[MP_COUNT]; struct session_bandwidth sdp_session_bandwidth; GString *last_out_sdp;