<commit_before>#include <gst/gst.h>
#include "kms-core.h"

static GstElement *pipe = NULL;
G_LOCK_DEFINE_STATIC(mutex);
static gboolean init = FALSE;

static gpointer
gstreamer_thread(gpointer data) {
	GMainLoop *loop;
	loop = g_main_loop_new(NULL, TRUE);
	g_main_loop_run(loop);
	return NULL;
}

static void
bus_msg(GstBus *bus, GstMessage *msg, gpointer not_used) {
	switch (msg->type) {
	case GST_MESSAGE_ERROR: {
		GError *err = NULL;
		gchar *dbg_info = NULL;

		gst_message_parse_error (msg, &err, &dbg_info);
		g_warning("ERROR from element %s: %s\n",
						GST_OBJECT_NAME (msg->src),
						err->message);
		g_printerr("Debugging info: %s\n",
						(dbg_info) ? dbg_info : "none");
		g_error_free(err);
		g_free(dbg_info);
		break;
	}
	case GST_MESSAGE_EOS:
		g_warning("EOS message should not be received, "
						"pipeline can be stopped!");
		break;
	default:
		/* No action */
		break;
	}


}

void
kms_init(gint *argc, gchar **argv[]) {
	G_LOCK(mutex);
	if (!init) {
		GstBus *bus;

		g_type_init();
		gst_init(argc, argv);
		pipe = gst_pipeline_new(NULL);
		gst_element_set_state(pipe, GST_STATE_PLAYING);

		bus = gst_element_get_bus(pipe);
		gst_bus_add_watch(bus, gst_bus_async_signal_func, NULL);
		g_object_connect(bus, "signal::message", bus_msg, NULL, NULL);

		g_thread_create(gstreamer_thread, NULL, TRUE, NULL);

		init = TRUE;
	}
	G_UNLOCK(mutex);
}

GstElement*
kms_get_pipeline() {
	return pipe;
}

void
kms_dynamic_connection(GstElement *orig, GstElement *dest, gchar *pad_name) {
	/* TODO: implement this function*/
}<commit_msg>Implement link and unlink callbacks to dynamically link elements.<commit_after>#include <gst/gst.h>
#include "kms-core.h"

static GstElement *pipe = NULL;
G_LOCK_DEFINE_STATIC(mutex);
static gboolean init = FALSE;

static gpointer
gstreamer_thread(gpointer data) {
	GMainLoop *loop;
	loop = g_main_loop_new(NULL, TRUE);
	g_main_loop_run(loop);
	return NULL;
}

static void
bus_msg(GstBus *bus, GstMessage *msg, gpointer not_used) {
	switch (msg->type) {
	case GST_MESSAGE_ERROR: {
		GError *err = NULL;
		gchar *dbg_info = NULL;

		gst_message_parse_error (msg, &err, &dbg_info);
		g_warning("ERROR from element %s: %s\n",
						GST_OBJECT_NAME (msg->src),
						err->message);
		g_printerr("Debugging info: %s\n",
						(dbg_info) ? dbg_info : "none");
		g_error_free(err);
		g_free(dbg_info);
		break;
	}
	case GST_MESSAGE_EOS:
		g_warning("EOS message should not be received, "
						"pipeline can be stopped!");
		break;
	default:
		/* No action */
		break;
	}


}

void
kms_init(gint *argc, gchar **argv[]) {
	G_LOCK(mutex);
	if (!init) {
		GstBus *bus;

		g_type_init();
		gst_init(argc, argv);
		pipe = gst_pipeline_new(NULL);
		gst_element_set_state(pipe, GST_STATE_PLAYING);

		bus = gst_element_get_bus(pipe);
		gst_bus_add_watch(bus, gst_bus_async_signal_func, NULL);
		g_object_connect(bus, "signal::message", bus_msg, NULL, NULL);

		g_thread_create(gstreamer_thread, NULL, TRUE, NULL);

		init = TRUE;
	}
	G_UNLOCK(mutex);
}

GstElement*
kms_get_pipeline() {
	return pipe;
}

static void
linked(GstPad *pad, GstPad *peer, gpointer orig) {
	GstElement *dest;

	dest = gst_pad_get_parent_element(pad);
	gst_element_link(orig, dest);
	g_object_unref(dest);
}

static void
unlinked(GstPad *pad, gpointer orig) {
	GstElement *dest;
	GstPad *peer, *sink;

	dest = gst_pad_get_parent_element(pad);
	sink = gst_element_get_static_pad(dest, "sink");
	if (gst_pad_is_linked(sink)) {
		peer = gst_pad_get_peer(sink);
		if (peer != NULL) {
			gst_pad_unlink(peer, sink);
			g_object_unref(peer);
		}
	}
	g_object_unref(dest);
	g_object_unref(sink);
}

void
kms_dynamic_connection(GstElement *orig, GstElement *dest,
						const gchar *pad_name) {
	GstPad *pad;

	pad = gst_element_get_static_pad(dest, pad_name);

	g_object_connect(pad, "signal::linked", linked, orig, NULL);
	g_object_connect(pad, "signal::unlinked", unlinked, orig, NULL);
	g_object_unref(pad);
}
{'fraction_non_alphanumeric': 0.13171974522292992, 'fraction_numerical': 0.0, 'mean_word_length': 4.993893129770992, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3908347', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1597, 'n_words': 324}