void Frontend::CloseDemux( int fd ) { dvb_dmx_close( fd ); }
int main(int argc, char **argv) { struct arguments args; char *homedir = getenv("HOME"); char *channel = NULL; int lnb = -1, idx = -1; int vpid = -1, apid = -1, sid = -1; int pmtpid = 0; int pat_fd = -1, pmt_fd = -1, sid_fd = -1; int audio_fd = -1, video_fd = -1; int dvr_fd = -1, file_fd = -1; int err = -1; int r; struct dvb_v5_fe_parms *parms = NULL; const struct argp argp = { .options = options, .parser = parse_opt, .doc = N_("DVB zap utility"), .args_doc = N_("<channel name> [or <frequency> if in monitor mode]"), }; #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif memset(&args, 0, sizeof(args)); args.sat_number = -1; args.lna = LNA_AUTO; args.input_format = FILE_DVBV5; argp_parse(&argp, argc, argv, ARGP_NO_HELP | ARGP_NO_EXIT, &idx, &args); if (idx < argc) channel = argv[idx]; if (!channel) { argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (args.input_format == FILE_UNKNOWN) { fprintf(stderr, _("ERROR: Please specify a valid format\n")); argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (!args.traffic_monitor && args.search) { fprintf(stderr, _("ERROR: search string can be used only on monitor mode\n")); argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (args.lnb_name) { lnb = dvb_sat_search_lnb(args.lnb_name); if (lnb < 0) { printf(_("Please select one of the LNBf's below:\n")); dvb_print_all_lnb(); exit(1); } else { printf(_("Using LNBf ")); dvb_print_lnb(lnb); } } r = asprintf(&args.demux_dev, "/dev/dvb/adapter%i/demux%i", args.adapter, args.demux); if (r < 0) { fprintf(stderr, _("asprintf error\n")); return -1; } r = asprintf(&args.dvr_dev, "/dev/dvb/adapter%i/dvr%i", args.adapter, args.demux); if (r < 0) { fprintf(stderr, _("asprintf error\n")); return -1; } if (args.silent < 2) fprintf(stderr, _("using demux '%s'\n"), args.demux_dev); if (!args.confname) { if (!homedir) ERROR(_("$HOME not set")); r = asprintf(&args.confname, "%s/.tzap/%i/%s", homedir, args.adapter, CHANNEL_FILE); if (access(args.confname, R_OK)) { free(args.confname); r = asprintf(&args.confname, "%s/.tzap/%s", homedir, CHANNEL_FILE); } } fprintf(stderr, _("reading channels from file '%s'\n"), args.confname); parms = dvb_fe_open(args.adapter, args.frontend, args.verbose, args.force_dvbv3); if (!parms) goto err; if (lnb >= 0) parms->lnb = dvb_sat_get_lnb(lnb); if (args.sat_number > 0) parms->sat_number = args.sat_number % 3; parms->diseqc_wait = args.diseqc_wait; parms->freq_bpf = args.freq_bpf; parms->lna = args.lna; r = dvb_fe_set_default_country(parms, args.cc); if (r < 0) fprintf(stderr, _("Failed to set the country code:%s\n"), args.cc); if (parse(&args, parms, channel, &vpid, &apid, &sid)) goto err; if (setup_frontend(&args, parms) < 0) goto err; if (args.exit_after_tuning) { err = 0; check_frontend(&args, parms); goto err; } if (args.traffic_monitor) { signal(SIGTERM, do_timeout); signal(SIGINT, do_timeout); if (args.timeout > 0) { signal(SIGINT, do_timeout); alarm(args.timeout); } err = do_traffic_monitor(&args, parms); goto err; } if (args.rec_psi) { if (sid < 0) { fprintf(stderr, _("Service id 0x%04x was not specified at the file\n"), sid); goto err; } sid_fd = dvb_dmx_open(args.adapter, args.demux); if (sid_fd < 0) { perror(_("opening pat demux failed")); return -1; } pmtpid = dvb_get_pmt_pid(sid_fd, sid); dvb_dmx_close(sid_fd); if (pmtpid <= 0) { fprintf(stderr, _("couldn't find pmt-pid for sid %04x\n"), sid); goto err; } if ((pat_fd = open(args.demux_dev, O_RDWR)) < 0) { perror(_("opening pat demux failed")); goto err; } if (dvb_set_pesfilter(pat_fd, 0, DMX_PES_OTHER, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; if ((pmt_fd = open(args.demux_dev, O_RDWR)) < 0) { perror(_("opening pmt demux failed")); goto err; } if (dvb_set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; } if (args.all_pids++) { vpid = 0x2000; apid = 0; } if (vpid >= 0) { if (args.silent < 2) { if (vpid == 0x2000) fprintf(stderr, _("pass all PID's to TS\n")); else fprintf(stderr, _("video pid %d\n"), vpid); } if ((video_fd = open(args.demux_dev, O_RDWR)) < 0) { PERROR(_("failed opening '%s'"), args.demux_dev); goto err; } if (args.silent < 2) fprintf(stderr, _(" dvb_set_pesfilter %d\n"), vpid); if (vpid == 0x2000) { if (ioctl(video_fd, DMX_SET_BUFFER_SIZE, 1024 * 1024) == -1) perror(_("DMX_SET_BUFFER_SIZE failed")); if (dvb_set_pesfilter(video_fd, vpid, DMX_PES_OTHER, DMX_OUT_TS_TAP, 0) < 0) goto err; } else { if (dvb_set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; } } if (apid > 0) { if (args.silent < 2) fprintf(stderr, _("audio pid %d\n"), apid); if ((audio_fd = open(args.demux_dev, O_RDWR)) < 0) { PERROR(_("failed opening '%s'"), args.demux_dev); goto err; } if (args.silent < 2) fprintf(stderr, _(" dvb_set_pesfilter %d\n"), apid); if (dvb_set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; } signal(SIGALRM, do_timeout); signal(SIGTERM, do_timeout); if (args.timeout > 0) { signal(SIGINT, do_timeout); alarm(args.timeout); } if (!check_frontend(&args, parms)) { err = 1; fprintf(stderr, _("frontend doesn't lock\n")); goto err; } if (args.dvr) { if (args.filename) { file_fd = STDOUT_FILENO; if (strcmp(args.filename, "-") != 0) { file_fd = open(args.filename, #ifdef O_LARGEFILE O_LARGEFILE | #endif O_WRONLY | O_CREAT, 0644); if (file_fd < 0) { PERROR(_("open of '%s' failed"), args.filename); return -1; } } } if (args.silent < 2) get_show_stats(&args, parms, 0); if (file_fd >= 0) { if ((dvr_fd = open(args.dvr_dev, O_RDONLY)) < 0) { PERROR(_("failed opening '%s'"), args.dvr_dev); goto err; } if (!timeout_flag) fprintf(stderr, _("Record to file '%s' started\n"), args.filename); copy_to_file(dvr_fd, file_fd, args.timeout, args.silent); } else { if (!timeout_flag) fprintf(stderr, _("DVR interface '%s' can now be opened\n"), args.dvr_dev); get_show_stats(&args, parms, 1); } if (args.silent < 2) get_show_stats(&args, parms, 0); } err = 0; err: if (file_fd > 0) close(file_fd); if (dvr_fd > 0) close(dvr_fd); if (pat_fd > 0) close(pat_fd); if (pmt_fd > 0) close(pmt_fd); if (audio_fd > 0) close(audio_fd); if (video_fd > 0) close(video_fd); if (parms) dvb_fe_close(parms); if (args.confname) free(args.confname); if (args.demux_dev) free(args.demux_dev); if (args.dvr_dev) free(args.dvr_dev); return err; }