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)
117 /* unlink all media managed in this session */
118 while (g_list_length (session->medias) > 0) {
119 GstRTSPSessionMedia *media = g_list_first (session->medias)->data;
121 gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
122 unlink_session_streams (client, session, media);
123 /* unmanage the media in the session. this will modify session->medias */
124 gst_rtsp_session_release_media (session, media);
129 client_cleanup_sessions (GstRTSPClient * client)
133 /* remove weak-ref from sessions */
134 for (sessions = client->sessions; sessions; sessions = g_list_next (sessions)) {
135 GstRTSPSession *session = (GstRTSPSession *) sessions->data;
136 g_object_weak_unref (G_OBJECT (session),
137 (GWeakNotify) client_session_finalized, client);
138 client_unlink_session (client, session);
140 g_list_free (client->sessions);
141 client->sessions = NULL;
144 /* A client is finalized when the connection is broken */
146 gst_rtsp_client_finalize (GObject * obj)
148 GstRTSPClient *client = GST_RTSP_CLIENT (obj);
150 GST_INFO ("finalize client %p", client);
152 client_cleanup_sessions (client);
154 gst_rtsp_connection_free (client->connection);
155 if (client->session_pool)
156 g_object_unref (client->session_pool);
157 if (client->media_mapping)
158 g_object_unref (client->media_mapping);
160 g_object_unref (client->auth);
163 gst_rtsp_url_free (client->uri);
165 g_object_unref (client->media);
167 g_free (client->server_ip);
169 G_OBJECT_CLASS (gst_rtsp_client_parent_class)->finalize (obj);
173 gst_rtsp_client_get_property (GObject * object, guint propid,
174 GValue * value, GParamSpec * pspec)
176 GstRTSPClient *client = GST_RTSP_CLIENT (object);
179 case PROP_SESSION_POOL:
180 g_value_take_object (value, gst_rtsp_client_get_session_pool (client));
182 case PROP_MEDIA_MAPPING:
183 g_value_take_object (value, gst_rtsp_client_get_media_mapping (client));
186 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
191 gst_rtsp_client_set_property (GObject * object, guint propid,
192 const GValue * value, GParamSpec * pspec)
194 GstRTSPClient *client = GST_RTSP_CLIENT (object);
197 case PROP_SESSION_POOL:
198 gst_rtsp_client_set_session_pool (client, g_value_get_object (value));
200 case PROP_MEDIA_MAPPING:
201 gst_rtsp_client_set_media_mapping (client, g_value_get_object (value));
204 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
209 * gst_rtsp_client_new:
211 * Create a new #GstRTSPClient instance.
213 * Returns: a new #GstRTSPClient
216 gst_rtsp_client_new (void)
218 GstRTSPClient *result;
220 result = g_object_new (GST_TYPE_RTSP_CLIENT, NULL);
226 send_response (GstRTSPClient * client, GstRTSPSession * session,
227 GstRTSPMessage * response)
229 gst_rtsp_message_add_header (response, GST_RTSP_HDR_SERVER,
230 "GStreamer RTSP server");
232 /* remove any previous header */
233 gst_rtsp_message_remove_header (response, GST_RTSP_HDR_SESSION, -1);
235 /* add the new session header for new session ids */
239 if (session->timeout != 60)
241 g_strdup_printf ("%s; timeout=%d", session->sessionid,
244 str = g_strdup (session->sessionid);
246 gst_rtsp_message_take_header (response, GST_RTSP_HDR_SESSION, str);
249 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
250 gst_rtsp_message_dump (response);
253 gst_rtsp_watch_send_message (client->watch, response, NULL);
254 gst_rtsp_message_unset (response);
258 send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
259 GstRTSPClientState * state)
261 gst_rtsp_message_init_response (state->response, code,
262 gst_rtsp_status_as_text (code), state->request);
264 send_response (client, NULL, state->response);
268 handle_unauthorized_request (GstRTSPClient * client, GstRTSPAuth * auth,
269 GstRTSPClientState * state)
271 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_UNAUTHORIZED,
272 gst_rtsp_status_as_text (GST_RTSP_STS_UNAUTHORIZED), state->request);
275 /* and let the authentication manager setup the auth tokens */
276 gst_rtsp_auth_setup_auth (auth, client, 0, state);
279 send_response (client, state->session, state->response);
284 compare_uri (const GstRTSPUrl * uri1, const GstRTSPUrl * uri2)
286 if (uri1 == NULL || uri2 == NULL)
289 if (strcmp (uri1->abspath, uri2->abspath))
295 /* this function is called to initially find the media for the DESCRIBE request
296 * but is cached for when the same client (without breaking the connection) is
297 * doing a setup for the exact same url. */
298 static GstRTSPMedia *
299 find_media (GstRTSPClient * client, GstRTSPClientState * state)
301 GstRTSPMediaFactory *factory;
305 if (!compare_uri (client->uri, state->uri)) {
306 /* remove any previously cached values before we try to construct a new
309 gst_rtsp_url_free (client->uri);
312 g_object_unref (client->media);
313 client->media = NULL;
315 if (!client->media_mapping)
318 /* find the factory for the uri first */
320 gst_rtsp_media_mapping_find_factory (client->media_mapping,
324 state->factory = factory;
326 /* check if we have access to the factory */
327 if ((auth = gst_rtsp_media_factory_get_auth (factory))) {
328 if (!gst_rtsp_auth_check (auth, client, 0, state))
331 g_object_unref (auth);
334 /* prepare the media and add it to the pipeline */
335 if (!(media = gst_rtsp_media_factory_construct (factory, state->uri)))
338 g_object_unref (factory);
340 state->factory = NULL;
342 /* set ipv6 on the media before preparing */
343 media->is_ipv6 = client->is_ipv6;
344 state->media = media;
346 /* prepare the media */
347 if (!(gst_rtsp_media_prepare (media)))
350 /* now keep track of the uri and the media */
351 client->uri = gst_rtsp_url_copy (state->uri);
352 client->media = media;
354 /* we have seen this uri before, used cached media */
355 media = client->media;
356 state->media = media;
357 GST_INFO ("reusing cached media %p", media);
361 g_object_ref (media);
368 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
373 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
378 handle_unauthorized_request (client, auth, state);
379 g_object_unref (factory);
380 g_object_unref (auth);
385 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
386 g_object_unref (factory);
391 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
392 g_object_unref (media);
398 do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
400 GstRTSPMessage message = { 0 };
405 gst_rtsp_message_init_data (&message, channel);
407 if (!gst_buffer_map (buffer, &map_info, GST_MAP_READ))
410 gst_rtsp_message_take_body (&message, map_info.data, map_info.size);
412 /* FIXME, client->watch could have been finalized here, we need to keep an
413 * extra refcount to the watch. */
414 gst_rtsp_watch_send_message (client->watch, &message, NULL);
416 gst_rtsp_message_steal_body (&message, &data, &usize);
417 gst_buffer_unmap (buffer, &map_info);
419 gst_rtsp_message_unset (&message);
425 link_stream (GstRTSPClient * client, GstRTSPSession * session,
426 GstRTSPSessionStream * stream)
428 GST_DEBUG ("client %p: linking stream %p", client, stream);
429 gst_rtsp_session_stream_set_callbacks (stream, (GstRTSPSendFunc) do_send_data,
430 (GstRTSPSendFunc) do_send_data, client, NULL);
431 client->streams = g_list_prepend (client->streams, stream);
432 /* make sure our session can't expire */
433 gst_rtsp_session_prevent_expire (session);
437 unlink_stream (GstRTSPClient * client, GstRTSPSession * session,
438 GstRTSPSessionStream * stream)
440 GST_DEBUG ("client %p: unlinking stream %p", client, stream);
441 gst_rtsp_session_stream_set_callbacks (stream, NULL, NULL, NULL, NULL);
442 client->streams = g_list_remove (client->streams, stream);
443 /* our session can now expire */
444 gst_rtsp_session_allow_expire (session);
448 unlink_session_streams (GstRTSPClient * client, GstRTSPSession * session,
449 GstRTSPSessionMedia * media)
453 n_streams = gst_rtsp_media_n_streams (media->media);
454 for (i = 0; i < n_streams; i++) {
455 GstRTSPSessionStream *sstream;
456 GstRTSPTransport *tr;
458 /* get the stream as configured in the session */
459 sstream = gst_rtsp_session_media_get_stream (media, i);
460 /* get the transport, if there is no transport configured, skip this stream */
461 if (!(tr = sstream->trans.transport))
464 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
465 /* for TCP, unlink the stream from the TCP connection of the client */
466 unlink_stream (client, session, sstream);
472 close_connection (GstRTSPClient * client)
474 const gchar *tunnelid;
476 GST_DEBUG ("client %p: closing connection", client);
478 if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
479 g_mutex_lock (&tunnels_lock);
480 /* remove from tunnelids */
481 g_hash_table_remove (tunnels, tunnelid);
482 g_mutex_unlock (&tunnels_lock);
485 gst_rtsp_connection_close (client->connection);
486 if (client->watchid) {
487 g_source_destroy ((GSource *) client->watch);
489 client->watch = NULL;
494 handle_teardown_request (GstRTSPClient * client, GstRTSPClientState * state)
496 GstRTSPSession *session;
497 GstRTSPSessionMedia *media;
498 GstRTSPStatusCode code;
503 session = state->session;
505 /* get a handle to the configuration of the media in the session */
506 media = gst_rtsp_session_get_media (session, state->uri);
510 state->sessmedia = media;
512 /* unlink the all TCP callbacks */
513 unlink_session_streams (client, session, media);
515 /* remove the session from the watched sessions */
516 g_object_weak_unref (G_OBJECT (session),
517 (GWeakNotify) client_session_finalized, client);
518 client->sessions = g_list_remove (client->sessions, session);
520 gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
522 /* unmanage the media in the session, returns false if all media session
524 if (!gst_rtsp_session_release_media (session, media)) {
525 /* remove the session */
526 gst_rtsp_session_pool_remove (client->session_pool, session);
528 /* construct the response now */
529 code = GST_RTSP_STS_OK;
530 gst_rtsp_message_init_response (state->response, code,
531 gst_rtsp_status_as_text (code), state->request);
533 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONNECTION,
536 send_response (client, session, state->response);
538 close_connection (client);
545 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
550 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
556 handle_get_param_request (GstRTSPClient * client, GstRTSPClientState * state)
562 res = gst_rtsp_message_get_body (state->request, &data, &size);
563 if (res != GST_RTSP_OK)
567 /* no body, keep-alive request */
568 send_generic_response (client, GST_RTSP_STS_OK, state);
570 /* there is a body, handle the params */
571 res = gst_rtsp_params_get (client, state);
572 if (res != GST_RTSP_OK)
575 send_response (client, state->session, state->response);
582 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
588 handle_set_param_request (GstRTSPClient * client, GstRTSPClientState * state)
594 res = gst_rtsp_message_get_body (state->request, &data, &size);
595 if (res != GST_RTSP_OK)
599 /* no body, keep-alive request */
600 send_generic_response (client, GST_RTSP_STS_OK, state);
602 /* there is a body, handle the params */
603 res = gst_rtsp_params_set (client, state);
604 if (res != GST_RTSP_OK)
607 send_response (client, state->session, state->response);
614 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
620 handle_pause_request (GstRTSPClient * client, GstRTSPClientState * state)
622 GstRTSPSession *session;
623 GstRTSPSessionMedia *media;
624 GstRTSPStatusCode code;
626 if (!(session = state->session))
629 /* get a handle to the configuration of the media in the session */
630 media = gst_rtsp_session_get_media (session, state->uri);
634 state->sessmedia = media;
636 /* the session state must be playing or recording */
637 if (media->state != GST_RTSP_STATE_PLAYING &&
638 media->state != GST_RTSP_STATE_RECORDING)
641 /* unlink the all TCP callbacks */
642 unlink_session_streams (client, session, media);
644 /* then pause sending */
645 gst_rtsp_session_media_set_state (media, GST_STATE_PAUSED);
647 /* construct the response now */
648 code = GST_RTSP_STS_OK;
649 gst_rtsp_message_init_response (state->response, code,
650 gst_rtsp_status_as_text (code), state->request);
652 send_response (client, session, state->response);
654 /* the state is now READY */
655 media->state = GST_RTSP_STATE_READY;
662 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
667 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
672 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
679 handle_play_request (GstRTSPClient * client, GstRTSPClientState * state)
681 GstRTSPSession *session;
682 GstRTSPSessionMedia *media;
683 GstRTSPStatusCode code;
685 guint n_streams, i, infocount;
686 guint timestamp, seqnum;
688 GstRTSPTimeRange *range;
691 if (!(session = state->session))
694 /* get a handle to the configuration of the media in the session */
695 media = gst_rtsp_session_get_media (session, state->uri);
699 state->sessmedia = media;
701 /* the session state must be playing or ready */
702 if (media->state != GST_RTSP_STATE_PLAYING &&
703 media->state != GST_RTSP_STATE_READY)
706 /* parse the range header if we have one */
708 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_RANGE, &str, 0);
709 if (res == GST_RTSP_OK) {
710 if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
711 /* we have a range, seek to the position */
712 gst_rtsp_media_seek (media->media, range);
713 gst_rtsp_range_free (range);
717 /* grab RTPInfo from the payloaders now */
718 rtpinfo = g_string_new ("");
720 n_streams = gst_rtsp_media_n_streams (media->media);
721 for (i = 0, infocount = 0; i < n_streams; i++) {
722 GstRTSPSessionStream *sstream;
723 GstRTSPMediaStream *stream;
724 GstRTSPTransport *tr;
725 GObjectClass *payobjclass;
728 /* get the stream as configured in the session */
729 sstream = gst_rtsp_session_media_get_stream (media, i);
730 /* get the transport, if there is no transport configured, skip this stream */
731 if (!(tr = sstream->trans.transport)) {
732 GST_INFO ("stream %d is not configured", i);
736 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
737 /* for TCP, link the stream to the TCP connection of the client */
738 link_stream (client, session, sstream);
741 stream = sstream->media_stream;
743 payobjclass = G_OBJECT_GET_CLASS (stream->payloader);
745 if (g_object_class_find_property (payobjclass, "seqnum") &&
746 g_object_class_find_property (payobjclass, "timestamp")) {
749 payobj = G_OBJECT (stream->payloader);
751 /* only add RTP-Info for streams with seqnum and timestamp */
752 g_object_get (payobj, "seqnum", &seqnum, "timestamp", ×tamp, NULL);
755 g_string_append (rtpinfo, ", ");
757 uristr = gst_rtsp_url_get_request_uri (state->uri);
758 g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
759 uristr, i, seqnum, timestamp);
764 GST_WARNING ("RTP-Info cannot be determined for stream %d", i);
768 /* construct the response now */
769 code = GST_RTSP_STS_OK;
770 gst_rtsp_message_init_response (state->response, code,
771 gst_rtsp_status_as_text (code), state->request);
773 /* add the RTP-Info header */
775 str = g_string_free (rtpinfo, FALSE);
776 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RTP_INFO, str);
778 g_string_free (rtpinfo, TRUE);
782 str = gst_rtsp_media_get_range_string (media->media, TRUE);
783 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RANGE, str);
785 send_response (client, session, state->response);
787 /* start playing after sending the request */
788 gst_rtsp_session_media_set_state (media, GST_STATE_PLAYING);
790 media->state = GST_RTSP_STATE_PLAYING;
797 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
802 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
807 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
814 do_keepalive (GstRTSPSession * session)
816 GST_INFO ("keep session %p alive", session);
817 gst_rtsp_session_touch (session);
821 handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
827 gboolean have_transport;
828 GstRTSPTransport *ct, *st;
830 GstRTSPLowerTrans supported;
831 GstRTSPStatusCode code;
832 GstRTSPSession *session;
833 GstRTSPSessionStream *stream;
834 gchar *trans_str, *pos;
836 GstRTSPSessionMedia *media;
840 /* the uri contains the stream number we added in the SDP config, which is
841 * always /stream=%d so we need to strip that off
842 * parse the stream we need to configure, look for the stream in the abspath
843 * first and then in the query. */
844 if (uri->abspath == NULL || !(pos = strstr (uri->abspath, "/stream="))) {
845 if (uri->query == NULL || !(pos = strstr (uri->query, "/stream=")))
849 /* we can mofify the parse uri in place */
852 pos += strlen ("/stream=");
853 if (sscanf (pos, "%u", &streamid) != 1)
856 /* parse the transport */
858 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_TRANSPORT,
860 if (res != GST_RTSP_OK)
863 transports = g_strsplit (transport, ",", 0);
864 gst_rtsp_transport_new (&ct);
866 /* init transports */
867 have_transport = FALSE;
868 gst_rtsp_transport_init (ct);
870 /* our supported transports */
871 supported = GST_RTSP_LOWER_TRANS_UDP |
872 GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
874 /* loop through the transports, try to parse */
875 for (i = 0; transports[i]; i++) {
876 res = gst_rtsp_transport_parse (transports[i], ct);
877 if (res != GST_RTSP_OK) {
878 /* no valid transport, search some more */
879 GST_WARNING ("could not parse transport %s", transports[i]);
883 /* we have a transport, see if it's RTP/AVP */
884 if (ct->trans != GST_RTSP_TRANS_RTP || ct->profile != GST_RTSP_PROFILE_AVP) {
885 GST_WARNING ("invalid transport %s", transports[i]);
889 if (!(ct->lower_transport & supported)) {
890 GST_WARNING ("unsupported transport %s", transports[i]);
894 /* we have a valid transport */
895 GST_INFO ("found valid transport %s", transports[i]);
896 have_transport = TRUE;
900 gst_rtsp_transport_init (ct);
902 g_strfreev (transports);
904 /* we have not found anything usable, error out */
906 goto unsupported_transports;
908 if (client->session_pool == NULL)
911 session = state->session;
914 g_object_ref (session);
915 /* get a handle to the configuration of the media in the session, this can
916 * return NULL if this is a new url to manage in this session. */
917 media = gst_rtsp_session_get_media (session, uri);
919 /* create a session if this fails we probably reached our session limit or
921 if (!(session = gst_rtsp_session_pool_create (client->session_pool)))
922 goto service_unavailable;
924 state->session = session;
926 /* we need a new media configuration in this session */
930 /* we have no media, find one and manage it */
934 /* get a handle to the configuration of the media in the session */
935 if ((m = find_media (client, state))) {
936 /* manage the media in our session now */
937 media = gst_rtsp_session_manage_media (session, uri, m);
941 /* if we stil have no media, error */
945 state->sessmedia = media;
947 /* we have a valid transport now, set the destination of the client. */
948 g_free (ct->destination);
949 if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
950 ct->destination = gst_rtsp_media_get_multicast_group (media->media);
954 url = gst_rtsp_connection_get_url (client->connection);
955 ct->destination = g_strdup (url->host);
957 if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
958 /* check if the client selected channels for TCP */
959 if (ct->interleaved.min == -1 || ct->interleaved.max == -1) {
960 gst_rtsp_session_media_alloc_channels (media, &ct->interleaved);
965 /* get a handle to the stream in the media */
966 if (!(stream = gst_rtsp_session_media_get_stream (media, streamid)))
969 st = gst_rtsp_session_stream_set_transport (stream, ct);
971 /* configure keepalive for this transport */
972 gst_rtsp_session_stream_set_keepalive (stream,
973 (GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
975 /* serialize the server transport */
976 trans_str = gst_rtsp_transport_as_text (st);
977 gst_rtsp_transport_free (st);
979 /* construct the response now */
980 code = GST_RTSP_STS_OK;
981 gst_rtsp_message_init_response (state->response, code,
982 gst_rtsp_status_as_text (code), state->request);
984 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_TRANSPORT,
988 send_response (client, session, state->response);
990 /* update the state */
991 switch (media->state) {
992 case GST_RTSP_STATE_PLAYING:
993 case GST_RTSP_STATE_RECORDING:
994 case GST_RTSP_STATE_READY:
995 /* no state change */
998 media->state = GST_RTSP_STATE_READY;
1001 g_object_unref (session);
1008 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1013 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1014 g_object_unref (session);
1019 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1020 g_object_unref (session);
1021 gst_rtsp_transport_free (ct);
1026 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1029 unsupported_transports:
1031 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1032 gst_rtsp_transport_free (ct);
1037 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1040 service_unavailable:
1042 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1047 static GstSDPMessage *
1048 create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
1053 GstRTSPLowerTrans protocols;
1055 gst_sdp_message_new (&sdp);
1057 /* some standard things first */
1058 gst_sdp_message_set_version (sdp, "0");
1060 if (client->is_ipv6)
1065 gst_sdp_message_set_origin (sdp, "-", "1188340656180883", "1", "IN", proto,
1068 gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
1069 gst_sdp_message_set_information (sdp, "rtsp-server");
1070 gst_sdp_message_add_time (sdp, "0", "0", NULL);
1071 gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
1072 gst_sdp_message_add_attribute (sdp, "type", "broadcast");
1073 gst_sdp_message_add_attribute (sdp, "control", "*");
1075 info.server_proto = proto;
1076 protocols = gst_rtsp_media_get_protocols (media);
1077 if (protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST)
1078 info.server_ip = gst_rtsp_media_get_multicast_group (media);
1080 info.server_ip = g_strdup (client->server_ip);
1082 /* create an SDP for the media object */
1083 if (!gst_rtsp_sdp_from_media (sdp, &info, media))
1086 g_free (info.server_ip);
1093 g_free (info.server_ip);
1094 gst_sdp_message_free (sdp);
1099 /* for the describe we must generate an SDP */
1101 handle_describe_request (GstRTSPClient * client, GstRTSPClientState * state)
1106 gchar *str, *content_base;
1107 GstRTSPMedia *media;
1109 /* check what kind of format is accepted, we don't really do anything with it
1110 * and always return SDP for now. */
1115 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_ACCEPT,
1117 if (res == GST_RTSP_ENOTIMPL)
1120 if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
1124 /* find the media object for the uri */
1125 if (!(media = find_media (client, state)))
1128 /* create an SDP for the media object on this client */
1129 if (!(sdp = create_sdp (client, media)))
1132 g_object_unref (media);
1134 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1135 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1137 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_TYPE,
1140 /* content base for some clients that might screw up creating the setup uri */
1141 str = gst_rtsp_url_get_request_uri (state->uri);
1142 str_len = strlen (str);
1144 /* check for trailing '/' and append one */
1145 if (str[str_len - 1] != '/') {
1146 content_base = g_malloc (str_len + 2);
1147 memcpy (content_base, str, str_len);
1148 content_base[str_len] = '/';
1149 content_base[str_len + 1] = '\0';
1155 GST_INFO ("adding content-base: %s", content_base);
1157 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_BASE,
1159 g_free (content_base);
1161 /* add SDP to the response body */
1162 str = gst_sdp_message_as_text (sdp);
1163 gst_rtsp_message_take_body (state->response, (guint8 *) str, strlen (str));
1164 gst_sdp_message_free (sdp);
1166 send_response (client, state->session, state->response);
1173 /* error reply is already sent */
1178 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1179 g_object_unref (media);
1185 handle_options_request (GstRTSPClient * client, GstRTSPClientState * state)
1187 GstRTSPMethod options;
1190 options = GST_RTSP_DESCRIBE |
1195 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN;
1197 str = gst_rtsp_options_as_text (options);
1199 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1200 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1202 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_PUBLIC, str);
1205 send_response (client, state->session, state->response);
1210 /* remove duplicate and trailing '/' */
1212 sanitize_uri (GstRTSPUrl * uri)
1216 gboolean have_slash, prev_slash;
1218 s = d = uri->abspath;
1219 len = strlen (uri->abspath);
1223 for (i = 0; i < len; i++) {
1224 have_slash = s[i] == '/';
1226 if (!have_slash || !prev_slash)
1228 prev_slash = have_slash;
1230 len = d - uri->abspath;
1231 /* don't remove the first slash if that's the only thing left */
1232 if (len > 1 && *(d - 1) == '/')
1238 client_session_finalized (GstRTSPClient * client, GstRTSPSession * session)
1240 GST_INFO ("client %p: session %p finished", client, session);
1242 /* unlink all media managed in this session */
1243 client_unlink_session (client, session);
1245 /* remove the session */
1246 if (!(client->sessions = g_list_remove (client->sessions, session))) {
1247 GST_INFO ("client %p: all sessions finalized, close the connection",
1249 close_connection (client);
1254 client_watch_session (GstRTSPClient * client, GstRTSPSession * session)
1258 for (walk = client->sessions; walk; walk = g_list_next (walk)) {
1259 GstRTSPSession *msession = (GstRTSPSession *) walk->data;
1261 /* we already know about this session */
1262 if (msession == session)
1266 GST_INFO ("watching session %p", session);
1268 g_object_weak_ref (G_OBJECT (session), (GWeakNotify) client_session_finalized,
1270 client->sessions = g_list_prepend (client->sessions, session);
1274 handle_request (GstRTSPClient * client, GstRTSPMessage * request)
1276 GstRTSPMethod method;
1277 const gchar *uristr;
1279 GstRTSPVersion version;
1281 GstRTSPSession *session;
1282 GstRTSPClientState state = { NULL };
1283 GstRTSPMessage response = { 0 };
1286 state.request = request;
1287 state.response = &response;
1289 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
1290 gst_rtsp_message_dump (request);
1293 GST_INFO ("client %p: received a request", client);
1295 gst_rtsp_message_parse_request (request, &method, &uristr, &version);
1297 if (version != GST_RTSP_VERSION_1_0) {
1298 /* we can only handle 1.0 requests */
1299 send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
1303 state.method = method;
1305 /* we always try to parse the url first */
1306 if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) {
1307 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
1311 /* sanitize the uri */
1315 /* get the session if there is any */
1316 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
1317 if (res == GST_RTSP_OK) {
1318 if (client->session_pool == NULL)
1321 /* we had a session in the request, find it again */
1322 if (!(session = gst_rtsp_session_pool_find (client->session_pool, sessid)))
1323 goto session_not_found;
1325 /* we add the session to the client list of watched sessions. When a session
1326 * disappears because it times out, we will be notified. If all sessions are
1327 * gone, we will close the connection */
1328 client_watch_session (client, session);
1332 state.session = session;
1335 if (!gst_rtsp_auth_check (client->auth, client, 0, &state))
1336 goto not_authorized;
1339 /* now see what is asked and dispatch to a dedicated handler */
1341 case GST_RTSP_OPTIONS:
1342 handle_options_request (client, &state);
1344 case GST_RTSP_DESCRIBE:
1345 handle_describe_request (client, &state);
1347 case GST_RTSP_SETUP:
1348 handle_setup_request (client, &state);
1351 handle_play_request (client, &state);
1353 case GST_RTSP_PAUSE:
1354 handle_pause_request (client, &state);
1356 case GST_RTSP_TEARDOWN:
1357 handle_teardown_request (client, &state);
1359 case GST_RTSP_SET_PARAMETER:
1360 handle_set_param_request (client, &state);
1362 case GST_RTSP_GET_PARAMETER:
1363 handle_get_param_request (client, &state);
1365 case GST_RTSP_ANNOUNCE:
1366 case GST_RTSP_RECORD:
1367 case GST_RTSP_REDIRECT:
1368 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &state);
1370 case GST_RTSP_INVALID:
1372 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
1376 g_object_unref (session);
1378 gst_rtsp_url_free (uri);
1384 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, &state);
1389 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
1394 handle_unauthorized_request (client, client->auth, &state);
1400 handle_data (GstRTSPClient * client, GstRTSPMessage * message)
1410 /* find the stream for this message */
1411 res = gst_rtsp_message_parse_data (message, &channel);
1412 if (res != GST_RTSP_OK)
1415 gst_rtsp_message_steal_body (message, &data, &size);
1417 buffer = gst_buffer_new_wrapped (data, size);
1420 for (walk = client->streams; walk; walk = g_list_next (walk)) {
1421 GstRTSPSessionStream *stream = (GstRTSPSessionStream *) walk->data;
1422 GstRTSPMediaStream *mstream;
1423 GstRTSPTransport *tr;
1425 /* get the transport, if there is no transport configured, skip this stream */
1426 if (!(tr = stream->trans.transport))
1429 /* we also need a media stream */
1430 if (!(mstream = stream->media_stream))
1433 /* check for TCP transport */
1434 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
1435 /* dispatch to the stream based on the channel number */
1436 if (tr->interleaved.min == channel) {
1437 gst_rtsp_media_stream_rtp (mstream, buffer);
1440 } else if (tr->interleaved.max == channel) {
1441 gst_rtsp_media_stream_rtcp (mstream, buffer);
1448 gst_buffer_unref (buffer);
1452 * gst_rtsp_client_set_session_pool:
1453 * @client: a #GstRTSPClient
1454 * @pool: a #GstRTSPSessionPool
1456 * Set @pool as the sessionpool for @client which it will use to find
1457 * or allocate sessions. the sessionpool is usually inherited from the server
1458 * that created the client but can be overridden later.
1461 gst_rtsp_client_set_session_pool (GstRTSPClient * client,
1462 GstRTSPSessionPool * pool)
1464 GstRTSPSessionPool *old;
1466 old = client->session_pool;
1469 g_object_ref (pool);
1470 client->session_pool = pool;
1472 g_object_unref (old);
1477 * gst_rtsp_client_get_session_pool:
1478 * @client: a #GstRTSPClient
1480 * Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
1482 * Returns: a #GstRTSPSessionPool, unref after usage.
1484 GstRTSPSessionPool *
1485 gst_rtsp_client_get_session_pool (GstRTSPClient * client)
1487 GstRTSPSessionPool *result;
1489 if ((result = client->session_pool))
1490 g_object_ref (result);
1496 * gst_rtsp_client_set_server:
1497 * @client: a #GstRTSPClient
1498 * @server: a #GstRTSPServer
1500 * Set @server as the server that created @client.
1503 gst_rtsp_client_set_server (GstRTSPClient * client, GstRTSPServer * server)
1507 old = client->server;
1508 if (old != server) {
1510 g_object_ref (server);
1511 client->server = server;
1513 g_object_unref (old);
1518 * gst_rtsp_client_get_server:
1519 * @client: a #GstRTSPClient
1521 * Get the #GstRTSPServer object that @client was created from.
1523 * Returns: a #GstRTSPServer, unref after usage.
1526 gst_rtsp_client_get_server (GstRTSPClient * client)
1528 GstRTSPServer *result;
1530 if ((result = client->server))
1531 g_object_ref (result);
1537 * gst_rtsp_client_set_media_mapping:
1538 * @client: a #GstRTSPClient
1539 * @mapping: a #GstRTSPMediaMapping
1541 * Set @mapping as the media mapping for @client which it will use to map urls
1542 * to media streams. These mapping is usually inherited from the server that
1543 * created the client but can be overriden later.
1546 gst_rtsp_client_set_media_mapping (GstRTSPClient * client,
1547 GstRTSPMediaMapping * mapping)
1549 GstRTSPMediaMapping *old;
1551 old = client->media_mapping;
1553 if (old != mapping) {
1555 g_object_ref (mapping);
1556 client->media_mapping = mapping;
1558 g_object_unref (old);
1563 * gst_rtsp_client_get_media_mapping:
1564 * @client: a #GstRTSPClient
1566 * Get the #GstRTSPMediaMapping object that @client uses to manage its sessions.
1568 * Returns: a #GstRTSPMediaMapping, unref after usage.
1570 GstRTSPMediaMapping *
1571 gst_rtsp_client_get_media_mapping (GstRTSPClient * client)
1573 GstRTSPMediaMapping *result;
1575 if ((result = client->media_mapping))
1576 g_object_ref (result);
1582 * gst_rtsp_client_set_auth:
1583 * @client: a #GstRTSPClient
1584 * @auth: a #GstRTSPAuth
1586 * configure @auth to be used as the authentication manager of @client.
1589 gst_rtsp_client_set_auth (GstRTSPClient * client, GstRTSPAuth * auth)
1593 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
1599 g_object_ref (auth);
1600 client->auth = auth;
1602 g_object_unref (old);
1608 * gst_rtsp_client_get_auth:
1609 * @client: a #GstRTSPClient
1611 * Get the #GstRTSPAuth used as the authentication manager of @client.
1613 * Returns: the #GstRTSPAuth of @client. g_object_unref() after
1617 gst_rtsp_client_get_auth (GstRTSPClient * client)
1619 GstRTSPAuth *result;
1621 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
1623 if ((result = client->auth))
1624 g_object_ref (result);
1629 static GstRTSPResult
1630 message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
1633 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1635 switch (message->type) {
1636 case GST_RTSP_MESSAGE_REQUEST:
1637 handle_request (client, message);
1639 case GST_RTSP_MESSAGE_RESPONSE:
1641 case GST_RTSP_MESSAGE_DATA:
1642 handle_data (client, message);
1650 static GstRTSPResult
1651 message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
1653 /* GstRTSPClient *client; */
1655 /* client = GST_RTSP_CLIENT (user_data); */
1657 /* GST_INFO ("client %p: sent a message with cseq %d", client, cseq); */
1662 static GstRTSPResult
1663 closed (GstRTSPWatch * watch, gpointer user_data)
1665 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1666 const gchar *tunnelid;
1668 GST_INFO ("client %p: connection closed", client);
1670 if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
1671 g_mutex_lock (&tunnels_lock);
1672 /* remove from tunnelids */
1673 g_hash_table_remove (tunnels, tunnelid);
1674 g_mutex_unlock (&tunnels_lock);
1680 static GstRTSPResult
1681 error (GstRTSPWatch * watch, GstRTSPResult result, gpointer user_data)
1683 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1686 str = gst_rtsp_strresult (result);
1687 GST_INFO ("client %p: received an error %s", client, str);
1693 static GstRTSPResult
1694 error_full (GstRTSPWatch * watch, GstRTSPResult result,
1695 GstRTSPMessage * message, guint id, gpointer user_data)
1697 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1700 str = gst_rtsp_strresult (result);
1702 ("client %p: received an error %s when handling message %p with id %d",
1703 client, str, message, id);
1710 remember_tunnel (GstRTSPClient * client)
1712 const gchar *tunnelid;
1714 /* store client in the pending tunnels */
1715 tunnelid = gst_rtsp_connection_get_tunnelid (client->connection);
1716 if (tunnelid == NULL)
1719 GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
1721 /* we can't have two clients connecting with the same tunnelid */
1722 g_mutex_lock (&tunnels_lock);
1723 if (g_hash_table_lookup (tunnels, tunnelid))
1724 goto tunnel_existed;
1726 g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
1727 g_mutex_unlock (&tunnels_lock);
1734 GST_ERROR ("client %p: no tunnelid provided", client);
1739 g_mutex_unlock (&tunnels_lock);
1740 GST_ERROR ("client %p: tunnel session %s already existed", client,
1746 static GstRTSPStatusCode
1747 tunnel_start (GstRTSPWatch * watch, gpointer user_data)
1749 GstRTSPClient *client;
1751 client = GST_RTSP_CLIENT (user_data);
1753 GST_INFO ("client %p: tunnel start (connection %p)", client,
1754 client->connection);
1756 if (!remember_tunnel (client))
1759 return GST_RTSP_STS_OK;
1764 GST_ERROR ("client %p: error starting tunnel", client);
1765 return GST_RTSP_STS_SERVICE_UNAVAILABLE;
1769 static GstRTSPResult
1770 tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
1772 GstRTSPClient *client;
1774 client = GST_RTSP_CLIENT (user_data);
1776 GST_INFO ("client %p: tunnel lost (connection %p)", client,
1777 client->connection);
1779 /* ignore error, it'll only be a problem when the client does a POST again */
1780 remember_tunnel (client);
1785 static GstRTSPResult
1786 tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
1788 const gchar *tunnelid;
1789 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
1790 GstRTSPClient *oclient;
1792 GST_INFO ("client %p: tunnel complete", client);
1794 /* find previous tunnel */
1795 tunnelid = gst_rtsp_connection_get_tunnelid (client->connection);
1796 if (tunnelid == NULL)
1799 g_mutex_lock (&tunnels_lock);
1800 if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
1803 /* remove the old client from the table. ref before because removing it will
1804 * remove the ref to it. */
1805 g_object_ref (oclient);
1806 g_hash_table_remove (tunnels, tunnelid);
1808 if (oclient->watch == NULL)
1810 g_mutex_unlock (&tunnels_lock);
1812 GST_INFO ("client %p: found tunnel %p (old %p, new %p)", client, oclient,
1813 oclient->connection, client->connection);
1815 /* merge the tunnels into the first client */
1816 gst_rtsp_connection_do_tunnel (oclient->connection, client->connection);
1817 gst_rtsp_watch_reset (oclient->watch);
1818 g_object_unref (oclient);
1820 /* we don't need this watch anymore */
1821 g_source_destroy ((GSource *) client->watch);
1822 client->watchid = 0;
1823 client->watch = NULL;
1830 GST_INFO ("client %p: no tunnelid provided", client);
1831 return GST_RTSP_ERROR;
1835 g_mutex_unlock (&tunnels_lock);
1836 GST_INFO ("client %p: tunnel session %s not found", client, tunnelid);
1837 return GST_RTSP_ERROR;
1841 g_mutex_unlock (&tunnels_lock);
1842 GST_INFO ("client %p: tunnel session %s was closed", client, tunnelid);
1843 g_object_unref (oclient);
1844 return GST_RTSP_ERROR;
1848 static GstRTSPWatchFuncs watch_funcs = {
1860 client_watch_notify (GstRTSPClient * client)
1862 GST_INFO ("client %p: watch destroyed", client);
1863 client->watchid = 0;
1864 client->watch = NULL;
1865 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
1866 g_object_unref (client);
1870 * gst_rtsp_client_attach:
1871 * @client: a #GstRTSPClient
1872 * @socket: a #GSocket
1873 * @cancellable: a #GCancellable
1876 * Accept a new connection for @client on @socket.
1878 * This function should be called when the client properties and urls are fully
1879 * configured and the client is ready to start.
1881 * Returns: %TRUE if the client could be accepted.
1884 gst_rtsp_client_accept (GstRTSPClient * client, GSocket * socket,
1885 GCancellable * cancellable, GError ** error)
1887 GstRTSPConnection *conn;
1889 GSocket *read_socket;
1890 GSocketAddress *addres;
1892 GMainContext *context;
1894 struct sockaddr_storage addr;
1896 gchar ip[INET6_ADDRSTRLEN];
1898 /* a new client connected. */
1899 GST_RTSP_CHECK (gst_rtsp_connection_accept (socket, &conn, cancellable),
1902 read_socket = gst_rtsp_connection_get_read_socket (conn);
1903 client->is_ipv6 = g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV6;
1905 if (!(addres = g_socket_get_remote_address (read_socket, error)))
1908 addrlen = sizeof (addr);
1909 if (!g_socket_address_to_native (addres, &addr, addrlen, error))
1911 g_object_unref (addres);
1913 if (getnameinfo ((struct sockaddr *) &addr, addrlen, ip, sizeof (ip), NULL, 0,
1914 NI_NUMERICHOST) != 0)
1915 goto getnameinfo_failed;
1917 /* keep the original ip that the client connected to */
1918 g_free (client->server_ip);
1919 client->server_ip = g_strndup (ip, sizeof (ip));
1921 GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
1922 client->server_ip, client->is_ipv6);
1924 url = gst_rtsp_connection_get_url (conn);
1925 GST_INFO ("added new client %p ip %s:%d", client, url->host, url->port);
1927 client->connection = conn;
1929 /* create watch for the connection and attach */
1930 client->watch = gst_rtsp_watch_new (client->connection, &watch_funcs,
1931 g_object_ref (client), (GDestroyNotify) client_watch_notify);
1933 /* find the context to add the watch */
1934 if ((source = g_main_current_source ()))
1935 context = g_source_get_context (source);
1939 GST_INFO ("attaching to context %p", context);
1941 client->watchid = gst_rtsp_watch_attach (client->watch, context);
1942 gst_rtsp_watch_unref (client->watch);
1949 gchar *str = gst_rtsp_strresult (res);
1951 GST_ERROR ("Could not accept client on server socket %p: %s", socket, str);
1957 GST_ERROR ("could not get remote address %s", (*error)->message);
1962 g_object_unref (addres);
1963 GST_ERROR ("could not get native address %s", (*error)->message);
1968 GST_ERROR ("getnameinfo failed: %s", g_strerror (errno));