X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=plugins%2Fmpeg%2Finput_ts.c;h=a2bb081457f9b3a95ed1117bf4a40d3c69afd1fc;hb=94d3d4d8be146d5a7ca5e77eb025820d26b9396d;hp=e6eda47b73bf18c9e1eb7744535215e5c3fec7e5;hpb=910f40f93c543d78c5c9f3da3f5a5706be98b453;p=vlc diff --git a/plugins/mpeg/input_ts.c b/plugins/mpeg/input_ts.c index e6eda47b73..a2bb081457 100644 --- a/plugins/mpeg/input_ts.c +++ b/plugins/mpeg/input_ts.c @@ -2,9 +2,9 @@ * input_ts.c: TS demux and netlist management ***************************************************************************** * Copyright (C) 1998, 1999, 2000 VideoLAN - * $Id: input_ts.c,v 1.6 2001/02/21 04:38:59 henri Exp $ + * $Id: input_ts.c,v 1.22 2001/05/31 01:37:08 sam Exp $ * - * Authors: + * Authors: Henri Fallon * * 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 @@ -31,14 +31,36 @@ #include #include +#ifdef STRNCASECMP_IN_STRINGS_H +# include +#endif #include -#include #include + +#if !defined( _MSC_VER ) +#include +#endif + +#ifdef SYS_NTO +#include +#endif + #include + +#ifdef HAVE_UNISTD_H #include +#endif + #include +#if !defined( WIN32 ) +#include /* struct iovec */ +#else +#include +#include "iovec.h" +#endif + #include "config.h" #include "common.h" #include "threads.h" @@ -62,10 +84,11 @@ * Local prototypes *****************************************************************************/ static int TSProbe ( probedata_t * ); -static int TSRead ( struct input_thread_s *, - data_packet_t * p_packets[INPUT_READ_ONCE] ); static void TSInit ( struct input_thread_s * ); +static void TSFakeOpen ( struct input_thread_s * ); static void TSEnd ( struct input_thread_s * ); +static int TSRead ( struct input_thread_s *, + data_packet_t * p_packets[INPUT_READ_ONCE] ); /***************************************************************************** * Functions exported as capabilities. They are declared as static so that @@ -76,8 +99,8 @@ void _M( input_getfunctions )( function_list_t * p_function_list ) #define input p_function_list->functions.input p_function_list->pf_probe = TSProbe; input.pf_init = TSInit; - input.pf_open = input_FileOpen; - input.pf_close = input_FileClose; + input.pf_open = TSFakeOpen; + input.pf_close = NULL; /* Will be set by pf_open */ input.pf_end = TSEnd; input.pf_set_area = NULL; input.pf_read = TSRead; @@ -107,12 +130,25 @@ static int TSProbe( probedata_t * p_data ) return( 999 ); } + if( ( strlen(psz_name) > 3 ) && !strncasecmp( psz_name, "ts:", 3 ) ) + { + /* If the user specified "ts:" then it's probably a network stream */ + return( 999 ); + } + if( ( strlen(psz_name) > 5 ) && !strncasecmp( psz_name, "file:", 5 ) ) { /* If the user specified "file:" then it's probably a file */ 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 ) { @@ -138,28 +174,31 @@ 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; } /* 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 ; @@ -177,6 +216,30 @@ static void TSInit( input_thread_t * p_input ) } +/***************************************************************************** + * TSFakeOpen: open the stream and set pf_close + *****************************************************************************/ +void TSFakeOpen( input_thread_t * p_input ) +{ +#if !defined( SYS_BEOS ) && !defined( SYS_NTO ) + char *psz_name = p_input->p_source; + + if( ( strlen(psz_name) > 3 ) && !strncasecmp( psz_name, "ts:", 3 ) ) + { + /* If the user specified "ts:" he wants a network stream */ + p_input->pf_open = p_input->pf_network_open; + p_input->pf_close = p_input->pf_network_close; + } + else +#endif + { + p_input->pf_open = p_input->pf_file_open; + p_input->pf_close = p_input->pf_file_close; + } + + p_input->pf_open( p_input ); +} + /***************************************************************************** * TSEnd: frees unused data *****************************************************************************/ @@ -200,11 +263,14 @@ 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; - - memset( pp_packets, 0, INPUT_READ_ONCE*sizeof(data_packet_t *) ); + thread_ts_data_t * p_method; + unsigned int i_read, i_loop; + int i_data; + struct iovec * p_iovec; + struct timeval s_wait; + + /* Get iovecs */ p_iovec = input_NetlistGetiovec( p_input->p_method_data ); if ( p_iovec == NULL ) @@ -212,22 +278,55 @@ static int TSRead( input_thread_t * p_input, return( -1 ); /* empty netlist */ } - i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE ); + /* 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; + s_wait.tv_usec = 500000; - if( i_read == -1 ) + /* Reset pointer table */ + memset( pp_packets, 0, INPUT_READ_ONCE * sizeof(data_packet_t *) ); + + /* 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( "input error: TS select error (%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( "input error: TS readv error" ); + 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 * TS_PACKET_SIZE < i_read; i_loop++ ) + { + if( pp_packets[i_loop]->p_buffer[0] != 0x47 ) + intf_ErrMsg( "input error: bad TS packet (starts with " + "0x%.2x, should be 0x47)", + pp_packets[i_loop]->p_buffer[0] ); + } + + p_input->stream.p_selected_area->i_tell += i_read; } return 0; } +