diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-10-15 05:43:25 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-10-15 05:43:25 +0200 |
commit | 5596daacb1b8ac8bd396882abf827887cae4b1c9 (patch) | |
tree | aae394e1112317459f309b6c19a43808fff8eb1d | |
parent | a3d38c49ba1698e022d41b43490aa23b874e8439 (diff) | |
download | multicat-5596daacb1b8ac8bd396882abf827887cae4b1c9.tar multicat-5596daacb1b8ac8bd396882abf827887cae4b1c9.zip |
multicat: improve signal and EOF handling
-rw-r--r-- | multicat.c | 44 |
1 files changed, 36 insertions, 8 deletions
@@ -42,7 +42,7 @@ /***************************************************************************** * Local declarations *****************************************************************************/ -static int i_input_fd, i_output_fd; +static int i_input_fd = -1, i_output_fd; FILE *p_input_aux, *p_output_aux; static uint16_t i_pcr_pid = 0; static bool b_overwrite_ssrc = false; @@ -59,11 +59,15 @@ void (*pf_Skip)( size_t i_len, int i_nb_chunks ); ssize_t (*pf_Read)( void *p_buf, size_t i_len ); ssize_t (*pf_Write)( const void *p_buf, size_t i_len ); +extern int i_verbose; + static void usage(void) { - msg_Raw( NULL, "Usage: multicat [-i <RT priority>] [-t <ttl>] [-p <PCR PID>] [-s <chunks>] [-n <chunks>] [-d <time>] [-a] [-S <SSRC IP>] [-u] [-U] [-P] [-m <payload size>] <input item> <output item>" ); + msg_Raw( NULL, "Usage: multicat [-v] [-i <RT priority>] [-t <ttl>] [-p <PCR PID>] [-s <chunks>] [-n <chunks>] [-d <time>] [-a] [-S <SSRC IP>] [-u] [-U] [-P] [-m <payload size>] <input item> <output item>" ); msg_Raw( NULL, " item format: <file path | device path | FIFO path | network host>" ); msg_Raw( NULL, " host format: [<connect addr>[:<connect port>]][@[<bind addr][:<bind port>]]" ); + msg_Raw( NULL, " -v: enable verbose output" ); + msg_Raw( NULL, " -vv: more verbose output" ); msg_Raw( NULL, " -p: overwrite or create RTP timestamps using PCR PID (MPEG-2/TS)" ); msg_Raw( NULL, " -s: skip the first N chunks of payload" ); msg_Raw( NULL, " -n: exit after playing N chunks of payload" ); @@ -83,6 +87,9 @@ static void usage(void) static void SigHandler( int i_signal ) { b_die = true; + + if ( i_input_fd >= 0 ) + close(i_input_fd); } /***************************************************************************** @@ -100,8 +107,11 @@ static ssize_t udp_Read( void *p_buf, size_t i_len ) ssize_t i_ret; if ( (i_ret = recv( i_input_fd, p_buf, i_len, 0 )) < 0 ) { - msg_Err( NULL, "recv error (%s)", strerror(errno) ); - b_die = true; + if ( !b_die ) + { + msg_Err( NULL, "recv error (%s)", strerror(errno) ); + b_die = true; + } return 0; } @@ -137,7 +147,16 @@ static ssize_t stream_Read( void *p_buf, size_t i_len ) ssize_t i_ret; if ( (i_ret = read( i_input_fd, p_buf, i_len )) < 0 ) { - msg_Err( NULL, "read error (%s)", strerror(errno) ); + if ( !b_die ) + { + msg_Err( NULL, "read error (%s)", strerror(errno) ); + b_die = true; + } + return 0; + } + if ( i_ret == 0 ) + { + msg_Dbg( NULL, "end of file reached" ); b_die = true; return 0; } @@ -179,8 +198,11 @@ static ssize_t file_Read( void *p_buf, size_t i_len ) if ( (i_ret = read( i_input_fd, p_buf, i_len )) < 0 ) { - msg_Err( NULL, "read error (%s)", strerror(errno) ); - b_die = true; + if ( !b_die ) + { + msg_Err( NULL, "read error (%s)", strerror(errno) ); + b_die = true; + } return 0; } if ( i_ret == 0 ) @@ -281,10 +303,16 @@ int main( int i_argc, char **pp_argv ) size_t i_max_read_size, i_max_write_size; int c; - while ( (c = getopt( i_argc, pp_argv, "i:t:p:s:n:d:aS:uUPm:h" )) != -1 ) + i_verbose = VERB_WARN; + + while ( (c = getopt( i_argc, pp_argv, "vi:t:p:s:n:d:aS:uUPm:h" )) != -1 ) { switch ( c ) { + case 'v': + i_verbose++; + break; + case 'i': i_priority = strtol( optarg, NULL, 0 ); break; |