mirror of
https://github.com/DigitalDevices/dddvb.git
synced 2025-03-01 10:35:23 +00:00
decoding support
This commit is contained in:
parent
1124f00b34
commit
a1c604f212
173
lib/ddzap.c
173
lib/ddzap.c
@ -1,3 +1,4 @@
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#include "../include/linux/dvb/frontend.h"
|
||||
#include "src/libdddvb.h"
|
||||
#include <stdio.h>
|
||||
@ -14,6 +15,8 @@
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "dvb_filter.h"
|
||||
|
||||
char line_start[16] = "";
|
||||
char line_end[16] = "\r";
|
||||
|
||||
@ -23,6 +26,14 @@ uint32_t packets = 0;
|
||||
uint32_t payload_packets = 0;
|
||||
uint32_t packet_errors = 0;
|
||||
|
||||
|
||||
#define SYS_FILE 200
|
||||
uint16_t pmt_pid[16];
|
||||
uint32_t numpmt = 0;
|
||||
uint8_t *pmts[16];
|
||||
int32_t ci = -1;
|
||||
uint32_t loop = 1;
|
||||
|
||||
uint8_t cc[8192] = { 0 };
|
||||
|
||||
enum { IQ_RED=1, IQ_GREE, IQ_BLUE , IQ_EVIL, IQ_LOG_RED, IQ_LOG_GREEN, IQ_LOG_BLUE , IQ_LOG_EVIL , IQ_TEST, };
|
||||
@ -196,8 +207,8 @@ void pam_write (int fd, pamdata *iq){
|
||||
|
||||
void proc_ts(int i, uint8_t *buf)
|
||||
{
|
||||
uint16_t pid=0x1fff&((buf[1]<<8)|buf[2]);
|
||||
uint8_t ccin = buf[3] & 0x1F;
|
||||
uint16_t pid=0x1fff&((buf[1]<<8)|buf[2]);
|
||||
uint8_t ccin = buf[3] & 0x1F;
|
||||
|
||||
if (buf[0] == 0x47 && (buf[1] & 0x80) == 0) {
|
||||
if( pid != 8191 ) {
|
||||
@ -225,6 +236,34 @@ void proc_ts(int i, uint8_t *buf)
|
||||
|
||||
#define TSBUFSIZE (100*188)
|
||||
|
||||
void tscheck_orig(int ts)
|
||||
{
|
||||
uint8_t *buf;
|
||||
uint8_t id;
|
||||
int i, nts;
|
||||
int len;
|
||||
|
||||
buf=(uint8_t *)malloc(TSBUFSIZE);
|
||||
|
||||
while(1) {
|
||||
len=read(ts, buf, TSBUFSIZE);
|
||||
if (len<0)
|
||||
continue;
|
||||
if (len%188) { /* should not happen */
|
||||
printf("blah\n");
|
||||
continue;
|
||||
}
|
||||
if (buf[0]!=0x47) {
|
||||
printf("unaligned\n");
|
||||
read(ts, buf, 1);
|
||||
continue;
|
||||
}
|
||||
nts=len/188;
|
||||
for (i=0; i<nts; i++)
|
||||
proc_ts(i, buf+i*188);
|
||||
}
|
||||
}
|
||||
|
||||
void tscheck(int ts)
|
||||
{
|
||||
uint8_t *buf;
|
||||
@ -234,20 +273,19 @@ void tscheck(int ts)
|
||||
|
||||
buf=(uint8_t *)malloc(TSBUFSIZE);
|
||||
|
||||
|
||||
while(1) {
|
||||
while(1) {
|
||||
len=read(ts, buf, TSBUFSIZE);
|
||||
if (len<0) {
|
||||
if (len<0)
|
||||
continue;
|
||||
if (len%188) { /* should not happen */
|
||||
printf("blah\n");
|
||||
continue;
|
||||
}
|
||||
if (buf[0]!=0x47) {
|
||||
printf("unaligned\n");
|
||||
read(ts, buf, 1);
|
||||
continue;
|
||||
}
|
||||
if (len%188) { /* should not happen */
|
||||
printf("blah\n");
|
||||
continue;
|
||||
}
|
||||
nts=len/188;
|
||||
for (i=0; i<nts; i++)
|
||||
proc_ts(i, buf+i*188);
|
||||
@ -266,6 +304,63 @@ static uint32_t root2gold(uint32_t root)
|
||||
return 0xffffffff;
|
||||
}
|
||||
|
||||
ssize_t rread(int fd, void *buf, size_t count)
|
||||
{
|
||||
size_t len, todo=count;
|
||||
|
||||
while (todo) {
|
||||
len = read(fd, buf, todo);
|
||||
if (len < 0)
|
||||
return len;
|
||||
if (len == 0 && fd && loop!=1) {
|
||||
lseek64(fd, SEEK_SET, 0);
|
||||
loop -= loop ? 1 : 0;
|
||||
}
|
||||
buf+=len;
|
||||
todo-=len;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void decode(struct dddvb *dd, int fd)
|
||||
{
|
||||
uint8_t buf[200*188];
|
||||
uint8_t ts[188];
|
||||
struct dvbf_pid pidf[16];
|
||||
int pmt;
|
||||
ssize_t len;
|
||||
|
||||
|
||||
for (pmt = 0; pmt < numpmt; pmt++) {
|
||||
dvbf_init_pid(&pidf[pmt], pmt_pid[pmt]);
|
||||
do {
|
||||
len=rread(fd,ts,188);
|
||||
if (len < 0) {
|
||||
dprintf(2, "Error reading stream\n");
|
||||
exit(-1);
|
||||
}
|
||||
write(fileno(stdout),ts,188);
|
||||
}
|
||||
while (proc_pidf(&pidf[pmt], ts)<=0);
|
||||
dprintf(2, "PMT %u of %u\n", pmt, numpmt);
|
||||
dump(stderr, pidf[pmt].buf, pidf[pmt].len);
|
||||
pmts[pmt]=pidf[pmt].buf;
|
||||
}
|
||||
while (dddvb_ca_set_pmts(dd, ci, pmts) < 0)
|
||||
sleep(1);
|
||||
while (1) {
|
||||
rread(fd, buf, sizeof(buf));
|
||||
if (len < 0) {
|
||||
dprintf(2, "Error reading stream\n");
|
||||
exit(-1);
|
||||
}
|
||||
dddvb_ca_write(dd, ci, buf, sizeof(buf));
|
||||
dddvb_ca_read(dd, ci, buf, sizeof(buf));
|
||||
write(fileno(stdout),buf, sizeof(buf));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct dddvb *dd;
|
||||
@ -286,7 +381,7 @@ int main(int argc, char **argv)
|
||||
int color = 0;
|
||||
pamdata iq;
|
||||
|
||||
|
||||
memset(pmts, 0, sizeof(pmts));
|
||||
while (1) {
|
||||
int cur_optind = optind ? optind : 1;
|
||||
int option_index = 0;
|
||||
@ -311,16 +406,35 @@ int main(int argc, char **argv)
|
||||
{"nodvr", no_argument , 0, 'q'},
|
||||
{"pam", no_argument , 0, 'P'},
|
||||
{"pam_color", no_argument , 0, 'e'},
|
||||
{"decode", required_argument, 0, 'x'},
|
||||
{"loop", required_argument, 0, 'L'},
|
||||
{"help", no_argument , 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
c = getopt_long(argc, argv,
|
||||
"e:c:i:f:s:d:p:hg:r:n:b:l:v:m:ota:qP",
|
||||
"e:c:i:f:s:d:p:hg:r:n:b:l:v:m:ota:qPx:L:",
|
||||
long_options, &option_index);
|
||||
if (c==-1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'x':
|
||||
{
|
||||
int j;
|
||||
char *str,*estr;
|
||||
|
||||
for (numpmt = 0, str = optarg; numpmt < 17 && *str; numpmt++, str=*estr?estr+1:estr) {
|
||||
if (numpmt)
|
||||
pmt_pid[numpmt-1] = strtoul(str, &estr, 10);
|
||||
else
|
||||
ci = strtoul(str, &estr, 10);
|
||||
}
|
||||
numpmt--;
|
||||
odvr = 4;
|
||||
break;
|
||||
}
|
||||
case 'L':
|
||||
loop = strtoul(optarg, NULL, 0);
|
||||
case 'e':
|
||||
color = strtoul(optarg, NULL, 0);
|
||||
case 'P':
|
||||
@ -423,6 +537,8 @@ int main(int argc, char **argv)
|
||||
delsys = SYS_ISDBT;
|
||||
if (!strcmp(optarg, "ISDBS"))
|
||||
delsys = SYS_ISDBS;
|
||||
if (!strcmp(optarg, "FILE"))
|
||||
delsys = SYS_FILE;
|
||||
break;
|
||||
case 'p':
|
||||
if (!strcmp(optarg, "h") || !strcmp(optarg, "H"))
|
||||
@ -446,6 +562,7 @@ int main(int argc, char **argv)
|
||||
" [-a [display line] (display continuity check in line)]\n"
|
||||
" [-P (output IQ diagram as pam)]\n"
|
||||
" [-e [color] (use color for pam 0=green)]\n"
|
||||
" [-x cinum[,pmt0,pmt1,..,.pmt15]]\n"
|
||||
"\n"
|
||||
" delivery_system = C,S,S2,T,T2,J83B,ISDBC,ISDBT\n"
|
||||
" polarity = h/H,v/V\n"
|
||||
@ -456,9 +573,20 @@ int main(int argc, char **argv)
|
||||
|
||||
}
|
||||
}
|
||||
if (optind < argc) {
|
||||
fprintf(fout,"Warning: unused arguments\n");
|
||||
if (delsys==SYS_FILE) {
|
||||
if (optind >= argc) {
|
||||
fd = 0;
|
||||
} else {
|
||||
fd = open(argv[optind], O_RDONLY);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr,"error opening %s\n", argv[optind]);
|
||||
exit(-1);
|
||||
}
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
if (optind < argc)
|
||||
fprintf(fout,"Warning: unused arguments\n");
|
||||
|
||||
if (delsys == ~0) {
|
||||
fprintf(fout,"You have to choose a delivery system: -d (C|S|S2|T|T2)\n");
|
||||
@ -476,7 +604,12 @@ int main(int argc, char **argv)
|
||||
fprintf(fout,"dddvb_init failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
fprintf(fout,"dvbnum = %u\n", dd->dvbfe_num);
|
||||
if (delsys==SYS_FILE) {
|
||||
if (ci>=0)
|
||||
decode(dd, fd);
|
||||
fprintf(fout, "FILE delsys only alowed for decoding.\n");
|
||||
exit(-1);
|
||||
}
|
||||
dddvb_get_ts(dd, get_ts);
|
||||
|
||||
if (num != DDDVB_UNDEF)
|
||||
@ -499,14 +632,6 @@ int main(int argc, char **argv)
|
||||
dddvb_set_ssi(&p, ssi);
|
||||
dddvb_dvb_tune(fe, &p);
|
||||
|
||||
#if 0
|
||||
{
|
||||
uint8_t ts[188];
|
||||
|
||||
dddvb_ca_write(dd, 0, ts, 188);
|
||||
|
||||
}
|
||||
#endif
|
||||
if (!odvr){
|
||||
while (1) {
|
||||
fe_status_t stat;
|
||||
@ -523,9 +648,9 @@ int main(int argc, char **argv)
|
||||
sleep(1);
|
||||
}
|
||||
} else {
|
||||
#define BUFFSIZE (1024*188)
|
||||
fe_status_t stat;
|
||||
char filename[150];
|
||||
#define BUFFSIZE (1024*188)
|
||||
uint8_t buf[BUFFSIZE];
|
||||
|
||||
stat = 0;
|
||||
@ -571,6 +696,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
tscheck(fd);
|
||||
break;
|
||||
case 4:
|
||||
decode(dd, fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
201
lib/dvb_filter.h
Normal file
201
lib/dvb_filter.h
Normal file
@ -0,0 +1,201 @@
|
||||
static inline uint16_t seclen(const uint8_t *buf)
|
||||
{
|
||||
return 3+((buf[1]&0x0f)<<8)+buf[2];
|
||||
}
|
||||
|
||||
static inline uint16_t tspid(const uint8_t *buf)
|
||||
{
|
||||
return ((buf[1]&0x1f)<<8)+buf[2];
|
||||
}
|
||||
|
||||
static inline int tspayload(const uint8_t *tsp)
|
||||
{
|
||||
if (!(tsp[3] & 0x10))
|
||||
return 0;
|
||||
if (tsp[3] & 0x20)
|
||||
return (tsp[4] > 183) ? 0 : (183 - tsp[4]);
|
||||
return 184;
|
||||
}
|
||||
|
||||
static inline int tspaystart(const uint8_t *tsp)
|
||||
{
|
||||
if (!(tsp[3]&0x10))
|
||||
return 188;
|
||||
if (tsp[3]&0x20)
|
||||
return (tsp[4] >= 184) ? 188 : tsp[4]+5;
|
||||
return 4;
|
||||
}
|
||||
|
||||
static uint32_t dvb_crc_table[256] = {
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
|
||||
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
|
||||
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
||||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
|
||||
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
||||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
|
||||
0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
||||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
|
||||
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
||||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
|
||||
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
||||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
|
||||
0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
||||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
|
||||
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
||||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
|
||||
0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
||||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
|
||||
0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
||||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
|
||||
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
||||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
|
||||
0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
||||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
|
||||
0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
||||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
|
||||
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
||||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
|
||||
0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
||||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
|
||||
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
||||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
|
||||
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
||||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
|
||||
0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
||||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
|
||||
0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
||||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
|
||||
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
||||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
|
||||
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4};
|
||||
|
||||
uint32_t dvb_crc32(uint8_t *data, int len)
|
||||
{
|
||||
int i;
|
||||
uint32_t crc=0xffffffff;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
crc = (crc << 8) ^ dvb_crc_table[((crc >> 24) ^ *data++) & 0xff];
|
||||
return crc;
|
||||
}
|
||||
|
||||
struct dvbf_pid {
|
||||
uint16_t pid;
|
||||
uint8_t cc;
|
||||
uint16_t bufp;
|
||||
uint16_t len;
|
||||
uint8_t buf[4096];
|
||||
};
|
||||
|
||||
static inline void pidf_reset(struct dvbf_pid *pidf)
|
||||
{
|
||||
pidf->bufp = pidf->len = 0;
|
||||
}
|
||||
|
||||
void dvbf_init_pid(struct dvbf_pid *pidf, uint16_t pid)
|
||||
{
|
||||
pidf->pid = pid;
|
||||
pidf->cc = 0xff;
|
||||
pidf_reset(pidf);
|
||||
}
|
||||
|
||||
static inline void write_secbuf(struct dvbf_pid *p, uint8_t *tsp, int n)
|
||||
{
|
||||
memcpy(p->buf+p->bufp, tsp, n);
|
||||
p->bufp += n;
|
||||
}
|
||||
|
||||
static inline int validcc(struct dvbf_pid *p, uint8_t *tsp)
|
||||
{
|
||||
uint8_t newcc;
|
||||
int valid;
|
||||
|
||||
newcc = tsp[3] & 0x0f;
|
||||
if (p->cc == 0xff)
|
||||
valid=1;
|
||||
else
|
||||
valid = (((p->cc + 1) & 0x0f) == newcc) ? 1 : 0;
|
||||
p->cc = newcc;
|
||||
if (!valid)
|
||||
pidf_reset(p);
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
void dump(FILE *fp, uint8_t *b, int l)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (j = 0; j < l; j += 16, b += 16) {
|
||||
for (i = 0; i < 16; i++)
|
||||
if (i + j < l)
|
||||
fprintf(fp, "%02x ", b[i]);
|
||||
else
|
||||
fprintf(fp, " ");
|
||||
fprintf(fp, " | ");
|
||||
for (i = 0; i < 16; i++)
|
||||
if (i + j < l)
|
||||
fprintf(fp, "%c", (b[i] > 31 && b[i] < 127) ? b[i] : '.');
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void pidf_section(struct dvbf_pid *p)
|
||||
{
|
||||
dump(stderr, p->buf, p->len);
|
||||
}
|
||||
|
||||
|
||||
static int proc_pidf(struct dvbf_pid *p, uint8_t *tsp)
|
||||
{
|
||||
int pusoff, todo, off;
|
||||
|
||||
if (tspid(tsp) != p->pid)
|
||||
return 0;
|
||||
if (!(tsp[3] & 0x10)) //no payload
|
||||
return 0;
|
||||
todo = (tsp[3] & 0x20) ? // AF?
|
||||
((tsp[4] > 183) ? 0 : (183 - tsp[4])) :
|
||||
184;
|
||||
if (!todo)
|
||||
return 0;
|
||||
off = 188 - todo;
|
||||
pusoff = (tsp[1] & 0x40) ? tsp[off++] : todo;
|
||||
if (pusoff + off > 188)
|
||||
goto error;
|
||||
if (validcc(p, tsp) && pusoff && p->bufp) {
|
||||
int rlen = pusoff;
|
||||
if (p->len) {
|
||||
if (p->bufp + rlen > p->len)
|
||||
rlen = p->len - p->bufp;
|
||||
} else
|
||||
if (p->bufp + rlen > 4096)
|
||||
rlen = 4096 - p->bufp;
|
||||
write_secbuf(p, tsp + off, rlen);
|
||||
if (!p->len && p->bufp >= 3 && (p->len = seclen(p->buf)) > 4096)
|
||||
pidf_reset(p);
|
||||
else
|
||||
return 1;//pidf_section(p);
|
||||
}
|
||||
off += pusoff;
|
||||
while ((todo = 188 - off) > 0 && tsp[off] != 0xff) {
|
||||
pidf_reset(p);
|
||||
if (todo < 3 || (p->len = seclen(tsp+off)) > todo) {
|
||||
if (p->len > 4096)
|
||||
goto error;
|
||||
write_secbuf(p, tsp+off, todo);
|
||||
off+=todo;
|
||||
} else {
|
||||
write_secbuf(p, tsp+off, p->len);
|
||||
off+=p->len;
|
||||
return 2;//pidf_section(p);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
error:
|
||||
pidf_reset(p);
|
||||
return -1;
|
||||
}
|
62
lib/src/ca.c
62
lib/src/ca.c
@ -7,6 +7,7 @@
|
||||
#include <linux/dvb/frontend.h>
|
||||
#include <linux/dvb/video.h>
|
||||
#include <linux/dvb/net.h>
|
||||
#include <linux/dvb/ca.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -252,6 +253,24 @@ static int handle_pmts(struct dddvb_ca *ca)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dump(FILE *fp, uint8_t *b, int l)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (j = 0; j < l; j += 16, b += 16) {
|
||||
for (i = 0; i < 16; i++)
|
||||
if (i + j < l)
|
||||
fprintf(fp, "%02x ", b[i]);
|
||||
else
|
||||
fprintf(fp, " ");
|
||||
fprintf(fp, " | ");
|
||||
for (i = 0; i < 16; i++)
|
||||
if (i + j < l)
|
||||
fprintf(fp, "%c", (b[i] > 31 && b[i] < 127) ? b[i] : '.');
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
static int set_pmts(struct dddvb_ca *ca, uint8_t **pmts)
|
||||
{
|
||||
int listmgmt = CA_LIST_MANAGEMENT_ONLY;
|
||||
@ -273,10 +292,26 @@ static int set_pmts(struct dddvb_ca *ca, uint8_t **pmts)
|
||||
len = ((sec[1] & 0x0f) << 8) | sec[2];
|
||||
len += 3;
|
||||
memcpy(sec, pmts[i], len);
|
||||
//dump(stderr, sec, len);
|
||||
section = section_codec(sec, len);
|
||||
if (!section) {
|
||||
dbgprintf(DEBUG_CA, "section_codec failed\n");;
|
||||
continue;
|
||||
}
|
||||
section_ext = section_ext_decode(section, 0);
|
||||
if (!section_ext) {
|
||||
dbgprintf(DEBUG_CA, "section_ext_decode failed\n");;
|
||||
continue;
|
||||
}
|
||||
pmt = mpeg_pmt_section_codec(section_ext);
|
||||
|
||||
//pmt = (struct mpeg_pmt_section *) section_ext;
|
||||
if (!pmt) {
|
||||
dbgprintf(DEBUG_CA, "mpeg_pmt_section_codec failed\n");;
|
||||
continue;
|
||||
}
|
||||
|
||||
dbgprintf(DEBUG_CA, "PMT = %p section=%p\n", pmt, section);
|
||||
|
||||
ca->ca_pmt_version[i] = section_ext->version_number;
|
||||
if (ca->sentpmt) {
|
||||
//return 0;
|
||||
@ -291,14 +326,16 @@ static int set_pmts(struct dddvb_ca *ca, uint8_t **pmts)
|
||||
listmgmt = CA_LIST_MANAGEMENT_LAST;
|
||||
}
|
||||
}
|
||||
dbgprintf(DEBUG_CA, "set ca_pmt\n");
|
||||
|
||||
//dump(stderr, (uint8_t *) pmt, len);
|
||||
dbgprintf(DEBUG_CA, "format ca_pmt %p length %u\n", pmt, len);
|
||||
|
||||
if ((size = en50221_ca_format_pmt(pmt, capmt, sizeof(capmt), ca->moveca, listmgmt,
|
||||
CA_PMT_CMD_ID_OK_DESCRAMBLING)) < 0) {
|
||||
dbgprintf(DEBUG_CA, "Failed to format PMT\n");
|
||||
return -1;
|
||||
}
|
||||
//dump(capmt, size);
|
||||
dbgprintf(DEBUG_CA, "set ca_pmt\n");
|
||||
if (en50221_app_ca_pmt(ca->stdcam->ca_resource, ca->stdcam->ca_session_number, capmt, size)) {
|
||||
dbgprintf(DEBUG_CA, "Failed to send PMT\n");
|
||||
return -1;
|
||||
@ -585,7 +622,7 @@ static int mmi_menu_callback(void *arg, uint8_t slot_id, uint16_t snum,
|
||||
|
||||
|
||||
static int init_ca_stack(struct dddvb_ca *ca)
|
||||
{
|
||||
{
|
||||
ca->tl = en50221_tl_create(1, 16);
|
||||
if (ca->tl == NULL) {
|
||||
dbgprintf(DEBUG_CA, "Failed to create transport layer\n");
|
||||
@ -625,6 +662,19 @@ static int init_ca_stack(struct dddvb_ca *ca)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cam_reset(int fd)
|
||||
{
|
||||
ca_slot_info_t info;
|
||||
|
||||
info.num = 0;
|
||||
if (ioctl(fd, CA_GET_SLOT_INFO, &info))
|
||||
return;
|
||||
if (info.flags & CA_CI_MODULE_READY)
|
||||
return;
|
||||
if (!(info.flags & CA_CI_MODULE_PRESENT))
|
||||
return;
|
||||
ioctl(fd, CA_RESET);
|
||||
}
|
||||
|
||||
static int init_ca(struct dddvb *dd, int a, int f, int fd)
|
||||
{
|
||||
@ -640,6 +690,8 @@ static int init_ca(struct dddvb *dd, int a, int f, int fd)
|
||||
ca->nr = dd->dvbca_num + 1;
|
||||
ca->fd = fd;
|
||||
pthread_mutex_init(&ca->mutex, 0);
|
||||
|
||||
//cam_reset(fd);
|
||||
|
||||
init_ca_stack(ca);
|
||||
|
||||
@ -671,7 +723,7 @@ int dddvb_ca_set_pmts(struct dddvb *dd, uint32_t nr, uint8_t **pmts)
|
||||
{
|
||||
struct dddvb_ca *ca = &dd->dvbca[nr];
|
||||
|
||||
dbgprintf(DEBUG_CA, "ca_set_pmt\n");
|
||||
dbgprintf(DEBUG_CA, "ca%u.%u.%u:ca_set_pmt\n", ca->nr,ca->anum,ca->fnum);
|
||||
return set_pmts(ca, pmts);
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ LIBDDDVB_EXPORTED struct dddvb *dddvb_init(char *config, uint32_t flags)
|
||||
struct dddvb *dd;
|
||||
pthread_mutexattr_t mta;
|
||||
|
||||
dddvb_debug = flags;
|
||||
dddvb_debug = flags & 0xff;
|
||||
|
||||
pthread_mutex_lock(&dddvb_mutex);
|
||||
if (global_dd) {
|
||||
@ -90,9 +90,11 @@ LIBDDDVB_EXPORTED struct dddvb *dddvb_init(char *config, uint32_t flags)
|
||||
pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&dd->lock, &mta);
|
||||
|
||||
dd->get_ts = (flags & 0x100) ? 0 : 1;
|
||||
dd->use_ca = (flags & 0x200) ? 0 : 1;
|
||||
|
||||
dddvb_dvb_init(dd);
|
||||
global_dd = dd;
|
||||
dd->get_ts = 1;
|
||||
fail:
|
||||
pthread_mutex_unlock(&dddvb_mutex);
|
||||
return dd;
|
||||
|
@ -158,7 +158,8 @@ struct dddvb {
|
||||
unsigned int cam_proto;
|
||||
unsigned int cam_port;
|
||||
|
||||
unsigned int get_ts:1;
|
||||
unsigned int get_ts;
|
||||
unsigned int use_ca;
|
||||
};
|
||||
|
||||
int dddvb_dvb_init(struct dddvb *dd);
|
||||
|
@ -605,6 +605,7 @@ int open_dmx(struct dddvb_fe *fe)
|
||||
struct dmx_pes_filter_params pesFilterParams;
|
||||
|
||||
sprintf(fname, "/dev/dvb/adapter%u/demux%u", fe->anum, fe->fnum);
|
||||
dbgprintf(DEBUG_DVB, "open %s\n", fname);
|
||||
|
||||
fe->dmx = open(fname, O_RDWR);
|
||||
if (fe->dmx < 0)
|
||||
@ -690,7 +691,6 @@ void dddvb_fe_handle(struct dddvb_fe *fe)
|
||||
uint32_t newtune, count = 0, max, nolock = 0;
|
||||
int ret;
|
||||
|
||||
|
||||
if (fe->dd->get_ts)
|
||||
open_dmx(fe);
|
||||
while (fe->state == 1) {
|
||||
@ -727,13 +727,14 @@ void dddvb_fe_handle(struct dddvb_fe *fe)
|
||||
break;
|
||||
count = 0;
|
||||
get_stats(fe);
|
||||
dbgprintf(DEBUG_DVB, "fe: nolock = %u, stat = %u\n", nolock, fe->stat);
|
||||
if (fe->lock) {
|
||||
max = 20;
|
||||
nolock = 0;
|
||||
} else {
|
||||
max = 1;
|
||||
nolock++;
|
||||
if (nolock > 40)
|
||||
if (nolock > 200 || fe->stat == FE_TIMEDOUT)
|
||||
fe->tune = 1;
|
||||
}
|
||||
break;
|
||||
@ -799,7 +800,7 @@ static int dddvb_fe_init(struct dddvb *dd, int a, int f, int fd)
|
||||
int r;
|
||||
uint32_t i, ds;
|
||||
|
||||
if (dd->dvbca_num >= DDDVB_MAX_DVB_CA)
|
||||
if (dd->dvbfe_num >= DDDVB_MAX_DVB_FE)
|
||||
return -1;
|
||||
fe = &dd->dvbfe[dd->dvbfe_num];
|
||||
|
||||
@ -1034,7 +1035,8 @@ int dddvb_dvb_init(struct dddvb *dd)
|
||||
if (dd->cam_port == 0)
|
||||
dd->cam_port = 8888;
|
||||
}
|
||||
scan_dvbca(dd);
|
||||
if (dd->use_ca)
|
||||
scan_dvbca(dd);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user