Last active
May 26, 2022 16:48
-
-
Save michaelgruner/b1c2d138ed76c49244cb8172e0e35b3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* gcc gstoddsrc.c `pkg-config --cflags --libs gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0` -shared -o gstoddsrc.so | |
* | |
* GST_DEBUG=2 gst-launch-1.0 oddsrc ! video/x-raw,format=BGR,width=321,height=240 ! videoconvert ! autovideosink | |
* | |
* | |
*/ | |
#include <gst/gst.h> | |
#include <gst/base/gstpushsrc.h> | |
#include <gst/video/video.h> | |
#define GST_TYPE_ODD_SRC (gst_odd_src_get_type()) | |
G_DECLARE_FINAL_TYPE (GstOddSrc, gst_odd_src, GST, ODD_SRC, GstPushSrc) | |
struct _GstOddSrc | |
{ | |
GstPushSrc base_odd_src; | |
}; | |
GST_DEBUG_CATEGORY_STATIC (gst_odd_src_debug_category); | |
#define GST_CAT_DEFAULT gst_odd_src_debug_category | |
/* prototypes */ | |
GType gst_odd_src_get_type (void); | |
static GstFlowReturn gst_odd_src_alloc(GstPushSrc *src, GstBuffer **buf); | |
static GstFlowReturn gst_odd_src_fill (GstPushSrc * src, GstBuffer * buf); | |
enum | |
{ | |
PROP_0 | |
}; | |
/* pad templates */ | |
static GstStaticPadTemplate gst_odd_src_src_template = | |
GST_STATIC_PAD_TEMPLATE ("src", | |
GST_PAD_SRC, | |
GST_PAD_ALWAYS, | |
GST_STATIC_CAPS ("video/x-raw,width=321,height=240,format=BGR,framerate=30/1") | |
); | |
/* class initialization */ | |
G_DEFINE_TYPE_WITH_CODE (GstOddSrc, gst_odd_src, GST_TYPE_PUSH_SRC, | |
GST_DEBUG_CATEGORY_INIT (gst_odd_src_debug_category, "oddsrc", 0, | |
"debug category for oddsrc element")); | |
static void | |
gst_odd_src_class_init (GstOddSrcClass * klass) | |
{ | |
GstPushSrcClass *push_src_class = GST_PUSH_SRC_CLASS (klass); | |
/* Setting up pads and setting metadata should be moved to | |
base_class_init if you intend to subclass this class. */ | |
gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass), | |
&gst_odd_src_src_template); | |
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass), | |
"Odd Src", "Generic", "Send frames with odd widths and no stride", | |
"Michael Gruner <michael.gruner@ridgerun.com>"); | |
push_src_class->alloc = GST_DEBUG_FUNCPTR (gst_odd_src_alloc); | |
push_src_class->fill = GST_DEBUG_FUNCPTR (gst_odd_src_fill); | |
} | |
static void | |
gst_odd_src_init (GstOddSrc * oddsrc) | |
{ | |
gst_base_src_set_format (GST_BASE_SRC(oddsrc), GST_FORMAT_TIME); | |
gst_base_src_set_live (GST_BASE_SRC(oddsrc), TRUE); | |
} | |
static GstFlowReturn | |
gst_odd_src_alloc (GstPushSrc * src, GstBuffer ** buf) | |
{ | |
GstOddSrc *self = GST_ODD_SRC (src); | |
gint size = 321*240*3; | |
*buf = gst_buffer_new_allocate (NULL, size, NULL); | |
return GST_FLOW_OK; | |
} | |
static GstFlowReturn | |
gst_odd_src_fill (GstPushSrc * src, GstBuffer * buf) | |
{ | |
GstOddSrc *self = GST_ODD_SRC (src); | |
gsize offset[GST_VIDEO_MAX_PLANES] = { 0 }; | |
gint stride[GST_VIDEO_MAX_PLANES] = { 321*3, 0, 0, 0 }; | |
GstMapInfo info = { 0 }; | |
GstVideoMeta *meta = NULL; | |
meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE, GST_VIDEO_FORMAT_BGR, | |
321, 240, 1, offset, stride); | |
gst_buffer_map (buf, &info, GST_MAP_WRITE); | |
memset (info.data, 0, info.size); | |
memset (info.data + 321*3*80, 255, 321*3*80); | |
gst_buffer_unmap (buf, &info); | |
return GST_FLOW_OK; | |
} | |
static gboolean | |
plugin_init (GstPlugin * plugin) | |
{ | |
/* FIXME Remember to set the rank if it's an element that is meant | |
to be autoplugged by decodebin. */ | |
return gst_element_register (plugin, "oddsrc", GST_RANK_NONE, | |
GST_TYPE_ODD_SRC); | |
} | |
/* FIXME: these are normally defined by the GStreamer build system. | |
If you are creating an element to be included in gst-plugins-*, | |
remove these, as they're always defined. Otherwise, edit as | |
appropriate for your external plugin package. */ | |
#ifndef VERSION | |
#define VERSION "0.0.FIXME" | |
#endif | |
#ifndef PACKAGE | |
#define PACKAGE "FIXME_package" | |
#endif | |
#ifndef PACKAGE_NAME | |
#define PACKAGE_NAME "FIXME_package_name" | |
#endif | |
#ifndef GST_PACKAGE_ORIGIN | |
#define GST_PACKAGE_ORIGIN "http://FIXME.org/" | |
#endif | |
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, | |
GST_VERSION_MINOR, | |
oddsrc, | |
"FIXME plugin description", | |
plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment