vaapioverlay: unroll the recursive call

Recursive functions are elegant but dangerous since they might
overflow the stack. It is better to turn them into a list tranversal
if possible, as this case.
This commit is contained in:
Víctor Manuel Jáquez Leal 2020-01-14 18:57:31 +01:00
parent d0e14ec308
commit 889fac3823

View file

@ -374,49 +374,45 @@ gst_vaapi_overlay_surface_next (gpointer data)
generator = (GstVaapiOverlaySurfaceGenerator *) data; generator = (GstVaapiOverlaySurfaceGenerator *) data;
/* at the end of the generator? */ /* at the end of the generator? */
if (!generator->current) while (generator->current) {
return NULL; /* get the current video aggregator sinkpad */
vagg_pad = GST_VIDEO_AGGREGATOR_PAD (generator->current->data);
/* get the current video aggregator sinkpad */ /* increment list pointer */
vagg_pad = GST_VIDEO_AGGREGATOR_PAD (generator->current->data); generator->current = generator->current->next;
/* increment list pointer */ /* recycle the blend surface from the overlay surface generator */
generator->current = generator->current->next; blend_surface = &generator->blend_surface;
blend_surface->surface = NULL;
/* recycle the blend surface from the overlay surface generator */ inframe = gst_video_aggregator_pad_get_prepared_frame (vagg_pad);
blend_surface = &generator->blend_surface; buf = gst_video_aggregator_pad_get_current_buffer (vagg_pad);
blend_surface->surface = NULL; pad = GST_VAAPI_OVERLAY_SINK_PAD (vagg_pad);
inframe = gst_video_aggregator_pad_get_prepared_frame (vagg_pad); if (gst_vaapi_plugin_base_pad_get_input_buffer (GST_VAAPI_PLUGIN_BASE
buf = gst_video_aggregator_pad_get_current_buffer (vagg_pad); (generator->overlay), GST_PAD (pad), buf, &inbuf) != GST_FLOW_OK)
pad = GST_VAAPI_OVERLAY_SINK_PAD (vagg_pad); return blend_surface;
if (gst_vaapi_plugin_base_pad_get_input_buffer (GST_VAAPI_PLUGIN_BASE /* Current sinkpad may have reached EOS */
(generator->overlay), GST_PAD (pad), buf, &inbuf) != GST_FLOW_OK) if (!inframe || !inbuf)
return blend_surface; continue;
/* Current sinkpad may have reached EOS */ inbuf_meta = gst_buffer_get_vaapi_video_meta (inbuf);
if (!inframe || !inbuf) if (inbuf_meta) {
return gst_vaapi_overlay_surface_next (generator); blend_surface->surface = gst_vaapi_video_meta_get_surface (inbuf_meta);
blend_surface->crop = gst_vaapi_video_meta_get_render_rect (inbuf_meta);
blend_surface->target.x = pad->xpos;
blend_surface->target.y = pad->ypos;
blend_surface->target.width = GST_VIDEO_FRAME_WIDTH (inframe);
blend_surface->target.height = GST_VIDEO_FRAME_HEIGHT (inframe);
blend_surface->alpha = pad->alpha;
}
inbuf_meta = gst_buffer_get_vaapi_video_meta (inbuf);
if (!inbuf_meta) {
gst_buffer_unref (inbuf); gst_buffer_unref (inbuf);
return blend_surface; return blend_surface;
} }
blend_surface->surface = gst_vaapi_video_meta_get_surface (inbuf_meta); return NULL;
blend_surface->crop = gst_vaapi_video_meta_get_render_rect (inbuf_meta);
blend_surface->target.x = pad->xpos;
blend_surface->target.y = pad->ypos;
blend_surface->target.width = GST_VIDEO_FRAME_WIDTH (inframe);
blend_surface->target.height = GST_VIDEO_FRAME_HEIGHT (inframe);
blend_surface->alpha = pad->alpha;
gst_buffer_unref (inbuf);
return blend_surface;
} }
static GstFlowReturn static GstFlowReturn