]> git.sesse.net Git - vlc/commitdiff
- Changed read method : we now use select, so we are now able to quit
authorHenri Fallon <henri@videolan.org>
Sun, 18 Mar 2001 18:48:27 +0000 (18:48 +0000)
committerHenri Fallon <henri@videolan.org>
Sun, 18 Mar 2001 18:48:27 +0000 (18:48 +0000)
even if no packet has benn receivced.
- Put more exmplicit error messages

I noticed that now I have "Seeking to position ...." messages even with
network input. If someone can do a quick fix, thanks about it.

plugins/mpeg/input_ts.c
plugins/mpeg/input_ts.h

index 56ff82cafff7c02bb99420a5f6cf678ce2e55c84..17d158ca457ad92a12f1c9e8c49ff731c342a1cb 100644 (file)
@@ -2,9 +2,9 @@
  * input_ts.c: TS demux and netlist management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ts.c,v 1.9 2001/03/07 01:36:41 sam Exp $
+ * $Id: input_ts.c,v 1.10 2001/03/18 18:48:27 henri Exp $
  *
- * Authors: 
+ * Authors: Henri Fallon <henri@videolan.org>
  *
  * 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
@@ -143,22 +143,20 @@ static void TSInit( input_thread_t * p_input )
     p_method = malloc( sizeof( thread_ts_data_t ) );
     if( p_method == NULL )
     {
-        intf_ErrMsg( "Out of memory" );
+        intf_ErrMsg( "TS input : Out of memory" );
         p_input->b_error = 1;
         return;
     }
+
     p_input->p_plugin_data = (void *)p_method;
     p_input->p_method_data = NULL;
  
     
-    /* XXX : For the time being, only file, after, i'll do the network */ 
-    
     /* Initialize netlist */
     if( input_NetlistInit( p_input, NB_DATA, NB_PES, TS_PACKET_SIZE, 
                 INPUT_READ_ONCE ) )
     {
-        intf_ErrMsg( "Could not initialize netlist" );
+        intf_ErrMsg( "TS input : Could not initialize netlist" );
         return;
     }
    
@@ -205,11 +203,29 @@ static void TSEnd( input_thread_t * p_input )
 static int TSRead( input_thread_t * p_input,
                    data_packet_t * pp_packets[INPUT_READ_ONCE] )
 {
-    unsigned int i_read, i_loop;
-    struct iovec * p_iovec;
+    thread_ts_data_t    * p_method;
+    unsigned int    i_read, i_loop;
+    int             i_data;
+    struct iovec  * p_iovec;
+    struct timeval  s_wait;
+    
+
+    /* Init */
+    p_method = ( thread_ts_data_t * )p_input->p_plugin_data;
+   
+    /* Initialize file descriptor set */
+    FD_ZERO( &(p_method->s_fdset) );
+    FD_SET( p_input->i_handle, &(p_method->s_fdset) );
+
+    
+    /* We'll wait 0.5 second if nothing happens */
+    s_wait.tv_sec = 0.5;
+    s_wait.tv_usec = 0;
     
+    /* Reset pointer table */
     memset( pp_packets, 0, INPUT_READ_ONCE*sizeof(data_packet_t *) );
     
+    /* Get iovecs */
     p_iovec = input_NetlistGetiovec( p_input->p_method_data );
     
     if ( p_iovec == NULL )
@@ -217,21 +233,35 @@ static int TSRead( input_thread_t * p_input,
         return( -1 ); /* empty netlist */
     } 
 
-    i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
-    if( i_read == -1 )
+    /* Fill if some data is available */
+    i_data = select(p_input->i_handle + 1, &(p_method->s_fdset), NULL, NULL, 
+                    &s_wait);
+    
+    if( i_data == -1 )
     {
-        intf_ErrMsg( "Could not readv" );
+        intf_ErrMsg( "TS input : Error in select : %s", strerror(errno) );
         return( -1 );
     }
-
-    input_NetlistMviovec( p_input->p_method_data, 
-            (int)(i_read/TS_PACKET_SIZE) , pp_packets );
-
-    /* check correct TS header */
-    for( i_loop=0; i_loop < (int)(i_read/TS_PACKET_SIZE); i_loop++ )
+    
+    if( i_data )
     {
-        if( pp_packets[i_loop]->p_buffer[0] != 0x47 )
-            intf_ErrMsg( "Bad TS Packet (starcode != 0x47)." );
+        i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
+        
+        if( i_read == -1 )
+        {
+            intf_ErrMsg( "TS input : Could not readv" );
+            return( -1 );
+        }
+    
+        input_NetlistMviovec( p_input->p_method_data, 
+                (int)(i_read/TS_PACKET_SIZE) , pp_packets );
+    
+        /* check correct TS header */
+        for( i_loop=0; i_loop < (int)(i_read/TS_PACKET_SIZE); i_loop++ )
+        {
+            if( pp_packets[i_loop]->p_buffer[0] != 0x47 )
+                intf_ErrMsg( "TS input : Bad TS Packet (starcode != 0x47)." );
+        }
     }
     return 0;
 }
index 99006f357f8c7df8da41e9e961c7dbe454e7de4d..b90f43ccb0f279ac0fdcec6c47335aa033c5a484 100644 (file)
@@ -2,7 +2,7 @@
  * input.h: structures of the input not exported to other modules
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ts.h,v 1.2 2001/02/21 04:38:59 henri Exp $
+ * $Id: input_ts.h,v 1.3 2001/03/18 18:48:27 henri Exp $
  *
  * Authors:
  *
@@ -29,5 +29,6 @@
 typedef struct thread_ts_data_s { 
     
     // FILE *                  stream;
+    fd_set s_fdset;
     
 } thread_ts_data_t;