Port codec objects to GstVaapiMiniObject.

This commit is contained in:
Gwenole Beauchesne 2012-12-03 11:19:08 +01:00
parent 1130a46837
commit f88374d642
5 changed files with 188 additions and 556 deletions

View file

@ -35,98 +35,69 @@
/* --- Base Codec Object --- */
/* ------------------------------------------------------------------------- */
G_DEFINE_TYPE(GstVaapiCodecObject, gst_vaapi_codec_object, GST_TYPE_MINI_OBJECT)
#define GST_VAAPI_CODEC_OBJECT_GET_CLASS(object) \
gst_vaapi_codec_object_get_class(object)
static void
gst_vaapi_codec_object_finalize(GstMiniObject *object)
const GstVaapiCodecObjectClass *
gst_vaapi_codec_object_get_class(GstVaapiCodecObject *object)
{
GstVaapiCodecObject * const obj = GST_VAAPI_CODEC_OBJECT(object);
obj->codec = NULL;
}
static void
gst_vaapi_codec_object_init(GstVaapiCodecObject *obj)
{
obj->codec = NULL;
return (const GstVaapiCodecObjectClass *)
gst_vaapi_mini_object_get_class(GST_VAAPI_MINI_OBJECT(object));
}
static gboolean
gst_vaapi_codec_object_create(
GstVaapiCodecObject *obj,
const GstVaapiCodecObjectConstructorArgs *args
)
gst_vaapi_codec_object_create(GstVaapiCodecObject *object,
const GstVaapiCodecObjectConstructorArgs *args)
{
obj->codec = args->codec;
const GstVaapiCodecObjectClass *klass;
g_return_val_if_fail(args->param_size > 0, FALSE);
if (GST_VAAPI_MINI_OBJECT_FLAG_IS_SET(object,
GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED))
return TRUE;
klass = GST_VAAPI_CODEC_OBJECT_GET_CLASS(object);
if (!klass->create || !klass->create(object, args))
return FALSE;
GST_VAAPI_MINI_OBJECT_FLAG_SET(object,
GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED);
return TRUE;
}
static void
gst_vaapi_codec_object_class_init(GstVaapiCodecObjectClass *klass)
{
GstMiniObjectClass * const object_class = GST_MINI_OBJECT_CLASS(klass);
object_class->finalize = gst_vaapi_codec_object_finalize;
klass->construct = gst_vaapi_codec_object_create;
}
GstVaapiCodecObject *
gst_vaapi_codec_object_new(
GType type,
GstVaapiCodecBase *codec,
gconstpointer param,
guint param_size,
gconstpointer data,
guint data_size
)
gst_vaapi_codec_object_new(const GstVaapiCodecObjectClass *object_class,
GstVaapiCodecBase *codec, gconstpointer param, guint param_size,
gconstpointer data, guint data_size, guint flags)
{
GstMiniObject *obj;
GstVaapiMiniObject *obj;
GstVaapiCodecObject *va_obj;
GstVaapiCodecObjectConstructorArgs args;
obj = gst_mini_object_new(type);
g_return_val_if_fail(codec != NULL, NULL);
obj = gst_vaapi_mini_object_new0(&object_class->parent_class);
if (!obj)
return NULL;
va_obj = GST_VAAPI_CODEC_OBJECT(obj);
args.codec = codec;
va_obj->codec = codec;
args.param = param;
args.param_size = param_size;
args.data = data;
args.data_size = data_size;
args.flags = 0;
if (gst_vaapi_codec_object_construct(va_obj, &args))
args.flags = flags;
if (gst_vaapi_codec_object_create(va_obj, &args))
return va_obj;
gst_mini_object_unref(obj);
gst_vaapi_mini_object_unref(obj);
return NULL;
}
gboolean
gst_vaapi_codec_object_construct(
GstVaapiCodecObject *obj,
const GstVaapiCodecObjectConstructorArgs *args
)
{
GstVaapiCodecObjectClass *klass;
g_return_val_if_fail(GST_VAAPI_CODEC_OBJECT(obj), FALSE);
g_return_val_if_fail(args->codec != NULL, FALSE);
g_return_val_if_fail(args->param_size > 0, FALSE);
if (GST_MINI_OBJECT_FLAG_IS_SET(obj, GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED))
return TRUE;
klass = GST_VAAPI_CODEC_OBJECT_GET_CLASS(obj);
if (!klass || !klass->construct || !klass->construct(obj, args))
return FALSE;
GST_MINI_OBJECT_FLAG_SET(obj, GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED);
return TRUE;
}
#define GET_DECODER(obj) GST_VAAPI_DECODER_CAST((obj)->parent_instance.codec)
#define GET_CONTEXT(obj) GET_DECODER(obj)->priv->context
#define GET_VA_DISPLAY(obj) GET_DECODER(obj)->priv->va_display
#define GET_VA_CONTEXT(obj) GET_DECODER(obj)->priv->va_context
@ -134,23 +105,22 @@ gst_vaapi_codec_object_construct(
/* --- Inverse Quantization Matrices --- */
/* ------------------------------------------------------------------------- */
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiIqMatrix,
gst_vaapi_iq_matrix,
GST_VAAPI_TYPE_CODEC_OBJECT)
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiIqMatrix, gst_vaapi_iq_matrix);
static void
void
gst_vaapi_iq_matrix_destroy(GstVaapiIqMatrix *iq_matrix)
{
vaapi_destroy_buffer(GET_VA_DISPLAY(iq_matrix), &iq_matrix->param_id);
iq_matrix->param = NULL;
}
static gboolean
gboolean
gst_vaapi_iq_matrix_create(
GstVaapiIqMatrix *iq_matrix,
const GstVaapiCodecObjectConstructorArgs *args
)
{
iq_matrix->param_id = VA_INVALID_ID;
return vaapi_create_buffer(GET_VA_DISPLAY(iq_matrix),
GET_VA_CONTEXT(iq_matrix),
VAIQMatrixBufferType,
@ -160,13 +130,6 @@ gst_vaapi_iq_matrix_create(
&iq_matrix->param);
}
static void
gst_vaapi_iq_matrix_init(GstVaapiIqMatrix *iq_matrix)
{
iq_matrix->param = NULL;
iq_matrix->param_id = VA_INVALID_ID;
}
GstVaapiIqMatrix *
gst_vaapi_iq_matrix_new(
GstVaapiDecoder *decoder,
@ -179,10 +142,11 @@ gst_vaapi_iq_matrix_new(
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
GST_VAAPI_TYPE_IQ_MATRIX,
&GstVaapiIqMatrixClass,
GST_VAAPI_CODEC_BASE(decoder),
param, param_size,
NULL, 0
NULL, 0,
0
);
if (!object)
return NULL;
@ -193,23 +157,22 @@ gst_vaapi_iq_matrix_new(
/* --- VC-1 Bit Planes --- */
/* ------------------------------------------------------------------------- */
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiBitPlane,
gst_vaapi_bitplane,
GST_VAAPI_TYPE_CODEC_OBJECT)
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiBitPlane, gst_vaapi_bitplane);
static void
void
gst_vaapi_bitplane_destroy(GstVaapiBitPlane *bitplane)
{
vaapi_destroy_buffer(GET_VA_DISPLAY(bitplane), &bitplane->data_id);
bitplane->data = NULL;
}
static gboolean
gboolean
gst_vaapi_bitplane_create(
GstVaapiBitPlane *bitplane,
const GstVaapiCodecObjectConstructorArgs *args
)
{
bitplane->data_id = VA_INVALID_ID;
return vaapi_create_buffer(GET_VA_DISPLAY(bitplane),
GET_VA_CONTEXT(bitplane),
VABitPlaneBufferType,
@ -219,12 +182,6 @@ gst_vaapi_bitplane_create(
(void **)&bitplane->data);
}
static void
gst_vaapi_bitplane_init(GstVaapiBitPlane *bitplane)
{
bitplane->data = NULL;
bitplane->data_id = VA_INVALID_ID;
}
GstVaapiBitPlane *
gst_vaapi_bitplane_new(GstVaapiDecoder *decoder, guint8 *data, guint data_size)
@ -234,10 +191,11 @@ gst_vaapi_bitplane_new(GstVaapiDecoder *decoder, guint8 *data, guint data_size)
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
GST_VAAPI_TYPE_BITPLANE,
&GstVaapiBitPlaneClass,
GST_VAAPI_CODEC_BASE(decoder),
data, data_size,
NULL, 0
NULL, 0,
0
);
if (!object)
return NULL;
@ -249,23 +207,22 @@ gst_vaapi_bitplane_new(GstVaapiDecoder *decoder, guint8 *data, guint data_size)
/* ------------------------------------------------------------------------- */
#if USE_JPEG_DECODER
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiHuffmanTable,
gst_vaapi_huffman_table,
GST_VAAPI_TYPE_CODEC_OBJECT)
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiHuffmanTable, gst_vaapi_huffman_table);
static void
void
gst_vaapi_huffman_table_destroy(GstVaapiHuffmanTable *huf_table)
{
vaapi_destroy_buffer(GET_VA_DISPLAY(huf_table), &huf_table->param_id);
huf_table->param = NULL;
}
static gboolean
gboolean
gst_vaapi_huffman_table_create(
GstVaapiHuffmanTable *huf_table,
const GstVaapiCodecObjectConstructorArgs *args
)
{
huf_table->param_id = VA_INVALID_ID;
return vaapi_create_buffer(GET_VA_DISPLAY(huf_table),
GET_VA_CONTEXT(huf_table),
VAHuffmanTableBufferType,
@ -275,13 +232,6 @@ gst_vaapi_huffman_table_create(
(void **)&huf_table->param);
}
static void
gst_vaapi_huffman_table_init(GstVaapiHuffmanTable *huf_table)
{
huf_table->param = NULL;
huf_table->param_id = VA_INVALID_ID;
}
GstVaapiHuffmanTable *
gst_vaapi_huffman_table_new(
GstVaapiDecoder *decoder,
@ -294,10 +244,11 @@ gst_vaapi_huffman_table_new(
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
GST_VAAPI_TYPE_HUFFMAN_TABLE,
&GstVaapiHuffmanTableClass,
GST_VAAPI_CODEC_BASE(decoder),
data, data_size,
NULL, 0
NULL, 0,
0
);
if (!object)
return NULL;

View file

@ -23,7 +23,7 @@
#ifndef GST_VAAPI_CODEC_COMMON_H
#define GST_VAAPI_CODEC_COMMON_H
#include <gst/gstminiobject.h>
#include <gst/vaapi/gstvaapiminiobject.h>
#include <gst/vaapi/gstvaapidecoder.h>
G_BEGIN_DECLS
@ -32,11 +32,8 @@ typedef gpointer GstVaapiCodecBase;
typedef struct _GstVaapiCodecObject GstVaapiCodecObject;
typedef struct _GstVaapiCodecObjectClass GstVaapiCodecObjectClass;
typedef struct _GstVaapiIqMatrix GstVaapiIqMatrix;
typedef struct _GstVaapiIqMatrixClass GstVaapiIqMatrixClass;
typedef struct _GstVaapiBitPlane GstVaapiBitPlane;
typedef struct _GstVaapiBitPlaneClass GstVaapiBitPlaneClass;
typedef struct _GstVaapiHuffmanTable GstVaapiHuffmanTable;
typedef struct _GstVaapiHuffmanTableClass GstVaapiHuffmanTableClass;
/* ------------------------------------------------------------------------- */
/* --- Base Codec Object --- */
@ -46,38 +43,15 @@ typedef struct _GstVaapiHuffmanTableClass GstVaapiHuffmanTableClass;
#define GST_VAAPI_CODEC_BASE(obj) \
((GstVaapiCodecBase *)(obj))
#define GST_VAAPI_TYPE_CODEC_OBJECT \
(gst_vaapi_codec_object_get_type())
#define GST_VAAPI_CODEC_OBJECT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_CODEC_OBJECT, \
GstVaapiCodecObject))
#define GST_VAAPI_CODEC_OBJECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_CODEC_OBJECT, \
GstVaapiCodecObjectClass))
#define GST_VAAPI_IS_CODEC_OBJECT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_CODEC_OBJECT))
#define GST_VAAPI_IS_CODEC_OBJECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_CODEC_OBJECT))
#define GST_VAAPI_CODEC_OBJECT_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_CODEC_OBJECT, \
GstVaapiCodecObjectClass))
#define GST_VAAPI_CODEC_OBJECT(obj) \
((GstVaapiCodecObject *)(obj))
enum {
GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED = (GST_MINI_OBJECT_FLAG_LAST << 0),
GST_VAAPI_CODEC_OBJECT_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 1)
GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED = (1 << 0),
GST_VAAPI_CODEC_OBJECT_FLAG_LAST = (1 << 1)
};
typedef struct {
GstVaapiCodecObject *obj;
GstVaapiCodecBase *codec;
gconstpointer param;
guint param_size;
gconstpointer data;
@ -85,14 +59,20 @@ typedef struct {
guint flags;
} GstVaapiCodecObjectConstructorArgs;
typedef gboolean
(*GstVaapiCodecObjectCreateFunc)(GstVaapiCodecObject *object,
const GstVaapiCodecObjectConstructorArgs *args);
typedef GDestroyNotify GstVaapiCodecObjectDestroyFunc;
/**
* GstVaapiCodecObject:
*
* A #GstMiniObject holding the base codec object data
* A #GstVaapiMiniObject holding the base codec object data
*/
struct _GstVaapiCodecObject {
/*< private >*/
GstMiniObject parent_instance;
GstVaapiMiniObject parent_instance;
GstVaapiCodecBase *codec;
};
@ -103,65 +83,28 @@ struct _GstVaapiCodecObject {
*/
struct _GstVaapiCodecObjectClass {
/*< private >*/
GstMiniObjectClass parent_class;
GstVaapiMiniObjectClass parent_class;
gboolean (*construct) (GstVaapiCodecObject *obj,
const GstVaapiCodecObjectConstructorArgs *args);
GstVaapiCodecObjectCreateFunc create;
};
G_GNUC_INTERNAL
GType
gst_vaapi_codec_object_get_type(void) G_GNUC_CONST;
const GstVaapiCodecObjectClass *
gst_vaapi_codec_object_get_class(GstVaapiCodecObject *object) G_GNUC_CONST;
G_GNUC_INTERNAL
GstVaapiCodecObject *
gst_vaapi_codec_object_new(
GType type,
GstVaapiCodecBase *codec,
gconstpointer param,
guint param_size,
gconstpointer data,
guint data_size
);
G_GNUC_INTERNAL
gboolean
gst_vaapi_codec_object_construct(
GstVaapiCodecObject *obj,
const GstVaapiCodecObjectConstructorArgs *args
);
gst_vaapi_codec_object_new(const GstVaapiCodecObjectClass *object_class,
GstVaapiCodecBase *codec, gconstpointer param, guint param_size,
gconstpointer data, guint data_size, guint flags);
/* ------------------------------------------------------------------------- */
/* --- Inverse Quantization Matrices --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_IQ_MATRIX \
(gst_vaapi_iq_matrix_get_type())
#define GST_VAAPI_IQ_MATRIX_CAST(obj) \
((GstVaapiIqMatrix *)(obj))
#define GST_VAAPI_IQ_MATRIX(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_IQ_MATRIX, \
GstVaapiIqMatrix))
#define GST_VAAPI_IQ_MATRIX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_IQ_MATRIX, \
GstVaapiIqMatrixClass))
#define GST_VAAPI_IS_IQ_MATRIX(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_IQ_MATRIX))
#define GST_VAAPI_IS_IQ_MATRIX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_IQ_MATRIX))
#define GST_VAAPI_IQ_MATRIX_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_IQ_MATRIX, \
GstVaapiIqMatrixClass))
/**
* GstVaapiIqMatrix:
*
@ -176,20 +119,6 @@ struct _GstVaapiIqMatrix {
gpointer param;
};
/**
* GstVaapiIqMatrixClass:
*
* The #GstVaapiIqMatrix base class.
*/
struct _GstVaapiIqMatrixClass {
/*< private >*/
GstVaapiCodecObjectClass parent_class;
};
G_GNUC_INTERNAL
GType
gst_vaapi_iq_matrix_get_type(void) G_GNUC_CONST;
G_GNUC_INTERNAL
GstVaapiIqMatrix *
gst_vaapi_iq_matrix_new(
@ -202,33 +131,9 @@ gst_vaapi_iq_matrix_new(
/* --- VC-1 Bit Planes --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_BITPLANE \
(gst_vaapi_bitplane_get_type())
#define GST_VAAPI_BITPLANE_CAST(obj) \
((GstVaapiBitPlane *)(obj))
#define GST_VAAPI_BITPLANE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_BITPLANE, \
GstVaapiBitPlane))
#define GST_VAAPI_BITPLANE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_BITPLANE, \
GstVaapiBitPlaneClass))
#define GST_VAAPI_IS_BITPLANE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_BITPLANE))
#define GST_VAAPI_IS_BITPLANE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_BITPLANE))
#define GST_VAAPI_BITPLANE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_BITPLANE, \
GstVaapiBitPlaneClass))
/**
* GstVaapiBitPlane:
*
@ -243,20 +148,6 @@ struct _GstVaapiBitPlane {
guint8 *data;
};
/**
* GstVaapiBitPlaneClass:
*
* The #GstVaapiBitPlane base class.
*/
struct _GstVaapiBitPlaneClass {
/*< private >*/
GstVaapiCodecObjectClass parent_class;
};
G_GNUC_INTERNAL
GType
gst_vaapi_bitplane_get_type(void) G_GNUC_CONST;
G_GNUC_INTERNAL
GstVaapiBitPlane *
gst_vaapi_bitplane_new(GstVaapiDecoder *decoder, guint8 *data, guint data_size);
@ -265,33 +156,9 @@ gst_vaapi_bitplane_new(GstVaapiDecoder *decoder, guint8 *data, guint data_size);
/* --- JPEG Huffman Tables --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_HUFFMAN_TABLE \
(gst_vaapi_huffman_table_get_type())
#define GST_VAAPI_HUFFMAN_TABLE_CAST(obj) \
((GstVaapiHuffmanTable *)(obj))
#define GST_VAAPI_HUFFMAN_TABLE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_HUFFMAN_TABLE, \
GstVaapiHuffmanTable))
#define GST_VAAPI_HUFFMAN_TABLE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_HUFFMAN_TABLE, \
GstVaapiHuffmanTableClass))
#define GST_VAAPI_IS_HUFFMAN_TABLE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_HUFFMAN_TABLE))
#define GST_VAAPI_IS_HUFFMAN_TABLE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_HUFFMAN_TABLE))
#define GST_VAAPI_HUFFMAN_TABLE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_HUFFMAN_TABLE, \
GstVaapiHuffmanTableClass))
/**
* GstVaapiHuffmanTable:
*
@ -306,20 +173,6 @@ struct _GstVaapiHuffmanTable {
gpointer param;
};
/**
* GstVaapiHuffmanTableClass:
*
* The #GstVaapiHuffmanTable base class.
*/
struct _GstVaapiHuffmanTableClass {
/*< private >*/
GstVaapiCodecObjectClass parent_class;
};
G_GNUC_INTERNAL
GType
gst_vaapi_huffman_table_get_type(void) G_GNUC_CONST;
G_GNUC_INTERNAL
GstVaapiHuffmanTable *
gst_vaapi_huffman_table_new(
@ -332,56 +185,26 @@ gst_vaapi_huffman_table_new(
/* --- Helpers to create codec-dependent objects --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_CODEC_DEFINE_TYPE(type, prefix, base_type) \
G_DEFINE_TYPE(type, prefix, base_type) \
\
static void \
prefix##_destroy(type *); \
\
static gboolean \
prefix##_create( \
type *, \
const GstVaapiCodecObjectConstructorArgs *args \
); \
\
static void \
prefix##_finalize(GstMiniObject *object) \
{ \
GstMiniObjectClass *parent_class; \
\
prefix##_destroy((type *)object); \
\
parent_class = GST_MINI_OBJECT_CLASS(prefix##_parent_class); \
if (parent_class->finalize) \
parent_class->finalize(object); \
} \
\
static gboolean \
prefix##_construct( \
GstVaapiCodecObject *object, \
const GstVaapiCodecObjectConstructorArgs *args \
) \
{ \
GstVaapiCodecObjectClass *parent_class; \
\
parent_class = GST_VAAPI_CODEC_OBJECT_CLASS(prefix##_parent_class); \
if (parent_class->construct) { \
if (!parent_class->construct(object, args)) \
return FALSE; \
} \
return prefix##_create((type *)object, args); \
} \
\
static void \
prefix##_class_init(type##Class *klass) \
{ \
GstMiniObjectClass * const object_class = \
GST_MINI_OBJECT_CLASS(klass); \
GstVaapiCodecObjectClass * const codec_class = \
GST_VAAPI_CODEC_OBJECT_CLASS(klass); \
\
object_class->finalize = prefix##_finalize; \
codec_class->construct = prefix##_construct; \
#define GST_VAAPI_CODEC_DEFINE_TYPE(type, prefix) \
G_GNUC_INTERNAL \
void \
prefix##_destroy(type *); \
\
G_GNUC_INTERNAL \
gboolean \
prefix##_create( \
type *, \
const GstVaapiCodecObjectConstructorArgs *args \
); \
\
static const GstVaapiCodecObjectClass type##Class = { \
.parent_class = { \
.size = sizeof(type), \
.finalize = (GstVaapiCodecObjectDestroyFunc) \
prefix##_destroy \
}, \
.create = (GstVaapiCodecObjectCreateFunc) \
prefix##_create, \
}
#define GST_VAAPI_IQ_MATRIX_NEW(codec, decoder) \

View file

@ -43,9 +43,7 @@
typedef struct _GstVaapiFrameStore GstVaapiFrameStore;
typedef struct _GstVaapiFrameStoreClass GstVaapiFrameStoreClass;
typedef struct _GstVaapiPictureH264 GstVaapiPictureH264;
typedef struct _GstVaapiPictureH264Class GstVaapiPictureH264Class;
typedef struct _GstVaapiSliceH264 GstVaapiSliceH264;
typedef struct _GstVaapiSliceH264Class GstVaapiSliceH264Class;
// Used for field_poc[]
#define TOP_FIELD 0
@ -55,32 +53,14 @@ typedef struct _GstVaapiSliceH264Class GstVaapiSliceH264Class;
/* --- H.264 Pictures --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_PICTURE_H264 \
(gst_vaapi_picture_h264_get_type())
#define GST_VAAPI_PICTURE_H264_CAST(obj) \
((GstVaapiPictureH264 *)(obj))
#define GST_VAAPI_PICTURE_H264(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_PICTURE_H264, \
GstVaapiPictureH264))
#define GST_VAAPI_PICTURE_H264_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_PICTURE_H264, \
GstVaapiPictureH264Class))
#define GST_VAAPI_PICTURE_H264(obj) \
GST_VAAPI_PICTURE_H264_CAST(obj)
#define GST_VAAPI_IS_PICTURE_H264(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_PICTURE_H264))
#define GST_VAAPI_IS_PICTURE_H264_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_PICTURE_H264))
#define GST_VAAPI_PICTURE_H264_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_PICTURE_H264, \
GstVaapiPictureH264Class))
(GST_VAAPI_PICTURE_H264(obj) != NULL)
/*
* Extended picture flags:
@ -133,35 +113,27 @@ struct _GstVaapiPictureH264 {
guint output_needed : 1;
};
struct _GstVaapiPictureH264Class {
/*< private >*/
GstVaapiPictureClass parent_class;
};
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiPictureH264, gst_vaapi_picture_h264);
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiPictureH264,
gst_vaapi_picture_h264,
GST_VAAPI_TYPE_PICTURE)
static void
gst_vaapi_picture_h264_destroy(GstVaapiPictureH264 *decoder)
void
gst_vaapi_picture_h264_destroy(GstVaapiPictureH264 *picture)
{
gst_vaapi_picture_destroy(GST_VAAPI_PICTURE(picture));
}
static gboolean
gboolean
gst_vaapi_picture_h264_create(
GstVaapiPictureH264 *picture,
const GstVaapiCodecObjectConstructorArgs *args
)
{
return TRUE;
}
if (!gst_vaapi_picture_create(GST_VAAPI_PICTURE(picture), args))
return FALSE;
static void
gst_vaapi_picture_h264_init(GstVaapiPictureH264 *picture)
{
picture->field_poc[0] = G_MAXINT32;
picture->field_poc[1] = G_MAXINT32;
picture->output_needed = FALSE;
return TRUE;
}
static inline GstVaapiPictureH264 *
@ -172,10 +144,11 @@ gst_vaapi_picture_h264_new(GstVaapiDecoderH264 *decoder)
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
GST_VAAPI_TYPE_PICTURE_H264,
&GstVaapiPictureH264Class,
GST_VAAPI_CODEC_BASE(decoder),
NULL, sizeof(VAPictureParameterBufferH264),
NULL, 0
NULL, 0,
0
);
if (!object)
return NULL;
@ -228,66 +201,39 @@ gst_vaapi_picture_h264_get_last_slice(GstVaapiPictureH264 *picture)
/* --- Slices --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_SLICE_H264 \
(gst_vaapi_slice_h264_get_type())
#define GST_VAAPI_SLICE_H264_CAST(obj) \
((GstVaapiSliceH264 *)(obj))
#define GST_VAAPI_SLICE_H264(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_SLICE_H264, \
GstVaapiSliceH264))
#define GST_VAAPI_SLICE_H264_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_SLICE_H264, \
GstVaapiSliceH264Class))
#define GST_VAAPI_SLICE_H264(obj) \
GST_VAAPI_SLICE_H264(obj)
#define GST_VAAPI_IS_SLICE_H264(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_SLICE_H264))
#define GST_VAAPI_IS_SLICE_H264_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_SLICE_H264))
#define GST_VAAPI_SLICE_H264_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_SLICE_H264, \
GstVaapiSliceH264Class))
(GST_VAAPI_SLICE_H264(obj) != NULL)
struct _GstVaapiSliceH264 {
GstVaapiSlice base;
GstH264SliceHdr slice_hdr; // parsed slice_header()
};
struct _GstVaapiSliceH264Class {
/*< private >*/
GstVaapiSliceClass parent_class;
};
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiSliceH264, gst_vaapi_slice_h264);
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiSliceH264,
gst_vaapi_slice_h264,
GST_VAAPI_TYPE_SLICE)
static void
void
gst_vaapi_slice_h264_destroy(GstVaapiSliceH264 *slice)
{
gst_vaapi_slice_destroy(GST_VAAPI_SLICE(slice));
}
static gboolean
gboolean
gst_vaapi_slice_h264_create(
GstVaapiSliceH264 *slice,
const GstVaapiCodecObjectConstructorArgs *args
)
{
if (!gst_vaapi_slice_create(GST_VAAPI_SLICE(slice), args))
return FALSE;
return TRUE;
}
static void
gst_vaapi_slice_h264_init(GstVaapiSliceH264 *slice)
{
}
static inline GstVaapiSliceH264 *
gst_vaapi_slice_h264_new(
GstVaapiDecoderH264 *decoder,
@ -300,10 +246,11 @@ gst_vaapi_slice_h264_new(
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
GST_VAAPI_TYPE_SLICE_H264,
&GstVaapiSliceH264Class,
GST_VAAPI_CODEC_BASE(decoder),
NULL, sizeof(VASliceParameterBufferH264),
data, data_size
data, data_size,
0
);
if (!object)
return NULL;
@ -2927,7 +2874,7 @@ decode_slice(GstVaapiDecoderH264 *decoder, GstH264NalUnit *nalu)
error:
if (slice)
gst_mini_object_unref(GST_MINI_OBJECT(slice));
gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(slice));
return status;
}

View file

@ -40,9 +40,7 @@
/* --- Pictures --- */
/* ------------------------------------------------------------------------- */
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiPicture,
gst_vaapi_picture,
GST_VAAPI_TYPE_CODEC_OBJECT)
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiPicture, gst_vaapi_picture);
enum {
GST_VAAPI_CREATE_PICTURE_FLAG_CLONE = 1 << 0,
@ -52,12 +50,12 @@ enum {
static void
destroy_slice_cb(gpointer data, gpointer user_data)
{
GstMiniObject * const object = data;
GstVaapiMiniObject * const object = data;
gst_mini_object_unref(object);
gst_vaapi_mini_object_unref(object);
}
static void
void
gst_vaapi_picture_destroy(GstVaapiPicture *picture)
{
if (picture->slices) {
@ -66,20 +64,12 @@ gst_vaapi_picture_destroy(GstVaapiPicture *picture)
picture->slices = NULL;
}
if (picture->iq_matrix) {
gst_mini_object_unref(GST_MINI_OBJECT(picture->iq_matrix));
picture->iq_matrix = NULL;
}
if (picture->huf_table) {
gst_mini_object_unref(GST_MINI_OBJECT(picture->huf_table));
picture->huf_table = NULL;
}
if (picture->bitplane) {
gst_mini_object_unref(GST_MINI_OBJECT(picture->bitplane));
picture->bitplane = NULL;
}
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)&picture->iq_matrix,
NULL);
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)&picture->huf_table,
NULL);
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)&picture->bitplane,
NULL);
if (picture->proxy) {
gst_vaapi_surface_proxy_unref(picture->proxy);
@ -96,7 +86,7 @@ gst_vaapi_picture_destroy(GstVaapiPicture *picture)
picture->param = NULL;
}
static gboolean
gboolean
gst_vaapi_picture_create(
GstVaapiPicture *picture,
const GstVaapiCodecObjectConstructorArgs *args
@ -139,6 +129,9 @@ gst_vaapi_picture_create(
}
}
else {
picture->type = GST_VAAPI_PICTURE_TYPE_NONE;
picture->pts = GST_CLOCK_TIME_NONE;
picture->surface = gst_vaapi_context_get_surface(GET_CONTEXT(picture));
if (!picture->surface)
return FALSE;
@ -153,6 +146,7 @@ gst_vaapi_picture_create(
}
picture->surface_id = gst_vaapi_surface_get_id(picture->surface);
picture->param_id = VA_INVALID_ID;
success = vaapi_create_buffer(
GET_VA_DISPLAY(picture),
GET_VA_CONTEXT(picture),
@ -172,24 +166,6 @@ gst_vaapi_picture_create(
return TRUE;
}
static void
gst_vaapi_picture_init(GstVaapiPicture *picture)
{
picture->type = GST_VAAPI_PICTURE_TYPE_NONE;
picture->surface = NULL;
picture->proxy = NULL;
picture->surface_id = VA_INVALID_ID;
picture->param = NULL;
picture->param_id = VA_INVALID_ID;
picture->param_size = 0;
picture->slices = NULL;
picture->iq_matrix = NULL;
picture->huf_table = NULL;
picture->bitplane = NULL;
picture->pts = GST_CLOCK_TIME_NONE;
picture->poc = 0;
}
GstVaapiPicture *
gst_vaapi_picture_new(
GstVaapiDecoder *decoder,
@ -202,10 +178,11 @@ gst_vaapi_picture_new(
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
GST_VAAPI_TYPE_PICTURE,
&GstVaapiPictureClass,
GST_VAAPI_CODEC_BASE(decoder),
param, param_size,
NULL, 0
NULL, 0,
0
);
if (!object)
return NULL;
@ -215,31 +192,20 @@ gst_vaapi_picture_new(
GstVaapiPicture *
gst_vaapi_picture_new_field(GstVaapiPicture *picture)
{
GType type;
GstMiniObject *obj;
GstVaapiCodecObject *va_obj;
GstVaapiCodecObjectConstructorArgs args;
GstVaapiDecoder * const decoder = GET_DECODER(picture);
GstVaapiCodecObject *object;
g_return_val_if_fail(GST_VAAPI_IS_PICTURE(picture), NULL);
type = G_TYPE_FROM_CLASS(GST_VAAPI_PICTURE_GET_CLASS(picture));
obj = gst_mini_object_new(type);
if (!obj)
object = gst_vaapi_codec_object_new(
gst_vaapi_codec_object_get_class(&picture->parent_instance),
GST_VAAPI_CODEC_BASE(decoder),
NULL, picture->param_size,
picture, 0,
(GST_VAAPI_CREATE_PICTURE_FLAG_CLONE|
GST_VAAPI_CREATE_PICTURE_FLAG_FIELD)
);
if (!object)
return NULL;
va_obj = GST_VAAPI_CODEC_OBJECT(obj);
args.codec = GST_VAAPI_CODEC_BASE(GET_DECODER(picture));
args.param = NULL;
args.param_size = picture->param_size;
args.data = picture;
args.data_size = 0;
args.flags = (GST_VAAPI_CREATE_PICTURE_FLAG_CLONE|
GST_VAAPI_CREATE_PICTURE_FLAG_FIELD);
if (gst_vaapi_codec_object_construct(va_obj, &args))
return GST_VAAPI_PICTURE_CAST(va_obj);
gst_mini_object_unref(obj);
return NULL;
return GST_VAAPI_PICTURE_CAST(object);
}
void
@ -357,11 +323,9 @@ gst_vaapi_picture_output(GstVaapiPicture *picture)
/* --- Slices --- */
/* ------------------------------------------------------------------------- */
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiSlice,
gst_vaapi_slice,
GST_VAAPI_TYPE_CODEC_OBJECT)
GST_VAAPI_CODEC_DEFINE_TYPE(GstVaapiSlice, gst_vaapi_slice);
static void
void
gst_vaapi_slice_destroy(GstVaapiSlice *slice)
{
VADisplay const va_display = GET_VA_DISPLAY(slice);
@ -371,7 +335,7 @@ gst_vaapi_slice_destroy(GstVaapiSlice *slice)
slice->param = NULL;
}
static gboolean
gboolean
gst_vaapi_slice_create(
GstVaapiSlice *slice,
const GstVaapiCodecObjectConstructorArgs *args
@ -380,6 +344,7 @@ gst_vaapi_slice_create(
VASliceParameterBufferBase *slice_param;
gboolean success;
slice->data_id = VA_INVALID_ID;
success = vaapi_create_buffer(
GET_VA_DISPLAY(slice),
GET_VA_CONTEXT(slice),
@ -392,6 +357,7 @@ gst_vaapi_slice_create(
if (!success)
return FALSE;
slice->param_id = VA_INVALID_ID;
success = vaapi_create_buffer(
GET_VA_DISPLAY(slice),
GET_VA_CONTEXT(slice),
@ -411,14 +377,6 @@ gst_vaapi_slice_create(
return TRUE;
}
static void
gst_vaapi_slice_init(GstVaapiSlice *slice)
{
slice->param = NULL;
slice->param_id = VA_INVALID_ID;
slice->data_id = VA_INVALID_ID;
}
GstVaapiSlice *
gst_vaapi_slice_new(
GstVaapiDecoder *decoder,
@ -433,10 +391,11 @@ gst_vaapi_slice_new(
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
GST_VAAPI_TYPE_SLICE,
&GstVaapiSliceClass,
GST_VAAPI_CODEC_BASE(decoder),
param, param_size,
data, data_size
data, data_size,
0
);
return GST_VAAPI_SLICE_CAST(object);
}

View file

@ -28,40 +28,20 @@
G_BEGIN_DECLS
typedef struct _GstVaapiPicture GstVaapiPicture;
typedef struct _GstVaapiPictureClass GstVaapiPictureClass;
typedef struct _GstVaapiSlice GstVaapiSlice;
typedef struct _GstVaapiSliceClass GstVaapiSliceClass;
/* ------------------------------------------------------------------------- */
/* --- Pictures --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_PICTURE \
(gst_vaapi_picture_get_type())
#define GST_VAAPI_PICTURE_CAST(obj) \
((GstVaapiPicture *)(obj))
#define GST_VAAPI_PICTURE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_PICTURE, \
GstVaapiPicture))
#define GST_VAAPI_PICTURE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_PICTURE, \
GstVaapiPictureClass))
#define GST_VAAPI_PICTURE(obj) \
GST_VAAPI_PICTURE_CAST(obj)
#define GST_VAAPI_IS_PICTURE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_PICTURE))
#define GST_VAAPI_IS_PICTURE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_PICTURE))
#define GST_VAAPI_PICTURE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_PICTURE, \
GstVaapiPictureClass))
(GST_VAAPI_PICTURE(obj) != NULL)
typedef enum {
GST_VAAPI_PICTURE_TYPE_NONE = 0, // Undefined
@ -96,10 +76,10 @@ enum {
GST_VAAPI_PICTURE_FLAG_LAST = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 6),
};
#define GST_VAAPI_PICTURE_FLAGS GST_MINI_OBJECT_FLAGS
#define GST_VAAPI_PICTURE_FLAG_IS_SET GST_MINI_OBJECT_FLAG_IS_SET
#define GST_VAAPI_PICTURE_FLAG_SET GST_MINI_OBJECT_FLAG_SET
#define GST_VAAPI_PICTURE_FLAG_UNSET GST_MINI_OBJECT_FLAG_UNSET
#define GST_VAAPI_PICTURE_FLAGS GST_VAAPI_MINI_OBJECT_FLAGS
#define GST_VAAPI_PICTURE_FLAG_IS_SET GST_VAAPI_MINI_OBJECT_FLAG_IS_SET
#define GST_VAAPI_PICTURE_FLAG_SET GST_VAAPI_MINI_OBJECT_FLAG_SET
#define GST_VAAPI_PICTURE_FLAG_UNSET GST_VAAPI_MINI_OBJECT_FLAG_UNSET
#define GST_VAAPI_PICTURE_IS_SKIPPED(picture) \
GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_SKIPPED)
@ -152,19 +132,14 @@ struct _GstVaapiPicture {
guint structure;
};
/**
* GstVaapiPictureClass:
*
* The #GstVaapiPicture base class.
*/
struct _GstVaapiPictureClass {
/*< private >*/
GstVaapiCodecObjectClass parent_class;
};
G_GNUC_INTERNAL
void
gst_vaapi_picture_destroy(GstVaapiPicture *picture);
G_GNUC_INTERNAL
GType
gst_vaapi_picture_get_type(void) G_GNUC_CONST;
gboolean
gst_vaapi_picture_create(GstVaapiPicture *picture,
const GstVaapiCodecObjectConstructorArgs *args);
G_GNUC_INTERNAL
GstVaapiPicture *
@ -193,49 +168,31 @@ gst_vaapi_picture_output(GstVaapiPicture *picture);
static inline gpointer
gst_vaapi_picture_ref(gpointer ptr)
{
return gst_mini_object_ref(GST_MINI_OBJECT(ptr));
return gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(ptr));
}
static inline void
gst_vaapi_picture_unref(gpointer ptr)
{
gst_mini_object_unref(GST_MINI_OBJECT(ptr));
gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(ptr));
}
#define gst_vaapi_picture_replace(old_picture_p, new_picture) \
gst_mini_object_replace((GstMiniObject **)(old_picture_p), \
(GstMiniObject *)(new_picture))
#define gst_vaapi_picture_replace(old_picture_p, new_picture) \
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_picture_p), \
(GstVaapiMiniObject *)(new_picture))
/* ------------------------------------------------------------------------- */
/* --- Slices --- */
/* ------------------------------------------------------------------------- */
#define GST_VAAPI_TYPE_SLICE \
(gst_vaapi_slice_get_type())
#define GST_VAAPI_SLICE_CAST(obj) \
((GstVaapiSlice *)(obj))
#define GST_VAAPI_SLICE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_SLICE, \
GstVaapiSlice))
#define GST_VAAPI_SLICE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_SLICE, \
GstVaapiSliceClass))
#define GST_VAAPI_SLICE(obj) \
GST_VAAPI_SLICE_CAST(obj)
#define GST_VAAPI_IS_SLICE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_SLICE))
#define GST_VAAPI_IS_SLICE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_SLICE))
#define GST_VAAPI_SLICE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_SLICE, \
GstVaapiSliceClass))
(GST_VAAPI_SLICE(obj) != NULL)
/**
* GstVaapiSlice:
@ -252,19 +209,14 @@ struct _GstVaapiSlice {
gpointer param;
};
/**
* GstVaapiSliceClass:
*
* The #GstVaapiSlice base class.
*/
struct _GstVaapiSliceClass {
/*< private >*/
GstVaapiCodecObjectClass parent_class;
};
G_GNUC_INTERNAL
void
gst_vaapi_slice_destroy(GstVaapiSlice *slice);
G_GNUC_INTERNAL
GType
gst_vaapi_slice_get_type(void) G_GNUC_CONST;
gboolean
gst_vaapi_slice_create(GstVaapiSlice *slice,
const GstVaapiCodecObjectConstructorArgs *args);
G_GNUC_INTERNAL
GstVaapiSlice *