1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 08:12:17 +00:00

support for audio stream switching

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@18765 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
nicodvb 2006-06-20 19:57:16 +00:00
parent 95db10787d
commit e9f0940c47

View File

@ -44,6 +44,7 @@ typedef struct lavf_priv_t{
int audio_streams;
int video_streams;
int64_t last_pts;
int astreams[MAX_A_STREAMS];
}lavf_priv_t;
extern void print_wave_header(WAVEFORMATEX *h, int verbose_level);
@ -184,7 +185,12 @@ static demuxer_t* demux_open_lavf(demuxer_t *demuxer){
switch(codec->codec_type){
case CODEC_TYPE_AUDIO:{
WAVEFORMATEX *wf= calloc(sizeof(WAVEFORMATEX) + codec->extradata_size, 1);
if(priv->audio_streams >= MAX_A_STREAMS)
break;
sh_audio_t* sh_audio=new_sh_audio(demuxer, i);
if(!sh_audio)
break;
priv->astreams[priv->audio_streams] = i;
priv->audio_streams++;
if(!codec->codec_tag)
codec->codec_tag= codec_get_wav_tag(codec->codec_id);
@ -418,7 +424,50 @@ static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg)
*((int *)arg) = (int)(priv->last_pts*100 / priv->avfc->duration);
return DEMUXER_CTRL_OK;
case DEMUXER_CTRL_SWITCH_AUDIO:
{
int id = *((int*)arg);
int newid = -2;
int i, curridx = -2;
if(demuxer->audio->id == -2)
return DEMUXER_CTRL_NOTIMPL;
for(i = 0; i < priv->audio_streams; i++)
{
if(priv->astreams[i] == demuxer->audio->id) //current stream id
{
curridx = i;
break;
}
}
if(id < 0)
{
i = (curridx + 1) % priv->audio_streams;
newid = priv->astreams[i];
}
else
{
for(i = 0; i < priv->audio_streams; i++)
{
if(priv->astreams[i] == id)
{
newid = id;
break;
}
}
}
if(newid == -2 || i == curridx)
return DEMUXER_CTRL_NOTIMPL;
else
{
ds_free_packs(demuxer->audio);
priv->avfc->streams[demuxer->audio->id]->discard = AVDISCARD_ALL;
*((int*)arg) = demuxer->audio->id = newid;
priv->avfc->streams[newid]->discard = AVDISCARD_NONE;
return DEMUXER_CTRL_OK;
}
}
default:
return DEMUXER_CTRL_NOTIMPL;
}