2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3 * Copyright (C) 2015 Centricular Ltd
4 * Author: Sebastian Dröge <sebastian@centricular.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * @short_description: A client connection state
24 * @see_also: #GstRTSPServer, #GstRTSPThreadPool
26 * The client object handles the connection with a client for as long as a TCP
29 * A #GstRTSPClient is created by #GstRTSPServer when a new connection is
30 * accepted and it inherits the #GstRTSPMountPoints, #GstRTSPSessionPool,
31 * #GstRTSPAuth and #GstRTSPThreadPool from the server.
33 * The client connection should be configured with the #GstRTSPConnection using
34 * gst_rtsp_client_set_connection() before it can be attached to a #GMainContext
35 * using gst_rtsp_client_attach(). From then on the client will handle requests
38 * Use gst_rtsp_client_session_filter() to iterate or modify all the
39 * #GstRTSPSession objects managed by the client object.
41 * Last reviewed on 2013-07-11 (1.0.0)
47 #include <gst/sdp/gstmikey.h>
48 #include <gst/rtsp/gstrtsp-enumtypes.h>
50 #include "rtsp-client.h"
52 #include "rtsp-params.h"
62 * send_lock, lock, tunnels_lock
65 struct _GstRTSPClientPrivate
67 GMutex lock; /* protects everything else */
70 GstRTSPConnection *connection;
72 GMainContext *watch_context;
76 /* protected by send_lock */
77 GstRTSPClientSendFunc send_func;
79 GDestroyNotify send_notify;
83 GstRTSPSessionPool *session_pool;
84 gulong session_removed_id;
85 GstRTSPMountPoints *mount_points;
87 GstRTSPThreadPool *thread_pool;
89 /* used to cache the media in the last requested DESCRIBE so that
90 * we can pick it up in the next SETUP immediately */
94 GHashTable *transports;
96 guint sessions_cookie;
98 gboolean drop_backlog;
100 guint rtsp_ctrl_timeout_id;
101 guint rtsp_ctrl_timeout_cnt;
103 /* The version currently being used */
104 GstRTSPVersion version;
106 GHashTable *pipelined_requests; /* pipelined_request_id -> session_id */
107 GstRTSPTunnelState tstate;
116 static GMutex tunnels_lock;
117 static GHashTable *tunnels; /* protected by tunnels_lock */
119 #define WATCH_BACKLOG_SIZE 100
121 #define DEFAULT_SESSION_POOL NULL
122 #define DEFAULT_MOUNT_POINTS NULL
123 #define DEFAULT_DROP_BACKLOG TRUE
125 #define RTSP_CTRL_CB_INTERVAL 1
126 #define RTSP_CTRL_TIMEOUT_VALUE 60
141 SIGNAL_PRE_OPTIONS_REQUEST,
142 SIGNAL_OPTIONS_REQUEST,
143 SIGNAL_PRE_DESCRIBE_REQUEST,
144 SIGNAL_DESCRIBE_REQUEST,
145 SIGNAL_PRE_SETUP_REQUEST,
146 SIGNAL_SETUP_REQUEST,
147 SIGNAL_PRE_PLAY_REQUEST,
149 SIGNAL_PRE_PAUSE_REQUEST,
150 SIGNAL_PAUSE_REQUEST,
151 SIGNAL_PRE_TEARDOWN_REQUEST,
152 SIGNAL_TEARDOWN_REQUEST,
153 SIGNAL_PRE_SET_PARAMETER_REQUEST,
154 SIGNAL_SET_PARAMETER_REQUEST,
155 SIGNAL_PRE_GET_PARAMETER_REQUEST,
156 SIGNAL_GET_PARAMETER_REQUEST,
157 SIGNAL_HANDLE_RESPONSE,
159 SIGNAL_PRE_ANNOUNCE_REQUEST,
160 SIGNAL_ANNOUNCE_REQUEST,
161 SIGNAL_PRE_RECORD_REQUEST,
162 SIGNAL_RECORD_REQUEST,
163 SIGNAL_CHECK_REQUIREMENTS,
167 GST_DEBUG_CATEGORY_STATIC (rtsp_client_debug);
168 #define GST_CAT_DEFAULT rtsp_client_debug
170 static guint gst_rtsp_client_signals[SIGNAL_LAST] = { 0 };
172 static void gst_rtsp_client_get_property (GObject * object, guint propid,
173 GValue * value, GParamSpec * pspec);
174 static void gst_rtsp_client_set_property (GObject * object, guint propid,
175 const GValue * value, GParamSpec * pspec);
176 static void gst_rtsp_client_finalize (GObject * obj);
178 static GstSDPMessage *create_sdp (GstRTSPClient * client, GstRTSPMedia * media);
179 static gboolean handle_sdp (GstRTSPClient * client, GstRTSPContext * ctx,
180 GstRTSPMedia * media, GstSDPMessage * sdp);
181 static gboolean default_configure_client_media (GstRTSPClient * client,
182 GstRTSPMedia * media, GstRTSPStream * stream, GstRTSPContext * ctx);
183 static gboolean default_configure_client_transport (GstRTSPClient * client,
184 GstRTSPContext * ctx, GstRTSPTransport * ct);
185 static GstRTSPResult default_params_set (GstRTSPClient * client,
186 GstRTSPContext * ctx);
187 static GstRTSPResult default_params_get (GstRTSPClient * client,
188 GstRTSPContext * ctx);
189 static gchar *default_make_path_from_uri (GstRTSPClient * client,
190 const GstRTSPUrl * uri);
191 static void client_session_removed (GstRTSPSessionPool * pool,
192 GstRTSPSession * session, GstRTSPClient * client);
193 static GstRTSPStatusCode default_pre_signal_handler (GstRTSPClient * client,
194 GstRTSPContext * ctx);
195 static gboolean pre_signal_accumulator (GSignalInvocationHint * ihint,
196 GValue * return_accu, const GValue * handler_return, gpointer data);
198 G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPClient, gst_rtsp_client, G_TYPE_OBJECT);
201 gst_rtsp_client_class_init (GstRTSPClientClass * klass)
203 GObjectClass *gobject_class;
205 gobject_class = G_OBJECT_CLASS (klass);
207 gobject_class->get_property = gst_rtsp_client_get_property;
208 gobject_class->set_property = gst_rtsp_client_set_property;
209 gobject_class->finalize = gst_rtsp_client_finalize;
211 klass->create_sdp = create_sdp;
212 klass->handle_sdp = handle_sdp;
213 klass->configure_client_media = default_configure_client_media;
214 klass->configure_client_transport = default_configure_client_transport;
215 klass->params_set = default_params_set;
216 klass->params_get = default_params_get;
217 klass->make_path_from_uri = default_make_path_from_uri;
219 klass->pre_options_request = default_pre_signal_handler;
220 klass->pre_describe_request = default_pre_signal_handler;
221 klass->pre_setup_request = default_pre_signal_handler;
222 klass->pre_play_request = default_pre_signal_handler;
223 klass->pre_pause_request = default_pre_signal_handler;
224 klass->pre_teardown_request = default_pre_signal_handler;
225 klass->pre_set_parameter_request = default_pre_signal_handler;
226 klass->pre_get_parameter_request = default_pre_signal_handler;
227 klass->pre_announce_request = default_pre_signal_handler;
228 klass->pre_record_request = default_pre_signal_handler;
230 g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
231 g_param_spec_object ("session-pool", "Session Pool",
232 "The session pool to use for client session",
233 GST_TYPE_RTSP_SESSION_POOL,
234 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
236 g_object_class_install_property (gobject_class, PROP_MOUNT_POINTS,
237 g_param_spec_object ("mount-points", "Mount Points",
238 "The mount points to use for client session",
239 GST_TYPE_RTSP_MOUNT_POINTS,
240 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
242 g_object_class_install_property (gobject_class, PROP_DROP_BACKLOG,
243 g_param_spec_boolean ("drop-backlog", "Drop Backlog",
244 "Drop data when the backlog queue is full",
245 DEFAULT_DROP_BACKLOG, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
247 gst_rtsp_client_signals[SIGNAL_CLOSED] =
248 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
249 G_STRUCT_OFFSET (GstRTSPClientClass, closed), NULL, NULL,
250 g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE);
252 gst_rtsp_client_signals[SIGNAL_NEW_SESSION] =
253 g_signal_new ("new-session", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
254 G_STRUCT_OFFSET (GstRTSPClientClass, new_session), NULL, NULL,
255 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_RTSP_SESSION);
258 * GstRTSPClient::pre-options-request:
259 * @client: a #GstRTSPClient
260 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
262 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
263 * otherwise an appropriate return code
267 gst_rtsp_client_signals[SIGNAL_PRE_OPTIONS_REQUEST] =
268 g_signal_new ("pre-options-request", G_TYPE_FROM_CLASS (klass),
269 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
270 pre_options_request), pre_signal_accumulator, NULL,
271 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
272 GST_TYPE_RTSP_CONTEXT);
275 * GstRTSPClient::options-request:
276 * @client: a #GstRTSPClient
277 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
279 gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST] =
280 g_signal_new ("options-request", G_TYPE_FROM_CLASS (klass),
281 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, options_request),
282 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
283 GST_TYPE_RTSP_CONTEXT);
286 * GstRTSPClient::pre-describe-request:
287 * @client: a #GstRTSPClient
288 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
290 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
291 * otherwise an appropriate return code
295 gst_rtsp_client_signals[SIGNAL_PRE_DESCRIBE_REQUEST] =
296 g_signal_new ("pre-describe-request", G_TYPE_FROM_CLASS (klass),
297 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
298 pre_describe_request), pre_signal_accumulator, NULL,
299 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
300 GST_TYPE_RTSP_CONTEXT);
303 * GstRTSPClient::describe-request:
304 * @client: a #GstRTSPClient
305 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
307 gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST] =
308 g_signal_new ("describe-request", G_TYPE_FROM_CLASS (klass),
309 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, describe_request),
310 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
311 GST_TYPE_RTSP_CONTEXT);
314 * GstRTSPClient::pre-setup-request:
315 * @client: a #GstRTSPClient
316 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
318 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
319 * otherwise an appropriate return code
323 gst_rtsp_client_signals[SIGNAL_PRE_SETUP_REQUEST] =
324 g_signal_new ("pre-setup-request", G_TYPE_FROM_CLASS (klass),
325 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
326 pre_setup_request), pre_signal_accumulator, NULL,
327 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
328 GST_TYPE_RTSP_CONTEXT);
331 * GstRTSPClient::setup-request:
332 * @client: a #GstRTSPClient
333 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
335 gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST] =
336 g_signal_new ("setup-request", G_TYPE_FROM_CLASS (klass),
337 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, setup_request),
338 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
339 GST_TYPE_RTSP_CONTEXT);
342 * GstRTSPClient::pre-play-request:
343 * @client: a #GstRTSPClient
344 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
346 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
347 * otherwise an appropriate return code
351 gst_rtsp_client_signals[SIGNAL_PRE_PLAY_REQUEST] =
352 g_signal_new ("pre-play-request", G_TYPE_FROM_CLASS (klass),
353 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
354 pre_play_request), pre_signal_accumulator, NULL,
355 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
356 GST_TYPE_RTSP_CONTEXT);
359 * GstRTSPClient::play-request:
360 * @client: a #GstRTSPClient
361 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
363 gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST] =
364 g_signal_new ("play-request", G_TYPE_FROM_CLASS (klass),
365 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, play_request),
366 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
367 GST_TYPE_RTSP_CONTEXT);
370 * GstRTSPClient::pre-pause-request:
371 * @client: a #GstRTSPClient
372 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
374 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
375 * otherwise an appropriate return code
379 gst_rtsp_client_signals[SIGNAL_PRE_PAUSE_REQUEST] =
380 g_signal_new ("pre-pause-request", G_TYPE_FROM_CLASS (klass),
381 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
382 pre_pause_request), pre_signal_accumulator, NULL,
383 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
384 GST_TYPE_RTSP_CONTEXT);
387 * GstRTSPClient::pause-request:
388 * @client: a #GstRTSPClient
389 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
391 gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST] =
392 g_signal_new ("pause-request", G_TYPE_FROM_CLASS (klass),
393 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, pause_request),
394 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
395 GST_TYPE_RTSP_CONTEXT);
398 * GstRTSPClient::pre-teardown-request:
399 * @client: a #GstRTSPClient
400 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
402 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
403 * otherwise an appropriate return code
407 gst_rtsp_client_signals[SIGNAL_PRE_TEARDOWN_REQUEST] =
408 g_signal_new ("pre-teardown-request", G_TYPE_FROM_CLASS (klass),
409 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
410 pre_teardown_request), pre_signal_accumulator, NULL,
411 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
412 GST_TYPE_RTSP_CONTEXT);
415 * GstRTSPClient::teardown-request:
416 * @client: a #GstRTSPClient
417 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
419 gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST] =
420 g_signal_new ("teardown-request", G_TYPE_FROM_CLASS (klass),
421 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, teardown_request),
422 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
423 GST_TYPE_RTSP_CONTEXT);
426 * GstRTSPClient::pre-set-parameter-request:
427 * @client: a #GstRTSPClient
428 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
430 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
431 * otherwise an appropriate return code
435 gst_rtsp_client_signals[SIGNAL_PRE_SET_PARAMETER_REQUEST] =
436 g_signal_new ("pre-set-parameter-request", G_TYPE_FROM_CLASS (klass),
437 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
438 pre_set_parameter_request), pre_signal_accumulator, NULL,
439 g_cclosure_marshal_generic,
440 GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
443 * GstRTSPClient::set-parameter-request:
444 * @client: a #GstRTSPClient
445 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
447 gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST] =
448 g_signal_new ("set-parameter-request", G_TYPE_FROM_CLASS (klass),
449 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
450 set_parameter_request), NULL, NULL, g_cclosure_marshal_generic,
451 G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
454 * GstRTSPClient::pre-get-parameter-request:
455 * @client: a #GstRTSPClient
456 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
458 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
459 * otherwise an appropriate return code
463 gst_rtsp_client_signals[SIGNAL_PRE_GET_PARAMETER_REQUEST] =
464 g_signal_new ("pre-get-parameter-request", G_TYPE_FROM_CLASS (klass),
465 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
466 pre_get_parameter_request), pre_signal_accumulator, NULL,
467 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
468 GST_TYPE_RTSP_CONTEXT);
471 * GstRTSPClient::get-parameter-request:
472 * @client: a #GstRTSPClient
473 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
475 gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST] =
476 g_signal_new ("get-parameter-request", G_TYPE_FROM_CLASS (klass),
477 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
478 get_parameter_request), NULL, NULL, g_cclosure_marshal_generic,
479 G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
482 * GstRTSPClient::handle-response:
483 * @client: a #GstRTSPClient
484 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
486 gst_rtsp_client_signals[SIGNAL_HANDLE_RESPONSE] =
487 g_signal_new ("handle-response", G_TYPE_FROM_CLASS (klass),
488 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
489 handle_response), NULL, NULL, g_cclosure_marshal_generic,
490 G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
493 * GstRTSPClient::send-message:
494 * @client: The RTSP client
495 * @session: (type GstRtspServer.RTSPSession): The session
496 * @message: (type GstRtsp.RTSPMessage): The message
498 gst_rtsp_client_signals[SIGNAL_SEND_MESSAGE] =
499 g_signal_new ("send-message", G_TYPE_FROM_CLASS (klass),
500 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
501 send_message), NULL, NULL, g_cclosure_marshal_generic,
502 G_TYPE_NONE, 2, GST_TYPE_RTSP_CONTEXT, G_TYPE_POINTER);
505 * GstRTSPClient::pre-announce-request:
506 * @client: a #GstRTSPClient
507 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
509 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
510 * otherwise an appropriate return code
514 gst_rtsp_client_signals[SIGNAL_PRE_ANNOUNCE_REQUEST] =
515 g_signal_new ("pre-announce-request", G_TYPE_FROM_CLASS (klass),
516 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
517 pre_announce_request), pre_signal_accumulator, NULL,
518 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
519 GST_TYPE_RTSP_CONTEXT);
522 * GstRTSPClient::announce-request:
523 * @client: a #GstRTSPClient
524 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
526 gst_rtsp_client_signals[SIGNAL_ANNOUNCE_REQUEST] =
527 g_signal_new ("announce-request", G_TYPE_FROM_CLASS (klass),
528 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, announce_request),
529 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
530 GST_TYPE_RTSP_CONTEXT);
533 * GstRTSPClient::pre-record-request:
534 * @client: a #GstRTSPClient
535 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
537 * Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
538 * otherwise an appropriate return code
542 gst_rtsp_client_signals[SIGNAL_PRE_RECORD_REQUEST] =
543 g_signal_new ("pre-record-request", G_TYPE_FROM_CLASS (klass),
544 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
545 pre_record_request), pre_signal_accumulator, NULL,
546 g_cclosure_marshal_generic, GST_TYPE_RTSP_STATUS_CODE, 1,
547 GST_TYPE_RTSP_CONTEXT);
550 * GstRTSPClient::record-request:
551 * @client: a #GstRTSPClient
552 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
554 gst_rtsp_client_signals[SIGNAL_RECORD_REQUEST] =
555 g_signal_new ("record-request", G_TYPE_FROM_CLASS (klass),
556 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, record_request),
557 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
558 GST_TYPE_RTSP_CONTEXT);
561 * GstRTSPClient::check-requirements:
562 * @client: a #GstRTSPClient
563 * @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
564 * @arr: a NULL-terminated array of strings
566 * Returns: a newly allocated string with comma-separated list of
567 * unsupported options. An empty string must be returned if
568 * all options are supported.
572 gst_rtsp_client_signals[SIGNAL_CHECK_REQUIREMENTS] =
573 g_signal_new ("check-requirements", G_TYPE_FROM_CLASS (klass),
574 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
575 check_requirements), NULL, NULL, g_cclosure_marshal_generic,
576 G_TYPE_STRING, 2, GST_TYPE_RTSP_CONTEXT, G_TYPE_STRV);
579 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
580 g_mutex_init (&tunnels_lock);
582 GST_DEBUG_CATEGORY_INIT (rtsp_client_debug, "rtspclient", 0, "GstRTSPClient");
586 gst_rtsp_client_init (GstRTSPClient * client)
588 GstRTSPClientPrivate *priv = gst_rtsp_client_get_instance_private (client);
592 g_mutex_init (&priv->lock);
593 g_mutex_init (&priv->send_lock);
594 g_mutex_init (&priv->watch_lock);
596 priv->data_seqs = g_array_new (FALSE, FALSE, sizeof (DataSeq));
597 priv->drop_backlog = DEFAULT_DROP_BACKLOG;
599 g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
601 priv->pipelined_requests = g_hash_table_new_full (g_str_hash,
602 g_str_equal, g_free, g_free);
603 priv->tstate = TUNNEL_STATE_UNKNOWN;
606 static GstRTSPFilterResult
607 filter_session_media (GstRTSPSession * sess, GstRTSPSessionMedia * sessmedia,
610 gboolean *closed = user_data;
613 gboolean is_all_udp = TRUE;
615 media = gst_rtsp_session_media_get_media (sessmedia);
616 n_streams = gst_rtsp_media_n_streams (media);
618 for (i = 0; i < n_streams; i++) {
619 GstRTSPStreamTransport *transport =
620 gst_rtsp_session_media_get_transport (sessmedia, i);
621 const GstRTSPTransport *rtsp_transport;
626 rtsp_transport = gst_rtsp_stream_transport_get_transport (transport);
628 && rtsp_transport->lower_transport != GST_RTSP_LOWER_TRANS_UDP
629 && rtsp_transport->lower_transport != GST_RTSP_LOWER_TRANS_UDP_MCAST) {
635 if (!is_all_udp || gst_rtsp_media_is_stop_on_disconnect (media)) {
636 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_NULL);
637 return GST_RTSP_FILTER_REMOVE;
640 return GST_RTSP_FILTER_KEEP;
645 client_watch_session (GstRTSPClient * client, GstRTSPSession * session)
647 GstRTSPClientPrivate *priv = client->priv;
649 g_mutex_lock (&priv->lock);
650 /* check if we already know about this session */
651 if (g_list_find (priv->sessions, session) == NULL) {
652 GST_INFO ("watching session %p", session);
654 priv->sessions = g_list_prepend (priv->sessions, g_object_ref (session));
655 priv->sessions_cookie++;
657 /* connect removed session handler, it will be disconnected when the last
658 * session gets removed */
659 if (priv->session_removed_id == 0)
660 priv->session_removed_id = g_signal_connect_data (priv->session_pool,
661 "session-removed", G_CALLBACK (client_session_removed),
662 g_object_ref (client), (GClosureNotify) g_object_unref, 0);
664 g_mutex_unlock (&priv->lock);
669 /* should be called with lock */
671 client_unwatch_session (GstRTSPClient * client, GstRTSPSession * session,
674 GstRTSPClientPrivate *priv = client->priv;
676 GST_INFO ("client %p: unwatch session %p", client, session);
679 link = g_list_find (priv->sessions, session);
684 priv->sessions = g_list_delete_link (priv->sessions, link);
685 priv->sessions_cookie++;
687 /* if this was the last session, disconnect the handler.
688 * This will also drop the extra client ref */
689 if (!priv->sessions) {
690 g_signal_handler_disconnect (priv->session_pool, priv->session_removed_id);
691 priv->session_removed_id = 0;
694 if (!priv->drop_backlog) {
695 /* unlink all media managed in this session */
696 gst_rtsp_session_filter (session, filter_session_media, client);
699 /* remove the session */
700 g_object_unref (session);
703 static GstRTSPFilterResult
704 cleanup_session (GstRTSPClient * client, GstRTSPSession * sess,
707 gboolean *closed = user_data;
708 GstRTSPClientPrivate *priv = client->priv;
710 if (priv->drop_backlog) {
711 /* unlink all media managed in this session. This needs to happen
712 * without the client lock, so we really want to do it here. */
713 gst_rtsp_session_filter (sess, filter_session_media, user_data);
717 return GST_RTSP_FILTER_REMOVE;
719 return GST_RTSP_FILTER_KEEP;
723 clean_cached_media (GstRTSPClient * client, gboolean unprepare)
725 GstRTSPClientPrivate *priv = client->priv;
733 gst_rtsp_media_unprepare (priv->media);
734 g_object_unref (priv->media);
739 /* A client is finalized when the connection is broken */
741 gst_rtsp_client_finalize (GObject * obj)
743 GstRTSPClient *client = GST_RTSP_CLIENT (obj);
744 GstRTSPClientPrivate *priv = client->priv;
746 GST_INFO ("finalize client %p", client);
749 gst_rtsp_watch_set_flushing (priv->watch, TRUE);
750 gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
753 g_source_destroy ((GSource *) priv->watch);
755 if (priv->watch_context)
756 g_main_context_unref (priv->watch_context);
758 /* all sessions should have been removed by now. We keep a ref to
759 * the client object for the session removed handler. The ref is
760 * dropped when the last session is removed from the list. */
761 g_assert (priv->sessions == NULL);
762 g_assert (priv->session_removed_id == 0);
764 g_array_unref (priv->data_seqs);
765 g_hash_table_unref (priv->transports);
766 g_hash_table_unref (priv->pipelined_requests);
768 if (priv->connection)
769 gst_rtsp_connection_free (priv->connection);
770 if (priv->session_pool) {
771 g_object_unref (priv->session_pool);
773 if (priv->mount_points)
774 g_object_unref (priv->mount_points);
776 g_object_unref (priv->auth);
777 if (priv->thread_pool)
778 g_object_unref (priv->thread_pool);
780 clean_cached_media (client, TRUE);
782 g_free (priv->server_ip);
783 g_mutex_clear (&priv->lock);
784 g_mutex_clear (&priv->send_lock);
785 g_mutex_clear (&priv->watch_lock);
787 G_OBJECT_CLASS (gst_rtsp_client_parent_class)->finalize (obj);
791 gst_rtsp_client_get_property (GObject * object, guint propid,
792 GValue * value, GParamSpec * pspec)
794 GstRTSPClient *client = GST_RTSP_CLIENT (object);
795 GstRTSPClientPrivate *priv = client->priv;
798 case PROP_SESSION_POOL:
799 g_value_take_object (value, gst_rtsp_client_get_session_pool (client));
801 case PROP_MOUNT_POINTS:
802 g_value_take_object (value, gst_rtsp_client_get_mount_points (client));
804 case PROP_DROP_BACKLOG:
805 g_value_set_boolean (value, priv->drop_backlog);
808 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
813 gst_rtsp_client_set_property (GObject * object, guint propid,
814 const GValue * value, GParamSpec * pspec)
816 GstRTSPClient *client = GST_RTSP_CLIENT (object);
817 GstRTSPClientPrivate *priv = client->priv;
820 case PROP_SESSION_POOL:
821 gst_rtsp_client_set_session_pool (client, g_value_get_object (value));
823 case PROP_MOUNT_POINTS:
824 gst_rtsp_client_set_mount_points (client, g_value_get_object (value));
826 case PROP_DROP_BACKLOG:
827 g_mutex_lock (&priv->lock);
828 priv->drop_backlog = g_value_get_boolean (value);
829 g_mutex_unlock (&priv->lock);
832 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
837 * gst_rtsp_client_new:
839 * Create a new #GstRTSPClient instance.
841 * Returns: (transfer full): a new #GstRTSPClient
844 gst_rtsp_client_new (void)
846 GstRTSPClient *result;
848 result = g_object_new (GST_TYPE_RTSP_CLIENT, NULL);
854 send_message (GstRTSPClient * client, GstRTSPContext * ctx,
855 GstRTSPMessage * message, gboolean close)
857 GstRTSPClientPrivate *priv = client->priv;
859 gst_rtsp_message_add_header (message, GST_RTSP_HDR_SERVER,
860 "GStreamer RTSP server");
862 /* remove any previous header */
863 gst_rtsp_message_remove_header (message, GST_RTSP_HDR_SESSION, -1);
865 /* add the new session header for new session ids */
867 gst_rtsp_message_take_header (message, GST_RTSP_HDR_SESSION,
868 gst_rtsp_session_get_header (ctx->session));
871 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
872 gst_rtsp_message_dump (message);
876 gst_rtsp_message_add_header (message, GST_RTSP_HDR_CONNECTION, "close");
879 message->type_data.response.version =
880 ctx->request->type_data.request.version;
882 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SEND_MESSAGE],
885 g_mutex_lock (&priv->send_lock);
887 priv->send_func (client, message, close, priv->send_data);
888 g_mutex_unlock (&priv->send_lock);
890 gst_rtsp_message_unset (message);
894 send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
895 GstRTSPContext * ctx)
897 gst_rtsp_message_init_response (ctx->response, code,
898 gst_rtsp_status_as_text (code), ctx->request);
902 send_message (client, ctx, ctx->response, FALSE);
906 send_option_not_supported_response (GstRTSPClient * client,
907 GstRTSPContext * ctx, const gchar * unsupported_options)
909 GstRTSPStatusCode code = GST_RTSP_STS_OPTION_NOT_SUPPORTED;
911 gst_rtsp_message_init_response (ctx->response, code,
912 gst_rtsp_status_as_text (code), ctx->request);
914 if (unsupported_options != NULL) {
915 gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_UNSUPPORTED,
916 unsupported_options);
921 send_message (client, ctx, ctx->response, FALSE);
925 paths_are_equal (const gchar * path1, const gchar * path2, gint len2)
927 if (path1 == NULL || path2 == NULL)
930 if (strlen (path1) != len2)
933 if (strncmp (path1, path2, len2))
939 /* this function is called to initially find the media for the DESCRIBE request
940 * but is cached for when the same client (without breaking the connection) is
941 * doing a setup for the exact same url. */
942 static GstRTSPMedia *
943 find_media (GstRTSPClient * client, GstRTSPContext * ctx, gchar * path,
946 GstRTSPClientPrivate *priv = client->priv;
947 GstRTSPMediaFactory *factory;
951 /* find the longest matching factory for the uri first */
952 if (!(factory = gst_rtsp_mount_points_match (priv->mount_points,
956 ctx->factory = factory;
958 if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS))
959 goto no_factory_access;
961 if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT))
967 path_len = strlen (path);
969 if (!paths_are_equal (priv->path, path, path_len)) {
970 /* remove any previously cached values before we try to construct a new
972 clean_cached_media (client, TRUE);
974 /* prepare the media and add it to the pipeline */
975 if (!(media = gst_rtsp_media_factory_construct (factory, ctx->uri)))
980 if (!(gst_rtsp_media_get_transport_mode (media) &
981 GST_RTSP_TRANSPORT_MODE_RECORD)) {
982 GstRTSPThread *thread;
984 thread = gst_rtsp_thread_pool_get_thread (priv->thread_pool,
985 GST_RTSP_THREAD_TYPE_MEDIA, ctx);
989 /* prepare the media */
990 if (!gst_rtsp_media_prepare (media, thread))
994 /* now keep track of the uri and the media */
995 priv->path = g_strndup (path, path_len);
998 /* we have seen this path before, used cached media */
1001 GST_INFO ("reusing cached media %p for path %s", media, priv->path);
1004 g_object_unref (factory);
1005 ctx->factory = NULL;
1008 g_object_ref (media);
1015 GST_ERROR ("client %p: no factory for path %s", client, path);
1016 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
1021 g_object_unref (factory);
1022 ctx->factory = NULL;
1023 GST_ERROR ("client %p: not authorized to see factory path %s", client,
1025 /* error reply is already sent */
1030 g_object_unref (factory);
1031 ctx->factory = NULL;
1032 GST_ERROR ("client %p: not authorized for factory path %s", client, path);
1033 /* error reply is already sent */
1038 GST_ERROR ("client %p: can't create media", client);
1039 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1040 g_object_unref (factory);
1041 ctx->factory = NULL;
1046 GST_ERROR ("client %p: can't create thread", client);
1047 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
1048 g_object_unref (media);
1050 g_object_unref (factory);
1051 ctx->factory = NULL;
1056 GST_ERROR ("client %p: can't prepare media", client);
1057 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
1058 g_object_unref (media);
1060 g_object_unref (factory);
1061 ctx->factory = NULL;
1066 static inline DataSeq *
1067 get_data_seq_element (GstRTSPClient * client, guint8 channel)
1069 GstRTSPClientPrivate *priv = client->priv;
1070 GArray *data_seqs = priv->data_seqs;
1073 while (i < data_seqs->len) {
1074 DataSeq *data_seq = &g_array_index (data_seqs, DataSeq, i);
1075 if (data_seq->channel == channel)
1084 add_data_seq (GstRTSPClient * client, guint8 channel)
1086 GstRTSPClientPrivate *priv = client->priv;
1087 DataSeq data_seq = {.channel = channel,.seq = 0 };
1089 if (get_data_seq_element (client, channel) == NULL)
1090 g_array_append_val (priv->data_seqs, data_seq);
1094 set_data_seq (GstRTSPClient * client, guint8 channel, guint seq)
1098 data_seq = get_data_seq_element (client, channel);
1099 g_assert_nonnull (data_seq);
1100 data_seq->seq = seq;
1104 get_data_seq (GstRTSPClient * client, guint8 channel)
1108 data_seq = get_data_seq_element (client, channel);
1109 g_assert_nonnull (data_seq);
1110 return data_seq->seq;
1114 get_data_channel (GstRTSPClient * client, guint seq, guint8 * channel)
1116 GstRTSPClientPrivate *priv = client->priv;
1117 GArray *data_seqs = priv->data_seqs;
1120 while (i < data_seqs->len) {
1121 DataSeq *data_seq = &g_array_index (data_seqs, DataSeq, i);
1122 if (data_seq->seq == seq) {
1123 *channel = data_seq->channel;
1133 do_close (gpointer user_data)
1135 GstRTSPClient *client = user_data;
1137 gst_rtsp_client_close (client);
1139 return G_SOURCE_REMOVE;
1143 do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
1145 GstRTSPClientPrivate *priv = client->priv;
1146 GstRTSPMessage message = { 0 };
1147 gboolean ret = TRUE;
1148 GstMapInfo map_info;
1152 gst_rtsp_message_init_data (&message, channel);
1154 /* FIXME, need some sort of iovec RTSPMessage here */
1155 if (!gst_buffer_map (buffer, &map_info, GST_MAP_READ))
1158 gst_rtsp_message_take_body (&message, map_info.data, map_info.size);
1160 g_mutex_lock (&priv->send_lock);
1161 if (get_data_seq (client, channel) != 0) {
1162 GST_WARNING ("already a queued data message for channel %d", channel);
1163 g_mutex_unlock (&priv->send_lock);
1166 if (priv->send_func)
1167 ret = priv->send_func (client, &message, FALSE, priv->send_data);
1168 g_mutex_unlock (&priv->send_lock);
1170 gst_rtsp_message_steal_body (&message, &data, &usize);
1171 gst_buffer_unmap (buffer, &map_info);
1173 gst_rtsp_message_unset (&message);
1178 /* close in watch context */
1179 idle_src = g_idle_source_new ();
1180 g_source_set_callback (idle_src, do_close, client, NULL);
1181 g_source_attach (idle_src, priv->watch_context);
1182 g_source_unref (idle_src);
1189 * gst_rtsp_client_close:
1190 * @client: a #GstRTSPClient
1192 * Close the connection of @client and remove all media it was managing.
1197 gst_rtsp_client_close (GstRTSPClient * client)
1199 GstRTSPClientPrivate *priv = client->priv;
1200 const gchar *tunnelid;
1202 GST_DEBUG ("client %p: closing connection", client);
1204 if (priv->connection) {
1205 if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
1206 g_mutex_lock (&tunnels_lock);
1207 /* remove from tunnelids */
1208 g_hash_table_remove (tunnels, tunnelid);
1209 g_mutex_unlock (&tunnels_lock);
1211 gst_rtsp_connection_close (priv->connection);
1214 /* connection is now closed, destroy the watch which will also cause the
1215 * closed signal to be emitted */
1217 GST_DEBUG ("client %p: destroying watch", client);
1218 g_source_destroy ((GSource *) priv->watch);
1220 gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
1221 g_main_context_unref (priv->watch_context);
1222 priv->watch_context = NULL;
1227 default_make_path_from_uri (GstRTSPClient * client, const GstRTSPUrl * uri)
1232 path = g_strconcat (uri->abspath, "?", uri->query, NULL);
1234 path = g_strdup (uri->abspath);
1239 /* Default signal handler function for all "pre-command" signals, like
1240 * pre-options-request. It just returns the RTSP return code 200.
1241 * Subclasses can override this to get another default behaviour.
1243 static GstRTSPStatusCode
1244 default_pre_signal_handler (GstRTSPClient * client, GstRTSPContext * ctx)
1246 GST_LOG_OBJECT (client, "returning GST_RTSP_STS_OK");
1247 return GST_RTSP_STS_OK;
1250 /* The pre-signal accumulator function checks the return value of the signal
1251 * handlers. If any of them returns an RTSP status code that does not start
1252 * with 2 it will return FALSE, no more signal handlers will be called, and
1253 * this last RTSP status code will be the result of the signal emission.
1256 pre_signal_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
1257 const GValue * handler_return, gpointer data)
1259 GstRTSPStatusCode handler_value = g_value_get_enum (handler_return);
1260 GstRTSPStatusCode accumulated_value = g_value_get_enum (return_accu);
1262 if (handler_value < 200 || handler_value > 299) {
1263 GST_DEBUG ("handler_value : %d, returning FALSE", handler_value);
1264 g_value_set_enum (return_accu, handler_value);
1268 /* the accumulated value is initiated to 0 by GLib. if current handler value is
1269 * bigger then use that instead
1271 * FIXME: Should we prioritize the 2xx codes in a smarter way?
1272 * Like, "201 Created" > "250 Low On Storage Space" > "200 OK"?
1274 if (handler_value > accumulated_value)
1275 g_value_set_enum (return_accu, handler_value);
1281 handle_teardown_request (GstRTSPClient * client, GstRTSPContext * ctx)
1283 GstRTSPClientPrivate *priv = client->priv;
1284 GstRTSPClientClass *klass;
1285 GstRTSPSession *session;
1286 GstRTSPSessionMedia *sessmedia;
1287 GstRTSPStatusCode code;
1290 gboolean keep_session;
1291 GstRTSPStatusCode sig_result;
1296 session = ctx->session;
1301 klass = GST_RTSP_CLIENT_GET_CLASS (client);
1302 path = klass->make_path_from_uri (client, ctx->uri);
1304 /* get a handle to the configuration of the media in the session */
1305 sessmedia = gst_rtsp_session_get_media (session, path, &matched);
1309 /* only aggregate control for now.. */
1310 if (path[matched] != '\0')
1315 ctx->sessmedia = sessmedia;
1317 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_TEARDOWN_REQUEST],
1318 0, ctx, &sig_result);
1319 if (sig_result != GST_RTSP_STS_OK) {
1323 /* we emit the signal before closing the connection */
1324 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST],
1327 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_NULL);
1329 /* unmanage the media in the session, returns false if all media session
1331 keep_session = gst_rtsp_session_release_media (session, sessmedia);
1333 /* construct the response now */
1334 code = GST_RTSP_STS_OK;
1335 gst_rtsp_message_init_response (ctx->response, code,
1336 gst_rtsp_status_as_text (code), ctx->request);
1338 send_message (client, ctx, ctx->response, TRUE);
1340 if (!keep_session) {
1341 /* remove the session */
1342 gst_rtsp_session_pool_remove (priv->session_pool, session);
1350 GST_ERROR ("client %p: no session", client);
1351 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
1356 GST_ERROR ("client %p: no uri supplied", client);
1357 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1362 GST_ERROR ("client %p: no media for uri", client);
1363 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
1369 GST_ERROR ("client %p: no aggregate path %s", client, path);
1370 send_generic_response (client,
1371 GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
1377 GST_ERROR ("client %p: pre signal returned error: %s", client,
1378 gst_rtsp_status_as_text (sig_result));
1379 send_generic_response (client, sig_result, ctx);
1384 static GstRTSPResult
1385 default_params_set (GstRTSPClient * client, GstRTSPContext * ctx)
1389 res = gst_rtsp_params_set (client, ctx);
1394 static GstRTSPResult
1395 default_params_get (GstRTSPClient * client, GstRTSPContext * ctx)
1399 res = gst_rtsp_params_get (client, ctx);
1405 handle_get_param_request (GstRTSPClient * client, GstRTSPContext * ctx)
1410 GstRTSPStatusCode sig_result;
1412 g_signal_emit (client,
1413 gst_rtsp_client_signals[SIGNAL_PRE_GET_PARAMETER_REQUEST], 0, ctx,
1415 if (sig_result != GST_RTSP_STS_OK) {
1419 res = gst_rtsp_message_get_body (ctx->request, &data, &size);
1420 if (res != GST_RTSP_OK)
1423 if (size == 0 || !data || strlen ((char *) data) == 0) {
1424 if (ctx->request->type_data.request.version >= GST_RTSP_VERSION_2_0) {
1425 GST_ERROR_OBJECT (client, "Using PLAY request for keep-alive is forbidden"
1430 /* no body (or only '\0'), keep-alive request */
1431 send_generic_response (client, GST_RTSP_STS_OK, ctx);
1433 /* there is a body, handle the params */
1434 res = GST_RTSP_CLIENT_GET_CLASS (client)->params_get (client, ctx);
1435 if (res != GST_RTSP_OK)
1438 send_message (client, ctx, ctx->response, FALSE);
1441 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST],
1449 GST_ERROR ("client %p: pre signal returned error: %s", client,
1450 gst_rtsp_status_as_text (sig_result));
1451 send_generic_response (client, sig_result, ctx);
1456 GST_ERROR ("client %p: bad request", client);
1457 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1463 handle_set_param_request (GstRTSPClient * client, GstRTSPContext * ctx)
1468 GstRTSPStatusCode sig_result;
1470 g_signal_emit (client,
1471 gst_rtsp_client_signals[SIGNAL_PRE_SET_PARAMETER_REQUEST], 0, ctx,
1473 if (sig_result != GST_RTSP_STS_OK) {
1477 res = gst_rtsp_message_get_body (ctx->request, &data, &size);
1478 if (res != GST_RTSP_OK)
1481 if (size == 0 || !data || strlen ((char *) data) == 0) {
1482 /* no body (or only '\0'), keep-alive request */
1483 send_generic_response (client, GST_RTSP_STS_OK, ctx);
1485 /* there is a body, handle the params */
1486 res = GST_RTSP_CLIENT_GET_CLASS (client)->params_set (client, ctx);
1487 if (res != GST_RTSP_OK)
1490 send_message (client, ctx, ctx->response, FALSE);
1493 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST],
1501 GST_ERROR ("client %p: pre signal returned error: %s", client,
1502 gst_rtsp_status_as_text (sig_result));
1503 send_generic_response (client, sig_result, ctx);
1508 GST_ERROR ("client %p: bad request", client);
1509 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1515 handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
1517 GstRTSPSession *session;
1518 GstRTSPClientClass *klass;
1519 GstRTSPSessionMedia *sessmedia;
1520 GstRTSPMedia *media;
1521 GstRTSPStatusCode code;
1522 GstRTSPState rtspstate;
1525 GstRTSPStatusCode sig_result;
1528 if (!(session = ctx->session))
1534 klass = GST_RTSP_CLIENT_GET_CLASS (client);
1535 path = klass->make_path_from_uri (client, ctx->uri);
1537 /* get a handle to the configuration of the media in the session */
1538 sessmedia = gst_rtsp_session_get_media (session, path, &matched);
1542 if (path[matched] != '\0')
1547 media = gst_rtsp_session_media_get_media (sessmedia);
1548 n = gst_rtsp_media_n_streams (media);
1549 for (i = 0; i < n; i++) {
1550 GstRTSPStream *stream = gst_rtsp_media_get_stream (media, i);
1552 if (gst_rtsp_stream_get_publish_clock_mode (stream) ==
1553 GST_RTSP_PUBLISH_CLOCK_MODE_CLOCK_AND_OFFSET)
1557 ctx->sessmedia = sessmedia;
1559 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_PAUSE_REQUEST], 0,
1561 if (sig_result != GST_RTSP_STS_OK) {
1565 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
1566 /* the session state must be playing or recording */
1567 if (rtspstate != GST_RTSP_STATE_PLAYING &&
1568 rtspstate != GST_RTSP_STATE_RECORDING)
1571 /* then pause sending */
1572 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_PAUSED);
1574 /* construct the response now */
1575 code = GST_RTSP_STS_OK;
1576 gst_rtsp_message_init_response (ctx->response, code,
1577 gst_rtsp_status_as_text (code), ctx->request);
1579 send_message (client, ctx, ctx->response, FALSE);
1581 /* the state is now READY */
1582 gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_READY);
1584 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST], 0, ctx);
1591 GST_ERROR ("client %p: no session", client);
1592 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
1597 GST_ERROR ("client %p: no uri supplied", client);
1598 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1603 GST_ERROR ("client %p: no media for uri", client);
1604 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
1610 GST_ERROR ("client %p: no aggregate path %s", client, path);
1611 send_generic_response (client,
1612 GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
1618 GST_ERROR ("client %p: pre signal returned error: %s", client,
1619 gst_rtsp_status_as_text (sig_result));
1620 send_generic_response (client, sig_result, ctx);
1625 GST_ERROR ("client %p: not PLAYING or RECORDING", client);
1626 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
1632 GST_ERROR ("client %p: pausing not supported", client);
1633 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1638 /* convert @url and @path to a URL used as a content base for the factory
1639 * located at @path */
1641 make_base_url (GstRTSPClient * client, GstRTSPUrl * url, const gchar * path)
1647 /* check for trailing '/' and append one */
1648 trail = (path[strlen (path) - 1] != '/' ? "/" : "");
1653 tmp.abspath = g_strdup_printf ("%s%s", path, trail);
1655 result = gst_rtsp_url_get_request_uri (&tmp);
1656 g_free (tmp.abspath);
1662 handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
1664 GstRTSPSession *session;
1665 GstRTSPClientClass *klass;
1666 GstRTSPSessionMedia *sessmedia;
1667 GstRTSPMedia *media;
1668 GstRTSPStatusCode code;
1671 GstRTSPTimeRange *range;
1673 GstRTSPState rtspstate;
1674 GstRTSPRangeUnit unit = GST_RTSP_RANGE_NPT;
1675 gchar *path, *rtpinfo;
1677 gchar *seek_style = NULL;
1678 GstRTSPStatusCode sig_result;
1679 GPtrArray *transports;
1681 if (!(session = ctx->session))
1684 if (!(uri = ctx->uri))
1687 klass = GST_RTSP_CLIENT_GET_CLASS (client);
1688 path = klass->make_path_from_uri (client, uri);
1690 /* get a handle to the configuration of the media in the session */
1691 sessmedia = gst_rtsp_session_get_media (session, path, &matched);
1695 if (path[matched] != '\0')
1700 ctx->sessmedia = sessmedia;
1701 ctx->media = media = gst_rtsp_session_media_get_media (sessmedia);
1703 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_PLAY_REQUEST], 0,
1705 if (sig_result != GST_RTSP_STS_OK) {
1709 if (!(gst_rtsp_media_get_transport_mode (media) &
1710 GST_RTSP_TRANSPORT_MODE_PLAY))
1711 goto unsupported_mode;
1713 /* the session state must be playing or ready */
1714 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
1715 if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
1718 /* update the pipeline */
1719 transports = gst_rtsp_session_media_get_transports (sessmedia);
1720 if (!gst_rtsp_media_complete_pipeline (media, transports)) {
1721 g_ptr_array_unref (transports);
1722 goto pipeline_error;
1724 g_ptr_array_unref (transports);
1726 /* in play we first unsuspend, media could be suspended from SDP or PAUSED */
1727 if (!gst_rtsp_media_unsuspend (media))
1728 goto unsuspend_failed;
1730 /* parse the range header if we have one */
1731 res = gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_RANGE, &str, 0);
1732 if (res == GST_RTSP_OK) {
1733 if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
1734 GstRTSPMediaStatus media_status;
1735 GstSeekFlags flags = 0;
1737 if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_SEEK_STYLE,
1739 if (g_strcmp0 (seek_style, "RAP") == 0)
1740 flags = GST_SEEK_FLAG_ACCURATE;
1741 else if (g_strcmp0 (seek_style, "CoRAP") == 0)
1742 flags = GST_SEEK_FLAG_KEY_UNIT;
1743 else if (g_strcmp0 (seek_style, "First-Prior") == 0)
1744 flags = GST_SEEK_FLAG_KEY_UNIT & GST_SEEK_FLAG_SNAP_BEFORE;
1745 else if (g_strcmp0 (seek_style, "Next") == 0)
1746 flags = GST_SEEK_FLAG_KEY_UNIT & GST_SEEK_FLAG_SNAP_AFTER;
1748 GST_FIXME_OBJECT (client, "Add support for seek style %s",
1752 /* we have a range, seek to the position */
1754 gst_rtsp_media_seek_full (media, range, flags);
1755 gst_rtsp_range_free (range);
1757 media_status = gst_rtsp_media_get_status (media);
1758 if (media_status == GST_RTSP_MEDIA_STATUS_ERROR)
1763 /* grab RTPInfo from the media now */
1764 rtpinfo = gst_rtsp_session_media_get_rtpinfo (sessmedia);
1766 /* construct the response now */
1767 code = GST_RTSP_STS_OK;
1768 gst_rtsp_message_init_response (ctx->response, code,
1769 gst_rtsp_status_as_text (code), ctx->request);
1771 /* add the RTP-Info header */
1773 gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_RTP_INFO,
1776 gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_SEEK_STYLE,
1780 str = gst_rtsp_media_get_range_string (media, TRUE, unit);
1782 gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_RANGE, str);
1784 send_message (client, ctx, ctx->response, FALSE);
1786 /* start playing after sending the response */
1787 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_PLAYING);
1789 gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_PLAYING);
1791 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST], 0, ctx);
1798 GST_ERROR ("client %p: no session", client);
1799 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
1804 GST_ERROR ("client %p: no uri supplied", client);
1805 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1810 GST_ERROR ("client %p: media not found", client);
1811 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
1816 GST_ERROR ("client %p: no aggregate path %s", client, path);
1817 send_generic_response (client,
1818 GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
1824 GST_ERROR ("client %p: pre signal returned error: %s", client,
1825 gst_rtsp_status_as_text (sig_result));
1826 send_generic_response (client, sig_result, ctx);
1831 GST_ERROR ("client %p: not PLAYING or READY", client);
1832 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
1838 GST_ERROR ("client %p: failed to configure the pipeline", client);
1839 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
1845 GST_ERROR ("client %p: unsuspend failed", client);
1846 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
1851 GST_ERROR ("client %p: seek failed", client);
1852 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
1857 GST_ERROR ("client %p: media does not support PLAY", client);
1858 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
1864 do_keepalive (GstRTSPSession * session)
1866 GST_INFO ("keep session %p alive", session);
1867 gst_rtsp_session_touch (session);
1870 /* parse @transport and return a valid transport in @tr. only transports
1871 * supported by @stream are returned. Returns FALSE if no valid transport
1874 parse_transport (const char *transport, GstRTSPStream * stream,
1875 GstRTSPTransport * tr)
1882 gst_rtsp_transport_init (tr);
1884 GST_DEBUG ("parsing transports %s", transport);
1886 transports = g_strsplit (transport, ",", 0);
1888 /* loop through the transports, try to parse */
1889 for (i = 0; transports[i]; i++) {
1890 g_strstrip (transports[i]);
1891 res = gst_rtsp_transport_parse (transports[i], tr);
1892 if (res != GST_RTSP_OK) {
1893 /* no valid transport, search some more */
1894 GST_WARNING ("could not parse transport %s", transports[i]);
1898 /* we have a transport, see if it's supported */
1899 if (!gst_rtsp_stream_is_transport_supported (stream, tr)) {
1900 GST_WARNING ("unsupported transport %s", transports[i]);
1904 /* we have a valid transport */
1905 GST_INFO ("found valid transport %s", transports[i]);
1910 gst_rtsp_transport_init (tr);
1912 g_strfreev (transports);
1918 default_configure_client_media (GstRTSPClient * client, GstRTSPMedia * media,
1919 GstRTSPStream * stream, GstRTSPContext * ctx)
1921 GstRTSPMessage *request = ctx->request;
1922 gchar *blocksize_str;
1924 if (!gst_rtsp_stream_is_sender (stream))
1927 if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_BLOCKSIZE,
1928 &blocksize_str, 0) == GST_RTSP_OK) {
1932 blocksize = g_ascii_strtoull (blocksize_str, &end, 10);
1933 if (end == blocksize_str)
1936 /* we don't want to change the mtu when this media
1937 * can be shared because it impacts other clients */
1938 if (gst_rtsp_media_is_shared (media))
1941 if (blocksize > G_MAXUINT)
1942 blocksize = G_MAXUINT;
1944 gst_rtsp_stream_set_mtu (stream, blocksize);
1952 GST_ERROR_OBJECT (client, "failed to parse blocksize");
1953 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
1959 default_configure_client_transport (GstRTSPClient * client,
1960 GstRTSPContext * ctx, GstRTSPTransport * ct)
1962 GstRTSPClientPrivate *priv = client->priv;
1964 /* we have a valid transport now, set the destination of the client. */
1965 if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST ||
1966 ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
1967 /* allocate UDP ports */
1968 GSocketFamily family;
1969 gboolean use_client_settings = FALSE;
1971 family = priv->is_ipv6 ? G_SOCKET_FAMILY_IPV6 : G_SOCKET_FAMILY_IPV4;
1973 if ((ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) &&
1974 gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS) &&
1975 (ct->destination != NULL)) {
1977 if (!gst_rtsp_stream_verify_mcast_ttl (ctx->stream, ct->ttl))
1980 use_client_settings = TRUE;
1983 /* We need to allocate the sockets for both families before starting
1984 * multiudpsink, otherwise multiudpsink won't accept new clients with
1985 * a different family.
1987 /* FIXME: could be more adequately solved by making it possible
1988 * to set a socket on multiudpsink after it has already been started */
1989 if (!gst_rtsp_stream_allocate_udp_sockets (ctx->stream, G_SOCKET_FAMILY_IPV4, ct,
1990 use_client_settings) && family == G_SOCKET_FAMILY_IPV4)
1991 goto error_allocating_ports;
1993 if (!gst_rtsp_stream_allocate_udp_sockets (ctx->stream, G_SOCKET_FAMILY_IPV6, ct,
1994 use_client_settings) && family == G_SOCKET_FAMILY_IPV6)
1995 goto error_allocating_ports;
1997 if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
1998 if (use_client_settings) {
1999 /* FIXME: the address has been successfully allocated, however, in
2000 * the use_client_settings case we need to verify that the allocated
2001 * address is the one requested by the client and if this address is
2002 * an allowed destination. Verifying this via the address pool in not
2003 * the proper way as the address pool should only be used for choosing
2004 * the server-selected address/port pairs. */
2005 GSocket *rtp_socket;
2009 gst_rtsp_stream_get_rtp_multicast_socket (ctx->stream, family);
2010 if (rtp_socket == NULL)
2012 ttl = g_socket_get_multicast_ttl (rtp_socket);
2013 g_object_unref (rtp_socket);
2014 if (ct->ttl < ttl) {
2015 /* use the maximum ttl that is requested by multicast clients */
2016 GST_DEBUG ("requested ttl %u, but keeping ttl %u", ct->ttl, ttl);
2021 GstRTSPAddress *addr = NULL;
2023 g_free (ct->destination);
2024 addr = gst_rtsp_stream_get_multicast_address (ctx->stream, family);
2027 ct->destination = g_strdup (addr->address);
2028 ct->port.min = addr->port;
2029 ct->port.max = addr->port + addr->n_ports - 1;
2030 ct->ttl = addr->ttl;
2031 gst_rtsp_address_free (addr);
2034 if (!gst_rtsp_stream_add_multicast_client_address (ctx->stream,
2035 ct->destination, ct->port.min, ct->port.max, family))
2036 goto error_mcast_transport;
2041 url = gst_rtsp_connection_get_url (priv->connection);
2042 g_free (ct->destination);
2043 ct->destination = g_strdup (url->host);
2048 url = gst_rtsp_connection_get_url (priv->connection);
2049 g_free (ct->destination);
2050 ct->destination = g_strdup (url->host);
2052 if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
2054 GSocketAddress *addr;
2056 sock = gst_rtsp_connection_get_read_socket (priv->connection);
2057 if ((addr = g_socket_get_remote_address (sock, NULL))) {
2058 /* our read port is the sender port of client */
2059 ct->client_port.min =
2060 g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
2061 g_object_unref (addr);
2063 if ((addr = g_socket_get_local_address (sock, NULL))) {
2064 ct->server_port.max =
2065 g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
2066 g_object_unref (addr);
2068 sock = gst_rtsp_connection_get_write_socket (priv->connection);
2069 if ((addr = g_socket_get_remote_address (sock, NULL))) {
2070 /* our write port is the receiver port of client */
2071 ct->client_port.max =
2072 g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
2073 g_object_unref (addr);
2075 if ((addr = g_socket_get_local_address (sock, NULL))) {
2076 ct->server_port.min =
2077 g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
2078 g_object_unref (addr);
2080 /* check if the client selected channels for TCP */
2081 if (ct->interleaved.min == -1 || ct->interleaved.max == -1) {
2082 gst_rtsp_session_media_alloc_channels (ctx->sessmedia,
2092 GST_ERROR_OBJECT (client,
2093 "Failed to allocate UDP ports: invalid ttl value");
2096 error_allocating_ports:
2098 GST_ERROR_OBJECT (client, "Failed to allocate UDP ports");
2103 GST_ERROR_OBJECT (client, "Failed to acquire address for stream");
2108 GST_ERROR_OBJECT (client, "Failed to get UDP socket");
2111 error_mcast_transport:
2113 GST_ERROR_OBJECT (client, "Failed to add multicast client transport");
2118 static GstRTSPTransport *
2119 make_server_transport (GstRTSPClient * client, GstRTSPMedia * media,
2120 GstRTSPContext * ctx, GstRTSPTransport * ct)
2122 GstRTSPTransport *st;
2124 GSocketFamily family;
2126 /* prepare the server transport */
2127 gst_rtsp_transport_new (&st);
2129 st->trans = ct->trans;
2130 st->profile = ct->profile;
2131 st->lower_transport = ct->lower_transport;
2132 st->mode_play = ct->mode_play;
2133 st->mode_record = ct->mode_record;
2135 addr = g_inet_address_new_from_string (ct->destination);
2138 GST_ERROR ("failed to get inet addr from client destination");
2139 family = G_SOCKET_FAMILY_IPV4;
2141 family = g_inet_address_get_family (addr);
2142 g_object_unref (addr);
2146 switch (st->lower_transport) {
2147 case GST_RTSP_LOWER_TRANS_UDP:
2148 st->client_port = ct->client_port;
2149 gst_rtsp_stream_get_server_port (ctx->stream, &st->server_port, family);
2151 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
2152 st->port = ct->port;
2153 st->destination = g_strdup (ct->destination);
2156 case GST_RTSP_LOWER_TRANS_TCP:
2157 st->interleaved = ct->interleaved;
2158 st->client_port = ct->client_port;
2159 st->server_port = ct->server_port;
2164 if ((gst_rtsp_media_get_transport_mode (media) &
2165 GST_RTSP_TRANSPORT_MODE_PLAY))
2166 gst_rtsp_stream_get_ssrc (ctx->stream, &st->ssrc);
2172 rtsp_ctrl_timeout_cb (gpointer user_data)
2174 gboolean res = G_SOURCE_CONTINUE;
2175 GstRTSPClient *client = (GstRTSPClient *) user_data;
2176 GstRTSPClientPrivate *priv = client->priv;
2178 priv->rtsp_ctrl_timeout_cnt += RTSP_CTRL_CB_INTERVAL;
2180 if (priv->rtsp_ctrl_timeout_cnt > RTSP_CTRL_TIMEOUT_VALUE) {
2181 GST_DEBUG ("rtsp control session timeout id=%u expired, closing client.",
2182 priv->rtsp_ctrl_timeout_id);
2183 g_mutex_lock (&priv->lock);
2184 priv->rtsp_ctrl_timeout_id = 0;
2185 priv->rtsp_ctrl_timeout_cnt = 0;
2186 g_mutex_unlock (&priv->lock);
2187 gst_rtsp_client_close (client);
2189 res = G_SOURCE_REMOVE;
2196 rtsp_ctrl_timeout_remove (GstRTSPClientPrivate * priv)
2198 g_mutex_lock (&priv->lock);
2200 if (priv->rtsp_ctrl_timeout_id != 0) {
2201 g_source_destroy (g_main_context_find_source_by_id (priv->watch_context,
2202 priv->rtsp_ctrl_timeout_id));
2203 GST_DEBUG ("rtsp control session removed timeout id=%u.",
2204 priv->rtsp_ctrl_timeout_id);
2205 priv->rtsp_ctrl_timeout_id = 0;
2206 priv->rtsp_ctrl_timeout_cnt = 0;
2209 g_mutex_unlock (&priv->lock);
2213 stream_make_keymgmt (GstRTSPClient * client, const gchar * location,
2214 GstRTSPStream * stream)
2216 gchar *base64, *result = NULL;
2217 GstMIKEYMessage *mikey_msg;
2218 GstCaps *srtcpparams;
2219 GstElement *rtcp_encoder;
2220 gint srtcp_cipher, srtp_cipher;
2221 gint srtcp_auth, srtp_auth;
2223 GType ciphertype, authtype;
2224 GEnumClass *cipher_enum, *auth_enum;
2225 GEnumValue *srtcp_cipher_value, *srtp_cipher_value, *srtcp_auth_value,
2228 rtcp_encoder = gst_rtsp_stream_get_srtp_encoder (stream);
2233 ciphertype = g_type_from_name ("GstSrtpCipherType");
2234 authtype = g_type_from_name ("GstSrtpAuthType");
2236 cipher_enum = g_type_class_ref (ciphertype);
2237 auth_enum = g_type_class_ref (authtype);
2239 /* We need to bring the encoder to READY so that it generates its key */
2240 gst_element_set_state (rtcp_encoder, GST_STATE_READY);
2242 g_object_get (rtcp_encoder, "rtcp-cipher", &srtcp_cipher, "rtcp-auth",
2243 &srtcp_auth, "rtp-cipher", &srtp_cipher, "rtp-auth", &srtp_auth, "key",
2245 g_object_unref (rtcp_encoder);
2247 srtcp_cipher_value = g_enum_get_value (cipher_enum, srtcp_cipher);
2248 srtp_cipher_value = g_enum_get_value (cipher_enum, srtp_cipher);
2249 srtcp_auth_value = g_enum_get_value (auth_enum, srtcp_auth);
2250 srtp_auth_value = g_enum_get_value (auth_enum, srtp_auth);
2252 g_type_class_unref (cipher_enum);
2253 g_type_class_unref (auth_enum);
2255 srtcpparams = gst_caps_new_simple ("application/x-srtcp",
2256 "srtcp-cipher", G_TYPE_STRING, srtcp_cipher_value->value_nick,
2257 "srtcp-auth", G_TYPE_STRING, srtcp_auth_value->value_nick,
2258 "srtp-cipher", G_TYPE_STRING, srtp_cipher_value->value_nick,
2259 "srtp-auth", G_TYPE_STRING, srtp_auth_value->value_nick,
2260 "srtp-key", GST_TYPE_BUFFER, key, NULL);
2262 mikey_msg = gst_mikey_message_new_from_caps (srtcpparams);
2266 gst_rtsp_stream_get_ssrc (stream, &send_ssrc);
2267 gst_mikey_message_add_cs_srtp (mikey_msg, 0, send_ssrc, 0);
2269 base64 = gst_mikey_message_base64_encode (mikey_msg);
2270 gst_mikey_message_unref (mikey_msg);
2273 result = gst_sdp_make_keymgmt (location, base64);
2283 handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
2285 GstRTSPClientPrivate *priv = client->priv;
2288 gchar *transport, *keymgmt;
2289 GstRTSPTransport *ct, *st;
2290 GstRTSPStatusCode code;
2291 GstRTSPSession *session;
2292 GstRTSPStreamTransport *trans;
2294 GstRTSPSessionMedia *sessmedia;
2295 GstRTSPMedia *media;
2296 GstRTSPStream *stream;
2297 GstRTSPState rtspstate;
2298 GstRTSPClientClass *klass;
2299 gchar *path, *control = NULL;
2301 gboolean new_session = FALSE;
2302 GstRTSPStatusCode sig_result;
2303 gchar *pipelined_request_id = NULL, *accept_range = NULL;
2309 klass = GST_RTSP_CLIENT_GET_CLASS (client);
2310 path = klass->make_path_from_uri (client, uri);
2312 /* parse the transport */
2314 gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_TRANSPORT,
2316 if (res != GST_RTSP_OK)
2319 /* Handle Pipelined-requests if using >= 2.0 */
2320 if (ctx->request->type_data.request.version >= GST_RTSP_VERSION_2_0)
2321 gst_rtsp_message_get_header (ctx->request,
2322 GST_RTSP_HDR_PIPELINED_REQUESTS, &pipelined_request_id, 0);
2324 /* we create the session after parsing stuff so that we don't make
2325 * a session for malformed requests */
2326 if (priv->session_pool == NULL)
2329 session = ctx->session;
2332 g_object_ref (session);
2333 /* get a handle to the configuration of the media in the session, this can
2334 * return NULL if this is a new url to manage in this session. */
2335 sessmedia = gst_rtsp_session_get_media (session, path, &matched);
2337 /* we need a new media configuration in this session */
2341 /* we have no session media, find one and manage it */
2342 if (sessmedia == NULL) {
2343 /* get a handle to the configuration of the media in the session */
2344 media = find_media (client, ctx, path, &matched);
2345 /* need to suspend the media, if the protocol has changed */
2347 gst_rtsp_media_suspend (media);
2349 if ((media = gst_rtsp_session_media_get_media (sessmedia)))
2350 g_object_ref (media);
2352 goto media_not_found;
2354 /* no media, not found then */
2356 goto media_not_found_no_reply;
2358 if (path[matched] == '\0') {
2359 if (gst_rtsp_media_n_streams (media) == 1) {
2360 stream = gst_rtsp_media_get_stream (media, 0);
2362 goto control_not_found;
2365 /* path is what matched. */
2366 path[matched] = '\0';
2367 /* control is remainder */
2368 control = &path[matched + 1];
2370 /* find the stream now using the control part */
2371 stream = gst_rtsp_media_find_stream (media, control);
2375 goto stream_not_found;
2377 /* now we have a uri identifying a valid media and stream */
2378 ctx->stream = stream;
2381 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_SETUP_REQUEST], 0,
2383 if (sig_result != GST_RTSP_STS_OK) {
2387 if (session == NULL) {
2388 /* create a session if this fails we probably reached our session limit or
2390 if (!(session = gst_rtsp_session_pool_create (priv->session_pool)))
2391 goto service_unavailable;
2393 /* Pipelined requests should be cleared between sessions */
2394 g_hash_table_remove_all (priv->pipelined_requests);
2396 /* make sure this client is closed when the session is closed */
2397 client_watch_session (client, session);
2400 /* signal new session */
2401 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_NEW_SESSION], 0,
2404 ctx->session = session;
2407 if (pipelined_request_id) {
2408 g_hash_table_insert (client->priv->pipelined_requests,
2409 g_strdup (pipelined_request_id),
2410 g_strdup (gst_rtsp_session_get_sessionid (session)));
2412 rtsp_ctrl_timeout_remove (priv);
2414 if (!klass->configure_client_media (client, media, stream, ctx))
2415 goto configure_media_failed_no_reply;
2417 gst_rtsp_transport_new (&ct);
2419 /* parse and find a usable supported transport */
2420 if (!parse_transport (transport, stream, ct))
2421 goto unsupported_transports;
2424 && !(gst_rtsp_media_get_transport_mode (media) &
2425 GST_RTSP_TRANSPORT_MODE_PLAY)) || (ct->mode_record
2426 && !(gst_rtsp_media_get_transport_mode (media) &
2427 GST_RTSP_TRANSPORT_MODE_RECORD)))
2428 goto unsupported_mode;
2430 /* parse the keymgmt */
2431 if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_KEYMGMT,
2432 &keymgmt, 0) == GST_RTSP_OK) {
2433 if (!gst_rtsp_stream_handle_keymgmt (ctx->stream, keymgmt))
2437 if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_ACCEPT_RANGES,
2438 &accept_range, 0) == GST_RTSP_OK) {
2439 GEnumValue *runit = NULL;
2441 gchar **valid_ranges;
2442 GEnumClass *runit_class = g_type_class_ref (GST_TYPE_RTSP_RANGE_UNIT);
2444 gst_rtsp_message_dump (ctx->request);
2445 valid_ranges = g_strsplit (accept_range, ",", -1);
2447 for (i = 0; valid_ranges[i]; i++) {
2448 gchar *range = valid_ranges[i];
2450 while (*range == ' ')
2453 runit = g_enum_get_value_by_nick (runit_class, range);
2457 g_strfreev (valid_ranges);
2458 g_type_class_unref (runit_class);
2461 goto unsupported_range_unit;
2464 if (sessmedia == NULL) {
2465 /* manage the media in our session now, if not done already */
2467 gst_rtsp_session_manage_media (session, path, g_object_ref (media));
2468 /* if we stil have no media, error */
2469 if (sessmedia == NULL)
2470 goto sessmedia_unavailable;
2472 /* don't cache media anymore */
2473 clean_cached_media (client, FALSE);
2476 ctx->sessmedia = sessmedia;
2478 /* update the client transport */
2479 if (!klass->configure_client_transport (client, ctx, ct))
2480 goto unsupported_client_transport;
2482 /* set in the session media transport */
2483 trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
2487 /* configure the url used to set this transport, this we will use when
2488 * generating the response for the PLAY request */
2489 gst_rtsp_stream_transport_set_url (trans, uri);
2490 /* configure keepalive for this transport */
2491 gst_rtsp_stream_transport_set_keepalive (trans,
2492 (GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
2494 if (ct->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
2495 /* our callbacks to send data on this TCP connection */
2496 gst_rtsp_stream_transport_set_callbacks (trans,
2497 (GstRTSPSendFunc) do_send_data,
2498 (GstRTSPSendFunc) do_send_data, client, NULL);
2500 g_hash_table_insert (priv->transports,
2501 GINT_TO_POINTER (ct->interleaved.min), trans);
2502 g_object_ref (trans);
2503 g_hash_table_insert (priv->transports,
2504 GINT_TO_POINTER (ct->interleaved.max), trans);
2505 g_object_ref (trans);
2506 add_data_seq (client, ct->interleaved.min);
2507 add_data_seq (client, ct->interleaved.max);
2510 /* create and serialize the server transport */
2511 st = make_server_transport (client, media, ctx, ct);
2512 trans_str = gst_rtsp_transport_as_text (st);
2513 gst_rtsp_transport_free (st);
2515 /* construct the response now */
2516 code = GST_RTSP_STS_OK;
2517 gst_rtsp_message_init_response (ctx->response, code,
2518 gst_rtsp_status_as_text (code), ctx->request);
2520 gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_TRANSPORT,
2524 if (pipelined_request_id)
2525 gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_PIPELINED_REQUESTS,
2526 pipelined_request_id);
2528 if (ctx->request->type_data.request.version >= GST_RTSP_VERSION_2_0) {
2529 GstClockTimeDiff seekable = gst_rtsp_media_seekable (media);
2530 GString *media_properties = g_string_new (NULL);
2533 g_string_append (media_properties,
2534 "No-Seeking,Time-Progressing,Time-Duration=0.0");
2535 else if (seekable == 0)
2536 g_string_append (media_properties, "Beginning-Only");
2537 else if (seekable == G_MAXINT64)
2538 g_string_append (media_properties, "Random-Access");
2540 g_string_append_printf (media_properties,
2541 "Random-Access=%f, Unlimited, Immutable",
2542 (gdouble) seekable / GST_SECOND);
2544 gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_MEDIA_PROPERTIES,
2545 g_string_free (media_properties, FALSE));
2546 /* TODO Check how Accept-Ranges should be filled */
2547 gst_rtsp_message_add_header (ctx->request, GST_RTSP_HDR_ACCEPT_RANGES,
2548 "npt, clock, smpte, clock");
2551 send_message (client, ctx, ctx->response, FALSE);
2553 /* update the state */
2554 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
2555 switch (rtspstate) {
2556 case GST_RTSP_STATE_PLAYING:
2557 case GST_RTSP_STATE_RECORDING:
2558 case GST_RTSP_STATE_READY:
2559 /* no state change */
2562 gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_READY);
2565 g_object_unref (media);
2566 g_object_unref (session);
2569 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST], 0, ctx);
2576 GST_ERROR ("client %p: no uri", client);
2577 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
2582 GST_ERROR ("client %p: no transport", client);
2583 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
2588 GST_ERROR ("client %p: no session pool configured", client);
2589 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
2592 media_not_found_no_reply:
2594 GST_ERROR ("client %p: media '%s' not found", client, path);
2595 /* error reply is already sent */
2596 goto cleanup_session;
2600 GST_ERROR ("client %p: media '%s' not found", client, path);
2601 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
2602 goto cleanup_session;
2606 GST_ERROR ("client %p: no control in path '%s'", client, path);
2607 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
2608 g_object_unref (media);
2609 goto cleanup_session;
2613 GST_ERROR ("client %p: stream '%s' not found", client,
2614 GST_STR_NULL (control));
2615 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
2616 g_object_unref (media);
2617 goto cleanup_session;
2621 GST_ERROR ("client %p: pre signal returned error: %s", client,
2622 gst_rtsp_status_as_text (sig_result));
2623 send_generic_response (client, sig_result, ctx);
2624 g_object_unref (media);
2627 service_unavailable:
2629 GST_ERROR ("client %p: can't create session", client);
2630 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
2631 g_object_unref (media);
2632 goto cleanup_session;
2634 sessmedia_unavailable:
2636 GST_ERROR ("client %p: can't create session media", client);
2637 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
2638 goto cleanup_transport;
2640 configure_media_failed_no_reply:
2642 GST_ERROR ("client %p: configure_media failed", client);
2643 g_object_unref (media);
2644 /* error reply is already sent */
2645 goto cleanup_session;
2647 unsupported_transports:
2649 GST_ERROR ("client %p: unsupported transports", client);
2650 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
2651 goto cleanup_transport;
2653 unsupported_client_transport:
2655 GST_ERROR ("client %p: unsupported client transport", client);
2656 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
2657 goto cleanup_transport;
2661 GST_ERROR ("client %p: unsupported mode (media play: %d, media record: %d, "
2662 "mode play: %d, mode record: %d)", client,
2663 ! !(gst_rtsp_media_get_transport_mode (media) &
2664 GST_RTSP_TRANSPORT_MODE_PLAY),
2665 ! !(gst_rtsp_media_get_transport_mode (media) &
2666 GST_RTSP_TRANSPORT_MODE_RECORD), ct->mode_play, ct->mode_record);
2667 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
2668 goto cleanup_transport;
2670 unsupported_range_unit:
2672 GST_ERROR ("Client %p: does not support any range format we support",
2674 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, ctx);
2675 goto cleanup_transport;
2679 GST_ERROR ("client %p: keymgmt error", client);
2680 send_generic_response (client, GST_RTSP_STS_KEY_MANAGEMENT_FAILURE, ctx);
2681 goto cleanup_transport;
2685 gst_rtsp_transport_free (ct);
2687 g_object_unref (media);
2690 gst_rtsp_session_pool_remove (priv->session_pool, session);
2692 g_object_unref (session);
2699 static GstSDPMessage *
2700 create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
2702 GstRTSPClientPrivate *priv = client->priv;
2706 guint64 session_id_tmp;
2707 gchar session_id[21];
2709 gst_sdp_message_new (&sdp);
2711 /* some standard things first */
2712 gst_sdp_message_set_version (sdp, "0");
2719 session_id_tmp = (((guint64) g_random_int ()) << 32) | g_random_int ();
2720 g_snprintf (session_id, sizeof (session_id), "%" G_GUINT64_FORMAT,
2723 gst_sdp_message_set_origin (sdp, "-", session_id, "1", "IN", proto,
2726 gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
2727 gst_sdp_message_set_information (sdp, "rtsp-server");
2728 gst_sdp_message_add_time (sdp, "0", "0", NULL);
2729 gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
2730 gst_sdp_message_add_attribute (sdp, "type", "broadcast");
2731 gst_sdp_message_add_attribute (sdp, "control", "*");
2733 info.is_ipv6 = priv->is_ipv6;
2734 info.server_ip = priv->server_ip;
2736 /* create an SDP for the media object */
2737 if (!gst_rtsp_media_setup_sdp (media, sdp, &info))
2745 GST_ERROR ("client %p: could not create SDP", client);
2746 gst_sdp_message_free (sdp);
2751 /* for the describe we must generate an SDP */
2753 handle_describe_request (GstRTSPClient * client, GstRTSPContext * ctx)
2755 GstRTSPClientPrivate *priv = client->priv;
2760 GstRTSPMedia *media;
2761 GstRTSPClientClass *klass;
2762 GstRTSPStatusCode sig_result;
2764 klass = GST_RTSP_CLIENT_GET_CLASS (client);
2769 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_DESCRIBE_REQUEST],
2770 0, ctx, &sig_result);
2771 if (sig_result != GST_RTSP_STS_OK) {
2775 /* check what kind of format is accepted, we don't really do anything with it
2776 * and always return SDP for now. */
2781 gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_ACCEPT,
2783 if (res == GST_RTSP_ENOTIMPL)
2786 if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
2790 if (!priv->mount_points)
2791 goto no_mount_points;
2793 if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
2796 /* find the media object for the uri */
2797 if (!(media = find_media (client, ctx, path, NULL)))
2800 if (!(gst_rtsp_media_get_transport_mode (media) &
2801 GST_RTSP_TRANSPORT_MODE_PLAY))
2802 goto unsupported_mode;
2804 /* create an SDP for the media object on this client */
2805 if (!(sdp = klass->create_sdp (client, media)))
2808 /* we suspend after the describe */
2809 gst_rtsp_media_suspend (media);
2810 g_object_unref (media);
2812 gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
2813 gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
2815 gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_CONTENT_TYPE,
2818 /* content base for some clients that might screw up creating the setup uri */
2819 str = make_base_url (client, ctx->uri, path);
2822 GST_INFO ("adding content-base: %s", str);
2823 gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_CONTENT_BASE, str);
2825 /* add SDP to the response body */
2826 str = gst_sdp_message_as_text (sdp);
2827 gst_rtsp_message_take_body (ctx->response, (guint8 *) str, strlen (str));
2828 gst_sdp_message_free (sdp);
2830 send_message (client, ctx, ctx->response, FALSE);
2832 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST],
2840 GST_ERROR ("client %p: pre signal returned error: %s", client,
2841 gst_rtsp_status_as_text (sig_result));
2842 send_generic_response (client, sig_result, ctx);
2847 GST_ERROR ("client %p: no uri", client);
2848 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
2853 GST_ERROR ("client %p: no mount points configured", client);
2854 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
2859 GST_ERROR ("client %p: can't find path for url", client);
2860 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
2865 GST_ERROR ("client %p: no media", client);
2867 /* error reply is already sent */
2872 GST_ERROR ("client %p: media does not support DESCRIBE", client);
2873 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
2875 g_object_unref (media);
2880 GST_ERROR ("client %p: can't create SDP", client);
2881 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
2883 g_object_unref (media);
2889 handle_sdp (GstRTSPClient * client, GstRTSPContext * ctx, GstRTSPMedia * media,
2890 GstSDPMessage * sdp)
2892 GstRTSPClientPrivate *priv = client->priv;
2893 GstRTSPThread *thread;
2895 /* create an SDP for the media object */
2896 if (!gst_rtsp_media_handle_sdp (media, sdp))
2899 thread = gst_rtsp_thread_pool_get_thread (priv->thread_pool,
2900 GST_RTSP_THREAD_TYPE_MEDIA, ctx);
2904 /* prepare the media */
2905 if (!gst_rtsp_media_prepare (media, thread))
2913 GST_ERROR ("client %p: could not handle SDP", client);
2918 GST_ERROR ("client %p: can't create thread", client);
2923 GST_ERROR ("client %p: can't prepare media", client);
2929 handle_announce_request (GstRTSPClient * client, GstRTSPContext * ctx)
2931 GstRTSPClientPrivate *priv = client->priv;
2932 GstRTSPClientClass *klass;
2935 GstRTSPMedia *media;
2936 gchar *path, *cont = NULL;
2939 GstRTSPStatusCode sig_result;
2942 klass = GST_RTSP_CLIENT_GET_CLASS (client);
2947 if (!priv->mount_points)
2948 goto no_mount_points;
2950 /* check if reply is SDP */
2951 gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_CONTENT_TYPE, &cont,
2953 /* could not be set but since the request returned OK, we assume it
2954 * was SDP, else check it. */
2956 if (g_ascii_strcasecmp (cont, "application/sdp") != 0)
2957 goto wrong_content_type;
2960 /* get message body and parse as SDP */
2961 gst_rtsp_message_get_body (ctx->request, &data, &size);
2962 if (data == NULL || size == 0)
2965 GST_DEBUG ("client %p: parse SDP...", client);
2966 gst_sdp_message_new (&sdp);
2967 sres = gst_sdp_message_parse_buffer (data, size, sdp);
2968 if (sres != GST_SDP_OK)
2969 goto sdp_parse_failed;
2971 if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
2974 /* find the media object for the uri */
2975 if (!(media = find_media (client, ctx, path, NULL)))
2980 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_ANNOUNCE_REQUEST],
2981 0, ctx, &sig_result);
2982 if (sig_result != GST_RTSP_STS_OK) {
2986 if (!(gst_rtsp_media_get_transport_mode (media) &
2987 GST_RTSP_TRANSPORT_MODE_RECORD))
2988 goto unsupported_mode;
2990 /* Tell client subclass about the media */
2991 if (!klass->handle_sdp (client, ctx, media, sdp))
2994 gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
2995 gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
2997 n_streams = gst_rtsp_media_n_streams (media);
2998 for (i = 0; i < n_streams; i++) {
2999 GstRTSPStream *stream = gst_rtsp_media_get_stream (media, i);
3001 g_strdup_printf ("rtsp://%s%s:8554/stream=%d", priv->server_ip, path,
3003 gchar *keymgmt = stream_make_keymgmt (client, location, stream);
3006 gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_KEYMGMT,
3012 /* we suspend after the announce */
3013 gst_rtsp_media_suspend (media);
3014 g_object_unref (media);
3016 send_message (client, ctx, ctx->response, FALSE);
3018 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_ANNOUNCE_REQUEST],
3021 gst_sdp_message_free (sdp);
3027 GST_ERROR ("client %p: no uri", client);
3028 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
3033 GST_ERROR ("client %p: no mount points configured", client);
3034 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
3039 GST_ERROR ("client %p: can't find path for url", client);
3040 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
3041 gst_sdp_message_free (sdp);
3046 GST_ERROR ("client %p: unknown content type", client);
3047 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
3052 GST_ERROR ("client %p: can't find SDP message", client);
3053 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
3058 GST_ERROR ("client %p: failed to parse SDP message", client);
3059 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
3060 gst_sdp_message_free (sdp);
3065 GST_ERROR ("client %p: no media", client);
3067 /* error reply is already sent */
3068 gst_sdp_message_free (sdp);
3073 GST_ERROR ("client %p: pre signal returned error: %s", client,
3074 gst_rtsp_status_as_text (sig_result));
3075 send_generic_response (client, sig_result, ctx);
3076 gst_sdp_message_free (sdp);
3081 GST_ERROR ("client %p: media does not support ANNOUNCE", client);
3082 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
3084 g_object_unref (media);
3085 gst_sdp_message_free (sdp);
3090 GST_ERROR ("client %p: can't handle SDP", client);
3091 send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_MEDIA_TYPE, ctx);
3093 g_object_unref (media);
3094 gst_sdp_message_free (sdp);
3100 handle_record_request (GstRTSPClient * client, GstRTSPContext * ctx)
3102 GstRTSPSession *session;
3103 GstRTSPClientClass *klass;
3104 GstRTSPSessionMedia *sessmedia;
3105 GstRTSPMedia *media;
3107 GstRTSPState rtspstate;
3110 GstRTSPStatusCode sig_result;
3111 GPtrArray *transports;
3113 if (!(session = ctx->session))
3116 if (!(uri = ctx->uri))
3119 klass = GST_RTSP_CLIENT_GET_CLASS (client);
3120 path = klass->make_path_from_uri (client, uri);
3122 /* get a handle to the configuration of the media in the session */
3123 sessmedia = gst_rtsp_session_get_media (session, path, &matched);
3127 if (path[matched] != '\0')
3132 ctx->sessmedia = sessmedia;
3133 ctx->media = media = gst_rtsp_session_media_get_media (sessmedia);
3135 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_RECORD_REQUEST], 0,
3137 if (sig_result != GST_RTSP_STS_OK) {
3141 if (!(gst_rtsp_media_get_transport_mode (media) &
3142 GST_RTSP_TRANSPORT_MODE_RECORD))
3143 goto unsupported_mode;
3145 /* the session state must be playing or ready */
3146 rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
3147 if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
3150 /* update the pipeline */
3151 transports = gst_rtsp_session_media_get_transports (sessmedia);
3152 if (!gst_rtsp_media_complete_pipeline (media, transports)) {
3153 g_ptr_array_unref (transports);
3154 goto pipeline_error;
3156 g_ptr_array_unref (transports);
3158 /* in record we first unsuspend, media could be suspended from SDP or PAUSED */
3159 if (!gst_rtsp_media_unsuspend (media))
3160 goto unsuspend_failed;
3162 gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
3163 gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
3165 send_message (client, ctx, ctx->response, FALSE);
3167 /* start playing after sending the response */
3168 gst_rtsp_session_media_set_state (sessmedia, GST_STATE_PLAYING);
3170 gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_PLAYING);
3172 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_RECORD_REQUEST], 0,
3180 GST_ERROR ("client %p: no session", client);
3181 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
3186 GST_ERROR ("client %p: no uri supplied", client);
3187 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
3192 GST_ERROR ("client %p: media not found", client);
3193 send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
3198 GST_ERROR ("client %p: no aggregate path %s", client, path);
3199 send_generic_response (client,
3200 GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
3206 GST_ERROR ("client %p: pre signal returned error: %s", client,
3207 gst_rtsp_status_as_text (sig_result));
3208 send_generic_response (client, sig_result, ctx);
3213 GST_ERROR ("client %p: media does not support RECORD", client);
3214 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
3219 GST_ERROR ("client %p: not PLAYING or READY", client);
3220 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
3226 GST_ERROR ("client %p: failed to configure the pipeline", client);
3227 send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
3233 GST_ERROR ("client %p: unsuspend failed", client);
3234 send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
3240 handle_options_request (GstRTSPClient * client, GstRTSPContext * ctx,
3241 GstRTSPVersion version)
3243 GstRTSPMethod options;
3245 GstRTSPStatusCode sig_result;
3247 options = GST_RTSP_DESCRIBE |
3252 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN;
3254 if (version < GST_RTSP_VERSION_2_0) {
3255 options |= GST_RTSP_RECORD;
3256 options |= GST_RTSP_ANNOUNCE;
3259 str = gst_rtsp_options_as_text (options);
3261 gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
3262 gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
3264 gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_PUBLIC, str);
3267 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_OPTIONS_REQUEST], 0,
3269 if (sig_result != GST_RTSP_STS_OK) {
3273 send_message (client, ctx, ctx->response, FALSE);
3275 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST],
3283 GST_ERROR ("client %p: pre signal returned error: %s", client,
3284 gst_rtsp_status_as_text (sig_result));
3285 send_generic_response (client, sig_result, ctx);
3286 gst_rtsp_message_free (ctx->response);
3291 /* remove duplicate and trailing '/' */
3293 sanitize_uri (GstRTSPUrl * uri)
3297 gboolean have_slash, prev_slash;
3299 s = d = uri->abspath;
3300 len = strlen (uri->abspath);
3304 for (i = 0; i < len; i++) {
3305 have_slash = s[i] == '/';
3307 if (!have_slash || !prev_slash)
3309 prev_slash = have_slash;
3311 len = d - uri->abspath;
3312 /* don't remove the first slash if that's the only thing left */
3313 if (len > 1 && *(d - 1) == '/')
3318 /* is called when the session is removed from its session pool. */
3320 client_session_removed (GstRTSPSessionPool * pool, GstRTSPSession * session,
3321 GstRTSPClient * client)
3323 GstRTSPClientPrivate *priv = client->priv;
3325 GST_INFO ("client %p: session %p removed", client, session);
3327 g_mutex_lock (&priv->lock);
3328 client_unwatch_session (client, session, NULL);
3329 g_mutex_unlock (&priv->lock);
3332 /* Check for Require headers. Returns TRUE if there are no Require headers,
3333 * otherwise lets the application decide which headers are supported.
3334 * By default all headers are unsupported.
3335 * If there are unsupported options, FALSE will be returned together with
3336 * a newly-allocated string of (comma-separated) unsupported options in
3337 * the unsupported_reqs variable.
3339 * There may be multiple Require headers, but we must send one single
3340 * Unsupported header with all the unsupported options as response. If
3341 * an incoming Require header contained a comma-separated list of options
3342 * GstRtspConnection will already have split that list up into multiple
3346 check_request_requirements (GstRTSPContext * ctx, gchar ** unsupported_reqs)
3349 GPtrArray *arr = NULL;
3350 GstRTSPMessage *msg = ctx->request;
3353 gchar *sig_result = NULL;
3354 gboolean result = TRUE;
3358 res = gst_rtsp_message_get_header (msg, GST_RTSP_HDR_REQUIRE, &reqs, i++);
3360 if (res == GST_RTSP_ENOTIMPL)
3364 arr = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
3366 g_ptr_array_add (arr, g_strdup (reqs));
3370 /* if we don't have any Require headers at all, all is fine */
3374 /* otherwise we've now processed at all the Require headers */
3375 g_ptr_array_add (arr, NULL);
3377 g_signal_emit (ctx->client,
3378 gst_rtsp_client_signals[SIGNAL_CHECK_REQUIREMENTS], 0, ctx,
3379 (gchar **) arr->pdata, &sig_result);
3381 if (sig_result == NULL) {
3382 /* no supported options, just report all of the required ones as
3384 *unsupported_reqs = g_strjoinv (", ", (gchar **) arr->pdata);
3389 if (strlen (sig_result) == 0)
3390 g_free (sig_result);
3392 *unsupported_reqs = sig_result;
3397 g_ptr_array_unref (arr);
3402 handle_request (GstRTSPClient * client, GstRTSPMessage * request)
3404 GstRTSPClientPrivate *priv = client->priv;
3405 GstRTSPMethod method;
3406 const gchar *uristr;
3407 GstRTSPUrl *uri = NULL;
3408 GstRTSPVersion version;
3410 GstRTSPSession *session = NULL;
3411 GstRTSPContext sctx = { NULL }, *ctx;
3412 GstRTSPMessage response = { 0 };
3413 gchar *unsupported_reqs = NULL;
3414 gchar *sessid = NULL, *pipelined_request_id = NULL;
3416 if (!(ctx = gst_rtsp_context_get_current ())) {
3418 ctx->auth = priv->auth;
3419 gst_rtsp_context_push_current (ctx);
3422 ctx->conn = priv->connection;
3423 ctx->client = client;
3424 ctx->request = request;
3425 ctx->response = &response;
3427 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
3428 gst_rtsp_message_dump (request);
3431 gst_rtsp_message_parse_request (request, &method, &uristr, &version);
3433 GST_INFO ("client %p: received a request %s %s %s", client,
3434 gst_rtsp_method_as_text (method), uristr,
3435 gst_rtsp_version_as_text (version));
3437 /* we can only handle 1.0 requests */
3438 if (version != GST_RTSP_VERSION_1_0 && version != GST_RTSP_VERSION_2_0)
3441 ctx->method = method;
3443 /* we always try to parse the url first */
3444 if (strcmp (uristr, "*") == 0) {
3445 /* special case where we have * as uri, keep uri = NULL */
3446 } else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) {
3447 /* check if the uristr is an absolute path <=> scheme and host information
3451 scheme = g_uri_parse_scheme (uristr);
3452 if (scheme == NULL && g_str_has_prefix (uristr, "/")) {
3453 gchar *absolute_uristr = NULL;
3455 GST_WARNING_OBJECT (client, "request doesn't contain absolute url");
3456 if (priv->server_ip == NULL) {
3457 GST_WARNING_OBJECT (client, "host information missing");
3462 g_strdup_printf ("rtsp://%s%s", priv->server_ip, uristr);
3464 GST_DEBUG_OBJECT (client, "absolute url: %s", absolute_uristr);
3465 if (gst_rtsp_url_parse (absolute_uristr, &uri) != GST_RTSP_OK) {
3466 g_free (absolute_uristr);
3469 g_free (absolute_uristr);
3476 /* get the session if there is any */
3477 res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_PIPELINED_REQUESTS,
3478 &pipelined_request_id, 0);
3479 if (res == GST_RTSP_OK) {
3480 sessid = g_hash_table_lookup (client->priv->pipelined_requests,
3481 pipelined_request_id);
3484 res = GST_RTSP_ERROR;
3487 if (res != GST_RTSP_OK)
3489 gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
3491 if (res == GST_RTSP_OK) {
3492 if (priv->session_pool == NULL)
3495 /* we had a session in the request, find it again */
3496 if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid)))
3497 goto session_not_found;
3499 /* we add the session to the client list of watched sessions. When a session
3500 * disappears because it times out, we will be notified. If all sessions are
3501 * gone, we will close the connection */
3502 client_watch_session (client, session);
3505 /* sanitize the uri */
3509 ctx->session = session;
3511 if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_URL))
3512 goto not_authorized;
3514 /* handle any 'Require' headers */
3515 if (!check_request_requirements (ctx, &unsupported_reqs))
3516 goto unsupported_requirement;
3518 /* now see what is asked and dispatch to a dedicated handler */
3520 case GST_RTSP_OPTIONS:
3521 priv->version = version;
3522 handle_options_request (client, ctx, version);
3524 case GST_RTSP_DESCRIBE:
3525 handle_describe_request (client, ctx);
3527 case GST_RTSP_SETUP:
3528 handle_setup_request (client, ctx);
3531 handle_play_request (client, ctx);
3533 case GST_RTSP_PAUSE:
3534 handle_pause_request (client, ctx);
3536 case GST_RTSP_TEARDOWN:
3537 handle_teardown_request (client, ctx);
3539 case GST_RTSP_SET_PARAMETER:
3540 handle_set_param_request (client, ctx);
3542 case GST_RTSP_GET_PARAMETER:
3543 handle_get_param_request (client, ctx);
3545 case GST_RTSP_ANNOUNCE:
3546 if (version >= GST_RTSP_VERSION_2_0)
3547 goto invalid_command_for_version;
3548 handle_announce_request (client, ctx);
3550 case GST_RTSP_RECORD:
3551 if (version >= GST_RTSP_VERSION_2_0)
3552 goto invalid_command_for_version;
3553 handle_record_request (client, ctx);
3555 case GST_RTSP_REDIRECT:
3556 goto not_implemented;
3557 case GST_RTSP_INVALID:
3564 gst_rtsp_context_pop_current (ctx);
3566 g_object_unref (session);
3568 gst_rtsp_url_free (uri);
3574 GST_ERROR ("client %p: version %d not supported", client, version);
3575 send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
3579 invalid_command_for_version:
3581 GST_ERROR ("client %p: invalid command for version", client);
3582 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
3587 GST_ERROR ("client %p: bad request", client);
3588 send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
3593 GST_ERROR ("client %p: no pool configured", client);
3594 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
3599 GST_ERROR ("client %p: session not found", client);
3600 send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
3605 GST_ERROR ("client %p: not allowed", client);
3606 /* error reply is already sent */
3609 unsupported_requirement:
3611 GST_ERROR ("client %p: Required option is not supported (%s)", client,
3613 send_option_not_supported_response (client, ctx, unsupported_reqs);
3614 g_free (unsupported_reqs);
3619 GST_ERROR ("client %p: method %d not implemented", client, method);
3620 send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, ctx);
3627 handle_response (GstRTSPClient * client, GstRTSPMessage * response)
3629 GstRTSPClientPrivate *priv = client->priv;
3631 GstRTSPSession *session = NULL;
3632 GstRTSPContext sctx = { NULL }, *ctx;
3635 if (!(ctx = gst_rtsp_context_get_current ())) {
3637 ctx->auth = priv->auth;
3638 gst_rtsp_context_push_current (ctx);
3641 ctx->conn = priv->connection;
3642 ctx->client = client;
3643 ctx->request = NULL;
3645 ctx->method = GST_RTSP_INVALID;
3646 ctx->response = response;
3648 if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
3649 gst_rtsp_message_dump (response);
3652 GST_INFO ("client %p: received a response", client);
3654 /* get the session if there is any */
3656 gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION, &sessid, 0);
3657 if (res == GST_RTSP_OK) {
3658 if (priv->session_pool == NULL)
3661 /* we had a session in the request, find it again */
3662 if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid)))
3663 goto session_not_found;
3665 /* we add the session to the client list of watched sessions. When a session
3666 * disappears because it times out, we will be notified. If all sessions are
3667 * gone, we will close the connection */
3668 client_watch_session (client, session);
3671 ctx->session = session;
3673 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_HANDLE_RESPONSE],
3678 gst_rtsp_context_pop_current (ctx);
3680 g_object_unref (session);
3685 GST_ERROR ("client %p: no pool configured", client);
3690 GST_ERROR ("client %p: session not found", client);
3696 handle_data (GstRTSPClient * client, GstRTSPMessage * message)
3698 GstRTSPClientPrivate *priv = client->priv;
3704 GstRTSPStreamTransport *trans;
3706 /* find the stream for this message */
3707 res = gst_rtsp_message_parse_data (message, &channel);
3708 if (res != GST_RTSP_OK)
3711 gst_rtsp_message_get_body (message, &data, &size);
3713 goto invalid_length;
3715 gst_rtsp_message_steal_body (message, &data, &size);
3717 /* Strip trailing \0 (which GstRTSPConnection adds) */
3720 buffer = gst_buffer_new_wrapped (data, size);
3723 g_hash_table_lookup (priv->transports, GINT_TO_POINTER ((gint) channel));
3725 GSocketAddress *addr;
3727 /* Only create the socket address once for the transport, we don't really
3728 * want to do that for every single packet.
3730 * The netaddress meta is later used by the RTP stack to know where
3731 * packets came from and allows us to match it again to a stream transport
3733 * In theory we could use the remote socket address of the RTSP connection
3734 * here, but this would fail with a custom configure_client_transport()
3738 g_object_get_data (G_OBJECT (trans), "rtsp-client.remote-addr"))) {
3739 const GstRTSPTransport *tr;
3740 GInetAddress *iaddr;
3742 tr = gst_rtsp_stream_transport_get_transport (trans);
3743 iaddr = g_inet_address_new_from_string (tr->destination);
3745 addr = g_inet_socket_address_new (iaddr, tr->client_port.min);
3746 g_object_unref (iaddr);
3747 g_object_set_data_full (G_OBJECT (trans), "rtsp-client.remote-addr",
3748 addr, (GDestroyNotify) g_object_unref);
3753 gst_buffer_add_net_address_meta (buffer, addr);
3756 /* dispatch to the stream based on the channel number */
3757 GST_LOG_OBJECT (client, "%u bytes of data on channel %u", size, channel);
3758 gst_rtsp_stream_transport_recv_data (trans, channel, buffer);
3760 GST_DEBUG_OBJECT (client, "received %u bytes of data for "
3761 "unknown channel %u", size, channel);
3762 gst_buffer_unref (buffer);
3770 GST_DEBUG ("client %p: Short message received, ignoring", client);
3776 * gst_rtsp_client_set_session_pool:
3777 * @client: a #GstRTSPClient
3778 * @pool: (transfer none) (nullable): a #GstRTSPSessionPool
3780 * Set @pool as the sessionpool for @client which it will use to find
3781 * or allocate sessions. the sessionpool is usually inherited from the server
3782 * that created the client but can be overridden later.
3785 gst_rtsp_client_set_session_pool (GstRTSPClient * client,
3786 GstRTSPSessionPool * pool)
3788 GstRTSPSessionPool *old;
3789 GstRTSPClientPrivate *priv;
3791 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
3793 priv = client->priv;
3796 g_object_ref (pool);
3798 g_mutex_lock (&priv->lock);
3799 old = priv->session_pool;
3800 priv->session_pool = pool;
3802 if (priv->session_removed_id) {
3803 g_signal_handler_disconnect (old, priv->session_removed_id);
3804 priv->session_removed_id = 0;
3806 g_mutex_unlock (&priv->lock);
3808 /* FIXME, should remove all sessions from the old pool for this client */
3810 g_object_unref (old);
3814 * gst_rtsp_client_get_session_pool:
3815 * @client: a #GstRTSPClient
3817 * Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
3819 * Returns: (transfer full) (nullable): a #GstRTSPSessionPool, unref after usage.
3821 GstRTSPSessionPool *
3822 gst_rtsp_client_get_session_pool (GstRTSPClient * client)
3824 GstRTSPClientPrivate *priv;
3825 GstRTSPSessionPool *result;
3827 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
3829 priv = client->priv;
3831 g_mutex_lock (&priv->lock);
3832 if ((result = priv->session_pool))
3833 g_object_ref (result);
3834 g_mutex_unlock (&priv->lock);
3840 * gst_rtsp_client_set_mount_points:
3841 * @client: a #GstRTSPClient
3842 * @mounts: (transfer none) (nullable): a #GstRTSPMountPoints
3844 * Set @mounts as the mount points for @client which it will use to map urls
3845 * to media streams. These mount points are usually inherited from the server that
3846 * created the client but can be overriden later.
3849 gst_rtsp_client_set_mount_points (GstRTSPClient * client,
3850 GstRTSPMountPoints * mounts)
3852 GstRTSPClientPrivate *priv;
3853 GstRTSPMountPoints *old;
3855 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
3857 priv = client->priv;
3860 g_object_ref (mounts);
3862 g_mutex_lock (&priv->lock);
3863 old = priv->mount_points;
3864 priv->mount_points = mounts;
3865 g_mutex_unlock (&priv->lock);
3868 g_object_unref (old);
3872 * gst_rtsp_client_get_mount_points:
3873 * @client: a #GstRTSPClient
3875 * Get the #GstRTSPMountPoints object that @client uses to manage its sessions.
3877 * Returns: (transfer full) (nullable): a #GstRTSPMountPoints, unref after usage.
3879 GstRTSPMountPoints *
3880 gst_rtsp_client_get_mount_points (GstRTSPClient * client)
3882 GstRTSPClientPrivate *priv;
3883 GstRTSPMountPoints *result;
3885 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
3887 priv = client->priv;
3889 g_mutex_lock (&priv->lock);
3890 if ((result = priv->mount_points))
3891 g_object_ref (result);
3892 g_mutex_unlock (&priv->lock);
3898 * gst_rtsp_client_set_auth:
3899 * @client: a #GstRTSPClient
3900 * @auth: (transfer none) (nullable): a #GstRTSPAuth
3902 * configure @auth to be used as the authentication manager of @client.
3905 gst_rtsp_client_set_auth (GstRTSPClient * client, GstRTSPAuth * auth)
3907 GstRTSPClientPrivate *priv;
3910 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
3912 priv = client->priv;
3915 g_object_ref (auth);
3917 g_mutex_lock (&priv->lock);
3920 g_mutex_unlock (&priv->lock);
3923 g_object_unref (old);
3928 * gst_rtsp_client_get_auth:
3929 * @client: a #GstRTSPClient
3931 * Get the #GstRTSPAuth used as the authentication manager of @client.
3933 * Returns: (transfer full) (nullable): the #GstRTSPAuth of @client.
3934 * g_object_unref() after usage.
3937 gst_rtsp_client_get_auth (GstRTSPClient * client)
3939 GstRTSPClientPrivate *priv;
3940 GstRTSPAuth *result;
3942 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
3944 priv = client->priv;
3946 g_mutex_lock (&priv->lock);
3947 if ((result = priv->auth))
3948 g_object_ref (result);
3949 g_mutex_unlock (&priv->lock);
3955 * gst_rtsp_client_set_thread_pool:
3956 * @client: a #GstRTSPClient
3957 * @pool: (transfer none) (nullable): a #GstRTSPThreadPool
3959 * configure @pool to be used as the thread pool of @client.
3962 gst_rtsp_client_set_thread_pool (GstRTSPClient * client,
3963 GstRTSPThreadPool * pool)
3965 GstRTSPClientPrivate *priv;
3966 GstRTSPThreadPool *old;
3968 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
3970 priv = client->priv;
3973 g_object_ref (pool);
3975 g_mutex_lock (&priv->lock);
3976 old = priv->thread_pool;
3977 priv->thread_pool = pool;
3978 g_mutex_unlock (&priv->lock);
3981 g_object_unref (old);
3985 * gst_rtsp_client_get_thread_pool:
3986 * @client: a #GstRTSPClient
3988 * Get the #GstRTSPThreadPool used as the thread pool of @client.
3990 * Returns: (transfer full) (nullable): the #GstRTSPThreadPool of @client. g_object_unref() after
3994 gst_rtsp_client_get_thread_pool (GstRTSPClient * client)
3996 GstRTSPClientPrivate *priv;
3997 GstRTSPThreadPool *result;
3999 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
4001 priv = client->priv;
4003 g_mutex_lock (&priv->lock);
4004 if ((result = priv->thread_pool))
4005 g_object_ref (result);
4006 g_mutex_unlock (&priv->lock);
4012 * gst_rtsp_client_set_connection:
4013 * @client: a #GstRTSPClient
4014 * @conn: (transfer full): a #GstRTSPConnection
4016 * Set the #GstRTSPConnection of @client. This function takes ownership of
4019 * Returns: %TRUE on success.
4022 gst_rtsp_client_set_connection (GstRTSPClient * client,
4023 GstRTSPConnection * conn)
4025 GstRTSPClientPrivate *priv;
4026 GSocket *read_socket;
4027 GSocketAddress *address;
4029 GError *error = NULL;
4031 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
4032 g_return_val_if_fail (conn != NULL, FALSE);
4034 priv = client->priv;
4036 read_socket = gst_rtsp_connection_get_read_socket (conn);
4038 if (!(address = g_socket_get_local_address (read_socket, &error)))
4041 g_free (priv->server_ip);
4042 /* keep the original ip that the client connected to */
4043 if (G_IS_INET_SOCKET_ADDRESS (address)) {
4044 GInetAddress *iaddr;
4046 iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address));
4048 /* socket might be ipv6 but adress still ipv4 */
4049 priv->is_ipv6 = g_inet_address_get_family (iaddr) == G_SOCKET_FAMILY_IPV6;
4050 priv->server_ip = g_inet_address_to_string (iaddr);
4051 g_object_unref (address);
4053 priv->is_ipv6 = g_socket_get_family (read_socket) == G_SOCKET_FAMILY_IPV6;
4054 priv->server_ip = g_strdup ("unknown");
4057 GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
4058 priv->server_ip, priv->is_ipv6);
4060 url = gst_rtsp_connection_get_url (conn);
4061 GST_INFO ("added new client %p ip %s:%d", client, url->host, url->port);
4063 priv->connection = conn;
4070 GST_ERROR ("could not get local address %s", error->message);
4071 g_error_free (error);
4077 * gst_rtsp_client_get_connection:
4078 * @client: a #GstRTSPClient
4080 * Get the #GstRTSPConnection of @client.
4082 * Returns: (transfer none) (nullable): the #GstRTSPConnection of @client.
4083 * The connection object returned remains valid until the client is freed.
4086 gst_rtsp_client_get_connection (GstRTSPClient * client)
4088 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
4090 return client->priv->connection;
4094 * gst_rtsp_client_set_send_func:
4095 * @client: a #GstRTSPClient
4096 * @func: (scope notified): a #GstRTSPClientSendFunc
4097 * @user_data: (closure): user data passed to @func
4098 * @notify: (allow-none): called when @user_data is no longer in use
4100 * Set @func as the callback that will be called when a new message needs to be
4101 * sent to the client. @user_data is passed to @func and @notify is called when
4102 * @user_data is no longer in use.
4104 * By default, the client will send the messages on the #GstRTSPConnection that
4105 * was configured with gst_rtsp_client_attach() was called.
4108 gst_rtsp_client_set_send_func (GstRTSPClient * client,
4109 GstRTSPClientSendFunc func, gpointer user_data, GDestroyNotify notify)
4111 GstRTSPClientPrivate *priv;
4112 GDestroyNotify old_notify;
4115 g_return_if_fail (GST_IS_RTSP_CLIENT (client));
4117 priv = client->priv;
4119 g_mutex_lock (&priv->send_lock);
4120 priv->send_func = func;
4121 old_notify = priv->send_notify;
4122 old_data = priv->send_data;
4123 priv->send_notify = notify;
4124 priv->send_data = user_data;
4125 g_mutex_unlock (&priv->send_lock);
4128 old_notify (old_data);
4132 * gst_rtsp_client_handle_message:
4133 * @client: a #GstRTSPClient
4134 * @message: (transfer none): an #GstRTSPMessage
4136 * Let the client handle @message.
4138 * Returns: a #GstRTSPResult.
4141 gst_rtsp_client_handle_message (GstRTSPClient * client,
4142 GstRTSPMessage * message)
4144 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
4145 g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
4147 switch (message->type) {
4148 case GST_RTSP_MESSAGE_REQUEST:
4149 handle_request (client, message);
4151 case GST_RTSP_MESSAGE_RESPONSE:
4152 handle_response (client, message);
4154 case GST_RTSP_MESSAGE_DATA:
4155 handle_data (client, message);
4164 * gst_rtsp_client_send_message:
4165 * @client: a #GstRTSPClient
4166 * @session: (allow-none) (transfer none): a #GstRTSPSession to send
4167 * the message to or %NULL
4168 * @message: (transfer none): The #GstRTSPMessage to send
4170 * Send a message message to the remote end. @message must be a
4171 * #GST_RTSP_MESSAGE_REQUEST or a #GST_RTSP_MESSAGE_RESPONSE.
4174 gst_rtsp_client_send_message (GstRTSPClient * client, GstRTSPSession * session,
4175 GstRTSPMessage * message)
4177 GstRTSPContext sctx = { NULL }
4179 GstRTSPClientPrivate *priv;
4181 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
4182 g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
4183 g_return_val_if_fail (message->type == GST_RTSP_MESSAGE_REQUEST ||
4184 message->type == GST_RTSP_MESSAGE_RESPONSE, GST_RTSP_EINVAL);
4186 priv = client->priv;
4188 if (!(ctx = gst_rtsp_context_get_current ())) {
4190 ctx->auth = priv->auth;
4191 gst_rtsp_context_push_current (ctx);
4194 ctx->conn = priv->connection;
4195 ctx->client = client;
4196 ctx->session = session;
4198 send_message (client, ctx, message, FALSE);
4201 gst_rtsp_context_pop_current (ctx);
4207 do_send_message (GstRTSPClient * client, GstRTSPMessage * message,
4208 gboolean close, gpointer user_data)
4210 GstRTSPClientPrivate *priv = client->priv;
4214 /* send the message */
4215 ret = gst_rtsp_watch_send_message (priv->watch, message, &id);
4216 if (ret != GST_RTSP_OK)
4219 /* if close flag is set, store the seq number so we can wait until it's
4220 * written to the client to close the connection */
4222 priv->close_seq = id;
4224 if (gst_rtsp_message_get_type (message) == GST_RTSP_MESSAGE_DATA) {
4228 r = gst_rtsp_message_parse_data (message, &channel);
4229 if (r != GST_RTSP_OK) {
4234 /* check if the message has been queued for transmission in watch */
4236 /* store the seq number so we can wait until it has been sent */
4237 GST_DEBUG_OBJECT (client, "wait for message %d, channel %d", id, channel);
4238 set_data_seq (client, channel, id);
4240 GstRTSPStreamTransport *trans;
4243 g_hash_table_lookup (priv->transports,
4244 GINT_TO_POINTER ((gint) channel));
4246 GST_DEBUG_OBJECT (client, "emit 'message-sent' signal");
4247 g_mutex_unlock (&priv->send_lock);
4248 gst_rtsp_stream_transport_message_sent (trans);
4249 g_mutex_lock (&priv->send_lock);
4254 return ret == GST_RTSP_OK;
4259 GST_DEBUG_OBJECT (client, "got error %d", ret);
4264 static GstRTSPResult
4265 message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
4268 return gst_rtsp_client_handle_message (GST_RTSP_CLIENT (user_data), message);
4271 static GstRTSPResult
4272 message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
4274 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4275 GstRTSPClientPrivate *priv = client->priv;
4276 GstRTSPStreamTransport *trans = NULL;
4278 gboolean close = FALSE;
4280 g_mutex_lock (&priv->send_lock);
4282 if (get_data_channel (client, cseq, &channel)) {
4283 trans = g_hash_table_lookup (priv->transports, GINT_TO_POINTER (channel));
4284 set_data_seq (client, channel, 0);
4287 if (priv->close_seq && priv->close_seq == cseq) {
4288 GST_INFO ("client %p: send close message", client);
4290 priv->close_seq = 0;
4293 g_mutex_unlock (&priv->send_lock);
4296 GST_DEBUG_OBJECT (client, "emit 'message-sent' signal");
4297 gst_rtsp_stream_transport_message_sent (trans);
4301 gst_rtsp_client_close (client);
4306 static GstRTSPResult
4307 closed (GstRTSPWatch * watch, gpointer user_data)
4309 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4310 GstRTSPClientPrivate *priv = client->priv;
4311 const gchar *tunnelid;
4313 GST_INFO ("client %p: connection closed", client);
4315 if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
4316 g_mutex_lock (&tunnels_lock);
4317 /* remove from tunnelids */
4318 g_hash_table_remove (tunnels, tunnelid);
4319 g_mutex_unlock (&tunnels_lock);
4322 gst_rtsp_watch_set_flushing (watch, TRUE);
4323 g_mutex_lock (&priv->watch_lock);
4324 gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
4325 g_mutex_unlock (&priv->watch_lock);
4330 static GstRTSPResult
4331 error (GstRTSPWatch * watch, GstRTSPResult result, gpointer user_data)
4333 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4336 str = gst_rtsp_strresult (result);
4337 GST_INFO ("client %p: received an error %s", client, str);
4343 static GstRTSPResult
4344 error_full (GstRTSPWatch * watch, GstRTSPResult result,
4345 GstRTSPMessage * message, guint id, gpointer user_data)
4347 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4350 str = gst_rtsp_strresult (result);
4352 ("client %p: error when handling message %p with id %d: %s",
4353 client, message, id, str);
4360 remember_tunnel (GstRTSPClient * client)
4362 GstRTSPClientPrivate *priv = client->priv;
4363 const gchar *tunnelid;
4365 /* store client in the pending tunnels */
4366 tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
4367 if (tunnelid == NULL)
4370 GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
4372 /* we can't have two clients connecting with the same tunnelid */
4373 g_mutex_lock (&tunnels_lock);
4374 if (g_hash_table_lookup (tunnels, tunnelid))
4375 goto tunnel_existed;
4377 g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
4378 g_mutex_unlock (&tunnels_lock);
4385 GST_ERROR ("client %p: no tunnelid provided", client);
4390 g_mutex_unlock (&tunnels_lock);
4391 GST_ERROR ("client %p: tunnel session %s already existed", client,
4397 static GstRTSPResult
4398 tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
4400 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4401 GstRTSPClientPrivate *priv = client->priv;
4403 GST_WARNING ("client %p: tunnel lost (connection %p)", client,
4406 /* ignore error, it'll only be a problem when the client does a POST again */
4407 remember_tunnel (client);
4412 static GstRTSPStatusCode
4413 handle_tunnel (GstRTSPClient * client)
4415 GstRTSPClientPrivate *priv = client->priv;
4416 GstRTSPClient *oclient;
4417 GstRTSPClientPrivate *opriv;
4418 const gchar *tunnelid;
4420 tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
4421 if (tunnelid == NULL)
4424 /* check for previous tunnel */
4425 g_mutex_lock (&tunnels_lock);
4426 oclient = g_hash_table_lookup (tunnels, tunnelid);
4428 if (oclient == NULL) {
4429 /* no previous tunnel, remember tunnel */
4430 g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
4431 g_mutex_unlock (&tunnels_lock);
4433 GST_INFO ("client %p: no previous tunnel found, remembering tunnel (%p)",
4434 client, priv->connection);
4436 /* merge both tunnels into the first client */
4437 /* remove the old client from the table. ref before because removing it will
4438 * remove the ref to it. */
4439 g_object_ref (oclient);
4440 g_hash_table_remove (tunnels, tunnelid);
4441 g_mutex_unlock (&tunnels_lock);
4443 opriv = oclient->priv;
4445 g_mutex_lock (&opriv->watch_lock);
4446 if (opriv->watch == NULL)
4448 if (opriv->tstate == priv->tstate)
4449 goto tunnel_duplicate_id;
4451 GST_INFO ("client %p: found previous tunnel %p (old %p, new %p)", client,
4452 oclient, opriv->connection, priv->connection);
4454 gst_rtsp_connection_do_tunnel (opriv->connection, priv->connection);
4455 gst_rtsp_watch_reset (priv->watch);
4456 gst_rtsp_watch_reset (opriv->watch);
4457 g_mutex_unlock (&opriv->watch_lock);
4458 g_object_unref (oclient);
4460 /* the old client owns the tunnel now, the new one will be freed */
4461 g_source_destroy ((GSource *) priv->watch);
4463 gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
4466 return GST_RTSP_STS_OK;
4471 GST_ERROR ("client %p: no tunnelid provided", client);
4472 return GST_RTSP_STS_SERVICE_UNAVAILABLE;
4476 GST_ERROR ("client %p: tunnel session %s was closed", client, tunnelid);
4477 g_mutex_unlock (&opriv->watch_lock);
4478 g_object_unref (oclient);
4479 return GST_RTSP_STS_SERVICE_UNAVAILABLE;
4481 tunnel_duplicate_id:
4483 GST_ERROR ("client %p: tunnel session %s was duplicate", client, tunnelid);
4484 g_mutex_unlock (&opriv->watch_lock);
4485 g_object_unref (oclient);
4486 return GST_RTSP_STS_BAD_REQUEST;
4490 static GstRTSPStatusCode
4491 tunnel_get (GstRTSPWatch * watch, gpointer user_data)
4493 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4495 GST_INFO ("client %p: tunnel get (connection %p)", client,
4496 client->priv->connection);
4498 g_mutex_lock (&client->priv->lock);
4499 client->priv->tstate = TUNNEL_STATE_GET;
4500 g_mutex_unlock (&client->priv->lock);
4502 return handle_tunnel (client);
4505 static GstRTSPResult
4506 tunnel_post (GstRTSPWatch * watch, gpointer user_data)
4508 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4510 GST_INFO ("client %p: tunnel post (connection %p)", client,
4511 client->priv->connection);
4513 g_mutex_lock (&client->priv->lock);
4514 client->priv->tstate = TUNNEL_STATE_POST;
4515 g_mutex_unlock (&client->priv->lock);
4517 if (handle_tunnel (client) != GST_RTSP_STS_OK)
4518 return GST_RTSP_ERROR;
4523 static GstRTSPResult
4524 tunnel_http_response (GstRTSPWatch * watch, GstRTSPMessage * request,
4525 GstRTSPMessage * response, gpointer user_data)
4527 GstRTSPClientClass *klass;
4529 GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
4530 klass = GST_RTSP_CLIENT_GET_CLASS (client);
4532 if (klass->tunnel_http_response) {
4533 klass->tunnel_http_response (client, request, response);
4539 static GstRTSPWatchFuncs watch_funcs = {
4548 tunnel_http_response
4552 client_watch_notify (GstRTSPClient * client)
4554 GstRTSPClientPrivate *priv = client->priv;
4555 gboolean closed = TRUE;
4557 GST_INFO ("client %p: watch destroyed", client);
4559 /* remove all sessions if the media says so and so drop the extra client ref */
4560 rtsp_ctrl_timeout_remove (priv);
4561 gst_rtsp_client_session_filter (client, cleanup_session, &closed);
4563 g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
4564 g_object_unref (client);
4568 * gst_rtsp_client_attach:
4569 * @client: a #GstRTSPClient
4570 * @context: (allow-none): a #GMainContext
4572 * Attaches @client to @context. When the mainloop for @context is run, the
4573 * client will be dispatched. When @context is %NULL, the default context will be
4576 * This function should be called when the client properties and urls are fully
4577 * configured and the client is ready to start.
4579 * Returns: the ID (greater than 0) for the source within the GMainContext.
4582 gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
4584 GstRTSPClientPrivate *priv;
4588 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), 0);
4589 priv = client->priv;
4590 g_return_val_if_fail (priv->connection != NULL, 0);
4591 g_return_val_if_fail (priv->watch == NULL, 0);
4593 /* make sure noone will free the context before the watch is destroyed */
4594 priv->watch_context = g_main_context_ref (context);
4596 /* create watch for the connection and attach */
4597 priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs,
4598 g_object_ref (client), (GDestroyNotify) client_watch_notify);
4599 gst_rtsp_client_set_send_func (client, do_send_message, priv->watch,
4600 (GDestroyNotify) gst_rtsp_watch_unref);
4602 gst_rtsp_watch_set_send_backlog (priv->watch, 0, WATCH_BACKLOG_SIZE);
4604 GST_INFO ("client %p: attaching to context %p", client, context);
4605 res = gst_rtsp_watch_attach (priv->watch, context);
4607 /* Setting up a timeout for the RTSP control channel until a session
4608 * is up where it is handling timeouts. */
4609 rtsp_ctrl_timeout_remove (priv); /* removing old if any */
4610 g_mutex_lock (&priv->lock);
4612 timer_src = g_timeout_source_new_seconds (RTSP_CTRL_CB_INTERVAL);
4613 g_source_set_callback (timer_src, rtsp_ctrl_timeout_cb, client, NULL);
4614 priv->rtsp_ctrl_timeout_id = g_source_attach (timer_src, priv->watch_context);
4615 g_source_unref (timer_src);
4616 GST_DEBUG ("rtsp control setting up session timeout id=%u.",
4617 priv->rtsp_ctrl_timeout_id);
4619 g_mutex_unlock (&priv->lock);
4625 * gst_rtsp_client_session_filter:
4626 * @client: a #GstRTSPClient
4627 * @func: (scope call) (allow-none): a callback
4628 * @user_data: user data passed to @func
4630 * Call @func for each session managed by @client. The result value of @func
4631 * determines what happens to the session. @func will be called with @client
4632 * locked so no further actions on @client can be performed from @func.
4634 * If @func returns #GST_RTSP_FILTER_REMOVE, the session will be removed from
4637 * If @func returns #GST_RTSP_FILTER_KEEP, the session will remain in @client.
4639 * If @func returns #GST_RTSP_FILTER_REF, the session will remain in @client but
4640 * will also be added with an additional ref to the result #GList of this
4643 * When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for each session.
4645 * Returns: (element-type GstRTSPSession) (transfer full): a #GList with all
4646 * sessions for which @func returned #GST_RTSP_FILTER_REF. After usage, each
4647 * element in the #GList should be unreffed before the list is freed.
4650 gst_rtsp_client_session_filter (GstRTSPClient * client,
4651 GstRTSPClientSessionFilterFunc func, gpointer user_data)
4653 GstRTSPClientPrivate *priv;
4654 GList *result, *walk, *next;
4655 GHashTable *visited;
4658 g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
4660 priv = client->priv;
4664 visited = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL);
4666 g_mutex_lock (&priv->lock);
4668 cookie = priv->sessions_cookie;
4669 for (walk = priv->sessions; walk; walk = next) {
4670 GstRTSPSession *sess = walk->data;
4671 GstRTSPFilterResult res;
4674 next = g_list_next (walk);
4677 /* only visit each session once */
4678 if (g_hash_table_contains (visited, sess))
4681 g_hash_table_add (visited, g_object_ref (sess));
4682 g_mutex_unlock (&priv->lock);
4684 res = func (client, sess, user_data);
4686 g_mutex_lock (&priv->lock);
4688 res = GST_RTSP_FILTER_REF;
4690 changed = (cookie != priv->sessions_cookie);
4693 case GST_RTSP_FILTER_REMOVE:
4694 /* stop watching the session and pretend it went away, if the list was
4695 * changed, we can't use the current list position, try to see if we
4696 * still have the session */
4697 client_unwatch_session (client, sess, changed ? NULL : walk);
4698 cookie = priv->sessions_cookie;
4700 case GST_RTSP_FILTER_REF:
4701 result = g_list_prepend (result, g_object_ref (sess));
4703 case GST_RTSP_FILTER_KEEP:
4710 g_mutex_unlock (&priv->lock);
4713 g_hash_table_unref (visited);