Commit a6c6f723 authored by Henri Fallon's avatar Henri Fallon

- Fixed TS input ( a nasty dead lock had appeared 4 days ago )
- Added base of network support

Things to be done :
- Meuuh : fix the PCR synchronisation so that we can set b_pace_cntrol to 0
- Sam : find a way of specifing the type of media (file, net). For the
moment, the "--input ts" always call input_NetworkOpen
- Maybe sam : for the moment the working syntax is vlc --input ts
servername, it should nbe turned into "vlc --server servername".

Things that don't work (i'll work on this this week end) :
- stopping and retaking a stream
- a nice 'waiting for stream'
- we select all incoming streams. we should be able to select.

Things that haven't been tested :
- broadcast
- only tested with one stream.

Kick me if something is broken by my fault.
parent 6304d60d
......@@ -179,6 +179,7 @@
/* Default remote server */
#define INPUT_SERVER_VAR "vlc_server"
#define INPUT_SERVER_DEFAULT "138.195.143.220"
#define INPUT_BCAST_ADDR "138.195.143.255"
/* Default input port */
#define INPUT_PORT_VAR "vlc_server_port"
......
......@@ -2,7 +2,7 @@
* input.h: structures of the input not exported to other modules
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: input.h,v 1.33 2001/03/02 13:49:37 massiot Exp $
* $Id: input.h,v 1.34 2001/03/07 00:18:46 henri Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -48,6 +48,13 @@ void NextDataPacket ( struct bit_stream_s * );
void input_FileOpen ( struct input_thread_s * );
void input_FileClose( struct input_thread_s * );
/*****************************************************************************
* Prototypes from input.c to open a network socket
*****************************************************************************/
void input_NetworkOpen ( struct input_thread_s * );
void input_NetworkClose( struct input_thread_s * );
/*****************************************************************************
* Prototypes from input_programs.c
*****************************************************************************/
......
......@@ -2,7 +2,7 @@
* input_ts.c: TS demux and netlist management
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: input_ts.c,v 1.7 2001/03/05 11:53:44 sam Exp $
* $Id: input_ts.c,v 1.8 2001/03/07 00:18:46 henri Exp $
*
* Authors:
*
......@@ -76,8 +76,10 @@ 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 = input_FileOpen;
// input.pf_close = input_FileClose;
input.pf_open = input_NetworkOpen;
input.pf_close = input_NetworkClose;
input.pf_end = TSEnd;
input.pf_set_area = NULL;
input.pf_read = TSRead;
......@@ -213,7 +215,6 @@ static int TSRead( input_thread_t * p_input,
}
i_read = readv( p_input->i_handle, p_iovec, INPUT_READ_ONCE );
if( i_read == -1 )
{
intf_ErrMsg( "Could not readv" );
......
......@@ -4,7 +4,7 @@
* decoders.
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: input.c,v 1.88 2001/03/02 03:32:46 stef Exp $
* $Id: input.c,v 1.89 2001/03/07 00:18:46 henri Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -36,6 +36,15 @@
#include <string.h>
#include <errno.h>
/* Network functions */
#include <netdb.h> /* hostent ... */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifdef STATS
# include <sys/times.h>
#endif
......@@ -316,7 +325,6 @@ static int InitThread( input_thread_t * p_input )
p_input->pf_rewind = f.pf_rewind;
p_input->pf_seek = f.pf_seek;
#undef f
p_input->pf_open( p_input );
if( p_input->b_error )
......@@ -426,16 +434,16 @@ void input_FileOpen( input_thread_t * p_input )
/* get rid of the 'dvd:' stuff and try again */
psz_name += 4;
i_stat = stat( psz_name, &stat_info );
}
}
else if( ( i_size > 5 )
&& !strncasecmp( psz_name, "file:", 5 ) )
{
/* get rid of the 'file:' stuff and try again */
psz_name += 5;
i_stat = stat( psz_name, &stat_info );
}
}
if( i_stat == (-1) )
if( i_stat == (-1) )
{
intf_ErrMsg( "input error: cannot stat() file `%s' (%s)",
psz_name, strerror(errno));
......@@ -497,3 +505,212 @@ void input_FileClose( input_thread_t * p_input )
return;
}
/*****************************************************************************
* input_BuildLocalAddr : fill a sockaddr_in structure for local binding
*****************************************************************************/
int input_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port,
boolean_t b_broadcast )
{
char psz_hostname[INPUT_MAX_SOURCE_LENGTH];
struct hostent * p_hostent;
/* Reset struct */
memset( p_socket, 0, sizeof( struct sockaddr_in ) );
p_socket->sin_family = AF_INET; /* family */
p_socket->sin_port = htons( i_port );
if( !b_broadcast )
{
/* Try to get our own IP */
if( gethostname( psz_hostname, sizeof(psz_hostname) ) )
{
intf_ErrMsg( "BuildLocalAddr : unable to resolve local name : %s",
strerror( errno ) );
return( -1 );
}
}
else
{
/* Using broadcast address. There are many ways of doing it, one of
* the simpliest being a #define ...
* FIXME : this is ugly */
strncpy( psz_hostname, INPUT_BCAST_ADDR,INPUT_MAX_SOURCE_LENGTH );
}
/* Try to convert address directly from in_addr - this will work if
* psz_in_addr is dotted decimal. */
#ifdef HAVE_ARPA_INET_H
if( !inet_aton( psz_hostname, &p_socket->sin_addr) )
#else
if( (p_socket->sin_addr.s_addr = inet_addr( psz_hostname )) == -1 )
#endif
{
/* We have a fqdn, try to find its address */
if ( (p_hostent = gethostbyname( psz_hostname )) == NULL )
{
intf_ErrMsg( "BuildLocalAddr: unknown host %s", psz_hostname );
return( -1 );
}
/* Copy the first address of the host in the socket address */
memcpy( &p_socket->sin_addr, p_hostent->h_addr_list[0],
p_hostent->h_length );
}
return( 0 );
}
/*****************************************************************************
* input_BuildRemoteAddr : fill a sockaddr_in structure for remote host
*****************************************************************************/
int input_BuildRemoteAddr( input_thread_t * p_input,
struct sockaddr_in * p_socket )
{
struct hostent * p_hostent;
/* Reset structure */
memset( p_socket, 0, sizeof( struct sockaddr_in ) );
p_socket->sin_family = AF_INET; /* family */
p_socket->sin_port = htons( 0 ); /* This is for remote end */
/* Get the remote server */
if( p_input->p_source == NULL )
{
p_input->p_source = main_GetPszVariable( INPUT_SERVER_VAR,
INPUT_SERVER_DEFAULT );
}
/* Try to convert address directly from in_addr - this will work if
* psz_in_addr is dotted decimal. */
#ifdef HAVE_ARPA_INET_H
if( !inet_aton( p_input->p_source, &p_socket->sin_addr) )
#else
if( (p_socket->sin_addr.s_addr = inet_addr( p_input->p_source )) == -1 )
#endif
{
/* We have a fqdn, try to find its address */
if ( (p_hostent = gethostbyname(p_input->p_source)) == NULL )
{
intf_ErrMsg( "BuildRemoteAddr: unknown host %s",
p_input->p_source );
return( -1 );
}
/* Copy the first address of the host in the socket address */
memcpy( &p_socket->sin_addr, p_hostent->h_addr_list[0],
p_hostent->h_length );
}
return( 0 );
}
/*****************************************************************************
* input_NetworkOpen : open a network socket
*****************************************************************************/
void input_NetworkOpen( input_thread_t * p_input )
{
int i_option_value, i_port;
struct sockaddr_in s_socket;
boolean_t b_broadcast;
/* FIXME : we don't handle channels for the moment */
/* Open a SOCK_DGRAM (UDP) socket, in the AF_INET domain, automatic (0)
* protocol */
p_input->i_handle = socket( AF_INET, SOCK_DGRAM, 0 );
if( p_input->i_handle == -1 )
{
intf_ErrMsg("NetworkOpen : can't create socket : %s", strerror(errno));
p_input->b_error = 1;
return;
}
/* We may want to reuse an already used socket */
i_option_value = 1;
if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_REUSEADDR,
&i_option_value,sizeof( i_option_value ) ) == -1 )
{
intf_ErrMsg("NetworkOpen : can't configure socket (SO_REUSEADDR: %s)",
strerror(errno));
close( p_input->i_handle );
p_input->b_error = 1;
return;
}
#ifndef SYS_BEOS
/* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
* packet loss caused by scheduling problems */
i_option_value = 524288;
if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_RCVBUF, &i_option_value,
sizeof( i_option_value ) ) == -1 )
{
intf_ErrMsg("NetworkOpen : can't configure socket (SO_RCVBUF: %s)",
strerror(errno));
close( p_input->i_handle );
p_input->b_error = 1;
return;
}
#endif /* SYS_BEOS */
/* Get details about what we are supposed to do */
b_broadcast = (boolean_t)main_GetIntVariable( INPUT_BROADCAST_VAR, 0 );
i_port = main_GetIntVariable( INPUT_PORT_VAR, INPUT_PORT_DEFAULT );
/* TODO : here deal with channel stufs */
/* Build the local socket */
if ( input_BuildLocalAddr( &s_socket, i_port, b_broadcast )
== -1 )
{
close( p_input->i_handle );
p_input->b_error = 1;
return;
}
/* Bind it */
if( bind( p_input->i_handle, (struct sockaddr *)&s_socket,
sizeof( s_socket ) ) < 0 )
{
intf_ErrMsg("NetworkOpen: can't bind socket (%s)", strerror(errno));
close( p_input->i_handle );
p_input->b_error = 1;
return;
}
/* Build socket for remote connection */
if ( input_BuildRemoteAddr( p_input, &s_socket )
== -1 )
{
close( p_input->i_handle );
p_input->b_error = 1;
return;
}
/* And connect it ... should we really connect ? */
if( connect( p_input->i_handle, (struct sockaddr *) &s_socket,
sizeof( s_socket ) ) == (-1) )
{
intf_ErrMsg("NetworkOpen: can't connect socket" );
close( p_input->i_handle );
p_input->b_error = 1;
return;
}
/* We can't pace control, but FIXME : bug in meuuh's code to sync PCR
* with the server. */
p_input->stream.b_pace_control = 1;
return;
}
/*****************************************************************************
* input_NetworkClose : close a network socket
*****************************************************************************/
void input_NetworkClose( input_thread_t * p_input )
{
close( p_input->i_handle );
/* FIXME: deal with channels */
}
......@@ -2,7 +2,7 @@
* mpeg_system.c: TS, PS and PES management
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: mpeg_system.c,v 1.42 2001/03/06 17:54:48 massiot Exp $
* $Id: mpeg_system.c,v 1.43 2001/03/07 00:18:46 henri Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
......@@ -934,7 +934,6 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
pgrm_ts_data_t * p_pgrm_demux = NULL;
#define p (p_data->p_buffer)
/* Extract flags values from TS common header. */
i_pid = U16_AT(&p[1]) & 0x1fff;
b_unit_start = (p[1] & 0x40);
......@@ -943,7 +942,6 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
/* Find out the elementary stream. */
vlc_mutex_lock( &p_input->stream.stream_lock );
p_es= input_FindES( p_input, i_pid );
......@@ -953,10 +951,11 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
if( p_es_demux->b_psi )
b_psi = 1;
else
p_pgrm_demux = (pgrm_ts_data_t *)p_es->p_pgrm->p_demux_data;
}
vlc_mutex_lock( &p_input->stream.control.control_lock );
if( ( p_es == NULL ) || (p_es->b_audio && p_input->stream.control.b_mute) )
{
/* Not selected. Just read the adaptation field for a PCR. */
......@@ -969,17 +968,12 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
vlc_mutex_unlock( &p_input->stream.stream_lock );
/* Don't change the order of the tests : if b_psi then p_pgrm_demux
* may still be null. Who said it was ugly ? */
if( ( p_es != NULL ) &&
((p_es->p_decoder_fifo != NULL) || b_psi
|| (p_pgrm_demux->i_pcr_pid == i_pid) ) )
{
p_es_demux = (es_ts_data_t *)p_es->p_demux_data;
if( ! p_es_demux->b_psi )
{
p_pgrm_demux = (pgrm_ts_data_t *)p_es->p_pgrm->p_demux_data;
}
#ifdef STATS
p_es->c_packets++;
#endif
......@@ -1288,7 +1282,6 @@ static void input_DecodePAT( input_thread_t * p_input, es_descriptor_t * p_es )
stream_ts_data_t * p_stream_data;
es_ts_data_t * p_demux_data;
p_demux_data = (es_ts_data_t *)p_es->p_demux_data;
p_stream_data = (stream_ts_data_t *)p_input->stream.p_demux_data;
......@@ -1394,6 +1387,9 @@ static void input_DecodePMT( input_thread_t * p_input, es_descriptor_t * p_es )
p_current_data = p_psi->buffer;
p_pgrm_data->i_pcr_pid = U16_AT(p_current_section + 8) & 0x1fff;
/* Lock stream information */
vlc_mutex_lock( &p_input->stream.stream_lock );
/* Delete all ES in this program except the PSI */
for( i_loop=0; i_loop < p_es->p_pgrm->i_es_number; i_loop++ )
......@@ -1430,7 +1426,6 @@ static void input_DecodePMT( input_thread_t * p_input, es_descriptor_t * p_es )
/* We want to decode */
input_SelectES( p_input, p_new_es );
p_current_data += 5 + i_es_info_length;
}
......@@ -1446,4 +1441,7 @@ static void input_DecodePMT( input_thread_t * p_input, es_descriptor_t * p_es )
}
#undef p_psi
/* Remove lock */
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment