|
From: <lin...@us...> - 2003-10-09 19:28:59
|
Update of /cvsroot/dvbtools/dvbstream
In directory sc8-pr-cvs1:/tmp/cvs-serv1247
Modified Files:
ts_filter.c
Log Message:
Add some error detection
Index: ts_filter.c
===================================================================
RCS file: /cvsroot/dvbtools/dvbstream/ts_filter.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ts_filter.c 27 Jun 2002 19:30:29 -0000 1.3
--- ts_filter.c 9 Oct 2003 19:28:55 -0000 1.4
***************
*** 1,4 ****
/* A simple filter (stdin -> stdout) to extract a single stream from a
! multiplexed TS. Specify the PID on the command-line */
#include <stdio.h>
--- 1,7 ----
/* A simple filter (stdin -> stdout) to extract a single stream from a
! multiplexed TS. Specify the PID on the command-line
!
! Updated 29th January 2003 - Added some error checking and reporting.
! */
#include <stdio.h>
***************
*** 9,13 ****
--- 12,20 ----
{
int pid,n;
+ unsigned int i=0;
+ unsigned int j=0;
unsigned char buf[188];
+ unsigned char my_cc;
+ int errors=0;
pid=atoi(argv[1]);
***************
*** 15,26 ****
fprintf(stderr,"filtering PID %d\n",pid);
! for (;;) {
! n=fread(buf,1,188,stdin);
! if (n==188) {
! if (pid==(((buf[1] & 0x1f) << 8) | buf[2])) {
! fwrite(buf,1,188,stdout);
}
}
}
return(0);
}
--- 22,57 ----
fprintf(stderr,"filtering PID %d\n",pid);
! n=fread(buf,1,188,stdin);
! my_cc=buf[3]&0x0f;
! i++;
! while (n==188) {
! if (buf[0]!=0x47) {
! // TO DO: Re-sync.
! fprintf(stderr,"FATAL ERROR IN STREAM AT PACKET %d\n",i);
! exit;
! }
! if (pid==(((buf[1] & 0x1f) << 8) | buf[2])) {
! if (my_cc!=(buf[3]&0x0f)) {
! fprintf(stderr,"Output packet %d: packet incontinuity - expected %02x, found %02x\n",j,my_cc,buf[3]&0x0f);
! my_cc=buf[3]&0x0f;
! errors++;
! }
! n=fwrite(buf,1,188,stdout);
! if (n==188) {
! j++;
! } else {
! fprintf(stderr,"FATAL ERROR - CAN NOT WRITE PACKET %d\n",i);
! exit;
! }
! if (my_cc==0x0f) {
! my_cc=0;
! } else {
! my_cc++;
}
}
+ n=fread(buf,1,188,stdin);
}
+ fprintf(stderr,"Read %d packets, wrote %d.\n",i,j);
+ fprintf(stderr,"%d incontinuity errors.\n",errors);
return(0);
}
|