MT#62272 media_player_new: possibility to add opts

Add a possibility to add opts when actually
creating new media player.

This can be useful for cases with MoH implementation.

Change-Id: Ie7f9d290cd5e46063dd4095d57a521396b58bcfb
coverity_scan
Donat Zenichev 9 months ago
parent c478d1384e
commit aa006ccf85

@ -108,7 +108,7 @@ bool audio_player_setup(struct call_media *m, const rtp_payload_type *dst_pt,
if (mp) if (mp)
media_player_stop(mp); media_player_stop(mp);
else { else {
media_player_new(&mp, m->monologue, NULL); media_player_new(&mp, m->monologue, NULL, NULL);
ap->mp = mp; ap->mp = mp;
} }
if (!mp) if (!mp)

@ -2766,7 +2766,6 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c
#ifdef WITH_TRANSCODING #ifdef WITH_TRANSCODING
if (flags->recording_announcement) { if (flags->recording_announcement) {
media_player_new(&ml->rec_player, ml, NULL);
media_player_opts_t opts = MPO( media_player_opts_t opts = MPO(
.repeat = flags->repeat_times, .repeat = flags->repeat_times,
.duration_spent = flags->repeat_duration, .duration_spent = flags->repeat_duration,
@ -2777,6 +2776,7 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c
.blob = flags->blob, .blob = flags->blob,
.db_id = flags->db_id, .db_id = flags->db_id,
); );
media_player_new(&ml->rec_player, ml, NULL, &opts);
if (!media_player_add(ml->rec_player, opts)) if (!media_player_add(ml->rec_player, opts))
ilog(LOG_WARN, "Failed to add media player for recording announcement"); ilog(LOG_WARN, "Failed to add media player for recording announcement");

@ -53,6 +53,7 @@ struct media_player_cache_packet;
static void cache_packet_free(struct media_player_cache_packet *p); static void cache_packet_free(struct media_player_cache_packet *p);
TYPED_GPTRARRAY_FULL(cache_packet_arr, struct media_player_cache_packet, cache_packet_free) TYPED_GPTRARRAY_FULL(cache_packet_arr, struct media_player_cache_packet, cache_packet_free)
static void __media_player_set_opts(struct media_player *mp, media_player_opts_t opts);
struct media_player_cache_index { struct media_player_cache_index {
struct media_player_content_index index; struct media_player_content_index index;
@ -234,7 +235,9 @@ static void __media_player_free(struct media_player *mp) {
// call->master_lock held in W // call->master_lock held in W
void media_player_new(struct media_player **mpp, struct call_monologue *ml, struct ssrc_ctx *prev_ssrc) { void media_player_new(struct media_player **mpp, struct call_monologue *ml, struct ssrc_ctx *prev_ssrc,
media_player_opts_t *opts)
{
#ifdef WITH_TRANSCODING #ifdef WITH_TRANSCODING
struct media_player *mp; struct media_player *mp;
@ -264,6 +267,10 @@ void media_player_new(struct media_player **mpp, struct call_monologue *ml, stru
mp->ssrc_out = ssrc_ctx; mp->ssrc_out = ssrc_ctx;
} }
/* add opts if given */
if (opts)
__media_player_set_opts(mp, *opts);
if (!mp->coder.pkt) { if (!mp->coder.pkt) {
mp->coder.pkt = av_packet_alloc(); mp->coder.pkt = av_packet_alloc();
mp->coder.pkt->data = NULL; mp->coder.pkt->data = NULL;
@ -1407,7 +1414,7 @@ static struct media_player_media_file *(*media_player_db_id_get)(unsigned long l
static void __media_player_set_opts(struct media_player *mp, media_player_opts_t opts) { static void __media_player_set_opts(struct media_player *mp, media_player_opts_t opts) {
mp->opts = opts; mp->opts = opts;
if (mp->opts.block_egress) if (mp->media && mp->opts.block_egress)
MEDIA_SET(mp->media, BLOCK_EGRESS); MEDIA_SET(mp->media, BLOCK_EGRESS);
} }
@ -1609,7 +1616,7 @@ const char * call_play_media_for_ml(struct call_monologue *ml,
update_init_subscribers(ml, OP_PLAY_MEDIA); update_init_subscribers(ml, OP_PLAY_MEDIA);
/* media_player_new() now knows that audio player is in use /* media_player_new() now knows that audio player is in use
* TODO: player options can have changed if already exists */ * TODO: player options can have changed if already exists */
media_player_new(&ml->player, ml, NULL); media_player_new(&ml->player, ml, NULL, &opts);
if (opts.file.len) { if (opts.file.len) {
if (!media_player_play_file(ml->player, opts)) if (!media_player_play_file(ml->player, opts))

@ -407,7 +407,8 @@ int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media,
goto err; goto err;
media_player_new(&tg->pcm_player, pcm_media->monologue, media_player_new(&tg->pcm_player, pcm_media->monologue,
pcm_media->streams.length ? pcm_media->streams.head->data->ssrc_out[0] : NULL); (pcm_media->streams.length ? pcm_media->streams.head->data->ssrc_out[0] : NULL),
NULL);
// even though we call media_player_set_media() here, we need to call it again in // even though we call media_player_set_media() here, we need to call it again in
// t38_gateway_start because our sink might not have any streams added here yet, // t38_gateway_start because our sink might not have any streams added here yet,
// leaving the media_player setup incomplete // leaving the media_player setup incomplete

@ -121,7 +121,7 @@ struct send_timer {
#define MPO(...) (media_player_opts_t){__VA_ARGS__} #define MPO(...) (media_player_opts_t){__VA_ARGS__}
void media_player_new(struct media_player **, struct call_monologue *, struct ssrc_ctx *prev_ssrc); void media_player_new(struct media_player **, struct call_monologue *, struct ssrc_ctx *prev_ssrc, media_player_opts_t *);
bool media_player_add(struct media_player *mp, media_player_opts_t opts); bool media_player_add(struct media_player *mp, media_player_opts_t opts);
bool media_player_start(struct media_player *); bool media_player_start(struct media_player *);
long long media_player_stop(struct media_player *); long long media_player_stop(struct media_player *);

Loading…
Cancel
Save