mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
libs: blend: simplify generator API
Instead of using a parent structure that has to be derived by API consumers, this change propse a simplification by using the common pattern of GTK of passing a function pointer and user data which will be passed as its parameter. That user data contains the state and the function will be called to update that state.
This commit is contained in:
parent
f97d858237
commit
81f3a7f02b
3 changed files with 19 additions and 25 deletions
|
@ -210,7 +210,8 @@ gst_vaapi_blend_replace (GstVaapiBlend ** old_blend_ptr,
|
|||
|
||||
static gboolean
|
||||
gst_vaapi_blend_process_unlocked (GstVaapiBlend * blend,
|
||||
GstVaapiSurface * output, GstVaapiBlendSurfaceGenerator * generator)
|
||||
GstVaapiSurface * output, GstVaapiBlendSurfaceNextFunc next,
|
||||
gpointer user_data)
|
||||
{
|
||||
VAStatus va_status;
|
||||
VADisplay va_display;
|
||||
|
@ -223,8 +224,8 @@ gst_vaapi_blend_process_unlocked (GstVaapiBlend * blend,
|
|||
if (!vaapi_check_status (va_status, "vaBeginPicture()"))
|
||||
return FALSE;
|
||||
|
||||
current = generator->next (generator);
|
||||
for (; current; current = generator->next (generator)) {
|
||||
current = next (user_data);
|
||||
for (; current; current = next (user_data)) {
|
||||
VAProcPipelineParameterBuffer *param = NULL;
|
||||
VABufferID id = VA_INVALID_ID;
|
||||
VARectangle src_rect = { 0, };
|
||||
|
@ -290,17 +291,16 @@ gst_vaapi_blend_process_unlocked (GstVaapiBlend * blend,
|
|||
|
||||
gboolean
|
||||
gst_vaapi_blend_process (GstVaapiBlend * blend, GstVaapiSurface * output,
|
||||
GstVaapiBlendSurfaceGenerator * generator)
|
||||
GstVaapiBlendSurfaceNextFunc next, gpointer user_data)
|
||||
{
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (blend != NULL, FALSE);
|
||||
g_return_val_if_fail (output != NULL, FALSE);
|
||||
g_return_val_if_fail (generator != NULL, FALSE);
|
||||
g_return_val_if_fail (generator->next != NULL, FALSE);
|
||||
g_return_val_if_fail (next != NULL, FALSE);
|
||||
|
||||
GST_VAAPI_DISPLAY_LOCK (blend->display);
|
||||
result = gst_vaapi_blend_process_unlocked (blend, output, generator);
|
||||
result = gst_vaapi_blend_process_unlocked (blend, output, next, user_data);
|
||||
GST_VAAPI_DISPLAY_UNLOCK (blend->display);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -36,7 +36,6 @@ G_BEGIN_DECLS
|
|||
|
||||
typedef struct _GstVaapiBlend GstVaapiBlend;
|
||||
typedef struct _GstVaapiBlendSurface GstVaapiBlendSurface;
|
||||
typedef struct _GstVaapiBlendSurfaceGenerator GstVaapiBlendSurfaceGenerator;
|
||||
|
||||
struct _GstVaapiBlendSurface
|
||||
{
|
||||
|
@ -46,10 +45,7 @@ struct _GstVaapiBlendSurface
|
|||
gdouble alpha;
|
||||
};
|
||||
|
||||
struct _GstVaapiBlendSurfaceGenerator
|
||||
{
|
||||
GstVaapiBlendSurface* (*next)();
|
||||
};
|
||||
typedef GstVaapiBlendSurface* (*GstVaapiBlendSurfaceNextFunc)(gpointer data);
|
||||
|
||||
GstVaapiBlend *
|
||||
gst_vaapi_blend_new (GstVaapiDisplay * display);
|
||||
|
@ -60,7 +56,7 @@ gst_vaapi_blend_replace (GstVaapiBlend ** old_blend_ptr,
|
|||
|
||||
gboolean
|
||||
gst_vaapi_blend_process (GstVaapiBlend * blend, GstVaapiSurface * output,
|
||||
GstVaapiBlendSurfaceGenerator * generator);
|
||||
GstVaapiBlendSurfaceNextFunc next, gpointer user_data);
|
||||
|
||||
GType
|
||||
gst_vaapi_blend_get_type (void) G_GNUC_CONST;
|
||||
|
|
|
@ -69,7 +69,6 @@ G_DEFINE_TYPE (GstVaapiOverlaySinkPad, gst_vaapi_overlay_sink_pad,
|
|||
typedef struct _GstVaapiOverlaySurfaceGenerator GstVaapiOverlaySurfaceGenerator;
|
||||
struct _GstVaapiOverlaySurfaceGenerator
|
||||
{
|
||||
GstVaapiBlendSurfaceGenerator parent;
|
||||
GstVaapiOverlay *overlay;
|
||||
GList *current;
|
||||
GstVaapiBlendSurface blend_surface;
|
||||
|
@ -340,9 +339,9 @@ gst_vaapi_overlay_decide_allocation (GstAggregator * agg, GstQuery * query)
|
|||
}
|
||||
|
||||
static GstVaapiBlendSurface *
|
||||
gst_vaapi_overlay_surface_next (GstVaapiBlendSurfaceGenerator * generator)
|
||||
gst_vaapi_overlay_surface_next (gpointer data)
|
||||
{
|
||||
GstVaapiOverlaySurfaceGenerator *ogenerator;
|
||||
GstVaapiOverlaySurfaceGenerator *generator;
|
||||
GstVideoAggregatorPad *vagg_pad;
|
||||
GstVaapiOverlaySinkPad *pad;
|
||||
GstVideoFrame *inframe;
|
||||
|
@ -351,20 +350,20 @@ gst_vaapi_overlay_surface_next (GstVaapiBlendSurfaceGenerator * generator)
|
|||
GstVaapiVideoMeta *inbuf_meta;
|
||||
GstVaapiBlendSurface *blend_surface;
|
||||
|
||||
ogenerator = (GstVaapiOverlaySurfaceGenerator *) generator;
|
||||
generator = (GstVaapiOverlaySurfaceGenerator *) data;
|
||||
|
||||
/* at the end of the generator? */
|
||||
if (!ogenerator->current)
|
||||
if (!generator->current)
|
||||
return NULL;
|
||||
|
||||
/* get the current video aggregator sinkpad */
|
||||
vagg_pad = GST_VIDEO_AGGREGATOR_PAD (ogenerator->current->data);
|
||||
vagg_pad = GST_VIDEO_AGGREGATOR_PAD (generator->current->data);
|
||||
|
||||
/* increment list pointer */
|
||||
ogenerator->current = ogenerator->current->next;
|
||||
generator->current = generator->current->next;
|
||||
|
||||
/* recycle the blend surface from the overlay surface generator */
|
||||
blend_surface = &ogenerator->blend_surface;
|
||||
blend_surface = &generator->blend_surface;
|
||||
blend_surface->surface = NULL;
|
||||
|
||||
inframe = gst_video_aggregator_pad_get_prepared_frame (vagg_pad);
|
||||
|
@ -372,12 +371,12 @@ gst_vaapi_overlay_surface_next (GstVaapiBlendSurfaceGenerator * generator)
|
|||
pad = GST_VAAPI_OVERLAY_SINK_PAD (vagg_pad);
|
||||
|
||||
if (gst_vaapi_plugin_base_pad_get_input_buffer (GST_VAAPI_PLUGIN_BASE
|
||||
(ogenerator->overlay), GST_PAD (pad), buf, &inbuf) != GST_FLOW_OK)
|
||||
(generator->overlay), GST_PAD (pad), buf, &inbuf) != GST_FLOW_OK)
|
||||
return blend_surface;
|
||||
|
||||
/* Current sinkpad may have reached EOS */
|
||||
if (!inframe || !inbuf)
|
||||
return generator->next (generator);
|
||||
return gst_vaapi_overlay_surface_next (generator);
|
||||
|
||||
inbuf_meta = gst_buffer_get_vaapi_video_meta (inbuf);
|
||||
|
||||
|
@ -436,12 +435,11 @@ gst_vaapi_overlay_aggregate_frames (GstVideoAggregator * vagg,
|
|||
outbuf_surface = gst_vaapi_video_meta_get_surface (outbuf_meta);
|
||||
|
||||
/* initialize the surface generator */
|
||||
generator.parent.next = gst_vaapi_overlay_surface_next;
|
||||
generator.overlay = overlay;
|
||||
generator.current = GST_ELEMENT (overlay)->sinkpads;
|
||||
|
||||
if (!gst_vaapi_blend_process (overlay->blend, outbuf_surface,
|
||||
(GstVaapiBlendSurfaceGenerator *) & generator))
|
||||
gst_vaapi_overlay_surface_next, &generator))
|
||||
return GST_FLOW_ERROR;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
|
Loading…
Reference in a new issue