[MOVED FROM BAD 109/134] vp8dec: Improve output_state handling
authorThiago Santos <thiago.sousa.santos@collabora.com>
Fri, 27 Apr 2012 21:22:42 +0000 (18:22 -0300)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Sun, 16 Sep 2012 13:30:22 +0000 (15:30 +0200)
Avoid getting output_state for every buffer as that requires
getting the objectlock and doing reference counting. Store it locally
when it is created and use it.

ext/vp8/gstvp8dec.c
ext/vp8/gstvp8dec.h

index d13f6b6..e88a9ae 100644 (file)
@@ -294,6 +294,10 @@ gst_vp8_dec_reset (GstVideoDecoder * base_video_decoder, gboolean hard)
 
   decoder = GST_VP8_DEC (base_video_decoder);
 
+  if (decoder->output_state) {
+    gst_video_codec_state_unref (decoder->output_state);
+    decoder->output_state = NULL;
+  }
   if (decoder->decoder_inited)
     vpx_codec_destroy (&decoder->decoder);
   decoder->decoder_inited = FALSE;
@@ -320,11 +324,9 @@ gst_vp8_dec_image_to_buffer (GstVP8Dec * dec, const vpx_image_t * img,
 {
   int stride, w, h, i;
   guint8 *d;
-  GstVideoCodecState *outputstate;
   GstVideoInfo *info;
 
-  outputstate = gst_video_decoder_get_output_state (GST_VIDEO_DECODER (dec));
-  info = &outputstate->info;
+  info = &dec->output_state->info;
 
   d = GST_BUFFER_DATA (buffer) + GST_VIDEO_INFO_COMP_OFFSET (info, 0);
   stride = GST_VIDEO_INFO_COMP_STRIDE (info, 0);
@@ -352,8 +354,6 @@ gst_vp8_dec_image_to_buffer (GstVP8Dec * dec, const vpx_image_t * img,
   for (i = 0; i < h; i++)
     memcpy (d + i * stride,
         img->planes[VPX_PLANE_V] + i * img->stride[VPX_PLANE_V], w);
-
-  gst_video_codec_state_unref (outputstate);
 }
 
 static GstFlowReturn
@@ -364,7 +364,6 @@ open_codec (GstVP8Dec * dec, GstVideoCodecFrame * frame)
   vpx_codec_caps_t caps;
   GstVideoCodecState *state = dec->input_state;
   vpx_codec_err_t status;
-  GstVideoCodecState *output_state;
 
   memset (&stream_info, 0, sizeof (stream_info));
   stream_info.sz = sizeof (stream_info);
@@ -379,9 +378,10 @@ open_codec (GstVP8Dec * dec, GstVideoCodecFrame * frame)
     return GST_FLOW_OK;
   }
 
-  output_state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
+  g_assert (dec->output_state == NULL);
+  dec->output_state =
+      gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
       GST_VIDEO_FORMAT_I420, stream_info.w, stream_info.h, state);
-  gst_video_codec_state_unref (output_state);
   gst_vp8_dec_send_tags (dec);
 
   caps = vpx_codec_get_caps (&vpx_codec_vp8_dx_algo);
index f68c85f..0984267 100644 (file)
@@ -24,7 +24,7 @@
 #define __GST_VP8_DEC_H__
 
 #include <gst/gst.h>
-#include <gst/video/gstbasevideodecoder.h>
+#include <gst/video/gstvideodecoder.h>
 
 /* FIXME: Undef HAVE_CONFIG_H because vpx_codec.h uses it,
  * which causes compilation failures */
@@ -53,7 +53,7 @@ typedef struct _GstVP8DecClass GstVP8DecClass;
 
 struct _GstVP8Dec
 {
-  GstBaseVideoDecoder base_video_decoder;
+  GstVideoDecoder base_video_decoder;
 
   /* < private > */
   vpx_codec_ctx_t decoder;
@@ -66,11 +66,14 @@ struct _GstVP8Dec
   enum vp8_postproc_level post_processing_flags;
   gint deblocking_level;
   gint noise_level;
+
+  GstVideoCodecState *input_state;
+  GstVideoCodecState *output_state;
 };
 
 struct _GstVP8DecClass
 {
-  GstBaseVideoDecoderClass base_video_decoder_class;
+  GstVideoDecoderClass base_video_decoder_class;
 };
 
 GType gst_vp8_dec_get_type (void);