]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/eacmv.c
x86inc: Support arbitrary stack alignments
[ffmpeg] / libavcodec / eacmv.c
index 6236bd2dd1c764c1bc7de160b4540345d87c9531..9668f64fbf84bf65699498333bef7790569fd5f7 100644 (file)
@@ -129,22 +129,31 @@ static void cmv_decode_inter(CmvContext *s, AVFrame *frame, const uint8_t *buf,
     }
 }
 
-static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t *buf_end)
+static int cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t *buf_end)
 {
-    int pal_start, pal_count, i;
+    int pal_start, pal_count, i, ret, fps;
 
     if(buf_end - buf < 16) {
         av_log(s->avctx, AV_LOG_WARNING, "truncated header\n");
-        return;
+        return AVERROR_INVALIDDATA;
     }
 
     s->width  = AV_RL16(&buf[4]);
     s->height = AV_RL16(&buf[6]);
-    if (s->avctx->width!=s->width || s->avctx->height!=s->height)
-        avcodec_set_dimensions(s->avctx, s->width, s->height);
 
-    s->avctx->time_base.num = 1;
-    s->avctx->time_base.den = AV_RL16(&buf[10]);
+    if (s->width  != s->avctx->width ||
+        s->height != s->avctx->height) {
+        av_frame_unref(s->last_frame);
+        av_frame_unref(s->last2_frame);
+    }
+
+    ret = ff_set_dimensions(s->avctx, s->width, s->height);
+    if (ret < 0)
+        return ret;
+
+    fps = AV_RL16(&buf[10]);
+    if (fps > 0)
+        s->avctx->framerate = (AVRational){ fps, 1 };
 
     pal_start = AV_RL16(&buf[12]);
     pal_count = AV_RL16(&buf[14]);
@@ -154,6 +163,8 @@ static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t
         s->palette[i] = AV_RB24(buf);
         buf += 3;
     }
+
+    return 0;
 }
 
 #define EA_PREAMBLE_SIZE 8
@@ -174,7 +185,9 @@ static int cmv_decode_frame(AVCodecContext *avctx,
         return AVERROR_INVALIDDATA;
 
     if (AV_RL32(buf)==MVIh_TAG||AV_RB32(buf)==MVIh_TAG) {
-        cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end);
+        ret = cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end);
+        if (ret < 0)
+            return ret;
         return buf_size;
     }
 
@@ -220,12 +233,12 @@ static av_cold int cmv_decode_end(AVCodecContext *avctx){
 
 AVCodec ff_eacmv_decoder = {
     .name           = "eacmv",
+    .long_name      = NULL_IF_CONFIG_SMALL("Electronic Arts CMV video"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_CMV,
     .priv_data_size = sizeof(CmvContext),
     .init           = cmv_decode_init,
     .close          = cmv_decode_end,
     .decode         = cmv_decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("Electronic Arts CMV video"),
+    .capabilities   = AV_CODEC_CAP_DR1,
 };