]> git.sesse.net Git - vlc/blobdiff - src/input/input_programs.c
* ALL: changed the prototype of input_AddES() to include enough information so we...
[vlc] / src / input / input_programs.c
index 96c2cdf0ecb4a4b0e4d1bfc0d67ded138966305d..3fac781c794972092019fbf23a6bcc3c8adfa739 100644 (file)
@@ -2,7 +2,7 @@
  * input_programs.c: es_descriptor_t, pgrm_descriptor_t management
  *****************************************************************************
  * Copyright (C) 1999-2002 VideoLAN
- * $Id: input_programs.c,v 1.101 2003/01/31 11:23:37 massiot Exp $
+ * $Id: input_programs.c,v 1.106 2003/05/05 22:23:42 gbazin Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
  * p_input->stream.lock
  */
 
+/* Navigation callbacks */
+static int ProgramCallback( vlc_object_t *, char const *,
+                            vlc_value_t, vlc_value_t, void * );
+static int TitleCallback( vlc_object_t *, char const *,
+                          vlc_value_t, vlc_value_t, void * );
+static int ChapterCallback( vlc_object_t *, char const *,
+                            vlc_value_t, vlc_value_t, void * );
+static int NavigationCallback( vlc_object_t *, char const *,
+                               vlc_value_t, vlc_value_t, void * );
+static int ESCallback( vlc_object_t *, char const *,
+                       vlc_value_t, vlc_value_t, void * );
+
 /*****************************************************************************
  * input_InitStream: init the stream descriptor of the given input
  *****************************************************************************/
 int input_InitStream( input_thread_t * p_input, size_t i_data_len )
 {
+    vlc_value_t text;
 
     p_input->stream.i_stream_id = 0;
 
@@ -72,6 +85,36 @@ int input_InitStream( input_thread_t * p_input, size_t i_data_len )
         p_input->stream.p_demux_data = NULL;
     }
 
+    /* Create a few object variables used for navigation in the interfaces */
+    var_Create( p_input, "program", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Program");
+    var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
+    var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Title");
+    var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );
+    var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Chapter");
+    var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );
+    var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Navigation");
+    var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );
+    var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Video track");
+    var_Change( p_input, "video-es", VLC_VAR_SETTEXT, &text, NULL );
+    var_Create( p_input, "audio-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Audio track");
+    var_Change( p_input, "audio-es", VLC_VAR_SETTEXT, &text, NULL );
+    var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Subtitle track");
+    var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
+
+    var_AddCallback( p_input, "program", ProgramCallback, NULL );
+    var_AddCallback( p_input, "title", TitleCallback, NULL );
+    var_AddCallback( p_input, "chapter", ChapterCallback, NULL );
+    var_AddCallback( p_input, "video-es", ESCallback, NULL );
+    var_AddCallback( p_input, "audio-es", ESCallback, NULL );
+    var_AddCallback( p_input, "spu-es", ESCallback, NULL );
+
     return 0;
 }
 
@@ -108,6 +151,14 @@ void input_EndStream( input_thread_t * p_input )
     {
         free( p_input->stream.p_demux_data );
     }
+
+    /* Free navigation variables */
+    var_Destroy( p_input, "program" );
+    var_Destroy( p_input, "title" );
+    var_Destroy( p_input, "chapter" );
+    var_Destroy( p_input, "video-es" );
+    var_Destroy( p_input, "audio-es" );
+    var_Destroy( p_input, "spu-es" );
 }
 
 /*****************************************************************************
@@ -139,6 +190,7 @@ pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
 {
     /* Where to add the pgrm */
     pgrm_descriptor_t * p_pgrm = malloc( sizeof(pgrm_descriptor_t) );
+    vlc_value_t val;
 
     if( p_pgrm == NULL )
     {
@@ -179,6 +231,9 @@ pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
                  p_input->stream.i_pgrm_number,
                  p_pgrm );
 
+    val.i_int = i_pgrm_id;
+    var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
+
     return p_pgrm;
 }
 
@@ -190,6 +245,7 @@ pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
 void input_DelProgram( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm )
 {
     unsigned int i_pgrm_index;
+    vlc_value_t val;
 
     /* Find the program in the programs table */
     for( i_pgrm_index = 0; i_pgrm_index < p_input->stream.i_pgrm_number;
@@ -206,6 +262,9 @@ void input_DelProgram( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm )
         return;
     }
 
+    val.i_int = i_pgrm_index;
+    var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
+
     /* Free the structures that describe the es that belongs to that program */
     while( p_pgrm->i_es_number )
     {
@@ -232,10 +291,13 @@ void input_DelProgram( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm )
  *****************************************************************************
  * This area descriptor will be referenced in the given stream descriptor
  *****************************************************************************/
-input_area_t * input_AddArea( input_thread_t * p_input )
+input_area_t * input_AddArea( input_thread_t * p_input,
+                              uint16_t i_area_id, uint16_t i_part_nb )
 {
     /* Where to add the pgrm */
     input_area_t * p_area = malloc( sizeof(input_area_t) );
+    vlc_value_t val;
+    int i;
 
     if( p_area == NULL )
     {
@@ -244,13 +306,13 @@ input_area_t * input_AddArea( input_thread_t * p_input )
     }
 
     /* Init this entry */
-    p_area->i_id = 0;
+    p_area->i_id = i_area_id;
+    p_area->i_part_nb = i_part_nb;
+    p_area->i_part= 0;
     p_area->i_start = 0;
     p_area->i_size = 0;
     p_area->i_tell = 0;
     p_area->i_seek = NO_SEEK;
-    p_area->i_part_nb = 1;
-    p_area->i_part= 0;
 
     /* Add an entry to the list of program associated with the stream */
     INSERT_ELEM( p_input->stream.pp_areas,
@@ -258,6 +320,36 @@ input_area_t * input_AddArea( input_thread_t * p_input )
                  p_input->stream.i_area_nb,
                  p_area );
 
+    /* Don't add empty areas */
+    if( i_part_nb == 0 )
+        return NULL;
+
+    /* Take care of the navigation variables */
+    val.i_int = i_area_id;
+    var_Change( p_input, "title", VLC_VAR_ADDCHOICE, &val, NULL );
+
+    val.psz_string = malloc( sizeof("title ") + 5 );
+    if( val.psz_string )
+    {
+        vlc_value_t val2;
+
+        sprintf( val.psz_string, "title %2i", i_area_id );
+       var_Destroy( p_input, val.psz_string );
+       var_Create( p_input, val.psz_string, VLC_VAR_INTEGER |
+                   VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND );
+       var_AddCallback( p_input, val.psz_string, NavigationCallback,
+                        (void *)(int)i_area_id );
+
+       var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, NULL );
+
+       for( i = 1; i <= i_part_nb; i++ )
+       {
+           val2.i_int = i;
+           var_Change( p_input, val.psz_string,
+                        VLC_VAR_ADDCHOICE, &val2, NULL );
+       }
+    }
+
     return p_area;
 }
 
@@ -271,6 +363,7 @@ int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
     int i_required_spu_es;
     int i_audio_es = 0;
     int i_spu_es = 0;
+    vlc_value_t val;
 
     if ( p_input->stream.p_selected_program )
     {
@@ -356,10 +449,13 @@ int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
 
     p_input->stream.p_selected_program = p_new_prg;
 
+    /* Update the navigation variables without triggering a callback */
+    val.i_int = p_new_prg->i_number;
+    var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
+
     return( 0 );
 }
 
-
 /*****************************************************************************
  * input_DelArea: destroy a area descriptor
  *****************************************************************************
@@ -368,6 +464,7 @@ int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
 void input_DelArea( input_thread_t * p_input, input_area_t * p_area )
 {
     unsigned int i_area_index;
+    vlc_value_t val;
 
     /* Find the area in the areas table */
     for( i_area_index = 0; i_area_index < p_input->stream.i_area_nb;
@@ -384,6 +481,15 @@ void input_DelArea( input_thread_t * p_input, input_area_t * p_area )
         return;
     }
 
+    /* Take care of the navigation variables */
+    val.psz_string = malloc( sizeof("title ") + 5 );
+    if( val.psz_string )
+    {
+        sprintf( val.psz_string, "title %i", p_area->i_id );
+       var_Change( p_input, "navigation", VLC_VAR_DELCHOICE, &val, NULL );
+       var_Destroy( p_input, val.psz_string );
+    }
+
     /* Remove this area from the stream's list of areas */
     REMOVE_ELEM( p_input->stream.pp_areas,
                  p_input->stream.i_area_nb,
@@ -421,9 +527,12 @@ es_descriptor_t * input_FindES( input_thread_t * p_input, uint16_t i_es_id )
  *****************************************************************************/
 es_descriptor_t * input_AddES( input_thread_t * p_input,
                                pgrm_descriptor_t * p_pgrm, u16 i_es_id,
+                               int i_category, char const *psz_desc,
                                size_t i_data_len )
 {
     es_descriptor_t * p_es;
+    vlc_value_t val, text;
+    char *psz_var = NULL;
 
     p_es = (es_descriptor_t *)malloc( sizeof(es_descriptor_t) );
     if( p_es == NULL )
@@ -439,13 +548,14 @@ es_descriptor_t * input_AddES( input_thread_t * p_input,
 
     /* Init its values */
     p_es->i_id = i_es_id;
-    p_es->psz_desc[0] = '\0';
+    p_es->psz_desc = psz_desc ? strdup( psz_desc ) : NULL;
     p_es->p_pes = NULL;
     p_es->p_decoder_fifo = NULL;
-    p_es->i_cat = UNKNOWN_ES;
+    p_es->i_cat = i_category;
     p_es->i_demux_fd = 0;
     p_es->c_packets = 0;
     p_es->c_invalid_packets = 0;
+    p_es->b_force_decoder = VLC_FALSE;
 
     if( i_data_len )
     {
@@ -478,6 +588,26 @@ es_descriptor_t * input_AddES( input_thread_t * p_input,
         p_es->p_pgrm = NULL;
     }
 
+    switch( i_category )
+    {
+    case AUDIO_ES:
+        psz_var = "audio-es";
+        break;
+    case SPU_ES:
+        psz_var = "spu-es";
+        break;
+    case VIDEO_ES:
+        psz_var = "video-es";
+        break;
+    }
+
+    if( psz_var )
+    {
+        val.i_int = p_es->i_id;
+        text.psz_string = (char *)psz_desc;
+        var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
+    }
+
     return p_es;
 }
 
@@ -488,6 +618,8 @@ void input_DelES( input_thread_t * p_input, es_descriptor_t * p_es )
 {
     unsigned int            i_index, i_es_index;
     pgrm_descriptor_t *     p_pgrm;
+    char *                  psz_var;
+    vlc_value_t             val;
 
     /* Find the ES in the ES table */
     for( i_es_index = 0; i_es_index < p_input->stream.i_es_number;
@@ -504,7 +636,22 @@ void input_DelES( input_thread_t * p_input, es_descriptor_t * p_es )
         return;
     }
 
-    p_pgrm = p_es->p_pgrm;
+    /* Remove es from its associated variable */
+    switch( p_es->i_cat )
+    {
+    case AUDIO_ES:
+        psz_var = "audio-es";
+       break;
+    case SPU_ES:
+        psz_var = "spu-es";
+       break;
+    case VIDEO_ES:
+    default:
+        psz_var = "video-es";
+       break;
+    }
+    val.i_int = p_es->i_id;
+    var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
 
     /* Kill associated decoder, if any. */
     if( p_es->p_decoder_fifo != NULL )
@@ -512,8 +659,9 @@ void input_DelES( input_thread_t * p_input, es_descriptor_t * p_es )
         input_EndDecoder( p_input, p_es );
     }
 
-    /* Remove this ES from the description of the program if it is associated to
-     * one */
+    /* Remove this ES from the description of the program if it is associated
+     * to one */
+    p_pgrm = p_es->p_pgrm;
     if( p_pgrm )
     {
         for( i_index = 0; i_index < p_pgrm->i_es_number; i_index++ )
@@ -542,6 +690,12 @@ void input_DelES( input_thread_t * p_input, es_descriptor_t * p_es )
         free( p_es->p_bitmapinfoheader );
     }
 
+    /* Free the description string */
+    if( p_es->psz_desc != NULL )
+    {
+        free( p_es->psz_desc );
+    }
+
     /* Find the ES in the ES table */
     for( i_es_index = 0; i_es_index < p_input->stream.i_es_number;
          i_es_index++ )
@@ -567,6 +721,8 @@ void input_DelES( input_thread_t * p_input, es_descriptor_t * p_es )
  *****************************************************************************/
 int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
 {
+    vlc_value_t val;
+
     if( p_es == NULL )
     {
         msg_Err( p_input, "nothing to do in input_SelectES" );
@@ -607,6 +763,10 @@ int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
         return -1;
     }
 
+    /* Update the es variable without triggering a callback */
+    val.i_int = p_es->i_id;
+    var_Change( p_input, "audio-es", VLC_VAR_SETVALUE, &val, NULL );
+
     return 0;
 }
 
@@ -658,3 +818,134 @@ int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
 
     return 0;
 }
+
+/*****************************************************************************
+ * Navigation callback: a bunch of navigation variables are used as an
+ *  alternative to the navigation API.
+ *****************************************************************************/
+static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
+                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    input_thread_t *p_input = (input_thread_t *)p_this;
+
+    if( oldval.i_int == newval.i_int )
+       return VLC_SUCCESS;
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+    if( ( newval.i_int > 0 ) )
+    {
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+        input_ChangeProgram( p_input, (uint16_t)newval.i_int );
+        input_SetStatus( p_input, INPUT_STATUS_PLAY );
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+    }
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    return VLC_SUCCESS;
+}
+
+static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
+                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    input_thread_t *p_input = (input_thread_t *)p_this;
+    input_area_t *p_area;
+
+    if( oldval.i_int == newval.i_int )
+       return VLC_SUCCESS;
+
+    /* Sanity check should have already be done by var_Set(). */
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+    p_area = p_input->stream.pp_areas[newval.i_int];
+    p_area->i_part = 1;
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+    input_ChangeArea( p_input, p_area );
+    input_SetStatus( p_input, INPUT_STATUS_PLAY );
+
+    return VLC_SUCCESS;
+}
+
+static int ChapterCallback( vlc_object_t *p_this, char const *psz_cmd,
+                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    input_thread_t *p_input = (input_thread_t *)p_this;
+    input_area_t *p_area;
+
+    if( oldval.i_int == newval.i_int )
+       return VLC_SUCCESS;
+
+    /* Sanity check will have already be done by var_Set(). */
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+    p_area = p_input->stream.p_selected_area;
+    p_input->stream.p_selected_area->i_part = newval.i_int;
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    input_ChangeArea( p_input, p_area );
+    input_SetStatus( p_input, INPUT_STATUS_PLAY );
+
+    return VLC_SUCCESS;
+}
+
+static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
+                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    input_thread_t *p_input = (input_thread_t *)p_this;
+    uint16_t i_area_id = (int)p_data;
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+    if( p_input->stream.p_selected_area->i_id == i_area_id &&
+        oldval.i_int == newval.i_int )
+    {
+        /* Nothing to do */
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+        return VLC_SUCCESS;
+    }
+
+    if( ( i_area_id < p_input->stream.i_area_nb ) && ( newval.i_int > 0 ) &&
+        ( (uint16_t)newval.i_int <=
+          p_input->stream.pp_areas[i_area_id]->i_part_nb ) )
+    {
+        input_area_t *p_area = p_input->stream.pp_areas[i_area_id];
+        p_input->stream.p_selected_area->i_part = newval.i_int;
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+        input_ChangeArea( p_input, p_area );
+        input_SetStatus( p_input, INPUT_STATUS_PLAY );
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+    }
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    return VLC_SUCCESS;
+}
+
+static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
+                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    input_thread_t *p_input = (input_thread_t *)p_this;
+    unsigned int i;
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+    /* Unselect old ES */
+    for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
+    {
+        if( p_input->stream.pp_es[i]->i_id == oldval.i_int &&
+            p_input->stream.pp_es[i]->p_decoder_fifo != NULL )
+        {
+            input_UnselectES( p_input, p_input->stream.pp_es[i] );
+        }
+    }
+
+    /* Select new ES */
+    for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
+    {
+        if( p_input->stream.pp_es[i]->i_id == newval.i_int &&
+            p_input->stream.pp_es[i]->p_decoder_fifo == NULL )
+        {
+            input_SelectES( p_input, p_input->stream.pp_es[i] );
+        }
+    }
+
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    return VLC_SUCCESS;
+}