gst_controller_new returns NULL

Rossana Guerra guerra.rossana at gmail.com
Tue Oct 25 12:09:26 PDT 2011


Thanks Stefan, as I understand, now I have to control the "position"
property.

I run an the following example, where I control the "alpha" property, and it
works fine. I don't know if it's due a different pipeline, but it doesn't
concern about "alpha" property.
Here's the code which runs (without sound):


#include <gst.h>
#include <controller/gstcontroller.h>

#include <iostream>

using namespace std;


// Manejador de errores
static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
:::::::::::::::
}

static void on_pad_added (GstElement *element, GstPad *pad, gpointer  data)
{
  GstPad *sinkpad = NULL;
  GstElement * queue = (GstElement *) data;

  /* Ahora linkeo el pad de comp con sink pad */
  g_print ("Dynamic pad created, linking queue\n");
  sinkpad = gst_element_get_static_pad (queue, "sink");

  gst_pad_link (pad, sinkpad);

  gst_object_unref (sinkpad);

}

GstElement * getBin(const gchar * nomBin, GstElement * &alfa1, GstElement
*&smpte, GstElement * &color, gint transicion = 1)
{

  GstElement * bin = gst_bin_new(nomBin);

  if (!bin)
  {
      g_printerr ("No se pudo crear el bin. Saliendo\n");
     return NULL;
  }

  alfa1   = gst_element_factory_make ("alpha","alfa1");
  smpte  = gst_element_factory_make ("smptealpha","smpte");
  color  = gst_element_factory_make ("ffmpegcolorspace", "color");
  GstElement * mixer  = gst_element_factory_make("videomixer", "mixer");


  if ((!alfa1) || (!smpte) || (!color) || (!mixer))
  {
      g_printerr ("Alguno de los elementos del Bin no pudo ser creado.
Saliendo\n");
     return NULL;
  }

  // Anexamos al bin
  gst_bin_add_many(GST_BIN (bin),alfa1,smpte,mixer,color,NULL);

  // Enlazamos elementos
  gst_element_link (alfa1, mixer);
  gst_element_link (smpte, mixer);
  gst_element_link (mixer,color);

  g_object_set(smpte,"type", transicion, NULL);

  return bin;
}

void getAndSetController(GstElement * smpte, gdouble duracion)
{
    GstController * ctrl = NULL;
    if (!(ctrl = gst_controller_new (G_OBJECT (smpte), "alpha",NULL))) {  //
Here it works fine
        GST_WARNING ("No puede controlar el elemento fuente\n");
        return;
   }

  // Todo valor GValue debe inicializarse en 0
  GValue val_double = { 0, };
  g_value_init (&val_double, G_TYPE_DOUBLE);


  // Creo la fuente al controlador y la asocio al controlador
  // Seteo modo de interpolacion

  GstInterpolationControlSource * csource =
gst_interpolation_control_source_new();
  gst_controller_set_control_source (ctrl, "alpha", GST_CONTROL_SOURCE
(csource));


gst_interpolation_control_source_set_interpolation_mode(csource,GST_INTERPOLATE_LINEAR);

  // Seteo primer valor
  g_value_set_double(&val_double, 0.0);
  gst_interpolation_control_source_set(csource,(0 *
GST_MSECOND),&val_double);

  // Seteo segundo valor
  g_value_set_double (&val_double, duracion);
  gst_interpolation_control_source_set(csource,(1 *
GST_MSECOND),&val_double);


  g_object_unref (csource);

}

void addGhostPadsToBin(GstElement *alfa1, GstElement * smpte, GstElement *
color, GstElement* bin)
{
    /* add ghostpad */
  GstPad * pad1 = gst_element_get_static_pad (alfa1, "sink");
  gst_element_add_pad(bin, gst_ghost_pad_new("alfasink1", pad1));
  gst_object_unref (GST_OBJECT (pad1));

  GstPad * pad2 = gst_element_get_static_pad (smpte, "sink");
  gst_element_add_pad(bin, gst_ghost_pad_new("alfasink2", pad2));
  gst_object_unref(GST_OBJECT(pad2));

  GstPad * pad3 = gst_element_get_static_pad (color, "src");
  gst_element_add_pad(bin, gst_ghost_pad_new("colorsrc", pad3));
  gst_object_unref(GST_OBJECT(pad3));

}

void crossTransicion(gdouble duracion, GstElement * & bin,gint transicion =
1)
{
    // devuelve el bin
    GstElement * alfa1, *smpte, *color;
    alfa1 = 0;
    smpte = 0;
    color = 0;

    bin = getBin("bin",alfa1, smpte,color,transicion);  // Crea el bin y los
elementos

    getAndSetController(smpte,duracion);

    addGhostPadsToBin(alfa1, smpte, color, bin);

}

GstElement * getSetPipeline(gchar *argv[])
{
    gint dur1 = 9000; // duration (in ms) to play of first clip
    gint dur2 = 8000; // duration (in ms) to play of second clip
    gint dur_crossfade = 500; //number of milliseconds to crossfade for
    GstElement *comp = 0;
    GstElement *pipeline, *video1, *video2, *op, *bin, *queue, *sink;

    // ejecuta 2 clips serialmente con un crosdfade entre ellos usando el
elemento (GnlOlin) gnlcomposition
    if ((comp = gst_element_factory_make("gnlcomposition", "micomposicion"))
== NULL)
    {
      printf ("\n Fallo al crear gnlcomposition \n");
      return NULL;
    }

    op = gst_element_factory_make("gnloperation", "op");

    crossTransicion(dur_crossfade, bin,1);

    if (gst_bin_add (GST_BIN (op), bin) == FALSE)
    {
      printf ("\n No pudo agregar el bin a la gnloperacion op \n");
      return NULL;
    }

    g_object_set (op,"start", (dur1-dur_crossfade) * GST_MSECOND,NULL);
    g_object_set (op,"duration", dur_crossfade *  GST_MSECOND,NULL);
    g_object_set (op,"media-start", 0 *  GST_MSECOND,NULL);
    g_object_set(op,"media-duration", dur_crossfade * GST_MSECOND,NULL);
    g_object_set(op,"priority",0,NULL);

    if (gst_bin_add (GST_BIN (comp), op) == FALSE)
    {
      printf ("\n No pudo agregar la gnloperacion a la gnlcomposition \n");
      return NULL;
    }


    // configura primer clip

    if ((video1 = gst_element_factory_make("gnlfilesource", "video1")) ==
NULL)
    {
      printf ("\n Falló la creacion del gnlfilesource \n");
      return NULL;
    }
    if (gst_bin_add (GST_BIN (comp), video1) == FALSE)
    {
      printf ("\n No pudo agregar video1 a comp \n");
      return NULL;
    }

    g_object_set (video1, "location", argv[1], NULL);
    g_object_set(video1, "uri", argv[1],NULL);
    g_object_set (video1, "start", 0 * GST_MSECOND, NULL);
    g_object_set (video1, "duration", dur1 * GST_MSECOND, NULL);
    g_object_set (video1, "media-start", 0* GST_MSECOND, NULL);
    g_object_set (video1, "media-duration", dur1 * GST_MSECOND, NULL);
    g_object_set (video1, "priority", 1,NULL);

    // crea 2º clip
    if ((video2 = gst_element_factory_make("gnlfilesource", "video2")) ==
NULL)
    {
      printf ("\n Falló la creacion del gnlfilesource \n");
      return NULL;
    }


    if (gst_bin_add (GST_BIN (comp), video2) == FALSE)
    {
      printf ("\n No pudo agregar video2 a comp \n");
      return NULL;
    }

    g_object_set (video2, "location", argv[2], NULL);
    g_object_set (video2,"uri",argv[2],NULL);
    g_object_set (video2, "start", (dur1-dur_crossfade) * GST_MSECOND,
NULL);
    g_object_set (video2, "duration", dur2 * GST_MSECOND, NULL);
    g_object_set (video2, "media-start", 0 * GST_MSECOND, NULL);
    g_object_set (video2, "media-duration", dur2 * GST_MSECOND, NULL);
    g_object_set (video2, "priority", 2,NULL);

    // setup the backend viewer
    queue = gst_element_factory_make("queue", "queue");
    sink  = gst_element_factory_make("autovideosink", "sink");

    pipeline = gst_pipeline_new ("video-player");

    /* Agrego elementos al pipeline */

    gst_bin_add_many (GST_BIN (pipeline),comp, queue, sink, NULL);

    g_signal_connect (comp, "pad-added", G_CALLBACK (on_pad_added),queue);

    gst_element_link (queue, sink);

    return pipeline;

}

void startPlay(GstElement * pip)
{
    /* Set the pipeline to "playing" state*/
  gst_element_set_state (pip, GST_STATE_PLAYING);

}


int main(gint argc, gchar *argv[])
{
    GMainLoop *loop = NULL;

    /* init GStreamer */
    gst_init (&argc, &argv);
    gst_controller_init (&argc, &argv);

    loop = g_main_loop_new (NULL, FALSE);

    /* chequeamos sintaxis */
    if (argc != 3)
    {
        g_print ("Uso: %s <URI1>  <URI2>\n", argv[0]);
        return -1;
    }

    GstElement * play = getSetPipeline(argv);


    GstBus *bus2 = gst_pipeline_get_bus (GST_PIPELINE (play));
    gst_bus_add_watch (bus2, bus_call, loop);
    gst_object_unref (bus2);

    cout << "...PLAY" << endl;

    startPlay(play);

    /* now run */
    g_main_loop_run (loop);

    /* also clean up */
    gst_element_set_state (play, GST_STATE_NULL);
    gst_object_unref (GST_OBJECT (play));
    return 0;
}





2011/10/25 Stefan Sauer <ensonic at hora-obscura.de>

> **
> On 10/25/2011 08:06 AM, Rossana Guerra wrote:
>
> Hello everyone, I am translating the following code to C/C++:
> http://notes.brooks.nu/2011/01/python-gstreamer-controller/
> It's a controller for controlling the alpha channel during crossfade, I
> adapted it for transitions, using, smpte instead.
>
>
> smptealpha does not have a property called "alpha". Only "border" and
> "invert" are controllable right now.
>
> Stefan
>
>
> The fact is it returns NULL and the programs stop running. The code is
> below, I appreciate any suggestion.
> I am a bit clueless is an adaptation of a code I did before and it works.
>
> Thanks and regards.
>
> Rossana
>
> //// the code
>
> #include <gst.h>
> #include <controller/gstcontroller.h>
>
> #include <iostream>
>
>
> using namespace std;
>
> // Manejador de errores
> static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
> {
> ::::::::::::::::::::::::................
> }
>
> static void on_pad_added (GstElement *element, GstPad *pad, gpointer  data)
> {
>   GstPad *sinkpad = NULL;
>   GstElement * elemento = (GstElement *) data;
>
>
>   /* Ahora linkeo el pad de comp con sink pad */
>   g_print ("Dynamic pad created, linking queue\n");
>   sinkpad = gst_element_get_static_pad (elemento, "sink");
>
>
>   gst_pad_link (pad, sinkpad);
>   gst_object_unref(sinkpad);
>
> }
>
>
> int main(int argc, char *argv[])
> {
>
>   GMainLoop *loop = NULL;
>
>   GstElement *src1, *src2,*dec1,*dec2,*alfa1,*color,*smpte,*queue,*sink;
>   GstBus *bus;
>
>   gdouble duracion = 500;
>   gint transicion = 1;
>
>   cout << "Inicio..." << endl;
>
>     /* init GStreamer */
>   gst_init (&argc, &argv);
>   gst_controller_init (&argc, &argv);
>
>   loop = g_main_loop_new (NULL, FALSE);
>
>   /* make sure we have input */
>   if (argc != 3) {
>     g_print ("Usage: %s <filename1> <filename2>\n", argv[0]);
>     return -1;
>   }
>
>   src1 = gst_element_factory_make("filesrc", "src1");
>   g_object_set(G_OBJECT(src1),"location",argv[1], NULL);
>
>   src2 = gst_element_factory_make("filesrc", "src2");
>   g_object_set(G_OBJECT(src1),"location",argv[2], NULL);
>
>   GstElement *pipeline = gst_pipeline_new ("video-player");
>
>   dec1 = gst_element_factory_make("decodebin2","dec1");
>
>   dec2 = gst_element_factory_make("decodebin2","dec2");
>
>   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
>   gst_bus_add_watch (bus, bus_call, loop);
>   gst_object_unref (bus);
>
>   alfa1   = gst_element_factory_make ("alpha","alfa1");
>   smpte  = gst_element_factory_make ("smptealpha","smpte");
>   color  = gst_element_factory_make ("ffmpegcolorspace", "color");
>   GstElement * mixer  = gst_element_factory_make("videomixer", "mixer");
>
>   if ((!alfa1) || (!smpte) || (!color) || (!mixer))
>   {
>       g_printerr ("Alguno de los elementos del Bin no pudo ser creado.
> Saliendo\n");
>      return 0;
>   }
>
>   queue = gst_element_factory_make("queue", "queue");
>   sink  = gst_element_factory_make("autovideosink", "sink");
>
>   cout << "Creando 1..." << endl;
>
>   // Agrego Controlador
>
>   GstController * ctrl = NULL;
>   if (!(ctrl = gst_controller_new (G_OBJECT(smpte), "alpha",NULL)))  ///
> Here's the error, always return NULL
>   {
>         cout << "ctrl value..." << ctrl << endl;
>         GST_WARNING ("No puede controlar el elemento fuente\n");
>         return 1;
>   }
>
>
>
>
>
>   // Todo valor GValue debe inicializarse en 0
>   GValue val_double = { 0, };
>   g_value_init (&val_double, G_TYPE_DOUBLE);
>
>
>   // Creo la fuente al controlador y la asocio al controlador
>   // Seteo modo de interpolacion
>
>   GstInterpolationControlSource * csource =
> gst_interpolation_control_source_new();
>   gst_controller_set_control_source (ctrl, "alpha", GST_CONTROL_SOURCE
> (csource));
>
>
> gst_interpolation_control_source_set_interpolation_mode(csource,GST_INTERPOLATE_LINEAR);
>
>   // Seteo primer valor
>   g_value_set_double(&val_double, 0.0);
>   gst_interpolation_control_source_set(csource,(0 *
> GST_MSECOND),&val_double);
>
>   // Seteo segundo valor
>   g_value_set_double (&val_double, duracion);
>   gst_interpolation_control_source_set(csource,(1 *
> GST_MSECOND),&val_double);
>
>   g_object_unref (csource);
>
>   gst_bin_add_many (GST_BIN (pipeline),src1, src2, dec1, dec2, alfa1,
> smpte, mixer, queue, color, sink, NULL);
>   g_signal_connect (G_OBJECT (dec1), "pad-added", G_CALLBACK
> (on_pad_added),alfa1);
>   g_signal_connect (G_OBJECT (dec2), "pad-added", G_CALLBACK
> (on_pad_added),smpte);
>
>   gst_element_link (src1,dec1);
>   gst_element_link (src2,dec2);
>   gst_element_link (alfa1,mixer);
>   gst_element_link (smpte,mixer);
>   gst_element_link (mixer,queue);
>   gst_element_link (queue,sink);
>   g_object_set(smpte,"type", transicion, NULL);
>
>   /* now run */
>   gst_element_set_state (pipeline, GST_STATE_PLAYING);
>   cout << "Playing..." << endl;
>   g_main_loop_run (loop);
>
>     /* also clean up */
>   gst_element_set_state (pipeline, GST_STATE_NULL);
>   gst_object_unref (GST_OBJECT (pipeline));
>
>   return 0;
> }
>
>
>
>
> _______________________________________________
> gstreamer-devel mailing listgstreamer-devel at lists.freedesktop.orghttp://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/20111025/bc05844f/attachment.htm>


More information about the gstreamer-devel mailing list