[libdvbpsi-devel] check_cc_pid: Check continuity counter for only 1 PID.
Jean-Paul Saman
git at videolan.org
Wed Apr 16 15:53:31 CEST 2014
libdvbpsi | branch: master | Jean-Paul Saman <jpsaman at videolan.org> | Fri Apr 11 13:50:18 2014 +0200| [6befa2b64c252190a9d1de2dc30d727305af38d8] | committer: Jean-Paul Saman
check_cc_pid: Check continuity counter for only 1 PID.
> http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=6befa2b64c252190a9d1de2dc30d727305af38d8
---
.gitignore | 1 +
examples/Makefile.am | 6 +++-
examples/check_cc_pid.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 9032899..72aab25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,7 @@ stamp-*
*-stamp
doc/doxygen
doc/decoder.png
+examples/check_cc_pid
examples/decode_mpeg
examples/decode_pat
examples/decode_pmt
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 7f6c294..87e5918 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -3,12 +3,16 @@
SUBDIRS = dvbinfo
DIST_SUBDIRS = $(SUBDIRS)
-noinst_PROGRAMS = decode_pat decode_pmt get_pcr_pid decode_sdt decode_mpeg decode_bat dump_pids
+noinst_PROGRAMS = decode_pat decode_pmt get_pcr_pid decode_sdt decode_mpeg decode_bat dump_pids check_cc_pid
dump_pids_SOURCES = dump_pids.c
dump_pids_CPPFLAGS =
dump_pids_LDFLAGS =
+check_cc_pid_SOURCES = check_cc_pid.c
+check_cc_pid_CPPFLAGS =
+check_cc_pid_LDFLAGS =
+
decode_pat_SOURCES = decode_pat.c
decode_pat_CPPFLAGS = -DDVBPSI_DIST
decode_pat_LDFLAGS = -L../src -ldvbpsi
diff --git a/examples/check_cc_pid.c b/examples/check_cc_pid.c
new file mode 100644
index 0000000..26c5212
--- /dev/null
+++ b/examples/check_cc_pid.c
@@ -0,0 +1,71 @@
+#include "config.h"
+
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+# include <stdint.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <assert.h>
+
+static inline uint32_t ts_getcc(uint8_t *packet)
+{
+ return (packet[3] & 0x0f);
+}
+
+static inline uint32_t ts_getpid(uint8_t *packet)
+{
+ assert(packet[0] == 0x47);
+ return ((uint16_t)(packet[1] & 0x1f) << 8) + packet[2];
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc != 3) {
+ printf("Usage: check_cc_pid <filename> <pid>\n");
+ return -1;
+ }
+
+ /* Get arguments */
+ char *fname = argv[1];
+ uint32_t tpid = atoi(argv[2]); /* PID to track */
+
+ int file = open(fname, O_RDONLY | O_NONBLOCK);
+ if (file < 0) {
+ perror(argv[1]);
+ printf("error opening %s\n", argv[1]);
+ return -1;
+ }
+
+ int32_t s = 188; /* COULD ALSO BE 192 */
+ uint8_t p[188] = { 0 };
+ int64_t n = 0;
+ size_t len = 0;
+ uint32_t tcc = 0;
+ for (;;) {
+
+ /* slow read */
+ len = read(file, &p[0], s);
+ if (len == 0)
+ break;
+ uint32_t pid = ts_getpid(&p[0]);
+ uint32_t cc = ts_getcc(&p[0]);
+ n++;
+ tcc = cc;
+ if (pid == tpid)
+ printf("packet %ld, pid %u (0x%x), cc %d %s\n",
+ n, pid, pid, cc,
+ ((cc % 16) == (tcc + 1)%16) ? "discontinuity" : "");
+ }
+
+ close(file);
+ return 0;
+}
More information about the libdvbpsi-devel
mailing list