]> git.sesse.net Git - vlc/blobdiff - src/input/input_programs.c
* ./src/misc/modules_plugin.h: exported input_ClockManageRef for fenrir.
[vlc] / src / input / input_programs.c
index 9d4c23593e338d98bc232af3fc1906b4805baed4..0404a95012a7223ef8efaab6bab1a675ea10b073 100644 (file)
@@ -2,7 +2,7 @@
  * input_programs.c: es_descriptor_t, pgrm_descriptor_t management
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: input_programs.c,v 1.71 2002/02/19 00:50:19 sam Exp $
+ * $Id: input_programs.c,v 1.83 2002/04/25 21:52:42 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -35,8 +35,6 @@
 #include "input_ext-dec.h"
 #include "input_ext-plugins.h"
 
-#include "debug.h"
-
 /*
  * NOTICE : all of these functions expect you to have taken the lock on
  * p_input->stream.lock
@@ -283,8 +281,6 @@ input_area_t * input_AddArea( input_thread_t * p_input )
     p_input->stream.pp_areas[i_area_index]->i_seek = NO_SEEK;
     p_input->stream.pp_areas[i_area_index]->i_part_nb = 1;
     p_input->stream.pp_areas[i_area_index]->i_part= 0;
-    p_input->stream.pp_areas[i_area_index]->i_angle_nb = 1;
-    p_input->stream.pp_areas[i_area_index]->i_angle = 0;
 
     return p_input->stream.pp_areas[i_area_index];
 }
@@ -295,17 +291,93 @@ input_area_t * input_AddArea( input_thread_t * p_input )
 int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
 {
     int i_es_index;
-#define old_prg p_input->stream.p_selected_program
-    for ( i_es_index = 0 ; i_es_index < old_prg->i_es_number ; i_es_index ++ )
+    int i_required_audio_es;
+    int i_required_spu_es;
+    int i_audio_es = 0;
+    int i_spu_es = 0;
+
+    if ( p_input->stream.p_selected_program )
+    {
+        for ( i_es_index = 1 ; /* 0 should be the PMT */
+                i_es_index < p_input->stream.p_selected_program->
+                i_es_number ;
+                i_es_index ++ )
+        {
+#define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
+            if ( p_es->p_decoder_fifo ) /* if the ES was selected */
+            {
+                input_UnselectES( p_input , p_es );
+            }
+#undef p_es
+        }
+    }
+    /* Get the number of the required audio stream */
+    if( p_main->b_audio )
     {
-        input_UnselectES( p_input , old_prg->pp_es[i_es_index] );
+        /* Default is the first one */
+        i_required_audio_es = config_GetIntVariable( "audio-channel" );
+        if( i_required_audio_es < 0 )
+        {
+            i_required_audio_es = 1;
+        }
     }
-#undef old_prg
+    else
+    {
+        i_required_audio_es = 0;
+    }
+
+    /* Same thing for subtitles */
+    if( p_main->b_video )
+    {
+        /* for spu, default is none */
+        i_required_spu_es = config_GetIntVariable( "spu-channel" );
+        if( i_required_spu_es < 0 )
+        {
+            i_required_spu_es = 0;
+        }
+    }
+    else
+    {
+        i_required_spu_es = 0;
+    }
+
     for (i_es_index = 0 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
     {
-        input_SelectES( p_input , p_new_prg->pp_es[i_es_index] );
+        switch( p_new_prg->pp_es[i_es_index]->i_cat )
+        {
+            case VIDEO_ES:
+                intf_WarnMsg( 4, "Selecting ES %x",
+                            p_new_prg->pp_es[i_es_index]->i_id );
+                input_SelectES( p_input, p_new_prg->pp_es[i_es_index] );
+                break;
+            case AUDIO_ES:
+                i_audio_es += 1;
+                if( i_audio_es <= i_required_audio_es )
+                {
+                    intf_WarnMsg( 4, "Selecting ES %x",
+                                p_new_prg->pp_es[i_es_index]->i_id );
+                    input_SelectES( p_input, p_new_prg->pp_es[i_es_index]);
+                }
+                break;
+            /* Not sure this one is fully specification-compliant */
+            case SPU_ES :
+                i_spu_es += 1;
+                if( i_spu_es <= i_required_spu_es )
+                {
+                    intf_WarnMsg( 4, "Selecting ES %x",
+                                p_new_prg->pp_es[i_es_index]->i_id );
+                    input_SelectES( p_input, p_new_prg->pp_es[i_es_index] );
+                }
+            break;
+            default :
+                intf_WarnMsg( 2, "ES %x has unknown type",
+                            p_new_prg->pp_es[i_es_index]->i_id );
+                break;
+        }
+
     }
 
+
     p_input->stream.p_selected_program = p_new_prg;
 
     return( 0 );
@@ -406,6 +478,7 @@ es_descriptor_t * input_AddES( input_thread_t * p_input,
     p_es->p_decoder_fifo = NULL;
     p_es->b_audio = 0;
     p_es->i_cat = UNKNOWN_ES;
+    p_es->i_demux_fd = 0;
 
     if( i_data_len )
     {
@@ -535,17 +608,18 @@ int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
         return( -1 );
     }
 
+    p_es->thread_id = 0;
+
     switch( p_es->i_type )
     {
     case AC3_AUDIO_ES:
     case MPEG1_AUDIO_ES:
     case MPEG2_AUDIO_ES:
+    case MPEG4_VIDEO_ES:
+    case MSMPEG4_VIDEO_ES:
     case LPCM_AUDIO_ES:
         if( p_main->b_audio )
         {
-            /* This kludge should be removed */
-            p_main->b_ac3 = ( p_es->i_type == AC3_AUDIO_ES );
-
             /* Release the lock, not to block the input thread during
              * the creation of the thread. */
             vlc_mutex_unlock( &p_input->stream.stream_lock );
@@ -604,6 +678,7 @@ int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
     }
 
     input_EndDecoder( p_input, p_es );
+    p_es->p_pes = NULL;
 
     if( ( p_es->p_decoder_fifo == NULL ) &&
         ( p_input->stream.i_selected_es_number > 0 ) )