Commit dc804fe5 authored by Christophe Massiot's avatar Christophe Massiot

The input-II. (more info by mail in about an hour)

parent d9cac7cd
......@@ -100,7 +100,7 @@ ifeq ($(OPTIMS),1)
CFLAGS += -O6
CFLAGS += -ffast-math -funroll-loops -fargument-noalias-global
CFLAGS += -funroll-all-loops -fstrict-aliasing
CFLAGS += -fomit-frame-pointer
#CFLAGS += -fomit-frame-pointer
# Optimizations for x86 familiy
ifneq (,$(findstring 86,$(ARCH)))
......@@ -176,13 +176,9 @@ interface_obj = interface/main.o \
interface/intf_ctrl.o \
interface/intf_console.o
input_obj = input/input_vlan.o \
input/input_file.o \
input/input_netlist.o \
input/input_network.o \
input/input_ctrl.o \
input/input_pcr.o \
input/input_psi.o \
input_obj = input/input_ps.o \
input/mpeg_system.o \
input/input_ext-dec.o \
input/input.o
audio_output_obj = audio_output/audio_output.o
......@@ -236,8 +232,7 @@ misc_obj = misc/mtime.o \
misc/rsc_files.o \
misc/netutils.o \
misc/playlist.o \
misc/plugins.o \
misc/decoder_fifo.o
misc/plugins.o
C_OBJ = $(interface_obj) \
......
......@@ -239,7 +239,7 @@
/* Duration between the time we receive the TS packet, and the time we will
* mark it to be presented */
#define INPUT_PTS_DELAY (.5*CLOCK_FREQ)
#define DEFAULT_PTS_DELAY (.5*CLOCK_FREQ)
#define INPUT_DVD_AUDIO_VAR "vlc_dvd_audio"
#define INPUT_DVD_CHANNEL_VAR "vlc_dvd_channel"
......
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
* input_netlist.h: netlist interface
* The netlists are an essential part of the input structure. We maintain a
* list of free TS packets and free PES packets to avoid continuous malloc
* and free.
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "intf_msg.h"
/*****************************************************************************
* Prototypes
*****************************************************************************/
int input_NetlistInit ( input_thread_t *p_input );
void input_NetlistEnd ( input_thread_t *p_input );
static __inline__ void input_NetlistFreePES( input_thread_t *p_input, pes_packet_t *p_pes_packet );
static __inline__ void input_NetlistFreeTS( input_thread_t *p_input, ts_packet_t *p_ts_packet );
static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input );
/*****************************************************************************
* input_NetlistFreePES: add a PES packet to the netlist
*****************************************************************************
* Add a PES packet to the PES netlist, so that the packet can immediately be
* reused by the demultiplexer. We put this function directly in the .h file,
* because it is very frequently called.
*****************************************************************************/
static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
pes_packet_t *p_pes_packet )
{
int i_dummy;
ts_packet_t * p_ts_packet;
ASSERT(p_pes_packet);
/* We will be playing with indexes, so we take a lock. */
vlc_mutex_lock( &p_input->netlist.lock );
/* Free all TS packets in this PES structure. */
p_ts_packet = p_pes_packet->p_first_ts;
for( i_dummy = 0; i_dummy < p_pes_packet->i_ts_packets; i_dummy++ )
{
ASSERT(p_ts_packet);
#ifdef INPUT_LIFO_TS_NETLIST
p_input->netlist.i_ts_index--;
p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base
= (void *)p_ts_packet;
#else /* FIFO */
p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
= (void *)p_ts_packet;
p_input->netlist.i_ts_end++;
p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
#endif
p_ts_packet = p_ts_packet->p_next_ts;
}
/* Free the PES structure. */
#ifdef INPUT_LIFO_PES_NETLIST
p_input->netlist.i_pes_index--;
p_input->netlist.p_pes_free[p_input->netlist.i_pes_index] = p_pes_packet;
#else /* FIFO */
p_input->netlist.p_pes_free[p_input->netlist.i_pes_end] = p_pes_packet;
p_input->netlist.i_pes_end++;
p_input->netlist.i_pes_end &= INPUT_MAX_PES; /* loop */
#endif
vlc_mutex_unlock( &p_input->netlist.lock );
}
/*****************************************************************************
* input_NetlistFreeTS: add a TS packet to the netlist
*****************************************************************************
* Add a TS packet to the TS netlist, so that the packet can immediately be
* reused by the demultiplexer. Shouldn't be called by other threads (they
* should only use input_FreePES.
*****************************************************************************/
static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
ts_packet_t *p_ts_packet )
{
ASSERT(p_ts_packet);
/* We will be playing with indexes, so we take a lock. */
vlc_mutex_lock( &p_input->netlist.lock );
/* Free the TS structure. */
#ifdef INPUT_LIFO_TS_NETLIST
p_input->netlist.i_ts_index--;
p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base
= (void *)p_ts_packet;
#else /* FIFO */
p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
= (void *)p_ts_packet;
p_input->netlist.i_ts_end++;
p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
#endif
vlc_mutex_unlock( &p_input->netlist.lock );
}
/*****************************************************************************
* input_NetlistGetPES: remove a PES packet from the netlist
*****************************************************************************
* Add a TS packet to the TS netlist, so that the packet can immediately be
* reused by the demultiplexer. Shouldn't be called by other threads (they
* should only use input_FreePES.
*****************************************************************************/
static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input )
{
pes_packet_t * p_pes_packet;
#ifdef INPUT_LIFO_PES_NETLIST
/* i_pes_index might be accessed by a decoder thread to give back a
* packet. */
vlc_mutex_lock( &p_input->netlist.lock );
/* Verify that we still have PES packet in the netlist */
if( (INPUT_MAX_PES - p_input->netlist.i_pes_index ) <= 1 )
{
intf_ErrMsg("input error: PES netlist is empty !\n");
return( NULL );
}
/* Fetch a new PES packet */
p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_index];
p_input->netlist.i_pes_index++;
vlc_mutex_unlock( &p_input->netlist.lock );
#else /* FIFO */
/* No need to lock, since we are the only ones accessing i_pes_start. */
/* Verify that we still have PES packet in the netlist */
if( ((p_input->netlist.i_pes_end -1 - p_input->netlist.i_pes_start) & INPUT_MAX_PES) <= 1 )
{
intf_ErrMsg("input error: PES netlist is empty !\n");
return( NULL );
}
p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_start];
p_input->netlist.i_pes_start++;
p_input->netlist.i_pes_start &= INPUT_MAX_PES; /* loop */
#endif /* netlist type */
/* Initialize PES flags. */
p_pes_packet->b_data_loss = 0;
p_pes_packet->b_data_alignment = 0;
p_pes_packet->b_has_pts = 0;
p_pes_packet->b_random_access = 0;
p_pes_packet->b_discard_payload = 0;
p_pes_packet->i_pes_size = 0;
p_pes_packet->i_pes_real_size = 0;
p_pes_packet->i_ts_packets = 0;
p_pes_packet->p_first_ts = NULL;
p_pes_packet->p_last_ts = NULL;
return( p_pes_packet );
}
/*****************************************************************************
* input_file.h: file input method
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Prototypes
*****************************************************************************/
#define REQUESTED_AC3 0
#define REQUESTED_MPEG 1
#define REQUESTED_LPCM 2
#define REQUESTED_NOAUDIO 255
/*****************************************************************************
* input_vlan.h: vlan input method
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Required headers:
* <netinet/in.h>
* "threads.h"
*****************************************************************************/
/*****************************************************************************
* Prototypes
*****************************************************************************/
int input_VlanCreate ( void );
void input_VlanDestroy ( void );
int input_VlanJoin ( int i_vlan_id );
void input_VlanLeave ( int i_vlan_id );
/* Structures exported to interface, input and decoders */
/*****************************************************************************
* stream_ctrl_t
*****************************************************************************
* Describe the state of a program stream.
*****************************************************************************/
typedef struct stream_ctrl_s
{
vlc_mutex_t control_lock;
int i_status;
/* if i_status == FORWARD_S or BACKWARD_S */
int i_rate;
s64 i_ref_sysdate;
s64 i_ref_clock;
boolean_t b_mute;
boolean_t b_bw; /* black & white */
} stream_ctrl_t;
/* Possible status : */
#define PLAYING_S 0
#define PAUSE_S 1
#define FORWARD_S 2
#define BACKWARD_S 3
#define DEFAULT_RATE 1000
......@@ -95,10 +95,10 @@ typedef struct vpar_thread_s
/* Input properties */
decoder_fifo_t fifo; /* PES input fifo */
/* The bit stream structure handles the PES stream at the bit level */
decoder_fifo_t * p_fifo; /* PES input fifo */
bit_stream_t bit_stream;
vdec_config_t * p_config;
/* Output properties */
vout_thread_t * p_vout; /* video output thread */
......@@ -151,28 +151,20 @@ typedef struct vpar_thread_s
*****************************************************************************/
/* Thread management functions */
vpar_thread_t * vpar_CreateThread ( /* video_cfg_t *p_cfg, */ input_thread_t *p_input /*,
vout_thread_t *p_vout, int *pi_status */ );
void vpar_DestroyThread ( vpar_thread_t *p_vpar /*, int *pi_status */ );
/* Time management functions */
/* XXX?? */
/* Dynamic thread settings */
/* XXX?? */
vlc_thread_t vpar_CreateThread ( vdec_config_t * );
/*****************************************************************************
* NextStartCode : Find the next start code
*****************************************************************************/
static __inline__ void NextStartCode( vpar_thread_t * p_vpar )
static __inline__ void NextStartCode( bit_stream_t * p_bit_stream )
{
/* Re-align the buffer on an 8-bit boundary */
RealignBits( &p_vpar->bit_stream );
RealignBits( p_bit_stream );
while( ShowBits( &p_vpar->bit_stream, 24 ) != 0x01L && !p_vpar->b_die )
while( ShowBits( p_bit_stream, 24 ) != 0x01L
&& !p_bit_stream->p_decoder_fifo->b_die )
{
RemoveBits( &p_vpar->bit_stream, 8 );
RemoveBits( p_bit_stream, 8 );
}
}
......
......@@ -26,8 +26,6 @@
#include "defs.h"
#include <stdlib.h> /* malloc(), free() */
#include <sys/types.h> /* on BSD, uio.h needs types.h */
#include <sys/uio.h> /* "input.h" */
#include "config.h"
#include "common.h"
......@@ -35,7 +33,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
......@@ -44,7 +44,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
......@@ -42,7 +42,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
......@@ -36,7 +36,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
......@@ -41,7 +41,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
......@@ -41,7 +41,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
......@@ -38,7 +38,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
......@@ -41,7 +41,9 @@
#include "mtime.h"
#include "plugins.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "video.h"
#include "video_output.h"
......
This diff is collapsed.
......@@ -36,10 +36,10 @@ typedef struct ac3dec_thread_s
/*
* Input properties
*/
decoder_fifo_t fifo; /* stores the PES stream data */
input_thread_t * p_input;
ts_packet_t * p_ts;
int sync_ptr; /* sync ptr from ac3 magic header */
decoder_fifo_t * p_fifo; /* stores the PES stream data */
data_packet_t * p_data;
int sync_ptr; /* sync ptr from ac3 magic header */
adec_config_t * p_config;
/*
* Decoder properties
......@@ -58,5 +58,4 @@ typedef struct ac3dec_thread_s
/*****************************************************************************
* Prototypes
*****************************************************************************/
ac3dec_thread_t * ac3dec_CreateThread( input_thread_t * p_input );
void ac3dec_DestroyThread( ac3dec_thread_t * p_ac3dec );
vlc_thread_t ac3dec_CreateThread( adec_config_t * p_config );
This diff is collapsed.
......@@ -36,10 +36,11 @@ typedef struct adec_thread_s
/*
* Input properties
*/
decoder_fifo_t fifo; /* stores the PES stream data */
input_thread_t * p_input;
ts_packet_t * p_ts;
int align;
decoder_fifo_t * p_fifo; /* stores the PES stream data */
data_packet_t * p_data;
int align;
adec_config_t * p_config;
/*
* Decoder properties
......@@ -57,5 +58,4 @@ typedef struct adec_thread_s
/*****************************************************************************
* Prototypes
*****************************************************************************/
adec_thread_t * adec_CreateThread ( input_thread_t * p_input /* !! , aout_thread_t * p_aout !! */ );
void adec_DestroyThread ( adec_thread_t * p_adec );
vlc_thread_t adec_CreateThread ( adec_config_t * p_config );
This diff is collapsed.
/* Communication plugin -> input */
#define INPUT_READ_ONCE 7 /* We live in a world dominated by Ethernet. *
* Ethernet MTU is 1500 bytes, so in a UDP *
* packet we can put : 1500/188 = 7 TS *
* packets. Have a nice day and merry Xmas. */
/*****************************************************************************
* input_capabilities_t
*****************************************************************************
* This structure gives pointers to the useful methods of the plugin
*****************************************************************************/
typedef struct input_capabilities_s
{
/* Plugin properties */
int i_weight; /* for a given stream type, the plugin *
* with higher weight will be used */
/* Init/End */
int (* pf_probe)( struct input_thread_s * );
void (* pf_init)( struct input_thread_s * );
void (* pf_end)( struct input_thread_s * );
/* Read & Demultiplex */
void (* pf_read)( struct input_thread_s *,
struct data_packet_s * pp_packets[INPUT_READ_ONCE] );
void (* pf_demux)( struct input_thread_s *,
struct data_packet_s * );
/* Packet management facilities */
struct data_packet_s *(* pf_new_packet)( void *, size_t );
void (* pf_delete_packet)( void *,
struct data_packet_s * );
void (* pf_delete_pes)( void *, struct pes_packet_s * );
/* Stream control capabilities */
int (* pf_rewind)( struct input_thread_s * );
/* NULL if we don't support going *
* backwards (it's gonna be fun) */
int (* pf_seek)( struct input_thread_s *, off_t );
} input_capabilities_t;
/*****************************************************************************
* Prototypes from input_ext-dec.c
*****************************************************************************/
void InitBitstream ( struct bit_stream_s *, struct decoder_fifo_s * );
void NextDataPacket ( struct bit_stream_s * );
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
* input_file.h: file streams functions interface
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Prototypes
*****************************************************************************/
int input_FileOpen ( input_thread_t *p_input );
int input_FileRead ( input_thread_t *p_input, const struct iovec *p_vector,
size_t i_count );
void input_FileClose ( input_thread_t *p_input );
/*****************************************************************************
* netlist.c: input thread
* Manages the TS and PES netlists (see netlist.h).
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h"
#include <sys/types.h> /* on BSD, uio.h needs types.h */
#include <sys/uio.h> /* "input.h" */
#include <stdlib.h> /* free() */
#include <string.h> /* strerror() */
#include <errno.h> /* errno */
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "intf_msg.h"
#include "debug.h"
#include "input.h"
#include "input_netlist.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
/*****************************************************************************
* input_NetlistOpen: initialize the netlists buffers
*****************************************************************************/
int input_NetlistInit( input_thread_t *p_input )
{
int i_base, i_packets, i_iovec;
/* Initialize running indexes. */
#ifdef INPUT_LIFO_TS_NETLIST
p_input->netlist.i_ts_index = INPUT_TS_READ_ONCE;
#else
p_input->netlist.i_ts_start = 0;
p_input->netlist.i_ts_end = 0;
#endif
#ifdef INPUT_LIFO_PES_NETLIST
p_input->netlist.i_pes_index = 1; /* We allocate one PES at a time */
#else
p_input->netlist.i_pes_start = 0;
p_input->netlist.i_pes_end = 0;
#endif
/* Initialize all iovec from the TS netlist with the length of a packet */
for( i_iovec = 0; i_iovec < INPUT_MAX_TS + INPUT_TS_READ_ONCE; i_iovec++ )
{
p_input->netlist.p_ts_free[i_iovec].iov_len = TS_PACKET_SIZE;
}
/* Allocate a big piece of memory to contain the INPUT_MAX_TS TS packets */
if( ( p_input->netlist.p_ts_packets = malloc( (INPUT_MAX_TS + 1)
* sizeof(ts_packet_t) ) ) == NULL )
{
intf_ErrMsg("input error: can't allocate TS netlist buffer (%s)\n",
strerror(errno) );
return( -1 );
}
/* Allocate a big piece of memory to contain the INPUT_MAX_PES PES packets */
if( !( p_input->netlist.p_pes_packets = malloc( (INPUT_MAX_PES + 1)
* sizeof(pes_packet_t) ) ) )
{
intf_ErrMsg("input error: can't allocate PES netlist buffer (%s)\n",
strerror(errno) );
free( p_input->netlist.p_ts_packets );
return( -1 );
}
/* Insert TS packets into the TS netlist */
#ifdef INPUT_LIFO_TS_NETLIST
i_base = p_input->netlist.i_ts_index;
#else
i_base = p_input->netlist.i_ts_start;
#endif
/* i_base is now the base address to locate free packets in the netlist */
for( i_packets = 0; i_packets < INPUT_MAX_TS + 1; i_packets++ )
{
p_input->netlist.p_ts_free[i_base + i_packets].iov_base
= (void *)(p_input->netlist.p_ts_packets + i_packets);
/* Initialize TS length. */
(p_input->netlist.p_ts_packets[i_packets]).i_payload_end = TS_PACKET_SIZE;
}
/* Insert PES packets into the netlist */
#ifdef INPUT_LIFO_PES_NETLIST
i_base = p_input->netlist.i_pes_index;
#else
i_base = p_input->netlist.i_pes_start;
#endif
/* i_base is now the base address to locate free packets in the netlist */
for( i_packets = 0; i_packets < INPUT_MAX_PES + 1; i_packets++ )
{
p_input->netlist.p_pes_free[i_base + i_packets]
= p_input->netlist.p_pes_packets + i_packets;
}
/* the p_pes_header_save buffer is allocated on the fly by the PES
demux if needed, and freed with the PES packet when the netlist
is destroyed. We initialise the field to NULL so that the demux
can determine if it has already allocated this buffer or not. */
for( i_packets = 0; i_packets < INPUT_MAX_PES + 1; i_packets++ )
{
p_input->netlist.p_pes_packets[i_packets].p_pes_header_save = NULL;
}
return( 0 );
}
/*****************************************************************************
* input_NetlistClean: clean the netlists buffers
*****************************************************************************/
void input_NetlistEnd( input_thread_t *p_input )
{
int i;
/* free TS netlist */
free( p_input->netlist.p_ts_packets );
/* free the pes_buffer_save buffers of the PES packets if they have
been allocated */
for( i = 0; i < INPUT_MAX_PES + 1; i++ )
{
byte_t* p_buffer = p_input->netlist.p_pes_packets[i].p_pes_header_save;
if(p_buffer)
free(p_buffer);
}
/* free PES netlist */
free( p_input->netlist.p_pes_packets );
}
/*****************************************************************************
* network.c: functions to read from the network
* Manages a socket.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Benot Steiner <benny@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h"
#include <sys/types.h> /* on BSD, uio.h needs types.h */
#include <sys/uio.h> /* "input.h" */
#include <string.h> /* strerror() */
#include <unistd.h> /* close() */
#include <errno.h> /* errno */
#include <sys/time.h> /* "input_network.h" */
#if defined(SYS_BSD) || defined(SYS_BEOS)
#include <sys/socket.h> /* struct sockaddr */
#endif
#include <netdb.h> /* servent, getservbyname(), hostent, gethostbyname() */
#include <netinet/in.h> /* sockaddr_in, htons(), htonl() */
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "netutils.h"
#include "input.h"
#include "input_network.h"
#include "input_vlan.h"
#include "intf_msg.h"
#include "plugins.h"
#include "main.h"
/*****************************************************************************
* input_NetworkOpen: initialize a network stream
*****************************************************************************/
int input_NetworkOpen( input_thread_t *p_input )
{
int i_socket_option;
struct sockaddr_in sa_in;
char psz_hostname[INPUT_MAX_SOURCE_LENGTH];
/* First and foremost, in the VLAN method, join the desired VLAN. */
if( p_input->i_method == INPUT_METHOD_TS_VLAN_BCAST )
{
if( input_VlanJoin( p_input->i_vlan ) )
{
intf_ErrMsg("error: can't join vlan %d\n", p_input->i_vlan);
return( 1 );
}
}
/* Open a SOCK_DGRAM (UDP) socket, in the AF_INET domain, automatic (0)
* protocol */
if( (p_input->i_handle = socket( AF_INET, SOCK_DGRAM, 0 )) == (-1) )
{
intf_ErrMsg("error: can't create socket (%s)\n", strerror(errno));
return( 1 );
}
/*
* Set up the options of the socket
*/
/* Set SO_REUSEADDR option which allows to re-bind() a busy port */
i_socket_option = 1;
if( setsockopt( p_input->i_handle,
SOL_SOCKET,
SO_REUSEADDR,
&i_socket_option,
sizeof( i_socket_option ) ) == (-1) )
{
intf_ErrMsg("error: can't configure socket (SO_REUSEADDR: %s)\n", strerror(errno));
close( p_input->i_handle );
return( 1 );
}
#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_socket_option = 524288;
if( setsockopt( p_input->i_handle,
SOL_SOCKET,
SO_RCVBUF,
&i_socket_option,
sizeof( i_socket_option ) ) == (-1) )
{
intf_ErrMsg("error: can't configure socket (SO_RCVBUF: %s)\n", strerror(errno));
close( p_input->i_handle );
return( 1 );
}
#endif /* SYS_BEOS */
/*
* Bind the socket
*/
/* Use default port if not specified */
if( p_input->i_port == 0 )
{
p_input->i_port = main_GetIntVariable( INPUT_PORT_VAR, INPUT_PORT_DEFAULT );
}
/* See if the user requested broadcast method */
if( main_GetIntVariable( INPUT_BROADCAST_VAR, INPUT_BROADCAST_DEFAULT ) )
{
p_input->i_method = INPUT_METHOD_TS_BCAST;
}
/* Find the address. */
switch( p_input->i_method )
{
case INPUT_METHOD_TS_BCAST:
case INPUT_METHOD_TS_VLAN_BCAST:
/* In that case, we have to bind with the broadcast address.
* broadcast addresses are very hard to find and depends on
* implementation, so we thought using a #define would be much
* simpler. */
#ifdef INPUT_BCAST_ADDR
if( BuildInetAddr( &sa_in, INPUT_BCAST_ADDR, p_input->i_port ) == (-1) )
{
close( p_input->i_handle );
return( 1 );
}
#else
/* We bind with any address. Security problem ! */
if( BuildInetAddr( &sa_in, NULL, p_input->i_port ) == (-1) )
{
close( p_input->i_handle );
return( -1 );
}
#endif
break;
case INPUT_METHOD_TS_UCAST:
/* Unicast: bind with the local address. */
if( gethostname( psz_hostname, sizeof( psz_hostname ) ) == (-1) )
{
intf_ErrMsg("error: can't get hostname (%s)\n", strerror(errno));
close( p_input->i_handle );
return( 1 );
}
if( BuildInetAddr( &sa_in, psz_hostname, p_input->i_port ) == (-1) )
{
close( p_input->i_handle );
return( 1 );
}
break;
case INPUT_METHOD_TS_MCAST:
/* Multicast: bind with 239.0.0.1. */
if( BuildInetAddr( &sa_in, "239.0.0.1", p_input->i_port ) == (-1) )
{
close( p_input->i_handle );
return( 1 );
}
break;
}
/* Effectively bind the socket. */
if( bind( p_input->i_handle, (struct sockaddr *) &sa_in, sizeof( sa_in ) ) < 0 )
{
intf_ErrMsg("error: can't bind socket (%s)\n", strerror(errno));
close( p_input->i_handle );
return( 1 );
}
/*
* Connect the socket to the remote server
*/
/* Use default host if not specified */
if( p_input->p_source == NULL )
{
p_input->p_source = main_GetPszVariable( INPUT_SERVER_VAR, INPUT_SERVER_DEFAULT );
}
if( BuildInetAddr( &sa_in, p_input->p_source, htons(0) ) == (-1) )
{
close( p_input->i_handle );
return( -1 );
}
/* Connect the socket. */
if( connect( p_input->i_handle, (struct sockaddr *) &sa_in,
sizeof( sa_in ) ) == (-1) )
{
intf_ErrMsg("error: can't connect socket\n" );
close( p_input->i_handle );
return( 1 );
}
return( 0 );
}
/*****************************************************************************
* input_NetworkRead: read a stream from the network
*****************************************************************************
* Wait for data during up to 1 second and then abort if none is arrived. The
* number of bytes read is returned or -1 if an error occurs (so 0 is returned
* after a timeout)
* We don't have to make any test on presentation times, since we suppose
* the network server sends us data when we need it.
*****************************************************************************/
int input_NetworkRead( input_thread_t *p_input, const struct iovec *p_vector,
size_t i_count )
{
fd_set rfds;
struct timeval tv;
int i_rc;
/* Watch the given fd to see when it has input */
FD_ZERO(&rfds);
FD_SET(p_input->i_handle, &rfds);
/* Wait up to 1 second */
tv.tv_sec = 1;
tv.tv_usec = 0;
i_rc = select(p_input->i_handle+1, &rfds, NULL, NULL, &tv);
if( i_rc > 0 )
{
/* Data were received before timeout */
i_rc = readv( p_input->i_handle, p_vector, i_count );
}
return( i_rc );
}
/*****************************************************************************
* input_NetworkClose: close a network stream
*****************************************************************************/
void input_NetworkClose( input_thread_t *p_input )
{
/* Close local socket. */
if( p_input->i_handle )
{
close( p_input->i_handle );
}
/* Leave vlan if required */
if( p_input->i_method == INPUT_METHOD_TS_VLAN_BCAST )
{
input_VlanLeave( p_input->i_vlan );
}
}
/*****************************************************************************
* input_network.h: network functions interface
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Christophe Massiot <massot@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Prototypes
*****************************************************************************/
int input_NetworkOpen ( input_thread_t *p_input );
int input_NetworkRead ( input_thread_t *p_input, const struct iovec *p_vector,
size_t i_count );
void input_NetworkClose ( input_thread_t *p_input );
This diff is collapsed.
/*****************************************************************************
* input_pcr.h: PCR management interface
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/* Maximum number of samples used to compute the dynamic average value,
* it is also the maximum of c_average in the pcr_descriptor_struct.
* We use the following formula :
* new_average = (old_average * c_average + new_sample_value) / (c_average +1) */
#define PCR_MAX_AVERAGE_COUNTER 40
/* Maximum gap allowed between two PCRs. */
#define PCR_MAX_GAP 1000000
/* synchro states */
#define SYNCHRO_NOT_STARTED 1
#define SYNCHRO_START 2
#define SYNCHRO_REINIT 3
/*****************************************************************************
* Prototypes
*****************************************************************************/
int input_PcrInit ( input_thread_t *p_input );
void input_PcrDecode ( input_thread_t *p_input, es_descriptor_t* p_es,
u8* p_pcr_data );
void input_PcrEnd ( input_thread_t *p_input );
This diff is collapsed.
/*****************************************************************************
* Constants
*****************************************************************************/
/*****************************************************************************
* thread_ps_data_t: extension of input_thread_t
*****************************************************************************/
typedef struct thread_ps_data_s
{
/* We're necessarily reading a file. */
FILE * stream;
} thread_ps_data_t;
This diff is collapsed.
/*****************************************************************************
* psi.h: PSI management interface
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Benoît Steiner <benny@via.ecp.fr>
*
* 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
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Prototypes
*****************************************************************************/
int input_PsiInit ( input_thread_t *p_input );
void input_PsiDecode ( input_thread_t *p_input, psi_section_t* p_psi_section );
void input_PsiRead ( input_thread_t *p_input );
int input_PsiEnd ( input_thread_t *p_input );
/*****************************************************************************
* thread_ts_data_t: extension of input_thread_t
*****************************************************************************/
typedef struct thread_ts_data_s
{
/* To use the efficiency of the scatter/gather IO operations without
* malloc'ing all the time, we implemented a FIFO of free data packets.
*/
vlc_mutex_lock lock;
struct iovec p_free_iovec[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
data_packet_t * p_free_ts[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
int i_free_start, i_free_end;
/* The free data packets are stored here : */
data_packet_t * p_data_packets;
byte_t * p_buffers;
} thread_ts_data_t;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -59,7 +59,8 @@
#include "plugins.h"
#include "intf_msg.h"
#include "input.h"
#include "stream_control.h"
#include "input_ext-intf.h"
#include "audio_output.h"
#include "intf_cmd.h"
#include "interface.h"
......@@ -463,6 +464,8 @@ static int SpawnInput( int i_argc, intf_arg_t *p_argv )
int i_port = 0; /* port parameter */
int i_vlan = 0; /* vlan parameter */
/* FIXME */
#if 0
/* Parse parameters - see command list above */
for ( i_arg = 1; i_arg < i_argc; i_arg++ )
{
......@@ -495,6 +498,7 @@ static int SpawnInput( int i_argc, intf_arg_t *p_argv )
p_main->p_intf->p_vout, p_main->p_aout,
NULL );
return( INTF_NO_ERROR );
#endif
}
/*****************************************************************************
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -36,8 +36,9 @@
#include "intf_msg.h"
#include "input.h"
#include "decoder_fifo.h"
#include "stream_control.h"
#include "input_ext-dec.h"
#include "video.h"
#include "video_output.h"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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