[gst-devel] Fakesrc example without 100% CPU usage

Riccardo Corona coronariccardo at gmail.com
Thu Jun 7 12:14:03 CEST 2007


Just for knowledge....
I was able to avoid the 100% CPU usage doing these changes to the fakesrc
example on the gst manual (note that I've used the directdrawsink and not
the xvimagesink):

static void
cb_handoff (GstElement *fakesrc,
        GstBuffer  *buffer,
        GstPad     *pad,
        gpointer    user_data)
{
    static gboolean white = FALSE;

    GTimeVal gtime;
    g_get_current_time(&gtime);

    GstClockTime gstClock=GST_TIMEVAL_TO_TIME(gtime);

//basetime is a static GstClockTime var
    buffer->timestamp= gstClock-baseTime;

    memset (GST_BUFFER_DATA (buffer), white ? 0xff : 0x0,
      GST_BUFFER_SIZE (buffer));
    white = !white;

}



gint
main (gint   argc,
      gchar *argv[])
{
  GstElement *pipeline, *fakesrc, *flt, *conv, *videosink,*parDDSink;
  GMainLoop *loop;
  GstBus* bus;

  /* init GStreamer */
  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);

  /* setup pipeline */
  pipeline = gst_pipeline_new ("pipeline");
  fakesrc = gst_element_factory_make ("fakesrc", "source");

  gst_base_src_set_format((GstBaseSrc*)fakesrc,GST_FORMAT_TIME);

  flt = gst_element_factory_make ("capsfilter", "flt");
  conv = gst_element_factory_make ("ffmpegcolorspace", "conv");
  videosink = gst_element_factory_make ("directdrawsink", "directdraw");
  parDDSink = gst_element_factory_make ("capsfilter", "ddSinkPar");
  /* setup */
  g_object_set (G_OBJECT (flt), "caps",
          gst_caps_new_simple ("video/x-raw-rgb",
                     "width", G_TYPE_INT, 384,
                     "height", G_TYPE_INT, 288,
                     "framerate", GST_TYPE_FRACTION, 1, 1,
                     "bpp", G_TYPE_INT, 16,
                     "depth", G_TYPE_INT, 16,
                     "endianness", G_TYPE_INT, G_BYTE_ORDER,
                     NULL), NULL);


  g_object_set (G_OBJECT(parDDSink), "caps",
        gst_caps_new_simple ("video/x-raw-rgb",
        "width", G_TYPE_INT, 384,
        "height", G_TYPE_INT, 288,
        "framerate",GST_TYPE_FRACTION, 1, 1),
        NULL);

  gst_bin_add_many (GST_BIN (pipeline), fakesrc, flt,conv,parDDSink,
videosink, NULL);

  gst_element_link_many (fakesrc, flt, conv, parDDSink,videosink, NULL);


  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);

  /* setup fake source */
  g_object_set (G_OBJECT (fakesrc),
        "signal-handoffs", TRUE,
        "sizemax", 384 * 288 * 2,
        "sizetype", 2, NULL);
  g_signal_connect (fakesrc, "handoff", G_CALLBACK (cb_handoff), NULL);

  /* play */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  GstClock *clock;
  clock=gst_pipeline_get_clock ((GstPipeline*)pipeline);
  baseTime=gst_clock_get_time(clock);

  g_main_loop_run (loop);

  /* clean up */
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (GST_OBJECT (pipeline));

  return 0;
}


Simply I've done some add on the time management, unfortunately I can't
reach the flow control of 1fps and the video is flickering as fast as it can
with a strange behaviour: if I run the example with GST_DEBUG >= 3 the fps
is exactly 1, this is a very mistery for me....

Hope that's helpfull for some of you.

Regards.




-- 
Riccardo Corona
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20070607/95daf41e/attachment.htm>


More information about the gstreamer-devel mailing list