We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

felipec on 01/19/08


Tagged

multimedia gstreamer


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

jeffhung


GStreamer hello world


Published in: C++ 


  1. #include <gst/gst.h>
  2. #include <stdbool.h>
  3.  
  4. static GMainLoop *loop;
  5.  
  6. static gboolean
  7. bus_call (GstBus *bus,
  8. GstMessage *msg,
  9. gpointer user_data)
  10. {
  11. switch (GST_MESSAGE_TYPE (msg))
  12. {
  13. case GST_MESSAGE_EOS:
  14. {
  15. g_message ("End-of-stream");
  16. g_main_loop_quit (loop);
  17. break;
  18. }
  19. case GST_MESSAGE_ERROR:
  20. {
  21. gchar *debug;
  22. GError *err;
  23.  
  24. gst_message_parse_error (msg, &err, &debug);
  25. g_free (debug);
  26.  
  27. g_error ("%s", err->message);
  28. g_error_free (err);
  29.  
  30. g_main_loop_quit (loop);
  31. break;
  32. }
  33. default:
  34. break;
  35. }
  36.  
  37. return true;
  38. }
  39.  
  40. void
  41. play_uri (gchar *uri)
  42. {
  43. GstElement *pipeline;
  44.  
  45. loop = g_main_loop_new (NULL, FALSE);
  46.  
  47. pipeline = gst_element_factory_make ("playbin", "player");
  48.  
  49. if (uri)
  50. {
  51. g_object_set (G_OBJECT (pipeline), "uri", uri, NULL);
  52. }
  53.  
  54. {
  55. GstBus *bus;
  56.  
  57. bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  58. gst_bus_add_watch (bus, bus_call, NULL);
  59. gst_object_unref (bus);
  60. }
  61.  
  62. gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
  63.  
  64. g_main_loop_run (loop);
  65.  
  66. gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
  67. gst_object_unref (GST_OBJECT (pipeline));
  68. }
  69.  
  70. int
  71. main (int argc,
  72. char *argv[])
  73. {
  74. gst_init (&argc, &argv);
  75.  
  76. play_uri (argv[1]);
  77.  
  78. return 0;
  79. }

Report this snippet 

You need to login to post a comment.