Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Centricular Ltd
Nirbheek Chauhan
(nirbheek on IRC)
GNOME contributor since 2007
http://nirbheek.in
nirbheek@centricular.co...
Centricular Ltd
An introduction to using GStreamer
in your GNOME application
Centricular Ltd
What is GStreamer?
Centricular Ltd
GStreamer 1.0
GStreamer 0.10
Centricular Ltd
How does it work?
Centricular Ltd
filter2
sink src
filter1
sink src
bin
sink
sink
source
src
Centricular Ltd
pipeline
mp3 decoder
sink src
audio sink
sink
file source
src
Centricular Ltd
How do you use it?
Centricular Ltd
gst-launch-1.0
Centricular Ltd
$ gst-launch-1.0 
filesrc location=audio.mp3 ! 
mad ! 
pulsesink
Centricular Ltd
GstElement *pipeline;
GstElement *src, *decoder, *sink;
gst_init (&argc, &argv);
src = gst_element_factory...
Centricular Ltd
Element States
Centricular Ltd
Element States
NULL READY PAUSED PLAYING→ → →
Centricular Ltd
Element States
PLAYING PAUSED PLAYING→ →
Centricular Ltd
Element States
PLAYING [...] NULL→ →
Centricular Ltd
Video files?
Centricular Ltd
“Sometimes” pads.
Centricular Ltd
pipeline
URI Decoder queue
sink src
audio sink
sinksrc_0
queue
sink src
video sink
sinksrc_1
Centricular Ltd
$ gst-launch-1.0 
uridecodebin name=d 
uri=file://.../video.mp4 
d. ! queue ! pulsesink 
d. ! queue ! xvim...
Centricular Ltd
GstElement *pipeline, *d;
gst_init (&argc, &argv);
d = gst_element_factory_make ("uridecodebin", NULL);
g_...
Centricular Ltd
static void
pad_added_cb (GstElement * d, GstPad * newsrcpad,
GstElement * pipeline)
{
GstCaps *caps;
GstS...
Centricular Ltd
What the hell are “caps”?!
Centricular Ltd
static void
pad_added_cb (GstElement * d, GstPad * newsrcpad,
GstElement * pipeline)
{
GstCaps *caps;
GstS...
Centricular Ltd
static void
pipeline_add_audio_sink (GstElement * pipeline,
GstPad * srcpad)
{
GstElement *q, *sink;
GstPa...
Centricular Ltd
static void
pipeline_add_video_sink (GstElement * pipeline,
GstPad * srcpad)
{
GstElement *q, *sink;
GstPa...
Centricular Ltd
Seems like a lot of work for something so common
☹
Centricular Ltd
playbin
Centricular Ltd
$ gst-launch-1.0 playbin uri=file://.../video.mp4
$ gst-launch-1.0 playbin uri=http://.../audio.mp3
Centricular Ltd
GstElement *playbin;
gst_init (&argc, &argv);
playbin = gst_element_factory_make ("playbin", NULL);
g_obje...
Centricular Ltd
One more thing.
Centricular Ltd
Static Pads & Request Pads
Centricular Ltd
$ gst-launch-1.0 
qtmux name=m ! filesink location=file.mp4 
pulsesrc ! queue ! faac ! m. 
v4l2src ! queue...
Centricular Ltd
/* Insert similar code as earlier slides */
srcpad = gst_element_get_static_pad (faac, "src");
audio_pad =...
Centricular Ltd
I lied. There’s a lot more.
GStreamer is quite versatile!
Centricular Ltd
Events, Queries, Messages
Action Signals, Pad Probes, Threading
Mainloop integration, Platform-specific qu...
Centricular Ltd
The rest is left as an exercise for the reader.
☺
Centricular Ltd
Too much?
Centricular Ltd
$ gst-play-1.0 file://.../video.mp4
Centricular Ltd
$ gst-launch-1.0 playbin uri=file://.../video.mp4
Centricular Ltd
GstElement *playbin;
gst_init (&argc, &argv);
playbin = gst_element_factory_make ("playbin", NULL);
g_obje...
Centricular Ltd
Questions?
Upcoming SlideShare
Loading in …5
×

An introduction to using GStreamer in your GNOME application

621 views

Published on

Presentation given by me at GNOME Asia 2015. Uploading here as requested by the conference organisers.

  • Be the first to comment

  • Be the first to like this

An introduction to using GStreamer in your GNOME application

  1. 1. Centricular Ltd Nirbheek Chauhan (nirbheek on IRC) GNOME contributor since 2007 http://nirbheek.in nirbheek@centricular.com nirbheek.chauhan@gmail.com
  2. 2. Centricular Ltd An introduction to using GStreamer in your GNOME application
  3. 3. Centricular Ltd What is GStreamer?
  4. 4. Centricular Ltd GStreamer 1.0 GStreamer 0.10
  5. 5. Centricular Ltd How does it work?
  6. 6. Centricular Ltd filter2 sink src filter1 sink src bin sink sink source src
  7. 7. Centricular Ltd pipeline mp3 decoder sink src audio sink sink file source src
  8. 8. Centricular Ltd How do you use it?
  9. 9. Centricular Ltd gst-launch-1.0
  10. 10. Centricular Ltd $ gst-launch-1.0 filesrc location=audio.mp3 ! mad ! pulsesink
  11. 11. Centricular Ltd GstElement *pipeline; GstElement *src, *decoder, *sink; gst_init (&argc, &argv); src = gst_element_factory_make ("filesrc", NULL); decoder = gst_element_factory_make ("mad", NULL); sink = gst_element_factory_make ("pulsesink", NULL); g_object_set (src, "location", "audio.mp3", NULL); pipeline = gst_pipeline_new (); gst_bin_add_many (GST_BIN (pipeline), src, decoder, sink, NULL); gst_element_link_many (src, decoder, sink, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); do {} while (1); /* Wait forever */
  12. 12. Centricular Ltd Element States
  13. 13. Centricular Ltd Element States NULL READY PAUSED PLAYING→ → →
  14. 14. Centricular Ltd Element States PLAYING PAUSED PLAYING→ →
  15. 15. Centricular Ltd Element States PLAYING [...] NULL→ →
  16. 16. Centricular Ltd Video files?
  17. 17. Centricular Ltd “Sometimes” pads.
  18. 18. Centricular Ltd pipeline URI Decoder queue sink src audio sink sinksrc_0 queue sink src video sink sinksrc_1
  19. 19. Centricular Ltd $ gst-launch-1.0 uridecodebin name=d uri=file://.../video.mp4 d. ! queue ! pulsesink d. ! queue ! xvimagesink
  20. 20. Centricular Ltd GstElement *pipeline, *d; gst_init (&argc, &argv); d = gst_element_factory_make ("uridecodebin", NULL); g_object_set (d, "uri", "file://.../video.mp4", NULL); pipeline = gst_pipeline_new (); gst_bin_add (GST_BIN (pipeline), d); g_signal_connect (d, "pad-added", pad_added_cb, pipeline); gst_element_set_state (pipeline, GST_STATE_PLAYING); do {} while (1); /* Wait forever */
  21. 21. Centricular Ltd static void pad_added_cb (GstElement * d, GstPad * newsrcpad, GstElement * pipeline) { GstCaps *caps; GstStructure *s; caps = gst_pad_get_current_caps (newsrcpad); s = gst_caps_get_structure (caps, 0); if (gst_structure_has_name (s, "audio/x-raw")) pipeline_add_audio_sink (pipeline, newsrcpad); else if (gst_structure_has_name (s, "video/x-raw")) pipeline_add_video_sink (pipeline, newsrcpad); gst_caps_unref (caps); /* ignore other types of pads */ }
  22. 22. Centricular Ltd What the hell are “caps”?!
  23. 23. Centricular Ltd static void pad_added_cb (GstElement * d, GstPad * newsrcpad, GstElement * pipeline) { GstCaps *caps; GstStructure *s; caps = gst_pad_get_current_caps (newsrcpad); s = gst_caps_get_structure (caps, 0); if (gst_structure_has_name (s, "audio/x-raw")) pipeline_add_audio_sink (pipeline, newsrcpad); else if (gst_structure_has_name (s, "video/x-raw")) pipeline_add_video_sink (pipeline, newsrcpad); gst_caps_unref (caps); /* ignore other types of pads */ }
  24. 24. Centricular Ltd static void pipeline_add_audio_sink (GstElement * pipeline, GstPad * srcpad) { GstElement *q, *sink; GstPad *sinkpad; q = gst_element_factory_make ("queue", NULL); sink = gst_element_factory_make ("pulsesink", NULL); gst_bin_add_many (GST_BIN (pipeline), q, sink, NULL); sinkpad = gst_element_get_static_pad (q, "sink"); gst_pad_link (srcpad, sinkpad) gst_element_link (q, sink); gst_element_sync_state_with_parent (q); gst_element_sync_state_with_parent (sink); gst_object_unref (sinkpad); }
  25. 25. Centricular Ltd static void pipeline_add_video_sink (GstElement * pipeline, GstPad * srcpad) { GstElement *q, *sink; GstPad *sinkpad; q = gst_element_factory_make ("queue", NULL); sink = gst_element_factory_make ("xvimagesink", NULL); gst_bin_add_many (GST_BIN (pipeline), q, sink, NULL); sinkpad = gst_element_get_static_pad (q, "sink"); gst_pad_link (srcpad, sinkpad) gst_element_link (q, sink); gst_element_sync_state_with_parent (q); gst_element_sync_state_with_parent (sink); gst_object_unref (sinkpad); }
  26. 26. Centricular Ltd Seems like a lot of work for something so common ☹
  27. 27. Centricular Ltd playbin
  28. 28. Centricular Ltd $ gst-launch-1.0 playbin uri=file://.../video.mp4 $ gst-launch-1.0 playbin uri=http://.../audio.mp3
  29. 29. Centricular Ltd GstElement *playbin; gst_init (&argc, &argv); playbin = gst_element_factory_make ("playbin", NULL); g_object_set (p, "uri", "file://.../video.mp4", NULL); gst_element_set_state (playbin, GST_STATE_PLAYING); do {} while (1); /* Wait forever */
  30. 30. Centricular Ltd One more thing.
  31. 31. Centricular Ltd Static Pads & Request Pads
  32. 32. Centricular Ltd $ gst-launch-1.0 qtmux name=m ! filesink location=file.mp4 pulsesrc ! queue ! faac ! m. v4l2src ! queue ! x264enc ! m.
  33. 33. Centricular Ltd /* Insert similar code as earlier slides */ srcpad = gst_element_get_static_pad (faac, "src"); audio_pad = gst_element_get_request_pad (qtmux, "audio_%d"); gst_pad_link (srcpad, audio_pad); srcpad = gst_element_get_static_pad (x264enc, "src"); video_pad = gst_element_get_request_pad (qtmux, "video_%d"); gst_pad_link (srcpad, video_pad); gst_element_set_state (pipeline, GST_STATE_PLAYING); do {} while (1); /* Wait forever */
  34. 34. Centricular Ltd I lied. There’s a lot more. GStreamer is quite versatile!
  35. 35. Centricular Ltd Events, Queries, Messages Action Signals, Pad Probes, Threading Mainloop integration, Platform-specific quirks ... 45 min is only enough for a taste.
  36. 36. Centricular Ltd The rest is left as an exercise for the reader. ☺
  37. 37. Centricular Ltd Too much?
  38. 38. Centricular Ltd $ gst-play-1.0 file://.../video.mp4
  39. 39. Centricular Ltd $ gst-launch-1.0 playbin uri=file://.../video.mp4
  40. 40. Centricular Ltd GstElement *playbin; gst_init (&argc, &argv); playbin = gst_element_factory_make ("playbin", NULL); g_object_set (p, "uri", "file://.../video.mp4", NULL); gst_element_set_state (playbin, GST_STATE_PLAYING); do {} while (1); /* Wait forever */
  41. 41. Centricular Ltd Questions?

×