From 6e40287e2f39a80fc72bd8d0fbc1a8334d688c2d Mon Sep 17 00:00:00 2001 From: etobi Date: Tue, 3 Sep 2013 09:48:38 +0200 Subject: Imported Upstream version 1.1.0 --- test/Makefile | 37 ++++ test/README | 51 +++++ test/dia | 7 + test/diseqc.c | 140 ++++++++++++ test/hex_dump.c | 63 ++++++ test/hex_dump.h | 28 +++ test/sendburst.c | 55 +++++ test/set22k.c | 50 +++++ test/setpid.c | 87 ++++++++ test/setvoltage.c | 47 ++++ test/test.c | 281 ++++++++++++++++++++++++ test/test_audio.c | 345 +++++++++++++++++++++++++++++ test/test_av.c | 574 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_av_play.c | 310 ++++++++++++++++++++++++++ test/test_dvr.c | 164 ++++++++++++++ test/test_dvr_play.c | 144 +++++++++++++ test/test_front.c | 328 ++++++++++++++++++++++++++++ test/test_pes.c | 137 ++++++++++++ test/test_sec_ne.c | 165 ++++++++++++++ test/test_sections.c | 197 +++++++++++++++++ test/test_stc.c | 74 +++++++ test/test_stillimage.c | 103 +++++++++ test/test_switch.c | 355 ++++++++++++++++++++++++++++++ test/test_tt.c | 205 ++++++++++++++++++ test/test_vevent.c | 125 +++++++++++ test/test_video.c | 368 +++++++++++++++++++++++++++++++ test/video.c | 182 ++++++++++++++++ 27 files changed, 4622 insertions(+) create mode 100644 test/Makefile create mode 100644 test/README create mode 100755 test/dia create mode 100644 test/diseqc.c create mode 100644 test/hex_dump.c create mode 100644 test/hex_dump.h create mode 100644 test/sendburst.c create mode 100644 test/set22k.c create mode 100644 test/setpid.c create mode 100644 test/setvoltage.c create mode 100644 test/test.c create mode 100644 test/test_audio.c create mode 100644 test/test_av.c create mode 100644 test/test_av_play.c create mode 100644 test/test_dvr.c create mode 100644 test/test_dvr_play.c create mode 100644 test/test_front.c create mode 100644 test/test_pes.c create mode 100644 test/test_sec_ne.c create mode 100644 test/test_sections.c create mode 100644 test/test_stc.c create mode 100644 test/test_stillimage.c create mode 100644 test/test_switch.c create mode 100644 test/test_tt.c create mode 100644 test/test_vevent.c create mode 100644 test/test_video.c create mode 100644 test/video.c (limited to 'test') diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..ddff9ab --- /dev/null +++ b/test/Makefile @@ -0,0 +1,37 @@ +# Makefile for Linux DVB API Version 3 test programs + +CC = gcc +CFLAGS = -g -O2 -W -Wall -I../include + +TARGETS = \ + diseqc \ + set22k \ + sendburst \ + setvoltage \ + setpid \ + video \ + test_sections \ + test_sec_ne \ + test_pes \ + test_dvr \ + test_dvr_play \ + test_tt \ + test_av \ + test_av_play \ + test_vevent \ + test_stc \ + test_stillimage + +# test \ +# test_audio \ +# test_front \ +# test_switch \ +# test_video \ + +all: $(TARGETS) + +test_sections test_sec_ne test_pes test_tt: hex_dump.o + +clean: + rm -f $(TARGETS) *.o + diff --git a/test/README b/test/README new file mode 100644 index 0000000..b3f0cac --- /dev/null +++ b/test/README @@ -0,0 +1,51 @@ +Various small test/sample programs for the Linux DVB API Version 2 + +The default devices used by the test programs are generally +/dev/dvb/adapter0/*0, and can be overridden using environment +variables: + + FRONTEND=/dev/dvb/adapter0/frontend0 + DEMUX=/dev/dvb/adapter0/demux0 + DVR=/dev/dvb/adapter0/dvr0 + AUDIO=/dev/dvb/adapter0/audio0 + VIDEO=/dev/dvb/adapter0/video0 + NET=/dev/dvb/adapter0/net0 + + +diseqc : Send various diseqc sequences on a SAT frontend. + Best used with a diseqc test box with some LEDs to + show the result of the commands. +set22k : Legacy tone switching for SAT frontends. +setvoltage : Legacy voltage switching for SAT frontends. + +setpid : Set video and audio PIDs in the demux; useful only + if you have a hardware MPEG decoder. +video : A tiny video watching application, just starts capturing /dev/video + into /dev/fb0. + WARNING: May crash your box or mess up your console! + +test_sections : Hex dump of section data from stream. +test_sec_ne : Like test_sections, but also test Not-Equal filter mode. +test_pes : Hex dump of PES data from stream. +test_tt : Demonstrate teletext decoding from PES data. +test_av : Test audio and video MPEG decoder API. +test_vevent : Test VIDEO_GET_EVENT and poll() for video events +test_stc : Test DMX_GET_STC. + +test_stillimage : Display single iframes as stillimages + iframes can be created with the 'convert' tool from + imagemagick and mpeg2encode from ftp.mpeg.org, and must + have a supported size, e.g. 702x576 + ($ convert -sample 702x576\! test.jpg test.mpg) + +(test_av_play : Test playing MPEG TS from a file (apparently broken)) + + +test : +test_audio : +test_dmx : +test_dvr : +test_front : +test_switch : +test_video : + diff --git a/test/dia b/test/dia new file mode 100755 index 0000000..5cb2600 --- /dev/null +++ b/test/dia @@ -0,0 +1,7 @@ +#!/bin/sh + +for f in $@ +do /usr/X11R6/bin/convert -geomtry 702x576 $f test.mpg +test_video test.mpg +rm test.mpg +done \ No newline at end of file diff --git a/test/diseqc.c b/test/diseqc.c new file mode 100644 index 0000000..8f2e411 --- /dev/null +++ b/test/diseqc.c @@ -0,0 +1,140 @@ +/* + * Test sending DiSEqC commands on a SAT frontend. + * + * usage: FRONTEND=/dev/dvb/adapterX/frontendX diseqc [test_seq_no] + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +struct diseqc_cmd { + struct dvb_diseqc_master_cmd cmd; + uint32_t wait; +}; + + +struct diseqc_cmd switch_cmds[] = { + { { { 0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf2, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf1, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf3, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf4, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf6, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf5, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf7, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf8, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xfa, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xf9, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xfb, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xfc, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xfe, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xfd, 0x00, 0x00 }, 4 }, 0 }, + { { { 0xe0, 0x10, 0x38, 0xff, 0x00, 0x00 }, 4 }, 0 } +}; + + +/*--------------------------------------------------------------------------*/ + +static inline +void msleep(uint32_t msec) +{ + struct timespec req = { msec / 1000, 1000000 * (msec % 1000) }; + + while (nanosleep(&req, &req)) + ; +} + + +static +void diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd **cmd, + fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b) +{ + ioctl(fd, FE_SET_TONE, SEC_TONE_OFF); + ioctl(fd, FE_SET_VOLTAGE, v); + + msleep(15); + while (*cmd) { + printf("msg: %02x %02x %02x %02x %02x %02x\n", + (*cmd)->cmd.msg[0], (*cmd)->cmd.msg[1], + (*cmd)->cmd.msg[2], (*cmd)->cmd.msg[3], + (*cmd)->cmd.msg[4], (*cmd)->cmd.msg[5]); + + ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &(*cmd)->cmd); + msleep((*cmd)->wait); + cmd++; + } + + printf("%s: ", __FUNCTION__); + + printf(" %s ", v == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" : + v == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "???"); + + printf(" %s ", b == SEC_MINI_A ? "SEC_MINI_A" : + b == SEC_MINI_B ? "SEC_MINI_B" : "???"); + + printf(" %s\n", t == SEC_TONE_ON ? "SEC_TONE_ON" : + t == SEC_TONE_OFF ? "SEC_TONE_OFF" : "???"); + + msleep(15); + ioctl(fd, FE_DISEQC_SEND_BURST, b); + + msleep(15); + ioctl(fd, FE_SET_TONE, t); +} + + +int main(int argc, char **argv) +{ + struct diseqc_cmd *cmd[2] = { NULL, NULL }; + char *fedev = "/dev/dvb/adapter0/frontend0"; + int fd; + + if (getenv("FRONTEND")) + fedev = getenv("FRONTEND"); + + printf("diseqc test: using '%s'\n", fedev); + + if ((fd = open(fedev, O_RDWR)) < 0) { + perror("open"); + return -1; + } + + if (argc > 1) { + int i = atol(argv[1]); + cmd[0] = &switch_cmds[i]; + diseqc_send_msg(fd, + i % 2 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13, + cmd, + (i/2) % 2 ? SEC_TONE_ON : SEC_TONE_OFF, + (i/4) % 2 ? SEC_MINI_B : SEC_MINI_A); + } else { + unsigned int j; + + for (j=0; j + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "hex_dump.h" + + +void hex_dump(uint8_t data[], int bytes) +{ + int i, j; + uint8_t c; + + for (i = 0; i < bytes; i++) { + if (!(i % 8) && i) + printf(" "); + if (!(i % 16) && i) { + printf(" "); + for (j = 0; j < 16; j++) { + c = data[i+j-16]; + if ((c < 0x20) || (c >= 0x7f)) + c = '.'; + printf("%c", c); + } + printf("\n"); + } + printf("%.2x ", data[i]); + } + j = (bytes % 16); + j = (j != 0 ? j : 16); + for (i = j; i < 16; i++) { + if (!(i % 8) && i) + printf(" "); + printf(" "); + } + printf(" "); + for (i = bytes - j; i < bytes; i++) { + c = data[i]; + if ((c < 0x20) || (c >= 0x7f)) + c = '.'; + printf("%c", c); + } + printf("\n"); +} + diff --git a/test/hex_dump.h b/test/hex_dump.h new file mode 100644 index 0000000..030cc37 --- /dev/null +++ b/test/hex_dump.h @@ -0,0 +1,28 @@ +#ifndef _HEXDUMP_H_ +#define _HEXDUMP_H_ +/* hex_dump.h -- simple hex dump routine + * + * Copyright (C) 2002 convergence GmbH + * Johannes Stezenbach + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +extern void hex_dump(uint8_t data[], int bytes); + + +#endif /* _HEXDUMP_H_ */ diff --git a/test/sendburst.c b/test/sendburst.c new file mode 100644 index 0000000..a96b68c --- /dev/null +++ b/test/sendburst.c @@ -0,0 +1,55 @@ +/* + * Test sending the burst mini command A/B on a SAT frontend. + * + * usage: FRONTEND=/dev/dvb/adapterX/frontendX sendburst {a|b} + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +int main (int argc, char **argv) +{ + char *fedev = "/dev/dvb/adapter0/frontend0"; + int fd, r; + + if (argc != 2 || (strcmp(argv[1], "a") && strcmp(argv[1], "b"))) { + fprintf (stderr, "usage: %s \n", argv[0]); + return 1; + } + + if (getenv("FRONTEND")) + fedev = getenv("FRONTEND"); + + printf("set22k: using '%s'\n", fedev); + + if ((fd = open (fedev, O_RDWR)) < 0) { + perror ("open"); + return 1; + } + + ioctl (fd, FE_SET_TONE, SEC_TONE_OFF); + + usleep (30000); /* 30ms according to DiSEqC spec */ + + if (strcmp(argv[1], "a") == 0) + r = ioctl (fd, FE_DISEQC_SEND_BURST, SEC_MINI_A); + else + r = ioctl (fd, FE_DISEQC_SEND_BURST, SEC_MINI_B); + + if (r == -1) + perror("ioctl FE_SET_TONE"); + + close (fd); + + return 0; +} + diff --git a/test/set22k.c b/test/set22k.c new file mode 100644 index 0000000..51ffa1c --- /dev/null +++ b/test/set22k.c @@ -0,0 +1,50 @@ +/* + * Test switching the 22kHz tone signal on and off on a SAT frontend. + * (Note: DiSEqC equipment ignores this after it has once seen a diseqc + * sequence; reload the driver or unplug/replug the SAT cable to reset.) + * + * usage: FRONTEND=/dev/dvb/adapterX/frontendX set22k {on|off} + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +int main (int argc, char **argv) +{ + char *fedev = "/dev/dvb/adapter0/frontend0"; + int fd, r; + + if (argc != 2 || (strcmp(argv[1], "on") && strcmp(argv[1], "off"))) { + fprintf (stderr, "usage: %s \n", argv[0]); + return 1; + } + if (getenv("FRONTEND")) + fedev = getenv("FRONTEND"); + printf("set22k: using '%s'\n", fedev); + + if ((fd = open (fedev, O_RDWR)) < 0) { + perror ("open"); + return 1; + } + + if (strcmp(argv[1], "on") == 0) + r = ioctl (fd, FE_SET_TONE, SEC_TONE_ON); + else + r = ioctl (fd, FE_SET_TONE, SEC_TONE_OFF); + if (r == -1) + perror("ioctl FE_SET_TONE"); + + close (fd); + + return 0; +} + diff --git a/test/setpid.c b/test/setpid.c new file mode 100644 index 0000000..fa0333c --- /dev/null +++ b/test/setpid.c @@ -0,0 +1,87 @@ +/* + * Set video and audio PIDs in the demux; useful only if you have + * a hardware MPEG decoder and you're tuned to a transport stream. + * + * usage: DEMUX=/dev/dvb/adapterX/demuxX setpid video_pid audio_pid + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +static +int setup_demux (char *dmxdev, int video_pid, int audio_pid) +{ + int vfd, afd; + struct dmx_pes_filter_params pesfilter; + + printf ("video_pid == 0x%04x\n", video_pid); + printf ("audio_pid == 0x%04x\n", audio_pid); + + if ((vfd = open (dmxdev, O_RDWR)) < 0) { + perror("open 1"); + return -1; + } + + pesfilter.pid = video_pid; + pesfilter.input = DMX_IN_FRONTEND; + pesfilter.output = DMX_OUT_DECODER; + pesfilter.pes_type = DMX_PES_VIDEO; + pesfilter.flags = DMX_IMMEDIATE_START; + + if (ioctl (vfd, DMX_SET_PES_FILTER, &pesfilter) < 0) { + perror("ioctl DMX_SET_PES_FILTER (video)"); + return -1; + } + + close (vfd); + + if ((afd = open (dmxdev, O_RDWR)) < 0) { + perror("open 1"); + return -1; + } + + pesfilter.pid = audio_pid; + pesfilter.input = DMX_IN_FRONTEND; + pesfilter.output = DMX_OUT_DECODER; + pesfilter.pes_type = DMX_PES_AUDIO; + pesfilter.flags = DMX_IMMEDIATE_START; + + if (ioctl (afd, DMX_SET_PES_FILTER, &pesfilter) < 0) { + perror("ioctl DMX_SET_PES_FILTER (audio)"); + return -1; + } + + close (afd); + return 0; +} + + +int main (int argc, char **argv) +{ + char *dmxdev = "/dev/dvb/adapter0/demux0"; + int video_pid, audio_pid; + + if (argc != 3) { + printf ("\nusage: %s