OSDN Git Service

Merge commit '57e7b3a89f5a0879ad039e8f04273b48649799a8'
[android-x86/external-ffmpeg.git] / libavcodec / gif.c
index 8b9d95f..27d054e 100644 (file)
@@ -216,6 +216,13 @@ static av_cold int gif_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
+    avctx->coded_frame = av_frame_alloc();
+    if (!avctx->coded_frame)
+        return AVERROR(ENOMEM);
+
+    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
+    avctx->coded_frame->key_frame = 1;
+
     s->lzw = av_mallocz(ff_lzw_encode_state_size);
     s->buf = av_malloc(avctx->width*avctx->height*2);
     s->tmpl = av_malloc(avctx->width);
@@ -232,7 +239,6 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                             const AVFrame *pict, int *got_packet)
 {
     GIFContext *s = avctx->priv_data;
-    AVFrame *const p = (AVFrame *)pict;
     uint8_t *outbuf_ptr, *end;
     const uint32_t *palette = NULL;
     int ret;
@@ -242,15 +248,12 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     outbuf_ptr = pkt->data;
     end        = pkt->data + pkt->size;
 
-    p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
-
     if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
         uint8_t *pal_exdata = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
         if (!pal_exdata)
             return AVERROR(ENOMEM);
-        memcpy(pal_exdata, p->data[1], AVPALETTE_SIZE);
-        palette = (uint32_t*)p->data[1];
+        memcpy(pal_exdata, pict->data[1], AVPALETTE_SIZE);
+        palette = (uint32_t*)pict->data[1];
     }
 
     gif_image_write_image(avctx, &outbuf_ptr, end, palette,
@@ -276,6 +279,8 @@ static int gif_encode_close(AVCodecContext *avctx)
 {
     GIFContext *s = avctx->priv_data;
 
+    av_frame_free(&avctx->coded_frame);
+
     av_freep(&s->lzw);
     av_freep(&s->buf);
     av_frame_free(&s->last_frame);