[vlc-commits] codec: aom: rework decoder loop

Francois Cartegnie git at videolan.org
Thu Jul 19 17:15:23 CEST 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul 19 16:46:40 2018 +0200| [548a1ee07111695f0f34b567486bb259f5611840] | committer: Francois Cartegnie

codec: aom: rework decoder loop

now outputs delayed frames

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=548a1ee07111695f0f34b567486bb259f5611840
---

 modules/codec/aom.c | 132 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 78 insertions(+), 54 deletions(-)

diff --git a/modules/codec/aom.c b/modules/codec/aom.c
index c5cd4fc62c..ad291a436d 100644
--- a/modules/codec/aom.c
+++ b/modules/codec/aom.c
@@ -152,21 +152,27 @@ static vlc_fourcc_t FindVlcChroma( struct aom_image *img )
     return 0;
 }
 
-/****************************************************************************
- * Decode: the whole thing
- ****************************************************************************/
-static int Decode(decoder_t *dec, block_t *block)
+static void CopyPicture(const struct aom_image *img, picture_t *pic)
 {
-    decoder_sys_t *p_sys = dec->p_sys;
-    aom_codec_ctx_t *ctx = &p_sys->ctx;
-
-    if (!block) /* No Drain */
-        return VLCDEC_SUCCESS;
+    for (int plane = 0; plane < pic->i_planes; plane++ ) {
+        uint8_t *src = img->planes[plane];
+        uint8_t *dst = pic->p[plane].p_pixels;
+        int src_stride = img->stride[plane];
+        int dst_stride = pic->p[plane].i_pitch;
 
-    if (block->i_flags & (BLOCK_FLAG_CORRUPTED)) {
-        block_Release(block);
-        return VLCDEC_SUCCESS;
+        int size = __MIN( src_stride, dst_stride );
+        for( int line = 0; line < pic->p[plane].i_visible_lines; line++ ) {
+            memcpy( dst, src, size );
+            src += src_stride;
+            dst += dst_stride;
+        }
     }
+}
+
+static int PushFrame(decoder_t *dec, block_t *block)
+{
+    decoder_sys_t *p_sys = dec->p_sys;
+    aom_codec_ctx_t *ctx = &p_sys->ctx;
 
     /* Associate packet PTS with decoded frame */
     struct frame_priv_s *priv = &p_sys->frame_priv[p_sys->i_next_frame_priv++ % AOM_MAX_FRAMES_DEPTH];
@@ -181,27 +187,16 @@ static int Decode(decoder_t *dec, block_t *block)
         AOM_ERR(dec, ctx, "Failed to decode frame");
         if (err == AOM_CODEC_UNSUP_BITSTREAM)
             return VLCDEC_ECRITICAL;
-        else
-            return VLCDEC_SUCCESS;
-    }
-
-    const void *iter = NULL;
-    struct aom_image *img = aom_codec_get_frame(ctx, &iter);
-    if (!img)
-        return VLCDEC_SUCCESS;
-
-    /* fetches back the PTS */
-    vlc_tick_t pts = ((struct frame_priv_s *) img->user_priv)->pts;
-
-    dec->fmt_out.i_codec = FindVlcChroma(img);
-    if (dec->fmt_out.i_codec == 0) {
-        msg_Err(dec, "Unsupported output colorspace %d", img->fmt);
-        return VLCDEC_SUCCESS;
     }
+    return VLCDEC_SUCCESS;
+}
 
+static void OutputFrame(decoder_t *dec, const struct aom_image *img)
+{
     video_format_t *v = &dec->fmt_out.video;
 
-    if (img->d_w != v->i_visible_width || img->d_h != v->i_visible_height) {
+    if (img->d_w != v->i_visible_width || img->d_h != v->i_visible_height)
+    {
         v->i_visible_width = dec->fmt_out.video.i_width = img->d_w;
         v->i_visible_height = dec->fmt_out.video.i_height = img->d_h;
     }
@@ -235,33 +230,68 @@ static int Decode(decoder_t *dec, block_t *block)
     dec->fmt_out.video.multiview_mode = dec->fmt_in.video.multiview_mode;
     dec->fmt_out.video.pose = dec->fmt_in.video.pose;
 
-    if (decoder_UpdateVideoFormat(dec))
-        return VLCDEC_SUCCESS;
-    picture_t *pic = decoder_NewPicture(dec);
-    if (!pic)
-        return VLCDEC_SUCCESS;
+    if (decoder_UpdateVideoFormat(dec) == VLC_SUCCESS)
+    {
+        picture_t *pic = decoder_NewPicture(dec);
+        if (pic)
+        {
+            CopyPicture(img, pic);
 
-    for (int plane = 0; plane < pic->i_planes; plane++ ) {
-        uint8_t *src = img->planes[plane];
-        uint8_t *dst = pic->p[plane].p_pixels;
-        int src_stride = img->stride[plane];
-        int dst_stride = pic->p[plane].i_pitch;
+            /* fetches back the PTS */
+            vlc_tick_t pts = ((struct frame_priv_s *) img->user_priv)->pts;
 
-        int size = __MIN( src_stride, dst_stride );
-        for( int line = 0; line < pic->p[plane].i_visible_lines; line++ ) {
-            memcpy( dst, src, size );
-            src += src_stride;
-            dst += dst_stride;
+            pic->b_progressive = true; /* codec does not support interlacing */
+            pic->date = pts;
+
+            decoder_QueueVideo(dec, pic);
         }
     }
+}
 
-    pic->b_progressive = true; /* codec does not support interlacing */
-    pic->date = pts;
+static int PopFrames(decoder_t *dec)
+{
+    decoder_sys_t *p_sys = dec->p_sys;
+    aom_codec_ctx_t *ctx = &p_sys->ctx;
+
+    for(const void *iter = NULL;; )
+    {
+        struct aom_image *img = aom_codec_get_frame(ctx, &iter);
+        if (!img)
+            break;
+
+        dec->fmt_out.i_codec = FindVlcChroma(img);
+        if (dec->fmt_out.i_codec == 0) {
+            msg_Err(dec, "Unsupported output colorspace %d", img->fmt);
+            continue;
+        }
+
+        OutputFrame(dec, img);
+    }
 
-    decoder_QueueVideo(dec, pic);
     return VLCDEC_SUCCESS;
 }
 
+
+/****************************************************************************
+ * Decode: the whole thing
+ ****************************************************************************/
+static int Decode(decoder_t *dec, block_t *block)
+{
+    if (!block) /* No Drain */
+        return VLCDEC_SUCCESS;
+
+    if (block->i_flags & (BLOCK_FLAG_CORRUPTED)) {
+        block_Release(block);
+        return VLCDEC_SUCCESS;
+    }
+
+    int i_ret = PushFrame(dec, block);
+
+    PopFrames(dec);
+
+    return i_ret;
+}
+
 /*****************************************************************************
  * OpenDecoder: probe the decoder
  *****************************************************************************/
@@ -327,13 +357,7 @@ static void CloseDecoder(vlc_object_t *p_this)
         AOM_ERR(p_this, &sys->ctx, "Failed to flush decoder");
     }
 
-    /* Free our PTS */
-    const void *iter = NULL;
-    for (;;) {
-        struct aom_image *img = aom_codec_get_frame(&sys->ctx, &iter);
-        if (!img)
-            break;
-    }
+    PopFrames(dec);
 
     aom_codec_destroy(&sys->ctx);
 



More information about the vlc-commits mailing list