aboutsummaryrefslogtreecommitdiffstats
path: root/util/szap
diff options
context:
space:
mode:
Diffstat (limited to 'util/szap')
-rw-r--r--util/szap/Makefile7
-rw-r--r--util/szap/azap.c82
-rw-r--r--util/szap/czap.c25
-rw-r--r--util/szap/lnb.c11
-rw-r--r--util/szap/lnb.h6
-rw-r--r--util/szap/szap.c962
-rw-r--r--util/szap/tzap.c232
-rw-r--r--util/szap/util.c153
8 files changed, 743 insertions, 735 deletions
diff --git a/util/szap/Makefile b/util/szap/Makefile
index 48d7149..837e989 100644
--- a/util/szap/Makefile
+++ b/util/szap/Makefile
@@ -1,5 +1,11 @@
# Makefile for linuxtv.org dvb-apps/util/szap
+# get DVB API version
+VERSION_FILE := "/usr/include/linux/dvb/version.h"
+
+DVB_API_MAJOR := $(word 3, $(shell grep -m1 "DVB_API_VERSION" $(VERSION_FILE)) )
+DVB_API_MINOR := $(word 3, $(shell grep -m1 "DVB_API_VERSION_MINOR" $(VERSION_FILE)) )
+
objects = lnb.o util.o
binaries = azap \
@@ -12,6 +18,7 @@ inst_bin = $(binaries)
.PHONY: all
all: $(binaries)
+$(info DVB API is $(DVB_API_MAJOR).$(DVB_API_MINOR))
$(binaries): $(objects)
diff --git a/util/szap/azap.c b/util/szap/azap.c
index ea13236..230a7b9 100644
--- a/util/szap/azap.c
+++ b/util/szap/azap.c
@@ -21,18 +21,18 @@ static char DEMUX_DEV [80];
#define CHANNEL_FILE "/.azap/channels.conf"
#define ERROR(x...) \
- do { \
- fprintf(stderr, "ERROR: "); \
- fprintf(stderr, x); \
- fprintf (stderr, "\n"); \
- } while (0)
+ do { \
+ fprintf(stderr, "ERROR: "); \
+ fprintf(stderr, x); \
+ fprintf (stderr, "\n"); \
+ } while (0)
#define PERROR(x...) \
- do { \
- fprintf(stderr, "ERROR: "); \
- fprintf(stderr, x); \
- fprintf (stderr, " (%s)\n", strerror(errno)); \
- } while (0)
+ do { \
+ fprintf(stderr, "ERROR: "); \
+ fprintf(stderr, x); \
+ fprintf (stderr, " (%s)\n", strerror(errno)); \
+ } while (0)
typedef struct {
@@ -353,49 +353,49 @@ int main(int argc, char **argv)
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;
- }
+ 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;
+ }
printf ("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;
- }
+ PERROR("failed opening '%s'", DEMUX_DEV);
+ return -1;
+ }
if (set_pesfilter (audio_fd, apid, DMX_PES_AUDIO, dvr) < 0)
return -1;
check_frontend (frontend_fd);
- close (pat_fd);
- close (pmt_fd);
+ close (pat_fd);
+ close (pmt_fd);
close (audio_fd);
close (video_fd);
close (frontend_fd);
diff --git a/util/szap/czap.c b/util/szap/czap.c
index e04ed4b..8a97d98 100644
--- a/util/szap/czap.c
+++ b/util/szap/czap.c
@@ -242,19 +242,18 @@ int check_frontend (int fe_fd, int human_readable)
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"
-;
+ "\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)
{
diff --git a/util/szap/lnb.c b/util/szap/lnb.c
index 9052d1c..3202da1 100644
--- a/util/szap/lnb.c
+++ b/util/szap/lnb.c
@@ -44,8 +44,7 @@ static struct lnb_types_st lnbs[] = {
* Increment curno each time
*/
-struct lnb_types_st *
-lnb_enum(int curno)
+struct lnb_types_st *lnb_enum(int curno)
{
if (curno >= (int) (sizeof(lnbs) / sizeof(lnbs[0])))
return (struct lnb_types_st *)NULL;
@@ -57,16 +56,16 @@ lnb_enum(int curno)
* otherwise low[,high[,switch]]
*/
-int
-lnb_decode(char *str, struct lnb_types_st *lnbp)
+int lnb_decode(char *str, struct lnb_types_st *lnbp)
{
-int i;
-char *cp, *np;
+ int i;
+ char *cp, *np;
memset(lnbp, 0, sizeof(*lnbp));
cp = str;
while(*cp && isspace(*cp))
cp++;
+
if (isalpha(*cp)) {
for (i = 0; i < (int)(sizeof(lnbs) / sizeof(lnbs[0])); i++) {
if (!strcasecmp(lnbs[i].name, cp)) {
diff --git a/util/szap/lnb.h b/util/szap/lnb.h
index 6370fd4..6cc9e1d 100644
--- a/util/szap/lnb.h
+++ b/util/szap/lnb.h
@@ -10,13 +10,11 @@ struct lnb_types_st {
* Increment curno each time
*/
-struct lnb_types_st *
-lnb_enum(int curno);
+struct lnb_types_st *lnb_enum(int curno);
/* Decode an lnb type, for example given on a command line
* If alpha and standard type, e.g. "Universal" then match that
* otherwise low[,high[,switch]]
*/
-int
-lnb_decode(char *str, struct lnb_types_st *lnbp);
+int lnb_decode(char *str, struct lnb_types_st *lnbp);
diff --git a/util/szap/szap.c b/util/szap/szap.c
index 78da3a6..9de752e 100644
--- a/util/szap/szap.c
+++ b/util/szap/szap.c
@@ -75,46 +75,46 @@ static int exit_after_tuning;
static int interactive;
static char *usage_str =
- "\nusage: szap -q\n"
- " list known channels\n"
- " szap [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"
- " -b : enable Audio Bypass (default no)\n"
- " -x : exit after tuning\n"
- " -H : human readable output\n"
- " -r : set up /dev/dvb/adapterX/dvr0 for TS recording\n"
- " -l lnb-type (DVB-S Only) (use -l help to print types) or \n"
- " -l low[,high[,switch]] in Mhz\n"
- " -i : run interactively, allowing you to type in channel names\n"
- " -p : add pat and pmt to TS recording (implies -r)\n"
- " or -n numbers for zapping\n";
+ "\nusage: szap -q\n"
+ " list known channels\n"
+ " szap [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"
+ " -b : enable Audio Bypass (default no)\n"
+ " -x : exit after tuning\n"
+ " -H : human readable output\n"
+ " -r : set up /dev/dvb/adapterX/dvr0 for TS recording\n"
+ " -l lnb-type (DVB-S Only) (use -l help to print types) or \n"
+ " -l low[,high[,switch]] in Mhz\n"
+ " -i : run interactively, allowing you to type in channel names\n"
+ " -p : add pat and pmt to TS recording (implies -r)\n"
+ " or -n numbers for zapping\n";
struct diseqc_cmd {
- struct dvb_diseqc_master_cmd cmd;
- uint32_t wait;
+ struct dvb_diseqc_master_cmd cmd;
+ uint32_t wait;
};
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)
{
- if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
- perror("FE_SET_TONE failed");
- if (ioctl(fd, FE_SET_VOLTAGE, v) == -1)
- perror("FE_SET_VOLTAGE failed");
- usleep(15 * 1000);
- if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd) == -1)
- perror("FE_DISEQC_SEND_MASTER_CMD failed");
- usleep(cmd->wait * 1000);
- usleep(15 * 1000);
- if (ioctl(fd, FE_DISEQC_SEND_BURST, b) == -1)
- perror("FE_DISEQC_SEND_BURST failed");
- usleep(15 * 1000);
- if (ioctl(fd, FE_SET_TONE, t) == -1)
- perror("FE_SET_TONE failed");
+ if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
+ perror("FE_SET_TONE failed");
+ if (ioctl(fd, FE_SET_VOLTAGE, v) == -1)
+ perror("FE_SET_VOLTAGE failed");
+ usleep(15 * 1000);
+ if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd) == -1)
+ perror("FE_DISEQC_SEND_MASTER_CMD failed");
+ usleep(cmd->wait * 1000);
+ usleep(15 * 1000);
+ if (ioctl(fd, FE_DISEQC_SEND_BURST, b) == -1)
+ perror("FE_DISEQC_SEND_BURST failed");
+ usleep(15 * 1000);
+ if (ioctl(fd, FE_SET_TONE, t) == -1)
+ perror("FE_SET_TONE failed");
}
@@ -125,89 +125,89 @@ void diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd,
*/
static int diseqc(int secfd, int sat_no, int pol_vert, int hi_band)
{
- struct diseqc_cmd cmd =
- { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
+ struct diseqc_cmd cmd =
+ { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
- /* param: high nibble: reset bits, low nibble set bits,
- * bits are: option, position, polarization, band
- */
- cmd.cmd.msg[3] =
- 0xf0 | (((sat_no * 4) & 0x0f) | (hi_band ? 1 : 0) | (pol_vert ? 0 : 2));
+ /* param: high nibble: reset bits, low nibble set bits,
+ * bits are: option, position, polarization, band
+ */
+ cmd.cmd.msg[3] =
+ 0xf0 | (((sat_no * 4) & 0x0f) | (hi_band ? 1 : 0) | (pol_vert ? 0 : 2));
- diseqc_send_msg(secfd, pol_vert ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18,
- &cmd, hi_band ? SEC_TONE_ON : SEC_TONE_OFF,
- sat_no % 2 ? SEC_MINI_B : SEC_MINI_A);
+ diseqc_send_msg(secfd, pol_vert ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18,
+ &cmd, hi_band ? SEC_TONE_ON : SEC_TONE_OFF,
+ sat_no % 2 ? SEC_MINI_B : SEC_MINI_A);
- return TRUE;
+ return TRUE;
}
static int do_tune(int fefd, unsigned int ifreq, unsigned int sr)
{
- struct dvb_frontend_parameters tuneto;
- struct dvb_frontend_event ev;
-
- /* discard stale QPSK events */
- while (1) {
- if (ioctl(fefd, FE_GET_EVENT, &ev) == -1)
- break;
- }
-
- tuneto.frequency = ifreq;
- tuneto.inversion = INVERSION_AUTO;
- tuneto.u.qpsk.symbol_rate = sr;
- tuneto.u.qpsk.fec_inner = FEC_AUTO;
-
- if (ioctl(fefd, FE_SET_FRONTEND, &tuneto) == -1) {
- perror("FE_SET_FRONTEND failed");
- return FALSE;
- }
-
- return TRUE;
+ struct dvb_frontend_parameters tuneto;
+ struct dvb_frontend_event ev;
+
+ /* discard stale QPSK events */
+ while (1) {
+ if (ioctl(fefd, FE_GET_EVENT, &ev) == -1)
+ break;
+ }
+
+ tuneto.frequency = ifreq;
+ tuneto.inversion = INVERSION_AUTO;
+ tuneto.u.qpsk.symbol_rate = sr;
+ tuneto.u.qpsk.fec_inner = FEC_AUTO;
+
+ if (ioctl(fefd, FE_SET_FRONTEND, &tuneto) == -1) {
+ perror("FE_SET_FRONTEND failed");
+ return FALSE;
+ }
+
+ return TRUE;
}
-static
-int check_frontend (int fe_fd, int dvr, int human_readable)
+static int check_frontend (int fe_fd, int dvr, int human_readable)
{
- (void)dvr;
- fe_status_t status;
- uint16_t snr, signal;
- uint32_t ber, uncorrected_blocks;
- int timeout = 0;
-
- do {
- if (ioctl(fe_fd, FE_READ_STATUS, &status) == -1)
- perror("FE_READ_STATUS failed");
- /* some frontends might not support all these ioctls, thus we
- * avoid printing errors */
- if (ioctl(fe_fd, FE_READ_SIGNAL_STRENGTH, &signal) == -1)
- signal = -2;
- if (ioctl(fe_fd, FE_READ_SNR, &snr) == -1)
- snr = -2;
- if (ioctl(fe_fd, FE_READ_BER, &ber) == -1)
- ber = -2;
- if (ioctl(fe_fd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks) == -1)
- uncorrected_blocks = -2;
-
- if (human_readable) {
- printf ("status %02x | signal %3u%% | snr %3u%% | ber %d | unc %d | ",
- status, (signal * 100) / 0xffff, (snr * 100) / 0xffff, ber, uncorrected_blocks);
- } else {
- printf ("status %02x | signal %04x | snr %04x | ber %08x | unc %08x | ",
- status, signal, snr, ber, uncorrected_blocks);
- }
+ (void)dvr;
+ fe_status_t status;
+ uint16_t snr, signal;
+ uint32_t ber, uncorrected_blocks;
+ int timeout = 0;
+
+ do {
+ if (ioctl(fe_fd, FE_READ_STATUS, &status) == -1)
+ perror("FE_READ_STATUS failed");
+ /* some frontends might not support all these ioctls, thus we
+ * avoid printing errors
+ */
+ if (ioctl(fe_fd, FE_READ_SIGNAL_STRENGTH, &signal) == -1)
+ signal = -2;
+ if (ioctl(fe_fd, FE_READ_SNR, &snr) == -1)
+ snr = -2;
+ if (ioctl(fe_fd, FE_READ_BER, &ber) == -1)
+ ber = -2;
+ if (ioctl(fe_fd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks) == -1)
+ uncorrected_blocks = -2;
+
+ if (human_readable) {
+ printf ("status %02x | signal %3u%% | snr %3u%% | ber %d | unc %d | ",
+ status, (signal * 100) / 0xffff, (snr * 100) / 0xffff, ber, uncorrected_blocks);
+ } else {
+ printf ("status %02x | signal %04x | snr %04x | ber %08x | unc %08x | ",
+ status, signal, snr, ber, uncorrected_blocks);
+ }
- if (status & FE_HAS_LOCK)
- printf("FE_HAS_LOCK");
- printf("\n");
+ if (status & FE_HAS_LOCK)
+ printf("FE_HAS_LOCK");
+ printf("\n");
- if (exit_after_tuning && ((status & FE_HAS_LOCK) || (++timeout >= 10)))
- break;
+ if (exit_after_tuning && ((status & FE_HAS_LOCK) || (++timeout >= 10)))
+ break;
- usleep(1000000);
- } while (1);
+ usleep(1000000);
+ } while (1);
- return 0;
+ return 0;
}
@@ -217,126 +217,125 @@ int zap_to(unsigned int adapter, unsigned int frontend, unsigned int demux,
unsigned int sr, unsigned int vpid, unsigned int apid, int sid,
int dvr, int rec_psi, int bypass, int human_readable)
{
- char fedev[128], dmxdev[128], auddev[128];
- static int fefd, dmxfda, dmxfdv, audiofd = -1, patfd, pmtfd;
- int pmtpid;
- uint32_t ifreq;
- int hiband, result;
- static struct dvb_frontend_info fe_info;
-
- if (!fefd) {
- snprintf(fedev, sizeof(fedev), FRONTENDDEVICE, adapter, frontend);
- snprintf(dmxdev, sizeof(dmxdev), DEMUXDEVICE, adapter, demux);
- snprintf(auddev, sizeof(auddev), AUDIODEVICE, adapter, demux);
- printf("using '%s' and '%s'\n", fedev, dmxdev);
-
- if ((fefd = open(fedev, O_RDWR | O_NONBLOCK)) < 0) {
- perror("opening frontend failed");
- return FALSE;
- }
-
- result = ioctl(fefd, FE_GET_INFO, &fe_info);
-
- if (result < 0) {
- perror("ioctl FE_GET_INFO failed");
- close(fefd);
- return FALSE;
- }
-
- if (fe_info.type != FE_QPSK) {
- fprintf(stderr, "frontend device is not a QPSK (DVB-S) device!\n");
- close(fefd);
- return FALSE;
- }
-
- if ((dmxfdv = open(dmxdev, O_RDWR)) < 0) {
- perror("opening video demux failed");
- close(fefd);
- return FALSE;
- }
-
- if ((dmxfda = open(dmxdev, O_RDWR)) < 0) {
- perror("opening audio demux failed");
- close(fefd);
- return FALSE;
- }
-
- if (dvr == 0) /* DMX_OUT_DECODER */
- audiofd = open(auddev, O_RDWR);
-
- if (rec_psi){
- if ((patfd = open(dmxdev, O_RDWR)) < 0) {
- perror("opening pat demux failed");
- close(audiofd);
- close(dmxfda);
- close(dmxfdv);
- close(fefd);
- return FALSE;
- }
-
- if ((pmtfd = open(dmxdev, O_RDWR)) < 0) {
- perror("opening pmt demux failed");
- close(patfd);
- close(audiofd);
- close(dmxfda);
- close(dmxfdv);
- close(fefd);
- return FALSE;
- }
- }
- }
-
- hiband = 0;
- if (lnb_type.switch_val && lnb_type.high_val &&
- freq >= lnb_type.switch_val)
- hiband = 1;
-
- if (hiband)
- ifreq = freq - lnb_type.high_val;
- else {
- if (freq < lnb_type.low_val)
- ifreq = lnb_type.low_val - freq;
- else
- ifreq = freq - lnb_type.low_val;
- }
- result = FALSE;
-
- if (diseqc(fefd, sat_no, pol, hiband))
- if (do_tune(fefd, ifreq, sr))
- if (set_pesfilter(dmxfdv, vpid, DMX_PES_VIDEO, dvr))
- if (audiofd >= 0)
- (void)ioctl(audiofd, AUDIO_SET_BYPASS_MODE, bypass);
- if (set_pesfilter(dmxfda, apid, DMX_PES_AUDIO, dvr)) {
- if (rec_psi) {
- pmtpid = get_pmt_pid(dmxdev, sid);
- if (pmtpid < 0) {
- result = FALSE;
- }
- if (pmtpid == 0) {
- fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid);
- result = FALSE;
- }
- if (set_pesfilter(patfd, 0, DMX_PES_OTHER, dvr))
- if (set_pesfilter(pmtfd, pmtpid, DMX_PES_OTHER, dvr))
- result = TRUE;
- } else {
- result = TRUE;
- }
- }
-
- check_frontend (fefd, dvr, human_readable);
-
- if (!interactive) {
- close(patfd);
- close(pmtfd);
- if (audiofd >= 0)
- close(audiofd);
- close(dmxfda);
- close(dmxfdv);
- close(fefd);
- }
-
- return result;
+ char fedev[128], dmxdev[128], auddev[128];
+ static int fefd, dmxfda, dmxfdv, audiofd = -1, patfd, pmtfd;
+ int pmtpid;
+ uint32_t ifreq;
+ int hiband, result;
+ static struct dvb_frontend_info fe_info;
+
+ if (!fefd) {
+ snprintf(fedev, sizeof(fedev), FRONTENDDEVICE, adapter, frontend);
+ snprintf(dmxdev, sizeof(dmxdev), DEMUXDEVICE, adapter, demux);
+ snprintf(auddev, sizeof(auddev), AUDIODEVICE, adapter, demux);
+ printf("using '%s' and '%s'\n", fedev, dmxdev);
+
+ if ((fefd = open(fedev, O_RDWR | O_NONBLOCK)) < 0) {
+ perror("opening frontend failed");
+ return FALSE;
+ }
+
+ result = ioctl(fefd, FE_GET_INFO, &fe_info);
+ if (result < 0) {
+ perror("ioctl FE_GET_INFO failed");
+ close(fefd);
+ return FALSE;
+ }
+
+ if (fe_info.type != FE_QPSK) {
+ fprintf(stderr, "frontend device is not a QPSK (DVB-S) device!\n");
+ close(fefd);
+ return FALSE;
+ }
+
+ if ((dmxfdv = open(dmxdev, O_RDWR)) < 0) {
+ perror("opening video demux failed");
+ close(fefd);
+ return FALSE;
+ }
+
+ if ((dmxfda = open(dmxdev, O_RDWR)) < 0) {
+ perror("opening audio demux failed");
+ close(fefd);
+ return FALSE;
+ }
+
+ if (dvr == 0) /* DMX_OUT_DECODER */
+ audiofd = open(auddev, O_RDWR);
+
+ if (rec_psi) {
+ if ((patfd = open(dmxdev, O_RDWR)) < 0) {
+ perror("opening pat demux failed");
+ close(audiofd);
+ close(dmxfda);
+ close(dmxfdv);
+ close(fefd);
+ return FALSE;
+ }
+ if ((pmtfd = open(dmxdev, O_RDWR)) < 0) {
+ perror("opening pmt demux failed");
+ close(patfd);
+ close(audiofd);
+ close(dmxfda);
+ close(dmxfdv);
+ close(fefd);
+ return FALSE;
+ }
+ }
+ }
+
+ hiband = 0;
+ if (lnb_type.switch_val && lnb_type.high_val && freq >= lnb_type.switch_val)
+ hiband = 1;
+
+ if (hiband)
+ ifreq = freq - lnb_type.high_val;
+ else {
+ if (freq < lnb_type.low_val)
+ ifreq = lnb_type.low_val - freq;
+ else
+ ifreq = freq - lnb_type.low_val;
+ }
+ result = FALSE;
+
+ if (diseqc(fefd, sat_no, pol, hiband))
+ if (do_tune(fefd, ifreq, sr))
+ if (set_pesfilter(dmxfdv, vpid, DMX_PES_VIDEO, dvr))
+ if (audiofd >= 0)
+ (void)ioctl(audiofd, AUDIO_SET_BYPASS_MODE, bypass);
+
+ if (set_pesfilter(dmxfda, apid, DMX_PES_AUDIO, dvr)) {
+ if (rec_psi) {
+ pmtpid = get_pmt_pid(dmxdev, sid);
+ if (pmtpid < 0) {
+ result = FALSE;
+ }
+ if (pmtpid == 0) {
+ fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid);
+ result = FALSE;
+ }
+ if (set_pesfilter(patfd, 0, DMX_PES_OTHER, dvr))
+ if (set_pesfilter(pmtfd, pmtpid, DMX_PES_OTHER, dvr))
+ result = TRUE;
+ } else {
+ result = TRUE;
+ }
+ }
+
+ check_frontend (fefd, dvr, human_readable);
+ if (!interactive) {
+ close(patfd);
+ close(pmtfd);
+
+ if (audiofd >= 0)
+ close(audiofd);
+
+ close(dmxfda);
+ close(dmxfdv);
+ close(fefd);
+ }
+
+ return result;
}
@@ -346,165 +345,174 @@ static int read_channels(const char *filename, int list_channels,
unsigned int demux, int dvr, int rec_psi,
int bypass, int human_readable)
{
- FILE *cfp;
- char buf[4096];
- char inp[256];
- char *field, *tmp, *p;
- unsigned int line;
- unsigned int freq, pol, sat_no, sr, vpid, apid, sid;
- int ret;
+ FILE *cfp;
+ char buf[4096];
+ char inp[256];
+ char *field, *tmp, *p;
+ unsigned int line;
+ unsigned int freq, pol, sat_no, sr, vpid, apid, sid;
+ int ret;
again:
- line = 0;
- if (!(cfp = fopen(filename, "r"))) {
- fprintf(stderr, "error opening channel list '%s': %d %m\n",
- filename, errno);
- return FALSE;
- }
+ line = 0;
+ if (!(cfp = fopen(filename, "r"))) {
+ fprintf(stderr, "error opening channel list '%s': %d %m\n",
+ filename, errno);
+ return FALSE;
+ }
+
+ if (interactive) {
+ fprintf(stderr, "\n>>> ");
+
+ if (!fgets(inp, sizeof(inp), stdin)) {
+ printf("\n");
+ return -1;
+ }
+ if (inp[0] == '-' && inp[1] == 'n') {
+ chan_no = strtoul(inp+2, NULL, 0);
+ chan_name = NULL;
+ if (!chan_no) {
+ fprintf(stderr, "bad channel number\n");
+ goto again;
+ }
+ } else {
+ p = strchr(inp, '\n');
+ if (p)
+ *p = '\0';
+ chan_name = inp;
+ chan_no = 0;
+ }
+ }
+
+ while (!feof(cfp)) {
+ if (fgets(buf, sizeof(buf), cfp)) {
+ line++;
+
+ if (chan_no && chan_no != line)
+ continue;
+
+ tmp = buf;
+ field = strsep(&tmp, ":");
+
+ if (!field)
+ goto syntax_err;
+
+ if (list_channels) {
+ printf("%03u %s\n", line, field);
+ continue;
+ }
+
+ if (chan_name && strcasecmp(chan_name, field) != 0)
+ continue;
+
+ printf("zapping to %d '%s':\n", line, field);
+
+ if (!(field = strsep(&tmp, ":")))
+ goto syntax_err;
+
+ freq = strtoul(field, NULL, 0);
+
+ if (!(field = strsep(&tmp, ":")))
+ goto syntax_err;
+
+ pol = (field[0] == 'h' ? 0 : 1);
+
+ if (!(field = strsep(&tmp, ":")))
+ goto syntax_err;
+
+ sat_no = strtoul(field, NULL, 0);
- if (interactive) {
- fprintf(stderr, "\n>>> ");
- if (!fgets(inp, sizeof(inp), stdin)) {
- printf("\n");
- return -1;
- }
- if (inp[0] == '-' && inp[1] == 'n') {
- chan_no = strtoul(inp+2, NULL, 0);
- chan_name = NULL;
- if (!chan_no) {
- fprintf(stderr, "bad channel number\n");
- goto again;
- }
- } else {
- p = strchr(inp, '\n');
- if (p)
- *p = '\0';
- chan_name = inp;
- chan_no = 0;
- }
- }
-
- while (!feof(cfp)) {
- if (fgets(buf, sizeof(buf), cfp)) {
- line++;
-
- if (chan_no && chan_no != line)
- continue;
-
- tmp = buf;
- field = strsep(&tmp, ":");
-
- if (!field)
- goto syntax_err;
-
- if (list_channels) {
- printf("%03u %s\n", line, field);
- continue;
- }
-
- if (chan_name && strcasecmp(chan_name, field) != 0)
- continue;
-
- printf("zapping to %d '%s':\n", line, field);
-
- if (!(field = strsep(&tmp, ":")))
- goto syntax_err;
-
- freq = strtoul(field, NULL, 0);
-
- if (!(field = strsep(&tmp, ":")))
- goto syntax_err;
-
- pol = (field[0] == 'h' ? 0 : 1);
-
- if (!(field = strsep(&tmp, ":")))
- goto syntax_err;
-
- sat_no = strtoul(field, NULL, 0);
-
- if (!(field = strsep(&tmp, ":")))
- goto syntax_err;
-
- sr = strtoul(field, NULL, 0) * 1000;
-
- if (!(field = strsep(&tmp, ":")))
- goto syntax_err;
-
- vpid = strtoul(field, NULL, 0);
- if (!vpid)
- vpid = 0x1fff;
-
- if (!(field = strsep(&tmp, ":")))
- goto syntax_err;
-
- p = strchr(field, ';');
-
- if (p) {
- *p = '\0';
- p++;
- if (bypass) {
- if (!p || !*p)
- goto syntax_err;
- field = p;
- }
- }
-
- apid = strtoul(field, NULL, 0);
- if (!apid)
- apid = 0x1fff;
-
- if (!(field = strsep(&tmp, ":")))
- goto syntax_err;
-
- sid = strtoul(field, NULL, 0);
-
- printf("sat %u, frequency = %u MHz %c, symbolrate %u, "
- "vpid = 0x%04x, apid = 0x%04x sid = 0x%04x\n",
- sat_no, freq, pol ? 'V' : 'H', sr, vpid, apid, sid);
+ if (!(field = strsep(&tmp, ":")))
+ goto syntax_err;
- fclose(cfp);
-
- ret = zap_to(adapter, frontend, demux, sat_no, freq * 1000,
- pol, sr, vpid, apid, sid, dvr, rec_psi, bypass, human_readable);
- if (interactive)
- goto again;
+ sr = strtoul(field, NULL, 0) * 1000;
- if (ret)
- return TRUE;
+ if (!(field = strsep(&tmp, ":")))
+ goto syntax_err;
- return FALSE;
+ vpid = strtoul(field, NULL, 0);
+ if (!vpid)
+ vpid = 0x1fff;
- syntax_err:
- fprintf(stderr, "syntax error in line %u: '%s'\n", line, buf);
- } else if (ferror(cfp)) {
- fprintf(stderr, "error reading channel list '%s': %d %m\n",
- filename, errno);
- fclose(cfp);
- return FALSE;
- } else
- break;
- }
+ if (!(field = strsep(&tmp, ":")))
+ goto syntax_err;
- fclose(cfp);
+ p = strchr(field, ';');
- if (!list_channels) {
- fprintf(stderr, "channel not found\n");
- if (!interactive)
- return FALSE;
- }
- if (interactive)
- goto again;
+ if (p) {
+ *p = '\0';
+ p++;
+ if (bypass) {
+ if (!p || !*p)
+ goto syntax_err;
+ field = p;
+ }
+ }
+ apid = strtoul(field, NULL, 0);
+ if (!apid)
+ apid = 0x1fff;
+
+ if (!(field = strsep(&tmp, ":")))
+ goto syntax_err;
+
+ sid = strtoul(field, NULL, 0);
+
+ printf("sat %u, frequency = %u MHz %c, symbolrate %u, "
+ "vpid = 0x%04x, apid = 0x%04x sid = 0x%04x\n",
+ sat_no, freq, pol ? 'V' : 'H', sr, vpid, apid, sid);
+
+ fclose(cfp);
+
+ ret = zap_to(adapter,
+ frontend,
+ demux,
+ sat_no,
+ freq * 1000,
+ pol,
+ sr,
+ vpid,
+ apid,
+ sid,
+ dvr,
+ rec_psi,
+ bypass,
+ human_readable);
+
+ if (interactive)
+ goto again;
+ if (ret)
+ return TRUE;
+
+ return FALSE;
+syntax_err:
+ fprintf(stderr, "syntax error in line %u: '%s'\n", line, buf);
+ } else if (ferror(cfp)) {
+ fprintf(stderr, "error reading channel list '%s': %d %m\n", filename, errno);
+ fclose(cfp);
+ return FALSE;
+ } else {
+ break;
+ }
+ }
+
+ fclose(cfp);
+ if (!list_channels) {
+ fprintf(stderr, "channel not found\n");
+ if (!interactive)
+ return FALSE;
+ }
+ if (interactive)
+ goto again;
- return TRUE;
+ return TRUE;
}
-void
-bad_usage(char *pname, int prlnb)
+void bad_usage(char *pname, int prlnb)
{
-int i;
-struct lnb_types_st *lnbp;
-char **cp;
+ int i;
+ struct lnb_types_st *lnbp;
+ char **cp;
if (!prlnb) {
fprintf (stderr, usage_str, pname);
@@ -523,107 +531,125 @@ char **cp;
int main(int argc, char *argv[])
{
- const char *home;
- char chanfile[2 * PATH_MAX];
- int list_channels = 0;
- unsigned int chan_no = 0;
- const char *chan_name = NULL;
- unsigned int adapter = 0, frontend = 0, demux = 0, dvr = 0, rec_psi = 0;
- int bypass = 0;
- int opt, copt = 0;
- int human_readable = 0;
-
- lnb_type = *lnb_enum(0);
- while ((opt = getopt(argc, argv, "Hhqrpn:a:f:d:c:l:xib")) != -1) {
- switch (opt)
- {
- case '?':
- case 'h':
- default:
- bad_usage(argv[0], 0);
- case 'b':
- bypass = 1;
- break;
- case 'q':
- list_channels = 1;
- break;
- case 'r':
- dvr = 1;
- break;
- case 'n':
- chan_no = strtoul(optarg, NULL, 0);
- break;
- case 'a':
- adapter = strtoul(optarg, NULL, 0);
- break;
- case 'f':
- frontend = strtoul(optarg, NULL, 0);
- break;
- case 'p':
- rec_psi = 1;
- break;
- case 'd':
- demux = strtoul(optarg, NULL, 0);
- break;
- case 'c':
- copt = 1;
- strncpy(chanfile, optarg, sizeof(chanfile));
- break;
- case 'l':
- if (lnb_decode(optarg, &lnb_type) < 0) {
- bad_usage(argv[0], 1);
+ const char *home;
+ char chanfile[2 * PATH_MAX];
+ int list_channels = 0;
+ unsigned int chan_no = 0;
+ const char *chan_name = NULL;
+ unsigned int adapter = 0, frontend = 0, demux = 0, dvr = 0, rec_psi = 0;
+ int bypass = 0;
+ int opt, copt = 0;
+ int human_readable = 0;
+
+ lnb_type = *lnb_enum(0);
+
+ while ((opt = getopt(argc, argv, "Hhqrpn:a:f:d:c:l:xib")) != -1) {
+ switch (opt) {
+ case '?':
+ case 'h':
+ default:
+ bad_usage(argv[0], 0);
+ case 'b':
+ bypass = 1;
+ break;
+ case 'q':
+ list_channels = 1;
+ break;
+ case 'r':
+ dvr = 1;
+ break;
+ case 'n':
+ chan_no = strtoul(optarg, NULL, 0);
+ break;
+ case 'a':
+ adapter = strtoul(optarg, NULL, 0);
+ break;
+ case 'f':
+ frontend = strtoul(optarg, NULL, 0);
+ break;
+ case 'p':
+ rec_psi = 1;
+ break;
+ case 'd':
+ demux = strtoul(optarg, NULL, 0);
+ break;
+ case 'c':
+ copt = 1;
+ strncpy(chanfile, optarg, sizeof(chanfile));
+ break;
+ case 'l':
+ if (lnb_decode(optarg, &lnb_type) < 0) {
+ bad_usage(argv[0], 1);
+ return -1;
+ }
+ break;
+ case 'x':
+ exit_after_tuning = 1;
+ break;
+ case 'H':
+ human_readable = 1;
+ break;
+ case 'i':
+ interactive = 1;
+ exit_after_tuning = 1;
+ }
+ }
+ lnb_type.low_val *= 1000; /* convert to kiloherz */
+ lnb_type.high_val *= 1000; /* convert to kiloherz */
+ lnb_type.switch_val *= 1000; /* convert to kiloherz */
+
+ if (optind < argc)
+ chan_name = argv[optind];
+
+ if (chan_name && chan_no) {
+ bad_usage(argv[0], 0);
+ return -1;
+ }
+ if (list_channels && (chan_name || chan_no)) {
+ bad_usage(argv[0], 0);
+ return -1;
+ }
+ if (!list_channels && !chan_name && !chan_no && !interactive) {
+ bad_usage(argv[0], 0);
return -1;
- }
- break;
- case 'x':
- exit_after_tuning = 1;
- break;
- case 'H':
- human_readable = 1;
- break;
- case 'i':
- interactive = 1;
- exit_after_tuning = 1;
- }
- }
- lnb_type.low_val *= 1000; /* convert to kiloherz */
- lnb_type.high_val *= 1000; /* convert to kiloherz */
- lnb_type.switch_val *= 1000; /* convert to kiloherz */
- if (optind < argc)
- chan_name = argv[optind];
- if (chan_name && chan_no) {
- bad_usage(argv[0], 0);
- return -1;
- }
- if (list_channels && (chan_name || chan_no)) {
- bad_usage(argv[0], 0);
- return -1;
- }
- if (!list_channels && !chan_name && !chan_no && !interactive) {
- bad_usage(argv[0], 0);
- return -1;
- }
-
- if (!copt) {
- if (!(home = getenv("HOME"))) {
- fprintf(stderr, "error: $HOME not set\n");
- return TRUE;
- }
- snprintf(chanfile, sizeof(chanfile),
- "%s/.szap/%i/%s", home, adapter, CHANNEL_FILE);
- if (access(chanfile, R_OK))
- snprintf(chanfile, sizeof(chanfile),
- "%s/.szap/%s", home, CHANNEL_FILE);
- }
-
- printf("reading channels from file '%s'\n", chanfile);
-
- if (rec_psi)
- dvr=1;
-
- if (!read_channels(chanfile, list_channels, chan_no, chan_name,
- adapter, frontend, demux, dvr, rec_psi, bypass, human_readable))
- return TRUE;
-
- return FALSE;
+ }
+
+ if (!copt) {
+ if (!(home = getenv("HOME"))) {
+ fprintf(stderr, "error: $HOME not set\n");
+ return TRUE;
+ }
+ snprintf(chanfile,
+ sizeof(chanfile),
+ "%s/.szap/%i/%s",
+ home,
+ adapter,
+ CHANNEL_FILE);
+
+ if (access(chanfile, R_OK))
+ snprintf(chanfile,
+ sizeof(chanfile),
+ "%s/.szap/%s",
+ home,
+ CHANNEL_FILE);
+ }
+ printf("reading channels from file '%s'\n", chanfile);
+
+ if (rec_psi)
+ dvr=1;
+
+ if (!read_channels(chanfile,
+ list_channels,
+ chan_no,
+ chan_name,
+ adapter,
+ frontend,
+ demux,
+ dvr,
+ rec_psi,
+ bypass,
+ human_readable))
+ return TRUE;
+
+ return FALSE;
}
diff --git a/util/szap/tzap.c b/util/szap/tzap.c
index b24bc2c..ce63832 100644
--- a/util/szap/tzap.c
+++ b/util/szap/tzap.c
@@ -47,18 +47,18 @@ static int exit_after_tuning;
#define CHANNEL_FILE "channels.conf"
#define ERROR(x...) \
- do { \
- fprintf(stderr, "ERROR: "); \
- fprintf(stderr, x); \
- fprintf (stderr, "\n"); \
- } while (0)
+ do { \
+ fprintf(stderr, "ERROR: "); \
+ fprintf(stderr, x); \
+ fprintf (stderr, "\n"); \
+ } while (0)
#define PERROR(x...) \
- do { \
- fprintf(stderr, "ERROR: "); \
- fprintf(stderr, x); \
- fprintf (stderr, " (%s)\n", strerror(errno)); \
- } while (0)
+ do { \
+ fprintf(stderr, "ERROR: "); \
+ fprintf(stderr, x); \
+ fprintf (stderr, " (%s)\n", strerror(errno)); \
+ } while (0)
typedef struct {
@@ -125,9 +125,7 @@ static const Param transmissionmode_list [] = {
#define LIST_SIZE(x) sizeof(x)/sizeof(Param)
-
-static
-int parse_param (int fd, const Param * plist, int list_size, int *param)
+static int parse_param (int fd, const Param * plist, int list_size, int *param)
{
char c;
int character = 0;
@@ -157,8 +155,7 @@ int parse_param (int fd, const Param * plist, int list_size, int *param)
}
-static
-int parse_int(int fd, int *val)
+static int parse_int(int fd, int *val)
{
char number[11]; /* 2^32 needs 10 digits... */
int character = 0;
@@ -190,8 +187,7 @@ int parse_int(int fd, int *val)
}
-static
-int find_channel(int fd, const char *channel)
+static int find_channel(int fd, const char *channel)
{
int character = 0;
@@ -346,13 +342,11 @@ int parse(const char *fname, const char *channel,
if ((err = try_parse_int(fd, apid, "Audio PID")))
return -13;
-
+
if ((err = try_parse_int(fd, sid, "Service ID")))
return -14;
-
-
- close(fd);
+ close(fd);
return 0;
}
@@ -372,7 +366,7 @@ int setup_frontend (int fe_fd, struct dvb_frontend_parameters *frontend)
return -1;
}
- if (silent<2)
+ if (silent < 2)
fprintf (stderr,"tuning to %i Hz\n", frontend->frequency);
if (ioctl(fe_fd, FE_SET_FRONTEND, frontend) < 0) {
@@ -383,25 +377,20 @@ int setup_frontend (int fe_fd, struct dvb_frontend_parameters *frontend)
return 0;
}
-static void
-do_timeout(int x)
+static void do_timeout(int x)
{
(void)x;
- if (timeout_flag==0)
- {
- timeout_flag=1;
+ if (timeout_flag == 0) {
+ timeout_flag = 1;
alarm(2);
signal(SIGALRM, do_timeout);
- }
- else
- {
+ } else {
/* something has gone wrong ... exit */
exit(1);
}
}
-static void
-print_frontend_stats (int fe_fd, int human_readable)
+static void print_frontend_stats(int fe_fd, int human_readable)
{
fe_status_t status;
uint16_t snr, _signal;
@@ -446,14 +435,13 @@ int check_frontend (int fe_fd, int human_readable)
}
#define BUFLEN (188*256)
-static
-void copy_to_file(int in_fd, int out_fd)
+static void copy_to_file(int in_fd, int out_fd)
{
char buf[BUFLEN];
int r;
long long int rc = 0LL;
- while(timeout_flag==0)
- {
+
+ while (timeout_flag==0) {
r=read(in_fd,buf,BUFLEN);
if (r < 0) {
if (errno == EOVERFLOW) {
@@ -469,36 +457,36 @@ void copy_to_file(int in_fd, int out_fd)
}
rc+=r;
}
- if (silent<2)
- {
+
+ if (silent<2) {
fprintf(stderr, "copied %lld bytes (%lld Kbytes/sec)\n",rc,rc/(1024*timeout));
}
}
static char *usage =
- "usage:\n"
- " tzap [options] <channel_name>\n"
- " zap to channel channel_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"
- " -r : set up /dev/dvb/adapterX/dvr0 for TS recording\n"
- " -p : add pat and pmt to TS recording (implies -r)\n"
- " -s : only print summary\n"
- " -S : run silently (no output)\n"
- " -H : human readable output\n"
- " -F : set up frontend only, don't touch demux\n"
- " -t number : timeout (seconds)\n"
- " -o file : output filename (use -o - for stdout)\n"
- " -h -? : display this help and exit\n";
+ "usage:\n"
+ " tzap [options] <channel_name>\n"
+ " zap to channel channel_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"
+ " -r : set up /dev/dvb/adapterX/dvr0 for TS recording\n"
+ " -p : add pat and pmt to TS recording (implies -r)\n"
+ " -s : only print summary\n"
+ " -S : run silently (no output)\n"
+ " -H : human readable output\n"
+ " -F : set up frontend only, don't touch demux\n"
+ " -t number : timeout (seconds)\n"
+ " -o file : output filename (use -o - for stdout)\n"
+ " -h -? : display this help and exit\n";
int main(int argc, char **argv)
{
struct dvb_frontend_parameters frontend_param;
- char *homedir = getenv ("HOME");
+ char *homedir = getenv("HOME");
char *confname = NULL;
char *channel = NULL;
int adapter = 0, frontend = 0, demux = 0, dvr = 0;
@@ -569,32 +557,37 @@ int main(int argc, char **argv)
return -1;
}
- snprintf (FRONTEND_DEV, sizeof(FRONTEND_DEV),
- "/dev/dvb/adapter%i/frontend%i", adapter, frontend);
+ 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(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);
+ snprintf(DVR_DEV,
+ sizeof(DVR_DEV),
+ "/dev/dvb/adapter%i/dvr%i",
+ adapter,
+ demux);
- if (silent<2)
+ if (silent < 2)
fprintf (stderr,"using '%s' and '%s'\n", FRONTEND_DEV, DEMUX_DEV);
- if (!confname)
- {
+ 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);
+ 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);
+ 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))
@@ -612,71 +605,62 @@ int main(int argc, char **argv)
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;
- }
+ 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 ((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 ((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 ((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);
+ fprintf(stderr,"video pid 0x%04x, audio pid 0x%04x\n", vpid, apid);
- if (set_pesfilter (video_fd, vpid, DMX_PES_VIDEO, dvr) < 0)
+ 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;
- }
+ PERROR("failed opening '%s'", DEMUX_DEV);
+ return -1;
+ }
- if (set_pesfilter (audio_fd, apid, DMX_PES_AUDIO, dvr) < 0)
+ if (set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, dvr) < 0)
return -1;
signal(SIGALRM,do_timeout);
- if (timeout>0)
+ 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)
- {
+ 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
- {
+ } else {
file_fd=1;
}
- }
- else
- {
+ } else {
PERROR("Record mode but no filename!");
return -1;
}
@@ -686,23 +670,21 @@ int main(int argc, char **argv)
return -1;
}
if (silent<2)
- print_frontend_stats (frontend_fd, human_readable);
+ 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 {
+ print_frontend_stats(frontend_fd, human_readable);
+ } else {
just_the_frontend_dude:
- check_frontend (frontend_fd, human_readable);
+ check_frontend(frontend_fd, human_readable);
}
- close (pat_fd);
- close (pmt_fd);
- close (audio_fd);
- close (video_fd);
- close (frontend_fd);
-
+ close(pat_fd);
+ close(pmt_fd);
+ close(audio_fd);
+ close(video_fd);
+ close(frontend_fd);
return 0;
}
diff --git a/util/szap/util.c b/util/szap/util.c
index 301d666..99d303a 100644
--- a/util/szap/util.c
+++ b/util/szap/util.c
@@ -35,92 +35,89 @@
int set_pesfilter(int dmxfd, int pid, int pes_type, int dvr)
{
- struct dmx_pes_filter_params pesfilter;
+ struct dmx_pes_filter_params pesfilter;
- /* ignore this pid to allow radio services */
- if (pid < 0 ||
- pid >= 0x1fff ||
- (pid == 0 && pes_type != DMX_PES_OTHER))
- return 0;
+ /* ignore this pid to allow radio services */
+ if (pid < 0 || pid >= 0x1fff || (pid == 0 && pes_type != DMX_PES_OTHER))
+ return 0;
+
+ if (dvr) {
+ int buffersize = 64 * 1024;
+ if (ioctl(dmxfd, DMX_SET_BUFFER_SIZE, buffersize) == -1)
+ perror("DMX_SET_BUFFER_SIZE failed");
+ }
- if (dvr) {
- int buffersize = 64 * 1024;
- if (ioctl(dmxfd, DMX_SET_BUFFER_SIZE, buffersize) == -1)
- perror("DMX_SET_BUFFER_SIZE failed");
- }
-
- pesfilter.pid = pid;
- pesfilter.input = DMX_IN_FRONTEND;
- pesfilter.output = dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER;
- pesfilter.pes_type = pes_type;
- pesfilter.flags = DMX_IMMEDIATE_START;
-
- if (ioctl(dmxfd, DMX_SET_PES_FILTER, &pesfilter) == -1) {
- fprintf(stderr, "DMX_SET_PES_FILTER failed "
- "(PID = 0x%04x): %d %m\n", pid, errno);
- return -1;
- }
-
- return 0;
+ pesfilter.pid = pid;
+ pesfilter.input = DMX_IN_FRONTEND;
+ pesfilter.output = dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER;
+ pesfilter.pes_type = pes_type;
+ pesfilter.flags = DMX_IMMEDIATE_START;
+
+ if (ioctl(dmxfd, DMX_SET_PES_FILTER, &pesfilter) == -1) {
+ fprintf(stderr, "DMX_SET_PES_FILTER failed "
+ "(PID = 0x%04x): %d %m\n", pid, errno);
+ return -1;
+ }
+ return 0;
}
int get_pmt_pid(char *dmxdev, int sid)
{
- int patfd, count;
- int pmt_pid = 0;
- int patread = 0;
- int section_length;
- unsigned char buft[4096];
- unsigned char *buf = buft;
- struct dmx_sct_filter_params f;
-
- memset(&f, 0, sizeof(f));
- f.pid = 0;
- f.filter.filter[0] = 0x00;
- f.filter.mask[0] = 0xff;
- f.timeout = 0;
- f.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;
-
- if ((patfd = open(dmxdev, O_RDWR)) < 0) {
- perror("openening pat demux failed");
- return -1;
- }
-
- if (ioctl(patfd, DMX_SET_FILTER, &f) == -1) {
- perror("ioctl DMX_SET_FILTER failed");
- close(patfd);
- return -1;
- }
-
- while (!patread){
- if (((count = read(patfd, buf, sizeof(buft))) < 0) && errno == EOVERFLOW)
- count = read(patfd, buf, sizeof(buft));
- if (count < 0) {
- perror("read_sections: read error");
- close(patfd);
- return -1;
+ int patfd, count;
+ int pmt_pid = 0;
+ int patread = 0;
+ int section_length;
+ unsigned char buft[4096];
+ unsigned char *buf = buft;
+ struct dmx_sct_filter_params f;
+
+ memset(&f, 0, sizeof(f));
+ f.pid = 0;
+ f.filter.filter[0] = 0x00;
+ f.filter.mask[0] = 0xff;
+ f.timeout = 0;
+ f.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;
+
+ if ((patfd = open(dmxdev, O_RDWR)) < 0) {
+ perror("openening pat demux failed");
+ return -1;
}
-
- section_length = ((buf[1] & 0x0f) << 8) | buf[2];
- if (count != section_length + 3)
- continue;
-
- buf += 8;
- section_length -= 8;
-
- patread = 1; /* assumes one section contains the whole pat */
- while (section_length > 0) {
- int service_id = (buf[0] << 8) | buf[1];
- if (service_id == sid) {
- pmt_pid = ((buf[2] & 0x1f) << 8) | buf[3];
- section_length = 0;
- }
- buf += 4;
- section_length -= 4;
+
+ if (ioctl(patfd, DMX_SET_FILTER, &f) == -1) {
+ perror("ioctl DMX_SET_FILTER failed");
+ close(patfd);
+ return -1;
}
- }
- close(patfd);
- return pmt_pid;
+ while (!patread) {
+ if (((count = read(patfd, buf, sizeof(buft))) < 0) && errno == EOVERFLOW)
+ count = read(patfd, buf, sizeof(buft));
+
+ if (count < 0) {
+ perror("read_sections: read error");
+ close(patfd);
+ return -1;
+ }
+ section_length = ((buf[1] & 0x0f) << 8) | buf[2];
+ if (count != section_length + 3)
+ continue;
+
+ buf += 8;
+ section_length -= 8;
+
+ patread = 1; /* assumes one section contains the whole pat */
+ while (section_length > 0) {
+ int service_id = (buf[0] << 8) | buf[1];
+
+ if (service_id == sid) {
+ pmt_pid = ((buf[2] & 0x1f) << 8) | buf[3];
+ section_length = 0;
+ }
+ buf += 4;
+ section_length -= 4;
+ }
+ }
+ close(patfd);
+ return pmt_pid;
}