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.
22 * SECTION:rtsp-media-factory
23 * @short_description: A factory for media pipelines
24 * @see_also: #GstRTSPMountPoints, #GstRTSPMedia
26 * The #GstRTSPMediaFactory is responsible for creating or recycling
27 * #GstRTSPMedia objects based on the passed URL.
29 * The default implementation of the object can create #GstRTSPMedia objects
30 * containing a pipeline created from a launch description set with
31 * gst_rtsp_media_factory_set_launch().
33 * Media from a factory can be shared by setting the shared flag with
34 * gst_rtsp_media_factory_set_shared(). When a factory is shared,
35 * gst_rtsp_media_factory_construct() will return the same #GstRTSPMedia when
38 * Last reviewed on 2013-07-11 (1.0.0)
44 #include "rtsp-server-internal.h"
45 #include "rtsp-media-factory.h"
47 #define GST_RTSP_MEDIA_FACTORY_GET_LOCK(f) (&(GST_RTSP_MEDIA_FACTORY_CAST(f)->priv->lock))
48 #define GST_RTSP_MEDIA_FACTORY_LOCK(f) (g_mutex_lock(GST_RTSP_MEDIA_FACTORY_GET_LOCK(f)))
49 #define GST_RTSP_MEDIA_FACTORY_UNLOCK(f) (g_mutex_unlock(GST_RTSP_MEDIA_FACTORY_GET_LOCK(f)))
51 struct _GstRTSPMediaFactoryPrivate
53 GMutex lock; /* protects everything but medias */
54 GstRTSPPermissions *permissions;
57 GstRTSPSuspendMode suspend_mode;
58 gboolean eos_shutdown;
59 GstRTSPProfile profiles;
60 GstRTSPLowerTrans protocols;
63 GstRTSPAddressPool *pool;
64 GstRTSPTransportMode transport_mode;
65 gboolean stop_on_disconnect;
66 gchar *multicast_iface;
68 gboolean bind_mcast_address;
71 GstClockTime rtx_time;
73 gboolean do_retransmission;
76 GHashTable *medias; /* protected by medias_lock */
82 GstRTSPPublishClockMode publish_clock_mode;
85 #define DEFAULT_LAUNCH NULL
86 #define DEFAULT_SHARED FALSE
87 #define DEFAULT_SUSPEND_MODE GST_RTSP_SUSPEND_MODE_NONE
88 #define DEFAULT_EOS_SHUTDOWN FALSE
89 #define DEFAULT_PROFILES GST_RTSP_PROFILE_AVP
90 #define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | \
91 GST_RTSP_LOWER_TRANS_TCP
92 #define DEFAULT_BUFFER_SIZE 0x80000
93 #define DEFAULT_LATENCY 200
94 #define DEFAULT_MAX_MCAST_TTL 255
95 #define DEFAULT_BIND_MCAST_ADDRESS FALSE
96 #define DEFAULT_TRANSPORT_MODE GST_RTSP_TRANSPORT_MODE_PLAY
97 #define DEFAULT_STOP_ON_DISCONNECT TRUE
98 #define DEFAULT_DO_RETRANSMISSION FALSE
99 #define DEFAULT_DSCP_QOS (-1)
100 #define DEFAULT_ENABLE_RTCP TRUE
114 PROP_STOP_ON_DISCONNECT,
117 PROP_BIND_MCAST_ADDRESS,
125 SIGNAL_MEDIA_CONSTRUCTED,
126 SIGNAL_MEDIA_CONFIGURE,
130 GST_DEBUG_CATEGORY_STATIC (rtsp_media_debug);
131 #define GST_CAT_DEFAULT rtsp_media_debug
133 static guint gst_rtsp_media_factory_signals[SIGNAL_LAST] = { 0 };
135 static void gst_rtsp_media_factory_get_property (GObject * object, guint propid,
136 GValue * value, GParamSpec * pspec);
137 static void gst_rtsp_media_factory_set_property (GObject * object, guint propid,
138 const GValue * value, GParamSpec * pspec);
139 static void gst_rtsp_media_factory_finalize (GObject * obj);
141 static gchar *default_gen_key (GstRTSPMediaFactory * factory,
142 const GstRTSPUrl * url);
143 static GstElement *default_create_element (GstRTSPMediaFactory * factory,
144 const GstRTSPUrl * url);
145 static GstRTSPMedia *default_construct (GstRTSPMediaFactory * factory,
146 const GstRTSPUrl * url);
147 static void default_configure (GstRTSPMediaFactory * factory,
148 GstRTSPMedia * media);
149 static GstElement *default_create_pipeline (GstRTSPMediaFactory * factory,
150 GstRTSPMedia * media);
152 G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPMediaFactory, gst_rtsp_media_factory,
156 gst_rtsp_media_factory_class_init (GstRTSPMediaFactoryClass * klass)
158 GObjectClass *gobject_class;
160 gobject_class = G_OBJECT_CLASS (klass);
162 gobject_class->get_property = gst_rtsp_media_factory_get_property;
163 gobject_class->set_property = gst_rtsp_media_factory_set_property;
164 gobject_class->finalize = gst_rtsp_media_factory_finalize;
167 * GstRTSPMediaFactory::launch:
169 * The gst_parse_launch() line to use for constructing the pipeline in the
170 * default prepare vmethod.
172 * The pipeline description should return a GstBin as the toplevel element
173 * which can be accomplished by enclosing the description with brackets '('
176 * The description should return a pipeline with payloaders named pay0, pay1,
177 * etc.. Each of the payloaders will result in a stream.
179 * Support for dynamic payloaders can be accomplished by adding payloaders
180 * named dynpay0, dynpay1, etc..
182 g_object_class_install_property (gobject_class, PROP_LAUNCH,
183 g_param_spec_string ("launch", "Launch",
184 "A launch description of the pipeline", DEFAULT_LAUNCH,
185 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
187 g_object_class_install_property (gobject_class, PROP_SHARED,
188 g_param_spec_boolean ("shared", "Shared",
189 "If media from this factory is shared", DEFAULT_SHARED,
190 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192 g_object_class_install_property (gobject_class, PROP_SUSPEND_MODE,
193 g_param_spec_enum ("suspend-mode", "Suspend Mode",
194 "Control how media will be suspended", GST_TYPE_RTSP_SUSPEND_MODE,
195 DEFAULT_SUSPEND_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
197 g_object_class_install_property (gobject_class, PROP_EOS_SHUTDOWN,
198 g_param_spec_boolean ("eos-shutdown", "EOS Shutdown",
199 "Send EOS down the pipeline before shutting down",
200 DEFAULT_EOS_SHUTDOWN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
202 g_object_class_install_property (gobject_class, PROP_PROFILES,
203 g_param_spec_flags ("profiles", "Profiles",
204 "Allowed transfer profiles", GST_TYPE_RTSP_PROFILE,
205 DEFAULT_PROFILES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
207 g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
208 g_param_spec_flags ("protocols", "Protocols",
209 "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
210 DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
212 g_object_class_install_property (gobject_class, PROP_BUFFER_SIZE,
213 g_param_spec_uint ("buffer-size", "Buffer Size",
214 "The kernel UDP buffer size to use", 0, G_MAXUINT,
215 DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
217 g_object_class_install_property (gobject_class, PROP_LATENCY,
218 g_param_spec_uint ("latency", "Latency",
219 "Latency used for receiving media in milliseconds", 0, G_MAXUINT,
220 DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
222 g_object_class_install_property (gobject_class, PROP_TRANSPORT_MODE,
223 g_param_spec_flags ("transport-mode", "Transport Mode",
224 "If media from this factory is for PLAY or RECORD",
225 GST_TYPE_RTSP_TRANSPORT_MODE, DEFAULT_TRANSPORT_MODE,
226 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
228 g_object_class_install_property (gobject_class, PROP_STOP_ON_DISCONNECT,
229 g_param_spec_boolean ("stop-on-disconnect", "Stop On Disconnect",
230 "If media from this factory should be stopped "
231 "when a client disconnects without TEARDOWN",
232 DEFAULT_STOP_ON_DISCONNECT,
233 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
235 g_object_class_install_property (gobject_class, PROP_CLOCK,
236 g_param_spec_object ("clock", "Clock",
237 "Clock to be used by the pipelines created for all "
238 "medias of this factory", GST_TYPE_CLOCK,
239 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
241 g_object_class_install_property (gobject_class, PROP_MAX_MCAST_TTL,
242 g_param_spec_uint ("max-mcast-ttl", "Maximum multicast ttl",
243 "The maximum time-to-live value of outgoing multicast packets", 1,
244 255, DEFAULT_MAX_MCAST_TTL,
245 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
247 g_object_class_install_property (gobject_class, PROP_BIND_MCAST_ADDRESS,
248 g_param_spec_boolean ("bind-mcast-address", "Bind mcast address",
249 "Whether the multicast sockets should be bound to multicast addresses "
251 DEFAULT_BIND_MCAST_ADDRESS,
252 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
255 * GstRTSPMediaFactory:enable-rtcp:
257 * Whether the created media should send and receive RTCP
261 g_object_class_install_property (gobject_class, PROP_ENABLE_RTCP,
262 g_param_spec_boolean ("enable-rtcp", "Enable RTCP",
263 "Whether the created media should send and receive RTCP",
264 DEFAULT_ENABLE_RTCP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
266 g_object_class_install_property (gobject_class, PROP_DSCP_QOS,
267 g_param_spec_int ("dscp-qos", "DSCP QoS",
268 "The IP DSCP field to use", -1, 63,
269 DEFAULT_DSCP_QOS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
271 gst_rtsp_media_factory_signals[SIGNAL_MEDIA_CONSTRUCTED] =
272 g_signal_new ("media-constructed", G_TYPE_FROM_CLASS (klass),
273 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPMediaFactoryClass,
274 media_constructed), NULL, NULL, NULL,
275 G_TYPE_NONE, 1, GST_TYPE_RTSP_MEDIA);
277 gst_rtsp_media_factory_signals[SIGNAL_MEDIA_CONFIGURE] =
278 g_signal_new ("media-configure", G_TYPE_FROM_CLASS (klass),
279 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPMediaFactoryClass,
280 media_configure), NULL, NULL, NULL,
281 G_TYPE_NONE, 1, GST_TYPE_RTSP_MEDIA);
283 klass->gen_key = default_gen_key;
284 klass->create_element = default_create_element;
285 klass->construct = default_construct;
286 klass->configure = default_configure;
287 klass->create_pipeline = default_create_pipeline;
289 GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmediafactory", 0,
290 "GstRTSPMediaFactory");
294 gst_rtsp_media_factory_init (GstRTSPMediaFactory * factory)
296 GstRTSPMediaFactoryPrivate *priv =
297 gst_rtsp_media_factory_get_instance_private (factory);
298 factory->priv = priv;
300 priv->launch = g_strdup (DEFAULT_LAUNCH);
301 priv->shared = DEFAULT_SHARED;
302 priv->suspend_mode = DEFAULT_SUSPEND_MODE;
303 priv->eos_shutdown = DEFAULT_EOS_SHUTDOWN;
304 priv->profiles = DEFAULT_PROFILES;
305 priv->protocols = DEFAULT_PROTOCOLS;
306 priv->buffer_size = DEFAULT_BUFFER_SIZE;
307 priv->latency = DEFAULT_LATENCY;
308 priv->transport_mode = DEFAULT_TRANSPORT_MODE;
309 priv->stop_on_disconnect = DEFAULT_STOP_ON_DISCONNECT;
310 priv->publish_clock_mode = GST_RTSP_PUBLISH_CLOCK_MODE_CLOCK;
311 priv->do_retransmission = DEFAULT_DO_RETRANSMISSION;
312 priv->max_mcast_ttl = DEFAULT_MAX_MCAST_TTL;
313 priv->bind_mcast_address = DEFAULT_BIND_MCAST_ADDRESS;
314 priv->enable_rtcp = DEFAULT_ENABLE_RTCP;
315 priv->dscp_qos = DEFAULT_DSCP_QOS;
317 g_mutex_init (&priv->lock);
318 g_mutex_init (&priv->medias_lock);
319 priv->medias = g_hash_table_new_full (g_str_hash, g_str_equal,
320 g_free, g_object_unref);
321 priv->media_gtype = GST_TYPE_RTSP_MEDIA;
325 gst_rtsp_media_factory_finalize (GObject * obj)
327 GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (obj);
328 GstRTSPMediaFactoryPrivate *priv = factory->priv;
331 gst_object_unref (priv->clock);
332 if (priv->permissions)
333 gst_rtsp_permissions_unref (priv->permissions);
334 g_hash_table_unref (priv->medias);
335 g_mutex_clear (&priv->medias_lock);
336 g_free (priv->launch);
337 g_mutex_clear (&priv->lock);
339 g_object_unref (priv->pool);
340 g_free (priv->multicast_iface);
342 G_OBJECT_CLASS (gst_rtsp_media_factory_parent_class)->finalize (obj);
346 gst_rtsp_media_factory_get_property (GObject * object, guint propid,
347 GValue * value, GParamSpec * pspec)
349 GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (object);
353 g_value_take_string (value, gst_rtsp_media_factory_get_launch (factory));
356 g_value_set_boolean (value, gst_rtsp_media_factory_is_shared (factory));
358 case PROP_SUSPEND_MODE:
359 g_value_set_enum (value,
360 gst_rtsp_media_factory_get_suspend_mode (factory));
362 case PROP_EOS_SHUTDOWN:
363 g_value_set_boolean (value,
364 gst_rtsp_media_factory_is_eos_shutdown (factory));
367 g_value_set_flags (value, gst_rtsp_media_factory_get_profiles (factory));
370 g_value_set_flags (value, gst_rtsp_media_factory_get_protocols (factory));
372 case PROP_BUFFER_SIZE:
373 g_value_set_uint (value,
374 gst_rtsp_media_factory_get_buffer_size (factory));
377 g_value_set_uint (value, gst_rtsp_media_factory_get_latency (factory));
379 case PROP_TRANSPORT_MODE:
380 g_value_set_flags (value,
381 gst_rtsp_media_factory_get_transport_mode (factory));
383 case PROP_STOP_ON_DISCONNECT:
384 g_value_set_boolean (value,
385 gst_rtsp_media_factory_is_stop_on_disonnect (factory));
388 g_value_take_object (value, gst_rtsp_media_factory_get_clock (factory));
390 case PROP_MAX_MCAST_TTL:
391 g_value_set_uint (value,
392 gst_rtsp_media_factory_get_max_mcast_ttl (factory));
394 case PROP_BIND_MCAST_ADDRESS:
395 g_value_set_boolean (value,
396 gst_rtsp_media_factory_is_bind_mcast_address (factory));
399 g_value_set_int (value, gst_rtsp_media_factory_get_dscp_qos (factory));
401 case PROP_ENABLE_RTCP:
402 g_value_set_boolean (value,
403 gst_rtsp_media_factory_is_enable_rtcp (factory));
406 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
411 gst_rtsp_media_factory_set_property (GObject * object, guint propid,
412 const GValue * value, GParamSpec * pspec)
414 GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (object);
418 gst_rtsp_media_factory_set_launch (factory, g_value_get_string (value));
421 gst_rtsp_media_factory_set_shared (factory, g_value_get_boolean (value));
423 case PROP_SUSPEND_MODE:
424 gst_rtsp_media_factory_set_suspend_mode (factory,
425 g_value_get_enum (value));
427 case PROP_EOS_SHUTDOWN:
428 gst_rtsp_media_factory_set_eos_shutdown (factory,
429 g_value_get_boolean (value));
432 gst_rtsp_media_factory_set_profiles (factory, g_value_get_flags (value));
435 gst_rtsp_media_factory_set_protocols (factory, g_value_get_flags (value));
437 case PROP_BUFFER_SIZE:
438 gst_rtsp_media_factory_set_buffer_size (factory,
439 g_value_get_uint (value));
442 gst_rtsp_media_factory_set_latency (factory, g_value_get_uint (value));
444 case PROP_TRANSPORT_MODE:
445 gst_rtsp_media_factory_set_transport_mode (factory,
446 g_value_get_flags (value));
448 case PROP_STOP_ON_DISCONNECT:
449 gst_rtsp_media_factory_set_stop_on_disconnect (factory,
450 g_value_get_boolean (value));
453 gst_rtsp_media_factory_set_clock (factory, g_value_get_object (value));
455 case PROP_MAX_MCAST_TTL:
456 gst_rtsp_media_factory_set_max_mcast_ttl (factory,
457 g_value_get_uint (value));
459 case PROP_BIND_MCAST_ADDRESS:
460 gst_rtsp_media_factory_set_bind_mcast_address (factory,
461 g_value_get_boolean (value));
464 gst_rtsp_media_factory_set_dscp_qos (factory, g_value_get_int (value));
466 case PROP_ENABLE_RTCP:
467 gst_rtsp_media_factory_set_enable_rtcp (factory,
468 g_value_get_boolean (value));
471 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
476 * gst_rtsp_media_factory_new:
478 * Create a new #GstRTSPMediaFactory instance.
480 * Returns: (transfer full): a new #GstRTSPMediaFactory object.
482 GstRTSPMediaFactory *
483 gst_rtsp_media_factory_new (void)
485 GstRTSPMediaFactory *result;
487 result = g_object_new (GST_TYPE_RTSP_MEDIA_FACTORY, NULL);
493 * gst_rtsp_media_factory_set_permissions:
494 * @factory: a #GstRTSPMediaFactory
495 * @permissions: (transfer none) (nullable): a #GstRTSPPermissions
497 * Set @permissions on @factory.
500 gst_rtsp_media_factory_set_permissions (GstRTSPMediaFactory * factory,
501 GstRTSPPermissions * permissions)
503 GstRTSPMediaFactoryPrivate *priv;
505 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
507 priv = factory->priv;
509 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
510 if (priv->permissions)
511 gst_rtsp_permissions_unref (priv->permissions);
512 if ((priv->permissions = permissions))
513 gst_rtsp_permissions_ref (permissions);
514 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
518 * gst_rtsp_media_factory_get_permissions:
519 * @factory: a #GstRTSPMediaFactory
521 * Get the permissions object from @factory.
523 * Returns: (transfer full) (nullable): a #GstRTSPPermissions object, unref after usage.
526 gst_rtsp_media_factory_get_permissions (GstRTSPMediaFactory * factory)
528 GstRTSPMediaFactoryPrivate *priv;
529 GstRTSPPermissions *result;
531 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
533 priv = factory->priv;
535 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
536 if ((result = priv->permissions))
537 gst_rtsp_permissions_ref (result);
538 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
544 * gst_rtsp_media_factory_add_role:
545 * @factory: a #GstRTSPMediaFactory
547 * @fieldname: the first field name
548 * @...: additional arguments
550 * A convenience method to add @role with @fieldname and additional arguments to
551 * the permissions of @factory. If @factory had no permissions, new permissions
552 * will be created and the role will be added to it.
555 gst_rtsp_media_factory_add_role (GstRTSPMediaFactory * factory,
556 const gchar * role, const gchar * fieldname, ...)
558 GstRTSPMediaFactoryPrivate *priv;
561 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
562 g_return_if_fail (role != NULL);
563 g_return_if_fail (fieldname != NULL);
565 priv = factory->priv;
567 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
568 if (priv->permissions == NULL)
569 priv->permissions = gst_rtsp_permissions_new ();
571 va_start (var_args, fieldname);
572 gst_rtsp_permissions_add_role_valist (priv->permissions, role, fieldname,
575 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
579 * gst_rtsp_media_factory_add_role_from_structure:
581 * A convenience wrapper around gst_rtsp_permissions_add_role_from_structure().
582 * If @factory had no permissions, new permissions will be created and the
583 * role will be added to it.
588 gst_rtsp_media_factory_add_role_from_structure (GstRTSPMediaFactory * factory,
589 GstStructure * structure)
591 GstRTSPMediaFactoryPrivate *priv;
592 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
593 g_return_if_fail (GST_IS_STRUCTURE (structure));
595 priv = factory->priv;
597 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
598 if (priv->permissions == NULL)
599 priv->permissions = gst_rtsp_permissions_new ();
601 gst_rtsp_permissions_add_role_from_structure (priv->permissions, structure);
602 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
606 * gst_rtsp_media_factory_set_launch:
607 * @factory: a #GstRTSPMediaFactory
608 * @launch: the launch description
611 * The gst_parse_launch() line to use for constructing the pipeline in the
612 * default prepare vmethod.
614 * The pipeline description should return a GstBin as the toplevel element
615 * which can be accomplished by enclosing the description with brackets '('
618 * The description should return a pipeline with payloaders named pay0, pay1,
619 * etc.. Each of the payloaders will result in a stream.
622 gst_rtsp_media_factory_set_launch (GstRTSPMediaFactory * factory,
623 const gchar * launch)
625 GstRTSPMediaFactoryPrivate *priv;
627 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
628 g_return_if_fail (launch != NULL);
630 priv = factory->priv;
632 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
633 g_free (priv->launch);
634 priv->launch = g_strdup (launch);
635 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
639 * gst_rtsp_media_factory_get_launch:
640 * @factory: a #GstRTSPMediaFactory
642 * Get the gst_parse_launch() pipeline description that will be used in the
643 * default prepare vmethod.
645 * Returns: (transfer full) (nullable): the configured launch description. g_free() after
649 gst_rtsp_media_factory_get_launch (GstRTSPMediaFactory * factory)
651 GstRTSPMediaFactoryPrivate *priv;
654 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
656 priv = factory->priv;
658 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
659 result = g_strdup (priv->launch);
660 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
666 * gst_rtsp_media_factory_set_suspend_mode:
667 * @factory: a #GstRTSPMediaFactory
668 * @mode: the new #GstRTSPSuspendMode
670 * Configure how media created from this factory will be suspended.
673 gst_rtsp_media_factory_set_suspend_mode (GstRTSPMediaFactory * factory,
674 GstRTSPSuspendMode mode)
676 GstRTSPMediaFactoryPrivate *priv;
678 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
680 priv = factory->priv;
682 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
683 priv->suspend_mode = mode;
684 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
688 * gst_rtsp_media_factory_get_suspend_mode:
689 * @factory: a #GstRTSPMediaFactory
691 * Get how media created from this factory will be suspended.
693 * Returns: a #GstRTSPSuspendMode.
696 gst_rtsp_media_factory_get_suspend_mode (GstRTSPMediaFactory * factory)
698 GstRTSPMediaFactoryPrivate *priv;
699 GstRTSPSuspendMode result;
701 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory),
702 GST_RTSP_SUSPEND_MODE_NONE);
704 priv = factory->priv;
706 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
707 result = priv->suspend_mode;
708 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
714 * gst_rtsp_media_factory_set_shared:
715 * @factory: a #GstRTSPMediaFactory
716 * @shared: the new value
718 * Configure if media created from this factory can be shared between clients.
721 gst_rtsp_media_factory_set_shared (GstRTSPMediaFactory * factory,
724 GstRTSPMediaFactoryPrivate *priv;
726 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
728 priv = factory->priv;
730 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
731 priv->shared = shared;
732 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
736 * gst_rtsp_media_factory_is_shared:
737 * @factory: a #GstRTSPMediaFactory
739 * Get if media created from this factory can be shared between clients.
741 * Returns: %TRUE if the media will be shared between clients.
744 gst_rtsp_media_factory_is_shared (GstRTSPMediaFactory * factory)
746 GstRTSPMediaFactoryPrivate *priv;
749 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), FALSE);
751 priv = factory->priv;
753 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
754 result = priv->shared;
755 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
761 * gst_rtsp_media_factory_set_eos_shutdown:
762 * @factory: a #GstRTSPMediaFactory
763 * @eos_shutdown: the new value
765 * Configure if media created from this factory will have an EOS sent to the
766 * pipeline before shutdown.
769 gst_rtsp_media_factory_set_eos_shutdown (GstRTSPMediaFactory * factory,
770 gboolean eos_shutdown)
772 GstRTSPMediaFactoryPrivate *priv;
774 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
776 priv = factory->priv;
778 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
779 priv->eos_shutdown = eos_shutdown;
780 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
784 * gst_rtsp_media_factory_is_eos_shutdown:
785 * @factory: a #GstRTSPMediaFactory
787 * Get if media created from this factory will have an EOS event sent to the
788 * pipeline before shutdown.
790 * Returns: %TRUE if the media will receive EOS before shutdown.
793 gst_rtsp_media_factory_is_eos_shutdown (GstRTSPMediaFactory * factory)
795 GstRTSPMediaFactoryPrivate *priv;
798 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), FALSE);
800 priv = factory->priv;
802 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
803 result = priv->eos_shutdown;
804 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
810 * gst_rtsp_media_factory_set_buffer_size:
811 * @factory: a #GstRTSPMedia
812 * @size: the new value
814 * Set the kernel UDP buffer size.
817 gst_rtsp_media_factory_set_buffer_size (GstRTSPMediaFactory * factory,
820 GstRTSPMediaFactoryPrivate *priv;
822 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
824 priv = factory->priv;
826 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
827 priv->buffer_size = size;
828 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
832 * gst_rtsp_media_factory_get_buffer_size:
833 * @factory: a #GstRTSPMedia
835 * Get the kernel UDP buffer size.
837 * Returns: the kernel UDP buffer size.
840 gst_rtsp_media_factory_get_buffer_size (GstRTSPMediaFactory * factory)
842 GstRTSPMediaFactoryPrivate *priv;
845 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), 0);
847 priv = factory->priv;
849 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
850 result = priv->buffer_size;
851 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
857 * gst_rtsp_media_factory_set_dscp_qos:
858 * @factory: a #GstRTSPMediaFactory
859 * @dscp_qos: a new dscp qos value (0-63, or -1 to disable)
861 * Configure the media dscp qos to @dscp_qos.
866 gst_rtsp_media_factory_set_dscp_qos (GstRTSPMediaFactory * factory,
869 GstRTSPMediaFactoryPrivate *priv;
871 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
873 if (dscp_qos < -1 || dscp_qos > 63) {
874 GST_WARNING_OBJECT (factory, "trying to set illegal dscp qos %d", dscp_qos);
878 priv = factory->priv;
880 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
881 priv->dscp_qos = dscp_qos;
882 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
886 * gst_rtsp_media_factory_get_dscp_qos:
887 * @factory: a #GstRTSPMediaFactory
889 * Get the configured media DSCP QoS.
891 * Returns: the media DSCP QoS value or -1 if disabled.
896 gst_rtsp_media_factory_get_dscp_qos (GstRTSPMediaFactory * factory)
898 GstRTSPMediaFactoryPrivate *priv;
901 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), 0);
903 priv = factory->priv;
905 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
906 result = priv->dscp_qos;
907 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
913 * gst_rtsp_media_factory_set_address_pool:
914 * @factory: a #GstRTSPMediaFactory
915 * @pool: (transfer none) (nullable): a #GstRTSPAddressPool
917 * configure @pool to be used as the address pool of @factory.
920 gst_rtsp_media_factory_set_address_pool (GstRTSPMediaFactory * factory,
921 GstRTSPAddressPool * pool)
923 GstRTSPMediaFactoryPrivate *priv;
924 GstRTSPAddressPool *old;
926 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
928 priv = factory->priv;
930 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
931 if ((old = priv->pool) != pool)
932 priv->pool = pool ? g_object_ref (pool) : NULL;
935 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
938 g_object_unref (old);
942 * gst_rtsp_media_factory_get_address_pool:
943 * @factory: a #GstRTSPMediaFactory
945 * Get the #GstRTSPAddressPool used as the address pool of @factory.
947 * Returns: (transfer full) (nullable): the #GstRTSPAddressPool of @factory. g_object_unref() after
951 gst_rtsp_media_factory_get_address_pool (GstRTSPMediaFactory * factory)
953 GstRTSPMediaFactoryPrivate *priv;
954 GstRTSPAddressPool *result;
956 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
958 priv = factory->priv;
960 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
961 if ((result = priv->pool))
962 g_object_ref (result);
963 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
969 * gst_rtsp_media_factory_set_multicast_iface:
970 * @factory: a #GstRTSPMediaFactory
971 * @multicast_iface: (transfer none) (nullable): a multicast interface name
973 * configure @multicast_iface to be used for @factory.
976 gst_rtsp_media_factory_set_multicast_iface (GstRTSPMediaFactory * media_factory,
977 const gchar * multicast_iface)
979 GstRTSPMediaFactoryPrivate *priv;
982 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (media_factory));
984 priv = media_factory->priv;
986 GST_LOG_OBJECT (media_factory, "set multicast interface %s", multicast_iface);
988 g_mutex_lock (&priv->lock);
989 if ((old = priv->multicast_iface) != multicast_iface)
990 priv->multicast_iface = multicast_iface ? g_strdup (multicast_iface) : NULL;
993 g_mutex_unlock (&priv->lock);
1000 * gst_rtsp_media_factory_get_multicast_iface:
1001 * @factory: a #GstRTSPMediaFactory
1003 * Get the multicast interface used for @factory.
1005 * Returns: (transfer full) (nullable): the multicast interface for @factory. g_free() after
1009 gst_rtsp_media_factory_get_multicast_iface (GstRTSPMediaFactory * media_factory)
1011 GstRTSPMediaFactoryPrivate *priv;
1014 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (media_factory), NULL);
1016 priv = media_factory->priv;
1018 g_mutex_lock (&priv->lock);
1019 if ((result = priv->multicast_iface))
1020 result = g_strdup (result);
1021 g_mutex_unlock (&priv->lock);
1027 * gst_rtsp_media_factory_set_profiles:
1028 * @factory: a #GstRTSPMediaFactory
1029 * @profiles: the new flags
1031 * Configure the allowed profiles for @factory.
1034 gst_rtsp_media_factory_set_profiles (GstRTSPMediaFactory * factory,
1035 GstRTSPProfile profiles)
1037 GstRTSPMediaFactoryPrivate *priv;
1039 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1041 priv = factory->priv;
1043 GST_DEBUG_OBJECT (factory, "profiles %d", profiles);
1045 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1046 priv->profiles = profiles;
1047 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1051 * gst_rtsp_media_factory_get_profiles:
1052 * @factory: a #GstRTSPMediaFactory
1054 * Get the allowed profiles of @factory.
1056 * Returns: a #GstRTSPProfile
1059 gst_rtsp_media_factory_get_profiles (GstRTSPMediaFactory * factory)
1061 GstRTSPMediaFactoryPrivate *priv;
1064 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory),
1065 GST_RTSP_PROFILE_UNKNOWN);
1067 priv = factory->priv;
1069 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1070 res = priv->profiles;
1071 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1077 * gst_rtsp_media_factory_set_protocols:
1078 * @factory: a #GstRTSPMediaFactory
1079 * @protocols: the new flags
1081 * Configure the allowed lower transport for @factory.
1084 gst_rtsp_media_factory_set_protocols (GstRTSPMediaFactory * factory,
1085 GstRTSPLowerTrans protocols)
1087 GstRTSPMediaFactoryPrivate *priv;
1089 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1091 priv = factory->priv;
1093 GST_DEBUG_OBJECT (factory, "protocols %d", protocols);
1095 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1096 priv->protocols = protocols;
1097 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1101 * gst_rtsp_media_factory_get_protocols:
1102 * @factory: a #GstRTSPMediaFactory
1104 * Get the allowed protocols of @factory.
1106 * Returns: a #GstRTSPLowerTrans
1109 gst_rtsp_media_factory_get_protocols (GstRTSPMediaFactory * factory)
1111 GstRTSPMediaFactoryPrivate *priv;
1112 GstRTSPLowerTrans res;
1114 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory),
1115 GST_RTSP_LOWER_TRANS_UNKNOWN);
1117 priv = factory->priv;
1119 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1120 res = priv->protocols;
1121 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1127 * gst_rtsp_media_factory_set_stop_on_disconnect:
1128 * @factory: a #GstRTSPMediaFactory
1129 * @stop_on_disconnect: the new value
1131 * Configure if media created from this factory should be stopped
1132 * when a client disconnects without sending TEARDOWN.
1135 gst_rtsp_media_factory_set_stop_on_disconnect (GstRTSPMediaFactory * factory,
1136 gboolean stop_on_disconnect)
1138 GstRTSPMediaFactoryPrivate *priv;
1140 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1142 priv = factory->priv;
1144 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1145 priv->stop_on_disconnect = stop_on_disconnect;
1146 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1150 * gst_rtsp_media_factory_is_stop_on_disconnect:
1151 * @factory: a #GstRTSPMediaFactory
1153 * Get if media created from this factory should be stopped when a client
1154 * disconnects without sending TEARDOWN.
1156 * Returns: %TRUE if the media will be stopped when a client disconnects
1157 * without sending TEARDOWN.
1160 gst_rtsp_media_factory_is_stop_on_disonnect (GstRTSPMediaFactory * factory)
1162 GstRTSPMediaFactoryPrivate *priv;
1165 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), TRUE);
1167 priv = factory->priv;
1169 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1170 result = priv->stop_on_disconnect;
1171 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1177 * gst_rtsp_media_factory_set_retransmission_time:
1178 * @factory: a #GstRTSPMediaFactory
1179 * @time: a #GstClockTime
1181 * Configure the time to store for possible retransmission
1184 gst_rtsp_media_factory_set_retransmission_time (GstRTSPMediaFactory * factory,
1187 GstRTSPMediaFactoryPrivate *priv;
1189 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1191 priv = factory->priv;
1193 GST_DEBUG_OBJECT (factory, "retransmission time %" G_GUINT64_FORMAT, time);
1195 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1196 priv->rtx_time = time;
1197 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1201 * gst_rtsp_media_factory_get_retransmission_time:
1202 * @factory: a #GstRTSPMediaFactory
1204 * Get the time that is stored for retransmission purposes
1206 * Returns: a #GstClockTime
1209 gst_rtsp_media_factory_get_retransmission_time (GstRTSPMediaFactory * factory)
1211 GstRTSPMediaFactoryPrivate *priv;
1214 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), 0);
1216 priv = factory->priv;
1218 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1219 res = priv->rtx_time;
1220 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1226 * gst_rtsp_media_factory_set_do_retransmission:
1228 * Set whether retransmission requests will be sent for
1234 gst_rtsp_media_factory_set_do_retransmission (GstRTSPMediaFactory * factory,
1235 gboolean do_retransmission)
1237 GstRTSPMediaFactoryPrivate *priv;
1239 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1241 priv = factory->priv;
1243 GST_DEBUG_OBJECT (factory, "Do retransmission %d", do_retransmission);
1245 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1246 priv->do_retransmission = do_retransmission;
1247 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1251 * gst_rtsp_media_factory_get_do_retransmission:
1253 * Returns: Whether retransmission requests will be sent for receiving media
1258 gst_rtsp_media_factory_get_do_retransmission (GstRTSPMediaFactory * factory)
1260 GstRTSPMediaFactoryPrivate *priv;
1263 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), 0);
1265 priv = factory->priv;
1267 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1268 res = priv->do_retransmission;
1269 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1275 * gst_rtsp_media_factory_set_latency:
1276 * @factory: a #GstRTSPMediaFactory
1277 * @latency: latency in milliseconds
1279 * Configure the latency used for receiving media
1282 gst_rtsp_media_factory_set_latency (GstRTSPMediaFactory * factory,
1285 GstRTSPMediaFactoryPrivate *priv;
1287 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1289 priv = factory->priv;
1291 GST_DEBUG_OBJECT (factory, "latency %ums", latency);
1293 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1294 priv->latency = latency;
1295 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1299 * gst_rtsp_media_factory_get_latency:
1300 * @factory: a #GstRTSPMediaFactory
1302 * Get the latency that is used for receiving media
1304 * Returns: latency in milliseconds
1307 gst_rtsp_media_factory_get_latency (GstRTSPMediaFactory * factory)
1309 GstRTSPMediaFactoryPrivate *priv;
1312 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), 0);
1314 priv = factory->priv;
1316 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1317 res = priv->latency;
1318 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1324 compare_media (gpointer key, GstRTSPMedia * media1, GstRTSPMedia * media2)
1326 return (media1 == media2);
1330 media_unprepared (GstRTSPMedia * media, GWeakRef * ref)
1332 GstRTSPMediaFactory *factory = g_weak_ref_get (ref);
1333 GstRTSPMediaFactoryPrivate *priv;
1338 priv = factory->priv;
1340 g_mutex_lock (&priv->medias_lock);
1341 g_hash_table_foreach_remove (priv->medias, (GHRFunc) compare_media, media);
1342 g_mutex_unlock (&priv->medias_lock);
1344 g_object_unref (factory);
1348 weak_ref_new (gpointer obj)
1350 GWeakRef *ref = g_slice_new (GWeakRef);
1352 g_weak_ref_init (ref, obj);
1357 weak_ref_free (GWeakRef * ref)
1359 g_weak_ref_clear (ref);
1360 g_slice_free (GWeakRef, ref);
1364 * gst_rtsp_media_factory_construct:
1365 * @factory: a #GstRTSPMediaFactory
1366 * @url: the url used
1368 * Construct the media object and create its streams. Implementations
1369 * should create the needed gstreamer elements and add them to the result
1370 * object. No state changes should be performed on them yet.
1372 * One or more GstRTSPStream objects should be created from the result
1373 * with gst_rtsp_media_create_stream ().
1375 * After the media is constructed, it can be configured and then prepared
1376 * with gst_rtsp_media_prepare ().
1378 * Returns: (transfer full): a new #GstRTSPMedia if the media could be prepared.
1381 gst_rtsp_media_factory_construct (GstRTSPMediaFactory * factory,
1382 const GstRTSPUrl * url)
1384 GstRTSPMediaFactoryPrivate *priv;
1386 GstRTSPMedia *media;
1387 GstRTSPMediaFactoryClass *klass;
1389 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
1390 g_return_val_if_fail (url != NULL, NULL);
1392 priv = factory->priv;
1393 klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory);
1395 /* convert the url to a key for the hashtable. NULL return or a NULL function
1396 * will not cache anything for this factory. */
1398 key = klass->gen_key (factory, url);
1402 g_mutex_lock (&priv->medias_lock);
1404 /* we have a key, see if we find a cached media */
1405 media = g_hash_table_lookup (priv->medias, key);
1407 g_object_ref (media);
1411 if (media == NULL) {
1412 /* nothing cached found, try to create one */
1413 if (klass->construct) {
1414 media = klass->construct (factory, url);
1416 g_signal_emit (factory,
1417 gst_rtsp_media_factory_signals[SIGNAL_MEDIA_CONSTRUCTED], 0, media,
1423 /* configure the media */
1424 if (klass->configure)
1425 klass->configure (factory, media);
1427 g_signal_emit (factory,
1428 gst_rtsp_media_factory_signals[SIGNAL_MEDIA_CONFIGURE], 0, media,
1431 /* check if we can cache this media */
1432 if (gst_rtsp_media_is_shared (media) && key) {
1433 /* insert in the hashtable, takes ownership of the key */
1434 g_object_ref (media);
1435 g_hash_table_insert (priv->medias, key, media);
1438 if (!gst_rtsp_media_is_reusable (media)) {
1439 /* when not reusable, connect to the unprepare signal to remove the item
1440 * from our cache when it gets unprepared */
1441 g_signal_connect_data (media, "unprepared",
1442 (GCallback) media_unprepared, weak_ref_new (factory),
1443 (GClosureNotify) weak_ref_free, 0);
1447 g_mutex_unlock (&priv->medias_lock);
1452 GST_INFO ("constructed media %p for url %s", media, url->abspath);
1458 * gst_rtsp_media_factory_set_media_gtype:
1459 * @factory: a #GstRTSPMediaFactory
1460 * @media_gtype: the GType of the class to create
1462 * Configure the GType of the GstRTSPMedia subclass to
1463 * create (by default, overridden construct vmethods
1464 * may of course do something different)
1469 gst_rtsp_media_factory_set_media_gtype (GstRTSPMediaFactory * factory,
1472 GstRTSPMediaFactoryPrivate *priv;
1474 g_return_if_fail (g_type_is_a (media_gtype, GST_TYPE_RTSP_MEDIA));
1476 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1477 priv = factory->priv;
1478 priv->media_gtype = media_gtype;
1479 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1483 * gst_rtsp_media_factory_get_media_gtype:
1484 * @factory: a #GstRTSPMediaFactory
1486 * Return the GType of the GstRTSPMedia subclass this
1487 * factory will create.
1492 gst_rtsp_media_factory_get_media_gtype (GstRTSPMediaFactory * factory)
1494 GstRTSPMediaFactoryPrivate *priv;
1497 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1498 priv = factory->priv;
1499 ret = priv->media_gtype;
1500 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1506 * gst_rtsp_media_factory_set_clock:
1507 * @factory: a #GstRTSPMediaFactory
1508 * @clock: (nullable): the clock to be used by the media factory
1510 * Configures a specific clock to be used by the pipelines
1511 * of all medias created from this factory.
1516 gst_rtsp_media_factory_set_clock (GstRTSPMediaFactory * factory,
1521 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1522 g_return_if_fail (GST_IS_CLOCK (clock) || clock == NULL);
1524 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1525 clock_p = &factory->priv->clock;
1526 gst_object_replace ((GstObject **) clock_p, (GstObject *) clock);
1527 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1531 * gst_rtsp_media_factory_get_clock:
1532 * @factory: a #GstRTSPMediaFactory
1534 * Returns the clock that is going to be used by the pipelines
1535 * of all medias created from this factory.
1537 * Returns: (transfer full): The GstClock
1542 gst_rtsp_media_factory_get_clock (GstRTSPMediaFactory * factory)
1544 GstRTSPMediaFactoryPrivate *priv;
1547 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
1549 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1550 priv = factory->priv;
1551 ret = priv->clock ? gst_object_ref (priv->clock) : NULL;
1552 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1558 * gst_rtsp_media_factory_set_publish_clock_mode:
1559 * @factory: a #GstRTSPMediaFactory
1560 * @mode: the clock publish mode
1562 * Sets if and how the media clock should be published according to RFC7273.
1567 gst_rtsp_media_factory_set_publish_clock_mode (GstRTSPMediaFactory * factory,
1568 GstRTSPPublishClockMode mode)
1570 GstRTSPMediaFactoryPrivate *priv;
1572 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1573 priv = factory->priv;
1574 priv->publish_clock_mode = mode;
1575 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1579 * gst_rtsp_media_factory_get_publish_clock_mode:
1580 * @factory: a #GstRTSPMediaFactory
1582 * Gets if and how the media clock should be published according to RFC7273.
1584 * Returns: The GstRTSPPublishClockMode
1588 GstRTSPPublishClockMode
1589 gst_rtsp_media_factory_get_publish_clock_mode (GstRTSPMediaFactory * factory)
1591 GstRTSPMediaFactoryPrivate *priv;
1592 GstRTSPPublishClockMode ret;
1594 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1595 priv = factory->priv;
1596 ret = priv->publish_clock_mode;
1597 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1603 * gst_rtsp_media_factory_set_max_mcast_ttl:
1604 * @factory: a #GstRTSPMedia
1605 * @ttl: the new multicast ttl value
1607 * Set the maximum time-to-live value of outgoing multicast packets.
1609 * Returns: %TRUE if the requested ttl has been set successfully.
1614 gst_rtsp_media_factory_set_max_mcast_ttl (GstRTSPMediaFactory * factory,
1617 GstRTSPMediaFactoryPrivate *priv;
1619 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), FALSE);
1621 priv = factory->priv;
1623 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1624 if (ttl == 0 || ttl > DEFAULT_MAX_MCAST_TTL) {
1625 GST_WARNING_OBJECT (factory, "The requested mcast TTL value is not valid.");
1626 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1629 priv->max_mcast_ttl = ttl;
1630 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1636 * gst_rtsp_media_factory_get_max_mcast_ttl:
1637 * @factory: a #GstRTSPMedia
1639 * Get the the maximum time-to-live value of outgoing multicast packets.
1641 * Returns: the maximum time-to-live value of outgoing multicast packets.
1646 gst_rtsp_media_factory_get_max_mcast_ttl (GstRTSPMediaFactory * factory)
1648 GstRTSPMediaFactoryPrivate *priv;
1651 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), 0);
1653 priv = factory->priv;
1655 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1656 result = priv->max_mcast_ttl;
1657 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1663 * gst_rtsp_media_factory_set_bind_mcast_address:
1664 * @factory: a #GstRTSPMediaFactory
1665 * @bind_mcast_addr: the new value
1667 * Decide whether the multicast socket should be bound to a multicast address or
1673 gst_rtsp_media_factory_set_bind_mcast_address (GstRTSPMediaFactory * factory,
1674 gboolean bind_mcast_addr)
1676 GstRTSPMediaFactoryPrivate *priv;
1678 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1680 priv = factory->priv;
1682 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1683 priv->bind_mcast_address = bind_mcast_addr;
1684 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1688 * gst_rtsp_media_factory_is_bind_mcast_address:
1689 * @factory: a #GstRTSPMediaFactory
1691 * Check if multicast sockets are configured to be bound to multicast addresses.
1693 * Returns: %TRUE if multicast sockets are configured to be bound to multicast addresses.
1698 gst_rtsp_media_factory_is_bind_mcast_address (GstRTSPMediaFactory * factory)
1700 GstRTSPMediaFactoryPrivate *priv;
1703 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), FALSE);
1705 priv = factory->priv;
1707 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1708 result = priv->bind_mcast_address;
1709 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1715 * gst_rtsp_media_factory_set_enable_rtcp:
1716 * @factory: a #GstRTSPMediaFactory
1717 * @enable: the new value
1719 * Decide whether the created media should send and receive RTCP
1724 gst_rtsp_media_factory_set_enable_rtcp (GstRTSPMediaFactory * factory,
1727 GstRTSPMediaFactoryPrivate *priv;
1729 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
1731 priv = factory->priv;
1733 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1734 priv->enable_rtcp = enable;
1735 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1739 * gst_rtsp_media_factory_is_enable_rtcp:
1740 * @factory: a #GstRTSPMediaFactory
1742 * Check if created media will send and receive RTCP
1744 * Returns: %TRUE if created media will send and receive RTCP
1749 gst_rtsp_media_factory_is_enable_rtcp (GstRTSPMediaFactory * factory)
1751 GstRTSPMediaFactoryPrivate *priv;
1754 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), FALSE);
1756 priv = factory->priv;
1758 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1759 result = priv->enable_rtcp;
1760 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1766 default_gen_key (GstRTSPMediaFactory * factory, const GstRTSPUrl * url)
1769 const gchar *pre_query;
1773 pre_query = url->query ? "?" : "";
1774 query = url->query ? url->query : "";
1776 gst_rtsp_url_get_port (url, &port);
1778 result = g_strdup_printf ("%u%s%s%s", port, url->abspath, pre_query, query);
1784 default_create_element (GstRTSPMediaFactory * factory, const GstRTSPUrl * url)
1786 GstRTSPMediaFactoryPrivate *priv = factory->priv;
1787 GstElement *element;
1788 GError *error = NULL;
1790 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1791 /* we need a parse syntax */
1792 if (priv->launch == NULL)
1795 /* parse the user provided launch line */
1797 gst_parse_launch_full (priv->launch, NULL, GST_PARSE_FLAG_PLACE_IN_BIN,
1799 if (element == NULL)
1802 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1804 if (error != NULL) {
1805 /* a recoverable error was encountered */
1806 GST_WARNING ("recoverable parsing error: %s", error->message);
1807 g_error_free (error);
1814 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1815 g_critical ("no launch line specified");
1820 g_critical ("could not parse launch syntax (%s): %s", priv->launch,
1821 (error ? error->message : "unknown reason"));
1822 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1824 g_error_free (error);
1829 static GstRTSPMedia *
1830 default_construct (GstRTSPMediaFactory * factory, const GstRTSPUrl * url)
1832 GstRTSPMedia *media;
1833 GstElement *element, *pipeline;
1834 GstRTSPMediaFactoryClass *klass;
1836 gboolean enable_rtcp;
1838 klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory);
1840 if (!klass->create_pipeline)
1843 element = gst_rtsp_media_factory_create_element (factory, url);
1844 if (element == NULL)
1847 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1848 media_gtype = factory->priv->media_gtype;
1849 enable_rtcp = factory->priv->enable_rtcp;
1850 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1852 /* create a new empty media */
1854 g_object_new (media_gtype, "element", element, "transport-mode",
1855 factory->priv->transport_mode, NULL);
1857 /* We need to call this prior to collecting streams */
1858 gst_rtsp_media_set_enable_rtcp (media, enable_rtcp);
1860 gst_rtsp_media_collect_streams (media);
1862 pipeline = klass->create_pipeline (factory, media);
1863 if (pipeline == NULL)
1871 g_critical ("no create_pipeline function");
1876 g_critical ("could not create element");
1881 g_critical ("can't create pipeline");
1882 g_object_unref (media);
1888 default_create_pipeline (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
1890 GstElement *pipeline;
1892 pipeline = gst_pipeline_new ("media-pipeline");
1894 /* FIXME 2.0: This should be done by the caller, not the vfunc. Every
1895 * implementation of the vfunc has to call it otherwise at the end.
1896 * Also it does not allow use to add further behaviour here that could
1897 * be reused by subclasses that chain up */
1898 gst_rtsp_media_take_pipeline (media, GST_PIPELINE_CAST (pipeline));
1904 default_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
1906 GstRTSPMediaFactoryPrivate *priv = factory->priv;
1907 gboolean shared, eos_shutdown, stop_on_disconnect;
1910 GstRTSPSuspendMode suspend_mode;
1911 GstRTSPProfile profiles;
1912 GstRTSPLowerTrans protocols;
1913 GstRTSPAddressPool *pool;
1914 GstRTSPPermissions *perms;
1915 GstClockTime rtx_time;
1917 GstRTSPTransportMode transport_mode;
1919 gchar *multicast_iface;
1920 GstRTSPPublishClockMode publish_clock_mode;
1922 gboolean bind_mcast;
1924 /* configure the sharedness */
1925 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
1926 suspend_mode = priv->suspend_mode;
1927 shared = priv->shared;
1928 eos_shutdown = priv->eos_shutdown;
1929 size = priv->buffer_size;
1930 dscp_qos = priv->dscp_qos;
1931 profiles = priv->profiles;
1932 protocols = priv->protocols;
1933 rtx_time = priv->rtx_time;
1934 latency = priv->latency;
1935 transport_mode = priv->transport_mode;
1936 stop_on_disconnect = priv->stop_on_disconnect;
1937 clock = priv->clock ? gst_object_ref (priv->clock) : NULL;
1938 publish_clock_mode = priv->publish_clock_mode;
1939 ttl = priv->max_mcast_ttl;
1940 bind_mcast = priv->bind_mcast_address;
1941 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
1943 gst_rtsp_media_set_suspend_mode (media, suspend_mode);
1944 gst_rtsp_media_set_shared (media, shared);
1945 gst_rtsp_media_set_eos_shutdown (media, eos_shutdown);
1946 gst_rtsp_media_set_buffer_size (media, size);
1947 gst_rtsp_media_set_dscp_qos (media, dscp_qos);
1948 gst_rtsp_media_set_profiles (media, profiles);
1949 gst_rtsp_media_set_protocols (media, protocols);
1950 gst_rtsp_media_set_retransmission_time (media, rtx_time);
1951 gst_rtsp_media_set_do_retransmission (media, priv->do_retransmission);
1952 gst_rtsp_media_set_latency (media, latency);
1953 gst_rtsp_media_set_transport_mode (media, transport_mode);
1954 gst_rtsp_media_set_stop_on_disconnect (media, stop_on_disconnect);
1955 gst_rtsp_media_set_publish_clock_mode (media, publish_clock_mode);
1956 gst_rtsp_media_set_max_mcast_ttl (media, ttl);
1957 gst_rtsp_media_set_bind_mcast_address (media, bind_mcast);
1960 gst_rtsp_media_set_clock (media, clock);
1961 gst_object_unref (clock);
1964 if ((pool = gst_rtsp_media_factory_get_address_pool (factory))) {
1965 gst_rtsp_media_set_address_pool (media, pool);
1966 g_object_unref (pool);
1968 if ((multicast_iface = gst_rtsp_media_factory_get_multicast_iface (factory))) {
1969 gst_rtsp_media_set_multicast_iface (media, multicast_iface);
1970 g_free (multicast_iface);
1972 if ((perms = gst_rtsp_media_factory_get_permissions (factory))) {
1973 gst_rtsp_media_set_permissions (media, perms);
1974 gst_rtsp_permissions_unref (perms);
1979 * gst_rtsp_media_factory_create_element:
1980 * @factory: a #GstRTSPMediaFactory
1981 * @url: the url used
1983 * Construct and return a #GstElement that is a #GstBin containing
1984 * the elements to use for streaming the media.
1986 * The bin should contain payloaders pay\%d for each stream. The default
1987 * implementation of this function returns the bin created from the
1990 * Returns: (transfer floating): a new #GstElement.
1993 gst_rtsp_media_factory_create_element (GstRTSPMediaFactory * factory,
1994 const GstRTSPUrl * url)
1996 GstRTSPMediaFactoryClass *klass;
1999 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
2000 g_return_val_if_fail (url != NULL, NULL);
2002 klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory);
2004 if (klass->create_element)
2005 result = klass->create_element (factory, url);
2013 * gst_rtsp_media_factory_set_transport_mode:
2014 * @factory: a #GstRTSPMediaFactory
2015 * @mode: the new value
2017 * Configure if this factory creates media for PLAY or RECORD modes.
2020 gst_rtsp_media_factory_set_transport_mode (GstRTSPMediaFactory * factory,
2021 GstRTSPTransportMode mode)
2023 GstRTSPMediaFactoryPrivate *priv;
2025 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
2027 priv = factory->priv;
2029 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
2030 priv->transport_mode = mode;
2031 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
2035 * gst_rtsp_media_factory_get_transport_mode:
2036 * @factory: a #GstRTSPMediaFactory
2038 * Get if media created from this factory can be used for PLAY or RECORD
2041 * Returns: The transport mode.
2043 GstRTSPTransportMode
2044 gst_rtsp_media_factory_get_transport_mode (GstRTSPMediaFactory * factory)
2046 GstRTSPMediaFactoryPrivate *priv;
2047 GstRTSPTransportMode result;
2049 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), FALSE);
2051 priv = factory->priv;
2053 GST_RTSP_MEDIA_FACTORY_LOCK (factory);
2054 result = priv->transport_mode;
2055 GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);