Exemplo n.º 1
0
Arquivo: rtp.c Projeto: hongbinz/poc
/*M
  \emph{Fill the RTP packet structure by unpacking payload
  information.}
**/
int rtp_pkt_unpack(rtp_pkt_t *pkt) {
  assert(pkt != NULL);
  
  /* v: 2 bits, p: 1 bit, x: 1 bit, cc: 4 bits */
  pkt->b.v  = (pkt->data[0] >> 6) & 0x3;
  /* check version */
  if (pkt->b.v != 2)
    return 0;
  pkt->b.p  = (pkt->data[0] >> 5) & 0x1;
  pkt->b.x  = (pkt->data[0] >> 4) & 0x1;
  pkt->b.cc = (pkt->data[0])      & 0xf;

  /* m: 1 bit, pt: 7 bits */
  pkt->b.m  = (pkt->data[1] >> 7) & 0x1;
  pkt->b.pt = (pkt->data[1])      & 0x7f;

  unsigned char *ptr = pkt->data + 2;
  /* seq: 16 bits */
  pkt->b.seq = UINT16_UNPACK(ptr);
  /* timestamp: 32 bits */
  pkt->timestamp = UINT32_UNPACK(ptr);
  /* ssrc: 32 bits, just ignore it */
  ptr += 4;

  if (pkt->unpack)
    if (!pkt->unpack(pkt))
      return 0;

  /*M
    If padding is used, then padding length is in last byte.
  **/
  if (pkt->b.p) {
    unsigned char *plen = pkt->data + pkt->length - 1;
    pkt->plen = *plen;
  } else {
    pkt->plen = 0;
  }
  

  /*M
    Ignore rest of packet for now.
  **/
  pkt->length -= pkt->hlen + pkt->b.cc * RTP_CSRC_SIZE;
  if (pkt->b.p)
    pkt->length -= pkt->plen + 1;

  return 1;
}
Exemplo n.º 2
0
/* endian issues will bite us if we don't call uint32_unpack when
 * reading numbers from the cdb file, so we do it here. */
static int read_uint32(int fd, uint32_t *n)
{
    unsigned char	buf[4];
    ssize_t		err;

    if ( (err = read(fd, &buf, sizeof(*n))) == -1)
      return -1;
    else if (err == 0)
      return 1;
    else if (err < sizeof(buf)) {
      /* Error: could not read a whole uint32_t */
      errno	 = EIO;		/* ENODATA not on FreeBSD */
      return -1;
    }
    
    UINT32_UNPACK(buf, n);

    return 0;
}