changeset 18762:369074e0eb7b

support for audio stream switching
author nicodvb
date Tue, 20 Jun 2006 19:57:16 +0000
parents 4168044c1be4
children 1d6833f57d4a
files libmpdemux/demux_lavf.c
diffstat 1 files changed, 50 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_lavf.c	Tue Jun 20 11:48:39 2006 +0000
+++ b/libmpdemux/demux_lavf.c	Tue Jun 20 19:57:16 2006 +0000
@@ -44,6 +44,7 @@
     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 @@
         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 @@
 	    
 	    *((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;
     }