Posted By

felipec on 01/19/08


Tagged

gstreamer multimedia


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jeffhung


GStreamer hello world


 / Published in: C
 

URL: http://felipec.wordpress.com/2008/01/19/gstreamer-hello-world/

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

Report this snippet  

You need to login to post a comment.