MT#66375 media_player: don't let the finished playback to cut the restart

When the `run_func()` reports the end of the playback,
then the cleanup is done after dropping the call's read lock and
taking the write lock.

If the `play media` command restarts the player, or the `stop media` stops it
in the meanwhile, the cleanup then clears the `next_run` of the new playback,
which silently stops it and also lifts its `block egress`.

Simplest solution is to count every stop and start/rester of the player
under the write lock and then skip the cleanup if the count has changed
since `run_func()` was called, means the stop has done its own cleanup
and the restart has set up the new playback.

Change-Id: I030b7d32c1b15aaaf81b2f56492bc3299bf6c231
pull/2222/head
Donat Zenichev 4 weeks ago
parent 8eb93450c3
commit 59e8f70583

@ -172,6 +172,7 @@ static void media_player_shutdown(struct media_player *mp) {
//ilog(LOG_DEBUG, "shutting down media_player");
timerthread_obj_deschedule(&mp->tt_obj);
mp->next_run = 0;
mp->run_gen++;
mp->stop_on_ingress_armed = false;
/* no handler means already shutdown (e.g. `stop media` after a `stop-on-ingress` stop),
@ -1559,6 +1560,7 @@ static void __media_player_set_opts(struct media_player *mp, const media_player_
if (mp->media && mp->opts.block_egress)
MEDIA_SET(mp->media, BLOCK_EGRESS);
mp->run_gen++;
mp->stop_on_ingress_armed = mp->opts.stop_on_ingress;
atomic_set_na(&mp->ingress_seen, false);
}
@ -2182,6 +2184,7 @@ static void media_player_run(void *ptr) {
mutex_lock(&mp->lock);
bool finished = false;
unsigned int gen = mp->run_gen;
/* stopping needs the call locked in W, done below */
bool stop = mp->stop_on_ingress_armed && atomic_get_na(&mp->ingress_seen);
if (!stop && mp->next_run)
@ -2195,14 +2198,18 @@ static void media_player_run(void *ptr) {
else if (finished) {
rwlock_lock_w(&call->master_lock);
mp->next_run = 0;
mp->stop_on_ingress_armed = false;
/* skip if stopped or restarted after the lock was released, as the
* cleanup below would cut off the new playback */
if (mp->run_gen == gen) {
mp->next_run = 0;
mp->stop_on_ingress_armed = false;
if (mp->opts.block_egress)
MEDIA_CLEAR(mp->media, BLOCK_EGRESS);
if (mp->opts.block_egress)
MEDIA_CLEAR(mp->media, BLOCK_EGRESS);
codec_update_all_source_handlers(mp->media->monologue);
update_init_monologue_subscribers(mp->media->monologue, OP_PLAY_MEDIA);
codec_update_all_source_handlers(mp->media->monologue);
update_init_monologue_subscribers(mp->media->monologue, OP_PLAY_MEDIA);
}
rwlock_unlock_w(&call->master_lock);
}

@ -72,6 +72,8 @@ struct media_player {
struct sink_handler sink;
int64_t next_run;
/* bumped on every stop and (re)start, only written with call->master_lock in W */
unsigned int run_gen;
media_player_opts_t opts;
/* `stop-on-ingress` playback waiting for media, only written with call->master_lock in W */

Loading…
Cancel
Save