nsresult
sbGStreamerMediaContainer::AcquireMimeType_Priv()
{
  NS_ENSURE_TRUE(!mPath.IsEmpty(), NS_ERROR_NOT_INITIALIZED);

  if (mCaps) {
    // Already acquired
    return NS_OK;
  }

  // Set the bus message callback:
  NS_ENSURE_STATE(mPipeline);
  GstBus *  bus = gst_pipeline_get_bus (GST_PIPELINE (mPipeline));
  gst_bus_add_watch_full (
    bus,
    G_PRIORITY_DEFAULT,
    OnBusMessage_Priv,
    this,
    OnPrerollDone_Priv);
  
  // Set the filesrc target:
  NS_ENSURE_STATE(mFilesrc);
  g_object_set (G_OBJECT (mFilesrc), "location", mPath.get(), NULL);

  // Preroll the pipeline:
  NS_ENSURE_STATE(mLoop);
  gst_element_set_state (GST_ELEMENT (mPipeline), GST_STATE_PAUSED);
  g_main_loop_run (mLoop);
	
  // Get the MIME type if typefind got caps:
  if (mCaps) {
    GetMimeTypeForCaps(mCaps, mMimeType);
  }

  // Set the bus message callback for pipeline shutdown:
  gst_bus_add_watch_full (
    bus,
    G_PRIORITY_DEFAULT,
    OnBusMessage_Priv,
    this,
    OnPrerollDone_Priv);
  gst_object_unref (bus);

  // Shut down the pipeline:
  GstStateChangeReturn mode =
    gst_element_set_state (GST_ELEMENT (mPipeline), GST_STATE_NULL);
  if (mode == GST_STATE_CHANGE_ASYNC) {
    g_main_loop_run (mLoop);
  }
  
  // Return the proper result:
  NS_ENSURE_TRUE(!mMimeType.IsEmpty(), NS_ERROR_NOT_AVAILABLE);

  return NS_OK;
}
Beispiel #2
0
int
main (int argc, char *argv[])
{
  guint i;

  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, FALSE);

  /* Check input arguments */
  if (argc < 2) {
    g_printerr ("Usage: %s <list of space separated URIs>\n",argv[0]);
    return -1;
  }

  for (i = 0; (i<argc  && i <10); i++)
    uri_list[i] = g_strdup (argv[i]);

  num_uri = i-1;
  count = 1;
  g_message ("Num of Input URIs %d", num_uri);

  pipeline = gst_element_factory_make ("playbin", "Playbin");

  g_signal_connect (pipeline, "about-to-finish",
      G_CALLBACK (set_next_uri), NULL);

  /* Set initial URI */
  g_object_set (G_OBJECT (pipeline), "uri", argv[1], NULL);

  bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));

  gst_bus_add_watch_full(bus,
                           G_PRIORITY_HIGH,
                           (GstBusFunc)async_bus_handler,
                           NULL,
                           NULL);

  g_print ("Playing: %s ", argv[1]);
  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  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));
  g_main_loop_unref (loop);

  for (i = 0; (i<argc-1  && i <10); i++)
    g_free (uri_list[i]);

  return 0;
}
Beispiel #3
0
/**
 * gst_bus_add_watch:
 * @bus: a #GstBus to create the watch for
 * @func: A function to call when a message is received.
 * @user_data: user data passed to @func.
 *
 * Adds a bus watch to the default main context with the default priority.
 * This function is used to receive asynchronous messages in the main loop.
 * There can only be a single bus watch per bus, you must remove it before you
 * can set a new one.
 *
 * The watch can be removed using g_source_remove() or by returning FALSE
 * from @func.
 *
 * Returns: The event source id.
 *
 * MT safe.
 */
guint
gst_bus_add_watch (GstBus * bus, GstBusFunc func, gpointer user_data)
{
  return gst_bus_add_watch_full (bus, G_PRIORITY_DEFAULT, func,
      user_data, NULL);
}
Beispiel #4
0
int
main (int argc, char **argv)
{
  GtkWidget *window, *hbox, *vbox, *play_button, *pause_button, *stop_button;
  GstBus *bus;
  GOptionEntry options[] = {
    {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
        "Verbose properties", NULL},
    {NULL}
  };
  gint type;
  GOptionContext *ctx;
  GError *err = NULL;

  if (!g_thread_supported ())
    g_thread_init (NULL);

  ctx = g_option_context_new ("seek");
  g_option_context_add_main_entries (ctx, options, NULL);
  g_option_context_add_group (ctx, gst_init_get_option_group ());

  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
    g_print ("Error initializing: %s\n", err->message);
    exit (1);
  }

  GST_DEBUG_CATEGORY_INIT (scrubby_debug, "scrubby", 0, "scrubby example");

  gtk_init (&argc, &argv);

  if (argc != 3) {
    print_usage (argc, argv);
    exit (-1);
  }

  type = atoi (argv[1]);

  if (type < 0 || type >= NUM_TYPES) {
    print_usage (argc, argv);
    exit (-1);
  }

  pipeline = pipelines[type].func (argv[2]);
  g_assert (pipeline);

  /* initialize gui elements ... */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  hbox = gtk_hbox_new (FALSE, 0);
  vbox = gtk_vbox_new (FALSE, 0);
  play_button = gtk_button_new_with_label ("play");
  pause_button = gtk_button_new_with_label ("pause");
  stop_button = gtk_button_new_with_label ("stop");

  adjustment =
      GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, (gdouble) RANGE_PREC, 0.1,
          1.0, 1.0));
  hscale = gtk_hscale_new (adjustment);
  gtk_scale_set_digits (GTK_SCALE (hscale), 2);
  gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);

  sadjustment =
      GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 0.0, 5.0, 0.1, 1.0, 0.0));
  shscale = gtk_hscale_new (sadjustment);
  gtk_scale_set_digits (GTK_SCALE (shscale), 2);
  gtk_range_set_update_policy (GTK_RANGE (shscale), GTK_UPDATE_CONTINUOUS);

  schanged_id = gtk_signal_connect (GTK_OBJECT (shscale),
      "value_changed", G_CALLBACK (speed_cb), pipeline);

  gtk_signal_connect (GTK_OBJECT (hscale),
      "button_press_event", G_CALLBACK (start_seek), pipeline);
  gtk_signal_connect (GTK_OBJECT (hscale),
      "button_release_event", G_CALLBACK (stop_seek), pipeline);
  gtk_signal_connect (GTK_OBJECT (hscale),
      "format_value", G_CALLBACK (format_value), pipeline);

  /* do the packing stuff ... */
  gtk_window_set_default_size (GTK_WINDOW (window), 96, 96);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_container_add (GTK_CONTAINER (vbox), hbox);
  gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
  gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
  gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
  gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2);
  gtk_box_pack_start (GTK_BOX (vbox), shscale, TRUE, TRUE, 2);

  /* connect things ... */
  g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
      pipeline);
  g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
      pipeline);
  g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
      pipeline);
  g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL);

  /* show the gui. */
  gtk_widget_show_all (window);

  if (verbose) {
    g_signal_connect (pipeline, "deep_notify",
        G_CALLBACK (gst_object_default_deep_notify), NULL);
  }
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  g_assert (bus);

  bus_watch = gst_bus_add_watch_full (bus,
      G_PRIORITY_HIGH, bus_message, pipeline, NULL);

  gtk_main ();

  g_print ("NULL pipeline\n");
  gst_element_set_state (pipeline, GST_STATE_NULL);

  g_print ("free pipeline\n");
  gst_object_unref (pipeline);

  return 0;
}