Browse code

lclenc: switch to encode2().

Anton Khirnov authored on 2012/02/20 21:21:58
Showing 1 changed files
... ...
@@ -68,12 +68,20 @@ typedef struct LclEncContext {
68 68
  * Encode a frame
69 69
  *
70 70
  */
71
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
71
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
72
+                        const AVFrame *pict, int *got_packet)
73
+{
72 74
     LclEncContext *c = avctx->priv_data;
73
-    AVFrame *pict = data;
74 75
     AVFrame * const p = &c->pic;
75
-    int i;
76
+    int i, ret;
76 77
     int zret; // Zlib return code
78
+    int max_size = deflateBound(&c->zstream, avctx->width * avctx->height * 3);
79
+
80
+    if (!pkt->data &&
81
+        (ret = av_new_packet(pkt, max_size)) < 0) {
82
+            av_log(avctx, AV_LOG_ERROR, "Error allocating packet of size %d.\n", max_size);
83
+            return ret;
84
+    }
77 85
 
78 86
     *p = *pict;
79 87
     p->pict_type= AV_PICTURE_TYPE_I;
... ...
@@ -89,8 +97,8 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
89 89
         av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret);
90 90
         return -1;
91 91
     }
92
-    c->zstream.next_out = buf;
93
-    c->zstream.avail_out = buf_size;
92
+    c->zstream.next_out  = pkt->data;
93
+    c->zstream.avail_out = pkt->size;
94 94
 
95 95
     for(i = avctx->height - 1; i >= 0; i--) {
96 96
         c->zstream.next_in = p->data[0]+p->linesize[0]*i;
... ...
@@ -107,7 +115,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
107 107
         return -1;
108 108
     }
109 109
 
110
-    return c->zstream.total_out;
110
+    pkt->size   = c->zstream.total_out;
111
+    pkt->flags |= AV_PKT_FLAG_KEY;
112
+    *got_packet = 1;
113
+
114
+    return 0;
111 115
 }
112 116
 
113 117
 /*
... ...
@@ -176,7 +188,7 @@ AVCodec ff_zlib_encoder = {
176 176
     .id             = CODEC_ID_ZLIB,
177 177
     .priv_data_size = sizeof(LclEncContext),
178 178
     .init           = encode_init,
179
-    .encode         = encode_frame,
179
+    .encode2        = encode_frame,
180 180
     .close          = encode_end,
181 181
     .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_BGR24, PIX_FMT_NONE },
182 182
     .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"),