static gboolean idler (gpointer data) { GstElement *pipeline = GST_ELEMENT (data); if (gst_bin_iterate (GST_BIN (pipeline))) return TRUE; gtk_main_quit (); return FALSE; }
static int act_gstreamer_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) { GstreamerPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); static int playing = 0; if (playing == 0) { char pipe[1024]; gst_init (NULL, NULL); /* snprintf(pipe, 1024, "filesrc location=%s ! decodebin ! ffmpegcolorspace ! " "videoscale ! video/x-raw-rgb,bpp=32,depth=32,width=%d,height=%d," "red_mask=0xff000000,green_mask=0x00ff0000,blue_mask=0x0000ff00 !" "fakesink name=sink sync=true", "test.mpg", video->width, video->height); */ snprintf(pipe, 1024, "filesrc location=%s ! decodebin ! ffmpegcolorspace ! " "video/x-raw-rgb,bpp=24,depth=24 ! " "fakesink name=sink signal-handoffs=true", "test.mpg"); GError *err = NULL; priv->pipe = GST_PIPELINE_CAST(gst_parse_launch (pipe, &err)); if (err) { visual_log (VISUAL_LOG_ERROR, "Failed to create pipeline", err->message); return; } gst_element_set_state (GST_ELEMENT (priv->pipe), GST_STATE_PLAYING); g_signal_connect (gst_bin_get_by_name_recurse_up (GST_BIN (priv->pipe), "sink"), "handoff", G_CALLBACK (have_data), video); playing = 1; } // g_signal_handlers_disconnect_by_func (gst_bin_get_by_name_recurse_up (GST_BIN (priv->pipe), "sink"), // G_CALLBACK (have_data), priv->old_video); gst_bin_iterate (GST_BIN (priv->pipe)); priv->old_video = video; return 0; }
/* This code, I've got from the gstreamer docs, * I just modified it a bit so that it fits the needs * of a GNotify-Soundplay function. */ gboolean gnotify_backend_gst_play(gpointer sfile) { GstElement *pipeline, *filesrc, *decoder, *audiosink; pipeline = gst_pipeline_new ("pipeline"); filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_object_set (G_OBJECT (filesrc), "location", (gchar*)sfile, NULL); decoder = gst_element_factory_make ("spider", "decoder"); audiosink = gst_element_factory_make((const gchar*)GnotifyConfig.gst_audiosink, "play_audio"); gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, audiosink, NULL); gst_element_link_many (filesrc, decoder, audiosink, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); while (gst_bin_iterate (GST_BIN (pipeline))); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT (pipeline)); return(FALSE); }
gint main (gint argc, gchar * argv[]) { gst_init (&argc, &argv); g_print ("\n" "This test will test the various formats ALSA and GStreamer support.\n" "You will hear a short sine tone on your default ALSA soundcard for every\n" "format tested. They should all sound the same (incl. volume).\n" "\n"); create_pipeline (); while (pipeline) { gst_bin_iterate (GST_BIN (pipeline)); if ((counter / 200) > last) { last = counter / 200; gst_object_unref (pipeline); create_pipeline (); } } return 0; }
G_GNUC_UNUSED static GstCaps * gst_play_type_find (GstBin * bin, GstElement * element) { GstElement *typefind; GstElement *pipeline; GstCaps *caps = NULL; GST_DEBUG ("GstPipeline: typefind for element \"%s\"", GST_ELEMENT_NAME (element)); pipeline = gst_pipeline_new ("autoplug_pipeline"); typefind = gst_element_factory_make ("typefind", "typefind"); g_return_val_if_fail (typefind != NULL, FALSE); gst_pad_link (gst_element_get_pad (element, "src"), gst_element_get_pad (typefind, "sink")); gst_bin_add (bin, typefind); gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (bin)); gst_element_set_state (pipeline, GST_STATE_PLAYING); /* push a buffer... the have_type signal handler will set the found flag */ gst_bin_iterate (GST_BIN (pipeline)); gst_element_set_state (pipeline, GST_STATE_NULL); caps = gst_pad_get_caps (gst_element_get_pad (element, "src")); gst_pad_unlink (gst_element_get_pad (element, "src"), gst_element_get_pad (typefind, "sink")); gst_bin_remove (bin, typefind); gst_bin_remove (GST_BIN (pipeline), GST_ELEMENT (bin)); gst_object_unref (typefind); gst_object_unref (pipeline); return caps; }
int main (int argc, char *argv[]) { GstElement *bin, *filesrc, *decoder, *encoder, *filesink; gchar *artist, *title, *ext, *filename; /* initialize GStreamer */ gst_init (&argc, &argv); /* check that the argument is there */ if (argc != 2) { g_print ("usage: %s <mp3 file>\n", argv[0]); return 1; } /* parse the mp3 name */ artist = strrchr (argv[1], '/'); if (artist == NULL) artist = argv[1]; artist = g_strdup (artist); ext = strrchr (artist, '.'); if (ext) *ext = '\0'; title = strstr (artist, " - "); if (title == NULL) { g_print ("The format of the mp3 file is invalid.\n"); g_print ("It needs to be in the form of artist - title.mp3.\n"); return 1; } *title = '\0'; title += 3; /* create a new bin to hold the elements */ bin = gst_pipeline_new ("pipeline"); g_assert (bin); /* create a file reader */ filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_assert (filesrc); /* now it's time to get the decoder */ decoder = gst_element_factory_make ("mad", "decode"); if (!decoder) { g_print ("could not find plugin \"mad\""); return 1; } /* create the encoder */ encoder = gst_element_factory_make ("vorbisenc", "encoder"); if (!encoder) { g_print ("cound not find plugin \"vorbisenc\""); return 1; } /* and a file writer */ filesink = gst_element_factory_make ("filesink", "filesink"); g_assert (filesink); /* set the filenames */ filename = g_strdup_printf ("%s.ogg", argv[1]); /* easy solution */ g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); g_object_set (G_OBJECT (filesink), "location", filename, NULL); g_free (filename); /* make sure the tag setter uses our stuff (though that should already be default) */ gst_tag_setter_set_merge_mode (GST_TAG_SETTER (encoder), GST_TAG_MERGE_KEEP); /* set the tagging information */ gst_tag_setter_add (GST_TAG_SETTER (encoder), GST_TAG_MERGE_REPLACE, GST_TAG_ARTIST, artist, GST_TAG_TITLE, title, NULL); /* add objects to the main pipeline */ gst_bin_add_many (GST_BIN (bin), filesrc, decoder, encoder, filesink, NULL); /* link the elements */ gst_element_link_many (filesrc, decoder, encoder, filesink, NULL); /* start playing */ gst_element_set_state (bin, GST_STATE_PLAYING); while (gst_bin_iterate (GST_BIN (bin))); /* stop the bin */ gst_element_set_state (bin, GST_STATE_NULL); return 0; }
int main (int argc, char *argv[]) { /*int i, j; */ /*gboolean done; */ /*char buffer[20]; */ /*output_channel_t *channel_out; */ GstElement *audiosrc; gst_init (&argc, &argv); /* if (argc == 1) { g_print("usage: %s <filename1> <filename2> <...>\n", argv[0]); exit(-1); }*/ /* set up input channel and main bin */ g_print ("creating main bin\n"); /* create cutter */ cutter = gst_element_factory_make ("cutter", "cutter"); g_object_set (G_OBJECT (cutter), "threshold_dB", -40.0, "runlength", 0.5, "prelength", 1.0, NULL); /* create an audio src */ if (!(audiosrc = gst_element_factory_make ("osssrc", "audio_src"))) g_error ("Could not create 'osssrc' element !\n"); /* set params */ g_object_set (G_OBJECT (audiosrc), "frequency", 44100, "channels", 1, "format", 16, NULL); if (!(encoder = gst_element_factory_make ("passthrough", "encoder"))) g_error ("Could not create 'passthrough' element !\n"); if (!(filesink = gst_element_factory_make ("afsink", "disk_sink"))) g_error ("Could not create 'afsink' element !\n"); g_object_set (G_OBJECT (filesink), "location", "/dev/null", NULL); thread = gst_thread_new ("thread"); g_assert (thread != NULL); /* create main bin */ main_bin = gst_pipeline_new ("bin"); g_assert (main_bin != NULL); queue = gst_element_factory_make ("queue", "queue"); g_assert (queue); /* add elements to bin */ gst_bin_add (GST_BIN (main_bin), audiosrc); gst_bin_add (GST_BIN (thread), queue); gst_bin_add_many (GST_BIN (thread), cutter, encoder, filesink, NULL); gst_element_link_many (audiosrc, queue, cutter, encoder, filesink, NULL); gst_bin_add (GST_BIN (main_bin), thread); /* set signal handlers */ g_print ("setting signal handlers\n"); g_signal_connect (G_OBJECT (cutter), "cut_start", (GCallback) cut_start_signal, NULL); g_signal_connect (G_OBJECT (cutter), "cut_stop", (GCallback) cut_stop_signal, NULL); /* start playing */ g_print ("setting to play\n"); gst_element_set_state (main_bin, GST_STATE_PLAYING); /* g_print ("setting thread to play\n"); gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING); */ while (playing) { /* g_print ("> "); */ gst_bin_iterate (GST_BIN (main_bin)); /* g_print (" <"); */ if (cut_start_signalled) { g_print ("\nDEBUG: main: cut_start_signalled true !\n"); cut_start (cutter); cut_start_signalled = FALSE; } if (cut_stop_signalled) { g_print ("\nDEBUG: main: cut_stop_signalled true !\n"); cut_stop (cutter); cut_stop_signalled = FALSE; } } g_print ("we're done iterating.\n"); /* stop the bin */ gst_element_set_state (main_bin, GST_STATE_NULL); gst_object_unref (filesink); gst_object_unref (main_bin); exit (0); }
int main (int argc, char *argv[]) { GstElement *bin, *filesrc, *decoder, *encoder, *filesink; gchar *artist, *title, *ext, *filename; /* initialize GStreamer */ gst_init (&argc, &argv); /* check that the argument is there */ if (argc != 2) { g_print ("usage: %s <mp4 file>\n", argv[0]); return 1; } artist = strrchr (argv[1], '/'); if (artist == NULL) artist = argv[1]; artist = g_strdup (artist); ext = strrchr (artist, '.'); if (ext) *ext = '\0'; title = strstr (artist, " - "); if (title == NULL) { return 1; } *title = '\0'; title += 3; bin = gst_pipeline_new ("pipeline"); g_assert (bin); filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_assert (filesrc); decoder = gst_element_factory_make ("h264dec", "decode"); if (!decoder) { return 1; } /* create the encoder */ encoder = gst_element_factory_make ("theoraenc", "encoder"); if (!encoder) { g_print ("cound not find plugin \"theoraenc\""); return 1; } filesink = gst_element_factory_make ("filesink", "filesink"); g_assert (filesink); filename = g_strdup_printf ("%s.ogg", argv[1]); /* easy solution */ g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); g_object_set (G_OBJECT (filesink), "location", filename, NULL); g_free (filename); gst_tag_setter_set_merge_mode (GST_TAG_SETTER (encoder), GST_TAG_MERGE_KEEP); gst_tag_setter_add (GST_TAG_SETTER (encoder), GST_TAG_MERGE_REPLACE, GST_TAG_ARTIST, artist, GST_TAG_TITLE, title, NULL); gst_bin_add_many (GST_BIN (bin), filesrc, decoder, encoder, filesink, NULL); /* link the elements */ gst_element_link_many (filesrc, decoder, encoder, filesink, NULL); /* start playing */ gst_element_set_state (bin, GST_STATE_PLAYING); while (gst_bin_iterate (GST_BIN (bin))); /* stop the bin */ gst_element_set_state (bin, GST_STATE_NULL); return 0; }
int main (int argc, char *argv[]) { GstElement *filesrc, *osssink, *queue, *queue2, *parse, *decode; GstElement *bin; GstElement *thread, *thread2; gst_init (&argc, &argv); if (argc != 2) { g_print ("usage: %s <filename>\n", argv[0]); exit (-1); } /* create a new thread to hold the elements */ thread = gst_thread_new ("thread"); g_assert (thread != NULL); thread2 = gst_thread_new ("thread2"); g_assert (thread2 != NULL); /* create a new bin to hold the elements */ bin = gst_bin_new ("bin"); g_assert (bin != NULL); /* create a disk reader */ filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_assert (filesrc != NULL); g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread); queue = gst_element_factory_make ("queue", "queue"); queue2 = gst_element_factory_make ("queue", "queue2"); /* and an audio sink */ osssink = gst_element_factory_make ("osssink", "play_audio"); g_assert (osssink != NULL); parse = gst_element_factory_make ("mp3parse", "parse"); decode = gst_element_factory_make ("mpg123", "decode"); /* add objects to the main bin */ gst_bin_add (GST_BIN (bin), filesrc); gst_bin_add (GST_BIN (bin), queue); gst_bin_add (GST_BIN (thread), parse); gst_bin_add (GST_BIN (thread), decode); gst_bin_add (GST_BIN (thread), queue2); gst_bin_add (GST_BIN (thread2), osssink); gst_element_link_many (filesrc, queue, parse, decode, queue2, osssink, NULL); gst_bin_add (GST_BIN (bin), thread); gst_bin_add (GST_BIN (bin), thread2); /* make it ready */ gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY); /* start playing */ gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING); playing = TRUE; while (playing) { gst_bin_iterate (GST_BIN (bin)); } gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL); exit (0); }
int main (int argc, char *argv[]) { int i, j; int num_channels; char buffer[20]; GList *input_channels; /* structure holding all the input channels */ input_channel_t *channel_in; GstElement *main_bin; GstElement *adder; GstElement *audiosink; GstPad *pad; /* to request pads for the adder */ gst_init (&argc, &argv); if (argc == 1) { g_print ("usage: %s <filename1> <filename2> <...>\n", argv[0]); exit (-1); } num_channels = argc - 1; /* set up output channel and main bin */ /* create adder */ adder = gst_element_factory_make ("adder", "adderel"); /* create an audio sink */ audiosink = gst_element_factory_make ("esdsink", "play_audio"); /* create main bin */ main_bin = gst_pipeline_new ("bin"); /* link adder and output to bin */ GST_INFO ("main: adding adder to bin"); gst_bin_add (GST_BIN (main_bin), adder); GST_INFO ("main: adding audiosink to bin"); gst_bin_add (GST_BIN (main_bin), audiosink); /* link adder and audiosink */ gst_pad_link (gst_element_get_pad (adder, "src"), gst_element_get_pad (audiosink, "sink")); /* start looping */ input_channels = NULL; for (i = 1; i < argc; ++i) { printf ("Opening channel %d from file %s...\n", i, argv[i]); channel_in = create_input_channel (i, argv[i]); input_channels = g_list_append (input_channels, channel_in); if (i > 1) gst_element_set_state (main_bin, GST_STATE_PAUSED); gst_bin_add (GST_BIN (main_bin), channel_in->pipe); /* request pads and link to adder */ GST_INFO ("requesting pad\n"); pad = gst_element_get_request_pad (adder, "sink%d"); printf ("\tGot new adder sink pad %s\n", gst_pad_get_name (pad)); sprintf (buffer, "channel%d", i); gst_pad_link (gst_element_get_pad (channel_in->pipe, buffer), pad); /* register a volume envelope */ printf ("\tregistering volume envelope...\n"); /* * this is the volenv : * each song gets a slot of 5 seconds, with a 5 second fadeout * at the end of that, all audio streams play simultaneously * at a level ensuring no distortion * example for three songs : * song1 : starts at full level, plays 5 seconds, faded out at 10 seconds, * sleep until 25, fade to end level at 30 * song2 : starts silent, fades in at 5 seconds, full blast at 10 seconds, * full level until 15, faded out at 20, sleep until 25, fade to end at 30 * song3 : starts muted, fades in from 15, full at 20, until 25, fade to end level */ if (i == 1) { /* first song gets special treatment for end style */ env_register_cp (channel_in->volenv, 0.0, 1.0); } else { env_register_cp (channel_in->volenv, 0.0, 0.0000001); /* start muted */ env_register_cp (channel_in->volenv, i * 10.0 - 15.0, 0.0000001); /* start fade in */ env_register_cp (channel_in->volenv, i * 10.0 - 10.0, 1.0); } env_register_cp (channel_in->volenv, i * 10.0 - 5.0, 1.0); /* end of full level */ if (i != num_channels) { env_register_cp (channel_in->volenv, i * 10.0, 0.0000001); /* fade to black */ env_register_cp (channel_in->volenv, num_channels * 10.0 - 5.0, 0.0000001); /* start fade in */ } env_register_cp (channel_in->volenv, num_channels * 10.0, 1.0 / num_channels); /* to end level */ #ifndef GST_DISABLE_LOADSAVE gst_xml_write_file (GST_ELEMENT (main_bin), fopen ("mixer.xml", "w")); #endif /* start playing */ gst_element_set_state (main_bin, GST_STATE_PLAYING); /* write out the schedule */ gst_scheduler_show (GST_ELEMENT_SCHEDULER (main_bin)); playing = TRUE; j = 0; /*printf ("main: start iterating from 0"); */ while (playing && j < 100) { /* printf ("main: iterating %d\n", j); */ gst_bin_iterate (GST_BIN (main_bin)); /*fprintf(stderr,"after iterate()\n"); */ ++j; } } printf ("main: all the channels are open\n"); while (playing) { gst_bin_iterate (GST_BIN (main_bin)); /*fprintf(stderr,"after iterate()\n"); */ } /* stop the bin */ gst_element_set_state (main_bin, GST_STATE_NULL); while (input_channels) { destroy_input_channel (input_channels->data); input_channels = g_list_next (input_channels); } g_list_free (input_channels); gst_object_unref (audiosink); gst_object_unref (main_bin); exit (0); }
gint main (gint argc, gchar * argv[]) { GstElement *pipeline; GError *error = NULL; gchar *description; GstElement *encoder, *decoder; GstPad *dec_sink, *enc_src; gst_init (&argc, &argv); if (argc < 3) { g_print ("usage: %s <inputfile> <outputfile>\n", argv[0]); return -1; } description = g_strdup_printf ("filesrc location=\"%s\" ! mad name=decoder ! " "vorbisenc name=encoder ! filesink location=\"%s\"", argv[1], argv[2]); pipeline = GST_ELEMENT (gst_parse_launch (description, &error)); if (!pipeline) { if (error) g_print ("ERROR: pipeline could not be constructed: %s\n", error->message); else g_print ("ERROR: pipeline could not be constructed\n"); return -1; } decoder = gst_bin_get_by_name (GST_BIN (pipeline), "decoder"); encoder = gst_bin_get_by_name (GST_BIN (pipeline), "encoder"); dec_sink = gst_element_get_pad (decoder, "sink"); enc_src = gst_element_get_pad (encoder, "src"); if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS) { g_print ("pipeline doesn't want to play\n"); return -1; } while (gst_bin_iterate (GST_BIN (pipeline))) { gint64 position; gint64 duration; gint64 bitrate_enc, bitrate_dec; GstFormat format; format = GST_FORMAT_TIME; /* get the position */ gst_pad_query (enc_src, GST_QUERY_POSITION, &format, &position); /* get the total duration */ gst_pad_query (enc_src, GST_QUERY_TOTAL, &format, &duration); format = GST_FORMAT_BYTES; /* see how many bytes are genereated per 8 seconds (== bitrate) */ gst_pad_convert (enc_src, GST_FORMAT_TIME, 8 * GST_SECOND, &format, &bitrate_enc); gst_pad_convert (dec_sink, GST_FORMAT_TIME, 8 * GST_SECOND, &format, &bitrate_dec); g_print ("[%2dm %.2ds] of [%2dm %.2ds], " "src avg bitrate: %" G_GINT64_FORMAT ", dest avg birate: %" G_GINT64_FORMAT ", ratio [%02.2f] \r", (gint) (position / (GST_SECOND * 60)), (gint) (position / (GST_SECOND)) % 60, (gint) (duration / (GST_SECOND * 60)), (gint) (duration / (GST_SECOND)) % 60, bitrate_dec, bitrate_enc, (gfloat) bitrate_dec / bitrate_enc); } g_print ("\n"); return 0; }
int main (int argc, char *argv[]) { GstElement *filesrc, *audiosink, *queue; GstElement *pipeline; gst_init (&argc, &argv); if (argc != 2) { g_print ("usage: %s <filename>\n", argv[0]); exit (-1); } /* create a new bin to hold the elements */ pipeline = gst_pipeline_new ("pipeline"); g_assert (pipeline != NULL); /* create a disk reader */ filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_assert (filesrc != NULL); g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread); queue = gst_element_factory_make ("queue", "queue"); /* and an audio sink */ audiosink = gst_element_factory_make ("alsasink", "play_audio"); g_assert (audiosink != NULL); /* add objects to the main pipeline */ /* gst_pipeline_add_src(GST_PIPELINE(pipeline), filesrc); gst_pipeline_add_sink(GST_PIPELINE(pipeline), queue); gst_bin_add(GST_BIN (pipeline), audiosink); gst_pad_link(gst_element_get_pad(queue,"src"), gst_element_get_pad(audiosink,"sink")); if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) { g_print("cannot autoplug pipeline\n"); exit(-1); } */ gst_bin_add (GST_BIN (pipeline), thread); /* make it ready */ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY); /* start playing */ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); playing = TRUE; while (playing) { gst_bin_iterate (GST_BIN (pipeline)); } gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); exit (0); }
void gap_metadata_load (GAPMetaData *md, const char *uri) { GstElement *pipeline = NULL; GstElement *gnomevfssrc = NULL; GstElement *typefind = NULL; GstElement *spider = NULL; GstElement *fakesink = NULL; GstCaps *filtercaps = NULL; const char *plugin_name = NULL; g_return_if_fail (uri != NULL); g_print ("Loading metadata for: %s\n", uri); md->uri = g_strdup (uri); md->duration = -1; /* The main tagfinding pipeline looks like this: * gnomevfssrc ! typefind ! spider ! application/x-gst-tags ! fakesink */ pipeline = gst_pipeline_new ("pipeline"); g_signal_connect (pipeline, "error", G_CALLBACK (cb_gst_error), md); g_signal_connect (pipeline, "found-tag", G_CALLBACK (cb_gst_found_tag), md); gnomevfssrc = gst_element_factory_make ("gnomevfssrc", "gnomevfssrc"); /* TODO: check error */ gst_bin_add (GST_BIN (pipeline), gnomevfssrc); g_object_set (G_OBJECT (gnomevfssrc), "location", uri, NULL); typefind = gst_element_factory_make ("typefind", "typefind"); /* TODO: check error */ g_signal_connect (typefind, "have_type", G_CALLBACK (cb_gst_have_type), md); gst_bin_add (GST_BIN (pipeline), typefind); spider = gst_element_factory_make ("spider", "spider"); /* TODO: check error */ gst_bin_add (GST_BIN (pipeline), spider); fakesink = gst_element_factory_make ("fakesink", "fakesink"); /* TODO: check error */ gst_bin_add (GST_BIN (pipeline), fakesink); g_object_set (G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL); g_signal_connect (fakesink, "handoff", G_CALLBACK (cb_gst_handoff), md); g_signal_connect (fakesink, "eos", G_CALLBACK (cb_gst_eos), md); gst_element_link_many (gnomevfssrc, typefind, spider, NULL); filtercaps = gst_caps_new_simple ("audio/x-raw-int", NULL); gst_element_link_filtered (spider, fakesink, filtercaps); gst_caps_free (filtercaps); gst_element_set_state (pipeline, GST_STATE_PLAYING); while ((gst_bin_iterate (GST_BIN (pipeline))) && (md->error == NULL) && (!md->handoff) && (!md->eos)) ; if (md->handoff) { if (md->duration == -1) { GstFormat format = GST_FORMAT_TIME; gint64 length; if (gst_element_query (fakesink, GST_QUERY_TOTAL, &format, &length)) { GValue *newval = g_new0 (GValue, 1); g_print ("Duration query succeeded\n"); g_value_init (newval, G_TYPE_LONG); g_value_set_long (newval, (long) (length / (1 * 1000 * 1000 * 1000))); md->duration = g_value_get_long (newval); g_printf ("Duration: %d\n", md->duration); } else g_print ("Duration query failed\n"); } } else if (md->eos) g_print ("Received eos without handoff\n"); gst_element_set_state (pipeline, GST_STATE_NULL); if (pipeline != NULL) gst_object_unref (GST_OBJECT (pipeline)); }