]> git.sesse.net Git - vlc/blobdiff - src/input/input_ext-intf.c
* src/misc/variables.c, ALL: improvements to the object variables api.
[vlc] / src / input / input_ext-intf.c
index d4f369d10497d2781d0c53853246ef0bdfad9fd6..c1f89a8ae752afb89efe5bae5a4acecd74819c61 100644 (file)
@@ -2,7 +2,7 @@
  * input_ext-intf.c: services to the interface
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ext-intf.c,v 1.35 2002/03/05 17:46:33 stef Exp $
+ * $Id: input_ext-intf.c,v 1.49 2003/05/04 22:42:17 gbazin Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -10,7 +10,7 @@
  * 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
@@ -25,9 +25,8 @@
  * Preamble
  *****************************************************************************/
 #include <string.h>                                    /* memcpy(), memset() */
-#include <sys/types.h>                                              /* off_t */
 
-#include <videolan/vlc.h>
+#include <vlc/vlc.h>
 
 #include "stream_control.h"
 #include "input_ext-dec.h"
 /*****************************************************************************
  * input_SetStatus: change the reading status
  *****************************************************************************/
-void input_SetStatus( input_thread_t * p_input, int i_mode )
+void __input_SetStatus( vlc_object_t * p_this, int i_mode )
 {
+    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 );
 
     switch( i_mode )
@@ -46,44 +55,48 @@ void input_SetStatus( input_thread_t * p_input, int i_mode )
     case INPUT_STATUS_END:
         p_input->stream.i_new_status = PLAYING_S;
         p_input->b_eof = 1;
-        intf_WarnMsg( 1, "input: end of stream" );
+        msg_Dbg( p_input, "end of stream" );
         break;
 
     case INPUT_STATUS_PLAY:
         p_input->stream.i_new_status = PLAYING_S;
-        intf_WarnMsg( 1, "input: playing at normal rate" );
+        msg_Dbg( p_input, "playing at normal rate" );
         break;
 
     case INPUT_STATUS_PAUSE:
         /* XXX: we don't need to check i_status, because input_clock.c
          * does it for us */
         p_input->stream.i_new_status = PAUSE_S;
-        intf_WarnMsg( 1, "input: toggling pause" );
+        msg_Dbg( p_input, "toggling pause" );
         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 )
         {
-            p_input->stream.i_new_status = PLAYING_S;
-            intf_WarnMsg( 1, "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 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
+            else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
             {
-                p_input->stream.i_new_rate = DEFAULT_RATE / 2;
+                p_input->stream.i_new_status = PLAYING_S;
+                msg_Dbg( p_input, "playing at normal rate" );
             }
-            intf_WarnMsg( 1, "input: playing at %i:1 fast forward",
-                          DEFAULT_RATE / p_input->stream.i_new_rate );
         }
         break;
 
@@ -91,25 +104,29 @@ void input_SetStatus( input_thread_t * p_input, int i_mode )
         /* 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;
-            intf_WarnMsg( 1, "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 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
+            else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
             {
-                p_input->stream.i_new_rate = DEFAULT_RATE * 2;
+                p_input->stream.i_new_status = PLAYING_S;
+                msg_Dbg( p_input, "playing at normal rate" );
             }
-            intf_WarnMsg( 1, "input: playing at 1:%i slow motion",
-                          p_input->stream.i_new_rate / DEFAULT_RATE );
         }
         break;
 
@@ -119,27 +136,111 @@ void input_SetStatus( input_thread_t * p_input, int i_mode )
 
     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
  *****************************************************************************/
-void input_Seek( input_thread_t * p_input, off_t i_position )
+void __input_Seek( vlc_object_t * p_this, off_t i_position, int i_whence )
 {
-    char        psz_time1[OFFSETTOTIME_MAX_SIZE];
-    char        psz_time2[OFFSETTOTIME_MAX_SIZE];
+    input_thread_t *p_input;
+
+    char psz_time1[OFFSETTOTIME_MAX_SIZE];
+    char psz_time2[OFFSETTOTIME_MAX_SIZE];
+
+    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 );
-    p_input->stream.p_selected_area->i_seek = i_position;
 
-    intf_WarnMsg( 3, "input: seeking position %lld/%lld (%s/%s)", i_position,
-                  p_input->stream.p_selected_area->i_size,
-                  input_OffsetToTime( p_input, psz_time1, i_position ),
-                  input_OffsetToTime( p_input, psz_time2,
-                              p_input->stream.p_selected_area->i_size ) );
+#define A p_input->stream.p_selected_area
+    switch( i_whence & 0x30 )
+    {
+        case INPUT_SEEK_SECONDS:
+            i_position *= (off_t)50 * p_input->stream.i_mux_rate;
+            break;
+
+        case INPUT_SEEK_PERCENT:
+            i_position = A->i_size * i_position / (off_t)100;
+            break;
+
+        case INPUT_SEEK_BYTES:
+        default:
+            break;
+    }
+
+    switch( i_whence & 0x03 )
+    {
+        case INPUT_SEEK_CUR:
+            A->i_seek = A->i_tell + i_position;
+            break;
+
+        case INPUT_SEEK_END:
+            A->i_seek = A->i_size + i_position;
+            break;
+
+        case INPUT_SEEK_SET:
+        default:
+            A->i_seek = i_position;
+            break;
+    }
+
+    if( A->i_seek < 0 )
+    {
+        A->i_seek = 0;
+    }
+    else if( A->i_seek > A->i_size )
+    {
+        A->i_seek = A->i_size;
+    }
+
+    msg_Dbg( p_input, "seeking position "I64Fd"/"I64Fd" (%s/%s)",
+             A->i_seek, A->i_size,
+             input_OffsetToTime( p_input, psz_time1, i_position ),
+             input_OffsetToTime( p_input, psz_time2, A->i_size ) );
+#undef A
 
     vlc_cond_signal( &p_input->stream.stream_wait );
     vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    vlc_object_release( p_input );
+}
+
+/*****************************************************************************
+ * input_Tell: requests the stream postion
+ *****************************************************************************/
+void __input_Tell( vlc_object_t * p_this, stream_position_t * p_position )
+{
+    input_thread_t *p_input;
+
+    p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
+
+    if( p_input == NULL )
+    {
+        p_position->i_tell = 0;
+        p_position->i_size = 0;
+        p_position->i_mux_rate = 0;
+        msg_Err( p_this, "no input found" );
+        return;
+    }
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+#define A p_input->stream.p_selected_area
+    p_position->i_tell = A->i_tell;
+    p_position->i_size = A->i_size;
+    p_position->i_mux_rate = p_input->stream.i_mux_rate;
+#undef A
+
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+    vlc_object_release( p_input );
 }
 
 /*****************************************************************************
@@ -179,110 +280,43 @@ 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[OFFSETTOTIME_MAX_SIZE];
+    char psz_time2[OFFSETTOTIME_MAX_SIZE];
+    unsigned int i, j;
 
 #define S   p_input->stream
-    intf_Msg( "input info: Dumping stream ID 0x%x [OK:%d/D:%d]", S.i_stream_id,
-              S.c_packets_read, S.c_packets_trashed );
+    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 )
-        intf_Msg( "input info: seekable stream, position: %lld/%lld (%s/%s)",
-                  S.p_selected_area->i_tell, S.p_selected_area->i_size,
-                  input_OffsetToTime( p_input, psz_time1,
-                                      S.p_selected_area->i_tell ),
-                  input_OffsetToTime( p_input, psz_time2,
-                                      S.p_selected_area->i_size ) );
+        msg_Dbg( p_input, "seekable stream, position: "I64Fd"/"I64Fd" (%s/%s)",
+                 S.p_selected_area->i_tell, S.p_selected_area->i_size,
+                 input_OffsetToTime( p_input, psz_time1,
+                                     S.p_selected_area->i_tell ),
+                 input_OffsetToTime( p_input, psz_time2,
+                                     S.p_selected_area->i_size ) );
     else
-        intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
-                  "pace un-controlled" );
+        msg_Dbg( p_input, "pace %scontrolled", S.b_pace_control ? "" : "un-" );
 #undef S
     for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
     {
 #define P   p_input->stream.pp_programs[i]
-        intf_Msg( "input info: Dumping program 0x%x, version %d (%s)",
-                  P->i_number, P->i_version,
-                  P->b_is_ok ? "complete" : "partial" );
+        msg_Dbg( p_input, "dumping program 0x%x, version %d (%s)",
+                 P->i_number, P->i_version,
+                 P->b_is_ok ? "complete" : "partial" );
 #undef P
         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]
-            intf_Msg( "input info: ES 0x%x, stream 0x%x, type 0x%x, %s [OK:%d/ERR:%d]",
-                      ES->i_id, ES->i_stream_id, ES->i_type,
-                      ES->p_decoder_fifo != NULL ? "selected" : "not selected",
-                      ES->c_packets, ES->c_invalid_packets );
+            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->c_packets, ES->c_invalid_packets );
 #undef ES
         }
     }
 }
 
-/*****************************************************************************
- * input_ChangeES: answers to a user request with calls to (Un)SelectES
- *****************************************************************************
- * Useful since the interface plugins know p_es
- * This functon is deprecated, use input_ToggleEs instead.
- *****************************************************************************/
-int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
-                    u8 i_cat )
-{
-    int                     i_index;
-    int                     i;
-
-    i_index = -1;
-
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-
-    for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
-    {
-        if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
-        {
-            i_index = i;
-            break;
-        }
-    }
-
-
-    if( p_es != NULL )
-    {
-
-    
-        if( i_index != -1 )
-        {
-            
-            if( p_input->stream.pp_selected_es[i_index] != p_es )
-            {
-                input_UnselectES( p_input,
-                                  p_input->stream.pp_selected_es[i_index] );
-                input_SelectES( p_input, p_es );
-                intf_WarnMsg( 3, "input info: es selected -> %s (0x%x)",
-                                                p_es->psz_desc, p_es->i_id );
-            }
-        }
-        else
-        {
-            input_SelectES( p_input, p_es );
-            intf_WarnMsg( 3, "input info: es selected -> %s (0x%x)",
-                          p_es->psz_desc, p_es->i_id );
-        }
-    }
-    else
-    {
-        if( i_index != -1 )
-        {
-            intf_WarnMsg( 3, "input info: es unselected -> %s (0x%x)",
-                          p_input->stream.pp_selected_es[i_index]->psz_desc,
-                          p_input->stream.pp_selected_es[i_index]->i_id );
-
-            input_UnselectES( p_input,
-                              p_input->stream.pp_selected_es[i_index] );
-        }
-    }
-
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-    return 0;
-}
-
 /*****************************************************************************
  * input_ToggleES: answers to a user request with calls to (Un)SelectES
  *****************************************************************************
@@ -291,9 +325,8 @@ int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
  * b_select is a boolean to know if we have to select or unselect ES
  *****************************************************************************/
 int input_ToggleES( input_thread_t * p_input, es_descriptor_t * p_es,
-                    boolean_t b_select )
+                    vlc_bool_t b_select )
 {
-
     vlc_mutex_lock( &p_input->stream.stream_lock );
 
     if( p_es != NULL )
@@ -330,24 +363,29 @@ 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 );
 
     if ( p_program == NULL )
     {
-        intf_ErrMsg("input: Could not find selected program");
+        msg_Err( p_input, "could not find selected program" );
         return -1;
     }
 
     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;
 }
 
@@ -362,8 +400,8 @@ int input_ToggleGrayscale( input_thread_t * p_input )
     p_input->stream.control.b_grayscale =
                     !p_input->stream.control.b_grayscale;
 
-    intf_WarnMsg( 3, "input warning: changing to %s output",
-            p_input->stream.control.b_grayscale ? "grayscale" : "color" );
+    msg_Dbg( p_input, "changing to %s output",
+             p_input->stream.control.b_grayscale ? "grayscale" : "color" );
 
     vlc_mutex_unlock( &p_input->stream.control.control_lock );
 
@@ -380,25 +418,11 @@ int input_ToggleMute( input_thread_t * p_input )
     vlc_mutex_lock( &p_input->stream.stream_lock );
     p_input->stream.b_new_mute = !p_input->stream.control.b_mute;
 
-    intf_WarnMsg( 3, "input warning: %s mute mode",
-            p_input->stream.control.b_mute ? "activating" : "deactivating" );
+    msg_Dbg( p_input, "%s mute mode",
+             p_input->stream.control.b_mute ? "activating" : "deactivating" );
 
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
     return 0;
 }
 
-/****************************************************************************
- * input_SetSMP: change the number of video decoder threads
- ****************************************************************************/
-int input_SetSMP( input_thread_t * p_input, int i_smp )
-{
-    /* No need to warn the input thread since only the decoders
-     * worry about it. */
-    vlc_mutex_lock( &p_input->stream.control.control_lock );
-    p_input->stream.control.i_smp = i_smp;
-    vlc_mutex_unlock( &p_input->stream.control.control_lock );
-
-    return 0;
-}
-