/*****************************************************************
 * gmerlin - a general purpose multimedia framework and applications
 *
 * Copyright (c) 2001 - 2012 Members of the Gmerlin project
 * gmerlin-general@lists.sourceforge.net
 * http://gmerlin.sourceforge.net
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * *****************************************************************/

#include "server.h"
#include "rtp.h"
#include <gavl/numptr.h>

#define RTP_VERSION 0x02

void rtp_packet_init(rtp_packet_t * p)
  {
  p->buffer_alloc = RTP_PACKET_BYTES;
  p->buffer = malloc(p->buffer_alloc);
  p->seq = rand() & 0x7fff;
  }

void rtp_packet_free(rtp_packet_t * p)
  {
  if(p->buffer)
    free(p->buffer);
  }

/* Create packet header */
void rtp_packet_init_header(rtp_packet_t * p)
  {
  uint8_t * ptr = p->buffer;

  *ptr = RTP_VERSION << 6;                      ptr++;
  *ptr = (p->pt & 0x7f) | ((p->m & 0x01) << 7); ptr++;

  GAVL_16BE_2_PTR(p->seq, ptr);                 ptr+=2;
  GAVL_32BE_2_PTR(p->pts, ptr);                 ptr+=4;
  GAVL_32BE_2_PTR(p->ssrc, ptr);                ptr+=4;

  p->len = (int)(ptr - p->buffer);
  p->seq = (p->seq + 1) & 0xffff;
  
  
  }
