From a486d1af667e93e299b35b83625d49ee12575a90 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Mon, 7 Jan 2013 13:59:07 +0100 Subject: [PATCH] decoder: optimize pre-allocation of decoder units. Optimize pre-allocation of decoder units, thus avoiding un-necessary memory reallocations. The heuristic used is that we could have around one slice unit per macroblock line. --- gst-libs/gst/vaapi/gstvaapidecoder.c | 7 +++++-- gst-libs/gst/vaapi/gstvaapidecoder_frame.c | 13 ++++++++++--- gst-libs/gst/vaapi/gstvaapidecoder_frame.h | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapidecoder.c b/gst-libs/gst/vaapi/gstvaapidecoder.c index 7a5cf0501b..966d3ea784 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder.c @@ -135,7 +135,8 @@ do_parse(GstVaapiDecoder *decoder, GstVideoCodecFrame *base_frame, GstAdapter *adapter, gboolean at_eos, guint *got_unit_size_ptr, gboolean *got_frame_ptr) { - GstVaapiParserState * const ps = &decoder->priv->parser_state; + GstVaapiDecoderPrivate * const priv = decoder->priv; + GstVaapiParserState * const ps = &priv->parser_state; GstVaapiDecoderFrame *frame; GstVaapiDecoderUnit *unit; GstVaapiDecoderStatus status; @@ -145,7 +146,9 @@ do_parse(GstVaapiDecoder *decoder, frame = gst_video_codec_frame_get_user_data(base_frame); if (!frame) { - frame = gst_vaapi_decoder_frame_new(); + GstVideoCodecState * const codec_state = priv->codec_state; + frame = gst_vaapi_decoder_frame_new(codec_state->info.width, + codec_state->info.height); if (!frame) return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; gst_video_codec_frame_set_user_data(base_frame, diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_frame.c b/gst-libs/gst/vaapi/gstvaapidecoder_frame.c index 4c1c178cee..cae0d30873 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_frame.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_frame.c @@ -66,24 +66,31 @@ free_units(GArray **units_ptr) /** * gst_vaapi_decoder_frame_new: + * @width: frame width in pixels + * @height: frame height in pixels * * Creates a new #GstVaapiDecoderFrame object. * * Returns: The newly allocated #GstVaapiDecoderFrame */ GstVaapiDecoderFrame * -gst_vaapi_decoder_frame_new(void) +gst_vaapi_decoder_frame_new(guint width, guint height) { GstVaapiDecoderFrame *frame; + guint num_slices; frame = (GstVaapiDecoderFrame *) gst_vaapi_mini_object_new(gst_vaapi_decoder_frame_class()); if (!frame) return NULL; - if (!alloc_units(&frame->pre_units, 4)) + if (!height) + height = 1088; + num_slices = (height + 15) / 16; + + if (!alloc_units(&frame->pre_units, 16)) goto error; - if (!alloc_units(&frame->units, 1)) + if (!alloc_units(&frame->units, num_slices)) goto error; if (!alloc_units(&frame->post_units, 1)) goto error; diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_frame.h b/gst-libs/gst/vaapi/gstvaapidecoder_frame.h index b89bb5dae9..4a3595a368 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_frame.h +++ b/gst-libs/gst/vaapi/gstvaapidecoder_frame.h @@ -76,7 +76,7 @@ struct _GstVaapiDecoderFrame { G_GNUC_INTERNAL GstVaapiDecoderFrame * -gst_vaapi_decoder_frame_new(void); +gst_vaapi_decoder_frame_new(guint width, guint height); G_GNUC_INTERNAL void