/tests/examples/gstplay/player.c

https://github.com/rikaunite/gst-opera_gst-plugins-bad · C · 176 lines · 115 code · 33 blank · 28 comment · 20 complexity · 6dd11bcfcafaa14e88a695cbbb8d1548 MD5 · raw file

  1. /* GStreamer
  2. * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #include <gst/play/play.h>
  20. #include <gst/gconf/gconf.h>
  21. static GMainLoop *loop = NULL;
  22. static gint64 length = 0;
  23. static void
  24. print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
  25. {
  26. gint i, count;
  27. count = gst_tag_list_get_tag_size (list, tag);
  28. for (i = 0; i < count; i++) {
  29. gchar *str;
  30. if (gst_tag_get_type (tag) == G_TYPE_STRING) {
  31. if (!gst_tag_list_get_string_index (list, tag, i, &str))
  32. g_assert_not_reached ();
  33. } else {
  34. str =
  35. g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i));
  36. }
  37. if (i == 0) {
  38. g_print ("%15s: %s\n", gst_tag_get_nick (tag), str);
  39. } else {
  40. g_print (" : %s\n", str);
  41. }
  42. g_free (str);
  43. }
  44. }
  45. static void
  46. got_found_tag (GstPlay * play, GstElement * source, GstTagList * tag_list)
  47. {
  48. gst_tag_list_foreach (tag_list, print_tag, NULL);
  49. }
  50. static void
  51. got_time_tick (GstPlay * play, gint64 time_nanos)
  52. {
  53. g_print ("time tick %f\n", time_nanos / (float) GST_SECOND);
  54. }
  55. static void
  56. got_stream_length (GstPlay * play, gint64 length_nanos)
  57. {
  58. g_print ("got length %" G_GUINT64_FORMAT "\n", length_nanos);
  59. length = length_nanos;
  60. }
  61. static void
  62. got_video_size (GstPlay * play, gint width, gint height)
  63. {
  64. g_print ("got video size %d, %d\n", width, height);
  65. }
  66. static void
  67. got_eos (GstPlay * play)
  68. {
  69. g_print ("End Of Stream\n");
  70. g_main_loop_quit (loop);
  71. }
  72. static gboolean
  73. seek_timer (GstPlay * play)
  74. {
  75. gst_play_seek_to_time (play, length / 2);
  76. return FALSE;
  77. }
  78. int
  79. main (int argc, char *argv[])
  80. {
  81. GstPlay *play;
  82. GstElement *data_src, *video_sink, *audio_sink, *vis_element;
  83. GError *error = NULL;
  84. /* Initing GStreamer library */
  85. gst_init (&argc, &argv);
  86. if (argc != 2) {
  87. g_print ("usage: %s <video filename>\n", argv[0]);
  88. exit (-1);
  89. }
  90. loop = g_main_loop_new (NULL, FALSE);
  91. /* Creating the GstPlay object */
  92. play = gst_play_new (&error);
  93. if (error) {
  94. g_print ("Error: could not create play object:\n%s\n", error->message);
  95. g_error_free (error);
  96. return 1;
  97. }
  98. /* Getting default audio and video plugins from GConf */
  99. vis_element = gst_element_factory_make ("goom", "vis_element");
  100. data_src = gst_element_factory_make ("gnomevfssrc", "source");
  101. audio_sink = gst_gconf_get_default_audio_sink ();
  102. if (!GST_IS_ELEMENT (audio_sink))
  103. g_error ("Could not get default audio sink from GConf");
  104. video_sink = gst_gconf_get_default_video_sink ();
  105. if (!GST_IS_ELEMENT (video_sink))
  106. g_error ("Could not get default video sink from GConf");
  107. /* Let's send them to GstPlay object */
  108. if (!gst_play_set_audio_sink (play, audio_sink))
  109. g_warning ("Could not set audio sink");
  110. if (!gst_play_set_video_sink (play, video_sink))
  111. g_warning ("Could not set video sink");
  112. if (!gst_play_set_data_src (play, data_src))
  113. g_warning ("Could not set data src");
  114. if (!gst_play_set_visualization (play, vis_element))
  115. g_warning ("Could not set visualisation");
  116. /* Setting location we want to play */
  117. if (!gst_play_set_location (play, argv[1]))
  118. g_warning ("Could not set location");
  119. /* Uncomment that line to get an XML dump of the pipeline */
  120. /* gst_xml_write_file (GST_ELEMENT (play), stdout); */
  121. g_signal_connect (G_OBJECT (play), "time_tick",
  122. G_CALLBACK (got_time_tick), NULL);
  123. g_signal_connect (G_OBJECT (play), "stream_length",
  124. G_CALLBACK (got_stream_length), NULL);
  125. g_signal_connect (G_OBJECT (play), "have_video_size",
  126. G_CALLBACK (got_video_size), NULL);
  127. g_signal_connect (G_OBJECT (play), "found_tag",
  128. G_CALLBACK (got_found_tag), NULL);
  129. g_signal_connect (G_OBJECT (play), "error",
  130. G_CALLBACK (gst_element_default_error), NULL);
  131. g_signal_connect (G_OBJECT (play), "eos", G_CALLBACK (got_eos), NULL);
  132. /* Change state to PLAYING */
  133. if (gst_element_set_state (GST_ELEMENT (play),
  134. GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
  135. g_error ("Could not set state to PLAYING");
  136. g_timeout_add (20000, (GSourceFunc) seek_timer, play);
  137. g_main_loop_run (loop);
  138. g_print ("setting pipeline to ready\n");
  139. gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
  140. /* unref
  141. gst_object_unref (GST_OBJECT (play)); */
  142. exit (0);
  143. }