gstreamer/tests/icles/playback/test6.c

165 lines
4.7 KiB
C
Raw Normal View History

/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h> /* exit */
#endif
#include <gst/gst.h>
static void
new_decoded_pad_cb (GstElement * decodebin, GstPad * new_pad, gboolean last,
GstElement * pipeline)
{
GstElement *fakesink;
GstPad *sinkpad;
fakesink = gst_element_factory_make ("fakesink", NULL);
gst_bin_add (GST_BIN (pipeline), fakesink);
Don't use bad gst_element_get_pad(). Original commit message from CVS: * ext/ogg/gstoggdemux.c: (gst_ogg_pad_typefind): * gst/playback/decodetest.c: (new_decoded_pad_cb): * gst/playback/gstdecodebin.c: (gst_decode_bin_init), (try_to_link_1), (elem_is_dynamic), (close_link), (type_found), (cleanup_decodebin): * gst/playback/gstdecodebin2.c: (gst_decode_bin_init), (connect_element), (gst_decode_group_control_demuxer_pad): * gst/playback/gstplaybasebin.c: (queue_remove_probe), (queue_out_of_data), (gen_preroll_element), (preroll_unlinked), (mute_group_type): * gst/playback/gstplaybin.c: (gst_play_bin_vis_blocked), (gst_play_bin_set_property), (handoff), (gen_video_element), (gen_text_element), (gen_audio_element), (gen_vis_element), (remove_sinks), (add_sink), (setup_sinks): * gst/playback/gstplaybin2.c: (pad_added_cb), (no_more_pads_cb): * gst/playback/gstplaysink.c: (gst_play_sink_get_video_sink), (gst_play_sink_get_audio_sink), (gst_play_sink_vis_unblocked), (gst_play_sink_vis_blocked), (gst_play_sink_set_vis_plugin), (gst_play_sink_get_vis_plugin), (gst_play_sink_set_mute), (gen_video_chain), (gen_text_chain), (gen_audio_chain), (gen_vis_chain), (gst_play_sink_reconfigure), (gst_play_sink_set_font_desc), (gst_play_sink_get_font_desc), (gst_play_sink_request_pad): * gst/playback/gsturidecodebin.c: (type_found), (setup_source): * gst/playback/test.c: (gen_video_element), (gen_audio_element), (cb_newpad): * gst/playback/test6.c: (new_decoded_pad_cb): * tests/check/elements/audioconvert.c: (GST_START_TEST): * tests/check/elements/audiorate.c: (test_injector_chain), (do_perfect_stream_test): * tests/check/elements/ffmpegcolorspace.c: (GST_START_TEST): * tests/check/elements/gdpdepay.c: (GST_START_TEST): * tests/check/elements/gnomevfssink.c: * tests/check/elements/textoverlay.c: (notgst_check_setup_src_pad2), (notgst_check_teardown_src_pad2): * tests/check/elements/videotestsrc.c: (GST_START_TEST): * tests/check/libs/cddabasesrc.c: (GST_START_TEST): * tests/check/pipelines/oggmux.c: (test_pipeline): * tests/check/pipelines/streamheader.c: (GST_START_TEST): * tests/check/pipelines/theoraenc.c: (GST_START_TEST): * tests/check/pipelines/vorbisenc.c: (GST_START_TEST): * tests/examples/seek/scrubby.c: (make_wav_pipeline): * tests/examples/seek/seek.c: (make_mod_pipeline), (make_dv_pipeline), (make_wav_pipeline), (make_flac_pipeline), (make_sid_pipeline), (make_parse_pipeline), (make_vorbis_pipeline), (make_theora_pipeline), (make_vorbis_theora_pipeline), (make_avi_msmpeg4v3_mp3_pipeline), (make_mp3_pipeline), (make_avi_pipeline), (make_mpeg_pipeline), (make_mpegnt_pipeline), (update_fill), (msg_buffering): Don't use bad gst_element_get_pad().
2008-05-21 16:36:50 +00:00
sinkpad = gst_element_get_static_pad (fakesink, "sink");
if (GST_PAD_LINK_FAILED (gst_pad_link (new_pad, sinkpad))) {
g_warning ("Failed to link %s:%s to %s:%s", GST_DEBUG_PAD_NAME (new_pad),
GST_DEBUG_PAD_NAME (sinkpad));
gst_bin_remove (GST_BIN (pipeline), fakesink);
} else {
gst_element_set_state (fakesink, GST_STATE_PAUSED);
}
}
static void
show_error (const gchar * errmsg, GstBus * bus)
{
GstMessage *msg;
GError *err = NULL;
gchar *dbg = NULL;
msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
if (msg) {
g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
gst_message_parse_error (msg, &err, &dbg);
}
g_print ("ERROR: %s\n", errmsg);
g_print (" %s\n", (err) ? err->message : "");
if (dbg) {
g_print ("\ndebug: %s\n\n", dbg);
g_free (dbg);
}
if (err)
g_error_free (err);
}
gint
main (gint argc, gchar * argv[])
{
GstElement *pipeline, *filesrc, *decodebin;
GstStateChangeReturn res;
GstIterator *it;
GstBus *bus;
gpointer data;
gst_init (&argc, &argv);
pipeline = gst_pipeline_new ("pipeline");
filesrc = gst_element_factory_make ("filesrc", "filesrc");
g_assert (filesrc);
decodebin = gst_element_factory_make ("decodebin", "decodebin");
g_assert (decodebin);
gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
gst_element_link (filesrc, decodebin);
if (argc < 2) {
g_print ("usage: %s <filenames>\n", argv[0]);
exit (-1);
}
if (!g_str_has_prefix (argv[1], "file://")) {
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
} else {
g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
}
/* we've got to connect fakesinks to newly decoded pads to make sure
* buffers have actually been flowing over those pads and caps have
* been set on them. decodebin might insert internal queues and
* without fakesinks it's pot-luck what caps we get from the pad, because
* it depends on whether the queues have started pushing buffers yet or not.
* With fakesinks we make sure that the pipeline doesn't go to PAUSED state
* before each fakesink has a buffer queued. */
g_signal_connect (decodebin, "new-decoded-pad",
G_CALLBACK (new_decoded_pad_cb), pipeline);
bus = gst_element_get_bus (pipeline);
g_print ("pause..\n");
res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
if (res == GST_STATE_CHANGE_FAILURE) {
show_error ("Could not go to PAUSED state", bus);
exit (-1);
}
g_print ("waiting..\n");
res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
if (res != GST_STATE_CHANGE_SUCCESS) {
show_error ("Failed to complete state change to PAUSED", bus);
exit (-1);
}
g_print ("stats..\n");
it = gst_element_iterate_src_pads (decodebin);
while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
GstPad *pad = GST_PAD (data);
GstCaps *caps;
gchar *str;
GstQuery *query;
g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
caps = gst_pad_get_caps (pad);
str = gst_caps_to_string (caps);
g_print (" caps: %s\n", str);
g_free (str);
gst_caps_unref (caps);
query = gst_query_new_duration (GST_FORMAT_TIME);
if (gst_pad_query (pad, query)) {
gint64 duration;
gst_query_parse_duration (query, NULL, &duration);
g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
}
gst_query_unref (query);
gst_object_unref (pad);
}
gst_iterator_free (it);
return 0;
}