aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Paul Saman <jpsaman@videolan.org>2014-01-27 16:14:33 (GMT)
committerJean-Paul Saman <jpsaman@videolan.org>2014-01-27 16:14:33 (GMT)
commitdd34b12fc8494282ca6c91807f8d8304d9f1ebba (patch)
tree8d7b28ecc01bf3c8f39b4bdbe1bc5cd8713b50f0
parentd9bf9c7570ddd48b5334fdc95f14c625178871d7 (diff)
examples/dump_pids.c:
Dump packet nr, PID and CC to stdout.
-rw-r--r--examples/Makefile.am6
-rw-r--r--examples/dump_pids.c57
2 files changed, 62 insertions, 1 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 02621e6..7f6c294 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -3,7 +3,11 @@
SUBDIRS = dvbinfo
DIST_SUBDIRS = $(SUBDIRS)
-noinst_PROGRAMS = decode_pat decode_pmt get_pcr_pid decode_sdt decode_mpeg decode_bat
+noinst_PROGRAMS = decode_pat decode_pmt get_pcr_pid decode_sdt decode_mpeg decode_bat dump_pids
+
+dump_pids_SOURCES = dump_pids.c
+dump_pids_CPPFLAGS =
+dump_pids_LDFLAGS =
decode_pat_SOURCES = decode_pat.c
decode_pat_CPPFLAGS = -DDVBPSI_DIST
diff --git a/examples/dump_pids.c b/examples/dump_pids.c
new file mode 100644
index 0000000..cd40215
--- /dev/null
+++ b/examples/dump_pids.c
@@ -0,0 +1,57 @@
+#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[])
+{
+ int file = open(argv[1], 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;
+ 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++;
+ printf("packet %ld, pid %u, cc %d\n", n, pid, cc );
+ }
+
+ close(file);
+ return 0;
+}

Privacy Policy