From e9f0940c47de88027c9e0fd8887f7a1fce24c1a5 Mon Sep 17 00:00:00 2001 From: nicodvb Date: Tue, 20 Jun 2006 19:57:16 +0000 Subject: [PATCH] support for audio stream switching git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@18765 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_lavf.c | 51 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index e2565f5dc7..94ade929db 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -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; }