diff options
author | etobi <git@e-tobi.net> | 2013-09-03 09:48:45 +0200 |
---|---|---|
committer | etobi <git@e-tobi.net> | 2013-09-03 09:48:45 +0200 |
commit | 9fe4d4ea9c054e539ab679ed2e9c076c35beb69d (patch) | |
tree | affff927f15c8ae6c77890cc9564855efe2e51db /util/szap/czap.c | |
parent | 9a5228e0f2b898367b7943d294be58caf6ce8bb3 (diff) | |
download | linux-dvb-apps-upstream/1.1.1+rev1355.tar.gz |
Imported Upstream version 1.1.1+rev1355upstream/1.1.1+rev1355
Diffstat (limited to 'util/szap/czap.c')
-rw-r--r-- | util/szap/czap.c | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/util/szap/czap.c b/util/szap/czap.c index 469df56..e04ed4b 100644 --- a/util/szap/czap.c +++ b/util/szap/czap.c @@ -13,6 +13,8 @@ #include <linux/dvb/frontend.h> #include <linux/dvb/dmx.h> +#include "util.h" + static char FRONTEND_DEV [80]; static char DEMUX_DEV [80]; @@ -118,7 +120,7 @@ char *find_channel(FILE *f, int list_channels, int *chan_no, const char *channel int parse(const char *fname, int list_channels, int chan_no, const char *channel, - struct dvb_frontend_parameters *frontend, int *vpid, int *apid) + struct dvb_frontend_parameters *frontend, int *vpid, int *apid, int *sid) { FILE *f; char *chan; @@ -141,10 +143,10 @@ int parse(const char *fname, int list_channels, int chan_no, const char *channel } printf("%3d %s", chan_no, chan); - if ((sscanf(chan, "%a[^:]:%d:%a[^:]:%d:%a[^:]:%a[^:]:%d:%d\n", + if ((sscanf(chan, "%m[^:]:%d:%m[^:]:%d:%m[^:]:%m[^:]:%d:%d:%d\n", &name, &frontend->frequency, &inv, &frontend->u.qam.symbol_rate, - &fec, &mod, vpid, apid) != 8) + &fec, &mod, vpid, apid, sid) != 9) || !name || !inv || !fec | !mod) { ERROR("cannot parse service data"); return -3; @@ -165,10 +167,10 @@ int parse(const char *fname, int list_channels, int chan_no, const char *channel ERROR("modulation field syntax '%s'", mod); return -6; } - printf("%3d %s: f %d, s %d, i %d, fec %d, qam %d, v %#x, a %#x\n", + printf("%3d %s: f %d, s %d, i %d, fec %d, qam %d, v %#x, a %#x, s %#x \n", chan_no, name, frontend->frequency, frontend->u.qam.symbol_rate, frontend->inversion, frontend->u.qam.fec_inner, - frontend->u.qam.modulation, *vpid, *apid); + frontend->u.qam.modulation, *vpid, *apid, *sid); free(name); free(inv); free(fec); @@ -178,31 +180,6 @@ int parse(const char *fname, int list_channels, int chan_no, const char *channel } - -static -int set_pesfilter (int fd, int pid, dmx_pes_type_t type, int dvr) -{ - struct dmx_pes_filter_params pesfilter; - - if (pid <= 0 || pid >= 0x1fff) - return 0; - - pesfilter.pid = pid; - pesfilter.input = DMX_IN_FRONTEND; - pesfilter.output = dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER; - pesfilter.pes_type = type; - pesfilter.flags = DMX_IMMEDIATE_START; - - if (ioctl(fd, DMX_SET_PES_FILTER, &pesfilter) < 0) { - PERROR ("ioctl(DMX_SET_PES_FILTER) for %s PID failed", - type == DMX_PES_AUDIO ? "Audio" : - type == DMX_PES_VIDEO ? "Video" : "??"); - return -1; - } - - return 0; -} - static int setup_frontend(int fe_fd, struct dvb_frontend_parameters *frontend) { @@ -264,9 +241,20 @@ int check_frontend (int fe_fd, int human_readable) } -static const char *usage = "\nusage: %s [-a adapter_num] [-f frontend_id] [-d demux_id] [-c conf_file] [ -H ] {<channel name>| -n channel_num} [-x]\n" - " or: %s [-c conf_file] -l\n\n"; - +static const char *usage = + "\nusage: %s [options] -l\n" + " list known channels\n" + " %s [options] {-n channel-number|channel_name}\n" + " zap to channel via number or full name (case insensitive)\n" + " -a number : use given adapter (default 0)\n" + " -f number : use given frontend (default 0)\n" + " -d number : use given demux (default 0)\n" + " -c file : read channels list from 'file'\n" + " -x : exit after tuning\n" + " -H : human readable output\n" + " -r : set up /dev/dvb/adapterX/dvr0 for TS recording\n" + " -p : add pat and pmt to TS recording (implies -r)\n" +; int main(int argc, char **argv) { @@ -275,12 +263,12 @@ int main(int argc, char **argv) char *confname = NULL; char *channel = NULL; int adapter = 0, frontend = 0, demux = 0, dvr = 0; - int vpid, apid; - int frontend_fd, video_fd, audio_fd; + int vpid, apid, sid, pmtpid = 0; + int frontend_fd, video_fd, audio_fd, pat_fd, pmt_fd; int opt, list_channels = 0, chan_no = 0; - int human_readable = 0; + int human_readable = 0, rec_psi = 0; - while ((opt = getopt(argc, argv, "Hln:hrn:a:f:d:c:x")) != -1) { + while ((opt = getopt(argc, argv, "Hln:hrn:a:f:d:c:x:p")) != -1) { switch (opt) { case 'a': adapter = strtoul(optarg, NULL, 0); @@ -300,6 +288,9 @@ int main(int argc, char **argv) case 'n': chan_no = strtoul(optarg, NULL, 0); break; + case 'p': + rec_psi = 1; + break; case 'x': exit_after_tuning = 1; break; @@ -352,7 +343,7 @@ int main(int argc, char **argv) memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters)); - if (parse(confname, list_channels, chan_no, channel, &frontend_param, &vpid, &apid)) + if (parse(confname, list_channels, chan_no, channel, &frontend_param, &vpid, &apid, &sid)) return -1; if (list_channels) return 0; @@ -365,6 +356,28 @@ int main(int argc, char **argv) if (setup_frontend(frontend_fd, &frontend_param) < 0) return -1; + if (rec_psi) { + pmtpid = get_pmt_pid(DEMUX_DEV, sid); + if (pmtpid <= 0) { + fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid); + return -1; + } + + if ((pat_fd = open(DEMUX_DEV, O_RDWR)) < 0) { + perror("opening pat demux failed"); + return -1; + } + if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, dvr) < 0) + return -1; + + if ((pmt_fd = open(DEMUX_DEV, O_RDWR)) < 0) { + perror("opening pmt demux failed"); + return -1; + } + if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, dvr) < 0) + return -1; + } + if ((video_fd = open(DEMUX_DEV, O_RDWR)) < 0) { PERROR("failed opening '%s'", DEMUX_DEV); return -1; @@ -383,6 +396,8 @@ int main(int argc, char **argv) check_frontend (frontend_fd, human_readable); + close (pat_fd); + close (pmt_fd); close (audio_fd); close (video_fd); close (frontend_fd); |