1
0
mirror of https://github.com/DigitalDevices/dddvb.git synced 2023-10-10 13:37:43 +02:00

Merge branch 'internal'

This commit is contained in:
Ralph Metzler 2018-09-17 14:35:04 +02:00
commit 405eb3e5b4
22 changed files with 2454 additions and 64 deletions

View File

@ -4,11 +4,16 @@ PWD := $(shell pwd)
MODDEFS := CONFIG_DVB_CORE=m CONFIG_DVB_DDBRIDGE=m CONFIG_DVB_DRXK=m CONFIG_DVB_TDA18271C2DD=m CONFIG_DVB_CXD2099=m CONFIG_DVB_LNBP21=m CONFIG_DVB_STV090x=m CONFIG_DVB_STV6110x=m CONFIG_DVB_STV0367=m CONFIG_DVB_TDA18212=m CONFIG_DVB_STV0367DD=m CONFIG_DVB_TDA18212DD=m CONFIG_DVB_OCTONET=m CONFIG_DVB_CXD2843=m CONFIG_DVB_STV0910=m CONFIG_DVB_STV6111=m CONFIG_DVB_LNBH25=m CONFIG_DVB_MXL5XX=m CONFIG_DVB_NET=m
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) $(MODDEFS) modules
$(MAKE) -C apps
libdddvb:
$(MAKE) -C lib
libdddvb-install:
$(MAKE) -C lib install
dep:
DIR=`pwd`; (cd $(TOPDIR); make SUBDIRS=$$DIR dep)

View File

@ -249,6 +249,10 @@ int main(int argc, char **argv)
fname="DVBBridgeV2B_DD01_0013_PRO.fpga";
printf("Octopus PRO\n");
break;
case 0x0020:
fname="DVBBridgeV2B_DD01_0020.fpga";
printf("Octopus GT Mini\n");
break;
case 0x0201:
fname="DVBModulatorV1B_DVBModulatorV1B.bit";
printf("Modulator\n");

View File

@ -1560,11 +1560,30 @@ static void dvb_input_detach(struct ddb_input *input)
static int dvb_register_adapters(struct ddb *dev)
{
int i, ret = 0;
int i, ret = 0, l = 0;
struct ddb_port *port;
struct dvb_adapter *adap;
if (adapter_alloc == 3 || dev->link[0].info->type == DDB_MOD ||
if (adapter_alloc == 4) {
for (i = 0; i < dev->port_num; i++) {
port = &dev->port[i];
if (port->lnr >= l) {
adap = port->dvb[0].adap;
ret = dvb_register_adapter(adap, "DDBridge", THIS_MODULE,
port->dev->dev,
adapter_nr);
if (ret < 0)
return ret;
port->dvb[0].adap_registered = 1;
l = port->lnr + 1;
}
port->dvb[0].adap = adap;
port->dvb[1].adap = adap;
}
return 0;
}
if (adapter_alloc >= 3 || dev->link[0].info->type == DDB_MOD ||
dev->link[0].info->type == DDB_OCTONET ||
dev->link[0].info->type == DDB_OCTOPRO ) {
port = &dev->port[0];
@ -1644,7 +1663,7 @@ static void dvb_unregister_adapters(struct ddb *dev)
struct ddb_port *port;
struct ddb_dvb *dvb;
for (i = 0; i < dev->link[0].info->port_num; i++) {
for (i = 0; i < dev->port_num; i++) {
port = &dev->port[i];
dvb = &port->dvb[0];

View File

@ -640,7 +640,7 @@ static const struct ddb_info ddb_m4 = {
};
static const struct ddb_info ddb_gtl_mini = {
.type = DDB_OCTONET,
.type = DDB_OCTOPUS,
.name = "Digital Devices Octopus GT Mini",
.regmap = &gtl_mini,
.port_num = 0,

View File

@ -473,7 +473,6 @@ extern struct mci_cfg ddb_max_m4_cfg;
int ddb_fe_attach_mci(struct ddb_input *input, u32 type)
{
struct ddb *dev = input->port->dev;
//struct i2c_adapter *i2c = &input->port->i2c->adap;
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
struct ddb_port *port = input->port;
struct ddb_link *link = &dev->link[port->lnr];
@ -514,8 +513,14 @@ int ddb_fe_attach_mci(struct ddb_input *input, u32 type)
dvb->fe->ops.diseqc_send_master_cmd = max_send_master_cmd;
dvb->fe->ops.diseqc_send_burst = max_send_burst;
dvb->fe->sec_priv = input;
dvb->set_input = dvb->fe->ops.set_input;
dvb->fe->ops.set_input = max_set_input;
switch (type) {
case DDB_TUNER_MCI_M4:
break;
default:
dvb->set_input = dvb->fe->ops.set_input;
dvb->fe->ops.set_input = max_set_input;
break;
}
dvb->input = tuner;
return 0;
}

View File

@ -93,17 +93,23 @@
/********************************************************/
#define SX8_DEMOD_STOPPED (0)
#define SX8_DEMOD_IQ_MODE (1)
#define SX8_DEMOD_WAIT_SIGNAL (2)
#define SX8_DEMOD_WAIT_MATYPE (3)
#define SX8_DEMOD_TIMEOUT (14)
#define SX8_DEMOD_LOCKED (15)
#define MCI_DEMOD_STOPPED (0)
#define MCI_DEMOD_WAIT_SIGNAL (2)
#define MCI_DEMOD_TIMEOUT (14)
#define MCI_DEMOD_LOCKED (15)
#define M4_DEMOD_STOPPED (0)
#define M4_DEMOD_WAIT_SIGNAL (1)
#define M4_DEMOD_TIMEOUT (14)
#define M4_DEMOD_LOCKED (15)
#define SX8_DEMOD_IQ_MODE (1)
#define SX8_DEMOD_WAIT_MATYPE (3)
#define M4_DEMOD_WAIT_TS (6)
#define M4_DEMOD_C2SCAN (16)
#define MCI_STATUS_OK (0x00)
#define MCI_STATUS_UNSUPPORTED (0x80)
#define MCI_STATUS_INVALID_PARAMETER (0xFC)
#define MCI_STATUS_RETRY (0xFD)
#define MCI_STATUS_NOT_READY (0xFE)
#define MCI_STATUS_ERROR (0xFF)
#define MCI_CMD_STOP (0x01)
#define MCI_CMD_GETSTATUS (0x02)
@ -111,11 +117,16 @@
#define MCI_CMD_RFPOWER (0x04)
#define MCI_CMD_SEARCH_DVBS (0x10)
#define MCI_CMD_SEARCH_ISDBS (0x11)
#define MCI_CMD_SEARCH_DVBC (0x20)
#define MCI_CMD_SEARCH_DVBT (0x21)
#define MCI_CMD_SEARCH_DVBT2 (0x22)
#define MCI_CMD_SEARCH_DVBC2 (0x23)
#define MCI_CMD_SEARCH_ISDBT (0x24)
#define MCI_CMD_SEARCH_ISDBC (0x25)
#define MCI_CMD_SEARCH_J83B (0x26)
#define MCI_CMD_GET_IQSYMBOL (0x30)
@ -126,13 +137,6 @@
#define MCI_BANDWIDTH_7MHZ (7)
#define MCI_BANDWIDTH_8MHZ (8)
#define M4_MODE_DVBSX (2)
#define M4_MODE_DVBC (3)
#define M4_MODE_DVBT (4)
#define M4_MODE_DVBT2 (5)
#define M4_MODE_DVBC2 (6)
#define M4_MODE_ISDBT (7)
#define SX8_CMD_INPUT_ENABLE (0x40)
#define SX8_CMD_INPUT_DISABLE (0x41)
#define SX8_CMD_START_IQ (0x42)
@ -140,15 +144,40 @@
#define SX8_CMD_ENABLE_IQOUTPUT (0x44)
#define SX8_CMD_DISABLE_IQOUTPUT (0x45)
#define M4_CMD_GET_T2_L1INFO (0x50)
#define M4_CMD_GET_C2_L1P2 (0x50)
#define M4_CMD_GET_L1INFO (0x50)
#define M4_CMD_GET_IDS (0x51)
#define M4_CMD_GET_DVBT_TPS (0x52)
#define M4_CMD_GET_BBHEADER (0x53)
#define M4_CMD_GET_ISDBT_TMCC (0x54)
#define M4_CMD_GET_ISDBS_TMCC (0x55)
#define M4_CMD_GET_ISDBC_TSMF (0x56)
#define MCI_STATUS_OK (0x00)
#define MCI_STATUS_UNSUPPORTED (0x80)
#define MCI_STATUS_RETRY (0xFD)
#define MCI_STATUS_NOT_READY (0xFE)
#define MCI_STATUS_ERROR (0xFF)
#define M4_L1INFO_SEL_PRE (0)
#define M4_L1INFO_SEL_DSINFO (1)
#define M4_L1INFO_SEL_PLPINFO (2)
#define M4_L1INFO_SEL_PLPINFO_C (3)
#define M4_L1INFO_SEL_SETID (0x80)
#define MCI_BANDWIDTH_EXTENSION (0x80) // currently used only for J83B in Japan
#define M4_MODE_DVBSX (2)
#define M4_MODE_DVBC (3)
#define M4_MODE_DVBT (4)
#define M4_MODE_DVBT2 (5)
#define M4_MODE_DVBC2 (6)
#define M4_MODE_J83B (7)
#define M4_MODE_ISDBT (8)
#define M4_MODE_ISDBC (9)
#define M4_MODE_ISDBS (10)
#define M4_DVBC_CONSTELLATION_16QAM (0)
#define M4_DVBC_CONSTELLATION_32QAM (1)
#define M4_DVBC_CONSTELLATION_64QAM (2) // also valid for J83B and ISDB-C
#define M4_DVBC_CONSTELLATION_128QAM (3)
#define M4_DVBC_CONSTELLATION_256QAM (4) // also valid for J83B and ISDB-C
#define M4_SIGNALINFO_FLAG_CHANGE (0x01)
#define M4_SIGNALINFO_FLAG_EWS (0x02)
#define MCI_SUCCESS(status) ((status & MCI_STATUS_UNSUPPORTED) == 0)
@ -181,6 +210,16 @@ struct mci_command {
u32 frequency_range;
} dvbs2_search;
struct {
u8 flags; /* Bit 0: 0 = TSID is Transport Stream ID, 1 = TSID is relative stream number */
u8 rsvd1[2];
u8 retry;
u32 frequency;
u32 rsvd2;
u16 rsvd3;
u16 tsid;
} isdbs_search;
struct {
u8 flags;
u8 bandwidth;
@ -228,6 +267,26 @@ struct mci_command {
u32 frequency;
} isdbt_search;
struct {
u8 flags; /* Bit 0: 0 = TSID is Transport Stream ID, 1 = TSID is relative stream number */
/* Bit 2..1: 0 = force single, 1 = force multi, 2 = auto detect */
u8 bandwidth;
u8 rsvd1;
u8 retry;
u32 frequency;
u32 rsvd2;
u16 onid;
u16 tsid;
} isdbc_search;
struct {
u8 flags;
u8 bandwidth;
u8 rsvd1;
u8 retry;
u32 frequency;
} j83b_Search;
struct {
u8 tap;
u8 rsvd;
@ -251,9 +310,9 @@ struct mci_command {
} sx8_input_enable;
struct {
u8 Offset; // Offset into list, must be multiple of 64
u8 Select; // 0 = Slices, 1 = PLPs (C2 Only)
u8 DataSlice; // DataSlice to get PLPList (C2 Only)
u8 offset; // Offset into list, must be multiple of 64
u8 select; // 0 = Slices, 1 = PLPs (C2 Only)
u8 data_slice; // DataSlice to get PLPList (C2 Only)
} get_ids;
struct {
@ -261,6 +320,9 @@ struct mci_command {
u8 id; // DataSliceID, PLPId
} get_l1_info;
struct {
u8 select; // 0 = Data PLP, 1 = Common PLP, only DVB-T2 and DVB-C2
} get_bb_header;
};
};
@ -273,13 +335,31 @@ struct mci_result {
u16 time;
};
};
union {
u32 result[27];
struct {
u8 Rsvd0[3];
u8 Flags;
u32 frequency; // actual frequency in Hz
u32 rsvd1;
s16 channel_power; // channel power in dBm x 100
s16 rsvd2;
s16 signal_to_noise; // SNR in dB x 100, Note: negativ values are valid in DVB-S2
s16 rsvd3;
u32 rsvd4;
u32 ber_numerator; /* Bit error rate: PreRS in DVB-S, PreBCH in DVB-S2X */
u32 ber_denominator;
u32 ber_rsvd1; // Place holder for modulation bit error rate
u32 ber_rsvd2;
} common_signal_info;
struct {
u8 standard; /* 1 = DVB-S, 2 = DVB-S2X */
u8 pls_code; /* puncture rate for DVB-S */
u8 roll_off; /* 2-0: rolloff */
u8 rsvd;
u8 flags;
u32 frequency; /* actual frequency in Hz */
u32 symbol_rate; /* actual symbolrate in Hz */
s16 channel_power; /* channel power in dBm x 100 */
@ -292,8 +372,9 @@ struct mci_result {
} dvbs2_signal_info;
struct {
u8 modulation;
u8 rsvd1[3];
u8 constellation;
u8 rsvd0[2];
u8 flags;
u32 frequency; /* actual frequency in Hz */
u32 symbol_rate; /* actual symbolrate in Hz */
s16 channel_power; /* channel power in dBm x 100 */
@ -306,9 +387,12 @@ struct mci_result {
} dvbc_signal_info;
struct {
u8 tps_25_32; /* Constellation (2), Hierarchy (3), Coderate HP (3) */
u8 tps_33_39; /* Coderate LP (3), Guardinterval (2), FFT (2), 0 (1) */
u16 tps_cell_id; /* Cell Identifier */
u8 modulation1; // bit 7..6: Constellation, bit 5..3 Hierachy, bit 2..0 CodeRate High
u8 modulation2; // bit 7..5: CodeRate Low, bit 4..3 Guard Interval, bit 2..1 FFT Mode
u8 Rsvd0;
u8 Flags;
//u16 tps_cell_id; /* Cell Identifier */
u32 frequency; /* actual frequency in Hz */
u32 rsvd1;
s16 channel_power; /* channel power in dBm x 100 */
@ -321,7 +405,8 @@ struct mci_result {
} dvbt_signal_info;
struct {
u32 rsvd0;
u8 rsvd0[3];
u8 flags;
u32 frequency; /* actual frequency in Hz */
u32 rsvd1;
s16 channel_power; /* channel power in dBm x 100 */
@ -333,8 +418,9 @@ struct mci_result {
u32 ber_denominator;
} dvbt2_signal_info;
struct { // Work in Progress
u32 rsvd0 ; // Cell Identifier
struct {
u8 rsvd0[3];
u8 flags;
u32 frequency; // actual frequency in Hz
u32 rsvd1; //
@ -348,7 +434,8 @@ struct mci_result {
} dvbc2_signal_info;
struct {
u32 rsvd0;
u8 rsvd0[3];
u8 flags;
u32 frequency; // actual frequency in Hz
u32 rsvd1; //
@ -357,23 +444,116 @@ struct mci_result {
s16 signal_to_noise; // SNR in dB x 100, Note: negativ values are valid in DVB-S2
s16 rsvd2;
u32 packet_errors; // Counter for packet errors. (set to 0 on Start command)
u32 ber_numerator; // Bit error rate: PreRS
u32 ber_denominator;
u8 tmcc_info[13]; // TMCC B20 - B121
u32 ber_denominator;
u32 ber_rsvd1; // Place holder for modulation bit error rate
u32 ber_rsvd2;
u32 ber_numeratorB; // Bit error rate: PreRS Segment B
u32 ber_numeratorC; // Bit error rate: PreRS Segment C
} isdbt_signal_info;
struct {
u8 Constellation;
u8 Rsvd0[2];
u8 Flags;
u32 Frequency; // actual frequency in Hz
u32 SymbolRate; // actual symbolrate in Hz
s16 ChannelPower; // channel power in dBm x 100
s16 BandPower; // band power in dBm x 100
s16 SignalToNoise; // SNR in dB x 100, Note: negativ values are valid in DVB-S2
s16 Rsvd2;
u32 PacketErrors; // Counter for packet errors. (set to 0 on Start command)
u32 BERNumerator; // Bit error rate: PreRS in DVB-S, PreBCH in DVB-S2X
u32 BERDenominator;
} ISDBC_SignalInfo;
struct {
u8 Constellation;
u8 Interleaving;
u8 Rsvd0;
u8 Flags;
u32 Frequency; // actual frequency in Hz
u32 SymbolRate; // actual symbolrate in Hz
s16 ChannelPower; // channel power in dBm x 100
s16 BandPower; // band power in dBm x 100
s16 SignalToNoise; // SNR in dB x 100, Note: negativ values are valid in DVB-S2
s16 Rsvd2;
u32 PacketErrors; // Counter for packet errors. (set to 0 on Start command)
u32 BERNumerator; // Bit error rate: PreRS in DVB-S, PreBCH in DVB-S2X
u32 BERDenominator;
} J83B_SignalInfo;
struct {
s16 i;
s16 q;
} iq_symbol;
struct {
u8 t2_l1_pre[37];
u8 t2_l1_post[15];
u8 t2_l1_post_d[19];
u8 t2_l1_post_c[19];
} dvbt2_l1_info;
u8 TPSInfo[7];
} DVBT_TPSInfo;
struct {
struct {
u8 Type;
u8 BWExtension;
u8 S1;
u8 S2;
u8 L1RepetitionFlag;
u8 GuardInterval;
u8 PAPR;
u8 L1Mod;
u8 L1Cod;
u8 L1FECType;
u8 L1PostSize[3];
u8 L1PostInfoSize[3];
u8 PilotPattern;
u8 TXIDAvailabilty;
u8 CellID[2];
u8 NetworkID[2];
u8 T2SystemID[2];
u8 NumT2Frames;
u8 NumDataSymbols[2];
u8 RegenFlag;
u8 L1PostExtension;
u8 NumRF;
u8 CurrentRFIndex;
u8 T2Version_PostScrambled_BaseLite_Rsvd[2]; // 4,1,1,4 bit
u8 CRC32[4];
} DVBT2_L1Pre;
struct {
u8 SubSlicesPerFrame[2];
u8 NumPLP;
u8 NumAux;
u8 AuxConfigRFU;
u8 RFIndex;
u8 Frequency[4];
u8 FEFType;
u8 FEFLength[3];
u8 FEFInterval;
} DVBT2_L1Post;
} DVBT2_L1Info;
struct {
u8 PLPID;
u8 Type;
u8 PayloadType;
u8 FFFlag;
u8 FirstRFIndex;
u8 FirstFrameIndex;
u8 GroupID;
u8 Cod;
u8 Mod;
u8 Rotation;
u8 FECType;
u8 NumBlocksMax[2];
u8 FrameInterval;
u8 TimeILLength;
u8 TimeILType;
u8 InBandAFlag;
u8 InBandBFlag_Rsvd1_Mode_StaticFlag_StaticPaddingFlag[2]; // 1,11,2,1,1
} DVBT2_PLPInfo;
struct {
u8 NetworkID[2];
@ -421,7 +601,7 @@ struct mci_result {
u8 PayloadType;
u8 GroupID;
u8 Start[2];
u8 FEC_Type;
u8 FECType;
u8 Mod;
u8 Cod;
u8 PSISIReprocessing;
@ -429,10 +609,46 @@ struct mci_result {
u8 OrginalNetworkID[2];
u8 Reserved1;
} DVBC2_PLPInfo;
struct {
u8 Valid;
u8 MATYPE_1;
u8 MATYPE_2;
u8 UPL[2];
u8 DFL[2];
u8 SYNC;
u8 SYNCD[2];
u8 rsvd;
u8 ISSY[3];
} BBHeader;
struct {
u8 Mode; // FFT Mode 1,2,3
u8 GuardInterval; // 1/32, 1/16, 1/8, /14
u8 TMCCInfo[13]; // TMCC B20 - B121, byte 0 bit 7: B20, byte 12 bit 2: B121
} ISDBT_TMCCInfo;
struct {
u8 Change; // 5 bits, increments with every change
struct {
u8 ModCod; // 4 bits
u8 NumSlots; // 6 bits
} Mode[4];
u8 RelTSID[24]; // bit 6..4 Relative TSID for slot i*2 + 1, bit 2..0 Relative TSID for slot i*2 + 2
struct {
u8 highByte;
u8 lowByte;
} TSID[8];
u8 Flags; // Bit 5: EWS flag, bit 4: Site Diversity flag, bit 3..1: Site Diversity information, bit 0: Extension flag
u8 Extension[8]; // 61 bits, right aligned
} ISDBS_TMCCInfo;
};
u32 version[4];
};
/* Helper Macros */
/* DVB-T2 L1-Pre Signalling Data ( ETSI EN 302 755 V1.4.1 Chapter 7.2.2 ) */

502
lib/COPYING.LGPLv2.1 Normal file
View File

@ -0,0 +1,502 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

23
lib/Makefile Normal file
View File

@ -0,0 +1,23 @@
all:
make -C ./src
make dddvb_test ddzap
install: all
cp -d src/libdddvb.so* /usr/local/lib
cp -d src/libdddvb.h /usr/local/include/
cp -d src/dddvb.h /usr/local/include/
cp -d ddzap /usr/local/bin
ldconfig
%.o: %.c
$(CC) $(CFLAGS) -fPIC -c $<
dddvb_test: dddvb_test.o
$(CC) -o dddvb_test $< -L ./src -l dddvb -l pthread
ddzap: ddzap.o
$(CC) -o ddzap $< -L ./src -l dddvb -l pthread
clean:
make -C ./src clean
rm *.o

19
lib/config/dddvb.conf Normal file
View File

@ -0,0 +1,19 @@
[scif]
# SCIF Settings
# Manufacturer = nn : Index to selected manaufacturer (only used in config webpage)
# Unit = nn : Index to selected unit (only used in config webpage)
# Type = nn : Type of unit: 1: EN 50494, 2: TS 50607
# TunerN = Slot,Frequency[,Pin] Slot = 1..nn, Frequency = 950..2150, Pin = 0-255
# Slot = 0 (no SCIF)
# Slot = 1..8 for EN 50494, 1..32 for TS 50607
Manufacturer=0
Unit=8
Type=2
Tuner1=1,1210
Tuner2=2,1420
Tuner3=3,1680
Tuner4=4,2040
Tuner5=5,984
Tuner6=6,1020
Tuner7=7,1056
Tuner8=8,1092

11
lib/dddvb_test.c Normal file
View File

@ -0,0 +1,11 @@
#include "src/libdddvb.h"
#include <stdio.h>
int main()
{
struct dddvb *dd = dddvb_init("", 0xffff);
if (!dd)
printf("dddvb_init failed\n");
printf("dvbnum = %u\n", dd->dvbfe_num);
}

152
lib/ddzap.c Normal file
View File

@ -0,0 +1,152 @@
#include <linux/dvb/frontend.h>
#include "src/libdddvb.h"
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <stdint.h>
#include <unistd.h>
static uint32_t root2gold(uint32_t root)
{
uint32_t x, g;
for (g = 0, x = 1; g < 0x3ffff; g++) {
if (root == x)
return g;
x = (((x ^ (x >> 7)) & 1) << 17) | (x >> 1);
}
return 0xffffffff;
}
int main(int argc, char **argv)
{
struct dddvb *dd;
struct dddvb_fe *fe;
struct dddvb_params p;
uint32_t frequency = 0, symbol_rate = 0, pol = DDDVB_UNDEF;
uint32_t id = DDDVB_UNDEF, pls = DDDVB_UNDEF, num = DDDVB_UNDEF;
enum fe_code_rate fec = FEC_AUTO;
enum fe_delivery_system delsys = ~0;
char *config = "config/";
while (1) {
int cur_optind = optind ? optind : 1;
int option_index = 0;
int c;
static struct option long_options[] = {
{"config", required_argument, 0, 'c'},
{"frequency", required_argument, 0, 'f'},
{"symbolrate", required_argument, 0, 's'},
{"delsys", required_argument, 0, 'd'},
{"id", required_argument, 0, 'i'},
{"pls", required_argument, 0, 'g'},
{"root", required_argument, 0, 'r'},
{"num", required_argument, 0, 'n'},
{"help", no_argument , 0, 'h'},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv,
"c:i:f:s:d:p:hg:r:n:",
long_options, &option_index);
if (c==-1)
break;
switch (c) {
case 'c':
config = strdup(optarg);
break;
case 'f':
frequency = strtoul(optarg, NULL, 0);
break;
case 's':
symbol_rate = strtoul(optarg, NULL, 0);
break;
case 'g':
pls = strtoul(optarg, NULL, 0);
break;
case 'r':
pls = root2gold(strtoul(optarg, NULL, 0));
break;
case 'i':
id = strtoul(optarg, NULL, 0);
break;
case 'n':
num = strtoul(optarg, NULL, 0);
break;
case 'd':
if (!strcmp(optarg, "C"))
delsys = SYS_DVBC_ANNEX_A;
if (!strcmp(optarg, "S"))
delsys = SYS_DVBS;
if (!strcmp(optarg, "S2"))
delsys = SYS_DVBS2;
if (!strcmp(optarg, "T"))
delsys = SYS_DVBT;
if (!strcmp(optarg, "T2"))
delsys = SYS_DVBT2;
break;
case 'p':
if (!strcmp(optarg, "h"))
pol = 1;
if (!strcmp(optarg, "v"))
pol = 0;
break;
case 'h':
printf("no help yet\n");
exit(-1);
default:
break;
}
}
if (optind < argc) {
printf("Warning: unused arguments\n");
}
if (delsys == ~0) {
printf("You have to choose a delivery system: -d (C|S|S2|T|T2)\n");
exit(-1);
}
switch (delsys) {
case SYS_DVBC_ANNEX_A:
if (!symbol_rate)
symbol_rate = 6900000;
break;
}
dd = dddvb_init(config, 0xffff);
if (!dd) {
printf("dddvb_init failed\n");
exit(-1);
}
printf("dvbnum = %u\n", dd->dvbfe_num);
if (num != DDDVB_UNDEF)
fe = dddvb_fe_alloc_num(dd, delsys, num);
else
fe = dddvb_fe_alloc(dd, delsys);
if (!fe) {
printf("dddvb_fe_alloc failed\n");
exit(-1);
}
dddvb_param_init(&p);
dddvb_set_frequency(&p, frequency);
dddvb_set_symbol_rate(&p, symbol_rate);
dddvb_set_polarization(&p, pol);
dddvb_set_delsys(&p, delsys);
dddvb_set_id(&p, id);
dddvb_set_pls(&p, pls);
dddvb_dvb_tune(fe, &p);
while (1) {
fe_status_t stat;
int64_t str, cnr;
stat = dddvb_get_stat(fe);
str = dddvb_get_strength(fe);
cnr = dddvb_get_cnr(fe);
printf("stat=%02x, str=%lld.%03llddB, snr=%lld.%03llddB \n",
stat, str/1000, abs(str%1000), cnr/1000, abs(cnr%1000));
sleep(1);
}
}

20
lib/src/Makefile Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View File

@ -0,0 +1,7 @@
#ifndef _DDDVB_DVB_H_
#define _DDDVB_DVB_H_
#endif

60
lib/src/fe.c Normal file
View 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
View 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
View 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
View File

@ -0,0 +1,6 @@
#ifndef _DDDVB_TOOLS_H_
#define _DDDVB_TOOLS_H_
time_t mtime(time_t *t);
#endif /* _DDDVB_TOOLS_H_ */