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 * sessmedia);
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 * sessmedia,
236 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
238 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_NULL);
239 unlink_session_transports (client, sess, sessmedia);
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 * sessmedia)
657 gst_rtsp_media_n_streams (gst_rtsp_session_media_get_media (sessmedia));
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 (sessmedia, 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 *sessmedia;
700 GstRTSPStatusCode code;
705 session = state->session;
710 /* get a handle to the configuration of the media in the session */
711 sessmedia = gst_rtsp_session_get_media (session, state->uri);
715 state->sessmedia = sessmedia;
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, sessmedia);
724 /* remove the session from the watched sessions */
725 client_unwatch_session (client, session);
727 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_NULL);
729 /* unmanage the media in the session, returns false if all media session
731 if (!gst_rtsp_session_release_media (session, sessmedia)) {
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 *sessmedia;
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 sessmedia = gst_rtsp_session_get_media (session, state->uri);
878 state->sessmedia = sessmedia;
880 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
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, sessmedia);
889 /* then pause sending */
890 gst_rtsp_session_media_set_state (sessmedia, 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 (sessmedia, 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 *sessmedia;
941 GstRTSPStatusCode code;
943 guint n_streams, i, infocount;
945 GstRTSPTimeRange *range;
947 GstRTSPState rtspstate;
948 GstRTSPRangeUnit unit = GST_RTSP_RANGE_NPT;
950 if (!(session = state->session))
956 /* get a handle to the configuration of the media in the session */
957 sessmedia = gst_rtsp_session_get_media (session, state->uri);
961 state->sessmedia = sessmedia;
962 state->media = media = gst_rtsp_session_media_get_media (sessmedia);
964 /* the session state must be playing or ready */
965 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
966 if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
969 /* parse the range header if we have one */
971 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_RANGE, &str, 0);
972 if (res == GST_RTSP_OK) {
973 if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
974 /* we have a range, seek to the position */
976 gst_rtsp_media_seek (media, range);
977 gst_rtsp_range_free (range);
981 /* grab RTPInfo from the payloaders now */
982 rtpinfo = g_string_new ("");
984 n_streams = gst_rtsp_media_n_streams (media);
985 for (i = 0, infocount = 0; i < n_streams; i++) {
986 GstRTSPStreamTransport *trans;
987 GstRTSPStream *stream;
988 const GstRTSPTransport *tr;
992 /* get the transport, if there is no transport configured, skip this stream */
993 trans = gst_rtsp_session_media_get_transport (sessmedia, i);
995 GST_INFO ("stream %d is not configured", i);
998 tr = gst_rtsp_stream_transport_get_transport (trans);
1000 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
1001 /* for TCP, link the stream to the TCP connection of the client */
1002 link_transport (client, session, trans);
1005 stream = gst_rtsp_stream_transport_get_stream (trans);
1006 if (gst_rtsp_stream_get_rtpinfo (stream, &rtptime, &seq)) {
1008 g_string_append (rtpinfo, ", ");
1010 uristr = gst_rtsp_url_get_request_uri (state->uri);
1011 g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
1012 uristr, i, seq, rtptime);
1017 GST_WARNING ("RTP-Info cannot be determined for stream %d", i);
1021 /* construct the response now */
1022 code = GST_RTSP_STS_OK;
1023 gst_rtsp_message_init_response (state->response, code,
1024 gst_rtsp_status_as_text (code), state->request);
1026 /* add the RTP-Info header */
1027 if (infocount > 0) {
1028 str = g_string_free (rtpinfo, FALSE);
1029 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RTP_INFO, str);
1031 g_string_free (rtpinfo, TRUE);
1035 str = gst_rtsp_media_get_range_string (media, TRUE, unit);
1036 gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RANGE, str);
1038 send_message (client, session, state->response, FALSE);
1040 /* start playing after sending the request */
1041 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_PLAYING);
1043 gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_PLAYING);
1045 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST],
1053 GST_ERROR ("client %p: no session", client);
1054 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
1059 GST_ERROR ("client %p: no uri supplied", client);
1060 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1065 GST_ERROR ("client %p: media not found", client);
1066 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1071 GST_ERROR ("client %p: not PLAYING or READY", client);
1072 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
1079 do_keepalive (GstRTSPSession * session)
1081 GST_INFO ("keep session %p alive", session);
1082 gst_rtsp_session_touch (session);
1085 /* parse @transport and return a valid transport in @tr. only transports
1086 * from @supported are returned. Returns FALSE if no valid transport
1089 parse_transport (const char *transport, GstRTSPLowerTrans supported,
1090 GstRTSPTransport * tr)
1097 gst_rtsp_transport_init (tr);
1099 GST_DEBUG ("parsing transports %s", transport);
1101 transports = g_strsplit (transport, ",", 0);
1103 /* loop through the transports, try to parse */
1104 for (i = 0; transports[i]; i++) {
1105 res = gst_rtsp_transport_parse (transports[i], tr);
1106 if (res != GST_RTSP_OK) {
1107 /* no valid transport, search some more */
1108 GST_WARNING ("could not parse transport %s", transports[i]);
1112 /* we have a transport, see if it's RTP/AVP */
1113 if (tr->trans != GST_RTSP_TRANS_RTP || tr->profile != GST_RTSP_PROFILE_AVP) {
1114 GST_WARNING ("invalid transport %s", transports[i]);
1118 if (!(tr->lower_transport & supported)) {
1119 GST_WARNING ("unsupported transport %s", transports[i]);
1123 /* we have a valid transport */
1124 GST_INFO ("found valid transport %s", transports[i]);
1129 gst_rtsp_transport_init (tr);
1131 g_strfreev (transports);
1137 handle_blocksize (GstRTSPMedia * media, GstRTSPStream * stream,
1138 GstRTSPMessage * request)
1140 gchar *blocksize_str;
1141 gboolean ret = TRUE;
1143 if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_BLOCKSIZE,
1144 &blocksize_str, 0) == GST_RTSP_OK) {
1148 blocksize = g_ascii_strtoull (blocksize_str, &end, 10);
1149 if (end == blocksize_str) {
1150 GST_ERROR ("failed to parse blocksize");
1153 /* we don't want to change the mtu when this media
1154 * can be shared because it impacts other clients */
1155 if (gst_rtsp_media_is_shared (media))
1158 if (blocksize > G_MAXUINT)
1159 blocksize = G_MAXUINT;
1160 gst_rtsp_stream_set_mtu (stream, blocksize);
1167 default_configure_client_transport (GstRTSPClient * client,
1168 GstRTSPClientState * state, GstRTSPTransport * ct)
1170 GstRTSPClientPrivate *priv = client->priv;
1172 /* we have a valid transport now, set the destination of the client. */
1173 if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
1174 if (ct->destination && priv->use_client_settings) {
1175 GstRTSPAddress *addr;
1177 addr = gst_rtsp_stream_reserve_address (state->stream, ct->destination,
1178 ct->port.min, ct->port.max - ct->port.min + 1, ct->ttl);
1183 gst_rtsp_address_free (addr);
1185 GstRTSPAddress *addr;
1186 GSocketFamily family;
1188 family = priv->is_ipv6 ? G_SOCKET_FAMILY_IPV6 : G_SOCKET_FAMILY_IPV4;
1190 addr = gst_rtsp_stream_get_multicast_address (state->stream, family);
1194 g_free (ct->destination);
1195 ct->destination = g_strdup (addr->address);
1196 ct->port.min = addr->port;
1197 ct->port.max = addr->port + addr->n_ports - 1;
1198 ct->ttl = addr->ttl;
1200 gst_rtsp_address_free (addr);
1205 url = gst_rtsp_connection_get_url (priv->connection);
1206 g_free (ct->destination);
1207 ct->destination = g_strdup (url->host);
1209 if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
1210 /* check if the client selected channels for TCP */
1211 if (ct->interleaved.min == -1 || ct->interleaved.max == -1) {
1212 gst_rtsp_session_media_alloc_channels (state->sessmedia,
1222 GST_ERROR_OBJECT (client, "failed to acquire address for stream");
1227 static GstRTSPTransport *
1228 make_server_transport (GstRTSPClient * client, GstRTSPClientState * state,
1229 GstRTSPTransport * ct)
1231 GstRTSPTransport *st;
1233 GSocketFamily family;
1235 /* prepare the server transport */
1236 gst_rtsp_transport_new (&st);
1238 st->trans = ct->trans;
1239 st->profile = ct->profile;
1240 st->lower_transport = ct->lower_transport;
1242 addr = g_inet_address_new_from_string (ct->destination);
1245 GST_ERROR ("failed to get inet addr from client destination");
1246 family = G_SOCKET_FAMILY_IPV4;
1248 family = g_inet_address_get_family (addr);
1249 g_object_unref (addr);
1253 switch (st->lower_transport) {
1254 case GST_RTSP_LOWER_TRANS_UDP:
1255 st->client_port = ct->client_port;
1256 gst_rtsp_stream_get_server_port (state->stream, &st->server_port, family);
1258 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
1259 st->port = ct->port;
1260 st->destination = g_strdup (ct->destination);
1263 case GST_RTSP_LOWER_TRANS_TCP:
1264 st->interleaved = ct->interleaved;
1269 gst_rtsp_stream_get_ssrc (state->stream, &st->ssrc);
1275 handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
1277 GstRTSPClientPrivate *priv = client->priv;
1281 GstRTSPTransport *ct, *st;
1282 GstRTSPLowerTrans supported;
1283 GstRTSPStatusCode code;
1284 GstRTSPSession *session;
1285 GstRTSPStreamTransport *trans;
1286 gchar *trans_str, *pos;
1288 GstRTSPSessionMedia *sessmedia;
1289 GstRTSPMedia *media;
1290 GstRTSPStream *stream;
1291 GstRTSPState rtspstate;
1292 GstRTSPClientClass *klass;
1299 /* the uri contains the stream number we added in the SDP config, which is
1300 * always /stream=%d so we need to strip that off
1301 * parse the stream we need to configure, look for the stream in the abspath
1302 * first and then in the query. */
1303 if (uri->abspath == NULL || !(pos = strstr (uri->abspath, "/stream="))) {
1304 if (uri->query == NULL || !(pos = strstr (uri->query, "/stream=")))
1308 /* we can mofify the parsed uri in place */
1311 pos += strlen ("/stream=");
1312 if (sscanf (pos, "%u", &streamid) != 1)
1315 /* parse the transport */
1317 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_TRANSPORT,
1319 if (res != GST_RTSP_OK)
1322 gst_rtsp_transport_new (&ct);
1324 /* our supported transports */
1325 supported = GST_RTSP_LOWER_TRANS_UDP |
1326 GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
1328 /* parse and find a usable supported transport */
1329 if (!parse_transport (transport, supported, ct))
1330 goto unsupported_transports;
1332 /* we create the session after parsing stuff so that we don't make
1333 * a session for malformed requests */
1334 if (priv->session_pool == NULL)
1337 session = state->session;
1340 g_object_ref (session);
1341 /* get a handle to the configuration of the media in the session, this can
1342 * return NULL if this is a new url to manage in this session. */
1343 sessmedia = gst_rtsp_session_get_media (session, uri);
1345 /* create a session if this fails we probably reached our session limit or
1347 if (!(session = gst_rtsp_session_pool_create (priv->session_pool)))
1348 goto service_unavailable;
1350 /* make sure this client is closed when the session is closed */
1351 client_watch_session (client, session);
1353 /* signal new session */
1354 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_NEW_SESSION], 0,
1357 state->session = session;
1359 /* we need a new media configuration in this session */
1363 /* we have no media, find one and manage it */
1364 if (sessmedia == NULL) {
1365 /* get a handle to the configuration of the media in the session */
1366 if ((media = find_media (client, state))) {
1367 /* manage the media in our session now */
1368 sessmedia = gst_rtsp_session_manage_media (session, uri, media);
1372 /* if we stil have no media, error */
1373 if (sessmedia == NULL)
1376 state->sessmedia = sessmedia;
1377 state->media = media = gst_rtsp_session_media_get_media (sessmedia);
1379 /* now get the stream */
1380 stream = gst_rtsp_media_get_stream (media, streamid);
1384 state->stream = stream;
1386 /* set blocksize on this stream */
1387 if (!handle_blocksize (media, stream, state->request))
1388 goto invalid_blocksize;
1390 /* update the client transport */
1391 klass = GST_RTSP_CLIENT_GET_CLASS (client);
1392 if (!klass->configure_client_transport (client, state, ct))
1393 goto unsupported_client_transport;
1395 /* set in the session media transport */
1396 trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
1398 /* configure keepalive for this transport */
1399 gst_rtsp_stream_transport_set_keepalive (trans,
1400 (GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
1402 /* create and serialize the server transport */
1403 st = make_server_transport (client, state, ct);
1404 trans_str = gst_rtsp_transport_as_text (st);
1405 gst_rtsp_transport_free (st);
1407 /* construct the response now */
1408 code = GST_RTSP_STS_OK;
1409 gst_rtsp_message_init_response (state->response, code,
1410 gst_rtsp_status_as_text (code), state->request);
1412 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_TRANSPORT,
1416 send_message (client, session, state->response, FALSE);
1418 /* update the state */
1419 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
1420 switch (rtspstate) {
1421 case GST_RTSP_STATE_PLAYING:
1422 case GST_RTSP_STATE_RECORDING:
1423 case GST_RTSP_STATE_READY:
1424 /* no state change */
1427 gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_READY);
1430 g_object_unref (session);
1432 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST],
1440 GST_ERROR ("client %p: no uri", client);
1441 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1446 GST_ERROR ("client %p: bad request", client);
1447 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1452 GST_ERROR ("client %p: media not found", client);
1453 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
1454 g_object_unref (session);
1455 gst_rtsp_transport_free (ct);
1460 GST_ERROR ("client %p: invalid blocksize", client);
1461 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1462 g_object_unref (session);
1463 gst_rtsp_transport_free (ct);
1466 unsupported_client_transport:
1468 GST_ERROR ("client %p: unsupported client transport", client);
1469 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1470 g_object_unref (session);
1471 gst_rtsp_transport_free (ct);
1476 GST_ERROR ("client %p: no transport", client);
1477 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1480 unsupported_transports:
1482 GST_ERROR ("client %p: unsupported transports", client);
1483 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
1484 gst_rtsp_transport_free (ct);
1489 GST_ERROR ("client %p: no session pool configured", client);
1490 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
1491 gst_rtsp_transport_free (ct);
1494 service_unavailable:
1496 GST_ERROR ("client %p: can't create session", client);
1497 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1498 gst_rtsp_transport_free (ct);
1503 static GstSDPMessage *
1504 create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
1506 GstRTSPClientPrivate *priv = client->priv;
1511 gst_sdp_message_new (&sdp);
1513 /* some standard things first */
1514 gst_sdp_message_set_version (sdp, "0");
1521 gst_sdp_message_set_origin (sdp, "-", "1188340656180883", "1", "IN", proto,
1524 gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
1525 gst_sdp_message_set_information (sdp, "rtsp-server");
1526 gst_sdp_message_add_time (sdp, "0", "0", NULL);
1527 gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
1528 gst_sdp_message_add_attribute (sdp, "type", "broadcast");
1529 gst_sdp_message_add_attribute (sdp, "control", "*");
1531 info.is_ipv6 = priv->is_ipv6;
1532 info.server_ip = priv->server_ip;
1534 /* create an SDP for the media object */
1535 if (!gst_rtsp_sdp_from_media (sdp, &info, media))
1543 GST_ERROR ("client %p: could not create SDP", client);
1544 gst_sdp_message_free (sdp);
1549 /* for the describe we must generate an SDP */
1551 handle_describe_request (GstRTSPClient * client, GstRTSPClientState * state)
1556 gchar *str, *content_base;
1557 GstRTSPMedia *media;
1558 GstRTSPClientClass *klass;
1560 klass = GST_RTSP_CLIENT_GET_CLASS (client);
1565 /* check what kind of format is accepted, we don't really do anything with it
1566 * and always return SDP for now. */
1571 gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_ACCEPT,
1573 if (res == GST_RTSP_ENOTIMPL)
1576 if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
1580 /* find the media object for the uri */
1581 if (!(media = find_media (client, state)))
1584 /* create an SDP for the media object on this client */
1585 if (!(sdp = klass->create_sdp (client, media)))
1588 g_object_unref (media);
1590 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1591 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1593 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_TYPE,
1596 /* content base for some clients that might screw up creating the setup uri */
1597 str = gst_rtsp_url_get_request_uri (state->uri);
1598 str_len = strlen (str);
1600 /* check for trailing '/' and append one */
1601 if (str[str_len - 1] != '/') {
1602 content_base = g_malloc (str_len + 2);
1603 memcpy (content_base, str, str_len);
1604 content_base[str_len] = '/';
1605 content_base[str_len + 1] = '\0';
1611 GST_INFO ("adding content-base: %s", content_base);
1613 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_BASE,
1615 g_free (content_base);
1617 /* add SDP to the response body */
1618 str = gst_sdp_message_as_text (sdp);
1619 gst_rtsp_message_take_body (state->response, (guint8 *) str, strlen (str));
1620 gst_sdp_message_free (sdp);
1622 send_message (client, state->session, state->response, FALSE);
1624 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST],
1632 GST_ERROR ("client %p: no uri", client);
1633 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
1638 GST_ERROR ("client %p: no media", client);
1639 /* error reply is already sent */
1644 GST_ERROR ("client %p: can't create SDP", client);
1645 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
1646 g_object_unref (media);
1652 handle_options_request (GstRTSPClient * client, GstRTSPClientState * state)
1654 GstRTSPMethod options;
1657 options = GST_RTSP_DESCRIBE |
1662 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN;
1664 str = gst_rtsp_options_as_text (options);
1666 gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
1667 gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
1669 gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_PUBLIC, str);
1672 send_message (client, state->session, state->response, FALSE);
1674 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST],
1680 /* remove duplicate and trailing '/' */
1682 sanitize_uri (GstRTSPUrl * uri)
1686 gboolean have_slash, prev_slash;
1688 s = d = uri->abspath;
1689 len = strlen (uri->abspath);
1693 for (i = 0; i < len; i++) {
1694 have_slash = s[i] == '/';
1696 if (!have_slash || !prev_slash)
1698 prev_slash = have_slash;
1700 len = d - uri->abspath;
1701 /* don't remove the first slash if that's the only thing left */
1702 if (len > 1 && *(d - 1) == '/')
1708 client_session_finalized (GstRTSPClient * client, GstRTSPSession * session)
1710 GstRTSPClientPrivate *priv = client->priv;
1712 GST_INFO ("client %p: session %p finished", client, session);
1714 /* unlink all media managed in this session */
1715 client_unlink_session (client, session);
1717 /* remove the session */
1718 if (!(priv->sessions = g_list_remove (priv->sessions, session))) {
1719 GST_INFO ("client %p: all sessions finalized, close the connection",
1721 close_connection (client);
1726 handle_request (GstRTSPClient * client, GstRTSPMessage * request)
1728 GstRTSPClientPrivate *priv = client->priv;
1729 GstRTSPMethod method;
1730 const gchar *uristr;
1731 GstRTSPUrl *uri = NULL;
1732 GstRTSPVersion version;
1734 GstRTSPSession *session = NULL;
1735 GstRTSPClientState state = { NULL };
1736 GstRTSPMessage response = { 0 };
1739 state.request = request;
1740 state.response = &response;
1742 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
1743 gst_rtsp_message_dump (request);
1746 GST_INFO ("client %p: received a request", client);
1748 gst_rtsp_message_parse_request (request, &method, &uristr, &version);
1750 /* we can only handle 1.0 requests */
1751 if (version != GST_RTSP_VERSION_1_0)
1754 state.method = method;
1756 /* we always try to parse the url first */
1757 if (strcmp (uristr, "*") == 0) {
1758 /* special case where we have * as uri, keep uri = NULL */
1759 } else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK)
1762 /* get the session if there is any */
1763 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
1764 if (res == GST_RTSP_OK) {
1765 if (priv->session_pool == NULL)
1768 /* we had a session in the request, find it again */
1769 if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid)))
1770 goto session_not_found;
1772 /* we add the session to the client list of watched sessions. When a session
1773 * disappears because it times out, we will be notified. If all sessions are
1774 * gone, we will close the connection */
1775 client_watch_session (client, session);
1778 /* sanitize the uri */
1782 state.session = session;
1785 if (!gst_rtsp_auth_check (priv->auth, client, 0, &state))
1786 goto not_authorized;
1789 /* now see what is asked and dispatch to a dedicated handler */
1791 case GST_RTSP_OPTIONS:
1792 handle_options_request (client, &state);
1794 case GST_RTSP_DESCRIBE:
1795 handle_describe_request (client, &state);
1797 case GST_RTSP_SETUP:
1798 handle_setup_request (client, &state);
1801 handle_play_request (client, &state);
1803 case GST_RTSP_PAUSE:
1804 handle_pause_request (client, &state);
1806 case GST_RTSP_TEARDOWN:
1807 handle_teardown_request (client, &state);
1809 case GST_RTSP_SET_PARAMETER:
1810 handle_set_param_request (client, &state);
1812 case GST_RTSP_GET_PARAMETER:
1813 handle_get_param_request (client, &state);
1815 case GST_RTSP_ANNOUNCE:
1816 case GST_RTSP_RECORD:
1817 case GST_RTSP_REDIRECT:
1818 goto not_implemented;
1819 case GST_RTSP_INVALID:
1826 g_object_unref (session);
1828 gst_rtsp_url_free (uri);
1834 GST_ERROR ("client %p: version %d not supported", client, version);
1835 send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
1841 GST_ERROR ("client %p: bad request", client);
1842 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
1847 GST_ERROR ("client %p: no pool configured", client);
1848 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
1853 GST_ERROR ("client %p: session not found", client);
1854 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
1859 GST_ERROR ("client %p: not allowed", client);
1860 handle_unauthorized_request (client, priv->auth, &state);
1865 GST_ERROR ("client %p: method %d not implemented", client, method);
1866 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &state);
1872 handle_data (GstRTSPClient * client, GstRTSPMessage * message)
1874 GstRTSPClientPrivate *priv = client->priv;
1883 /* find the stream for this message */
1884 res = gst_rtsp_message_parse_data (message, &channel);
1885 if (res != GST_RTSP_OK)
1888 gst_rtsp_message_steal_body (message, &data, &size);
1890 buffer = gst_buffer_new_wrapped (data, size);
1893 for (walk = priv->transports; walk; walk = g_list_next (walk)) {
1894 GstRTSPStreamTransport *trans;
1895 GstRTSPStream *stream;
1896 const GstRTSPTransport *tr;
1900 tr = gst_rtsp_stream_transport_get_transport (trans);
1901 stream = gst_rtsp_stream_transport_get_stream (trans);
1903 /* check for TCP transport */
1904 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
1905 /* dispatch to the stream based on the channel number */
1906 if (tr->interleaved.min == channel) {
1907 gst_rtsp_stream_recv_rtp (stream, buffer);
1910 } else if (tr->interleaved.max == channel) {
1911 gst_rtsp_stream_recv_rtcp (stream, buffer);
1918 gst_buffer_unref (buffer);
1922 * gst_rtsp_client_set_session_pool:
1923 * @client: a #GstRTSPClient
1924 * @pool: a #GstRTSPSessionPool
1926 * Set @pool as the sessionpool for @client which it will use to find
1927 * or allocate sessions. the sessionpool is usually inherited from the server
1928 * that created the client but can be overridden later.
1931 gst_rtsp_client_set_session_pool (GstRTSPClient * client,
1932 GstRTSPSessionPool * pool)
1934 GstRTSPSessionPool *old;
1935 GstRTSPClientPrivate *priv;
1937 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
1939 priv = client->priv;
1942 g_object_ref (pool);
1944 g_mutex_lock (&priv->lock);
1945 old = priv->session_pool;
1946 priv->session_pool = pool;
1947 g_mutex_unlock (&priv->lock);
1950 g_object_unref (old);
1954 * gst_rtsp_client_get_session_pool:
1955 * @client: a #GstRTSPClient
1957 * Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
1959 * Returns: (transfer full): a #GstRTSPSessionPool, unref after usage.
1961 GstRTSPSessionPool *
1962 gst_rtsp_client_get_session_pool (GstRTSPClient * client)
1964 GstRTSPClientPrivate *priv;
1965 GstRTSPSessionPool *result;
1967 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
1969 priv = client->priv;
1971 g_mutex_lock (&priv->lock);
1972 if ((result = priv->session_pool))
1973 g_object_ref (result);
1974 g_mutex_unlock (&priv->lock);
1980 * gst_rtsp_client_set_mount_points:
1981 * @client: a #GstRTSPClient
1982 * @mounts: a #GstRTSPMountPoints
1984 * Set @mounts as the mount points for @client which it will use to map urls
1985 * to media streams. These mount points are usually inherited from the server that
1986 * created the client but can be overriden later.
1989 gst_rtsp_client_set_mount_points (GstRTSPClient * client,
1990 GstRTSPMountPoints * mounts)
1992 GstRTSPClientPrivate *priv;
1993 GstRTSPMountPoints *old;
1995 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
1997 priv = client->priv;
2000 g_object_ref (mounts);
2002 g_mutex_lock (&priv->lock);
2003 old = priv->mount_points;
2004 priv->mount_points = mounts;
2005 g_mutex_unlock (&priv->lock);
2008 g_object_unref (old);
2012 * gst_rtsp_client_get_mount_points:
2013 * @client: a #GstRTSPClient
2015 * Get the #GstRTSPMountPoints object that @client uses to manage its sessions.
2017 * Returns: (transfer full): a #GstRTSPMountPoints, unref after usage.
2019 GstRTSPMountPoints *
2020 gst_rtsp_client_get_mount_points (GstRTSPClient * client)
2022 GstRTSPClientPrivate *priv;
2023 GstRTSPMountPoints *result;
2025 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2027 priv = client->priv;
2029 g_mutex_lock (&priv->lock);
2030 if ((result = priv->mount_points))
2031 g_object_ref (result);
2032 g_mutex_unlock (&priv->lock);
2038 * gst_rtsp_client_set_use_client_settings:
2039 * @client: a #GstRTSPClient
2040 * @use_client_settings: whether to use client settings for multicast
2042 * Use client transport settings (destination and ttl) for multicast.
2043 * When @use_client_settings is %FALSE, the server settings will be
2047 gst_rtsp_client_set_use_client_settings (GstRTSPClient * client,
2048 gboolean use_client_settings)
2050 GstRTSPClientPrivate *priv;
2052 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
2054 priv = client->priv;
2056 g_mutex_lock (&priv->lock);
2057 priv->use_client_settings = use_client_settings;
2058 g_mutex_unlock (&priv->lock);
2062 * gst_rtsp_client_get_use_client_settings:
2063 * @client: a #GstRTSPClient
2065 * Check if client transport settings (destination and ttl) for multicast
2069 gst_rtsp_client_get_use_client_settings (GstRTSPClient * client)
2071 GstRTSPClientPrivate *priv;
2074 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
2076 priv = client->priv;
2078 g_mutex_lock (&priv->lock);
2079 res = priv->use_client_settings;
2080 g_mutex_unlock (&priv->lock);
2086 * gst_rtsp_client_set_auth:
2087 * @client: a #GstRTSPClient
2088 * @auth: a #GstRTSPAuth
2090 * configure @auth to be used as the authentication manager of @client.
2093 gst_rtsp_client_set_auth (GstRTSPClient * client, GstRTSPAuth * auth)
2095 GstRTSPClientPrivate *priv;
2098 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
2100 priv = client->priv;
2103 g_object_ref (auth);
2105 g_mutex_lock (&priv->lock);
2108 g_mutex_unlock (&priv->lock);
2111 g_object_unref (old);
2116 * gst_rtsp_client_get_auth:
2117 * @client: a #GstRTSPClient
2119 * Get the #GstRTSPAuth used as the authentication manager of @client.
2121 * Returns: (transfer full): the #GstRTSPAuth of @client. g_object_unref() after
2125 gst_rtsp_client_get_auth (GstRTSPClient * client)
2127 GstRTSPClientPrivate *priv;
2128 GstRTSPAuth *result;
2130 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2132 priv = client->priv;
2134 g_mutex_lock (&priv->lock);
2135 if ((result = priv->auth))
2136 g_object_ref (result);
2137 g_mutex_unlock (&priv->lock);
2143 * gst_rtsp_client_set_connection:
2144 * @client: a #GstRTSPClient
2145 * @conn: (transfer full): a #GstRTSPConnection
2147 * Set the #GstRTSPConnection of @client. This function takes ownership of
2150 * Returns: %TRUE on success.
2153 gst_rtsp_client_set_connection (GstRTSPClient * client,
2154 GstRTSPConnection * conn)
2156 GstRTSPClientPrivate *priv;
2157 GSocket *read_socket;
2158 GSocketAddress *address;
2160 GError *error = NULL;
2162 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
2163 g_return_val_if_fail (conn != NULL, FALSE);
2165 priv = client->priv;
2167 read_socket = gst_rtsp_connection_get_read_socket (conn);
2169 if (!(address = g_socket_get_local_address (read_socket, &error)))
2172 g_free (priv->server_ip);
2173 /* keep the original ip that the client connected to */
2174 if (G_IS_INET_SOCKET_ADDRESS (address)) {
2175 GInetAddress *iaddr;
2177 iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address));
2179 /* socket might be ipv6 but adress still ipv4 */
2180 priv->is_ipv6 = g_inet_address_get_family (iaddr) == G_SOCKET_FAMILY_IPV6;
2181 priv->server_ip = g_inet_address_to_string (iaddr);
2182 g_object_unref (address);
2184 priv->is_ipv6 = g_socket_get_family (read_socket) == G_SOCKET_FAMILY_IPV6;
2185 priv->server_ip = g_strdup ("unknown");
2188 GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
2189 priv->server_ip, priv->is_ipv6);
2191 url = gst_rtsp_connection_get_url (conn);
2192 GST_INFO ("added new client %p ip %s:%d", client, url->host, url->port);
2194 priv->connection = conn;
2201 GST_ERROR ("could not get local address %s", error->message);
2202 g_error_free (error);
2208 * gst_rtsp_client_get_connection:
2209 * @client: a #GstRTSPClient
2211 * Get the #GstRTSPConnection of @client.
2213 * Returns: (transfer none): the #GstRTSPConnection of @client.
2214 * The connection object returned remains valid until the client is freed.
2217 gst_rtsp_client_get_connection (GstRTSPClient * client)
2219 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2221 return client->priv->connection;
2225 * gst_rtsp_client_set_send_func:
2226 * @client: a #GstRTSPClient
2227 * @func: a #GstRTSPClientSendFunc
2228 * @user_data: user data passed to @func
2229 * @notify: called when @user_data is no longer in use
2231 * Set @func as the callback that will be called when a new message needs to be
2232 * sent to the client. @user_data is passed to @func and @notify is called when
2233 * @user_data is no longer in use.
2236 gst_rtsp_client_set_send_func (GstRTSPClient * client,
2237 GstRTSPClientSendFunc func, gpointer user_data, GDestroyNotify notify)
2239 GstRTSPClientPrivate *priv;
2240 GDestroyNotify old_notify;
2243 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
2245 priv = client->priv;
2247 g_mutex_lock (&priv->send_lock);
2248 priv->send_func = func;
2249 old_notify = priv->send_notify;
2250 old_data = priv->send_data;
2251 priv->send_notify = notify;
2252 priv->send_data = user_data;
2253 g_mutex_unlock (&priv->send_lock);
2256 old_notify (old_data);
2260 * gst_rtsp_client_handle_message:
2261 * @client: a #GstRTSPClient
2262 * @message: an #GstRTSPMessage
2264 * Let the client handle @message.
2266 * Returns: a #GstRTSPResult.
2269 gst_rtsp_client_handle_message (GstRTSPClient * client,
2270 GstRTSPMessage * message)
2272 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
2273 g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
2275 switch (message->type) {
2276 case GST_RTSP_MESSAGE_REQUEST:
2277 handle_request (client, message);
2279 case GST_RTSP_MESSAGE_RESPONSE:
2281 case GST_RTSP_MESSAGE_DATA:
2282 handle_data (client, message);
2291 * gst_rtsp_client_send_request:
2292 * @client: a #GstRTSPClient
2293 * @session: a #GstRTSPSession to send the request to or %NULL
2294 * @request: The request #GstRTSPMessage to send
2296 * Send a request message to the client.
2299 gst_rtsp_client_send_request (GstRTSPClient * client, GstRTSPSession * session,
2300 GstRTSPMessage * request)
2302 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
2303 g_return_val_if_fail (request != NULL, GST_RTSP_EINVAL);
2304 g_return_val_if_fail (request->type == GST_RTSP_MESSAGE_REQUEST,
2307 send_message (client, session, request, FALSE);
2312 static GstRTSPResult
2313 do_send_message (GstRTSPClient * client, GstRTSPMessage * message,
2314 gboolean close, gpointer user_data)
2316 GstRTSPClientPrivate *priv = client->priv;
2318 /* send the response and store the seq number so we can wait until it's
2319 * written to the client to close the connection */
2320 return gst_rtsp_watch_send_message (priv->watch, message, close ?
2321 &priv->close_seq : NULL);
2324 static GstRTSPResult
2325 message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
2328 return gst_rtsp_client_handle_message (GST_RTSP_CLIENT (user_data), message);
2331 static GstRTSPResult
2332 message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
2334 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2335 GstRTSPClientPrivate *priv = client->priv;
2337 if (priv->close_seq && priv->close_seq == cseq) {
2338 priv->close_seq = 0;
2339 close_connection (client);
2345 static GstRTSPResult
2346 closed (GstRTSPWatch * watch, gpointer user_data)
2348 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2349 GstRTSPClientPrivate *priv = client->priv;
2350 const gchar *tunnelid;
2352 GST_INFO ("client %p: connection closed", client);
2354 if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
2355 g_mutex_lock (&tunnels_lock);
2356 /* remove from tunnelids */
2357 g_hash_table_remove (tunnels, tunnelid);
2358 g_mutex_unlock (&tunnels_lock);
2361 gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
2366 static GstRTSPResult
2367 error (GstRTSPWatch * watch, GstRTSPResult result, gpointer user_data)
2369 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2372 str = gst_rtsp_strresult (result);
2373 GST_INFO ("client %p: received an error %s", client, str);
2379 static GstRTSPResult
2380 error_full (GstRTSPWatch * watch, GstRTSPResult result,
2381 GstRTSPMessage * message, guint id, gpointer user_data)
2383 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2386 str = gst_rtsp_strresult (result);
2388 ("client %p: error when handling message %p with id %d: %s",
2389 client, message, id, str);
2396 remember_tunnel (GstRTSPClient * client)
2398 GstRTSPClientPrivate *priv = client->priv;
2399 const gchar *tunnelid;
2401 /* store client in the pending tunnels */
2402 tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
2403 if (tunnelid == NULL)
2406 GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
2408 /* we can't have two clients connecting with the same tunnelid */
2409 g_mutex_lock (&tunnels_lock);
2410 if (g_hash_table_lookup (tunnels, tunnelid))
2411 goto tunnel_existed;
2413 g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
2414 g_mutex_unlock (&tunnels_lock);
2421 GST_ERROR ("client %p: no tunnelid provided", client);
2426 g_mutex_unlock (&tunnels_lock);
2427 GST_ERROR ("client %p: tunnel session %s already existed", client,
2433 static GstRTSPStatusCode
2434 tunnel_start (GstRTSPWatch * watch, gpointer user_data)
2436 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2437 GstRTSPClientPrivate *priv = client->priv;
2439 GST_INFO ("client %p: tunnel start (connection %p)", client,
2442 if (!remember_tunnel (client))
2445 return GST_RTSP_STS_OK;
2450 GST_ERROR ("client %p: error starting tunnel", client);
2451 return GST_RTSP_STS_SERVICE_UNAVAILABLE;
2455 static GstRTSPResult
2456 tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
2458 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2459 GstRTSPClientPrivate *priv = client->priv;
2461 GST_WARNING ("client %p: tunnel lost (connection %p)", client,
2464 /* ignore error, it'll only be a problem when the client does a POST again */
2465 remember_tunnel (client);
2470 static GstRTSPResult
2471 tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
2473 const gchar *tunnelid;
2474 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
2475 GstRTSPClientPrivate *priv = client->priv;
2476 GstRTSPClient *oclient;
2477 GstRTSPClientPrivate *opriv;
2479 GST_INFO ("client %p: tunnel complete", client);
2481 /* find previous tunnel */
2482 tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
2483 if (tunnelid == NULL)
2486 g_mutex_lock (&tunnels_lock);
2487 if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
2490 /* remove the old client from the table. ref before because removing it will
2491 * remove the ref to it. */
2492 g_object_ref (oclient);
2493 g_hash_table_remove (tunnels, tunnelid);
2495 opriv = oclient->priv;
2497 if (opriv->watch == NULL)
2499 g_mutex_unlock (&tunnels_lock);
2501 GST_INFO ("client %p: found tunnel %p (old %p, new %p)", client, oclient,
2502 opriv->connection, priv->connection);
2504 /* merge the tunnels into the first client */
2505 gst_rtsp_connection_do_tunnel (opriv->connection, priv->connection);
2506 gst_rtsp_watch_reset (opriv->watch);
2507 g_object_unref (oclient);
2514 GST_ERROR ("client %p: no tunnelid provided", client);
2515 return GST_RTSP_ERROR;
2519 g_mutex_unlock (&tunnels_lock);
2520 GST_ERROR ("client %p: tunnel session %s not found", client, tunnelid);
2521 return GST_RTSP_ERROR;
2525 g_mutex_unlock (&tunnels_lock);
2526 GST_ERROR ("client %p: tunnel session %s was closed", client, tunnelid);
2527 g_object_unref (oclient);
2528 return GST_RTSP_ERROR;
2532 static GstRTSPWatchFuncs watch_funcs = {
2544 client_watch_notify (GstRTSPClient * client)
2546 GstRTSPClientPrivate *priv = client->priv;
2548 GST_INFO ("client %p: watch destroyed", client);
2550 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
2551 g_object_unref (client);
2555 * gst_rtsp_client_attach:
2556 * @client: a #GstRTSPClient
2557 * @context: (allow-none): a #GMainContext
2559 * Attaches @client to @context. When the mainloop for @context is run, the
2560 * client will be dispatched. When @context is NULL, the default context will be
2563 * This function should be called when the client properties and urls are fully
2564 * configured and the client is ready to start.
2566 * Returns: the ID (greater than 0) for the source within the GMainContext.
2569 gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
2571 GstRTSPClientPrivate *priv;
2574 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), 0);
2575 priv = client->priv;
2576 g_return_val_if_fail (priv->watch == NULL, 0);
2578 /* create watch for the connection and attach */
2579 priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs,
2580 g_object_ref (client), (GDestroyNotify) client_watch_notify);
2581 gst_rtsp_client_set_send_func (client, do_send_message, priv->watch,
2582 (GDestroyNotify) gst_rtsp_watch_unref);
2584 /* FIXME make this configurable. We don't want to do this yet because it will
2585 * be superceeded by a cache object later */
2586 gst_rtsp_watch_set_send_backlog (priv->watch, 0, 100);
2588 GST_INFO ("attaching to context %p", context);
2589 res = gst_rtsp_watch_attach (priv->watch, context);
2595 * gst_rtsp_client_session_filter:
2596 * @client: a #GstRTSPclient
2597 * @func: (scope call): a callback
2598 * @user_data: user data passed to @func
2600 * Call @func for each session managed by @client. The result value of @func
2601 * determines what happens to the session. @func will be called with @client
2602 * locked so no further actions on @client can be performed from @func.
2604 * If @func returns #GST_RTSP_FILTER_REMOVE, the session will be removed from
2607 * If @func returns #GST_RTSP_FILTER_KEEP, the session will remain in @client.
2609 * If @func returns #GST_RTSP_FILTER_REF, the session will remain in @client but
2610 * will also be added with an additional ref to the result #GList of this
2613 * Returns: (element-type GstRTSPSession) (transfer full): a #GList with all
2614 * sessions for which @func returned #GST_RTSP_FILTER_REF. After usage, each
2615 * element in the #GList should be unreffed before the list is freed.
2618 gst_rtsp_client_session_filter (GstRTSPClient * client,
2619 GstRTSPClientSessionFilterFunc func, gpointer user_data)
2621 GstRTSPClientPrivate *priv;
2622 GList *result, *walk, *next;
2624 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
2625 g_return_val_if_fail (func != NULL, NULL);
2627 priv = client->priv;
2631 g_mutex_lock (&priv->lock);
2632 for (walk = priv->sessions; walk; walk = next) {
2633 GstRTSPSession *sess = walk->data;
2635 next = g_list_next (walk);
2637 switch (func (client, sess, user_data)) {
2638 case GST_RTSP_FILTER_REMOVE:
2639 /* stop watching the session and pretent it went away */
2640 client_cleanup_session (client, sess);
2642 case GST_RTSP_FILTER_REF:
2643 result = g_list_prepend (result, g_object_ref (sess));
2645 case GST_RTSP_FILTER_KEEP:
2650 g_mutex_unlock (&priv->lock);