summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2020-01-14 18:25:11 +0100
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2020-01-14 19:52:18 +0100
commit81f3a7f02bc4e4d6b38214d2816e65c63a2e3435 (patch)
tree05243378190115c406b5f86795d89c588305190c
parentf97d858237e8ed830ab7515cef8fa103f9ecf107 (diff)
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.
-rw-r--r--gst-libs/gst/vaapi/gstvaapiblend.c14
-rw-r--r--gst-libs/gst/vaapi/gstvaapiblend.h8
-rw-r--r--gst/vaapi/gstvaapioverlay.c22
3 files changed, 19 insertions, 25 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiblend.c b/gst-libs/gst/vaapi/gstvaapiblend.c
index 90e92d6b..192865e9 100644
--- a/gst-libs/gst/vaapi/gstvaapiblend.c
+++ b/gst-libs/gst/vaapi/gstvaapiblend.c
@@ -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;
diff --git a/gst-libs/gst/vaapi/gstvaapiblend.h b/gst-libs/gst/vaapi/gstvaapiblend.h
index 8fcfbc40..8c941283 100644
--- a/gst-libs/gst/vaapi/gstvaapiblend.h
+++ b/gst-libs/gst/vaapi/gstvaapiblend.h
@@ -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;
diff --git a/gst/vaapi/gstvaapioverlay.c b/gst/vaapi/gstvaapioverlay.c
index 59b1a289..37155ee4 100644
--- a/gst/vaapi/gstvaapioverlay.c
+++ b/gst/vaapi/gstvaapioverlay.c
@@ -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;