appsink to appscr mixes up color channels

Richard Cagley rcagley at gmail.com
Sat May 25 16:10:12 PDT 2013


it's 0.10. apt-get install on Ubuntu 12.04 fwiw

I found that I had to set the sink/src caps explicitly. Otherwise, I got
pipeline execution errors. I would just bail out after a frame or two. I
did try setting the caps on videotestsrc with the hope they would flow
through.

Here's the complete set of code

#include <gst/gst.h>
#include <glib.h>
#include <gst/app/gstappsink.h>
#include <gst/app/gstappsrc.h>
#include <iostream>
#include <stdio.h>

using namespace std;

static GMainLoop *loop = NULL;
static GstElement *pipelineIn = NULL;
static GstElement *pipelineOut = NULL;

static const char app_src_name[] = "app-src_01";
static const char app_sink_name[] = "app-sink_01";

static GstFlowReturn
new_buffer (GstAppSink *app_sink,
            gpointer user_data)
{
  GstBuffer *buffer = gst_app_sink_pull_buffer(
      (GstAppSink*) gst_bin_get_by_name( GST_BIN(pipelineIn),
      app_sink_name));

  //debugging
  if (!gst_bin_get_by_name( GST_BIN(pipelineIn), app_sink_name))
  {
    g_print("app-sink bailed!\n");
  }
  if (!gst_bin_get_by_name( GST_BIN(pipelineOut), app_src_name))
  {
    g_print("app-src bailed!\n");
  }

  //pushes the buffer to AppSrc, it takes the ownership of the buffer. you
do not need to unref
  gst_app_src_push_buffer( GST_APP_SRC(
gst_bin_get_by_name(GST_BIN(pipelineOut),app_src_name)) , buffer);

  return GST_FLOW_OK;
}

static gboolean
bus_call (GstBus     *bus,
          GstMessage *msg,
          gpointer    data)
{
  gchar *userdata = (gchar *) data;

  switch (GST_MESSAGE_TYPE (msg))
  {

    case GST_MESSAGE_EOS:
    {
      //sender check - input pipeline send EOS to output pipeline
      if ( g_ascii_strcasecmp(userdata, gst_element_get_name(pipelineIn))
== 0)
      {
        g_print("EOS detected (%s)\n",userdata);
        gst_app_src_end_of_stream( GST_APP_SRC( gst_bin_get_by_name(
GST_BIN(pipelineOut), app_src_name ) ) );
      }
      //sender check - when pipelineOut sends the EOS msg, quite.
      if ( g_ascii_strcasecmp(userdata, gst_element_get_name(pipelineOut))
== 0)
      {
        g_print("Finished playback (%s)\n",userdata);
        g_main_loop_quit(loop);

      }
      break;
    }

    case GST_MESSAGE_STATE_CHANGED :
    {
      GstState oldstate;
      GstState newstate;
      GstState pending;

      gst_message_parse_state_changed (msg,&oldstate,&newstate,&pending);
      g_debug("pipeline:%s old:%s new:%s pending:%s", userdata,
              gst_element_state_get_name(oldstate),
              gst_element_state_get_name(newstate),
              gst_element_state_get_name(pending));
      break;
    }

    case GST_MESSAGE_WARNING:
    {
      gchar *debug;
      GError *error;

      gst_message_parse_warning (msg, &error, &debug);
      g_warning("pipeline:%s",userdata);
      g_warning("debug: %s", debug);
      g_warning("error: %s", error->message);
      g_free (debug);
      g_error_free (error);
      break;
    }

    case GST_MESSAGE_ERROR:
    {
      gchar  *debug;
      GError *error;

      gst_message_parse_error (msg, &error, &debug);
      g_free (debug);
      g_printerr ("Error in pipeline: %s\n", error->message);
      g_error_free (error);
      g_main_loop_quit (loop);
      break;
    }

    default:
      break;
  }

  return TRUE;
}

int
main (int   argc,
      char *argv[])
{
  GError *error = NULL;
  GstBus *bus = NULL;
  GstAppSinkCallbacks callbacks;

  gchar pipelineInStr[256];
  gchar pipelineOutStr[256];
  guint bus_watch_id;

  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, FALSE);

  // creating pipelines from strings
  sprintf(pipelineInStr, "videotestsrc num-buffers=10 pattern=4 ! queue !
appsink name=\"%s\"",app_sink_name);
  sprintf(pipelineOutStr, "appsrc name=\"%s\" ! queue !
 ximagesink",app_src_name);

  pipelineIn = gst_parse_launch(pipelineInStr, &error);
  if (error)
  {
    g_printerr("Could not create pipelineIn\n");
    return -1;
  }
  pipelineOut = gst_parse_launch(pipelineOutStr, &error);
  if (error)
  {
    g_printerr("Could not create pipelineOut\n");
    return -1;
  }
  if (!gst_bin_get_by_name(GST_BIN(pipelineIn), app_sink_name))
  {
    g_printerr("Error creating app-sink\n");
    return -1;
  }
  if (!gst_bin_get_by_name(GST_BIN(pipelineOut), app_src_name))
  {
    g_printerr("Error creating app-src\n");
    return -1;
  }
GstCaps *caps;
caps = gst_caps_new_simple ("video/x-raw-rgb",
          "width", G_TYPE_INT, 640,
          "height", G_TYPE_INT, 480,
          "framerate", GST_TYPE_FRACTION, 30000, 1001,
          NULL);
  gst_app_sink_set_caps( (GstAppSink*)
gst_bin_get_by_name(GST_BIN(pipelineIn),app_sink_name) , caps);
  gst_app_src_set_caps( (GstAppSrc*)
gst_bin_get_by_name(GST_BIN(pipelineOut),app_src_name) , caps);

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipelineIn));
  bus_watch_id = gst_bus_add_watch (bus, bus_call,
gst_element_get_name(pipelineIn));
  gst_object_unref (bus);
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipelineOut));
  bus_watch_id = gst_bus_add_watch (bus, bus_call,
gst_element_get_name(pipelineOut));
  gst_object_unref (bus);

  // app sink callback
  callbacks.eos = NULL;
  callbacks.new_preroll = NULL;
  callbacks.new_buffer = new_buffer;
  gst_app_sink_set_callbacks( (GstAppSink*)
gst_bin_get_by_name(GST_BIN(pipelineIn),
                              app_sink_name),
                              &callbacks,
                              NULL,
                              NULL);

  g_print ("Now playing: %s\n", argv[1]);
  gst_element_set_state (pipelineIn, GST_STATE_PLAYING);
  gst_element_set_state (pipelineOut, GST_STATE_PLAYING);

  g_print ("Running...\n");
  g_main_loop_run (loop);

  g_print ("Returned, stopping playback\n");
  gst_element_set_state (pipelineIn, GST_STATE_NULL);
  gst_element_set_state (pipelineOut, GST_STATE_NULL);

  g_print ("Deleting pipeline\n");
  gst_object_unref (GST_OBJECT (pipelineIn));
  gst_object_unref (GST_OBJECT (pipelineOut));
  g_source_remove (bus_watch_id);
  g_main_loop_unref (loop);

  return 0;
}



On Sat, May 25, 2013 at 4:00 PM, Tim-Philipp Müller <t.i.m at zen.co.uk> wrote:

> On Sat, 2013-05-25 at 15:49 -0700, Richard Cagley wrote:
>
> Hi,
>
> > I'm using videotestsrc and ximagesink and changing the patterns on
> > videotestsrc and looking at the output. I also have some print
> > statements to read the raw data pointers.
> >
> >
> > What would cause this? I'm setting the caps like this...
> >
> >
> > caps = gst_caps_new_simple ("video/x-raw-rgb",
> >           "format", G_TYPE_STRING, "RGB",
>
> Are you using 1.0 or 0.10 ? Those caps look like a mix of both.
>
>
> In 0.10 it's
> video/x-raw-rgb,endianness=...,{red,blue,green,alpha}_mask=..
>
> In 1.0 it's video/x-raw,format=(string)xyz
>
> Why are you creating the caps yourself anyway? Why not just forward/set
> the caps you get on the appsink?
>
> Cheers
>  -Tim
>
>
> _______________________________________________
> 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/20130525/f8339f44/attachment.html>


More information about the gstreamer-devel mailing list