]> git.sesse.net Git - vlc/blobdiff - plugins/dvd/dvd_netlist.c
*the dvd netlist no longer stops when the fifo is empty ; it just waits
[vlc] / plugins / dvd / dvd_netlist.c
index 83f959b93c34330f0b00d0b53f7c6ea2193e5f11..92ad6fa80de0cb378a1dfede9ae84a86ffae4d27 100644 (file)
@@ -1,13 +1,13 @@
 /*****************************************************************************
  * dvd_netlist.c: Specific netlist for DVD packets
- * ---
+ *****************************************************************************
  * The original is in src/input.
  * There is only one major change from input_netlist.c : data is now a
  * pointer to an offset in iovec ; and iovec has a reference counter. It
  * will only be given back to netlist when refcount is zero.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
- * $Id: dvd_netlist.c,v 1.2 2001/03/03 07:07:01 stef Exp $
+ * $Id: dvd_netlist.c,v 1.10 2001/06/13 00:03:08 stef Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org>
  *          Stéphane Borel <stef@videolan.org>
 #include "defs.h"
 
 #include <stdlib.h>
+#include <string.h>                                    /* memcpy(), memset() */
 #include <sys/types.h>
-#include <sys/uio.h>                                         /* struct iovec */
-#include <unistd.h>
+
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>
+#endif
+
+#if defined( WIN32 )
+#   include <io.h>
+#   include "input_iovec.h"
+#else
+#   include <sys/uio.h>                                      /* struct iovec */
+#endif
 
 #include "config.h"
 #include "common.h"
@@ -50,6 +60,9 @@
 #include "input.h"
 #include "dvd_netlist.h"
 
+#include "modules.h"
+#include "modules_export.h"
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -225,9 +238,9 @@ dvd_netlist_t * DVDNetlistInit( int i_nb_iovec, int i_nb_data, int i_nb_pes,
 /*****************************************************************************
  * DVDGetiovec: 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.
+ * We return an iovec vector, so that readv can read many packets at a time.
+ * pp_data will be set to direct to the fifo pointer in DVDMviovec, which
+ * will allow us to get the corresponding data_packet.
  *****************************************************************************/
 struct iovec * DVDGetiovec( void * p_method_data )
 {
@@ -236,15 +249,22 @@ struct iovec * DVDGetiovec( void * p_method_data )
     /* cast */
     p_netlist = (dvd_netlist_t *)p_method_data;
     
-    /* check */
-    if( (
+    /* check that we have enough free iovec */
+    while( (
      (p_netlist->i_iovec_end - p_netlist->i_iovec_start)
         & p_netlist->i_nb_iovec ) < p_netlist->i_read_once )
     {
-        intf_ErrMsg("Empty iovec FIFO. Unable to allocate memory");
-        return (NULL);
+        intf_WarnMsg( 12, "input info: waiting for free iovec" );
+        msleep( INPUT_IDLE_SLEEP );
     }
 
+    while( (
+     (p_netlist->i_data_end - p_netlist->i_data_start)
+        & p_netlist->i_nb_data ) < p_netlist->i_read_once )
+    {
+        intf_WarnMsg( 12, "input info: waiting for free data packet" );
+        msleep( INPUT_IDLE_SLEEP );
+    }
     /* readv only takes contiguous buffers 
      * 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
@@ -291,6 +311,7 @@ void DVDMviovec( void * p_method_data, int i_nb_iovec,
         
         pp_data[i_loop]->pi_refcount = p_netlist->pi_refcount +
                                        p_netlist->i_iovec_start;
+
         p_netlist->i_iovec_start ++;
         p_netlist->i_iovec_start &= p_netlist->i_nb_iovec;
 
@@ -317,15 +338,6 @@ struct data_packet_s * DVDNewPtr( void * p_method_data )
     /* cast */
     p_netlist = (dvd_netlist_t *)p_method_data; 
 
-#ifdef DEBUG
-    if( i_buffer_size > p_netlist->i_buffer_size )
-    {
-        /* This should not happen */
-        intf_ErrMsg( "Netlist packet too small !" );
-        return NULL;
-    }
-#endif
-
     /* lock */
     vlc_mutex_lock ( &p_netlist->lock );
         
@@ -356,7 +368,7 @@ struct data_packet_s * DVDNewPacket( void * p_method_data,
 {
     dvd_netlist_t *         p_netlist;
     struct data_packet_s *  p_packet;
-
+//intf_ErrMsg( "netlist: New packet" );
     /* cast */
     p_netlist = (dvd_netlist_t *)p_method_data;
     
@@ -381,14 +393,18 @@ struct data_packet_s * DVDNewPacket( void * p_method_data,
     p_packet = p_netlist->pp_free_data[p_netlist->i_data_start];
         
     p_packet->p_buffer =
-               p_netlist->p_free_iovec[p_netlist->i_iovec_start].iov_base;
+              p_netlist->p_free_iovec[p_netlist->i_iovec_start].iov_base;
         
     p_packet->p_payload_start = p_packet->p_buffer;
         
     p_packet->p_payload_end =
-               p_packet->p_buffer + i_buffer_size;
+              p_packet->p_buffer + i_buffer_size;
+
+    p_packet->p_next = NULL;
+    p_packet->b_discard_payload = 0;
 
     p_packet->pi_refcount = p_netlist->pi_refcount + p_netlist->i_iovec_start;
+    (*p_packet->pi_refcount)++;
 
     p_netlist->i_iovec_start ++;
     p_netlist->i_iovec_start &= p_netlist->i_nb_iovec;
@@ -410,6 +426,7 @@ struct pes_packet_s * DVDNewPES( void * p_method_data )
     dvd_netlist_t *     p_netlist;
     pes_packet_t *      p_return;
     
+//intf_ErrMsg( "netlist: New pes" );
     /* cast */ 
     p_netlist = (dvd_netlist_t *)p_method_data;
     
@@ -432,12 +449,13 @@ struct pes_packet_s * DVDNewPES( void * p_method_data )
     vlc_mutex_unlock (&p_netlist->lock);
     
     /* initialize PES */
-    p_return->b_data_alignment = 
-        p_return->b_discontinuity = 
-        p_return->i_pts = p_return->i_dts = 0;
+    p_return->b_data_alignment = 0;
+    p_return->b_discontinuity = 0; 
+    p_return->i_pts = 0;
+    p_return->i_dts = 0;
     p_return->i_pes_size = 0;
     p_return->p_first = NULL;
-   
+
     return ( p_return );
 }
 
@@ -461,6 +479,9 @@ void DVDDeletePacket( void * p_method_data, data_packet_t * p_data )
     
     p_netlist->pp_free_data[p_netlist->i_data_end] = p_data;
 
+    p_data->p_next = NULL;
+    p_data->b_discard_payload = 0;
+
     /* Update reference counter */
     (*p_data->pi_refcount)--;
 
@@ -472,10 +493,6 @@ void DVDDeletePacket( void * p_method_data, data_packet_t * p_data )
         p_netlist->p_free_iovec[p_netlist->i_iovec_end].iov_base =
                                                             p_data->p_buffer;
     }
-
-    /* re initialize for next time */
-    p_data->p_next = NULL;
-    p_data->b_discard_payload = 0;
  
     /* unlock */
     vlc_mutex_unlock (&p_netlist->lock);
@@ -505,7 +522,7 @@ void DVDDeletePES( void * p_method_data, pes_packet_t * p_pes )
         p_netlist->i_data_end ++;
         p_netlist->i_data_end &= p_netlist->i_nb_data;
 
-        /* re initialize*/
+        /* 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;
@@ -513,7 +530,7 @@ void DVDDeletePES( void * p_method_data, pes_packet_t * p_pes )
         /* Update reference counter */
         (*p_current_packet->pi_refcount)--;
 
-        if( (*p_current_packet->pi_refcount) == 0 )
+        if( (*p_current_packet->pi_refcount) <= 0 )
         {
             p_netlist->i_iovec_end++;
             p_netlist->i_iovec_end &= p_netlist->i_nb_iovec;
@@ -523,6 +540,7 @@ void DVDDeletePES( void * p_method_data, pes_packet_t * p_pes )
     
         p_next_packet = p_current_packet->p_next;
         p_current_packet->p_next = NULL;
+        p_current_packet->b_discard_payload = 0;
         p_current_packet = p_next_packet;
     }