Skip to content

Instantly share code, notes, and snippets.

@yashi
Last active December 9, 2015 13:51
Show Gist options
  • Save yashi/05299ff10bb892f77018 to your computer and use it in GitHub Desktop.
Save yashi/05299ff10bb892f77018 to your computer and use it in GitHub Desktop.
#include <gst/gst.h>
gboolean on_message(GstBus *bus, GstMessage *message, gpointer p)
{
GMainLoop *mainloop = p;
(void)bus;
if ((GST_MESSAGE_TYPE(message) & GST_MESSAGE_EOS)) {
g_print("message: eos\n");
g_main_loop_quit(mainloop);
}
return TRUE;
}
GstPadProbeReturn on_probe(GstPad *pad, GstPadProbeInfo *info, gpointer unused)
{
GstEvent *event;
(void)pad;
(void)unused;
event = gst_pad_probe_info_get_event(info);
g_print("event: %s\n", GST_EVENT_TYPE_NAME(event));
return GST_PAD_PROBE_OK;
}
int main(int argc, char *argv[])
{
GMainLoop *mainloop;
GstElement *pipeline;
GError *error = NULL;
GstBus *bus;
GstElement *src;
GstElement *sink;
GstPad *pad1;
GstPad *pad2;
gst_init(&argc, &argv);
mainloop = g_main_loop_new(NULL, FALSE);
pipeline = gst_parse_launch("filesrc location=a.txt ! fdsink", &error);
bus = gst_element_get_bus(pipeline);
gst_bus_add_watch(bus, on_message, mainloop);
src = gst_bin_get_by_name(GST_BIN(pipeline), "filesrc0");
pad1 = gst_element_get_static_pad(src, "src");
pad2 = gst_pad_get_peer(pad1);
sink = gst_pad_get_parent_element(pad2);
g_print("name: %s\n", gst_element_get_name(sink));
gst_pad_add_probe(pad1, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, on_probe, NULL, NULL);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_main_loop_run(mainloop);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment