]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/indeo4.c
hevc: store the escaped/raw bitstream in HEVCNAL
[ffmpeg] / libavcodec / indeo4.c
index 3e97221229797efb91b6c62bd9bfc99512b0b432..35f266ee1341ba45de510336eccd8838ee64b724 100644 (file)
@@ -194,7 +194,7 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
 
     /* check if picture layout was changed and reallocate buffers */
     if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) {
-        if (ff_ivi_init_planes(ctx->planes, &pic_conf)) {
+        if (ff_ivi_init_planes(ctx->planes, &pic_conf, 1)) {
             av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n");
             ctx->pic_conf.luma_bands = 0;
             return AVERROR(ENOMEM);
@@ -462,6 +462,8 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
             mb->xpos     = x;
             mb->ypos     = y;
             mb->buf_offs = mb_offset;
+            mb->b_mv_x   =
+            mb->b_mv_y   = 0;
 
             if (get_bits1(&ctx->gb)) {
                 if (ctx->frame_type == IVI4_FRAMETYPE_INTRA) {
@@ -537,6 +539,24 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
                         mv_x += IVI_TOSIGNED(mv_delta);
                         mb->mv_x = mv_x;
                         mb->mv_y = mv_y;
+                        if (mb->type == 3) {
+                            mv_delta = get_vlc2(&ctx->gb,
+                                                ctx->mb_vlc.tab->table,
+                                                IVI_VLC_BITS, 1);
+                            mv_y += IVI_TOSIGNED(mv_delta);
+                            mv_delta = get_vlc2(&ctx->gb,
+                                                ctx->mb_vlc.tab->table,
+                                                IVI_VLC_BITS, 1);
+                            mv_x += IVI_TOSIGNED(mv_delta);
+                            mb->b_mv_x = -mv_x;
+                            mb->b_mv_y = -mv_y;
+                        }
+                    }
+                    if (mb->type == 2) {
+                        mb->b_mv_x = -mb->mv_x;
+                        mb->b_mv_y = -mb->mv_y;
+                        mb->mv_x = 0;
+                        mb->mv_y = 0;
                     }
                 }
             }
@@ -563,32 +583,30 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
  */
 static void switch_buffers(IVI45DecContext *ctx)
 {
+    int is_prev_ref = 0, is_ref = 0;
+
     switch (ctx->prev_frame_type) {
     case IVI4_FRAMETYPE_INTRA:
     case IVI4_FRAMETYPE_INTRA1:
     case IVI4_FRAMETYPE_INTER:
-        ctx->buf_switch ^= 1;
-        ctx->dst_buf     = ctx->buf_switch;
-        ctx->ref_buf     = ctx->buf_switch ^ 1;
-        break;
-    case IVI4_FRAMETYPE_INTER_NOREF:
+        is_prev_ref = 1;
         break;
     }
 
     switch (ctx->frame_type) {
     case IVI4_FRAMETYPE_INTRA:
     case IVI4_FRAMETYPE_INTRA1:
-        ctx->buf_switch = 0;
-        /* FALLTHROUGH */
     case IVI4_FRAMETYPE_INTER:
-        ctx->dst_buf = ctx->buf_switch;
-        ctx->ref_buf = ctx->buf_switch ^ 1;
-        break;
-    case IVI4_FRAMETYPE_INTER_NOREF:
-    case IVI4_FRAMETYPE_NULL_FIRST:
-    case IVI4_FRAMETYPE_NULL_LAST:
+        is_ref = 1;
         break;
     }
+
+    if (is_prev_ref && is_ref) {
+        FFSWAP(int, ctx->dst_buf, ctx->ref_buf);
+    } else if (is_prev_ref) {
+        FFSWAP(int, ctx->ref_buf, ctx->b_ref_buf);
+        FFSWAP(int, ctx->dst_buf, ctx->ref_buf);
+    }
 }
 
 
@@ -620,6 +638,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
     ctx->switch_buffers   = switch_buffers;
     ctx->is_nonnull_frame = is_nonnull_frame;
 
+    ctx->is_indeo4 = 1;
+
+    ctx->dst_buf   = 0;
+    ctx->ref_buf   = 1;
+    ctx->b_ref_buf = 3; /* buffer 2 is used for scalability mode */
     ctx->p_frame = av_frame_alloc();
     if (!ctx->p_frame)
         return AVERROR(ENOMEM);