Skip to content

Instantly share code, notes, and snippets.

@SanchayanMaity
Created May 22, 2026 07:46
Show Gist options
  • Select an option

  • Save SanchayanMaity/dda782194aae1887d2b430d714fa0042 to your computer and use it in GitHub Desktop.

Select an option

Save SanchayanMaity/dda782194aae1887d2b430d714fa0042 to your computer and use it in GitHub Desktop.
glib-openssl-test
#include <gst/gst.h>
#include <stdbool.h>
#include <glib.h>
typedef struct {
GMainLoop *loop;
int total_pipelines;
int completed_pipelines;
} AppState;
typedef struct {
int pipeline_id;
AppState *app_state;
} PipelineContext;
static gboolean bus_callback(GstBus *bus, GstMessage *msg, gpointer data) {
PipelineContext *ctx = (PipelineContext *)data;
AppState *state = ctx->app_state;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
g_print("Pipeline %d finished (End of Stream).\n", ctx->pipeline_id);
state->completed_pipelines++;
if (state->completed_pipelines == state->total_pipelines) {
g_print("All pipelines completed. Exiting...\n");
g_main_loop_quit(state->loop);
}
break;
case GST_MESSAGE_ERROR: {
GError *err;
gchar *debug_info;
gst_message_parse_error(msg, &err, &debug_info);
g_printerr("Error received from pipeline %d: %s\n", ctx->pipeline_id, err->message);
g_printerr("Debugging information: %s\n", debug_info ? debug_info : "none");
g_clear_error(&err);
g_free(debug_info);
g_main_loop_quit(state->loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc, char *argv[]) {
gst_init(&argc, &argv);
int num_pipelines = 3;
guint bus_watch_ids[num_pipelines];
GstElement *pipelines[num_pipelines];
PipelineContext contexts[num_pipelines];
AppState app_state;
app_state.total_pipelines = num_pipelines;
app_state.completed_pipelines = 0;
app_state.loop = g_main_loop_new(NULL, FALSE);
const char *pipeline_str =
"souphttpsrc location=https://people.freedesktop.org/~tpm/samples/763884-Avatar_3D_720p.mp4 ! "
"decodebin ! queue ! audioconvert ! fakesink";
for (int i = 0; i < num_pipelines; i++) {
GError *err = NULL;
pipelines[i] = gst_parse_launch(pipeline_str, &err);
if (err != NULL) {
g_printerr("Pipeline %d could not be constructed: %s\n", i, err->message);
g_clear_error(&err);
return -1;
}
contexts[i].pipeline_id = i;
contexts[i].app_state = &app_state;
GstBus *bus = gst_element_get_bus(pipelines[i]);
bus_watch_ids[i] = gst_bus_add_watch(bus, bus_callback, &contexts[i]);
gst_object_unref(bus);
g_print("Starting pipeline %d...\n", i);
gst_element_set_state(pipelines[i], GST_STATE_PLAYING);
}
g_print("Running main loop...\n");
g_main_loop_run(app_state.loop);
for (int i = 0; i < num_pipelines; i++) {
g_print("Cleaning up pipeline %d...\n", i);
gst_element_set_state(pipelines[i], GST_STATE_NULL);
g_source_remove(bus_watch_ids[i]);
gst_object_unref(pipelines[i]);
}
g_main_loop_unref(app_state.loop);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment