Ejemplo n.º 1
0
static __inline__ sdp_message *
rtsp_method_mi_to_sdp(media_info *mi)
{
#define _MAX_RANGE	64
	sdp_message *sdp;
	char max_range[_MAX_RANGE];
	int32_t stm_i, stm_type;
	sdp_media *media;

	sdp_message_new(&sdp);
	sdp_message_set_version(sdp, "0");
#if 1
    sdp_message_set_origin(sdp, "-", "12345678910111213", "1", "IN", "IP4", "0.0.0.0");
#else
    sdp_message_set_origin(sdp, "-", "12345678910111213", "1", "IN", "IP4", "192.168.1.39");
#endif
    sdp_message_set_session_name(sdp, (const char *)mi->descp);
#if 0
    sdp_message_add_email(sdp, (const char *)mi->email);
	sdp_message_add_phone(sdp, (const char *)mi->phone);
#endif
    sdp_message_set_connection(sdp, "IN", "IP4", "0.0.0.0", DEFAULT_TTL, 0);
	sdp_message_add_time(sdp, "0", "0", NULL);
#if 0
    sdp_message_add_attribute(sdp, "tool", TR_SERVER_SHORT_BANNER);
	sdp_message_add_attribute(sdp, "type", "broadcast");
#endif
    sdp_message_add_attribute(sdp, "control", "*");
#if 1
    snprintf(max_range, _MAX_RANGE, "%s", mi->range[0] ? (char*)mi->range : "0-");
    sdp_message_add_attribute(sdp, "range", max_range);
#endif

	for (stm_i = 0; stm_i < mi->n_stms; ++stm_i)
	{
		sdp_media_new(&media);
		stm_type = mi->stms[stm_i].stm_type;
		sdp_media_set_media(media, __str(__stm_name(stm_type)));
		sdp_media_set_port_info(media, 0, 1);
		sdp_media_set_proto(media, __str(__stm_proto(stm_type)));
		sprintf(max_range, "%d", __stm_pt(stm_type, mi->stms[stm_i].fmt));
		sdp_media_add_format(media, max_range);
		sdp_media_add_bandwidth(media, "AS", mi->stms[stm_i].bit_rate);
		sdp_media_add_rtpmap(media, &mi->stms[stm_i], __stm_pt(stm_type, mi->stms[stm_i].fmt));
        sprintf(max_range, TRACK_INDICATOR"%d", stm_i);
		sdp_media_add_attribute(media, "control", max_range);
        sdp_media_append_fields(media, &mi->stms[stm_i], __stm_pt(stm_type, mi->stms[stm_i].fmt));

		sdp_message_add_media(sdp, media);
		sdp_media_free(media);
	}

	return sdp;
}
Ejemplo n.º 2
0
static int
sdp_message_parse_m (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;
  char *tmp;
  char *tmp_next;
  int i;
  sdp_media_t *m_header;
  char *slash;
  char *space;

  *next = buf;

  equal = buf;
  while ((*equal != '=') && (*equal != '\0'))
    equal++;
  if (*equal == '\0')
    return ERR_ERROR;

  /* check if header is "m" */
  if (equal[-1] != 'm')
    return ERR_DISCARD;

  crlf = equal + 1;

  while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0'))
    crlf++;
  if (*crlf == '\0')
    return ERR_ERROR;
  if (crlf == equal + 1)
    return ERR_ERROR;		/* a=\r ?? bad header */

  tmp = equal + 1;

  i = sdp_media_init (&m_header);
  if (i != 0)
    return ERR_ERROR;

  /* m=media port ["/"integer] proto *(payload_number) */

  /* media is "audio" "video" "application" "data" or other... */
  i = __osip_set_next_token (&(m_header->m_media), tmp, ' ', &tmp_next);
  if (i != 0)
    {
      sdp_media_free (m_header);
      return -1;
    }
  tmp = tmp_next;

  slash = strchr (tmp, '/');
  space = strchr (tmp, ' ');
  if (space == NULL)		/* not possible! */
    {
      sdp_media_free (m_header);
      return ERR_ERROR;
    }
  if ((slash != NULL) && (slash < space))
    {				/* a number of port is specified! */
      i = __osip_set_next_token (&(m_header->m_port), tmp, '/', &tmp_next);
      if (i != 0)
	{
	  sdp_media_free (m_header);
	  return -1;
	}
      tmp = tmp_next;

      i =
	__osip_set_next_token (&(m_header->m_number_of_port), tmp, ' ',
			       &tmp_next);
      if (i != 0)
	{
	  sdp_media_free (m_header);
	  return -1;
	}
      tmp = tmp_next;
    }
  else
    {
      i = __osip_set_next_token (&(m_header->m_port), tmp, ' ', &tmp_next);
      if (i != 0)
	{
	  sdp_media_free (m_header);
	  return -1;
	}
      tmp = tmp_next;
    }

  i = __osip_set_next_token (&(m_header->m_proto), tmp, ' ', &tmp_next);
  if (i != 0)
    {
      sdp_media_free (m_header);
      return -1;
    }
  tmp = tmp_next;

  {
    char *str;
    int more_space_before_crlf;

    space = strchr (tmp + 1, ' ');
    if (space == NULL)
      more_space_before_crlf = 1;
    else if ((space != NULL) && (space > crlf))
      more_space_before_crlf = 1;
    else
      more_space_before_crlf = 0;
    while (more_space_before_crlf == 0)
      {
	i = __osip_set_next_token (&str, tmp, ' ', &tmp_next);
	if (i != 0)
	  {
	    sdp_media_free (m_header);
	    return -1;
	  }
	tmp = tmp_next;
	osip_list_add (m_header->m_payloads, str, -1);

	space = strchr (tmp + 1, ' ');
	if (space == NULL)
	  more_space_before_crlf = 1;
	else if ((space != NULL) && (space > crlf))
	  more_space_before_crlf = 1;
	else
	  more_space_before_crlf = 0;
      }
    if (tmp_next < crlf)
      {				/* tmp_next is still less than clrf: no space */
	i = __osip_set_next_token (&str, tmp, '\r', &tmp_next);
	if (i != 0)
	  {
	    i = __osip_set_next_token (&str, tmp, '\n', &tmp_next);
	    if (i != 0)
	      {
		sdp_media_free (m_header);
		return -1;
	      }
	  }
	osip_list_add (m_header->m_payloads, str, -1);
      }
  }

  osip_list_add (sdp->m_medias, m_header, -1);

  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}