Skip to content

Commit

Permalink
Rename GstDManager to GstD
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseda8 committed Sep 9, 2021
1 parent 5a9725c commit 4eef8cf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 66 deletions.
12 changes: 6 additions & 6 deletions gstd/gstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ main (gint argc, gchar * argv[])
gchar *filename = NULL;
gboolean parent = FALSE;

GstDManager *manager = NULL;
GstD *gstd = NULL;

GOptionEntry entries[] = {
{"version", 'v', 0, G_OPTION_ARG_NONE, &version,
Expand Down Expand Up @@ -109,8 +109,8 @@ main (gint argc, gchar * argv[])
g_option_context_add_main_entries (context, entries, NULL);

/* Initialize GStreamer */
gstd_new (&manager, 0, NULL);
gstd_context_add_group (manager, context);
gstd_new (&gstd, 0, NULL);
gstd_context_add_group (gstd, context);

/* Parse the options before starting */
if (!g_option_context_parse (context, &argc, &argv, &error)) {
Expand Down Expand Up @@ -167,7 +167,7 @@ main (gint argc, gchar * argv[])
}

/* Start IPC subsystem */
if (!gstd_start (manager)) {
if (!gstd_start (gstd)) {
goto error;
}

Expand All @@ -189,7 +189,7 @@ main (gint argc, gchar * argv[])
main_loop = NULL;

/* Stop any IPC array */
gstd_stop (manager);
gstd_stop (gstd);

gstd_log_deinit ();

Expand All @@ -207,7 +207,7 @@ main (gint argc, gchar * argv[])
out:
{
gst_deinit ();
gstd_free (manager);
gstd_free (gstd);
return ret;
}
}
92 changes: 46 additions & 46 deletions libgstd/libgstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ enum _SupportedIpcs

static GType gstd_supported_ipc_to_ipc (const SupportedIpcs code);
static void gstd_init (int argc, char *argv[]);
static void gstd_set_ipc (GstDManager * manager);
static void gstd_set_ipc (GstD * gstd);

struct _GstDManager
struct _GstD
{
GstdSession *session;
GstdIpc **ipc_array;
Expand Down Expand Up @@ -94,7 +94,7 @@ gstd_init (int argc, char *argv[])
}

static void
gstd_set_ipc (GstDManager * manager)
gstd_set_ipc (GstD * gstd)
{
/* Array to specify gstd how many IPCs are supported,
* SupportedIpcs should be added to this array.
Expand All @@ -109,7 +109,7 @@ gstd_set_ipc (GstDManager * manager)

GstdIpc **ipc_array = NULL;

g_return_if_fail (NULL != manager);
g_return_if_fail (NULL != gstd);
g_return_if_fail (NULL != supported_ipcs);

/* If there is ipcs, then initialize them */
Expand All @@ -120,30 +120,30 @@ gstd_set_ipc (GstDManager * manager)
GSTD_IPC (g_object_new (gstd_supported_ipc_to_ipc (supported_ipcs
[ipc_idx]), NULL));
}
manager->ipc_array = ipc_array;
gstd->ipc_array = ipc_array;
}

manager->num_ipcs = num_ipcs;
manager->ipc_array = ipc_array;
gstd->num_ipcs = num_ipcs;
gstd->ipc_array = ipc_array;
}

void
gstd_context_add_group (GstDManager * manager, GOptionContext * context)
gstd_context_add_group (GstD * gstd, GOptionContext * context)
{
GOptionGroup *gst_options = NULL;
GOptionGroup **ipc_group_array = NULL;

g_return_if_fail (NULL != manager);
g_return_if_fail (NULL != manager->ipc_array);
g_return_if_fail (NULL != gstd);
g_return_if_fail (NULL != gstd->ipc_array);
g_return_if_fail (NULL != context);

gst_options = gst_init_get_option_group ();
g_option_context_add_group (context, gst_options);

ipc_group_array = g_malloc0 (manager->num_ipcs * sizeof (*ipc_group_array));
ipc_group_array = g_malloc0 (gstd->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],
for (gint ipc_idx = 0; ipc_idx < gstd->num_ipcs; ipc_idx++) {
gstd_ipc_get_option_group (gstd->ipc_array[ipc_idx],
&ipc_group_array[ipc_idx]);
g_option_context_add_group (context, ipc_group_array[ipc_idx]);
}
Expand All @@ -152,24 +152,24 @@ gstd_context_add_group (GstDManager * manager, GOptionContext * context)
}

GstdStatus
gstd_new (GstDManager ** out, int argc, char *argv[])
gstd_new (GstD ** out, int argc, char *argv[])
{
GstdStatus ret = GSTD_LIB_OK;
GstDManager *manager = NULL;
GstD *gstd = NULL;
GstdSession *session = NULL;

g_return_val_if_fail (NULL != out, GSTD_NULL_ARGUMENT);

manager = (GstDManager *) g_malloc0 (sizeof (*manager));
gstd = (GstD *) g_malloc0 (sizeof (*gstd));
session = gstd_session_new ("Session0");

manager->session = session;
manager->num_ipcs = 0;
manager->ipc_array = NULL;
gstd->session = session;
gstd->num_ipcs = 0;
gstd->ipc_array = NULL;

gstd_set_ipc (manager);
gstd_set_ipc (gstd);

*out = manager;
*out = gstd;

/* Initialize GStreamer */
gstd_init (argc, argv);
Expand All @@ -178,20 +178,20 @@ gstd_new (GstDManager ** out, int argc, char *argv[])
}

gboolean
gstd_start (GstDManager * manager)
gstd_start (GstD * gstd)
{
gboolean ipc_selected = FALSE;
gboolean ret = TRUE;
GstdReturnCode code = GSTD_EOK;
gint ipc_idx;

g_return_val_if_fail (NULL != manager, GSTD_NULL_ARGUMENT);
g_return_val_if_fail (NULL != manager->ipc_array, GSTD_LIB_NOT_FOUND);
g_return_val_if_fail (NULL != manager->session, GSTD_LIB_NOT_FOUND);
g_return_val_if_fail (NULL != gstd, GSTD_NULL_ARGUMENT);
g_return_val_if_fail (NULL != gstd->ipc_array, GSTD_LIB_NOT_FOUND);
g_return_val_if_fail (NULL != gstd->session, GSTD_LIB_NOT_FOUND);

/* Verify if at least one IPC mechanism was selected */
for (ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) {
g_object_get (G_OBJECT (manager->ipc_array[ipc_idx]), "enabled",
for (ipc_idx = 0; ipc_idx < gstd->num_ipcs; ipc_idx++) {
g_object_get (G_OBJECT (gstd->ipc_array[ipc_idx]), "enabled",
&ipc_selected, NULL);

if (ipc_selected) {
Expand All @@ -201,15 +201,15 @@ gstd_start (GstDManager * manager)

/* If no IPC was selected, default to TCP */
if (!ipc_selected) {
g_object_set (G_OBJECT (manager->ipc_array[0]), "enabled", TRUE, NULL);
g_object_set (G_OBJECT (gstd->ipc_array[0]), "enabled", TRUE, NULL);
}

/* Run start for each IPC (each start method checks for the enabled flag) */
for (ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) {
code = gstd_ipc_start (manager->ipc_array[ipc_idx], manager->session);
for (ipc_idx = 0; ipc_idx < gstd->num_ipcs; ipc_idx++) {
code = gstd_ipc_start (gstd->ipc_array[ipc_idx], gstd->session);
if (code) {
g_printerr ("Couldn't start IPC : (%s)\n",
G_OBJECT_TYPE_NAME (manager->ipc_array[ipc_idx]));
G_OBJECT_TYPE_NAME (gstd->ipc_array[ipc_idx]));
ret = FALSE;
}
}
Expand All @@ -218,28 +218,28 @@ gstd_start (GstDManager * manager)
}

void
gstd_stop (GstDManager * manager)
gstd_stop (GstD * gstd)
{
g_return_if_fail (NULL != manager);
g_return_if_fail (NULL != manager->ipc_array);
g_return_if_fail (NULL != manager->session);
g_return_if_fail (NULL != gstd);
g_return_if_fail (NULL != gstd->ipc_array);
g_return_if_fail (NULL != gstd->session);

/* Run stop for each IPC */
for (gint ipc_idx = 0; ipc_idx < manager->num_ipcs; ipc_idx++) {
if (NULL != manager->ipc_array[ipc_idx]
&& TRUE == manager->ipc_array[ipc_idx]->enabled) {
gstd_ipc_stop (manager->ipc_array[ipc_idx]);
g_clear_object (&manager->ipc_array[ipc_idx]);
for (gint ipc_idx = 0; ipc_idx < gstd->num_ipcs; ipc_idx++) {
if (NULL != gstd->ipc_array[ipc_idx]
&& TRUE == gstd->ipc_array[ipc_idx]->enabled) {
gstd_ipc_stop (gstd->ipc_array[ipc_idx]);
g_clear_object (&gstd->ipc_array[ipc_idx]);
}
}
}

void
gstd_free (GstDManager * manager)
gstd_free (GstD * gstd)
{
g_return_if_fail (NULL != manager);
gstd_stop (manager);
g_free (manager->ipc_array);
g_object_unref (manager->session);
g_free (manager);
g_return_if_fail (NULL != gstd);
gstd_stop (gstd);
g_free (gstd->ipc_array);
g_object_unref (gstd->session);
g_free (gstd);
}
29 changes: 15 additions & 14 deletions libgstd/libgstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ extern "C"
#include <glib-unix.h>

/*
* GstDManager:
* GstD:
* Opaque representation of GstD state.
* This struct will have: Session, GstdIpc and num_ipcs (for now)
*/
typedef struct _GstDManager GstDManager;
typedef struct _GstD GstD;

/**
* GstdStatus:
Expand Down Expand Up @@ -65,16 +65,17 @@ typedef enum
/**
* gstd_context_add_group:
*
* Returns: A GOptionGroup with GStreamer's argument specification.
* @gstd: The gstd returned by gstd_new()
* @out: GOptionContext which will contain the GstDOptions
*
*/
void
gstd_context_add_group (GstDManager *manager, GOptionContext *context);
gstd_context_add_group (GstD *gstd, GOptionContext *context);

/**
* gstd_new:
*
* @out: placeholder for newly allocated gstd manager.
* @out: placeholder for newly allocated gstd instance.
* @argc: arguments for gst_init
* @argv: arguments for gst_init
*
Expand All @@ -83,42 +84,42 @@ gstd_context_add_group (GstDManager *manager, GOptionContext *context);
* Returns: GstdStatus indicating success or fail
*/
GstdStatus
gstd_new (GstDManager ** out, int argc, char *argv[]);
gstd_new (GstD ** out, int argc, char *argv[]);


/**
* gstd_start:
* @manager: The manager returned by gstd_new()
* @gstd: The gstd returned by gstd_new()
*
* Starts the ipc in GstdIpc array
*
* Returns: GstdStatus indicating success or fail
*/
int
gstd_start (GstDManager * manager);
gstd_start (GstD * gstd);

/**
* gstd_stop:
* @manager: The manager returned by gstd_new()
* @gstd: The gstd instance returned by gstd_new()
*
* Stops the ipc in GstdIpc array
*
* Returns: GstdStatus indicating success or fail
*/
void
gstd_stop (GstDManager * manager);
gstd_stop (GstD * gstd);

/**
* gstd_free:
* @manager: A valid manager allocated with gstd_new()
* @gstd: A valid gstd instance allocated with gstd_new()
*
* Frees a previously allocated GstDManager.
* Frees a previously allocated GstD.
*
* Returns: A newly allocated GstDManager. Use gstd_free() after
* Returns: A newly allocated GstD. Use gstd_free() after
* usage.
*/
void
gstd_free (GstDManager * manager);
gstd_free (GstD * gstd);


#ifdef __cplusplus
Expand Down

0 comments on commit 4eef8cf

Please sign in to comment.