Commit 64354fcd authored by Christophe Massiot's avatar Christophe Massiot

* utils.c: Add a new level of verboseness so that error output can be...

* utils.c: Add a new level of verboseness so that error output can be disabled. * dvblast.c, demux.c: Reflect the change in biTStream API for printing. New -x switch to enable event output on stdout.
parent ca663870
......@@ -27,6 +27,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdarg.h>
#include <inttypes.h>
#include <sys/socket.h>
#include <netinet/in.h>
......@@ -187,6 +188,18 @@ static void demux_Handle( block_t *p_ts )
if ( !ts_validate( p_ts->p_ts ) )
{
msg_Warn( NULL, "lost TS sync" );
switch ( i_print_type )
{
case PRINT_XML:
printf("<ERROR type=\"invalid_ts\"/>\n");
break;
case PRINT_TEXT:
printf("lost TS sync");
break;
default:
break;
}
block_Delete( p_ts );
return;
}
......@@ -194,11 +207,38 @@ static void demux_Handle( block_t *p_ts )
if ( i_pid != PADDING_PID && p_pids[i_pid].i_last_cc != -1
&& !ts_check_duplicate( i_cc, p_pids[i_pid].i_last_cc )
&& ts_check_discontinuity( i_cc, p_pids[i_pid].i_last_cc ) )
{
msg_Warn( NULL, "TS discontinuity" );
switch ( i_print_type )
{
case PRINT_XML:
printf("<ERROR type=\"invalid_discontinuity\" pid=\"%hu\"/>\n",
i_pid);
break;
case PRINT_TEXT:
printf("TS discontinuity (PID=%hu)", i_pid);
break;
default:
break;
}
}
if ( ts_get_transporterror( p_ts->p_ts ) )
{
msg_Warn( NULL, "transport_error_indicator" );
switch ( i_print_type )
{
case PRINT_XML:
printf("<ERROR type=\"transport_error\" pid=\"%hu\"/>\n",
i_pid);
break;
case PRINT_TEXT:
printf("transport_error_indicator (PID=%hu)", i_pid);
break;
default:
break;
}
i_nb_errors++;
i_last_error = i_wallclock;
}
......@@ -1507,6 +1547,23 @@ char *demux_Iconv(void *_unused, const char *psz_encoding,
#endif
}
/*****************************************************************************
* demux_Print
*****************************************************************************
* This code is from biTStream's examples and is under the WTFPL (see
* LICENSE.WTFPL).
*****************************************************************************/
static void demux_Print(void *_unused, const char *psz_format, ...)
{
char psz_fmt[strlen(psz_format) + 2];
va_list args;
va_start(args, psz_format);
strcpy(psz_fmt, psz_format);
if ( i_print_type != PRINT_XML )
strcat(psz_fmt, "\n");
vprintf(psz_fmt, args);
}
/*****************************************************************************
* HandlePAT
*****************************************************************************/
......@@ -1529,6 +1586,13 @@ static void HandlePAT( mtime_t i_dts )
if ( !pat_table_validate( pp_next_pat_sections ) )
{
msg_Warn( NULL, "invalid PAT received" );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_pat\"/>\n");
break;
default:
printf("invalid PAT received\n");
}
psi_table_free( pp_next_pat_sections );
psi_table_init( pp_next_pat_sections );
goto out_pat;
......@@ -1643,7 +1707,16 @@ static void HandlePAT( mtime_t i_dts )
}
if ( b_display )
pat_table_print( pp_current_pat_sections, msg_Dbg, NULL );
{
pat_table_print( pp_current_pat_sections, msg_Dbg, NULL, PRINT_TEXT );
if ( i_print_type != -1 )
{
pat_table_print( pp_current_pat_sections, demux_Print, NULL,
i_print_type );
if ( i_print_type == PRINT_XML )
printf("\n");
}
}
out_pat:
SendPAT( i_dts );
......@@ -1658,6 +1731,13 @@ static void HandlePATSection( uint16_t i_pid, uint8_t *p_section,
if ( i_pid != PAT_PID || !pat_validate( p_section ) )
{
msg_Warn( NULL, "invalid PAT section received on PID %hu", i_pid );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_pat_section\"/>\n");
break;
default:
printf("invalid PAT section received on PID %hu\n", i_pid);
}
free( p_section );
return;
}
......@@ -1698,6 +1778,15 @@ static void HandlePMT( uint16_t i_pid, uint8_t *p_pmt, mtime_t i_dts )
if ( i_pid != p_sid->i_pmt_pid )
{
msg_Warn( NULL, "invalid PMT section received on PID %hu", i_pid );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"ghost_pmt\" program=\"%hu\n pid=\"%hu\"/>\n",
i_sid, i_pid);
break;
default:
printf("ghost PMT for service %hu carried on PID %hu\n", i_sid,
i_pid);
}
free( p_pmt );
return;
}
......@@ -1713,6 +1802,14 @@ static void HandlePMT( uint16_t i_pid, uint8_t *p_pmt, mtime_t i_dts )
if ( !pmt_validate( p_pmt ) )
{
msg_Warn( NULL, "invalid PMT section received on PID %hu", i_pid );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_pmt_section\" pid=\"%hu\"/>\n",
i_pid);
break;
default:
printf("invalid PMT section received on PID %hu\n", i_pid);
}
free( p_pmt );
goto out_pmt;
}
......@@ -1805,7 +1902,14 @@ static void HandlePMT( uint16_t i_pid, uint8_t *p_pmt, mtime_t i_dts )
UpdatePMT( i_sid );
pmt_print( p_pmt, msg_Dbg, NULL, demux_Iconv, NULL );
pmt_print( p_pmt, msg_Dbg, NULL, demux_Iconv, NULL, PRINT_TEXT );
if ( i_print_type != -1 )
{
pmt_print( p_pmt, demux_Print, NULL, demux_Iconv, NULL,
i_print_type );
if ( i_print_type == PRINT_XML )
printf("\n");
}
}
out_pmt:
......@@ -1831,6 +1935,13 @@ static void HandleNIT( mtime_t i_dts )
if ( !nit_table_validate( pp_next_nit_sections ) )
{
msg_Warn( NULL, "invalid NIT received" );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_nit\"/>\n");
break;
default:
printf("invalid NIT received\n");
}
psi_table_free( pp_next_nit_sections );
psi_table_init( pp_next_nit_sections );
goto out_nit;
......@@ -1846,8 +1957,17 @@ static void HandleNIT( mtime_t i_dts )
psi_table_init( pp_next_nit_sections );
if ( b_display )
{
nit_table_print( pp_current_nit_sections, msg_Dbg, NULL,
demux_Iconv, NULL );
demux_Iconv, NULL, PRINT_TEXT );
if ( i_print_type != -1 )
{
nit_table_print( pp_current_nit_sections, demux_Print, NULL,
demux_Iconv, NULL, i_print_type );
if ( i_print_type == PRINT_XML )
printf("\n");
}
}
out_nit:
;
......@@ -1862,6 +1982,14 @@ static void HandleNITSection( uint16_t i_pid, uint8_t *p_section,
if ( i_pid != NIT_PID || !nit_validate( p_section ) )
{
msg_Warn( NULL, "invalid NIT section received on PID %hu", i_pid );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_nit_section\" pid=\"%hu\"/>\n",
i_pid);
break;
default:
printf("invalid NIT section received on PID %hu\n", i_pid);
}
free( p_section );
return;
}
......@@ -1899,6 +2027,13 @@ static void HandleSDT( mtime_t i_dts )
if ( !sdt_table_validate( pp_next_sdt_sections ) )
{
msg_Warn( NULL, "invalid SDT received" );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_sdt\"/>\n");
break;
default:
printf("invalid SDT received\n");
}
psi_table_free( pp_next_sdt_sections );
psi_table_init( pp_next_sdt_sections );
goto out_sdt;
......@@ -1962,8 +2097,17 @@ static void HandleSDT( mtime_t i_dts )
}
if ( b_change )
{
sdt_table_print( pp_current_sdt_sections, msg_Dbg, NULL,
demux_Iconv, NULL );
demux_Iconv, NULL, PRINT_TEXT );
if ( i_print_type != -1 )
{
sdt_table_print( pp_current_sdt_sections, demux_Print, NULL,
demux_Iconv, NULL, i_print_type );
if ( i_print_type == PRINT_XML )
printf("\n");
}
}
out_sdt:
SendSDT( i_dts );
......@@ -1978,6 +2122,14 @@ static void HandleSDTSection( uint16_t i_pid, uint8_t *p_section,
if ( i_pid != SDT_PID || !sdt_validate( p_section ) )
{
msg_Warn( NULL, "invalid SDT section received on PID %hu", i_pid );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_sdt_section\" pid=\"%hu\"/>\n",
i_pid);
break;
default:
printf("invalid SDT section received on PID %hu\n", i_pid);
}
free( p_section );
return;
}
......@@ -2012,6 +2164,14 @@ static void HandleEIT( uint16_t i_pid, uint8_t *p_eit, mtime_t i_dts )
if ( i_pid != EIT_PID || !eit_validate( p_eit ) )
{
msg_Warn( NULL, "invalid EIT section received on PID %hu", i_pid );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_eit_section\" pid=\"%hu\"/>\n",
i_pid);
break;
default:
printf("invalid EIT section received on PID %hu\n", i_pid);
}
free( p_eit );
return;
}
......@@ -2030,6 +2190,13 @@ static void HandleSection( uint16_t i_pid, uint8_t *p_section, mtime_t i_dts )
if ( !psi_validate( p_section ) )
{
msg_Warn( NULL, "invalid section on PID %hu", i_pid );
switch (i_print_type) {
case PRINT_XML:
printf("<ERROR type=\"invalid_section\" pid=\"%hu\"/>\n", i_pid);
break;
default:
printf("invalid section on PID %hu\n", i_pid);
}
free( p_section );
return;
}
......
......@@ -49,6 +49,8 @@
#include "en50221.h"
#include "comm.h"
#include <bitstream/common.h>
/*****************************************************************************
* Local declarations
*****************************************************************************/
......@@ -361,6 +363,13 @@ static void FrontendPoll( void )
{
int32_t i_value = 0;
msg_Dbg( NULL, "frontend has acquired lock" );
switch (i_print_type) {
case PRINT_XML:
printf("<STATUS type=\"lock\" status=\"1\"/>\n");
break;
default:
printf("frontend has acquired lock" );
}
i_frontend_timeout = 0;
i_last_packet = i_wallclock;
......@@ -378,6 +387,13 @@ static void FrontendPoll( void )
else
{
msg_Dbg( NULL, "frontend has lost lock" );
switch (i_print_type) {
case PRINT_XML:
printf("<STATUS type=\"lock\" status=\"0\"/>\n");
break;
default:
printf("frontend has lost lock" );
}
i_frontend_timeout = i_wallclock + i_frontend_timeout_duration;
}
......
......@@ -86,6 +86,7 @@ char *psz_udp_src = NULL;
int i_asi_adapter = 0;
const char *psz_native_charset = "UTF-8";
const char *psz_dvb_charset = "ISO_8859-1";
print_type_t i_print_type = -1;
volatile sig_atomic_t b_hup_received = 0;
int i_verbose = DEFAULT_VERBOSITY;
......@@ -376,7 +377,8 @@ static void DisplayVersion()
*****************************************************************************/
void usage()
{
msg_Raw( NULL, "Usage: dvblast [-q] [-c <config file>] [-r <remote socket>] [-t <ttl>] [-o <SSRC IP>] [-i <RT priority>] [-a <adapter>] [-n <frontend number>] [-S <diseqc>] [-f <frequency>|-D [<src host>[:<src port>]@]<src mcast>[:<port>][/<opts>]*|-A <ASI adapter>] [-s <symbol rate>] [-v <0|13|18>] [-p] [-b <bandwidth>] [-I <inversion>] [-F <fec inner>] [-m <modulation] [-R <rolloff>] [-P <pilot>] [-K <fec lp>] [-G <guard interval>] [-H <hierarchy>] [-X <transmission>] [-O <lock timeout>] [-u] [-U] [-L <latency>] [-E <retention>] [-d <dest IP>[<:port>][/<opts>]*] [-C [-e] [-M <network name] [-N <network ID>]] [-T] [-j <system charset>] [-J <DVB charset>] [-Q <quit timeout>]" );
DisplayVersion();
msg_Raw( NULL, "Usage: dvblast [-q] [-c <config file>] [-r <remote socket>] [-t <ttl>] [-o <SSRC IP>] [-i <RT priority>] [-a <adapter>] [-n <frontend number>] [-S <diseqc>] [-f <frequency>|-D [<src host>[:<src port>]@]<src mcast>[:<port>][/<opts>]*|-A <ASI adapter>] [-s <symbol rate>] [-v <0|13|18>] [-p] [-b <bandwidth>] [-I <inversion>] [-F <fec inner>] [-m <modulation] [-R <rolloff>] [-P <pilot>] [-K <fec lp>] [-G <guard interval>] [-H <hierarchy>] [-X <transmission>] [-O <lock timeout>] [-u] [-U] [-L <latency>] [-E <retention>] [-d <dest IP>[<:port>][/<opts>]*] [-C [-e] [-M <network name] [-N <network ID>]] [-T] [-j <system charset>] [-J <DVB charset>] [-Q <quit timeout>] [-x <text|xml>" );
msg_Raw( NULL, "Input:" );
msg_Raw( NULL, " -a --adapter read packets from a Linux-DVB adapter (typically 0-n)" );
......@@ -427,6 +429,7 @@ void usage()
msg_Raw( NULL, " -j --system-charset character set used for printing messages (default UTF-8)" );
msg_Raw( NULL, " -J --dvb-charset character set used in output DVB tables (default ISO_8859-1)" );
msg_Raw( NULL, " -l --logger use syslog for logging messages instead of stderr" );
msg_Raw( NULL, " -x --print print interesting events on stdout in a given format" );
msg_Raw( NULL, " -q --quiet be quiet (less verbosity, repeat or use number for even quieter)" );
msg_Raw( NULL, " -Q --quit-timeout when locked, quit after this delay (in ms), or after the first lock timeout" );
msg_Raw( NULL, " -r --remote-socket <remote socket>" );
......@@ -447,8 +450,6 @@ int main( int i_argc, char **pp_argv )
int b_enable_syslog = 0;
DisplayVersion();
if ( i_argc == 1 )
usage();
......@@ -492,6 +493,7 @@ int main( int i_argc, char **pp_argv )
{ "system-charset", required_argument, NULL, 'j' },
{ "dvb-charset", required_argument, NULL, 'J' },
{ "logger", no_argument, NULL, 'l' },
{ "print", required_argument, NULL, 'x' },
{ "quit-timeout", required_argument, NULL, 'Q' },
{ "quiet", no_argument, NULL, 'q' },
{ "help", no_argument, NULL, 'h' },
......@@ -499,7 +501,7 @@ int main( int i_argc, char **pp_argv )
{ 0, 0, 0, 0 }
};
while ( (c = getopt_long(i_argc, pp_argv, "q::c:r:t:o:i:a:n:f:F:R:s:S:v:pb:I:m:P:K:G:H:X:O:uUTL:E:d:D:A:lCeM:N:j:J:Q:hV", long_options, NULL)) != -1 )
while ( (c = getopt_long(i_argc, pp_argv, "q::c:r:t:o:i:a:n:f:F:R:s:S:v:pb:I:m:P:K:G:H:X:O:uUTL:E:d:D:A:lCeM:N:j:J:x:Q:hV", long_options, NULL)) != -1 )
{
switch ( c )
{
......@@ -700,6 +702,10 @@ int main( int i_argc, char **pp_argv )
i_network_id = strtoul( optarg, NULL, 0 );
break;
case 'T':
b_random_tsid = 1;
break;
case 'j':
psz_native_charset = optarg;
break;
......@@ -712,8 +718,13 @@ int main( int i_argc, char **pp_argv )
b_enable_syslog = 1;
break;
case 'T':
b_random_tsid = 1;
case 'x':
if ( !strcmp(optarg, "text") )
i_print_type = PRINT_TEXT;
else if ( !strcmp(optarg, "xml") )
i_print_type = PRINT_XML;
else
msg_Warn( NULL, "unrecognized print type %s", optarg );
break;
case 'Q':
......@@ -735,7 +746,18 @@ int main( int i_argc, char **pp_argv )
if ( b_enable_syslog )
msg_Connect( pp_argv[0] );
if ( i_verbose )
DisplayVersion();
msg_Warn( NULL, "restarting" );
switch (i_print_type) {
case PRINT_XML:
printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
printf("<TS>\n");
break;
default:
break;
}
if ( b_udp_global )
{
......
......@@ -35,7 +35,7 @@
#define PADDING_PID 8191
#define WATCHDOG_WAIT 10000000LL
#define MAX_ERRORS 1000
#define DEFAULT_VERBOSITY 3
#define DEFAULT_VERBOSITY 4
#define MAX_POLL_TIMEOUT 100000 /* 100 ms */
#define DEFAULT_OUTPUT_LATENCY 200000 /* 200 ms */
#define DEFAULT_MAX_RETENTION 40000 /* 40 ms */
......@@ -165,6 +165,7 @@ extern char *psz_udp_src;
extern int i_asi_adapter;
extern const char *psz_native_charset;
extern const char *psz_dvb_charset;
extern enum print_type_t i_print_type;
extern void (*pf_Open)( void );
extern block_t * (*pf_Read)( mtime_t i_poll_timeout );
......
......@@ -114,7 +114,7 @@ signal_catch() {
exec_dvblast() {
tmp_file=`mktemp`
$DVBLAST $diseqc $adapter -O $LOCK_TIMEOUT -Q $QUIT_TIMEOUT $opts 2>| $tmp_file &
$DVBLAST $diseqc $adapter -O $LOCK_TIMEOUT -Q $QUIT_TIMEOUT -q4 -x xml $opts 2>| $tmp_file &
childpid=$!
wait $childpid
if test $? -eq 0; then
......
......@@ -43,9 +43,10 @@
* Local declarations
*****************************************************************************/
#define MAX_MSG 1024
#define VERB_DBG 3
#define VERB_INFO 2
#define VERB_WARN 1
#define VERB_DBG 4
#define VERB_INFO 3
#define VERB_WARN 2
#define VERB_ERR 1
/*****************************************************************************
* msg_Connect
......@@ -89,15 +90,18 @@ void msg_Info( void *_unused, const char *psz_format, ... )
*****************************************************************************/
void msg_Err( void *_unused, const char *psz_format, ... )
{
va_list args;
char psz_fmt[MAX_MSG];
va_start( args, psz_format );
if ( i_verbose >= VERB_ERR )
{
va_list args;
char psz_fmt[MAX_MSG];
va_start( args, psz_format );
snprintf( psz_fmt, MAX_MSG, "error: %s\n", psz_format );
if ( i_syslog )
vsyslog( LOG_ERR, psz_fmt, args );
else
vfprintf( stderr, psz_fmt, args );
snprintf( psz_fmt, MAX_MSG, "error: %s\n", psz_format );
if ( i_syslog )
vsyslog( LOG_ERR, psz_fmt, args );
else
vfprintf( stderr, psz_fmt, args );
}
}
/*****************************************************************************
......
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