From: Yechan Choi Date: Thu, 4 Aug 2022 05:12:35 +0000 (+0900) Subject: [Gst/Edge] Init edgesrc and edgesink X-Git-Tag: accepted/tizen/unified/20220925.234926~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=358c12090e7bd2b81cf5ae83a139a3774eb0f414;p=platform%2Fupstream%2Fnnstreamer.git [Gst/Edge] Init edgesrc and edgesink Init skelton of edgesrc and edgesink. Signed-off-by: Yechan Choi --- diff --git a/gst/edge/README.md b/gst/edge/README.md new file mode 100644 index 0000000..e69de29 diff --git a/gst/edge/edge_common.c b/gst/edge/edge_common.c new file mode 100644 index 0000000..b4d9a5e --- /dev/null +++ b/gst/edge/edge_common.c @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. + * + * @file edge_common.c + * @date 01 Aug 2022 + * @brief Common functions for edge sink and src + * @author Yechan Choi + * @see http://github.com/nnstreamer/nnstreamer + * @bug No known bugs + * + */ diff --git a/gst/edge/edge_common.h b/gst/edge/edge_common.h new file mode 100644 index 0000000..1fb8385 --- /dev/null +++ b/gst/edge/edge_common.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. + * + * @file edge_common.h + * @date 01 Aug 2022 + * @brief Common functions for edge sink and src + * @author Yechan Choi + * @see http://github.com/nnstreamer/nnstreamer + * @bug No known bugs + * + */ +#ifndef __GST_EDGE_H__ +#define __GST_EDGE_H__ + +G_BEGIN_DECLS +#ifndef UNUSED +#define UNUSED(expr) do { (void)(sizeof(x), 0); } while (0) +#endif /* UNUSED */ +#ifndef GST_EDGE_PACKAGE +#define GST_EDGE_PACKAGE "GStreamer Edge Plugins" +#endif /* GST_EDGE_PACKAGE */ +#define GST_EDGE_ELEM_NAME_SINK "edgesink" +#define GST_EDGE_ELEM_NAME_SRC "edgesrc" + G_END_DECLS +#endif /* __GST_EDGE_H__ */ diff --git a/gst/edge/edge_elements.c b/gst/edge/edge_elements.c new file mode 100644 index 0000000..eb995c2 --- /dev/null +++ b/gst/edge/edge_elements.c @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. + * + * @file edge_sink.h + * @date 02 Aug 2022 + * @brief Register edge plugins + * @author Yechan Choi + * @see http://github.com/nnstreamer/nnstreamer + * @bug No known bugs + * + */ +#include + +#include "edge_common.h" +#include "edge_sink.h" +#include "edge_src.h" + +/** + * @brief The entry point of the Gstreamer Edge plugin + */ +static gboolean +plugin_init (GstPlugin * plugin) +{ + if (!gst_element_register (plugin, GST_EDGE_ELEM_NAME_SINK, GST_RANK_NONE, + GST_TYPE_EDGESINK)) { + return FALSE; + } + + if (!gst_element_register (plugin, GST_EDGE_ELEM_NAME_SRC, GST_RANK_NONE, + GST_TYPE_EDGESRC)) { + return FALSE; + } + + return TRUE; +} + +#ifndef PACKAGE +#define PACKAGE GST_EDGE_PACKAGE +#endif + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, edge, + "A collcetion of GStreamer plugins to support Edge", + plugin_init, VERSION, "LGPL", PACKAGE, + "https://github.com/nnstreamer/nnstreamer") diff --git a/gst/edge/edge_sink.c b/gst/edge/edge_sink.c new file mode 100644 index 0000000..5525ea5 --- /dev/null +++ b/gst/edge/edge_sink.c @@ -0,0 +1,172 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. + * + * @file edge_sink.h + * @date 01 Aug 2022 + * @brief Publish incoming streams + * @author Yechan Choi + * @see http://github.com/nnstreamer/nnstreamer + * @bug No known bugs + * + */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "edge_sink.h" + +GST_DEBUG_CATEGORY_STATIC (gst_edgesink_debug); +#define GST_CAT_DEFAULT gst_edgesink_debug + +/** + * @brief the capabilities of the inputs. + */ +static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +enum +{ + PROP_0, + + /** @todo define props */ + + PROP_LAST +}; + +#define gst_edgesink_parent_class parent_class +G_DEFINE_TYPE (GstEdgeSink, gst_edgesink, GST_TYPE_BASE_SINK); + +static void gst_edgesink_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSepc * pspec); + +static void gst_edgesink_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); + +static void gst_edgesink_finalize (GObject * object); + +static gboolean gst_edgesink_start (GstBaseSink * basesink); +static GstFlowReturn gst_edgesink_render (GstBaseSink * basesink, + GstBuffer * buf); +static gboolean gst_edgesink_set_caps (GstBaseSink * basesink, GstCaps * caps); + +/** + * @brief initialize the class + */ +static void +gst_edgesink_class_init (GstEdgeSinkClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gselement_class; + GstBaseSinkClass *gstbasesink_class; + + gstbasesink_class = (GstBaseSinkClass *) klass; + gstelement_class = (GstElementClass *) gstbasesink_class; + gobject_class = (GObjectClass *) gstelement_class; + + gobject_class->set_property = gst_edgesink_set_property; + gobject_class->get_property = gst_edgesink_get_property; + gobject_class->finalize = gst_edgesink_finalize; + + /** @todo set props */ + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&sinktemplate)); + + gst_element_class_set_static_metadata (gstelement_class, + "EdgeSink", "Sink/Edge", + "Publish incoming streams", "Samsung Electronics Co., Ltd."); + + gstbasesink_class->start = gst_edgesink_start; + gstbasesink_class->render = gst_edgesink_render; + gstbasesink_class->set_caps = gst_edgesink_set_caps; + + GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, + GST_EDGE_ELEM_NAME_SINK, 0, "Edge sink"); +} + +/** + * @brief initialize the new element + */ +static void +gst_edgesink_init (GstEdgeSink * sink) +{ + /** @todo set default value of props */ +} + + +/** + * @brief finalize the object + */ +static void +gst_edgesink_finalize (GObject * object) +{ + GstEdgeSink *self = GST_EDGESINK (object); + /** @todo finalize - free all pointer in element */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +/** + * @brief set property + */ +static void +gst_edgesink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstEdgeSink *self = GST_EDGESINK (object); + + switch (prop_id) { + /** @todo set prop */ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/** + * @brief get property + */ +static void +gst_edgesink_get_property (GObject * object, guint prop_id, GValue * value, + GParmSpec * pspec) +{ + GstEdgeSInk *self = GST_EDGESINK (object); + + switch (prop_id) { + /** @todo props */ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/** + * @brief start processing of edgesink + */ +static gboolean +gst_edgesink_start (GstBaseSink * basesink) +{ + GstEdgeSink *sink = GST_EDGESINK (basesink); + + /** @todo start */ +} + +/** + * @brief render buffer, send buffer + */ +static GstFlowReturn +gst_edgesink_render (GstBaseSink * basesink, GstBuffer * buf) +{ + /** @todo render, send data */ +} + +/** + * @brief An implementation of the set_caps vmethod in GstBaseSinkClass + */ +static gboolean +gst_edgesink_set_caps (GstBaseSink * basesink, GstCaps * caps) +{ + /** @todo set caps */ +} diff --git a/gst/edge/edge_sink.h b/gst/edge/edge_sink.h new file mode 100644 index 0000000..c8c453c --- /dev/null +++ b/gst/edge/edge_sink.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. + * + * @file edge_sink.h + * @date 01 Aug 2022 + * @brief Publish incoming streams + * @author Yechan Choi + * @see http://github.com/nnstreamer/nnstreamer + * @bug No known bugs + * + */ +#ifndef __GST_EDGE_SINK_H__ +#define __GST_EDGE_SINK_H__ + +#include +#include + +G_BEGIN_DECLS +#define GST_TYPE_EDGESINK \ + (gst_edgesink_get_type()) +#define GST_EDGESINK(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EDGESINK,GstEdgeSink)) +#define GST_EDGESINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EDGESINK,GstEdgeSinkClass)) +#define GST_IS_EDGESINK(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDGESINK)) +#define GST_IS_EDGESINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EDGESINK)) +#define GST_EDGESINK_CAST(obj) ((GstEdgeSink *)(obj)) +typedef struct _GstEdgeSink GstEdgeSink; +typedef struct _GstEdgeSinkClass GstEdgeSinkClass; + +/** + * @brief GstEdgeSink data structure. + */ +struct _GstEdgeSink +{ + GstBaseSink element; + +}; + +/** + * @brief GstEdgeSinkClass data structure. + */ +struct _GstEdgeSinkClass +{ + GstBaseSinkClass parent_class; /** + * @see http://github.com/nnstreamer/nnstreamer + * @bug No known bugs + * + */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "edge_src.h" + +GST_DEBUG_CATEGORY_STATIC (gst_edgesrc_debug); +#define GST_CAT_DEFAULT gst_edgesrc_debug + +/** + * @brief the capabilities of the outputs + */ +static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY); + +/** + * @brief edgesrc properties + */ +enum +{ + PROP_0, + + /** @todo define props */ + + PROP_LAST +} + +#define gst_edgesrc_parent_class parent_class +G_DEFINE_TYPE (GstEdgeSrc, gst_edgesrc, GST_TYPE_PUSH_SRC); + +static void gst_edgesrc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_edgesrc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static void gst_edgesrc_class_finalize (GObject * object); + +static GstStateChangeReturn gst_edgesrc_change_state (GstElement * element, + GstStateChange transition); + +static gboolean gst_edgesrc_start (GstBaseSrc * basesrc); +static gboolean gst_edgesrc_stop (GstBaseSrc * basesrc); +static GstCaps *gst_edgesrc_get_caps (GstBaseSrc * basesrc, GstCaps * filter); +static void gst_edgesrc_get_times (GstBaseSrc * basesrc, GstBuffer * buffer, + GstClockTime * start, GstClockTime * end); +static gboolean gst_edgesrc_is_seekable (GstBaseSrc * basesrc); +static GstFlowReturn gst_edgesrc_create (GstBaseSrc * basesrc, guint64 offset, + guint size, GstBuffer ** buf); +static gboolean gst_edgesrc_query (GstBaseSrc * basesrc, GstQuery * query); + +/** + * @brief initialize the class + */ +static void +gst_edgesrc_class_init (GstEdgeSrcClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); + GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); + + gobject_class->set_property = gst_edgesrc_set_property; + gobject_class->get_property = gst_edgesrc_get_property; + gobject_class->finalize = gst_edgesrc_class_finalize; + + /** @todo set props */ + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&srctemplate)); + + gst_element_class_set_static_metadata (gelement_class, + "EdgeSrc", "Source/Edge", + "Subscribe and push incoming streams", "Samsung Electronics Co., Ltd."); + + gstelement_class->change_state = gst_edgesrc_change_state; + + gstbasesrc_class->start = gst_edgesrc_start; + gstbasesrc_class->stop = gst_edgesrc_stop; + gstbasesrc_class->get_caps = gst_edgesrc_get_caps; + gstbasesrc_class->get_times = gst_edgesrc_get_times; + gstbasesrc_class->is_seekable = gst_edgesrc_is_seekable; + gstbasesrc_class->create = gst_edgesrc_create; + gstbasesrc_class->query = gst_edgesrc_query; + + GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, + GST_EDGE_ELEM_NAME_SRC, 0, "Edge src"); +} + +/** + * @brief initialize edgesrc element + */ +static void +gst_edgesrc_init (GstEdgeSrc * self) +{ + GstBaseSrc *basesrc = GST_BASE_SRC (self); + + gst_base_src_set_format (basesrc, GST_FORMAT_TIME); + gst_base_src_set_async (basesrc, FALSE); + + /** @todo set default value of props */ +} + +/** + * @brief set property + */ +static void +gst_edgesrc_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) +{ + GstEdgeSrc *self = GST_EDGESRC (object); + + switch (prod_id) { + /** @todo set prop */ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/** + * @brief get property + */ +static void +gst_edgesrc_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) +{ + GstEdgeSrc *self = GST_EDGESRC (object); + + switch (prop_id) { + /** @todo props */ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/** + * @brief finalize the object + */ +static void +gst_edgesrc_class_finalize (GObject * object) +{ + GstEdgeSrc *self = GST_EDGESRC (object); + /** @todo finalize - free all pointer in element */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +/** + * @brief handle edgesrc's state change + */ +static GstStateChangeReturn +gst_edgesrc_change_state (GstElement * element, GstStateChange transition) +{ + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + + GstEdgeSrc *self = GST_EDGESRC (element); + + /** @todo handle transition */ + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + + /** @todo handle transition */ + + return ret; +} + +/** + * @brief start edgesrc, called when state changed null to ready + */ +static gboolean +gst_edgesrc_start (GstBaseSrc * basesrc) +{ + GstEdgeSrc *self = GST_EDGESRC (basesrc); + + /** @todo start */ +} + +/** + * @brief stop edgesrc, called when state changed ready to null + */ +static gboolean +gst_edgesrc_stop (GstBaseSrc * basesrc) +{ + GstEdgeSrc *self = GST_EDGESRC (basesrc); + + /** @todo stop */ +} + +/** + * @brief Get caps of subclass + */ +static GstCaps * +gst_edgesrc_get_caps (GstBaseSrc * basesrc, GstCaps * filter) +{ + /** @todo get caps */ +} + +/** + * @brief Return the time information of the given buffer + */ +static void +gst_edgesrc_get_times (GstBaseSrc * basesrc, GstBuffer * buffer, + GstClockTime * start, GstClockTime * end) +{ + /** @todo get times */ +} + +/** + * @brief Check if source supports seeking + */ +static gboolean +gst_edgesrc_is_seekable (GstBaseSrc * basesrc) +{ + /** @todo is seekable */ +} + +/** + * @brief Create a buffer containing the subscribed data + */ +static GstFlowReturn +gst_edgesrc_create (GstBaseSrc * basesrc, guint64 offset, guint size, + GstBuffer ** buf) +{ + GstEdgeSrc *self = GST_EDGESRC (basesrc); + + /** @todo create */ +} + +/** + * @brief An implementation of the GstBaseSrc vmethod that handles queries + */ +static gboolean +gst_edgesrc_query (GstBaseSrc * basesrc, GstQuery * query) +{ + /** @todo query */ +} diff --git a/gst/edge/edge_src.h b/gst/edge/edge_src.h new file mode 100644 index 0000000..af66c6d --- /dev/null +++ b/gst/edge/edge_src.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. + * + * @file edge_src.h + * @date 02 Aug 2022 + * @brief Subscribe and push incoming data to the GStreamer pipeline + * @author Yechan Choi + * @see http://github.com/nnstreamer/nnstreamer + * @bug No known bugs + * + */ +#ifndef __GST_EDGE_SRC_H__ +#define __GST_EDGE_SRC_H__ + +#include + +G_BEGIN_DECLS +#define GST_TYPE_EDGESRC \ + (gst_edgesrc_get_type()) +#define GST_EDGESRC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EDGESRC,GstEdgeSrc)) +#define GST_EDGESRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EDGESRC,GstEdgeSrcClass)) +#define GST_IS_EDGESRC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDGESRC)) +#define GST_IS_EDGESRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_EDGESRC)) +#define GST_EDGESRC_CAST(obj) ((GstEdgeSrc *) (obj)) +typedef struct _GstEdgeSrc GstEdgeSrc; +typedef struct _GstEdgeSrcClass GstEdgeSinkClass; + +/** + * @brief GstEdgeSrc data structure. + */ +struct _GstEdgeSrc +{ + GstBaseSrc element; +} + +/** + * @brief GstEdgeSrcClass data structure. + */ +struct _GstEdgeSrcClass +{ + GstBaseSrcClass parent_class; +} + +GType gst_edgesrc_get_type (void); + +G_END_DECLS +#endif /* __GST_EDGE_SRC_H__ */ diff --git a/gst/edge/meson.build b/gst/edge/meson.build new file mode 100644 index 0000000..1ef797b --- /dev/null +++ b/gst/edge/meson.build @@ -0,0 +1,31 @@ +edge_files = [ + 'edge_common.c', + 'edge_elements.c', + 'edge_sink.c', + 'edge_src.c', +] + +edge_srcs = [] +edge_dep = [ + glib_dep, + gst_base_dep, + gst_dep, +] + +foreach s : edge_files + edge_srcs += join_paths(meson.current_source_dir(), s) +endforeach + +gstedge_shared = shared_library('gstedge', + edge_srcs, + dependencies: edge_dep, + install: true, + include_directories: include_directories('../nnstreamer/include'), + install_dir: plugins_install_dir +) + +gstedge_dep = declare_dependency( + link_with: gstedge_shared, + dependencies: edge_dep, + include_directories: include_directories('.') +) diff --git a/gst/meson.build b/gst/meson.build index 2ae3c0e..f500695 100644 --- a/gst/meson.build +++ b/gst/meson.build @@ -1,3 +1,4 @@ +subdir('edge') subdir('join') if mqtt_support_is_available subdir('mqtt')