Commit 2c449e42 authored by Gwenole Beauchesne's avatar Gwenole Beauchesne

decoder: refactor decoder unit API.

Allocate decoder unit earlier in the main parse() function and don't
delegate this task to derived classes. The ultimate purpose is to get
rid of dynamic allocation of decoder units.
parent 78e9a78d
......@@ -170,9 +170,13 @@ do_parse(GstVaapiDecoder *decoder,
if (unit)
goto got_unit;
unit = gst_vaapi_decoder_unit_new();
if (!unit)
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
ps->current_frame = base_frame;
status = GST_VAAPI_DECODER_GET_CLASS(decoder)->parse(decoder,
adapter, at_eos, &unit);
adapter, at_eos, unit);
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
if (unit)
gst_vaapi_decoder_unit_unref(unit);
......
......@@ -117,7 +117,7 @@ struct _GstVaapiDecoderClass {
GstVaapiDecoderStatus (*parse)(GstVaapiDecoder *decoder,
GstAdapter *adapter, gboolean at_eos,
struct _GstVaapiDecoderUnit **unit_ptr);
struct _GstVaapiDecoderUnit *unit);
GstVaapiDecoderStatus (*decode)(GstVaapiDecoder *decoder,
struct _GstVaapiDecoderUnit *unit);
GstVaapiDecoderStatus (*start_frame)(GstVaapiDecoder *decoder,
......
......@@ -2852,14 +2852,13 @@ ensure_decoder(GstVaapiDecoderH264 *decoder)
static GstVaapiDecoderStatus
gst_vaapi_decoder_h264_parse(GstVaapiDecoder *base_decoder,
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit **unit_ptr)
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit *unit)
{
GstVaapiDecoderH264 * const decoder =
GST_VAAPI_DECODER_H264_CAST(base_decoder);
GstVaapiDecoderH264Private * const priv = decoder->priv;
GstVaapiParserState * const ps = GST_VAAPI_PARSER_STATE(base_decoder);
GstVaapiParserInfoH264 *pi;
GstVaapiDecoderUnit *unit;
GstVaapiDecoderStatus status;
GstH264ParserResult result;
guchar *buf;
......@@ -2924,10 +2923,7 @@ gst_vaapi_decoder_h264_parse(GstVaapiDecoder *base_decoder,
if (!buf)
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
unit = gst_vaapi_decoder_unit_new(buf_size);
if (!unit)
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
*unit_ptr = unit;
unit->size = buf_size;
pi = gst_vaapi_parser_info_h264_new();
if (!pi)
......
......@@ -634,11 +634,10 @@ scan_for_start_code(GstAdapter *adapter, guint ofs, guint size, guint32 *scp)
static GstVaapiDecoderStatus
gst_vaapi_decoder_jpeg_parse(GstVaapiDecoder *base_decoder,
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit **unit_ptr)
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit *unit)
{
GstVaapiDecoderJpeg * const decoder = GST_VAAPI_DECODER_JPEG(base_decoder);
GstVaapiDecoderStatus status;
GstVaapiDecoderUnit *unit;
guint size, buf_size, flags = 0;
gint ofs;
......@@ -667,16 +666,12 @@ gst_vaapi_decoder_jpeg_parse(GstVaapiDecoder *base_decoder,
}
buf_size = ofs;
unit = gst_vaapi_decoder_unit_new(buf_size);
if (!unit)
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
unit->size = buf_size;
flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_START;
flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_END;
flags |= GST_VAAPI_DECODER_UNIT_FLAG_SLICE;
GST_VAAPI_DECODER_UNIT_FLAG_SET(unit, flags);
*unit_ptr = unit;
return GST_VAAPI_DECODER_STATUS_SUCCESS;
}
......
......@@ -1173,13 +1173,12 @@ ensure_decoder(GstVaapiDecoderMpeg2 *decoder)
static GstVaapiDecoderStatus
gst_vaapi_decoder_mpeg2_parse(GstVaapiDecoder *base_decoder,
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit **unit_ptr)
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit *unit)
{
GstVaapiDecoderMpeg2 * const decoder =
GST_VAAPI_DECODER_MPEG2_CAST(base_decoder);
GstVaapiParserState * const ps = GST_VAAPI_PARSER_STATE(base_decoder);
GstVaapiParserInfoMpeg2 *pi;
GstVaapiDecoderUnit *unit;
GstVaapiDecoderStatus status;
GstMpegVideoPacket *packet;
const guchar *buf;
......@@ -1225,10 +1224,7 @@ gst_vaapi_decoder_mpeg2_parse(GstVaapiDecoder *base_decoder,
if (!buf)
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
unit = gst_vaapi_decoder_unit_new(buf_size);
if (!unit)
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
*unit_ptr = unit;
unit->size = buf_size;
pi = gst_vaapi_parser_info_mpeg2_new();
if (!pi)
......
......@@ -991,12 +991,11 @@ ensure_decoder(GstVaapiDecoderMpeg4 *decoder)
static GstVaapiDecoderStatus
gst_vaapi_decoder_mpeg4_parse(GstVaapiDecoder *base_decoder,
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit **unit_ptr)
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit *unit)
{
GstVaapiDecoderMpeg4 * const decoder =
GST_VAAPI_DECODER_MPEG4(base_decoder);
GstVaapiDecoderMpeg4Private * const priv = decoder->priv;
GstVaapiDecoderUnit *unit = NULL;
GstVaapiDecoderStatus status;
GstMpeg4Packet packet;
GstMpeg4ParseResult result;
......@@ -1025,6 +1024,7 @@ gst_vaapi_decoder_mpeg4_parse(GstVaapiDecoder *base_decoder,
buf_size = packet.size;
gst_adapter_flush(adapter, packet.offset);
unit->size = buf_size;
/* Check for start of new picture */
switch (packet.type) {
......@@ -1075,14 +1075,7 @@ gst_vaapi_decoder_mpeg4_parse(GstVaapiDecoder *base_decoder,
GST_WARNING("unsupported start code (0x%02x)", packet.type);
return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
}
unit = gst_vaapi_decoder_unit_new(buf_size);
if (!unit)
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
GST_VAAPI_DECODER_UNIT_FLAG_SET(unit, flags);
*unit_ptr = unit;
return GST_VAAPI_DECODER_STATUS_SUCCESS;
}
......
......@@ -32,7 +32,7 @@ gst_vaapi_decoder_unit_class(void)
{
static const GstVaapiMiniObjectClass GstVaapiDecoderUnitClass = {
sizeof(GstVaapiDecoderUnit),
(GDestroyNotify)gst_vaapi_decoder_unit_finalize
(GDestroyNotify)gst_vaapi_decoder_unit_clear
};
return &GstVaapiDecoderUnitClass;
}
......@@ -47,9 +47,9 @@ gst_vaapi_decoder_unit_class(void)
* sub-classes.
*/
static inline void
decoder_unit_init(GstVaapiDecoderUnit *unit, guint size)
decoder_unit_init(GstVaapiDecoderUnit *unit)
{
unit->size = size;
unit->size = 0;
unit->offset = 0;
unit->buffer = NULL;
......@@ -58,13 +58,13 @@ decoder_unit_init(GstVaapiDecoderUnit *unit, guint size)
}
void
gst_vaapi_decoder_unit_init(GstVaapiDecoderUnit *unit, guint size)
gst_vaapi_decoder_unit_init(GstVaapiDecoderUnit *unit)
{
decoder_unit_init(unit, size);
decoder_unit_init(unit);
}
/**
* gst_vaapi_decoder_unit_finalize:
* gst_vaapi_decoder_unit_clear:
* @unit: a #GstVaapiDecoderUnit
*
* Deallocates any internal resources bound to the supplied decoder
......@@ -74,16 +74,16 @@ gst_vaapi_decoder_unit_init(GstVaapiDecoderUnit *unit, guint size)
* sub-classes.
*/
static inline void
decoder_unit_finalize(GstVaapiDecoderUnit *unit)
decoder_unit_clear(GstVaapiDecoderUnit *unit)
{
gst_buffer_replace(&unit->buffer, NULL);
gst_vaapi_decoder_unit_set_parsed_info(unit, NULL, NULL);
}
void
gst_vaapi_decoder_unit_finalize(GstVaapiDecoderUnit *unit)
gst_vaapi_decoder_unit_clear(GstVaapiDecoderUnit *unit)
{
decoder_unit_finalize(unit);
decoder_unit_clear(unit);
}
/**
......@@ -95,7 +95,7 @@ gst_vaapi_decoder_unit_finalize(GstVaapiDecoderUnit *unit)
* Returns: The newly allocated #GstVaapiDecoderUnit
*/
GstVaapiDecoderUnit *
gst_vaapi_decoder_unit_new(guint size)
gst_vaapi_decoder_unit_new(void)
{
GstVaapiDecoderUnit *unit;
......@@ -104,7 +104,7 @@ gst_vaapi_decoder_unit_new(guint size)
if (!unit)
return NULL;
decoder_unit_init(unit, size);
decoder_unit_init(unit);
return unit;
}
......
......@@ -141,15 +141,15 @@ struct _GstVaapiDecoderUnit {
G_GNUC_INTERNAL
void
gst_vaapi_decoder_unit_init(GstVaapiDecoderUnit *unit, guint size);
gst_vaapi_decoder_unit_init(GstVaapiDecoderUnit *unit);
G_GNUC_INTERNAL
void
gst_vaapi_decoder_unit_finalize(GstVaapiDecoderUnit *unit);
gst_vaapi_decoder_unit_clear(GstVaapiDecoderUnit *unit);
G_GNUC_INTERNAL
GstVaapiDecoderUnit *
gst_vaapi_decoder_unit_new(guint size);
gst_vaapi_decoder_unit_new(void);
G_GNUC_INTERNAL
void
......
......@@ -1163,12 +1163,11 @@ scan_for_start_code(GstAdapter *adapter, guint ofs, guint size, guint32 *scp)
static GstVaapiDecoderStatus
gst_vaapi_decoder_vc1_parse(GstVaapiDecoder *base_decoder,
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit **unit_ptr)
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit *unit)
{
GstVaapiDecoderVC1 * const decoder = GST_VAAPI_DECODER_VC1(base_decoder);
GstVaapiDecoderVC1Private * const priv = decoder->priv;
GstVaapiDecoderStatus status;
GstVaapiDecoderUnit *unit;
guint8 bdu_type;
guint size, buf_size, flags = 0;
gint ofs;
......@@ -1208,9 +1207,7 @@ gst_vaapi_decoder_vc1_parse(GstVaapiDecoder *base_decoder,
gst_adapter_copy(adapter, &bdu_type, 3, 1);
}
unit = gst_vaapi_decoder_unit_new(buf_size);
if (!unit)
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
unit->size = buf_size;
/* Check for new picture layer */
switch (bdu_type) {
......@@ -1231,8 +1228,6 @@ gst_vaapi_decoder_vc1_parse(GstVaapiDecoder *base_decoder,
break;
}
GST_VAAPI_DECODER_UNIT_FLAG_SET(unit, flags);
*unit_ptr = unit;
return GST_VAAPI_DECODER_STATUS_SUCCESS;
}
......
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