--- /dev/null
+/* GStreamer
+ * Copyright (C) 2022 Samsung Electronics
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+/*
+ * SECTION:rtsp-media-factory-mtpr
+ * @short_description: A factory for media pipelines
+ * @see_also: #GstRTSPMediaFactory, #GstRTSPMedia
+ *
+ * The #GstRTSPMediaFactoryMTPR is responsible for creating or recycling
+ * #GstRTSPMedia objects based on the passed URL.
+ *
+ * The default implementation of the object can create #GstRTSPMedia objects
+ * containing a pipeline created from a launch description set with
+ * gst_rtsp_media_factory_set_launch().
+ *
+ * Media from a factory can be shared by setting the shared flag with
+ * gst_rtsp_media_factory_set_shared(). When a factory is shared,
+ * gst_rtsp_media_factory_construct() will return the same #GstRTSPMedia when
+ * the url matches.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#include "rtsp-media-factory-mtpr.h"
+
+#define GST_RTSP_MEDIA_FACTORY_MTPR_GET_LOCK(f) (&(GST_RTSP_MEDIA_FACTORY_MTPR_CAST(f)->priv->lock))
+#define GST_RTSP_MEDIA_FACTORY_MTPR_LOCK(f) (g_mutex_lock(GST_RTSP_MEDIA_FACTORY_MTPR_GET_LOCK(f)))
+#define GST_RTSP_MEDIA_FACTORY_MTPR_UNLOCK(f) (g_mutex_unlock(GST_RTSP_MEDIA_FACTORY_MTPR_GET_LOCK(f)))
+
+struct _GstRTSPMediaFactoryMTPRPrivate
+{
+ GMutex lock;
+ GstElement *custom_element;
+};
+
+GST_DEBUG_CATEGORY_STATIC (rtsp_media_mtpr_debug);
+#define GST_CAT_DEFAULT rtsp_media_mtpr_debug
+
+static void gst_rtsp_media_factory_mtpr_get_property (GObject * object,
+ guint propid, GValue * value, GParamSpec * pspec);
+static void gst_rtsp_media_factory_mtpr_set_property (GObject * object,
+ guint propid, const GValue * value, GParamSpec * pspec);
+static void gst_rtsp_media_factory_mtpr_finalize (GObject * obj);
+
+static GstElement
+ * gst_rtsp_media_factory_mtpr_create_element (GstRTSPMediaFactory * factory,
+ const GstRTSPUrl * url);
+static GstRTSPMedia *gst_rtsp_media_factory_mtpr_construct (GstRTSPMediaFactory
+ * factory, const GstRTSPUrl * url);
+
+#define gst_rtsp_media_factory_mtpr_parent_class parent_class
+G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPMediaFactoryMTPR,
+ gst_rtsp_media_factory_mtpr, GST_TYPE_RTSP_MEDIA_FACTORY);
+
+static void
+gst_rtsp_media_factory_mtpr_class_init (GstRTSPMediaFactoryMTPRClass * klass)
+{
+ GObjectClass *gobject_class;
+ GstRTSPMediaFactoryClass *factory_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ factory_class = GST_RTSP_MEDIA_FACTORY_CLASS (klass);
+
+ gobject_class->get_property = gst_rtsp_media_factory_mtpr_get_property;
+ gobject_class->set_property = gst_rtsp_media_factory_mtpr_set_property;
+ gobject_class->finalize = gst_rtsp_media_factory_mtpr_finalize;
+
+ factory_class->construct = gst_rtsp_media_factory_mtpr_construct;
+ factory_class->create_element = gst_rtsp_media_factory_mtpr_create_element;
+
+ GST_DEBUG_CATEGORY_INIT (rtsp_media_mtpr_debug, "rtspmediafactorymtpr", 0,
+ "GstRTSPMediaFactoryMTPR");
+}
+
+static void
+gst_rtsp_media_factory_mtpr_init (GstRTSPMediaFactoryMTPR * factory)
+{
+ GstRTSPMediaFactoryMTPRPrivate *priv =
+ gst_rtsp_media_factory_mtpr_get_instance_private (factory);
+
+ factory->priv = priv;
+
+ priv->custom_element = NULL;
+ g_mutex_init (&priv->lock);
+}
+
+static void
+gst_rtsp_media_factory_mtpr_finalize (GObject * obj)
+{
+ GstRTSPMediaFactoryMTPR *factory = GST_RTSP_MEDIA_FACTORY_MTPR (obj);
+ GstRTSPMediaFactoryMTPRPrivate *priv = factory->priv;
+
+ g_mutex_clear (&priv->lock);
+
+ G_OBJECT_CLASS (gst_rtsp_media_factory_mtpr_parent_class)->finalize (obj);
+}
+
+GstRTSPMediaFactoryMTPR *
+gst_rtsp_media_factory_mtpr_new (void)
+{
+ GstRTSPMediaFactoryMTPR *result;
+
+ result = g_object_new (GST_TYPE_RTSP_MEDIA_FACTORY_MTPR, NULL);
+
+ return result;
+}
+
+static void
+gst_rtsp_media_factory_mtpr_get_property (GObject * object,
+ guint propid, GValue * value, GParamSpec * pspec)
+{
+ switch (propid) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
+ }
+}
+
+static void
+gst_rtsp_media_factory_mtpr_set_property (GObject * object,
+ guint propid, const GValue * value, GParamSpec * pspec)
+{
+ switch (propid) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
+ }
+}
+
+void
+gst_rtsp_media_factory_mtpr_set_custom_element (GstRTSPMediaFactoryMTPR *
+ factory, GstElement * element)
+{
+ GstRTSPMediaFactoryMTPRPrivate *priv;
+
+ g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY_MTPR (factory));
+
+ priv = factory->priv;
+
+ GST_RTSP_MEDIA_FACTORY_MTPR_LOCK (factory);
+ priv->custom_element = element;
+ GST_RTSP_MEDIA_FACTORY_MTPR_UNLOCK (factory);
+}
+
+static GstElement *
+gst_rtsp_media_factory_mtpr_create_element (GstRTSPMediaFactory * factory,
+ const GstRTSPUrl * url)
+{
+ GstRTSPMediaFactoryMTPR *_factory =
+ GST_RTSP_MEDIA_FACTORY_MTPR_CAST (factory);
+ GstRTSPMediaFactoryMTPRPrivate *priv = NULL;
+ GstElement *element = NULL;
+
+ priv = _factory->priv;
+
+ GST_RTSP_MEDIA_FACTORY_MTPR_LOCK (factory);
+
+ if (priv->custom_element) {
+ element = priv->custom_element;
+ } else {
+ element =
+ GST_RTSP_MEDIA_FACTORY_CLASS (parent_class)->create_element (factory,
+ url);
+ }
+
+ GST_RTSP_MEDIA_FACTORY_MTPR_UNLOCK (factory);
+
+ return element;
+}
+
+static GstRTSPMedia *
+gst_rtsp_media_factory_mtpr_construct (GstRTSPMediaFactory * factory,
+ const GstRTSPUrl * url)
+{
+ GstRTSPMedia *media;
+ GstElement *element, *pipeline;
+ GstRTSPMediaFactoryClass *klass;
+
+ klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory);
+
+ if (!klass->create_pipeline)
+ goto no_create;
+
+ element = gst_rtsp_media_factory_create_element (factory, url);
+ if (element == NULL)
+ goto no_element;
+
+ /* create a new empty media */
+ media = gst_rtsp_media_new (element);
+
+ gst_rtsp_media_collect_streams (media);
+
+ pipeline = klass->create_pipeline (factory, media);
+ if (pipeline == NULL)
+ goto no_pipeline;
+
+ GST_ERROR ("pipeline %s, ref %d", GST_ELEMENT_NAME (pipeline),
+ GST_OBJECT_REFCOUNT_VALUE (pipeline));
+
+ GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
+ GST_DEBUG_GRAPH_SHOW_ALL, "mtpr-rtsp-sender");
+
+ return media;
+
+ /* ERRORS */
+no_create:
+ {
+ g_critical ("no create_pipeline function");
+ return NULL;
+ }
+no_element:
+ {
+ g_critical ("could not create element");
+ return NULL;
+ }
+no_pipeline:
+ {
+ g_critical ("can't create pipeline");
+ g_object_unref (media);
+ return NULL;
+ }
+}
--- /dev/null
+/* GStreamer
+ * Copyright (C) 2022 Samsung Electronics
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gst/gst.h>
+#include <gst/rtsp-server/rtsp-media-factory.h>
+
+#ifndef __GST_RTSP_MEDIA_FACTORY_MTPR_H__
+#define __GST_RTSP_MEDIA_FACTORY_MTPR_H__
+
+G_BEGIN_DECLS
+
+/* types for the media factory */
+#define GST_TYPE_RTSP_MEDIA_FACTORY_MTPR (gst_rtsp_media_factory_mtpr_get_type ())
+#define GST_IS_RTSP_MEDIA_FACTORY_MTPR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MEDIA_FACTORY_MTPR))
+#define GST_IS_RTSP_MEDIA_FACTORY_MTPR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MEDIA_FACTORY_MTPR))
+#define GST_RTSP_MEDIA_FACTORY_MTPR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MEDIA_FACTORY_MTPR, GstRTSPMediaFactoryMTPRClass))
+#define GST_RTSP_MEDIA_FACTORY_MTPR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MEDIA_FACTORY_MTPR, GstRTSPMediaFactoryMTPR))
+#define GST_RTSP_MEDIA_FACTORY_MTPR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MEDIA_FACTORY_MTPR, GstRTSPMediaFactoryMTPRClass))
+#define GST_RTSP_MEDIA_FACTORY_MTPR_CAST(obj) ((GstRTSPMediaFactoryMTPR*)(obj))
+#define GST_RTSP_MEDIA_FACTORY_MTPR_CLASS_CAST(klass) ((GstRTSPMediaFactoryMTPRClass*)(klass))
+
+typedef struct _GstRTSPMediaFactoryMTPR GstRTSPMediaFactoryMTPR;
+typedef struct _GstRTSPMediaFactoryMTPRClass GstRTSPMediaFactoryMTPRClass;
+typedef struct _GstRTSPMediaFactoryMTPRPrivate GstRTSPMediaFactoryMTPRPrivate;
+
+/**
+ * GstRTSPMediaFactoryMTPR:
+ *
+ * The definition and logic for constructing the pipeline for a media. The media
+ * can contain multiple streams like audio and video.
+ */
+struct _GstRTSPMediaFactoryMTPR
+{
+ GstRTSPMediaFactory parent;
+
+ /*< private > */
+ GstRTSPMediaFactoryMTPRPrivate *priv;
+ gpointer _gst_reserved[GST_PADDING];
+};
+
+/**
+ * GstRTSPMediaFactoryMTPRClass:
+ * @create_element: Construct and return a #GstElement that is a #GstBin containing
+ * the elements to use for streaming the media. The bin should contain
+ * payloaders pay\%d for each stream. The default implementation of this
+ * function returns the bin created from the launch parameter.
+ * @construct: the vmethod that will be called when the factory has to create the
+ * #GstRTSPMedia for @url. The default implementation of this
+ * function calls create_element to retrieve an element and then looks for
+ * pay\%d to create the streams.
+ * @media_constructed: signal emitted when a media was constructed
+ * @media_configure: signal emitted when a media should be configured
+ *
+ * The #GstRTSPMediaFactoryMTPR class structure.
+ */
+struct _GstRTSPMediaFactoryMTPRClass
+{
+ GstRTSPMediaFactoryClass parent_class;
+
+ GstElement * (*create_element) (GstRTSPMediaFactoryMTPR *factory, const GstRTSPUrl *url);
+ GstRTSPMedia * (*construct) (GstRTSPMediaFactoryMTPR *factory, const GstRTSPUrl *url);
+
+ /*< private >*/
+ gpointer _gst_reserved[GST_PADDING_LARGE];
+};
+
+GST_RTSP_SERVER_API
+GType gst_rtsp_media_factory_mtpr_get_type (void);
+
+GST_RTSP_SERVER_API
+GstRTSPMediaFactoryMTPR * gst_rtsp_media_factory_mtpr_new (void);
+
+GST_RTSP_SERVER_API
+void gst_rtsp_media_factory_mtpr_set_custom_element (GstRTSPMediaFactoryMTPR * factory,
+ GstElement * element);
+
+G_END_DECLS
+#endif /* __GST_RTSP_MEDIA_FACTORY_MTPR_H__ */