comparison iff.c @ 11806:8d8ca3eb8389 libavcodec

Move get_buffer() calls from decode_init() to decode_frame(). Anything else is unsupported and causes crashes when libavfilter is enabled. Patch by Sebastian Vater <cdgs basty googlemail com>.
author rbultje
date Tue, 01 Jun 2010 16:36:36 +0000
parents 9bfef228a117
children 317c18e0b753
comparison
equal deleted inserted replaced
11805:0448680fa221 11806:8d8ca3eb8389
32 32
33 typedef struct { 33 typedef struct {
34 AVFrame frame; 34 AVFrame frame;
35 int planesize; 35 int planesize;
36 uint8_t * planebuf; 36 uint8_t * planebuf;
37 int init; // 1 if buffer and palette data already initialized, 0 otherwise
37 } IffContext; 38 } IffContext;
38 39
39 #define LUT8_PART(plane, v) \ 40 #define LUT8_PART(plane, v) \
40 AV_LE2ME64C(UINT64_C(0x0000000)<<32 | v) << plane, \ 41 AV_LE2ME64C(UINT64_C(0x0000000)<<32 | v) << plane, \
41 AV_LE2ME64C(UINT64_C(0x1000000)<<32 | v) << plane, \ 42 AV_LE2ME64C(UINT64_C(0x1000000)<<32 | v) << plane, \
165 s->planebuf = av_malloc(s->planesize + FF_INPUT_BUFFER_PADDING_SIZE); 166 s->planebuf = av_malloc(s->planesize + FF_INPUT_BUFFER_PADDING_SIZE);
166 if (!s->planebuf) 167 if (!s->planebuf)
167 return AVERROR(ENOMEM); 168 return AVERROR(ENOMEM);
168 169
169 s->frame.reference = 1; 170 s->frame.reference = 1;
170 if ((err = avctx->get_buffer(avctx, &s->frame) < 0)) { 171
171 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 172 return 0;
172 return err;
173 }
174
175 return (avctx->bits_per_coded_sample <= 8 &&
176 avctx->pix_fmt != PIX_FMT_GRAY8) ?
177 ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1]) : 0;
178 } 173 }
179 174
180 /** 175 /**
181 * Decode interleaved plane buffer up to 8bpp 176 * Decode interleaved plane buffer up to 8bpp
182 * @param dst Destination buffer 177 * @param dst Destination buffer
256 { 251 {
257 IffContext *s = avctx->priv_data; 252 IffContext *s = avctx->priv_data;
258 const uint8_t *buf = avpkt->data; 253 const uint8_t *buf = avpkt->data;
259 int buf_size = avpkt->size; 254 int buf_size = avpkt->size;
260 const uint8_t *buf_end = buf+buf_size; 255 const uint8_t *buf_end = buf+buf_size;
261 int y, plane; 256 int y, plane, res;
262 257
263 if (avctx->reget_buffer(avctx, &s->frame) < 0){ 258 if (s->init) {
259 if ((res = avctx->reget_buffer(avctx, &s->frame)) < 0) {
260 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
261 return res;
262 }
263 } else if ((res = avctx->get_buffer(avctx, &s->frame)) < 0) {
264 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 264 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
265 return -1; 265 return res;
266 } 266 } else if (avctx->bits_per_coded_sample <= 8 && avctx->pix_fmt != PIX_FMT_GRAY8) {
267 if ((res = ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1])) < 0)
268 return res;
269 }
270 s->init = 1;
267 271
268 if (avctx->codec_tag == MKTAG('I','L','B','M')) { // interleaved 272 if (avctx->codec_tag == MKTAG('I','L','B','M')) { // interleaved
269 if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { 273 if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) {
270 for(y = 0; y < avctx->height; y++ ) { 274 for(y = 0; y < avctx->height; y++ ) {
271 uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; 275 uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
304 { 308 {
305 IffContext *s = avctx->priv_data; 309 IffContext *s = avctx->priv_data;
306 const uint8_t *buf = avpkt->data; 310 const uint8_t *buf = avpkt->data;
307 int buf_size = avpkt->size; 311 int buf_size = avpkt->size;
308 const uint8_t *buf_end = buf+buf_size; 312 const uint8_t *buf_end = buf+buf_size;
309 int y, plane; 313 int y, plane, res;
310 314
311 if (avctx->reget_buffer(avctx, &s->frame) < 0){ 315 if (s->init) {
316 if ((res = avctx->reget_buffer(avctx, &s->frame)) < 0) {
317 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
318 return res;
319 }
320 } else if ((res = avctx->get_buffer(avctx, &s->frame)) < 0) {
312 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 321 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
313 return -1; 322 return res;
314 } 323 } else if (avctx->bits_per_coded_sample <= 8 && avctx->pix_fmt != PIX_FMT_GRAY8) {
324 if ((res = ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1])) < 0)
325 return res;
326 }
327 s->init = 1;
315 328
316 if (avctx->codec_tag == MKTAG('I','L','B','M')) { //interleaved 329 if (avctx->codec_tag == MKTAG('I','L','B','M')) { //interleaved
317 if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { 330 if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) {
318 for(y = 0; y < avctx->height ; y++ ) { 331 for(y = 0; y < avctx->height ; y++ ) {
319 uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; 332 uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];