Browse code

dpxenc: switch to encode2().

Anton Khirnov authored on 2012/02/13 20:00:38
Showing 1 changed files
... ...
@@ -22,6 +22,7 @@
22 22
 #include "libavutil/intreadwrite.h"
23 23
 #include "libavutil/imgutils.h"
24 24
 #include "avcodec.h"
25
+#include "internal.h"
25 26
 
26 27
 typedef struct DPXContext {
27 28
     AVFrame picture;
... ...
@@ -99,15 +100,23 @@ static void encode_rgb48_10bit(AVCodecContext *avctx, const AVPicture *pic,
99 99
     }
100 100
 }
101 101
 
102
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
103
-                        int buf_size, void *data)
102
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
103
+                        const AVFrame *frame, int *got_packet)
104 104
 {
105 105
     DPXContext *s = avctx->priv_data;
106
-    int size;
106
+    int size, ret;
107
+    uint8_t *buf;
107 108
 
108 109
 #define HEADER_SIZE 1664  /* DPX Generic header */
109
-    if (buf_size < HEADER_SIZE)
110
-        return -1;
110
+    if (s->bits_per_component == 10)
111
+        size = avctx->height * avctx->width * 4;
112
+    else
113
+        size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
114
+    if ((ret = ff_alloc_packet(pkt, size + HEADER_SIZE)) < 0) {
115
+        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
116
+        return ret;
117
+    }
118
+    buf = pkt->data;
111 119
 
112 120
     memset(buf, 0, HEADER_SIZE);
113 121
 
... ...
@@ -138,17 +147,14 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
138 138
     switch (s->bits_per_component) {
139 139
     case 8:
140 140
     case 16:
141
-        size = avpicture_layout(data, avctx->pix_fmt,
141
+        size = avpicture_layout((const AVPicture*)frame, avctx->pix_fmt,
142 142
                                 avctx->width, avctx->height,
143
-                                buf + HEADER_SIZE, buf_size - HEADER_SIZE);
143
+                                buf + HEADER_SIZE, pkt->size - HEADER_SIZE);
144 144
         if (size < 0)
145 145
             return size;
146 146
         break;
147 147
     case 10:
148
-        size = avctx->height * avctx->width * 4;
149
-        if (buf_size < HEADER_SIZE + size)
150
-            return -1;
151
-        encode_rgb48_10bit(avctx, data, buf + HEADER_SIZE);
148
+        encode_rgb48_10bit(avctx, (const AVPicture*)frame, buf + HEADER_SIZE);
152 149
         break;
153 150
     default:
154 151
         av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", s->bits_per_component);
... ...
@@ -158,7 +164,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
158 158
     size += HEADER_SIZE;
159 159
 
160 160
     write32(buf + 16, size); /* file size */
161
-    return size;
161
+
162
+    pkt->flags |= AV_PKT_FLAG_KEY;
163
+    *got_packet = 1;
164
+
165
+    return 0;
162 166
 }
163 167
 
164 168
 AVCodec ff_dpx_encoder = {
... ...
@@ -167,7 +177,7 @@ AVCodec ff_dpx_encoder = {
167 167
     .id   = CODEC_ID_DPX,
168 168
     .priv_data_size = sizeof(DPXContext),
169 169
     .init   = encode_init,
170
-    .encode = encode_frame,
170
+    .encode2 = encode_frame,
171 171
     .pix_fmts = (const enum PixelFormat[]){
172 172
         PIX_FMT_RGB24,
173 173
         PIX_FMT_RGBA,