Browse code

huffyuv: use the AVFrame API properly.

Anton Khirnov authored on 2013/11/09 18:14:46
Showing 2 changed files
... ...
@@ -78,7 +78,6 @@ typedef struct HYuvContext {
78 78
     uint32_t bits[3][256];
79 79
     uint32_t pix_bgr_map[1<<VLC_BITS];
80 80
     VLC vlc[6];                             //Y,U,V,YY,YU,YV
81
-    AVFrame picture;
82 81
     uint8_t *bitstream_buffer;
83 82
     unsigned int bitstream_buffer_size;
84 83
     DSPContext dsp;
... ...
@@ -151,7 +151,12 @@ static av_cold int encode_init(AVCodecContext *avctx)
151 151
     avctx->stats_out = av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
152 152
     s->version = 2;
153 153
 
154
-    avctx->coded_frame = &s->picture;
154
+    avctx->coded_frame = av_frame_alloc();
155
+    if (!avctx->coded_frame)
156
+        return AVERROR(ENOMEM);
157
+
158
+    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
159
+    avctx->coded_frame->key_frame = 1;
155 160
 
156 161
     switch (avctx->pix_fmt) {
157 162
     case AV_PIX_FMT_YUV420P:
... ...
@@ -438,7 +443,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
438 438
     const int fake_ystride = s->interlaced ? pict->linesize[0]*2  : pict->linesize[0];
439 439
     const int fake_ustride = s->interlaced ? pict->linesize[1]*2  : pict->linesize[1];
440 440
     const int fake_vstride = s->interlaced ? pict->linesize[2]*2  : pict->linesize[2];
441
-    AVFrame * const p = &s->picture;
441
+    const AVFrame * const p = pict;
442 442
     int i, j, size = 0, ret;
443 443
 
444 444
     if (!pkt->data &&
... ...
@@ -447,10 +452,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
447 447
         return ret;
448 448
     }
449 449
 
450
-    *p = *pict;
451
-    p->pict_type = AV_PICTURE_TYPE_I;
452
-    p->key_frame = 1;
453
-
454 450
     if (s->context) {
455 451
         for (i = 0; i < 3; i++) {
456 452
             ff_huff_gen_len_table(s->len[i], s->stats[i]);
... ...
@@ -676,6 +677,8 @@ static av_cold int encode_end(AVCodecContext *avctx)
676 676
     av_freep(&avctx->extradata);
677 677
     av_freep(&avctx->stats_out);
678 678
 
679
+    av_frame_free(&avctx->coded_frame);
680
+
679 681
     return 0;
680 682
 }
681 683