gst_mpeg_audio_parse_head_check:<mpegaudioparse1> invalid samplerate: 0x3 - WARN during audio crossfading

Rossana Guerra guerra.rossana at gmail.com
Tue Nov 15 22:14:03 PST 2011


Hi I did a crossfading code, it works almost fine, at the begining of the
second audio clip two little dry noises appear.
The applications runs for avi files.

During the crossfade I do linear interpolation  of volume property.

Running the code with GST_DEBUG = 2, this is the warn for the second clip:
c:471:gst_mpeg_audio_parse_head_check:<mpegaudioparse1> invalid samplerate:
0x3
Is the noise related to this warn?

Thanks

Rossana

Here's the core of the code:


GstElement * getBin(const gchar * nomBin, GstElement * &v1, GstElement
*&v2, GstElement * &aconv1, GstElement * &aconv2, GstElement * &mixer)
{

  GstElement * bin = gst_bin_new(nomBin);

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

  v1   = gst_element_factory_make ("volume","vol1");
  v2  = gst_element_factory_make ("volume","vol2");
  aconv1   = gst_element_factory_make ("audioconvert","aconv1");
  aconv2  = gst_element_factory_make ("audioconvert","aconv2");

  mixer  = gst_element_factory_make("adder", "mixer");

  if ((!v1) || (!v2) || (!aconv1) || (!aconv2) || (!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),v1,v2,aconv1,aconv2,mixer, NULL);

  gst_element_link (aconv1,v1);
  gst_element_link (aconv2,v2);


   /* Now link volume outs to adder ins, on request */
  GstPad *pad = 0;

  pad = gst_element_get_request_pad(mixer, "sink%d");
  g_assert(pad != NULL);
  gst_pad_link(gst_element_get_pad(v1,"src"), pad);

  pad = gst_element_get_request_pad (mixer, "sink%d");
  g_assert(pad != NULL);
  gst_pad_link(gst_element_get_pad(v2, "src"), pad);

  return bin;
}

void getAndSetController(GstElement * volumen2, gdouble duracion)
{
    GstController * ctrl = NULL;
    if (!(ctrl = gst_controller_new (G_OBJECT (volumen2), "volume",NULL))) {
        cout << "No creo controlador.." << endl;
        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, "volume", 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, 1.0);
  gst_interpolation_control_source_set(csource,(duracion *
GST_MSECOND),&val_double);


  g_object_unref (csource);

}

void addGhostPadsToBin(GstElement *aconv1, GstElement * aconv2, GstElement
* mixer, GstElement* bin)
{
    /* add ghostpad */
  GstPad * pad1 = gst_element_get_static_pad (aconv1, "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 (aconv2, "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 (mixer, "src");
  gst_element_add_pad(bin, gst_ghost_pad_new("mixersrc", pad3));
  gst_object_unref(GST_OBJECT(pad3));
}

void crossTransicion(gdouble duracion, GstElement * & bin,gint transicion =
1)
{
    // devuelve el bin
    GstElement * volumen1, *volumen2, *aconv1,*aconv2,*mixer;
    volumen1 = 0;
    volumen2 = 0;
    aconv1 = 0;
    aconv2 = 0;
    mixer = 0;

    bin = getBin("bin",volumen1, volumen2,aconv1,aconv2,mixer);  // Crea el
bin y los elementos

    getAndSetController(volumen2,duracion);

    addGhostPadsToBin(aconv1, aconv2, mixer, 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, *audio1, *audio2, *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;
    }

    GstCaps *caps =
gst_caps_from_string("audio/x-raw-int;audio/x-raw-float");

    // Create our composition
    g_object_set(G_OBJECT(comp), "caps", caps, 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 ((audio1 = gst_element_factory_make("gnlfilesource", "audio1")) ==
NULL)
    {
      printf ("\n Falló la creacion del gnlfilesource \n");
      return NULL;
    }
    if (gst_bin_add (GST_BIN (comp), audio1) == FALSE)
    {
      printf ("\n No pudo agregar audio1 a comp \n");
      return NULL;
    }

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

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

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

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

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

    pipeline = gst_pipeline_new ("audio-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);
    GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(play),
GST_DEBUG_GRAPH_SHOW_ALL,"audio2");

    /* 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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20111116/49942ae8/attachment.html>


More information about the gstreamer-devel mailing list