mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-27 11:32:51 +00:00
v4l2: codec: Fix GValue leak
The levels and profiles probe function returned a dynamically allocated GValue that was leaked. Simplify this by using a stack allocated GValue and a boolean return value. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/599>
This commit is contained in:
parent
24e08553d6
commit
d93664d65d
4 changed files with 48 additions and 41 deletions
|
@ -34,19 +34,19 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
|
||||
GValue *
|
||||
gst_v4l2_codec_probe_profiles (const GstV4l2Codec * codec, gint video_fd)
|
||||
gboolean
|
||||
gst_v4l2_codec_probe_profiles (const GstV4l2Codec * codec, gint video_fd,
|
||||
GValue * profiles)
|
||||
{
|
||||
GValue *controls = NULL;
|
||||
struct v4l2_queryctrl query_ctrl;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
memset (&query_ctrl, 0, sizeof (query_ctrl));
|
||||
query_ctrl.id = codec->profile_cid;
|
||||
|
||||
if (ioctl (video_fd, VIDIOC_QUERYCTRL, &query_ctrl) == 0) {
|
||||
if (query_ctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
|
||||
return NULL;
|
||||
}
|
||||
if (query_ctrl.flags & V4L2_CTRL_FLAG_DISABLED)
|
||||
return FALSE;
|
||||
|
||||
if (query_ctrl.type == V4L2_CTRL_TYPE_MENU) {
|
||||
struct v4l2_querymenu query_menu;
|
||||
|
@ -54,8 +54,7 @@ gst_v4l2_codec_probe_profiles (const GstV4l2Codec * codec, gint video_fd)
|
|||
memset (&query_menu, 0, sizeof (query_menu));
|
||||
query_menu.id = query_ctrl.id;
|
||||
|
||||
controls = g_new0 (GValue, 1);
|
||||
g_value_init (controls, GST_TYPE_LIST);
|
||||
g_value_init (profiles, GST_TYPE_LIST);
|
||||
for (query_menu.index = query_ctrl.minimum;
|
||||
query_menu.index <= query_ctrl.maximum; query_menu.index++) {
|
||||
if (ioctl (video_fd, VIDIOC_QUERYMENU, &query_menu) >= 0) {
|
||||
|
@ -64,32 +63,34 @@ gst_v4l2_codec_probe_profiles (const GstV4l2Codec * codec, gint video_fd)
|
|||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value,
|
||||
codec->profile_to_string (query_menu.index));
|
||||
gst_value_list_append_and_take_value (controls, &value);
|
||||
gst_value_list_append_and_take_value (profiles, &value);
|
||||
ret = TRUE;
|
||||
}
|
||||
}
|
||||
if (gst_value_list_get_size (controls) == 0) {
|
||||
g_value_unset (controls);
|
||||
controls = NULL;
|
||||
|
||||
if (gst_value_list_get_size (profiles) == 0) {
|
||||
g_value_unset (profiles);
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return controls;
|
||||
return ret;
|
||||
}
|
||||
|
||||
GValue *
|
||||
gst_v4l2_codec_probe_levels (const GstV4l2Codec * codec, gint video_fd)
|
||||
gboolean
|
||||
gst_v4l2_codec_probe_levels (const GstV4l2Codec * codec, gint video_fd,
|
||||
GValue * levels)
|
||||
{
|
||||
GValue *controls = NULL;
|
||||
struct v4l2_queryctrl query_ctrl;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
memset (&query_ctrl, 0, sizeof (query_ctrl));
|
||||
query_ctrl.id = codec->level_cid;
|
||||
|
||||
if (ioctl (video_fd, VIDIOC_QUERYCTRL, &query_ctrl) == 0) {
|
||||
if (query_ctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
|
||||
return NULL;
|
||||
}
|
||||
if (query_ctrl.flags & V4L2_CTRL_FLAG_DISABLED)
|
||||
return FALSE;
|
||||
|
||||
if (query_ctrl.type == V4L2_CTRL_TYPE_MENU) {
|
||||
struct v4l2_querymenu query_menu;
|
||||
|
@ -101,8 +102,7 @@ gst_v4l2_codec_probe_levels (const GstV4l2Codec * codec, gint video_fd)
|
|||
if (ioctl (video_fd, VIDIOC_QUERYMENU, &query_menu) >= 0) {
|
||||
gint32 i;
|
||||
|
||||
controls = g_new0 (GValue, 1);
|
||||
g_value_init (controls, GST_TYPE_LIST);
|
||||
g_value_init (levels, GST_TYPE_LIST);
|
||||
|
||||
/* Assume that all levels below the highest one reported by the driver are supported. */
|
||||
for (i = query_ctrl.minimum; i <= query_ctrl.maximum; i++) {
|
||||
|
@ -110,11 +110,17 @@ gst_v4l2_codec_probe_levels (const GstV4l2Codec * codec, gint video_fd)
|
|||
|
||||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value, codec->level_to_string (i));
|
||||
gst_value_list_append_and_take_value (controls, &value);
|
||||
gst_value_list_append_and_take_value (levels, &value);
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
if (gst_value_list_get_size (levels) == 0) {
|
||||
g_value_unset (levels);
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return controls;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -40,8 +40,10 @@ struct _GstV4l2Codec {
|
|||
|
||||
};
|
||||
|
||||
GValue * gst_v4l2_codec_probe_profiles(const GstV4l2Codec * codec, gint video_fd);
|
||||
GValue * gst_v4l2_codec_probe_levels(const GstV4l2Codec * codec, gint video_fd);
|
||||
gboolean gst_v4l2_codec_probe_profiles(const GstV4l2Codec * codec, gint video_fd,
|
||||
GValue * value);
|
||||
gboolean gst_v4l2_codec_probe_levels(const GstV4l2Codec * codec, gint video_fd,
|
||||
GValue * value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -1180,16 +1180,16 @@ gst_v4l2_video_dec_register (GstPlugin * plugin, const gchar * basename,
|
|||
}
|
||||
|
||||
if (cdata->codec != NULL) {
|
||||
GValue *value = gst_v4l2_codec_probe_levels (cdata->codec, video_fd);
|
||||
if (value != NULL) {
|
||||
gst_caps_set_value (cdata->sink_caps, "level", value);
|
||||
g_value_unset (value);
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
if (gst_v4l2_codec_probe_levels (cdata->codec, video_fd, &value)) {
|
||||
gst_caps_set_value (cdata->sink_caps, "level", &value);
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
value = gst_v4l2_codec_probe_profiles (cdata->codec, video_fd);
|
||||
if (value != NULL) {
|
||||
gst_caps_set_value (cdata->sink_caps, "profile", value);
|
||||
g_value_unset (value);
|
||||
if (gst_v4l2_codec_probe_profiles (cdata->codec, video_fd, &value)) {
|
||||
gst_caps_set_value (cdata->sink_caps, "profile", &value);
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1174,18 +1174,17 @@ gst_v4l2_video_enc_register (GstPlugin * plugin, GType type,
|
|||
GType subtype;
|
||||
gchar *type_name;
|
||||
GstV4l2VideoEncCData *cdata;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
if (codec != NULL && video_fd != -1) {
|
||||
GValue *value = gst_v4l2_codec_probe_levels (codec, video_fd);
|
||||
if (value != NULL) {
|
||||
gst_caps_set_value (src_caps, "level", value);
|
||||
g_value_unset (value);
|
||||
if (gst_v4l2_codec_probe_levels (codec, video_fd, &value)) {
|
||||
gst_caps_set_value (src_caps, "level", &value);
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
value = gst_v4l2_codec_probe_profiles (codec, video_fd);
|
||||
if (value != NULL) {
|
||||
gst_caps_set_value (src_caps, "profile", value);
|
||||
g_value_unset (value);
|
||||
if (gst_v4l2_codec_probe_profiles (codec, video_fd, &value)) {
|
||||
gst_caps_set_value (src_caps, "profile", &value);
|
||||
g_value_unset (&value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue