Skip to content

Instantly share code, notes, and snippets.

@justinjoy
Created May 26, 2024 04:11
Show Gist options
  • Save justinjoy/7fff4f9954174a6166e633606ad4684a to your computer and use it in GitHub Desktop.
Save justinjoy/7fff4f9954174a6166e633606ad4684a to your computer and use it in GitHub Desktop.
basic-tutorial-1-cb.c
#include <gst/gst.h>
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
typedef struct CustomData {
GstElement *pipeline;
GMainLoop *main_loop;
} CustomData;
void
eos_cb (GstBus *bus, GstMessage *msg, CustomData *data)
{
g_main_loop_quit (data->main_loop);
}
int
tutorial_main (int argc, char *argv[])
{
CustomData data;
GstBus *bus;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Build the pipeline */
data.pipeline =
gst_parse_launch
("playbin uri=https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm",
NULL);
/* Start playing */
gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
/* Wait until error or EOS */
bus = gst_element_get_bus (data.pipeline);
gst_bus_add_signal_watch (bus);
g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb, &data);
data.main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (data.main_loop);
/* Free resources */
gst_object_unref (bus);
gst_element_set_state (data.pipeline, GST_STATE_NULL);
gst_object_unref (data.pipeline);
g_main_loop_unref (data.main_loop);
return 0;
}
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) tutorial_main, argc, argv, NULL);
#else
return tutorial_main (argc, argv);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment