libs: context: port to a plain C structure

The GstVaapiMiniObject is obsolete and we need to replace it. This
patch turns GstVaapiContext into a plain C structure with its own
reference counting mechanism.

Also this patch removes unused overlays attributes.

Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
This commit is contained in:
He Junyan 2019-09-24 01:01:22 +08:00 committed by GStreamer Merge Bot
parent 61de88e580
commit a6289308ee
8 changed files with 91 additions and 50 deletions

View file

@ -40,8 +40,8 @@ coded_buffer_create (GstVaapiCodedBuffer * buf, guint buf_size,
GST_VAAPI_DISPLAY_LOCK (display);
success = vaapi_create_buffer (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (context), VAEncCodedBufferType, buf_size, NULL,
&buf_id, NULL);
GST_VAAPI_CONTEXT_ID (context), VAEncCodedBufferType, buf_size,
NULL, &buf_id, NULL);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!success)
return FALSE;
@ -117,7 +117,7 @@ gst_vaapi_coded_buffer_new (GstVaapiContext * context, guint buf_size)
g_return_val_if_fail (context != NULL, NULL);
g_return_val_if_fail (buf_size > 0, NULL);
display = GST_VAAPI_OBJECT_DISPLAY (context);
display = GST_VAAPI_CONTEXT_DISPLAY (context);
g_return_val_if_fail (display != NULL, NULL);
buf = gst_vaapi_object_new (gst_vaapi_coded_buffer_class (), display);

View file

@ -47,7 +47,7 @@ static void
coded_buffer_pool_init (GstVaapiCodedBufferPool * pool,
GstVaapiContext * context, gsize buf_size)
{
pool->context = gst_vaapi_object_ref (context);
pool->context = gst_vaapi_context_ref (context);
pool->buf_size = buf_size;
}
@ -55,7 +55,8 @@ static void
coded_buffer_pool_finalize (GstVaapiCodedBufferPool * pool)
{
gst_vaapi_video_pool_finalize (GST_VAAPI_VIDEO_POOL (pool));
gst_vaapi_object_replace (&pool->context, NULL);
gst_vaapi_context_unref (pool->context);
pool->context = NULL;
}
static gpointer
@ -106,7 +107,7 @@ gst_vaapi_coded_buffer_pool_new (GstVaapiEncoder * encoder, gsize buf_size)
if (!pool)
return NULL;
gst_vaapi_video_pool_init (pool, GST_VAAPI_OBJECT_DISPLAY (context),
gst_vaapi_video_pool_init (pool, GST_VAAPI_CONTEXT_DISPLAY (context),
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_CODED_BUFFER);
coded_buffer_pool_init (GST_VAAPI_CODED_BUFFER_POOL (pool),
context, buf_size);

View file

@ -31,8 +31,7 @@
#include "gstvaapicompat.h"
#include "gstvaapicontext.h"
#include "gstvaapidisplay_priv.h"
#include "gstvaapiobject_priv.h"
#include "gstvaapisurface.h"
#include "gstvaapisurface_priv.h"
#include "gstvaapisurfacepool.h"
#include "gstvaapisurfaceproxy.h"
#include "gstvaapivideopool_priv.h"
@ -54,7 +53,7 @@ ensure_attributes (GstVaapiContext * context)
return TRUE;
context->attribs =
gst_vaapi_config_surface_attributes_get (GST_VAAPI_OBJECT_DISPLAY
gst_vaapi_config_surface_attributes_get (GST_VAAPI_CONTEXT_DISPLAY
(context), context->va_config);
return (context->attribs != NULL);
}
@ -63,7 +62,7 @@ static inline gboolean
context_get_attribute (GstVaapiContext * context, VAConfigAttribType type,
guint * out_value_ptr)
{
return gst_vaapi_get_config_attribute (GST_VAAPI_OBJECT_DISPLAY (context),
return gst_vaapi_get_config_attribute (GST_VAAPI_CONTEXT_DISPLAY (context),
context->va_profile, context->va_entrypoint, type, out_value_ptr);
}
@ -80,11 +79,11 @@ context_destroy_surfaces (GstVaapiContext * context)
static void
context_destroy (GstVaapiContext * context)
{
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
GstVaapiDisplay *const display = GST_VAAPI_CONTEXT_DISPLAY (context);
VAContextID context_id;
VAStatus status;
context_id = GST_VAAPI_OBJECT_ID (context);
context_id = GST_VAAPI_CONTEXT_ID (context);
GST_DEBUG ("context 0x%08x", context_id);
if (context_id != VA_INVALID_ID) {
@ -94,7 +93,7 @@ context_destroy (GstVaapiContext * context)
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaDestroyContext()"))
GST_WARNING ("failed to destroy context 0x%08x", context_id);
GST_VAAPI_OBJECT_ID (context) = VA_INVALID_ID;
GST_VAAPI_CONTEXT_ID (context) = VA_INVALID_ID;
}
if (context->va_config != VA_INVALID_ID) {
@ -126,7 +125,7 @@ context_ensure_surfaces (GstVaapiContext * context)
for (i = context->surfaces->len; i < num_surfaces; i++) {
surface =
gst_vaapi_surface_new_from_formats (GST_VAAPI_OBJECT_DISPLAY (context),
gst_vaapi_surface_new_from_formats (GST_VAAPI_CONTEXT_DISPLAY (context),
cip->chroma_type, cip->width, cip->height, context->attribs->formats);
if (!surface)
return FALSE;
@ -142,7 +141,7 @@ static gboolean
context_create_surfaces (GstVaapiContext * context)
{
const GstVaapiContextInfo *const cip = &context->info;
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
GstVaapiDisplay *const display = GST_VAAPI_CONTEXT_DISPLAY (context);
guint num_surfaces;
num_surfaces = cip->ref_frames + SCRATCH_SURFACES_COUNT;
@ -168,7 +167,7 @@ static gboolean
context_create (GstVaapiContext * context)
{
const GstVaapiContextInfo *const cip = &context->info;
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
GstVaapiDisplay *const display = GST_VAAPI_CONTEXT_DISPLAY (context);
VAContextID context_id;
VASurfaceID surface_id;
VAStatus status;
@ -203,7 +202,7 @@ context_create (GstVaapiContext * context)
goto cleanup;
GST_DEBUG ("context 0x%08x", context_id);
GST_VAAPI_OBJECT_ID (context) = context_id;
GST_VAAPI_CONTEXT_ID (context) = context_id;
success = TRUE;
cleanup:
@ -216,7 +215,7 @@ static gboolean
config_create (GstVaapiContext * context)
{
const GstVaapiContextInfo *const cip = &context->info;
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
GstVaapiDisplay *const display = GST_VAAPI_CONTEXT_DISPLAY (context);
VAConfigAttrib attribs[7], *attrib;
VAStatus status;
guint value, va_chroma_format, attrib_index;
@ -393,15 +392,6 @@ gst_vaapi_context_init (GstVaapiContext * context,
context->attribs = NULL;
}
static void
gst_vaapi_context_finalize (GstVaapiContext * context)
{
context_destroy (context);
context_destroy_surfaces (context);
}
GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiContext, gst_vaapi_context);
/**
* gst_vaapi_context_new:
* @display: a #GstVaapiDisplay
@ -421,11 +411,18 @@ gst_vaapi_context_new (GstVaapiDisplay * display,
g_return_val_if_fail (cip->profile, NULL);
g_return_val_if_fail (cip->entrypoint, NULL);
g_return_val_if_fail (display, NULL);
context = gst_vaapi_object_new (gst_vaapi_context_class (), display);
context = g_slice_new (GstVaapiContext);
if (!context)
return NULL;
GST_VAAPI_CONTEXT_DISPLAY (context) = gst_object_ref (display);
GST_VAAPI_CONTEXT_ID (context) = VA_INVALID_ID;
g_atomic_int_set (&context->ref_count, 1);
context->surfaces = NULL;
context->surfaces_pool = NULL;
gst_vaapi_context_init (context, cip);
if (!config_create (context))
@ -448,7 +445,7 @@ done:
/* ERRORS */
error:
{
gst_vaapi_object_unref (context);
gst_vaapi_context_unref (context);
return NULL;
}
}
@ -537,7 +534,7 @@ gst_vaapi_context_get_id (GstVaapiContext * context)
{
g_return_val_if_fail (context != NULL, VA_INVALID_ID);
return GST_VAAPI_OBJECT_ID (context);
return GST_VAAPI_CONTEXT_ID (context);
}
/**
@ -655,3 +652,42 @@ gst_vaapi_context_get_surface_attributes (GstVaapiContext * context,
return TRUE;
}
/**
* gst_vaapi_context_ref:
* @context: a #GstVaapiContext
*
* Atomically increases the reference count of the given @context by one.
*
* Returns: The same @context argument
*/
GstVaapiContext *
gst_vaapi_context_ref (GstVaapiContext * context)
{
g_return_val_if_fail (context != NULL, NULL);
g_atomic_int_inc (&context->ref_count);
return context;
}
/**
* gst_vaapi_context_unref:
* @context: a #GstVaapiContext
*
* Atomically decreases the reference count of the @context by one. If
* the reference count reaches zero, the object will be free'd.
*/
void
gst_vaapi_context_unref (GstVaapiContext * context)
{
g_return_if_fail (context != NULL);
g_return_if_fail (context->ref_count > 0);
if (g_atomic_int_dec_and_test (&context->ref_count)) {
context_destroy (context);
context_destroy_surfaces (context);
gst_vaapi_display_replace (&context->display, NULL);
g_slice_free (GstVaapiContext, context);
}
}

View file

@ -41,7 +41,6 @@ G_BEGIN_DECLS
typedef struct _GstVaapiConfigInfoEncoder GstVaapiConfigInfoEncoder;
typedef struct _GstVaapiContextInfo GstVaapiContextInfo;
typedef struct _GstVaapiContext GstVaapiContext;
typedef struct _GstVaapiContextClass GstVaapiContextClass;
/**
* GstVaapiContextUsage:
@ -105,30 +104,23 @@ struct _GstVaapiContextInfo
struct _GstVaapiContext
{
/*< private >*/
GstVaapiObject parent_instance;
volatile gint ref_count;
GstVaapiDisplay *display;
GstVaapiID object_id;
/*< public >*/
GstVaapiContextInfo info;
VAProfile va_profile;
VAEntrypoint va_entrypoint;
VAConfigID va_config;
GPtrArray *surfaces;
GstVaapiVideoPool *surfaces_pool;
GPtrArray *overlays[2];
guint overlay_id;
gboolean reset_on_resize;
GstVaapiConfigSurfaceAttributes *attribs;
};
/**
* GstVaapiContextClass:
*
* A VA context wrapper class.
*/
struct _GstVaapiContextClass
{
/*< private >*/
GstVaapiObjectClass parent_class;
};
#define GST_VAAPI_CONTEXT_ID(context) (((GstVaapiContext *)(context))->object_id)
#define GST_VAAPI_CONTEXT_DISPLAY(context) (((GstVaapiContext *)(context))->display)
G_GNUC_INTERNAL
GstVaapiContext *
@ -166,6 +158,16 @@ gboolean
gst_vaapi_context_get_surface_attributes (GstVaapiContext * context,
GstVaapiConfigSurfaceAttributes * out_attribs);
G_GNUC_INTERNAL
GstVaapiContext *
gst_vaapi_context_ref (GstVaapiContext * context);
G_GNUC_INTERNAL
void
gst_vaapi_context_unref (GstVaapiContext * context);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVaapiContext, gst_vaapi_context_unref)
G_END_DECLS
#endif /* GST_VAAPI_CONTEXT_H */

View file

@ -483,7 +483,8 @@ gst_vaapi_decoder_finalize (GObject * object)
decoder->frames = NULL;
}
gst_vaapi_object_replace (&decoder->context, NULL);
gst_vaapi_context_unref (decoder->context);
decoder->context = NULL;
decoder->va_context = VA_INVALID_ID;
gst_vaapi_display_replace (&decoder->display, NULL);

View file

@ -1345,7 +1345,8 @@ gst_vaapi_encoder_finalize (GObject * object)
{
GstVaapiEncoder *encoder = GST_VAAPI_ENCODER (object);
gst_vaapi_object_replace (&encoder->context, NULL);
gst_vaapi_context_unref (encoder->context);
encoder->context = NULL;
gst_vaapi_display_replace (&encoder->display, NULL);
encoder->va_display = NULL;
@ -1485,7 +1486,7 @@ create_test_context_config (GstVaapiEncoder * encoder, GstVaapiProfile profile)
GstVaapiContext *ctxt;
if (encoder->context)
return gst_vaapi_object_ref (encoder->context);
return gst_vaapi_context_ref (encoder->context);
/* if there is no profile, let's figure out one */
if (profile == GST_VAAPI_PROFILE_UNKNOWN)
@ -1506,7 +1507,7 @@ get_profile_surface_formats (GstVaapiEncoder * encoder, GstVaapiProfile profile)
if (!ctxt)
return NULL;
formats = gst_vaapi_context_get_surface_formats (ctxt);
gst_vaapi_object_unref (ctxt);
gst_vaapi_context_unref (ctxt);
return formats;
}

View file

@ -3798,7 +3798,7 @@ static inline gboolean
context_get_attribute (GstVaapiContext * context, VAConfigAttribType type,
guint * out_value_ptr)
{
return gst_vaapi_get_config_attribute (GST_VAAPI_OBJECT_DISPLAY (context),
return gst_vaapi_get_config_attribute (GST_VAAPI_CONTEXT_DISPLAY (context),
context->va_profile, context->va_entrypoint, type, out_value_ptr);
}

View file

@ -87,7 +87,7 @@ append_caps_with_context_info (GstVaapiDisplay * display,
return FALSE;
ret = append_caps (context, structure);
gst_vaapi_object_unref (context);
gst_vaapi_context_unref (context);
return ret;
}