Skip to content

Commit

Permalink
video_compress: del state with compress_done
Browse files Browse the repository at this point in the history
The whole stuff with generic modules is mostly abandoned and
module::deleter should not be used, anyways.
  • Loading branch information
MartinPulec committed Mar 8, 2024
1 parent fc46a7a commit 0557730
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
21 changes: 8 additions & 13 deletions src/video_compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @brief Video compress functions.
*/
/*
* Copyright (c) 2011-2023 CESNET z.s.p.o.
* Copyright (c) 2011-2024 CESNET z.s.p.o.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -37,18 +37,13 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config_unix.h"
#include "config_win32.h"
#endif // HAVE_CONFIG_H

#include <cassert>
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <memory>
#include <stdio.h>
#include <string>
#include <string.h>
#include <thread>
#include <vector>

Expand Down Expand Up @@ -111,7 +106,6 @@ struct compress_state {

static shared_ptr<video_frame> compress_frame_tiles(struct compress_state *proxy,
shared_ptr<video_frame> frame);
static void compress_done(struct module *mod);

/// @brief Displays list of available compressions.
void show_compress_help(bool full)
Expand Down Expand Up @@ -203,7 +197,6 @@ int compress_init(struct module *parent, const char *config_string, struct compr
module_init_default(&proxy->mod);
proxy->mod.cls = MODULE_CLASS_COMPRESS;
proxy->mod.priv_data = proxy;
proxy->mod.deleter = compress_done;

try {
proxy->ptr = compress_state_real::create(&proxy->mod, config_string, proxy);
Expand Down Expand Up @@ -486,18 +479,20 @@ static shared_ptr<video_frame> compress_frame_tiles(struct compress_state *proxy
* @brief Video compression cleanup function.
* @param mod video compress module
*/
static void compress_done(struct module *mod)
void
compress_done(struct compress_state *proxy)
{
if(!mod)
if (proxy == nullptr) {
return;
}

struct compress_state *proxy = (struct compress_state *) mod->priv_data;
struct compress_state_real *s = proxy->ptr;
if (!proxy->poisoned) { // pass poisoned pill if it wasn't
compress_frame(proxy, {});
}

delete s;
module_done(&proxy->mod);
delete proxy;
}

Expand Down
3 changes: 2 additions & 1 deletion src/video_compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @brief API for video compress drivers.
*/
/*
* Copyright (c) 2009-2023 CESNET, z. s. p. o.
* Copyright (c) 2009-2024 CESNET, z. s. p. o.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -93,6 +93,7 @@ typedef struct module *(*compress_init_t)(struct module *parent,
void show_compress_help(bool full);
// documented at definition
int compress_init(struct module *parent, const char *config_string, struct compress_state **);
void compress_done(struct compress_state *);
#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/video_rxtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ video_rxtx::video_rxtx(map<string, param_u> const &params): m_port_id("default")

} catch (...) {
if (m_compression) {
module_done(CAST_MODULE(m_compression));
compress_done(m_compression);
}

module_done(&m_receiver_mod);
Expand All @@ -112,7 +112,7 @@ video_rxtx::~video_rxtx() {
send(NULL);
compress_pop(m_compression);
}
module_done(CAST_MODULE(m_compression));
compress_done(m_compression);
module_done(&m_receiver_mod);
module_done(&m_sender_mod);
}
Expand Down

0 comments on commit 0557730

Please sign in to comment.