]> git.sesse.net Git - vlc/blobdiff - src/input/input_programs.c
* Altivec-enabled version of fastmemcpy
[vlc] / src / input / input_programs.c
index 5fdcd7b220ff619fe47110407b76578113bc543f..d0f1f40f2dcda6ac48f93cebe47dc3ff66cb6dbe 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.67 2001/12/05 03:31:04 jobi Exp $
+ * $Id: input_programs.c,v 1.77 2002/03/28 03:53:15 jobi Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
 #include <stdlib.h>
 #include <string.h>                                    /* memcpy(), memset() */
 #include <sys/types.h>                                              /* off_t */
 
-#include "config.h"
-#include "common.h"
-#include "intf_msg.h"
-#include "threads.h"
-#include "mtime.h"
-#include "debug.h"
+#include <videolan/vlc.h>
 
 #include "stream_control.h"
 #include "input_ext-intf.h"
 #include "input_ext-dec.h"
 #include "input_ext-plugins.h"
 
-#include "main.h"                                     /* --noaudio --novideo */
+#include "debug.h"
 
 /*
  * NOTICE : all of these functions expect you to have taken the lock on
@@ -149,8 +142,6 @@ pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
     /* Where to add the pgrm */
     int i_pgrm_index = p_input->stream.i_pgrm_number;
 
-    intf_DbgMsg("Adding description for pgrm %d", i_pgrm_id);
-
     /* Add an entry to the list of program associated with the stream */
     p_input->stream.i_pgrm_number++;
     p_input->stream.pp_programs = realloc( p_input->stream.pp_programs,
@@ -215,8 +206,6 @@ void input_DelProgram( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm )
 
     ASSERT( p_pgrm );
 
-    intf_DbgMsg("Deleting description for pgrm %d", p_pgrm->i_number);
-
     /* Free the structures that describe the es that belongs to that program */
     while( p_pgrm->i_es_number )
     {
@@ -266,8 +255,6 @@ input_area_t * input_AddArea( input_thread_t * p_input )
     /* Where to add the pgrm */
     int i_area_index = p_input->stream.i_area_nb;
 
-    intf_DbgMsg("Adding description for area %d", i_area_index );
-
     /* Add an entry to the list of program associated with the stream */
     p_input->stream.i_area_nb++;
     p_input->stream.pp_areas = realloc( p_input->stream.pp_areas,
@@ -296,12 +283,121 @@ 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];
 }
 
+/*****************************************************************************
+ * input_SetProgram: changes the current program
+ *****************************************************************************/
+int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
+{
+    int i_es_index;
+    
+    if ( p_input->stream.p_selected_program )
+    {
+        for ( i_es_index = 0 ; 
+                i_es_index < p_input->stream.i_selected_es_number; 
+                i_es_index ++ )
+        {
+            intf_WarnMsg( 4, "Unselecting ES %d", 
+                    p_input->stream.pp_selected_es[i_es_index]->i_id );
+            input_UnselectES( p_input , 
+                    p_input->stream.pp_selected_es[i_es_index] );
+        }
+    }
+
+    for (i_es_index = 0 ; i_es_index < p_new_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;
+
+        /* Get the number of the required audio stream */
+        if( p_main->b_audio )
+        {
+            /* Default is the first one */
+            i_required_audio_es = config_GetIntVariable( "input_channel" );
+            if( i_required_audio_es < 0 )
+            {
+                i_required_audio_es = 1;
+            }
+        }
+        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( "input_subtitle" );
+            if( i_required_spu_es < 0 )
+            {
+                i_required_spu_es = 0;
+            }
+        }
+        else
+        {
+            i_required_spu_es = 0;
+        }
+        switch( p_new_prg->pp_es[i_es_index]->i_cat )
+                    {
+                        case MPEG1_VIDEO_ES:
+                        case MPEG2_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 MPEG1_AUDIO_ES:
+                        case MPEG2_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;
+                        case LPCM_AUDIO_ES :
+                        case AC3_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 DVD_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 :
+                            break;
+                    }
+
+    }
+    
+
+    p_input->stream.p_selected_program = p_new_prg;
+
+    return( 0 );
+}
+
+
 /*****************************************************************************
  * input_DelArea: destroy a area descriptor
  *****************************************************************************
@@ -313,8 +409,6 @@ void input_DelArea( input_thread_t * p_input, input_area_t * p_area )
 
     ASSERT( p_area );
 
-    intf_DbgMsg("Deleting description for area %d", p_area->i_id );
-
     /* Find the area in the areas table */
     for( i_area_index = 0; i_area_index < p_input->stream.i_area_nb;
          i_area_index++ )
@@ -374,8 +468,6 @@ es_descriptor_t * input_AddES( input_thread_t * p_input,
 {
     es_descriptor_t * p_es;
 
-    intf_DbgMsg("Adding description for ES 0x%x", i_es_id);
-
     p_es = (es_descriptor_t *)malloc( sizeof(es_descriptor_t) );
     if( p_es == NULL )
     {
@@ -400,6 +492,9 @@ 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;
+#ifdef HAVE_SATELLITE
+    p_es->i_dmx_fd = 0;
+#endif
 
     if( i_data_len )
     {
@@ -517,13 +612,11 @@ int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
 {
     if( p_es == NULL )
     {
-        intf_ErrMsg( "Nothing to do in input_SelectES" );
+        intf_ErrMsg( "input error: nothing to do in input_SelectES" );
         return -1;
     }
 
-#ifdef TRACE_INPUT
-    intf_DbgMsg( "Selecting ES 0x%x", p_es->i_id );
-#endif
+    intf_WarnMsg( 4, "input: selecting ES 0x%x", p_es->i_id );
 
     if( p_es->p_decoder_fifo != NULL )
     {
@@ -531,6 +624,8 @@ 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:
@@ -539,9 +634,6 @@ int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_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 );
@@ -591,9 +683,7 @@ int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
         return -1;
     }
 
-#ifdef TRACE_INPUT
-    intf_DbgMsg( "Unselecting ES 0x%x", p_es->i_id );
-#endif
+    intf_WarnMsg( 4, "input: unselecting ES 0x%x", p_es->i_id );
 
     if( p_es->p_decoder_fifo == NULL )
     {
@@ -602,6 +692,7 @@ int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
     }
 
     input_EndDecoder( p_input, p_es );
+    free( p_es->p_pes );
 
     if( ( p_es->p_decoder_fifo == NULL ) &&
         ( p_input->stream.i_selected_es_number > 0 ) )
@@ -624,9 +715,7 @@ int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
 
         if( p_input->stream.pp_selected_es == NULL )
         {
-#ifdef TRACE_INPUT
-            intf_DbgMsg( "No more selected ES in input_UnselectES" );
-#endif
+            intf_WarnMsg( 4, "input: no more selected ES in input_UnselectES" );
             return( 1 );
         }
     }