control_socket acquire: get the pointer from priv_data

Do not assume that (struct module) is first in the (struct control_state)
anymore in particular and in any structure in general.
This commit is contained in:
Martin Pulec
2025-06-17 15:55:35 +02:00
parent cda3d1b860
commit ab5d2a5cac
5 changed files with 16 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
* @author Martin Piatka <piatka@cesnet.cz>
*/
/*
* Copyright (c) 2022 CESNET, z. s. p. o.
* Copyright (c) 2022-2025 CESNET
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,9 @@
struct state_controlport_stats{
state_controlport_stats(struct module *mod) : mod(MODULE_CLASS_DATA, mod, this)
{
control = (control_state *) (get_module(get_root_module(mod), "control"));
control = (control_state *) (get_module(get_root_module(mod),
"control"))
->priv_data;
}
module_raii mod;

View File

@@ -106,8 +106,9 @@ typedef void (*notify_t)(struct module *);
struct module {
enum module_class cls;
notify_t new_message; ///< if set, notifies module that new message is in queue, receiver lock is hold during the call
void *priv_data; ///< can be used to store state pointer for
///< new_message(); uneeded otherwise
void *priv_data; ///< optional; can be used to store state pointer for
///< new_message() or to retreive the state from the
///< module (control_socket)
char name[128]; ///< optional name of the module. May be used for indexing.
struct module_priv_state *module_priv;

View File

@@ -341,7 +341,9 @@ struct state_video_decoder
mod.priv_data = this;
mod.new_message = decoder_process_message;
module_register(&mod, parent);
control = (struct control_state *) get_module(get_root_module(parent), "control");
control = (struct control_state *) get_module(
get_root_module(parent), "control")
->priv_data;
}
~state_video_decoder() {
module_done(&mod);

View File

@@ -264,8 +264,10 @@ struct tx *tx_init(struct module *parent, unsigned mtu, enum tx_media_type media
tx->bitrate = bitrate;
if(parent)
tx->control = (struct control_state *) get_module(get_root_module(parent), "control");
if (parent) {
tx->control = (struct control_state *) get_module(
get_root_module(parent), "control")->priv_data;
}
return tx;
}

View File

@@ -3,7 +3,7 @@
* @author Martin Pulec <pulec@cesnet.cz>
*/
/*
* Copyright (c) 2013-2023 CESNET z.s.p.o.
* Copyright (c) 2013-2025 CESNET
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -93,7 +93,7 @@ ultragrid_rtp_video_rxtx::ultragrid_rtp_video_rxtx(const map<string, param_u> &p
}
m_control = (struct control_state *) get_module(
get_root_module(m_common.parent), "control");
get_root_module(m_common.parent), "control")->priv_data;
}
ultragrid_rtp_video_rxtx::~ultragrid_rtp_video_rxtx()