]> git.sesse.net Git - vlc/blobdiff - src/input/input_netlist.c
* Added functions and hooks to display dates instead of off_t.
[vlc] / src / input / input_netlist.c
index 816830c43fb3416f4cc91d878b5e40a9a5fed5c8..884377f2c041f9d48ab72f410dc41d03529e0e4b 100644 (file)
@@ -2,7 +2,7 @@
  * input_netlist.c: netlist management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_netlist.c,v 1.23 2000/12/29 14:03:44 henri Exp $
+ * $Id: input_netlist.c,v 1.31 2001/02/14 15:58:29 henri Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org>
  *
@@ -27,7 +27,9 @@
 #include "defs.h"
 
 #include <stdlib.h>
+#include <sys/types.h>
 #include <sys/uio.h>                                         /* struct iovec */
+#include <unistd.h>
 
 #include "config.h"
 #include "common.h"
@@ -39,8 +41,8 @@
 #include "input_ext-intf.h"
 #include "input_ext-dec.h"
 
-#include "input_netlist.h"
 #include "input.h"
+#include "input_netlist.h"
 
 /*****************************************************************************
  * Local prototypes
@@ -50,7 +52,7 @@
  * input_NetlistInit: allocates netlist buffers and init indexes
  *****************************************************************************/
 int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
-                       size_t i_buffer_size )
+                       size_t i_buffer_size, int i_read_once )
 {
     unsigned int i_loop;
     netlist_t * p_netlist;
@@ -65,6 +67,8 @@ int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
     
     p_netlist = (netlist_t *) p_input->p_method_data;
     
+    p_netlist->i_read_once = i_read_once;
+    
     /* allocate the buffers */ 
     p_netlist->p_buffers = 
         (byte_t *) malloc(i_buffer_size* i_nb_data );
@@ -105,7 +109,7 @@ int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
     }
     
     p_netlist->p_free_iovec = ( struct iovec * )
-        malloc( (i_nb_data + INPUT_READ_ONCE) * sizeof(struct iovec) );
+        malloc( (i_nb_data + p_netlist->i_read_once) * sizeof(struct iovec) );
     if ( p_netlist->p_free_iovec == NULL )
     {
         intf_ErrMsg ("Unable to malloc in netlist initialization (6)");
@@ -119,12 +123,10 @@ int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
 
         p_netlist->pp_free_data[i_loop]->p_buffer = 
             p_netlist->p_buffers + i_loop * i_buffer_size;
+      
+        p_netlist->pp_free_data[i_loop]->p_payload_start = 
+            p_netlist->pp_free_data[i_loop]->p_buffer;
         
-        //peut-être pas nécessaire ici vu qu'on le fera à chaque fois
-        //dans NewPacket et Getiovec
-    //    p_netlist->pp_free_data[i_loop]->p_payload_start = 
-    //        p_netlist->pp_free_data[i_loop]->p_buffer;
-
         p_netlist->pp_free_data[i_loop]->p_payload_end =
             p_netlist->pp_free_data[i_loop]->p_buffer + i_buffer_size;
     }
@@ -143,7 +145,7 @@ int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
    
         p_netlist->p_free_iovec[i_loop].iov_len = i_buffer_size;
     }
-    
+   
     /* vlc_mutex_init */
     vlc_mutex_init (&p_netlist->lock);
     
@@ -163,19 +165,22 @@ int input_NetlistInit( input_thread_t * p_input, int i_nb_data, int i_nb_pes,
 
 /*****************************************************************************
  * input_NetlistGetiovec: returns an iovec pointer for a readv() operation
+ *****************************************************************************
+ * We return an iovec vector, so that readv can read many packets at a time,
+ * and we set pp_data to direct to the fifo pointer, which will allow us
+ * to get the corresponding data_packet.
  *****************************************************************************/
 struct iovec * input_NetlistGetiovec( void * p_method_data )
 {
     netlist_t * p_netlist;
-    int i_loop;
 
     /* cast */
     p_netlist = ( netlist_t * ) p_method_data;
     
     /* check */
-    if 
+    if( 
      (p_netlist->i_data_end - p_netlist->i_data_start + p_netlist->i_nb_data)
-     %p_netlist->i_nb_data < INPUT_READ_ONCE )
+     %p_netlist->i_nb_data < p_netlist->i_read_once )
     {
         intf_ErrMsg("Empty iovec FIFO. Unable to allocate memory");
         return (NULL);
@@ -185,50 +190,53 @@ struct iovec * input_NetlistGetiovec( void * p_method_data )
      * so, as a solution, we chose to have a FIFO a bit longer
      * than i_nb_data, and copy the begining of the FIFO to its end
      * if the readv needs to go after the end */
-    if( p_netlist->i_nb_data - p_netlist->i_data_start < INPUT_READ_ONCE )
+    if( p_netlist->i_nb_data - p_netlist->i_data_start <
+                                                    p_netlist->i_read_once )
+    {
         memcpy( &p_netlist->p_free_iovec[p_netlist->i_nb_data], 
                 p_netlist->p_free_iovec, 
-                INPUT_READ_ONCE-(p_netlist->i_nb_data-p_netlist->i_data_start)
-                * sizeof(struct iovec *)
+                (p_netlist->i_read_once-
+                    (p_netlist->i_nb_data-p_netlist->i_data_start))
+                    * sizeof(struct iovec)
               );
-    // je suis pas complétement sûr que je fais ce que tu voulais ici ...
-    
-    for (i_loop=0; i_loop<INPUT_READ_ONCE; i_loop++)
-    {
-        p_netlist->pp_free_data[p_netlist->i_data_start]->p_payload_start 
-            = (byte_t *)p_netlist->pp_free_data[p_netlist->i_data_start];
 
-        p_netlist->pp_free_data[p_netlist->i_data_start]->p_payload_end 
-            = p_netlist->pp_free_data[p_netlist->i_data_start]->p_payload_start
-            + p_netlist->i_buffer_size;
     }
-
     return &p_netlist->p_free_iovec[p_netlist->i_data_start];
 
-    // ya un truc qui me pose pb : on va appeler Getiovec puis Mviovec, mais
-    // entre deux un autre thread peut pas venir foutre le brin dans les
-    // i_data_start et stop, du genre avec un newpacket ? 
-    
-    // je suppose qu'on fait pas tout dans une même fonction parce que si le
-    // readv a besoin de moins que INPUT_READ_ONCE on perdrait de la place, mais
-    // est-ce qu'il faut pas laisser le lock à ce moment là et le rendre
-    // à la fin de Mviovec ?
 }
 
 /*****************************************************************************
  * input_NetlistMviovec: move the iovec pointer after a readv() operation
  *****************************************************************************/
-void input_NetlistMviovec( void * p_method_data, size_t i_nb_iovec )
+void input_NetlistMviovec( void * p_method_data, size_t i_nb_iovec,
+                           struct data_packet_s * pp_packets[INPUT_READ_ONCE] )
 {
     netlist_t * p_netlist;
+    unsigned int i_loop = 0;
+    unsigned int i_current;
 
     /* cast */
     p_netlist = (netlist_t *) p_method_data;
     
     /* lock */
     vlc_mutex_lock ( &p_netlist->lock );
-    
+
+    i_current = p_netlist->i_data_start;
+
+
+    /* Fills a table of pointers to packets associated with the io_vec's */
+while (i_loop < i_nb_iovec )
+    {
+        if( i_current >= p_netlist->i_nb_data ) 
+            i_current-=p_netlist->i_nb_data;
+        
+        pp_packets[i_loop] = p_netlist->pp_free_data[i_current];
+
+        i_loop ++;
+        i_current ++;
+    }
+
     p_netlist->i_data_start += i_nb_iovec;
     p_netlist->i_data_start %= p_netlist->i_nb_data;
 
@@ -275,18 +283,13 @@ struct data_packet_s * input_NetlistNewPacket( void * p_method_data,
     /* unlock */
     vlc_mutex_unlock (&p_netlist->lock);
 
-    if (i_buffer_size < p_netlist->i_buffer_size) 
-    {
-        p_return->p_payload_end = p_return->p_payload_start + i_buffer_size;
-    }
    
     /* initialize data */
     p_return->p_next = NULL;
     p_return->b_discard_payload = 0;
     
-    p_return->p_payload_start = (byte_t *)p_return;
-    p_return->p_payload_end = p_return->p_payload_start 
-                            + p_netlist->i_buffer_size;
+    p_return->p_payload_start = p_return->p_buffer;
+    p_return->p_payload_end = p_return->p_payload_start + i_buffer_size;
     
     return ( p_return );
 }
@@ -321,8 +324,7 @@ struct pes_packet_s * input_NetlistNewPES( void * p_method_data )
     vlc_mutex_unlock (&p_netlist->lock);
     
     /* initialize PES */
-    p_return->b_messed_up = 
-        p_return->b_data_alignment = 
+    p_return->b_data_alignment = 
         p_return->b_discontinuity = 
         p_return->i_pts = p_return->i_dts = 0;
     p_return->i_pes_size = 0;
@@ -344,15 +346,20 @@ void input_NetlistDeletePacket( void * p_method_data, data_packet_t * p_data )
     /* lock */
     vlc_mutex_lock ( &p_netlist->lock );
 
-    /* Delete data_packet */
+
+   /* Delete data_packet */
     p_netlist->i_data_end ++;
     p_netlist->i_data_end %= p_netlist->i_nb_data;
-    p_netlist->pp_free_data[p_netlist->i_data_end] = p_data;
     
+    p_netlist->pp_free_data[p_netlist->i_data_end] = p_data;
     p_netlist->p_free_iovec[p_netlist->i_data_end].iov_base = p_data->p_buffer;
-    
+
+    /* re initialize for next time */
+    p_data->p_payload_start = p_data->p_buffer;
+    p_data->p_next = NULL;
     /* unlock */
-    vlc_mutex_unlock (&p_netlist->lock);    
+    vlc_mutex_unlock (&p_netlist->lock);
 }
 
 /*****************************************************************************
@@ -361,7 +368,7 @@ void input_NetlistDeletePacket( void * p_method_data, data_packet_t * p_data )
 void input_NetlistDeletePES( void * p_method_data, pes_packet_t * p_pes )
 {
     netlist_t * p_netlist; 
-    data_packet_t * p_current_packet;
+    data_packet_t * p_current_packet,* p_next_packet;
     
     /* cast */
     p_netlist = (netlist_t *)p_method_data;
@@ -377,12 +384,18 @@ void input_NetlistDeletePES( void * p_method_data, pes_packet_t * p_pes )
 
         p_netlist->i_data_end ++;
         p_netlist->i_data_end %= p_netlist->i_nb_data;
-        p_netlist->pp_free_data[p_netlist->i_data_end] = p_current_packet;
+
+        /* re initialize*/
+        p_current_packet->p_payload_start = p_current_packet->p_buffer;
         
+        p_netlist->pp_free_data[p_netlist->i_data_end] = p_current_packet;
+
         p_netlist->p_free_iovec[p_netlist->i_data_end].iov_base 
-            = p_netlist->p_data->p_buffer;
+            = p_current_packet->p_buffer;
     
-        p_current_packet = p_current_packet->p_next;
+        p_next_packet = p_current_packet->p_next;
+        p_current_packet->p_next = NULL;
+        p_current_packet = p_next_packet;
     }
  
     /* delete our current PES packet */
@@ -392,6 +405,7 @@ void input_NetlistDeletePES( void * p_method_data, pes_packet_t * p_pes )
     
     /* unlock */
     vlc_mutex_unlock (&p_netlist->lock);
+
 }
 
 /*****************************************************************************
@@ -404,6 +418,9 @@ void input_NetlistEnd( input_thread_t * p_input)
     /* cast */
     p_netlist = ( netlist_t * ) p_input->p_method_data;
     
+    /* destroy the mutex lock */
+    vlc_mutex_destroy (&p_netlist->lock);
+    
     /* free the FIFO, the buffer, and the netlist structure */
     free (p_netlist->pp_free_data);
     free (p_netlist->pp_free_pes);