示例#1
0
文件: azap.c 项目: ThangCZ/dvb-apps
int main(int argc, char **argv)
{
	struct dvb_frontend_parameters frontend_param;
	char *homedir = getenv ("HOME");
	char *confname = NULL;
	char *channel = NULL;
	int adapter = 0, frontend = 0, demux = 0, dvr = 0;
	int vpid, apid, sid, pmtpid = 0;
	int pat_fd, pmt_fd;
	int frontend_fd, audio_fd, video_fd;
	int opt;
	int rec_psi = 0;

	while ((opt = getopt(argc, argv, "hrpn:a:f:d:c:")) != -1) {
		switch (opt) {
		case 'a':
			adapter = strtoul(optarg, NULL, 0);
			break;
		case 'f':
			frontend = strtoul(optarg, NULL, 0);
			break;
		case 'd':
			demux = strtoul(optarg, NULL, 0);
			break;
		case 'r':
			dvr = 1;
			break;
		case 'p':
			rec_psi = 1;
			break;
		case 'c':
			confname = optarg;
			break;
		case '?':
		case 'h':
		default:
			fprintf (stderr, usage, argv[0]);
			return -1;
		};
	}

	if (optind < argc)
		channel = argv[optind];

	if (!channel) {
		fprintf (stderr, usage, argv[0]);
		return -1;
	}

	snprintf (FRONTEND_DEV, sizeof(FRONTEND_DEV),
		  "/dev/dvb/adapter%i/frontend%i", adapter, frontend);

	snprintf (DEMUX_DEV, sizeof(DEMUX_DEV),
		  "/dev/dvb/adapter%i/demux%i", adapter, demux);

	printf ("using '%s' and '%s'\n", FRONTEND_DEV, DEMUX_DEV);

	if (!confname)
	{
		if (!homedir)
			ERROR ("$HOME not set");
		confname = malloc (strlen(homedir) + strlen(CHANNEL_FILE) + 1);
		memcpy (confname, homedir, strlen(homedir));
		memcpy (confname + strlen(homedir), CHANNEL_FILE,
	        	strlen(CHANNEL_FILE) + 1);
	}

	memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters));

	if (parse (confname, channel, &frontend_param, &vpid, &apid, &sid))
		return -1;

	if ((frontend_fd = open(FRONTEND_DEV, O_RDWR | O_NONBLOCK)) < 0) {
		PERROR ("failed opening '%s'", FRONTEND_DEV);
		return -1;
	}

	if (setup_frontend (frontend_fd, &frontend_param) < 0)
		return -1;


	if (rec_psi) {
		pmtpid = get_pmt_pid(DEMUX_DEV, sid);
		if (pmtpid <= 0) {
			fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid);
			return -1;
		}

		if ((pat_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
			perror("opening pat demux failed");
			return -1;
		}
		if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, dvr) < 0)
			return -1;

		if ((pmt_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
			perror("opening pmt demux failed");
			return -1;
		}
		if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, dvr) < 0)
			return -1;
	}

	if ((video_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
		PERROR("failed opening '%s'", DEMUX_DEV);
		return -1;
	}

	printf ("video pid 0x%04x, audio pid 0x%04x\n", vpid, apid);
	if (set_pesfilter (video_fd, vpid, DMX_PES_VIDEO, dvr) < 0)
		return -1;

	if ((audio_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
		PERROR("failed opening '%s'", DEMUX_DEV);
		return -1;
	}

	if (set_pesfilter (audio_fd, apid, DMX_PES_AUDIO, dvr) < 0)
		return -1;

	monitor_frontend (frontend_fd);

	close (pat_fd);
	close (pmt_fd);
	close (audio_fd);
	close (video_fd);
	close (frontend_fd);

	return 0;
}
示例#2
0
int main(int argc, char **argv)
{
	struct arguments args;
	char *homedir = getenv("HOME");
	char *channel = NULL;
	int lnb = -1, idx = -1;
	int vpid = -1, apid = -1, sid = -1;
	int pmtpid = 0;
	int pat_fd = -1, pmt_fd = -1;
	int audio_fd = 0, video_fd = 0;
	int dvr_fd, file_fd;
	struct dvb_v5_fe_parms *parms;
	const struct argp argp = {
		.options = options,
		.parser = parse_opt,
		.doc = "DVB zap utility",
		.args_doc = "<initial file>",
	};

	memset(&args, 0, sizeof(args));
	args.sat_number = -1;

	argp_parse(&argp, argc, argv, 0, &idx, &args);

	if (idx < argc)
		channel = argv[idx];

	if (!channel) {
		argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME);
		return -1;
	}

	if (args.input_format == FILE_UNKNOWN) {
		fprintf(stderr, "ERROR: Please specify a valid format\n");
		argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME);
		return -1;
	}

	if (args.lnb_name) {
		lnb = search_lnb(args.lnb_name);
		if (lnb < 0) {
			printf("Please select one of the LNBf's below:\n");
			print_all_lnb();
			exit(1);
		} else {
			printf("Using LNBf ");
			print_lnb(lnb);
		}
	}

	asprintf(&args.demux_dev,
		 "/dev/dvb/adapter%i/demux%i", args.adapter, args.demux);

	asprintf(&args.dvr_dev,
		 "/dev/dvb/adapter%i/dvr%i", args.adapter, args.demux);

	if (args.silent < 2)
		fprintf(stderr, "using demux '%s'\n", args.demux_dev);

	if (!args.confname) {
		if (!homedir)
			ERROR("$HOME not set");
		asprintf(&args.confname, "%s/.tzap/%i/%s",
			 homedir, args.adapter, CHANNEL_FILE);
		if (access(args.confname, R_OK))
			asprintf(&args.confname, "%s/.tzap/%s",
				homedir, CHANNEL_FILE);
	}
	printf("reading channels from file '%s'\n", args.confname);

	parms = dvb_fe_open(args.adapter, args.frontend, 0, 0);
	if (!parms)
		return -1;
	if (lnb)
		parms->lnb = get_lnb(lnb);
	if (args.sat_number > 0)
		parms->sat_number = args.sat_number % 3;
	parms->diseqc_wait = args.diseqc_wait;
	parms->freq_bpf = args.freq_bpf;

	if (parse(&args, parms, channel, &vpid, &apid, &sid))
		return -1;

	if (setup_frontend(&args, parms) < 0)
		return -1;

	if (args.frontend_only) {
		check_frontend(&args, parms);
		dvb_fe_close(parms);
		return 0;
	}

	if (args.rec_psi) {
		if (sid < 0) {
			fprintf(stderr, "Service id 0x%04x was not specified at the file\n",
				sid);
			return -1;
		}
		pmtpid = get_pmt_pid(args.demux_dev, sid);
		if (pmtpid <= 0) {
			fprintf(stderr, "couldn't find pmt-pid for sid %04x\n",
				sid);
			return -1;
		}

		if ((pat_fd = open(args.demux_dev, O_RDWR)) < 0) {
			perror("opening pat demux failed");
			return -1;
		}
		if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, args.dvr) < 0)
			return -1;

		if ((pmt_fd = open(args.demux_dev, O_RDWR)) < 0) {
			perror("opening pmt demux failed");
			return -1;
		}
		if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, args.dvr) < 0)
			return -1;
	}

	if (vpid >= 0) {
		if (args.silent < 2)
			fprintf(stderr, "video pid %d\n", vpid);
		if ((video_fd = open(args.demux_dev, O_RDWR)) < 0) {
			PERROR("failed opening '%s'", args.demux_dev);
			return -1;
		}
		if (set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, args.dvr) < 0)
			return -1;
	}

	if (apid >= 0) {
		if (args.silent < 2)
			fprintf(stderr, "audio pid %d\n", apid);
		if ((audio_fd = open(args.demux_dev, O_RDWR)) < 0) {
			PERROR("failed opening '%s'", args.demux_dev);
			return -1;
		}

		if (set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, args.dvr) < 0)
			return -1;
	}

	signal(SIGALRM, do_timeout);
	if (args.timeout > 0)
		alarm(args.timeout);

	if (args.record) {
		if (args.filename != NULL) {
			if (strcmp(args.filename, "-") != 0) {
				file_fd =
				    open(args.filename,
					 O_WRONLY | O_LARGEFILE | O_CREAT,
					 0644);
				if (file_fd < 0) {
					PERROR("open of '%s' failed",
					       args.filename);
					return -1;
				}
			} else {
				file_fd = 1;
			}
		} else {
			PERROR("Record mode but no filename!");
			return -1;
		}

		if ((dvr_fd = open(args.dvr_dev, O_RDONLY)) < 0) {
			PERROR("failed opening '%s'", args.dvr_dev);
			return -1;
		}
		if (args.silent < 2)
			print_frontend_stats(parms, args.human_readable);

		copy_to_file(dvr_fd, file_fd, args.timeout, args.silent);

		if (args.silent < 2)
			print_frontend_stats(parms, args.human_readable);
	} else {
		check_frontend(&args, parms);
	}

	close(pat_fd);
	close(pmt_fd);
	close(audio_fd);
	close(video_fd);
	dvb_fe_close(parms);

	return 0;
}
示例#3
0
文件: szap.c 项目: ThangCZ/dvb-apps
static
int zap_to(unsigned int adapter, unsigned int frontend, unsigned int demux,
      unsigned int sat_no, unsigned int freq, unsigned int pol,
      unsigned int sr, unsigned int vpid, unsigned int apid, int sid,
      int dvr, int rec_psi, int bypass, int human_readable)
{
	char fedev[128], dmxdev[128], auddev[128];
	static int fefd, dmxfda, dmxfdv, audiofd = -1, patfd, pmtfd;
	int pmtpid;
	uint32_t ifreq, mstd;
	int hiband, result;

	if (!fefd) {
		snprintf(fedev, sizeof(fedev), FRONTENDDEVICE, adapter, frontend);
		snprintf(dmxdev, sizeof(dmxdev), DEMUXDEVICE, adapter, demux);
		snprintf(auddev, sizeof(auddev), AUDIODEVICE, adapter, demux);
		printf("using '%s' and '%s'\n", fedev, dmxdev);

		if ((fefd = open(fedev, O_RDWR | O_NONBLOCK)) < 0) {
			perror("opening frontend failed");
			return FALSE;
		}
		if (check_frontend(fefd, FE_QPSK, &mstd) < 0) {
			close(fefd);
			return FALSE;
		}
		/* TODO! Some frontends need to be explicit delivery system */
		if ((dmxfdv = open(dmxdev, O_RDWR)) < 0) {
			perror("opening video demux failed");
			close(fefd);
			return FALSE;
		}

		if ((dmxfda = open(dmxdev, O_RDWR)) < 0) {
			perror("opening audio demux failed");
			close(fefd);
			return FALSE;
		}

		if (dvr == 0)	/* DMX_OUT_DECODER */
			audiofd = open(auddev, O_RDWR);

		if (rec_psi) {
			if ((patfd = open(dmxdev, O_RDWR)) < 0) {
				perror("opening pat demux failed");
				close(audiofd);
				close(dmxfda);
				close(dmxfdv);
				close(fefd);
				return FALSE;
			}
			if ((pmtfd = open(dmxdev, O_RDWR)) < 0) {
				perror("opening pmt demux failed");
				close(patfd);
				close(audiofd);
				close(dmxfda);
				close(dmxfdv);
				close(fefd);
				return FALSE;
			}
		}
	}

	hiband = 0;
	if (lnb_type.switch_val && lnb_type.high_val && freq >= lnb_type.switch_val)
		hiband = 1;

	if (hiband)
		ifreq = freq - lnb_type.high_val;
	else {
		if (freq < lnb_type.low_val)
			ifreq = lnb_type.low_val - freq;
		else
			ifreq = freq - lnb_type.low_val;
	}
	result = FALSE;

	if (diseqc(fefd, sat_no, pol, hiband))
	if (do_tune(fefd, ifreq, sr))
		if (set_pesfilter(dmxfdv, vpid, DMX_PES_VIDEO, dvr))
		if (audiofd >= 0)
		(void)ioctl(audiofd, AUDIO_SET_BYPASS_MODE, bypass);

		if (set_pesfilter(dmxfda, apid, DMX_PES_AUDIO, dvr)) {
			if (rec_psi) {
				pmtpid = get_pmt_pid(dmxdev, sid);
				if (pmtpid < 0) {
					result = FALSE;
				}
				if (pmtpid == 0) {
					fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid);
					result = FALSE;
				}
				if (set_pesfilter(patfd, 0, DMX_PES_OTHER, dvr))
					if (set_pesfilter(pmtfd, pmtpid, DMX_PES_OTHER, dvr))
						result = TRUE;
			} else {
				result = TRUE;
			}
		}

	monitor_frontend (fefd, dvr, human_readable);
	if (!interactive) {
		close(patfd);
		close(pmtfd);

		if (audiofd >= 0)
			close(audiofd);

		close(dmxfda);
		close(dmxfdv);
		close(fefd);
	}

	return result;
}
示例#4
0
void scan_sdt() {
    int fd_sdt;
    int n,seclen;
    int i,k;
    int max_k;
    unsigned char buf[4096];
    struct dmx_sct_filter_params sctFilterParams;
    int ca,service_id,loop_length;
    int pmt_pid;
    struct pollfd ufd;
    int section_number,last_section_number;

    if((fd_sdt = open(demuxdev[card],O_RDWR|O_NONBLOCK)) < 0) {
        perror("fd_sdt DEVICE: ");
        return;
    }

    sctFilterParams.pid=0x11;
    memset(&sctFilterParams.filter,0,sizeof(sctFilterParams.filter));
    sctFilterParams.timeout = 0;
    sctFilterParams.flags = DMX_IMMEDIATE_START;
    sctFilterParams.filter.filter[0]=0x42;
    sctFilterParams.filter.mask[0]=0xff;

    if (ioctl(fd_sdt,DMX_SET_FILTER,&sctFilterParams) < 0) {
        perror("SDT - DMX_SET_FILTER:");
        close(fd_sdt);
        return;
    }

    max_k=1;
//  printf("<sdt>\n");

    for (k=0; k<max_k; k++) {
        ufd.fd=fd_sdt;
        ufd.events=POLLPRI;
        if (poll(&ufd,1,20000) < 0 ) {
            fprintf(stderr,"TIMEOUT on read from fd_sdt\n");
            close(fd_sdt);
            return;
        }
        if (read(fd_sdt,buf,3)==3) {
            seclen=((buf[1] & 0x0f) << 8) | (buf[2] & 0xff);
            n = read(fd_sdt,buf+3,seclen);
            if (n==seclen) {
                seclen+=3;
//      printf("Read %d bytes\n",seclen);
                //    for (i=0;i<seclen+3;i++) { printf("%02x ",buf[i]); }
                /*      for (i=0;i< seclen;i++) {
                        printf("%02x ",buf[i]);
                        if ((i % 16)==15) {
                          printf("  ");
                          for (j=i-15;j<=i;j++) {
                             printf("%c",((buf[j]>31) && (buf[j]<=127)) ? buf[j] : '.');
                          }
                          printf("\n");
                        }
                      }
                */
                section_number=buf[6];
                last_section_number=buf[7];
                fprintf(stderr,"Read SDT section - section_number=%d, last_section_number=%d\n",section_number,last_section_number);
                max_k=buf[7]+1; // last_sec_num - read this many (+1) sections

                i=11;
                while (i < (seclen-4)) {
                    service_id=(buf[i]<<8)|buf[i+1];
                    i+=2;
                    i++;  // Skip a field
                    ca=(buf[i]&0x10)>>4;
                    loop_length=((buf[i]&0x0f)<<8)|buf[i+1];
                    pmt_pid = get_pmt_pid(service_id);
                    printf("<service id=\"%d\" pmt_pid=\"%d\" ca=\"%d\">\n",service_id,pmt_pid,ca);
                    i+=2;
                    parse_descriptors(loop_length,&buf[i],&transponder,&transponders);
                    i+=loop_length;
                    scan_pmt(pmt_pid,service_id,(service_id==pnr));
                    printf("</service>\n");
                }
            }  else {
示例#5
0
int main(int argc, char **argv)
{
	struct dvb_frontend_parameters frontend_param;
	char *homedir = getenv("HOME");
	char *confname = NULL;
	char *channel = NULL;
	int adapter = 0, frontend = 0, demux = 0, dvr = 0;
	int vpid, apid, sid, pmtpid = 0;
	int pat_fd, pmt_fd;
	int frontend_fd, audio_fd = 0, video_fd = 0, dvr_fd, file_fd;
	int opt;
	int record = 0;
	int frontend_only = 0;
	char *filename = NULL;
	int human_readable = 0, rec_psi = 0;

	while ((opt = getopt(argc, argv, "H?hrpxRsFSn:a:f:d:c:t:o:")) != -1) {
		switch (opt) {
		case 'a':
			adapter = strtoul(optarg, NULL, 0);
			break;
		case 'f':
			frontend = strtoul(optarg, NULL, 0);
			break;
		case 'd':
			demux = strtoul(optarg, NULL, 0);
			break;
		case 't':
			timeout = strtoul(optarg, NULL, 0);
			break;
		case 'o':
			filename = strdup(optarg);
			record=1;
			/* fall through */
		case 'r':
			dvr = 1;
			break;
		case 'p':
			rec_psi = 1;
			break;
		case 'x':
			exit_after_tuning = 1;
			break;
		case 'c':
			confname = optarg;
			break;
		case 's':
			silent = 1;
			break;
		case 'S':
			silent = 2;
			break;
		case 'F':
			frontend_only = 1;
			break;
		case 'H':
			human_readable = 1;
			break;
		case '?':
		case 'h':
		default:
			fprintf (stderr, usage, argv[0]);
			return -1;
		};
	}

	if (optind < argc)
		channel = argv[optind];

	if (!channel) {
		fprintf (stderr, usage, argv[0]);
		return -1;
	}
#if defined(ANDROID)
	snprintf(FRONTEND_DEV,
		 sizeof(FRONTEND_DEV),
		 "/dev/dvb%i.frontend%i",
	  	 adapter,
	  	 frontend);

	snprintf(DEMUX_DEV,
		 sizeof(DEMUX_DEV),
		 "/dev/dvb%i.demux%i",
	  	 adapter,
	  	 demux);

	snprintf(DVR_DEV,
		 sizeof(DVR_DEV),
		 "/dev/dvb%i.dvr%i",
	  	 adapter,
	  	 demux);
#else
	snprintf(FRONTEND_DEV,
		 sizeof(FRONTEND_DEV),
		 "/dev/dvb/adapter%i/frontend%i",
	  	 adapter,
	  	 frontend);

	snprintf(DEMUX_DEV,
		 sizeof(DEMUX_DEV),
		 "/dev/dvb/adapter%i/demux%i",
	  	 adapter,
	  	 demux);

	snprintf(DVR_DEV,
		 sizeof(DVR_DEV),
		 "/dev/dvb/adapter%i/dvr%i",
	  	 adapter,
	  	 demux);
#endif
	if (silent < 2)
		fprintf (stderr,"using '%s' and '%s'\n", FRONTEND_DEV, DEMUX_DEV);

	if (!confname) {
		int len = strlen(homedir) + strlen(CHANNEL_FILE) + 18;
		if (!homedir)
			ERROR ("$HOME not set");
		confname = malloc (len);
		snprintf(confname, len, "%s/.tzap/%i/%s", homedir, adapter, CHANNEL_FILE);
		if (access (confname, R_OK))
			snprintf(confname, len, "%s/.tzap/%s", homedir, CHANNEL_FILE);
	}
	printf("reading channels from file '%s'\n", confname);
	memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters));

	if (parse (confname, channel, &frontend_param, &vpid, &apid, &sid))
		return -1;

	if ((frontend_fd = open(FRONTEND_DEV, O_RDWR | O_NONBLOCK)) < 0) {
		PERROR ("failed opening '%s'", FRONTEND_DEV);
		return -1;
	}

	if (setup_frontend (frontend_fd, &frontend_param) < 0)
		return -1;

	if (frontend_only)
		goto just_the_frontend_dude;

	if (rec_psi) {
	    	pmtpid = get_pmt_pid(DEMUX_DEV, sid);
	    	if (pmtpid <= 0) {
			fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid);
			return -1;
	    	}

	    	if ((pat_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
			perror("opening pat demux failed");
			return -1;
	    	}
	    	if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, dvr) < 0)
			return -1;

	    	if ((pmt_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
			perror("opening pmt demux failed");
			return -1;
	    	}
	    	if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, dvr) < 0)
			return -1;
	}

	if ((video_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
		PERROR("failed opening '%s'", DEMUX_DEV);
		return -1;
	}

	if (silent<2)
		fprintf(stderr,"video pid 0x%04x, audio pid 0x%04x\n", vpid, apid);

	if (set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, dvr) < 0)
		return -1;

	if ((audio_fd = open(DEMUX_DEV, O_RDWR)) < 0) {
		PERROR("failed opening '%s'", DEMUX_DEV);
		return -1;
	}

	if (set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, dvr) < 0)
		return -1;

	signal(SIGALRM,do_timeout);
	if (timeout > 0)
		alarm(timeout);

	if (record) {
		if (filename!=NULL) {
			if (strcmp(filename,"-")!=0) {
				file_fd = open(filename,O_WRONLY|O_LARGEFILE|O_CREAT,0644);
				if (file_fd<0) {
					PERROR("open of '%s' failed",filename);
					return -1;
				}
			} else {
				file_fd=1;
			}
		} else {
			PERROR("Record mode but no filename!");
			return -1;
		}

		if ((dvr_fd = open(DVR_DEV, O_RDONLY)) < 0) {
	                PERROR("failed opening '%s'", DVR_DEV);
	                return -1;
	        }
		if (silent<2)
			print_frontend_stats(frontend_fd, human_readable);

		copy_to_file(dvr_fd,file_fd);

		if (silent<2)
			print_frontend_stats(frontend_fd, human_readable);
	} else {
just_the_frontend_dude:
		monitor_frontend(frontend_fd, human_readable);
	}

	close(pat_fd);
	close(pmt_fd);
	close(audio_fd);
	close(video_fd);
	close(frontend_fd);
	return 0;
}
示例#6
0
 void CAPMT::send(const int sid )
 {
#ifdef PMT_FILE
   unlink("/tmp/pmt.tmp");
#endif
   int fd=-1;
   int length;
   int k,ii;
   int pmt_pid=0;
//   FILE *fout;
   unsigned char buffer[4096];
   char *demux_dev;
   asprintf(&demux_dev, "/dev/dvb/adapter%d/demux%d",adapter,demux);
   esyslog("DEMUX: %s",demux_dev);
   if ((fd = open(demux_dev, O_RDWR)) < 0)
   {
      esyslog("DVPAPI: Error opening demux device");
   }
   else
   {
    if (set_filter(fd, 0) < 0)
    {
      esyslog("DVPAPI: Error in set filter pat");
    }
     if ((length = read_t(fd, buffer)) < 0)
     {
        esyslog("DVPAPI: Error in read read_t (pat)");
     }
     else
     {
       pmt_pid=get_pmt_pid(buffer, sid);
       if (pmt_pid==0)
       {
         esyslog("DVPAPI: Error pmt_pid not found");
       }
       else
       {
        if (set_filter_pmt(fd, pmt_pid) < 0)
        {
         esyslog("DVPAPI: Error in set pmt filter");
        }
        for (k=0; k<64; k++)
       {
         if ((length = read_t(fd, buffer)) < 0)
         {
           esyslog("DVPAPI: Error in read pmt\n");
         }
         if (sid==((buffer[4]<<8)+buffer[5]))
         {
           break;
         }
        }
        
        length=((buffer[2]&0xf)<<8) + buffer[3]+3;
        close(fd);  // just in case ;)
#ifdef PMT_FILE
              FILE *fout=fopen("/tmp/pmt.tmp","wt");
              for (k=0;k<length;k++)
              {
                putc(buffer[k+1],fout);
              }
             fclose (fout);
#else
        char* caPMT=(char*)malloc(1024);
   // http://cvs.tuxbox.org/lists/tuxbox-cvs-0208/msg00434.html
        isyslog("DVBAPI: :: CAMPT channelSid =0x%x(%d) ",sid,sid);
        memcpy(caPMT, "\x9F\x80\x32\x82\xFF\xFB\x03\xFF\xFF\x00\x00\x13\x00", 12);
        int toWrite=(length-12-4-1)+13+2;
        caPMT[4]=(toWrite)>>8;
        caPMT[5]=(toWrite)&0xff;
        // [6]=03
        caPMT[7] = buffer[4]; // program no
        caPMT[8] = buffer[5]; // progno
        //
        caPMT[11]=buffer[12]+1;    
        caPMT[12]=(char)demux; // demux id
        caPMT[13]=(char)adapter; // adapter id

        memcpy(caPMT+13+2,buffer+13,length-12-4-1);        

        if(camdSocket==0)
        {
        	camdSocket=socket(AF_LOCAL,SOCK_STREAM,0);
        	sockaddr_un serv_addr_un;
        	memset(&serv_addr_un,0,sizeof(serv_addr_un));
        	serv_addr_un.sun_family=AF_LOCAL;
        	snprintf(serv_addr_un.sun_path,sizeof(serv_addr_un.sun_path),"/tmp/camd.socket");
        	if(connect(camdSocket,(const sockaddr*)&serv_addr_un,sizeof(serv_addr_un))!=0)
        	{
               esyslog("DVPAPI: Canot connecto to /tmp/camd.socket, Do you have OSCam running?");
        	   camdSocket=0;
        	}
        }
        if(camdSocket!=0)
        {
          int wrote=write(camdSocket,caPMT,toWrite);
          isyslog("DVBAPI: :: CAMPT length=%d toWrite=%d wrote=%d",length,toWrite,wrote);
          if(wrote!=toWrite)
          {
              esyslog("DVPAPI: CAMPT:send failed");
        	  close(camdSocket);
        	  camdSocket=0;
          }
        }
        free(caPMT);
#endif
         }
      }
   }
   free(demux_dev);
 }