Branch: Tag:

2002-11-08

2002-11-08 12:06:19 by Honza Petrous <hop@unibase.cz>

DVB.Stream object is here again!
(this time psparser.c contains PES extractor rewritten from scratch :)

Note: DVB.Stream sync interface isn't quick enough to server more then 2-4 audio streams at once.
Async I/O is on the way ...

Rev: src/modules/DVB/Makefile.in:1.2
Rev: src/modules/DVB/dvb.c:1.14
Rev: src/modules/DVB/dvb.h:1.5
Rev: src/modules/DVB/psparser.c:1.6

2:   || 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 $   */      /*
85:      #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;
124:    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;
711:    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");
727:       buffer[0] = 0;    -  //THREAD_ALLOW(); +  THREAD_ALLOW();    n = read(fd,buffer+1,length-1); -  //THREAD_DISALLOW(); +  THREAD_DISALLOW();    if (n < 0)    {    perror("read error");
1252:       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
1291:   #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);      }
1310:    */   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)
1322:    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;
1351:       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;
1366:    }    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);
1622:    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));
1637:    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 {