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, 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 gst_rtsp_connection_send (client->connection, response, &timeout);
172 gst_rtsp_message_unset (response);
176 send_generic_response (GstRTSPClient *client, GstRTSPStatusCode code,
177 GstRTSPMessage *request)
179 GstRTSPMessage response = { 0 };
181 gst_rtsp_message_init_response (&response, code,
182 gst_rtsp_status_as_text (code), request);
184 send_response (client, &response);
188 compare_uri (const GstRTSPUrl *uri1, const GstRTSPUrl *uri2)
190 if (uri1 == NULL || uri2 == NULL)
193 if (strcmp (uri1->abspath, uri2->abspath))
199 /* this function is called to initially find the media for the DESCRIBE request
200 * but is cached for when the same client (without breaking the connection) is
201 * doing a setup for the exact same url. */
202 static GstRTSPMedia *
203 find_media (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
205 GstRTSPMediaFactory *factory;
208 if (!compare_uri (client->uri, uri)) {
209 /* remove any previously cached values before we try to construct a new
212 gst_rtsp_url_free (client->uri);
215 g_object_unref (client->media);
216 client->media = NULL;
218 if (!client->media_mapping)
221 /* find the factory for the uri first */
222 if (!(factory = gst_rtsp_media_mapping_find_factory (client->media_mapping, uri)))
225 /* prepare the media and add it to the pipeline */
226 if (!(media = gst_rtsp_media_factory_construct (factory, uri)))
229 /* prepare the media */
230 if (!(gst_rtsp_media_prepare (media)))
233 /* now keep track of the uri and the media */
234 client->uri = gst_rtsp_url_copy (uri);
235 client->media = media;
238 /* we have seen this uri before, used cached media */
239 media = client->media;
240 g_message ("reusing cached media %p", media);
244 g_object_ref (media);
251 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
256 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
261 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
262 g_object_unref (factory);
267 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
268 g_object_unref (media);
269 g_object_unref (factory);
274 /* Get the session or NULL when there was no session */
275 static GstRTSPSession *
276 ensure_session (GstRTSPClient *client, GstRTSPMessage *request)
279 GstRTSPSession *session;
282 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
283 if (res == GST_RTSP_OK) {
284 if (client->session_pool == NULL)
287 /* we had a session in the request, find it again */
288 if (!(session = gst_rtsp_session_pool_find (client->session_pool, sessid)))
289 goto session_not_found;
291 client->timeout = gst_rtsp_session_get_timeout (session);
294 goto service_unavailable;
301 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
306 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
311 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
317 handle_teardown_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
319 GstRTSPSessionMedia *media;
320 GstRTSPSession *session;
321 GstRTSPMessage response = { 0 };
322 GstRTSPStatusCode code;
324 if (!(session = ensure_session (client, request)))
327 /* get a handle to the configuration of the media in the session */
328 media = gst_rtsp_session_get_media (session, uri);
332 gst_rtsp_session_media_stop (media);
334 /* unmanage the media in the session, returns false if all media session
336 if (!gst_rtsp_session_release_media (session, media)) {
337 /* remove the session */
338 gst_rtsp_session_pool_remove (client->session_pool, session);
340 /* remove the session id from the request, which will also remove it from the
342 gst_rtsp_message_remove_header (request, GST_RTSP_HDR_SESSION, -1);
344 g_object_unref (session);
346 /* construct the response now */
347 code = GST_RTSP_STS_OK;
348 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
350 send_response (client, &response);
357 /* error was sent already */
362 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
368 handle_pause_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
370 GstRTSPSessionMedia *media;
371 GstRTSPSession *session;
372 GstRTSPMessage response = { 0 };
373 GstRTSPStatusCode code;
375 if (!(session = ensure_session (client, request)))
378 /* get a handle to the configuration of the media in the session */
379 media = gst_rtsp_session_get_media (session, uri);
383 /* the session state must be playing or recording */
384 if (media->state != GST_RTSP_STATE_PLAYING &&
385 media->state != GST_RTSP_STATE_RECORDING)
388 gst_rtsp_session_media_pause (media);
390 /* construct the response now */
391 code = GST_RTSP_STS_OK;
392 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
394 send_response (client, &response);
396 /* the state is now READY */
397 media->state = GST_RTSP_STATE_READY;
398 g_object_unref (session);
409 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
410 g_object_unref (session);
415 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE, request);
416 g_object_unref (session);
422 handle_play_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
424 GstRTSPSessionMedia *media;
425 GstRTSPSession *session;
426 GstRTSPMessage response = { 0 };
427 GstRTSPStatusCode code;
430 guint timestamp, seqnum;
433 if (!(session = ensure_session (client, request)))
436 /* get a handle to the configuration of the media in the session */
437 media = gst_rtsp_session_get_media (session, uri);
441 /* the session state must be playing or ready */
442 if (media->state != GST_RTSP_STATE_PLAYING &&
443 media->state != GST_RTSP_STATE_READY)
446 /* grab RTPInfo from the payloaders now */
447 rtpinfo = g_string_new ("");
449 n_streams = gst_rtsp_media_n_streams (media->media);
450 for (i = 0; i < n_streams; i++) {
451 GstRTSPMediaStream *stream;
454 stream = gst_rtsp_media_get_stream (media->media, i);
456 g_object_get (G_OBJECT (stream->payloader), "seqnum", &seqnum, NULL);
457 g_object_get (G_OBJECT (stream->payloader), "timestamp", ×tamp, NULL);
460 g_string_append (rtpinfo, ", ");
462 uristr = gst_rtsp_url_get_request_uri (uri);
463 g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u", uristr, i, seqnum, timestamp);
467 /* construct the response now */
468 code = GST_RTSP_STS_OK;
469 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
471 /* add the RTP-Info header */
472 str = g_string_free (rtpinfo, FALSE);
473 gst_rtsp_message_take_header (&response, GST_RTSP_HDR_RTP_INFO, str);
476 str = gst_rtsp_range_to_string (&media->media->range);
477 gst_rtsp_message_take_header (&response, GST_RTSP_HDR_RANGE, str);
479 send_response (client, &response);
481 /* start playing after sending the request */
482 gst_rtsp_session_media_play (media);
484 media->state = GST_RTSP_STATE_PLAYING;
485 g_object_unref (session);
497 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
498 g_object_unref (session);
503 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE, request);
504 g_object_unref (session);
510 handle_setup_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
516 gboolean have_transport;
517 GstRTSPTransport *ct, *st;
518 GstRTSPSession *session;
520 GstRTSPLowerTrans supported;
521 GstRTSPMessage response = { 0 };
522 GstRTSPStatusCode code;
523 GstRTSPSessionStream *stream;
524 gchar *trans_str, *pos;
526 GstRTSPSessionMedia *media;
527 gboolean need_session;
529 /* the uri contains the stream number we added in the SDP config, which is
530 * always /stream=%d so we need to strip that off
531 * parse the stream we need to configure, look for the stream in the abspath
532 * first and then in the query. */
533 if (!(pos = strstr (uri->abspath, "/stream="))) {
534 if (!(pos = strstr (uri->query, "/stream=")))
538 /* we can mofify the parse uri in place */
541 pos += strlen ("/stream=");
542 if (sscanf (pos, "%u", &streamid) != 1)
545 /* parse the transport */
546 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_TRANSPORT, &transport, 0);
547 if (res != GST_RTSP_OK)
550 transports = g_strsplit (transport, ",", 0);
551 gst_rtsp_transport_new (&ct);
553 /* loop through the transports, try to parse */
554 have_transport = FALSE;
555 for (i = 0; transports[i]; i++) {
557 gst_rtsp_transport_init (ct);
558 res = gst_rtsp_transport_parse (transports[i], ct);
559 if (res == GST_RTSP_OK) {
560 have_transport = TRUE;
564 g_strfreev (transports);
566 /* we have not found anything usable, error out */
568 goto unsupported_transports;
570 /* we have a valid transport, check if we can handle it */
571 if (ct->trans != GST_RTSP_TRANS_RTP)
572 goto unsupported_transports;
573 if (ct->profile != GST_RTSP_PROFILE_AVP)
574 goto unsupported_transports;
576 supported = GST_RTSP_LOWER_TRANS_UDP |
577 GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
578 if (!(ct->lower_transport & supported))
579 goto unsupported_transports;
581 if (client->session_pool == NULL)
584 /* we have a valid transport now, set the destination of the client. */
585 g_free (ct->destination);
586 ct->destination = g_strdup (inet_ntoa (client->address.sin_addr));
588 /* a setup request creates a session for a client, check if the client already
589 * sent a session id to us */
590 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
591 if (res == GST_RTSP_OK) {
592 /* we had a session in the request, find it again */
593 if (!(session = gst_rtsp_session_pool_find (client->session_pool, sessid)))
594 goto session_not_found;
596 /* get a handle to the configuration of the media in the session, this can
597 * return NULL if this is a new url to manage in this session. */
598 media = gst_rtsp_session_get_media (session, uri);
600 need_session = FALSE;
603 /* create a session if this fails we probably reached our session limit or
605 if (!(session = gst_rtsp_session_pool_create (client->session_pool)))
606 goto service_unavailable;
608 /* we need a new media configuration in this session */
614 /* we have no media, find one and manage it */
618 /* get a handle to the configuration of the media in the session */
619 if ((m = find_media (client, uri, request))) {
620 /* manage the media in our session now */
621 media = gst_rtsp_session_manage_media (session, uri, m);
625 /* if we stil have no media, error */
629 /* get a handle to the stream in the media */
630 if (!(stream = gst_rtsp_session_media_get_stream (media, streamid)))
633 /* setup the server transport from the client transport */
634 st = gst_rtsp_session_stream_set_transport (stream, ct);
636 /* serialize the server transport */
637 trans_str = gst_rtsp_transport_as_text (st);
638 gst_rtsp_transport_free (st);
640 /* construct the response now */
641 code = GST_RTSP_STS_OK;
642 gst_rtsp_message_init_response (&response, code, gst_rtsp_status_as_text (code), request);
644 /* add the new session header for new session ids */
648 if (session->timeout != 60)
649 str = g_strdup_printf ("%s; timeout=%d", session->sessionid, session->timeout);
651 str = g_strdup (session->sessionid);
653 gst_rtsp_message_take_header (&response, GST_RTSP_HDR_SESSION, str);
656 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_TRANSPORT, trans_str);
659 send_response (client, &response);
661 /* update the state */
662 switch (media->state) {
663 case GST_RTSP_STATE_PLAYING:
664 case GST_RTSP_STATE_RECORDING:
665 case GST_RTSP_STATE_READY:
666 /* no state change */
669 media->state = GST_RTSP_STATE_READY;
673 g_object_unref (session);
680 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request);
685 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
690 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
691 g_object_unref (media);
696 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
701 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request);
704 unsupported_transports:
706 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request);
707 gst_rtsp_transport_free (ct);
712 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
717 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
722 /* for the describe we must generate an SDP */
724 handle_describe_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
726 GstRTSPMessage response = { 0 };
733 /* check what kind of format is accepted, we don't really do anything with it
734 * and always return SDP for now. */
738 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_ACCEPT, &accept, i);
739 if (res == GST_RTSP_ENOTIMPL)
742 if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
746 /* find the media object for the uri */
747 if (!(media = find_media (client, uri, request)))
750 /* create an SDP for the media object */
751 if (!(sdp = gst_rtsp_sdp_from_media (media)))
754 g_object_unref (media);
756 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
757 gst_rtsp_status_as_text (GST_RTSP_STS_OK), request);
759 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_TYPE, "application/sdp");
761 /* content base for some clients that might screw up creating the setup uri */
762 str = g_strdup_printf ("rtsp://%s:%u%s/", uri->host, uri->port, uri->abspath);
763 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_BASE, str);
766 /* add SDP to the response body */
767 str = gst_sdp_message_as_text (sdp);
768 gst_rtsp_message_take_body (&response, (guint8 *)str, strlen (str));
769 gst_sdp_message_free (sdp);
771 send_response (client, &response);
778 /* error reply is already sent */
783 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
784 g_object_unref (media);
790 handle_options_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *request)
792 GstRTSPMessage response = { 0 };
793 GstRTSPMethod options;
796 options = GST_RTSP_DESCRIBE |
803 str = gst_rtsp_options_as_text (options);
805 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
806 gst_rtsp_status_as_text (GST_RTSP_STS_OK), request);
808 gst_rtsp_message_add_header (&response, GST_RTSP_HDR_PUBLIC, str);
811 send_response (client, &response);
814 /* remove duplicate and trailing '/' */
816 santize_uri (GstRTSPUrl *uri)
820 gboolean have_slash, prev_slash;
822 s = d = uri->abspath;
823 len = strlen (uri->abspath);
827 for (i = 0; i < len; i++) {
828 have_slash = s[i] == '/';
830 if (!have_slash || !prev_slash)
832 prev_slash = have_slash;
834 len = d - uri->abspath;
835 /* don't remove the first slash if that's the only thing left */
836 if (len > 1 && *(d-1) == '/')
841 /* this function runs in a client specific thread and handles all rtsp messages
844 handle_client (GstRTSPClient *client)
846 GstRTSPMessage request = { 0 };
848 GstRTSPMethod method;
851 GstRTSPVersion version;
856 timeout.tv_sec = client->timeout;
858 /* start by waiting for a message from the client */
859 res = gst_rtsp_connection_receive (client->connection, &request, &timeout);
864 gst_rtsp_message_dump (&request);
867 gst_rtsp_message_parse_request (&request, &method, &uristr, &version);
869 if (version != GST_RTSP_VERSION_1_0) {
870 /* we can only handle 1.0 requests */
871 send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED, &request);
875 /* we always try to parse the url first */
876 if ((res = gst_rtsp_url_parse (uristr, &uri)) != GST_RTSP_OK) {
877 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &request);
881 /* sanitize the uri */
884 /* now see what is asked and dispatch to a dedicated handler */
886 case GST_RTSP_OPTIONS:
887 handle_options_request (client, uri, &request);
889 case GST_RTSP_DESCRIBE:
890 handle_describe_request (client, uri, &request);
893 handle_setup_request (client, uri, &request);
896 handle_play_request (client, uri, &request);
899 handle_pause_request (client, uri, &request);
901 case GST_RTSP_TEARDOWN:
902 handle_teardown_request (client, uri, &request);
904 case GST_RTSP_ANNOUNCE:
905 case GST_RTSP_GET_PARAMETER:
906 case GST_RTSP_RECORD:
907 case GST_RTSP_REDIRECT:
908 case GST_RTSP_SET_PARAMETER:
909 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &request);
911 case GST_RTSP_INVALID:
913 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &request);
916 gst_rtsp_url_free (uri);
918 g_object_unref (client);
925 str = gst_rtsp_strresult (res);
926 g_message ("receive failed %d (%s), disconnect client %p", res,
929 gst_rtsp_message_unset (&request);
930 gst_rtsp_connection_close (client->connection);
931 g_object_unref (client);
936 /* called when we need to accept a new request from a client */
938 client_accept (GstRTSPClient *client, GIOChannel *channel)
940 /* a new client connected. */
941 int server_sock_fd, fd;
942 unsigned int address_len;
943 GstRTSPConnection *conn;
945 server_sock_fd = g_io_channel_unix_get_fd (channel);
947 address_len = sizeof (client->address);
948 memset (&client->address, 0, address_len);
950 fd = accept (server_sock_fd, (struct sockaddr *) &client->address,
955 /* now create the connection object */
956 gst_rtsp_connection_create (NULL, &conn);
959 /* FIXME some hackery, we need to have a connection method to accept server
961 gst_poll_add_fd (conn->fdset, &conn->fd);
963 g_message ("added new client %p ip %s with fd %d", client,
964 inet_ntoa (client->address.sin_addr), conn->fd.fd);
966 client->connection = conn;
973 g_error ("Could not accept client on server socket %d: %s (%d)",
974 server_sock_fd, g_strerror (errno), errno);
980 * gst_rtsp_client_set_timeout:
981 * @client: a #GstRTSPClient
982 * @timeout: a timeout in seconds
984 * Set the connection timeout to @timeout seconds for @client.
987 gst_rtsp_client_set_timeout (GstRTSPClient *client, guint timeout)
989 client->timeout = timeout;
993 * gst_rtsp_client_get_timeout:
994 * @client: a #GstRTSPClient
996 * Get the connection timeout @client.
998 * Returns: the connection timeout for @client in seconds.
1001 gst_rtsp_client_get_timeout (GstRTSPClient *client)
1003 return client->timeout;
1007 * gst_rtsp_client_set_session_pool:
1008 * @client: a #GstRTSPClient
1009 * @pool: a #GstRTSPSessionPool
1011 * Set @pool as the sessionpool for @client which it will use to find
1012 * or allocate sessions. the sessionpool is usually inherited from the server
1013 * that created the client but can be overridden later.
1016 gst_rtsp_client_set_session_pool (GstRTSPClient *client, GstRTSPSessionPool *pool)
1018 GstRTSPSessionPool *old;
1020 old = client->session_pool;
1023 g_object_ref (pool);
1024 client->session_pool = pool;
1026 g_object_unref (old);
1031 * gst_rtsp_client_get_session_pool:
1032 * @client: a #GstRTSPClient
1034 * Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
1036 * Returns: a #GstRTSPSessionPool, unref after usage.
1038 GstRTSPSessionPool *
1039 gst_rtsp_client_get_session_pool (GstRTSPClient *client)
1041 GstRTSPSessionPool *result;
1043 if ((result = client->session_pool))
1044 g_object_ref (result);
1050 * gst_rtsp_client_set_media_mapping:
1051 * @client: a #GstRTSPClient
1052 * @mapping: a #GstRTSPMediaMapping
1054 * Set @mapping as the media mapping for @client which it will use to map urls
1055 * to media streams. These mapping is usually inherited from the server that
1056 * created the client but can be overriden later.
1059 gst_rtsp_client_set_media_mapping (GstRTSPClient *client, GstRTSPMediaMapping *mapping)
1061 GstRTSPMediaMapping *old;
1063 old = client->media_mapping;
1065 if (old != mapping) {
1067 g_object_ref (mapping);
1068 client->media_mapping = mapping;
1070 g_object_unref (old);
1075 * gst_rtsp_client_get_media_mapping:
1076 * @client: a #GstRTSPClient
1078 * Get the #GstRTSPMediaMapping object that @client uses to manage its sessions.
1080 * Returns: a #GstRTSPMediaMapping, unref after usage.
1082 GstRTSPMediaMapping *
1083 gst_rtsp_client_get_media_mapping (GstRTSPClient *client)
1085 GstRTSPMediaMapping *result;
1087 if ((result = client->media_mapping))
1088 g_object_ref (result);
1094 * gst_rtsp_client_attach:
1095 * @client: a #GstRTSPClient
1096 * @channel: a #GIOChannel
1098 * Accept a new connection for @client on the socket in @source.
1100 * This function should be called when the client properties and urls are fully
1101 * configured and the client is ready to start.
1103 * Returns: %TRUE if the client could be accepted.
1106 gst_rtsp_client_accept (GstRTSPClient *client, GIOChannel *channel)
1108 GError *error = NULL;
1110 if (!client_accept (client, channel))
1113 /* client accepted, spawn a thread for the client, we don't need to join the
1115 g_object_ref (client);
1116 client->thread = g_thread_create ((GThreadFunc)handle_client, client, FALSE, &error);
1117 if (client->thread == NULL)
1130 g_warning ("could not create thread for client %p: %s", client, error->message);
1131 g_error_free (error);
1133 g_object_unref (client);