Commit e44d8ee6 authored by Gwenole Beauchesne's avatar Gwenole Beauchesne

dpb: port to GstVaapiMiniObject.

parent 6f4e0125
......@@ -25,38 +25,78 @@
#define DEBUG 1
#include "gstvaapidebug.h"
G_GNUC_INTERNAL
GType
gst_vaapi_dpb2_get_type(void) G_GNUC_CONST;
#define GST_VAAPI_DPB_CLASS(klass) \
((GstVaapiDpbClass *)(klass))
#define GST_VAAPI_TYPE_DPB2 \
(gst_vaapi_dpb2_get_type())
#define GST_VAAPI_DPB_GET_CLASS(obj) \
GST_VAAPI_DPB_CLASS(gst_vaapi_mini_object_get_class( \
GST_VAAPI_MINI_OBJECT(obj)))
/**
* GstVaapiDpb:
*
* A decoded picture buffer (DPB) object.
*/
struct _GstVaapiDpb {
/*< private >*/
GstVaapiMiniObject parent_instance;
/*< protected >*/
GstVaapiPicture **pictures;
guint num_pictures;
guint max_pictures;
};
/**
* GstVaapiDpbClass:
*
* The #GstVaapiDpb base class.
*/
struct _GstVaapiDpbClass {
/*< private >*/
GstVaapiMiniObjectClass parent_class;
/*< protected >*/
void (*flush) (GstVaapiDpb *dpb);
gboolean (*add) (GstVaapiDpb *dpb, GstVaapiPicture *picture);
void (*get_neighbours) (GstVaapiDpb *dpb, GstVaapiPicture *picture,
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr);
};
static const GstVaapiMiniObjectClass *
gst_vaapi_dpb_class(void);
static const GstVaapiMiniObjectClass *
gst_vaapi_dpb2_class(void);
/* ------------------------------------------------------------------------- */
/* --- Common Decoded Picture Buffer utilities --- */
/* ------------------------------------------------------------------------- */
static GstVaapiDpb *
dpb_new(GType type, guint max_pictures)
dpb_new(guint max_pictures)
{
GstMiniObject *obj;
const GstVaapiMiniObjectClass *klass;
GstVaapiDpb *dpb;
g_return_val_if_fail(max_pictures > 0, NULL);
obj = gst_mini_object_new(type);
if (!obj)
klass = max_pictures == 2 ? gst_vaapi_dpb2_class() : gst_vaapi_dpb_class();
dpb = (GstVaapiDpb *)gst_vaapi_mini_object_new(klass);
if (!dpb)
return NULL;
dpb = GST_VAAPI_DPB_CAST(obj);
dpb->num_pictures = 0;
dpb->max_pictures = max_pictures;
dpb->pictures = g_new0(GstVaapiPicture *, max_pictures);
if (!dpb->pictures)
goto error;
dpb->max_pictures = max_pictures;
return dpb;
error:
gst_mini_object_unref(obj);
gst_vaapi_dpb_unref(dpb);
return NULL;
}
......@@ -130,8 +170,6 @@ dpb_clear(GstVaapiDpb *dpb)
/* --- Base Decoded Picture Buffer --- */
/* ------------------------------------------------------------------------- */
G_DEFINE_TYPE(GstVaapiDpb, gst_vaapi_dpb, GST_TYPE_MINI_OBJECT)
static void
gst_vaapi_dpb_base_flush(GstVaapiDpb *dpb)
{
......@@ -224,52 +262,38 @@ gst_vaapi_dpb_base_get_neighbours(
}
static void
gst_vaapi_dpb_finalize(GstMiniObject *object)
gst_vaapi_dpb_finalize(GstVaapiDpb *dpb)
{
GstVaapiDpb * const dpb = GST_VAAPI_DPB_CAST(object);
GstMiniObjectClass *parent_class;
if (dpb->pictures) {
dpb_clear(dpb);
g_free(dpb->pictures);
}
parent_class = GST_MINI_OBJECT_CLASS(gst_vaapi_dpb_parent_class);
if (parent_class->finalize)
parent_class->finalize(object);
}
static void
gst_vaapi_dpb_init(GstVaapiDpb *dpb)
static const GstVaapiMiniObjectClass *
gst_vaapi_dpb_class(void)
{
dpb->pictures = NULL;
dpb->num_pictures = 0;
dpb->max_pictures = 0;
}
static void
gst_vaapi_dpb_class_init(GstVaapiDpbClass *klass)
{
GstMiniObjectClass * const object_class = GST_MINI_OBJECT_CLASS(klass);
object_class->finalize = gst_vaapi_dpb_finalize;
klass->flush = gst_vaapi_dpb_base_flush;
klass->add = gst_vaapi_dpb_base_add;
klass->get_neighbours = gst_vaapi_dpb_base_get_neighbours;
static const GstVaapiDpbClass GstVaapiDpbClass = {
{ sizeof(GstVaapiDpb),
(GDestroyNotify)gst_vaapi_dpb_finalize },
gst_vaapi_dpb_base_flush,
gst_vaapi_dpb_base_add,
gst_vaapi_dpb_base_get_neighbours
};
return &GstVaapiDpbClass.parent_class;
}
GstVaapiDpb *
gst_vaapi_dpb_new(guint max_pictures)
{
if (G_LIKELY(max_pictures == 2))
return dpb_new(GST_VAAPI_TYPE_DPB2, max_pictures);
return dpb_new(GST_VAAPI_TYPE_DPB, max_pictures);
return dpb_new(max_pictures);
}
void
gst_vaapi_dpb_flush(GstVaapiDpb *dpb)
{
GstVaapiDpbClass *klass;
const GstVaapiDpbClass *klass;
g_return_if_fail(GST_VAAPI_IS_DPB(dpb));
......@@ -282,7 +306,7 @@ gst_vaapi_dpb_flush(GstVaapiDpb *dpb)
gboolean
gst_vaapi_dpb_add(GstVaapiDpb *dpb, GstVaapiPicture *picture)
{
GstVaapiDpbClass *klass;
const GstVaapiDpbClass *klass;
g_return_val_if_fail(GST_VAAPI_IS_DPB(dpb), FALSE);
g_return_val_if_fail(GST_VAAPI_IS_PICTURE(picture), FALSE);
......@@ -309,7 +333,7 @@ gst_vaapi_dpb_get_neighbours(
GstVaapiPicture **next_picture_ptr
)
{
GstVaapiDpbClass *klass;
const GstVaapiDpbClass *klass;
g_return_if_fail(GST_VAAPI_IS_DPB(dpb));
g_return_if_fail(GST_VAAPI_IS_PICTURE(picture));
......@@ -324,55 +348,6 @@ gst_vaapi_dpb_get_neighbours(
/* --- Decoded Picture Buffer (optimized for 2 reference pictures) --- */
/* ------------------------------------------------------------------------- */
typedef struct _GstVaapiDpb2 GstVaapiDpb2;
typedef struct _GstVaapiDpb2Class GstVaapiDpb2Class;
#define GST_VAAPI_DPB2_CAST(obj) \
((GstVaapiDpb2 *)(obj))
#define GST_VAAPI_DPB2(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_DPB2, \
GstVaapiDpb2))
#define GST_VAAPI_DPB2_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_DPB2, \
GstVaapiDpb2Class))
#define GST_VAAPI_IS_DPB2(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_DPB2))
#define GST_VAAPI_IS_DPB2_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_DPB2))
#define GST_VAAPI_DPB2_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_DPB2, \
GstVaapiDpb2Class))
/**
* GstVaapiDpb2:
*
* A decoded picture buffer (DPB2) object.
*/
struct _GstVaapiDpb2 {
/*< private >*/
GstVaapiDpb parent_instance;
};
/**
* GstVaapiDpb2Class:
*
* The #GstVaapiDpb2 base class.
*/
struct _GstVaapiDpb2Class {
/*< private >*/
GstVaapiDpbClass parent_class;
};
G_DEFINE_TYPE(GstVaapiDpb2, gst_vaapi_dpb2, GST_VAAPI_TYPE_DPB)
static void
gst_vaapi_dpb2_get_neighbours(
GstVaapiDpb *dpb,
......@@ -416,18 +391,18 @@ gst_vaapi_dpb2_add(GstVaapiDpb *dpb, GstVaapiPicture *picture)
return TRUE;
}
static void
gst_vaapi_dpb2_init(GstVaapiDpb2 *dpb)
static const GstVaapiMiniObjectClass *
gst_vaapi_dpb2_class(void)
{
}
static void
gst_vaapi_dpb2_class_init(GstVaapiDpb2Class *klass)
{
GstVaapiDpbClass * const dpb_class = GST_VAAPI_DPB_CLASS(klass);
dpb_class->add = gst_vaapi_dpb2_add;
dpb_class->get_neighbours = gst_vaapi_dpb2_get_neighbours;
static const GstVaapiDpbClass GstVaapiDpb2Class = {
{ sizeof(GstVaapiDpb),
(GDestroyNotify)gst_vaapi_dpb_finalize },
gst_vaapi_dpb_base_flush,
gst_vaapi_dpb2_add,
gst_vaapi_dpb2_get_neighbours
};
return &GstVaapiDpb2Class.parent_class;
}
void
......
......@@ -30,70 +30,14 @@ typedef struct _GstVaapiDpb GstVaapiDpb;
typedef struct _GstVaapiDpbClass GstVaapiDpbClass;
/* ------------------------------------------------------------------------- */
/* --- Base Decoded Picture Buffer --- */
/* --- Decoded Picture Buffer --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_DPB \
(gst_vaapi_dpb_get_type())
#define GST_VAAPI_DPB_CAST(obj) \
#define GST_VAAPI_DPB(obj) \
((GstVaapiDpb *)(obj))
#define GST_VAAPI_DPB(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_DPB, \
GstVaapiDpb))
#define GST_VAAPI_DPB_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_DPB, \
GstVaapiDpbClass))
#define GST_VAAPI_IS_DPB(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_DPB))
#define GST_VAAPI_IS_DPB_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_DPB))
#define GST_VAAPI_DPB_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_DPB, \
GstVaapiDpbClass))
/**
* GstVaapiDpb:
*
* A decoded picture buffer (DPB) object.
*/
struct _GstVaapiDpb {
/*< private >*/
GstMiniObject parent_instance;
/*< protected >*/
GstVaapiPicture **pictures;
guint num_pictures;
guint max_pictures;
};
/**
* GstVaapiDpbClass:
*
* The #GstVaapiDpb base class.
*/
struct _GstVaapiDpbClass {
/*< private >*/
GstMiniObjectClass parent_class;
/*< protected >*/
void (*flush) (GstVaapiDpb *dpb);
gboolean (*add) (GstVaapiDpb *dpb, GstVaapiPicture *picture);
void (*get_neighbours) (GstVaapiDpb *dpb, GstVaapiPicture *picture,
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr);
};
G_GNUC_INTERNAL
GType
gst_vaapi_dpb_get_type(void) G_GNUC_CONST;
(GST_VAAPI_DPB(obj) != NULL)
G_GNUC_INTERNAL
GstVaapiDpb *
......@@ -120,17 +64,15 @@ gst_vaapi_dpb_get_neighbours(
GstVaapiPicture **next_picture_ptr
);
static inline gpointer
gst_vaapi_dpb_ref(gpointer ptr)
{
return gst_mini_object_ref(GST_MINI_OBJECT(ptr));
}
static inline void
gst_vaapi_dpb_unref(gpointer ptr)
{
gst_mini_object_unref(GST_MINI_OBJECT(ptr));
}
#define gst_vaapi_dpb_ref(dpb) \
gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(dpb))
#define gst_vaapi_dpb_unref(dpb) \
gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(dpb))
#define gst_vaapi_dpb_replace(old_dpb_ptr, new_dpb) \
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_dpb_ptr), \
(GstVaapiMiniObject *)(new_dpb))
G_END_DECLS
......
......@@ -373,10 +373,7 @@ gst_vaapi_decoder_mpeg2_close(GstVaapiDecoderMpeg2 *decoder)
gst_vaapi_parser_info_mpeg2_replace(&priv->quant_matrix, NULL);
gst_vaapi_parser_info_mpeg2_replace(&priv->slice_hdr, NULL);
if (priv->dpb) {
gst_vaapi_dpb_unref(priv->dpb);
priv->dpb = NULL;
}
gst_vaapi_dpb_replace(&priv->dpb, NULL);
}
static gboolean
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment