scaletempo again
padam
skaromana at wp.pl
Fri May 11 06:29:53 PDT 2012
Hi, sorry that i ask so many questions.
I wrote that simple app to play audio, but it doesn't want to add scaletempo
pad to pipeline... I get errors *!gst_pad_is_linked <target> failed* and
*GST_IS_PAD <pad> failed*. Another problem is that, that when scaletempo is
linking player doesn't want to play. Where i made a mistake? Thanks for your
patience.
#include <gst/gst.h>
#include <glib.h>
GstElement *pipeline;
static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg))
{
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR:
{
gchar *debug;
GError *error;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
static void on_pad_added (GstElement *element, GstPad *pad, gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
static gboolean cb_print_position (GstElement *pipeline)
{
GstFormat fmt = GST_FORMAT_TIME;
gint64 pos, len;
if (gst_element_query_position (pipeline, &fmt, &pos) &&
gst_element_query_duration (pipeline, &fmt, &len))
{
g_print ("Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "\r",
GST_TIME_ARGS (pos), GST_TIME_ARGS (len));
}
/* call me again */
return TRUE;
}
void SetRate(gint64 sec)
{
GstFormat fmt = GST_FORMAT_TIME;
gint64 pos;
gdouble rate;
if(sec == 0)
rate = 1.0;
else if(sec == 1)
rate = 1.1;
else if(sec == 2)
rate = 1.2;
else if(sec == 3)
rate = 1.3;
else if(sec == 4)
rate = 1.4;
else if(sec == 5)
rate = 1.5;
gst_element_query_position(GST_ELEMENT(pipeline), &fmt, &pos);
GST_TIME_ARGS (pos);
gst_element_seek (pipeline, rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, pos,
GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
}
int main (int argc, char *argv[])
{
GMainLoop *loop;
GstElement *source, *demuxer, *decoder, *conv, *sink, *queue, *audioparser,
*audioresample, *scaletempo;
GstBus *bus;
GstElement *bin;
GstPad *ghostpad;
GstElement *audioline;
/* Initialisation */
argc++;
argv[1] = "D:\\chill.mp3";
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2)
{
g_printerr ("Usage: %s <Ogg/Vorbis filename>\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("typefind", "ogg-demuxer");
queue = gst_element_factory_make("queue", "queue");
audioparser = gst_element_factory_make("mp3parse","wav-parser");
decoder = gst_element_factory_make ("ffdec_mp3", "vorbis-decoder");
conv = gst_element_factory_make ("audioconvert", "converter");
scaletempo = gst_element_factory_make("scaletempo", "scaletempo");
audioresample = gst_element_factory_make("audioresample", "audioresample");
sink = gst_element_factory_make ("autoaudiosink", "audio-output");
bin = gst_bin_new("mybin");
if (!pipeline || !source || !demuxer || !decoder || !conv || !sink)
{
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
gst_bin_add(GST_BIN(pipeline), bin);
gst_bin_add_many (GST_BIN(bin),
source, demuxer, queue, audioparser, decoder, conv, audioresample,
scaletempo, sink, NULL);
gst_element_link_many (source, demuxer, queue, audioparser, decoder, conv,
audioresample, scaletempo, sink, NULL);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added),
decoder);
ghostpad = gst_element_get_pad (scaletempo, "sink");
gst_element_add_pad (pipeline, gst_ghost_pad_new ("sink", ghostpad));
gst_object_unref (ghostpad);
g_timeout_add (200, (GSourceFunc) cb_print_position, pipeline);
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Running...\n");
while(GST_STATE(pipeline) != GST_STATE_PLAYING);
SetRate(5);
g_object_set (G_OBJECT (scaletempo), "search", 500, NULL);
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/scaletempo-again-tp4626422.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list