Skip to content

Commit cd32693

Browse files
committed
unregister video decoder module when deactivated
Every video stream has its own decoder. So that when received new stream (eg. sender restart), new decoder is created while the old is just deactivated (display is removed and assigned to the newly created one). But the decoder lives for some time (AFAIK removed after RTP timeout, which is IIRC 30 sec). During the period, multiple decoders co-exist under the same path "receiver.decoder". Since the keycontrol prints the format obtained via control socket, almost certainly the message will be delivered to the old (inactive) decoder with the old format. As the solution we added module descturction when module is deactivated. Also renamed the `video_decoder_remove_display()` to `video_decoder_deactivate()` (2 things are done now). Removed video_decoder_register_display() from external API - it would not register the module again, so it cannot be used to revert the _deactivate() call now. Currently not used, anyways.
1 parent a49aa71 commit cd32693

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/rtp/video_decoders.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ static void *fec_thread(void *args);
188188
static void *decompress_thread(void *args);
189189
static void cleanup(struct state_video_decoder *decoder);
190190
static void decoder_process_message(struct module *);
191+
static bool video_decoder_register_display(struct state_video_decoder *decoder,
192+
struct display *display);
191193

192194
static int sum_map(map<int, int> const & m) {
193195
int ret = 0;
@@ -861,7 +863,9 @@ ADD_TO_PARAM("decoder-use-codec",
861863
* @param display new display to be registered
862864
* @return whether registration was successful
863865
*/
864-
bool video_decoder_register_display(struct state_video_decoder *decoder, struct display *display)
866+
static bool
867+
video_decoder_register_display(struct state_video_decoder *decoder,
868+
struct display *display)
865869
{
866870
assert(display != NULL);
867871
assert(decoder->display == NULL);
@@ -936,14 +940,18 @@ bool video_decoder_register_display(struct state_video_decoder *decoder, struct
936940
}
937941

938942
/**
939-
* @brief This removes display from current decoder.
943+
* This removes display from current decoder and uninitializes module so that it
944+
* won't respond on messages (newly created decoder should).
940945
*
941946
* From now on, no video frames will be decoded with current decoder.
942-
* @see decoder_register_display - the counterpart of this function
947+
* video_decoder_register_display() used to re-enable decoder but it is not
948+
* currently used and as this now also deactivates the module, this should be
949+
* re-enabled as well.
943950
*
944951
* @param decoder decoder from which will the decoder be removed
945952
*/
946-
void video_decoder_remove_display(struct state_video_decoder *decoder)
953+
void
954+
video_decoder_deactivate(struct state_video_decoder *decoder)
947955
{
948956
if (decoder->display) {
949957
video_decoder_stop_threads(decoder);
@@ -954,6 +962,10 @@ void video_decoder_remove_display(struct state_video_decoder *decoder)
954962
decoder->display = NULL;
955963
memset(&decoder->display_desc, 0, sizeof(decoder->display_desc));
956964
}
965+
if (decoder->mod.cls) {
966+
module_done(&decoder->mod);
967+
decoder->mod.cls = MODULE_CLASS_NONE;
968+
}
957969
}
958970

959971
static void cleanup(struct state_video_decoder *decoder)
@@ -987,7 +999,7 @@ void video_decoder_destroy(struct state_video_decoder *decoder)
987999
decoder->dec_funcs->destroy(decoder->decrypt);
9881000
}
9891001

990-
video_decoder_remove_display(decoder);
1002+
video_decoder_deactivate(decoder);
9911003

9921004
cleanup(decoder);
9931005

src/rtp/video_decoders.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
/*
1212
* Copyright (c) 2003 University of Southern California
13-
* Copyright (c) 2005-2013 CESNET z.s.p.o.
13+
* Copyright (c) 2005-2026 CESNET, zájmové sdružení právnických osob
1414
*
1515
* Redistribution and use in source and binary forms, with or without
1616
* modification, is permitted provided that the following conditions
@@ -71,8 +71,7 @@ int decode_video_frame(struct coded_data *received_data, void *decoder_data, str
7171
struct state_video_decoder *video_decoder_init(struct module *parent, enum video_mode,
7272
struct display *display, const char *encryption);
7373
void video_decoder_destroy(struct state_video_decoder *decoder);
74-
bool video_decoder_register_display(struct state_video_decoder *decoder, struct display *display);
75-
void video_decoder_remove_display(struct state_video_decoder *decoder);
74+
void video_decoder_deactivate(struct state_video_decoder *decoder);
7675
bool parse_video_hdr(const uint32_t *hdr, struct video_desc *desc);
7776

7877
/** @} */ // end of video_rtp_decoder

src/video_rxtx/ultragrid_rtp.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ void ultragrid_rtp_video_rxtx::remove_display_from_decoders() {
270270
pdb_iter_t it;
271271
struct pdb_e *cp = pdb_iter_init(m_rtp_common->participants, &it);
272272
while (cp != NULL) {
273-
if(cp->decoder_state)
274-
video_decoder_remove_display(
275-
((struct vcodec_state*) cp->decoder_state)->decoder);
273+
if (cp->decoder_state) {
274+
video_decoder_deactivate(
275+
((struct vcodec_state *) cp->decoder_state)
276+
->decoder);
277+
}
276278
cp = pdb_iter_next(&it);
277279
}
278280
pdb_iter_done(&it);

0 commit comments

Comments
 (0)