Combining data from two chain_functions

iron_guitarist1987 jtrinidadperez at gmail.com
Thu Aug 2 13:12:50 PDT 2012


Hello all,

I am creating a plugin that has two sinkpads with a chain_function each. The
idea is that when a pad receives data, it will store it in a static variable
in a function that is shared by both chain functions. The problem that I am
having is that when I run the pipeline, only one of the chain functions is
being called. In the code below, only the struct chain function is being
called.

Why is the text chain function not being called? I have created a src
element plugins for text and the structure and tested them with a collect
function, and they work. 


Another option would be to have only one chain function. Can it be possible
to have just one chain function, even if the inputs are very different?

Thank you.

/**
 * SECTION:element-ntoone_chain
 *
 * <refsect2>
 * <title>Sample pipelines</title>
 * |[
 * gst-launch texttestsrc ! ntoone_chain name=n ! structsink structtestsrc !
n.  
 * ]| A pipeline to demonstrate the ntoone_chain element.
 * </refsect2>
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include "gstntoone_chain.h"
#include <gst/video/video.h>
#include "datasetup.h"
#include "structtypes.h"

GST_DEBUG_CATEGORY_STATIC (gst_ntoone_chain_debug);
#define GST_CAT_DEFAULT gst_ntoone_chain_debug

static GstStaticPadTemplate gst_struct_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("structure/struct")
    );

static GstStaticPadTemplate gst_text_sink_template =
GST_STATIC_PAD_TEMPLATE ("text_sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("text/plain")
    );
static GstStaticPadTemplate gst_struct_sink_template =
GST_STATIC_PAD_TEMPLATE ("struct_sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("structure/struct")
    );

/* NTOONE_CHAIN signals and args */
enum
{
  /* FILL ME */
  LAST_SIGNAL
};

enum
{
  PROP_0,
  PROP_INPUT
};

static void gst_ntoone_chain_class_init (GstNTOONE_CHAINClass * klass);
static void gst_ntoone_chain_base_init (GstNTOONE_CHAINClass * klass);
static void gst_ntoone_chain_init (GstNTOONE_CHAIN * ntoone_chain);
static void gst_ntoone_chain_finalize (GstNTOONE_CHAIN * ntoone_chain);

static GstFlowReturn gst_ntoone_chain_text (GstPad * pad, GstBuffer * buf);
static GstFlowReturn gst_ntoone_chain_struct (GstPad * pad, GstBuffer *
buf);

static void gst_ntoone_chain_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec);
static void gst_ntoone_chain_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec);

extern void parse_text(char *unparsed_data, text_val *tvals);

static GstElementClass *parent_class = NULL;

/*static guint gst_ntoone_chain_signals[LAST_SIGNAL] = { 0 }; */

static GType
gst_ntoone_chain_get_type (void)
{
  static GType ntoone_chain_type = 0;

  if (!ntoone_chain_type) {
    static const GTypeInfo ntoone_chain_info = {
      sizeof (GstNTOONE_CHAINClass),
      (GBaseInitFunc) gst_ntoone_chain_base_init,
      NULL,
      (GClassInitFunc) gst_ntoone_chain_class_init,
      NULL,
      NULL,
      sizeof (GstNTOONE_CHAIN),
      0,
      (GInstanceInitFunc) gst_ntoone_chain_init,
    };

    ntoone_chain_type =
        g_type_register_static (GST_TYPE_ELEMENT, "GstNTOONE_CHAIN",
&ntoone_chain_info, 0);
  }
  return ntoone_chain_type;
}

static void
gst_ntoone_chain_base_init (GstNTOONE_CHAINClass * klass)
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);

  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&gst_text_sink_template));
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&gst_struct_sink_template));
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&gst_struct_src_template));
  gst_element_class_set_details_simple (element_class, "NTOONE_CHAIN",
      "template",
      "N to one template with static always pads",
      "Jason Trinidad
}

static void
gst_ntoone_chain_class_init (GstNTOONE_CHAINClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;

  parent_class = g_type_class_peek_parent (klass);

  gobject_class->set_property = gst_ntoone_chain_set_property;
  gobject_class->get_property = gst_ntoone_chain_get_property;
  gobject_class->finalize = (GObjectFinalizeFunc) gst_ntoone_chain_finalize;

  
  g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_INPUT,
      g_param_spec_int ("input", "Input",
          "Chooses the input that will be displayed", 0, 2,
          1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  
}

static GstCaps *
gst_ntoone_chain_text_getcaps (GstPad * pad)
{
  return gst_caps_copy (gst_pad_get_pad_template_caps (pad));
}

static gboolean
gst_ntoone_chain_text_setcaps (GstPad * pad, GstCaps * caps)
{
  gboolean res = FALSE;
  GstStructure *s = gst_caps_get_structure (caps, 0);
  if (gst_structure_has_name (s, "text/plain")) {
    res = TRUE;
  }
  return res;
}

static GstCaps *
gst_ntoone_chain_struct_getcaps (GstPad * pad)
{
  return gst_caps_copy (gst_pad_get_pad_template_caps (pad));
}

static gboolean
gst_ntoone_chain_struct_setcaps (GstPad * pad, GstCaps * caps)
{
  gboolean res = FALSE;
  GstStructure *s = gst_caps_get_structure (caps, 0);
  if (gst_structure_has_name (s, "structure/struct")) {
    res = TRUE;
  }
}

static void
gst_ntoone_chain_init (GstNTOONE_CHAIN * ntoone_chain)
{
  ntoone_chain->textsink =
      gst_pad_new_from_static_template (&gst_text_sink_template,
"textsink");
  gst_pad_set_setcaps_function (ntoone_chain->textsink,
      GST_DEBUG_FUNCPTR (gst_ntoone_chain_text_setcaps));
  gst_pad_set_getcaps_function (ntoone_chain->textsink,
      GST_DEBUG_FUNCPTR (gst_ntoone_chain_text_getcaps));
  gst_pad_set_chain_function (ntoone_chain->textsink,
      GST_DEBUG_FUNCPTR(gst_ntoone_chain_text));
  gst_element_add_pad (GST_ELEMENT (ntoone_chain), ntoone_chain->textsink);

  ntoone_chain->structsink =
      gst_pad_new_from_static_template (&gst_struct_sink_template,
"structsink");
  gst_pad_set_setcaps_function (ntoone_chain->structsink,
      GST_DEBUG_FUNCPTR (gst_ntoone_chain_struct_setcaps));
  gst_pad_set_getcaps_function (ntoone_chain->structsink,
      GST_DEBUG_FUNCPTR (gst_ntoone_chain_struct_getcaps));
  gst_pad_set_chain_function (ntoone_chain->structsink,
      GST_DEBUG_FUNCPTR(gst_ntoone_chain_struct));
  gst_element_add_pad (GST_ELEMENT (ntoone_chain),
ntoone_chain->structsink);

  ntoone_chain->srcpad =
      gst_pad_new_from_static_template (&gst_struct_src_template, "src");
  gst_pad_set_setcaps_function (ntoone_chain->srcpad,
      GST_DEBUG_FUNCPTR (gst_ntoone_chain_struct_setcaps));
  gst_pad_set_getcaps_function (ntoone_chain->srcpad,
      GST_DEBUG_FUNCPTR (gst_ntoone_chain_struct_getcaps));
  gst_element_add_pad (GST_ELEMENT (ntoone_chain), ntoone_chain->srcpad);
}

static void join(text_val *tvals, Mystruct *mystruct)
{

  static text_val *vals; //The element should retain these values until it
receives a new text_val buffer
 
if(gvals)
    values = *tvals;


  if(mystruct !=NULL){
      g_print("GREAT SUCCESS!");
      g_print("h = %f", values.h); 
  }
  else
      g_print("There is no struct data");

}


static void
gst_ntoone_chain_finalize (GstNTOONE_CHAIN * ntoone_chain)
{
  G_OBJECT_CLASS (parent_class)->finalize ((GObject *) ntoone_chain);
}


static GstFlowReturn
gst_ntoone_chain_text (GstPad * pad, GstBuffer * buf)
{

  GstNTOONE_CHAIN *ntoone_chain;
  GstBuffer *outbuf;
  text_val *tvals = NULL;
  Mystruct *mystruct = NULL;
  char *unparsed_data;

  ntoone_chain = GST_NTOONE_CHAIN (GST_OBJECT_PARENT (pad));

  unparsed_data = (char *) GST_BUFFER_DATA(buf);
  parse_text(unparsed_data, tvals);
  g_print("\n\n****************************\n  The text chain function is
being called \n****************************\n"); 

  join(tvals, mystruct);

  /* just push out the incoming buffer without touching it */
  return GST_FLOW_OK;
}

static GstFlowReturn
gst_ntoone_chain_struct (GstPad * pad, GstBuffer * buf)
{
  GstNTOONE_CHAIN *ntoone_chain;
  GstBuffer *outbuf;
  text_val *tvals = NULL;
  Mystruct *mystruct = NULL;
  g_print("\n\n****************************\n  The struct chain function is
being called \n****************************\n");
  outbuf = gst_buffer_try_new_and_alloc(sizeof(StructDetectedObject));
  ntoone_chain = GST_NTOONE_CHAIN (GST_OBJECT_PARENT (pad));
	
  mystruct = (Mystruct *)GST_BUFFER_DATA(buf);
	
  join(gvals, mystruct);
  }
  GST_BUFFER_DATA(outbuf) = (void *)mystruct;
  return gst_pad_push (ntoone_chain->srcpad, outbuf);
}


static void
gst_ntoone_chain_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstNTOONE_CHAIN *ntoone_chain;

  ntoone_chain = GST_NTOONE_CHAIN (object);
  switch (prop_id) {
    case PROP_INPUT:
      ntoone_chain->input = g_value_get_int (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
  
}

static void
gst_ntoone_chain_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GstNTOONE_CHAIN *ntoone_chain;

  ntoone_chain = GST_NTOONE_CHAIN (object);

  switch (prop_id) {
    case PROP_INPUT:
      g_value_set_int (value, ntoone_chain->input);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}


gboolean
gst_ntoone_chain_plugin_init (GstPlugin * plugin)
{
  GST_DEBUG_CATEGORY_INIT (gst_ntoone_chain_debug, "ntoone_chain", 0,
      "NTOONE_CHAIN transition effect");

  return gst_element_register (plugin, "ntoone_chain", GST_RANK_NONE,
GST_TYPE_NTOONE_CHAIN);
}

#ifndef PACKAGE
#define PACKAGE "ntoone_chain"
#endif

/* gstreamer looks for this structure to register structtextsync
 */
GST_PLUGIN_DEFINE (
    GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    "ntoone_chain",
    "ntoone_chain element",
    gst_ntoone_chain_plugin_init,
    VERSION,
    "Proprietary",
    GST_PACKAGE_NAME,
    " test "
)




--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Combining-data-from-two-chain-functions-tp4655802.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list