vacompositor: check caps and info return values

Check return values for get caps and video info from caps.

This was flagged by static analysis.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2480>
This commit is contained in:
U. Artie Eoff 2022-05-24 10:21:31 -04:00 committed by GStreamer Marge Bot
parent 39b13fcdbd
commit 8a161880fc

View file

@ -777,7 +777,13 @@ _get_sinkpad_pool (GstVaCompositor * const self, GstVaCompositorPad * const pad)
gst_allocation_params_init (&params); gst_allocation_params_init (&params);
caps = gst_pad_get_current_caps (GST_PAD (pad)); caps = gst_pad_get_current_caps (GST_PAD (pad));
gst_video_info_from_caps (&info, caps); if (!caps)
return NULL;
if (!gst_video_info_from_caps (&info, caps)) {
GST_ERROR_OBJECT (self, "Cannot parse caps %" GST_PTR_FORMAT, caps);
gst_caps_unref (caps);
return NULL;
}
size = GST_VIDEO_INFO_SIZE (&info); size = GST_VIDEO_INFO_SIZE (&info);
@ -892,21 +898,15 @@ extern GRecMutex GST_VA_SHARED_LOCK;
static gboolean static gboolean
_try_import_buffer (GstVaCompositor * const self, _try_import_buffer (GstVaCompositor * const self,
GstVaCompositorPad * const pad, GstBuffer * inbuf) GstVideoInfo info, GstBuffer * inbuf)
{ {
VASurfaceID surface; VASurfaceID surface;
GstCaps *caps;
GstVideoInfo info;
gboolean ret; gboolean ret;
surface = gst_va_buffer_get_surface (inbuf); surface = gst_va_buffer_get_surface (inbuf);
if (surface != VA_INVALID_ID) if (surface != VA_INVALID_ID)
return TRUE; return TRUE;
caps = gst_pad_get_current_caps (GST_PAD (pad));
gst_video_info_from_caps (&info, caps);
gst_caps_unref (caps);
g_rec_mutex_lock (&GST_VA_SHARED_LOCK); g_rec_mutex_lock (&GST_VA_SHARED_LOCK);
ret = _try_import_dmabuf_unlocked (self, &info, inbuf); ret = _try_import_dmabuf_unlocked (self, &info, inbuf);
g_rec_mutex_unlock (&GST_VA_SHARED_LOCK); g_rec_mutex_unlock (&GST_VA_SHARED_LOCK);
@ -926,12 +926,24 @@ gst_va_compositor_import_buffer (GstVaCompositor * const self,
GstVideoFrame in_frame, out_frame; GstVideoFrame in_frame, out_frame;
gboolean imported, copied; gboolean imported, copied;
imported = _try_import_buffer (self, pad, inbuf); caps = gst_pad_get_current_caps (GST_PAD (pad));
if (!caps)
return GST_FLOW_ERROR;
if (!gst_video_info_from_caps (&info, caps)) {
GST_ERROR_OBJECT (self, "Cannot parse caps %" GST_PTR_FORMAT, caps);
gst_caps_unref (caps);
return GST_FLOW_ERROR;
}
gst_caps_unref (caps);
imported = _try_import_buffer (self, info, inbuf);
if (imported) { if (imported) {
*buf = gst_buffer_ref (inbuf); *buf = gst_buffer_ref (inbuf);
return GST_FLOW_OK; return GST_FLOW_OK;
} }
GST_LOG_OBJECT (self, "copying input frame");
/* input buffer doesn't come from a vapool, thus it is required to /* input buffer doesn't come from a vapool, thus it is required to
* have a pool, grab from it a new buffer and copy the input * have a pool, grab from it a new buffer and copy the input
* buffer to the new one */ * buffer to the new one */
@ -942,12 +954,6 @@ gst_va_compositor_import_buffer (GstVaCompositor * const self,
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
return ret; return ret;
GST_LOG_OBJECT (self, "copying input frame");
caps = gst_pad_get_current_caps (GST_PAD (pad));
gst_video_info_from_caps (&info, caps);
gst_caps_unref (caps);
if (!gst_video_frame_map (&in_frame, &info, inbuf, GST_MAP_READ)) if (!gst_video_frame_map (&in_frame, &info, inbuf, GST_MAP_READ))
goto invalid_buffer; goto invalid_buffer;