]> git.sesse.net Git - vlc/blobdiff - src/input/input_ext-intf.c
* input.c: don't add subtitle track twice when using --sub-file and
[vlc] / src / input / input_ext-intf.c
index bf410feef283f5f0506296b842490a6021644472..785af38b5613a92c67c0711e61bc8a3973c3c32d 100644 (file)
@@ -1,16 +1,16 @@
 /*****************************************************************************
  * input_ext-intf.c: services to the interface
  *****************************************************************************
- * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ext-intf.c,v 1.43 2002/11/11 14:39:12 sam Exp $
+ * Copyright (C) 1998-2004 VideoLAN
+ * $Id: input_ext-intf.c,v 1.56 2004/01/25 17:16:05 zorglub Exp $
  *
- * Authors: Christophe Massiot <massiot@via.ecp.fr>
+ * Author: Christophe Massiot <massiot@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
  * (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
@@ -71,54 +71,60 @@ void __input_SetStatus( vlc_object_t * p_this, int i_mode )
         break;
 
     case INPUT_STATUS_FASTER:
-        /* If we are already going too fast, go back to default rate */
-        if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
+        if( p_input->stream.control.i_rate * 4 <= DEFAULT_RATE )
         {
-            p_input->stream.i_new_status = PLAYING_S;
-            msg_Dbg( p_input, "playing at normal rate" );
+            msg_Dbg( p_input, "can not play any faster" );
         }
         else
         {
             p_input->stream.i_new_status = FORWARD_S;
+            p_input->stream.i_new_rate =
+                                    p_input->stream.control.i_rate / 2;
 
-            if( p_input->stream.control.i_rate < DEFAULT_RATE
-                    && p_input->stream.control.i_status == FORWARD_S )
+            if ( p_input->stream.i_new_rate < DEFAULT_RATE )
             {
-                p_input->stream.i_new_rate =
-                                    p_input->stream.control.i_rate / 2;
+                msg_Dbg( p_input, "playing at %i:1 fast forward",
+                     DEFAULT_RATE / p_input->stream.i_new_rate );
             }
-            else
+            else if ( p_input->stream.i_new_rate > DEFAULT_RATE )
             {
-                p_input->stream.i_new_rate = DEFAULT_RATE / 2;
+                msg_Dbg( p_input, "playing at 1:%i slow motion",
+                      p_input->stream.i_new_rate / DEFAULT_RATE );
+            }
+            else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
+            {
+                p_input->stream.i_new_status = PLAYING_S;
+                msg_Dbg( p_input, "playing at normal rate" );
             }
-            msg_Dbg( p_input, "playing at %i:1 fast forward",
-                     DEFAULT_RATE / p_input->stream.i_new_rate );
         }
         break;
 
     case INPUT_STATUS_SLOWER:
-        /* If we are already going too slow, go back to default rate */
         if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
         {
-            p_input->stream.i_new_status = PLAYING_S;
-            msg_Dbg( p_input, "playing at normal rate" );
+            msg_Dbg( p_input, "can not play any slower" );
         }
         else
         {
             p_input->stream.i_new_status = FORWARD_S;
+            p_input->stream.i_new_rate =
+                                    p_input->stream.control.i_rate * 2;
 
-            if( p_input->stream.control.i_rate > DEFAULT_RATE
-                    && p_input->stream.control.i_status == FORWARD_S )
+            if ( p_input->stream.i_new_rate < DEFAULT_RATE )
             {
-                p_input->stream.i_new_rate =
-                                    p_input->stream.control.i_rate * 2;
+                msg_Dbg( p_input, "playing at %i:1 fast forward",
+                     DEFAULT_RATE / p_input->stream.i_new_rate );
             }
-            else
+            else if ( p_input->stream.i_new_rate > DEFAULT_RATE )
             {
-                p_input->stream.i_new_rate = DEFAULT_RATE * 2;
-            }
-            msg_Dbg( p_input, "playing at 1:%i slow motion",
+                msg_Dbg( p_input, "playing at 1:%i slow motion",
                       p_input->stream.i_new_rate / DEFAULT_RATE );
+            }
+            else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
+            {
+                p_input->stream.i_new_status = PLAYING_S;
+                msg_Dbg( p_input, "playing at normal rate" );
+            }
         }
         break;
 
@@ -132,6 +138,57 @@ void __input_SetStatus( vlc_object_t * p_this, int i_mode )
     vlc_object_release( p_input );
 }
 
+void __input_SetRate( vlc_object_t * p_this, int i_rate )
+{
+    input_thread_t *p_input;
+
+    p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
+
+    if( p_input == NULL )
+    {
+        msg_Err( p_this, "no input found" );
+        return;
+    }
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+    if( i_rate * 8 < DEFAULT_RATE )
+    {
+        msg_Dbg( p_input, "can not play faster than 8x" );
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+        return;
+    }
+    if( i_rate > DEFAULT_RATE * 8 )
+    {
+        msg_Dbg( p_input, "can not play slower than 1/8x" );
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+        return;
+    }
+    p_input->stream.i_new_status = FORWARD_S;
+    p_input->stream.i_new_rate = i_rate;
+
+    if ( p_input->stream.i_new_rate < DEFAULT_RATE )
+    {
+        msg_Dbg( p_input, "playing at %i:1 fast forward",
+             DEFAULT_RATE / p_input->stream.i_new_rate );
+    }
+    else if ( p_input->stream.i_new_rate > DEFAULT_RATE )
+    {
+        msg_Dbg( p_input, "playing at 1:%i slow motion",
+              p_input->stream.i_new_rate / DEFAULT_RATE );
+    }
+    else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
+    {
+        p_input->stream.i_new_status = PLAYING_S;
+        msg_Dbg( p_input, "playing at normal rate" );
+    }
+
+    vlc_cond_signal( &p_input->stream.stream_wait );
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    vlc_object_release( p_input );
+}
+
 /*****************************************************************************
  * input_Seek: changes the stream postion
  *****************************************************************************/
@@ -139,8 +196,8 @@ void __input_Seek( vlc_object_t * p_this, off_t i_position, int i_whence )
 {
     input_thread_t *p_input;
 
-    char psz_time1[OFFSETTOTIME_MAX_SIZE];
-    char psz_time2[OFFSETTOTIME_MAX_SIZE];
+    char psz_time1[MSTRTIME_MAX_SIZE];
+    char psz_time2[MSTRTIME_MAX_SIZE];
 
     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
 
@@ -250,11 +307,7 @@ char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
     if( p_input->stream.i_mux_rate )
     {
         i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
-        snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
-                 (int) (i_seconds / (60 * 60)),
-                 (int) (i_seconds / 60 % 60),
-                 (int) (i_seconds % 60) );
-        return( psz_buffer );
+        return secstotimestr( psz_buffer, i_seconds );
     }
     else
     {
@@ -272,12 +325,12 @@ char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
  *****************************************************************************/
 void input_DumpStream( input_thread_t * p_input )
 {
-    int         i, j;
-    char        psz_time1[OFFSETTOTIME_MAX_SIZE];
-    char        psz_time2[OFFSETTOTIME_MAX_SIZE];
+    char psz_time1[MSTRTIME_MAX_SIZE];
+    char psz_time2[MSTRTIME_MAX_SIZE];
+    unsigned int i, j;
 
 #define S   p_input->stream
-    msg_Dbg( p_input, "dumping stream ID 0x%x [OK:%d/D:%d]", S.i_stream_id,
+    msg_Dbg( p_input, "dumping stream ID 0x%x [OK:%ld/D:%ld]", S.i_stream_id,
              S.c_packets_read, S.c_packets_trashed );
     if( S.b_seekable )
         msg_Dbg( p_input, "seekable stream, position: "I64Fd"/"I64Fd" (%s/%s)",
@@ -299,10 +352,10 @@ void input_DumpStream( input_thread_t * p_input )
         for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
         {
 #define ES  p_input->stream.pp_programs[i]->pp_es[j]
-            msg_Dbg( p_input,
-                     "ES 0x%x, stream 0x%x, fourcc `%4.4s', %s [OK:%d/ERR:%d]",
+            msg_Dbg( p_input, "ES 0x%x, "
+                     "stream 0x%x, fourcc `%4.4s', %s [OK:%ld/ERR:%ld]",
                      ES->i_id, ES->i_stream_id, (char*)&ES->i_fourcc,
-                     ES->p_decoder_fifo != NULL ? "selected" : "not selected",
+                     ES->p_dec != NULL ? "selected" : "not selected",
                      ES->c_packets, ES->c_invalid_packets );
 #undef ES
         }
@@ -355,10 +408,11 @@ int input_ChangeArea( input_thread_t * p_input, input_area_t * p_area )
 /****************************************************************************
  * input_ChangeProgram: interface request a program change
  ****************************************************************************/
-int input_ChangeProgram( input_thread_t * p_input, u16 i_program_number )
+int input_ChangeProgram( input_thread_t * p_input, uint16_t i_program_number )
 {
     pgrm_descriptor_t *       p_program;
-    
+    vlc_value_t val;
+
     vlc_mutex_lock( &p_input->stream.stream_lock );
 
     p_program = input_FindProgram( p_input, i_program_number );
@@ -370,9 +424,13 @@ int input_ChangeProgram( input_thread_t * p_input, u16 i_program_number )
     }
 
     p_input->stream.p_new_program = p_program;
-    
+
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
+    /* Update the navigation variables without triggering a callback */
+    val.i_int = i_program_number;
+    var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
+
     return 0;
 }