Commit c87a6dca authored by gatty's avatar gatty

Migrate network code to use sockaddr_in instead of in_addr_t in readiness for...

Migrate network code to use sockaddr_in instead of in_addr_t in readiness for addition of IPv6 support

git-svn-id: svn://svn.videolan.org/dvblast/trunk@87 55d3f8b6-4a41-4d2d-a900-313d1436a5b8
parent 9e0f8b24
......@@ -207,7 +207,7 @@ static void demux_Handle( block_t *p_ts )
{
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->p_sdt_section )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->p_sdt_section )
output_Put( pp_outputs[i], p_ts );
}
}
......@@ -255,7 +255,7 @@ static void demux_Handle( block_t *p_ts )
output_t *p_output = p_pids[i_pid].pp_outputs[i];
if ( p_output != NULL )
{
if ( i_ca_handle && p_output->b_watch )
if ( i_ca_handle && (p_output->i_config & OUTPUT_WATCH) )
{
uint8_t *p_payload;
......@@ -274,15 +274,13 @@ static void demux_Handle( block_t *p_ts )
if ( p_output->i_nb_errors > MAX_ERRORS )
{
struct in_addr s;
int j;
for ( j = 0; j < i_nb_outputs; j++ )
pp_outputs[j]->i_nb_errors = 0;
s.s_addr = p_output->i_maddr;
msg_Warn( NULL,
"too many errors for stream %s:%d, resetting",
inet_ntoa( s ), p_output->i_port );
inet_ntoa( p_output->maddr.sin_addr ), p_output->maddr.sin_port );
en50221_Reset();
}
}
......@@ -291,7 +289,7 @@ static void demux_Handle( block_t *p_ts )
}
}
if ( output_dup.i_maddr )
if ( output_dup.i_config & OUTPUT_VALID )
output_Put( &output_dup, p_ts );
p_ts->i_refcount--;
......@@ -515,7 +513,7 @@ static void SelectPID( uint16_t i_sid, uint16_t i_pid )
int i;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid
&& !pp_outputs[i]->i_nb_pids )
StartPID( pp_outputs[i], i_pid );
}
......@@ -525,7 +523,7 @@ static void UnselectPID( uint16_t i_sid, uint16_t i_pid )
int i;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid
&& !pp_outputs[i]->i_nb_pids )
StopPID( pp_outputs[i], i_pid );
}
......@@ -538,7 +536,7 @@ static void SelectPSI( uint16_t i_sid, uint16_t i_pid )
int i;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid )
SetPID( i_pid );
}
......@@ -547,7 +545,7 @@ static void UnselectPSI( uint16_t i_sid, uint16_t i_pid )
int i;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid )
UnsetPID( i_pid );
}
......@@ -675,7 +673,7 @@ static void SendPAT( void )
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( !pp_outputs[i]->i_maddr )
if ( !( pp_outputs[i]->i_config & OUTPUT_VALID ) )
continue;
if ( pp_outputs[i]->p_pat_section == NULL &&
......@@ -720,7 +718,7 @@ static void SendSDT( void )
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->p_sdt_section != NULL )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->p_sdt_section != NULL )
{
block_t *p_block;
......@@ -746,7 +744,7 @@ static void SendPMT( sid_t *p_sid )
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == p_sid->i_sid )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == p_sid->i_sid )
{
if ( pp_outputs[i]->p_pmt_section != NULL )
{
......@@ -778,7 +776,7 @@ static void SendEIT( dvbpsi_psi_section_t *p_section, uint16_t i_sid,
for( i = 0; i < i_nb_outputs; i++ )
{
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid )
{
block_t *p_block;
......@@ -959,7 +957,7 @@ static void UpdatePAT( uint16_t i_sid )
int i;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid )
NewPAT( pp_outputs[i] );
}
......@@ -971,7 +969,7 @@ static void UpdatePMT( uint16_t i_sid )
int i;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid )
NewPMT( pp_outputs[i] );
}
......@@ -983,7 +981,7 @@ static int SIDIsSelected( uint16_t i_sid )
int i;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr && pp_outputs[i]->i_sid == i_sid )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) && pp_outputs[i]->i_sid == i_sid )
return 1;
return 0;
......@@ -1412,7 +1410,7 @@ static void SDTCallback( void *_unused, dvbpsi_sdt_t *p_sdt )
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( pp_outputs[i]->i_maddr )
if ( pp_outputs[i]->i_config & OUTPUT_VALID )
NewSDT( pp_outputs[i] );
}
......
......@@ -41,7 +41,7 @@
*****************************************************************************/
output_t **pp_outputs = NULL;
int i_nb_outputs = 0;
output_t output_dup = { 0 };
output_t output_dup = {{ 0 }};
static char *psz_conf_file = NULL;
char *psz_srv_socket = NULL;
int i_ttl = 64;
......@@ -159,8 +159,8 @@ static void ReadConfiguration( char *psz_file )
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( pp_outputs[i]->i_maddr == maddr.s_addr
&& pp_outputs[i]->i_port == i_port )
if ( pp_outputs[i]->maddr.sin_addr.s_addr == maddr.s_addr
&& ntohs( pp_outputs[i]->maddr.sin_port ) == i_port )
{
p_output = pp_outputs[i];
break;
......@@ -172,9 +172,18 @@ static void ReadConfiguration( char *psz_file )
if ( p_output != NULL )
{
demux_Change( p_output, i_sid, pi_pids, i_nb_pids );
p_output->b_rawudp = b_rawudp;
p_output->b_watch = (b_watch == 1);
p_output->b_still_present = 1;
if( b_rawudp )
p_output->i_config |= OUTPUT_UDP;
else
p_output->i_config &= ~OUTPUT_UDP;
if( b_watch == 1)
p_output->i_config |= OUTPUT_WATCH;
else
p_output->i_config &= ~OUTPUT_WATCH;
p_output->i_config |= OUTPUT_STILL_PRESENT;
}
free( pi_pids );
......@@ -184,17 +193,16 @@ static void ReadConfiguration( char *psz_file )
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( pp_outputs[i]->i_maddr && !pp_outputs[i]->b_still_present )
if ( ( pp_outputs[i]->i_config & OUTPUT_VALID ) &&
!( pp_outputs[i]->i_config & OUTPUT_STILL_PRESENT ) )
{
struct in_addr s;
s.s_addr = pp_outputs[i]->i_maddr;
msg_Dbg( NULL, "closing %s:%u", inet_ntoa( s ),
pp_outputs[i]->i_port );
msg_Dbg( NULL, "closing %s:%u", inet_ntoa( pp_outputs[i]->maddr.sin_addr ),
ntohs( pp_outputs[i]->maddr.sin_port ) );
demux_Change( pp_outputs[i], 0, NULL, 0 );
output_Close( pp_outputs[i] );
}
pp_outputs[i]->b_still_present = 0;
pp_outputs[i]->i_config &= ~OUTPUT_STILL_PRESENT;
}
}
......
......@@ -35,6 +35,23 @@
#define MAX_ERRORS 100000
#define DEFAULT_VERBOSITY 3
/*****************************************************************************
* Output configuration flags (for output_t -> i_config) - bit values
* Bit 0 : Set for watch mode
* Bit 1 : Set output still present
* Bit 2 : Set if output is valid (replaces m_addr != 0 tests)
* Bit 3 : Set for UDP, otherwise use RTP if a network stream
* Bit 4 : Set for IPv6, unset for IPv4 (future use)
* Bit 5 : Set for file / FIFO output, unset for network (future use)
*****************************************************************************/
#define OUTPUT_WATCH 0x01
#define OUTPUT_STILL_PRESENT 0x02
#define OUTPUT_VALID 0x04
#define OUTPUT_UDP 0x08
#define OUTPUT_IPV6 0x10
#define OUTPUT_FILE 0x20
typedef int64_t mtime_t;
typedef struct block_t
......@@ -46,8 +63,7 @@ typedef struct block_t
typedef struct output_t
{
in_addr_t i_maddr;
uint16_t i_port;
struct sockaddr_in maddr;
/* output */
int i_handle;
......@@ -73,9 +89,7 @@ typedef struct output_t
uint16_t i_sid; /* 0 if raw mode */
uint16_t *pi_pids;
int i_nb_pids;
int b_watch;
int b_rawudp;
int b_still_present;
uint8_t i_config;
} output_t;
extern int i_verbose;
......@@ -162,7 +176,7 @@ static inline int output_Count( void )
{
int i, i_nb = 0;
for ( i = 0; i < i_nb_outputs; i++ )
if ( pp_outputs[i]->i_maddr )
if ( pp_outputs[i]->i_config & OUTPUT_VALID )
i_nb++;
return i_nb;
}
......
......@@ -51,7 +51,7 @@ output_t *output_Create( in_addr_t i_maddr, uint16_t i_port )
for ( i = 0; i < i_nb_outputs; i++ )
{
if ( !pp_outputs[i]->i_maddr )
if ( !( pp_outputs[i]->i_config & OUTPUT_VALID ) )
{
p_output = pp_outputs[i];
break;
......@@ -100,14 +100,17 @@ int output_Init( output_t *p_output, in_addr_t i_maddr, uint16_t i_port )
p_output->i_ref_timestamp = 0;
p_output->i_ref_wallclock = 0;
p_output->i_maddr = i_maddr;
p_output->i_port = i_port;
p_output->maddr.sin_family = AF_INET;
p_output->maddr.sin_addr.s_addr = i_maddr;
p_output->maddr.sin_port = htons(i_port);
if ( (p_output->i_handle = net_Open(p_output)) < 0 )
{
p_output->i_maddr = 0;
p_output->i_config &= ~OUTPUT_VALID;
return -1;
}
p_output->i_config |= OUTPUT_VALID;
return 0;
}
......@@ -126,7 +129,7 @@ void output_Close( output_t *p_output )
}
p_output->i_depth = 0;
p_output->i_maddr = 0;
p_output->i_config &= ~OUTPUT_VALID;
close( p_output->i_handle );
}
......@@ -140,7 +143,7 @@ static void output_Flush( output_t *p_output )
int i;
int i_outblocks = NB_BLOCKS;
if ( !b_output_udp && !p_output->b_rawudp )
if ( !b_output_udp && !(p_output->i_config & OUTPUT_UDP) )
{
p_iov[0].iov_base = p_rtp_hdr;
p_iov[0].iov_len = sizeof(p_rtp_hdr);
......@@ -165,10 +168,8 @@ static void output_Flush( output_t *p_output )
if ( writev( p_output->i_handle, p_iov, i_outblocks ) < 0 )
{
struct in_addr s;
s.s_addr = p_output->i_maddr;
msg_Err( NULL, "couldn't writev to %s:%u (%s)", inet_ntoa( s ),
p_output->i_port, strerror(errno) );
msg_Err( NULL, "couldn't writev to %s:%u (%s)", inet_ntoa( p_output->maddr.sin_addr ),
p_output->maddr.sin_port, strerror(errno) );
}
for ( i = 0; i < NB_BLOCKS; i++ )
......@@ -200,23 +201,16 @@ void output_Put( output_t *p_output, block_t *p_block )
static int net_Open( output_t *p_output )
{
int i_handle = socket( AF_INET, SOCK_DGRAM, 0 );
struct sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(p_output->i_port);
sin.sin_addr.s_addr = p_output->i_maddr;
if ( connect( i_handle, (struct sockaddr *)&sin, sizeof( sin ) ) < 0 )
if ( connect( i_handle, (struct sockaddr *)&p_output->maddr, sizeof( p_output->maddr ) ) < 0 )
{
struct in_addr s;
s.s_addr = p_output->i_maddr;
msg_Err( NULL, "couldn't connect to %s:%u (%s)", inet_ntoa( s ),
p_output->i_port, strerror(errno) );
msg_Err( NULL, "couldn't connect to %s:%u (%s)", inet_ntoa( p_output->maddr.sin_addr ),
p_output->maddr.sin_port, strerror(errno) );
close( i_handle );
return -1;
}
if ( IN_MULTICAST( ntohl(p_output->i_maddr) ) )
if ( IN_MULTICAST( ntohl(p_output->maddr.sin_addr.s_addr ) ) )
{
int i = i_ttl;
setsockopt( i_handle, IPPROTO_IP, IP_MULTICAST_TTL,
......
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