... | ... |
@@ -21,22 +21,24 @@ |
21 | 21 |
|
22 | 22 |
#include "avcodec.h" |
23 | 23 |
#include "bytestream.h" |
24 |
+#include "internal.h" |
|
24 | 25 |
#include "pnm.h" |
25 | 26 |
|
26 | 27 |
|
27 |
-static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, |
|
28 |
- int buf_size, void *data) |
|
28 |
+static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
|
29 |
+ const AVFrame *pict, int *got_packet) |
|
29 | 30 |
{ |
30 | 31 |
PNMContext *s = avctx->priv_data; |
31 |
- AVFrame *pict = data; |
|
32 | 32 |
AVFrame * const p = (AVFrame*)&s->picture; |
33 |
- int i, h, w, n, linesize, depth, maxval; |
|
33 |
+ int i, h, w, n, linesize, depth, maxval, ret; |
|
34 | 34 |
const char *tuple_type; |
35 | 35 |
uint8_t *ptr; |
36 | 36 |
|
37 |
- if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) { |
|
37 |
+ if ((ret = ff_alloc_packet(pkt, avpicture_get_size(avctx->pix_fmt, |
|
38 |
+ avctx->width, |
|
39 |
+ avctx->height) + 200)) < 0) { |
|
38 | 40 |
av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
39 |
- return -1; |
|
41 |
+ return ret; |
|
40 | 42 |
} |
41 | 43 |
|
42 | 44 |
*p = *pict; |
... | ... |
@@ -44,8 +46,8 @@ static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, |
44 | 44 |
p->key_frame = 1; |
45 | 45 |
|
46 | 46 |
s->bytestream_start = |
47 |
- s->bytestream = outbuf; |
|
48 |
- s->bytestream_end = outbuf+buf_size; |
|
47 |
+ s->bytestream = pkt->data; |
|
48 |
+ s->bytestream_end = pkt->data + pkt->size; |
|
49 | 49 |
|
50 | 50 |
h = avctx->height; |
51 | 51 |
w = avctx->width; |
... | ... |
@@ -104,7 +106,11 @@ static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, |
104 | 104 |
ptr += linesize; |
105 | 105 |
} |
106 | 106 |
} |
107 |
- return s->bytestream - s->bytestream_start; |
|
107 |
+ |
|
108 |
+ pkt->size = s->bytestream - s->bytestream_start; |
|
109 |
+ pkt->flags |= AV_PKT_FLAG_KEY; |
|
110 |
+ *got_packet = 1; |
|
111 |
+ return 0; |
|
108 | 112 |
} |
109 | 113 |
|
110 | 114 |
|
... | ... |
@@ -114,7 +120,7 @@ AVCodec ff_pam_encoder = { |
114 | 114 |
.id = CODEC_ID_PAM, |
115 | 115 |
.priv_data_size = sizeof(PNMContext), |
116 | 116 |
.init = ff_pnm_init, |
117 |
- .encode = pam_encode_frame, |
|
117 |
+ .encode2 = pam_encode_frame, |
|
118 | 118 |
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE}, |
119 | 119 |
.long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"), |
120 | 120 |
}; |