Appsrc example with cairo
Annick Fron
annick.fron at afceurope.com
Wed Oct 29 08:59:56 PDT 2014
Hi Luis,
Here is the link :
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-data-spoof.html
Instead of the white and black image, I draw some cairo.
I have tried it with glimagesink , and it seems to work, so probably the caps are wrong, but I took them from gstcairooverlay.c.
Annick
Le 29 oct. 2014 à 11:52, Luis de Bethencourt <luis at debethencourt.com> a écrit :
> Hi Annick,
>
> Which doc did you grab this from? Just want to make sure it is proper ones.
>
> Luis
>
> On 28 October 2014 17:06, Annick Fron <list at afceurope.com> wrote:
> Hi,
>
> I have copied from the doc the appsrc example, and tried to create contents using cairo, but the example does not work.
>
> Any idea ?
>
> Annick Fron
>
> /*
> ============================================================================
> Name : Cairo-src.c
>
> ============================================================================
> */
>
>
> #include <gst/gst.h>
> #include <cairo.h>
> #include <gst/video/video.h>
> #include <stdio.h>
>
> static GMainLoop *loop;
>
> static void
> cb_need_data (GstElement *appsrc,
> guint unused_size,
> gpointer user_data)
> {
> static gboolean white = FALSE;
> static GstClockTime timestamp = 0;
> GstBuffer *buffer;
> GstMapInfo info;
> guint size;
> GstFlowReturn ret;
> GstMemory * memory;
> cairo_t * cr;
>
>
> cairo_surface_t * imageSurface;
>
>
> size = 640 * 50 * 4;
>
> buffer = gst_buffer_new_allocate (NULL, size, NULL);
>
>
> memory=gst_buffer_get_all_memory(buffer);
> gst_buffer_make_writable(buffer);
> gst_buffer_map (buffer, &info, GST_MAP_WRITE);
> printf("buffer \n");
> imageSurface = cairo_image_surface_create_for_data (info.data,
> CAIRO_FORMAT_ARGB32,
> 640,
> 50,
> 640*4);
> cr = cairo_create(imageSurface);
> cairo_set_source_rgb(cr,1.0,0,1.0);
> cairo_rectangle(cr, 100.0,20.0,400.0,40.0 );
> cairo_fill(cr);
>
> //gst_buffer_unmap (buffer, &info);
>
> GST_BUFFER_PTS (buffer) = timestamp;
> GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 2);
>
> timestamp += GST_BUFFER_DURATION (buffer);
>
>
> g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);
>
>
> if (ret != GST_FLOW_OK) {
> /* something wrong, stop pushing */
> g_main_loop_quit (loop);
> }
> }
>
> gint
> main (gint argc,
> gchar *argv[])
> {
> GstElement *pipeline, *appsrc, *conv, *videosink;
>
> /* init GStreamer */
> gst_init (&argc, &argv);
> loop = g_main_loop_new (NULL, FALSE);
>
> /* setup pipeline */
> pipeline = gst_pipeline_new ("pipeline");
> appsrc = gst_element_factory_make ("appsrc", "source");
> conv = gst_element_factory_make ("videoconvert", "conv");
> videosink = gst_element_factory_make ("ximagesink", "videosink");
>
> /* setup */
> g_object_set (G_OBJECT (appsrc), "caps",
> gst_caps_new_simple ("video/x-raw",
> "format", G_TYPE_STRING, "ARGB",
> "width", G_TYPE_INT, 640,
> "height", G_TYPE_INT, 50,
> "framerate", GST_TYPE_FRACTION, 15, 1,
> NULL), NULL);
> gst_bin_add_many (GST_BIN (pipeline), appsrc, conv, videosink, NULL);
> gst_element_link_many (appsrc, conv, videosink, NULL);
>
> /* setup appsrc */
> g_object_set (G_OBJECT (appsrc),
> "stream-type", 0,
> "format", GST_FORMAT_TIME, NULL);
> g_signal_connect (appsrc, "need-data", G_CALLBACK (cb_need_data), NULL);
>
> /* play */
> gst_element_set_state (pipeline, GST_STATE_PLAYING);
> g_main_loop_run (loop);
>
> /* clean up */
> gst_element_set_state (pipeline, GST_STATE_NULL);
> gst_object_unref (GST_OBJECT (pipeline));
> g_main_loop_unref (loop);
>
> return 0;
> }
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20141029/a4e2179e/attachment.html>
More information about the gstreamer-devel
mailing list