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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "rtsp-client.h"
25 #include "rtsp-params.h"
27 #define GST_RTSP_CLIENT_GET_PRIVATE(obj) \
28 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_CLIENT, GstRTSPClientPrivate))
31 * send_lock, lock, tunnels_lock
34 struct _GstRTSPClientPrivate
36 GMutex lock; /* protects everything else */
38 GstRTSPConnection *connection;
43 gboolean use_client_settings;
45 GstRTSPClientSendFunc send_func; /* protected by send_lock */
46 gpointer send_data; /* protected by send_lock */
47 GDestroyNotify send_notify; /* protected by send_lock */
49 GstRTSPSessionPool *session_pool;
50 GstRTSPMountPoints *mount_points;
53 /* used to cache the media in the last requested DESCRIBE so that
54 * we can pick it up in the next SETUP immediately */
62 static GMutex tunnels_lock;
63 static GHashTable *tunnels; /* protected by tunnels_lock */
65 #define DEFAULT_SESSION_POOL NULL
66 #define DEFAULT_MOUNT_POINTS NULL
67 #define DEFAULT_USE_CLIENT_SETTINGS FALSE
74 PROP_USE_CLIENT_SETTINGS,
82 SIGNAL_OPTIONS_REQUEST,
83 SIGNAL_DESCRIBE_REQUEST,
87 SIGNAL_TEARDOWN_REQUEST,
88 SIGNAL_SET_PARAMETER_REQUEST,
89 SIGNAL_GET_PARAMETER_REQUEST,
93 GST_DEBUG_CATEGORY_STATIC (rtsp_client_debug);
94 #define GST_CAT_DEFAULT rtsp_client_debug
96 static guint gst_rtsp_client_signals[SIGNAL_LAST] = { 0 };
98 static void gst_rtsp_client_get_property (GObject * object, guint propid,
99 GValue * value, GParamSpec * pspec);
100 static void gst_rtsp_client_set_property (GObject * object, guint propid,
101 const GValue * value, GParamSpec * pspec);
102 static void gst_rtsp_client_finalize (GObject * obj);
104 static GstSDPMessage *create_sdp (GstRTSPClient * client, GstRTSPMedia * media);
105 static void client_session_finalized (GstRTSPClient * client,
106 GstRTSPSession * session);
107 static void unlink_session_transports (GstRTSPClient * client,
108 GstRTSPSession * session, GstRTSPSessionMedia * media);
109 static gboolean default_configure_client_transport (GstRTSPClient * client,
110 GstRTSPClientState * state, GstRTSPTransport * ct);
111 static GstRTSPResult default_params_set (GstRTSPClient * client,
112 GstRTSPClientState * state);
113 static GstRTSPResult default_params_get (GstRTSPClient * client,
114 GstRTSPClientState * state);
116 G_DEFINE_TYPE (GstRTSPClient, gst_rtsp_client, G_TYPE_OBJECT);
119 gst_rtsp_client_class_init (GstRTSPClientClass * klass)
121 GObjectClass *gobject_class;
123 g_type_class_add_private (klass, sizeof (GstRTSPClientPrivate));
125 gobject_class = G_OBJECT_CLASS (klass);
127 gobject_class->get_property = gst_rtsp_client_get_property;
128 gobject_class->set_property = gst_rtsp_client_set_property;
129 gobject_class->finalize = gst_rtsp_client_finalize;
131 klass->create_sdp = create_sdp;
132 klass->configure_client_transport = default_configure_client_transport;
133 klass->params_set = default_params_set;
134 klass->params_get = default_params_get;
136 g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
137 g_param_spec_object ("session-pool", "Session Pool",
138 "The session pool to use for client session",
139 GST_TYPE_RTSP_SESSION_POOL,
140 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
142 g_object_class_install_property (gobject_class, PROP_MOUNT_POINTS,
143 g_param_spec_object ("mount-points", "Mount Points",
144 "The mount points to use for client session",
145 GST_TYPE_RTSP_MOUNT_POINTS,
146 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
148 g_object_class_install_property (gobject_class, PROP_USE_CLIENT_SETTINGS,
149 g_param_spec_boolean ("use-client-settings", "Use Client Settings",
150 "Use client settings for ttl and destination in multicast",
151 DEFAULT_USE_CLIENT_SETTINGS,
152 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
154 gst_rtsp_client_signals[SIGNAL_CLOSED] =
155 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
156 G_STRUCT_OFFSET (GstRTSPClientClass, closed), NULL, NULL,
157 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
159 gst_rtsp_client_signals[SIGNAL_NEW_SESSION] =
160 g_signal_new ("new-session", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
161 G_STRUCT_OFFSET (GstRTSPClientClass, new_session), NULL, NULL,
162 g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_RTSP_SESSION);
164 gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST] =
165 g_signal_new ("options-request", G_TYPE_FROM_CLASS (klass),
166 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, options_request),
167 NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
170 gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST] =
171 g_signal_new ("describe-request", G_TYPE_FROM_CLASS (klass),
172 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, describe_request),
173 NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
176 gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST] =
177 g_signal_new ("setup-request", G_TYPE_FROM_CLASS (klass),
178 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, setup_request),
179 NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
182 gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST] =
183 g_signal_new ("play-request", G_TYPE_FROM_CLASS (klass),
184 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, play_request),
185 NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
188 gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST] =
189 g_signal_new ("pause-request", G_TYPE_FROM_CLASS (klass),
190 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, pause_request),
191 NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
194 gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST] =
195 g_signal_new ("teardown-request", G_TYPE_FROM_CLASS (klass),
196 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, teardown_request),
197 NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
200 gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST] =
201 g_signal_new ("set-parameter-request", G_TYPE_FROM_CLASS (klass),
202 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
203 set_parameter_request), NULL, NULL, g_cclosure_marshal_VOID__POINTER,
204 G_TYPE_NONE, 1, G_TYPE_POINTER);
206 gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST] =
207 g_signal_new ("get-parameter-request", G_TYPE_FROM_CLASS (klass),
208 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
209 get_parameter_request), NULL, NULL, g_cclosure_marshal_VOID__POINTER,
210 G_TYPE_NONE, 1, G_TYPE_POINTER);
213 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
214 g_mutex_init (&tunnels_lock);
216 GST_DEBUG_CATEGORY_INIT (rtsp_client_debug, "rtspclient", 0, "GstRTSPClient");
220 gst_rtsp_client_init (GstRTSPClient * client)
222 GstRTSPClientPrivate *priv = GST_RTSP_CLIENT_GET_PRIVATE (client);
226 g_mutex_init (&priv->lock);
227 g_mutex_init (&priv->send_lock);
228 priv->use_client_settings = DEFAULT_USE_CLIENT_SETTINGS;
232 static GstRTSPFilterResult
233 filter_session (GstRTSPSession * sess, GstRTSPSessionMedia * media,
236 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
238 gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
239 unlink_session_transports (client, sess, media);
241 /* unmanage the media in the session */
242 return GST_RTSP_FILTER_REMOVE;
246 client_unlink_session (GstRTSPClient * client, GstRTSPSession * session)
248 /* unlink all media managed in this session */
249 gst_rtsp_session_filter (session, filter_session, client);
253 client_watch_session (GstRTSPClient * client, GstRTSPSession * session)
255 GstRTSPClientPrivate *priv = client->priv;
258 for (walk = priv->sessions; walk; walk = g_list_next (walk)) {
259 GstRTSPSession *msession = (GstRTSPSession *) walk->data;
261 /* we already know about this session */
262 if (msession == session)
266 GST_INFO ("watching session %p", session);
268 g_object_weak_ref (G_OBJECT (session), (GWeakNotify) client_session_finalized,
270 priv->sessions = g_list_prepend (priv->sessions, session);
274 client_unwatch_session (GstRTSPClient * client, GstRTSPSession * session)
276 GstRTSPClientPrivate *priv = client->priv;
278 GST_INFO ("unwatching session %p", session);
280 g_object_weak_unref (G_OBJECT (session),
281 (GWeakNotify) client_session_finalized, client);
282 priv->sessions = g_list_remove (priv->sessions, session);
286 client_cleanup_session (GstRTSPClient * client, GstRTSPSession * session)
288 g_object_weak_unref (G_OBJECT (session),
289 (GWeakNotify) client_session_finalized, client);
290 client_unlink_session (client, session);
294 client_cleanup_sessions (GstRTSPClient * client)
296 GstRTSPClientPrivate *priv = client->priv;
299 /* remove weak-ref from sessions */
300 for (sessions = priv->sessions; sessions; sessions = g_list_next (sessions)) {
301 client_cleanup_session (client, (GstRTSPSession *) sessions->data);
303 g_list_free (priv->sessions);
304 priv->sessions = NULL;
307 /* A client is finalized when the connection is broken */
309 gst_rtsp_client_finalize (GObject * obj)
311 GstRTSPClient *client = GST_RTSP_CLIENT (obj);
312 GstRTSPClientPrivate *priv = client->priv;
314 GST_INFO ("finalize client %p", client);
316 gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
319 g_source_destroy ((GSource *) priv->watch);
321 client_cleanup_sessions (client);
323 if (priv->connection)
324 gst_rtsp_connection_free (priv->connection);
325 if (priv->session_pool)
326 g_object_unref (priv->session_pool);
327 if (priv->mount_points)
328 g_object_unref (priv->mount_points);
330 g_object_unref (priv->auth);
333 gst_rtsp_url_free (priv->uri);
335 gst_rtsp_media_unprepare (priv->media);
336 g_object_unref (priv->media);
339 g_free (priv->server_ip);
340 g_mutex_clear (&priv->lock);
341 g_mutex_clear (&priv->send_lock);
343 G_OBJECT_CLASS (gst_rtsp_client_parent_class)->finalize (obj);
347 gst_rtsp_client_get_property (GObject * object, guint propid,
348 GValue * value, GParamSpec * pspec)
350 GstRTSPClient *client = GST_RTSP_CLIENT (object);
353 case PROP_SESSION_POOL:
354 g_value_take_object (value, gst_rtsp_client_get_session_pool (client));
356 case PROP_MOUNT_POINTS:
357 g_value_take_object (value, gst_rtsp_client_get_mount_points (client));
359 case PROP_USE_CLIENT_SETTINGS:
360 g_value_set_boolean (value,
361 gst_rtsp_client_get_use_client_settings (client));
364 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
369 gst_rtsp_client_set_property (GObject * object, guint propid,
370 const GValue * value, GParamSpec * pspec)
372 GstRTSPClient *client = GST_RTSP_CLIENT (object);
375 case PROP_SESSION_POOL:
376 gst_rtsp_client_set_session_pool (client, g_value_get_object (value));
378 case PROP_MOUNT_POINTS:
379 gst_rtsp_client_set_mount_points (client, g_value_get_object (value));
381 case PROP_USE_CLIENT_SETTINGS:
382 gst_rtsp_client_set_use_client_settings (client,
383 g_value_get_boolean (value));
386 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
391 * gst_rtsp_client_new:
393 * Create a new #GstRTSPClient instance.
395 * Returns: a new #GstRTSPClient
398 gst_rtsp_client_new (void)
400 GstRTSPClient *result;
402 result = g_object_new (GST_TYPE_RTSP_CLIENT, NULL);
408 send_message (GstRTSPClient * client, GstRTSPSession * session,
409 GstRTSPMessage * message, gboolean close)
411 GstRTSPClientPrivate *priv = client->priv;
413 gst_rtsp_message_add_header (message, GST_RTSP_HDR_SERVER,
414 "GStreamer RTSP server");
416 /* remove any previous header */
417 gst_rtsp_message_remove_header (message, GST_RTSP_HDR_SESSION, -1);
419 /* add the new session header for new session ids */
421 gst_rtsp_message_take_header (message, GST_RTSP_HDR_SESSION,
422 gst_rtsp_session_get_header (session));
425 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
426 gst_rtsp_message_dump (message);
430 gst_rtsp_message_add_header (message, GST_RTSP_HDR_CONNECTION, "close");
432 g_mutex_lock (&priv->send_lock);
434 priv->send_func (client, message, close, priv->send_data);
435 g_mutex_unlock (&priv->send_lock);
437 gst_rtsp_message_unset (message);
441 send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
442 GstRTSPClientState * state)
444 gst_rtsp_message_init_response (state->response, code,
445 gst_rtsp_status_as_text (code), state->request);
447 send_message (client, NULL, state->response, FALSE);
451 handle_unauthorized_request (GstRTSPClient * client, GstRTSPAuth * auth,
452 GstRTSPClientState * state)
454 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_UNAUTHORIZED,
455 gst_rtsp_status_as_text (GST_RTSP_STS_UNAUTHORIZED), state->request);
458 /* and let the authentication manager setup the auth tokens */
459 gst_rtsp_auth_setup_auth (auth, client, 0, state);
462 send_message (client, state->session, state->response, FALSE);
467 compare_uri (const GstRTSPUrl * uri1, const GstRTSPUrl * uri2)
469 if (uri1 == NULL || uri2 == NULL)
472 if (strcmp (uri1->abspath, uri2->abspath))
478 /* this function is called to initially find the media for the DESCRIBE request
479 * but is cached for when the same client (without breaking the connection) is
480 * doing a setup for the exact same url. */
481 static GstRTSPMedia *
482 find_media (GstRTSPClient * client, GstRTSPClientState * state)
484 GstRTSPClientPrivate *priv = client->priv;
485 GstRTSPMediaFactory *factory;
489 if (!compare_uri (priv->uri, state->uri)) {
490 /* remove any previously cached values before we try to construct a new
493 gst_rtsp_url_free (priv->uri);
496 gst_rtsp_media_unprepare (priv->media);
497 g_object_unref (priv->media);
501 if (!priv->mount_points)
502 goto no_mount_points;
504 /* find the factory for the uri first */
506 gst_rtsp_mount_points_find_factory (priv->mount_points,
510 /* check if we have access to the factory */
511 if ((auth = gst_rtsp_media_factory_get_auth (factory))) {
512 state->factory = factory;
514 if (!gst_rtsp_auth_check (auth, client, 0, state))
517 state->factory = NULL;
518 g_object_unref (auth);
521 /* prepare the media and add it to the pipeline */
522 if (!(media = gst_rtsp_media_factory_construct (factory, state->uri)))
525 g_object_unref (factory);
528 /* prepare the media */
529 if (!(gst_rtsp_media_prepare (media)))
532 /* now keep track of the uri and the media */
533 priv->uri = gst_rtsp_url_copy (state->uri);
535 state->media = media;
537 /* we have seen this uri before, used cached media */
539 state->media = media;
540 GST_INFO ("reusing cached media %p", media);
544 g_object_ref (media);
551 GST_ERROR ("client %p: no mount points configured", client);
552 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
557 GST_ERROR ("client %p: no factory for uri", client);
558 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
563 GST_ERROR ("client %p: unauthorized request", client);
564 handle_unauthorized_request (client, auth, state);
565 g_object_unref (factory);
566 state->factory = NULL;
567 g_object_unref (auth);
572 GST_ERROR ("client %p: can't create media", client);
573 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
574 g_object_unref (factory);
579 GST_ERROR ("client %p: can't prepare media", client);
580 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
581 g_object_unref (media);
587 do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
589 GstRTSPClientPrivate *priv = client->priv;
590 GstRTSPMessage message = { 0 };
595 gst_rtsp_message_init_data (&message, channel);
597 /* FIXME, need some sort of iovec RTSPMessage here */
598 if (!gst_buffer_map (buffer, &map_info, GST_MAP_READ))
601 gst_rtsp_message_take_body (&message, map_info.data, map_info.size);
603 g_mutex_lock (&priv->send_lock);
605 priv->send_func (client, &message, FALSE, priv->send_data);
606 g_mutex_unlock (&priv->send_lock);
608 gst_rtsp_message_steal_body (&message, &data, &usize);
609 gst_buffer_unmap (buffer, &map_info);
611 gst_rtsp_message_unset (&message);
617 link_transport (GstRTSPClient * client, GstRTSPSession * session,
618 GstRTSPStreamTransport * trans)
620 GstRTSPClientPrivate *priv = client->priv;
622 GST_DEBUG ("client %p: linking transport %p", client, trans);
624 gst_rtsp_stream_transport_set_callbacks (trans,
625 (GstRTSPSendFunc) do_send_data,
626 (GstRTSPSendFunc) do_send_data, client, NULL);
628 priv->transports = g_list_prepend (priv->transports, trans);
630 /* make sure our session can't expire */
631 gst_rtsp_session_prevent_expire (session);
635 unlink_transport (GstRTSPClient * client, GstRTSPSession * session,
636 GstRTSPStreamTransport * trans)
638 GstRTSPClientPrivate *priv = client->priv;
640 GST_DEBUG ("client %p: unlinking transport %p", client, trans);
642 gst_rtsp_stream_transport_set_callbacks (trans, NULL, NULL, NULL, NULL);
644 priv->transports = g_list_remove (priv->transports, trans);
646 /* our session can now expire */
647 gst_rtsp_session_allow_expire (session);
651 unlink_session_transports (GstRTSPClient * client, GstRTSPSession * session,
652 GstRTSPSessionMedia * media)
657 gst_rtsp_media_n_streams (gst_rtsp_session_media_get_media (media));
658 for (i = 0; i < n_streams; i++) {
659 GstRTSPStreamTransport *trans;
660 const GstRTSPTransport *tr;
662 /* get the transport, if there is no transport configured, skip this stream */
663 trans = gst_rtsp_session_media_get_transport (media, i);
667 tr = gst_rtsp_stream_transport_get_transport (trans);
669 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
670 /* for TCP, unlink the stream from the TCP connection of the client */
671 unlink_transport (client, session, trans);
677 close_connection (GstRTSPClient * client)
679 GstRTSPClientPrivate *priv = client->priv;
680 const gchar *tunnelid;
682 GST_DEBUG ("client %p: closing connection", client);
684 if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
685 g_mutex_lock (&tunnels_lock);
686 /* remove from tunnelids */
687 g_hash_table_remove (tunnels, tunnelid);
688 g_mutex_unlock (&tunnels_lock);
691 gst_rtsp_connection_close (priv->connection);
695 handle_teardown_request (GstRTSPClient * client, GstRTSPClientState * state)
697 GstRTSPClientPrivate *priv = client->priv;
698 GstRTSPSession *session;
699 GstRTSPSessionMedia *media;
700 GstRTSPStatusCode code;
705 session = state->session;
710 /* get a handle to the configuration of the media in the session */
711 media = gst_rtsp_session_get_media (session, state->uri);
715 state->sessmedia = media;
717 /* we emit the signal before closing the connection */
718 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST],
721 /* unlink the all TCP callbacks */
722 unlink_session_transports (client, session, media);
724 /* remove the session from the watched sessions */
725 client_unwatch_session (client, session);
727 gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
729 /* unmanage the media in the session, returns false if all media session
731 if (!gst_rtsp_session_release_media (session, media)) {
732 /* remove the session */
733 gst_rtsp_session_pool_remove (priv->session_pool, session);
735 /* construct the response now */
736 code = GST_RTSP_STS_OK;
737 gst_rtsp_message_init_response (state->response, code,
738 gst_rtsp_status_as_text (code), state->request);
740 send_message (client, session, state->response, TRUE);
747 GST_ERROR ("client %p: no session", client);
748 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
753 GST_ERROR ("client %p: no uri supplied", client);
754 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
759 GST_ERROR ("client %p: no media for uri", client);
760 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
766 default_params_set (GstRTSPClient * client, GstRTSPClientState * state)
770 res = gst_rtsp_params_set (client, state);
776 default_params_get (GstRTSPClient * client, GstRTSPClientState * state)
780 res = gst_rtsp_params_get (client, state);
786 handle_get_param_request (GstRTSPClient * client, GstRTSPClientState * state)
792 res = gst_rtsp_message_get_body (state->request, &data, &size);
793 if (res != GST_RTSP_OK)
797 /* no body, keep-alive request */
798 send_generic_response (client, GST_RTSP_STS_OK, state);
800 /* there is a body, handle the params */
801 res = GST_RTSP_CLIENT_GET_CLASS (client)->params_get (client, state);
802 if (res != GST_RTSP_OK)
805 send_message (client, state->session, state->response, FALSE);
808 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST],
816 GST_ERROR ("client %p: bad request", client);
817 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
823 handle_set_param_request (GstRTSPClient * client, GstRTSPClientState * state)
829 res = gst_rtsp_message_get_body (state->request, &data, &size);
830 if (res != GST_RTSP_OK)
834 /* no body, keep-alive request */
835 send_generic_response (client, GST_RTSP_STS_OK, state);
837 /* there is a body, handle the params */
838 res = GST_RTSP_CLIENT_GET_CLASS (client)->params_set (client, state);
839 if (res != GST_RTSP_OK)
842 send_message (client, state->session, state->response, FALSE);
845 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST],
853 GST_ERROR ("client %p: bad request", client);
854 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
860 handle_pause_request (GstRTSPClient * client, GstRTSPClientState * state)
862 GstRTSPSession *session;
863 GstRTSPSessionMedia *media;
864 GstRTSPStatusCode code;
865 GstRTSPState rtspstate;
867 if (!(session = state->session))
873 /* get a handle to the configuration of the media in the session */
874 media = gst_rtsp_session_get_media (session, state->uri);
878 state->sessmedia = media;
880 rtspstate = gst_rtsp_session_media_get_rtsp_state (media);
881 /* the session state must be playing or recording */
882 if (rtspstate != GST_RTSP_STATE_PLAYING &&
883 rtspstate != GST_RTSP_STATE_RECORDING)
886 /* unlink the all TCP callbacks */
887 unlink_session_transports (client, session, media);
889 /* then pause sending */
890 gst_rtsp_session_media_set_state (media, GST_STATE_PAUSED);
892 /* construct the response now */
893 code = GST_RTSP_STS_OK;
894 gst_rtsp_message_init_response (state->response, code,
895 gst_rtsp_status_as_text (code), state->request);
897 send_message (client, session, state->response, FALSE);
899 /* the state is now READY */
900 gst_rtsp_session_media_set_rtsp_state (media, GST_RTSP_STATE_READY);
902 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST],
910 GST_ERROR ("client %p: no seesion", client);
911 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
916 GST_ERROR ("client %p: no uri supplied", client);
917 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
922 GST_ERROR ("client %p: no media for uri", client);
923 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
928 GST_ERROR ("client %p: not PLAYING or RECORDING", client);
929 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
936 handle_play_request (GstRTSPClient * client, GstRTSPClientState * state)
938 GstRTSPSession *session;
939 GstRTSPSessionMedia *media;
940 GstRTSPStatusCode code;
942 guint n_streams, i, infocount;
944 GstRTSPTimeRange *range;
946 GstRTSPState rtspstate;
947 GstRTSPRangeUnit unit = GST_RTSP_RANGE_NPT;
949 if (!(session = state->session))
955 /* get a handle to the configuration of the media in the session */
956 media = gst_rtsp_session_get_media (session, state->uri);
960 state->sessmedia = media;
962 /* the session state must be playing or ready */
963 rtspstate = gst_rtsp_session_media_get_rtsp_state (media);
964 if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
967 /* parse the range header if we have one */
969 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_RANGE, &str, 0);
970 if (res == GST_RTSP_OK) {
971 if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
972 /* we have a range, seek to the position */
974 gst_rtsp_media_seek (gst_rtsp_session_media_get_media (media), range);
975 gst_rtsp_range_free (range);
979 /* grab RTPInfo from the payloaders now */
980 rtpinfo = g_string_new ("");
983 gst_rtsp_media_n_streams (gst_rtsp_session_media_get_media (media));
984 for (i = 0, infocount = 0; i < n_streams; i++) {
985 GstRTSPStreamTransport *trans;
986 GstRTSPStream *stream;
987 const GstRTSPTransport *tr;
991 /* get the transport, if there is no transport configured, skip this stream */
992 trans = gst_rtsp_session_media_get_transport (media, i);
994 GST_INFO ("stream %d is not configured", i);
997 tr = gst_rtsp_stream_transport_get_transport (trans);
999 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
1000 /* for TCP, link the stream to the TCP connection of the client */
1001 link_transport (client, session, trans);
1004 stream = gst_rtsp_stream_transport_get_stream (trans);
1005 if (gst_rtsp_stream_get_rtpinfo (stream, &rtptime, &seq)) {
1007 g_string_append (rtpinfo, ", ");
1009 uristr = gst_rtsp_url_get_request_uri (state->uri);
1010 g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
1011 uristr, i, seq, rtptime);
1016 GST_WARNING ("RTP-Info cannot be determined for stream %d", i);
1020 /* construct the response now */
1021 code = GST_RTSP_STS_OK;
1022 gst_rtsp_message_init_response (state->response, code,
1023 gst_rtsp_status_as_text (code), state->request);
1025 /* add the RTP-Info header */
1026 if (infocount > 0) {
1027 str = g_string_free (rtpinfo, FALSE);
1028 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RTP_INFO, str);
1030 g_string_free (rtpinfo, TRUE);
1035 gst_rtsp_media_get_range_string (gst_rtsp_session_media_get_media (media),
1037 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RANGE, str);
1039 send_message (client, session, state->response, FALSE);
1041 /* start playing after sending the request */
1042 gst_rtsp_session_media_set_state (media, GST_STATE_PLAYING);
1044 gst_rtsp_session_media_set_rtsp_state (media, GST_RTSP_STATE_PLAYING);
1046 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST],
1054 GST_ERROR ("client %p: no session", client);
1055 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
1060 GST_ERROR ("client %p: no uri supplied", client);
1061 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1066 GST_ERROR ("client %p: media not found", client);
1067 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1072 GST_ERROR ("client %p: not PLAYING or READY", client);
1073 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
1080 do_keepalive (GstRTSPSession * session)
1082 GST_INFO ("keep session %p alive", session);
1083 gst_rtsp_session_touch (session);
1086 /* parse @transport and return a valid transport in @tr. only transports
1087 * from @supported are returned. Returns FALSE if no valid transport
1090 parse_transport (const char *transport, GstRTSPLowerTrans supported,
1091 GstRTSPTransport * tr)
1098 gst_rtsp_transport_init (tr);
1100 GST_DEBUG ("parsing transports %s", transport);
1102 transports = g_strsplit (transport, ",", 0);
1104 /* loop through the transports, try to parse */
1105 for (i = 0; transports[i]; i++) {
1106 res = gst_rtsp_transport_parse (transports[i], tr);
1107 if (res != GST_RTSP_OK) {
1108 /* no valid transport, search some more */
1109 GST_WARNING ("could not parse transport %s", transports[i]);
1113 /* we have a transport, see if it's RTP/AVP */
1114 if (tr->trans != GST_RTSP_TRANS_RTP || tr->profile != GST_RTSP_PROFILE_AVP) {
1115 GST_WARNING ("invalid transport %s", transports[i]);
1119 if (!(tr->lower_transport & supported)) {
1120 GST_WARNING ("unsupported transport %s", transports[i]);
1124 /* we have a valid transport */
1125 GST_INFO ("found valid transport %s", transports[i]);
1130 gst_rtsp_transport_init (tr);
1132 g_strfreev (transports);
1138 handle_blocksize (GstRTSPMedia * media, GstRTSPStream * stream,
1139 GstRTSPMessage * request)
1141 gchar *blocksize_str;
1142 gboolean ret = TRUE;
1144 if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_BLOCKSIZE,
1145 &blocksize_str, 0) == GST_RTSP_OK) {
1149 blocksize = g_ascii_strtoull (blocksize_str, &end, 10);
1150 if (end == blocksize_str) {
1151 GST_ERROR ("failed to parse blocksize");
1154 /* we don't want to change the mtu when this media
1155 * can be shared because it impacts other clients */
1156 if (gst_rtsp_media_is_shared (media))
1159 if (blocksize > G_MAXUINT)
1160 blocksize = G_MAXUINT;
1161 gst_rtsp_stream_set_mtu (stream, blocksize);
1168 default_configure_client_transport (GstRTSPClient * client,
1169 GstRTSPClientState * state, GstRTSPTransport * ct)
1171 GstRTSPClientPrivate *priv = client->priv;
1173 /* we have a valid transport now, set the destination of the client. */
1174 if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
1175 if (ct->destination && priv->use_client_settings) {
1176 GstRTSPAddress *addr;
1178 addr = gst_rtsp_stream_reserve_address (state->stream, ct->destination,
1179 ct->port.min, ct->port.max - ct->port.min + 1, ct->ttl);
1184 gst_rtsp_address_free (addr);
1186 GstRTSPAddress *addr;
1187 GSocketFamily family;
1189 family = priv->is_ipv6 ? G_SOCKET_FAMILY_IPV6 : G_SOCKET_FAMILY_IPV4;
1191 addr = gst_rtsp_stream_get_multicast_address (state->stream, family);
1195 g_free (ct->destination);
1196 ct->destination = g_strdup (addr->address);
1197 ct->port.min = addr->port;
1198 ct->port.max = addr->port + addr->n_ports - 1;
1199 ct->ttl = addr->ttl;
1201 gst_rtsp_address_free (addr);
1206 url = gst_rtsp_connection_get_url (priv->connection);
1207 g_free (ct->destination);
1208 ct->destination = g_strdup (url->host);
1210 if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
1211 /* check if the client selected channels for TCP */
1212 if (ct->interleaved.min == -1 || ct->interleaved.max == -1) {
1213 gst_rtsp_session_media_alloc_channels (state->sessmedia,
1223 GST_ERROR_OBJECT (client, "failed to acquire address for stream");
1228 static GstRTSPTransport *
1229 make_server_transport (GstRTSPClient * client, GstRTSPClientState * state,
1230 GstRTSPTransport * ct)
1232 GstRTSPTransport *st;
1234 GSocketFamily family;
1236 /* prepare the server transport */
1237 gst_rtsp_transport_new (&st);
1239 st->trans = ct->trans;
1240 st->profile = ct->profile;
1241 st->lower_transport = ct->lower_transport;
1243 addr = g_inet_address_new_from_string (ct->destination);
1246 GST_ERROR ("failed to get inet addr from client destination");
1247 family = G_SOCKET_FAMILY_IPV4;
1249 family = g_inet_address_get_family (addr);
1250 g_object_unref (addr);
1254 switch (st->lower_transport) {
1255 case GST_RTSP_LOWER_TRANS_UDP:
1256 st->client_port = ct->client_port;
1257 gst_rtsp_stream_get_server_port (state->stream, &st->server_port, family);
1259 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
1260 st->port = ct->port;
1261 st->destination = g_strdup (ct->destination);
1264 case GST_RTSP_LOWER_TRANS_TCP:
1265 st->interleaved = ct->interleaved;
1270 gst_rtsp_stream_get_ssrc (state->stream, &st->ssrc);
1276 handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
1278 GstRTSPClientPrivate *priv = client->priv;
1282 GstRTSPTransport *ct, *st;
1283 GstRTSPLowerTrans supported;
1284 GstRTSPStatusCode code;
1285 GstRTSPSession *session;
1286 GstRTSPStreamTransport *trans;
1287 gchar *trans_str, *pos;
1289 GstRTSPSessionMedia *sessmedia;
1290 GstRTSPMedia *media;
1291 GstRTSPStream *stream;
1292 GstRTSPState rtspstate;
1293 GstRTSPClientClass *klass;
1300 /* the uri contains the stream number we added in the SDP config, which is
1301 * always /stream=%d so we need to strip that off
1302 * parse the stream we need to configure, look for the stream in the abspath
1303 * first and then in the query. */
1304 if (uri->abspath == NULL || !(pos = strstr (uri->abspath, "/stream="))) {
1305 if (uri->query == NULL || !(pos = strstr (uri->query, "/stream=")))
1309 /* we can mofify the parsed uri in place */
1312 pos += strlen ("/stream=");
1313 if (sscanf (pos, "%u", &streamid) != 1)
1316 /* parse the transport */
1318 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_TRANSPORT,
1320 if (res != GST_RTSP_OK)
1323 gst_rtsp_transport_new (&ct);
1325 /* our supported transports */
1326 supported = GST_RTSP_LOWER_TRANS_UDP |
1327 GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
1329 /* parse and find a usable supported transport */
1330 if (!parse_transport (transport, supported, ct))
1331 goto unsupported_transports;
1333 /* we create the session after parsing stuff so that we don't make
1334 * a session for malformed requests */
1335 if (priv->session_pool == NULL)
1338 session = state->session;
1341 g_object_ref (session);
1342 /* get a handle to the configuration of the media in the session, this can
1343 * return NULL if this is a new url to manage in this session. */
1344 sessmedia = gst_rtsp_session_get_media (session, uri);
1346 /* create a session if this fails we probably reached our session limit or
1348 if (!(session = gst_rtsp_session_pool_create (priv->session_pool)))
1349 goto service_unavailable;
1351 /* make sure this client is closed when the session is closed */
1352 client_watch_session (client, session);
1354 /* signal new session */
1355 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_NEW_SESSION], 0,
1358 state->session = session;
1360 /* we need a new media configuration in this session */
1364 /* we have no media, find one and manage it */
1365 if (sessmedia == NULL) {
1366 /* get a handle to the configuration of the media in the session */
1367 if ((media = find_media (client, state))) {
1368 /* manage the media in our session now */
1369 sessmedia = gst_rtsp_session_manage_media (session, uri, media);
1373 /* if we stil have no media, error */
1374 if (sessmedia == NULL)
1377 state->sessmedia = sessmedia;
1378 state->media = media = gst_rtsp_session_media_get_media (sessmedia);
1380 /* now get the stream */
1381 stream = gst_rtsp_media_get_stream (media, streamid);
1385 state->stream = stream;
1387 /* set blocksize on this stream */
1388 if (!handle_blocksize (media, stream, state->request))
1389 goto invalid_blocksize;
1391 /* update the client transport */
1392 klass = GST_RTSP_CLIENT_GET_CLASS (client);
1393 if (!klass->configure_client_transport (client, state, ct))
1394 goto unsupported_client_transport;
1396 /* set in the session media transport */
1397 trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
1399 /* configure keepalive for this transport */
1400 gst_rtsp_stream_transport_set_keepalive (trans,
1401 (GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
1403 /* create and serialize the server transport */
1404 st = make_server_transport (client, state, ct);
1405 trans_str = gst_rtsp_transport_as_text (st);
1406 gst_rtsp_transport_free (st);
1408 /* construct the response now */
1409 code = GST_RTSP_STS_OK;
1410 gst_rtsp_message_init_response (state->response, code,
1411 gst_rtsp_status_as_text (code), state->request);
1413 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_TRANSPORT,
1417 send_message (client, session, state->response, FALSE);
1419 /* update the state */
1420 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
1421 switch (rtspstate) {
1422 case GST_RTSP_STATE_PLAYING:
1423 case GST_RTSP_STATE_RECORDING:
1424 case GST_RTSP_STATE_READY:
1425 /* no state change */
1428 gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_READY);
1431 g_object_unref (session);
1433 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST],
1441 GST_ERROR ("client %p: no uri", client);
1442 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1447 GST_ERROR ("client %p: bad request", client);
1448 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1453 GST_ERROR ("client %p: media not found", client);
1454 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1455 g_object_unref (session);
1456 gst_rtsp_transport_free (ct);
1461 GST_ERROR ("client %p: invalid blocksize", client);
1462 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1463 g_object_unref (session);
1464 gst_rtsp_transport_free (ct);
1467 unsupported_client_transport:
1469 GST_ERROR ("client %p: unsupported client transport", client);
1470 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1471 g_object_unref (session);
1472 gst_rtsp_transport_free (ct);
1477 GST_ERROR ("client %p: no transport", client);
1478 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1481 unsupported_transports:
1483 GST_ERROR ("client %p: unsupported transports", client);
1484 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1485 gst_rtsp_transport_free (ct);
1490 GST_ERROR ("client %p: no session pool configured", client);
1491 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
1492 gst_rtsp_transport_free (ct);
1495 service_unavailable:
1497 GST_ERROR ("client %p: can't create session", client);
1498 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1499 gst_rtsp_transport_free (ct);
1504 static GstSDPMessage *
1505 create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
1507 GstRTSPClientPrivate *priv = client->priv;
1512 gst_sdp_message_new (&sdp);
1514 /* some standard things first */
1515 gst_sdp_message_set_version (sdp, "0");
1522 gst_sdp_message_set_origin (sdp, "-", "1188340656180883", "1", "IN", proto,
1525 gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
1526 gst_sdp_message_set_information (sdp, "rtsp-server");
1527 gst_sdp_message_add_time (sdp, "0", "0", NULL);
1528 gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
1529 gst_sdp_message_add_attribute (sdp, "type", "broadcast");
1530 gst_sdp_message_add_attribute (sdp, "control", "*");
1532 info.is_ipv6 = priv->is_ipv6;
1533 info.server_ip = priv->server_ip;
1535 /* create an SDP for the media object */
1536 if (!gst_rtsp_sdp_from_media (sdp, &info, media))
1544 GST_ERROR ("client %p: could not create SDP", client);
1545 gst_sdp_message_free (sdp);
1550 /* for the describe we must generate an SDP */
1552 handle_describe_request (GstRTSPClient * client, GstRTSPClientState * state)
1557 gchar *str, *content_base;
1558 GstRTSPMedia *media;
1559 GstRTSPClientClass *klass;
1561 klass = GST_RTSP_CLIENT_GET_CLASS (client);
1566 /* check what kind of format is accepted, we don't really do anything with it
1567 * and always return SDP for now. */
1572 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_ACCEPT,
1574 if (res == GST_RTSP_ENOTIMPL)
1577 if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
1581 /* find the media object for the uri */
1582 if (!(media = find_media (client, state)))
1585 /* create an SDP for the media object on this client */
1586 if (!(sdp = klass->create_sdp (client, media)))
1589 g_object_unref (media);
1591 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1592 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1594 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_TYPE,
1597 /* content base for some clients that might screw up creating the setup uri */
1598 str = gst_rtsp_url_get_request_uri (state->uri);
1599 str_len = strlen (str);
1601 /* check for trailing '/' and append one */
1602 if (str[str_len - 1] != '/') {
1603 content_base = g_malloc (str_len + 2);
1604 memcpy (content_base, str, str_len);
1605 content_base[str_len] = '/';
1606 content_base[str_len + 1] = '\0';
1612 GST_INFO ("adding content-base: %s", content_base);
1614 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_BASE,
1616 g_free (content_base);
1618 /* add SDP to the response body */
1619 str = gst_sdp_message_as_text (sdp);
1620 gst_rtsp_message_take_body (state->response, (guint8 *) str, strlen (str));
1621 gst_sdp_message_free (sdp);
1623 send_message (client, state->session, state->response, FALSE);
1625 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST],
1633 GST_ERROR ("client %p: no uri", client);
1634 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1639 GST_ERROR ("client %p: no media", client);
1640 /* error reply is already sent */
1645 GST_ERROR ("client %p: can't create SDP", client);
1646 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1647 g_object_unref (media);
1653 handle_options_request (GstRTSPClient * client, GstRTSPClientState * state)
1655 GstRTSPMethod options;
1658 options = GST_RTSP_DESCRIBE |
1663 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN;
1665 str = gst_rtsp_options_as_text (options);
1667 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1668 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1670 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_PUBLIC, str);
1673 send_message (client, state->session, state->response, FALSE);
1675 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST],
1681 /* remove duplicate and trailing '/' */
1683 sanitize_uri (GstRTSPUrl * uri)
1687 gboolean have_slash, prev_slash;
1689 s = d = uri->abspath;
1690 len = strlen (uri->abspath);
1694 for (i = 0; i < len; i++) {
1695 have_slash = s[i] == '/';
1697 if (!have_slash || !prev_slash)
1699 prev_slash = have_slash;
1701 len = d - uri->abspath;
1702 /* don't remove the first slash if that's the only thing left */
1703 if (len > 1 && *(d - 1) == '/')
1709 client_session_finalized (GstRTSPClient * client, GstRTSPSession * session)
1711 GstRTSPClientPrivate *priv = client->priv;
1713 GST_INFO ("client %p: session %p finished", client, session);
1715 /* unlink all media managed in this session */
1716 client_unlink_session (client, session);
1718 /* remove the session */
1719 if (!(priv->sessions = g_list_remove (priv->sessions, session))) {
1720 GST_INFO ("client %p: all sessions finalized, close the connection",
1722 close_connection (client);
1727 handle_request (GstRTSPClient * client, GstRTSPMessage * request)
1729 GstRTSPClientPrivate *priv = client->priv;
1730 GstRTSPMethod method;
1731 const gchar *uristr;
1732 GstRTSPUrl *uri = NULL;
1733 GstRTSPVersion version;
1735 GstRTSPSession *session = NULL;
1736 GstRTSPClientState state = { NULL };
1737 GstRTSPMessage response = { 0 };
1740 state.request = request;
1741 state.response = &response;
1743 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
1744 gst_rtsp_message_dump (request);
1747 GST_INFO ("client %p: received a request", client);
1749 gst_rtsp_message_parse_request (request, &method, &uristr, &version);
1751 /* we can only handle 1.0 requests */
1752 if (version != GST_RTSP_VERSION_1_0)
1755 state.method = method;
1757 /* we always try to parse the url first */
1758 if (strcmp (uristr, "*") == 0) {
1759 /* special case where we have * as uri, keep uri = NULL */
1760 } else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK)
1763 /* get the session if there is any */
1764 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
1765 if (res == GST_RTSP_OK) {
1766 if (priv->session_pool == NULL)
1769 /* we had a session in the request, find it again */
1770 if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid)))
1771 goto session_not_found;
1773 /* we add the session to the client list of watched sessions. When a session
1774 * disappears because it times out, we will be notified. If all sessions are
1775 * gone, we will close the connection */
1776 client_watch_session (client, session);
1779 /* sanitize the uri */
1783 state.session = session;
1786 if (!gst_rtsp_auth_check (priv->auth, client, 0, &state))
1787 goto not_authorized;
1790 /* now see what is asked and dispatch to a dedicated handler */
1792 case GST_RTSP_OPTIONS:
1793 handle_options_request (client, &state);
1795 case GST_RTSP_DESCRIBE:
1796 handle_describe_request (client, &state);
1798 case GST_RTSP_SETUP:
1799 handle_setup_request (client, &state);
1802 handle_play_request (client, &state);
1804 case GST_RTSP_PAUSE:
1805 handle_pause_request (client, &state);
1807 case GST_RTSP_TEARDOWN:
1808 handle_teardown_request (client, &state);
1810 case GST_RTSP_SET_PARAMETER:
1811 handle_set_param_request (client, &state);
1813 case GST_RTSP_GET_PARAMETER:
1814 handle_get_param_request (client, &state);
1816 case GST_RTSP_ANNOUNCE:
1817 case GST_RTSP_RECORD:
1818 case GST_RTSP_REDIRECT:
1819 goto not_implemented;
1820 case GST_RTSP_INVALID:
1827 g_object_unref (session);
1829 gst_rtsp_url_free (uri);
1835 GST_ERROR ("client %p: version %d not supported", client, version);
1836 send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
1842 GST_ERROR ("client %p: bad request", client);
1843 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
1848 GST_ERROR ("client %p: no pool configured", client);
1849 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
1854 GST_ERROR ("client %p: session not found", client);
1855 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
1860 GST_ERROR ("client %p: not allowed", client);
1861 handle_unauthorized_request (client, priv->auth, &state);
1866 GST_ERROR ("client %p: method %d not implemented", client, method);
1867 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &state);
1873 handle_data (GstRTSPClient * client, GstRTSPMessage * message)
1875 GstRTSPClientPrivate *priv = client->priv;
1884 /* find the stream for this message */
1885 res = gst_rtsp_message_parse_data (message, &channel);
1886 if (res != GST_RTSP_OK)
1889 gst_rtsp_message_steal_body (message, &data, &size);
1891 buffer = gst_buffer_new_wrapped (data, size);
1894 for (walk = priv->transports; walk; walk = g_list_next (walk)) {
1895 GstRTSPStreamTransport *trans;
1896 GstRTSPStream *stream;
1897 const GstRTSPTransport *tr;
1901 tr = gst_rtsp_stream_transport_get_transport (trans);
1902 stream = gst_rtsp_stream_transport_get_stream (trans);
1904 /* check for TCP transport */
1905 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
1906 /* dispatch to the stream based on the channel number */
1907 if (tr->interleaved.min == channel) {
1908 gst_rtsp_stream_recv_rtp (stream, buffer);
1911 } else if (tr->interleaved.max == channel) {
1912 gst_rtsp_stream_recv_rtcp (stream, buffer);
1919 gst_buffer_unref (buffer);
1923 * gst_rtsp_client_set_session_pool:
1924 * @client: a #GstRTSPClient
1925 * @pool: a #GstRTSPSessionPool
1927 * Set @pool as the sessionpool for @client which it will use to find
1928 * or allocate sessions. the sessionpool is usually inherited from the server
1929 * that created the client but can be overridden later.
1932 gst_rtsp_client_set_session_pool (GstRTSPClient * client,
1933 GstRTSPSessionPool * pool)
1935 GstRTSPSessionPool *old;
1936 GstRTSPClientPrivate *priv;
1938 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
1940 priv = client->priv;
1943 g_object_ref (pool);
1945 g_mutex_lock (&priv->lock);
1946 old = priv->session_pool;
1947 priv->session_pool = pool;
1948 g_mutex_unlock (&priv->lock);
1951 g_object_unref (old);
1955 * gst_rtsp_client_get_session_pool:
1956 * @client: a #GstRTSPClient
1958 * Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
1960 * Returns: (transfer full): a #GstRTSPSessionPool, unref after usage.
1962 GstRTSPSessionPool *
1963 gst_rtsp_client_get_session_pool (GstRTSPClient * client)
1965 GstRTSPClientPrivate *priv;
1966 GstRTSPSessionPool *result;
1968 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
1970 priv = client->priv;
1972 g_mutex_lock (&priv->lock);
1973 if ((result = priv->session_pool))
1974 g_object_ref (result);
1975 g_mutex_unlock (&priv->lock);
1981 * gst_rtsp_client_set_mount_points:
1982 * @client: a #GstRTSPClient
1983 * @mounts: a #GstRTSPMountPoints
1985 * Set @mounts as the mount points for @client which it will use to map urls
1986 * to media streams. These mount points are usually inherited from the server that
1987 * created the client but can be overriden later.
1990 gst_rtsp_client_set_mount_points (GstRTSPClient * client,
1991 GstRTSPMountPoints * mounts)
1993 GstRTSPClientPrivate *priv;
1994 GstRTSPMountPoints *old;
1996 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
1998 priv = client->priv;
2001 g_object_ref (mounts);
2003 g_mutex_lock (&priv->lock);
2004 old = priv->mount_points;
2005 priv->mount_points = mounts;
2006 g_mutex_unlock (&priv->lock);
2009 g_object_unref (old);
2013 * gst_rtsp_client_get_mount_points:
2014 * @client: a #GstRTSPClient
2016 * Get the #GstRTSPMountPoints object that @client uses to manage its sessions.
2018 * Returns: (transfer full): a #GstRTSPMountPoints, unref after usage.
2020 GstRTSPMountPoints *
2021 gst_rtsp_client_get_mount_points (GstRTSPClient * client)
2023 GstRTSPClientPrivate *priv;
2024 GstRTSPMountPoints *result;
2026 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2028 priv = client->priv;
2030 g_mutex_lock (&priv->lock);
2031 if ((result = priv->mount_points))
2032 g_object_ref (result);
2033 g_mutex_unlock (&priv->lock);
2039 * gst_rtsp_client_set_use_client_settings:
2040 * @client: a #GstRTSPClient
2041 * @use_client_settings: whether to use client settings for multicast
2043 * Use client transport settings (destination and ttl) for multicast.
2044 * When @use_client_settings is %FALSE, the server settings will be
2048 gst_rtsp_client_set_use_client_settings (GstRTSPClient * client,
2049 gboolean use_client_settings)
2051 GstRTSPClientPrivate *priv;
2053 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
2055 priv = client->priv;
2057 g_mutex_lock (&priv->lock);
2058 priv->use_client_settings = use_client_settings;
2059 g_mutex_unlock (&priv->lock);
2063 * gst_rtsp_client_get_use_client_settings:
2064 * @client: a #GstRTSPClient
2066 * Check if client transport settings (destination and ttl) for multicast
2070 gst_rtsp_client_get_use_client_settings (GstRTSPClient * client)
2072 GstRTSPClientPrivate *priv;
2075 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
2077 priv = client->priv;
2079 g_mutex_lock (&priv->lock);
2080 res = priv->use_client_settings;
2081 g_mutex_unlock (&priv->lock);
2087 * gst_rtsp_client_set_auth:
2088 * @client: a #GstRTSPClient
2089 * @auth: a #GstRTSPAuth
2091 * configure @auth to be used as the authentication manager of @client.
2094 gst_rtsp_client_set_auth (GstRTSPClient * client, GstRTSPAuth * auth)
2096 GstRTSPClientPrivate *priv;
2099 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
2101 priv = client->priv;
2104 g_object_ref (auth);
2106 g_mutex_lock (&priv->lock);
2109 g_mutex_unlock (&priv->lock);
2112 g_object_unref (old);
2117 * gst_rtsp_client_get_auth:
2118 * @client: a #GstRTSPClient
2120 * Get the #GstRTSPAuth used as the authentication manager of @client.
2122 * Returns: (transfer full): the #GstRTSPAuth of @client. g_object_unref() after
2126 gst_rtsp_client_get_auth (GstRTSPClient * client)
2128 GstRTSPClientPrivate *priv;
2129 GstRTSPAuth *result;
2131 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2133 priv = client->priv;
2135 g_mutex_lock (&priv->lock);
2136 if ((result = priv->auth))
2137 g_object_ref (result);
2138 g_mutex_unlock (&priv->lock);
2144 * gst_rtsp_client_set_connection:
2145 * @client: a #GstRTSPClient
2146 * @conn: (transfer full): a #GstRTSPConnection
2148 * Set the #GstRTSPConnection of @client. This function takes ownership of
2151 * Returns: %TRUE on success.
2154 gst_rtsp_client_set_connection (GstRTSPClient * client,
2155 GstRTSPConnection * conn)
2157 GstRTSPClientPrivate *priv;
2158 GSocket *read_socket;
2159 GSocketAddress *address;
2161 GError *error = NULL;
2163 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
2164 g_return_val_if_fail (conn != NULL, FALSE);
2166 priv = client->priv;
2168 read_socket = gst_rtsp_connection_get_read_socket (conn);
2170 if (!(address = g_socket_get_local_address (read_socket, &error)))
2173 g_free (priv->server_ip);
2174 /* keep the original ip that the client connected to */
2175 if (G_IS_INET_SOCKET_ADDRESS (address)) {
2176 GInetAddress *iaddr;
2178 iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address));
2180 /* socket might be ipv6 but adress still ipv4 */
2181 priv->is_ipv6 = g_inet_address_get_family (iaddr) == G_SOCKET_FAMILY_IPV6;
2182 priv->server_ip = g_inet_address_to_string (iaddr);
2183 g_object_unref (address);
2185 priv->is_ipv6 = g_socket_get_family (read_socket) == G_SOCKET_FAMILY_IPV6;
2186 priv->server_ip = g_strdup ("unknown");
2189 GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
2190 priv->server_ip, priv->is_ipv6);
2192 url = gst_rtsp_connection_get_url (conn);
2193 GST_INFO ("added new client %p ip %s:%d", client, url->host, url->port);
2195 priv->connection = conn;
2202 GST_ERROR ("could not get local address %s", error->message);
2203 g_error_free (error);
2209 * gst_rtsp_client_get_connection:
2210 * @client: a #GstRTSPClient
2212 * Get the #GstRTSPConnection of @client.
2214 * Returns: (transfer none): the #GstRTSPConnection of @client.
2215 * The connection object returned remains valid until the client is freed.
2218 gst_rtsp_client_get_connection (GstRTSPClient * client)
2220 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2222 return client->priv->connection;
2226 * gst_rtsp_client_set_send_func:
2227 * @client: a #GstRTSPClient
2228 * @func: a #GstRTSPClientSendFunc
2229 * @user_data: user data passed to @func
2230 * @notify: called when @user_data is no longer in use
2232 * Set @func as the callback that will be called when a new message needs to be
2233 * sent to the client. @user_data is passed to @func and @notify is called when
2234 * @user_data is no longer in use.
2237 gst_rtsp_client_set_send_func (GstRTSPClient * client,
2238 GstRTSPClientSendFunc func, gpointer user_data, GDestroyNotify notify)
2240 GstRTSPClientPrivate *priv;
2241 GDestroyNotify old_notify;
2244 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
2246 priv = client->priv;
2248 g_mutex_lock (&priv->send_lock);
2249 priv->send_func = func;
2250 old_notify = priv->send_notify;
2251 old_data = priv->send_data;
2252 priv->send_notify = notify;
2253 priv->send_data = user_data;
2254 g_mutex_unlock (&priv->send_lock);
2257 old_notify (old_data);
2261 * gst_rtsp_client_handle_message:
2262 * @client: a #GstRTSPClient
2263 * @message: an #GstRTSPMessage
2265 * Let the client handle @message.
2267 * Returns: a #GstRTSPResult.
2270 gst_rtsp_client_handle_message (GstRTSPClient * client,
2271 GstRTSPMessage * message)
2273 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
2274 g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
2276 switch (message->type) {
2277 case GST_RTSP_MESSAGE_REQUEST:
2278 handle_request (client, message);
2280 case GST_RTSP_MESSAGE_RESPONSE:
2282 case GST_RTSP_MESSAGE_DATA:
2283 handle_data (client, message);
2292 * gst_rtsp_client_send_request:
2293 * @client: a #GstRTSPClient
2294 * @session: a #GstRTSPSession to send the request to or %NULL
2295 * @request: The request #GstRTSPMessage to send
2297 * Send a request message to the client.
2300 gst_rtsp_client_send_request (GstRTSPClient * client, GstRTSPSession * session,
2301 GstRTSPMessage * request)
2303 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
2304 g_return_val_if_fail (request != NULL, GST_RTSP_EINVAL);
2305 g_return_val_if_fail (request->type == GST_RTSP_MESSAGE_REQUEST,
2308 send_message (client, session, request, FALSE);
2313 static GstRTSPResult
2314 do_send_message (GstRTSPClient * client, GstRTSPMessage * message,
2315 gboolean close, gpointer user_data)
2317 GstRTSPClientPrivate *priv = client->priv;
2319 /* send the response and store the seq number so we can wait until it's
2320 * written to the client to close the connection */
2321 return gst_rtsp_watch_send_message (priv->watch, message, close ?
2322 &priv->close_seq : NULL);
2325 static GstRTSPResult
2326 message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
2329 return gst_rtsp_client_handle_message (GST_RTSP_CLIENT (user_data), message);
2332 static GstRTSPResult
2333 message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
2335 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2336 GstRTSPClientPrivate *priv = client->priv;
2338 if (priv->close_seq && priv->close_seq == cseq) {
2339 priv->close_seq = 0;
2340 close_connection (client);
2346 static GstRTSPResult
2347 closed (GstRTSPWatch * watch, gpointer user_data)
2349 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2350 GstRTSPClientPrivate *priv = client->priv;
2351 const gchar *tunnelid;
2353 GST_INFO ("client %p: connection closed", client);
2355 if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
2356 g_mutex_lock (&tunnels_lock);
2357 /* remove from tunnelids */
2358 g_hash_table_remove (tunnels, tunnelid);
2359 g_mutex_unlock (&tunnels_lock);
2362 gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
2367 static GstRTSPResult
2368 error (GstRTSPWatch * watch, GstRTSPResult result, gpointer user_data)
2370 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2373 str = gst_rtsp_strresult (result);
2374 GST_INFO ("client %p: received an error %s", client, str);
2380 static GstRTSPResult
2381 error_full (GstRTSPWatch * watch, GstRTSPResult result,
2382 GstRTSPMessage * message, guint id, gpointer user_data)
2384 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2387 str = gst_rtsp_strresult (result);
2389 ("client %p: error when handling message %p with id %d: %s",
2390 client, message, id, str);
2397 remember_tunnel (GstRTSPClient * client)
2399 GstRTSPClientPrivate *priv = client->priv;
2400 const gchar *tunnelid;
2402 /* store client in the pending tunnels */
2403 tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
2404 if (tunnelid == NULL)
2407 GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
2409 /* we can't have two clients connecting with the same tunnelid */
2410 g_mutex_lock (&tunnels_lock);
2411 if (g_hash_table_lookup (tunnels, tunnelid))
2412 goto tunnel_existed;
2414 g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
2415 g_mutex_unlock (&tunnels_lock);
2422 GST_ERROR ("client %p: no tunnelid provided", client);
2427 g_mutex_unlock (&tunnels_lock);
2428 GST_ERROR ("client %p: tunnel session %s already existed", client,
2434 static GstRTSPStatusCode
2435 tunnel_start (GstRTSPWatch * watch, gpointer user_data)
2437 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2438 GstRTSPClientPrivate *priv = client->priv;
2440 GST_INFO ("client %p: tunnel start (connection %p)", client,
2443 if (!remember_tunnel (client))
2446 return GST_RTSP_STS_OK;
2451 GST_ERROR ("client %p: error starting tunnel", client);
2452 return GST_RTSP_STS_SERVICE_UNAVAILABLE;
2456 static GstRTSPResult
2457 tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
2459 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2460 GstRTSPClientPrivate *priv = client->priv;
2462 GST_WARNING ("client %p: tunnel lost (connection %p)", client,
2465 /* ignore error, it'll only be a problem when the client does a POST again */
2466 remember_tunnel (client);
2471 static GstRTSPResult
2472 tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
2474 const gchar *tunnelid;
2475 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2476 GstRTSPClientPrivate *priv = client->priv;
2477 GstRTSPClient *oclient;
2478 GstRTSPClientPrivate *opriv;
2480 GST_INFO ("client %p: tunnel complete", client);
2482 /* find previous tunnel */
2483 tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
2484 if (tunnelid == NULL)
2487 g_mutex_lock (&tunnels_lock);
2488 if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
2491 /* remove the old client from the table. ref before because removing it will
2492 * remove the ref to it. */
2493 g_object_ref (oclient);
2494 g_hash_table_remove (tunnels, tunnelid);
2496 opriv = oclient->priv;
2498 if (opriv->watch == NULL)
2500 g_mutex_unlock (&tunnels_lock);
2502 GST_INFO ("client %p: found tunnel %p (old %p, new %p)", client, oclient,
2503 opriv->connection, priv->connection);
2505 /* merge the tunnels into the first client */
2506 gst_rtsp_connection_do_tunnel (opriv->connection, priv->connection);
2507 gst_rtsp_watch_reset (opriv->watch);
2508 g_object_unref (oclient);
2515 GST_ERROR ("client %p: no tunnelid provided", client);
2516 return GST_RTSP_ERROR;
2520 g_mutex_unlock (&tunnels_lock);
2521 GST_ERROR ("client %p: tunnel session %s not found", client, tunnelid);
2522 return GST_RTSP_ERROR;
2526 g_mutex_unlock (&tunnels_lock);
2527 GST_ERROR ("client %p: tunnel session %s was closed", client, tunnelid);
2528 g_object_unref (oclient);
2529 return GST_RTSP_ERROR;
2533 static GstRTSPWatchFuncs watch_funcs = {
2545 client_watch_notify (GstRTSPClient * client)
2547 GstRTSPClientPrivate *priv = client->priv;
2549 GST_INFO ("client %p: watch destroyed", client);
2551 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
2552 g_object_unref (client);
2556 * gst_rtsp_client_attach:
2557 * @client: a #GstRTSPClient
2558 * @context: (allow-none): a #GMainContext
2560 * Attaches @client to @context. When the mainloop for @context is run, the
2561 * client will be dispatched. When @context is NULL, the default context will be
2564 * This function should be called when the client properties and urls are fully
2565 * configured and the client is ready to start.
2567 * Returns: the ID (greater than 0) for the source within the GMainContext.
2570 gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
2572 GstRTSPClientPrivate *priv;
2575 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), 0);
2576 priv = client->priv;
2577 g_return_val_if_fail (priv->watch == NULL, 0);
2579 /* create watch for the connection and attach */
2580 priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs,
2581 g_object_ref (client), (GDestroyNotify) client_watch_notify);
2582 gst_rtsp_client_set_send_func (client, do_send_message, priv->watch,
2583 (GDestroyNotify) gst_rtsp_watch_unref);
2585 /* FIXME make this configurable. We don't want to do this yet because it will
2586 * be superceeded by a cache object later */
2587 gst_rtsp_watch_set_send_backlog (priv->watch, 0, 100);
2589 GST_INFO ("attaching to context %p", context);
2590 res = gst_rtsp_watch_attach (priv->watch, context);
2596 * gst_rtsp_client_session_filter:
2597 * @client: a #GstRTSPclient
2598 * @func: (scope call): a callback
2599 * @user_data: user data passed to @func
2601 * Call @func for each session managed by @client. The result value of @func
2602 * determines what happens to the session. @func will be called with @client
2603 * locked so no further actions on @client can be performed from @func.
2605 * If @func returns #GST_RTSP_FILTER_REMOVE, the session will be removed from
2608 * If @func returns #GST_RTSP_FILTER_KEEP, the session will remain in @client.
2610 * If @func returns #GST_RTSP_FILTER_REF, the session will remain in @client but
2611 * will also be added with an additional ref to the result #GList of this
2614 * Returns: (element-type GstRTSPSession) (transfer full): a #GList with all
2615 * sessions for which @func returned #GST_RTSP_FILTER_REF. After usage, each
2616 * element in the #GList should be unreffed before the list is freed.
2619 gst_rtsp_client_session_filter (GstRTSPClient * client,
2620 GstRTSPClientSessionFilterFunc func, gpointer user_data)
2622 GstRTSPClientPrivate *priv;
2623 GList *result, *walk, *next;
2625 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2626 g_return_val_if_fail (func != NULL, NULL);
2628 priv = client->priv;
2632 g_mutex_lock (&priv->lock);
2633 for (walk = priv->sessions; walk; walk = next) {
2634 GstRTSPSession *sess = walk->data;
2636 next = g_list_next (walk);
2638 switch (func (client, sess, user_data)) {
2639 case GST_RTSP_FILTER_REMOVE:
2640 /* stop watching the session and pretent it went away */
2641 client_cleanup_session (client, sess);
2643 case GST_RTSP_FILTER_REF:
2644 result = g_list_prepend (result, g_object_ref (sess));
2646 case GST_RTSP_FILTER_KEEP:
2651 g_mutex_unlock (&priv->lock);