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.
26 #include <sys/types.h>
27 #include <netinet/in.h>
29 #include <sys/socket.h>
32 #include <arpa/inet.h>
33 #include <sys/ioctl.h>
35 #include "rtsp-client.h"
37 #include "rtsp-params.h"
39 static GMutex tunnels_lock;
40 static GHashTable *tunnels;
56 GST_DEBUG_CATEGORY_STATIC (rtsp_client_debug);
57 #define GST_CAT_DEFAULT rtsp_client_debug
59 static guint gst_rtsp_client_signals[SIGNAL_LAST] = { 0 };
61 static void gst_rtsp_client_get_property (GObject * object, guint propid,
62 GValue * value, GParamSpec * pspec);
63 static void gst_rtsp_client_set_property (GObject * object, guint propid,
64 const GValue * value, GParamSpec * pspec);
65 static void gst_rtsp_client_finalize (GObject * obj);
67 static void client_session_finalized (GstRTSPClient * client,
68 GstRTSPSession * session);
69 static void unlink_session_streams (GstRTSPClient * client,
70 GstRTSPSession * session, GstRTSPSessionMedia * media);
72 G_DEFINE_TYPE (GstRTSPClient, gst_rtsp_client, G_TYPE_OBJECT);
75 gst_rtsp_client_class_init (GstRTSPClientClass * klass)
77 GObjectClass *gobject_class;
79 gobject_class = G_OBJECT_CLASS (klass);
81 gobject_class->get_property = gst_rtsp_client_get_property;
82 gobject_class->set_property = gst_rtsp_client_set_property;
83 gobject_class->finalize = gst_rtsp_client_finalize;
85 g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
86 g_param_spec_object ("session-pool", "Session Pool",
87 "The session pool to use for client session",
88 GST_TYPE_RTSP_SESSION_POOL,
89 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
91 g_object_class_install_property (gobject_class, PROP_MEDIA_MAPPING,
92 g_param_spec_object ("media-mapping", "Media Mapping",
93 "The media mapping to use for client session",
94 GST_TYPE_RTSP_MEDIA_MAPPING,
95 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
97 gst_rtsp_client_signals[SIGNAL_CLOSED] =
98 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
99 G_STRUCT_OFFSET (GstRTSPClientClass, closed), NULL, NULL,
100 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
103 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
104 g_mutex_init (&tunnels_lock);
106 GST_DEBUG_CATEGORY_INIT (rtsp_client_debug, "rtspclient", 0, "GstRTSPClient");
110 gst_rtsp_client_init (GstRTSPClient * client)
115 client_unlink_session (GstRTSPClient * client, GstRTSPSession * session)
119 /* unlink all media managed in this session */
120 for (medias = session->medias; medias; medias = g_list_next (medias)) {
121 GstRTSPSessionMedia *media = medias->data;
123 gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
124 unlink_session_streams (client, session, media);
125 /* unmanage the media in the session. */
126 gst_rtsp_session_release_media (session, media);
131 client_cleanup_sessions (GstRTSPClient * client)
135 /* remove weak-ref from sessions */
136 for (sessions = client->sessions; sessions; sessions = g_list_next (sessions)) {
137 GstRTSPSession *session = (GstRTSPSession *) sessions->data;
138 g_object_weak_unref (G_OBJECT (session),
139 (GWeakNotify) client_session_finalized, client);
140 client_unlink_session (client, session);
142 g_list_free (client->sessions);
143 client->sessions = NULL;
146 /* A client is finalized when the connection is broken */
148 gst_rtsp_client_finalize (GObject * obj)
150 GstRTSPClient *client = GST_RTSP_CLIENT (obj);
152 GST_INFO ("finalize client %p", client);
154 client_cleanup_sessions (client);
156 gst_rtsp_connection_free (client->connection);
157 if (client->session_pool)
158 g_object_unref (client->session_pool);
159 if (client->media_mapping)
160 g_object_unref (client->media_mapping);
162 g_object_unref (client->auth);
165 gst_rtsp_url_free (client->uri);
167 g_object_unref (client->media);
169 g_free (client->server_ip);
171 G_OBJECT_CLASS (gst_rtsp_client_parent_class)->finalize (obj);
175 gst_rtsp_client_get_property (GObject * object, guint propid,
176 GValue * value, GParamSpec * pspec)
178 GstRTSPClient *client = GST_RTSP_CLIENT (object);
181 case PROP_SESSION_POOL:
182 g_value_take_object (value, gst_rtsp_client_get_session_pool (client));
184 case PROP_MEDIA_MAPPING:
185 g_value_take_object (value, gst_rtsp_client_get_media_mapping (client));
188 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
193 gst_rtsp_client_set_property (GObject * object, guint propid,
194 const GValue * value, GParamSpec * pspec)
196 GstRTSPClient *client = GST_RTSP_CLIENT (object);
199 case PROP_SESSION_POOL:
200 gst_rtsp_client_set_session_pool (client, g_value_get_object (value));
202 case PROP_MEDIA_MAPPING:
203 gst_rtsp_client_set_media_mapping (client, g_value_get_object (value));
206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
211 * gst_rtsp_client_new:
213 * Create a new #GstRTSPClient instance.
215 * Returns: a new #GstRTSPClient
218 gst_rtsp_client_new (void)
220 GstRTSPClient *result;
222 result = g_object_new (GST_TYPE_RTSP_CLIENT, NULL);
228 send_response (GstRTSPClient * client, GstRTSPSession * session,
229 GstRTSPMessage * response)
231 gst_rtsp_message_add_header (response, GST_RTSP_HDR_SERVER,
232 "GStreamer RTSP server");
234 /* remove any previous header */
235 gst_rtsp_message_remove_header (response, GST_RTSP_HDR_SESSION, -1);
237 /* add the new session header for new session ids */
241 if (session->timeout != 60)
243 g_strdup_printf ("%s; timeout=%d", session->sessionid,
246 str = g_strdup (session->sessionid);
248 gst_rtsp_message_take_header (response, GST_RTSP_HDR_SESSION, str);
251 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
252 gst_rtsp_message_dump (response);
255 gst_rtsp_watch_send_message (client->watch, response, NULL);
256 gst_rtsp_message_unset (response);
260 send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
261 GstRTSPClientState * state)
263 gst_rtsp_message_init_response (state->response, code,
264 gst_rtsp_status_as_text (code), state->request);
266 send_response (client, NULL, state->response);
270 handle_unauthorized_request (GstRTSPClient * client, GstRTSPAuth * auth,
271 GstRTSPClientState * state)
273 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_UNAUTHORIZED,
274 gst_rtsp_status_as_text (GST_RTSP_STS_UNAUTHORIZED), state->request);
277 /* and let the authentication manager setup the auth tokens */
278 gst_rtsp_auth_setup_auth (auth, client, 0, state);
281 send_response (client, state->session, state->response);
286 compare_uri (const GstRTSPUrl * uri1, const GstRTSPUrl * uri2)
288 if (uri1 == NULL || uri2 == NULL)
291 if (strcmp (uri1->abspath, uri2->abspath))
297 /* this function is called to initially find the media for the DESCRIBE request
298 * but is cached for when the same client (without breaking the connection) is
299 * doing a setup for the exact same url. */
300 static GstRTSPMedia *
301 find_media (GstRTSPClient * client, GstRTSPClientState * state)
303 GstRTSPMediaFactory *factory;
307 if (!compare_uri (client->uri, state->uri)) {
308 /* remove any previously cached values before we try to construct a new
311 gst_rtsp_url_free (client->uri);
314 g_object_unref (client->media);
315 client->media = NULL;
317 if (!client->media_mapping)
320 /* find the factory for the uri first */
322 gst_rtsp_media_mapping_find_factory (client->media_mapping,
326 state->factory = factory;
328 /* check if we have access to the factory */
329 if ((auth = gst_rtsp_media_factory_get_auth (factory))) {
330 if (!gst_rtsp_auth_check (auth, client, 0, state))
333 g_object_unref (auth);
336 /* prepare the media and add it to the pipeline */
337 if (!(media = gst_rtsp_media_factory_construct (factory, state->uri)))
340 g_object_unref (factory);
342 state->factory = NULL;
344 /* set ipv6 on the media before preparing */
345 media->is_ipv6 = client->is_ipv6;
346 state->media = media;
348 /* prepare the media */
349 if (!(gst_rtsp_media_prepare (media)))
352 /* now keep track of the uri and the media */
353 client->uri = gst_rtsp_url_copy (state->uri);
354 client->media = media;
356 /* we have seen this uri before, used cached media */
357 media = client->media;
358 state->media = media;
359 GST_INFO ("reusing cached media %p", media);
363 g_object_ref (media);
370 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
375 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
380 handle_unauthorized_request (client, auth, state);
381 g_object_unref (factory);
382 g_object_unref (auth);
387 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
388 g_object_unref (factory);
393 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
394 g_object_unref (media);
400 do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
402 GstRTSPMessage message = { 0 };
407 gst_rtsp_message_init_data (&message, channel);
409 if (!gst_buffer_map (buffer, &map_info, GST_MAP_READ))
412 gst_rtsp_message_take_body (&message, map_info.data, map_info.size);
414 /* FIXME, client->watch could have been finalized here, we need to keep an
415 * extra refcount to the watch. */
416 gst_rtsp_watch_send_message (client->watch, &message, NULL);
418 gst_rtsp_message_steal_body (&message, &data, &usize);
419 gst_buffer_unmap (buffer, &map_info);
421 gst_rtsp_message_unset (&message);
427 link_stream (GstRTSPClient * client, GstRTSPSession * session,
428 GstRTSPSessionStream * stream)
430 GST_DEBUG ("client %p: linking stream %p", client, stream);
431 gst_rtsp_session_stream_set_callbacks (stream, (GstRTSPSendFunc) do_send_data,
432 (GstRTSPSendFunc) do_send_data, client, NULL);
433 client->streams = g_list_prepend (client->streams, stream);
434 /* make sure our session can't expire */
435 gst_rtsp_session_prevent_expire (session);
439 unlink_stream (GstRTSPClient * client, GstRTSPSession * session,
440 GstRTSPSessionStream * stream)
442 GST_DEBUG ("client %p: unlinking stream %p", client, stream);
443 gst_rtsp_session_stream_set_callbacks (stream, NULL, NULL, NULL, NULL);
444 client->streams = g_list_remove (client->streams, stream);
445 /* our session can now expire */
446 gst_rtsp_session_allow_expire (session);
450 unlink_session_streams (GstRTSPClient * client, GstRTSPSession * session,
451 GstRTSPSessionMedia * media)
455 n_streams = gst_rtsp_media_n_streams (media->media);
456 for (i = 0; i < n_streams; i++) {
457 GstRTSPSessionStream *sstream;
458 GstRTSPTransport *tr;
460 /* get the stream as configured in the session */
461 sstream = gst_rtsp_session_media_get_stream (media, i);
462 /* get the transport, if there is no transport configured, skip this stream */
463 if (!(tr = sstream->trans.transport))
466 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
467 /* for TCP, unlink the stream from the TCP connection of the client */
468 unlink_stream (client, session, sstream);
474 close_connection (GstRTSPClient * client)
476 const gchar *tunnelid;
478 GST_DEBUG ("client %p: closing connection", client);
480 if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
481 g_mutex_lock (&tunnels_lock);
482 /* remove from tunnelids */
483 g_hash_table_remove (tunnels, tunnelid);
484 g_mutex_unlock (&tunnels_lock);
487 gst_rtsp_connection_close (client->connection);
488 if (client->watchid) {
489 g_source_destroy ((GSource *) client->watch);
491 client->watch = NULL;
496 handle_teardown_request (GstRTSPClient * client, GstRTSPClientState * state)
498 GstRTSPSession *session;
499 GstRTSPSessionMedia *media;
500 GstRTSPStatusCode code;
505 session = state->session;
507 /* get a handle to the configuration of the media in the session */
508 media = gst_rtsp_session_get_media (session, state->uri);
512 state->sessmedia = media;
514 /* unlink the all TCP callbacks */
515 unlink_session_streams (client, session, media);
517 /* remove the session from the watched sessions */
518 g_object_weak_unref (G_OBJECT (session),
519 (GWeakNotify) client_session_finalized, client);
520 client->sessions = g_list_remove (client->sessions, session);
522 gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
524 /* unmanage the media in the session, returns false if all media session
526 if (!gst_rtsp_session_release_media (session, media)) {
527 /* remove the session */
528 gst_rtsp_session_pool_remove (client->session_pool, session);
530 /* construct the response now */
531 code = GST_RTSP_STS_OK;
532 gst_rtsp_message_init_response (state->response, code,
533 gst_rtsp_status_as_text (code), state->request);
535 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONNECTION,
538 send_response (client, session, state->response);
540 close_connection (client);
547 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
552 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
558 handle_get_param_request (GstRTSPClient * client, GstRTSPClientState * state)
564 res = gst_rtsp_message_get_body (state->request, &data, &size);
565 if (res != GST_RTSP_OK)
569 /* no body, keep-alive request */
570 send_generic_response (client, GST_RTSP_STS_OK, state);
572 /* there is a body, handle the params */
573 res = gst_rtsp_params_get (client, state);
574 if (res != GST_RTSP_OK)
577 send_response (client, state->session, state->response);
584 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
590 handle_set_param_request (GstRTSPClient * client, GstRTSPClientState * state)
596 res = gst_rtsp_message_get_body (state->request, &data, &size);
597 if (res != GST_RTSP_OK)
601 /* no body, keep-alive request */
602 send_generic_response (client, GST_RTSP_STS_OK, state);
604 /* there is a body, handle the params */
605 res = gst_rtsp_params_set (client, state);
606 if (res != GST_RTSP_OK)
609 send_response (client, state->session, state->response);
616 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
622 handle_pause_request (GstRTSPClient * client, GstRTSPClientState * state)
624 GstRTSPSession *session;
625 GstRTSPSessionMedia *media;
626 GstRTSPStatusCode code;
628 if (!(session = state->session))
631 /* get a handle to the configuration of the media in the session */
632 media = gst_rtsp_session_get_media (session, state->uri);
636 state->sessmedia = media;
638 /* the session state must be playing or recording */
639 if (media->state != GST_RTSP_STATE_PLAYING &&
640 media->state != GST_RTSP_STATE_RECORDING)
643 /* unlink the all TCP callbacks */
644 unlink_session_streams (client, session, media);
646 /* then pause sending */
647 gst_rtsp_session_media_set_state (media, GST_STATE_PAUSED);
649 /* construct the response now */
650 code = GST_RTSP_STS_OK;
651 gst_rtsp_message_init_response (state->response, code,
652 gst_rtsp_status_as_text (code), state->request);
654 send_response (client, session, state->response);
656 /* the state is now READY */
657 media->state = GST_RTSP_STATE_READY;
664 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
669 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
674 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
681 handle_play_request (GstRTSPClient * client, GstRTSPClientState * state)
683 GstRTSPSession *session;
684 GstRTSPSessionMedia *media;
685 GstRTSPStatusCode code;
687 guint n_streams, i, infocount;
688 guint timestamp, seqnum;
690 GstRTSPTimeRange *range;
693 if (!(session = state->session))
696 /* get a handle to the configuration of the media in the session */
697 media = gst_rtsp_session_get_media (session, state->uri);
701 state->sessmedia = media;
703 /* the session state must be playing or ready */
704 if (media->state != GST_RTSP_STATE_PLAYING &&
705 media->state != GST_RTSP_STATE_READY)
708 /* parse the range header if we have one */
710 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_RANGE, &str, 0);
711 if (res == GST_RTSP_OK) {
712 if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
713 /* we have a range, seek to the position */
714 gst_rtsp_media_seek (media->media, range);
715 gst_rtsp_range_free (range);
719 /* grab RTPInfo from the payloaders now */
720 rtpinfo = g_string_new ("");
722 n_streams = gst_rtsp_media_n_streams (media->media);
723 for (i = 0, infocount = 0; i < n_streams; i++) {
724 GstRTSPSessionStream *sstream;
725 GstRTSPMediaStream *stream;
726 GstRTSPTransport *tr;
727 GObjectClass *payobjclass;
730 /* get the stream as configured in the session */
731 sstream = gst_rtsp_session_media_get_stream (media, i);
732 /* get the transport, if there is no transport configured, skip this stream */
733 if (!(tr = sstream->trans.transport)) {
734 GST_INFO ("stream %d is not configured", i);
738 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
739 /* for TCP, link the stream to the TCP connection of the client */
740 link_stream (client, session, sstream);
743 stream = sstream->media_stream;
745 payobjclass = G_OBJECT_GET_CLASS (stream->payloader);
747 if (g_object_class_find_property (payobjclass, "seqnum") &&
748 g_object_class_find_property (payobjclass, "timestamp")) {
751 payobj = G_OBJECT (stream->payloader);
753 /* only add RTP-Info for streams with seqnum and timestamp */
754 g_object_get (payobj, "seqnum", &seqnum, "timestamp", ×tamp, NULL);
757 g_string_append (rtpinfo, ", ");
759 uristr = gst_rtsp_url_get_request_uri (state->uri);
760 g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
761 uristr, i, seqnum, timestamp);
766 GST_WARNING ("RTP-Info cannot be determined for stream %d", i);
770 /* construct the response now */
771 code = GST_RTSP_STS_OK;
772 gst_rtsp_message_init_response (state->response, code,
773 gst_rtsp_status_as_text (code), state->request);
775 /* add the RTP-Info header */
777 str = g_string_free (rtpinfo, FALSE);
778 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RTP_INFO, str);
780 g_string_free (rtpinfo, TRUE);
784 str = gst_rtsp_media_get_range_string (media->media, TRUE);
785 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RANGE, str);
787 send_response (client, session, state->response);
789 /* start playing after sending the request */
790 gst_rtsp_session_media_set_state (media, GST_STATE_PLAYING);
792 media->state = GST_RTSP_STATE_PLAYING;
799 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
804 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
809 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
816 do_keepalive (GstRTSPSession * session)
818 GST_INFO ("keep session %p alive", session);
819 gst_rtsp_session_touch (session);
823 handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
829 gboolean have_transport;
830 GstRTSPTransport *ct, *st;
832 GstRTSPLowerTrans supported;
833 GstRTSPStatusCode code;
834 GstRTSPSession *session;
835 GstRTSPSessionStream *stream;
836 gchar *trans_str, *pos;
838 GstRTSPSessionMedia *media;
842 /* the uri contains the stream number we added in the SDP config, which is
843 * always /stream=%d so we need to strip that off
844 * parse the stream we need to configure, look for the stream in the abspath
845 * first and then in the query. */
846 if (uri->abspath == NULL || !(pos = strstr (uri->abspath, "/stream="))) {
847 if (uri->query == NULL || !(pos = strstr (uri->query, "/stream=")))
851 /* we can mofify the parse uri in place */
854 pos += strlen ("/stream=");
855 if (sscanf (pos, "%u", &streamid) != 1)
858 /* parse the transport */
860 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_TRANSPORT,
862 if (res != GST_RTSP_OK)
865 transports = g_strsplit (transport, ",", 0);
866 gst_rtsp_transport_new (&ct);
868 /* init transports */
869 have_transport = FALSE;
870 gst_rtsp_transport_init (ct);
872 /* our supported transports */
873 supported = GST_RTSP_LOWER_TRANS_UDP |
874 GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
876 /* loop through the transports, try to parse */
877 for (i = 0; transports[i]; i++) {
878 res = gst_rtsp_transport_parse (transports[i], ct);
879 if (res != GST_RTSP_OK) {
880 /* no valid transport, search some more */
881 GST_WARNING ("could not parse transport %s", transports[i]);
885 /* we have a transport, see if it's RTP/AVP */
886 if (ct->trans != GST_RTSP_TRANS_RTP || ct->profile != GST_RTSP_PROFILE_AVP) {
887 GST_WARNING ("invalid transport %s", transports[i]);
891 if (!(ct->lower_transport & supported)) {
892 GST_WARNING ("unsupported transport %s", transports[i]);
896 /* we have a valid transport */
897 GST_INFO ("found valid transport %s", transports[i]);
898 have_transport = TRUE;
902 gst_rtsp_transport_init (ct);
904 g_strfreev (transports);
906 /* we have not found anything usable, error out */
908 goto unsupported_transports;
910 if (client->session_pool == NULL)
913 session = state->session;
916 g_object_ref (session);
917 /* get a handle to the configuration of the media in the session, this can
918 * return NULL if this is a new url to manage in this session. */
919 media = gst_rtsp_session_get_media (session, uri);
921 /* create a session if this fails we probably reached our session limit or
923 if (!(session = gst_rtsp_session_pool_create (client->session_pool)))
924 goto service_unavailable;
926 state->session = session;
928 /* we need a new media configuration in this session */
932 /* we have no media, find one and manage it */
936 /* get a handle to the configuration of the media in the session */
937 if ((m = find_media (client, state))) {
938 /* manage the media in our session now */
939 media = gst_rtsp_session_manage_media (session, uri, m);
943 /* if we stil have no media, error */
947 state->sessmedia = media;
949 /* we have a valid transport now, set the destination of the client. */
950 g_free (ct->destination);
951 if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
952 ct->destination = gst_rtsp_media_get_multicast_group (media->media);
956 url = gst_rtsp_connection_get_url (client->connection);
957 ct->destination = g_strdup (url->host);
959 if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
960 /* check if the client selected channels for TCP */
961 if (ct->interleaved.min == -1 || ct->interleaved.max == -1) {
962 gst_rtsp_session_media_alloc_channels (media, &ct->interleaved);
967 /* get a handle to the stream in the media */
968 if (!(stream = gst_rtsp_session_media_get_stream (media, streamid)))
971 st = gst_rtsp_session_stream_set_transport (stream, ct);
973 /* configure keepalive for this transport */
974 gst_rtsp_session_stream_set_keepalive (stream,
975 (GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
977 /* serialize the server transport */
978 trans_str = gst_rtsp_transport_as_text (st);
979 gst_rtsp_transport_free (st);
981 /* construct the response now */
982 code = GST_RTSP_STS_OK;
983 gst_rtsp_message_init_response (state->response, code,
984 gst_rtsp_status_as_text (code), state->request);
986 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_TRANSPORT,
990 send_response (client, session, state->response);
992 /* update the state */
993 switch (media->state) {
994 case GST_RTSP_STATE_PLAYING:
995 case GST_RTSP_STATE_RECORDING:
996 case GST_RTSP_STATE_READY:
997 /* no state change */
1000 media->state = GST_RTSP_STATE_READY;
1003 g_object_unref (session);
1010 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1015 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1016 g_object_unref (session);
1021 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1022 g_object_unref (media);
1023 g_object_unref (session);
1028 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1031 unsupported_transports:
1033 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1034 gst_rtsp_transport_free (ct);
1039 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1042 service_unavailable:
1044 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1049 static GstSDPMessage *
1050 create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
1055 GstRTSPLowerTrans protocols;
1057 gst_sdp_message_new (&sdp);
1059 /* some standard things first */
1060 gst_sdp_message_set_version (sdp, "0");
1062 if (client->is_ipv6)
1067 gst_sdp_message_set_origin (sdp, "-", "1188340656180883", "1", "IN", proto,
1070 gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
1071 gst_sdp_message_set_information (sdp, "rtsp-server");
1072 gst_sdp_message_add_time (sdp, "0", "0", NULL);
1073 gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
1074 gst_sdp_message_add_attribute (sdp, "type", "broadcast");
1075 gst_sdp_message_add_attribute (sdp, "control", "*");
1077 info.server_proto = proto;
1078 protocols = gst_rtsp_media_get_protocols (media);
1079 if (protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST)
1080 info.server_ip = gst_rtsp_media_get_multicast_group (media);
1082 info.server_ip = g_strdup (client->server_ip);
1084 /* create an SDP for the media object */
1085 if (!gst_rtsp_sdp_from_media (sdp, &info, media))
1088 g_free (info.server_ip);
1095 g_free (info.server_ip);
1096 gst_sdp_message_free (sdp);
1101 /* for the describe we must generate an SDP */
1103 handle_describe_request (GstRTSPClient * client, GstRTSPClientState * state)
1108 gchar *str, *content_base;
1109 GstRTSPMedia *media;
1111 /* check what kind of format is accepted, we don't really do anything with it
1112 * and always return SDP for now. */
1117 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_ACCEPT,
1119 if (res == GST_RTSP_ENOTIMPL)
1122 if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
1126 /* find the media object for the uri */
1127 if (!(media = find_media (client, state)))
1130 /* create an SDP for the media object on this client */
1131 if (!(sdp = create_sdp (client, media)))
1134 g_object_unref (media);
1136 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1137 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1139 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_TYPE,
1142 /* content base for some clients that might screw up creating the setup uri */
1143 str = gst_rtsp_url_get_request_uri (state->uri);
1144 str_len = strlen (str);
1146 /* check for trailing '/' and append one */
1147 if (str[str_len - 1] != '/') {
1148 content_base = g_malloc (str_len + 2);
1149 memcpy (content_base, str, str_len);
1150 content_base[str_len] = '/';
1151 content_base[str_len + 1] = '\0';
1157 GST_INFO ("adding content-base: %s", content_base);
1159 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_BASE,
1161 g_free (content_base);
1163 /* add SDP to the response body */
1164 str = gst_sdp_message_as_text (sdp);
1165 gst_rtsp_message_take_body (state->response, (guint8 *) str, strlen (str));
1166 gst_sdp_message_free (sdp);
1168 send_response (client, state->session, state->response);
1175 /* error reply is already sent */
1180 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1181 g_object_unref (media);
1187 handle_options_request (GstRTSPClient * client, GstRTSPClientState * state)
1189 GstRTSPMethod options;
1192 options = GST_RTSP_DESCRIBE |
1197 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN;
1199 str = gst_rtsp_options_as_text (options);
1201 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1202 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1204 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_PUBLIC, str);
1207 send_response (client, state->session, state->response);
1212 /* remove duplicate and trailing '/' */
1214 sanitize_uri (GstRTSPUrl * uri)
1218 gboolean have_slash, prev_slash;
1220 s = d = uri->abspath;
1221 len = strlen (uri->abspath);
1225 for (i = 0; i < len; i++) {
1226 have_slash = s[i] == '/';
1228 if (!have_slash || !prev_slash)
1230 prev_slash = have_slash;
1232 len = d - uri->abspath;
1233 /* don't remove the first slash if that's the only thing left */
1234 if (len > 1 && *(d - 1) == '/')
1240 client_session_finalized (GstRTSPClient * client, GstRTSPSession * session)
1242 GST_INFO ("client %p: session %p finished", client, session);
1244 /* unlink all media managed in this session */
1245 client_unlink_session (client, session);
1247 /* remove the session */
1248 if (!(client->sessions = g_list_remove (client->sessions, session))) {
1249 GST_INFO ("client %p: all sessions finalized, close the connection",
1251 close_connection (client);
1256 client_watch_session (GstRTSPClient * client, GstRTSPSession * session)
1260 for (walk = client->sessions; walk; walk = g_list_next (walk)) {
1261 GstRTSPSession *msession = (GstRTSPSession *) walk->data;
1263 /* we already know about this session */
1264 if (msession == session)
1268 GST_INFO ("watching session %p", session);
1270 g_object_weak_ref (G_OBJECT (session), (GWeakNotify) client_session_finalized,
1272 client->sessions = g_list_prepend (client->sessions, session);
1276 handle_request (GstRTSPClient * client, GstRTSPMessage * request)
1278 GstRTSPMethod method;
1279 const gchar *uristr;
1281 GstRTSPVersion version;
1283 GstRTSPSession *session;
1284 GstRTSPClientState state = { NULL };
1285 GstRTSPMessage response = { 0 };
1288 state.request = request;
1289 state.response = &response;
1291 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
1292 gst_rtsp_message_dump (request);
1295 GST_INFO ("client %p: received a request", client);
1297 gst_rtsp_message_parse_request (request, &method, &uristr, &version);
1299 if (version != GST_RTSP_VERSION_1_0) {
1300 /* we can only handle 1.0 requests */
1301 send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
1305 state.method = method;
1307 /* we always try to parse the url first */
1308 if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) {
1309 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
1313 /* sanitize the uri */
1317 /* get the session if there is any */
1318 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
1319 if (res == GST_RTSP_OK) {
1320 if (client->session_pool == NULL)
1323 /* we had a session in the request, find it again */
1324 if (!(session = gst_rtsp_session_pool_find (client->session_pool, sessid)))
1325 goto session_not_found;
1327 /* we add the session to the client list of watched sessions. When a session
1328 * disappears because it times out, we will be notified. If all sessions are
1329 * gone, we will close the connection */
1330 client_watch_session (client, session);
1334 state.session = session;
1337 if (!gst_rtsp_auth_check (client->auth, client, 0, &state))
1338 goto not_authorized;
1341 /* now see what is asked and dispatch to a dedicated handler */
1343 case GST_RTSP_OPTIONS:
1344 handle_options_request (client, &state);
1346 case GST_RTSP_DESCRIBE:
1347 handle_describe_request (client, &state);
1349 case GST_RTSP_SETUP:
1350 handle_setup_request (client, &state);
1353 handle_play_request (client, &state);
1355 case GST_RTSP_PAUSE:
1356 handle_pause_request (client, &state);
1358 case GST_RTSP_TEARDOWN:
1359 handle_teardown_request (client, &state);
1361 case GST_RTSP_SET_PARAMETER:
1362 handle_set_param_request (client, &state);
1364 case GST_RTSP_GET_PARAMETER:
1365 handle_get_param_request (client, &state);
1367 case GST_RTSP_ANNOUNCE:
1368 case GST_RTSP_RECORD:
1369 case GST_RTSP_REDIRECT:
1370 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &state);
1372 case GST_RTSP_INVALID:
1374 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
1378 g_object_unref (session);
1380 gst_rtsp_url_free (uri);
1386 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, &state);
1391 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
1396 handle_unauthorized_request (client, client->auth, &state);
1402 handle_data (GstRTSPClient * client, GstRTSPMessage * message)
1412 /* find the stream for this message */
1413 res = gst_rtsp_message_parse_data (message, &channel);
1414 if (res != GST_RTSP_OK)
1417 gst_rtsp_message_steal_body (message, &data, &size);
1419 buffer = gst_buffer_new_wrapped (data, size);
1422 for (walk = client->streams; walk; walk = g_list_next (walk)) {
1423 GstRTSPSessionStream *stream = (GstRTSPSessionStream *) walk->data;
1424 GstRTSPMediaStream *mstream;
1425 GstRTSPTransport *tr;
1427 /* get the transport, if there is no transport configured, skip this stream */
1428 if (!(tr = stream->trans.transport))
1431 /* we also need a media stream */
1432 if (!(mstream = stream->media_stream))
1435 /* check for TCP transport */
1436 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
1437 /* dispatch to the stream based on the channel number */
1438 if (tr->interleaved.min == channel) {
1439 gst_rtsp_media_stream_rtp (mstream, buffer);
1442 } else if (tr->interleaved.max == channel) {
1443 gst_rtsp_media_stream_rtcp (mstream, buffer);
1450 gst_buffer_unref (buffer);
1454 * gst_rtsp_client_set_session_pool:
1455 * @client: a #GstRTSPClient
1456 * @pool: a #GstRTSPSessionPool
1458 * Set @pool as the sessionpool for @client which it will use to find
1459 * or allocate sessions. the sessionpool is usually inherited from the server
1460 * that created the client but can be overridden later.
1463 gst_rtsp_client_set_session_pool (GstRTSPClient * client,
1464 GstRTSPSessionPool * pool)
1466 GstRTSPSessionPool *old;
1468 old = client->session_pool;
1471 g_object_ref (pool);
1472 client->session_pool = pool;
1474 g_object_unref (old);
1479 * gst_rtsp_client_get_session_pool:
1480 * @client: a #GstRTSPClient
1482 * Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
1484 * Returns: a #GstRTSPSessionPool, unref after usage.
1486 GstRTSPSessionPool *
1487 gst_rtsp_client_get_session_pool (GstRTSPClient * client)
1489 GstRTSPSessionPool *result;
1491 if ((result = client->session_pool))
1492 g_object_ref (result);
1498 * gst_rtsp_client_set_server:
1499 * @client: a #GstRTSPClient
1500 * @server: a #GstRTSPServer
1502 * Set @server as the server that created @client.
1505 gst_rtsp_client_set_server (GstRTSPClient * client, GstRTSPServer * server)
1509 old = client->server;
1510 if (old != server) {
1512 g_object_ref (server);
1513 client->server = server;
1515 g_object_unref (old);
1520 * gst_rtsp_client_get_server:
1521 * @client: a #GstRTSPClient
1523 * Get the #GstRTSPServer object that @client was created from.
1525 * Returns: a #GstRTSPServer, unref after usage.
1528 gst_rtsp_client_get_server (GstRTSPClient * client)
1530 GstRTSPServer *result;
1532 if ((result = client->server))
1533 g_object_ref (result);
1539 * gst_rtsp_client_set_media_mapping:
1540 * @client: a #GstRTSPClient
1541 * @mapping: a #GstRTSPMediaMapping
1543 * Set @mapping as the media mapping for @client which it will use to map urls
1544 * to media streams. These mapping is usually inherited from the server that
1545 * created the client but can be overriden later.
1548 gst_rtsp_client_set_media_mapping (GstRTSPClient * client,
1549 GstRTSPMediaMapping * mapping)
1551 GstRTSPMediaMapping *old;
1553 old = client->media_mapping;
1555 if (old != mapping) {
1557 g_object_ref (mapping);
1558 client->media_mapping = mapping;
1560 g_object_unref (old);
1565 * gst_rtsp_client_get_media_mapping:
1566 * @client: a #GstRTSPClient
1568 * Get the #GstRTSPMediaMapping object that @client uses to manage its sessions.
1570 * Returns: a #GstRTSPMediaMapping, unref after usage.
1572 GstRTSPMediaMapping *
1573 gst_rtsp_client_get_media_mapping (GstRTSPClient * client)
1575 GstRTSPMediaMapping *result;
1577 if ((result = client->media_mapping))
1578 g_object_ref (result);
1584 * gst_rtsp_client_set_auth:
1585 * @client: a #GstRTSPClient
1586 * @auth: a #GstRTSPAuth
1588 * configure @auth to be used as the authentication manager of @client.
1591 gst_rtsp_client_set_auth (GstRTSPClient * client, GstRTSPAuth * auth)
1595 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
1601 g_object_ref (auth);
1602 client->auth = auth;
1604 g_object_unref (old);
1610 * gst_rtsp_client_get_auth:
1611 * @client: a #GstRTSPClient
1613 * Get the #GstRTSPAuth used as the authentication manager of @client.
1615 * Returns: the #GstRTSPAuth of @client. g_object_unref() after
1619 gst_rtsp_client_get_auth (GstRTSPClient * client)
1621 GstRTSPAuth *result;
1623 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
1625 if ((result = client->auth))
1626 g_object_ref (result);
1631 static GstRTSPResult
1632 message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
1635 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1637 switch (message->type) {
1638 case GST_RTSP_MESSAGE_REQUEST:
1639 handle_request (client, message);
1641 case GST_RTSP_MESSAGE_RESPONSE:
1643 case GST_RTSP_MESSAGE_DATA:
1644 handle_data (client, message);
1652 static GstRTSPResult
1653 message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
1655 /* GstRTSPClient *client; */
1657 /* client = GST_RTSP_CLIENT (user_data); */
1659 /* GST_INFO ("client %p: sent a message with cseq %d", client, cseq); */
1664 static GstRTSPResult
1665 closed (GstRTSPWatch * watch, gpointer user_data)
1667 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1668 const gchar *tunnelid;
1670 GST_INFO ("client %p: connection closed", client);
1672 if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
1673 g_mutex_lock (&tunnels_lock);
1674 /* remove from tunnelids */
1675 g_hash_table_remove (tunnels, tunnelid);
1676 g_mutex_unlock (&tunnels_lock);
1682 static GstRTSPResult
1683 error (GstRTSPWatch * watch, GstRTSPResult result, gpointer user_data)
1685 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1688 str = gst_rtsp_strresult (result);
1689 GST_INFO ("client %p: received an error %s", client, str);
1695 static GstRTSPResult
1696 error_full (GstRTSPWatch * watch, GstRTSPResult result,
1697 GstRTSPMessage * message, guint id, gpointer user_data)
1699 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1702 str = gst_rtsp_strresult (result);
1704 ("client %p: received an error %s when handling message %p with id %d",
1705 client, str, message, id);
1712 remember_tunnel (GstRTSPClient * client)
1714 const gchar *tunnelid;
1716 /* store client in the pending tunnels */
1717 tunnelid = gst_rtsp_connection_get_tunnelid (client->connection);
1718 if (tunnelid == NULL)
1721 GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
1723 /* we can't have two clients connecting with the same tunnelid */
1724 g_mutex_lock (&tunnels_lock);
1725 if (g_hash_table_lookup (tunnels, tunnelid))
1726 goto tunnel_existed;
1728 g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
1729 g_mutex_unlock (&tunnels_lock);
1736 GST_ERROR ("client %p: no tunnelid provided", client);
1741 g_mutex_unlock (&tunnels_lock);
1742 GST_ERROR ("client %p: tunnel session %s already existed", client,
1748 static GstRTSPStatusCode
1749 tunnel_start (GstRTSPWatch * watch, gpointer user_data)
1751 GstRTSPClient *client;
1753 client = GST_RTSP_CLIENT (user_data);
1755 GST_INFO ("client %p: tunnel start (connection %p)", client,
1756 client->connection);
1758 if (!remember_tunnel (client))
1761 return GST_RTSP_STS_OK;
1766 GST_ERROR ("client %p: error starting tunnel", client);
1767 return GST_RTSP_STS_SERVICE_UNAVAILABLE;
1771 static GstRTSPResult
1772 tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
1774 GstRTSPClient *client;
1776 client = GST_RTSP_CLIENT (user_data);
1778 GST_INFO ("client %p: tunnel lost (connection %p)", client,
1779 client->connection);
1781 /* ignore error, it'll only be a problem when the client does a POST again */
1782 remember_tunnel (client);
1787 static GstRTSPResult
1788 tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
1790 const gchar *tunnelid;
1791 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1792 GstRTSPClient *oclient;
1794 GST_INFO ("client %p: tunnel complete", client);
1796 /* find previous tunnel */
1797 tunnelid = gst_rtsp_connection_get_tunnelid (client->connection);
1798 if (tunnelid == NULL)
1801 g_mutex_lock (&tunnels_lock);
1802 if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
1805 /* remove the old client from the table. ref before because removing it will
1806 * remove the ref to it. */
1807 g_object_ref (oclient);
1808 g_hash_table_remove (tunnels, tunnelid);
1810 if (oclient->watch == NULL)
1812 g_mutex_unlock (&tunnels_lock);
1814 GST_INFO ("client %p: found tunnel %p (old %p, new %p)", client, oclient,
1815 oclient->connection, client->connection);
1817 /* merge the tunnels into the first client */
1818 gst_rtsp_connection_do_tunnel (oclient->connection, client->connection);
1819 gst_rtsp_watch_reset (oclient->watch);
1820 g_object_unref (oclient);
1822 /* we don't need this watch anymore */
1823 g_source_destroy ((GSource *) client->watch);
1824 client->watchid = 0;
1825 client->watch = NULL;
1832 GST_INFO ("client %p: no tunnelid provided", client);
1833 return GST_RTSP_ERROR;
1837 g_mutex_unlock (&tunnels_lock);
1838 GST_INFO ("client %p: tunnel session %s not found", client, tunnelid);
1839 return GST_RTSP_ERROR;
1843 g_mutex_unlock (&tunnels_lock);
1844 GST_INFO ("client %p: tunnel session %s was closed", client, tunnelid);
1845 g_object_unref (oclient);
1846 return GST_RTSP_ERROR;
1850 static GstRTSPWatchFuncs watch_funcs = {
1862 client_watch_notify (GstRTSPClient * client)
1864 GST_INFO ("client %p: watch destroyed", client);
1865 client->watchid = 0;
1866 client->watch = NULL;
1867 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
1868 g_object_unref (client);
1872 * gst_rtsp_client_attach:
1873 * @client: a #GstRTSPClient
1874 * @socket: a #GSocket
1875 * @cancellable: a #GCancellable
1878 * Accept a new connection for @client on @socket.
1880 * This function should be called when the client properties and urls are fully
1881 * configured and the client is ready to start.
1883 * Returns: %TRUE if the client could be accepted.
1886 gst_rtsp_client_accept (GstRTSPClient * client, GSocket * socket,
1887 GCancellable * cancellable, GError ** error)
1889 GstRTSPConnection *conn;
1891 GSocket *read_socket;
1892 GSocketAddress *addres;
1894 GMainContext *context;
1896 struct sockaddr_storage addr;
1898 gchar ip[INET6_ADDRSTRLEN];
1900 /* a new client connected. */
1901 GST_RTSP_CHECK (gst_rtsp_connection_accept (socket, &conn, cancellable),
1904 read_socket = gst_rtsp_connection_get_read_socket (conn);
1905 client->is_ipv6 = g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV6;
1907 if (!(addres = g_socket_get_remote_address (read_socket, error)))
1910 addrlen = sizeof (addr);
1911 if (!g_socket_address_to_native (addres, &addr, addrlen, error))
1913 g_object_unref (addres);
1915 if (getnameinfo ((struct sockaddr *) &addr, addrlen, ip, sizeof (ip), NULL, 0,
1916 NI_NUMERICHOST) != 0)
1917 goto getnameinfo_failed;
1919 /* keep the original ip that the client connected to */
1920 g_free (client->server_ip);
1921 client->server_ip = g_strndup (ip, sizeof (ip));
1923 GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
1924 client->server_ip, client->is_ipv6);
1926 url = gst_rtsp_connection_get_url (conn);
1927 GST_INFO ("added new client %p ip %s:%d", client, url->host, url->port);
1929 client->connection = conn;
1931 /* create watch for the connection and attach */
1932 client->watch = gst_rtsp_watch_new (client->connection, &watch_funcs,
1933 g_object_ref (client), (GDestroyNotify) client_watch_notify);
1935 /* find the context to add the watch */
1936 if ((source = g_main_current_source ()))
1937 context = g_source_get_context (source);
1941 GST_INFO ("attaching to context %p", context);
1943 client->watchid = gst_rtsp_watch_attach (client->watch, context);
1944 gst_rtsp_watch_unref (client->watch);
1951 gchar *str = gst_rtsp_strresult (res);
1953 GST_ERROR ("Could not accept client on server socket %p: %s", socket, str);
1959 GST_ERROR ("could not get remote address %s", (*error)->message);
1964 g_object_unref (addres);
1965 GST_ERROR ("could not get native address %s", (*error)->message);
1970 GST_ERROR ("getnameinfo failed: %s", g_strerror (errno));