diff options
Diffstat (limited to 'kaffeine/src/input/dvb/lib/libdvbapi')
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/Makefile.am | 5 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.c | 50 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.h | 55 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.c | 12 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.h | 6 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.c | 580 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.h | 233 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.c | 11 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.h | 10 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.c | 46 | ||||
-rw-r--r-- | kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.h | 46 |
11 files changed, 555 insertions, 499 deletions
diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/Makefile.am b/kaffeine/src/input/dvb/lib/libdvbapi/Makefile.am index 59f288b..9963cd4 100644 --- a/kaffeine/src/input/dvb/lib/libdvbapi/Makefile.am +++ b/kaffeine/src/input/dvb/lib/libdvbapi/Makefile.am @@ -2,10 +2,11 @@ noinst_LTLIBRARIES = libdvbapi.la INCLUDES = -I$(top_srcdir)/kaffeine/src/input/dvb/lib -libdvbapi_la_SOURCES = diseqc.c \ +libdvbapi_la_SOURCES = dvbaudio.c \ dvbca.c \ dvbdemux.c \ dvbfe.c \ - dvbnet.c + dvbnet.c \ + dvbvideo.c CFLAGS = -g -O2 -Wall -Wshadow -Wpointer-arith -Wstrict-prototypes -fPIC diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.c b/kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.c new file mode 100644 index 0000000..72b4d70 --- /dev/null +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.c @@ -0,0 +1,50 @@ +/* + * libdvbnet - a DVB network support library + * + * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) + * + * This library 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 library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <sys/param.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <linux/dvb/audio.h> +#include <errno.h> +#include "dvbaudio.h" + +int dvbaudio_open(int adapter, int audiodeviceid) +{ + char filename[PATH_MAX+1]; + int fd; + + sprintf(filename, "/dev/dvb/adapter%i/audio%i", adapter, audiodeviceid); + if ((fd = open(filename, O_RDWR)) < 0) { + // if that failed, try a flat /dev structure + sprintf(filename, "/dev/dvb%i.audio%i", adapter, audiodeviceid); + fd = open(filename, O_RDWR); + } + + return fd; +} + +int dvbaudio_set_bypass(int fd, int bypass) +{ + return ioctl(fd, AUDIO_SET_BYPASS_MODE, bypass); +} diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.h b/kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.h new file mode 100644 index 0000000..36f6a55 --- /dev/null +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbaudio.h @@ -0,0 +1,55 @@ +/* + * libdvbnet - a DVB network support library + * + * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) + * + * This library 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 library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef LIBDVBAUDIO_H +#define LIBDVBAUDIO_H 1 + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include <stdint.h> + +/** + * Open a DVB audio device. + * + * @param adapter DVB adapter ID. + * @param audiodeviceid Id of audio device of that adapter to open. + * @return A unix file descriptor on success, or -1 on failure. + */ +extern int dvbaudio_open(int adapter, int audiodeviceid); + +/** + * Control audio bypass - i.e. output decoded audio, or the raw bitstream (e.g. AC3). + * + * @param fd Audio device opened with dvbaudio_open(). + * @param bypass 1=> enable bypass, 0=> disable. + * @return 0 on success, nonzero on failure. + */ +extern int dvbaudio_set_bypass(int fd, int bypass); + +// FIXME: this is a stub library + +#ifdef __cplusplus +} +#endif + +#endif // LIBDVBAUDIO_H diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.c b/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.c index aebad34..a882af6 100644 --- a/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.c +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.c @@ -128,6 +128,12 @@ int dvbdemux_set_pes_filter(int fd, int pid, filter.output = DMX_OUT_TS_TAP; break; +#ifdef DMX_OUT_TSDEMUX_TAP + case DVBDEMUX_OUTPUT_TS_DEMUX: + filter.output = DMX_OUT_TSDEMUX_TAP; + break; +#endif + default: return -EINVAL; } @@ -201,6 +207,12 @@ int dvbdemux_set_pid_filter(int fd, int pid, filter.output = DMX_OUT_TS_TAP; break; +#ifdef DMX_OUT_TSDEMUX_TAP + case DVBDEMUX_OUTPUT_TS_DEMUX: + filter.output = DMX_OUT_TSDEMUX_TAP; + break; +#endif + default: return -EINVAL; } diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.h b/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.h index 3fe4a4b..808ee80 100644 --- a/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.h +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbdemux.h @@ -55,6 +55,7 @@ extern "C" #define DVBDEMUX_OUTPUT_DECODER 0 #define DVBDEMUX_OUTPUT_DEMUX 1 #define DVBDEMUX_OUTPUT_DVR 2 +#define DVBDEMUX_OUTPUT_TS_DEMUX 3 /** * PES types. @@ -65,6 +66,7 @@ extern "C" #define DVBDEMUX_PESTYPE_SUBTITLE 3 #define DVBDEMUX_PESTYPE_PCR 4 + /** * Open a demux device. Can be called multiple times. These let you setup a * single filter per FD. It can can also be read() from if you use a section @@ -78,8 +80,8 @@ extern "C" extern int dvbdemux_open_demux(int adapter, int demuxdevice, int nonblocking); /** - * Open a DVR device. May be opened for writing once, or multiple times in readonly - * mode. It is used to either write() transport stream data to be demuxed + * Open a DVR device. May be opened for writing or reading once. + * It is used to either write() transport stream data to be demuxed * (if input == DVBDEMUX_INPUT_DVR), or to read() a stream of demuxed data * (if output == DVBDEMUX_OUTPUT_DVR). * diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.c b/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.c index fc6ecf4..98104c9 100644 --- a/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.c +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.c @@ -2,6 +2,7 @@ * libdvbfe - a DVB frontend library * * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) + * Copyright (C) 2005 Manu Abraham <abraham.manu@gmail.com> * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org) * * This library is free software; you can redistribute it and/or @@ -26,14 +27,16 @@ #include <sys/param.h> #include <sys/ioctl.h> #include <sys/time.h> +#include <sys/poll.h> #include <fcntl.h> #include <unistd.h> #include <ctype.h> #include <errno.h> #include <linux/dvb/frontend.h> +#include <libdvbmisc/dvbmisc.h> #include "dvbfe.h" -#define GET_INFO_MIN_DELAY_US 100000 +int verbose = 0; static int dvbfe_spectral_inversion_to_kapi[][2] = { @@ -128,6 +131,7 @@ static int dvbfe_dvbt_hierarchy_to_kapi[][2] = { -1, -1 } }; + static int lookupval(int val, int reverse, int table[][2]) { int i =0; @@ -149,19 +153,16 @@ static int lookupval(int val, int reverse, int table[][2]) } -struct dvbfe_handle_prv { +struct dvbfe_handle { int fd; - dvbfe_type_t type; + enum dvbfe_type type; char *name; - struct timeval nextinfotime; - struct dvbfe_info cachedinfo; - int cachedreturnval; }; -dvbfe_handle_t dvbfe_open(int adapter, int frontend, int readonly) +struct dvbfe_handle *dvbfe_open(int adapter, int frontend, int readonly) { char filename[PATH_MAX+1]; - struct dvbfe_handle_prv *fehandle; + struct dvbfe_handle *fehandle; int fd; struct dvb_frontend_info info; @@ -188,8 +189,8 @@ dvbfe_handle_t dvbfe_open(int adapter, int frontend, int readonly) } // setup structure - fehandle = (struct dvbfe_handle_prv*) malloc(sizeof(struct dvbfe_handle_prv)); - memset(fehandle, 0, sizeof(struct dvbfe_handle_prv)); + fehandle = (struct dvbfe_handle*) malloc(sizeof(struct dvbfe_handle)); + memset(fehandle, 0, sizeof(struct dvbfe_handle)); fehandle->fd = fd; switch(info.type) { case FE_QPSK: @@ -214,99 +215,118 @@ dvbfe_handle_t dvbfe_open(int adapter, int frontend, int readonly) return fehandle; } -void dvbfe_close(dvbfe_handle_t _fehandle) +void dvbfe_close(struct dvbfe_handle *fehandle) { - struct dvbfe_handle_prv *fehandle = (struct dvbfe_handle_prv*) _fehandle; - close(fehandle->fd); free(fehandle->name); free(fehandle); } -int dvbfe_get_info(dvbfe_handle_t _fehandle, dvbfe_info_mask_t querymask, struct dvbfe_info *result) +extern int dvbfe_get_info(struct dvbfe_handle *fehandle, + enum dvbfe_info_mask querymask, + struct dvbfe_info *result, + enum dvbfe_info_querytype querytype, + int timeout) { int returnval = 0; - fe_status_t status; - struct dvb_frontend_parameters kparams; - struct dvbfe_handle_prv *fehandle = (struct dvbfe_handle_prv*) _fehandle; - struct timeval curtime; - - // limit how often this is called to reduce bus traffic - gettimeofday(&curtime, NULL); - if ((curtime.tv_sec < fehandle->nextinfotime.tv_sec) || - ((curtime.tv_sec == fehandle->nextinfotime.tv_sec) && (curtime.tv_usec < fehandle->nextinfotime.tv_usec))) { - memcpy(result, &fehandle->cachedinfo, sizeof(struct dvbfe_info)); - return fehandle->cachedreturnval; - } + struct dvb_frontend_event kevent; + int ok = 0; - // retrieve the requested values - memset(result, 0, sizeof(result)); - result->type = fehandle->type; result->name = fehandle->name; - if (querymask & DVBFE_INFO_LOCKSTATUS) { - if (!ioctl(fehandle->fd, FE_READ_STATUS, &status)) { - returnval |= DVBFE_INFO_LOCKSTATUS; - if (status & FE_HAS_SIGNAL) - result->signal = 1; - - if (status & FE_HAS_CARRIER) - result->carrier = 1; + result->type = fehandle->type; - if (status & FE_HAS_VITERBI) - result->viterbi = 1; + switch(querytype) { + case DVBFE_INFO_QUERYTYPE_IMMEDIATE: + if (querymask & DVBFE_INFO_LOCKSTATUS) { + if (!ioctl(fehandle->fd, FE_READ_STATUS, &kevent.status)) { + returnval |= DVBFE_INFO_LOCKSTATUS; + } + } + if (querymask & DVBFE_INFO_FEPARAMS) { + if (!ioctl(fehandle->fd, FE_GET_FRONTEND, &kevent.parameters)) { + returnval |= DVBFE_INFO_FEPARAMS; + } + } + break; - if (status & FE_HAS_SYNC) - result->sync = 1; + case DVBFE_INFO_QUERYTYPE_LOCKCHANGE: + { + struct pollfd pollfd; + pollfd.fd = fehandle->fd; + pollfd.events = POLLIN | POLLERR; + + ok = 1; + if (poll(&pollfd, 1, timeout) < 0) + ok = 0; + if (pollfd.revents & POLLERR) + ok = 0; + if (!(pollfd.revents & POLLIN)) + ok = 0; + } - if (status & FE_HAS_LOCK) - result->lock = 1; + if (ok && + ((querymask & DVBFE_INFO_LOCKSTATUS) || + (querymask & DVBFE_INFO_FEPARAMS))) { + if (!ioctl(fehandle->fd, FE_GET_EVENT, &kevent)) { + if (querymask & DVBFE_INFO_LOCKSTATUS) + returnval |= DVBFE_INFO_LOCKSTATUS; + if (querymask & DVBFE_INFO_FEPARAMS) + returnval |= DVBFE_INFO_FEPARAMS; + } } + break; } - if (querymask & DVBFE_INFO_FEPARAMS) { - if (!ioctl(fehandle->fd, FE_GET_FRONTEND, &kparams)) { - returnval |= DVBFE_INFO_FEPARAMS; - result->feparams.frequency = kparams.frequency; - result->feparams.inversion = lookupval(kparams.inversion, 1, dvbfe_spectral_inversion_to_kapi); - switch(fehandle->type) { - case FE_QPSK: - result->feparams.u.dvbs.symbol_rate = kparams.u.qpsk.symbol_rate; - result->feparams.u.dvbs.fec_inner = - lookupval(kparams.u.qpsk.fec_inner, 1, dvbfe_code_rate_to_kapi); - break; - case FE_QAM: - result->feparams.u.dvbc.symbol_rate = kparams.u.qam.symbol_rate; - result->feparams.u.dvbc.fec_inner = - lookupval(kparams.u.qam.fec_inner, 1, dvbfe_code_rate_to_kapi); - result->feparams.u.dvbc.modulation = - lookupval(kparams.u.qam.modulation, 1, dvbfe_dvbc_mod_to_kapi); - break; + if (returnval & DVBFE_INFO_LOCKSTATUS) { + result->signal = kevent.status & FE_HAS_SIGNAL ? 1 : 0; + result->carrier = kevent.status & FE_HAS_CARRIER ? 1 : 0; + result->viterbi = kevent.status & FE_HAS_VITERBI ? 1 : 0; + result->sync = kevent.status & FE_HAS_SYNC ? 1 : 0; + result->lock = kevent.status & FE_HAS_LOCK ? 1 : 0; + } - case FE_OFDM: - result->feparams.u.dvbt.bandwidth = - lookupval(kparams.u.ofdm.bandwidth, 1, dvbfe_dvbt_bandwidth_to_kapi); - result->feparams.u.dvbt.code_rate_HP = - lookupval(kparams.u.ofdm.code_rate_HP, 1, dvbfe_code_rate_to_kapi); - result->feparams.u.dvbt.code_rate_LP = - lookupval(kparams.u.ofdm.code_rate_LP, 1, dvbfe_code_rate_to_kapi); - result->feparams.u.dvbt.constellation = - lookupval(kparams.u.ofdm.constellation, 1, dvbfe_dvbt_const_to_kapi); - result->feparams.u.dvbt.transmission_mode = - lookupval(kparams.u.ofdm.transmission_mode, 1, dvbfe_dvbt_transmit_mode_to_kapi); - result->feparams.u.dvbt.guard_interval = - lookupval(kparams.u.ofdm.guard_interval, 1, dvbfe_dvbt_guard_interval_to_kapi); - result->feparams.u.dvbt.hierarchy_information = - lookupval(kparams.u.ofdm.hierarchy_information, 1, dvbfe_dvbt_hierarchy_to_kapi); - break; + if (returnval & DVBFE_INFO_FEPARAMS) { + result->feparams.frequency = kevent.parameters.frequency; + result->feparams.inversion = lookupval(kevent.parameters.inversion, 1, dvbfe_spectral_inversion_to_kapi); + switch(fehandle->type) { + case FE_QPSK: + result->feparams.u.dvbs.symbol_rate = kevent.parameters.u.qpsk.symbol_rate; + result->feparams.u.dvbs.fec_inner = + lookupval(kevent.parameters.u.qpsk.fec_inner, 1, dvbfe_code_rate_to_kapi); + break; - case FE_ATSC: - result->feparams.u.atsc.modulation = - lookupval(kparams.u.vsb.modulation, 1, dvbfe_atsc_mod_to_kapi); - break; - } - } + case FE_QAM: + result->feparams.u.dvbc.symbol_rate = kevent.parameters.u.qam.symbol_rate; + result->feparams.u.dvbc.fec_inner = + lookupval(kevent.parameters.u.qam.fec_inner, 1, dvbfe_code_rate_to_kapi); + result->feparams.u.dvbc.modulation = + lookupval(kevent.parameters.u.qam.modulation, 1, dvbfe_dvbc_mod_to_kapi); + break; + + case FE_OFDM: + result->feparams.u.dvbt.bandwidth = + lookupval(kevent.parameters.u.ofdm.bandwidth, 1, dvbfe_dvbt_bandwidth_to_kapi); + result->feparams.u.dvbt.code_rate_HP = + lookupval(kevent.parameters.u.ofdm.code_rate_HP, 1, dvbfe_code_rate_to_kapi); + result->feparams.u.dvbt.code_rate_LP = + lookupval(kevent.parameters.u.ofdm.code_rate_LP, 1, dvbfe_code_rate_to_kapi); + result->feparams.u.dvbt.constellation = + lookupval(kevent.parameters.u.ofdm.constellation, 1, dvbfe_dvbt_const_to_kapi); + result->feparams.u.dvbt.transmission_mode = + lookupval(kevent.parameters.u.ofdm.transmission_mode, 1, dvbfe_dvbt_transmit_mode_to_kapi); + result->feparams.u.dvbt.guard_interval = + lookupval(kevent.parameters.u.ofdm.guard_interval, 1, dvbfe_dvbt_guard_interval_to_kapi); + result->feparams.u.dvbt.hierarchy_information = + lookupval(kevent.parameters.u.ofdm.hierarchy_information, 1, dvbfe_dvbt_hierarchy_to_kapi); + break; + case FE_ATSC: + result->feparams.u.atsc.modulation = + lookupval(kevent.parameters.u.vsb.modulation, 1, dvbfe_atsc_mod_to_kapi); + break; + } } + if (querymask & DVBFE_INFO_BER) { if (!ioctl(fehandle->fd, FE_READ_BER, &result->ber)) returnval |= DVBFE_INFO_BER; @@ -324,24 +344,15 @@ int dvbfe_get_info(dvbfe_handle_t _fehandle, dvbfe_info_mask_t querymask, struct returnval |= DVBFE_INFO_UNCORRECTED_BLOCKS; } - // setup for next poll - gettimeofday(&fehandle->nextinfotime, NULL); - fehandle->nextinfotime.tv_usec += GET_INFO_MIN_DELAY_US; - if (fehandle->nextinfotime.tv_usec >= 1000000) { - fehandle->nextinfotime.tv_usec -= 1000000; - fehandle->nextinfotime.tv_sec++; - } - memcpy(&fehandle->cachedinfo, result, sizeof(struct dvbfe_info)); - fehandle->cachedreturnval = returnval; - // done return returnval; } -int dvbfe_set(dvbfe_handle_t _fehandle, struct dvbfe_parameters *params, int timeout) +int dvbfe_set(struct dvbfe_handle *fehandle, + struct dvbfe_parameters *params, + int timeout) { struct dvb_frontend_parameters kparams; - struct dvbfe_handle_prv *fehandle = (struct dvbfe_handle_prv*) _fehandle; int res; struct timeval endtime; fe_status_t status; @@ -428,320 +439,123 @@ int dvbfe_set(dvbfe_handle_t _fehandle, struct dvbfe_parameters *params, int tim return -ETIMEDOUT; } -void dvbfe_poll(dvbfe_handle_t fehandle) +int dvbfe_get_pollfd(struct dvbfe_handle *handle) { - // no implementation required yet + return handle->fd; } +int dvbfe_set_22k_tone(struct dvbfe_handle *fehandle, enum dvbfe_sec_tone_mode tone) +{ + int ret = 0; + switch (tone) { + case DVBFE_SEC_TONE_OFF: + ret = ioctl(fehandle->fd, FE_SET_TONE, SEC_TONE_OFF); + break; + case DVBFE_SEC_TONE_ON: + ret = ioctl(fehandle->fd, FE_SET_TONE, SEC_TONE_ON); + break; + default: + print(verbose, ERROR, 1, "Invalid command !"); + break; + } + if (ret == -1) + print(verbose, ERROR, 1, "IOCTL failed !"); + return ret; +} - - - -int dvbfe_diseqc_command(dvbfe_handle_t _fehandle, char *command) +int dvbfe_set_tone_data_burst(struct dvbfe_handle *fehandle, enum dvbfe_sec_mini_cmd minicmd) { - int i = 0; - int waittime; - int status; - struct dvb_diseqc_master_cmd master_cmd; - unsigned int tmpcmd[6]; - struct dvbfe_handle_prv *fehandle = (struct dvbfe_handle_prv*) _fehandle; - char value_s[20]; - int value_i; - int addr; - - while(command[i]) { - /* kill whitespace */ - if (isspace(command[i])) { - i++; - continue; - } + int ret = 0; - switch(command[i]) { - case 't': - if ((status = ioctl(fehandle->fd, FE_SET_TONE, SEC_TONE_OFF)) != 0) - return status; - break; - - case 'T': - if ((status = ioctl(fehandle->fd, FE_SET_TONE, SEC_TONE_ON)) != 0) - return status; - break; - - case '_': - if ((status = ioctl(fehandle->fd, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF)) != 0) - return status; - break; + switch (minicmd) { + case DVBFE_SEC_MINI_A: + ret = ioctl(fehandle->fd, FE_DISEQC_SEND_BURST, SEC_MINI_A); + break; + case DVBFE_SEC_MINI_B: + ret = ioctl(fehandle->fd, FE_DISEQC_SEND_BURST, SEC_MINI_B); + break; + default: + print(verbose, ERROR, 1, "Invalid command"); + break; + } + if (ret == -1) + print(verbose, ERROR, 1, "IOCTL failed"); - case 'v': - if ((status = ioctl(fehandle->fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13)) != 0) - return status; - break; + return ret; +} - case 'V': - if ((status = ioctl(fehandle->fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18)) != 0) - return status; - break; +int dvbfe_set_voltage(struct dvbfe_handle *fehandle, enum dvbfe_sec_voltage voltage) +{ + int ret = 0; - case 'A': - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_BURST, SEC_MINI_A)) != 0) - return status; - break; + switch (voltage) { + case DVBFE_SEC_VOLTAGE_OFF: + ret = ioctl(fehandle->fd, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF); + break; + case DVBFE_SEC_VOLTAGE_13: + ret = ioctl(fehandle->fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13); + break; + case DVBFE_SEC_VOLTAGE_18: + ret = ioctl(fehandle->fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18); + break; + default: + print(verbose, ERROR, 1, "Invalid command"); + break; + } + if (ret == -1) + print(verbose, ERROR, 1, "IOCTL failed"); - case 'B': - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_BURST, SEC_MINI_B)) != 0) - return status; - break; + return ret; +} - case '+': - ioctl(fehandle->fd, FE_ENABLE_HIGH_LNB_VOLTAGE, 1); - /* don't care if this one is not supported */ - break; +int dvbfe_set_high_lnb_voltage(struct dvbfe_handle *fehandle, int on) +{ + switch (on) { + case 0: + ioctl(fehandle->fd, FE_ENABLE_HIGH_LNB_VOLTAGE, 0); + break; + default: + ioctl(fehandle->fd, FE_ENABLE_HIGH_LNB_VOLTAGE, 1); + break; + } + return 0; +} - case '-': - ioctl(fehandle->fd, FE_ENABLE_HIGH_LNB_VOLTAGE, 0); - /* don't care if this one is not supported */ - break; +int dvbfe_do_dishnetworks_legacy_command(struct dvbfe_handle *fehandle, unsigned int cmd) +{ + int ret = 0; - case 'W': - waittime = atoi(command + i + 1); - if (waittime == 0) { - return -EINVAL; - } - usleep(waittime * 1000); - while(command[i] && !isspace(command[i])) - i++; - break; + ret = ioctl(fehandle->fd, FE_DISHNETWORK_SEND_LEGACY_CMD, cmd); + if (ret == -1) + print(verbose, ERROR, 1, "IOCTL failed"); - case '.': // extended command - { - i++; - - if (!strncmp(command+i, "D(", 2)) { - i += 2; - - master_cmd.msg_len = - sscanf(command+i, "%x %x %x %x %x %x", - tmpcmd, tmpcmd+1, tmpcmd+2, tmpcmd+3, tmpcmd+4, tmpcmd+5); - if (master_cmd.msg_len == 0) - return -EINVAL; - master_cmd.msg[0] = tmpcmd[0]; - master_cmd.msg[1] = tmpcmd[1]; - master_cmd.msg[2] = tmpcmd[2]; - master_cmd.msg[3] = tmpcmd[3]; - master_cmd.msg[4] = tmpcmd[4]; - master_cmd.msg[5] = tmpcmd[5]; - - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - } else if (!strncmp(command+i, "Dband(", 6)) { - if (sscanf(command+i+6, "%i %2s", &addr, value_s) != 2) - return -EINVAL; - if (!strncmp(value_s, "lo", 2)) { - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x20; - master_cmd.msg_len = 3; - } else if (!strncmp(value_s, "hi", 2)) { - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x24; - master_cmd.msg_len = 3; - } else { - return -EINVAL; - } - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - - } else if ((!strncmp(command+i, "Dpolarisation(", 14) || - (!strncmp(command+i, "Dpolarization(", 14)))) { - if (sscanf(command+i+14, "%i %1s", &addr, value_s) != 2) - return -EINVAL; - switch(*value_s) { - case 'H': - case 'L': - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x25; - master_cmd.msg_len = 3; - break; - - case 'V': - case 'R': - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x21; - master_cmd.msg_len = 3; - break; - - default: - return -EINVAL; - } - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - - } else if (!strncmp(command+i, "Dsatellite_position(", 20)) { - if (sscanf(command+i+20, "%i %1s", &addr, value_s) != 2) - return -EINVAL; - switch(*value_s) { - case 'A': - case 'C': - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x22; - master_cmd.msg_len = 3; - break; - - case 'B': - case 'D': - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x26; - master_cmd.msg_len = 3; - break; - - default: - return -EINVAL; - } - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - - } else if (!strncmp(command+i, "Dswitch_option(", 15)) { - if (sscanf(command+i+15, "%i %1s", &addr, value_s) != 2) - return -EINVAL; - switch(*value_s) { - case 'A': - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x23; - master_cmd.msg_len = 3; - break; - - case 'B': - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x27; - master_cmd.msg_len = 3; - break; - - default: - return -EINVAL; - } - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - - } else if (!strncmp(command+i, "Dport_pins(", 11)) { - int mask; - if (sscanf(command+i+11, "%i %i %i", &addr, &mask, &value_i) != 3) - return -EINVAL; - - if (mask & 0x0f) { - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x38; - master_cmd.msg[3] = ((mask & 0x0f) << 4) | (value_i & 0x0f); - master_cmd.msg_len = 4; - - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - } - if (mask & 0xf0) { - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x39; - master_cmd.msg[3] = (mask & 0xf0) | ((value_i & 0xf0) >> 4); - master_cmd.msg_len = 4; - - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - } - - } else if (!strncmp(command+i, "Dgoto_preset(", 13)) { - if (sscanf(command+i+13, "%i %i", &addr, &value_i) != 2) - return -EINVAL; - - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x3b; - master_cmd.msg[3] = value_i; - master_cmd.msg_len = 4; - - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - - } else if (!strncmp(command+i, "Dgoto_angle(", 12)) { - int integer = 0; - int fraction = 0; - char *tmp; - - if (sscanf(command+i+12, "%i %s", &addr, value_s) != 2) - return -EINVAL; - - // parse the integer and fractional parts using fixed point - integer = atoi(value_s); - tmp = strchr(value_s, '.'); - if (tmp != NULL) { - tmp++; - tmp[3] = 0; - fraction = ((atoi(tmp) * 16000) / 1000000) & 0xf; - } - - // generate the command - master_cmd.msg[0] = 0xe0; - master_cmd.msg[1] = addr; - master_cmd.msg[2] = 0x6e; - if (integer < -256) { - return -EINVAL; - } else if (integer < 0) { - integer = -integer; - master_cmd.msg[3] = 0xf0; - } else if (integer < 256) { - master_cmd.msg[3] = 0x00; - } else if (integer < 512) { - integer -= 256; - master_cmd.msg[3] = 0x10; - } else { - return -EINVAL; - } - master_cmd.msg[3] |= ((integer / 16) & 0x0f); - integer = integer % 16; - master_cmd.msg[4] |= ((integer & 0x0f) << 4) | fraction; - master_cmd.msg_len = 5; - - if ((status = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &master_cmd)) != 0) - return status; - - } else if (!strncmp(command+i, "dishnetworks(", 13)) { - if (sscanf(command+i+13, "%i", tmpcmd) != 1) - return -EINVAL; - - if ((status = ioctl(fehandle->fd, FE_DISHNETWORK_SEND_LEGACY_CMD, tmpcmd)) != 0) - return status; - } + return ret; +} - /* skip to the end... */ - while(command[i] && (command[i] != ')')) - i++; - break; - } +int dvbfe_do_diseqc_command(struct dvbfe_handle *fehandle, uint8_t *data, uint8_t len) +{ + int ret = 0; + struct dvb_diseqc_master_cmd diseqc_message; + if (len > 6) + return -EINVAL; - default: - return -EINVAL; - } + diseqc_message.msg_len = len; + memcpy(diseqc_message.msg, data, len); - i++; - } + ret = ioctl(fehandle->fd, FE_DISEQC_SEND_MASTER_CMD, &diseqc_message); + if (ret == -1) + print(verbose, ERROR, 1, "IOCTL failed"); - return 0; + return ret; } -int dvbfe_diseqc_read(dvbfe_handle_t _fehandle, int timeout, unsigned char *buf, unsigned int len) +int dvbfe_diseqc_read(struct dvbfe_handle *fehandle, int timeout, unsigned char *buf, unsigned int len) { struct dvb_diseqc_slave_reply reply; int result; - struct dvbfe_handle_prv *fehandle = (struct dvbfe_handle_prv*) _fehandle; if (len > 4) len = 4; diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.h b/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.h index 9eb03b7..69cb05b 100644 --- a/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.h +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbfe.h @@ -2,6 +2,7 @@ * libdvbfe - a DVB frontend library * * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) + * Copyright (C) 2005 Manu Abraham <abraham.manu@gmail.com> * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org) * * This library is free software; you can redistribute it and/or @@ -32,27 +33,20 @@ extern "C" /** * The types of frontend we support. */ -typedef enum dvbfe_type { +enum dvbfe_type { DVBFE_TYPE_DVBS, DVBFE_TYPE_DVBC, DVBFE_TYPE_DVBT, DVBFE_TYPE_ATSC, -} dvbfe_type_t; - -typedef enum dvbfe_polarization { - DVBFE_POLARIZATION_H, - DVBFE_POLARIZATION_V, - DVBFE_POLARIZATION_L, - DVBFE_POLARIZATION_R, -} dvbfe_polarization_t; +}; -typedef enum dvbfe_spectral_inversion { +enum dvbfe_spectral_inversion { DVBFE_INVERSION_OFF, DVBFE_INVERSION_ON, DVBFE_INVERSION_AUTO -} dvbfe_spectral_inversion_t; +}; -typedef enum dvbfe_code_rate { +enum dvbfe_code_rate { DVBFE_FEC_NONE, DVBFE_FEC_1_2, DVBFE_FEC_2_3, @@ -63,9 +57,9 @@ typedef enum dvbfe_code_rate { DVBFE_FEC_7_8, DVBFE_FEC_8_9, DVBFE_FEC_AUTO -} dvbfe_code_rate_t; +}; -typedef enum dvbfe_dvbt_const { +enum dvbfe_dvbt_const { DVBFE_DVBT_CONST_QPSK, DVBFE_DVBT_CONST_QAM_16, DVBFE_DVBT_CONST_QAM_32, @@ -73,106 +67,121 @@ typedef enum dvbfe_dvbt_const { DVBFE_DVBT_CONST_QAM_128, DVBFE_DVBT_CONST_QAM_256, DVBFE_DVBT_CONST_AUTO -} dvbfe_dvbt_const_t; +}; -typedef enum dvbfe_dvbc_mod { +enum dvbfe_dvbc_mod { DVBFE_DVBC_MOD_QAM_16, DVBFE_DVBC_MOD_QAM_32, DVBFE_DVBC_MOD_QAM_64, DVBFE_DVBC_MOD_QAM_128, DVBFE_DVBC_MOD_QAM_256, DVBFE_DVBC_MOD_AUTO, -} dvbfe_dvbc_mod_t; +}; -typedef enum dvbfe_atsc_mod { +enum dvbfe_atsc_mod { DVBFE_ATSC_MOD_QAM_64, DVBFE_ATSC_MOD_QAM_256, DVBFE_ATSC_MOD_VSB_8, DVBFE_ATSC_MOD_VSB_16, DVBFE_ATSC_MOD_AUTO -} dvbfe_atsc_mod_t; +}; -typedef enum dvbfe_dvbt_transmit_mode { +enum dvbfe_dvbt_transmit_mode { DVBFE_DVBT_TRANSMISSION_MODE_2K, DVBFE_DVBT_TRANSMISSION_MODE_8K, DVBFE_DVBT_TRANSMISSION_MODE_AUTO -} dvbfe_dvbt_transmit_mode_t; +}; -typedef enum dvbfe_dvbt_bandwidth { +enum dvbfe_dvbt_bandwidth { DVBFE_DVBT_BANDWIDTH_8_MHZ, DVBFE_DVBT_BANDWIDTH_7_MHZ, DVBFE_DVBT_BANDWIDTH_6_MHZ, DVBFE_DVBT_BANDWIDTH_AUTO -} dvbfe_dvbt_bandwidth_t; +}; -typedef enum dvbfe_dvbt_guard_interval { +enum dvbfe_dvbt_guard_interval { DVBFE_DVBT_GUARD_INTERVAL_1_32, DVBFE_DVBT_GUARD_INTERVAL_1_16, DVBFE_DVBT_GUARD_INTERVAL_1_8, DVBFE_DVBT_GUARD_INTERVAL_1_4, DVBFE_DVBT_GUARD_INTERVAL_AUTO -} dvbfe_dvbt_guard_interval_t; +}; -typedef enum dvbfe_dvbt_hierarchy { +enum dvbfe_dvbt_hierarchy { DVBFE_DVBT_HIERARCHY_NONE, DVBFE_DVBT_HIERARCHY_1, DVBFE_DVBT_HIERARCHY_2, DVBFE_DVBT_HIERARCHY_4, DVBFE_DVBT_HIERARCHY_AUTO -} dvbfe_dvbt_hierarchy_t; +}; /** * Structure used to store and communicate frontend parameters. */ struct dvbfe_parameters { uint32_t frequency; - dvbfe_spectral_inversion_t inversion; + enum dvbfe_spectral_inversion inversion; union { struct { uint32_t symbol_rate; - dvbfe_code_rate_t fec_inner; - dvbfe_polarization_t polarization; + enum dvbfe_code_rate fec_inner; } dvbs; struct { uint32_t symbol_rate; - dvbfe_code_rate_t fec_inner; - dvbfe_dvbc_mod_t modulation; + enum dvbfe_code_rate fec_inner; + enum dvbfe_dvbc_mod modulation; } dvbc; struct { - dvbfe_dvbt_bandwidth_t bandwidth; - dvbfe_code_rate_t code_rate_HP; - dvbfe_code_rate_t code_rate_LP; - dvbfe_dvbt_const_t constellation; - dvbfe_dvbt_transmit_mode_t transmission_mode; - dvbfe_dvbt_guard_interval_t guard_interval; - dvbfe_dvbt_hierarchy_t hierarchy_information; + enum dvbfe_dvbt_bandwidth bandwidth; + enum dvbfe_code_rate code_rate_HP; + enum dvbfe_code_rate code_rate_LP; + enum dvbfe_dvbt_const constellation; + enum dvbfe_dvbt_transmit_mode transmission_mode; + enum dvbfe_dvbt_guard_interval guard_interval; + enum dvbfe_dvbt_hierarchy hierarchy_information; } dvbt; struct { - dvbfe_atsc_mod_t modulation; + enum dvbfe_atsc_mod modulation; } atsc; } u; }; +enum dvbfe_sec_voltage { + DVBFE_SEC_VOLTAGE_13, + DVBFE_SEC_VOLTAGE_18, + DVBFE_SEC_VOLTAGE_OFF +}; + +enum dvbfe_sec_tone_mode { + DVBFE_SEC_TONE_ON, + DVBFE_SEC_TONE_OFF +}; + +enum dvbfe_sec_mini_cmd { + DVBFE_SEC_MINI_A, + DVBFE_SEC_MINI_B +}; + /** * Mask of values used in the dvbfe_get_info() call. */ -typedef enum dvbfe_info_mask { +enum dvbfe_info_mask { DVBFE_INFO_LOCKSTATUS = 0x01, DVBFE_INFO_FEPARAMS = 0x02, DVBFE_INFO_BER = 0x04, DVBFE_INFO_SIGNAL_STRENGTH = 0x08, DVBFE_INFO_SNR = 0x10, DVBFE_INFO_UNCORRECTED_BLOCKS = 0x20, -} dvbfe_info_mask_t; +}; /** * Structure containing values used by the dvbfe_get_info() call. */ struct dvbfe_info { - dvbfe_type_t type; /* always retrieved */ + enum dvbfe_type type; /* always retrieved */ const char *name; /* always retrieved */ unsigned int signal : 1; /* } DVBFE_INFO_LOCKSTATUS */ unsigned int carrier : 1; /* } */ @@ -187,9 +196,23 @@ struct dvbfe_info { }; /** + * Possible types of query used in dvbfe_get_info. + * + * DVBFE_INFO_QUERYTYPE_IMMEDIATE - interrogate frontend for most up to date values. + * DVBFE_INFO_QUERYTYPE_LOCKCHANGE - return details from queued lock status + * change events, or wait for one to occur + * if none are queued. + */ +enum dvbfe_info_querytype { + DVBFE_INFO_QUERYTYPE_IMMEDIATE, + DVBFE_INFO_QUERYTYPE_LOCKCHANGE, +}; + + +/** * Frontend handle datatype. */ -typedef void *dvbfe_handle_t; +struct dvbfe_handle; /** * Open a DVB frontend. @@ -199,18 +222,21 @@ typedef void *dvbfe_handle_t; * @param readonly If 1, frontend will be opened in readonly mode only. * @return A handle on success, or NULL on failure. */ -extern dvbfe_handle_t dvbfe_open(int adapter, int frontend, int readonly); +extern struct dvbfe_handle *dvbfe_open(int adapter, int frontend, int readonly); /** * Close a DVB frontend. * * @param fehandle Handle opened with dvbfe_open(). */ -extern void dvbfe_close(dvbfe_handle_t handle); +extern void dvbfe_close(struct dvbfe_handle *handle); /** * Set the frontend tuning parameters. * + * Note: this function provides only the basic tuning operation; you might want to + * investigate dvbfe_set_sec() in sec.h for a unified device tuning operation. + * * @param fehandle Handle opened with dvbfe_open(). * @param params Params to set. * @param timeout <0 => wait forever for lock. 0=>return immediately, >0=> @@ -218,14 +244,9 @@ extern void dvbfe_close(dvbfe_handle_t handle); * @return 0 on locked (or if timeout==0 and everything else worked), or * nonzero on failure (including no lock). */ -extern int dvbfe_set(dvbfe_handle_t fehandle, struct dvbfe_parameters *params, int timeout); - -/** - * Call this function regularly from a loop to maintain the frontend lock. - * - * @param fehandle Handle opened with dvbfe_open(). - */ -extern void dvbfe_poll(dvbfe_handle_t fehandle); +extern int dvbfe_set(struct dvbfe_handle *fehandle, + struct dvbfe_parameters *params, + int timeout); /** * Retrieve information about the frontend. @@ -233,62 +254,66 @@ extern void dvbfe_poll(dvbfe_handle_t fehandle); * @param fehandle Handle opened with dvbfe_open(). * @param querymask ORed bitmask of desired DVBFE_INFO_* values. * @param result Where to put the retrieved results. + * @param querytype Type of query requested. + * @param timeout Timeout in ms to use if querytype==lockchange (0=>no timeout, <0=> wait forever). * @return ORed bitmask of DVBFE_INFO_* indicating which values were read successfully. */ -extern int dvbfe_get_info(dvbfe_handle_t fehandle, dvbfe_info_mask_t querymask, struct dvbfe_info *result); +extern int dvbfe_get_info(struct dvbfe_handle *fehandle, + enum dvbfe_info_mask querymask, + struct dvbfe_info *result, + enum dvbfe_info_querytype querytype, + int timeout); /** - * Execute a DISEQC command string. - * - * A diseqc command consists of a sequence of the following codes, separated by - * whitespace: - * Simple commands: - * t - turn 22kHz tone off. - * T - turn 22kHz tone on. - * _ - set voltage to 0v (i.e. off). - * v - set voltage to 13v. - * V - set voltage to 18v. - * + - Enable high LNB voltage. - * - - Disable high LNB voltage. - * A - send DISEQC mini command A. - * B - send DISEQC mini command B. - * Wii - Delay for ii milliseconds. - * - * Extended commands: - * .dishnetworks(<value>) - Send a dish networks legacy command <value> - * .D(<value> ...) - Send a raw diseqc master command. The command may be up - * to 6 bytes long. - * .Dband(<addr> <lo|hi>) - Set frequency band hi or lo. - * .Dpolarisation(<addr> <V|H|L|R>) - Set polarisation. - * .Dsatellite_position(<addr> <A|B>) - Set "satellite position" input switch. - * .Dswitch_option(<addr> <A|B>) - Set "switch option" input switch. - * .Dport_pins(<addr> <mask> <value>) - Set all input switches. Mask and value - * are hex-ascii 8 bit bytes. Only bits with a corresponding '1' in mask - * will be changed. - * .Dgoto_preset(<addr> <index>) - Set a positioner to a preset index (integer) - * .Dgoto_angle(<addr> <angle>) - Set a positioner to a given angle - * (e.g. 49.6). The angle may range between -180 to 496. It may include a - * fractional part. - * - * All integer values use standard notation - no prefix=>decimal, 0x=>hex etc. - * - * Set <addr> to 0 if you just have a simple DISEQC setup (e.g. one switch). See - * the DISEQC specification at http://www.eutelsat.org/ for full information. - * - * Comments begin with '#' - any characters after this will be ignored - * to the end of the line. - * - * Examples: - * S-19.2E 11700000 V 9750000 t v W15 .D(E0 10 38 F0) W15 A W15 t - * S-19.2E 99999999 V 10600000 t v W15 .D(E0 10 38 F1) W15 A W15 T - * S-19.2E 11700000 H 9750000 t V W15 .D(E0 10 38 F2) W15 A W15 t - * S-19.2E 99999999 H 10600000 t V W15 .D(E0 10 38 F3) W15 A W15 T + * Get a file descriptor for polling for lock status changes. * * @param fehandle Handle opened with dvbfe_open(). - * @param command Command to execute. - * @return 0 on success, nonzero on failure. + * @return FD for polling. + */ +extern int dvbfe_get_pollfd(struct dvbfe_handle *handle); + +/** + * Tone/Data Burst control + * @param fehandle Handle opened with dvbfe_open(). + * @param tone, SEC_TONE_ON/SEC_TONE_OFF + */ +extern int dvbfe_set_22k_tone(struct dvbfe_handle *handle, enum dvbfe_sec_tone_mode tone); + +/** + * 22khz Tone control + * @param fehandle Handle opened with dvbfe_open(). + * @param adapter, minicmd, SEC_MINI_A/SEC_MINI_B + */ +extern int dvbfe_set_tone_data_burst(struct dvbfe_handle *handle, enum dvbfe_sec_mini_cmd minicmd); + +/** + * Voltage control + * @param fehandle Handle opened with dvbfe_open(). + * @param polarization, SEC_VOLTAGE_13/SEC_VOLTAGE_18/SEC_VOLTAGE_OFF + */ +extern int dvbfe_set_voltage(struct dvbfe_handle *handle, enum dvbfe_sec_voltage voltage); + +/** + * High LNB voltage control (increases voltage by 1v to compensate for long cables) + * @param fehandle Handle opened with dvbfe_open(). + * @param on 1 to enable, 0 to disable. + */ +extern int dvbfe_set_high_lnb_voltage(struct dvbfe_handle *fehandle, int on); + +/** + * Send a legacy Dish Networks command + * @param fehandle Handle opened with dvbfe_open(). + * @param cmd, the command to send + */ +extern int dvbfe_do_dishnetworks_legacy_command(struct dvbfe_handle *handle, unsigned int cmd); + +/** + * Send a DiSEqC Command + * @param fehandle Handle opened with dvbfe_open(). + * @param data, a pointer to am array containing the data to be sent. + * @param len Length of data in bytes, max 6 bytes. */ -extern int dvbfe_diseqc_command(dvbfe_handle_t fehandle, char *command); +extern int dvbfe_do_diseqc_command(struct dvbfe_handle *handle, uint8_t *data, uint8_t len); /** * Read a DISEQC response from the frontend. @@ -299,7 +324,7 @@ extern int dvbfe_diseqc_command(dvbfe_handle_t fehandle, char *command); * @param len Number of bytes in buffer. * @return >= 0 on success (number of received bytes), <0 on failure. */ -extern int dvbfe_diseqc_read(dvbfe_handle_t fehandle, int timeout, unsigned char *buf, unsigned int len); +extern int dvbfe_diseqc_read(struct dvbfe_handle *fehandle, int timeout, unsigned char *buf, unsigned int len); #ifdef __cplusplus } diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.c b/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.c index d6ee632..f0f08f9 100644 --- a/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.c +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.c @@ -44,9 +44,10 @@ int dvbnet_open(int adapter, int netdeviceid) return fd; } -int dvbnet_add_interface(int fd, uint16_t pid, int encapsulation) +int dvbnet_add_interface(int fd, uint16_t pid, enum dvbnet_encap encapsulation) { struct dvb_net_if params; + int status; memset(¶ms, 0, sizeof(params)); params.pid = pid; @@ -63,10 +64,14 @@ int dvbnet_add_interface(int fd, uint16_t pid, int encapsulation) default: return -EINVAL; } - return ioctl(fd, NET_ADD_IF, ¶ms); + + status = ioctl(fd, NET_ADD_IF, ¶ms); + if (status < 0) + return status; + return params.if_num; } -int dvbnet_get_interface(int fd, int ifnum, uint16_t *pid, int *encapsulation) +int dvbnet_get_interface(int fd, int ifnum, uint16_t *pid, enum dvbnet_encap *encapsulation) { struct dvb_net_if info; int res; diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.h b/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.h index 426e540..287919f 100644 --- a/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.h +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbnet.h @@ -31,10 +31,10 @@ extern "C" /** * Possible encapsulations of data. */ -typedef enum dvbnet_encap { +enum dvbnet_encap { DVBNET_ENCAP_MPE, DVBNET_ENCAP_ULE, -} dvbnet_encap_t; +}; /** * The maximum allowed number of dvb network devices per adapter netdevice. @@ -56,9 +56,9 @@ extern int dvbnet_open(int adapter, int netdeviceid); * @param fd FD opened with libdvbnet_open(). * @param pid PID of the stream containing the network data. * @param encapsulation Encapsulation type of the stream (one of DVBNET_ENCAP_*). - * @return 0 on success, nonzero on failure. + * @return Index of new interface on success, < 0 on failure. */ -extern int dvbnet_add_interface(int fd, uint16_t pid, int encapsulation); +extern int dvbnet_add_interface(int fd, uint16_t pid, enum dvbnet_encap encapsulation); /** * Get details of a DVBNET interface. @@ -69,7 +69,7 @@ extern int dvbnet_add_interface(int fd, uint16_t pid, int encapsulation); * @param encapsulation The encapsulation of the interface (DVBNET_ENCAP_*). * @return 0 on success, nonzero on failure. */ -extern int dvbnet_get_interface(int fd, int ifnum, uint16_t *pid, int *encapsulation); +extern int dvbnet_get_interface(int fd, int ifnum, uint16_t *pid, enum dvbnet_encap *encapsulation); /** * Remove a DVBNET interface. diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.c b/kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.c new file mode 100644 index 0000000..f1ffbe8 --- /dev/null +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.c @@ -0,0 +1,46 @@ +/* + * libdvbnet - a DVB network support library + * + * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) + * + * This library 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 library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <sys/param.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <linux/types.h> +#include <linux/dvb/video.h> +#include <errno.h> +#include "dvbvideo.h" + +int dvbvideo_open(int adapter, int videodeviceid) +{ + char filename[PATH_MAX+1]; + int fd; + + sprintf(filename, "/dev/dvb/adapter%i/video%i", adapter, videodeviceid); + if ((fd = open(filename, O_RDWR)) < 0) { + // if that failed, try a flat /dev structure + sprintf(filename, "/dev/dvb%i.video%i", adapter, videodeviceid); + fd = open(filename, O_RDWR); + } + + return fd; +} diff --git a/kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.h b/kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.h new file mode 100644 index 0000000..cc49914 --- /dev/null +++ b/kaffeine/src/input/dvb/lib/libdvbapi/dvbvideo.h @@ -0,0 +1,46 @@ +/* + * libdvbnet - a DVB network support library + * + * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) + * + * This library 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 library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef LIBDVBVIDEO_H +#define LIBDVBVIDEO_H 1 + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include <stdint.h> + +/** + * Open a DVB video device. + * + * @param adapter DVB adapter ID. + * @param videodeviceid Id of video device of that adapter to open. + * @return A unix file descriptor on success, or -1 on failure. + */ +extern int dvbvideo_open(int adapter, int videodeviceid); + +// FIXME: this is a stub library + +#ifdef __cplusplus +} +#endif + +#endif // LIBDVBVIDEO_H |