diff options
-rw-r--r-- | command.c | 21 | ||||
-rw-r--r-- | libmpdemux/demux_lavf.c | 11 | ||||
-rw-r--r-- | libmpdemux/demuxer.c | 13 |
3 files changed, 23 insertions, 22 deletions
@@ -851,11 +851,10 @@ static int mp_property_balance(m_option_t *prop, int action, void *arg, static int mp_property_audio(m_option_t *prop, int action, void *arg, MPContext *mpctx) { - struct MPOpts *opts = &mpctx->opts; int current_id, tmp; if (!mpctx->demuxer || !mpctx->demuxer->audio) return M_PROPERTY_UNAVAILABLE; - current_id = mpctx->demuxer->audio->id; + current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2; switch (action) { case M_PROPERTY_GET: @@ -901,21 +900,17 @@ static int mp_property_audio(m_option_t *prop, int action, void *arg, tmp = *((int *) arg); else tmp = -1; - opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp); - if (opts->audio_id == -2 - || (opts->audio_id > -1 - && mpctx->demuxer->audio->id != current_id && current_id != -2)) + int new_id = demuxer_switch_audio(mpctx->demuxer, tmp); + if (new_id != current_id) uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC); - if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) { + if (new_id != current_id && new_id >= 0) { sh_audio_t *sh2; sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id]; - if (sh2) { - sh2->ds = mpctx->demuxer->audio; - mpctx->sh_audio = sh2; - reinit_audio_chain(mpctx); - } + sh2->ds = mpctx->demuxer->audio; + mpctx->sh_audio = sh2; + reinit_audio_chain(mpctx); } - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id); return M_PROPERTY_OK; default: return M_PROPERTY_NOT_IMPLEMENTED; diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index 2e8495c1c4..2d7e6092e1 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -737,14 +737,15 @@ static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg) newid = pstreams[i]; } } - if(i == curridx) - return DEMUXER_CTRL_NOTIMPL; - else - { + if (i == curridx) { + *(int *) arg = curridx; + return DEMUXER_CTRL_OK; + } else { ds_free_packs(ds); if(ds->id >= 0) priv->avfc->streams[ds->id]->discard = AVDISCARD_ALL; - *((int*)arg) = ds->id = newid; + ds->id = newid; + *(int *) arg = i < 0 ? -2 : i; if(newid >= 0) priv->avfc->streams[newid]->discard = AVDISCARD_NONE; return DEMUXER_CTRL_OK; diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index 14d2c85f67..71e75e2efb 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -1407,10 +1407,15 @@ int demuxer_get_percent_pos(demuxer_t *demuxer) int demuxer_switch_audio(demuxer_t *demuxer, int index) { int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &index); - if (res == DEMUXER_CTRL_NOTIMPL) - index = demuxer->audio->id; - if (demuxer->audio->id >= 0) - demuxer->audio->sh = demuxer->a_streams[demuxer->audio->id]; + if (res == DEMUXER_CTRL_NOTIMPL) { + struct sh_audio *sh_audio = demuxer->audio->sh; + return sh_audio ? sh_audio->aid : -2; + } + if (demuxer->audio->id >= 0) { + struct sh_audio *sh_audio = demuxer->a_streams[demuxer->audio->id]; + demuxer->audio->sh = sh_audio; + index = sh_audio->aid; // internal MPEG demuxers don't set it right + } else demuxer->audio->sh = NULL; return index; |