Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * GStreamer
- * Copyright (C) 2005 Thomas Vander Stichele <[email protected]>
- * Copyright (C) 2005 Ronald S. Bultje <[email protected]>
- * Copyright (C) 2012 BrianTheLion <<[email protected]>>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Alternatively, the contents of this file may be used under the
- * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
- * which case the following provisions apply instead of the ones
- * mentioned above:
- *
- * 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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
- /**
- * SECTION:element-syncfilter
- *
- * FIXME:Describe syncfilter here.
- *
- * <refsect2>
- * <title>Example launch line</title>
- * |[
- * gst-launch -v -m fakesrc ! syncfilter ! fakesink silent=TRUE
- * ]|
- * </refsect2>
- */
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #include <gst/gst.h>
- #include "gstsyncfilter.h"
- GST_DEBUG_CATEGORY_STATIC (gst_sync_filter_debug);
- #define GST_CAT_DEFAULT gst_sync_filter_debug
- /* Filter signals and args */
- enum {
- /* FILL ME */
- LAST_SIGNAL
- };
- enum {
- PROP_0, PROP_SILENT
- };
- /* the capabilities of the inputs and outputs.
- *
- * describe the real formats here.
- */
- //static GstStaticPadTemplate SINK_FACTORY_GLOBAL = GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS("ANY"));
- static GstStaticPadTemplate SINK_FACTORY_GLOBAL = GST_STATIC_PAD_TEMPLATE(
- "sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY);
- //static GstStaticPadTemplate SRC_FACTORY_GLOBAL = GST_STATIC_PAD_TEMPLATE("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS("ANY"));
- static GstStaticPadTemplate SRC_FACTORY_GLOBAL = GST_STATIC_PAD_TEMPLATE("src",
- GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY);
- #define gst_sync_filter_parent_class parent_class
- G_DEFINE_TYPE(GstSyncFilter, gst_sync_filter, GST_TYPE_ELEMENT);
- static void gst_sync_filter_set_property(GObject * object, guint prop_id,
- const GValue * value, GParamSpec * pspec);
- static void gst_sync_filter_get_property(GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec);
- //static gboolean gst_sync_filter_sink_event(GstPad * pad, GstObject * parent, GstEvent * event);
- //static GstFlowReturn gst_sync_filter_chain(GstPad * pad, GstObject * parent, GstBuffer * buf);
- static GstFlowReturn gst_syncfilter_collected(GstCollectPads * pads,
- GstSyncFilter * filter);
- /* GObject vmethod implementations */
- /* initialize the syncfilter's class */
- static void gst_sync_filter_class_init(GstSyncFilterClass * klass) {
- GObjectClass *gobject_class;
- GstElementClass *gstelement_class;
- gobject_class = (GObjectClass *) klass;
- gstelement_class = (GstElementClass *) klass;
- gobject_class->set_property = gst_sync_filter_set_property;
- gobject_class->get_property = gst_sync_filter_get_property;
- g_object_class_install_property(gobject_class, PROP_SILENT,
- g_param_spec_boolean("silent", "Silent", "Produce verbose output ?",
- FALSE, G_PARAM_READWRITE));
- gst_element_class_set_details_simple(gstelement_class, "SyncFilter",
- "FIXME:Generic", "FIXME:Generic Template Element",
- gst_element_class_add_pad_template(gstelement_class,
- gst_static_pad_template_get(&SRC_FACTORY_GLOBAL));
- gst_element_class_add_pad_template(gstelement_class,
- gst_static_pad_template_get(&SINK_FACTORY_GLOBAL));
- }
- /* initialize the new element
- * instantiate pads and add them to element
- * set pad calback functions
- * initialize instance structure
- */
- static void gst_sync_filter_init(GstSyncFilter * filter) {
- filter->asnkpad = gst_pad_new_from_static_template(&SINK_FACTORY_GLOBAL,
- "asnk");
- // gst_pad_set_event_function(filter->asnkpad, GST_DEBUG_FUNCPTR(gst_sync_filter_sink_event));
- // gst_pad_set_chain_function(filter->asnkpad, GST_DEBUG_FUNCPTR(gst_sync_filter_chain));
- GST_PAD_SET_PROXY_CAPS(filter->asnkpad);
- gst_element_add_pad(GST_ELEMENT(filter), filter->asnkpad);
- filter->vsnkpad = gst_pad_new_from_static_template(&SINK_FACTORY_GLOBAL,
- "vsnk");
- // gst_pad_set_event_function(filter->vsnkpad, GST_DEBUG_FUNCPTR(gst_sync_filter_sink_event));
- // gst_pad_set_chain_function(filter->vsnkpad, GST_DEBUG_FUNCPTR(gst_sync_filter_chain));
- GST_PAD_SET_PROXY_CAPS(filter->vsnkpad);
- gst_element_add_pad(GST_ELEMENT(filter), filter->vsnkpad);
- filter->asrcpad = gst_pad_new_from_static_template(&SRC_FACTORY_GLOBAL,
- "asrc");
- GST_PAD_SET_PROXY_CAPS(filter->asrcpad);
- gst_element_add_pad(GST_ELEMENT(filter), filter->asrcpad);
- filter->vsrcpad = gst_pad_new_from_static_template(&SRC_FACTORY_GLOBAL,
- "vsrc");
- GST_PAD_SET_PROXY_CAPS(filter->vsrcpad);
- gst_element_add_pad(GST_ELEMENT(filter), filter->vsrcpad);
- filter->collect = gst_collect_pads_new();
- gst_collect_pads_set_function(filter->collect,
- (GstCollectPadsFunction) gst_syncfilter_collected, filter);
- filter->video_collect_data = gst_collect_pads_add_pad(filter->collect,
- filter->asnkpad, sizeof(GstCollectData), NULL, TRUE);
- filter->audio_collect_data = gst_collect_pads_add_pad(filter->collect,
- filter->vsnkpad, sizeof(GstCollectData), NULL, TRUE);
- filter->silent = FALSE;
- }
- static void gst_sync_filter_set_property(GObject * object, guint prop_id,
- const GValue * value, GParamSpec * pspec) {
- GstSyncFilter *filter = GST_SYNCFILTER (object);
- switch (prop_id) {
- case PROP_SILENT:
- filter->silent = g_value_get_boolean(value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
- }
- static void gst_sync_filter_get_property(GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec) {
- GstSyncFilter *filter = GST_SYNCFILTER (object);
- switch (prop_id) {
- case PROP_SILENT:
- g_value_set_boolean(value, filter->silent);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
- }
- /* GstElement vmethod implementations */
- /* this function handles sink events */
- //static gboolean gst_sync_filter_sink_event(GstPad * pad, GstObject * parent, GstEvent * event) {
- // gboolean ret;
- // GstSyncFilter *filter;
- //
- // filter = GST_SYNCFILTER (parent);
- //
- // switch (GST_EVENT_TYPE(event)) {
- // case GST_EVENT_CAPS: {
- // GstCaps * caps;
- //
- // gst_event_parse_caps(event, &caps);
- // /* do something with the caps */
- //
- // /* and forward */
- // ret = gst_pad_event_default(pad, parent, event);
- // break;
- // }
- // default:
- // ret = gst_pad_event_default(pad, parent, event);
- // break;
- // }
- // return ret;
- //}
- /* chain function
- * this function does the actual processing
- */
- //static GstFlowReturn gst_sync_filter_chain(GstPad * pad, GstObject * parent, GstBuffer * buf) {
- // GstSyncFilter *filter;
- //
- // filter = GST_SYNCFILTER (parent);
- //
- // if (filter->silent == FALSE)
- // g_print("I'm plugged, therefore I'm in.\n");
- //
- // /* just push out the incoming buffer without touching it */
- // return gst_pad_push(filter->srcpad, buf);
- //}
- static GstFlowReturn gst_syncfilter_collected(GstCollectPads * pads,
- GstSyncFilter * filter) {
- GstFlowReturn ret = GST_FLOW_OK;
- // GstClockTime now, video_end, audio_end;
- GstBuffer *video_frame = NULL;
- GstBuffer *audio_buffer = NULL;
- // gchar *text;
- // gint text_len;
- GST_DEBUG("Collecting");
- video_frame = gst_collect_pads_peek(filter->collect,
- filter->video_collect_data);
- audio_buffer = gst_collect_pads_peek(filter->collect,
- filter->audio_collect_data);
- if (video_frame != NULL) {
- if (GST_BUFFER_TIMESTAMP(video_frame) == GST_CLOCK_TIME_NONE)
- g_warning("%s: video frame has invalid timestamp", G_STRLOC);
- // GST_DEBUG ("Got video frame: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT, GST_TIME_ARGS (now), GST_TIME_ARGS (frame_end));
- ret = gst_pad_push(filter->vsrcpad, video_frame);
- }
- if (audio_buffer != NULL) {
- if (GST_BUFFER_TIMESTAMP(audio_buffer) == GST_CLOCK_TIME_NONE)
- g_warning("%s: audio buffer has invalid timestamp", G_STRLOC);
- // txt_end = GST_BUFFER_TIMESTAMP(audio_buffer) + GST_BUFFER_DURATION(audio_buffer);
- // GST_DEBUG ("Got text buffer: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (text_buf)), GST_TIME_ARGS (txt_end));
- ret = gst_pad_push(filter->asrcpad, audio_buffer);
- }
- if ((video_frame == NULL) & (audio_buffer == NULL)) {
- gst_pad_push_event(filter->asrcpad, gst_event_new_eos());
- gst_pad_push_event(filter->vsrcpad, gst_event_new_eos());
- ret = GST_FLOW_EOS;
- goto done;
- }
- // /* send EOS if video stream EOSed regardless of text stream */
- // if (video_frame == NULL) {
- // GST_DEBUG("Video stream at EOS");
- // if (filter->audio_collect_data) {
- // audio_buffer = gst_collect_pads_pop(filter->collect, filter->audio_collect_data);
- // }
- // gst_pad_push_event(filter->vsrcpad, gst_event_new_eos());
- // ret = GST_FLOW_EOS;
- // goto done;
- // }
- // if (GST_BUFFER_TIMESTAMP(video_frame) == GST_CLOCK_TIME_NONE) {
- // g_warning("%s: video frame has invalid timestamp", G_STRLOC);
- // }
- // now = GST_BUFFER_TIMESTAMP(video_frame);
- //
- // if (GST_BUFFER_DURATION(video_frame) != GST_CLOCK_TIME_NONE) {
- // frame_end = now + GST_BUFFER_DURATION(video_frame);
- // } else if (filter->fps_n > 0) {
- // frame_end = now + gst_util_uint64_scale_int(GST_SECOND, filter->fps_d, filter->fps_n);
- // } else {
- // /* magic value, does not really matter since texts
- // * tend to span quite a few frames in practice anyway */
- // frame_end = now + GST_SECOND / 25;
- // }
- //
- // GST_DEBUG ("Got video frame: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT, GST_TIME_ARGS (now), GST_TIME_ARGS (frame_end));
- //
- // /* text pad not linked? */
- // if (filter->audio_collect_data == NULL) {
- // GST_DEBUG("Text pad not linked, rendering default text: '%s'", GST_STR_NULL(filter->default_text));
- // if (filter->default_text && *filter->default_text != '\0') {
- // gst_text_overlay_render_text(filter, filter->default_text, -1);
- // ret = gst_text_overlay_push_frame(filter, video_frame);
- // } else {
- // ret = gst_pad_push(filter->srcpad, video_frame);
- // }
- // gst_text_overlay_pop_video(filter);
- // video_frame = NULL;
- // goto done;
- // }
- // audio_buffer = gst_collect_pads_peek(filter->collect, filter->audio_collect_data);
- /* just push the video frame if the text stream has EOSed */
- // if (audio_buffer == NULL) {
- // GST_DEBUG("Text pad EOSed, just pushing video frame as is");
- // ret = gst_pad_push(filter->srcpad, video_frame);
- // gst_text_overlay_pop_video(filter);
- // video_frame = NULL;
- // goto done;
- // }
- /* if the text buffer isn't stamped right, pop it off the
- * queue and display it for the current video frame only */
- // if (GST_BUFFER_TIMESTAMP(audio_buffer) == GST_CLOCK_TIME_NONE || GST_BUFFER_DURATION(audio_buffer) == GST_CLOCK_TIME_NONE) {
- // GST_WARNING("Got text buffer with invalid time stamp or duration");
- // gst_text_overlay_pop_text(filter);
- // GST_BUFFER_TIMESTAMP (text_buf) = now;
- // GST_BUFFER_DURATION (text_buf) = frame_end - now;
- // }
- // txt_end = GST_BUFFER_TIMESTAMP(audio_buffer) + GST_BUFFER_DURATION(audio_buffer);
- //
- // GST_DEBUG ("Got text buffer: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (text_buf)), GST_TIME_ARGS (txt_end));
- /* if the text buffer is too old, pop it off the
- * queue and return so we get a new one next time */
- // if (txt_end < now) {
- // GST_DEBUG("Text buffer too old, popping off the queue");
- // gst_text_overlay_pop_text(filter);
- // ret = GST_FLOW_OK;
- // goto done;
- // }
- /* if the video frame ends before the text even starts,
- * just push it out as is and pop it off the queue */
- // if (frame_end < GST_BUFFER_TIMESTAMP(audio_buffer)) {
- // GST_DEBUG("Video buffer before text, pushing out and popping off queue");
- // ret = gst_pad_push(filter->srcpad, video_frame);
- // gst_text_overlay_pop_video(filter);
- // video_frame = NULL;
- // goto done;
- // }
- /* text duration overlaps video frame duration */
- // text = g_strndup((gchar *) GST_BUFFER_DATA(audio_buffer), GST_BUFFER_SIZE(audio_buffer));
- // g_strdelimit(text, "\n\r\t", ' ');
- // text_len = strlen(text);
- // if (text_len > 0) {
- // GST_DEBUG("Rendering text '%*s'", text_len, text);
- // ;
- // gst_text_overlay_render_text(filter, text, text_len);
- // } else {
- // GST_DEBUG("No text to render (empty buffer)");
- // gst_text_overlay_render_text(filter, " ", 1);
- // }
- //
- // g_free(text);
- //
- // gst_text_overlay_pop_video(filter);
- // ret = gst_text_overlay_push_frame(filter, video_frame);
- // video_frame = NULL;
- // goto done;
- done: {
- if (audio_buffer)
- gst_buffer_unref(audio_buffer);
- if (video_frame)
- gst_buffer_unref(video_frame);
- return ret;
- }
- }
- /* entry point to initialize the plug-in
- * initialize the plug-in itself
- * register the element factories and other features
- */
- static gboolean syncfilter_init(GstPlugin * syncfilter) {
- /* debug category for fltering log messages
- *
- * exchange the string 'Template syncfilter' with your description
- */
- GST_DEBUG_CATEGORY_INIT(gst_sync_filter_debug, "syncfilter", 0,
- "Template syncfilter");
- return gst_element_register(syncfilter, "syncfilter", GST_RANK_NONE,
- GST_TYPE_SYNCFILTER);
- }
- /* PACKAGE: this is usually set by autotools depending on some _INIT macro
- * in configure.ac and then written into and defined in config.h, but we can
- * just set it ourselves here in case someone doesn't use autotools to
- * compile this code. GST_PLUGIN_DEFINE needs PACKAGE to be defined.
- */
- #ifndef PACKAGE
- #define PACKAGE "myfirstsyncfilter"
- #endif
- /* gstreamer looks for this structure to register syncfilters
- *
- * exchange the string 'Template syncfilter' with your syncfilter description
- */
- GST_PLUGIN_DEFINE (
- GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- syncfilter,
- "Template syncfilter",
- syncfilter_init,
- VERSION,
- "LGPL",
- "GStreamer",
- "http://gstreamer.net/"
- )
Advertisement
Add Comment
Please, Sign In to add comment