mirror of
https://github.com/DigitalDevices/dddvb.git
synced 2025-03-01 10:35:23 +00:00
add libdddvb
This commit is contained in:
20
lib/src/Makefile
Normal file
20
lib/src/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
LIB_FLAGS = -fvisibility=hidden -fPIC -DBUILDING_LIBDDDVB
|
||||
|
||||
all: libdddvb.so.1.0.1
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(LIB_FLAGS) $(CFLAGS) -c $<
|
||||
|
||||
libdddvb.a: dvb.o dddvb.o tools.o config.o
|
||||
$(AR) -cvq libdddvb.a $^
|
||||
|
||||
libdddvb.so.1.0.1: dvb.o dddvb.o tools.o config.o
|
||||
$(CC) $(LIB_FLAGS) $(CFLAGS) -shared -Wl,-soname,libdddvb.so.1 -o libdddvb.so.1.0.1 $^ -lc
|
||||
ln -sf libdddvb.so.1.0.1 libdddvb.so.1
|
||||
ln -sf libdddvb.so.1.0.1 libdddvb.so
|
||||
|
||||
dddvb_test: dddvb_test.o
|
||||
$(CC) -o dddvb_test $< -L . -l dddvb
|
||||
|
||||
clean:
|
||||
rm *.o
|
74
lib/src/config.c
Normal file
74
lib/src/config.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
(C) 2012-17 Digital Devices GmbH.
|
||||
|
||||
This file is part of the libdddvb.
|
||||
|
||||
Libdddvb is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Octoserve 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with octoserve. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dddvb.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int parse_config(struct dddvb *dd, char *name, char *sec,
|
||||
void (*cb)(struct dddvb *, char *, char *) )
|
||||
{
|
||||
char line[256], csec[80], par[80], val[80], *p;
|
||||
FILE *f;
|
||||
char fname[90];
|
||||
size_t name_len, config_len;
|
||||
|
||||
name_len = strlen(name);
|
||||
config_len = strlen(dd->config);
|
||||
|
||||
if (name_len + config_len > sizeof(fname) - 1)
|
||||
return -1;
|
||||
memcpy(fname, dd->config, config_len);
|
||||
if (name_len)
|
||||
memcpy(fname + config_len, name, name_len);
|
||||
else
|
||||
memcpy(fname + config_len, "dddvb.conf", 11);
|
||||
|
||||
if ((f = fopen (fname, "r")) == NULL) {
|
||||
printf("config fiile %s not found\n", fname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((p = fgets(line, sizeof(line), f))) {
|
||||
if (*p == '\r' || *p == '\n' || *p == '#')
|
||||
continue;
|
||||
if (*p == '[') {
|
||||
if ((p = strtok(line + 1, "]")) == NULL)
|
||||
continue;
|
||||
strncpy(csec, p, sizeof(csec));
|
||||
//printf("current section %s\n", csec);
|
||||
if (!strcmp(sec, csec) && cb)
|
||||
cb(dd, NULL, NULL);
|
||||
continue;
|
||||
}
|
||||
if (!(p = strtok(line, "=")))
|
||||
continue;
|
||||
strncpy(par, p, sizeof(par));
|
||||
if (!(p = strtok(NULL, "=")))
|
||||
continue;
|
||||
strncpy (val, p, sizeof(val));
|
||||
//printf("%s=%s\n", par, val);
|
||||
if (!strcmp(sec, csec) && cb)
|
||||
cb(dd, par, val);
|
||||
}
|
||||
if (!strcmp(sec, csec) && cb)
|
||||
cb(dd, NULL, NULL);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
96
lib/src/dddvb.c
Normal file
96
lib/src/dddvb.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "libdddvb.h"
|
||||
#include "dddvb.h"
|
||||
#include "debug.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
LIBDDDVB_EXPORTED uint32_t dddvb_debug;
|
||||
LIBDDDVB_EXPORTED struct dddvb *global_dd = NULL;
|
||||
LIBDDDVB_EXPORTED pthread_mutex_t dddvb_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void __attribute__ ((constructor)) setup(void) {
|
||||
printf("SETUP\n");
|
||||
}
|
||||
|
||||
LIBDDDVB_EXPORTED struct dddvb_fe *dddvb_fe_alloc_num(struct dddvb *dd, uint32_t type, uint32_t num)
|
||||
{
|
||||
struct dddvb_fe *fe;
|
||||
|
||||
if (num >= dd->dvbfe_num)
|
||||
return NULL;
|
||||
dbgprintf(DEBUG_SYS, "alloc_fe_num %u type %u\n", num, type);
|
||||
pthread_mutex_lock(&dd->lock);
|
||||
fe = &dd->dvbfe[num];
|
||||
if (fe->state || !(fe->type & (1UL << type))) {
|
||||
dbgprintf(DEBUG_SYS, "fe %d state = %d, type = %08x wanted %08x\n",
|
||||
fe->nr, fe->state, fe->type, 1UL << type);
|
||||
pthread_mutex_unlock(&dd->lock);
|
||||
return NULL;
|
||||
}
|
||||
fe->state = 1;
|
||||
pthread_mutex_unlock(&dd->lock);
|
||||
if (dddvb_fe_start(fe) < 0) {
|
||||
dbgprintf(DEBUG_SYS, "fe %d busy\n", fe->nr);
|
||||
return 0;
|
||||
}
|
||||
dbgprintf(DEBUG_SYS, "Allocated fe %d = %d/%d, fd=%d\n",
|
||||
fe->nr, fe->anum, fe->fnum, fe->fd);
|
||||
return fe;
|
||||
}
|
||||
|
||||
LIBDDDVB_EXPORTED struct dddvb_fe *dddvb_fe_alloc(struct dddvb *dd, uint32_t type)
|
||||
{
|
||||
int i;
|
||||
struct dddvb_fe *fe = NULL;
|
||||
|
||||
pthread_mutex_lock(&dd->lock);
|
||||
dbgprintf(DEBUG_SYS, "alloc_fe type %u\n", type);
|
||||
for (i = 0; i < dd->dvbfe_num; i++) {
|
||||
fe = &dd->dvbfe[i];
|
||||
if (fe->state == 0 &&
|
||||
(fe->type & (1UL << type))) {
|
||||
fe = dddvb_fe_alloc_num(dd, type, i);
|
||||
if (fe)
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&dd->lock);
|
||||
return fe;
|
||||
|
||||
}
|
||||
|
||||
LIBDDDVB_EXPORTED int dddvb_dvb_tune(struct dddvb_fe *fe, struct dddvb_params *p)
|
||||
{
|
||||
return dddvb_fe_tune(fe, p);
|
||||
}
|
||||
|
||||
LIBDDDVB_EXPORTED struct dddvb *dddvb_init(char *config, uint32_t flags)
|
||||
{
|
||||
struct dddvb *dd;
|
||||
pthread_mutexattr_t mta;
|
||||
|
||||
dddvb_debug = flags;
|
||||
|
||||
pthread_mutex_lock(&dddvb_mutex);
|
||||
if (global_dd) {
|
||||
pthread_mutex_unlock(&dddvb_mutex);
|
||||
return global_dd;
|
||||
}
|
||||
|
||||
dd = calloc(1, sizeof(struct dddvb));
|
||||
if (!dd)
|
||||
goto fail;
|
||||
dd->config[0] = 0;
|
||||
if (config && strlen(config) < 80)
|
||||
strcpy(dd->config, config);
|
||||
|
||||
pthread_mutexattr_init(&mta);
|
||||
pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&dd->lock, &mta);
|
||||
|
||||
dddvb_dvb_init(dd);
|
||||
global_dd = dd;
|
||||
fail:
|
||||
pthread_mutex_unlock(&dddvb_mutex);
|
||||
return dd;
|
||||
}
|
118
lib/src/dddvb.h
Normal file
118
lib/src/dddvb.h
Normal file
@@ -0,0 +1,118 @@
|
||||
#ifndef _DDDVB_H_
|
||||
#define _DDDVB_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <linux/dvb/dmx.h>
|
||||
#include <linux/dvb/frontend.h>
|
||||
#include <linux/dvb/video.h>
|
||||
#include <linux/dvb/net.h>
|
||||
|
||||
|
||||
#define DDDVB_MAX_DVB_FE 256
|
||||
|
||||
#define DDDVB_MAX_SOURCE 4
|
||||
|
||||
#define MAX_PMT 16
|
||||
|
||||
|
||||
struct dddvb_params {
|
||||
uint32_t param[32];
|
||||
uint8_t pid[1024];
|
||||
};
|
||||
|
||||
struct dddvb_status {
|
||||
struct dddvb_params params;
|
||||
fe_status_t stat;
|
||||
int64_t strength;
|
||||
int64_t snr;
|
||||
};
|
||||
|
||||
struct dddvb_fe {
|
||||
struct dddvb *dd;
|
||||
uint32_t state;
|
||||
pthread_t pt;
|
||||
pthread_mutex_t mutex;
|
||||
char name[120];
|
||||
|
||||
uint32_t source;
|
||||
#define DDDVB_FE_SOURCE_DEMOD 0
|
||||
#define DDDVB_FE_SOURCE_SATIP 1
|
||||
#define DDDVB_FE_SOURCE_RTP 2
|
||||
#define DDDVB_FE_SOURCE_MCAST 3
|
||||
|
||||
uint32_t modulation;
|
||||
#define DDDVB_MODULATION_DVB_C 1
|
||||
#define DDDVB_MODULATION_DVB_S 2
|
||||
#define DDDVB_MODULATION_DVB_T 3
|
||||
|
||||
uint32_t nr;
|
||||
uint32_t type;
|
||||
uint32_t anum;
|
||||
uint32_t fnum;
|
||||
|
||||
uint32_t scif_type;
|
||||
uint32_t scif_slot;
|
||||
uint32_t scif_freq;
|
||||
uint32_t input;
|
||||
|
||||
uint32_t lof1[DDDVB_MAX_SOURCE];
|
||||
uint32_t lof2[DDDVB_MAX_SOURCE];
|
||||
uint32_t lofs[DDDVB_MAX_SOURCE];
|
||||
uint32_t prev_delay[DDDVB_MAX_SOURCE];
|
||||
|
||||
int fd;
|
||||
int dmx;
|
||||
|
||||
fe_status_t stat;
|
||||
uint32_t level;
|
||||
uint32_t lock;
|
||||
uint32_t quality;
|
||||
int64_t strength;
|
||||
int64_t cnr;
|
||||
int first;
|
||||
|
||||
uint32_t tune;
|
||||
struct dddvb_params param;
|
||||
|
||||
uint32_t n_tune;
|
||||
struct dddvb_params n_param;
|
||||
|
||||
struct dddvb_status status;
|
||||
};
|
||||
|
||||
struct dddvb {
|
||||
pthread_mutex_t lock;
|
||||
pthread_mutex_t uni_lock;
|
||||
|
||||
char config[80];
|
||||
|
||||
uint32_t state;
|
||||
|
||||
uint32_t dvbnum;
|
||||
uint32_t dvbtnum;
|
||||
uint32_t dvbs2num;
|
||||
uint32_t dvbt2num;
|
||||
uint32_t dvbcnum;
|
||||
uint32_t dvbc2num;
|
||||
|
||||
uint32_t dvbfe_num;
|
||||
uint32_t scif_type;
|
||||
|
||||
struct dddvb_fe dvbfe[DDDVB_MAX_DVB_FE];
|
||||
};
|
||||
|
||||
int dddvb_dvb_init(struct dddvb *dd);
|
||||
int parse_config(struct dddvb *dd, char *name, char *sec,
|
||||
void (*cb)(struct dddvb *, char *, char *) );
|
||||
void dddvb_fe_handle(struct dddvb_fe *fe);
|
||||
int dddvb_fe_tune(struct dddvb_fe *fe, struct dddvb_params *p);
|
||||
int dddvb_fe_start(struct dddvb_fe *fe);
|
||||
|
||||
|
||||
|
||||
#endif /* _DDDVB_H_ */
|
30
lib/src/debug.h
Normal file
30
lib/src/debug.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef _DDDVB_DEBUG_H_
|
||||
#define _DDDVB_DEBUG_H_
|
||||
|
||||
#include "tools.h"
|
||||
|
||||
#if BUILDING_LIBDDDVB
|
||||
extern uint32_t dddvb_debug;
|
||||
#endif
|
||||
|
||||
#define DEBUG_RTSP 1
|
||||
#define DEBUG_SSDP 2
|
||||
#define DEBUG_NET 4
|
||||
#define DEBUG_SYS 8
|
||||
#define DEBUG_DVB 16
|
||||
#define DEBUG_IGMP 32
|
||||
#define DEBUG_SWITCH 64
|
||||
#define DEBUG_DEBUG 256
|
||||
|
||||
|
||||
#if 0
|
||||
#define dbgprintf(_mask_, ...) \
|
||||
do { if (dddvb_debug & _mask_) fprintf(stderr, __VA_ARGS__); } while (0)
|
||||
#else
|
||||
#define dbgprintf(_mask_, ...) \
|
||||
do { if (dddvb_debug & _mask_) { fprintf(stderr, "[%5u] ", mtime(NULL)); \
|
||||
fprintf(stderr, __VA_ARGS__); } } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
896
lib/src/dvb.c
Normal file
896
lib/src/dvb.c
Normal file
@@ -0,0 +1,896 @@
|
||||
#include "libdddvb.h"
|
||||
#include "dddvb.h"
|
||||
#include "tools.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <linux/dvb/dmx.h>
|
||||
#include <linux/dvb/frontend.h>
|
||||
#include <linux/dvb/video.h>
|
||||
#include <linux/dvb/net.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DTV_SCRAMBLING_SEQUENCE_INDEX 70
|
||||
#define DTV_INPUT 71
|
||||
#define SYS_DVBC2 19
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
static int set_property(int fd, uint32_t cmd, uint32_t data)
|
||||
{
|
||||
struct dtv_property p;
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
p.cmd = cmd;
|
||||
c.num = 1;
|
||||
c.props = &p;
|
||||
p.u.data = data;
|
||||
ret = ioctl(fd, FE_SET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int get_property(int fd, uint32_t cmd, uint32_t *data)
|
||||
{
|
||||
struct dtv_property p;
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
p.cmd = cmd;
|
||||
c.num = 1;
|
||||
c.props = &p;
|
||||
ret = ioctl(fd, FE_GET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_GET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
*data = p.u.data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_stat(int fd, uint32_t cmd, struct dtv_fe_stats *stats)
|
||||
{
|
||||
struct dtv_property p;
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
p.cmd = cmd;
|
||||
c.num = 1;
|
||||
c.props = &p;
|
||||
ret = ioctl(fd, FE_GET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_GET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
memcpy(stats, &p.u.st, sizeof(struct dtv_fe_stats));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int set_fe_input(struct dddvb_fe *fe, uint32_t fr,
|
||||
uint32_t sr, fe_delivery_system_t ds,
|
||||
uint32_t input)
|
||||
{
|
||||
struct dtv_property p[] = {
|
||||
{ .cmd = DTV_CLEAR },
|
||||
{ .cmd = DTV_DELIVERY_SYSTEM, .u.data = ds },
|
||||
{ .cmd = DTV_FREQUENCY, .u.data = fr },
|
||||
{ .cmd = DTV_INVERSION, .u.data = INVERSION_AUTO },
|
||||
{ .cmd = DTV_SYMBOL_RATE, .u.data = sr },
|
||||
{ .cmd = DTV_INNER_FEC, .u.data = FEC_AUTO },
|
||||
};
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
int fd = fe->fd;
|
||||
|
||||
if (fe->param.param[PARAM_FEC] != DDDVB_UNDEF)
|
||||
p[5].u.data = fe->param.param[PARAM_FEC];
|
||||
|
||||
c.num = ARRAY_SIZE(p);
|
||||
c.props = p;
|
||||
ret = ioctl(fd, FE_SET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
if (input != DDDVB_UNDEF)
|
||||
set_property(fd, DTV_INPUT, input);
|
||||
if (fe->param.param[PARAM_ISI] != DDDVB_UNDEF)
|
||||
set_property(fd, DTV_STREAM_ID, fe->param.param[PARAM_ISI]);
|
||||
if (fe->param.param[PARAM_PLS] != DDDVB_UNDEF)
|
||||
set_property(fd, DTV_SCRAMBLING_SEQUENCE_INDEX,
|
||||
fe->param.param[PARAM_PLS]);
|
||||
set_property(fd, DTV_TUNE, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void diseqc_send_msg(int fd, fe_sec_voltage_t v,
|
||||
struct dvb_diseqc_master_cmd *cmd,
|
||||
fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b,
|
||||
int wait)
|
||||
{
|
||||
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) == -1)
|
||||
perror("FE_DISEQC_SEND_MASTER_CMD failed");
|
||||
usleep(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");
|
||||
}
|
||||
|
||||
static int diseqc(int fd, int sat, int hor, int band)
|
||||
{
|
||||
struct dvb_diseqc_master_cmd cmd = {
|
||||
.msg = {0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00},
|
||||
.msg_len = 4
|
||||
};
|
||||
|
||||
hor &= 1;
|
||||
cmd.msg[3] = 0xf0 | ( ((sat << 2) & 0x0c) | (band ? 1 : 0) | (hor ? 2 : 0));
|
||||
|
||||
diseqc_send_msg(fd, hor ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
|
||||
&cmd, band ? SEC_TONE_ON : SEC_TONE_OFF,
|
||||
(sat & 1) ? SEC_MINI_B : SEC_MINI_A, 0);
|
||||
dbgprintf(DEBUG_DVB, "MS %02x %02x %02x %02x\n",
|
||||
cmd.msg[0], cmd.msg[1], cmd.msg[2], cmd.msg[3]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_en50494(struct dddvb_fe *fe, uint32_t freq, uint32_t sr,
|
||||
int sat, int hor, int band,
|
||||
uint32_t slot, uint32_t ubfreq,
|
||||
fe_delivery_system_t ds)
|
||||
{
|
||||
struct dvb_diseqc_master_cmd cmd = {
|
||||
.msg = {0xe0, 0x11, 0x5a, 0x00, 0x00},
|
||||
.msg_len = 5
|
||||
};
|
||||
uint16_t t;
|
||||
uint32_t input = 3 & (sat >> 6);
|
||||
int fd = fe->fd;
|
||||
|
||||
t = (freq + ubfreq + 2) / 4 - 350;
|
||||
hor &= 1;
|
||||
|
||||
cmd.msg[3] = ((t & 0x0300) >> 8) |
|
||||
(slot << 5) | ((sat & 0x3f) ? 0x10 : 0) | (band ? 4 : 0) | (hor ? 8 : 0);
|
||||
cmd.msg[4] = t & 0xff;
|
||||
|
||||
set_property(fd, DTV_INPUT, input);
|
||||
if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
|
||||
perror("FE_SET_TONE failed");
|
||||
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18) == -1)
|
||||
perror("FE_SET_VOLTAGE failed");
|
||||
usleep(15000);
|
||||
if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd) == -1)
|
||||
perror("FE_DISEQC_SEND_MASTER_CMD failed");
|
||||
usleep(15000);
|
||||
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) == -1)
|
||||
perror("FE_SET_VOLTAGE failed");
|
||||
|
||||
set_fe_input(fe, ubfreq * 1000, sr, ds, input);
|
||||
dbgprintf(DEBUG_DVB, "EN50494 %02x %02x %02x %02x %02x\n",
|
||||
cmd.msg[0], cmd.msg[1], cmd.msg[2], cmd.msg[3], cmd.msg[4]);
|
||||
}
|
||||
|
||||
static int set_en50607(struct dddvb_fe *fe, uint32_t freq, uint32_t sr,
|
||||
int sat, int hor, int band,
|
||||
uint32_t slot, uint32_t ubfreq,
|
||||
fe_delivery_system_t ds)
|
||||
{
|
||||
struct dvb_diseqc_master_cmd cmd = {
|
||||
.msg = {0x70, 0x00, 0x00, 0x00, 0x00},
|
||||
.msg_len = 4
|
||||
};
|
||||
uint32_t t = freq - 100;
|
||||
uint32_t input = 3 & (sat >> 6);
|
||||
int fd = fe->fd;
|
||||
|
||||
hor &= 1;
|
||||
cmd.msg[1] = slot << 3;
|
||||
cmd.msg[1] |= ((t >> 8) & 0x07);
|
||||
cmd.msg[2] = (t & 0xff);
|
||||
cmd.msg[3] = ((sat & 0x3f) << 2) | (hor ? 2 : 0) | (band ? 1 : 0);
|
||||
|
||||
set_property(fd, DTV_INPUT, input);
|
||||
if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
|
||||
perror("FE_SET_TONE failed");
|
||||
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18) == -1)
|
||||
perror("FE_SET_VOLTAGE failed");
|
||||
usleep(15000);
|
||||
if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd) == -1)
|
||||
perror("FE_DISEQC_SEND_MASTER_CMD failed");
|
||||
usleep(15000);
|
||||
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) == -1)
|
||||
perror("FE_SET_VOLTAGE failed");
|
||||
|
||||
set_fe_input(fe, ubfreq * 1000, sr, ds, input);
|
||||
dbgprintf(DEBUG_DVB, "EN50607 %02x %02x %02x %02x\n",
|
||||
cmd.msg[0], cmd.msg[1], cmd.msg[2], cmd.msg[3]);
|
||||
dbgprintf(DEBUG_DVB, "EN50607 freq %u sr %u hor %u\n",
|
||||
freq, sr, hor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int tune_sat(struct dddvb_fe *fe)
|
||||
{
|
||||
uint32_t freq, hi = 0, src, lnb = 0, lnbc = 0, lofs;
|
||||
fe_delivery_system_t ds = fe->param.param[PARAM_MSYS];
|
||||
|
||||
freq = fe->param.param[PARAM_FREQ];
|
||||
dbgprintf(DEBUG_DVB, "tune_sat freq=%u\n", freq);
|
||||
|
||||
if (fe->param.param[PARAM_SRC] != DDDVB_UNDEF)
|
||||
lnb = fe->param.param[PARAM_SRC];
|
||||
|
||||
lnbc = lnb & (DDDVB_MAX_SOURCE - 1);
|
||||
lofs = fe->lofs[lnbc];
|
||||
#if 0
|
||||
if (freq < 5000000) { //3400 - 4200 ->5150
|
||||
lofs = 5150000;
|
||||
if (freq > lofs)
|
||||
freq -= lofs;
|
||||
else
|
||||
freq = lofs - freq;
|
||||
} else if (freq > 19700000 && freq < 22000000) { //19700-22000 ->21200
|
||||
lofs = 21200000;
|
||||
if (freq > lofs)
|
||||
freq -= lofs;
|
||||
else
|
||||
freq = lofs - freq;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (lofs)
|
||||
hi = (freq > lofs) ? 1 : 0;
|
||||
if (hi)
|
||||
freq -= fe->lof2[lnbc];
|
||||
else
|
||||
freq -= fe->lof1[lnbc];
|
||||
}
|
||||
dbgprintf(DEBUG_DVB, "tune_sat IF=%u\n", freq);
|
||||
if (fe->first) {
|
||||
fe->first = 0;
|
||||
dbgprintf(DEBUG_DVB, "pre voltage %d\n", fe->prev_delay[lnbc]);
|
||||
if (ioctl(fe->fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) == -1)
|
||||
perror("FE_SET_VOLTAGE failed");
|
||||
usleep(fe->prev_delay[lnbc]);
|
||||
}
|
||||
dbgprintf(DEBUG_DVB, "scif_type = %u\n", fe->scif_type);
|
||||
if (fe->scif_type == 1) {
|
||||
pthread_mutex_lock(&fe->dd->uni_lock);
|
||||
set_en50494(fe, freq / 1000, fe->param.param[PARAM_SR],
|
||||
lnb, fe->param.param[PARAM_POL], hi,
|
||||
fe->scif_slot, fe->scif_freq, ds);
|
||||
pthread_mutex_unlock(&fe->dd->uni_lock);
|
||||
} else if (fe->scif_type == 2) {
|
||||
pthread_mutex_lock(&fe->dd->uni_lock);
|
||||
set_en50607(fe, freq / 1000, fe->param.param[PARAM_SR],
|
||||
lnb, fe->param.param[PARAM_POL], hi,
|
||||
fe->scif_slot, fe->scif_freq, ds);
|
||||
pthread_mutex_unlock(&fe->dd->uni_lock);
|
||||
} else {
|
||||
//set_property(fe->fd, DTV_INPUT, 3 & (lnb >> 6));
|
||||
diseqc(fe->fd, lnb, fe->param.param[PARAM_POL], hi);
|
||||
set_fe_input(fe, freq, fe->param.param[PARAM_SR], ds, ~(0U));
|
||||
}
|
||||
}
|
||||
|
||||
static int tune_c(struct dddvb_fe *fe)
|
||||
{
|
||||
struct dtv_property p[] = {
|
||||
{ .cmd = DTV_CLEAR },
|
||||
{ .cmd = DTV_FREQUENCY, .u.data = fe->param.param[PARAM_FREQ] },
|
||||
{ .cmd = DTV_BANDWIDTH_HZ, .u.data = (fe->param.param[PARAM_BW_HZ] != DDDVB_UNDEF) ?
|
||||
fe->param.param[PARAM_BW_HZ] : 8000000 },
|
||||
{ .cmd = DTV_SYMBOL_RATE, .u.data = fe->param.param[PARAM_SR] },
|
||||
{ .cmd = DTV_INNER_FEC, .u.data = (fe->param.param[PARAM_FEC] != DDDVB_UNDEF) ?
|
||||
fe->param.param[PARAM_FEC] : FEC_AUTO },
|
||||
{ .cmd = DTV_MODULATION,
|
||||
.u.data = (fe->param.param[PARAM_MTYPE] != DDDVB_UNDEF) ?
|
||||
fe->param.param[PARAM_MTYPE] : QAM_AUTO },
|
||||
{ .cmd = DTV_TUNE },
|
||||
};
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
printf("tune_c()\n");
|
||||
set_property(fe->fd, DTV_DELIVERY_SYSTEM, SYS_DVBC_ANNEX_A);
|
||||
|
||||
c.num = ARRAY_SIZE(p);
|
||||
c.props = p;
|
||||
ret = ioctl(fe->fd, FE_SET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tune_cable(struct dddvb_fe *fe)
|
||||
{
|
||||
uint32_t freq;
|
||||
struct dvb_frontend_parameters p = {
|
||||
.frequency = fe->param.param[PARAM_FREQ] * 1000,
|
||||
.u.qam.symbol_rate = fe->param.param[PARAM_SR],
|
||||
.u.qam.fec_inner = (fe->param.param[PARAM_FEC] != DDDVB_UNDEF) ?
|
||||
(fe->param.param[PARAM_FEC]) : FEC_AUTO,
|
||||
.u.qam.modulation = fe->param.param[PARAM_MTYPE],
|
||||
};
|
||||
set_property(fe->fd, DTV_DELIVERY_SYSTEM, SYS_DVBC_ANNEX_A);
|
||||
if (ioctl(fe->fd, FE_SET_FRONTEND, &p) == -1) {
|
||||
perror("FE_SET_FRONTEND error");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tune_terr(struct dddvb_fe *fe)
|
||||
{
|
||||
struct dtv_property p[] = {
|
||||
{ .cmd = DTV_CLEAR },
|
||||
{ .cmd = DTV_FREQUENCY, .u.data = fe->param.param[PARAM_FREQ] * 1000 },
|
||||
{ .cmd = DTV_BANDWIDTH_HZ, .u.data = fe->param.param[PARAM_BW_HZ] },
|
||||
{ .cmd = DTV_TUNE },
|
||||
};
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
set_property(fe->fd, DTV_DELIVERY_SYSTEM, SYS_DVBT);
|
||||
|
||||
c.num = ARRAY_SIZE(p);
|
||||
c.props = p;
|
||||
ret = ioctl(fe->fd, FE_SET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
static int tune_terr(struct dddvb_fe *fe)
|
||||
{
|
||||
uint32_t freq;
|
||||
enum fe_bandwidth bw;
|
||||
struct dvb_frontend_parameters p = {
|
||||
.frequency = fe->param.param[PARAM_FREQ] * 1000,
|
||||
.inversion = INVERSION_AUTO,
|
||||
.u.ofdm.code_rate_HP = FEC_AUTO,
|
||||
.u.ofdm.code_rate_LP = FEC_AUTO,
|
||||
.u.ofdm.constellation = fe->param.param[PARAM_MTYPE],
|
||||
.u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO,
|
||||
.u.ofdm.guard_interval = GUARD_INTERVAL_AUTO,
|
||||
.u.ofdm.hierarchy_information = HIERARCHY_AUTO,
|
||||
.u.ofdm.bandwidth = (fe->param.param[PARAM_BW] != DDDVB_UNDEF) ?
|
||||
(fe->param.param[PARAM_BW]) : BANDWIDTH_AUTO,
|
||||
};
|
||||
set_property(fe->fd, DTV_DELIVERY_SYSTEM, SYS_DVBT);
|
||||
if (ioctl(fe->fd, FE_SET_FRONTEND, &p) == -1) {
|
||||
perror("FE_SET_FRONTEND error");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int tune_c2(struct dddvb_fe *fe)
|
||||
{
|
||||
struct dtv_property p[] = {
|
||||
{ .cmd = DTV_CLEAR },
|
||||
{ .cmd = DTV_FREQUENCY, .u.data = fe->param.param[PARAM_FREQ] * 1000 },
|
||||
{ .cmd = DTV_BANDWIDTH_HZ, .u.data = fe->param.param[PARAM_BW_HZ] },
|
||||
{ .cmd = DTV_STREAM_ID, .u.data = fe->param.param[PARAM_PLP] },
|
||||
{ .cmd = DTV_TUNE },
|
||||
};
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
set_property(fe->fd, DTV_DELIVERY_SYSTEM, SYS_DVBC2);
|
||||
|
||||
c.num = ARRAY_SIZE(p);
|
||||
c.props = p;
|
||||
ret = ioctl(fe->fd, FE_SET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tune_terr2(struct dddvb_fe *fe)
|
||||
{
|
||||
struct dtv_property p[] = {
|
||||
{ .cmd = DTV_CLEAR },
|
||||
{ .cmd = DTV_FREQUENCY, .u.data = fe->param.param[PARAM_FREQ] * 1000 },
|
||||
{ .cmd = DTV_BANDWIDTH_HZ, .u.data = fe->param.param[PARAM_BW_HZ] },
|
||||
{ .cmd = DTV_STREAM_ID, .u.data = fe->param.param[PARAM_PLP] },
|
||||
{ .cmd = DTV_TUNE },
|
||||
};
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
set_property(fe->fd, DTV_DELIVERY_SYSTEM, SYS_DVBT2);
|
||||
|
||||
c.num = ARRAY_SIZE(p);
|
||||
c.props = p;
|
||||
ret = ioctl(fe->fd, FE_SET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tune_isdbt(struct dddvb_fe *fe)
|
||||
{
|
||||
struct dtv_property p[] = {
|
||||
{ .cmd = DTV_CLEAR },
|
||||
{ .cmd = DTV_FREQUENCY, .u.data = fe->param.param[PARAM_FREQ] * 1000 },
|
||||
{ .cmd = DTV_BANDWIDTH_HZ, .u.data = fe->param.param[PARAM_BW_HZ] },
|
||||
{ .cmd = DTV_TUNE },
|
||||
};
|
||||
struct dtv_properties c;
|
||||
int ret;
|
||||
|
||||
set_property(fe->fd, DTV_DELIVERY_SYSTEM, SYS_ISDBT);
|
||||
|
||||
c.num = ARRAY_SIZE(p);
|
||||
c.props = p;
|
||||
ret = ioctl(fe->fd, FE_SET_PROPERTY, &c);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tune(struct dddvb_fe *fe)
|
||||
{
|
||||
int ret;
|
||||
|
||||
printf("tune()\n");
|
||||
switch (fe->n_param.param[PARAM_MSYS]) {
|
||||
case SYS_DVBS:
|
||||
case SYS_DVBS2:
|
||||
ret = tune_sat(fe);
|
||||
break;
|
||||
case SYS_DVBC_ANNEX_A:
|
||||
ret = tune_c(fe);
|
||||
break;
|
||||
case SYS_DVBT:
|
||||
ret = tune_terr(fe);
|
||||
break;
|
||||
case SYS_DVBT2:
|
||||
ret = tune_terr2(fe);
|
||||
break;
|
||||
case SYS_DVBC2:
|
||||
ret = tune_c2(fe);
|
||||
break;
|
||||
case SYS_ISDBT:
|
||||
ret = tune_isdbt(fe);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int open_dmx(struct dddvb_fe *fe)
|
||||
{
|
||||
char fname[80];
|
||||
struct dmx_pes_filter_params pesFilterParams;
|
||||
|
||||
sprintf(fname, "/dev/dvb/adapter%u/demux%u", fe->anum, fe->fnum);
|
||||
|
||||
fe->dmx = open(fname, O_RDWR);
|
||||
if (fe->dmx < 0)
|
||||
return -1;
|
||||
|
||||
pesFilterParams.input = DMX_IN_FRONTEND;
|
||||
pesFilterParams.output = DMX_OUT_TS_TAP;
|
||||
pesFilterParams.pes_type = DMX_PES_OTHER;
|
||||
pesFilterParams.flags = DMX_IMMEDIATE_START;
|
||||
pesFilterParams.pid = 0x2000;
|
||||
|
||||
if (ioctl(fe->dmx, DMX_SET_PES_FILTER, &pesFilterParams) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int open_fe(struct dddvb_fe *fe)
|
||||
{
|
||||
char fname[80];
|
||||
|
||||
sprintf(fname, "/dev/dvb/adapter%d/frontend%d", fe->anum, fe->fnum);
|
||||
fe->fd = open(fname, O_RDWR);
|
||||
printf("open = %d\n", fe->fd);
|
||||
if (fe->fd < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_stats(struct dddvb_fe *fe)
|
||||
{
|
||||
uint16_t sig = 0, snr = 0;
|
||||
fe_status_t stat;
|
||||
int64_t str, cnr;
|
||||
int64_t val;
|
||||
uint64_t uval;
|
||||
struct dtv_fe_stats st;
|
||||
|
||||
ioctl(fe->fd, FE_READ_STATUS, &stat);
|
||||
fe->stat = stat;
|
||||
fe->lock = (stat == 0x1f) ? 1 : 0;
|
||||
//calc_lq(fe);
|
||||
if (!get_stat(fe->fd, DTV_STAT_SIGNAL_STRENGTH, &st)) {
|
||||
|
||||
fe->strength = str = st.stat[0].svalue;
|
||||
dbgprintf(DEBUG_DVB, "fe%d: str=%lld.%03llddB\n",
|
||||
fe->nr, str/1000, abs(str%1000));
|
||||
}
|
||||
if (!get_stat(fe->fd, DTV_STAT_CNR, &st)) {
|
||||
fe->cnr = cnr = st.stat[0].svalue;
|
||||
dbgprintf(DEBUG_DVB, "fe%d: cnr=%lld.%03llddB\n",
|
||||
fe->nr, cnr/1000, abs(cnr%1000));
|
||||
}
|
||||
if (!get_stat(fe->fd, DTV_STAT_PRE_TOTAL_BIT_COUNT, &st) &&
|
||||
(st.stat[0].scale == FE_SCALE_COUNTER)) {
|
||||
uval = st.stat[0].uvalue;
|
||||
dbgprintf(DEBUG_DVB, "fe%d: pre_total_bit_count = %08x\n",
|
||||
fe->nr, (uint32_t)uval);
|
||||
}
|
||||
if (!get_stat(fe->fd, DTV_STAT_PRE_ERROR_BIT_COUNT, &st) &&
|
||||
(st.stat[0].scale == FE_SCALE_COUNTER)) {
|
||||
uval = st.stat[0].uvalue;
|
||||
dbgprintf(DEBUG_DVB, "fe%d: pre_error_bit_count = %llu\n",
|
||||
fe->nr, uval);
|
||||
}
|
||||
if (!get_stat(fe->fd, DTV_STAT_ERROR_BLOCK_COUNT, &st) &&
|
||||
(st.stat[0].scale == FE_SCALE_COUNTER)) {
|
||||
uval = st.stat[0].uvalue;
|
||||
dbgprintf(DEBUG_DVB, "fe%d: error_block_count = %llu\n",
|
||||
fe->nr, uval);
|
||||
}
|
||||
if (!get_stat(fe->fd, DTV_STAT_TOTAL_BLOCK_COUNT, &st) &&
|
||||
(st.stat[0].scale == FE_SCALE_COUNTER)) {
|
||||
uval = st.stat[0].uvalue;
|
||||
dbgprintf(DEBUG_DVB, "fe%d: total_block_count = %llu\n",
|
||||
fe->nr, uval);
|
||||
}
|
||||
}
|
||||
|
||||
void dddvb_fe_handle(struct dddvb_fe *fe)
|
||||
{
|
||||
uint32_t newtune, count = 0, max, nolock = 0;
|
||||
int ret;
|
||||
|
||||
printf("fe_handle\n");
|
||||
|
||||
open_dmx(fe);
|
||||
printf("fe_handle 2\n");
|
||||
while (fe->state == 1) {
|
||||
pthread_mutex_lock(&fe->mutex);
|
||||
newtune = fe->n_tune;
|
||||
if (newtune == 1) {
|
||||
fe->n_tune = 0;
|
||||
if (!memcmp(fe->param.param, fe->n_param.param, sizeof(fe->param.param))) {
|
||||
dbgprintf(DEBUG_DVB, "same params\n");
|
||||
fe->tune = 2;
|
||||
count = 0;
|
||||
nolock = 10;
|
||||
max = 2;
|
||||
} else {
|
||||
memcpy(fe->param.param, fe->n_param.param, sizeof(fe->param.param));
|
||||
fe->tune = 1;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&fe->mutex);
|
||||
|
||||
switch (fe->tune) {
|
||||
case 1:
|
||||
dbgprintf(DEBUG_DVB, "fe %d tune\n", fe->nr);
|
||||
tune(fe);
|
||||
nolock = 0;
|
||||
count = 0;
|
||||
max = 2;
|
||||
dbgprintf(DEBUG_DVB, "fe %d tune done\n", fe->nr);
|
||||
fe->tune = 2;
|
||||
break;
|
||||
case 2:
|
||||
count++;
|
||||
if (count < max)
|
||||
break;
|
||||
count = 0;
|
||||
get_stats(fe);
|
||||
if (fe->lock) {
|
||||
max = 20;
|
||||
nolock = 0;
|
||||
} else {
|
||||
max = 1;
|
||||
nolock++;
|
||||
if (nolock > 100)
|
||||
fe->tune = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (fe->state != 1)
|
||||
break;
|
||||
usleep(50000);
|
||||
}
|
||||
close(fe->fd);
|
||||
if (fe->dmx > 0)
|
||||
close(fe->dmx);
|
||||
fe->fd = -1;
|
||||
fe->dmx = -1;
|
||||
fe->stat = fe->lock = fe->level = fe->quality = 0;
|
||||
fe->state = 0;
|
||||
dbgprintf(DEBUG_DVB, "fe %d done\n", fe->nr);
|
||||
}
|
||||
|
||||
int dddvb_fe_start(struct dddvb_fe *fe)
|
||||
{
|
||||
fe->dmx = -1;
|
||||
fe->tune = 0;
|
||||
dddvb_param_init(&fe->param);
|
||||
fe->first = 1;
|
||||
if (open_fe(fe))
|
||||
return -1;
|
||||
return pthread_create(&fe->pt, NULL, (void *) dddvb_fe_handle, fe);
|
||||
}
|
||||
|
||||
int dddvb_fe_tune(struct dddvb_fe *fe, struct dddvb_params *p)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
dbgprintf(DEBUG_DVB, "dvb_tune\n");
|
||||
pthread_mutex_lock(&fe->mutex);
|
||||
memcpy(fe->n_param.param, p->param, sizeof(fe->n_param.param));
|
||||
fe->n_tune = 1;
|
||||
pthread_mutex_unlock(&fe->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dddvb_fe_get(struct dddvb_fe *fe, struct dddvb_params *p)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
dbgprintf(DEBUG_DVB, "fe_get\n");
|
||||
pthread_mutex_lock(&fe->mutex);
|
||||
memcpy(fe->n_param.param, p->param, sizeof(fe->n_param.param));
|
||||
fe->n_tune = 1;
|
||||
pthread_mutex_unlock(&fe->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dddvb_fe_init(struct dddvb *dd, int a, int f, int fd)
|
||||
{
|
||||
struct dtv_properties dps;
|
||||
struct dtv_property dp[10];
|
||||
struct dddvb_fe *fe;
|
||||
int r;
|
||||
uint32_t i, ds;
|
||||
|
||||
fe = &dd->dvbfe[dd->dvbfe_num];
|
||||
|
||||
r = snprintf(fe->name, sizeof(fe->name), "/dev/dvb/adapter%d/frontend%d", a, f);
|
||||
if (r >= sizeof(fe->name))
|
||||
return -1;
|
||||
dbgprintf(DEBUG_DVB, "fe_init a=%d f=%d name=%s\n", a, f, fe->name);
|
||||
|
||||
dps.num = 1;
|
||||
dps.props = dp;
|
||||
dp[0].cmd = DTV_ENUM_DELSYS;
|
||||
r = ioctl(fd, FE_GET_PROPERTY, &dps);
|
||||
if (r < 0)
|
||||
return -1;
|
||||
for (i = 0; i < dp[0].u.buffer.len; i++) {
|
||||
ds = dp[0].u.buffer.data[i];
|
||||
dbgprintf(DEBUG_DVB, "delivery system %d\n", ds);
|
||||
fe->type |= (1UL << ds);
|
||||
}
|
||||
dbgprintf(DEBUG_DVB, "fe %d type = %08x\n", dd->dvbfe_num, fe->type);
|
||||
if (!fe->type)
|
||||
return -1;
|
||||
|
||||
fe->dd = dd;
|
||||
fe->anum = a;
|
||||
fe->fnum = f;
|
||||
fe->nr = dd->dvbfe_num;
|
||||
|
||||
dps.num = 1;
|
||||
dps.props = dp;
|
||||
dp[0].cmd = DTV_INPUT;
|
||||
r = ioctl(fd, FE_GET_PROPERTY, &dps);
|
||||
if (r < 0)
|
||||
return -1;
|
||||
#if 0
|
||||
for (i = 0; i < dp[0].u.buffer.len; i++) {
|
||||
fe->input[i] = dp[0].u.buffer.data[i];
|
||||
//dbgprintf(DEBUG_DVB, "input prop %u = %u\n", i, fe->input[i]);
|
||||
}
|
||||
if (fe->input[3]) {
|
||||
dd->has_feswitch = 1;
|
||||
if (!dd->scif_type && !msmode) {
|
||||
if (fe->input[2] >= fe->input[1]) {
|
||||
fe->type = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (fe->type & (1UL << SYS_DVBS2))
|
||||
dd->dvbs2num++;
|
||||
if (fe->type & (1UL << SYS_DVBT2))
|
||||
dd->dvbt2num++;
|
||||
else if (fe->type & (1UL << SYS_DVBT))
|
||||
dd->dvbtnum++;
|
||||
if (fe->type & (1UL << SYS_DVBC2))
|
||||
dd->dvbc2num++;
|
||||
else if (fe->type & (1UL << SYS_DVBC_ANNEX_A))
|
||||
dd->dvbcnum++;
|
||||
|
||||
dd->dvbfe_num++;
|
||||
pthread_mutex_init(&fe->mutex, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int scan_dvbfe(struct dddvb *dd)
|
||||
{
|
||||
int a, f, fd;
|
||||
char fname[80];
|
||||
|
||||
for (a = 0; a < 16; a++) {
|
||||
for (f = 0; f < 24; f++) {
|
||||
sprintf(fname, "/dev/dvb/adapter%d/frontend%d", a, f);
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
dddvb_fe_init(dd, a, f, fd);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
dbgprintf(DEBUG_DVB, "Found %d frontends\n", dd->dvbfe_num);
|
||||
}
|
||||
|
||||
void scif_config(struct dddvb *dd, char *name, char *val)
|
||||
{
|
||||
if (!name || !val)
|
||||
return;
|
||||
|
||||
if (!strncasecmp(name, "type", 4) &&
|
||||
val[0] >= 0x30 && val[0] <= 0x32) {
|
||||
dd->scif_type = val[0] - 0x30;
|
||||
dbgprintf(DEBUG_DVB, "setting type = %d\n", dd->scif_type);
|
||||
}
|
||||
if (!strncasecmp(name, "tuner", 5) &&
|
||||
name[5] >= 0x31 && name[5] <= 0x39) {
|
||||
int fe = strtol(name + 5, NULL, 10 );
|
||||
if (fe >= 0 && fe < DDDVB_MAX_DVB_FE) {
|
||||
char *end;
|
||||
unsigned long int nr = strtoul(val, &end, 10), freq = 0;
|
||||
|
||||
if (*end == ',') {
|
||||
val = end + 1;
|
||||
freq = strtoul(val, &end, 10);
|
||||
if (val == end)
|
||||
return;
|
||||
}
|
||||
fe--;
|
||||
if (nr == 0)
|
||||
dd->dvbfe[fe].scif_type = 0;
|
||||
else {
|
||||
dd->dvbfe[fe].scif_slot = nr - 1;
|
||||
dd->dvbfe[fe].scif_freq = freq;
|
||||
dd->dvbfe[fe].scif_type = dd->scif_type;
|
||||
}
|
||||
dbgprintf(DEBUG_DVB, "fe%d: type=%d, slot=%d, freq=%d\n", fe,
|
||||
dd->dvbfe[fe].scif_type,
|
||||
dd->dvbfe[fe].scif_slot,
|
||||
dd->dvbfe[fe].scif_freq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_lnb(struct dddvb *dd, int tuner,
|
||||
uint32_t source, uint32_t lof1, uint32_t lof2, uint32_t lofs)
|
||||
{
|
||||
int i, j;
|
||||
int i1 = 0, i2 = DDDVB_MAX_DVB_FE;
|
||||
int j1 = 0, j2 = DDDVB_MAX_SOURCE;
|
||||
|
||||
if (tuner > DDDVB_MAX_DVB_FE)
|
||||
return;
|
||||
if (source > DDDVB_MAX_SOURCE)
|
||||
return;
|
||||
|
||||
if (tuner) {
|
||||
i1 = tuner - 1;
|
||||
i2 = i1 + 1;
|
||||
}
|
||||
if (source) {
|
||||
j1 = source - 1;
|
||||
j2 = j1 + 1;
|
||||
}
|
||||
for (i = i1; i < i2; i++) {
|
||||
struct dddvb_fe *fe = &dd->dvbfe[i];
|
||||
for (j = j1; j < j2; j++) {
|
||||
dbgprintf(DEBUG_DVB, "setting %d %d %u %u %u\n",
|
||||
i, j, lof1, lof2, lofs);
|
||||
fe->lof1[j] = lof1;
|
||||
fe->lof2[j] = lof2;
|
||||
fe->lofs[j] = lofs;
|
||||
fe->prev_delay[j] = 250000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lnb_config(struct dddvb *dd, char *name, char *val)
|
||||
{
|
||||
static int lnb = -1;
|
||||
static uint32_t lof1, lof2, lofs, tuner, source;
|
||||
char *end;
|
||||
|
||||
if (!name || !val) {
|
||||
if (lnb >= 0)
|
||||
set_lnb(dd, tuner, source,
|
||||
lof1 * 1000, lof2 * 1000, lofs * 1000);
|
||||
lnb++;
|
||||
tuner = source = lof1 = lof2 = lofs = 0;
|
||||
return;
|
||||
}
|
||||
if (!strcasecmp(name, "tuner")) {
|
||||
tuner = strtoul(val, &end, 10);
|
||||
} else if (!strcasecmp(name, "source")) {
|
||||
source = strtoul(val, &end, 10);
|
||||
} else if (!strcasecmp(name, "lof1")) {
|
||||
lof1 = strtoul(val, &end, 10);
|
||||
} else if (!strcasecmp(name, "lof2")) {
|
||||
lof2 = strtoul(val, &end, 10);
|
||||
} else if (!strcasecmp(name, "lofs")) {
|
||||
lofs = strtoul(val, &end, 10);
|
||||
}
|
||||
}
|
||||
|
||||
int dddvb_dvb_init(struct dddvb *dd)
|
||||
{
|
||||
pthread_mutex_init(&dd->uni_lock, 0);
|
||||
scan_dvbfe(dd);
|
||||
parse_config(dd, "", "scif", &scif_config);
|
||||
set_lnb(dd, 0, 0, 9750000, 10600000, 11700000);
|
||||
parse_config(dd, "", "LNB", &lnb_config);
|
||||
}
|
||||
|
||||
|
||||
int dddvb_dvb_exit(struct dddvb *dd)
|
||||
{
|
||||
|
||||
|
||||
}
|
7
lib/src/dvb.h
Normal file
7
lib/src/dvb.h
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef _DDDVB_DVB_H_
|
||||
#define _DDDVB_DVB_H_
|
||||
|
||||
|
||||
#endif
|
||||
|
60
lib/src/fe.c
Normal file
60
lib/src/fe.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#if 0
|
||||
|
||||
static void release_fe(struct octoserve *os, struct dvbfe *fe)
|
||||
{
|
||||
if (!fe)
|
||||
return;
|
||||
dbgprintf(DEBUG_SYS, "release fe %d\n", fe->nr);
|
||||
fe->state = 2;
|
||||
pthread_join(fe->pt, NULL);
|
||||
}
|
||||
|
||||
static struct dvbfe *alloc_fe_num(struct octoserve *os, int i, int type)
|
||||
{
|
||||
struct dvbfe *fe;
|
||||
|
||||
if (i > os->dvbfe_num)
|
||||
return NULL;
|
||||
dbgprintf(DEBUG_SYS, "alloc_fe_num %d\n", i);
|
||||
pthread_mutex_lock(&os->lock);
|
||||
fe = &os->dvbfe[i];
|
||||
if (fe->state || !(fe->type & (1UL << type))) {
|
||||
pthread_mutex_unlock(&os->lock);
|
||||
return NULL;
|
||||
}
|
||||
fe->n_tune = 0;
|
||||
fe->state = 1;
|
||||
pthread_create(&fe->pt, NULL, (void *) handle_fe, fe);
|
||||
pthread_mutex_unlock(&os->lock);
|
||||
dbgprintf(DEBUG_SYS, "Allocated fe %d = %d/%d, fd=%d\n",
|
||||
fe->nr, fe->anum, fe->fnum, fe->fd);
|
||||
return fe;
|
||||
}
|
||||
|
||||
static struct dvbfe *alloc_fe(struct octoserve *os, int type)
|
||||
{
|
||||
int i;
|
||||
struct dvbfe *fe;
|
||||
|
||||
pthread_mutex_lock(&os->lock);
|
||||
for (i = 0; i < os->dvbfe_num; i++) {
|
||||
fe = &os->dvbfe[i];
|
||||
if (fe->state == 0 &&
|
||||
(fe->type & (1UL << type))) {
|
||||
pthread_mutex_unlock(&os->lock);
|
||||
return alloc_fe_num(os, i, type);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&os->lock);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct dddvb_fe *alloc_fe_num(struct dddvb *dd, int num, int type, int source)
|
||||
{
|
||||
if (num > dd->dvbfe_num)
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
}
|
115
lib/src/libdddvb.h
Normal file
115
lib/src/libdddvb.h
Normal file
@@ -0,0 +1,115 @@
|
||||
#ifndef _LIBDDDVB_H_
|
||||
#define _LIBDDDVB_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <linux/dvb/dmx.h>
|
||||
#include <linux/dvb/frontend.h>
|
||||
#include <linux/dvb/video.h>
|
||||
#include <linux/dvb/net.h>
|
||||
|
||||
|
||||
#define DDDVB_UNDEF (~0U)
|
||||
|
||||
#define PARAM_STREAMID 0
|
||||
#define PARAM_FE 1
|
||||
#define PARAM_SRC 3
|
||||
#define PARAM_FEC 4
|
||||
#define PARAM_FREQ 5
|
||||
#define PARAM_SR 6
|
||||
#define PARAM_POL 7
|
||||
#define PARAM_RO 8
|
||||
|
||||
#define PARAM_MSYS 9
|
||||
|
||||
#define PARAM_MTYPE 10
|
||||
#define PARAM_PLTS 11
|
||||
#define PARAM_BW 12
|
||||
#define PARAM_BW_HZ 13
|
||||
#define PARAM_TMODE 14
|
||||
#define PARAM_GI 15
|
||||
#define PARAM_PLP 16
|
||||
#define PARAM_ISI 16
|
||||
#define PARAM_PLS 17
|
||||
#define PARAM_T2ID 17
|
||||
#define PARAM_SM 18
|
||||
#define PARAM_C2TFT 19
|
||||
#define PARAM_DS 20
|
||||
#define PARAM_SPECINV 21
|
||||
|
||||
#define PARAM_CI 27
|
||||
#define PARAM_PMT 28
|
||||
#define PARAM_PID 29
|
||||
#define PARAM_APID 30
|
||||
#define PARAM_DPID 31
|
||||
|
||||
|
||||
#include "dddvb.h"
|
||||
|
||||
#if BUILDING_LIBDDDVB
|
||||
#define LIBDDDVB_EXPORTED __attribute__((__visibility__("default")))
|
||||
#else
|
||||
#define LIBDDDVB_EXPORTED
|
||||
#endif
|
||||
|
||||
LIBDDDVB_EXPORTED struct dddvb *dddvb_init(char *config, uint32_t flags);
|
||||
LIBDDDVB_EXPORTED int dddvb_dvb_tune(struct dddvb_fe *fe, struct dddvb_params *p);
|
||||
LIBDDDVB_EXPORTED struct dddvb_fe *dddvb_fe_alloc(struct dddvb *dd, uint32_t type);
|
||||
LIBDDDVB_EXPORTED struct dddvb_fe *dddvb_fe_alloc_num(struct dddvb *dd, uint32_t type, uint32_t num);
|
||||
|
||||
static inline void dddvb_set_frequency(struct dddvb_params *p, uint32_t freq) {
|
||||
p->param[PARAM_FREQ] = freq;
|
||||
};
|
||||
|
||||
static inline void dddvb_set_symbol_rate(struct dddvb_params *p, uint32_t srate) {
|
||||
p->param[PARAM_SR] = srate;
|
||||
};
|
||||
|
||||
static inline void dddvb_set_delsys(struct dddvb_params *p, enum fe_delivery_system delsys) {
|
||||
p->param[PARAM_MSYS] = delsys;
|
||||
};
|
||||
|
||||
static inline void dddvb_set_polarization(struct dddvb_params *p, uint32_t pol) {
|
||||
p->param[PARAM_POL] = pol;
|
||||
};
|
||||
|
||||
static inline void dddvb_set_src(struct dddvb_params *p, uint32_t src) {
|
||||
p->param[PARAM_SRC] = src;
|
||||
};
|
||||
|
||||
static inline void dddvb_set_fec(struct dddvb_params *p, enum fe_code_rate fec) {
|
||||
p->param[PARAM_FEC] = fec;
|
||||
};
|
||||
|
||||
static inline void dddvb_set_pls(struct dddvb_params *p, uint32_t pls) {
|
||||
p->param[PARAM_PLS] = pls;
|
||||
};
|
||||
|
||||
static inline void dddvb_set_id(struct dddvb_params *p, uint32_t id) {
|
||||
p->param[PARAM_ISI] = id;
|
||||
};
|
||||
|
||||
static inline uint32_t dddvb_get_stat(struct dddvb_fe *fe) {
|
||||
return fe->stat;
|
||||
};
|
||||
|
||||
static inline int64_t dddvb_get_strength(struct dddvb_fe *fe) {
|
||||
return fe->strength;
|
||||
};
|
||||
|
||||
static inline int64_t dddvb_get_cnr(struct dddvb_fe *fe) {
|
||||
return fe->cnr;
|
||||
};
|
||||
|
||||
static inline void dddvb_param_init(struct dddvb_params *p) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
p->param[i] = DDDVB_UNDEF;
|
||||
};
|
||||
|
||||
#endif /* _LIBDDDVB_H_ */
|
12
lib/src/tools.c
Normal file
12
lib/src/tools.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "time.h"
|
||||
|
||||
time_t mtime(time_t *t)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts))
|
||||
return 0;
|
||||
if (t)
|
||||
*t = ts.tv_sec;
|
||||
return ts.tv_sec;
|
||||
}
|
6
lib/src/tools.h
Normal file
6
lib/src/tools.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _DDDVB_TOOLS_H_
|
||||
#define _DDDVB_TOOLS_H_
|
||||
|
||||
time_t mtime(time_t *t);
|
||||
|
||||
#endif /* _DDDVB_TOOLS_H_ */
|
Reference in New Issue
Block a user