]> git.sesse.net Git - vlc/blobdiff - plugins/mpeg/input_ts.c
* VC++/Intel compiler fixes by Jon Lech Johansen <jon-vl@nanocrew.net>.
[vlc] / plugins / mpeg / input_ts.c
index 0ed311ea89f2ba631b75f9a87c242fd63ff503f7..8835f795bed775ac939e426a357bd1d617abb185 100644 (file)
@@ -2,7 +2,7 @@
  * input_ts.c: TS demux and netlist management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ts.c,v 1.15 2001/04/27 16:08:26 sam Exp $
+ * $Id: input_ts.c,v 1.31 2001/07/30 00:53:05 sam Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org>
  *
@@ -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
 #include <string.h>
 #include <errno.h>
 
+#ifdef STRNCASECMP_IN_STRINGS_H
+#   include <strings.h>
+#endif
+
 #include <sys/types.h>
-#include <sys/time.h>
+
+#if !defined( _MSC_VER )
+#   include <sys/time.h>
+#endif
+
 #ifdef SYS_NTO
-#include <sys/select.h>
+#   include <sys/select.h>
 #endif
-#include <sys/uio.h>
+
 #include <sys/stat.h>
-#include <unistd.h>
+
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>
+#endif
+
 #include <fcntl.h>
 
+#if defined( WIN32 )
+#   include <io.h>
+#   include <winsock2.h>
+#else
+#   include <sys/uio.h>                                      /* struct iovec */
+#endif
+
 #include "config.h"
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
 #include "tests.h"
-#include "modules.h"
+
+#if defined( WIN32 )
+#   include "input_iovec.h"
+#endif
 
 #include "intf_msg.h"
 
 #include "stream_control.h"
 #include "input_ext-intf.h"
 #include "input_ext-dec.h"
+#include "input_ext-plugins.h"
 
-#include "input.h"
 #include "input_ts.h"
 
-#include "mpeg_system.h"
-#include "input_netlist.h"
+#include "modules.h"
+#include "modules_export.h"
 
 /*****************************************************************************
  * Local prototypes
@@ -84,6 +106,7 @@ void _M( input_getfunctions )( function_list_t * p_function_list )
     input.pf_open             = TSFakeOpen;
     input.pf_close            = NULL;              /* Will be set by pf_open */
     input.pf_end              = TSEnd;
+    input.pf_init_bit_stream  = InitBitstream;
     input.pf_set_area         = NULL;
     input.pf_read             = TSRead;
     input.pf_demux            = input_DemuxTS;
@@ -124,6 +147,13 @@ static int TSProbe( probedata_t * p_data )
         psz_name += 5;
     }
 
+    if( ( strlen(psz_name) > 3 ) &&
+                    !strncasecmp( psz_name+strlen(psz_name)-3, ".ts", 3) )
+    {
+        /* If it is a ".ts" file it's probably a TS file ... */
+        return( 900 );
+    }
+
     i_handle = open( psz_name, 0 );
     if( i_handle == -1 )
     {
@@ -154,30 +184,36 @@ static void TSInit( input_thread_t * p_input )
         return;
     }
 
+#if defined( WIN32 )
+    p_method->i_length = 0;
+    p_method->i_offset = 0;
+#endif
+
     p_input->p_plugin_data = (void *)p_method;
     p_input->p_method_data = NULL;
-    
+
+
     /* Initialize netlist */
-    if( input_NetlistInit( p_input, NB_DATA, NB_PES, TS_PACKET_SIZE, 
+    if( input_NetlistInit( p_input, NB_DATA, NB_PES, TS_PACKET_SIZE,
                 INPUT_READ_ONCE ) )
     {
         intf_ErrMsg( "TS input : Could not initialize netlist" );
         return;
     }
-   
+
     /* Initialize the stream */
     input_InitStream( p_input, sizeof( stream_ts_data_t ) );
 
     /* input method type */
     /* FIXME: should test if you have network or file here */
     p_input->stream.i_method = INPUT_METHOD_NETWORK;
+    p_input->stream.p_selected_area->i_tell = 0;
 
     /* Init */
     p_stream_data = (stream_ts_data_t *)p_input->stream.p_demux_data;
     p_stream_data->i_pat_version = PAT_UNINITIALIZED ;
 
-    /* We'll have to catch the PAT in order to continue 
+    /* We'll have to catch the PAT in order to continue
      * Then the input will catch the PMT and then the others ES
      * The PAT es is indepedent of any program. */
     p_pat_es = input_AddES( p_input, NULL,
@@ -187,7 +223,7 @@ static void TSInit( input_thread_t * p_input )
     p_demux_data->i_psi_type = PSI_IS_PAT;
     p_demux_data->p_psi_section = malloc(sizeof(psi_section_t));
     p_demux_data->p_psi_section->b_is_complete = 1;
-    
+
 }
 
 /*****************************************************************************
@@ -201,14 +237,14 @@ void TSFakeOpen( input_thread_t * p_input )
     if( ( strlen(psz_name) > 3 ) && !strncasecmp( psz_name, "ts:", 3 ) )
     {
         /* If the user specified "ts:" he wants a network stream */
-        p_input->pf_open = input_NetworkOpen;
-        p_input->pf_close = input_NetworkClose;
+        p_input->pf_open  = p_input->pf_network_open;
+        p_input->pf_close = p_input->pf_network_close;
     }
     else
 #endif
     {
-        p_input->pf_open = input_FileOpen;
-        p_input->pf_close = input_FileClose;
+        p_input->pf_open  = p_input->pf_file_open;
+        p_input->pf_close = p_input->pf_file_close;
     }
 
     p_input->pf_open( p_input );
@@ -220,7 +256,7 @@ void TSFakeOpen( input_thread_t * p_input )
 static void TSEnd( input_thread_t * p_input )
 {
     es_descriptor_t     * p_pat_es;
-    
+
     p_pat_es = input_FindES( p_input, 0x00 );
 
     if( p_pat_es != NULL )
@@ -238,58 +274,73 @@ static int TSRead( input_thread_t * p_input,
                    data_packet_t * pp_packets[INPUT_READ_ONCE] )
 {
     thread_ts_data_t    * p_method;
-    unsigned int    i_read, i_loop;
-    int             i_data;
+    unsigned int    i_loop;
+    int             i_read;
+    int             i_data = 0;
     struct iovec  * p_iovec;
-    struct timeval  s_wait;
-    
+    struct timeval  timeout;
+
+    /* Get iovecs */
+    p_iovec = input_NetlistGetiovec( p_input->p_method_data );
+
+    if ( p_iovec == NULL )
+    {
+        return( -1 ); /* empty netlist */
+    }
 
     /* 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) );
+    FD_ZERO( &(p_method->fds) );
+    FD_SET( p_input->i_handle, &(p_method->fds) );
 
-    
     /* We'll wait 0.5 second if nothing happens */
-    s_wait.tv_sec = 0.5;
-    s_wait.tv_usec = 0;
-    
+    timeout.tv_sec = 0;
+    timeout.tv_usec = 500000;
+
     /* 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 )
-    {
-        return( -1 ); /* empty netlist */
-    } 
 
     /* Fill if some data is available */
-    i_data = select(p_input->i_handle + 1, &(p_method->s_fdset), NULL, NULL, 
-                    &s_wait);
-    
+#if defined( WIN32 )
+    if ( ! p_input->stream.b_pace_control ) 
+#endif
+    {
+        i_data = select( p_input->i_handle + 1, &p_method->fds,
+                         NULL, NULL, &timeout );
+    }
+
     if( i_data == -1 )
     {
         intf_ErrMsg( "input error: TS select error (%s)", strerror(errno) );
         return( -1 );
     }
-    
+
     if( i_data )
     {
+#if defined( WIN32 )
+        if( p_input->stream.b_pace_control )
+        {
+            i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
+        }
+        else
+        {
+            i_read = readv_network( p_input->i_handle, p_iovec,
+                                    INPUT_READ_ONCE, p_method );
+        }
+#else
         i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
-        
+#endif
         if( i_read == -1 )
         {
             intf_ErrMsg( "input error: TS readv error" );
             return( -1 );
         }
-    
-        input_NetlistMviovec( p_input->p_method_data, 
+
+        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 * TS_PACKET_SIZE < i_read; i_loop++ )
         {
@@ -298,6 +349,9 @@ static int TSRead( input_thread_t * p_input,
                              "0x%.2x, should be 0x47)",
                              pp_packets[i_loop]->p_buffer[0] );
         }
+
+        p_input->stream.p_selected_area->i_tell += i_read;
     }
     return 0;
 }
+