Exemplo n.º 1
0
GST_END_TEST
GST_START_TEST (copy)
{
  GstSDPMessage *message, *copy;
  glong length = -1;
  gchar *message_str, *copy_str;
  const gchar *repeat1[] = { "789", "012", NULL };
  const gchar *repeat2[] = { "987", "210", NULL };

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

  gst_sdp_message_add_time (message, "123", "456", repeat1);
  gst_sdp_message_add_time (message, "321", "654", repeat2);

  gst_sdp_message_copy (message, &copy);

  message_str = gst_sdp_message_as_text (message);
  GST_DEBUG ("Original:\n%s", message_str);
  gst_sdp_message_free (message);
  copy_str = gst_sdp_message_as_text (copy);
  gst_sdp_message_free (copy);
  GST_DEBUG ("Copy:\n%s", copy_str);

  fail_if (g_strcmp0 (copy_str, message_str) != 0);
  g_free (copy_str);
  g_free (message_str);
}
Exemplo n.º 2
0
/**
 * \brief creates SAP message: header + payload returned in a buffer
 * \param channelTable_entry * entry the entry in the channelTable associated to the socket
 * \param sap_msg_length a location to save the lenght of the SAP message
 * \param gboolean deletion specify if we should build the SAP deletion message
 * \return char* buffer that contains the SAP message (the UDP payload)
 */
static char*  build_SAP_msg(struct channelTable_entry * entry, int *sap_msg_length, gboolean deletion){

	GstSDPMessage *msg;
	/* create a new SDP message */
	if (gst_sdp_message_new(&msg)){
		g_critical("Failed to create SDP message\n");
		return FALSE;
	}

	/*
	 * build the SDP message
	 */
	create_SDP(msg, entry);

	/* extract the randomly generated session_version integer */
	const GstSDPOrigin 	*origin 			= gst_sdp_message_get_origin (msg);
	int 				session_version 	= htonl(atoi(origin->sess_version));

	/* Build the  header */
	char header[SAP_header_size];
   	build_SAP_header(header, session_version, deletion);

	/* Build the *payload */
	char *payload = g_strdup (gst_sdp_message_as_text(msg));

	/* concat header and payload */
	int 	sap_msg_size 	= SAP_header_size+strlen(payload);
	char 	*sap_msg 		= (char*) malloc(sap_msg_size*sizeof(char));
	memcpy(sap_msg, header, SAP_header_size);
	memcpy(sap_msg+SAP_header_size, payload, strlen(payload));
	*sap_msg_length = sap_msg_size; // save the length if the message into sap_msg_length
	free(payload);
	return sap_msg;
}
Exemplo n.º 3
0
GstSDPMessage *
kms_sdp_message_context_pack (SdpMessageContext * ctx, GError ** error)
{
  GstSDPMessage *msg;
  gchar *sdp_str;
  GSList *l;

  gst_sdp_message_new (&msg);

  /* Context's message only stores media session attributes */
  sdp_str = gst_sdp_message_as_text (ctx->msg);

  if (gst_sdp_message_parse_buffer ((const guint8 *) sdp_str, -1,
          msg) != GST_SDP_OK) {
    g_set_error_literal (error, KMS_SDP_AGENT_ERROR, SDP_AGENT_UNEXPECTED_ERROR,
        "Can not create SDP message");
    g_free (sdp_str);
    return NULL;
  }

  g_free (sdp_str);

  /* Add group attributes */
  g_slist_foreach (ctx->groups, (GFunc) add_group_to_sdp_message, msg);

  /* Append medias to the message */
  for (l = ctx->medias; l != NULL; l = g_slist_next (l)) {
    if (!add_media_to_sdp_message (l->data, msg, error)) {
      gst_sdp_message_free (msg);
      return NULL;
    }
  }

  return msg;
}
Exemplo n.º 4
0
static void
sdp_to_str (std::string &_return, const GstSDPMessage *sdp)
{
  std::string sdpStr;
  gchar *sdpGchar;

  sdpGchar = gst_sdp_message_as_text (sdp);
  _return.clear ();
  _return.append (sdpGchar);
  free (sdpGchar);
}
Exemplo n.º 5
0
GST_END_TEST
GST_START_TEST (process_webrtc_offer)
{
  GstSDPMessage *pattern_sdp;
  GstElement *rtpendpoint = gst_element_factory_make ("rtpendpoint", NULL);
  GstSDPMessage *offer = NULL, *answer = NULL;
  gchar *aux = NULL;

  static const gchar *offer_str = "v=0\r\n"
      "o=- 1783800438437245920 2 IN IP4 127.0.0.1\r\n"
      "s=-\r\n"
      "t=0 0\r\n"
      "a=group:BUNDLE audio video\r\n"
      "a=msid-semantic: WMS MediaStream0\r\n"
      "m=audio 37426 RTP/SAVPF 111 103 9 102 0 8 106 105 13 127 126\r\n"
      "c=IN IP4 5.5.5.5\r\n"
      "a=rtcp:37426 IN IP4 5.5.5.5\r\n"
      "a=candidate:1840965416 1 udp 2113937151 192.168.0.100 37426 typ host generation 0\r\n"
      "a=candidate:1840965416 2 udp 2113937151 192.168.0.100 37426 typ host generation 0\r\n"
      "a=candidate:590945240 1 tcp 1509957375 192.168.0.100 46029 typ host generation 0\r\n"
      "a=candidate:590945240 2 tcp 1509957375 192.168.0.100 46029 typ host generation 0\r\n"
      "a=candidate:3975340444 1 udp 1677729535 5.5.5.5 37426 typ srflx raddr 192.168.0.100 rport 37426 generation 0\r\n"
      "a=candidate:3975340444 2 udp 1677729535 5.5.5.5 37426 typ srflx raddr 192.168.0.100 rport 37426 generation 0\r\n"
      "a=ice-ufrag:RkI7xTFiQgGZu1ww\r\n"
      "a=ice-pwd:6ZTKNoP2vXWYLweywju9Bydv\r\n"
      "a=ice-options:google-ice\r\n"
      "a=mid:audio\r\n"
      "a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n"
      "a=sendrecv\r\n"
      "a=rtcp-mux\r\n"
      "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:vpy+PnhF0bWmwYlAngWT1cc9qppYCvRlwT4aKrYh\r\n"
      "a=rtpmap:111 opus/48000/1\r\n"
      "a=fmtp:111 minptime=10\r\n"
      "a=rtpmap:103 ISAC/16000\r\n"
      "a=rtpmap:9 G722/16000\r\n"
      "a=rtpmap:102 ILBC/8000\r\n"
      "a=rtpmap:0 PCMU/8000\r\n"
      "a=rtpmap:8 PCMA/8000\r\n"
      "a=rtpmap:106 CN/32000\r\n"
      "a=rtpmap:105 CN/16000\r\n"
      "a=rtpmap:13 CN/8000\r\n"
      "a=rtpmap:127 red/8000\r\n"
      "a=rtpmap:126 telephone-event/8000\r\n"
      "a=maxptime:60\r\n"
      "a=ssrc:4210654932 cname:/9kskFtadoxn1x70\r\n"
      "a=ssrc:4210654932 msid:MediaStream0 AudioTrack0\r\n"
      "a=ssrc:4210654932 mslabel:MediaStream0\r\n"
      "a=ssrc:4210654932 label:AudioTrack0\r\n"
      "m=video 37426 RTP/SAVPF 100 116 117\r\n"
      "c=IN IP4 5.5.5.5\r\n"
      "a=rtcp:37426 IN IP4 5.5.5.5\r\n"
      "a=candidate:1840965416 1 udp 2113937151 192.168.0.100 37426 typ host generation 0\r\n"
      "a=candidate:1840965416 2 udp 2113937151 192.168.0.100 37426 typ host generation 0\r\n"
      "a=candidate:590945240 1 tcp 1509957375 192.168.0.100 46029 typ host generation 0\r\n"
      "a=candidate:590945240 2 tcp 1509957375 192.168.0.100 46029 typ host generation 0\r\n"
      "a=candidate:3975340444 1 udp 1677729535 5.5.5.5 37426 typ srflx raddr 192.168.0.100 rport 37426 generation 0\r\n"
      "a=candidate:3975340444 2 udp 1677729535 5.5.5.5 37426 typ srflx raddr 192.168.0.100 rport 37426 generation 0\r\n"
      "a=ice-ufrag:RkI7xTFiQgGZu1ww\r\n"
      "a=ice-pwd:6ZTKNoP2vXWYLweywju9Bydv\r\n"
      "a=ice-options:google-ice\r\n"
      "a=mid:video\r\n"
      "a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\n"
      "a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n"
      "a=sendrecv\r\n"
      "a=rtcp-mux\r\n"
      "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:vpy+PnhF0bWmwYlAngWT1cc9qppYCvRlwT4aKrYh\r\n"
      "a=rtpmap:100 VP8/90000\r\n"
      "a=rtcp-fb:100 ccm fir\r\n"
      "a=rtcp-fb:100 nack\r\n"
      "a=rtcp-fb:100 nack pli\r\n"
      "a=rtcp-fb:100 goog-remb\r\n"
      "a=rtpmap:116 red/90000\r\n"
      "a=rtpmap:117 ulpfec/90000\r\n"
      "a=ssrc:1686396354 cname:/9kskFtadoxn1x70\r\n"
      "a=ssrc:1686396354 msid:MediaStream0 VideoTrack0\r\n"
      "a=ssrc:1686396354 mslabel:MediaStream0\r\n"
      "a=ssrc:1686396354 label:VideoTrack0\r\n";

  fail_unless (gst_sdp_message_new (&pattern_sdp) == GST_SDP_OK);
  fail_unless (gst_sdp_message_parse_buffer ((const guint8 *)
          pattern_offer_sdp_str, -1, pattern_sdp) == GST_SDP_OK);

  g_object_set (rtpendpoint, "pattern-sdp", pattern_sdp, NULL);
  fail_unless (gst_sdp_message_free (pattern_sdp) == GST_SDP_OK);
  g_object_get (rtpendpoint, "pattern-sdp", &pattern_sdp, NULL);
  fail_unless (pattern_sdp != NULL);
  fail_unless (gst_sdp_message_free (pattern_sdp) == GST_SDP_OK);

  fail_unless (gst_sdp_message_new (&offer) == GST_SDP_OK);
  fail_unless (gst_sdp_message_parse_buffer ((const guint8 *)
          offer_str, -1, offer) == GST_SDP_OK);

  GST_DEBUG ("Offer:\n%s", (aux = gst_sdp_message_as_text (offer)));
  g_free (aux);
  aux = NULL;

  g_signal_emit_by_name (rtpendpoint, "process-offer", offer, &answer);
  fail_unless (answer != NULL);
  GST_DEBUG ("Answer:\n%s", (aux = gst_sdp_message_as_text (answer)));
  g_free (aux);
  aux = NULL;

  gst_sdp_message_free (offer);
  gst_sdp_message_free (answer);

  g_object_unref (rtpendpoint);
}
Exemplo n.º 6
0
GST_END_TEST
GST_START_TEST (negotiation_offerer)
{
  GstSDPMessage *pattern_sdp;
  GstElement *offerer = gst_element_factory_make ("rtpendpoint", NULL);
  GstElement *answerer = gst_element_factory_make ("rtpendpoint", NULL);
  GstSDPMessage *offer = NULL, *answer = NULL;
  GstSDPMessage *local_offer = NULL, *local_answer = NULL, *remote_offer =
      NULL, *remote_answer = NULL;
  gchar *local_offer_str, *local_answer_str, *remote_offer_str,
      *remote_answer_str;
  gchar *aux = NULL;

  fail_unless (gst_sdp_message_new (&pattern_sdp) == GST_SDP_OK);
  fail_unless (gst_sdp_message_parse_buffer ((const guint8 *)
          pattern_offer_sdp_str, -1, pattern_sdp) == GST_SDP_OK);

  g_object_set (offerer, "pattern-sdp", pattern_sdp, NULL);
  fail_unless (gst_sdp_message_free (pattern_sdp) == GST_SDP_OK);
  g_object_get (offerer, "pattern-sdp", &pattern_sdp, NULL);
  fail_unless (pattern_sdp != NULL);
  fail_unless (gst_sdp_message_free (pattern_sdp) == GST_SDP_OK);

  fail_unless (gst_sdp_message_new (&pattern_sdp) == GST_SDP_OK);
  fail_unless (gst_sdp_message_parse_buffer ((const guint8 *)
          pattern_answer_sdp_str, -1, pattern_sdp) == GST_SDP_OK);
  g_object_set (answerer, "pattern-sdp", pattern_sdp, NULL);
  fail_unless (gst_sdp_message_free (pattern_sdp) == GST_SDP_OK);

  g_signal_emit_by_name (offerer, "generate-offer", &offer);

  fail_unless (offer != NULL);

  GST_DEBUG ("Offer:\n%s", (aux = gst_sdp_message_as_text (offer)));
  g_free (aux);
  aux = NULL;

  g_signal_emit_by_name (answerer, "process-offer", offer, &answer);
  fail_unless (answer != NULL);
  GST_DEBUG ("Answer:\n%s", (aux = gst_sdp_message_as_text (answer)));
  g_free (aux);
  aux = NULL;

  g_signal_emit_by_name (offerer, "process-answer", answer);

  gst_sdp_message_free (offer);
  gst_sdp_message_free (answer);

  g_object_get (offerer, "local-offer-sdp", &local_offer, NULL);
  g_object_get (offerer, "remote-answer-sdp", &remote_answer, NULL);

  g_object_get (answerer, "remote-offer-sdp", &remote_offer, NULL);
  g_object_get (answerer, "local-answer-sdp", &local_answer, NULL);

  fail_unless (local_offer != NULL);
  fail_unless (remote_answer != NULL);
  fail_unless (remote_offer != NULL);
  fail_unless (local_answer != NULL);

  local_offer_str = gst_sdp_message_as_text (local_offer);
  remote_answer_str = gst_sdp_message_as_text (remote_answer);

  remote_offer_str = gst_sdp_message_as_text (remote_offer);
  local_answer_str = gst_sdp_message_as_text (local_answer);

  GST_DEBUG ("Local offer\n%s", local_offer_str);
  GST_DEBUG ("Remote answer\n%s", remote_answer_str);
  GST_DEBUG ("Remote offer\n%s", remote_offer_str);
  GST_DEBUG ("Local answer\n%s", local_answer_str);

  fail_unless (g_strcmp0 (local_offer_str, remote_offer_str) == 0);
  fail_unless (g_strcmp0 (remote_answer_str, local_answer_str) == 0);

  g_free (local_offer_str);
  g_free (remote_answer_str);
  g_free (local_answer_str);
  g_free (remote_offer_str);

  gst_sdp_message_free (local_offer);
  gst_sdp_message_free (remote_answer);
  gst_sdp_message_free (remote_offer);
  gst_sdp_message_free (local_answer);

  g_object_unref (offerer);
  g_object_unref (answerer);
}
Exemplo n.º 7
0
GST_END_TEST
GST_START_TEST (negotiation_offerer)
{
  GArray *audio_codecs_array, *video_codecs_array;
  gchar *audio_codecs[] = { "OPUS/48000/1", "AMR/8000/1", NULL };
  gchar *video_codecs[] = { "H263-1998/90000", "VP8/90000", NULL };
  GstElement *offerer = gst_element_factory_make ("rtpendpoint", NULL);
  GstElement *answerer = gst_element_factory_make ("rtpendpoint", NULL);
  GstSDPMessage *offer = NULL, *answer = NULL;
  GstSDPMessage *offerer_local_sdp = NULL, *offerer_remote_sdp = NULL;
  gchar *offerer_local_sdp_str, *offerer_remote_sdp_str;
  GstSDPMessage *answerer_local_sdp = NULL, *answerer_remote_sdp = NULL;
  gchar *answerer_local_sdp_str, *answerer_remote_sdp_str;
  gchar *sdp_str = NULL;

  audio_codecs_array = create_codecs_array (audio_codecs);
  video_codecs_array = create_codecs_array (video_codecs);
  g_object_set (offerer, "num-audio-medias", 1, "audio-codecs",
      g_array_ref (audio_codecs_array), "num-video-medias", 1, "video-codecs",
      g_array_ref (video_codecs_array), NULL);
  g_object_set (answerer, "num-audio-medias", 1, "audio-codecs",
      g_array_ref (audio_codecs_array), "num-video-medias", 1, "video-codecs",
      g_array_ref (video_codecs_array), NULL);
  g_array_unref (audio_codecs_array);
  g_array_unref (video_codecs_array);

  g_signal_emit_by_name (offerer, "generate-offer", &offer);
  fail_unless (offer != NULL);
  GST_DEBUG ("Offer:\n%s", (sdp_str = gst_sdp_message_as_text (offer)));
  g_free (sdp_str);
  sdp_str = NULL;

  g_signal_emit_by_name (answerer, "process-offer", offer, &answer);
  fail_unless (answer != NULL);
  GST_DEBUG ("Answer:\n%s", (sdp_str = gst_sdp_message_as_text (answer)));
  g_free (sdp_str);
  sdp_str = NULL;

  g_signal_emit_by_name (offerer, "process-answer", answer);

  gst_sdp_message_free (offer);
  gst_sdp_message_free (answer);

  g_object_get (offerer, "local-sdp", &offerer_local_sdp, NULL);
  fail_unless (offerer_local_sdp != NULL);
  g_object_get (offerer, "remote-sdp", &offerer_remote_sdp, NULL);
  fail_unless (offerer_remote_sdp != NULL);

  g_object_get (answerer, "local-sdp", &answerer_local_sdp, NULL);
  fail_unless (answerer_local_sdp != NULL);
  g_object_get (answerer, "remote-sdp", &answerer_remote_sdp, NULL);
  fail_unless (answerer_remote_sdp != NULL);

  offerer_local_sdp_str = gst_sdp_message_as_text (offerer_local_sdp);
  offerer_remote_sdp_str = gst_sdp_message_as_text (offerer_remote_sdp);

  answerer_local_sdp_str = gst_sdp_message_as_text (answerer_local_sdp);
  answerer_remote_sdp_str = gst_sdp_message_as_text (answerer_remote_sdp);

  GST_DEBUG ("Offerer local SDP\n%s", offerer_local_sdp_str);
  GST_DEBUG ("Offerer remote SDPr\n%s", offerer_remote_sdp_str);
  GST_DEBUG ("Answerer local SDP\n%s", answerer_local_sdp_str);
  GST_DEBUG ("Answerer remote SDP\n%s", answerer_remote_sdp_str);

  fail_unless (g_strcmp0 (offerer_local_sdp_str, answerer_remote_sdp_str) == 0);
  fail_unless (g_strcmp0 (offerer_remote_sdp_str, answerer_local_sdp_str) == 0);

  g_free (offerer_local_sdp_str);
  g_free (offerer_remote_sdp_str);
  g_free (answerer_local_sdp_str);
  g_free (answerer_remote_sdp_str);

  gst_sdp_message_free (offerer_local_sdp);
  gst_sdp_message_free (offerer_remote_sdp);
  gst_sdp_message_free (answerer_local_sdp);
  gst_sdp_message_free (answerer_remote_sdp);

  g_object_unref (offerer);
  g_object_unref (answerer);
}
Exemplo n.º 8
0
std::string SDPDescription::get_string() {
  gchar* tmp = gst_sdp_message_as_text(sdp_description_);
  std::string res(tmp);
  g_free(tmp);
  return res;
}
Exemplo n.º 9
0
GST_END_TEST
GST_START_TEST (negotiation_offerer)
{
  GArray *audio_codecs_array, *video_codecs_array;
  gchar *audio_codecs[] = { "OPUS/48000/1", "AMR/8000/1", NULL };
  gchar *video_codecs[] = { "H263-1998/90000", "VP8/90000", NULL };
  gchar *offerer_sess_id, *answerer_sess_id;
  GstElement *offerer = gst_element_factory_make ("rtpendpoint", NULL);
  GstElement *answerer = gst_element_factory_make ("rtpendpoint", NULL);
  GstSDPMessage *offer = NULL, *answer = NULL;
  GstSDPMessage *offerer_local_sdp = NULL, *offerer_remote_sdp = NULL;
  gchar *offerer_local_sdp_str, *offerer_remote_sdp_str;
  GstSDPMessage *answerer_local_sdp = NULL, *answerer_remote_sdp = NULL;
  gchar *answerer_local_sdp_str, *answerer_remote_sdp_str;
  gchar *sdp_str = NULL;
  const GstSDPConnection *connection;
  gboolean answer_ok;

  audio_codecs_array = create_codecs_array (audio_codecs);
  video_codecs_array = create_codecs_array (video_codecs);
  g_object_set (offerer, "num-audio-medias", 1, "audio-codecs",
      g_array_ref (audio_codecs_array), "num-video-medias", 1, "video-codecs",
      g_array_ref (video_codecs_array), NULL);
  g_object_set (answerer, "num-audio-medias", 1, "audio-codecs",
      g_array_ref (audio_codecs_array), "num-video-medias", 1, "video-codecs",
      g_array_ref (video_codecs_array), NULL);
  g_array_unref (audio_codecs_array);
  g_array_unref (video_codecs_array);

  /* Session creation */
  g_signal_emit_by_name (offerer, "create-session", &offerer_sess_id);
  GST_DEBUG_OBJECT (offerer, "Created session with id '%s'", offerer_sess_id);
  g_signal_emit_by_name (answerer, "create-session", &answerer_sess_id);
  GST_DEBUG_OBJECT (answerer, "Created session with id '%s'", answerer_sess_id);

  /* SDP negotiation */
  g_signal_emit_by_name (offerer, "generate-offer", offerer_sess_id, &offer);
  fail_unless (offer != NULL);
  GST_DEBUG ("Offer:\n%s", (sdp_str = gst_sdp_message_as_text (offer)));
  g_free (sdp_str);
  sdp_str = NULL;
  connection = gst_sdp_message_get_connection (offer);

  fail_unless (g_strcmp0 (connection->address, "0.0.0.0"));
  fail_unless (g_strcmp0 (connection->address, "::"));

  g_signal_emit_by_name (answerer, "process-offer", answerer_sess_id, offer,
      &answer);
  fail_unless (answer != NULL);
  GST_DEBUG ("Answer:\n%s", (sdp_str = gst_sdp_message_as_text (answer)));
  g_free (sdp_str);
  sdp_str = NULL;

  g_signal_emit_by_name (offerer, "process-answer", offerer_sess_id, answer,
      &answer_ok);
  fail_unless (answer_ok);

  gst_sdp_message_free (offer);
  gst_sdp_message_free (answer);

  g_signal_emit_by_name (offerer, "get-local-sdp", offerer_sess_id,
      &offerer_local_sdp);
  fail_unless (offerer_local_sdp != NULL);
  g_signal_emit_by_name (offerer, "get-remote-sdp", offerer_sess_id,
      &offerer_remote_sdp);
  fail_unless (offerer_remote_sdp != NULL);

  g_signal_emit_by_name (answerer, "get-local-sdp", answerer_sess_id,
      &answerer_local_sdp);
  fail_unless (answerer_local_sdp != NULL);
  g_signal_emit_by_name (answerer, "get-remote-sdp", answerer_sess_id,
      &answerer_remote_sdp);
  fail_unless (answerer_remote_sdp != NULL);

  offerer_local_sdp_str = gst_sdp_message_as_text (offerer_local_sdp);
  offerer_remote_sdp_str = gst_sdp_message_as_text (offerer_remote_sdp);

  answerer_local_sdp_str = gst_sdp_message_as_text (answerer_local_sdp);
  answerer_remote_sdp_str = gst_sdp_message_as_text (answerer_remote_sdp);

  GST_DEBUG ("Offerer local SDP\n%s", offerer_local_sdp_str);
  GST_DEBUG ("Offerer remote SDPr\n%s", offerer_remote_sdp_str);
  GST_DEBUG ("Answerer local SDP\n%s", answerer_local_sdp_str);
  GST_DEBUG ("Answerer remote SDP\n%s", answerer_remote_sdp_str);

  fail_unless (g_strcmp0 (offerer_local_sdp_str, answerer_remote_sdp_str) == 0);
  fail_unless (g_strcmp0 (offerer_remote_sdp_str, answerer_local_sdp_str) == 0);

  g_free (offerer_local_sdp_str);
  g_free (offerer_remote_sdp_str);
  g_free (answerer_local_sdp_str);
  g_free (answerer_remote_sdp_str);

  gst_sdp_message_free (offerer_local_sdp);
  gst_sdp_message_free (offerer_remote_sdp);
  gst_sdp_message_free (answerer_local_sdp);
  gst_sdp_message_free (answerer_remote_sdp);

  g_object_unref (offerer);
  g_object_unref (answerer);
  g_free (offerer_sess_id);
  g_free (answerer_sess_id);
}
Exemplo n.º 10
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;
}