<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
I have re-done the mrtg input count patch slightly. This is now
against HEAD. Sorry, I was wrong about a recent change using 'Z' so
that is the option I have kept. Any comments would be welcome.<br>
<br>
Regards<br>
<br>
Pete<br>
<br>
diff -Naur dvblast-7-21-11-with-ac3-atsc/dvblast.c
dvblast-7-21-11-with-ac3-atsc-inputcount/dvblast.c<br>
--- dvblast-7-21-11-with-ac3-atsc/dvblast.c 2011-07-21
12:14:54.000000000 +0100<br>
+++ dvblast-7-21-11-with-ac3-atsc-inputcount/dvblast.c 2011-08-02
14:37:30.000000000 +0100<br>
@@ -49,6 +49,8 @@<br>
#include <bitstream/dvb/si.h><br>
#include <bitstream/ietf/rtp.h><br>
<br>
+#include "mrtg-cnt.h"<br>
+<br>
/*****************************************************************************<br>
* Local declarations<br>
*****************************************************************************/<br>
@@ -107,6 +109,9 @@<br>
static mtime_t i_retention_global = DEFAULT_MAX_RETENTION;<br>
static int i_ttl_global = 64;<br>
<br>
+/* TPS Input log filename */<br>
+char * psz_mrtg_file = NULL;<br>
+<br>
void (*pf_Open)( void ) = NULL;<br>
block_t * (*pf_Read)( mtime_t i_poll_timeout ) = NULL;<br>
void (*pf_Reset)( void ) = NULL;<br>
@@ -461,6 +466,8 @@<br>
msg_Raw( NULL, " -Q --quit-timeout when locked, quit after
this delay (in ms), or after the first lock timeout" );<br>
msg_Raw( NULL, " -r --remote-socket <remote socket>" );<br>
msg_Raw( NULL, " -V --version only display the
version" );<br>
+ msg_Raw( NULL, " -Z --mrtg-file <file> Log input
packets and errors into mrtg-file" );<br>
+ msg_Raw( NULL, " -k ppid,apid,vpid,spid Map the PMT, Audio,
Video and subtitles pids the values provided" );<br>
exit(1);<br>
}<br>
<br>
@@ -531,10 +538,11 @@<br>
{ "quiet", no_argument, NULL, 'q' },<br>
{ "help", no_argument, NULL, 'h' },<br>
{ "version", no_argument, NULL, 'V' },<br>
+ { "mrtg-file", required_argument, NULL, 'Z' },<br>
{ 0, 0, 0, 0 }<br>
};<br>
<br>
- 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:uwUTL:E:d:D:A:lzCWYeM:N:j:J:x:Q:hV",
long_options, NULL)) != -1 )<br>
+ 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:uwUTL:E:d:D:A:lzCWYeM:N:j:J:x:Q:hVZ",
long_options, NULL)) != -1 )<br>
{<br>
switch ( c )<br>
{<br>
@@ -789,6 +797,10 @@<br>
exit(0);<br>
break;<br>
<br>
+ case 'Z':<br>
+ psz_mrtg_file = optarg;<br>
+ break;<br>
+<br>
case 'h':<br>
default:<br>
usage();<br>
@@ -804,13 +816,14 @@<br>
DisplayVersion();<br>
<br>
msg_Warn( NULL, "restarting" );<br>
- switch (i_print_type) {<br>
- case PRINT_XML:<br>
- printf("<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n");<br>
- printf("<TS>\n");<br>
- break;<br>
- default:<br>
- break;<br>
+ switch (i_print_type) <br>
+ {<br>
+ case PRINT_XML:<br>
+ printf("<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n");<br>
+ printf("<TS>\n");<br>
+ break;<br>
+ default:<br>
+ break;<br>
}<br>
<br>
if ( b_udp_global )<br>
@@ -893,6 +906,9 @@<br>
srand( time(NULL) * getpid() );<br>
<br>
demux_Open();<br>
+ <br>
+ // init the mrtg logfile<br>
+ mrtgInit(psz_mrtg_file);<br>
<br>
if ( i_priority > 0 )<br>
{<br>
@@ -924,7 +940,8 @@<br>
<br>
if ( i_quit_timeout && i_quit_timeout <=
i_wallclock )<br>
{<br>
- switch (i_print_type) {<br>
+ switch (i_print_type) <br>
+ {<br>
case PRINT_XML:<br>
printf("</TS>\n");<br>
break;<br>
@@ -935,13 +952,17 @@<br>
}<br>
<br>
p_ts = pf_Read( i_poll_timeout );<br>
- if ( p_ts != NULL )<br>
+ if ( p_ts != NULL ) <br>
+ {<br>
+ mrtgAnalyse(p_ts);<br>
demux_Run( p_ts );<br>
+ }<br>
i_poll_timeout = output_Send();<br>
if ( i_poll_timeout == -1 || i_poll_timeout >
MAX_POLL_TIMEOUT )<br>
i_poll_timeout = MAX_POLL_TIMEOUT;<br>
}<br>
<br>
+ mrtgClose();<br>
if ( b_enable_syslog )<br>
msg_Disconnect();<br>
return EXIT_SUCCESS;<br>
diff -Naur dvblast-7-21-11-with-ac3-atsc/Makefile
dvblast-7-21-11-with-ac3-atsc-inputcount/Makefile<br>
--- dvblast-7-21-11-with-ac3-atsc/Makefile 2011-07-21
12:14:54.000000000 +0100<br>
+++ dvblast-7-21-11-with-ac3-atsc-inputcount/Makefile 2011-07-21
13:32:23.000000000 +0100<br>
@@ -10,7 +10,7 @@<br>
LDLIBS += -lrt<br>
LDLIBS_DVBLAST += -lpthread<br>
<br>
-OBJ_DVBLAST = dvblast.o util.o dvb.o udp.o asi.o demux.o output.o
en50221.o comm.o<br>
+OBJ_DVBLAST = dvblast.o util.o dvb.o udp.o asi.o demux.o output.o
en50221.o comm.o mrtg-cnt.o<br>
OBJ_DVBLASTCTL = util.o dvblastctl.o<br>
<br>
PREFIX ?= /usr/local<br>
diff -Naur dvblast-7-21-11-with-ac3-atsc/mrtg-cnt.c
dvblast-7-21-11-with-ac3-atsc-inputcount/mrtg-cnt.c<br>
--- dvblast-7-21-11-with-ac3-atsc/mrtg-cnt.c 1970-01-01
01:00:00.000000000 +0100<br>
+++ dvblast-7-21-11-with-ac3-atsc-inputcount/mrtg-cnt.c
2011-07-21 13:32:23.000000000 +0100<br>
@@ -0,0 +1,176 @@<br>
+// vim: set shiftwidth=4 tabstop=4 expandtab autoindent :<br>
+//////////////////////////////////////////////////////////////////<br>
+// Handle dvb TS packets and count them for MRTG<br>
+///////////////////////////////////////////////////<br>
+// Copyright Tripleplay service 2004,2005<br>
+///////////////////////////////////////////////////<br>
+<br>
+#include <stdint.h><br>
+#include <stdlib.h><br>
+#include <string.h><br>
+#include <stdio.h><br>
+#include <stdbool.h><br>
+#include <sys/types.h><br>
+<br>
+#include <unistd.h><br>
+#include <fcntl.h><br>
+#include <sys/time.h><br>
+<br>
+#include "dvblast.h"<br>
+<br>
+// File handle<br>
+static FILE *mrtg_fh = NULL;<br>
+<br>
+// Counts<br>
+static long long l_mrtg_packets = 0; // Packets received<br>
+static long long l_mrtg_seq_err_packets = 0; // Out of sequence
packets received<br>
+static long long l_mrtg_error_packets = 0; // Packets received
with the error flag set<br>
+static long long l_mrtg_scram_packets = 0; // Scrambled
Packets received<br>
+<br>
+// Reporting timer<br>
+#if defined( WIN32 )<br>
+static LARGE_INTEGER mrtg_time;<br>
+static LARGE_INTEGER mrtg_inc;<br>
+#else<br>
+static struct timeval mrtg_time = { 0, 0 };<br>
+#endif<br>
+<br>
+// Define the dump period in seconds<br>
+#define MRTG_INTERVAL 10<br>
+<br>
+// Pid sequence numbers<br>
+#define PIDS 0x2000<br>
+static signed char i_pid_seq[PIDS];<br>
+<br>
+// Report the mrtg counters: bytes received, error packets &
sequence errors<br>
+static void dumpCounts()<br>
+{<br>
+ unsigned int multiplier = 1; //MRTG_INTERVAL;<br>
+ if(mrtg_fh) {<br>
+ rewind(mrtg_fh);<br>
+ fprintf(mrtg_fh, "%lld %lld %lld %lld\n",<br>
+ l_mrtg_packets * 188 * multiplier,<br>
+ l_mrtg_error_packets * multiplier,<br>
+ l_mrtg_seq_err_packets * multiplier,<br>
+ l_mrtg_scram_packets * multiplier);<br>
+ fflush(mrtg_fh);<br>
+ }<br>
+}<br>
+<br>
+// analyse the input block counting packets and errors<br>
+// The input is a pointer to a block_t structure, which might be a
linked list<br>
+// of blocks. Each block has one TS packet.<br>
+int mrtgAnalyse(block_t * p_ts)<br>
+{<br>
+ unsigned int i_pid;<br>
+ block_t *p_block = p_ts;<br>
+ <br>
+ while (p_block != NULL) {<br>
+ uint8_t *ts_packet = p_block->p_ts;<br>
+<br>
+ char i_seq, i_last_seq;<br>
+ l_mrtg_packets++;<br>
+<br>
+ if (ts_packet[0] != 0x47) {<br>
+ l_mrtg_error_packets++;<br>
+ p_block = p_block->p_next;<br>
+ continue;<br>
+ }<br>
+<br>
+ if (ts_packet[1] & 0x80) {<br>
+ l_mrtg_error_packets++;<br>
+ p_block = p_block->p_next;<br>
+ continue;<br>
+ }<br>
+<br>
+ i_pid = (ts_packet[1] & 0x1f) << 8 |
ts_packet[2];<br>
+<br>
+ // Just count null packets - don't check the sequence
numbering<br>
+ if (i_pid == 0x1fff) {<br>
+ p_block = p_block->p_next;<br>
+ continue;<br>
+ }<br>
+<br>
+ if (ts_packet[3] & 0xc0) {<br>
+ l_mrtg_scram_packets++;<br>
+ }<br>
+ // Check the sequence numbering<br>
+ i_seq = ts_packet[3] & 0xf;<br>
+ i_last_seq = i_pid_seq[i_pid];<br>
+<br>
+ if (i_last_seq == -1) {<br>
+ // First packet - ignore the sequence<br>
+ } else if (ts_packet[3] & 0x10) {<br>
+ // Packet contains payload - sequence should be up by
one<br>
+ if (i_seq != ((i_last_seq + 1) & 0x0f)) {<br>
+ l_mrtg_seq_err_packets++;<br>
+ }<br>
+ } else {<br>
+ // Packet contains no payload - sequence should be
unchanged<br>
+ if (i_seq != i_last_seq) {<br>
+ l_mrtg_seq_err_packets++;<br>
+ }<br>
+ }<br>
+ i_pid_seq[i_pid] = i_seq;<br>
+<br>
+ // Look at next block<br>
+ p_block = p_block->p_next;<br>
+ }<br>
+<br>
+ // All blocks processed. See if we need to dump the stats<br>
+ struct timeval now;<br>
+ gettimeofday(&now, NULL);<br>
+ if (timercmp(&now, &mrtg_time, >)) {<br>
+ // Time to report the mrtg counters<br>
+ dumpCounts();<br>
+<br>
+ // Set the timer for next time<br>
+ //<br>
+ // Normally we add the interval to the previous time so
that if one<br>
+ // dump is a bit late, the next one still occurs at the
correct time.<br>
+ // However, if there is a long gap (e.g. because the
channel has<br>
+ // stopped for some time), then just rebase the timing to
the current<br>
+ // time. I've chosen MRTG_INTERVAL as the long gap - this
is arbitary<br>
+ if ((now.tv_sec - mrtg_time.tv_sec) > MRTG_INTERVAL) {<br>
+ msg_Dbg(NULL, "Dump is %d seconds late - reset
timing\n",<br>
+ (int) (now.tv_sec - mrtg_time.tv_sec));<br>
+ mrtg_time = now;<br>
+ }<br>
+ mrtg_time.tv_sec += MRTG_INTERVAL;<br>
+ }<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+int mrtgInit(char *mrtg_file)<br>
+{<br>
+<br>
+ /* Open MRTG file */<br>
+ msg_Dbg(NULL, "Opening mrtg file %s.\n", mrtg_file);<br>
+ if ((mrtg_fh = fopen(mrtg_file, "wb")) == NULL) {<br>
+ msg_Err(NULL, "unable to open mrtg file");<br>
+ return -1;<br>
+ }<br>
+ // Initialise the file<br>
+ fprintf(mrtg_fh, "0 0 0 0\n");<br>
+ fflush(mrtg_fh);<br>
+<br>
+ // Initialise the sequence numbering<br>
+ memset(&i_pid_seq[0], -1, sizeof(signed char) * PIDS);<br>
+<br>
+ // Set the reporting timer<br>
+ gettimeofday(&mrtg_time, NULL);<br>
+ mrtg_time.tv_sec += MRTG_INTERVAL;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+void mrtgClose()<br>
+{<br>
+ // This is only for testing when using filetest.<br>
+ if (mrtg_fh) {<br>
+ dumpCounts();<br>
+ fclose(mrtg_fh);<br>
+ mrtg_fh = NULL;<br>
+ }<br>
+}<br>
diff -Naur dvblast-7-21-11-with-ac3-atsc/mrtg-cnt.h
dvblast-7-21-11-with-ac3-atsc-inputcount/mrtg-cnt.h<br>
--- dvblast-7-21-11-with-ac3-atsc/mrtg-cnt.h 1970-01-01
01:00:00.000000000 +0100<br>
+++ dvblast-7-21-11-with-ac3-atsc-inputcount/mrtg-cnt.h
2011-07-21 13:32:23.000000000 +0100<br>
@@ -0,0 +1,13 @@<br>
+// vim: set shiftwidth=4 tabstop=4 expandtab autoindent :<br>
+///////////////////////////////////////////////////<br>
+// Copyright Tripleplay service 2004,2005<br>
+///////////////////////////////////////////////////<br>
+<br>
+#ifndef MRTG_CNT_H<br>
+#define MRTG_CNT_H<br>
+<br>
+int mrtgInit(char *mrtg_file);<br>
+void mrtgClose();<br>
+int mrtgAnalyse(block_t * p_ts);<br>
+<br>
+#endif<br>
<br>
<br>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Tripleplay Signature - Poole</title>
<font style="candara"> <br>
<font size="2">Best Regards,</font><br>
<br>
<b>Dr. Peter Martin</b><br>
<font color="#404041" size="2">Chief Technical Officer</font><br>
<br>
Tripleplay Services Ltd<br>
<br>
Tel: +44 (0) 845 643 2057</font><br>
Support: +44 (0) 845 094 3357<br>
Mobile: +44 (0) 7810 876713<br>
Mail: <a href="mailto:peter.martin@tripleplay-services.com">peter.martin@tripleplay-services.com</a><br>
WWW: <a href="http://www.tripleplay-services.com">http://www.tripleplay-services.com</a><br>
<br>
<b><font color="#404041" size="2">Tripleplay Services Ltd.</font></b><br>
<font color="#404041" size="2">Unit 3, Concept Park, Yarrow Road,
POOLE, DORSET, BH12 4QT</font><br>
<br>
<i><font color="#404041" size="2">This message is for the
designated recipient only and may contain privileged,
proprietary, or otherwise private information. If you have
received it in error, please notify the sender immediately and
delete the original. Any review, retransmission, dissemination
or other use of, or taking of any action in reliance upon,
this information by persons or entities other than the
intended recipient is prohibited </font></i><br>
<br>
<i><font color="#404041" size="2">Tripleplay Services Limited is a
private limited liability company in England and Wales, whose
registered office is Cromwell House, 14 Fulwood Place, London,
WC1V 6HZ. Registered in England, number 4338092.</font></i></div>
</body>
</html>