diff --git a/Makefile.am b/Makefile.am index 0206d810..7f976826 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,10 @@ ACLOCAL_AMFLAGS=-I m4 -I . -SUBDIRS=gstd \ +SUBDIRS= \ + libgstd \ gst_client \ libgstc \ + gstd \ tests \ examples \ docs \ diff --git a/configure.ac b/configure.ac index 20af0ea3..64b70611 100644 --- a/configure.ac +++ b/configure.ac @@ -297,6 +297,7 @@ libgstc/Makefile libgstc/c/Makefile libgstc/javascript/Makefile libgstc/python/Makefile +libgstd/Makefile examples/Makefile examples/libgstc/Makefile tests/Makefile diff --git a/gstd/Makefile.am b/gstd/Makefile.am index 5a90e282..61b7637e 100644 --- a/gstd/Makefile.am +++ b/gstd/Makefile.am @@ -1,141 +1,20 @@ -# Core library if user wants to use as code base for its own application -lib_LTLIBRARIES = libgstd-core.la - -libgstd_core_la_SOURCES = gstd_session.c \ - gstd_object.c \ - gstd_pipeline.c \ - gstd_element.c \ - gstd_list.c \ - gstd_ipc.c \ - gstd_tcp.c \ - gstd_http.c \ - gstd_icreator.c \ - gstd_iformatter.c \ - gstd_pipeline_creator.c \ - gstd_no_creator.c \ - gstd_json_builder.c \ - gstd_ideleter.c \ - gstd_pipeline_deleter.c \ - gstd_no_deleter.c \ - gstd_debug.c \ - gstd_event_creator.c \ - gstd_event_factory.c \ - gstd_pipeline_bus.c \ - gstd_ireader.c \ - gstd_property_reader.c \ - gstd_no_reader.c \ - gstd_list_reader.c \ - gstd_property.c \ - gstd_property_int.c \ - gstd_property_string.c \ - gstd_property_boolean.c \ - gstd_property_array.c \ - gstd_iupdater.c \ - gstd_no_updater.c \ - gstd_property_enum.c \ - gstd_property_flags.c \ - gstd_event_handler.c \ - gstd_bus_msg.c \ - gstd_bus_msg_simple.c \ - gstd_bus_msg_notify.c \ - gstd_bus_msg_state_changed.c \ - gstd_msg_reader.c \ - gstd_msg_type.c \ - gstd_bus_msg_qos.c \ - gstd_return_codes.c \ - gstd_state.c \ - gstd_parser.c \ - gstd_log.c \ - gstd_bus_msg_stream_status.c \ - gstd_bus_msg_element.c \ - gstd_signal.c \ - gstd_callback.c \ - gstd_signal_reader.c \ - gstd_socket.c \ - gstd_unix.c \ - gstd_signal_list.c - -libgstd_core_la_CFLAGS = $(GST_CFLAGS) \ - $(GIO_CFLAGS) \ - $(GIO_UNIX_CFLAGS) \ - $(LIBSOUP_CFLAGS) \ - $(GJSON_CFLAGS) \ - -DGSTD_LOG_STATE_DIR=\"$(GSTD_LOG_STATE_DIR)\" \ - -DGSTD_RUN_STATE_DIR=\"$(GSTD_RUN_STATE_DIR)\" - -libgstd_core_la_LDFLAGS = $(GST_LIBS) $(GIO_LIBS) $(GJSON_LIBS) $(LIBSOUP_LIBS) - -# Standalone application that uses libgstd-core +# Standalone application bin_PROGRAMS = gstd gstd_SOURCES = gstd.c gstd_daemon.c -gstd_CFLAGS = $(GST_CFLAGS) \ - $(GIO_CFLAGS) \ - $(LIBSOUP_CFLAGS) \ - $(GIO_UNIX_CFLAGS) \ - $(GJSON_CFLAGS) \ - $(LIBD_CFLAGS) \ - -DGSTD_LOG_STATE_DIR=\"$(GSTD_LOG_STATE_DIR)\" \ +gstd_CFLAGS = \ + $(GST_CFLAGS) \ + -I$(top_srcdir)/libgstd/ \ + $(LIBD_CFLAGS) \ + -DGSTD_LOG_STATE_DIR=\"$(GSTD_LOG_STATE_DIR)\" \ -DGSTD_RUN_STATE_DIR=\"$(GSTD_RUN_STATE_DIR)\" -gstd_LDFLAGS = $(GST_LIBS) \ - $(GIO_LIBS) \ - $(GIO_UNIX_LIBS) \ - $(GJSON_LIBS) \ - $(LIBD_LIBS) \ - $(LIBSOUP_LIBS) \ +gstd_LDFLAGS = $(GST_LIBS) \ + $(LIBD_LIBS) \ -Wl,-rpath -Wl,$(libdir) -gstd_LDADD = libgstd-core.la - -gstdincludedir = $(includedir)/gstd -gstdinclude_HEADERS = \ - gstd_session.h \ - gstd_object.h \ - gstd_return_codes.h \ - gstd_pipeline.h \ - gstd_element.h \ - gstd_list.h \ - gstd_ipc.h \ - gstd_tcp.h \ - gstd_http.h \ - gstd_icreator.h \ - gstd_iformatter.h \ - gstd_pipeline_creator.h \ - gstd_json_builder.h \ - gstd_no_creator.h \ - gstd_ideleter.h \ - gstd_pipeline_deleter.h \ - gstd_no_deleter.h \ - gstd_ireader.h \ - gstd_property_reader.h \ - gstd_no_reader.h \ - gstd_list_reader.h \ - gstd_property.h \ - gstd_property_int.h \ - gstd_property_string.h \ - gstd_property_boolean.h \ - gstd_property_array.h \ - gstd_iupdater.h \ - gstd_no_updater.h \ - gstd_property_enum.h \ - gstd_property_flags.h \ - gstd_event_handler.h \ - gstd_event_creator.h \ - gstd_bus_msg.h \ - gstd_bus_msg_simple.h \ - gstd_bus_msg_notify.h \ - gstd_bus_msg_state_changed.h \ - gstd_msg_reader.h \ - gstd_msg_type.h \ - gstd_bus_msg_qos.h \ - gstd_state.h \ - gstd_parser.h \ - gstd_log.h \ - gstd_bus_msg_stream_status.h \ - gstd_bus_msg_element.h \ - gstd_signal_list.h +gstd_LDADD = $(top_builddir)/libgstd/libgstd-1.0.la noinst_HEADERS = gstd_daemon.h diff --git a/gstd/gstd.c b/gstd/gstd.c index 98ad0d00..27b7c126 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -1,6 +1,6 @@ /* * GStreamer Daemon - Gst Launch under steroids - * Copyright (c) 2015-2017 Ridgerun, LLC (http://www.ridgerun.com) + * Copyright (c) 2015-2021 Ridgerun, LLC (http://www.ridgerun.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,28 +22,18 @@ #endif #include -#include -#include - -#include "gstd_session.h" -#include "gstd_ipc.h" -#include "gstd_tcp.h" -#include "gstd_unix.h" -#include "gstd_http.h" + #include "gstd_daemon.h" #include "gstd_log.h" -static gboolean int_term_handler (gpointer user_data); -static void ipc_add_option_groups (GstdIpc * ipc[], GType factory[], - guint num_ipcs, GOptionContext * context, GOptionGroup * groups[]); -static gboolean ipc_start (GstdIpc * ipc[], guint num_ipcs, - GstdSession * session); -static void ipc_stop (GstdIpc * ipc[], guint numipc); -static void print_header (); +#include "libgstd.h" #define HEADER \ - "\nGstd version " PACKAGE_VERSION "\n" \ - "Copyright (C) 2015-2020 RidgeRun (https://www.ridgerun.com)\n\n" + "\nGstD version " PACKAGE_VERSION "\n" \ + "Copyright (C) 2015-2021 RidgeRun (https://www.ridgerun.com)\n\n" + +static gboolean int_term_handler (gpointer user_data); +static void print_header (); static void print_header (void) @@ -63,86 +53,16 @@ int_term_handler (gpointer user_data) /* User has pressed CTRL-C, stop the main loop so the application closes itself */ GST_INFO ("Interrupt received, shutting down..."); + g_print ("\n"); g_main_loop_quit (main_loop); return TRUE; } -static void -ipc_add_option_groups (GstdIpc * ipc[], GType factory[], guint num_ipcs, - GOptionContext * context, GOptionGroup * groups[]) -{ - gint i; - - g_return_if_fail (ipc); - g_return_if_fail (context); - g_return_if_fail (groups); - - for (i = 0; i < num_ipcs; i++) { - ipc[i] = GSTD_IPC (g_object_new (factory[i], NULL)); - gstd_ipc_get_option_group (ipc[i], &groups[i]); - g_option_context_add_group (context, groups[i]); - } -} - -static gboolean -ipc_start (GstdIpc * ipc[], guint num_ipcs, GstdSession * session) -{ - gboolean ipc_selected = FALSE; - gboolean ret = TRUE; - GstdReturnCode code; - gint i; - - g_return_val_if_fail (ipc, FALSE); - g_return_val_if_fail (session, FALSE); - - /* Verify if at leas one IPC mechanism was selected */ - for (i = 0; i < num_ipcs; i++) { - g_object_get (G_OBJECT (ipc[i]), "enabled", &ipc_selected, NULL); - - if (ipc_selected) { - break; - } - } - - /* If no IPC was selected, default to TCP */ - if (!ipc_selected) { - g_object_set (G_OBJECT (ipc[0]), "enabled", TRUE, NULL); - } - - /* Run start for each IPC (each start method checks for the enabled flag) */ - for (i = 0; i < num_ipcs; i++) { - code = gstd_ipc_start (ipc[i], session); - if (code) { - g_printerr ("Couldn't start IPC : (%s)\n", G_OBJECT_TYPE_NAME (ipc[i])); - ret = FALSE; - } - } - - return ret; -} - -static void -ipc_stop (GstdIpc * ipc[], guint num_ipcs) -{ - gint i; - - g_return_if_fail (ipc); - - /* Run stop for each IPC */ - for (i = 0; i < num_ipcs; i++) { - if (TRUE == ipc[i]->enabled) { - gstd_ipc_stop (ipc[i]); - g_object_unref (ipc[i]); - } - } -} - gint main (gint argc, gchar * argv[]) { GMainLoop *main_loop; - GstdSession *session; gboolean version = FALSE; gboolean kill = FALSE; gboolean daemon = FALSE; @@ -151,24 +71,13 @@ main (gint argc, gchar * argv[]) const gchar *gstlogfile = NULL; gchar *pidfile = NULL; GError *error = NULL; - GOptionContext *context; - GOptionGroup *gstreamer_group; + GOptionContext *context = NULL; gint ret = EXIT_SUCCESS; gchar *current_filename = NULL; + gchar *filename = NULL; + gboolean parent = FALSE; - /* Array to specify gstd how many IPCs are supported, - * IPCs should be added this array. - */ - GType supported_ipcs[] = { - GSTD_TYPE_TCP, - GSTD_TYPE_UNIX, - GSTD_TYPE_HTTP, - }; - - guint num_ipcs = (sizeof (supported_ipcs) / sizeof (GType)); - GstdIpc **ipc_array = g_malloc (num_ipcs * sizeof (GstdIpc *)); - GOptionGroup **optiongroup_array = - g_malloc (num_ipcs * sizeof (GOptionGroup *)); + GstDManager *manager = NULL; GOptionEntry entries[] = { {"version", 'v', 0, G_OPTION_ARG_NONE, &version, @@ -200,12 +109,8 @@ main (gint argc, gchar * argv[]) g_option_context_add_main_entries (context, entries, NULL); /* Initialize GStreamer */ - gstreamer_group = gst_init_get_option_group (); - g_option_context_add_group (context, gstreamer_group); - - /* Read option group for each IPC */ - ipc_add_option_groups (ipc_array, supported_ipcs, num_ipcs, context, - optiongroup_array); + gstd_manager_new (&manager, 0, NULL); + gstd_context_add_group (manager, context); /* Parse the options before starting */ if (!g_option_context_parse (context, &argc, &argv, &error)) { @@ -245,8 +150,6 @@ main (gint argc, gchar * argv[]) } if (daemon) { - gboolean parent; - if (!gstd_daemon_start (&parent)) { goto error; } @@ -254,7 +157,6 @@ main (gint argc, gchar * argv[]) /* Parent fork ends here */ if (parent) { if (!quiet) { - gchar *filename; filename = gstd_log_get_current_gstd (); g_print ("Log traces will be saved to %s.\n", filename); g_print ("Detaching from parent process.\n"); @@ -264,11 +166,8 @@ main (gint argc, gchar * argv[]) } } - /*Create session */ - session = gstd_session_new ("Session0"); - /* Start IPC subsystem */ - if (!ipc_start (ipc_array, num_ipcs, session)) { + if (!gstd_manager_start (manager)) { goto error; } @@ -290,17 +189,10 @@ main (gint argc, gchar * argv[]) main_loop = NULL; /* Stop any IPC array */ - ipc_stop (ipc_array, num_ipcs); + gstd_manager_stop (manager); - /* Free Gstd session */ - g_object_unref (session); - - gst_deinit (); gstd_log_deinit (); - g_free (ipc_array); - g_free (optiongroup_array); - goto out; error: @@ -314,6 +206,8 @@ main (gint argc, gchar * argv[]) } out: { + gst_deinit (); + gstd_manager_free (manager); return ret; } } diff --git a/gstd/meson.build b/gstd/meson.build index b81a6866..68f6313d 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -1,142 +1,21 @@ gstd_name = 'gstd' + # Application source files gstd_src_files = [ 'gstd_daemon.c', 'gstd.c' ] -# Library source files -libgstd_src_files = [ - 'gstd_object.c', - 'gstd_pipeline.c', - 'gstd_element.c', - 'gstd_list.c', - 'gstd_ipc.c', - 'gstd_tcp.c', - 'gstd_http.c', - 'gstd_icreator.c', - 'gstd_iformatter.c', - 'gstd_pipeline_creator.c', - 'gstd_no_creator.c', - 'gstd_json_builder.c', - 'gstd_ideleter.c', - 'gstd_pipeline_deleter.c', - 'gstd_no_deleter.c', - 'gstd_debug.c', - 'gstd_event_creator.c', - 'gstd_event_factory.c', - 'gstd_pipeline_bus.c', - 'gstd_ireader.c', - 'gstd_property_reader.c', - 'gstd_no_reader.c', - 'gstd_list_reader.c', - 'gstd_property.c', - 'gstd_property_int.c', - 'gstd_property_string.c', - 'gstd_property_boolean.c', - 'gstd_property_array.c', - 'gstd_iupdater.c', - 'gstd_no_updater.c', - 'gstd_property_enum.c', - 'gstd_property_flags.c', - 'gstd_event_handler.c', - 'gstd_bus_msg.c', - 'gstd_bus_msg_simple.c', - 'gstd_bus_msg_notify.c', - 'gstd_bus_msg_state_changed.c', - 'gstd_msg_reader.c', - 'gstd_msg_type.c', - 'gstd_bus_msg_qos.c', - 'gstd_return_codes.c', - 'gstd_state.c', - 'gstd_parser.c', - 'gstd_log.c', - 'gstd_bus_msg_stream_status.c', - 'gstd_bus_msg_element.c', - 'gstd_signal.c', - 'gstd_signal_list.c', - 'gstd_callback.c', - 'gstd_signal_reader.c', - 'gstd_session.c', - 'gstd_socket.c', - 'gstd_unix.c' -] -libgstd_header_files = [ - 'gstd_bus_msg_element.h', - 'gstd_bus_msg.h', - 'gstd_bus_msg_simple.h', - 'gstd_bus_msg_notify.h', - 'gstd_bus_msg_qos.h', - 'gstd_bus_msg_state_changed.h', - 'gstd_bus_msg_stream_status.h', - 'gstd_callback.h', - 'gstd_daemon.h', - 'gstd_debug.h', - 'gstd_element.h', - 'gstd_event_creator.h', - 'gstd_event_factory.h', - 'gstd_event_handler.h', - 'gstd_icreator.h', - 'gstd_ideleter.h', - 'gstd_iformatter.h', - 'gstd_ipc.h', - 'gstd_ireader.h', - 'gstd_iupdater.h', - 'gstd_json_builder.h', - 'gstd_list.h', - 'gstd_list_reader.h', - 'gstd_log.h', - 'gstd_msg_reader.h', - 'gstd_msg_type.h', - 'gstd_no_creator.h', - 'gstd_no_deleter.h', - 'gstd_no_reader.h', - 'gstd_no_updater.h', - 'gstd_object.h', - 'gstd_parser.h', - 'gstd_pipeline_bus.h', - 'gstd_pipeline_creator.h', - 'gstd_pipeline_deleter.h', - 'gstd_pipeline.h', - 'gstd_property_array.h', - 'gstd_property_boolean.h', - 'gstd_property_enum.h', - 'gstd_property_flags.h', - 'gstd_property.h', - 'gstd_property_int.h', - 'gstd_property_reader.h', - 'gstd_property_string.h', - 'gstd_return_codes.h', - 'gstd_session.h', - 'gstd_signal.h', - 'gstd_signal_reader.h', - 'gstd_state.h', - 'gstd_tcp.h', - 'gstd_socket.h', - 'gstd_unix.h' +libgstd_src_files = [ + '../libgstd/libgstd.c' ] -# Create a static library used to create gstd daemon and also is used for tests -gstd_lib = both_libraries('gstd-core', - libgstd_src_files, - c_args : gst_c_args, - version : gstd_version, - include_directories : configinc, - dependencies : [gstd_deps], - install : true, - install_dir : lib_install_dir, -) - -# Define the library as an internal dependency to the current build -lib_gstd_dep = declare_dependency(link_with: gstd_lib, - dependencies : [gstd_deps]) - # Create gstd application exe_name = '@0@-@1@'.format(gstd_name, apiversion) executable(exe_name, - gstd_src_files, + [gstd_src_files, libgstd_src_files], install: true, - include_directories : [configinc], + include_directories : [configinc, libgstd_inc_dir], dependencies : [gstd_deps, lib_gstd_dep], c_args: gst_c_args, ) diff --git a/libgstd/Makefile.am b/libgstd/Makefile.am new file mode 100644 index 00000000..15f0b3cc --- /dev/null +++ b/libgstd/Makefile.am @@ -0,0 +1,73 @@ +lib_LTLIBRARIES = libgstd-@GSTD_API_VERSION@.la + +gstdincludedir = $(includedir)/libgstd +gstdinclude_HEADERS = libgstd.h + +libgstd_@GSTD_API_VERSION@_la_SOURCES = \ + libgstd.c \ + gstd_session.c \ + gstd_object.c \ + gstd_pipeline.c \ + gstd_element.c \ + gstd_list.c \ + gstd_ipc.c \ + gstd_tcp.c \ + gstd_http.c \ + gstd_icreator.c \ + gstd_iformatter.c \ + gstd_pipeline_creator.c \ + gstd_no_creator.c \ + gstd_json_builder.c \ + gstd_ideleter.c \ + gstd_pipeline_deleter.c \ + gstd_no_deleter.c \ + gstd_debug.c \ + gstd_event_creator.c \ + gstd_event_factory.c \ + gstd_pipeline_bus.c \ + gstd_ireader.c \ + gstd_property_reader.c \ + gstd_no_reader.c \ + gstd_list_reader.c \ + gstd_property.c \ + gstd_property_int.c \ + gstd_property_string.c \ + gstd_property_boolean.c \ + gstd_property_array.c \ + gstd_iupdater.c \ + gstd_no_updater.c \ + gstd_property_enum.c \ + gstd_property_flags.c \ + gstd_event_handler.c \ + gstd_bus_msg.c \ + gstd_bus_msg_simple.c \ + gstd_bus_msg_notify.c \ + gstd_bus_msg_state_changed.c \ + gstd_msg_reader.c \ + gstd_msg_type.c \ + gstd_bus_msg_qos.c \ + gstd_return_codes.c \ + gstd_state.c \ + gstd_parser.c \ + gstd_bus_msg_stream_status.c \ + gstd_bus_msg_element.c \ + gstd_signal.c \ + gstd_callback.c \ + gstd_signal_reader.c \ + gstd_socket.c \ + gstd_unix.c \ + gstd_signal_list.c \ + ../gstd/gstd_log.c + +libgstd_@GSTD_API_VERSION@_la_CFLAGS = \ + $(GST_CFLAGS) \ + -I$(top_srcdir)/gstd/ \ + $(GIO_CFLAGS) \ + $(GIO_UNIX_CFLAGS) \ + $(LIBSOUP_CFLAGS) \ + $(GJSON_CFLAGS) \ + -DGSTD_LOG_STATE_DIR=\"$(GSTD_LOG_STATE_DIR)\" \ + -DGSTD_RUN_STATE_DIR=\"$(GSTD_RUN_STATE_DIR)\" \ + $(JANSSON_CFLAGS) -pthread + +libgstd_@GSTD_API_VERSION@_la_LDFLAGS = $(GST_LIBS) $(GIO_LIBS) $(GJSON_LIBS) $(LIBSOUP_LIBS) $(JANSSON_LIBS) -pthread diff --git a/gstd/gstd_bus_msg.c b/libgstd/gstd_bus_msg.c similarity index 100% rename from gstd/gstd_bus_msg.c rename to libgstd/gstd_bus_msg.c diff --git a/gstd/gstd_bus_msg.h b/libgstd/gstd_bus_msg.h similarity index 100% rename from gstd/gstd_bus_msg.h rename to libgstd/gstd_bus_msg.h diff --git a/gstd/gstd_bus_msg_element.c b/libgstd/gstd_bus_msg_element.c similarity index 100% rename from gstd/gstd_bus_msg_element.c rename to libgstd/gstd_bus_msg_element.c diff --git a/gstd/gstd_bus_msg_element.h b/libgstd/gstd_bus_msg_element.h similarity index 100% rename from gstd/gstd_bus_msg_element.h rename to libgstd/gstd_bus_msg_element.h diff --git a/gstd/gstd_bus_msg_notify.c b/libgstd/gstd_bus_msg_notify.c similarity index 100% rename from gstd/gstd_bus_msg_notify.c rename to libgstd/gstd_bus_msg_notify.c diff --git a/gstd/gstd_bus_msg_notify.h b/libgstd/gstd_bus_msg_notify.h similarity index 100% rename from gstd/gstd_bus_msg_notify.h rename to libgstd/gstd_bus_msg_notify.h diff --git a/gstd/gstd_bus_msg_qos.c b/libgstd/gstd_bus_msg_qos.c similarity index 100% rename from gstd/gstd_bus_msg_qos.c rename to libgstd/gstd_bus_msg_qos.c diff --git a/gstd/gstd_bus_msg_qos.h b/libgstd/gstd_bus_msg_qos.h similarity index 100% rename from gstd/gstd_bus_msg_qos.h rename to libgstd/gstd_bus_msg_qos.h diff --git a/gstd/gstd_bus_msg_simple.c b/libgstd/gstd_bus_msg_simple.c similarity index 100% rename from gstd/gstd_bus_msg_simple.c rename to libgstd/gstd_bus_msg_simple.c diff --git a/gstd/gstd_bus_msg_simple.h b/libgstd/gstd_bus_msg_simple.h similarity index 100% rename from gstd/gstd_bus_msg_simple.h rename to libgstd/gstd_bus_msg_simple.h diff --git a/gstd/gstd_bus_msg_state_changed.c b/libgstd/gstd_bus_msg_state_changed.c similarity index 100% rename from gstd/gstd_bus_msg_state_changed.c rename to libgstd/gstd_bus_msg_state_changed.c diff --git a/gstd/gstd_bus_msg_state_changed.h b/libgstd/gstd_bus_msg_state_changed.h similarity index 100% rename from gstd/gstd_bus_msg_state_changed.h rename to libgstd/gstd_bus_msg_state_changed.h diff --git a/gstd/gstd_bus_msg_stream_status.c b/libgstd/gstd_bus_msg_stream_status.c similarity index 98% rename from gstd/gstd_bus_msg_stream_status.c rename to libgstd/gstd_bus_msg_stream_status.c index 60ed9895..b9b8db47 100644 --- a/gstd/gstd_bus_msg_stream_status.c +++ b/libgstd/gstd_bus_msg_stream_status.c @@ -35,7 +35,7 @@ gstd_bus_msg_stream_status_to_string (GstdBusMsg * msg, GstdIFormatter * formatter, GstMessage * target); static const gchar - *gstd_bus_msg_stream_status_code_to_string (GstStreamStatusType type); + * gstd_bus_msg_stream_status_code_to_string (GstStreamStatusType type); struct _GstdBusMsgStreamStatus { diff --git a/gstd/gstd_bus_msg_stream_status.h b/libgstd/gstd_bus_msg_stream_status.h similarity index 100% rename from gstd/gstd_bus_msg_stream_status.h rename to libgstd/gstd_bus_msg_stream_status.h diff --git a/gstd/gstd_callback.c b/libgstd/gstd_callback.c similarity index 100% rename from gstd/gstd_callback.c rename to libgstd/gstd_callback.c diff --git a/gstd/gstd_callback.h b/libgstd/gstd_callback.h similarity index 100% rename from gstd/gstd_callback.h rename to libgstd/gstd_callback.h diff --git a/gstd/gstd_debug.c b/libgstd/gstd_debug.c similarity index 100% rename from gstd/gstd_debug.c rename to libgstd/gstd_debug.c diff --git a/gstd/gstd_debug.h b/libgstd/gstd_debug.h similarity index 100% rename from gstd/gstd_debug.h rename to libgstd/gstd_debug.h diff --git a/gstd/gstd_element.c b/libgstd/gstd_element.c similarity index 100% rename from gstd/gstd_element.c rename to libgstd/gstd_element.c diff --git a/gstd/gstd_element.h b/libgstd/gstd_element.h similarity index 100% rename from gstd/gstd_element.h rename to libgstd/gstd_element.h diff --git a/gstd/gstd_event_creator.c b/libgstd/gstd_event_creator.c similarity index 100% rename from gstd/gstd_event_creator.c rename to libgstd/gstd_event_creator.c diff --git a/gstd/gstd_event_creator.h b/libgstd/gstd_event_creator.h similarity index 100% rename from gstd/gstd_event_creator.h rename to libgstd/gstd_event_creator.h diff --git a/gstd/gstd_event_factory.c b/libgstd/gstd_event_factory.c similarity index 100% rename from gstd/gstd_event_factory.c rename to libgstd/gstd_event_factory.c diff --git a/gstd/gstd_event_factory.h b/libgstd/gstd_event_factory.h similarity index 100% rename from gstd/gstd_event_factory.h rename to libgstd/gstd_event_factory.h diff --git a/gstd/gstd_event_handler.c b/libgstd/gstd_event_handler.c similarity index 100% rename from gstd/gstd_event_handler.c rename to libgstd/gstd_event_handler.c diff --git a/gstd/gstd_event_handler.h b/libgstd/gstd_event_handler.h similarity index 100% rename from gstd/gstd_event_handler.h rename to libgstd/gstd_event_handler.h diff --git a/gstd/gstd_http.c b/libgstd/gstd_http.c similarity index 100% rename from gstd/gstd_http.c rename to libgstd/gstd_http.c diff --git a/gstd/gstd_http.h b/libgstd/gstd_http.h similarity index 100% rename from gstd/gstd_http.h rename to libgstd/gstd_http.h diff --git a/gstd/gstd_icreator.c b/libgstd/gstd_icreator.c similarity index 100% rename from gstd/gstd_icreator.c rename to libgstd/gstd_icreator.c diff --git a/gstd/gstd_icreator.h b/libgstd/gstd_icreator.h similarity index 100% rename from gstd/gstd_icreator.h rename to libgstd/gstd_icreator.h diff --git a/gstd/gstd_ideleter.c b/libgstd/gstd_ideleter.c similarity index 100% rename from gstd/gstd_ideleter.c rename to libgstd/gstd_ideleter.c diff --git a/gstd/gstd_ideleter.h b/libgstd/gstd_ideleter.h similarity index 100% rename from gstd/gstd_ideleter.h rename to libgstd/gstd_ideleter.h diff --git a/gstd/gstd_iformatter.c b/libgstd/gstd_iformatter.c similarity index 100% rename from gstd/gstd_iformatter.c rename to libgstd/gstd_iformatter.c diff --git a/gstd/gstd_iformatter.h b/libgstd/gstd_iformatter.h similarity index 100% rename from gstd/gstd_iformatter.h rename to libgstd/gstd_iformatter.h diff --git a/gstd/gstd_ipc.c b/libgstd/gstd_ipc.c similarity index 100% rename from gstd/gstd_ipc.c rename to libgstd/gstd_ipc.c diff --git a/gstd/gstd_ipc.h b/libgstd/gstd_ipc.h similarity index 100% rename from gstd/gstd_ipc.h rename to libgstd/gstd_ipc.h diff --git a/gstd/gstd_ireader.c b/libgstd/gstd_ireader.c similarity index 100% rename from gstd/gstd_ireader.c rename to libgstd/gstd_ireader.c diff --git a/gstd/gstd_ireader.h b/libgstd/gstd_ireader.h similarity index 100% rename from gstd/gstd_ireader.h rename to libgstd/gstd_ireader.h diff --git a/gstd/gstd_iupdater.c b/libgstd/gstd_iupdater.c similarity index 100% rename from gstd/gstd_iupdater.c rename to libgstd/gstd_iupdater.c diff --git a/gstd/gstd_iupdater.h b/libgstd/gstd_iupdater.h similarity index 100% rename from gstd/gstd_iupdater.h rename to libgstd/gstd_iupdater.h diff --git a/gstd/gstd_json_builder.c b/libgstd/gstd_json_builder.c similarity index 100% rename from gstd/gstd_json_builder.c rename to libgstd/gstd_json_builder.c diff --git a/gstd/gstd_json_builder.h b/libgstd/gstd_json_builder.h similarity index 100% rename from gstd/gstd_json_builder.h rename to libgstd/gstd_json_builder.h diff --git a/gstd/gstd_list.c b/libgstd/gstd_list.c similarity index 100% rename from gstd/gstd_list.c rename to libgstd/gstd_list.c diff --git a/gstd/gstd_list.h b/libgstd/gstd_list.h similarity index 100% rename from gstd/gstd_list.h rename to libgstd/gstd_list.h diff --git a/gstd/gstd_list_reader.c b/libgstd/gstd_list_reader.c similarity index 100% rename from gstd/gstd_list_reader.c rename to libgstd/gstd_list_reader.c diff --git a/gstd/gstd_list_reader.h b/libgstd/gstd_list_reader.h similarity index 100% rename from gstd/gstd_list_reader.h rename to libgstd/gstd_list_reader.h diff --git a/gstd/gstd_msg_reader.c b/libgstd/gstd_msg_reader.c similarity index 100% rename from gstd/gstd_msg_reader.c rename to libgstd/gstd_msg_reader.c diff --git a/gstd/gstd_msg_reader.h b/libgstd/gstd_msg_reader.h similarity index 100% rename from gstd/gstd_msg_reader.h rename to libgstd/gstd_msg_reader.h diff --git a/gstd/gstd_msg_type.c b/libgstd/gstd_msg_type.c similarity index 100% rename from gstd/gstd_msg_type.c rename to libgstd/gstd_msg_type.c diff --git a/gstd/gstd_msg_type.h b/libgstd/gstd_msg_type.h similarity index 100% rename from gstd/gstd_msg_type.h rename to libgstd/gstd_msg_type.h diff --git a/gstd/gstd_no_creator.c b/libgstd/gstd_no_creator.c similarity index 100% rename from gstd/gstd_no_creator.c rename to libgstd/gstd_no_creator.c diff --git a/gstd/gstd_no_creator.h b/libgstd/gstd_no_creator.h similarity index 100% rename from gstd/gstd_no_creator.h rename to libgstd/gstd_no_creator.h diff --git a/gstd/gstd_no_deleter.c b/libgstd/gstd_no_deleter.c similarity index 100% rename from gstd/gstd_no_deleter.c rename to libgstd/gstd_no_deleter.c diff --git a/gstd/gstd_no_deleter.h b/libgstd/gstd_no_deleter.h similarity index 100% rename from gstd/gstd_no_deleter.h rename to libgstd/gstd_no_deleter.h diff --git a/gstd/gstd_no_reader.c b/libgstd/gstd_no_reader.c similarity index 100% rename from gstd/gstd_no_reader.c rename to libgstd/gstd_no_reader.c diff --git a/gstd/gstd_no_reader.h b/libgstd/gstd_no_reader.h similarity index 100% rename from gstd/gstd_no_reader.h rename to libgstd/gstd_no_reader.h diff --git a/gstd/gstd_no_updater.c b/libgstd/gstd_no_updater.c similarity index 100% rename from gstd/gstd_no_updater.c rename to libgstd/gstd_no_updater.c diff --git a/gstd/gstd_no_updater.h b/libgstd/gstd_no_updater.h similarity index 100% rename from gstd/gstd_no_updater.h rename to libgstd/gstd_no_updater.h diff --git a/gstd/gstd_object.c b/libgstd/gstd_object.c similarity index 100% rename from gstd/gstd_object.c rename to libgstd/gstd_object.c diff --git a/gstd/gstd_object.h b/libgstd/gstd_object.h similarity index 100% rename from gstd/gstd_object.h rename to libgstd/gstd_object.h diff --git a/gstd/gstd_parser.c b/libgstd/gstd_parser.c similarity index 100% rename from gstd/gstd_parser.c rename to libgstd/gstd_parser.c diff --git a/gstd/gstd_parser.h b/libgstd/gstd_parser.h similarity index 100% rename from gstd/gstd_parser.h rename to libgstd/gstd_parser.h diff --git a/gstd/gstd_pipeline.c b/libgstd/gstd_pipeline.c similarity index 100% rename from gstd/gstd_pipeline.c rename to libgstd/gstd_pipeline.c diff --git a/gstd/gstd_pipeline.h b/libgstd/gstd_pipeline.h similarity index 100% rename from gstd/gstd_pipeline.h rename to libgstd/gstd_pipeline.h diff --git a/gstd/gstd_pipeline_bus.c b/libgstd/gstd_pipeline_bus.c similarity index 100% rename from gstd/gstd_pipeline_bus.c rename to libgstd/gstd_pipeline_bus.c diff --git a/gstd/gstd_pipeline_bus.h b/libgstd/gstd_pipeline_bus.h similarity index 100% rename from gstd/gstd_pipeline_bus.h rename to libgstd/gstd_pipeline_bus.h diff --git a/gstd/gstd_pipeline_creator.c b/libgstd/gstd_pipeline_creator.c similarity index 100% rename from gstd/gstd_pipeline_creator.c rename to libgstd/gstd_pipeline_creator.c diff --git a/gstd/gstd_pipeline_creator.h b/libgstd/gstd_pipeline_creator.h similarity index 100% rename from gstd/gstd_pipeline_creator.h rename to libgstd/gstd_pipeline_creator.h diff --git a/gstd/gstd_pipeline_deleter.c b/libgstd/gstd_pipeline_deleter.c similarity index 100% rename from gstd/gstd_pipeline_deleter.c rename to libgstd/gstd_pipeline_deleter.c diff --git a/gstd/gstd_pipeline_deleter.h b/libgstd/gstd_pipeline_deleter.h similarity index 100% rename from gstd/gstd_pipeline_deleter.h rename to libgstd/gstd_pipeline_deleter.h diff --git a/gstd/gstd_property.c b/libgstd/gstd_property.c similarity index 100% rename from gstd/gstd_property.c rename to libgstd/gstd_property.c diff --git a/gstd/gstd_property.h b/libgstd/gstd_property.h similarity index 100% rename from gstd/gstd_property.h rename to libgstd/gstd_property.h diff --git a/gstd/gstd_property_array.c b/libgstd/gstd_property_array.c similarity index 100% rename from gstd/gstd_property_array.c rename to libgstd/gstd_property_array.c diff --git a/gstd/gstd_property_array.h b/libgstd/gstd_property_array.h similarity index 100% rename from gstd/gstd_property_array.h rename to libgstd/gstd_property_array.h diff --git a/gstd/gstd_property_boolean.c b/libgstd/gstd_property_boolean.c similarity index 100% rename from gstd/gstd_property_boolean.c rename to libgstd/gstd_property_boolean.c diff --git a/gstd/gstd_property_boolean.h b/libgstd/gstd_property_boolean.h similarity index 100% rename from gstd/gstd_property_boolean.h rename to libgstd/gstd_property_boolean.h diff --git a/gstd/gstd_property_enum.c b/libgstd/gstd_property_enum.c similarity index 100% rename from gstd/gstd_property_enum.c rename to libgstd/gstd_property_enum.c diff --git a/gstd/gstd_property_enum.h b/libgstd/gstd_property_enum.h similarity index 100% rename from gstd/gstd_property_enum.h rename to libgstd/gstd_property_enum.h diff --git a/gstd/gstd_property_flags.c b/libgstd/gstd_property_flags.c similarity index 100% rename from gstd/gstd_property_flags.c rename to libgstd/gstd_property_flags.c diff --git a/gstd/gstd_property_flags.h b/libgstd/gstd_property_flags.h similarity index 100% rename from gstd/gstd_property_flags.h rename to libgstd/gstd_property_flags.h diff --git a/gstd/gstd_property_int.c b/libgstd/gstd_property_int.c similarity index 100% rename from gstd/gstd_property_int.c rename to libgstd/gstd_property_int.c diff --git a/gstd/gstd_property_int.h b/libgstd/gstd_property_int.h similarity index 100% rename from gstd/gstd_property_int.h rename to libgstd/gstd_property_int.h diff --git a/gstd/gstd_property_reader.c b/libgstd/gstd_property_reader.c similarity index 100% rename from gstd/gstd_property_reader.c rename to libgstd/gstd_property_reader.c diff --git a/gstd/gstd_property_reader.h b/libgstd/gstd_property_reader.h similarity index 100% rename from gstd/gstd_property_reader.h rename to libgstd/gstd_property_reader.h diff --git a/gstd/gstd_property_string.c b/libgstd/gstd_property_string.c similarity index 100% rename from gstd/gstd_property_string.c rename to libgstd/gstd_property_string.c diff --git a/gstd/gstd_property_string.h b/libgstd/gstd_property_string.h similarity index 100% rename from gstd/gstd_property_string.h rename to libgstd/gstd_property_string.h diff --git a/gstd/gstd_return_codes.c b/libgstd/gstd_return_codes.c similarity index 100% rename from gstd/gstd_return_codes.c rename to libgstd/gstd_return_codes.c diff --git a/gstd/gstd_return_codes.h b/libgstd/gstd_return_codes.h similarity index 100% rename from gstd/gstd_return_codes.h rename to libgstd/gstd_return_codes.h diff --git a/gstd/gstd_session.c b/libgstd/gstd_session.c similarity index 100% rename from gstd/gstd_session.c rename to libgstd/gstd_session.c diff --git a/gstd/gstd_session.h b/libgstd/gstd_session.h similarity index 100% rename from gstd/gstd_session.h rename to libgstd/gstd_session.h diff --git a/gstd/gstd_signal.c b/libgstd/gstd_signal.c similarity index 100% rename from gstd/gstd_signal.c rename to libgstd/gstd_signal.c diff --git a/gstd/gstd_signal.h b/libgstd/gstd_signal.h similarity index 100% rename from gstd/gstd_signal.h rename to libgstd/gstd_signal.h diff --git a/gstd/gstd_signal_list.c b/libgstd/gstd_signal_list.c similarity index 100% rename from gstd/gstd_signal_list.c rename to libgstd/gstd_signal_list.c diff --git a/gstd/gstd_signal_list.h b/libgstd/gstd_signal_list.h similarity index 100% rename from gstd/gstd_signal_list.h rename to libgstd/gstd_signal_list.h diff --git a/gstd/gstd_signal_reader.c b/libgstd/gstd_signal_reader.c similarity index 100% rename from gstd/gstd_signal_reader.c rename to libgstd/gstd_signal_reader.c diff --git a/gstd/gstd_signal_reader.h b/libgstd/gstd_signal_reader.h similarity index 100% rename from gstd/gstd_signal_reader.h rename to libgstd/gstd_signal_reader.h diff --git a/gstd/gstd_socket.c b/libgstd/gstd_socket.c similarity index 100% rename from gstd/gstd_socket.c rename to libgstd/gstd_socket.c diff --git a/gstd/gstd_socket.h b/libgstd/gstd_socket.h similarity index 100% rename from gstd/gstd_socket.h rename to libgstd/gstd_socket.h diff --git a/gstd/gstd_state.c b/libgstd/gstd_state.c similarity index 100% rename from gstd/gstd_state.c rename to libgstd/gstd_state.c diff --git a/gstd/gstd_state.h b/libgstd/gstd_state.h similarity index 100% rename from gstd/gstd_state.h rename to libgstd/gstd_state.h diff --git a/gstd/gstd_tcp.c b/libgstd/gstd_tcp.c similarity index 100% rename from gstd/gstd_tcp.c rename to libgstd/gstd_tcp.c diff --git a/gstd/gstd_tcp.h b/libgstd/gstd_tcp.h similarity index 100% rename from gstd/gstd_tcp.h rename to libgstd/gstd_tcp.h diff --git a/gstd/gstd_unix.c b/libgstd/gstd_unix.c similarity index 100% rename from gstd/gstd_unix.c rename to libgstd/gstd_unix.c diff --git a/gstd/gstd_unix.h b/libgstd/gstd_unix.h similarity index 100% rename from gstd/gstd_unix.h rename to libgstd/gstd_unix.h diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c new file mode 100644 index 00000000..c3fbefe6 --- /dev/null +++ b/libgstd/libgstd.c @@ -0,0 +1,245 @@ +/* + * GStreamer Daemon - gst-launch on steroids + * C library abstracting gstd + * + * Copyright (c) 2015-2021 RidgeRun, LLC (http://www.ridgerun.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#define _GNU_SOURCE + +#include "libgstd.h" + +#include +#include + +#include "gstd_http.h" +#include "gstd_ipc.h" +#include "gstd_log.h" +#include "gstd_tcp.h" +#include "gstd_unix.h" + +/** + * Supported_IPCs: + * @GSTD_IPC_TYPE_TCP: To enable TCP communication + * @GSTD_IPC_TYPE_UNIX: To enable UNIX communication + * @GSTD_IPC_TYPE_HTTP: To enable HTTP communication + * IPC options for libGstD + */ +typedef enum _SupportedIpcs SupportedIpcs; + +enum _SupportedIpcs +{ + GSTD_IPC_TYPE_TCP, + GSTD_IPC_TYPE_UNIX, + GSTD_IPC_TYPE_HTTP, +}; + +static GType gstd_supported_ipc_to_ipc (const SupportedIpcs code); +static void gstd_manager_init (int argc, char *argv[]); +static void gstd_manager_set_ipc (GstDManager * manager); + +struct _GstDManager +{ + GstdSession *session; + GstdIpc **ipc_array; + guint num_ipcs; +}; + +static GType +gstd_supported_ipc_to_ipc (const SupportedIpcs code) +{ + GType code_description[] = { + [GSTD_IPC_TYPE_TCP] = GSTD_TYPE_TCP, + [GSTD_IPC_TYPE_UNIX] = GSTD_TYPE_UNIX, + [GSTD_IPC_TYPE_HTTP] = GSTD_TYPE_HTTP + }; + + const gint size = sizeof (code_description) / sizeof (gchar *); + + g_return_val_if_fail (0 <= code, GSTD_TYPE_IPC); + g_return_val_if_fail (size > code, GSTD_TYPE_IPC); + + return code_description[code]; +} + +static void +gstd_manager_init (int argc, char *argv[]) +{ + gst_init (&argc, &argv); + gstd_debug_init (); +} + +static void +gstd_manager_set_ipc (GstDManager * manager) +{ + /* Array to specify gstd how many IPCs are supported, + * SupportedIpcs should be added to this array. + */ + const SupportedIpcs supported_ipcs[] = { + GSTD_IPC_TYPE_TCP, + GSTD_IPC_TYPE_UNIX, + GSTD_IPC_TYPE_HTTP, + }; + + const guint num_ipcs = (sizeof (supported_ipcs) / sizeof (SupportedIpcs)); + + GstdIpc **ipc_array = NULL; + + g_return_if_fail (NULL != manager); + g_return_if_fail (NULL != supported_ipcs); + + /* If there is ipcs, then initialize them */ + if (NULL != supported_ipcs && num_ipcs > 0) { + ipc_array = g_malloc0 (num_ipcs * sizeof (*ipc_array)); + for (gint ipc_idx = 0; ipc_idx < num_ipcs; ipc_idx++) { + ipc_array[ipc_idx] = + GSTD_IPC (g_object_new (gstd_supported_ipc_to_ipc (supported_ipcs + [ipc_idx]), NULL)); + } + manager->ipc_array = ipc_array; + } + + manager->num_ipcs = num_ipcs; + manager->ipc_array = ipc_array; +} + +void +gstd_context_add_group (GstDManager * manager, GOptionContext * context) +{ + GOptionGroup *gst_options = NULL; + GOptionGroup **ipc_group_array = NULL; + + g_return_if_fail (NULL != manager); + g_return_if_fail (NULL != manager->ipc_array); + g_return_if_fail (NULL != context); + + gst_options = gst_init_get_option_group (); + g_option_context_add_group (context, gst_options); + + ipc_group_array = g_malloc0 (manager->num_ipcs * sizeof (*ipc_group_array)); + + for (gint ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) { + gstd_ipc_get_option_group (manager->ipc_array[ipc_idx], + &ipc_group_array[ipc_idx]); + g_option_context_add_group (context, ipc_group_array[ipc_idx]); + } + + g_free (ipc_group_array); +} + +GstdStatus +gstd_manager_new (GstDManager ** out, int argc, char *argv[]) +{ + GstdStatus ret = GSTD_LIB_OK; + GstDManager *manager = NULL; + GstdSession *session = NULL; + + g_return_val_if_fail (NULL != out, GSTD_NULL_ARGUMENT); + + manager = (GstDManager *) g_malloc0 (sizeof (*manager)); + session = gstd_session_new ("Session0"); + + manager->session = session; + manager->num_ipcs = 0; + manager->ipc_array = NULL; + + gstd_manager_set_ipc (manager); + + *out = manager; + + /* Initialize GStreamer */ + gstd_manager_init (argc, argv); + + return ret; +} + +gboolean +gstd_manager_start (GstDManager * manager) +{ + gboolean ipc_selected = FALSE; + gboolean ret = TRUE; + GstdReturnCode code = GSTD_EOK; + gint ipc_idx; + + g_return_val_if_fail (NULL != manager, GSTD_NULL_ARGUMENT); + g_return_val_if_fail (NULL != manager->ipc_array, GSTD_LIB_NOT_FOUND); + g_return_val_if_fail (NULL != manager->session, GSTD_LIB_NOT_FOUND); + + /* Verify if at least one IPC mechanism was selected */ + for (ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) { + g_object_get (G_OBJECT (manager->ipc_array[ipc_idx]), "enabled", + &ipc_selected, NULL); + + if (ipc_selected) { + break; + } + } + + /* If no IPC was selected, default to TCP */ + if (!ipc_selected) { + g_object_set (G_OBJECT (manager->ipc_array[0]), "enabled", TRUE, NULL); + } + + /* Run start for each IPC (each start method checks for the enabled flag) */ + for (ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) { + code = gstd_ipc_start (manager->ipc_array[ipc_idx], manager->session); + if (code) { + g_printerr ("Couldn't start IPC : (%s)\n", + G_OBJECT_TYPE_NAME (manager->ipc_array[ipc_idx])); + ret = FALSE; + } + } + + return ret; +} + +void +gstd_manager_stop (GstDManager * manager) +{ + g_return_if_fail (NULL != manager); + g_return_if_fail (NULL != manager->ipc_array); + g_return_if_fail (NULL != manager->session); + + /* Run stop for each IPC */ + for (gint ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) { + if (NULL != manager->ipc_array[ipc_idx] + && TRUE == manager->ipc_array[ipc_idx]->enabled) { + gstd_ipc_stop (manager->ipc_array[ipc_idx]); + g_clear_object (&manager->ipc_array[ipc_idx]); + } + } +} + +void +gstd_manager_free (GstDManager * manager) +{ + g_return_if_fail (NULL != manager); + gstd_manager_stop (manager); + g_free (manager->ipc_array); + g_object_unref (manager->session); + g_free (manager); +} diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h new file mode 100644 index 00000000..c3a6a454 --- /dev/null +++ b/libgstd/libgstd.h @@ -0,0 +1,128 @@ +/* + * GStreamer Daemon - Gst Launch under steroids + * Copyright (c) 2015-2021 Ridgerun, LLC (http://www.ridgerun.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __LIBGSTD_H__ +#define __LIBGSTD_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include + +/* + * GstDManager: + * Opaque representation of GstD state. + * This struct will have: Session, GstdIpc and num_ipcs (for now) + */ +typedef struct _GstDManager GstDManager; + +/** + * GstdStatus: + * @GSTD_LIB_OK: Everything went okay + * @GSTD_LIB_NULL_ARGUMENT: A mandatory argument was passed in as NULL + * @GSTD_LIB_OOM: The system has run out of memory + * @GSTD_LIB_TYPE_ERROR: An error occurred parsing a type from a string + * @GSTD_LIB_NOT_FOUND: The response is missing the field requested + * @GSTD_LIB_THREAD_ERROR: Unable to create a new thread + * @GSTD_LIB_BUS_TIMEOUT: A timeout was received while waiting on the bus + * @GSTD_LIB_LONG_RESPONSE: The response exceeds our maximum, typically + * meaning a missing null terminator + * + * Return codes for the different libgstd operations + */ +typedef enum +{ + GSTD_LIB_OK = 0, + GSTD_LIB_NULL_ARGUMENT = -1, + GSTD_LIB_OOM = -4, + GSTD_LIB_TYPE_ERROR = -5, + GSTD_LIB_NOT_FOUND = -7, + GSTD_LIB_THREAD_ERROR = -11, + GSTD_LIB_BUS_TIMEOUT = -12, + GSTD_LIB_LONG_RESPONSE = -14 +} GstdStatus; + + +/** + * gstd_context_add_group: + * + * Returns: A GOptionGroup with GStreamer's argument specification. + * + */ +void +gstd_context_add_group (GstDManager *manager, GOptionContext *context); + +/** + * gstd_manager_new: + * + * @out: placeholder for newly allocated gstd manager. + * @argc: arguments for gst_init + * @argv: arguments for gst_init + * + * Initializes gstd. + * + * Returns: GstdStatus indicating success or fail + */ +GstdStatus +gstd_manager_new (GstDManager ** out, int argc, char *argv[]); + + +/** + * gstd_manager_start: + * @manager: The manager returned by gstd_manager_new() + * + * Starts the ipc in GstdIpc array + * + * Returns: GstdStatus indicating success or fail + */ +int +gstd_manager_start (GstDManager * manager); + +/** + * gstd_manager_stop: + * @manager: The manager returned by gstd_manager_new() + * + * Stops the ipc in GstdIpc array + * + * Returns: GstdStatus indicating success or fail + */ +void +gstd_manager_stop (GstDManager * manager); + +/** + * gstd_manager_free: + * @manager: A valid manager allocated with gstd_new() + * + * Frees a previously allocated GstDManager. + * + * Returns: A newly allocated GstDManager. Use gstd_free() after + * usage. + */ +void +gstd_manager_free (GstDManager * manager); + + +#ifdef __cplusplus +} +#endif + +#endif /* __LIBGSTD_H__ */ diff --git a/libgstd/meson.build b/libgstd/meson.build new file mode 100644 index 00000000..5ec437d1 --- /dev/null +++ b/libgstd/meson.build @@ -0,0 +1,83 @@ +gstd_headers = [ + 'libgstd.h', +] + +# Common files needed for GstD and libGstD +gstd_src = [ + 'gstd_object.c', + 'gstd_pipeline.c', + 'gstd_element.c', + 'gstd_list.c', + 'gstd_ipc.c', + 'gstd_tcp.c', + 'gstd_http.c', + 'gstd_icreator.c', + 'gstd_iformatter.c', + 'gstd_pipeline_creator.c', + 'gstd_no_creator.c', + 'gstd_json_builder.c', + 'gstd_ideleter.c', + 'gstd_pipeline_deleter.c', + 'gstd_no_deleter.c', + 'gstd_debug.c', + 'gstd_event_creator.c', + 'gstd_event_factory.c', + 'gstd_pipeline_bus.c', + 'gstd_ireader.c', + 'gstd_property_reader.c', + 'gstd_no_reader.c', + 'gstd_list_reader.c', + 'gstd_property.c', + 'gstd_property_int.c', + 'gstd_property_string.c', + 'gstd_property_boolean.c', + 'gstd_property_array.c', + 'gstd_iupdater.c', + 'gstd_no_updater.c', + 'gstd_property_enum.c', + 'gstd_property_flags.c', + 'gstd_event_handler.c', + 'gstd_bus_msg.c', + 'gstd_bus_msg_simple.c', + 'gstd_bus_msg_notify.c', + 'gstd_bus_msg_state_changed.c', + 'gstd_msg_reader.c', + 'gstd_msg_type.c', + 'gstd_bus_msg_qos.c', + 'gstd_return_codes.c', + 'gstd_state.c', + 'gstd_parser.c', + 'gstd_bus_msg_stream_status.c', + 'gstd_bus_msg_element.c', + 'gstd_signal.c', + 'gstd_signal_list.c', + 'gstd_callback.c', + 'gstd_signal_reader.c', + 'gstd_session.c', + 'gstd_socket.c', + 'gstd_unix.c', + '../gstd/gstd_log.c', +] + +libgstd_src = [ + 'libgstd.c' +] + +gstd_lib_manager = library('gstd-@0@'.format(apiversion), + [gstd_src, libgstd_src], + c_args : gst_d_args, + version : gstd_version, + include_directories : [configinc, gstd_inc_dir], + install : true, + install_dir : lib_install_dir, + dependencies : [libgstd_deps], +) + +install_headers(gstd_headers) + +# Generate pkgconfig file +pkgconfig.generate(gstd_lib_manager, description : 'GStreamer Manager library to control Gstd') + +# Define the library as an internal dependency to the current build +lib_gstd_dep = declare_dependency(link_with: gstd_lib_manager, + dependencies : [libgstd_deps]) diff --git a/meson.build b/meson.build index a0af2e25..1d9ce9de 100644 --- a/meson.build +++ b/meson.build @@ -52,9 +52,11 @@ endif ## Dependencies # Define gst Daemon dependencies -gstd_deps = [gst_base_dep, gio_unix_dep, json_glib_dep, libd_dep, jansson_dep, libsoup_dep] +gstd_deps = [libd_dep] # Define gst client library dependencies libgstc_deps = [gst_base_dep, json_glib_dep, jansson_dep, thread_dep] +# Define gst core library dependencies +libgstd_deps = [gst_base_dep, gio_unix_dep, json_glib_dep, jansson_dep, thread_dep, libsoup_dep] # Define gst client application dependencies gst_client_deps = [readline_dep, json_glib_dep, gio_unix_dep] # Define test dependencies @@ -64,6 +66,7 @@ test_gstd_deps=[gst_base_dep, gio_unix_dep, json_glib_dep, libd_dep, jansson_dep # Define header directories lib_gstc_inc_dir = include_directories('libgstc/c') gstd_inc_dir = include_directories('gstd') +libgstd_inc_dir = include_directories('libgstd') configinc = include_directories('.') # Define gstreamer API version @@ -89,6 +92,7 @@ if logstatedir == '${prefix}/var/log/gstd/' endif gstd_log_state_dir = '-DGSTD_LOG_STATE_DIR="@0@"'.format(logstatedir) gst_c_args = ['-DHAVE_CONFIG_H',gstd_log_state_dir,gstd_run_state_dir] +gst_d_args = ['-DHAVE_CONFIG_H',gstd_log_state_dir,gstd_run_state_dir] # Get an object returns describing a compiler cc = meson.get_compiler('c') @@ -240,10 +244,10 @@ endif configure_file(output : 'config.h', configuration : cdata) # Enter to each subdirectory and execute the meson.build -subdir('gstd') subdir('libgstc') +subdir('libgstd') +subdir('gstd') subdir('gst_client') subdir('tests') subdir('examples') subdir('docs') -subdir('init') diff --git a/tests/gstd/Makefile.am b/tests/gstd/Makefile.am index 907c4949..1bb186e2 100644 --- a/tests/gstd/Makefile.am +++ b/tests/gstd/Makefile.am @@ -4,6 +4,6 @@ TESTS = test_gstd_pipeline_create \ check_PROGRAMS = $(TESTS) -AM_CFLAGS = $(GST_CFLAGS) -I$(top_srcdir)/gstd/ +AM_CFLAGS = $(GST_CFLAGS) -I$(top_srcdir)/libgstd/ AM_LDFLAGS = $(GST_LIBS) -LDADD = $(top_srcdir)/gstd/libgstd-core.la +LDADD = $(top_srcdir)/libgstd/libgstd-1.0.la diff --git a/tests/gstd/meson.build b/tests/gstd/meson.build index be854051..c2d064d9 100644 --- a/tests/gstd/meson.build +++ b/tests/gstd/meson.build @@ -37,9 +37,9 @@ foreach t : gstd_tests exe = executable(test_name, fname, c_args : gst_c_args + test_defines, cpp_args : gst_c_args + test_defines, - include_directories : [configinc, gstd_inc_dir], + include_directories : [configinc, libgstd_inc_dir], link_with : link_with_libs, - dependencies : [test_gstd_deps,lib_gstd_dep], + dependencies : [test_gstd_deps, lib_gstd_dep], ) # Define enviroment variable