/*****************************************************************
 * 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/>.
 * *****************************************************************/


/* RTP packet */

#define RTP_HEADER_BYTES 12
#define RTP_PACKET_BYTES 1500 // TODO: Get MTU??

typedef struct
  {
  int m;
  int pt;
  int seq;
  uint32_t pts;
  uint32_t ssrc;

  uint8_t * buffer;
  int buffer_alloc;
  int len;
  } rtp_packet_t;

void rtp_packet_init(rtp_packet_t * p);
void rtp_packet_free(rtp_packet_t * p);

/* Create packet header */
void rtp_packet_init_header(rtp_packet_t * p);


typedef struct rtp_context_s rtp_context_t;

typedef struct
  {
  gavl_packet_sink_t * sink_int;
  gavl_packet_sink_t * sink_ext;
  
  rtp_context_t * ctx;
  int udp_fds[2];
  int rtp_id;

  const gavf_stream_header_t * sh;
  rtp_packet_t p;
  } rtp_stream_t;

struct rtp_context_s
  {
  int num_streams;
  rtp_stream_t * streams;
  
  int session;
  int fd; // Control FD

  gavl_dictionary_t play_response;
  };

/* Filter methods */

int rtp_supported();
  
int rtp_probe(int protocol,
              const gavf_program_header_t * ph,
              const gavl_dictionary_t * request);
  
void * rtp_create(server_t * s,
                  const gavf_program_header_t * ph,
                  const gavl_dictionary_t * req,
                  const gavl_dictionary_t * vars,
                  gavl_dictionary_t * res);

int rtp_start(void * priv,
              const gavf_program_header_t * ph,
              const gavl_dictionary_t * req,
              const gavl_dictionary_t * inline_metadata,
              int fd);

int rtp_sync(void * priv, int64_t * pts);

int rtp_put_buffer(void * priv, buffer_element_t *);
void rtp_destroy(void * priv);

/* */

rtsp_status_t
rtp_stream_setup(const server_t * srv,
                 rtp_context_t * ctx,
                 rtp_stream_t * s,
                 const gavl_dictionary_t * req,
                 gavl_dictionary_t * res);

