[MPlayer-cvslog] r18765 - trunk/libmpdemux/demux_lavf.c

nicodvb subversion at mplayerhq.hu
Tue Jun 20 21:57:16 CEST 2006


Author: nicodvb
Date: Tue Jun 20 21:57:16 2006
New Revision: 18765

Modified:
   trunk/libmpdemux/demux_lavf.c

Log:
support for audio stream switching

Modified: trunk/libmpdemux/demux_lavf.c
==============================================================================
--- trunk/libmpdemux/demux_lavf.c	(original)
+++ trunk/libmpdemux/demux_lavf.c	Tue Jun 20 21:57:16 2006
@@ -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;
     }



More information about the MPlayer-cvslog mailing list