e576bb2002-10-11Martin Nilsson /* || 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.
ab6f442011-04-25Martin Stjernholm || $Id$
e576bb2002-10-11Martin Nilsson */
1b10db2002-10-08Martin Nilsson 
4aa0ba2002-09-30Honza Petrous /* * DVB module, PES extractor * * Creator: Honza Petrous <hop@unibase.cz>
3f8b4b2002-10-08Honza Petrous  *
4aa0ba2002-09-30Honza Petrous  */ #include "dvb.h"
d0cacf2002-11-08Honza Petrous #include <stdio.h> #include <sys/types.h> #include <string.h> int dvb_pes2es(unsigned char *bufin, int count, struct dvb_es_packet *pkt, int id) { unsigned char *cptr = bufin;
d21b922002-12-01Martin Nilsson  int i = 0, plen, extf = 0, hlen;
d0cacf2002-11-08Honza Petrous  int skipped = 0; while(i+4 < count && (cptr[0] != 0 || cptr[1] != 0 || cptr[2] != 1 || cptr[3] != id)) { i++; cptr++; skipped++; } if(i+4 > count) return -1; #ifdef DVB_DEBUG if(skipped) printf("skipped: %d\n", skipped); #endif switch(cptr[3]) {
9c2b982002-11-09Henrik Grubbström (Grubba)  case 0xC0: case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: case 0xC6: case 0xC7: case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF: case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: case 0xD5: case 0xD6: case 0xD7: case 0xD8: case 0xD9: case 0xDA: case 0xDB: case 0xDC: case 0xDD: case 0xDE: case 0xDF:
d0cacf2002-11-08Honza Petrous  extf = 1; pkt->ptype = DVB_PES_TYPE_AUDIO; break;
9c2b982002-11-09Henrik Grubbström (Grubba)  case 0xE0: case 0xE1: case 0xE2: case 0xE3: case 0xE4: case 0xE5: case 0xE6: case 0xE7: case 0xE8: case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: case 0xEE: case 0xEF:
d0cacf2002-11-08Honza Petrous  extf = 1; pkt->ptype = DVB_PES_TYPE_VIDEO; break; case 0xBD: extf = 1; pkt->ptype = DVB_PES_TYPE_PRIVATE; break; default: pkt->ptype = DVB_PES_TYPE_NOPES; extf = 0; break; } hlen = extf ? 9 : 6; if(i+hlen > count) return -1; plen = (cptr[4] << 8) + cptr[5]; if(extf) { pkt->attr[0] = cptr[6]; pkt->attr[1] = cptr[7]; hlen += cptr[8]; } if(i+plen+hlen > count) return -1;
4aa0ba2002-09-30Honza Petrous 
d0cacf2002-11-08Honza Petrous  memcpy(pkt->payload, cptr + hlen, plen-hlen+6); pkt->payload_len = plen-hlen+6; pkt->skipped = skipped;
4aa0ba2002-09-30Honza Petrous 
d0cacf2002-11-08Honza Petrous  return i+plen+6;
4aa0ba2002-09-30Honza Petrous }