Exemplo n.º 1
0
static int check_frontend(struct arguments *args,
			  struct dvb_v5_fe_parms *parms)
{
	int rc;
	fe_status_t status = 0;
	do {
		rc = dvb_fe_get_stats(parms);
		if (rc) {
			PERROR(_("dvb_fe_get_stats failed"));
			usleep(1000000);
			continue;
		}

		status = 0;
		rc = dvb_fe_retrieve_stats(parms, DTV_STATUS, &status);
		if (!args->silent)
			print_frontend_stats(stderr, args, parms);
		if (status & FE_HAS_LOCK)
			break;
		usleep(1000000);
	} while (!timeout_flag);
	if (args->silent < 2)
		print_frontend_stats(stderr, args, parms);

	return status & FE_HAS_LOCK;
}
Exemplo n.º 2
0
static int check_frontend(struct arguments *args, struct dvb_v5_fe_parms *parms)
{
	int rc, i;
	fe_status_t status;

	args->n_status_lines = 0;
	for (i = 0; i < args->timeout_multiply * 40; i++) {
		rc = dvb_fe_get_stats(parms);
		if (rc)
			PERROR("dvb_fe_get_stats failed");

		rc = dvb_fe_retrieve_stats(parms, DTV_STATUS, &status);
		if (rc)
			status = 0;
		print_frontend_stats(args, parms);
		if (status & FE_HAS_LOCK)
			break;
		usleep(100000);
	};

	if (isatty(STDERR_FILENO)) {
		fprintf(stderr, "\x1b[37m");
	}

	return (status & FE_HAS_LOCK) ? 0 : -1;
}
Exemplo n.º 3
0
static
int monitor_frontend (int fe_fd, int human_readable)
{
	fe_status_t status;
	do {
	        ioctl(fe_fd, FE_READ_STATUS, &status);
		if (!silent)
			print_frontend_stats(fe_fd, human_readable);
		if (exit_after_tuning && (status & FE_HAS_LOCK))
			break;
		usleep(1000000);
	} while (!timeout_flag);
	if (silent < 2)
		print_frontend_stats (fe_fd, human_readable);

	return 0;
}
Exemplo n.º 4
0
static int check_frontend(struct arguments *args,
			  struct dvb_v5_fe_parms *parms)
{
	int rc;
	fe_status_t status;
	do {
		rc = dvb_fe_get_stats(parms);
		if (rc < 0)
			PERROR("dvb_fe_get_stats failed");

		rc = dvb_fe_retrieve_stats(parms, DTV_STATUS, &status);
		if (!args->silent)
			print_frontend_stats(parms, args->human_readable);
		if (args->exit_after_tuning && (status & FE_HAS_LOCK))
			break;
		usleep(1000000);
	} while (!timeout_flag);
	if (args->silent < 2)
		print_frontend_stats(parms, args->human_readable);

	return 0;
}
Exemplo n.º 5
0
static void get_show_stats(struct arguments *args,
			   struct dvb_v5_fe_parms *parms,
			   int loop)
{
	int rc;

	args->n_status_lines = 0;
	do {
		rc = dvb_fe_get_stats(parms);
		if (!rc)
			print_frontend_stats(stderr, args, parms);
		if (!timeout_flag && loop)
			usleep(1000000);
	} while (!timeout_flag && loop);
}
Exemplo n.º 6
0
static void get_show_stats(struct dvb_v5_fe_parms *parms)
{
	int rc;

	signal(SIGTERM, do_timeout);
	signal(SIGINT, do_timeout);

	do {
		rc = dvb_fe_get_stats(parms);
		if (!rc)
			print_frontend_stats(stderr, parms);
		if (!timeout_flag)
			usleep(1000000);
	} while (!timeout_flag);
}
Exemplo n.º 7
0
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;
	int audio_fd = 0, video_fd = 0;
	int dvr_fd, file_fd;
	struct dvb_v5_fe_parms *parms;
	const struct argp argp = {
		.options = options,
		.parser = parse_opt,
		.doc = "DVB zap utility",
		.args_doc = "<initial file>",
	};

	memset(&args, 0, sizeof(args));
	args.sat_number = -1;

	argp_parse(&argp, argc, argv, 0, &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.lnb_name) {
		lnb = search_lnb(args.lnb_name);
		if (lnb < 0) {
			printf("Please select one of the LNBf's below:\n");
			print_all_lnb();
			exit(1);
		} else {
			printf("Using LNBf ");
			print_lnb(lnb);
		}
	}

	asprintf(&args.demux_dev,
		 "/dev/dvb/adapter%i/demux%i", args.adapter, args.demux);

	asprintf(&args.dvr_dev,
		 "/dev/dvb/adapter%i/dvr%i", args.adapter, args.demux);

	if (args.silent < 2)
		fprintf(stderr, "using demux '%s'\n", args.demux_dev);

	if (!args.confname) {
		if (!homedir)
			ERROR("$HOME not set");
		asprintf(&args.confname, "%s/.tzap/%i/%s",
			 homedir, args.adapter, CHANNEL_FILE);
		if (access(args.confname, R_OK))
			asprintf(&args.confname, "%s/.tzap/%s",
				homedir, CHANNEL_FILE);
	}
	printf("reading channels from file '%s'\n", args.confname);

	parms = dvb_fe_open(args.adapter, args.frontend, 0, 0);
	if (!parms)
		return -1;
	if (lnb)
		parms->lnb = 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;

	if (parse(&args, parms, channel, &vpid, &apid, &sid))
		return -1;

	if (setup_frontend(&args, parms) < 0)
		return -1;

	if (args.frontend_only) {
		check_frontend(&args, parms);
		dvb_fe_close(parms);
		return 0;
	}

	if (args.rec_psi) {
		if (sid < 0) {
			fprintf(stderr, "Service id 0x%04x was not specified at the file\n",
				sid);
			return -1;
		}
		pmtpid = get_pmt_pid(args.demux_dev, sid);
		if (pmtpid <= 0) {
			fprintf(stderr, "couldn't find pmt-pid for sid %04x\n",
				sid);
			return -1;
		}

		if ((pat_fd = open(args.demux_dev, O_RDWR)) < 0) {
			perror("opening pat demux failed");
			return -1;
		}
		if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, args.dvr) < 0)
			return -1;

		if ((pmt_fd = open(args.demux_dev, O_RDWR)) < 0) {
			perror("opening pmt demux failed");
			return -1;
		}
		if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, args.dvr) < 0)
			return -1;
	}

	if (vpid >= 0) {
		if (args.silent < 2)
			fprintf(stderr, "video pid %d\n", vpid);
		if ((video_fd = open(args.demux_dev, O_RDWR)) < 0) {
			PERROR("failed opening '%s'", args.demux_dev);
			return -1;
		}
		if (set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, args.dvr) < 0)
			return -1;
	}

	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);
			return -1;
		}

		if (set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, args.dvr) < 0)
			return -1;
	}

	signal(SIGALRM, do_timeout);
	if (args.timeout > 0)
		alarm(args.timeout);

	if (args.record) {
		if (args.filename != NULL) {
			if (strcmp(args.filename, "-") != 0) {
				file_fd =
				    open(args.filename,
					 O_WRONLY | O_LARGEFILE | O_CREAT,
					 0644);
				if (file_fd < 0) {
					PERROR("open of '%s' failed",
					       args.filename);
					return -1;
				}
			} else {
				file_fd = 1;
			}
		} else {
			PERROR("Record mode but no filename!");
			return -1;
		}

		if ((dvr_fd = open(args.dvr_dev, O_RDONLY)) < 0) {
			PERROR("failed opening '%s'", args.dvr_dev);
			return -1;
		}
		if (args.silent < 2)
			print_frontend_stats(parms, args.human_readable);

		copy_to_file(dvr_fd, file_fd, args.timeout, args.silent);

		if (args.silent < 2)
			print_frontend_stats(parms, args.human_readable);
	} else {
		check_frontend(&args, parms);
	}

	close(pat_fd);
	close(pmt_fd);
	close(audio_fd);
	close(video_fd);
	dvb_fe_close(parms);

	return 0;
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
	struct dvb_frontend_parameters frontend_param;
	char *homedir = getenv("HOME");
	char *confname = NULL;
	char *channel = NULL;
	int adapter = 0, frontend = 0, demux = 0, dvr = 0;
	int vpid, apid, sid, pmtpid = 0;
	int pat_fd, pmt_fd;
	int frontend_fd, audio_fd = 0, video_fd = 0, dvr_fd, file_fd;
	int opt;
	int record = 0;
	int frontend_only = 0;
	char *filename = NULL;
	int human_readable = 0, rec_psi = 0;

	while ((opt = getopt(argc, argv, "H?hrpxRsFSn:a:f:d:c:t:o:")) != -1) {
		switch (opt) {
		case 'a':
			adapter = strtoul(optarg, NULL, 0);
			break;
		case 'f':
			frontend = strtoul(optarg, NULL, 0);
			break;
		case 'd':
			demux = strtoul(optarg, NULL, 0);
			break;
		case 't':
			timeout = strtoul(optarg, NULL, 0);
			break;
		case 'o':
			filename = strdup(optarg);
			record=1;
			/* fall through */
		case 'r':
			dvr = 1;
			break;
		case 'p':
			rec_psi = 1;
			break;
		case 'x':
			exit_after_tuning = 1;
			break;
		case 'c':
			confname = optarg;
			break;
		case 's':
			silent = 1;
			break;
		case 'S':
			silent = 2;
			break;
		case 'F':
			frontend_only = 1;
			break;
		case 'H':
			human_readable = 1;
			break;
		case '?':
		case 'h':
		default:
			fprintf (stderr, usage, argv[0]);
			return -1;
		};
	}

	if (optind < argc)
		channel = argv[optind];

	if (!channel) {
		fprintf (stderr, usage, argv[0]);
		return -1;
	}
#if defined(ANDROID)
	snprintf(FRONTEND_DEV,
		 sizeof(FRONTEND_DEV),
		 "/dev/dvb%i.frontend%i",
	  	 adapter,
	  	 frontend);

	snprintf(DEMUX_DEV,
		 sizeof(DEMUX_DEV),
		 "/dev/dvb%i.demux%i",
	  	 adapter,
	  	 demux);

	snprintf(DVR_DEV,
		 sizeof(DVR_DEV),
		 "/dev/dvb%i.dvr%i",
	  	 adapter,
	  	 demux);
#else
	snprintf(FRONTEND_DEV,
		 sizeof(FRONTEND_DEV),
		 "/dev/dvb/adapter%i/frontend%i",
	  	 adapter,
	  	 frontend);

	snprintf(DEMUX_DEV,
		 sizeof(DEMUX_DEV),
		 "/dev/dvb/adapter%i/demux%i",
	  	 adapter,
	  	 demux);

	snprintf(DVR_DEV,
		 sizeof(DVR_DEV),
		 "/dev/dvb/adapter%i/dvr%i",
	  	 adapter,
	  	 demux);
#endif
	if (silent < 2)
		fprintf (stderr,"using '%s' and '%s'\n", FRONTEND_DEV, DEMUX_DEV);

	if (!confname) {
		int len = strlen(homedir) + strlen(CHANNEL_FILE) + 18;
		if (!homedir)
			ERROR ("$HOME not set");
		confname = malloc (len);
		snprintf(confname, len, "%s/.tzap/%i/%s", homedir, adapter, CHANNEL_FILE);
		if (access (confname, R_OK))
			snprintf(confname, len, "%s/.tzap/%s", homedir, CHANNEL_FILE);
	}
	printf("reading channels from file '%s'\n", confname);
	memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters));

	if (parse (confname, channel, &frontend_param, &vpid, &apid, &sid))
		return -1;

	if ((frontend_fd = open(FRONTEND_DEV, O_RDWR | O_NONBLOCK)) < 0) {
		PERROR ("failed opening '%s'", FRONTEND_DEV);
		return -1;
	}

	if (setup_frontend (frontend_fd, &frontend_param) < 0)
		return -1;

	if (frontend_only)
		goto just_the_frontend_dude;

	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;
	}

	if (silent<2)
		fprintf(stderr,"video pid 0x%04x, audio pid 0x%04x\n", vpid, apid);

	if (set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, dvr) < 0)
		return -1;

	if ((audio_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
		PERROR("failed opening '%s'", DEMUX_DEV);
		return -1;
	}

	if (set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, dvr) < 0)
		return -1;

	signal(SIGALRM,do_timeout);
	if (timeout > 0)
		alarm(timeout);

	if (record) {
		if (filename!=NULL) {
			if (strcmp(filename,"-")!=0) {
				file_fd = open(filename,O_WRONLY|O_LARGEFILE|O_CREAT,0644);
				if (file_fd<0) {
					PERROR("open of '%s' failed",filename);
					return -1;
				}
			} else {
				file_fd=1;
			}
		} else {
			PERROR("Record mode but no filename!");
			return -1;
		}

		if ((dvr_fd = open(DVR_DEV, O_RDONLY)) < 0) {
	                PERROR("failed opening '%s'", DVR_DEV);
	                return -1;
	        }
		if (silent<2)
			print_frontend_stats(frontend_fd, human_readable);

		copy_to_file(dvr_fd,file_fd);

		if (silent<2)
			print_frontend_stats(frontend_fd, human_readable);
	} else {
just_the_frontend_dude:
		monitor_frontend(frontend_fd, human_readable);
	}

	close(pat_fd);
	close(pmt_fd);
	close(audio_fd);
	close(video_fd);
	close(frontend_fd);
	return 0;
}
Exemplo n.º 9
0
int do_traffic_monitor(struct arguments *args,
		    struct dvb_v5_fe_parms *parms)
{
	int fd, dvr_fd;
	long long unsigned pidt[0x2001], wait;
	int packets = 0;
	struct timeval startt;

	memset(pidt, 0, sizeof(pidt));

	args->exit_after_tuning = 1;
	check_frontend(args, parms);

	if ((dvr_fd = open(args->dvr_dev, O_RDONLY)) < 0) {
		PERROR("failed opening '%s'", args->dvr_dev);
		return -1;
	}

	if (ioctl(dvr_fd, DMX_SET_BUFFER_SIZE, 1024 * 1024) == -1)
		perror("DMX_SET_BUFFER_SIZE failed");

	if ((fd = open(args->demux_dev, O_RDWR)) < 0) {
		PERROR("failed opening '%s'", args->demux_dev);
		return -1;
	}

	if (args->silent < 2)
		fprintf(stderr, "  dvb_set_pesfilter to 0x2000\n");
	if (dvb_set_pesfilter(fd, 0x2000, DMX_PES_OTHER,
			      DMX_OUT_TS_TAP, 0) < 0) {
		PERROR("couldn't set filter");
		return -1;
	}

	gettimeofday(&startt, 0);
	wait = 1000;

	while (1) {
		unsigned char buffer[BSIZE];
		int pid, ok;
		ssize_t r;
		if ((r = read(dvr_fd, buffer, BSIZE)) <= 0) {
			if (errno == EOVERFLOW) {
				struct timeval now;
				int diff;
				gettimeofday(&now, 0);
				diff =
				    (now.tv_sec - startt.tv_sec) * 1000 +
				    (now.tv_usec - startt.tv_usec) / 1000;
				fprintf(stderr, "%.2fs: buffer overrun\n", diff / 1000.);
				continue;
			}
			perror("read");
			break;
		}
		if (r != BSIZE) {
			fprintf(stderr, "dvbtraffic: only read %zd bytes\n", r);
			break;
		}
		if (buffer[0] != 0x47) {
			continue;
			printf("desync (%x)\n", buffer[0]);
			while (buffer[0] != 0x47)
				read(fd, buffer, 1);
			continue;
		}
		ok = 1;
		pid = ((((unsigned) buffer[1]) << 8) |
		       ((unsigned) buffer[2])) & 0x1FFF;

		if (args->search) {
			int i, sl = strlen(args->search);
			ok = 0;
			if (pid != 0x1fff) {
				for (i = 0; i < (188 - sl); ++i) {
					if (!memcmp(buffer + i, args->search, sl))
						ok = 1;
				}
			}
		}

		if (ok) {
			pidt[pid]++;
			pidt[0x2000]++;
		}

		packets++;

		if (!(packets & 0xFF)) {
			struct timeval now;
			int diff;
			gettimeofday(&now, 0);
			diff =
			    (now.tv_sec - startt.tv_sec) * 1000 +
			    (now.tv_usec - startt.tv_usec) / 1000;
			if (diff > wait) {
				if (isatty(STDOUT_FILENO))
			                printf("\x1b[1H\x1b[2J");

				args->n_status_lines = 0;
				printf(" PID          FREQ         SPEED       TOTAL\n");
				int _pid = 0;
				for (_pid = 0; _pid < 0x2000; _pid++) {
					if (pidt[_pid]) {
						if (!args->low_traffic && (pidt[_pid] * 1000. / diff) < 1)
							continue;
						printf("%04x %9.2f p/s %8.1f Kbps ",
						     _pid,
						     pidt[_pid] * 1000. / diff,
						     pidt[_pid] * 1000. / diff * 8 * 188 / 1024);
						if (pidt[_pid] * 188 / 1024)
							printf("%8llu KB\n", pidt[_pid] * 188 / 1024);
						else
							printf(" %8llu B\n", pidt[_pid] * 188);
					}
				}
				/* 0x2000 is the total traffic */
				printf("TOT %10.2f p/s %8.1f Kbps %8llu KB\n",
				     pidt[_pid] * 1000. / diff,
				     pidt[_pid] * 1000. / diff * 8 * 188 / 1024,
				     pidt[_pid] * 188 / 1024);
				printf("\n\n");
				print_frontend_stats(stdout, args, parms);
				wait += 1000;
			}
		}
	}
	close (fd);
	return 0;
}