I downloaded and checked the source code of ‘nvv4l2h265enc’ from:
https://developer.download.nvidia.cn/embedded/L4T/r32_Release_v5.1/r32_Release_v5.1/sources/T186/public_sources.tbz2
In file ‘gstv4l2h265enc.c’, line 391~line 404:
gboolean
gst_v4l2_is_h265_enc (GstCaps * sink_caps, GstCaps * src_caps)
{
return gst_v4l2_is_video_enc (sink_caps, src_caps,
gst_static_caps_get (&src_template_caps));
}
void
gst_v4l2_h265_enc_register (GstPlugin * plugin, const gchar * basename,
const gchar * device_path, GstCaps * sink_caps, GstCaps * src_caps)
{
gst_v4l2_video_enc_register (plugin, GST_TYPE_V4L2_H265_ENC,
“h265”, basename, device_path, sink_caps,
gst_static_caps_get (&src_template_caps), src_caps);
}
These two APIs both call 'gst_static_caps_get() '.
And from:
/**
- gst_static_caps_get:
- @static_caps: the #GstStaticCaps to convert
- Converts a #GstStaticCaps to a #GstCaps.
- Returns: (transfer full) (nullable): a pointer to the #GstCaps. Since the
-
core holds an additional ref to the returned caps, use
-
gst_caps_make_writable() on the returned caps to modify it.
*/
GstCaps *
gst_static_caps_get (GstStaticCaps * static_caps)
{
GstCaps **caps;
g_return_val_if_fail (static_caps != NULL, NULL);
caps = &static_caps->caps;
/* refcount is 0 when we need to convert */
if (G_UNLIKELY (*caps == NULL)) {
const char *string;
G_LOCK (static_caps_lock);
/* check if other thread already updated */
if (G_UNLIKELY (*caps != NULL))
goto done;
string = static_caps->string;
if (G_UNLIKELY (string == NULL))
goto no_string;
*caps = gst_caps_from_string (string);
/* convert to string */
if (G_UNLIKELY (*caps == NULL)) {
g_critical ("Could not convert static caps \"%s\"", string);
goto done;
}
/* Caps generated from static caps are usually leaked */
GST_MINI_OBJECT_FLAG_SET (*caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
GST_CAT_TRACE (GST_CAT_CAPS, "created %p from string %s", static_caps,
string);
done:
G_UNLOCK (static_caps_lock);
}
/* ref the caps, makes it not writable */
if (G_LIKELY (*caps != NULL))
gst_caps_ref (*caps);
return *caps;
/* ERRORS */
no_string:
{
G_UNLOCK (static_caps_lock);
g_warning (“static caps %p string is NULL”, static_caps);
return NULL;
}
}
Seems that ‘gst_static_caps_get()’ will return a GstCaps object with refcount >= 1.
And this GstCaps object should be ‘unref’-ed after use, in order to release the object.
However, this release is missed in both ‘gst_v4l2_is_h265_enc’ and ‘gst_v4l2_h265_enc_register’, which may possibly cause the memory leak,
as indicated by :
0:03:33.169063483 30128 0x55a1686040 TRACE GST_TRACER :0:: object-alive, type-name=(string)GstCaps, address=(gpointer)0x7f9808a320, description=(string)video/x-h265, stream-format=(string)byte-stream, alignment=(string)au, ref-count=(uint)1, trace=(string);