static gint create_and_send_RECORD_message(GstRTSPsink* sink, GTimeVal *timeout, char *szSessionNumber) { GstRTSPMethod method; GstRTSPMessage msg = { 0 }; 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"; GstRTSPResult res; method = GST_RTSP_RECORD; res = gst_rtsp_message_init_request(&msg, method, url_server_str_full); if (res < 0) return res; gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_RANGE, "npt=0.000-"); // start live. gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_SESSION, szSessionNumber); // 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; } return res; }
GstRTSPResult rtsp_session_describe(RTSP_client_session *session) { GstRTSPMessage *message; GstRTSPResult res; gchar *uri, *cseq; gint nseq; uri = g_strdup_printf("rtsp://%s:%s%s", session->url->hostname, session->url->port, session->url->path); GST_RTSP_CHECK( gst_rtsp_message_new_request(&message, GST_RTSP_DESCRIBE, uri ), no_describe_message ); nseq = ++session->rtsp_seq; cseq = g_strdup_printf("%d", nseq); gst_rtsp_message_add_header(message, GST_RTSP_HDR_CSEQ, cseq ); gst_rtsp_message_add_header(message, GST_RTSP_HDR_ACCEPT, "application/sdp" ); res = rtsp_sesseion_send_message(session, message); gst_rtsp_message_free(message); if (res == GST_RTSP_OK) { session->wait_for.seq = nseq; session->wait_for.method = GST_RTSP_DESCRIBE; } g_free(cseq); g_free(uri); return res; no_describe_message: g_free(uri); return GST_RTSP_ENOMEM; }
void rtsp_handle_options_request(RTSP_Client *client, RTSP_Ps *state) { GstRTSPMethod options; gchar *str; rtsp_client_remove_dead_session(client); options = GST_RTSP_DESCRIBE | GST_RTSP_OPTIONS | GST_RTSP_PAUSE | GST_RTSP_PLAY | GST_RTSP_SETUP | GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN; str = gst_rtsp_options_as_text(options); gst_rtsp_message_init_response( state->response, GST_RTSP_STS_OK, gst_rtsp_status_as_text(GST_RTSP_STS_OK), state->request ); gst_rtsp_message_add_header(state->response, GST_RTSP_HDR_PUBLIC, str); g_free(str); rtsp_client_send_response(client, NULL, state->response); }
static gint create_and_send_SETUP_message(GstRTSPsink* sink, GTimeVal *timeout, char *szSessionNumber) { GstRTSPMethod method; 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"; GstRTSPResult res; GstRTSPMessage msg = { 0 }; gint video_start_port = 5002; gint video_end_port = video_start_port + 1; gchar *transfer_foramt; gchar *tmp; method = GST_RTSP_SETUP; tmp = g_strdup_printf("%s/streamid=0", url_server_str_full); res = gst_rtsp_message_init_request(&msg, method, tmp); if (res < 0) return res; transfer_foramt = g_strdup_printf("RTP/AVP/UDP;unicast;client_port=%d-%d;mode=record", video_start_port, video_end_port); gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_TRANSPORT, transfer_foramt); gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_SESSION, szSessionNumber); // TODO: Get the session id from the responce. gst_rtsp_message_add_header(&msg, GST_RTSP_HDR_CONTENT_LENGTH, "0"); // TODO: Get the session id from the responce. // 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; } GstRTSPTransport *transport; res = gst_rtsp_transport_new(&transport); res = extractTransportFromMessage(&msg, transport); g_print("Got server port %d", transport->server_port); sink->server_rtp_port = transport->server_port.min; if (res != GST_RTSP_OK) return -ERR_PARSING; return GST_RTSP_OK; }
/** * gst_rtsp_message_init_response: * @msg: a #GstRTSPMessage * @code: the status code * @reason: the status reason or #NULL * @request: the request that triggered the response or #NULL * * Initialize @msg with @code and @reason. * * When @reason is #NULL, the default reason for @code will be used. * * When @request is not #NULL, the relevant headers will be copied to the new * response message. * * Returns: a #GstRTSPResult. */ GstRTSPResult gst_rtsp_message_init_response (GstRTSPMessage * msg, GstRTSPStatusCode code, const gchar * reason, const GstRTSPMessage * request) { g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL); gst_rtsp_message_unset (msg); if (reason == NULL) reason = gst_rtsp_status_as_text (code); msg->type = GST_RTSP_MESSAGE_RESPONSE; msg->type_data.response.code = code; msg->type_data.response.reason = g_strdup (reason); msg->type_data.response.version = GST_RTSP_VERSION_1_0; msg->hdr_fields = g_array_new (FALSE, FALSE, sizeof (RTSPKeyValue)); if (request) { gchar *header; /* copy CSEQ */ if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_CSEQ, &header, 0) == GST_RTSP_OK) { gst_rtsp_message_add_header (msg, GST_RTSP_HDR_CSEQ, header); } /* copy session id */ if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &header, 0) == GST_RTSP_OK) { char *pos; header = g_strdup (header); if ((pos = strchr (header, ';'))) { *pos = '\0'; } g_strchomp (header); gst_rtsp_message_add_header (msg, GST_RTSP_HDR_SESSION, header); g_free (header); } /* FIXME copy more headers? */ } return GST_RTSP_OK; }
static gint create_and_send_OPTION_message(GstRTSPsink* sink, GTimeVal *timeout) { GstRTSPResult res; const gchar *url_server_str = g_strdup_printf("rtsp://%s", sink->host); //"rtsp://192.168.2.108"; // TODO: get ip and port from parameters. const gchar *url_server_ip_str = sink->host;// "192.168.2.108"; //GstRTSPConnection *conn = sink->conn ; int port = sink->port; GstRTSPUrl * url; GstRTSPMessage msg = { 0 }; // set parameters res = gst_rtsp_url_parse((const guint8*)url_server_str, &url); res = gst_rtsp_url_set_port(url, port); // create connection res = gst_rtsp_connection_create(url, &sink->conn); res = gst_rtsp_connection_connect(sink->conn, timeout); if (res != GST_RTSP_OK) goto beach; GstRTSPMethod method = GST_RTSP_OPTIONS; res = gst_rtsp_message_init_request(&msg, method, url_server_str); 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); // 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; } // check if server supports RECORD. if (isServerSupportStreamPush(&msg) != GST_RTSP_OK) { return -ERR_CANNOT_PUSH_STREAM; } beach: return GST_RTSP_OK; }
static __inline__ void nmp_rtsp_give_options_response(NmpMediaDevice *device, NmpRtspState *state, GstRTSPStatusCode code) { GstRTSPMethod options; gchar *str; if (code == GST_RTSP_STS_OK) { options = GST_RTSP_OPTIONS | GST_RTSP_TEARDOWN; str = gst_rtsp_options_as_text(options); gst_rtsp_message_init_response(state->response, GST_RTSP_STS_OK, gst_rtsp_status_as_text(GST_RTSP_STS_OK), state->request); gst_rtsp_message_add_header(state->response, GST_RTSP_HDR_PUBLIC, str); g_free(str); nmp_rtsp_device_send_response(device, state->response); } else { nmp_rtsp_device_send_generic_response(device, code, state); } }
static void test_client_sdp (const gchar * launch_line, guint * bandwidth_val) { GstRTSPClient *client; GstRTSPMessage request = { 0, }; gchar *str; /* simple DESCRIBE for an existing url */ client = setup_client (launch_line); fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE, "rtsp://localhost/test") == GST_RTSP_OK); str = g_strdup_printf ("%d", cseq); gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str); g_free (str); gst_rtsp_client_set_send_func (client, test_response_sdp, (gpointer) bandwidth_val, NULL); fail_unless (gst_rtsp_client_handle_message (client, &request) == GST_RTSP_OK); gst_rtsp_message_unset (&request); teardown_client (client); }
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; }