From f97374539ed4146c9c2da5affcb177affa4cb90e Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 16 Aug 2021 17:51:22 -0600 Subject: [PATCH 01/13] Create libgstd interface This is the API to be implemented in order to use gstd as a library. It also will work to providing to GstD app the functionalities not related to the daemon management --- init/gstd | 49 +++++++++++++++ init/gstd.service | 13 ++++ libgstd/libgstd.h | 154 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 init/gstd create mode 100644 init/gstd.service create mode 100644 libgstd/libgstd.h diff --git a/init/gstd b/init/gstd new file mode 100644 index 00000000..55a24bcc --- /dev/null +++ b/init/gstd @@ -0,0 +1,49 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: GstD +# Short-Description: start and stop GstD +# Description: Gstreamer Daemon is a framework for +# controlling audio and video streaming +### END INIT INFO + +manage_dir() +{ + dir="$1"; + mode="$2"; + user="$3"; + + #Create directory if not created yet + mkdir -m "$mode" -p "$dir"; + if [ $? -ne 0 ]; then + echo "GstD init: Error, cannot create directory $dir" 1>&2; + exit 1 + fi + + #Set the owner + chown -R "$user" "$dir"; + if [ $? -ne 0 ]; then + echo "GstD init: Error, cannot change $dir owner to $user" 1>&2; + exit 1 + fi +} + +prefix=/usr/local +gstdrunstatedir=${prefix}/var/run/gstd/ +gstdlogstatedir=${prefix}/var/log/gstd/ + +case "$1" in + start) + #Manage pid and log directories + manage_dir "$gstdrunstatedir" 777 root + manage_dir "$gstdlogstatedir" 777 root + + #Start gstd + /usr/local/bin/gstd -e; + ;; + stop) + /usr/local/bin/gstd -k; + ;; + *) + echo "$0 {start|stop}" +esac diff --git a/init/gstd.service b/init/gstd.service new file mode 100644 index 00000000..99ff4fcc --- /dev/null +++ b/init/gstd.service @@ -0,0 +1,13 @@ +[Unit] +Description=GStreamer Daemon +StartLimitBurst=3 +StartLimitIntervalSec=30 + +[Service] +Restart=on-failure +RestartSec=5s +ExecStartPre=/usr/lib/systemd/user/gstd-check-user-xenv.sh +ExecStart=/usr/local/bin/gstd + +[Install] +WantedBy=default.target diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h new file mode 100644 index 00000000..716e90b2 --- /dev/null +++ b/libgstd/libgstd.h @@ -0,0 +1,154 @@ +/* + * GStreamer Daemon - Gst Launch under steroids + * Copyright (c) 2015-2017 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 + +#define HEADER \ + "\nGstd version " PACKAGE_VERSION "\n" \ + "Copyright (C) 2015-2020 RidgeRun (https://www.ridgerun.com)\n\n" + +/* + * GstDManager: + * Opaque representation of GstD state. + * This struct will have: Session, GstdIpc and num_ipcs (for now) + */ +typedef struct _GstDManager GstDManager; + +/** + * Supported_IPCs: + * IPC options for libGstD + */ +typedef enum _SupportedIpcs SupportedIpcs; /* Used to avoid importing gstd_ipc.h in this file */ + +enum _SupportedIpcs +{ + GSTD_IPC_TYPE_TCP, + GSTD_IPC_TYPE_UNIX, + GSTD_IPC_TYPE_HTTP, +}; + +/** + * GstdStatus: + * @gstd_OK: Everything went okay + * @gstd_NULL_ARGUMENT: A mandatory argument was passed in as NULL + * @gstd_OOM: The system has run out of memory + * @gstd_TYPE_ERROR: An error occurred parsing a type from a string + * @gstd_NOT_FOUND: The response is missing the field requested + * @gstd_THREAD_ERROR: Unable to create a new thread + * @gstd_BUS_TIMEOUT: A timeout was received while waiting on the bus + * @gstd_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_SOCKET_TIMEOUT = -13, + GSTD_LIB_LONG_RESPONSE = -14 +} GstdStatus; + + +/** + * gstd_manager_new: + * + * @supported_ipcs: ipcs the user will use + * @num_ipcs: lenght of supported_ipcs + * @out: placeholder for newly allocated gstd manager. + * @gst_group: placeholder for GStreamer's argument specifications + * @argc: arguments for gst_init + * @argv: arguments for gst_init + * + * Initializes gstd. If ipc array is not NULL + * it will initialize the GstdIpc in GstDManager. + * If it is NULL it will just initialize the session. + * + * Returns: GstdStatus indicating success or fail + */ +GstdStatus +gstd_manager_new (SupportedIpcs supported_ipcs[], uint num_ipcs, + GstDManager ** out, GOptionGroup **gst_group, int argc, char *argv[]); + +/** + * gstd_manager_ipc_options: + * @manager: The manager returned by gstd_manager_new() + * @ipc_group: placeholder for IPCs specifications + * + * Get IPCs information into a group + * + */ +void +gstd_manager_ipc_options (GstDManager * manager, GOptionGroup **ipc_group); + +/** + * gstd_manager_ipc_start: + * @manager: The manager returned by gstd_manager_new() + * + * Starts the ipc in GstdIpc array + * + * Returns: GstdStatus indicating success or fail + */ +int +gstd_manager_ipc_start (GstDManager * manager); + +/** + * gstd_manager_ipc_start: + * @manager: The manager returned by gstd_manager_new() + * + * Stops the ipc in GstdIpc array + * + * Returns: GstdStatus indicating success or fail + */ +void +gstd_manager_ipc_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__ \ No newline at end of file From ec7cd0aa11feccf686876ec8a61a5069e546e519 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 16 Aug 2021 18:01:35 -0600 Subject: [PATCH 02/13] Include libgstd header in GstD app --- .vscode/settings.json | 5 +++++ gstd/gstd.c | 2 ++ gstd/meson.build | 7 +++++-- libgstd/meson.build | 0 meson.build | 2 ++ 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 libgstd/meson.build diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..d37494e0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "libgstd.h": "c" + } +} \ No newline at end of file diff --git a/gstd/gstd.c b/gstd/gstd.c index 98ad0d00..fb47cf01 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -33,6 +33,8 @@ #include "gstd_daemon.h" #include "gstd_log.h" +#include "libgstd.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[]); diff --git a/gstd/meson.build b/gstd/meson.build index b81a6866..a24249ef 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -116,6 +116,9 @@ libgstd_header_files = [ 'gstd_unix.h' ] +gstd_src = [ +] + # Create a static library used to create gstd daemon and also is used for tests gstd_lib = both_libraries('gstd-core', libgstd_src_files, @@ -134,9 +137,9 @@ lib_gstd_dep = declare_dependency(link_with: gstd_lib, # Create gstd application exe_name = '@0@-@1@'.format(gstd_name, apiversion) executable(exe_name, - gstd_src_files, + [gstd_src_files, gstd_src], 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/meson.build b/libgstd/meson.build new file mode 100644 index 00000000..e69de29b diff --git a/meson.build b/meson.build index a0af2e25..05a17eba 100644 --- a/meson.build +++ b/meson.build @@ -64,6 +64,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 @@ -242,6 +243,7 @@ configure_file(output : 'config.h', configuration : cdata) # Enter to each subdirectory and execute the meson.build subdir('gstd') subdir('libgstc') +subdir('libgstd') subdir('gst_client') subdir('tests') subdir('examples') From 8c7c879e2b44748b2827b92e6cc827eade3ed4b0 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 16 Aug 2021 18:05:53 -0600 Subject: [PATCH 03/13] Build libgstd using meson It includes Meson management to sure that library will be integrated to the rest of the project --- gstd/meson.build | 3 +- libgstd/libgstd.c | 48 ++++++++++++++++++++++++++ libgstd/meson.build | 84 +++++++++++++++++++++++++++++++++++++++++++++ meson.build | 7 ++-- 4 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 libgstd/libgstd.c diff --git a/gstd/meson.build b/gstd/meson.build index a24249ef..a378b931 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -117,6 +117,7 @@ libgstd_header_files = [ ] gstd_src = [ + '../libgstd/libgstd.c' ] # Create a static library used to create gstd daemon and also is used for tests @@ -169,4 +170,4 @@ meson.add_install_script('gstd_chmod.sh','777', logstatedir) meson.add_install_script('gstd_symbolic_link.sh', get_option('bindir') +'/'+ exe_name, get_option('bindir') +'/'+ gstd_name -) +) \ No newline at end of file diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c new file mode 100644 index 00000000..e21ec53d --- /dev/null +++ b/libgstd/libgstd.c @@ -0,0 +1,48 @@ +/* + * 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 +#include + +#include "libgstd.h" +#include "gstd_ipc.h" +#include "gstd_tcp.h" +#include "gstd_unix.h" +#include "gstd_http.h" +#include "gstd_log.h" + +struct _GstDManager +{ + GstdSession *session; + GstdIpc **ipc_array; + guint num_ipcs; +}; diff --git a/libgstd/meson.build b/libgstd/meson.build index e69de29b..b4834275 100644 --- a/libgstd/meson.build +++ b/libgstd/meson.build @@ -0,0 +1,84 @@ +libgstd_src_files = [ + '../gstd/gstd_object.c', + '../gstd/gstd_pipeline.c', + '../gstd/gstd_element.c', + '../gstd/gstd_list.c', + '../gstd/gstd_ipc.c', + '../gstd/gstd_tcp.c', + '../gstd/gstd_http.c', + '../gstd/gstd_icreator.c', + '../gstd/gstd_iformatter.c', + '../gstd/gstd_pipeline_creator.c', + '../gstd/gstd_no_creator.c', + '../gstd/gstd_json_builder.c', + '../gstd/gstd_ideleter.c', + '../gstd/gstd_pipeline_deleter.c', + '../gstd/gstd_no_deleter.c', + '../gstd/gstd_debug.c', + '../gstd/gstd_event_creator.c', + '../gstd/gstd_event_factory.c', + '../gstd/gstd_pipeline_bus.c', + '../gstd/gstd_ireader.c', + '../gstd/gstd_property_reader.c', + '../gstd/gstd_no_reader.c', + '../gstd/gstd_list_reader.c', + '../gstd/gstd_property.c', + '../gstd/gstd_property_int.c', + '../gstd/gstd_property_string.c', + '../gstd/gstd_property_boolean.c', + '../gstd/gstd_property_array.c', + '../gstd/gstd_iupdater.c', + '../gstd/gstd_no_updater.c', + '../gstd/gstd_property_enum.c', + '../gstd/gstd_property_flags.c', + '../gstd/gstd_event_handler.c', + '../gstd/gstd_bus_msg.c', + '../gstd/gstd_bus_msg_simple.c', + '../gstd/gstd_bus_msg_notify.c', + '../gstd/gstd_bus_msg_state_changed.c', + '../gstd/gstd_msg_reader.c', + '../gstd/gstd_msg_type.c', + '../gstd/gstd_bus_msg_qos.c', + '../gstd/gstd_return_codes.c', + '../gstd/gstd_state.c', + '../gstd/gstd_parser.c', + '../gstd/gstd_log.c', + '../gstd/gstd_bus_msg_stream_status.c', + '../gstd/gstd_bus_msg_element.c', + '../gstd/gstd_signal.c', + '../gstd/gstd_signal_list.c', + '../gstd/gstd_callback.c', + '../gstd/gstd_signal_reader.c', + '../gstd/gstd_session.c', + '../gstd/gstd_socket.c', + '../gstd/gstd_unix.c' +] + +gstd_src = [ + 'libgstd.c' +] + +gstd_headers = [ + 'libgstd.h', +] + +gstd_lib_manager = library('gstd-@0@'.format(apiversion), + [libgstd_src_files, gstd_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_manager_dep = declare_dependency(link_with: gstd_lib_manager, + dependencies : [libgstd_deps]) + +lib_gstd_manager_dir = meson.current_source_dir() \ No newline at end of file diff --git a/meson.build b/meson.build index 05a17eba..426b84f2 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('gstd', 'c', - version : '0.13.0', + version : '0.12.0', meson_version : '>= 0.50',) gstd_version = meson.project_version() @@ -55,6 +55,8 @@ endif gstd_deps = [gst_base_dep, gio_unix_dep, json_glib_dep, libd_dep, jansson_dep, libsoup_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, libd_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 @@ -90,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') @@ -248,4 +251,4 @@ subdir('gst_client') subdir('tests') subdir('examples') subdir('docs') -subdir('init') +subdir('init') \ No newline at end of file From 3ba19eb0c0b245784286e2eb9d488d7b1f5bcd44 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 16 Aug 2021 18:12:05 -0600 Subject: [PATCH 04/13] Implement interface methods to GstD app --- .vscode/settings.json | 5 -- gstd/gstd.c | 116 +++++------------------------- gstd/meson.build | 1 + libgstd/libgstd.c | 150 +++++++++++++++++++++++++++++++++++++++ libgstd/libgstd_assert.c | 47 ++++++++++++ libgstd/libgstd_assert.h | 74 +++++++++++++++++++ libgstd/meson.build | 1 + 7 files changed, 290 insertions(+), 104 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 libgstd/libgstd_assert.c create mode 100644 libgstd/libgstd_assert.h diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index d37494e0..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "libgstd.h": "c" - } -} \ No newline at end of file diff --git a/gstd/gstd.c b/gstd/gstd.c index fb47cf01..20384c12 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -36,17 +36,8 @@ #include "libgstd.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 (); -#define HEADER \ - "\nGstd version " PACKAGE_VERSION "\n" \ - "Copyright (C) 2015-2020 RidgeRun (https://www.ridgerun.com)\n\n" - static void print_header (void) { @@ -70,81 +61,10 @@ int_term_handler (gpointer user_data) 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; @@ -155,20 +75,22 @@ main (gint argc, gchar * argv[]) GError *error = NULL; GOptionContext *context; GOptionGroup *gstreamer_group; + GOptionGroup *ipc_group; gint ret = EXIT_SUCCESS; gchar *current_filename = NULL; + GstDManager *manager; + /* Array to specify gstd how many IPCs are supported, - * IPCs should be added this array. + * SupportedIpcs should be added this array. */ - GType supported_ipcs[] = { - GSTD_TYPE_TCP, - GSTD_TYPE_UNIX, - GSTD_TYPE_HTTP, + SupportedIpcs supported_ipcs[] = { + GSTD_IPC_TYPE_TCP, + GSTD_IPC_TYPE_UNIX, + GSTD_IPC_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 *)); @@ -202,12 +124,15 @@ main (gint argc, gchar * argv[]) g_option_context_add_main_entries (context, entries, NULL); /* Initialize GStreamer */ - gstreamer_group = gst_init_get_option_group (); + gstreamer_group = g_malloc (sizeof (GOptionGroup *)); + gstd_manager_new (supported_ipcs, num_ipcs, &manager, + &gstreamer_group, 0, NULL); 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); + ipc_group = g_malloc (num_ipcs * sizeof (GOptionGroup *)); + gstd_manager_ipc_options (manager, &ipc_group); // If you don't want this option, you can avoid calling this function + g_option_context_add_group (context, ipc_group); /* Parse the options before starting */ if (!g_option_context_parse (context, &argc, &argv, &error)) { @@ -266,11 +191,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_ipc_start (manager)) { goto error; } @@ -292,15 +214,10 @@ main (gint argc, gchar * argv[]) main_loop = NULL; /* Stop any IPC array */ - ipc_stop (ipc_array, num_ipcs); - - /* Free Gstd session */ - g_object_unref (session); + gstd_manager_ipc_stop (manager); - gst_deinit (); gstd_log_deinit (); - g_free (ipc_array); g_free (optiongroup_array); goto out; @@ -316,6 +233,7 @@ main (gint argc, gchar * argv[]) } out: { + gstd_manager_free (manager); return ret; } } diff --git a/gstd/meson.build b/gstd/meson.build index a378b931..59b6a62c 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -117,6 +117,7 @@ libgstd_header_files = [ ] gstd_src = [ + '../libgstd/libgstd_assert.c', '../libgstd/libgstd.c' ] diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c index e21ec53d..4146053b 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -39,6 +39,11 @@ #include "gstd_unix.h" #include "gstd_http.h" #include "gstd_log.h" +#include "libgstd_assert.h" + +static GType gstd_supported_ipc_to_ipc (SupportedIpcs code); +static void gstd_manager_init (GOptionGroup ** gst_group, int argc, + char *argv[]); struct _GstDManager { @@ -46,3 +51,148 @@ struct _GstDManager GstdIpc **ipc_array; guint num_ipcs; }; + +static GType +gstd_supported_ipc_to_ipc (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 *); + + gstd_assert_and_ret_val (0 <= code, GSTD_TYPE_IPC); // TODO: Proponer un GSTD_TYPE_DEFAULT + gstd_assert_and_ret_val (size > code, GSTD_TYPE_IPC); + + return code_description[code]; +} + +static void +gstd_manager_init (GOptionGroup ** gst_group, int argc, char *argv[]) +{ + gst_init (&argc, &argv); + gstd_debug_init (); + + if (gst_group != NULL && *gst_group != NULL) { + *gst_group = gst_init_get_option_group (); + } + +} + +GstdStatus +gstd_manager_new (SupportedIpcs supported_ipcs[], guint num_ipcs, + GstDManager ** out, GOptionGroup ** gst_group, int argc, char *argv[]) +{ + GstDManager *manager; + GstdSession *session; + GstdStatus ret = GSTD_LIB_OK; + GstdIpc **ipc_array; + + gstd_assert_and_ret_val (NULL != out, GSTD_NULL_ARGUMENT); + + manager = (GstDManager *) malloc (sizeof (GstDManager)); + session = gstd_session_new ("Session0"); + + /* If there is ipcs, then initialize them */ + if (NULL != supported_ipcs) { + ipc_array = g_malloc (num_ipcs * sizeof (GstdIpc *)); + for (int i = 0; i < num_ipcs; i++) { + ipc_array[i] = + GSTD_IPC (g_object_new (gstd_supported_ipc_to_ipc (supported_ipcs[i]), + NULL)); + } + manager->ipc_array = ipc_array; + } + + manager->session = session; + manager->num_ipcs = num_ipcs; + + *out = manager; + + /* Initialize GStreamer */ + gstd_manager_init (gst_group, argc, argv); + + return ret; +} + +void +gstd_manager_ipc_options (GstDManager * manager, GOptionGroup ** ipc_group) +{ + gint i; + + gstd_assert_and_ret (NULL != manager); + gstd_assert_and_ret (NULL != manager->ipc_array); + gstd_assert_and_ret (NULL != ipc_group); + + for (i = 0; i < manager->num_ipcs; i++) { + gstd_ipc_get_option_group (manager->ipc_array[i], &ipc_group[i]); + } +} + +gboolean +gstd_manager_ipc_start (GstDManager * manager) +{ + gboolean ipc_selected = FALSE; + gboolean ret = TRUE; + GstdReturnCode code; + gint i; + + gstd_assert_and_ret_val (NULL != manager, GSTD_NULL_ARGUMENT); + gstd_assert_and_ret_val (NULL != manager->ipc_array, GSTD_LIB_NOT_FOUND); + gstd_assert_and_ret_val (NULL != manager->session, GSTD_LIB_NOT_FOUND); + + /* Verify if at least one IPC mechanism was selected */ + for (i = 0; i < manager->num_ipcs; i++) { + g_object_get (G_OBJECT (manager->ipc_array[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 (manager->ipc_array[0]), "enabled", TRUE, NULL); + } + + /* Run start for each IPC (each start method checks for the enabled flag) */ + for (i = 0; i < manager->num_ipcs; i++) { + code = gstd_ipc_start (manager->ipc_array[i], manager->session); + if (code) { + g_printerr ("Couldn't start IPC : (%s)\n", + G_OBJECT_TYPE_NAME (manager->ipc_array[i])); + ret = FALSE; + } + } + + return ret; +} + +void +gstd_manager_ipc_stop (GstDManager * manager) +{ + gint i; + + gstd_assert_and_ret (NULL != manager); + gstd_assert_and_ret (NULL != manager->ipc_array); + gstd_assert_and_ret (NULL != manager->session); + + /* Run stop for each IPC */ + for (i = 0; i < manager->num_ipcs; i++) { + if (TRUE == manager->ipc_array[i]->enabled) { + gstd_ipc_stop (manager->ipc_array[i]); + g_object_unref (manager->ipc_array[i]); + } + } +} + +void +gstd_manager_free (GstDManager * manager) +{ + gstd_assert_and_ret (NULL != manager); + g_free (manager); + gst_deinit (); +} diff --git a/libgstd/libgstd_assert.c b/libgstd/libgstd_assert.c new file mode 100644 index 00000000..3fc94ca3 --- /dev/null +++ b/libgstd/libgstd_assert.c @@ -0,0 +1,47 @@ +/* + * GStreamer Daemon - gst-launch on steroids + * C client library abstracting gstd interprocess communication + * + * Copyright (c) 2015-2018 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. + */ + +#include +#include + +#include "libgstd_assert.h" + +void +_gstd_assert (int cond, const char *scond, const char *file, + const char *function, int line) +{ + if (0 == cond) { + fprintf (stderr, "**libgstd**: %s:%s:%d: \"%s\" failed!\n", file, + function, line, scond); + gstd_abort (); + } +} diff --git a/libgstd/libgstd_assert.h b/libgstd/libgstd_assert.h new file mode 100644 index 00000000..706a20e8 --- /dev/null +++ b/libgstd/libgstd_assert.h @@ -0,0 +1,74 @@ +/* + * 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. + */ + +#ifndef __LIBGSTD_ASSERT_H__ +#define __LIBGSTD_ASSERT_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef LIBGSTD_CHECKS_CRITICAL +#define gstd_abort() abort() +#else +#define gstd_abort() +#endif + +#ifdef LIBGST_CHECKS_DISABLE +#define gstd_assert_and_ret(cond) +#define gstd_assert_and_ret_val(cond, val) +#define gstd_assert(cond) +#else + +#define gstd_assert_and_ret(cond) \ + _gstd_assert ((cond), #cond, __FILE__, __FUNCTION__, __LINE__); \ + if (!(cond)) return + +#define gstd_assert_and_ret_val(cond, val) \ + _gstd_assert ((cond), #cond, __FILE__, __FUNCTION__, __LINE__); \ + if (!(cond)) return (val) + +#define gstd_assert(cond) \ + _gstd_assert ((cond), #cond, __FILE__, __FUNCTION__, __LINE__) + +void +_gstd_assert (int cond, const char *scond, const char *file, + const char *function, int line); + +#endif // LIBGSTD_CHECKS_DISABLE + +#ifdef __cplusplus +} +#endif + +#endif // __LIBGSTD_ASSERT_H__ \ No newline at end of file diff --git a/libgstd/meson.build b/libgstd/meson.build index b4834275..cf3853d2 100644 --- a/libgstd/meson.build +++ b/libgstd/meson.build @@ -55,6 +55,7 @@ libgstd_src_files = [ ] gstd_src = [ + 'libgstd_assert.c', 'libgstd.c' ] From 023ecf272af72dda505e3a00abc2c3b7cb8061bd Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 16 Aug 2021 19:26:23 -0600 Subject: [PATCH 05/13] Fix version number --- init/gstd | 49 ----------------------------------------------- init/gstd.service | 13 ------------- meson.build | 2 +- 3 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 init/gstd delete mode 100644 init/gstd.service diff --git a/init/gstd b/init/gstd deleted file mode 100644 index 55a24bcc..00000000 --- a/init/gstd +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -### BEGIN INIT INFO -# Provides: GstD -# Short-Description: start and stop GstD -# Description: Gstreamer Daemon is a framework for -# controlling audio and video streaming -### END INIT INFO - -manage_dir() -{ - dir="$1"; - mode="$2"; - user="$3"; - - #Create directory if not created yet - mkdir -m "$mode" -p "$dir"; - if [ $? -ne 0 ]; then - echo "GstD init: Error, cannot create directory $dir" 1>&2; - exit 1 - fi - - #Set the owner - chown -R "$user" "$dir"; - if [ $? -ne 0 ]; then - echo "GstD init: Error, cannot change $dir owner to $user" 1>&2; - exit 1 - fi -} - -prefix=/usr/local -gstdrunstatedir=${prefix}/var/run/gstd/ -gstdlogstatedir=${prefix}/var/log/gstd/ - -case "$1" in - start) - #Manage pid and log directories - manage_dir "$gstdrunstatedir" 777 root - manage_dir "$gstdlogstatedir" 777 root - - #Start gstd - /usr/local/bin/gstd -e; - ;; - stop) - /usr/local/bin/gstd -k; - ;; - *) - echo "$0 {start|stop}" -esac diff --git a/init/gstd.service b/init/gstd.service deleted file mode 100644 index 99ff4fcc..00000000 --- a/init/gstd.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=GStreamer Daemon -StartLimitBurst=3 -StartLimitIntervalSec=30 - -[Service] -Restart=on-failure -RestartSec=5s -ExecStartPre=/usr/lib/systemd/user/gstd-check-user-xenv.sh -ExecStart=/usr/local/bin/gstd - -[Install] -WantedBy=default.target diff --git a/meson.build b/meson.build index 426b84f2..ccf65ba5 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('gstd', 'c', - version : '0.12.0', + version : '0.13.0', meson_version : '>= 0.50',) gstd_version = meson.project_version() From d0a7576e1cb94c24f8cf6bb857f152277d526c91 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 16 Aug 2021 22:11:46 -0600 Subject: [PATCH 06/13] Build libgstd using AutoTools --- Makefile.am | 1 + configure.ac | 1 + gstd/Makefile.am | 10 +++++++--- libgstd/Makefile.am | 26 ++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 libgstd/Makefile.am diff --git a/Makefile.am b/Makefile.am index 0206d810..6388e01f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,6 +3,7 @@ ACLOCAL_AMFLAGS=-I m4 -I . SUBDIRS=gstd \ gst_client \ libgstc \ + libgstd \ 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..b78fe1af 100644 --- a/gstd/Makefile.am +++ b/gstd/Makefile.am @@ -53,7 +53,10 @@ libgstd_core_la_SOURCES = gstd_session.c \ gstd_signal_reader.c \ gstd_socket.c \ gstd_unix.c \ - gstd_signal_list.c + gstd_signal_list.c \ + ../libgstd/libgstd_assert.c \ + ../libgstd/libgstd.c + libgstd_core_la_CFLAGS = $(GST_CFLAGS) \ $(GIO_CFLAGS) \ @@ -71,6 +74,7 @@ bin_PROGRAMS = gstd gstd_SOURCES = gstd.c gstd_daemon.c gstd_CFLAGS = $(GST_CFLAGS) \ + -I$(top_srcdir)/libgstd/ \ $(GIO_CFLAGS) \ $(LIBSOUP_CFLAGS) \ $(GIO_UNIX_CFLAGS) \ @@ -87,7 +91,7 @@ gstd_LDFLAGS = $(GST_LIBS) \ $(LIBSOUP_LIBS) \ -Wl,-rpath -Wl,$(libdir) -gstd_LDADD = libgstd-core.la +gstd_LDADD = libgstd-core.la $(top_srcdir)/libgstd/libgstd.h gstdincludedir = $(includedir)/gstd gstdinclude_HEADERS = \ @@ -144,4 +148,4 @@ install-data-hook: $(DESTDIR)$(GSTD_RUN_STATE_DIR) $(DESTDIR)$(GSTD_LOG_STATE_DI $(DESTDIR)@GSTD_RUN_STATE_DIR@ $(DESTDIR)@GSTD_LOG_STATE_DIR@: $(MKDIR_P) $@ - chmod a+w $@ + chmod a+w $@ \ No newline at end of file diff --git a/libgstd/Makefile.am b/libgstd/Makefile.am new file mode 100644 index 00000000..c83ee3e8 --- /dev/null +++ b/libgstd/Makefile.am @@ -0,0 +1,26 @@ +lib_LTLIBRARIES = libgstd-@GSTD_API_VERSION@.la + +gstdincludedir = $(includedir)/gstd +gstdinclude_HEADERS = libgstd.h + +libgstd_@GSTD_API_VERSION@_la_SOURCES = \ + libgstd.c \ + libgstd_assert.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 + +LDADD = $(top_srcdir)/gstd/libgstd-core.la + +noinst_HEADERS = \ + libgstd_assert.h + From 9f4490138c8892b1c86008134438b2ab405c9b0f Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Thu, 19 Aug 2021 12:11:05 -0600 Subject: [PATCH 07/13] Applying PR changes to gstd manager * Updating copyright year * Fixing leak for manager * Adding new line at the end of files * Sorting alphabetically include headers " Fixing and adding comments * Fixing redundant variable for meson.build --- gstd/Makefile.am | 198 +++++++++++++++++++-------------------- gstd/gstd.c | 16 ++-- gstd/meson.build | 60 +----------- libgstd/libgstd.c | 30 +++--- libgstd/libgstd.h | 26 ++--- libgstd/libgstd_assert.c | 2 +- libgstd/libgstd_assert.h | 2 +- libgstd/meson.build | 58 +----------- meson.build | 58 +++++++++++- 9 files changed, 198 insertions(+), 252 deletions(-) diff --git a/gstd/Makefile.am b/gstd/Makefile.am index b78fe1af..a4986f2f 100644 --- a/gstd/Makefile.am +++ b/gstd/Makefile.am @@ -1,64 +1,64 @@ # 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 \ +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_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 \ + 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/libgstd_assert.c \ ../libgstd/libgstd.c -libgstd_core_la_CFLAGS = $(GST_CFLAGS) \ +libgstd_core_la_CFLAGS = $(GST_CFLAGS) \ $(GIO_CFLAGS) \ $(GIO_UNIX_CFLAGS) \ $(LIBSOUP_CFLAGS) \ @@ -74,8 +74,8 @@ bin_PROGRAMS = gstd gstd_SOURCES = gstd.c gstd_daemon.c gstd_CFLAGS = $(GST_CFLAGS) \ - -I$(top_srcdir)/libgstd/ \ - $(GIO_CFLAGS) \ + -I$(top_srcdir)/libgstd/ \ + $(GIO_CFLAGS) \ $(LIBSOUP_CFLAGS) \ $(GIO_UNIX_CFLAGS) \ $(GJSON_CFLAGS) \ @@ -84,10 +84,10 @@ gstd_CFLAGS = $(GST_CFLAGS) \ -DGSTD_RUN_STATE_DIR=\"$(GSTD_RUN_STATE_DIR)\" gstd_LDFLAGS = $(GST_LIBS) \ - $(GIO_LIBS) \ + $(GIO_LIBS) \ $(GIO_UNIX_LIBS) \ $(GJSON_LIBS) \ - $(LIBD_LIBS) \ + $(LIBD_LIBS) \ $(LIBSOUP_LIBS) \ -Wl,-rpath -Wl,$(libdir) @@ -95,50 +95,50 @@ gstd_LDADD = libgstd-core.la $(top_srcdir)/libgstd/libgstd.h 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_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_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_bus_msg_element.h \ gstd_signal_list.h noinst_HEADERS = gstd_daemon.h @@ -148,4 +148,4 @@ install-data-hook: $(DESTDIR)$(GSTD_RUN_STATE_DIR) $(DESTDIR)$(GSTD_LOG_STATE_DI $(DESTDIR)@GSTD_RUN_STATE_DIR@ $(DESTDIR)@GSTD_LOG_STATE_DIR@: $(MKDIR_P) $@ - chmod a+w $@ \ No newline at end of file + chmod a+w $@ diff --git a/gstd/gstd.c b/gstd/gstd.c index 20384c12..7321e4ba 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 @@ -73,13 +73,13 @@ main (gint argc, gchar * argv[]) const gchar *gstlogfile = NULL; gchar *pidfile = NULL; GError *error = NULL; - GOptionContext *context; - GOptionGroup *gstreamer_group; - GOptionGroup *ipc_group; + GOptionContext *context = NULL; + GOptionGroup *gstreamer_group = NULL; + GOptionGroup *ipc_group = NULL; gint ret = EXIT_SUCCESS; gchar *current_filename = NULL; - GstDManager *manager; + GstDManager *manager = NULL; /* Array to specify gstd how many IPCs are supported, * SupportedIpcs should be added this array. @@ -124,14 +124,14 @@ main (gint argc, gchar * argv[]) g_option_context_add_main_entries (context, entries, NULL); /* Initialize GStreamer */ - gstreamer_group = g_malloc (sizeof (GOptionGroup *)); + gstreamer_group = (GOptionGroup *) g_malloc0 (sizeof (gstreamer_group)); /* OptionGroup is assigned inside gstd_manager_new */ gstd_manager_new (supported_ipcs, num_ipcs, &manager, &gstreamer_group, 0, NULL); g_option_context_add_group (context, gstreamer_group); /* Read option group for each IPC */ - ipc_group = g_malloc (num_ipcs * sizeof (GOptionGroup *)); - gstd_manager_ipc_options (manager, &ipc_group); // If you don't want this option, you can avoid calling this function + ipc_group = (GOptionGroup *) g_malloc0 (num_ipcs * sizeof (ipc_group)); + gstd_manager_ipc_options (manager, &ipc_group); /* If you don't want this option, you can avoid calling this function */ g_option_context_add_group (context, ipc_group); /* Parse the options before starting */ diff --git a/gstd/meson.build b/gstd/meson.build index 59b6a62c..025d5554 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -4,62 +4,6 @@ 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', @@ -141,7 +85,7 @@ exe_name = '@0@-@1@'.format(gstd_name, apiversion) executable(exe_name, [gstd_src_files, gstd_src], install: true, - include_directories : [configinc,libgstd_inc_dir], + include_directories : [configinc, libgstd_inc_dir], dependencies : [gstd_deps, lib_gstd_dep], c_args: gst_c_args, ) @@ -171,4 +115,4 @@ meson.add_install_script('gstd_chmod.sh','777', logstatedir) meson.add_install_script('gstd_symbolic_link.sh', get_option('bindir') +'/'+ exe_name, get_option('bindir') +'/'+ gstd_name -) \ No newline at end of file +) diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c index 4146053b..fa2ee488 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -33,12 +33,12 @@ #include #include -#include "libgstd.h" +#include "gstd_http.h" #include "gstd_ipc.h" +#include "gstd_log.h" #include "gstd_tcp.h" #include "gstd_unix.h" -#include "gstd_http.h" -#include "gstd_log.h" +#include "libgstd.h" #include "libgstd_assert.h" static GType gstd_supported_ipc_to_ipc (SupportedIpcs code); @@ -63,7 +63,7 @@ gstd_supported_ipc_to_ipc (SupportedIpcs code) const gint size = sizeof (code_description) / sizeof (gchar *); - gstd_assert_and_ret_val (0 <= code, GSTD_TYPE_IPC); // TODO: Proponer un GSTD_TYPE_DEFAULT + gstd_assert_and_ret_val (0 <= code, GSTD_TYPE_IPC); gstd_assert_and_ret_val (size > code, GSTD_TYPE_IPC); return code_description[code]; @@ -85,20 +85,20 @@ GstdStatus gstd_manager_new (SupportedIpcs supported_ipcs[], guint num_ipcs, GstDManager ** out, GOptionGroup ** gst_group, int argc, char *argv[]) { - GstDManager *manager; - GstdSession *session; GstdStatus ret = GSTD_LIB_OK; - GstdIpc **ipc_array; + GstDManager *manager = NULL; + GstdSession *session = NULL; + GstdIpc **ipc_array = NULL; gstd_assert_and_ret_val (NULL != out, GSTD_NULL_ARGUMENT); - manager = (GstDManager *) malloc (sizeof (GstDManager)); + manager = (GstDManager *) g_malloc0 (sizeof (*manager)); session = gstd_session_new ("Session0"); /* If there is ipcs, then initialize them */ - if (NULL != supported_ipcs) { - ipc_array = g_malloc (num_ipcs * sizeof (GstdIpc *)); - for (int i = 0; i < num_ipcs; i++) { + if (NULL != supported_ipcs && num_ipcs > 0) { + ipc_array = g_malloc0 (num_ipcs * sizeof (*ipc_array)); + for (guint i = 0; i < num_ipcs; i++) { ipc_array[i] = GSTD_IPC (g_object_new (gstd_supported_ipc_to_ipc (supported_ipcs[i]), NULL)); @@ -120,7 +120,7 @@ gstd_manager_new (SupportedIpcs supported_ipcs[], guint num_ipcs, void gstd_manager_ipc_options (GstDManager * manager, GOptionGroup ** ipc_group) { - gint i; + gint i = 0; gstd_assert_and_ret (NULL != manager); gstd_assert_and_ret (NULL != manager->ipc_array); @@ -136,8 +136,8 @@ gstd_manager_ipc_start (GstDManager * manager) { gboolean ipc_selected = FALSE; gboolean ret = TRUE; - GstdReturnCode code; - gint i; + GstdReturnCode code = GSTD_EOK; + gint i = 0; gstd_assert_and_ret_val (NULL != manager, GSTD_NULL_ARGUMENT); gstd_assert_and_ret_val (NULL != manager->ipc_array, GSTD_LIB_NOT_FOUND); @@ -174,7 +174,7 @@ gstd_manager_ipc_start (GstDManager * manager) void gstd_manager_ipc_stop (GstDManager * manager) { - gint i; + gint i = 0; gstd_assert_and_ret (NULL != manager); gstd_assert_and_ret (NULL != manager->ipc_array); diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h index 716e90b2..cbec4269 100644 --- a/libgstd/libgstd.h +++ b/libgstd/libgstd.h @@ -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 @@ -30,7 +30,7 @@ extern "C" #define HEADER \ "\nGstd version " PACKAGE_VERSION "\n" \ - "Copyright (C) 2015-2020 RidgeRun (https://www.ridgerun.com)\n\n" + "Copyright (C) 2015-2021 RidgeRun (https://www.ridgerun.com)\n\n" /* * GstDManager: @@ -41,6 +41,9 @@ typedef struct _GstDManager GstDManager; /** * Supported_IPCs: + * @GSTD_IPC_TYPE_TCP: To enable TCP communication + * @GSTD_IPC_TYPE_UNIX: To enable TCP communication + * @GSTD_IPC_TYPE_HTTP: To enable TCP communication * IPC options for libGstD */ typedef enum _SupportedIpcs SupportedIpcs; /* Used to avoid importing gstd_ipc.h in this file */ @@ -54,14 +57,14 @@ enum _SupportedIpcs /** * GstdStatus: - * @gstd_OK: Everything went okay - * @gstd_NULL_ARGUMENT: A mandatory argument was passed in as NULL - * @gstd_OOM: The system has run out of memory - * @gstd_TYPE_ERROR: An error occurred parsing a type from a string - * @gstd_NOT_FOUND: The response is missing the field requested - * @gstd_THREAD_ERROR: Unable to create a new thread - * @gstd_BUS_TIMEOUT: A timeout was received while waiting on the bus - * @gstd_LONG_RESPONSE: The response exceeds our maximum, typically + * @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 @@ -75,7 +78,6 @@ typedef enum GSTD_LIB_NOT_FOUND = -7, GSTD_LIB_THREAD_ERROR = -11, GSTD_LIB_BUS_TIMEOUT = -12, - GSTD_LIB_SOCKET_TIMEOUT = -13, GSTD_LIB_LONG_RESPONSE = -14 } GstdStatus; @@ -151,4 +153,4 @@ gstd_manager_free (GstDManager * manager); } #endif -#endif // __LIBGSTD_H__ \ No newline at end of file +#endif // __LIBGSTD_H__ diff --git a/libgstd/libgstd_assert.c b/libgstd/libgstd_assert.c index 3fc94ca3..aaf0bfff 100644 --- a/libgstd/libgstd_assert.c +++ b/libgstd/libgstd_assert.c @@ -2,7 +2,7 @@ * GStreamer Daemon - gst-launch on steroids * C client library abstracting gstd interprocess communication * - * Copyright (c) 2015-2018 RidgeRun, LLC (http://www.ridgerun.com) + * 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 diff --git a/libgstd/libgstd_assert.h b/libgstd/libgstd_assert.h index 706a20e8..41384c51 100644 --- a/libgstd/libgstd_assert.h +++ b/libgstd/libgstd_assert.h @@ -71,4 +71,4 @@ _gstd_assert (int cond, const char *scond, const char *file, } #endif -#endif // __LIBGSTD_ASSERT_H__ \ No newline at end of file +#endif // __LIBGSTD_ASSERT_H__ diff --git a/libgstd/meson.build b/libgstd/meson.build index cf3853d2..29c6bd36 100644 --- a/libgstd/meson.build +++ b/libgstd/meson.build @@ -1,59 +1,3 @@ -libgstd_src_files = [ - '../gstd/gstd_object.c', - '../gstd/gstd_pipeline.c', - '../gstd/gstd_element.c', - '../gstd/gstd_list.c', - '../gstd/gstd_ipc.c', - '../gstd/gstd_tcp.c', - '../gstd/gstd_http.c', - '../gstd/gstd_icreator.c', - '../gstd/gstd_iformatter.c', - '../gstd/gstd_pipeline_creator.c', - '../gstd/gstd_no_creator.c', - '../gstd/gstd_json_builder.c', - '../gstd/gstd_ideleter.c', - '../gstd/gstd_pipeline_deleter.c', - '../gstd/gstd_no_deleter.c', - '../gstd/gstd_debug.c', - '../gstd/gstd_event_creator.c', - '../gstd/gstd_event_factory.c', - '../gstd/gstd_pipeline_bus.c', - '../gstd/gstd_ireader.c', - '../gstd/gstd_property_reader.c', - '../gstd/gstd_no_reader.c', - '../gstd/gstd_list_reader.c', - '../gstd/gstd_property.c', - '../gstd/gstd_property_int.c', - '../gstd/gstd_property_string.c', - '../gstd/gstd_property_boolean.c', - '../gstd/gstd_property_array.c', - '../gstd/gstd_iupdater.c', - '../gstd/gstd_no_updater.c', - '../gstd/gstd_property_enum.c', - '../gstd/gstd_property_flags.c', - '../gstd/gstd_event_handler.c', - '../gstd/gstd_bus_msg.c', - '../gstd/gstd_bus_msg_simple.c', - '../gstd/gstd_bus_msg_notify.c', - '../gstd/gstd_bus_msg_state_changed.c', - '../gstd/gstd_msg_reader.c', - '../gstd/gstd_msg_type.c', - '../gstd/gstd_bus_msg_qos.c', - '../gstd/gstd_return_codes.c', - '../gstd/gstd_state.c', - '../gstd/gstd_parser.c', - '../gstd/gstd_log.c', - '../gstd/gstd_bus_msg_stream_status.c', - '../gstd/gstd_bus_msg_element.c', - '../gstd/gstd_signal.c', - '../gstd/gstd_signal_list.c', - '../gstd/gstd_callback.c', - '../gstd/gstd_signal_reader.c', - '../gstd/gstd_session.c', - '../gstd/gstd_socket.c', - '../gstd/gstd_unix.c' -] - gstd_src = [ 'libgstd_assert.c', 'libgstd.c' @@ -82,4 +26,4 @@ pkgconfig.generate(gstd_lib_manager, description : 'GStreamer Manager library to lib_gstd_manager_dep = declare_dependency(link_with: gstd_lib_manager, dependencies : [libgstd_deps]) -lib_gstd_manager_dir = meson.current_source_dir() \ No newline at end of file +lib_gstd_manager_dir = meson.current_source_dir() diff --git a/meson.build b/meson.build index ccf65ba5..832d0647 100644 --- a/meson.build +++ b/meson.build @@ -243,6 +243,63 @@ endif # Meson will generate a header file all the entries in the configuration data object configure_file(output : 'config.h', configuration : cdata) +# Common files needed for GstD and libGstD +libgstd_src_files = [ + '../gstd/gstd_object.c', + '../gstd/gstd_pipeline.c', + '../gstd/gstd_element.c', + '../gstd/gstd_list.c', + '../gstd/gstd_ipc.c', + '../gstd/gstd_tcp.c', + '../gstd/gstd_http.c', + '../gstd/gstd_icreator.c', + '../gstd/gstd_iformatter.c', + '../gstd/gstd_pipeline_creator.c', + '../gstd/gstd_no_creator.c', + '../gstd/gstd_json_builder.c', + '../gstd/gstd_ideleter.c', + '../gstd/gstd_pipeline_deleter.c', + '../gstd/gstd_no_deleter.c', + '../gstd/gstd_debug.c', + '../gstd/gstd_event_creator.c', + '../gstd/gstd_event_factory.c', + '../gstd/gstd_pipeline_bus.c', + '../gstd/gstd_ireader.c', + '../gstd/gstd_property_reader.c', + '../gstd/gstd_no_reader.c', + '../gstd/gstd_list_reader.c', + '../gstd/gstd_property.c', + '../gstd/gstd_property_int.c', + '../gstd/gstd_property_string.c', + '../gstd/gstd_property_boolean.c', + '../gstd/gstd_property_array.c', + '../gstd/gstd_iupdater.c', + '../gstd/gstd_no_updater.c', + '../gstd/gstd_property_enum.c', + '../gstd/gstd_property_flags.c', + '../gstd/gstd_event_handler.c', + '../gstd/gstd_bus_msg.c', + '../gstd/gstd_bus_msg_simple.c', + '../gstd/gstd_bus_msg_notify.c', + '../gstd/gstd_bus_msg_state_changed.c', + '../gstd/gstd_msg_reader.c', + '../gstd/gstd_msg_type.c', + '../gstd/gstd_bus_msg_qos.c', + '../gstd/gstd_return_codes.c', + '../gstd/gstd_state.c', + '../gstd/gstd_parser.c', + '../gstd/gstd_log.c', + '../gstd/gstd_bus_msg_stream_status.c', + '../gstd/gstd_bus_msg_element.c', + '../gstd/gstd_signal.c', + '../gstd/gstd_signal_list.c', + '../gstd/gstd_callback.c', + '../gstd/gstd_signal_reader.c', + '../gstd/gstd_session.c', + '../gstd/gstd_socket.c', + '../gstd/gstd_unix.c' +] + # Enter to each subdirectory and execute the meson.build subdir('gstd') subdir('libgstc') @@ -251,4 +308,3 @@ subdir('gst_client') subdir('tests') subdir('examples') subdir('docs') -subdir('init') \ No newline at end of file From 9007fadaf89195282896d4ee9f6fb63ecf678167 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Thu, 19 Aug 2021 12:11:05 -0600 Subject: [PATCH 08/13] Applying PR changes to gstd manager * Updating copyright year * Fixing leak for manager * Adding new line at the end of files * Sorting alphabetically include headers " Fixing and adding comments * Fixing redundant variable for meson.build * Fixing spacing * Fixing wrong memory allocation --- gstd/Makefile.am | 239 ++++++++++++++++++++------------------- gstd/gstd.c | 21 ++-- gstd/meson.build | 6 +- libgstd/Makefile.am | 23 ++-- libgstd/libgstd.c | 22 ++-- libgstd/libgstd.h | 8 +- libgstd/libgstd_assert.c | 4 +- libgstd/meson.build | 5 - meson.build | 5 + 9 files changed, 169 insertions(+), 164 deletions(-) diff --git a/gstd/Makefile.am b/gstd/Makefile.am index a4986f2f..c9695cda 100644 --- a/gstd/Makefile.am +++ b/gstd/Makefile.am @@ -1,69 +1,71 @@ # 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 \ +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/libgstd_assert.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/libgstd_assert.c \ ../libgstd/libgstd.c -libgstd_core_la_CFLAGS = $(GST_CFLAGS) \ - $(GIO_CFLAGS) \ - $(GIO_UNIX_CFLAGS) \ - $(LIBSOUP_CFLAGS) \ - $(GJSON_CFLAGS) \ - -DGSTD_LOG_STATE_DIR=\"$(GSTD_LOG_STATE_DIR)\" \ +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) @@ -73,72 +75,73 @@ bin_PROGRAMS = gstd gstd_SOURCES = gstd.c gstd_daemon.c -gstd_CFLAGS = $(GST_CFLAGS) \ - -I$(top_srcdir)/libgstd/ \ - $(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/ \ + $(GIO_CFLAGS) \ + $(LIBSOUP_CFLAGS) \ + $(GIO_UNIX_CFLAGS) \ + $(GJSON_CFLAGS) \ + $(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) \ + $(GIO_LIBS) \ + $(GIO_UNIX_LIBS) \ + $(GJSON_LIBS) \ + $(LIBD_LIBS) \ + $(LIBSOUP_LIBS) \ -Wl,-rpath -Wl,$(libdir) gstd_LDADD = libgstd-core.la $(top_srcdir)/libgstd/libgstd.h 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 \ +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 noinst_HEADERS = gstd_daemon.h diff --git a/gstd/gstd.c b/gstd/gstd.c index 7321e4ba..26ffd727 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -56,6 +56,7 @@ 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; @@ -75,7 +76,7 @@ main (gint argc, gchar * argv[]) GError *error = NULL; GOptionContext *context = NULL; GOptionGroup *gstreamer_group = NULL; - GOptionGroup *ipc_group = NULL; + GOptionGroup **ipc_group_array = NULL; gint ret = EXIT_SUCCESS; gchar *current_filename = NULL; @@ -84,15 +85,13 @@ main (gint argc, gchar * argv[]) /* Array to specify gstd how many IPCs are supported, * SupportedIpcs should be added this array. */ - SupportedIpcs supported_ipcs[] = { + const SupportedIpcs supported_ipcs[] = { GSTD_IPC_TYPE_TCP, GSTD_IPC_TYPE_UNIX, GSTD_IPC_TYPE_HTTP, }; - guint num_ipcs = (sizeof (supported_ipcs) / sizeof (GType)); - GOptionGroup **optiongroup_array = - g_malloc (num_ipcs * sizeof (GOptionGroup *)); + const guint num_ipcs = (sizeof (supported_ipcs) / sizeof (SupportedIpcs)); GOptionEntry entries[] = { {"version", 'v', 0, G_OPTION_ARG_NONE, &version, @@ -124,15 +123,16 @@ main (gint argc, gchar * argv[]) g_option_context_add_main_entries (context, entries, NULL); /* Initialize GStreamer */ - gstreamer_group = (GOptionGroup *) g_malloc0 (sizeof (gstreamer_group)); /* OptionGroup is assigned inside gstd_manager_new */ gstd_manager_new (supported_ipcs, num_ipcs, &manager, &gstreamer_group, 0, NULL); g_option_context_add_group (context, gstreamer_group); /* Read option group for each IPC */ - ipc_group = (GOptionGroup *) g_malloc0 (num_ipcs * sizeof (ipc_group)); - gstd_manager_ipc_options (manager, &ipc_group); /* If you don't want this option, you can avoid calling this function */ - g_option_context_add_group (context, ipc_group); + ipc_group_array = g_malloc0 (num_ipcs * sizeof (*ipc_group_array)); + gstd_manager_ipc_options (manager, ipc_group_array); /* If you don't want this option, you can avoid calling this function */ + for (int i = 0; i < num_ipcs; i++) { + g_option_context_add_group (context, ipc_group_array[i]); + } /* Parse the options before starting */ if (!g_option_context_parse (context, &argc, &argv, &error)) { @@ -218,8 +218,6 @@ main (gint argc, gchar * argv[]) gstd_log_deinit (); - g_free (optiongroup_array); - goto out; error: @@ -233,6 +231,7 @@ main (gint argc, gchar * argv[]) } out: { + g_free (ipc_group_array); gstd_manager_free (manager); return ret; } diff --git a/gstd/meson.build b/gstd/meson.build index 025d5554..650cd5ee 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -5,6 +5,7 @@ gstd_src_files = [ 'gstd.c' ] +# Library source files libgstd_header_files = [ 'gstd_bus_msg_element.h', 'gstd_bus_msg.h', @@ -60,11 +61,6 @@ libgstd_header_files = [ 'gstd_unix.h' ] -gstd_src = [ - '../libgstd/libgstd_assert.c', - '../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, diff --git a/libgstd/Makefile.am b/libgstd/Makefile.am index c83ee3e8..0ebf59cd 100644 --- a/libgstd/Makefile.am +++ b/libgstd/Makefile.am @@ -3,18 +3,19 @@ lib_LTLIBRARIES = libgstd-@GSTD_API_VERSION@.la gstdincludedir = $(includedir)/gstd gstdinclude_HEADERS = libgstd.h -libgstd_@GSTD_API_VERSION@_la_SOURCES = \ - libgstd.c \ - libgstd_assert.c +libgstd_@GSTD_API_VERSION@_la_SOURCES = \ + libgstd.c \ + libgstd_assert.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)\" \ +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/libgstd/libgstd.c b/libgstd/libgstd.c index fa2ee488..12e32f86 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -30,6 +30,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE + +#include "libgstd.h" + #include #include @@ -38,10 +41,9 @@ #include "gstd_log.h" #include "gstd_tcp.h" #include "gstd_unix.h" -#include "libgstd.h" #include "libgstd_assert.h" -static GType gstd_supported_ipc_to_ipc (SupportedIpcs code); +static GType gstd_supported_ipc_to_ipc (const SupportedIpcs code); static void gstd_manager_init (GOptionGroup ** gst_group, int argc, char *argv[]); @@ -53,7 +55,7 @@ struct _GstDManager }; static GType -gstd_supported_ipc_to_ipc (SupportedIpcs code) +gstd_supported_ipc_to_ipc (const SupportedIpcs code) { GType code_description[] = { [GSTD_IPC_TYPE_TCP] = GSTD_TYPE_TCP, @@ -75,14 +77,15 @@ gstd_manager_init (GOptionGroup ** gst_group, int argc, char *argv[]) gst_init (&argc, &argv); gstd_debug_init (); - if (gst_group != NULL && *gst_group != NULL) { + if (gst_group != NULL) { + g_free (*gst_group); *gst_group = gst_init_get_option_group (); } } GstdStatus -gstd_manager_new (SupportedIpcs supported_ipcs[], guint num_ipcs, +gstd_manager_new (const SupportedIpcs supported_ipcs[], const guint num_ipcs, GstDManager ** out, GOptionGroup ** gst_group, int argc, char *argv[]) { GstdStatus ret = GSTD_LIB_OK; @@ -118,7 +121,7 @@ gstd_manager_new (SupportedIpcs supported_ipcs[], guint num_ipcs, } void -gstd_manager_ipc_options (GstDManager * manager, GOptionGroup ** ipc_group) +gstd_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]) { gint i = 0; @@ -182,9 +185,9 @@ gstd_manager_ipc_stop (GstDManager * manager) /* Run stop for each IPC */ for (i = 0; i < manager->num_ipcs; i++) { - if (TRUE == manager->ipc_array[i]->enabled) { + if (NULL != manager->ipc_array[i] && TRUE == manager->ipc_array[i]->enabled) { gstd_ipc_stop (manager->ipc_array[i]); - g_object_unref (manager->ipc_array[i]); + g_clear_object (&manager->ipc_array[i]); } } } @@ -193,6 +196,9 @@ void gstd_manager_free (GstDManager * manager) { gstd_assert_and_ret (NULL != manager); + gstd_manager_ipc_stop (manager); + g_free (manager->ipc_array); + g_object_unref (manager->session); g_free (manager); gst_deinit (); } diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h index cbec4269..f51ff458 100644 --- a/libgstd/libgstd.h +++ b/libgstd/libgstd.h @@ -29,7 +29,7 @@ extern "C" #include #define HEADER \ - "\nGstd version " PACKAGE_VERSION "\n" \ + "\nGstD version " PACKAGE_VERSION "\n" \ "Copyright (C) 2015-2021 RidgeRun (https://www.ridgerun.com)\n\n" /* @@ -86,7 +86,7 @@ typedef enum * gstd_manager_new: * * @supported_ipcs: ipcs the user will use - * @num_ipcs: lenght of supported_ipcs + * @num_ipcs: length of supported_ipcs * @out: placeholder for newly allocated gstd manager. * @gst_group: placeholder for GStreamer's argument specifications * @argc: arguments for gst_init @@ -99,7 +99,7 @@ typedef enum * Returns: GstdStatus indicating success or fail */ GstdStatus -gstd_manager_new (SupportedIpcs supported_ipcs[], uint num_ipcs, +gstd_manager_new (const SupportedIpcs supported_ipcs[], const uint num_ipcs, GstDManager ** out, GOptionGroup **gst_group, int argc, char *argv[]); /** @@ -111,7 +111,7 @@ gstd_manager_new (SupportedIpcs supported_ipcs[], uint num_ipcs, * */ void -gstd_manager_ipc_options (GstDManager * manager, GOptionGroup **ipc_group); +gstd_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]); /** * gstd_manager_ipc_start: diff --git a/libgstd/libgstd_assert.c b/libgstd/libgstd_assert.c index aaf0bfff..552a960a 100644 --- a/libgstd/libgstd_assert.c +++ b/libgstd/libgstd_assert.c @@ -30,11 +30,11 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "libgstd_assert.h" + #include #include -#include "libgstd_assert.h" - void _gstd_assert (int cond, const char *scond, const char *file, const char *function, int line) diff --git a/libgstd/meson.build b/libgstd/meson.build index 29c6bd36..f34a32d3 100644 --- a/libgstd/meson.build +++ b/libgstd/meson.build @@ -1,8 +1,3 @@ -gstd_src = [ - 'libgstd_assert.c', - 'libgstd.c' -] - gstd_headers = [ 'libgstd.h', ] diff --git a/meson.build b/meson.build index 832d0647..4ba65d6d 100644 --- a/meson.build +++ b/meson.build @@ -300,6 +300,11 @@ libgstd_src_files = [ '../gstd/gstd_unix.c' ] +gstd_src = [ + '../libgstd/libgstd_assert.c', + '../libgstd/libgstd.c' +] + # Enter to each subdirectory and execute the meson.build subdir('gstd') subdir('libgstc') From 2e848e5288135165acd47acbe508a0e06d996721 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 30 Aug 2021 12:35:13 -0600 Subject: [PATCH 09/13] Add method to get GStreamer options --- gstd/gstd.c | 4 ++-- libgstd/libgstd.c | 19 +++++++++---------- libgstd/libgstd.h | 10 +++++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/gstd/gstd.c b/gstd/gstd.c index 26ffd727..c7901e36 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -123,8 +123,8 @@ main (gint argc, gchar * argv[]) g_option_context_add_main_entries (context, entries, NULL); /* Initialize GStreamer */ - gstd_manager_new (supported_ipcs, num_ipcs, &manager, - &gstreamer_group, 0, NULL); + gstreamer_group = gstd_init_get_option_group (); + gstd_manager_new (supported_ipcs, num_ipcs, &manager, 0, NULL); g_option_context_add_group (context, gstreamer_group); /* Read option group for each IPC */ diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c index 12e32f86..91a9f96c 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -44,8 +44,7 @@ #include "libgstd_assert.h" static GType gstd_supported_ipc_to_ipc (const SupportedIpcs code); -static void gstd_manager_init (GOptionGroup ** gst_group, int argc, - char *argv[]); +static void gstd_manager_init (int argc, char *argv[]); struct _GstDManager { @@ -72,21 +71,21 @@ gstd_supported_ipc_to_ipc (const SupportedIpcs code) } static void -gstd_manager_init (GOptionGroup ** gst_group, int argc, char *argv[]) +gstd_manager_init (int argc, char *argv[]) { gst_init (&argc, &argv); gstd_debug_init (); +} - if (gst_group != NULL) { - g_free (*gst_group); - *gst_group = gst_init_get_option_group (); - } - +GOptionGroup * +gstd_init_get_option_group (void) +{ + return gst_init_get_option_group (); } GstdStatus gstd_manager_new (const SupportedIpcs supported_ipcs[], const guint num_ipcs, - GstDManager ** out, GOptionGroup ** gst_group, int argc, char *argv[]) + GstDManager ** out, int argc, char *argv[]) { GstdStatus ret = GSTD_LIB_OK; GstDManager *manager = NULL; @@ -115,7 +114,7 @@ gstd_manager_new (const SupportedIpcs supported_ipcs[], const guint num_ipcs, *out = manager; /* Initialize GStreamer */ - gstd_manager_init (gst_group, argc, argv); + gstd_manager_init (argc, argv); return ret; } diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h index f51ff458..6740263d 100644 --- a/libgstd/libgstd.h +++ b/libgstd/libgstd.h @@ -82,6 +82,14 @@ typedef enum } GstdStatus; +/** + * gstd_init_get_option_group: + * + * Returns: A GOptionGroup with GStreamer's argument specification. + * + */ +GOptionGroup* gstd_init_get_option_group (void); + /** * gstd_manager_new: * @@ -100,7 +108,7 @@ typedef enum */ GstdStatus gstd_manager_new (const SupportedIpcs supported_ipcs[], const uint num_ipcs, - GstDManager ** out, GOptionGroup **gst_group, int argc, char *argv[]); + GstDManager ** out, int argc, char *argv[]); /** * gstd_manager_ipc_options: From e83c94920bb33846ff0642dcf070fc5fd124e4f6 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Mon, 30 Aug 2021 18:30:15 -0600 Subject: [PATCH 10/13] Optimize Meson and Autotools files Remove lib-core library from Meson and Autotools lib-core library is replaced by libgstd Remove not required dependencies for gstd application in Meson and Autotools --- Makefile.am | 5 +-- gstd/Makefile.am | 76 ++-------------------------------------- gstd/gstd.c | 3 +- gstd/meson.build | 17 +-------- libgstd/Makefile.am | 62 ++++++++++++++++++++++++++++---- libgstd/libgstd.c | 75 ++++++++++++++++++++++----------------- libgstd/libgstd.h | 25 ++++++++----- libgstd/libgstd_assert.h | 4 +-- libgstd/meson.build | 68 ++++++++++++++++++++++++++++++++--- meson.build | 68 ++--------------------------------- tests/gstd/Makefile.am | 2 +- tests/gstd/meson.build | 2 +- 12 files changed, 194 insertions(+), 213 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6388e01f..5c6d97bf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,10 @@ ACLOCAL_AMFLAGS=-I m4 -I . -SUBDIRS=gstd \ +SUBDIRS= \ + libgstd \ gst_client \ libgstc \ - libgstd \ + gstd \ tests \ examples \ docs \ diff --git a/gstd/Makefile.am b/gstd/Makefile.am index c9695cda..63105277 100644 --- a/gstd/Makefile.am +++ b/gstd/Makefile.am @@ -1,76 +1,4 @@ -# 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/libgstd_assert.c \ - ../libgstd/libgstd.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 @@ -94,7 +22,7 @@ gstd_LDFLAGS = $(GST_LIBS) \ $(LIBSOUP_LIBS) \ -Wl,-rpath -Wl,$(libdir) -gstd_LDADD = libgstd-core.la $(top_srcdir)/libgstd/libgstd.h +gstd_LDADD = $(top_srcdir)/libgstd/libgstd-1.0.la gstdincludedir = $(includedir)/gstd gstdinclude_HEADERS = \ diff --git a/gstd/gstd.c b/gstd/gstd.c index c7901e36..e46e8cfa 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -124,8 +124,9 @@ main (gint argc, gchar * argv[]) /* Initialize GStreamer */ gstreamer_group = gstd_init_get_option_group (); - gstd_manager_new (supported_ipcs, num_ipcs, &manager, 0, NULL); + gstd_manager_new (&manager, 0, NULL); g_option_context_add_group (context, gstreamer_group); + gstd_manager_set_ipc (manager, supported_ipcs, num_ipcs); /* Read option group for each IPC */ ipc_group_array = g_malloc0 (num_ipcs * sizeof (*ipc_group_array)); diff --git a/gstd/meson.build b/gstd/meson.build index 650cd5ee..a8c836a4 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -61,25 +61,10 @@ libgstd_header_files = [ 'gstd_unix.h' ] -# 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], + [gstd_src_files], install: true, include_directories : [configinc, libgstd_inc_dir], dependencies : [gstd_deps, lib_gstd_dep], diff --git a/libgstd/Makefile.am b/libgstd/Makefile.am index 0ebf59cd..9a4e21ec 100644 --- a/libgstd/Makefile.am +++ b/libgstd/Makefile.am @@ -3,9 +3,62 @@ lib_LTLIBRARIES = libgstd-@GSTD_API_VERSION@.la gstdincludedir = $(includedir)/gstd gstdinclude_HEADERS = libgstd.h -libgstd_@GSTD_API_VERSION@_la_SOURCES = \ - libgstd.c \ - libgstd_assert.c +libgstd_@GSTD_API_VERSION@_la_SOURCES = \ + libgstd.c \ + libgstd_assert.c \ + ../gstd/gstd_session.c \ + ../gstd/gstd_object.c \ + ../gstd/gstd_pipeline.c \ + ../gstd/gstd_element.c \ + ../gstd/gstd_list.c \ + ../gstd/gstd_ipc.c \ + ../gstd/gstd_tcp.c \ + ../gstd/gstd_http.c \ + ../gstd/gstd_icreator.c \ + ../gstd/gstd_iformatter.c \ + ../gstd/gstd_pipeline_creator.c \ + ../gstd/gstd_no_creator.c \ + ../gstd/gstd_json_builder.c \ + ../gstd/gstd_ideleter.c \ + ../gstd/gstd_pipeline_deleter.c \ + ../gstd/gstd_no_deleter.c \ + ../gstd/gstd_debug.c \ + ../gstd/gstd_event_creator.c \ + ../gstd/gstd_event_factory.c \ + ../gstd/gstd_pipeline_bus.c \ + ../gstd/gstd_ireader.c \ + ../gstd/gstd_property_reader.c \ + ../gstd/gstd_no_reader.c \ + ../gstd/gstd_list_reader.c \ + ../gstd/gstd_property.c \ + ../gstd/gstd_property_int.c \ + ../gstd/gstd_property_string.c \ + ../gstd/gstd_property_boolean.c \ + ../gstd/gstd_property_array.c \ + ../gstd/gstd_iupdater.c \ + ../gstd/gstd_no_updater.c \ + ../gstd/gstd_property_enum.c \ + ../gstd/gstd_property_flags.c \ + ../gstd/gstd_event_handler.c \ + ../gstd/gstd_bus_msg.c \ + ../gstd/gstd_bus_msg_simple.c \ + ../gstd/gstd_bus_msg_notify.c \ + ../gstd/gstd_bus_msg_state_changed.c \ + ../gstd/gstd_msg_reader.c \ + ../gstd/gstd_msg_type.c \ + ../gstd/gstd_bus_msg_qos.c \ + ../gstd/gstd_return_codes.c \ + ../gstd/gstd_state.c \ + ../gstd/gstd_parser.c \ + ../gstd/gstd_log.c \ + ../gstd/gstd_bus_msg_stream_status.c \ + ../gstd/gstd_bus_msg_element.c \ + ../gstd/gstd_signal.c \ + ../gstd/gstd_callback.c \ + ../gstd/gstd_signal_reader.c \ + ../gstd/gstd_socket.c \ + ../gstd/gstd_unix.c \ + ../gstd/gstd_signal_list.c libgstd_@GSTD_API_VERSION@_la_CFLAGS = \ $(GST_CFLAGS) \ @@ -20,8 +73,5 @@ libgstd_@GSTD_API_VERSION@_la_CFLAGS = \ libgstd_@GSTD_API_VERSION@_la_LDFLAGS = $(GST_LIBS) $(GIO_LIBS) $(GJSON_LIBS) $(LIBSOUP_LIBS) $(JANSSON_LIBS) -pthread -LDADD = $(top_srcdir)/gstd/libgstd-core.la - noinst_HEADERS = \ libgstd_assert.h - diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c index 91a9f96c..85269346 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -84,32 +84,20 @@ gstd_init_get_option_group (void) } GstdStatus -gstd_manager_new (const SupportedIpcs supported_ipcs[], const guint num_ipcs, - GstDManager ** out, int argc, char *argv[]) +gstd_manager_new (GstDManager ** out, int argc, char *argv[]) { GstdStatus ret = GSTD_LIB_OK; GstDManager *manager = NULL; GstdSession *session = NULL; - GstdIpc **ipc_array = NULL; gstd_assert_and_ret_val (NULL != out, GSTD_NULL_ARGUMENT); manager = (GstDManager *) g_malloc0 (sizeof (*manager)); session = gstd_session_new ("Session0"); - /* If there is ipcs, then initialize them */ - if (NULL != supported_ipcs && num_ipcs > 0) { - ipc_array = g_malloc0 (num_ipcs * sizeof (*ipc_array)); - for (guint i = 0; i < num_ipcs; i++) { - ipc_array[i] = - GSTD_IPC (g_object_new (gstd_supported_ipc_to_ipc (supported_ipcs[i]), - NULL)); - } - manager->ipc_array = ipc_array; - } - manager->session = session; - manager->num_ipcs = num_ipcs; + manager->num_ipcs = 0; + manager->ipc_array = NULL; *out = manager; @@ -120,16 +108,40 @@ gstd_manager_new (const SupportedIpcs supported_ipcs[], const guint num_ipcs, } void -gstd_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]) +gstd_manager_set_ipc (GstDManager * manager, + const SupportedIpcs supported_ipcs[], const guint num_ipcs) { - gint i = 0; + GstdIpc **ipc_array = NULL; + + gstd_assert_and_ret (NULL != manager); + gstd_assert_and_ret (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_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]) +{ gstd_assert_and_ret (NULL != manager); gstd_assert_and_ret (NULL != manager->ipc_array); gstd_assert_and_ret (NULL != ipc_group); - for (i = 0; i < manager->num_ipcs; i++) { - gstd_ipc_get_option_group (manager->ipc_array[i], &ipc_group[i]); + for (gint ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) { + gstd_ipc_get_option_group (manager->ipc_array[ipc_idx], + &ipc_group[ipc_idx]); } } @@ -139,16 +151,16 @@ gstd_manager_ipc_start (GstDManager * manager) gboolean ipc_selected = FALSE; gboolean ret = TRUE; GstdReturnCode code = GSTD_EOK; - gint i = 0; + gint ipc_idx; gstd_assert_and_ret_val (NULL != manager, GSTD_NULL_ARGUMENT); gstd_assert_and_ret_val (NULL != manager->ipc_array, GSTD_LIB_NOT_FOUND); gstd_assert_and_ret_val (NULL != manager->session, GSTD_LIB_NOT_FOUND); /* Verify if at least one IPC mechanism was selected */ - for (i = 0; i < manager->num_ipcs; i++) { - g_object_get (G_OBJECT (manager->ipc_array[i]), "enabled", &ipc_selected, - NULL); + 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; @@ -161,11 +173,11 @@ gstd_manager_ipc_start (GstDManager * manager) } /* Run start for each IPC (each start method checks for the enabled flag) */ - for (i = 0; i < manager->num_ipcs; i++) { - code = gstd_ipc_start (manager->ipc_array[i], manager->session); + 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[i])); + G_OBJECT_TYPE_NAME (manager->ipc_array[ipc_idx])); ret = FALSE; } } @@ -176,17 +188,16 @@ gstd_manager_ipc_start (GstDManager * manager) void gstd_manager_ipc_stop (GstDManager * manager) { - gint i = 0; - gstd_assert_and_ret (NULL != manager); gstd_assert_and_ret (NULL != manager->ipc_array); gstd_assert_and_ret (NULL != manager->session); /* Run stop for each IPC */ - for (i = 0; i < manager->num_ipcs; i++) { - if (NULL != manager->ipc_array[i] && TRUE == manager->ipc_array[i]->enabled) { - gstd_ipc_stop (manager->ipc_array[i]); - g_clear_object (&manager->ipc_array[i]); + 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]); } } } diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h index 6740263d..40701302 100644 --- a/libgstd/libgstd.h +++ b/libgstd/libgstd.h @@ -93,22 +93,29 @@ GOptionGroup* gstd_init_get_option_group (void); /** * gstd_manager_new: * - * @supported_ipcs: ipcs the user will use - * @num_ipcs: length of supported_ipcs * @out: placeholder for newly allocated gstd manager. - * @gst_group: placeholder for GStreamer's argument specifications * @argc: arguments for gst_init * @argv: arguments for gst_init * - * Initializes gstd. If ipc array is not NULL - * it will initialize the GstdIpc in GstDManager. - * If it is NULL it will just initialize the session. + * Initializes gstd. * * Returns: GstdStatus indicating success or fail */ GstdStatus -gstd_manager_new (const SupportedIpcs supported_ipcs[], const uint num_ipcs, - GstDManager ** out, int argc, char *argv[]); +gstd_manager_new (GstDManager ** out, int argc, char *argv[]); + + +/** + * gstd_manager_set_ipc: + * + * @manager: The manager returned by gstd_manager_new() + * @supported_ipcs: ipcs the user will use + * @num_ipcs: length of supported_ipcs + * + * It will initialize the GstdIpc in GstDManager. + * + */ +void gstd_manager_set_ipc (GstDManager * manager, const SupportedIpcs supported_ipcs[], const guint num_ipcs); /** * gstd_manager_ipc_options: @@ -161,4 +168,4 @@ gstd_manager_free (GstDManager * manager); } #endif -#endif // __LIBGSTD_H__ +#endif /* __LIBGSTD_H__ */ diff --git a/libgstd/libgstd_assert.h b/libgstd/libgstd_assert.h index 41384c51..c929a630 100644 --- a/libgstd/libgstd_assert.h +++ b/libgstd/libgstd_assert.h @@ -65,10 +65,10 @@ void _gstd_assert (int cond, const char *scond, const char *file, const char *function, int line); -#endif // LIBGSTD_CHECKS_DISABLE +#endif /* LIBGSTD_CHECKS_DISABLE */ #ifdef __cplusplus } #endif -#endif // __LIBGSTD_ASSERT_H__ +#endif /* __LIBGSTD_ASSERT_H__ */ diff --git a/libgstd/meson.build b/libgstd/meson.build index f34a32d3..990e4bb3 100644 --- a/libgstd/meson.build +++ b/libgstd/meson.build @@ -2,8 +2,70 @@ gstd_headers = [ 'libgstd.h', ] +# Common files needed for GstD and libGstD +gstd_src = [ + '../gstd/gstd_object.c', + '../gstd/gstd_pipeline.c', + '../gstd/gstd_element.c', + '../gstd/gstd_list.c', + '../gstd/gstd_ipc.c', + '../gstd/gstd_tcp.c', + '../gstd/gstd_http.c', + '../gstd/gstd_icreator.c', + '../gstd/gstd_iformatter.c', + '../gstd/gstd_pipeline_creator.c', + '../gstd/gstd_no_creator.c', + '../gstd/gstd_json_builder.c', + '../gstd/gstd_ideleter.c', + '../gstd/gstd_pipeline_deleter.c', + '../gstd/gstd_no_deleter.c', + '../gstd/gstd_debug.c', + '../gstd/gstd_event_creator.c', + '../gstd/gstd_event_factory.c', + '../gstd/gstd_pipeline_bus.c', + '../gstd/gstd_ireader.c', + '../gstd/gstd_property_reader.c', + '../gstd/gstd_no_reader.c', + '../gstd/gstd_list_reader.c', + '../gstd/gstd_property.c', + '../gstd/gstd_property_int.c', + '../gstd/gstd_property_string.c', + '../gstd/gstd_property_boolean.c', + '../gstd/gstd_property_array.c', + '../gstd/gstd_iupdater.c', + '../gstd/gstd_no_updater.c', + '../gstd/gstd_property_enum.c', + '../gstd/gstd_property_flags.c', + '../gstd/gstd_event_handler.c', + '../gstd/gstd_bus_msg.c', + '../gstd/gstd_bus_msg_simple.c', + '../gstd/gstd_bus_msg_notify.c', + '../gstd/gstd_bus_msg_state_changed.c', + '../gstd/gstd_msg_reader.c', + '../gstd/gstd_msg_type.c', + '../gstd/gstd_bus_msg_qos.c', + '../gstd/gstd_return_codes.c', + '../gstd/gstd_state.c', + '../gstd/gstd_parser.c', + '../gstd/gstd_log.c', + '../gstd/gstd_bus_msg_stream_status.c', + '../gstd/gstd_bus_msg_element.c', + '../gstd/gstd_signal.c', + '../gstd/gstd_signal_list.c', + '../gstd/gstd_callback.c', + '../gstd/gstd_signal_reader.c', + '../gstd/gstd_session.c', + '../gstd/gstd_socket.c', + '../gstd/gstd_unix.c' +] + +libgstd_src = [ + 'libgstd_assert.c', + 'libgstd.c' +] + gstd_lib_manager = library('gstd-@0@'.format(apiversion), - [libgstd_src_files, gstd_src], + [gstd_src, libgstd_src], c_args : gst_d_args, version : gstd_version, include_directories : [configinc, gstd_inc_dir], @@ -18,7 +80,5 @@ install_headers(gstd_headers) 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_manager_dep = declare_dependency(link_with: gstd_lib_manager, +lib_gstd_dep = declare_dependency(link_with: gstd_lib_manager, dependencies : [libgstd_deps]) - -lib_gstd_manager_dir = meson.current_source_dir() diff --git a/meson.build b/meson.build index 4ba65d6d..1d9ce9de 100644 --- a/meson.build +++ b/meson.build @@ -52,11 +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, libd_dep, jansson_dep, thread_dep, libsoup_dep] +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 @@ -243,72 +243,10 @@ endif # Meson will generate a header file all the entries in the configuration data object configure_file(output : 'config.h', configuration : cdata) -# Common files needed for GstD and libGstD -libgstd_src_files = [ - '../gstd/gstd_object.c', - '../gstd/gstd_pipeline.c', - '../gstd/gstd_element.c', - '../gstd/gstd_list.c', - '../gstd/gstd_ipc.c', - '../gstd/gstd_tcp.c', - '../gstd/gstd_http.c', - '../gstd/gstd_icreator.c', - '../gstd/gstd_iformatter.c', - '../gstd/gstd_pipeline_creator.c', - '../gstd/gstd_no_creator.c', - '../gstd/gstd_json_builder.c', - '../gstd/gstd_ideleter.c', - '../gstd/gstd_pipeline_deleter.c', - '../gstd/gstd_no_deleter.c', - '../gstd/gstd_debug.c', - '../gstd/gstd_event_creator.c', - '../gstd/gstd_event_factory.c', - '../gstd/gstd_pipeline_bus.c', - '../gstd/gstd_ireader.c', - '../gstd/gstd_property_reader.c', - '../gstd/gstd_no_reader.c', - '../gstd/gstd_list_reader.c', - '../gstd/gstd_property.c', - '../gstd/gstd_property_int.c', - '../gstd/gstd_property_string.c', - '../gstd/gstd_property_boolean.c', - '../gstd/gstd_property_array.c', - '../gstd/gstd_iupdater.c', - '../gstd/gstd_no_updater.c', - '../gstd/gstd_property_enum.c', - '../gstd/gstd_property_flags.c', - '../gstd/gstd_event_handler.c', - '../gstd/gstd_bus_msg.c', - '../gstd/gstd_bus_msg_simple.c', - '../gstd/gstd_bus_msg_notify.c', - '../gstd/gstd_bus_msg_state_changed.c', - '../gstd/gstd_msg_reader.c', - '../gstd/gstd_msg_type.c', - '../gstd/gstd_bus_msg_qos.c', - '../gstd/gstd_return_codes.c', - '../gstd/gstd_state.c', - '../gstd/gstd_parser.c', - '../gstd/gstd_log.c', - '../gstd/gstd_bus_msg_stream_status.c', - '../gstd/gstd_bus_msg_element.c', - '../gstd/gstd_signal.c', - '../gstd/gstd_signal_list.c', - '../gstd/gstd_callback.c', - '../gstd/gstd_signal_reader.c', - '../gstd/gstd_session.c', - '../gstd/gstd_socket.c', - '../gstd/gstd_unix.c' -] - -gstd_src = [ - '../libgstd/libgstd_assert.c', - '../libgstd/libgstd.c' -] - # Enter to each subdirectory and execute the meson.build -subdir('gstd') subdir('libgstc') subdir('libgstd') +subdir('gstd') subdir('gst_client') subdir('tests') subdir('examples') diff --git a/tests/gstd/Makefile.am b/tests/gstd/Makefile.am index 907c4949..934c51c8 100644 --- a/tests/gstd/Makefile.am +++ b/tests/gstd/Makefile.am @@ -6,4 +6,4 @@ check_PROGRAMS = $(TESTS) AM_CFLAGS = $(GST_CFLAGS) -I$(top_srcdir)/gstd/ 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..0625a14e 100644 --- a/tests/gstd/meson.build +++ b/tests/gstd/meson.build @@ -39,7 +39,7 @@ foreach t : gstd_tests cpp_args : gst_c_args + test_defines, include_directories : [configinc, gstd_inc_dir], link_with : link_with_libs, - dependencies : [test_gstd_deps,lib_gstd_dep], + dependencies : [test_gstd_deps, lib_gstd_dep], ) # Define enviroment variable From 88dd60b591dfabc08002ce132897b293b0ca4b8a Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Thu, 2 Sep 2021 11:31:57 -0600 Subject: [PATCH 11/13] Move files from gstd folder to libgstd folder --- gstd/Makefile.am | 48 ---- gstd/gstd.c | 40 +-- gstd/meson.build | 112 ++++---- libgstd/Makefile.am | 108 ++++---- {gstd => libgstd}/gstd_bus_msg.c | 0 {gstd => libgstd}/gstd_bus_msg.h | 0 {gstd => libgstd}/gstd_bus_msg_element.c | 0 {gstd => libgstd}/gstd_bus_msg_element.h | 0 {gstd => libgstd}/gstd_bus_msg_notify.c | 0 {gstd => libgstd}/gstd_bus_msg_notify.h | 0 {gstd => libgstd}/gstd_bus_msg_qos.c | 0 {gstd => libgstd}/gstd_bus_msg_qos.h | 0 {gstd => libgstd}/gstd_bus_msg_simple.c | 0 {gstd => libgstd}/gstd_bus_msg_simple.h | 0 .../gstd_bus_msg_state_changed.c | 0 .../gstd_bus_msg_state_changed.h | 0 .../gstd_bus_msg_stream_status.c | 2 +- .../gstd_bus_msg_stream_status.h | 0 {gstd => libgstd}/gstd_callback.c | 0 {gstd => libgstd}/gstd_callback.h | 0 libgstd/gstd_chmod.sh | 6 + libgstd/gstd_daemon.c | 256 ++++++++++++++++++ libgstd/gstd_daemon.h | 60 ++++ {gstd => libgstd}/gstd_debug.c | 0 {gstd => libgstd}/gstd_debug.h | 0 {gstd => libgstd}/gstd_element.c | 0 {gstd => libgstd}/gstd_element.h | 0 {gstd => libgstd}/gstd_event_creator.c | 0 {gstd => libgstd}/gstd_event_creator.h | 0 {gstd => libgstd}/gstd_event_factory.c | 0 {gstd => libgstd}/gstd_event_factory.h | 0 {gstd => libgstd}/gstd_event_handler.c | 0 {gstd => libgstd}/gstd_event_handler.h | 0 {gstd => libgstd}/gstd_http.c | 0 {gstd => libgstd}/gstd_http.h | 0 {gstd => libgstd}/gstd_icreator.c | 0 {gstd => libgstd}/gstd_icreator.h | 0 {gstd => libgstd}/gstd_ideleter.c | 0 {gstd => libgstd}/gstd_ideleter.h | 0 {gstd => libgstd}/gstd_iformatter.c | 0 {gstd => libgstd}/gstd_iformatter.h | 0 {gstd => libgstd}/gstd_ipc.c | 0 {gstd => libgstd}/gstd_ipc.h | 0 {gstd => libgstd}/gstd_ireader.c | 0 {gstd => libgstd}/gstd_ireader.h | 0 {gstd => libgstd}/gstd_iupdater.c | 0 {gstd => libgstd}/gstd_iupdater.h | 0 {gstd => libgstd}/gstd_json_builder.c | 0 {gstd => libgstd}/gstd_json_builder.h | 0 {gstd => libgstd}/gstd_list.c | 0 {gstd => libgstd}/gstd_list.h | 0 {gstd => libgstd}/gstd_list_reader.c | 0 {gstd => libgstd}/gstd_list_reader.h | 0 libgstd/gstd_log.c | 172 ++++++++++++ libgstd/gstd_log.h | 36 +++ {gstd => libgstd}/gstd_msg_reader.c | 0 {gstd => libgstd}/gstd_msg_reader.h | 0 {gstd => libgstd}/gstd_msg_type.c | 0 {gstd => libgstd}/gstd_msg_type.h | 0 {gstd => libgstd}/gstd_no_creator.c | 0 {gstd => libgstd}/gstd_no_creator.h | 0 {gstd => libgstd}/gstd_no_deleter.c | 0 {gstd => libgstd}/gstd_no_deleter.h | 0 {gstd => libgstd}/gstd_no_reader.c | 0 {gstd => libgstd}/gstd_no_reader.h | 0 {gstd => libgstd}/gstd_no_updater.c | 0 {gstd => libgstd}/gstd_no_updater.h | 0 {gstd => libgstd}/gstd_object.c | 0 {gstd => libgstd}/gstd_object.h | 0 {gstd => libgstd}/gstd_parser.c | 0 {gstd => libgstd}/gstd_parser.h | 0 {gstd => libgstd}/gstd_pipeline.c | 0 {gstd => libgstd}/gstd_pipeline.h | 0 {gstd => libgstd}/gstd_pipeline_bus.c | 0 {gstd => libgstd}/gstd_pipeline_bus.h | 0 {gstd => libgstd}/gstd_pipeline_creator.c | 0 {gstd => libgstd}/gstd_pipeline_creator.h | 0 {gstd => libgstd}/gstd_pipeline_deleter.c | 0 {gstd => libgstd}/gstd_pipeline_deleter.h | 0 {gstd => libgstd}/gstd_property.c | 0 {gstd => libgstd}/gstd_property.h | 0 {gstd => libgstd}/gstd_property_array.c | 0 {gstd => libgstd}/gstd_property_array.h | 0 {gstd => libgstd}/gstd_property_boolean.c | 0 {gstd => libgstd}/gstd_property_boolean.h | 0 {gstd => libgstd}/gstd_property_enum.c | 0 {gstd => libgstd}/gstd_property_enum.h | 0 {gstd => libgstd}/gstd_property_flags.c | 0 {gstd => libgstd}/gstd_property_flags.h | 0 {gstd => libgstd}/gstd_property_int.c | 0 {gstd => libgstd}/gstd_property_int.h | 0 {gstd => libgstd}/gstd_property_reader.c | 0 {gstd => libgstd}/gstd_property_reader.h | 0 {gstd => libgstd}/gstd_property_string.c | 0 {gstd => libgstd}/gstd_property_string.h | 0 {gstd => libgstd}/gstd_return_codes.c | 0 {gstd => libgstd}/gstd_return_codes.h | 0 {gstd => libgstd}/gstd_session.c | 0 {gstd => libgstd}/gstd_session.h | 0 {gstd => libgstd}/gstd_signal.c | 0 {gstd => libgstd}/gstd_signal.h | 0 {gstd => libgstd}/gstd_signal_list.c | 0 {gstd => libgstd}/gstd_signal_list.h | 0 {gstd => libgstd}/gstd_signal_reader.c | 0 {gstd => libgstd}/gstd_signal_reader.h | 0 {gstd => libgstd}/gstd_socket.c | 0 {gstd => libgstd}/gstd_socket.h | 0 {gstd => libgstd}/gstd_state.c | 0 {gstd => libgstd}/gstd_state.h | 0 {gstd => libgstd}/gstd_tcp.c | 0 {gstd => libgstd}/gstd_tcp.h | 0 {gstd => libgstd}/gstd_unix.c | 0 {gstd => libgstd}/gstd_unix.h | 0 libgstd/libgstd.c | 158 ++++++----- libgstd/libgstd.h | 44 +-- libgstd/meson.build | 106 ++++---- tests/gstd/Makefile.am | 2 +- tests/gstd/meson.build | 2 +- 118 files changed, 794 insertions(+), 358 deletions(-) rename {gstd => libgstd}/gstd_bus_msg.c (100%) rename {gstd => libgstd}/gstd_bus_msg.h (100%) rename {gstd => libgstd}/gstd_bus_msg_element.c (100%) rename {gstd => libgstd}/gstd_bus_msg_element.h (100%) rename {gstd => libgstd}/gstd_bus_msg_notify.c (100%) rename {gstd => libgstd}/gstd_bus_msg_notify.h (100%) rename {gstd => libgstd}/gstd_bus_msg_qos.c (100%) rename {gstd => libgstd}/gstd_bus_msg_qos.h (100%) rename {gstd => libgstd}/gstd_bus_msg_simple.c (100%) rename {gstd => libgstd}/gstd_bus_msg_simple.h (100%) rename {gstd => libgstd}/gstd_bus_msg_state_changed.c (100%) rename {gstd => libgstd}/gstd_bus_msg_state_changed.h (100%) rename {gstd => libgstd}/gstd_bus_msg_stream_status.c (98%) rename {gstd => libgstd}/gstd_bus_msg_stream_status.h (100%) rename {gstd => libgstd}/gstd_callback.c (100%) rename {gstd => libgstd}/gstd_callback.h (100%) create mode 100755 libgstd/gstd_chmod.sh create mode 100644 libgstd/gstd_daemon.c create mode 100644 libgstd/gstd_daemon.h rename {gstd => libgstd}/gstd_debug.c (100%) rename {gstd => libgstd}/gstd_debug.h (100%) rename {gstd => libgstd}/gstd_element.c (100%) rename {gstd => libgstd}/gstd_element.h (100%) rename {gstd => libgstd}/gstd_event_creator.c (100%) rename {gstd => libgstd}/gstd_event_creator.h (100%) rename {gstd => libgstd}/gstd_event_factory.c (100%) rename {gstd => libgstd}/gstd_event_factory.h (100%) rename {gstd => libgstd}/gstd_event_handler.c (100%) rename {gstd => libgstd}/gstd_event_handler.h (100%) rename {gstd => libgstd}/gstd_http.c (100%) rename {gstd => libgstd}/gstd_http.h (100%) rename {gstd => libgstd}/gstd_icreator.c (100%) rename {gstd => libgstd}/gstd_icreator.h (100%) rename {gstd => libgstd}/gstd_ideleter.c (100%) rename {gstd => libgstd}/gstd_ideleter.h (100%) rename {gstd => libgstd}/gstd_iformatter.c (100%) rename {gstd => libgstd}/gstd_iformatter.h (100%) rename {gstd => libgstd}/gstd_ipc.c (100%) rename {gstd => libgstd}/gstd_ipc.h (100%) rename {gstd => libgstd}/gstd_ireader.c (100%) rename {gstd => libgstd}/gstd_ireader.h (100%) rename {gstd => libgstd}/gstd_iupdater.c (100%) rename {gstd => libgstd}/gstd_iupdater.h (100%) rename {gstd => libgstd}/gstd_json_builder.c (100%) rename {gstd => libgstd}/gstd_json_builder.h (100%) rename {gstd => libgstd}/gstd_list.c (100%) rename {gstd => libgstd}/gstd_list.h (100%) rename {gstd => libgstd}/gstd_list_reader.c (100%) rename {gstd => libgstd}/gstd_list_reader.h (100%) create mode 100644 libgstd/gstd_log.c create mode 100644 libgstd/gstd_log.h rename {gstd => libgstd}/gstd_msg_reader.c (100%) rename {gstd => libgstd}/gstd_msg_reader.h (100%) rename {gstd => libgstd}/gstd_msg_type.c (100%) rename {gstd => libgstd}/gstd_msg_type.h (100%) rename {gstd => libgstd}/gstd_no_creator.c (100%) rename {gstd => libgstd}/gstd_no_creator.h (100%) rename {gstd => libgstd}/gstd_no_deleter.c (100%) rename {gstd => libgstd}/gstd_no_deleter.h (100%) rename {gstd => libgstd}/gstd_no_reader.c (100%) rename {gstd => libgstd}/gstd_no_reader.h (100%) rename {gstd => libgstd}/gstd_no_updater.c (100%) rename {gstd => libgstd}/gstd_no_updater.h (100%) rename {gstd => libgstd}/gstd_object.c (100%) rename {gstd => libgstd}/gstd_object.h (100%) rename {gstd => libgstd}/gstd_parser.c (100%) rename {gstd => libgstd}/gstd_parser.h (100%) rename {gstd => libgstd}/gstd_pipeline.c (100%) rename {gstd => libgstd}/gstd_pipeline.h (100%) rename {gstd => libgstd}/gstd_pipeline_bus.c (100%) rename {gstd => libgstd}/gstd_pipeline_bus.h (100%) rename {gstd => libgstd}/gstd_pipeline_creator.c (100%) rename {gstd => libgstd}/gstd_pipeline_creator.h (100%) rename {gstd => libgstd}/gstd_pipeline_deleter.c (100%) rename {gstd => libgstd}/gstd_pipeline_deleter.h (100%) rename {gstd => libgstd}/gstd_property.c (100%) rename {gstd => libgstd}/gstd_property.h (100%) rename {gstd => libgstd}/gstd_property_array.c (100%) rename {gstd => libgstd}/gstd_property_array.h (100%) rename {gstd => libgstd}/gstd_property_boolean.c (100%) rename {gstd => libgstd}/gstd_property_boolean.h (100%) rename {gstd => libgstd}/gstd_property_enum.c (100%) rename {gstd => libgstd}/gstd_property_enum.h (100%) rename {gstd => libgstd}/gstd_property_flags.c (100%) rename {gstd => libgstd}/gstd_property_flags.h (100%) rename {gstd => libgstd}/gstd_property_int.c (100%) rename {gstd => libgstd}/gstd_property_int.h (100%) rename {gstd => libgstd}/gstd_property_reader.c (100%) rename {gstd => libgstd}/gstd_property_reader.h (100%) rename {gstd => libgstd}/gstd_property_string.c (100%) rename {gstd => libgstd}/gstd_property_string.h (100%) rename {gstd => libgstd}/gstd_return_codes.c (100%) rename {gstd => libgstd}/gstd_return_codes.h (100%) rename {gstd => libgstd}/gstd_session.c (100%) rename {gstd => libgstd}/gstd_session.h (100%) rename {gstd => libgstd}/gstd_signal.c (100%) rename {gstd => libgstd}/gstd_signal.h (100%) rename {gstd => libgstd}/gstd_signal_list.c (100%) rename {gstd => libgstd}/gstd_signal_list.h (100%) rename {gstd => libgstd}/gstd_signal_reader.c (100%) rename {gstd => libgstd}/gstd_signal_reader.h (100%) rename {gstd => libgstd}/gstd_socket.c (100%) rename {gstd => libgstd}/gstd_socket.h (100%) rename {gstd => libgstd}/gstd_state.c (100%) rename {gstd => libgstd}/gstd_state.h (100%) rename {gstd => libgstd}/gstd_tcp.c (100%) rename {gstd => libgstd}/gstd_tcp.h (100%) rename {gstd => libgstd}/gstd_unix.c (100%) rename {gstd => libgstd}/gstd_unix.h (100%) diff --git a/gstd/Makefile.am b/gstd/Makefile.am index 63105277..dfc57b55 100644 --- a/gstd/Makefile.am +++ b/gstd/Makefile.am @@ -24,54 +24,6 @@ gstd_LDFLAGS = $(GST_LIBS) \ gstd_LDADD = $(top_srcdir)/libgstd/libgstd-1.0.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 - noinst_HEADERS = gstd_daemon.h # Create an open area for our pid and log files diff --git a/gstd/gstd.c b/gstd/gstd.c index e46e8cfa..e8aaec31 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -25,11 +25,6 @@ #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" @@ -75,24 +70,13 @@ main (gint argc, gchar * argv[]) gchar *pidfile = NULL; GError *error = NULL; GOptionContext *context = NULL; - GOptionGroup *gstreamer_group = NULL; - GOptionGroup **ipc_group_array = NULL; gint ret = EXIT_SUCCESS; gchar *current_filename = NULL; + gchar *filename = NULL; + gboolean parent = FALSE; GstDManager *manager = NULL; - /* Array to specify gstd how many IPCs are supported, - * SupportedIpcs should be added 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)); - GOptionEntry entries[] = { {"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Print current gstd version and exit", NULL} @@ -123,17 +107,8 @@ main (gint argc, gchar * argv[]) g_option_context_add_main_entries (context, entries, NULL); /* Initialize GStreamer */ - gstreamer_group = gstd_init_get_option_group (); gstd_manager_new (&manager, 0, NULL); - g_option_context_add_group (context, gstreamer_group); - gstd_manager_set_ipc (manager, supported_ipcs, num_ipcs); - - /* Read option group for each IPC */ - ipc_group_array = g_malloc0 (num_ipcs * sizeof (*ipc_group_array)); - gstd_manager_ipc_options (manager, ipc_group_array); /* If you don't want this option, you can avoid calling this function */ - for (int i = 0; i < num_ipcs; i++) { - g_option_context_add_group (context, ipc_group_array[i]); - } + gstd_get_option_context (manager, &context); /* Parse the options before starting */ if (!g_option_context_parse (context, &argc, &argv, &error)) { @@ -173,8 +148,6 @@ main (gint argc, gchar * argv[]) } if (daemon) { - gboolean parent; - if (!gstd_daemon_start (&parent)) { goto error; } @@ -182,7 +155,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"); @@ -193,7 +165,7 @@ main (gint argc, gchar * argv[]) } /* Start IPC subsystem */ - if (!gstd_manager_ipc_start (manager)) { + if (!gstd_manager_start (manager)) { goto error; } @@ -214,9 +186,6 @@ main (gint argc, gchar * argv[]) g_main_loop_unref (main_loop); main_loop = NULL; - /* Stop any IPC array */ - gstd_manager_ipc_stop (manager); - gstd_log_deinit (); goto out; @@ -232,7 +201,6 @@ main (gint argc, gchar * argv[]) } out: { - g_free (ipc_group_array); gstd_manager_free (manager); return ret; } diff --git a/gstd/meson.build b/gstd/meson.build index a8c836a4..0a15fb43 100644 --- a/gstd/meson.build +++ b/gstd/meson.build @@ -1,70 +1,72 @@ gstd_name = 'gstd' + # Application source files gstd_src_files = [ 'gstd_daemon.c', 'gstd.c' ] -# Library source files -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/gstd_object.c', + '../libgstd/gstd_pipeline.c', + '../libgstd/gstd_element.c', + '../libgstd/gstd_list.c', + '../libgstd/gstd_ipc.c', + '../libgstd/gstd_tcp.c', + '../libgstd/gstd_http.c', + '../libgstd/gstd_icreator.c', + '../libgstd/gstd_iformatter.c', + '../libgstd/gstd_pipeline_creator.c', + '../libgstd/gstd_no_creator.c', + '../libgstd/gstd_json_builder.c', + '../libgstd/gstd_ideleter.c', + '../libgstd/gstd_pipeline_deleter.c', + '../libgstd/gstd_no_deleter.c', + '../libgstd/gstd_debug.c', + '../libgstd/gstd_event_creator.c', + '../libgstd/gstd_event_factory.c', + '../libgstd/gstd_pipeline_bus.c', + '../libgstd/gstd_ireader.c', + '../libgstd/gstd_property_reader.c', + '../libgstd/gstd_no_reader.c', + '../libgstd/gstd_list_reader.c', + '../libgstd/gstd_property.c', + '../libgstd/gstd_property_int.c', + '../libgstd/gstd_property_string.c', + '../libgstd/gstd_property_boolean.c', + '../libgstd/gstd_property_array.c', + '../libgstd/gstd_iupdater.c', + '../libgstd/gstd_no_updater.c', + '../libgstd/gstd_property_enum.c', + '../libgstd/gstd_property_flags.c', + '../libgstd/gstd_event_handler.c', + '../libgstd/gstd_bus_msg.c', + '../libgstd/gstd_bus_msg_simple.c', + '../libgstd/gstd_bus_msg_notify.c', + '../libgstd/gstd_bus_msg_state_changed.c', + '../libgstd/gstd_msg_reader.c', + '../libgstd/gstd_msg_type.c', + '../libgstd/gstd_bus_msg_qos.c', + '../libgstd/gstd_return_codes.c', + '../libgstd/gstd_state.c', + '../libgstd/gstd_parser.c', + '../libgstd/gstd_log.c', + '../libgstd/gstd_bus_msg_stream_status.c', + '../libgstd/gstd_bus_msg_element.c', + '../libgstd/gstd_signal.c', + '../libgstd/gstd_signal_list.c', + '../libgstd/gstd_callback.c', + '../libgstd/gstd_signal_reader.c', + '../libgstd/gstd_session.c', + '../libgstd/gstd_socket.c', + '../libgstd/gstd_unix.c', + '../libgstd/libgstd.c' ] # 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, libgstd_inc_dir], dependencies : [gstd_deps, lib_gstd_dep], diff --git a/libgstd/Makefile.am b/libgstd/Makefile.am index 9a4e21ec..d1491165 100644 --- a/libgstd/Makefile.am +++ b/libgstd/Makefile.am @@ -1,64 +1,64 @@ lib_LTLIBRARIES = libgstd-@GSTD_API_VERSION@.la -gstdincludedir = $(includedir)/gstd +gstdincludedir = $(includedir)/libgstd gstdinclude_HEADERS = libgstd.h libgstd_@GSTD_API_VERSION@_la_SOURCES = \ libgstd.c \ libgstd_assert.c \ - ../gstd/gstd_session.c \ - ../gstd/gstd_object.c \ - ../gstd/gstd_pipeline.c \ - ../gstd/gstd_element.c \ - ../gstd/gstd_list.c \ - ../gstd/gstd_ipc.c \ - ../gstd/gstd_tcp.c \ - ../gstd/gstd_http.c \ - ../gstd/gstd_icreator.c \ - ../gstd/gstd_iformatter.c \ - ../gstd/gstd_pipeline_creator.c \ - ../gstd/gstd_no_creator.c \ - ../gstd/gstd_json_builder.c \ - ../gstd/gstd_ideleter.c \ - ../gstd/gstd_pipeline_deleter.c \ - ../gstd/gstd_no_deleter.c \ - ../gstd/gstd_debug.c \ - ../gstd/gstd_event_creator.c \ - ../gstd/gstd_event_factory.c \ - ../gstd/gstd_pipeline_bus.c \ - ../gstd/gstd_ireader.c \ - ../gstd/gstd_property_reader.c \ - ../gstd/gstd_no_reader.c \ - ../gstd/gstd_list_reader.c \ - ../gstd/gstd_property.c \ - ../gstd/gstd_property_int.c \ - ../gstd/gstd_property_string.c \ - ../gstd/gstd_property_boolean.c \ - ../gstd/gstd_property_array.c \ - ../gstd/gstd_iupdater.c \ - ../gstd/gstd_no_updater.c \ - ../gstd/gstd_property_enum.c \ - ../gstd/gstd_property_flags.c \ - ../gstd/gstd_event_handler.c \ - ../gstd/gstd_bus_msg.c \ - ../gstd/gstd_bus_msg_simple.c \ - ../gstd/gstd_bus_msg_notify.c \ - ../gstd/gstd_bus_msg_state_changed.c \ - ../gstd/gstd_msg_reader.c \ - ../gstd/gstd_msg_type.c \ - ../gstd/gstd_bus_msg_qos.c \ - ../gstd/gstd_return_codes.c \ - ../gstd/gstd_state.c \ - ../gstd/gstd_parser.c \ - ../gstd/gstd_log.c \ - ../gstd/gstd_bus_msg_stream_status.c \ - ../gstd/gstd_bus_msg_element.c \ - ../gstd/gstd_signal.c \ - ../gstd/gstd_callback.c \ - ../gstd/gstd_signal_reader.c \ - ../gstd/gstd_socket.c \ - ../gstd/gstd_unix.c \ - ../gstd/gstd_signal_list.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_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_@GSTD_API_VERSION@_la_CFLAGS = \ $(GST_CFLAGS) \ 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/libgstd/gstd_chmod.sh b/libgstd/gstd_chmod.sh new file mode 100755 index 00000000..8e58bce0 --- /dev/null +++ b/libgstd/gstd_chmod.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# This script is executed at install time to change the mode of the directories installed +# $1 mode +# $2 file + +chmod $1 $2 diff --git a/libgstd/gstd_daemon.c b/libgstd/gstd_daemon.c new file mode 100644 index 00000000..9e0a3868 --- /dev/null +++ b/libgstd/gstd_daemon.c @@ -0,0 +1,256 @@ +/* + * GStreamer Daemon - Gst Launch under steroids + * Copyright (c) 2015-2017 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 + */ + +/* Code based on testd.c found in + * http://0pointer.de/lennart/projects/libdaemon/reference/html/testd_8c-example.html + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstd_daemon.h" +#include "gstd_log.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static gboolean gstd_daemon_start_parent (void); +static gboolean gstd_daemon_start_child (void); +static const gchar *gstd_daemon_pid (void); +static gchar *gstd_daemon_get_pid_filename (const gchar * filename); + +static gboolean _initialized = FALSE; +static gchar *pid_filename = NULL; + +gboolean +gstd_daemon_init (gint argc, gchar * argv[], gchar * pidfilename) +{ + const gchar *process_name; + gchar *pid_path = NULL; + gboolean ret = TRUE; + + g_return_val_if_fail (argv, FALSE); + + if (_initialized) + goto out; + + /* Check if pid dir available */ + pid_path = gstd_daemon_get_pid_filename (pidfilename); + + if (NULL == pid_path) { + g_printerr ("Unable to access Gstd pid dir: pid path is NULL\n"); + ret = FALSE; + goto out; + } + + if (g_access (pid_path, W_OK)) { + g_printerr ("Unable to open Gstd pid dir %s: %s\n", pid_path, + g_strerror (errno)); + ret = FALSE; + goto free_path; + } + + /* Sanitize the process name to use it as PID identification */ + process_name = daemon_ident_from_argv0 (argv[0]); + + /* Use the process name as the identification prefix for the + pid file */ + daemon_pid_file_ident = process_name; + + /* + Create a gstd.pid file in another path, it could be + nullable */ + pid_filename = pidfilename; + + /* Override the default pid file location to /tmp/ to avoid the need + of root privileges */ + daemon_pid_file_proc = gstd_daemon_pid; + + _initialized = TRUE; + +free_path: + g_free (pid_path); +out: + return ret; +} + +gboolean +gstd_daemon_start (gboolean * parent) +{ + pid_t pid; + gboolean ret = FALSE; + + g_return_val_if_fail (_initialized, FALSE); + g_return_val_if_fail (parent, FALSE); + + /* Check that the daemon is not rung twice a the same time */ + pid = daemon_pid_file_is_running (); + if (pid >= 0) { + GST_ERROR ("Daemon already running on PID file %u", pid); + goto out; + } + + /* Prepare for return value passing from the initialization + procedure of the daemon process */ + if (daemon_retval_init () < 0) { + GST_ERROR ("Failed to create pipe."); + goto out; + } + + pid = daemon_fork (); + + /* Negative PID means fork failure */ + if (pid < 0) { + daemon_retval_done (); + goto out; + } + /* Positive PID is for parent flow */ + if (pid > 0) { + ret = gstd_daemon_start_parent (); + *parent = TRUE; + } else { + ret = gstd_daemon_start_child (); + *parent = FALSE; + } + +out: + { + return ret; + } +} + +static gboolean +gstd_daemon_start_parent (void) +{ + gint iret; + gboolean ret = FALSE; + guint timeout = 20; + + g_return_val_if_fail (_initialized, FALSE); + + /* Wait for 20 seconds for the return value passed from the daemon + process */ + iret = daemon_retval_wait (timeout); + if (iret < 0) { + GST_ERROR ("Could not recieve return value from daemon process: %s", + g_strerror (errno)); + } else if (iret > 0) { + GST_ERROR ("Child process ended unexpectedly with code: %d", ret); + } else { + ret = TRUE; + } + + return ret; +} + +static gboolean +gstd_daemon_start_child (void) +{ + gint retval = 0; + gboolean ret; + + GST_INFO ("Detached form parent process"); + + /* Create the PID file */ + if (daemon_pid_file_create () < 0) { + GST_ERROR ("Could not create PID file: %s (%s).", gstd_daemon_pid (), + g_strerror (errno)); + goto error; + } + + GST_INFO ("Daemon successfully started"); + retval = 0; + ret = TRUE; + + goto out; + +error: + { + ret = FALSE; + retval = 1; + } +out: + { + daemon_retval_send (retval); + return ret; + } +} + +gboolean +gstd_daemon_stop (void) +{ + gboolean ret = FALSE; + guint timeout = 5; + + ret = daemon_pid_file_kill_wait (SIGTERM, timeout); + if (ret < 0) { + GST_ERROR + ("No running Gstd found or gstd.pid was saved using \"--pid-path\""); + ret = FALSE; + } else { + ret = TRUE; + } + + /* Cleanup the PID file */ + daemon_pid_file_remove (); + + return ret; +} + +static const gchar * +gstd_daemon_pid (void) +{ + static gchar *fn = NULL; + gchar *filename; + + if (fn) { + g_free (fn); + } + + filename = gstd_daemon_get_pid_filename (pid_filename); + fn = g_strdup_printf ("%s/%s.pid", filename, + daemon_pid_file_ident ? daemon_pid_file_ident : "gstd"); + g_free (filename); + + return fn; + +} + +static gchar * +gstd_daemon_get_pid_filename (const gchar * filename) +{ + if (filename == NULL) + return g_strdup (GSTD_RUN_STATE_DIR); + + if (g_path_is_absolute (filename)) { + return g_strdup (filename); + } else { + g_printerr ("The pid filename is not absolute since default filename\n"); + return g_strdup (GSTD_RUN_STATE_DIR); + } +} diff --git a/libgstd/gstd_daemon.h b/libgstd/gstd_daemon.h new file mode 100644 index 00000000..277b89a5 --- /dev/null +++ b/libgstd/gstd_daemon.h @@ -0,0 +1,60 @@ +/* + * GStreamer Daemon - Gst Launch under steroids + * Copyright (c) 2015-2017 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 __GSTD_DAEMON_H__ +#define __GSTD_DAEMON_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +/** + * Initializes the resources necessary to daemonize or kill a + * a process. + * + * \param argc The amount of parameters given in argv + * \param argv The array of cmdline arguments given to + * the process in the application's main + * + * \return TRUE if the resources were initilized succesfully, FALSE + * otherwise. + */ +gboolean gstd_daemon_init (gint argc, gchar * argv[], gchar * pidfilename); + +/** + * Daemonizes the current process using the given process name + * + * \param parent A memory location to hold either the fork belongs to + * the parent of the child. + * + * \return TRUE if the process was sucessfully daemonized, FALSE + * otherwise. + */ +gboolean gstd_daemon_start (gboolean * parent); + +/** + * Closes the resources associated with the daemon, if any. + * + * \return TRUE if the daemon was successfully closed, FALSE + * otherwise. + */ +gboolean gstd_daemon_stop (void); + +#endif // __GSTD_DAEMON_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/libgstd/gstd_log.c b/libgstd/gstd_log.c new file mode 100644 index 00000000..ce764a34 --- /dev/null +++ b/libgstd/gstd_log.c @@ -0,0 +1,172 @@ +/* + * GStreamer Daemon - Gst Launch under steroids + * Copyright (c) 2015-2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstd_log.h" + +#include +#include +#include + +GST_DEBUG_CATEGORY (gstd_debug); + +#define GSTD_LOG_NAME "gstd.log" +#define GST_LOG_NAME "gst.log" +#define GSTD_DEBUG_PREFIX "gstd" +#define GSTD_DEBUG_LEVEL "WARNING" + +static void +gstd_log_proxy (GstDebugCategory * category, GstDebugLevel level, + const gchar * file, const gchar * function, gint line, GObject * object, + GstDebugMessage * message, gpointer user_data) + G_GNUC_NO_INSTRUMENT; + + static const gchar *gstd_log_get_gstd_default (void); + static const gchar *gstd_log_get_gst_default (void); + static gchar *gstd_log_get_filename (const gchar * filename, + const gchar * default_filename); + + static FILE *_gstdlog = NULL; + static FILE *_gstlog = NULL; + static gchar *gstd_filename; + static gchar *gst_filename; + +gboolean +gstd_log_init (const gchar * gstdfilename, const gchar * gstfilename) +{ + if (_gstdlog) { + return TRUE; + } + + gstd_filename = + gstd_log_get_filename (gstdfilename, gstd_log_get_gstd_default ()); + + _gstdlog = g_fopen (gstd_filename, "a+"); + + if (!_gstdlog) { + g_printerr ("Unable to open Gstd log file %s: %s\n", gstd_filename, + g_strerror (errno)); + return FALSE; + } + + gst_filename = + gstd_log_get_filename (gstfilename, gstd_log_get_gst_default ()); + _gstlog = g_fopen (gst_filename, "a+"); + + if (!_gstlog) { + g_printerr ("Unable to open Gst log file %s: %s\n", gst_filename, + g_strerror (errno)); + return FALSE; + } + + /* Install our proxy handler */ + gst_debug_add_log_function (gstd_log_proxy, NULL, NULL); + + return TRUE; +} + +void +gstd_debug_init (void) +{ + gint debug_color; + /* Turn on up to info for gstd debug */ + gst_debug_set_threshold_from_string (GSTD_DEBUG_PREFIX "*:" GSTD_DEBUG_LEVEL, + FALSE); + + /* Initialize debug category with nice colors */ + debug_color = GST_DEBUG_FG_BLACK | GST_DEBUG_BOLD | GST_DEBUG_BG_WHITE; + GST_DEBUG_CATEGORY_INIT (gstd_debug, "gstd", debug_color, "Gstd category"); +} + +void +gstd_log_deinit (void) +{ + g_free (gstd_filename); + g_free (gst_filename); + + if (!_gstdlog) { + return; + } + + fclose (_gstdlog); + fclose (_gstlog); +} + +static void +gstd_log_proxy (GstDebugCategory * category, GstDebugLevel level, + const gchar * file, const gchar * function, gint line, GObject * object, + GstDebugMessage * message, gpointer user_data) +{ + const gchar *cat_name; + + cat_name = gst_debug_category_get_name (category); + + /* Log every gstd trace into the gstd log file */ + if (!strncmp (cat_name, GSTD_DEBUG_PREFIX, sizeof (GSTD_DEBUG_PREFIX) - 1)) { + /* Redirect gstd debug to its respective file */ + gst_debug_log_default (category, level, file, function, line, object, + message, _gstdlog); + } else { + /* Everything else goes to the gst file */ + gst_debug_log_default (category, level, file, function, line, object, + message, _gstlog); + } +} + +static const gchar * +gstd_log_get_gstd_default (void) +{ + return GSTD_LOG_STATE_DIR GSTD_LOG_NAME; +} + +static const gchar * +gstd_log_get_gst_default (void) +{ + return GSTD_LOG_STATE_DIR GST_LOG_NAME; +} + +static gchar * +gstd_log_get_filename (const gchar * filename, const gchar * default_filename) +{ + if (filename == NULL) + return g_strdup (default_filename); + + if (g_path_is_absolute (filename)) { + return g_strdup (filename); + } else { + g_printerr + ("WARNING: The pid filename is not absolute since default filename\n"); + return g_strdup (default_filename);; + } +} + +gchar * +gstd_log_get_current_gstd (void) +{ + return g_strdup (gstd_filename); +} + +gchar * +gstd_log_get_current_gst (void) +{ + return g_strdup (gst_filename); +} diff --git a/libgstd/gstd_log.h b/libgstd/gstd_log.h new file mode 100644 index 00000000..8fc9d4d3 --- /dev/null +++ b/libgstd/gstd_log.h @@ -0,0 +1,36 @@ +/* + * GStreamer Daemon - Gst Launch under steroids + * Copyright (c) 2015-2017 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 __GSTD_LOG_H__ +#define __GSTD_LOG_H__ + +#include + +gboolean gstd_log_init (const gchar * gstdfilename, const gchar * gstfilename); +void gstd_log_deinit (void); +void gstd_debug_init (void); + +gchar *gstd_log_get_current_gstd (void); +gchar *gstd_log_get_current_gst (void); + +/* A default category for every object not defining its own */ +GST_DEBUG_CATEGORY_EXTERN (gstd_debug); +#define GST_CAT_DEFAULT gstd_debug + +#endif // __GSTD_LOG_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 index 85269346..95abc438 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -45,6 +45,8 @@ static GType gstd_supported_ipc_to_ipc (const SupportedIpcs code); static void gstd_manager_init (int argc, char *argv[]); +static void gstd_manager_ipc_stop (GstDManager * manager); +static void gstd_manager_set_ipc (GstDManager * manager); struct _GstDManager { @@ -77,76 +79,8 @@ gstd_manager_init (int argc, char *argv[]) gstd_debug_init (); } -GOptionGroup * -gstd_init_get_option_group (void) -{ - return gst_init_get_option_group (); -} - -GstdStatus -gstd_manager_new (GstDManager ** out, int argc, char *argv[]) -{ - GstdStatus ret = GSTD_LIB_OK; - GstDManager *manager = NULL; - GstdSession *session = NULL; - - gstd_assert_and_ret_val (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; - - *out = manager; - - /* Initialize GStreamer */ - gstd_manager_init (argc, argv); - - return ret; -} - -void -gstd_manager_set_ipc (GstDManager * manager, - const SupportedIpcs supported_ipcs[], const guint num_ipcs) -{ - - GstdIpc **ipc_array = NULL; - - gstd_assert_and_ret (NULL != manager); - gstd_assert_and_ret (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_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]) -{ - gstd_assert_and_ret (NULL != manager); - gstd_assert_and_ret (NULL != manager->ipc_array); - gstd_assert_and_ret (NULL != ipc_group); - - for (gint ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) { - gstd_ipc_get_option_group (manager->ipc_array[ipc_idx], - &ipc_group[ipc_idx]); - } -} - gboolean -gstd_manager_ipc_start (GstDManager * manager) +gstd_manager_start (GstDManager * manager) { gboolean ipc_selected = FALSE; gboolean ret = TRUE; @@ -185,7 +119,7 @@ gstd_manager_ipc_start (GstDManager * manager) return ret; } -void +static void gstd_manager_ipc_stop (GstDManager * manager) { gstd_assert_and_ret (NULL != manager); @@ -202,6 +136,90 @@ gstd_manager_ipc_stop (GstDManager * manager) } } +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; + + gstd_assert_and_ret (NULL != manager); + gstd_assert_and_ret (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_get_option_context (GstDManager * manager, GOptionContext ** context) +{ + GOptionGroup *gst_options = NULL; + GOptionGroup **ipc_group_array = NULL; + + gstd_assert_and_ret (NULL != manager); + gstd_assert_and_ret (NULL != manager->ipc_array); + gstd_assert_and_ret (NULL != context); + + gst_options = gst_init_get_option_group (); + 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, gst_options); + for (int i = 0; i < manager->num_ipcs; i++) { + g_option_context_add_group (*context, ipc_group_array[i]); + } +} + +GstdStatus +gstd_manager_new (GstDManager ** out, int argc, char *argv[]) +{ + GstdStatus ret = GSTD_LIB_OK; + GstDManager *manager = NULL; + GstdSession *session = NULL; + + gstd_assert_and_ret_val (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; +} + void gstd_manager_free (GstDManager * manager) { diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h index 40701302..e0a7998c 100644 --- a/libgstd/libgstd.h +++ b/libgstd/libgstd.h @@ -83,12 +83,13 @@ typedef enum /** - * gstd_init_get_option_group: + * gstd_get_option_context: * * Returns: A GOptionGroup with GStreamer's argument specification. * */ -GOptionGroup* gstd_init_get_option_group (void); +void +gstd_get_option_context (GstDManager *manager, GOptionContext **context); /** * gstd_manager_new: @@ -106,30 +107,7 @@ gstd_manager_new (GstDManager ** out, int argc, char *argv[]); /** - * gstd_manager_set_ipc: - * - * @manager: The manager returned by gstd_manager_new() - * @supported_ipcs: ipcs the user will use - * @num_ipcs: length of supported_ipcs - * - * It will initialize the GstdIpc in GstDManager. - * - */ -void gstd_manager_set_ipc (GstDManager * manager, const SupportedIpcs supported_ipcs[], const guint num_ipcs); - -/** - * gstd_manager_ipc_options: - * @manager: The manager returned by gstd_manager_new() - * @ipc_group: placeholder for IPCs specifications - * - * Get IPCs information into a group - * - */ -void -gstd_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]); - -/** - * gstd_manager_ipc_start: + * gstd_manager_start: * @manager: The manager returned by gstd_manager_new() * * Starts the ipc in GstdIpc array @@ -137,19 +115,7 @@ gstd_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]); * Returns: GstdStatus indicating success or fail */ int -gstd_manager_ipc_start (GstDManager * manager); - -/** - * gstd_manager_ipc_start: - * @manager: The manager returned by gstd_manager_new() - * - * Stops the ipc in GstdIpc array - * - * Returns: GstdStatus indicating success or fail - */ -void -gstd_manager_ipc_stop (GstDManager * manager); - +gstd_manager_start (GstDManager * manager); /** * gstd_manager_free: diff --git a/libgstd/meson.build b/libgstd/meson.build index 990e4bb3..c54b94cc 100644 --- a/libgstd/meson.build +++ b/libgstd/meson.build @@ -4,59 +4,59 @@ gstd_headers = [ # Common files needed for GstD and libGstD gstd_src = [ - '../gstd/gstd_object.c', - '../gstd/gstd_pipeline.c', - '../gstd/gstd_element.c', - '../gstd/gstd_list.c', - '../gstd/gstd_ipc.c', - '../gstd/gstd_tcp.c', - '../gstd/gstd_http.c', - '../gstd/gstd_icreator.c', - '../gstd/gstd_iformatter.c', - '../gstd/gstd_pipeline_creator.c', - '../gstd/gstd_no_creator.c', - '../gstd/gstd_json_builder.c', - '../gstd/gstd_ideleter.c', - '../gstd/gstd_pipeline_deleter.c', - '../gstd/gstd_no_deleter.c', - '../gstd/gstd_debug.c', - '../gstd/gstd_event_creator.c', - '../gstd/gstd_event_factory.c', - '../gstd/gstd_pipeline_bus.c', - '../gstd/gstd_ireader.c', - '../gstd/gstd_property_reader.c', - '../gstd/gstd_no_reader.c', - '../gstd/gstd_list_reader.c', - '../gstd/gstd_property.c', - '../gstd/gstd_property_int.c', - '../gstd/gstd_property_string.c', - '../gstd/gstd_property_boolean.c', - '../gstd/gstd_property_array.c', - '../gstd/gstd_iupdater.c', - '../gstd/gstd_no_updater.c', - '../gstd/gstd_property_enum.c', - '../gstd/gstd_property_flags.c', - '../gstd/gstd_event_handler.c', - '../gstd/gstd_bus_msg.c', - '../gstd/gstd_bus_msg_simple.c', - '../gstd/gstd_bus_msg_notify.c', - '../gstd/gstd_bus_msg_state_changed.c', - '../gstd/gstd_msg_reader.c', - '../gstd/gstd_msg_type.c', - '../gstd/gstd_bus_msg_qos.c', - '../gstd/gstd_return_codes.c', - '../gstd/gstd_state.c', - '../gstd/gstd_parser.c', - '../gstd/gstd_log.c', - '../gstd/gstd_bus_msg_stream_status.c', - '../gstd/gstd_bus_msg_element.c', - '../gstd/gstd_signal.c', - '../gstd/gstd_signal_list.c', - '../gstd/gstd_callback.c', - '../gstd/gstd_signal_reader.c', - '../gstd/gstd_session.c', - '../gstd/gstd_socket.c', - '../gstd/gstd_unix.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_signal_list.c', + 'gstd_callback.c', + 'gstd_signal_reader.c', + 'gstd_session.c', + 'gstd_socket.c', + 'gstd_unix.c' ] libgstd_src = [ diff --git a/tests/gstd/Makefile.am b/tests/gstd/Makefile.am index 934c51c8..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)/libgstd/libgstd-1.0.la diff --git a/tests/gstd/meson.build b/tests/gstd/meson.build index 0625a14e..c2d064d9 100644 --- a/tests/gstd/meson.build +++ b/tests/gstd/meson.build @@ -37,7 +37,7 @@ 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], ) From 82e9898c07cd67fabedd3a58f1b947e63ad27b32 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Thu, 2 Sep 2021 11:46:49 -0600 Subject: [PATCH 12/13] Improve GOptions management Remove supported_ipcs array from gstd application. Now it's in libgstd Create a single function to get all GstD options (GStreamer Options + IPC options) Rename gstd_manager_ipc_start to gstd_manager_start Fix in spacing for Makefile.am files --- gstd/Makefile.am | 8 +-- gstd/gstd.c | 40 ++--------- libgstd/Makefile.am | 2 +- libgstd/libgstd.c | 158 ++++++++++++++++++++++++-------------------- libgstd/libgstd.h | 44 ++---------- 5 files changed, 102 insertions(+), 150 deletions(-) diff --git a/gstd/Makefile.am b/gstd/Makefile.am index 63105277..5096af4a 100644 --- a/gstd/Makefile.am +++ b/gstd/Makefile.am @@ -3,8 +3,8 @@ bin_PROGRAMS = gstd gstd_SOURCES = gstd.c gstd_daemon.c -gstd_CFLAGS = \ - $(GST_CFLAGS) \ +gstd_CFLAGS = \ + $(GST_CFLAGS) \ -I$(top_srcdir)/libgstd/ \ $(GIO_CFLAGS) \ $(LIBSOUP_CFLAGS) \ @@ -14,7 +14,7 @@ gstd_CFLAGS = \ -DGSTD_LOG_STATE_DIR=\"$(GSTD_LOG_STATE_DIR)\" \ -DGSTD_RUN_STATE_DIR=\"$(GSTD_RUN_STATE_DIR)\" -gstd_LDFLAGS = $(GST_LIBS) \ +gstd_LDFLAGS = $(GST_LIBS) \ $(GIO_LIBS) \ $(GIO_UNIX_LIBS) \ $(GJSON_LIBS) \ @@ -25,7 +25,7 @@ gstd_LDFLAGS = $(GST_LIBS) \ gstd_LDADD = $(top_srcdir)/libgstd/libgstd-1.0.la gstdincludedir = $(includedir)/gstd -gstdinclude_HEADERS = \ +gstdinclude_HEADERS = \ gstd_session.h \ gstd_object.h \ gstd_return_codes.h \ diff --git a/gstd/gstd.c b/gstd/gstd.c index e46e8cfa..e8aaec31 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -25,11 +25,6 @@ #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" @@ -75,24 +70,13 @@ main (gint argc, gchar * argv[]) gchar *pidfile = NULL; GError *error = NULL; GOptionContext *context = NULL; - GOptionGroup *gstreamer_group = NULL; - GOptionGroup **ipc_group_array = NULL; gint ret = EXIT_SUCCESS; gchar *current_filename = NULL; + gchar *filename = NULL; + gboolean parent = FALSE; GstDManager *manager = NULL; - /* Array to specify gstd how many IPCs are supported, - * SupportedIpcs should be added 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)); - GOptionEntry entries[] = { {"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Print current gstd version and exit", NULL} @@ -123,17 +107,8 @@ main (gint argc, gchar * argv[]) g_option_context_add_main_entries (context, entries, NULL); /* Initialize GStreamer */ - gstreamer_group = gstd_init_get_option_group (); gstd_manager_new (&manager, 0, NULL); - g_option_context_add_group (context, gstreamer_group); - gstd_manager_set_ipc (manager, supported_ipcs, num_ipcs); - - /* Read option group for each IPC */ - ipc_group_array = g_malloc0 (num_ipcs * sizeof (*ipc_group_array)); - gstd_manager_ipc_options (manager, ipc_group_array); /* If you don't want this option, you can avoid calling this function */ - for (int i = 0; i < num_ipcs; i++) { - g_option_context_add_group (context, ipc_group_array[i]); - } + gstd_get_option_context (manager, &context); /* Parse the options before starting */ if (!g_option_context_parse (context, &argc, &argv, &error)) { @@ -173,8 +148,6 @@ main (gint argc, gchar * argv[]) } if (daemon) { - gboolean parent; - if (!gstd_daemon_start (&parent)) { goto error; } @@ -182,7 +155,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"); @@ -193,7 +165,7 @@ main (gint argc, gchar * argv[]) } /* Start IPC subsystem */ - if (!gstd_manager_ipc_start (manager)) { + if (!gstd_manager_start (manager)) { goto error; } @@ -214,9 +186,6 @@ main (gint argc, gchar * argv[]) g_main_loop_unref (main_loop); main_loop = NULL; - /* Stop any IPC array */ - gstd_manager_ipc_stop (manager); - gstd_log_deinit (); goto out; @@ -232,7 +201,6 @@ main (gint argc, gchar * argv[]) } out: { - g_free (ipc_group_array); gstd_manager_free (manager); return ret; } diff --git a/libgstd/Makefile.am b/libgstd/Makefile.am index 9a4e21ec..06f59862 100644 --- a/libgstd/Makefile.am +++ b/libgstd/Makefile.am @@ -60,7 +60,7 @@ libgstd_@GSTD_API_VERSION@_la_SOURCES = \ ../gstd/gstd_unix.c \ ../gstd/gstd_signal_list.c -libgstd_@GSTD_API_VERSION@_la_CFLAGS = \ +libgstd_@GSTD_API_VERSION@_la_CFLAGS = \ $(GST_CFLAGS) \ -I$(top_srcdir)/gstd/ \ $(GIO_CFLAGS) \ diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c index 85269346..95abc438 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -45,6 +45,8 @@ static GType gstd_supported_ipc_to_ipc (const SupportedIpcs code); static void gstd_manager_init (int argc, char *argv[]); +static void gstd_manager_ipc_stop (GstDManager * manager); +static void gstd_manager_set_ipc (GstDManager * manager); struct _GstDManager { @@ -77,76 +79,8 @@ gstd_manager_init (int argc, char *argv[]) gstd_debug_init (); } -GOptionGroup * -gstd_init_get_option_group (void) -{ - return gst_init_get_option_group (); -} - -GstdStatus -gstd_manager_new (GstDManager ** out, int argc, char *argv[]) -{ - GstdStatus ret = GSTD_LIB_OK; - GstDManager *manager = NULL; - GstdSession *session = NULL; - - gstd_assert_and_ret_val (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; - - *out = manager; - - /* Initialize GStreamer */ - gstd_manager_init (argc, argv); - - return ret; -} - -void -gstd_manager_set_ipc (GstDManager * manager, - const SupportedIpcs supported_ipcs[], const guint num_ipcs) -{ - - GstdIpc **ipc_array = NULL; - - gstd_assert_and_ret (NULL != manager); - gstd_assert_and_ret (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_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]) -{ - gstd_assert_and_ret (NULL != manager); - gstd_assert_and_ret (NULL != manager->ipc_array); - gstd_assert_and_ret (NULL != ipc_group); - - for (gint ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) { - gstd_ipc_get_option_group (manager->ipc_array[ipc_idx], - &ipc_group[ipc_idx]); - } -} - gboolean -gstd_manager_ipc_start (GstDManager * manager) +gstd_manager_start (GstDManager * manager) { gboolean ipc_selected = FALSE; gboolean ret = TRUE; @@ -185,7 +119,7 @@ gstd_manager_ipc_start (GstDManager * manager) return ret; } -void +static void gstd_manager_ipc_stop (GstDManager * manager) { gstd_assert_and_ret (NULL != manager); @@ -202,6 +136,90 @@ gstd_manager_ipc_stop (GstDManager * manager) } } +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; + + gstd_assert_and_ret (NULL != manager); + gstd_assert_and_ret (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_get_option_context (GstDManager * manager, GOptionContext ** context) +{ + GOptionGroup *gst_options = NULL; + GOptionGroup **ipc_group_array = NULL; + + gstd_assert_and_ret (NULL != manager); + gstd_assert_and_ret (NULL != manager->ipc_array); + gstd_assert_and_ret (NULL != context); + + gst_options = gst_init_get_option_group (); + 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, gst_options); + for (int i = 0; i < manager->num_ipcs; i++) { + g_option_context_add_group (*context, ipc_group_array[i]); + } +} + +GstdStatus +gstd_manager_new (GstDManager ** out, int argc, char *argv[]) +{ + GstdStatus ret = GSTD_LIB_OK; + GstDManager *manager = NULL; + GstdSession *session = NULL; + + gstd_assert_and_ret_val (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; +} + void gstd_manager_free (GstDManager * manager) { diff --git a/libgstd/libgstd.h b/libgstd/libgstd.h index 40701302..e0a7998c 100644 --- a/libgstd/libgstd.h +++ b/libgstd/libgstd.h @@ -83,12 +83,13 @@ typedef enum /** - * gstd_init_get_option_group: + * gstd_get_option_context: * * Returns: A GOptionGroup with GStreamer's argument specification. * */ -GOptionGroup* gstd_init_get_option_group (void); +void +gstd_get_option_context (GstDManager *manager, GOptionContext **context); /** * gstd_manager_new: @@ -106,30 +107,7 @@ gstd_manager_new (GstDManager ** out, int argc, char *argv[]); /** - * gstd_manager_set_ipc: - * - * @manager: The manager returned by gstd_manager_new() - * @supported_ipcs: ipcs the user will use - * @num_ipcs: length of supported_ipcs - * - * It will initialize the GstdIpc in GstDManager. - * - */ -void gstd_manager_set_ipc (GstDManager * manager, const SupportedIpcs supported_ipcs[], const guint num_ipcs); - -/** - * gstd_manager_ipc_options: - * @manager: The manager returned by gstd_manager_new() - * @ipc_group: placeholder for IPCs specifications - * - * Get IPCs information into a group - * - */ -void -gstd_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]); - -/** - * gstd_manager_ipc_start: + * gstd_manager_start: * @manager: The manager returned by gstd_manager_new() * * Starts the ipc in GstdIpc array @@ -137,19 +115,7 @@ gstd_manager_ipc_options (GstDManager * manager, GOptionGroup * ipc_group[]); * Returns: GstdStatus indicating success or fail */ int -gstd_manager_ipc_start (GstDManager * manager); - -/** - * gstd_manager_ipc_start: - * @manager: The manager returned by gstd_manager_new() - * - * Stops the ipc in GstdIpc array - * - * Returns: GstdStatus indicating success or fail - */ -void -gstd_manager_ipc_stop (GstDManager * manager); - +gstd_manager_start (GstDManager * manager); /** * gstd_manager_free: From ed1d189d26633db4a33c338cbb7375f23bf91629 Mon Sep 17 00:00:00 2001 From: Joseda8 Date: Wed, 8 Sep 2021 14:35:38 -0600 Subject: [PATCH 13/13] Fix GStreamer deactivation in manager_free method and unnecessary includes in gstd.c --- gstd/gstd.c | 3 +-- libgstd/libgstd.c | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/gstd/gstd.c b/gstd/gstd.c index be74849b..27b7c126 100644 --- a/gstd/gstd.c +++ b/gstd/gstd.c @@ -22,8 +22,6 @@ #endif #include -#include -#include #include "gstd_daemon.h" #include "gstd_log.h" @@ -208,6 +206,7 @@ main (gint argc, gchar * argv[]) } out: { + gst_deinit (); gstd_manager_free (manager); return ret; } diff --git a/libgstd/libgstd.c b/libgstd/libgstd.c index 5eabe52c..c3fbefe6 100644 --- a/libgstd/libgstd.c +++ b/libgstd/libgstd.c @@ -242,5 +242,4 @@ gstd_manager_free (GstDManager * manager) g_free (manager->ipc_array); g_object_unref (manager->session); g_free (manager); - gst_deinit (); }