}
}
- static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int log2w, int log2h, int stride){
- const int index= size2index[log2h][log2w];
- const int h= 1<<log2h;
- int code= get_vlc2(&f->gb, block_type_vlc[1-(f->version>1)][index].table, BLOCK_TYPE_VLC_BITS, 1);
- uint16_t *start= (uint16_t*)f->last_picture.data[0];
- uint16_t *end= start + stride*(f->avctx->height-h+1) - (1<<log2w);
-
- assert(code>=0 && code<=6);
-
- if(code == 0){
- if (f->g.buffer_end - f->g.buffer < 1){
+ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src,
+ int log2w, int log2h, int stride)
+ {
+ const int index = size2index[log2h][log2w];
+ const int h = 1 << log2h;
+ int code = get_vlc2(&f->gb,
+ block_type_vlc[1 - (f->version > 1)][index].table,
+ BLOCK_TYPE_VLC_BITS, 1);
+ uint16_t *start = (uint16_t *)f->last_picture.data[0];
+ uint16_t *end = start + stride * (f->avctx->height - h + 1) - (1 << log2w);
+
+ assert(code >= 0 && code <= 6);
+
+ if (code == 0) {
++ if (f->g.buffer_end - f->g.buffer < 1) {
+ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n");
+ return;
+ }
- src += f->mv[ *f->g.buffer++ ];
- if(start > src || src > end){
+ src += f->mv[bytestream2_get_byte(&f->g)];
+ if (start > src || src > end) {
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
return;
}
mcdc(dst, src, log2w, h, stride, 1, 0);
- }else if(code == 1){
+ } else if (code == 1) {
log2h--;
- decode_p_block(f, dst , src , log2w, log2h, stride);
- decode_p_block(f, dst + (stride<<log2h), src + (stride<<log2h), log2w, log2h, stride);
- }else if(code == 2){
+ decode_p_block(f, dst, src, log2w, log2h, stride);
+ decode_p_block(f, dst + (stride << log2h),
+ src + (stride << log2h), log2w, log2h, stride);
+ } else if (code == 2) {
log2w--;
- decode_p_block(f, dst , src , log2w, log2h, stride);
- decode_p_block(f, dst + (1<<log2w), src + (1<<log2w), log2w, log2h, stride);
- }else if(code == 3 && f->version<2){
+ decode_p_block(f, dst , src, log2w, log2h, stride);
+ decode_p_block(f, dst + (1 << log2w),
+ src + (1 << log2w), log2w, log2h, stride);
+ } else if (code == 3 && f->version < 2) {
mcdc(dst, src, log2w, h, stride, 1, 0);
- }else if(code == 4){
- if (f->g.buffer_end - f->g.buffer < 1){
+ } else if (code == 4) {
++ if (f->g.buffer_end - f->g.buffer < 1) {
+ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n");
+ return;
+ }
- src += f->mv[ *f->g.buffer++ ];
- if(start > src || src > end){
+ src += f->mv[bytestream2_get_byte(&f->g)];
+ if (start > src || src > end) {
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
return;
}
+ if (f->g2.buffer_end - f->g2.buffer < 1){
+ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
+ return;
+ }
mcdc(dst, src, log2w, h, stride, 1, bytestream2_get_le16(&f->g2));
- }else if(code == 5){
- if (f->g2.buffer_end - f->g2.buffer < 1){
+ } else if (code == 5) {
++ if (f->g2.buffer_end - f->g2.buffer < 1) {
+ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
+ return;
+ }
mcdc(dst, src, log2w, h, stride, 0, bytestream2_get_le16(&f->g2));
- }else if(code == 6){
- if (f->g2.buffer_end - f->g2.buffer < 2){
+ } else if (code == 6) {
++ if (f->g2.buffer_end - f->g2.buffer < 2) {
+ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
+ return;
+ }
- if(log2w){
- dst[0] = bytestream2_get_le16(&f->g2);
- dst[1] = bytestream2_get_le16(&f->g2);
- }else{
- dst[0 ] = bytestream2_get_le16(&f->g2);
+ if (log2w) {
+ dst[0] = bytestream2_get_le16(&f->g2);
+ dst[1] = bytestream2_get_le16(&f->g2);
+ } else {
+ dst[0] = bytestream2_get_le16(&f->g2);
dst[stride] = bytestream2_get_le16(&f->g2);
}
}
}
- static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
+ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length)
+ {
int x, y;
- const int width= f->avctx->width;
- const int height= f->avctx->height;
- uint16_t *src= (uint16_t*)f->last_picture.data[0];
- uint16_t *dst= (uint16_t*)f->current_picture.data[0];
- const int stride= f->current_picture.linesize[0]>>1;
- unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset;
-
- if(f->version>1){
- extra=20;
+ const int width = f->avctx->width;
+ const int height = f->avctx->height;
+ uint16_t *src = (uint16_t *)f->last_picture.data[0];
+ uint16_t *dst = (uint16_t *)f->current_picture.data[0];
+ const int stride = f->current_picture.linesize[0] >> 1;
+ unsigned int bitstream_size, bytestream_size, wordstream_size, extra,
+ bytestream_offset, wordstream_offset;
+
+ if (f->version > 1) {
+ extra = 20;
+ if (length < extra)
+ return -1;
- bitstream_size= AV_RL32(buf+8);
- wordstream_size= AV_RL32(buf+12);
- bytestream_size= AV_RL32(buf+16);
- }else{
- extra=0;
- bitstream_size = AV_RL16(buf-4);
- wordstream_size= AV_RL16(buf-2);
- bytestream_size= FFMAX(length - bitstream_size - wordstream_size, 0);
+ bitstream_size = AV_RL32(buf + 8);
+ wordstream_size = AV_RL32(buf + 12);
+ bytestream_size = AV_RL32(buf + 16);
+ } else {
+ extra = 0;
+ bitstream_size = AV_RL16(buf - 4);
+ wordstream_size = AV_RL16(buf - 2);
+ bytestream_size = FFMAX(length - bitstream_size - wordstream_size, 0);
}
- if (bitstream_size + bytestream_size + wordstream_size + extra != length
- || bitstream_size > (1 << 26)
- || bytestream_size > (1 << 26)
- || wordstream_size > (1 << 26)) {
- av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n",
- bitstream_size, bytestream_size, wordstream_size,
- bitstream_size + bytestream_size + wordstream_size - length);
+ if (bitstream_size > length ||
+ bytestream_size > length - bitstream_size ||
+ wordstream_size > length - bytestream_size - bitstream_size ||
- extra > length - bytestream_size - bitstream_size - wordstream_size){
++ extra > length - bytestream_size - bitstream_size - wordstream_size) {
+ av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,
+ bitstream_size+ bytestream_size+ wordstream_size - length);
return -1;
}
* decode block and dequantize.
* Note this is almost identical to MJPEG.
*/
- static int decode_i_block(FourXContext *f, DCTELEM *block){
+ static int decode_i_block(FourXContext *f, DCTELEM *block)
+ {
int code, i, j, level, val;
- if(get_bits_left(&f->gb) < 2){
++ if (get_bits_left(&f->gb) < 2){
+ av_log(f->avctx, AV_LOG_ERROR, "%d bits left before decode_i_block()\n", get_bits_left(&f->gb));
+ return -1;
+ }
+
/* DC coef */
val = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
- if (val>>4){
+ if (val >> 4)
av_log(f->avctx, AV_LOG_ERROR, "error dc run != 0\n");
- }
- if(val)
+ if (val)
val = get_xbits(&f->gb, val);
- val = val * dequant_table[0] + f->last_dc;
- f->last_dc =
- block[0] = val;
+ val = val * dequant_table[0] + f->last_dc;
+ f->last_dc = block[0] = val;
/* AC coefs */
i = 1;
- for(;;) {
+ for (;;) {
code = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
/* EOB */
return 0;
}
- static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf, int buf_size){
+ static const uint8_t *read_huffman_tables(FourXContext *f,
- const uint8_t * const buf)
++ const uint8_t * const buf, int buf_size)
+ {
int frequency[512];
uint8_t flag[512];
int up[512];
uint8_t len_tab[257];
int bits_tab[257];
int start, end;
- const uint8_t *ptr= buf;
+ const uint8_t *ptr = buf;
+ const uint8_t *ptr_end = buf + buf_size;
int j;
memset(frequency, 0, sizeof(frequency));
memset(up, -1, sizeof(up));
- start= *ptr++;
- end= *ptr++;
- for(;;){
+ start = *ptr++;
+ end = *ptr++;
+ for (;;) {
int i;
- for(i=start; i<=end; i++){
- frequency[i]= *ptr++;
- }
- start= *ptr++;
- if(start==0) break;
+ if (start <= end && ptr_end - ptr < end - start + 1 + 1)
+ return NULL;
+ for (i = start; i <= end; i++)
+ frequency[i] = *ptr++;
+ start = *ptr++;
+ if (start == 0)
+ break;
- end= *ptr++;
+ end = *ptr++;
}
- frequency[256]=1;
+ frequency[256] = 1;
- while((ptr - buf)&3) ptr++; // 4byte align
+ while ((ptr - buf) & 3)
+ ptr++; // 4byte align
- for(j=257; j<512; j++){
- int min_freq[2]= {256*256, 256*256};
- int smallest[2]= {0, 0};
+ for (j = 257; j < 512; j++) {
+ int min_freq[2] = { 256 * 256, 256 * 256 };
+ int smallest[2] = { 0, 0 };
int i;
- for(i=0; i<j; i++){
- if(frequency[i] == 0) continue;
- if(frequency[i] < min_freq[1]){
- if(frequency[i] < min_freq[0]){
- min_freq[1]= min_freq[0]; smallest[1]= smallest[0];
- min_freq[0]= frequency[i];smallest[0]= i;
- }else{
- min_freq[1]= frequency[i];smallest[1]= i;
+ for (i = 0; i < j; i++) {
+ if (frequency[i] == 0)
+ continue;
+ if (frequency[i] < min_freq[1]) {
+ if (frequency[i] < min_freq[0]) {
+ min_freq[1] = min_freq[0];
+ smallest[1] = smallest[0];
+ min_freq[0] = frequency[i];
+ smallest[0] = i;
+ } else {
+ min_freq[1] = frequency[i];
+ smallest[1] = i;
}
}
}
return ptr;
}
- static int mix(int c0, int c1){
- int blue = 2*(c0&0x001F) + (c1&0x001F);
- int green= (2*(c0&0x03E0) + (c1&0x03E0))>>5;
- int red = 2*(c0>>10) + (c1>>10);
- return red/3*1024 + green/3*32 + blue/3;
+ static int mix(int c0, int c1)
+ {
+ int blue = 2 * (c0 & 0x001F) + (c1 & 0x001F);
+ int green = (2 * (c0 & 0x03E0) + (c1 & 0x03E0)) >> 5;
+ int red = 2 * (c0 >> 10) + (c1 >> 10);
+ return red / 3 * 1024 + green / 3 * 32 + blue / 3;
}
- static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){
+ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length)
+ {
int x, y, x2, y2;
- const int width= f->avctx->width;
- const int height= f->avctx->height;
- const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4);
- uint16_t *dst= (uint16_t*)f->current_picture.data[0];
- const int stride= f->current_picture.linesize[0]>>1;
+ const int width = f->avctx->width;
+ const int height = f->avctx->height;
+ const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4);
+ uint16_t *dst = (uint16_t*)f->current_picture.data[0];
+ const int stride = f->current_picture.linesize[0]>>1;
+ const uint8_t *buf_end = buf + length;
GetByteContext g3;
- if(length < mbs * 8) {
+ if (length < mbs * 8) {
av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n");
return AVERROR_INVALIDDATA;
}
bytestream2_init(&g3, buf, length);
- for(y=0; y<height; y+=16){
- for(x=0; x<width; x+=16){
+ for (y = 0; y < height; y += 16) {
+ for (x = 0; x < width; x += 16) {
unsigned int color[4], bits;
+ if (buf_end - buf < 8)
+ return -1;
memset(color, 0, sizeof(color));
- //warning following is purely guessed ...
- color[0]= bytestream2_get_le16u(&g3);
- color[1]= bytestream2_get_le16u(&g3);
-
- if(color[0]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 1\n");
- if(color[1]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 2\n");
-
- color[2]= mix(color[0], color[1]);
- color[3]= mix(color[1], color[0]);
-
- bits= bytestream2_get_le32u(&g3);
- for(y2=0; y2<16; y2++){
- for(x2=0; x2<16; x2++){
- int index= 2*(x2>>2) + 8*(y2>>2);
- dst[y2*stride+x2]= color[(bits>>index)&3];
+ // warning following is purely guessed ...
+ color[0] = bytestream2_get_le16u(&g3);
+ color[1] = bytestream2_get_le16u(&g3);
+
+ if (color[0] & 0x8000)
+ av_log(NULL, AV_LOG_ERROR, "unk bit 1\n");
+ if (color[1] & 0x8000)
+ av_log(NULL, AV_LOG_ERROR, "unk bit 2\n");
+
+ color[2] = mix(color[0], color[1]);
+ color[3] = mix(color[1], color[0]);
+
+ bits = bytestream2_get_le32u(&g3);
+ for (y2 = 0; y2 < 16; y2++) {
+ for (x2 = 0; x2 < 16; x2++) {
+ int index = 2 * (x2 >> 2) + 8 * (y2 >> 2);
+ dst[y2 * stride + x2] = color[(bits >> index) & 3];
}
}
- dst+=16;
+ dst += 16;
}
dst += 16 * stride - x;
}
return 0;
}
- static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){
+ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length)
+ {
int x, y;
- const int width= f->avctx->width;
- const int height= f->avctx->height;
- const unsigned int bitstream_size= AV_RL32(buf);
+ const int width = f->avctx->width;
+ const int height = f->avctx->height;
+ const unsigned int bitstream_size = AV_RL32(buf);
- int token_count av_unused;
unsigned int prestream_size;
const uint8_t *prestream;
return AVERROR_INVALIDDATA;
}
- token_count = AV_RL32(buf + bitstream_size + 8);
prestream_size = 4 * AV_RL32(buf + bitstream_size + 4);
- prestream = buf + bitstream_size + 12;
+ prestream = buf + bitstream_size + 12;
- if (prestream_size > (1<<26) ||
- prestream_size != length - (bitstream_size + 12)){
- av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length);
+ if (prestream_size + bitstream_size + 12 != length
+ || bitstream_size > (1 << 26)
+ || prestream_size > (1 << 26)) {
+ av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n",
+ prestream_size, bitstream_size, length);
return -1;
}
- prestream= read_huffman_tables(f, prestream, buf + length - prestream);
- prestream = read_huffman_tables(f, prestream);
++ prestream = read_huffman_tables(f, prestream, buf + length - prestream);
+ if (!prestream)
+ return -1;
- init_get_bits(&f->gb, buf + 4, 8*bitstream_size);
+ init_get_bits(&f->gb, buf + 4, 8 * bitstream_size);
- prestream_size= length + buf - prestream;
+ prestream_size = length + buf - prestream;
- av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,
+ prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!f->bitstream_buffer)
return AVERROR(ENOMEM);
- f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream, prestream_size/4);
- memset((uint8_t*)f->bitstream_buffer + prestream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
- init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size);
+ f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream,
+ prestream_size / 4);
+ memset((uint8_t*)f->bitstream_buffer + prestream_size,
+ 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size);
- f->last_dc= 0*128*8*8;
+ f->last_dc = 0 * 128 * 8 * 8;
- for(y=0; y<height; y+=16){
- for(x=0; x<width; x+=16){
- if(decode_i_mb(f) < 0)
+ for (y = 0; y < height; y += 16) {
+ for (x = 0; x < width; x += 16) {
+ if (decode_i_mb(f) < 0)
return -1;
idct_put(f, x, y);
AVFrame *p, temp;
int i, frame_4cc, frame_size;
- frame_4cc= AV_RL32(buf);
- if(buf_size != AV_RL32(buf+4)+8 || buf_size < 20){
- av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4));
- }
-
- if(frame_4cc == AV_RL32("cfrm")){
- int free_index=-1;
- const int data_size= buf_size - 20;
- const int id= AV_RL32(buf+12);
- const int whole_size= AV_RL32(buf+16);
+ if (buf_size < 12)
+ return AVERROR_INVALIDDATA;
+ frame_4cc = AV_RL32(buf);
+ if (buf_size != AV_RL32(buf + 4) + 8 || buf_size < 20)
+ av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n",
+ buf_size, AV_RL32(buf + 4));
+
+ if (frame_4cc == AV_RL32("cfrm")) {
+ int free_index = -1;
+ const int data_size = buf_size - 20;
+ const int id = AV_RL32(buf + 12);
+ const int whole_size = AV_RL32(buf + 16);
CFrameBuffer *cfrm;
- if (data_size < 0 || whole_size < 0){
++ if (data_size < 0 || whole_size < 0) {
+ av_log(f->avctx, AV_LOG_ERROR, "sizes invalid\n");
+ return AVERROR_INVALIDDATA;
+ }
+
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- if(f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
- av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id);
- }
+ for (i = 0; i < CFRAME_BUFFER_COUNT; i++)
+ if (f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
+ av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n",
+ f->cfrm[i].id);
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- if(f->cfrm[i].id == id) break;
- if(f->cfrm[i].size == 0 ) free_index= i;
+ for (i = 0; i < CFRAME_BUFFER_COUNT; i++) {
+ if (f->cfrm[i].id == id)
+ break;
+ if (f->cfrm[i].size == 0)
+ free_index = i;
}
- if(i>=CFRAME_BUFFER_COUNT){
- i= free_index;
- f->cfrm[i].id= id;
+ if (i >= CFRAME_BUFFER_COUNT) {
+ i = free_index;
+ f->cfrm[i].id = id;
}
- cfrm= &f->cfrm[i];
+ cfrm = &f->cfrm[i];
- cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if(!cfrm->data){ //explicit check needed as memcpy below might not catch a NULL
+ if (data_size > UINT_MAX - cfrm->size - FF_INPUT_BUFFER_PADDING_SIZE)
+ return AVERROR_INVALIDDATA;
++
+ cfrm->data = av_fast_realloc(cfrm->data, &cfrm->allocated_size,
+ cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ // explicit check needed as memcpy below might not catch a NULL
+ if (!cfrm->data) {
av_log(f->avctx, AV_LOG_ERROR, "realloc falure");
return -1;
}
- memcpy(cfrm->data + cfrm->size, buf+20, data_size);
+ memcpy(cfrm->data + cfrm->size, buf + 20, data_size);
cfrm->size += data_size;
- if(cfrm->size >= whole_size){
- buf= cfrm->data;
- frame_size= cfrm->size;
+ if (cfrm->size >= whole_size) {
+ buf = cfrm->data;
+ frame_size = cfrm->size;
- if(id != avctx->frame_number){
- av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n", id, avctx->frame_number);
- }
+ if (id != avctx->frame_number)
+ av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n",
+ id, avctx->frame_number);
- cfrm->size= cfrm->id= 0;
- frame_4cc= AV_RL32("pfrm");
- }else
+ cfrm->size = cfrm->id = 0;
+ frame_4cc = AV_RL32("pfrm");
+ } else
return buf_size;
- }else{
- buf= buf + 12;
- frame_size= buf_size - 12;
+ } else {
+ buf = buf + 12;
+ frame_size = buf_size - 12;
}
- temp= f->current_picture;
- f->current_picture= f->last_picture;
- f->last_picture= temp;
+ temp = f->current_picture;
+ f->current_picture = f->last_picture;
+ f->last_picture = temp;
- p= &f->current_picture;
- avctx->coded_frame= p;
+ p = &f->current_picture;
+ avctx->coded_frame = p;
- avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management
+ // alternatively we would have to use our own buffer management
+ avctx->flags |= CODEC_FLAG_EMU_EDGE;
- if (p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference = 1;
- if (avctx->get_buffer(avctx, p) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ p->reference= 3;
+ if (avctx->reget_buffer(avctx, p) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
- if(frame_4cc == AV_RL32("ifr2")){
+ if (frame_4cc == AV_RL32("ifr2")) {
- p->pict_type = AV_PICTURE_TYPE_I;
- if (decode_i2_frame(f, buf - 4, frame_size + 4) < 0)
+ p->pict_type= AV_PICTURE_TYPE_I;
- if(decode_i2_frame(f, buf-4, frame_size + 4) < 0) {
++ if (decode_i2_frame(f, buf - 4, frame_size + 4) < 0) {
+ av_log(f->avctx, AV_LOG_ERROR, "decode i2 frame failed\n");
return -1;
- }else if(frame_4cc == AV_RL32("ifrm")){
+ }
- p->pict_type = AV_PICTURE_TYPE_I;
- if (decode_i_frame(f, buf, frame_size) < 0)
+ } else if (frame_4cc == AV_RL32("ifrm")) {
- if(decode_i_frame(f, buf, frame_size) < 0){
+ p->pict_type= AV_PICTURE_TYPE_I;
++ if (decode_i_frame(f, buf, frame_size) < 0) {
+ av_log(f->avctx, AV_LOG_ERROR, "decode i frame failed\n");
return -1;
- }else if(frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")){
- if(!f->last_picture.data[0]){
- f->last_picture.reference= 3;
- if(avctx->get_buffer(avctx, &f->last_picture) < 0){
+ }
- f->last_picture.reference = 1;
+ } else if (frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")) {
+ if (!f->last_picture.data[0]) {
++ f->last_picture.reference = 3;
+ if (avctx->get_buffer(avctx, &f->last_picture) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
}
- p->pict_type= AV_PICTURE_TYPE_P;
- if(decode_p_frame(f, buf, frame_size) < 0){
+ p->pict_type = AV_PICTURE_TYPE_P;
- if (decode_p_frame(f, buf, frame_size) < 0)
++ if (decode_p_frame(f, buf, frame_size) < 0) {
+ av_log(f->avctx, AV_LOG_ERROR, "decode p frame failed\n");
return -1;
- }else if(frame_4cc == AV_RL32("snd_")){
- av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size);
- }else{
- av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", buf_size);
+ }
+ } else if (frame_4cc == AV_RL32("snd_")) {
+ av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n",
+ buf_size);
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n",
+ buf_size);
}
- p->key_frame= p->pict_type == AV_PICTURE_TYPE_I;
+ p->key_frame = p->pict_type == AV_PICTURE_TYPE_I;
- *picture= *p;
+ *picture = *p;
*data_size = sizeof(AVPicture);
emms_c();
av_log(avctx, AV_LOG_ERROR, "extradata wrong or missing\n");
return 1;
}
+ if((avctx->width % 16) || (avctx->height % 16)) {
+ av_log(avctx, AV_LOG_ERROR, "unsupported width/height\n");
+ return AVERROR_INVALIDDATA;
+ }
- f->version= AV_RL32(avctx->extradata)>>16;
+ avcodec_get_frame_defaults(&f->current_picture);
+ avcodec_get_frame_defaults(&f->last_picture);
+ f->version = AV_RL32(avctx->extradata) >> 16;
common_init(avctx);
init_vlcs(f);