]> git.sesse.net Git - vlc/blobdiff - src/input/input_ext-plugins.c
* ./include/vlc_common.h: defined the INSERT_ELEM and REMOVE_ELEM macros
[vlc] / src / input / input_ext-plugins.c
index 6da18868660f622d85bf4edab8f270f8e51b144c..fcc5ae1566d597ff964cb3f6bf3cd10915f52135 100644 (file)
@@ -2,7 +2,7 @@
  * input_ext-plugins.c: useful functions for access and demux plug-ins
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: input_ext-plugins.c,v 1.12 2002/06/01 18:04:49 sam Exp $
+ * $Id: input_ext-plugins.c,v 1.19 2002/10/26 15:24:19 gbazin Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -91,7 +91,7 @@
 /*****************************************************************************
  * data_buffer_t: shared data type
  *****************************************************************************/
-struct data_buffer_s
+struct data_buffer_t
 {
     data_buffer_t * p_next;
 
@@ -113,7 +113,7 @@ struct                                                                      \
     unsigned int i_depth;                                                   \
 } NAME;
 
-struct input_buffers_s
+struct input_buffers_t
 {
     vlc_mutex_t lock;
     PACKETS_LIFO( pes_packet_t, pes )
@@ -206,8 +206,6 @@ static inline data_buffer_t * NewBuffer( input_buffers_t * p_buffers,
     /* Safety check */
     if( p_buffers->i_allocated > INPUT_MAX_ALLOCATION )
     {
-//X        intf_Err( "INPUT_MAX_ALLOCATION reached (%d)",
-//X                     p_buffers->i_allocated );
         return NULL;
     } 
 
@@ -226,7 +224,6 @@ static inline data_buffer_t * NewBuffer( input_buffers_t * p_buffers,
             p_buf = malloc( sizeof(input_buffers_t) + i_size );
             if( p_buf == NULL )
             {
-//X                intf_ErrMsg( "Out of memory" );
                 return NULL;
             }
             p_buf->i_size = i_size;
@@ -239,7 +236,6 @@ static inline data_buffer_t * NewBuffer( input_buffers_t * p_buffers,
         p_buf = malloc( sizeof(input_buffers_t) + i_size );
         if( p_buf == NULL )
         {
-//X            intf_ErrMsg( "Out of memory" );
             return NULL;
         }
         p_buf->i_size = i_size;
@@ -250,7 +246,7 @@ static inline data_buffer_t * NewBuffer( input_buffers_t * p_buffers,
     p_buf->p_next = NULL;
     p_buf->i_refcount = 0;
 
-    return( p_buf );
+    return p_buf;
 }
 
 data_buffer_t * input_NewBuffer( input_buffers_t * p_buffers, size_t i_size )
@@ -318,7 +314,6 @@ static inline data_packet_t * ShareBuffer( input_buffers_t * p_buffers,
         p_data = malloc( sizeof(data_packet_t) );
         if( p_data == NULL )
         {
-//X            intf_ErrMsg( "Out of memory" );
             return NULL;
         }
     }
@@ -331,7 +326,7 @@ static inline data_packet_t * ShareBuffer( input_buffers_t * p_buffers,
     p_data->p_payload_end = p_data->p_demux_start + p_buf->i_size;
     p_buf->i_refcount++;
 
-    return( p_data );
+    return p_data;
 }
 
 data_packet_t * input_ShareBuffer( input_buffers_t * p_buffers,
@@ -352,9 +347,11 @@ data_packet_t * input_ShareBuffer( input_buffers_t * p_buffers,
 static inline data_packet_t * NewPacket( input_buffers_t * p_buffers,
                                          size_t i_size )
 {
-    data_buffer_t * p_buf = NewBuffer( p_buffers, i_size );
+    data_buffer_t * p_buf;
     data_packet_t * p_data;
 
+    p_buf = NewBuffer( p_buffers, i_size );
+
     if( p_buf == NULL )
     {
         return( NULL );
@@ -434,7 +431,6 @@ static inline pes_packet_t * NewPES( input_buffers_t * p_buffers )
         p_pes = malloc( sizeof(pes_packet_t) );
         if( p_pes == NULL )
         {
-//X            intf_ErrMsg( "Out of memory" );
             return NULL;
         }
     }
@@ -524,7 +520,8 @@ ssize_t input_FillBuffer( input_thread_t * p_input )
                        i_remains + p_input->i_bufsize );
     if( p_buf == NULL )
     {
-        return( -1 );
+        msg_Err( p_input, "failed allocating a new buffer (decoder stuck?)" );
+        return -1;
     }
     p_buf->i_refcount = 1;
 
@@ -543,11 +540,11 @@ ssize_t input_FillBuffer( input_thread_t * p_input )
     vlc_mutex_unlock( &p_input->p_method_data->lock );
 
     i_ret = p_input->pf_read( p_input,
-                             (byte_t *)p_buf + sizeof(data_buffer_t)
-                              + i_remains,
-                             p_input->i_bufsize );
-
+                              (byte_t *)p_buf + sizeof(data_buffer_t)
+                               + i_remains,
+                              p_input->i_bufsize );
     if( i_ret < 0 ) i_ret = 0;
+
     p_input->p_data_buffer = p_buf;
     p_input->p_current_data = (byte_t *)p_buf + sizeof(data_buffer_t);
     p_input->p_last_data = p_input->p_current_data + i_remains + i_ret;
@@ -602,6 +599,11 @@ ssize_t input_SplitBuffer( input_thread_t * p_input,
         }
     }
 
+    if ( !i_size )
+    {
+        return 0;
+    }
+
     *pp_data = input_ShareBuffer( p_input->p_method_data,
                                   p_input->p_data_buffer );
 
@@ -611,6 +613,11 @@ ssize_t input_SplitBuffer( input_thread_t * p_input,
 
     p_input->p_current_data += i_size;
 
+    /* Update stream position */
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+    p_input->stream.p_selected_area->i_tell += i_size;
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
     return( i_size );
 }
 
@@ -663,11 +670,12 @@ void input_AccessEnd( input_thread_t * p_input )
 /*****************************************************************************
  * input_FDClose: close the target
  *****************************************************************************/
-void input_FDClose( input_thread_t * p_input )
+void __input_FDClose( vlc_object_t * p_this )
 {
+    input_thread_t * p_input = (input_thread_t *)p_this;
     input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
 
-    msg_Info( p_input, "closing `%s/%s:%s'", 
+    msg_Info( p_input, "closing `%s/%s://%s'", 
               p_input->psz_access, p_input->psz_demux, p_input->psz_name );
  
     close( p_access_data->i_handle );
@@ -677,11 +685,12 @@ void input_FDClose( input_thread_t * p_input )
 /*****************************************************************************
  * input_FDNetworkClose: close a network target
  *****************************************************************************/
-void input_FDNetworkClose( input_thread_t * p_input )
+void __input_FDNetworkClose( vlc_object_t * p_this )
 {
+    input_thread_t * p_input = (input_thread_t *)p_this;
     input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
 
-    msg_Info( p_input, "closing network `%s/%s:%s'", 
+    msg_Info( p_input, "closing network `%s/%s://%s'", 
               p_input->psz_access, p_input->psz_demux, p_input->psz_name );
  
 #ifdef WIN32
@@ -702,13 +711,6 @@ ssize_t input_FDRead( input_thread_t * p_input, byte_t * p_buffer, size_t i_len
  
     ssize_t i_ret = read( p_access_data->i_handle, p_buffer, i_len );
  
-    if( i_ret > 0 )
-    {
-        vlc_mutex_lock( &p_input->stream.stream_lock );
-        p_input->stream.p_selected_area->i_tell += i_ret;
-        vlc_mutex_unlock( &p_input->stream.stream_lock );
-    }
     if( i_ret < 0 )
     {
         msg_Err( p_input, "read failed (%s)", strerror(errno) );