Skip to content

Commit 976e9ef

Browse files
committed
vcomp/lavc: fix init fail
Due to recent changes, libavcodec initialization fails because trying to register the lavc module prior to vcomp. This crashes due to the recent changes but it has been a dark zone so far. Initialize the vcomp module correctly prior to the lavc. + add assert to module_register that would catch this problem
1 parent 9ac2c6b commit 976e9ef

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/module.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void module_register(struct module *module_data, struct module *parent)
9090
if (parent == NULL) {
9191
return;
9292
}
93+
assert(parent->module_priv != NULL);
9394
module_priv->parent = parent->module_priv;
9495
module_mutex_lock(&parent->module_priv->lock);
9596
simple_linked_list_append(parent->module_priv->children, module_priv);

src/video_compress.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,17 @@ struct compress_state_real {
9999
* state. The point of doing this is to allow dynamic reconfiguration of the real state.
100100
*/
101101
struct compress_state {
102+
explicit compress_state(struct module *parent)
103+
{
104+
module_init_default(&mod);
105+
mod.cls = MODULE_CLASS_COMPRESS;
106+
mod.priv_data = this;
107+
module_register(&mod, parent);
108+
}
109+
~compress_state() { module_done(&mod); }
110+
102111
struct module mod; ///< compress module data
103-
struct compress_state_real *ptr; ///< pointer to real compress state
112+
struct compress_state_real *ptr{}; ///< pointer to real compress state
104113
synchronized_queue<shared_ptr<video_frame>, 1> queue;
105114
bool poisoned = false;
106115
};
@@ -195,11 +204,7 @@ static void compress_process_message(struct compress_state *proxy, struct msg_ch
195204
*/
196205
int compress_init(struct module *parent, const char *config_string, struct compress_state **state) {
197206
struct compress_state *proxy;
198-
proxy = new struct compress_state();
199-
200-
module_init_default(&proxy->mod);
201-
proxy->mod.cls = MODULE_CLASS_COMPRESS;
202-
proxy->mod.priv_data = proxy;
207+
proxy = new struct compress_state(parent);
203208

204209
try {
205210
proxy->ptr = compress_state_real::create(&proxy->mod, config_string, proxy);
@@ -208,7 +213,6 @@ int compress_init(struct module *parent, const char *config_string, struct compr
208213
return i;
209214
}
210215

211-
module_register(&proxy->mod, parent);
212216

213217
*state = proxy;
214218
return 0;
@@ -497,7 +501,6 @@ compress_done(struct compress_state *proxy)
497501
}
498502

499503
delete s;
500-
module_done(&proxy->mod);
501504
delete proxy;
502505
}
503506

0 commit comments

Comments
 (0)