Skip to content

Commit

Permalink
Fixed the common handle
Browse files Browse the repository at this point in the history
  • Loading branch information
DawidWesierski4 committed Jan 27, 2025
1 parent 511ae3e commit c4152fe
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 20 deletions.
30 changes: 25 additions & 5 deletions ecosystem/gstreamer_plugin/gst_mtl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,30 @@ gboolean gst_mtl_common_parse_dev_arguments(struct mtl_init_params* mtl_init_par
return ret;
}

mtl_handle gst_mtl_common_init_handle(struct mtl_init_params* p, StDevArgs* devArgs,
guint* log_level, gboolean force_to_initialize_new) {
/**
* Initializes the device with the given parameters.
*
* If the common handle is being used, the input parameters for the device
* (rx_queues, tx_queues, dev_ip, and dev_port) may be ignored.
*
* You can always force the initialization again by setting the appropriate flag.
*
* @param rx_queues Number of receive queues.
* @param tx_queues Number of transmit queues.
* @param dev_ip IP address of the device.
* @param dev_port Port number of the device.
* @param force_init Flag to force re-initialization of the device.
*/
mtl_handle gst_mtl_common_init_handle(StDevArgs* devArgs,
guint* log_level, gboolean force_to_initialize_new_instance) {
struct mtl_init_params mtl_init_params = {0};

if (!p || !devArgs || !log_level) {
if (!devArgs || !log_level) {
GST_ERROR("Invalid input");
return NULL;
}

if (gst_mtl_common_shared_handle) {
if (!force_to_initialize_new_instance && gst_mtl_common_shared_handle) {
GST_INFO("Mtl is already initialized with shared handle %p", gst_mtl_common_shared_handle);
return gst_mtl_common_shared_handle;
}
Expand All @@ -429,5 +443,11 @@ mtl_handle gst_mtl_common_init_handle(struct mtl_init_params* p, StDevArgs* devA
}
*log_level = mtl_init_params.log_level;

return mtl_init(&mtl_init_params);
if (!gst_mtl_common_shared_handle) {
gst_mtl_common_shared_handle = mtl_init(&mtl_init_params);
return gst_mtl_common_shared_handle;
} else {
GST_INFO("MTL shared handle %p ignored" , gst_mtl_common_shared_handle);
return mtl_init(&mtl_init_params);
}
}
4 changes: 2 additions & 2 deletions ecosystem/gstreamer_plugin/gst_mtl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void gst_mtl_common_get_general_arguments(GObject* object, guint prop_id,
StDevArgs* devArgs, SessionPortArgs* portArgs,
guint* log_level);

mtl_handle gst_mtl_common_init_handle(struct mtl_init_params* p, StDevArgs* devArgs,
guint* log_level, gboolean force_to_initialize_new);
mtl_handle gst_mtl_common_init_handle(StDevArgs* devArgs,
guint* log_level, gboolean force_to_initialize_new_instance);

#endif /* __GST_MTL_COMMON_H__ */
3 changes: 1 addition & 2 deletions ecosystem/gstreamer_plugin/gst_mtl_st20p_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ static void gst_mtl_st20p_rx_class_init(Gst_Mtl_St20p_RxClass* klass) {
}

static gboolean gst_mtl_st20p_rx_start(GstBaseSrc* basesrc) {
struct mtl_init_params mtl_init_params = {0};
struct st20p_rx_ops* ops_rx;
gint ret;

Expand All @@ -208,7 +207,7 @@ static gboolean gst_mtl_st20p_rx_start(GstBaseSrc* basesrc) {
GST_DEBUG("Media Transport Initialization start");

src->mtl_lib_handle =
gst_mtl_common_init_handle(&mtl_init_params, &(src->devArgs), &(src->log_level), FALSE);
gst_mtl_common_init_handle(&(src->devArgs), &(src->log_level), FALSE);

if (!src->mtl_lib_handle) {
GST_ERROR("Could not initialize MTL");
Expand Down
3 changes: 1 addition & 2 deletions ecosystem/gstreamer_plugin/gst_mtl_st20p_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ static void gst_mtl_st20p_tx_class_init(Gst_Mtl_St20p_TxClass* klass) {
}

static gboolean gst_mtl_st20p_tx_start(GstBaseSink* bsink) {
struct mtl_init_params mtl_init_params = {0};

Gst_Mtl_St20p_Tx* sink = GST_MTL_ST20P_TX(bsink);

Expand All @@ -179,7 +178,7 @@ static gboolean gst_mtl_st20p_tx_start(GstBaseSink* bsink) {
gst_base_sink_set_async_enabled(bsink, FALSE);

sink->mtl_lib_handle =
gst_mtl_common_init_handle(&mtl_init_params, &(sink->devArgs), &(sink->log_level), FALSE);
gst_mtl_common_init_handle(&(sink->devArgs), &(sink->log_level), FALSE);

if (!sink->mtl_lib_handle) {
GST_ERROR("Could not initialize MTL");
Expand Down
3 changes: 1 addition & 2 deletions ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ static void gst_mtl_st30p_rx_class_init(Gst_Mtl_St30p_RxClass* klass) {
}

static gboolean gst_mtl_st30p_rx_start(GstBaseSrc* basesrc) {
struct mtl_init_params mtl_init_params = {0};
struct st30p_rx_ops* ops_rx;
gint ret;

Expand All @@ -194,7 +193,7 @@ static gboolean gst_mtl_st30p_rx_start(GstBaseSrc* basesrc) {
GST_DEBUG("Media Transport Initialization start");

src->mtl_lib_handle =
gst_mtl_common_init_handle(&mtl_init_params, &(src->devArgs), &(src->log_level), FALSE);
gst_mtl_common_init_handle(&(src->devArgs), &(src->log_level), FALSE);

if (!src->mtl_lib_handle) {
GST_ERROR("Could not initialize MTL");
Expand Down
3 changes: 1 addition & 2 deletions ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ static void gst_mtl_st30p_tx_class_init(Gst_Mtl_St30p_TxClass* klass) {
}

static gboolean gst_mtl_st30p_tx_start(GstBaseSink* bsink) {
struct mtl_init_params mtl_init_params = {0};

Gst_Mtl_St30p_Tx* sink = GST_MTL_ST30P_TX(bsink);

Expand All @@ -190,7 +189,7 @@ static gboolean gst_mtl_st30p_tx_start(GstBaseSink* bsink) {
gst_base_sink_set_async_enabled(bsink, FALSE);

sink->mtl_lib_handle =
gst_mtl_common_init_handle(&mtl_init_params, &(sink->devArgs), &(sink->log_level), FALSE);
gst_mtl_common_init_handle(&(sink->devArgs), &(sink->log_level), FALSE);

if (!sink->mtl_lib_handle) {
GST_ERROR("Could not initialize MTL");
Expand Down
3 changes: 1 addition & 2 deletions ecosystem/gstreamer_plugin/gst_mtl_st40_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ static void gst_mtl_st40_rx_class_init(Gst_Mtl_St40_RxClass* klass) {
}

static gboolean gst_mtl_st40_rx_start(GstBaseSrc* basesrc) {
struct mtl_init_params mtl_init_params = {0};
struct st40_rx_ops ops_rx = {0};
gint ret;

Expand All @@ -192,7 +191,7 @@ static gboolean gst_mtl_st40_rx_start(GstBaseSrc* basesrc) {
GST_DEBUG("Media Transport Initialization start");

src->mtl_lib_handle =
gst_mtl_common_init_handle(&mtl_init_params, &(src->devArgs), &(src->log_level), FALSE);
gst_mtl_common_init_handle(&(src->devArgs), &(src->log_level), FALSE);

if (!src->mtl_lib_handle) {
GST_ERROR("Could not initialize MTL");
Expand Down
4 changes: 1 addition & 3 deletions ecosystem/gstreamer_plugin/gst_mtl_st40p_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,14 @@ static void gst_mtl_st40p_tx_class_init(Gst_Mtl_St40p_TxClass* klass) {
}

static gboolean gst_mtl_st40p_tx_start(GstBaseSink* bsink) {
struct mtl_init_params mtl_init_params = {0};

Gst_Mtl_St40p_Tx* sink = GST_MTL_ST40P_TX(bsink);

GST_DEBUG_OBJECT(sink, "start");
GST_DEBUG("Media Transport Initialization start");
gst_base_sink_set_async_enabled(bsink, FALSE);

sink->mtl_lib_handle =
gst_mtl_common_init_handle(&mtl_init_params, &(sink->devArgs), &(sink->log_level), FALSE);
gst_mtl_common_init_handle(&(sink->devArgs), &(sink->log_level), FALSE);

if (!sink->mtl_lib_handle) {
GST_ERROR("Could not initialize MTL");
Expand Down

0 comments on commit c4152fe

Please sign in to comment.