Blame tests/icles/playback/test6.c

Packit 971217
/* GStreamer
Packit 971217
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
#ifdef HAVE_UNISTD_H
Packit 971217
#include <unistd.h>
Packit 971217
#endif
Packit 971217
#ifdef HAVE_STDLIB_H
Packit 971217
#include <stdlib.h>             /* exit */
Packit 971217
#endif
Packit 971217
#include <gst/gst.h>
Packit 971217
Packit 971217
static void
Packit 971217
pad_added_cb (GstElement * decodebin, GstPad * new_pad, GstElement * pipeline)
Packit 971217
{
Packit 971217
  GstElement *fakesink;
Packit 971217
  GstPad *sinkpad;
Packit 971217
Packit 971217
  fakesink = gst_element_factory_make ("fakesink", NULL);
Packit 971217
  gst_bin_add (GST_BIN (pipeline), fakesink);
Packit 971217
Packit 971217
  sinkpad = gst_element_get_static_pad (fakesink, "sink");
Packit 971217
  if (GST_PAD_LINK_FAILED (gst_pad_link (new_pad, sinkpad))) {
Packit 971217
    g_warning ("Failed to link %s:%s to %s:%s", GST_DEBUG_PAD_NAME (new_pad),
Packit 971217
        GST_DEBUG_PAD_NAME (sinkpad));
Packit 971217
    gst_bin_remove (GST_BIN (pipeline), fakesink);
Packit 971217
  } else {
Packit 971217
    gst_element_set_state (fakesink, GST_STATE_PAUSED);
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
show_error (const gchar * errmsg, GstBus * bus)
Packit 971217
{
Packit 971217
  GstMessage *msg;
Packit 971217
  GError *err = NULL;
Packit 971217
  gchar *dbg = NULL;
Packit 971217
Packit 971217
  msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
Packit 971217
  if (msg) {
Packit 971217
    g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
Packit 971217
Packit 971217
    gst_message_parse_error (msg, &err, &dbg;;
Packit 971217
  }
Packit 971217
Packit 971217
  g_print ("ERROR: %s\n", errmsg);
Packit 971217
  g_print ("       %s\n", (err) ? err->message : "");
Packit 971217
  if (dbg) {
Packit 971217
    g_print ("\ndebug: %s\n\n", dbg);
Packit 971217
    g_free (dbg);
Packit 971217
  }
Packit 971217
Packit 971217
  if (err)
Packit 971217
    g_error_free (err);
Packit 971217
}
Packit 971217
Packit 971217
gint
Packit 971217
main (gint argc, gchar * argv[])
Packit 971217
{
Packit 971217
  GstElement *pipeline, *filesrc, *decodebin;
Packit 971217
  GstStateChangeReturn res;
Packit 971217
  GstIterator *it;
Packit 971217
  GstBus *bus;
Packit 971217
  GValue data = { 0, };
Packit 971217
Packit 971217
  gst_init (&argc, &argv);
Packit 971217
Packit 971217
  pipeline = gst_pipeline_new ("pipeline");
Packit 971217
Packit 971217
  filesrc = gst_element_factory_make ("filesrc", "filesrc");
Packit 971217
  g_assert (filesrc);
Packit 971217
Packit 971217
  decodebin = gst_element_factory_make ("decodebin", "decodebin");
Packit 971217
  g_assert (decodebin);
Packit 971217
Packit 971217
  gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
Packit 971217
  gst_element_link (filesrc, decodebin);
Packit 971217
Packit 971217
  if (argc < 2) {
Packit 971217
    g_print ("usage: %s <filenames>\n", argv[0]);
Packit 971217
    exit (-1);
Packit 971217
  }
Packit 971217
Packit 971217
  if (!g_str_has_prefix (argv[1], "file://")) {
Packit 971217
    g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
Packit 971217
  } else {
Packit 971217
    g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
Packit 971217
  }
Packit 971217
Packit 971217
  /* we've got to connect fakesinks to newly decoded pads to make sure
Packit 971217
   * buffers have actually been flowing over those pads and caps have
Packit 971217
   * been set on them. decodebin might insert internal queues and
Packit 971217
   * without fakesinks it's pot-luck what caps we get from the pad, because
Packit 971217
   * it depends on whether the queues have started pushing buffers yet or not.
Packit 971217
   * With fakesinks we make sure that the pipeline doesn't go to PAUSED state
Packit 971217
   * before each fakesink has a buffer queued. */
Packit 971217
  g_signal_connect (decodebin, "pad-added",
Packit 971217
      G_CALLBACK (pad_added_cb), pipeline);
Packit 971217
Packit 971217
  bus = gst_element_get_bus (pipeline);
Packit 971217
Packit 971217
  g_print ("pause..\n");
Packit 971217
  res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
Packit 971217
  if (res == GST_STATE_CHANGE_FAILURE) {
Packit 971217
    show_error ("Could not go to PAUSED state", bus);
Packit 971217
    exit (-1);
Packit 971217
  }
Packit 971217
  g_print ("waiting..\n");
Packit 971217
  res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
Packit 971217
  if (res != GST_STATE_CHANGE_SUCCESS) {
Packit 971217
    show_error ("Failed to complete state change to PAUSED", bus);
Packit 971217
    exit (-1);
Packit 971217
  }
Packit 971217
  g_print ("stats..\n");
Packit 971217
Packit 971217
  it = gst_element_iterate_src_pads (decodebin);
Packit 971217
  while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
Packit 971217
    GstPad *pad = g_value_get_object (&data);
Packit 971217
    GstCaps *caps;
Packit 971217
    gchar *str;
Packit 971217
    GstQuery *query;
Packit 971217
Packit 971217
    g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
Packit 971217
Packit 971217
    caps = gst_pad_query_caps (pad, NULL);
Packit 971217
    str = gst_caps_to_string (caps);
Packit 971217
    g_print (" caps: %s\n", str);
Packit 971217
    g_free (str);
Packit 971217
    gst_caps_unref (caps);
Packit 971217
Packit 971217
    query = gst_query_new_duration (GST_FORMAT_TIME);
Packit 971217
    if (gst_pad_query (pad, query)) {
Packit 971217
      gint64 duration;
Packit 971217
Packit 971217
      gst_query_parse_duration (query, NULL, &duration);
Packit 971217
Packit 971217
      g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
Packit 971217
    }
Packit 971217
    gst_query_unref (query);
Packit 971217
Packit 971217
    g_value_reset (&data);
Packit 971217
  }
Packit 971217
  g_value_unset (&data);
Packit 971217
  gst_iterator_free (it);
Packit 971217
Packit 971217
  return 0;
Packit 971217
}