pike.git / src / modules / DVB / dvb.c

version» Context lines:

pike.git/src/modules/DVB/dvb.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: dvb.c,v 1.13 2002/10/21 17:06:12 marcus Exp $ + || $Id: dvb.c,v 1.14 2002/11/08 12:06:19 hop Exp $   */      /*    * DVB module    *    * Creator: Honza Petrous <hop@unibase.cz>    *    * Credits:    * + Tuner zapping code inspired on 'szap' app from linux DVB driver    * package
pike.git/src/modules/DVB/dvb.c:78:   #include "operators.h"      #include "dvb.h"         /* WARNING: It is a design limit of DVB-S full cards! */   #define MAX_PES_FD 8      #define _DMX_PES_RDS 129    - #define MAX_DVB_READ_SIZE 4096 + #define MAX_DVB_READ_SIZE 9192   #define MAX_ERR_LEN 160      struct program *dvb_program;   struct program *dvb_stream_program;      struct dvb_stream_data_struct;      typedef struct {    int cardn;    int fefd;
pike.git/src/modules/DVB/dvb.c:117:    int ecm_pid;    int id;   };      typedef struct dvb_stream_data_struct {    dvb_data *parent;    struct dvb_stream_data_struct *next;    int fd;    unsigned int pid;    unsigned int stype; -  dvb_avpacket pkt; +  struct dvb_es_packet pkt;    unsigned int buflen;    struct svalue fcb; -  dvb_p2p p; +     struct ECMINFO *ecminfo;    char low_errmsg[MAX_ERR_LEN+1];   } dvb_stream_data;      #define DVBStream ((dvb_stream_data *)Pike_fp->current_storage)      /* internals */      int sl_count(dvb_data *parent) {    dvb_stream_data *st = parent->stream;
pike.git/src/modules/DVB/dvb.c:704:       struct pollfd u[1];    int retries;    int n,l;       for (retries=0;retries<100;retries++)    {    u[0].fd = fd;    u[0].events = POLLIN;    -  //THREAD_ALLOW(); +  THREAD_ALLOW();    n = poll(u,1,20000); -  //THREAD_DISALLOW(); +  THREAD_DISALLOW();    if (n < 0)    {    perror("poll error");    return -1;    }    if (n == 0)    {    fprintf(stderr,"timeout\n");    return -1;    }       buffer[0] = 0;    -  //THREAD_ALLOW(); +  THREAD_ALLOW();    n = read(fd,buffer+1,length-1); -  //THREAD_DISALLOW(); +  THREAD_DISALLOW();    if (n < 0)    {    perror("read error");    return -1;    }       if (cks && crc32(buffer+1,n) != 0)    {    fprintf(stderr,"crc error\n"); //FIXME: ???    continue;
pike.git/src/modules/DVB/dvb.c:1245:    printf("DEB: dvb: set_pes: PID=%d, type=%d\n", pid, ptype);   #endif    THREADS_ALLOW();    err = ioctl(fd, DMX_SET_PES_FILTER, &pesflt);    THREADS_DISALLOW();    if (err < 0)    Pike_error("seting PID failed.\n");       if((pktdata = malloc(DVBStream->buflen)) == NULL)    Pike_error("Internal error: can't malloc buffer.\n"); + #if 0    if(init_p2p(&DVBStream->p, 2048))    Pike_error("Internal error: repack size %d is out of range\n", 2048); -  + #endif    DVBStream->parent = dvbstor; -  DVBStream->p.filter = 0xC0; //FIXME: 0xC0 = audio, ... -  DVBStream->p.es = 1; +     DVBStream->fd = fd;    DVBStream->pid = pid;    DVBStream->stype = ptype; -  DVBStream->pkt.data = pktdata; -  DVBStream->pkt.size = 0; +  DVBStream->pkt.payload = pktdata; +  DVBStream->pkt.payload_len = 0;    /*DVB->pesfcb[ix] = NULL;*/    //fcntl(DVBStream->fd, F_SETFL, O_NONBLOCK);   #if 0    push_int(1);   #else    if(sl_add(dvbstor, DVBStream))    push_int(1);    else    push_int(0);   #endif
pike.git/src/modules/DVB/dvb.c:1284:    */   static void f_stream_detach(INT32 args) {       pop_n_elems(args);    close(DVBStream->fd);   #ifdef DVB_DEBUG    printf("DEB: dvb: stream_detach: pid=%d detached OK\n", DVBStream->pid);   #endif    DVBStream->pid = 0;    DVBStream->fd = -1; -  if(DVBStream->pkt.data != NULL) -  free(DVBStream->pkt.data); -  DVBStream->pkt.data = NULL; +  if(DVBStream->pkt.payload != NULL) +  free(DVBStream->pkt.payload); +  DVBStream->pkt.payload = NULL;    push_int(1);      }      /*! @decl string|int read()    *!    *! Read data from a stream. It reads up to read buffer size data.    *!    *! @note    *! Read buffer size is 4096 by default.    *!    *! @seealso    *! @[DVB.dvb()->stream()], @[close()]    */   static void f_stream_read(INT32 args) {    -  int all = 1, ret, e; -  unsigned int cnt, ix = 0; +  int all = 1, ret, e, cnt, ix = 0;    char buf[MAX_DVB_READ_SIZE], *bufptr;       if(DVBStream->fd < 0)    Pike_error("Object destroyed!\n");       check_all_args("DVB.dvb->stream_read", args, BIT_INT | BIT_VOID, 0);    if(args > 1)    all = (u_short)Pike_sp[-1].u.integer;    pop_n_elems(args);    -  DVBStream->pkt.size = 0; +  if(DVBStream->pkt.payload_len > 0) +  memcpy(buf, DVBStream->pkt.payload, DVBStream->pkt.payload_len);    for(;;) {    e = 0;    THREADS_ALLOW(); -  ret = read(DVBStream->fd, buf, DVBStream->buflen); +  ret = read(DVBStream->fd, buf + DVBStream->pkt.payload_len, +  DVBStream->buflen - DVBStream->pkt.payload_len);    e = errno; /* check_threads_etc may effect errno */    THREADS_DISALLOW();       //check_threads_etc();    -  if (ret > 0) +  if (ret > 0) { +  ret += DVBStream->pkt.payload_len;    break; -  +  }    if (ret == -1 && (e == EAGAIN || e == EINTR)) {    push_int(0);    return;    }   #if 0    if (!(ret == 0) || (ret == -1 && (e == EAGAIN || e == EINTR))) {   #ifdef DEBUG    printf("DEB: dvb: stream_read: errno=%d [%s]\n", e, strerror(e));   #endif    push_int(-e);    return;    }   #endif    }       if(ret > 0) {    bufptr = buf; -  while((cnt = get_pes_filt(bufptr,ret,&DVBStream->p, &DVBStream->pkt)) > 0) { +  while((cnt = dvb_pes2es(bufptr,ret,&DVBStream->pkt, 0xC0)) > 0) {   #ifdef DVB_DEBUG -  printf("DEB: dvb: cnt=%d (ix: %d): pkt.size=%d\n", cnt, ix, DVBStream->pkt.size); +  //printf("DEB: dvb: PID(%d): cnt=%d (ix: %d): pkt.len=%d (skipped: %d)\n", DVBStream->pid, cnt, ix, DVBStream->pkt.payload_len, DVBStream->pkt.skipped); +  if(DVBStream->pkt.skipped) +  printf("PID(%d): skipped: %d\n", DVBStream->pid, DVBStream->pkt.skipped);   #endif -  push_string(make_shared_binary_string((char *)DVBStream->pkt.data, -  DVBStream->pkt.size)); -  DVBStream->pkt.size = 0; /* clear internall buffer */ +  push_string(make_shared_binary_string((char *)DVBStream->pkt.payload, +  DVBStream->pkt.payload_len)); +  DVBStream->pkt.payload_len = 0; /* clear internall buffer */    ix++;    bufptr += cnt;    ret -= cnt;    if(ret < 1)    break;    }    if(ix)    f_add(ix); -  if(ret) { +  if(ret && ix) {    /* some unprocessed data remain in buf */ -  DVBStream->pkt.size = ret; +  memcpy(DVBStream->pkt.payload, bufptr, ret); +  DVBStream->pkt.payload_len = ret;    }   #ifdef DVB_DEBUG    printf("DEB: dvb: ret=%d (ix: %d)\n", ret, ix);   #endif    return;    }    push_int(0);      }   
pike.git/src/modules/DVB/dvb.c:1615:    if(DVBAudio->fd != -1)    close(DVBAudio->fd);   }      static void init_dvb_stream(struct object *obj) {       DVBStream->parent = NULL;    DVBStream->next = NULL;    DVBStream->fd = -1;    DVBStream->pid = 0; -  DVBStream->pkt.data = NULL; +  DVBStream->pkt.payload = NULL;    DVBStream->buflen = MAX_DVB_READ_SIZE;    DVBStream->ecminfo = NULL;    memset(&DVBStream->low_errmsg, '\0', sizeof(DVBStream->low_errmsg));   }         static void exit_dvb_stream(struct object *obj) {       struct ECMINFO *e;    unsigned int i;       sl_del(DVBStream->parent, DVBStream);    if(DVBStream->fd != -1) {    close(DVBStream->fd); -  if(DVBStream->pkt.data != NULL) -  free(DVBStream->pkt.data); +  if(DVBStream->pkt.payload != NULL) +  free(DVBStream->pkt.payload);    }    if(DVBStream->ecminfo != NULL)    do {    e = DVBStream->ecminfo->next;    free(DVBStream->ecminfo);    DVBStream->ecminfo = e;    } while (e != NULL);      }