Commit 5f621acb authored by Christophe Massiot's avatar Christophe Massiot

* multicat.c: New -X option to enable pass-through to stdout.

 * Various bug fixes to the code committed yesterday.
parent c53e35cb
......@@ -73,9 +73,10 @@ void (*pf_ExitWrite)(void);
static void usage(void)
{
msg_Raw( NULL, "Usage: multicat [-i <RT priority>] [-t <ttl>] [-f] [-p <PCR PID>] [-s <chunks>] [-n <chunks>] [-k <start time>] [-d <duration>] [-a] [-r <file duration>] [-S <SSRC IP>] [-u] [-U] [-m <payload size>] <input item> <output item>" );
msg_Raw( NULL, "Usage: multicat [-i <RT priority>] [-t <ttl>] [-X] [-f] [-p <PCR PID>] [-s <chunks>] [-n <chunks>] [-k <start time>] [-d <duration>] [-a] [-r <file duration>] [-S <SSRC IP>] [-u] [-U] [-m <payload size>] <input item> <output item>" );
msg_Raw( NULL, " item format: <file path | device path | FIFO path | directory path | network host>" );
msg_Raw( NULL, " host format: [<connect addr>[:<connect port>]][@[<bind addr][:<bind port>]]" );
msg_Raw( NULL, " -X: also pass-through all packets to stdout" );
msg_Raw( NULL, " -f: output packets as fast as possible" );
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 [deprecated]" );
......@@ -582,6 +583,7 @@ static void GetPCR( const uint8_t *p_buffer, size_t i_read_size )
int main( int i_argc, char **pp_argv )
{
int i_priority = -1;
bool b_passthrough = false;
off_t i_skip_chunks = 0, i_nb_chunks = -1;
int64_t i_seek = 0;
uint64_t i_duration = 0;
......@@ -593,7 +595,7 @@ int main( int i_argc, char **pp_argv )
sigset_t set;
/* Parse options */
while ( (c = getopt( i_argc, pp_argv, "i:t:fp:s:n:k:d:aS:uUm:h" )) != -1 )
while ( (c = getopt( i_argc, pp_argv, "i:t:Xfp:s:n:k:d:ar:S:uUm:h" )) != -1 )
{
switch ( c )
{
......@@ -605,6 +607,10 @@ int main( int i_argc, char **pp_argv )
i_ttl = strtol( optarg, NULL, 0 );
break;
case 'X':
b_passthrough = true;
break;
case 'f':
b_sleep = false;
break;
......@@ -851,6 +857,10 @@ int main( int i_argc, char **pp_argv )
}
pf_Write( p_write_buffer, i_write_size );
if ( b_passthrough )
if ( write( STDOUT_FILENO, p_write_buffer, i_write_size )
!= i_write_size )
msg_Warn( NULL, "write(stdout) error (%s)", strerror(errno) );
if ( i_nb_chunks > 0 )
i_nb_chunks--;
......
......@@ -33,8 +33,12 @@ fi
DIR=$1
WANTED_CHUNKS=$2
NB_CHUNKS=`ls -f "$DIR/*.ts" | wc -l`
cd "$DIR"
NB_CHUNKS=`ls -f *.ts | wc -l`
if test $NB_CHUNKS -gt $WANTED_CHUNKS; then
ls -t "$DIR/*.ts" | tail -n $(($WANTED_CHUNKS-$NB_CHUNKS)) | xargs echo
ls -t *.ts | tail -n $(($WANTED_CHUNKS-$NB_CHUNKS)) | cut -d. -f 1 | xargs -I FILE sh -c "rm FILE.ts FILE.aux*"
fi
ls -t *.ts | tail -n 1 | cut -d. -f 1
......@@ -173,9 +173,10 @@ static void _wall_Sleep( uint64_t i_delay, bool b_realtime )
ts.tv_nsec = (i_delay % 27000000) * 1000 / 27;
#if defined( HAVE_CLOCK_NANOSLEEP )
int val;
while ( !b_realtime || ( val = clock_nanosleep( CLOCK_MONOTONIC, 0, &ts, &ts ) ) == EINTR );
if( !b_realtime || val == EINVAL )
int val = EINVAL;
if ( !b_realtime )
while ( ( val = clock_nanosleep( CLOCK_MONOTONIC, 0, &ts, &ts ) ) == EINTR );
if( val == EINVAL )
{
ts.tv_sec = i_delay / 27000000;
ts.tv_nsec = (i_delay % 27000000) * 1000 / 27;
......@@ -737,15 +738,15 @@ char *GetAuxFile( const char *psz_arg, size_t i_payload_size )
strcpy( psz_aux, psz_arg );
/* Skip first character of base name */
psz_token = strrchr( psz_aux, '/' );
if ( psz_token != NULL )
psz_token++;
else
psz_token = psz_aux + 1;
if ( *psz_token ) psz_token++; /* Skip first character of base name */
/* Strip extension */
psz_token = strrchr( psz_aux, '.' );
psz_token = strrchr( psz_token, '.' );
if ( psz_token ) *psz_token = '\0';
/* Append extension */
......
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