]> git.sesse.net Git - vlc/blobdiff - src/input/var.c
demux: dash: return meta from manifest
[vlc] / src / input / var.c
index 4e7b712be8d37f50b7b7cab0c0599f7d1f3fa591..258b5f4584433a78de0ad708f4f2ee0cc75efc90 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * var.c: object variables for input thread
  *****************************************************************************
- * Copyright (C) 2004-2007 the VideoLAN team
+ * Copyright (C) 2004-2007 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -88,8 +88,6 @@ static const vlc_input_callback_t p_input_callbacks[] =
 {
     CALLBACK( "state", StateCallback ),
     CALLBACK( "rate", RateCallback ),
-    CALLBACK( "rate-slower", RateCallback ),
-    CALLBACK( "rate-faster", RateCallback ),
     CALLBACK( "position", PositionCallback ),
     CALLBACK( "position-offset", PositionCallback ),
     CALLBACK( "time", TimeCallback ),
@@ -138,13 +136,7 @@ void input_ControlVarInit ( input_thread_t *p_input )
     var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
 
     /* Rate */
-    var_Create( p_input, "rate", VLC_VAR_FLOAT );
-    val.f_float = (float)INPUT_RATE_DEFAULT / (float)p_input->p->i_rate;
-    var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
-
-    var_Create( p_input, "rate-slower", VLC_VAR_VOID );
-
-    var_Create( p_input, "rate-faster", VLC_VAR_VOID );
+    var_Create( p_input, "rate", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
 
     var_Create( p_input, "frame-next", VLC_VAR_VOID );
 
@@ -176,7 +168,7 @@ void input_ControlVarInit ( input_thread_t *p_input )
     var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
 
     /* Programs */
-    var_Create( p_input, "programs", VLC_VAR_LIST | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "programs", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     text.psz_string = _("Programs");
     var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );
 
@@ -215,10 +207,12 @@ void input_ControlVarInit ( input_thread_t *p_input )
 
     /* Spu ES */
     var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
-    text.psz_string = _("Subtitles Track");
+    text.psz_string = _("Subtitle Track");
     var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
 
-    var_Create( p_input, "sub-margin", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_input, "spu-choice", VLC_VAR_INTEGER );
+    val.i_int = -1;
+    var_Change( p_input, "spu-choice", VLC_VAR_SETVALUE, &val, NULL );
 
     /* Special read only objects variables for intf */
     var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
@@ -295,6 +289,8 @@ void input_ControlVarNavigation( input_thread_t *p_input )
     if( !val.psz_string )
         return;
 
+    var_Change( p_input, "title", VLC_VAR_CLEARCHOICES, NULL, NULL );
+
     for( i = 0; i < p_input->p->i_title; i++ )
     {
         vlc_value_t val2, text2;
@@ -308,16 +304,26 @@ void input_ControlVarNavigation( input_thread_t *p_input )
         var_AddCallback( p_input, val.psz_string,
                          NavigationCallback, (void *)(intptr_t)i );
 
+        char psz_length[MSTRTIME_MAX_SIZE + sizeof(" []")] = "";
+        if( p_input->p->title[i]->i_length > 0 )
+        {
+            strcpy( psz_length, " [" );
+            secstotimestr( &psz_length[2], p_input->p->title[i]->i_length / CLOCK_FREQ );
+            strcat( psz_length, "]" );
+        }
+
         if( p_input->p->title[i]->psz_name == NULL ||
             *p_input->p->title[i]->psz_name == '\0' )
         {
-            if( asprintf( &text.psz_string, _("Title %i"),
-                      i + p_input->p->i_title_offset ) == -1 )
+            if( asprintf( &text.psz_string, _("Title %i%s"),
+                          i + p_input->p->i_title_offset, psz_length ) == -1 )
                 continue;
         }
         else
         {
-            text.psz_string = strdup( p_input->p->title[i]->psz_name );
+            if( asprintf( &text.psz_string, "%s%s",
+                          p_input->p->title[i]->psz_name, psz_length ) == -1 )
+                continue;
         }
         var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
 
@@ -429,13 +435,15 @@ void input_ConfigVarInit ( input_thread_t *p_input )
                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
         var_Create( p_input, "sub-language",
                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
+        var_Create( p_input, "menu-language",
+                    VLC_VAR_STRING|VLC_VAR_DOINHERIT );
 
         var_Create( p_input, "audio-track-id",
                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
         var_Create( p_input, "sub-track-id",
                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
 
-        var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
+        var_Create( p_input, "sub-file", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
         var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
                     VLC_VAR_DOINHERIT );
         var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
@@ -566,68 +574,10 @@ static int RateCallback( 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;
-    VLC_UNUSED(oldval); VLC_UNUSED(p_data);
-
-    static const int ppi_factor[][2] = {
-        {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
-        {1,1},
-        {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
-        {0,0}
-    };
+    VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
 
-    int i;
-    int i_idx;
-    float f_rate = var_GetFloat( p_input, "rate" );
-    float f_sign = f_rate >= 0 ? +1. : -1.;
-    float f_error;
-
-    /* Determine the factor closest to the current rate */
-    f_error = 1E20;
-    i_idx = -1;
-    for( i = 0; ppi_factor[i][0] != 0; i++ )
-    {
-        const float f_test_r = (float)ppi_factor[i][0] / ppi_factor[i][1];
-        const float f_test_e = fabs( fabs( f_rate ) - f_test_r );
-        if( f_test_e < f_error )
-        {
-            i_idx = i;
-            f_error = f_test_e;
-        }
-    }
-
-    assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
-
-    float f_new_rate;
-    const float f_rate_min = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MAX;
-    const float f_rate_max = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MIN;
-
-    if( !strcmp( psz_cmd, "rate-slower" ) )
-    {
-        if( i_idx > 0 )
-            f_new_rate = (float)ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
-        else
-            f_new_rate = f_rate_min;
-        f_new_rate *= f_sign;
-
-        var_SetFloat( p_input, "rate", f_new_rate );
-    }
-    else if( !strcmp( psz_cmd, "rate-faster" ) )
-    {
-        if( ppi_factor[i_idx+1][0] > 0 )
-            f_new_rate = (float)ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
-        else
-            f_new_rate = f_rate_max;
-        f_new_rate *= f_sign;
-
-        var_SetFloat( p_input, "rate", f_new_rate );
-    }
-    else
-    {
-        /* Problem with this way: the "rate" variable is updated after the
-         * input thread did the change */
-        newval.i_int = INPUT_RATE_DEFAULT / newval.f_float;
-        input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
-    }
+    newval.i_int = INPUT_RATE_DEFAULT / newval.f_float;
+    input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
 
     return VLC_SUCCESS;
 }
@@ -642,17 +592,17 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
     if( !strcmp( psz_cmd, "position-offset" ) )
     {
         float f_position = var_GetFloat( p_input, "position" ) + newval.f_float;
-        if( f_position < 0.0 )
-            f_position = 0.0;
-        else if( f_position > 1.0 )
-            f_position = 1.0;
+        if( f_position < 0.f )
+            f_position = 0.f;
+        else if( f_position > 1.f )
+            f_position = 1.f;
         var_SetFloat( p_this, "position", f_position );
     }
     else
     {
         /* Update "length" for better intf behavour */
         const mtime_t i_length = var_GetTime( p_input, "length" );
-        if( i_length > 0 && newval.f_float >= 0.0 && newval.f_float <= 1.0 )
+        if( i_length > 0 && newval.f_float >= 0.f && newval.f_float <= 1.f )
         {
             vlc_value_t val;
 
@@ -689,6 +639,11 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
 
             val.f_float = (double)newval.i_time/(double)i_length;
             var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
+            /*
+             * Notify the intf that a new event has been occurred.
+             * XXX this is a bit hackish but it's the only way to do it now.
+             */
+            var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
         }
 
         /* */