Esempio n. 1
0
static gboolean
kms_sdp_message_context_set_default_session_attributes (GstSDPMessage * msg,
    SdpIPv ipv, const gchar * addr, GError ** error)
{
  const gchar *addrtype, *err_attr;
  gchar *ntp;

  addrtype = get_attr_addr_type (ipv);
  if (addrtype == NULL) {
    err_attr = "ip version";
    goto error;
  }

  if (gst_sdp_message_set_version (msg, "0") != GST_SDP_OK) {
    err_attr = "version";
    goto error;
  }

  /* The method of generating <sess-id> and <sess-version> is up to the    */
  /* creating tool, but it has been suggested that a Network Time Protocol */
  /* (NTP) format timestamp be used to ensure uniqueness [rfc4566] 5.2     */
  ntp = g_strdup_printf ("%" G_GUINT64_FORMAT, get_ntp_time ());

  if (gst_sdp_message_set_origin (msg, "-", ntp, ntp, ORIGIN_ATTR_NETTYPE,
          addrtype, addr) != GST_SDP_OK) {
    err_attr = "origin";
    g_free (ntp);
    goto error;
  }

  g_free (ntp);

  if (gst_sdp_message_set_session_name (msg,
          "Kurento Media Server") != GST_SDP_OK) {
    err_attr = "session";
    goto error;
  }

  if (gst_sdp_message_set_connection (msg, ORIGIN_ATTR_NETTYPE, addrtype,
          addr, 0, 0) != GST_SDP_OK) {
    err_attr = "connection";
    goto error;
  }

  return TRUE;

error:
  g_set_error (error, KMS_SDP_AGENT_ERROR, SDP_AGENT_INVALID_PARAMETER,
      "Can not set attr: %s", err_attr);

  return FALSE;
}
Esempio n. 2
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;
}