GST_END_TEST
GST_START_TEST (media_from_caps_rtcp_fb_pt_101)
{
  GstSDPResult ret = GST_SDP_OK;
  GstSDPMessage *message;
  glong length = -1;
  GstSDPMedia *media_caps;
  const GstSDPMedia *media_sdp;
  GstCaps *caps;
  const gchar *attr_val_caps1, *attr_val_sdp1;

  caps = gst_caps_from_string (caps_video_rtcp_fb_pt_101);

  gst_sdp_media_new (&media_caps);
  fail_unless (media_caps != NULL);

  ret = gst_sdp_media_set_media_from_caps (caps, media_caps);
  fail_unless (ret == GST_SDP_OK);
  gst_caps_unref (caps);

  gst_sdp_message_new (&message);
  gst_sdp_message_parse_buffer ((guint8 *) sdp_rtcp_fb, length, message);

  media_sdp = gst_sdp_message_get_media (message, 0);
  fail_unless (media_sdp != NULL);

  attr_val_caps1 = gst_sdp_media_get_attribute_val (media_caps, "rtcp-fb");
  attr_val_sdp1 = gst_sdp_media_get_attribute_val_n (media_sdp, "rtcp-fb", 3);

  fail_if (g_strcmp0 (attr_val_caps1, attr_val_sdp1) != 0);

  gst_sdp_media_free (media_caps);
  gst_sdp_message_free (message);
}
static GstSDPMedia *
kms_sdp_rtp_avpf_media_handler_create_offer (KmsSdpMediaHandler * handler,
    const gchar * media, GError ** error)
{
  GstSDPMedia *m;

  if (gst_sdp_media_new (&m) != GST_SDP_OK) {
    g_set_error (error, KMS_SDP_AGENT_ERROR, SDP_AGENT_UNEXPECTED_ERROR,
        "Can not create '%s' media", media);
    goto error;
  }

  /* Create m-line */
  if (!KMS_SDP_MEDIA_HANDLER_CLASS (parent_class)->init_offer (handler, media,
          m, error)) {
    goto error;
  }

  /* Add attributes to m-line */
  if (!KMS_SDP_MEDIA_HANDLER_GET_CLASS (handler)->add_offer_attributes (handler,
          m, error)) {
    goto error;
  }

  return m;

error:
  if (m != NULL) {
    gst_sdp_media_free (m);
  }

  return NULL;
}
示例#3
0
static GstSDPMedia *
reject_media_answer (const GstSDPMedia * offered)
{
  GstSDPMedia *media;
  const gchar *mid;
  guint i, len;

  gst_sdp_media_new (&media);

  /* [rfc3264] To reject an offered stream, the port number in the */
  /* corresponding stream in the answer MUST be set to zero. Any   */
  /* media formats listed are ignored. */

  gst_sdp_media_set_media (media, gst_sdp_media_get_media (offered));
  gst_sdp_media_set_port_info (media, 0, 1);
  gst_sdp_media_set_proto (media, gst_sdp_media_get_proto (offered));

  len = gst_sdp_media_formats_len (offered);
  for (i = 0; i < len; i++) {
    const gchar *format;

    format = gst_sdp_media_get_format (offered, i);
    gst_sdp_media_insert_format (media, i, format);
  }

  /* [rfc5888] mid attribute must be present in answer as well */
  mid = gst_sdp_media_get_attribute_val (offered, "mid");
  if (mid == NULL) {
    return media;
  }

  gst_sdp_media_add_attribute (media, "mid", mid);

  return media;
}
GstSDPMedia *
kms_sdp_reject_media_handler_create_answer (KmsSdpMediaHandler * handler,
        const GstSDPMessage * msg, const GstSDPMedia * offer, GError ** error)
{
    GstSDPMedia *m = NULL;

    if (gst_sdp_media_new (&m) != GST_SDP_OK) {
        g_set_error (error, KMS_SDP_AGENT_ERROR, SDP_AGENT_UNEXPECTED_ERROR,
                     "Can not create '%s' media answer", gst_sdp_media_get_media (offer));
        goto error;
    }

    /* Create m-line */
    if (!KMS_SDP_MEDIA_HANDLER_GET_CLASS (handler)->init_answer (handler, offer,
            m, error)) {
        goto error;
    }

    /* Add attributes to m-line */
    if (!KMS_SDP_MEDIA_HANDLER_GET_CLASS (handler)->add_answer_attributes
            (handler, offer, m, error)) {
        goto error;
    }

    return m;

error:

    if (m != NULL) {
        gst_sdp_media_free (m);
    }

    return NULL;
}
GST_END_TEST
GST_START_TEST (media_from_caps)
{
  GstSDPResult ret = GST_SDP_OK;
  GstSDPMessage *message;
  glong length = -1;
  GstSDPMedia *media_video, *media_audio;
  const GstSDPMedia *result_video, *result_audio;
  GstCaps *caps_video, *caps_audio;
  const gchar *media1_text, *media2_text, *media3_text, *media4_text;

  caps_video = gst_caps_from_string (caps_video_string1);
  caps_audio = gst_caps_from_string (caps_audio_string);

  gst_sdp_media_new (&media_video);
  fail_unless (media_video != NULL);
  gst_sdp_media_new (&media_audio);
  fail_unless (media_audio != NULL);

  ret = gst_sdp_media_set_media_from_caps (caps_video, media_video);
  fail_unless (ret == GST_SDP_OK);
  gst_caps_unref (caps_video);
  ret = gst_sdp_media_set_media_from_caps (caps_audio, media_audio);
  fail_unless (ret == GST_SDP_OK);
  gst_caps_unref (caps_audio);

  gst_sdp_message_new (&message);
  gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);

  result_video = gst_sdp_message_get_media (message, 0);
  fail_unless (result_video != NULL);

  result_audio = gst_sdp_message_get_media (message, 2);
  fail_unless (result_audio != NULL);

  media1_text = gst_sdp_media_get_attribute_val (media_video, "rtpmap");
  media2_text = gst_sdp_media_get_attribute_val (result_video, "rtpmap");
  media3_text = gst_sdp_media_get_format (media_audio, 0);
  media4_text = gst_sdp_media_get_format (result_audio, 0);

  fail_if (g_strcmp0 (media1_text, media2_text) != 0);
  fail_if (g_strcmp0 (media3_text, media4_text) != 0);

  gst_sdp_media_free (media_video);
  gst_sdp_media_free (media_audio);
  gst_sdp_message_free (message);
}
static void
make_media (GstSDPMessage * sdp, GstSDPInfo * info, GstRTSPMedia * media,
    GstRTSPStream * stream, GstStructure * s, GstRTSPProfile profile)
{
  GstSDPMedia *smedia;
  const gchar *caps_str, *caps_enc, *caps_params;
  gchar *tmp;
  gint caps_pt, caps_rate;
  guint n_fields, j;
  gboolean first;
  GString *fmtp;
  GstRTSPLowerTrans ltrans;
  GSocketFamily family;
  const gchar *addrtype, *proto;
  gchar *address;
  guint ttl;
  GstClockTime rtx_time;

  gst_sdp_media_new (&smedia);

  /* get media type and payload for the m= line */
  caps_str = gst_structure_get_string (s, "media");
  gst_sdp_media_set_media (smedia, caps_str);

  gst_structure_get_int (s, "payload", &caps_pt);
  tmp = g_strdup_printf ("%d", caps_pt);
  gst_sdp_media_add_format (smedia, tmp);
  g_free (tmp);

  gst_sdp_media_set_port_info (smedia, 0, 1);

  switch (profile) {
    case GST_RTSP_PROFILE_AVP:
      proto = "RTP/AVP";
      break;
    case GST_RTSP_PROFILE_AVPF:
      proto = "RTP/AVPF";
      break;
    case GST_RTSP_PROFILE_SAVP:
      proto = "RTP/SAVP";
      break;
    case GST_RTSP_PROFILE_SAVPF:
      proto = "RTP/SAVPF";
      break;
    default:
      proto = "udp";
      break;
  }
  gst_sdp_media_set_proto (smedia, proto);

  if (info->is_ipv6) {
    addrtype = "IP6";
    family = G_SOCKET_FAMILY_IPV6;
  } else {
    addrtype = "IP4";
    family = G_SOCKET_FAMILY_IPV4;
  }

  ltrans = gst_rtsp_stream_get_protocols (stream);
  if (ltrans == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
    GstRTSPAddress *addr;

    addr = gst_rtsp_stream_get_multicast_address (stream, family);
    if (addr == NULL)
      goto no_multicast;

    address = g_strdup (addr->address);
    ttl = addr->ttl;
    gst_rtsp_address_free (addr);
  } else {
    ttl = 16;
    if (info->is_ipv6)
      address = g_strdup ("::");
    else
      address = g_strdup ("0.0.0.0");
  }

  /* for the c= line */
  gst_sdp_media_add_connection (smedia, "IN", addrtype, address, ttl, 1);
  g_free (address);

  /* get clock-rate, media type and params for the rtpmap attribute */
  gst_structure_get_int (s, "clock-rate", &caps_rate);
  caps_enc = gst_structure_get_string (s, "encoding-name");
  caps_params = gst_structure_get_string (s, "encoding-params");

  if (caps_enc) {
    if (caps_params)
      tmp = g_strdup_printf ("%d %s/%d/%s", caps_pt, caps_enc, caps_rate,
          caps_params);
    else
      tmp = g_strdup_printf ("%d %s/%d", caps_pt, caps_enc, caps_rate);

    gst_sdp_media_add_attribute (smedia, "rtpmap", tmp);
    g_free (tmp);
  }

  /* the config uri */
  tmp = gst_rtsp_stream_get_control (stream);
  gst_sdp_media_add_attribute (smedia, "control", tmp);
  g_free (tmp);


  /* check for srtp */
  do {
    GstBuffer *srtpkey;
    const GValue *val;
    const gchar *srtpcipher, *srtpauth, *srtcpcipher, *srtcpauth;
    GstMIKEYMessage *msg;
    GstMIKEYPayload *payload, *pkd;
    GBytes *bytes;
    GstMapInfo info;
    const guint8 *data;
    gsize size;
    gchar *base64;
    guint8 byte;
    guint32 ssrc;

    val = gst_structure_get_value (s, "srtp-key");
    if (val == NULL)
      break;

    srtpkey = gst_value_get_buffer (val);
    if (srtpkey == NULL)
      break;

    srtpcipher = gst_structure_get_string (s, "srtp-cipher");
    srtpauth = gst_structure_get_string (s, "srtp-auth");
    srtcpcipher = gst_structure_get_string (s, "srtcp-cipher");
    srtcpauth = gst_structure_get_string (s, "srtcp-auth");

    if (srtpcipher == NULL || srtpauth == NULL || srtcpcipher == NULL ||
        srtcpauth == NULL)
      break;

    msg = gst_mikey_message_new ();
    /* unencrypted MIKEY message, we send this over TLS so this is allowed */
    gst_mikey_message_set_info (msg, GST_MIKEY_VERSION, GST_MIKEY_TYPE_PSK_INIT,
        FALSE, GST_MIKEY_PRF_MIKEY_1, 0, GST_MIKEY_MAP_TYPE_SRTP);
    /* add policy '0' for our SSRC */
    gst_rtsp_stream_get_ssrc (stream, &ssrc);
    gst_mikey_message_add_cs_srtp (msg, 0, ssrc, 0);
    /* timestamp is now */
    gst_mikey_message_add_t_now_ntp_utc (msg);
    /* add some random data */
    gst_mikey_message_add_rand_len (msg, 16);

    /* the policy '0' is SRTP with the above discovered algorithms */
    payload = gst_mikey_payload_new (GST_MIKEY_PT_SP);
    gst_mikey_payload_sp_set (payload, 0, GST_MIKEY_SEC_PROTO_SRTP);

    /* only AES-CM is supported */
    byte = 1;
    gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_ENC_ALG, 1,
        &byte);
    /* Encryption key length */
    byte = enc_key_length_from_cipher_name (srtpcipher);
    gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_ENC_KEY_LEN, 1,
        &byte);
    /* only HMAC-SHA1 */
    gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_AUTH_ALG, 1,
        &byte);
    /* Authentication key length */
    byte = auth_key_length_from_auth_name (srtpauth);
    gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_AUTH_KEY_LEN, 1,
        &byte);
    /* we enable encryption on RTP and RTCP */
    gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_SRTP_ENC, 1,
        &byte);
    gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_SRTCP_ENC, 1,
        &byte);
    /* we enable authentication on RTP and RTCP */
    gst_mikey_payload_sp_add_param (payload, GST_MIKEY_SP_SRTP_SRTP_AUTH, 1,
        &byte);
    gst_mikey_message_add_payload (msg, payload);

    /* make unencrypted KEMAC */
    payload = gst_mikey_payload_new (GST_MIKEY_PT_KEMAC);
    gst_mikey_payload_kemac_set (payload, GST_MIKEY_ENC_NULL,
        GST_MIKEY_MAC_NULL);

    /* add the key in key data */
    pkd = gst_mikey_payload_new (GST_MIKEY_PT_KEY_DATA);
    gst_buffer_map (srtpkey, &info, GST_MAP_READ);
    gst_mikey_payload_key_data_set_key (pkd, GST_MIKEY_KD_TEK, info.size,
        info.data);
    gst_buffer_unmap (srtpkey, &info);
    /* add key data to KEMAC */
    gst_mikey_payload_kemac_add_sub (payload, pkd);
    gst_mikey_message_add_payload (msg, payload);

    /* now serialize this to bytes */
    bytes = gst_mikey_message_to_bytes (msg, NULL, NULL);
    gst_mikey_message_unref (msg);
    /* and make it into base64 */
    data = g_bytes_get_data (bytes, &size);
    base64 = g_base64_encode (data, size);
    g_bytes_unref (bytes);

    tmp = g_strdup_printf ("mikey %s", base64);
    g_free (base64);

    gst_sdp_media_add_attribute (smedia, "key-mgmt", tmp);
    g_free (tmp);
  } while (FALSE);

  /* collect all other properties and add them to fmtp or attributes */
  fmtp = g_string_new ("");
  g_string_append_printf (fmtp, "%d ", caps_pt);
  first = TRUE;
  n_fields = gst_structure_n_fields (s);
  for (j = 0; j < n_fields; j++) {
    const gchar *fname, *fval;

    fname = gst_structure_nth_field_name (s, j);

    /* filter out standard properties */
    if (!strcmp (fname, "media"))
      continue;
    if (!strcmp (fname, "payload"))
      continue;
    if (!strcmp (fname, "clock-rate"))
      continue;
    if (!strcmp (fname, "encoding-name"))
      continue;
    if (!strcmp (fname, "encoding-params"))
      continue;
    if (!strcmp (fname, "ssrc"))
      continue;
    if (!strcmp (fname, "timestamp-offset"))
      continue;
    if (!strcmp (fname, "seqnum-offset"))
      continue;
    if (g_str_has_prefix (fname, "srtp-"))
      continue;
    if (g_str_has_prefix (fname, "srtcp-"))
      continue;
    /* handled later */
    if (g_str_has_prefix (fname, "x-gst-rtsp-server-rtx-time"))
      continue;

    if (!strcmp (fname, "a-framesize")) {
      /* a-framesize attribute */
      if ((fval = gst_structure_get_string (s, fname))) {
        tmp = g_strdup_printf ("%d %s", caps_pt, fval);
        gst_sdp_media_add_attribute (smedia, fname + 2, tmp);
        g_free (tmp);
      }
      continue;
    }

    if (g_str_has_prefix (fname, "a-")) {
      /* attribute */
      if ((fval = gst_structure_get_string (s, fname)))
        gst_sdp_media_add_attribute (smedia, fname + 2, fval);
      continue;
    }
    if (g_str_has_prefix (fname, "x-")) {
      /* attribute */
      if ((fval = gst_structure_get_string (s, fname)))
        gst_sdp_media_add_attribute (smedia, fname, fval);
      continue;
    }

    if ((fval = gst_structure_get_string (s, fname))) {
      g_string_append_printf (fmtp, "%s%s=%s", first ? "" : ";", fname, fval);
      first = FALSE;
    }
  }

  if (!first) {
    tmp = g_string_free (fmtp, FALSE);
    gst_sdp_media_add_attribute (smedia, "fmtp", tmp);
    g_free (tmp);
  } else {
    g_string_free (fmtp, TRUE);
  }

  update_sdp_from_tags (stream, smedia);

  if ((rtx_time = gst_rtsp_stream_get_retransmission_time (stream))) {
    /* ssrc multiplexed retransmit functionality */
    guint rtx_pt = gst_rtsp_stream_get_retransmission_pt (stream);

    if (rtx_pt == 0) {
      g_warning ("failed to find an available dynamic payload type. "
          "Not adding retransmission");
    } else {
      gchar *tmp;

      tmp = g_strdup_printf ("%d", rtx_pt);
      gst_sdp_media_add_format (smedia, tmp);
      g_free (tmp);

      tmp = g_strdup_printf ("%d rtx/%d", rtx_pt, caps_rate);
      gst_sdp_media_add_attribute (smedia, "rtpmap", tmp);
      g_free (tmp);

      tmp =
          g_strdup_printf ("%d apt=%d;rtx-time=%" G_GINT64_FORMAT, rtx_pt,
          caps_pt, GST_TIME_AS_MSECONDS (rtx_time));
      gst_sdp_media_add_attribute (smedia, "fmtp", tmp);
      g_free (tmp);
    }
  }

  gst_sdp_message_add_media (sdp, smedia);
  gst_sdp_media_free (smedia);

  return;

  /* ERRORS */
no_multicast:
  {
    gst_sdp_media_free (smedia);
    g_warning ("ignoring stream %d without multicast address",
        gst_rtsp_stream_get_index (stream));
    return;
  }
}
示例#7
0
SDPMedia::SDPMedia() { gst_sdp_media_new(&media_); }
示例#8
0
/**
 * gst_rtsp_sdp_from_media:
 * @sdp: a #GstSDPMessage
 * @info: info
 * @media: a #GstRTSPMedia
 *
 * Add @media specific info to @sdp. @info is used to configure the connection
 * information in the SDP.
 *
 * Returns: TRUE on success.
 */
gboolean
gst_rtsp_sdp_from_media (GstSDPMessage * sdp, GstSDPInfo * info,
    GstRTSPMedia * media)
{
  guint i, n_streams;
  gchar *rangestr;

  n_streams = gst_rtsp_media_n_streams (media);

  rangestr = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
  if (rangestr == NULL)
    goto not_prepared;

  gst_sdp_message_add_attribute (sdp, "range", rangestr);
  g_free (rangestr);

  for (i = 0; i < n_streams; i++) {
    GstRTSPStream *stream;
    GstSDPMedia *smedia;
    GstStructure *s;
    const gchar *caps_str, *caps_enc, *caps_params;
    gchar *tmp;
    gint caps_pt, caps_rate;
    guint n_fields, j;
    gboolean first;
    GString *fmtp;
    GstCaps *caps;

    stream = gst_rtsp_media_get_stream (media, i);
    caps = gst_rtsp_stream_get_caps (stream);

    if (caps == NULL) {
      g_warning ("ignoring stream %d without media type", i);
      continue;
    }

    s = gst_caps_get_structure (caps, 0);
    if (s == NULL) {
      gst_caps_unref (caps);
      g_warning ("ignoring stream %d without media type", i);
      continue;
    }

    gst_sdp_media_new (&smedia);

    /* get media type and payload for the m= line */
    caps_str = gst_structure_get_string (s, "media");
    gst_sdp_media_set_media (smedia, caps_str);

    gst_structure_get_int (s, "payload", &caps_pt);
    tmp = g_strdup_printf ("%d", caps_pt);
    gst_sdp_media_add_format (smedia, tmp);
    g_free (tmp);

    gst_sdp_media_set_port_info (smedia, 0, 1);
    gst_sdp_media_set_proto (smedia, "RTP/AVP");

    /* for the c= line */
    if (info->is_ipv6) {
      gst_sdp_media_add_connection (smedia, "IN", "IP6", "::", 16, 0);
    } else {
      gst_sdp_media_add_connection (smedia, "IN", "IP4", "0.0.0.0", 16, 0);
    }

    /* get clock-rate, media type and params for the rtpmap attribute */
    gst_structure_get_int (s, "clock-rate", &caps_rate);
    caps_enc = gst_structure_get_string (s, "encoding-name");
    caps_params = gst_structure_get_string (s, "encoding-params");

    if (caps_enc) {
      if (caps_params)
        tmp = g_strdup_printf ("%d %s/%d/%s", caps_pt, caps_enc, caps_rate,
            caps_params);
      else
        tmp = g_strdup_printf ("%d %s/%d", caps_pt, caps_enc, caps_rate);

      gst_sdp_media_add_attribute (smedia, "rtpmap", tmp);
      g_free (tmp);
    }

    /* the config uri */
    tmp = gst_rtsp_stream_get_control (stream);
    gst_sdp_media_add_attribute (smedia, "control", tmp);
    g_free (tmp);

    /* collect all other properties and add them to fmtp or attributes */
    fmtp = g_string_new ("");
    g_string_append_printf (fmtp, "%d ", caps_pt);
    first = TRUE;
    n_fields = gst_structure_n_fields (s);
    for (j = 0; j < n_fields; j++) {
      const gchar *fname, *fval;

      fname = gst_structure_nth_field_name (s, j);

      /* filter out standard properties */
      if (!strcmp (fname, "media"))
        continue;
      if (!strcmp (fname, "payload"))
        continue;
      if (!strcmp (fname, "clock-rate"))
        continue;
      if (!strcmp (fname, "encoding-name"))
        continue;
      if (!strcmp (fname, "encoding-params"))
        continue;
      if (!strcmp (fname, "ssrc"))
        continue;
      if (!strcmp (fname, "clock-base"))
        continue;
      if (!strcmp (fname, "seqnum-base"))
        continue;

      if (g_str_has_prefix (fname, "a-")) {
        /* attribute */
        if ((fval = gst_structure_get_string (s, fname)))
          gst_sdp_media_add_attribute (smedia, fname + 2, fval);
        continue;
      }
      if (g_str_has_prefix (fname, "x-")) {
        /* attribute */
        if ((fval = gst_structure_get_string (s, fname)))
          gst_sdp_media_add_attribute (smedia, fname, fval);
        continue;
      }

      if ((fval = gst_structure_get_string (s, fname))) {
        g_string_append_printf (fmtp, "%s%s=%s", first ? "" : ";", fname, fval);
        first = FALSE;
      }
    }
    if (!first) {
      tmp = g_string_free (fmtp, FALSE);
      gst_sdp_media_add_attribute (smedia, "fmtp", tmp);
      g_free (tmp);
    } else {
      g_string_free (fmtp, TRUE);
    }

    update_sdp_from_tags (stream, smedia);

    gst_sdp_message_add_media (sdp, smedia);
    gst_sdp_media_free (smedia);
    gst_caps_unref (caps);
  }

  {
    GstNetTimeProvider *provider;

    if ((provider =
            gst_rtsp_media_get_time_provider (media, info->server_ip, 0))) {
      GstClock *clock;
      gchar *address, *str;
      gint port;

      g_object_get (provider, "clock", &clock, "address", &address, "port",
          &port, NULL);

      str = g_strdup_printf ("GstNetTimeProvider %s %s:%d %" G_GUINT64_FORMAT,
          g_type_name (G_TYPE_FROM_INSTANCE (clock)), address, port,
          gst_clock_get_time (clock));

      gst_sdp_message_add_attribute (sdp, "x-gst-clock", str);
      g_free (str);
      gst_object_unref (clock);
      g_free (address);
      gst_object_unref (provider);
    }
  }

  return TRUE;

  /* ERRORS */
not_prepared:
  {
    GST_ERROR ("media %p is not prepared", media);
    return FALSE;
  }
}
示例#9
0
static gint  create_and_send_ANNOUNCE_message2(GstRTSPsink* sink, GTimeVal *timeout, char **szSessionNumber) {

	const gchar *url_client_ip_str = "0.0.0.0";//"192.168.2.104";
	const gchar *url_server_str_full = g_strdup_printf("rtsp://%s:%d/%s", sink->host, sink->port, sink->stream_name);	//"rtsp://192.168.2.108:1935/live/1";
	//conn = sink->conn;
	GstRTSPMessage  msg = { 0 };
	GstSDPMessage *sdp;
	GstRTSPMethod method;
	GstRTSPResult res;
	guint num_ports = 1;
	guint rtp_port = 5006;
	char *szPayloadType = g_strdup_printf("%d", sink->payload);



	method = GST_RTSP_ANNOUNCE ;
	res = gst_rtsp_message_init_request(&msg, method, url_server_str_full);
	if (res < 0)
		return res;

	/* set user-agent */
	if (sink->user_agent)
		gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_USER_AGENT, sink->user_agent);

	
	gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_CONTENT_TYPE, "application/sdp");

	// allocate sdp messege buffer... 
	res = gst_sdp_message_new(&sdp);

	//v=..
	res = gst_sdp_message_set_version(sdp, "0");
	//o=...
	res = gst_sdp_message_set_origin(sdp, "-", "0", "0", "IN", "IP4", "0.0.0.0");

	//s=..
	if (sink->session_name)
		res = gst_sdp_message_set_session_name(sdp, "Unnamed");


	//i=..
	if (sink->information)
		res = gst_sdp_message_set_information(sdp, "N/A");


	//c=...
	res = gst_sdp_message_set_connection(sdp, "IN", "IP4", url_client_ip_str, 0, 0);
	//a=...
	res = gst_sdp_message_add_attribute(sdp, "recvonly", NULL);


	// create media
	GstSDPMedia *media;
	res = gst_sdp_media_new(&media);
	res = gst_sdp_media_init(media);

	//m=...
	res = gst_sdp_media_set_media(media, "video");

	res = gst_sdp_media_set_port_info(media, rtp_port, num_ports);
	res = gst_sdp_media_set_proto(media, "RTP/AVP");
	res = gst_sdp_media_add_format(media, szPayloadType);

	//a=...
	char *rtpmap = g_strdup_printf("%s %s/%d", szPayloadType, sink->encoding_name, sink->clock_rate);
	res = gst_sdp_media_add_attribute(media, "rtpmap", rtpmap);
	res = gst_sdp_media_add_attribute(media, "fmtp", szPayloadType);
	res = gst_sdp_media_add_attribute(media, "control", "streamid=0");



	// insert media into sdp
	res = gst_sdp_message_add_media(sdp, media);

	gchar * sdp_str = gst_sdp_message_as_text(sdp);
	int size = g_utf8_strlen(sdp_str, 500);
	gst_sdp_message_free(sdp);
	gst_sdp_media_free(media);

	res = gst_rtsp_message_set_body(&msg, sdp_str, size);

	sink->responce = &msg;

	// Send our packet receive server answer and check some basic checks.
	if ((res = sendReceiveAndCheck(sink->conn, timeout, &msg, sink->debug)) != GST_RTSP_OK) {
		return res;
	}

	// get session number 
	*szSessionNumber = extractSessionNumberFromMessage(&msg);


	return GST_RTSP_OK;
}