Fw: Need Help to run my plugin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi Michel,
                 Please find my plugin source code for mpeg4dec is as 
follwoed.


#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gst/gst.h>

#include "gstmpeg4dec.h"
#include "string.h"
#include "Dec_api.h"

GST_DEBUG_CATEGORY_STATIC (gst_mpeg4dec_debug);
#define GST_CAT_DEFAULT gst_mpeg4dec_debug

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

enum
{
  PROP_0,
  PROP_SILENT
};

int ch_buf[55300000/4];
char *framebuffer[16];
// Tejas GstCaps *           gst_mpeg4_pad_get_caps 
(GstPad *pad);

/* the capabilities of the inputs and outputs.
 *
 * describe the real formats here.
 */
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("ANY")
    );

static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("video/x-raw-yuv, "
        "format = (fourcc) {YV12 }, "
        "framerate = (fraction) [0/1, MAX], "
        "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
    );

GST_BOILERPLATE (Gstmpeg4dec, gst_mpeg4dec, GstElement,
    GST_TYPE_ELEMENT);

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

static gboolean gst_mpeg4dec_set_caps (GstPad * pad, GstCaps * caps);
static GstFlowReturn gst_mpeg4dec_chain (GstPad * pad, GstBuffer * buf);

static GstStateChangeReturn gst_mpeg4dec_filter_change_state (GstElement 
*element, GstStateChange transition);
static gboolean gst_mpeg4dec_filter_allocate_memory (Gstmpeg4dec * filter);
static gboolean gst_mpeg4dec_filter_free_memory (Gstmpeg4dec * filter);

/* GObject vmethod implementations */

static void
gst_mpeg4dec_base_init (gpointer gclass)
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);

  gst_element_class_set_details_simple(element_class,
    "mpeg4dec",
    "FIXME:Generic",
    "FIXME:Generic Template Element",
    "Neelam Gaikwad <<user at hostname.org>>");

  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&src_factory));
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&sink_factory));
}

/* initialize the mpeg4dec's class */
static void
gst_mpeg4dec_class_init (Gstmpeg4decClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;

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

  gobject_class->set_property = gst_mpeg4dec_set_property;
  gobject_class->get_property = gst_mpeg4dec_get_property;
    gstelement_class->change_state = gst_mpeg4dec_filter_change_state;


  g_object_class_install_property (gobject_class, PROP_SILENT,
      g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
          FALSE, G_PARAM_READWRITE));
}

/* initialize the new element
 * instantiate pads and add them to element
 * set pad calback functions
 * initialize instance structure
 */
static void
gst_mpeg4dec_init (Gstmpeg4dec * filter,
    Gstmpeg4decClass * gclass)
{
  filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, 
"sink");
  gst_pad_set_setcaps_function (filter->sinkpad,
                                GST_DEBUG_FUNCPTR(gst_mpeg4dec_set_caps));
  gst_pad_set_getcaps_function (filter->sinkpad,
      GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));

  gst_pad_set_chain_function (filter->sinkpad,
                              GST_DEBUG_FUNCPTR(gst_mpeg4dec_chain));

  filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
  gst_pad_set_getcaps_function (filter->srcpad,
                                GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
  gst_pad_use_fixed_caps (filter->srcpad);

  gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
  gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
  filter->silent = FALSE;
}

static void
gst_mpeg4dec_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  Gstmpeg4dec *filter = GST_MPEG4DEC (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_mpeg4dec_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  Gstmpeg4dec *filter = GST_MPEG4DEC (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;
  }
}
static gboolean gst_mpeg4dec_filter_allocate_memory (Gstmpeg4dec * filter)
{
    gint iDecSize, iFbSize;
    gint width = 320, height = 240;
    gint iNumBlkReqd, i, iResult;

    // Parse SPS and PPS info
    memset(&frame,0,sizeof(filter->frame));
    // Get decoder memory estimate
    Decoder_GetMemoryInfo(width,height,&iDecSize,&iFbSize,&iNumBlkReqd);
    filter->pDecMem = g_malloc(iDecSize);
    framebuffer[0]=(char *)&ch_buf;
    for(i=1; i < iNumBlkReqd; i++)
 {
  framebuffer[i] = (framebuffer[i-1]+ (iFbSize));
 }
    iResult = InitDecoder(width,height,filter->pDecMem,(void 
*)framebuffer,iNumBlkReqd,&filter->info);
    return TRUE;
}

static gboolean gst_mpeg4dec_filter_free_memory (Gstmpeg4dec * filter)
{
    g_free(filter->pDecMem);

    return TRUE;
}

static GstStateChangeReturn gst_mpeg4dec_filter_change_state (GstElement 
*element, GstStateChange transition)
{
    GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
    Gstmpeg4dec *filter = GST_MPEG4DEC (element);
    switch (transition)
    {
        case GST_STATE_CHANGE_NULL_TO_READY:
            if (!gst_mpeg4dec_filter_allocate_memory (filter))
                return GST_STATE_CHANGE_FAILURE;
            break;
        default:
            break;
    }

    ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, 
transition);

    if (ret == GST_STATE_CHANGE_FAILURE)
        return ret;
    switch (transition)
    {
        case GST_STATE_CHANGE_READY_TO_NULL:
            gst_mpeg4dec_filter_free_memory (filter);
            break;
        default:
        break;
    }
    return ret;
}
static gboolean
gst_mpeg4dec_set_caps (GstPad * pad, GstCaps * caps)
{
  Gstmpeg4dec *filter;
  GstPad *otherpad;

  g_print("ENtering set caps function \n");

  filter = GST_MPEG4DEC (gst_pad_get_parent (pad));
  otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
  gst_object_unref (filter);

  return gst_pad_set_caps (otherpad, caps);
}


/* chain function
 * this function does the actual processing
 */
static GstFlowReturn
gst_mpeg4dec_chain (GstPad * pad, GstBuffer * buf)
{
    GstFlowReturn ret = GST_FLOW_OK;
    GstCaps *caps;
    Gstmpeg4dec *filter;
    gint iResult;
    guint32 fourcc;
    GstBuffer *gstOutBuffer;

    filter = GST_MPEG4DEC (GST_OBJECT_PARENT (pad));

    iResult = DecodeFrame((unsigned char 
*)GST_BUFFER_DATA(buf),filter->pDecMem,0,&filter->frame);
    if(filter->frame != NULL)
    {
        fourcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');

        caps = gst_caps_new_simple ("video/x-raw-yuv",
                                    "format", GST_TYPE_FOURCC, fourcc,
                                    "framerate", GST_TYPE_FRACTION,
                                    1, 1,
                                    "width", G_TYPE_INT, filter->info.width, 
"height", G_TYPE_INT, filter->info.height, NULL);
        if( !gst_pad_set_caps (filter->srcpad, caps))
            g_print("Failed to set caps !!!!\n");
        else
            g_print("Success to set caps !!!!\n");

        ret = gst_pad_alloc_buffer_and_set_caps (filter->srcpad, 
GST_BUFFER_OFFSET_NONE,
                                                    (filter->info.width * 
filter->info.height * 3 / 2),
                                                    GST_PAD_CAPS 
(filter->srcpad), &gstOutBuffer);
        if(ret != GST_FLOW_OK)
            g_print("(MPEG4DEC) Memory is not allocated \n !!");

        memcpy(gstOutBuffer->data, filter->frame, (filter->info.width * 
filter->info.height * 3 / 2));
        ret = gst_pad_push (filter->srcpad, gstOutBuffer);
        return ret;
    }
    else
        return ret;
}


/* entry point to initialize the plug-in
 * initialize the plug-in itself
 * register the element factories and other features
 */
static gboolean
mpeg4dec_init (GstPlugin * mpeg4dec)
{
  /* debug category for fltering log messages
   *
   * exchange the string 'Template mpeg4dec' with your description
   */
  GST_DEBUG_CATEGORY_INIT (gst_mpeg4dec_debug, "mpeg4dec",
      0, "Template mpeg4dec");

  return gst_element_register (mpeg4dec, "mpeg4dec", GST_RANK_NONE,
      GST_TYPE_MPEG4DEC);
}

/* 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 "myfirstmpeg4dec"
#endif

/* gstreamer looks for this structure to register mpeg4decs
 *
 * exchange the string 'Template mpeg4dec' with your mpeg4dec description
 */
GST_PLUGIN_DEFINE (
    GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    "mpeg4dec",
    "Template mpeg4dec",
    mpeg4dec_init,
    VERSION,
    "LGPL",
    "GStreamer",
    "http://gstreamer.net/";
)



-Tejas.
----- Original Message ----- 
From: "Michael Smith" <msmith at xiph.org>
To: "Tejas Bhanabhagavanwala" <tejas at oriolesoftware.com>
Cc: <gstreamer-embedded at lists.sourceforge.net>
Sent: Thursday, November 19, 2009 11:46 AM
Subject: Re: Fw: Need Help to run my plugin


On Wed, Nov 18, 2009 at 8:29 PM, Tejas Bhanabhagavanwala
<tejas at oriolesoftware.com> wrote:
> Hi Michel,
>
> Nice to have reply back. element yuv doen't do much thing.
> It reads data from buffer sent from filesrc, parse the raw video data and
> push buffer to next element which is mpeg4dec. For testing purpose i have
> set sink and source pad of yuv element to ANY. Following pipeline is 
> working
> fine.

It sounds like mpeg4videoparse, then - better to use a well tested
existing plugin than a custom one.

However, that won't cause a crash by itself.
\
>
> [ ] gst-launch-0.10 filesrc location=~/test.m4v ! yuv ! mpeg4dec !
> filesink location=~/out.yuv
>
> My mpeg4dec element reads data from yuv elemnet, decode it and
> generate output in YV12 format. When i connect mpeg4dec with
> ffmpegcolorspace element it crashes. I am not doing any set capabilities 
> for
> mpeg4dec element. When i create srcfactory pad, i have assigned following
> details.
>
> static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE 
> ("sink",
> GST_PAD_SINK,
> GST_PAD_ALWAYS,
> GST_STATIC_CAPS ("ANY")
> );
>
> static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
> GST_PAD_SRC,
> GST_PAD_ALWAYS,
> GST_STATIC_CAPS ("video/x-raw-yuv, "
> "format = (fourcc) {YV12 }, "
> "framerate = (fraction) [0/1, MAX], "
> "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
> // GST_STATIC_CAPS ("ANY")
> );
> Please help me and correct me if i am wrong at any places.

None of this is the cause of your crash. Your crash is simply a bug in
your plugin - and without the source to your plugin, or even any
details about where it's crashing, there's no possible way we can help
you any more than that. Good luck with your debugging!

Mike






[Index of Archives]     [Linux Embedded]     [Linux ARM Kernel]     [Linux for ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux Media]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux