2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <sys/ioctl.h>
22 #include "rtsp-client.h"
27 #define DEFAULT_TIMEOUT 60
38 static void gst_rtsp_client_get_property (GObject *object, guint propid,
39 GValue *value, GParamSpec *pspec);
40 static void gst_rtsp_client_set_property (GObject *object, guint propid,
41 const GValue *value, GParamSpec *pspec);
42 static void gst_rtsp_client_finalize (GObject * obj);
44 G_DEFINE_TYPE (GstRTSPClient, gst_rtsp_client, G_TYPE_OBJECT);
47 gst_rtsp_client_class_init (GstRTSPClientClass * klass)
49 GObjectClass *gobject_class;
51 gobject_class = G_OBJECT_CLASS (klass);
53 gobject_class->get_property = gst_rtsp_client_get_property;
54 gobject_class->set_property = gst_rtsp_client_set_property;
55 gobject_class->finalize = gst_rtsp_client_finalize;
57 g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
58 g_param_spec_uint ("timeout", "Timeout", "The client timeout",
59 0, G_MAXUINT, DEFAULT_TIMEOUT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
61 g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
62 g_param_spec_object ("session-pool", "Session Pool",
63 "The session pool to use for client session",
64 GST_TYPE_RTSP_SESSION_POOL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
66 g_object_class_install_property (gobject_class, PROP_MEDIA_MAPPING,
67 g_param_spec_object ("media-mapping", "Media Mapping",
68 "The media mapping to use for client session",
69 GST_TYPE_RTSP_MEDIA_MAPPING, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
73 gst_rtsp_client_init (GstRTSPClient * client)
75 client->timeout = DEFAULT_TIMEOUT;
78 /* A client is finalized when the connection is broken */
80 gst_rtsp_client_finalize (GObject * obj)
82 GstRTSPClient *client = GST_RTSP_CLIENT (obj);
84 g_message ("finalize client %p", client);
86 gst_rtsp_connection_free (client->connection);
87 if (client->session_pool)
88 g_object_unref (client->session_pool);
89 if (client->media_mapping)
90 g_object_unref (client->media_mapping);
93 gst_rtsp_url_free (client->uri);
95 g_object_unref (client->media);
97 G_OBJECT_CLASS (gst_rtsp_client_parent_class)->finalize (obj);
101 gst_rtsp_client_get_property (GObject *object, guint propid,
102 GValue *value, GParamSpec *pspec)
104 GstRTSPClient *client = GST_RTSP_CLIENT (object);
108 g_value_set_uint (value, gst_rtsp_client_get_timeout (client));
110 case PROP_SESSION_POOL:
111 g_value_take_object (value, gst_rtsp_client_get_session_pool (client));
113 case PROP_MEDIA_MAPPING:
114 g_value_take_object (value, gst_rtsp_client_get_media_mapping (client));
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
122 gst_rtsp_client_set_property (GObject *object, guint propid,
123 const GValue *value, GParamSpec *pspec)
125 GstRTSPClient *client = GST_RTSP_CLIENT (object);
129 gst_rtsp_client_set_timeout (client, g_value_get_uint (value));
131 case PROP_SESSION_POOL:
132 gst_rtsp_client_set_session_pool (client, g_value_get_object (value));
134 case PROP_MEDIA_MAPPING:
135 gst_rtsp_client_set_media_mapping (client, g_value_get_object (value));
138 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
143 * gst_rtsp_client_new:
145 * Create a new #GstRTSPClient instance.
148 gst_rtsp_client_new (void)
150 GstRTSPClient *result;
152 result = g_object_new (GST_TYPE_RTSP_CLIENT, NULL);
158 send_response (GstRTSPClient *client, GstRTSPSession *session, GstRTSPMessage *response)
162 gst_rtsp_message_add_header (response, GST_RTSP_HDR_SERVER, "GStreamer RTSP server");
165 gst_rtsp_message_dump (response);
168 timeout.tv_sec = client->timeout;
171 /* add the new session header for new session ids */
175 if (session->timeout != 60)
176 str = g_strdup_printf ("%s; timeout=%d", session->sessionid, session->timeout);
178 str = g_strdup (session->sessionid);
180 gst_rtsp_message_take_header (response, GST_RTSP_HDR_SESSION, str);
183 /* remove the session id from the response */
184 gst_rtsp_message_remove_header (response, GST_RTSP_HDR_SESSION, -1);
187 gst_rtsp_connection_send (client->connection, response, &timeout);
188 gst_rtsp_message_unset (response);
192 send_generic_response (GstRTSPClient *client, GstRTSPStatusCode code,
193 GstRTSPMessage *request)
195 GstRTSPMessage response = { 0 };
197 gst_rtsp_message_init_response (&response, code,
198 gst_rtsp_status_as_text (code), request);
200 send_response (client, NULL, &response);
204 compare_uri (const GstRTSPUrl *uri1, const GstRTSPUrl *uri2)
206 if (uri1 == NULL || uri2 == NULL)
209 if (strcmp (uri1->abspath, uri2->abspath))
215 /* this function is called to initially find the media for the DESCRIBE request
216 * but is cached for when the same client (without breaking the connection) is
217 * doing a setup for the exact same url. */
218 static GstRTSPMedia *
219 find_media (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
221 GstRTSPMediaFactory *factory;
224 if (!compare_uri (client->uri, uri)) {
225 /* remove any previously cached values before we try to construct a new
228 gst_rtsp_url_free (client->uri);
231 g_object_unref (client->media);
232 client->media = NULL;
234 if (!client->media_mapping)
237 /* find the factory for the uri first */
238 if (!(factory = gst_rtsp_media_mapping_find_factory (client->media_mapping, uri)))
241 /* prepare the media and add it to the pipeline */
242 if (!(media = gst_rtsp_media_factory_construct (factory, uri)))
245 /* prepare the media */
246 if (!(gst_rtsp_media_prepare (media)))
249 /* now keep track of the uri and the media */
250 client->uri = gst_rtsp_url_copy (uri);
251 client->media = media;
254 /* we have seen this uri before, used cached media */
255 media = client->media;
256 g_message ("reusing cached media %p", media);
260 g_object_ref (media);
267 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
272 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
277 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
278 g_object_unref (factory);
283 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
284 g_object_unref (media);
285 g_object_unref (factory);
290 /* Get the session or NULL when there was no session */
291 static GstRTSPSession *
292 find_session (GstRTSPClient *client, GstRTSPMessage *request)
295 GstRTSPSession *session;
298 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
299 if (res == GST_RTSP_OK) {
300 if (client->session_pool == NULL)
303 /* we had a session in the request, find it again */
304 if (!(session = gst_rtsp_session_pool_find (client->session_pool, sessid)))
305 goto session_not_found;
307 client->timeout = gst_rtsp_session_get_timeout (session);
310 goto service_unavailable;
330 handle_teardown_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPSession *session, GstRTSPMessage *request)
332 GstRTSPSessionMedia *media;
333 GstRTSPMessage response = { 0 };
334 GstRTSPStatusCode code;
339 /* get a handle to the configuration of the media in the session */
340 media = gst_rtsp_session_get_media (session, uri);
344 gst_rtsp_session_media_stop (media);
346 /* unmanage the media in the session, returns false if all media session
348 if (!gst_rtsp_session_release_media (session, media)) {
349 /* remove the session */
350 gst_rtsp_session_pool_remove (client->session_pool, session);
352 /* construct the response now */
353 code = GST_RTSP_STS_OK;
354 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
356 send_response (client, session, &response);
363 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
368 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
374 handle_pause_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPSession *session, GstRTSPMessage *request)
376 GstRTSPSessionMedia *media;
377 GstRTSPMessage response = { 0 };
378 GstRTSPStatusCode code;
383 /* get a handle to the configuration of the media in the session */
384 media = gst_rtsp_session_get_media (session, uri);
388 /* the session state must be playing or recording */
389 if (media->state != GST_RTSP_STATE_PLAYING &&
390 media->state != GST_RTSP_STATE_RECORDING)
393 gst_rtsp_session_media_pause (media);
395 /* construct the response now */
396 code = GST_RTSP_STS_OK;
397 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
399 send_response (client, session, &response);
401 /* the state is now READY */
402 media->state = GST_RTSP_STATE_READY;
409 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
414 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
419 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE, request);
425 handle_play_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPSession *session, GstRTSPMessage *request)
427 GstRTSPSessionMedia *media;
428 GstRTSPMessage response = { 0 };
429 GstRTSPStatusCode code;
432 guint timestamp, seqnum;
438 /* get a handle to the configuration of the media in the session */
439 media = gst_rtsp_session_get_media (session, uri);
443 /* the session state must be playing or ready */
444 if (media->state != GST_RTSP_STATE_PLAYING &&
445 media->state != GST_RTSP_STATE_READY)
448 /* grab RTPInfo from the payloaders now */
449 rtpinfo = g_string_new ("");
451 n_streams = gst_rtsp_media_n_streams (media->media);
452 for (i = 0; i < n_streams; i++) {
453 GstRTSPMediaStream *stream;
456 stream = gst_rtsp_media_get_stream (media->media, i);
458 g_object_get (G_OBJECT (stream->payloader), "seqnum", &seqnum, NULL);
459 g_object_get (G_OBJECT (stream->payloader), "timestamp", ×tamp, NULL);
462 g_string_append (rtpinfo, ", ");
464 uristr = gst_rtsp_url_get_request_uri (uri);
465 g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u", uristr, i, seqnum, timestamp);
469 /* construct the response now */
470 code = GST_RTSP_STS_OK;
471 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
473 /* add the RTP-Info header */
474 str = g_string_free (rtpinfo, FALSE);
475 gst_rtsp_message_take_header (&response, GST_RTSP_HDR_RTP_INFO, str);
478 str = gst_rtsp_range_to_string (&media->media->range);
479 gst_rtsp_message_take_header (&response, GST_RTSP_HDR_RANGE, str);
481 send_response (client, session, &response);
483 /* start playing after sending the request */
484 gst_rtsp_session_media_play (media);
486 media->state = GST_RTSP_STATE_PLAYING;
498 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
503 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE, request);
509 handle_setup_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPSession *session, GstRTSPMessage *request)
514 gboolean have_transport;
515 GstRTSPTransport *ct, *st;
517 GstRTSPLowerTrans supported;
518 GstRTSPMessage response = { 0 };
519 GstRTSPStatusCode code;
520 GstRTSPSessionStream *stream;
521 gchar *trans_str, *pos;
523 GstRTSPSessionMedia *media;
524 gboolean need_session;
526 /* the uri contains the stream number we added in the SDP config, which is
527 * always /stream=%d so we need to strip that off
528 * parse the stream we need to configure, look for the stream in the abspath
529 * first and then in the query. */
530 if (!(pos = strstr (uri->abspath, "/stream="))) {
531 if (!(pos = strstr (uri->query, "/stream=")))
535 /* we can mofify the parse uri in place */
538 pos += strlen ("/stream=");
539 if (sscanf (pos, "%u", &streamid) != 1)
542 /* parse the transport */
543 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_TRANSPORT, &transport, 0);
544 if (res != GST_RTSP_OK)
547 transports = g_strsplit (transport, ",", 0);
548 gst_rtsp_transport_new (&ct);
550 /* loop through the transports, try to parse */
551 have_transport = FALSE;
552 for (i = 0; transports[i]; i++) {
554 gst_rtsp_transport_init (ct);
555 res = gst_rtsp_transport_parse (transports[i], ct);
556 if (res == GST_RTSP_OK) {
557 have_transport = TRUE;
561 g_strfreev (transports);
563 /* we have not found anything usable, error out */
565 goto unsupported_transports;
567 /* we have a valid transport, check if we can handle it */
568 if (ct->trans != GST_RTSP_TRANS_RTP)
569 goto unsupported_transports;
570 if (ct->profile != GST_RTSP_PROFILE_AVP)
571 goto unsupported_transports;
573 supported = GST_RTSP_LOWER_TRANS_UDP |
574 GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
575 if (!(ct->lower_transport & supported))
576 goto unsupported_transports;
578 if (client->session_pool == NULL)
581 /* we have a valid transport now, set the destination of the client. */
582 g_free (ct->destination);
583 ct->destination = g_strdup (inet_ntoa (client->address.sin_addr));
586 g_object_ref (session);
587 /* get a handle to the configuration of the media in the session, this can
588 * return NULL if this is a new url to manage in this session. */
589 media = gst_rtsp_session_get_media (session, uri);
591 need_session = FALSE;
594 /* create a session if this fails we probably reached our session limit or
596 if (!(session = gst_rtsp_session_pool_create (client->session_pool)))
597 goto service_unavailable;
599 /* we need a new media configuration in this session */
605 /* we have no media, find one and manage it */
609 /* get a handle to the configuration of the media in the session */
610 if ((m = find_media (client, uri, request))) {
611 /* manage the media in our session now */
612 media = gst_rtsp_session_manage_media (session, uri, m);
616 /* if we stil have no media, error */
620 /* get a handle to the stream in the media */
621 if (!(stream = gst_rtsp_session_media_get_stream (media, streamid)))
624 /* setup the server transport from the client transport */
625 st = gst_rtsp_session_stream_set_transport (stream, ct);
627 /* serialize the server transport */
628 trans_str = gst_rtsp_transport_as_text (st);
629 gst_rtsp_transport_free (st);
631 /* construct the response now */
632 code = GST_RTSP_STS_OK;
633 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
635 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_TRANSPORT, trans_str);
638 send_response (client, session, &response);
640 /* update the state */
641 switch (media->state) {
642 case GST_RTSP_STATE_PLAYING:
643 case GST_RTSP_STATE_RECORDING:
644 case GST_RTSP_STATE_READY:
645 /* no state change */
648 media->state = GST_RTSP_STATE_READY;
651 g_object_unref (session);
658 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request);
663 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
664 g_object_unref (session);
669 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
670 g_object_unref (media);
671 g_object_unref (session);
676 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request);
679 unsupported_transports:
681 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request);
682 gst_rtsp_transport_free (ct);
687 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
692 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
697 /* for the describe we must generate an SDP */
699 handle_describe_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPSession *session, GstRTSPMessage *request)
701 GstRTSPMessage response = { 0 };
708 /* check what kind of format is accepted, we don't really do anything with it
709 * and always return SDP for now. */
713 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_ACCEPT, &accept, i);
714 if (res == GST_RTSP_ENOTIMPL)
717 if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
721 /* find the media object for the uri */
722 if (!(media = find_media (client, uri, request)))
725 /* create an SDP for the media object */
726 if (!(sdp = gst_rtsp_sdp_from_media (media)))
729 g_object_unref (media);
731 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
732 gst_rtsp_status_as_text (GST_RTSP_STS_OK), request);
734 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_TYPE, "application/sdp");
736 /* content base for some clients that might screw up creating the setup uri */
737 str = g_strdup_printf ("rtsp://%s:%u%s/", uri->host, uri->port, uri->abspath);
738 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_BASE, str);
741 /* add SDP to the response body */
742 str = gst_sdp_message_as_text (sdp);
743 gst_rtsp_message_take_body (&response, (guint8 *)str, strlen (str));
744 gst_sdp_message_free (sdp);
746 send_response (client, NULL, &response);
753 /* error reply is already sent */
758 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
759 g_object_unref (media);
765 handle_options_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPSession *session, GstRTSPMessage *request)
767 GstRTSPMessage response = { 0 };
768 GstRTSPMethod options;
771 options = GST_RTSP_DESCRIBE |
778 str = gst_rtsp_options_as_text (options);
780 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
781 gst_rtsp_status_as_text (GST_RTSP_STS_OK), request);
783 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_PUBLIC, str);
786 send_response (client, NULL, &response);
789 /* remove duplicate and trailing '/' */
791 santize_uri (GstRTSPUrl *uri)
795 gboolean have_slash, prev_slash;
797 s = d = uri->abspath;
798 len = strlen (uri->abspath);
802 for (i = 0; i < len; i++) {
803 have_slash = s[i] == '/';
805 if (!have_slash || !prev_slash)
807 prev_slash = have_slash;
809 len = d - uri->abspath;
810 /* don't remove the first slash if that's the only thing left */
811 if (len > 1 && *(d-1) == '/')
816 /* this function runs in a client specific thread and handles all rtsp messages
819 handle_client (GstRTSPClient *client)
821 GstRTSPMessage request = { 0 };
823 GstRTSPMethod method;
826 GstRTSPVersion version;
830 GstRTSPSession *session;
832 timeout.tv_sec = client->timeout;
835 /* start by waiting for a message from the client */
836 res = gst_rtsp_connection_receive (client->connection, &request, &timeout);
838 if (res == GST_RTSP_ETIMEOUT)
845 gst_rtsp_message_dump (&request);
848 gst_rtsp_message_parse_request (&request, &method, &uristr, &version);
850 if (version != GST_RTSP_VERSION_1_0) {
851 /* we can only handle 1.0 requests */
852 send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED, &request);
856 /* we always try to parse the url first */
857 if ((res = gst_rtsp_url_parse (uristr, &uri)) != GST_RTSP_OK) {
858 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &request);
862 /* sanitize the uri */
865 /* get the session if there is any */
866 session = find_session (client, &request);
868 /* now see what is asked and dispatch to a dedicated handler */
870 case GST_RTSP_OPTIONS:
871 handle_options_request (client, uri, session, &request);
873 case GST_RTSP_DESCRIBE:
874 handle_describe_request (client, uri, session, &request);
877 handle_setup_request (client, uri, session, &request);
880 handle_play_request (client, uri, session, &request);
883 handle_pause_request (client, uri, session, &request);
885 case GST_RTSP_TEARDOWN:
886 handle_teardown_request (client, uri, session, &request);
888 case GST_RTSP_ANNOUNCE:
889 case GST_RTSP_GET_PARAMETER:
890 case GST_RTSP_RECORD:
891 case GST_RTSP_REDIRECT:
892 case GST_RTSP_SET_PARAMETER:
893 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &request);
895 case GST_RTSP_INVALID:
897 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &request);
901 g_object_unref (session);
902 gst_rtsp_url_free (uri);
904 g_object_unref (client);
910 g_message ("client timed out");
911 if (client->session_pool)
912 gst_rtsp_session_pool_cleanup (client->session_pool);
918 str = gst_rtsp_strresult (res);
919 g_message ("receive failed %d (%s), disconnect client %p", res,
926 gst_rtsp_message_unset (&request);
927 gst_rtsp_connection_close (client->connection);
928 g_object_unref (client);
933 /* called when we need to accept a new request from a client */
935 client_accept (GstRTSPClient *client, GIOChannel *channel)
937 /* a new client connected. */
938 int server_sock_fd, fd;
939 unsigned int address_len;
940 GstRTSPConnection *conn;
942 server_sock_fd = g_io_channel_unix_get_fd (channel);
944 address_len = sizeof (client->address);
945 memset (&client->address, 0, address_len);
947 fd = accept (server_sock_fd, (struct sockaddr *) &client->address,
952 /* now create the connection object */
953 gst_rtsp_connection_create (NULL, &conn);
956 /* FIXME some hackery, we need to have a connection method to accept server
958 gst_poll_add_fd (conn->fdset, &conn->fd);
960 g_message ("added new client %p ip %s with fd %d", client,
961 inet_ntoa (client->address.sin_addr), conn->fd.fd);
963 client->connection = conn;
970 g_error ("Could not accept client on server socket %d: %s (%d)",
971 server_sock_fd, g_strerror (errno), errno);
977 * gst_rtsp_client_set_timeout:
978 * @client: a #GstRTSPClient
979 * @timeout: a timeout in seconds
981 * Set the connection timeout to @timeout seconds for @client.
984 gst_rtsp_client_set_timeout (GstRTSPClient *client, guint timeout)
986 client->timeout = timeout;
990 * gst_rtsp_client_get_timeout:
991 * @client: a #GstRTSPClient
993 * Get the connection timeout @client.
995 * Returns: the connection timeout for @client in seconds.
998 gst_rtsp_client_get_timeout (GstRTSPClient *client)
1000 return client->timeout;
1004 * gst_rtsp_client_set_session_pool:
1005 * @client: a #GstRTSPClient
1006 * @pool: a #GstRTSPSessionPool
1008 * Set @pool as the sessionpool for @client which it will use to find
1009 * or allocate sessions. the sessionpool is usually inherited from the server
1010 * that created the client but can be overridden later.
1013 gst_rtsp_client_set_session_pool (GstRTSPClient *client, GstRTSPSessionPool *pool)
1015 GstRTSPSessionPool *old;
1017 old = client->session_pool;
1020 g_object_ref (pool);
1021 client->session_pool = pool;
1023 g_object_unref (old);
1028 * gst_rtsp_client_get_session_pool:
1029 * @client: a #GstRTSPClient
1031 * Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
1033 * Returns: a #GstRTSPSessionPool, unref after usage.
1035 GstRTSPSessionPool *
1036 gst_rtsp_client_get_session_pool (GstRTSPClient *client)
1038 GstRTSPSessionPool *result;
1040 if ((result = client->session_pool))
1041 g_object_ref (result);
1047 * gst_rtsp_client_set_media_mapping:
1048 * @client: a #GstRTSPClient
1049 * @mapping: a #GstRTSPMediaMapping
1051 * Set @mapping as the media mapping for @client which it will use to map urls
1052 * to media streams. These mapping is usually inherited from the server that
1053 * created the client but can be overriden later.
1056 gst_rtsp_client_set_media_mapping (GstRTSPClient *client, GstRTSPMediaMapping *mapping)
1058 GstRTSPMediaMapping *old;
1060 old = client->media_mapping;
1062 if (old != mapping) {
1064 g_object_ref (mapping);
1065 client->media_mapping = mapping;
1067 g_object_unref (old);
1072 * gst_rtsp_client_get_media_mapping:
1073 * @client: a #GstRTSPClient
1075 * Get the #GstRTSPMediaMapping object that @client uses to manage its sessions.
1077 * Returns: a #GstRTSPMediaMapping, unref after usage.
1079 GstRTSPMediaMapping *
1080 gst_rtsp_client_get_media_mapping (GstRTSPClient *client)
1082 GstRTSPMediaMapping *result;
1084 if ((result = client->media_mapping))
1085 g_object_ref (result);
1091 * gst_rtsp_client_attach:
1092 * @client: a #GstRTSPClient
1093 * @channel: a #GIOChannel
1095 * Accept a new connection for @client on the socket in @source.
1097 * This function should be called when the client properties and urls are fully
1098 * configured and the client is ready to start.
1100 * Returns: %TRUE if the client could be accepted.
1103 gst_rtsp_client_accept (GstRTSPClient *client, GIOChannel *channel)
1105 GError *error = NULL;
1107 if (!client_accept (client, channel))
1110 /* client accepted, spawn a thread for the client, we don't need to join the
1112 g_object_ref (client);
1113 client->thread = g_thread_create ((GThreadFunc)handle_client, client, FALSE, &error);
1114 if (client->thread == NULL)
1127 g_warning ("could not create thread for client %p: %s", client, error->message);
1128 g_error_free (error);
1130 g_object_unref (client);