Hi, I'm trying to do an audio crossfade, it plays the first audio file correctly, but when it should play the second one, these errors come:
mad gstmad.c:1489:gst_mad_chain: mad_header_decode had an error: lost synchronization 0:00:11.054542971 5898 0x1757a60 WARN mad gstmad.c:1516:gst_mad_chain: mad_frame_decode had an error: reserved header layer v I could did the video crossfade with a similar technique. I appreciate any tip on about what I am doing wrong. Thanks and regards. Rossana Here's the core of the code: 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 * &v1, GstElement *&v2, GstElement * &mad1, GstElement * &mad2, 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"); mad1 = gst_element_factory_make ("mad","mad1"); mad2 = gst_element_factory_make ("mad","mad2"); mixer = gst_element_factory_make("adder", "mixer"); if ((!v1) || (!v2) || (!mad1) || (!mad2) || (!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,mad1,mad2,mixer, NULL); gst_element_link (mad1,v1); gst_element_link (mad2,v2); g_print("enlazo los mad con los volumenes \n"); /* Now link volume outs to adder ins, on request */ GstPad *pad = 0; /* src #1 */ pad = gst_element_get_request_pad(mixer, "sink%d"); g_assert(pad != NULL); gst_pad_link(gst_element_get_pad(v1, "src"), pad); /* Same thing for #2 */ pad = gst_element_get_request_pad (mixer, "sink%d"); g_assert(pad != NULL); gst_pad_link(gst_element_get_pad(v2, "src"), pad); g_print("hasta aqui ok!!! \n"); return bin; } void getAndSetController(GstElement * volumen2, gdouble duracion) { GstController * ctrl = NULL; if (!(ctrl = gst_controller_new (G_OBJECT (volumen2), "volume",NULL))) { 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 *mad1, GstElement * mad2, GstElement * mixer, GstElement* bin) { /* add ghostpad */ GstPad * pad1 = gst_element_get_static_pad (mad1, "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 (mad2, "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, *mad1,*mad2,*mixer; volumen1 = 0; volumen2 = 0; mad1 = 0; mad2 = 0; mixer = 0; bin = getBin("bin",volumen1, volumen2,mad1,mad2,mixer); // Crea el bin y los elementos getAndSetController(volumen2,duracion); addGhostPadsToBin(mad1, mad2, 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 video2 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; } _______________________________________________ gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hi, I change the following lines and it works now, however I appreciate any technical explanation:
Instead of mad1 = gst_element_factory_make ("mad","mad1"); mad2 = gst_element_factory_make ("mad","mad2"); I put these lines: aconv1 = gst_element_factory_make ("audioconvert","aconv1"); aconv2 = gst_element_factory_make ("audioconvert","aconv2"); Thanks Rossana 2011/11/13 Rossana Guerra <[hidden email]> Hi, I'm trying to do an audio crossfade, it plays the first audio file correctly, but when it should play the second one, these errors come: _______________________________________________ gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |