Skip to content

Commit

Permalink
video-converter: Set up matrix tables only once.
Browse files Browse the repository at this point in the history
When configuring a multi-thread converter, only allocate the
shared colour conversion matrices once for the first thread,
to avoid allocating multiple times and leaking memory.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1220>
  • Loading branch information
thaytan authored and tp-m committed Jun 28, 2021
1 parent b26b8ae commit a14c85f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions gst-libs/gst/video/video-converter.c
Expand Up @@ -1581,7 +1581,8 @@ chain_convert_to_RGB (GstVideoConverter * convert, GstLineCache * prev,
if (do_gamma) {
gint scale;

if (!convert->unpack_rgb) {
/* Set up conversion matrices if needed, but only for the first thread */
if (idx == 0 && !convert->unpack_rgb) {
color_matrix_set_identity (&convert->to_RGB_matrix);
compute_matrix_to_RGB (convert, &convert->to_RGB_matrix);

Expand Down Expand Up @@ -1833,8 +1834,10 @@ chain_convert (GstVideoConverter * convert, GstLineCache * prev, gint idx)
convert->current_bits = MAX (convert->in_bits, convert->out_bits);

do_conversion = TRUE;
if (!same_matrix || !same_primaries)
prepare_matrix (convert, &convert->convert_matrix);
if (!same_matrix || !same_primaries) {
if (idx == 0)
prepare_matrix (convert, &convert->convert_matrix);
}
if (convert->in_bits == convert->out_bits)
pass_alloc = TRUE;
} else
Expand All @@ -1848,7 +1851,8 @@ chain_convert (GstVideoConverter * convert, GstLineCache * prev, gint idx)
if (same_primaries) {
do_conversion = FALSE;
} else {
prepare_matrix (convert, &convert->convert_matrix);
if (idx == 0)
prepare_matrix (convert, &convert->convert_matrix);
convert->in_bits = convert->out_bits = 16;
pass_alloc = TRUE;
do_conversion = TRUE;
Expand Down Expand Up @@ -1970,7 +1974,7 @@ chain_convert_to_YUV (GstVideoConverter * convert, GstLineCache * prev,
convert->current_bits = convert->pack_bits;
convert->current_pstride = convert->current_bits >> 1;

if (!convert->pack_rgb) {
if (idx == 0 && !convert->pack_rgb) {
color_matrix_set_identity (&convert->to_YUV_matrix);
compute_matrix_to_YUV (convert, &convert->to_YUV_matrix, FALSE);

Expand Down

0 comments on commit a14c85f

Please sign in to comment.