|
|
|
@ -26,17 +26,17 @@ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "libavutil/cpu.h" |
|
|
|
|
#include "internal.h" |
|
|
|
|
#include "avcodec.h" |
|
|
|
|
#include "error_resilience.h" |
|
|
|
|
#include "mpegvideo.h" |
|
|
|
|
#include "flv.h" |
|
|
|
|
#include "h263.h" |
|
|
|
|
#include "h263_parser.h" |
|
|
|
|
#include "internal.h" |
|
|
|
|
#include "mpeg4video.h" |
|
|
|
|
#include "mpeg4video_parser.h" |
|
|
|
|
#include "mpegvideo.h" |
|
|
|
|
#include "msmpeg4.h" |
|
|
|
|
#include "thread.h" |
|
|
|
|
#include "flv.h" |
|
|
|
|
#include "mpeg4video.h" |
|
|
|
|
|
|
|
|
|
av_cold int ff_h263_decode_init(AVCodecContext *avctx) |
|
|
|
|
{ |
|
|
|
@ -44,7 +44,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) |
|
|
|
|
|
|
|
|
|
s->avctx = avctx; |
|
|
|
|
s->out_format = FMT_H263; |
|
|
|
|
|
|
|
|
|
s->width = avctx->coded_width; |
|
|
|
|
s->height = avctx->coded_height; |
|
|
|
|
s->workaround_bugs = avctx->workaround_bugs; |
|
|
|
@ -109,7 +108,8 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) |
|
|
|
|
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); |
|
|
|
|
|
|
|
|
|
/* for h263, we allocate the images after having read the header */ |
|
|
|
|
if (avctx->codec->id != AV_CODEC_ID_H263 && avctx->codec->id != AV_CODEC_ID_MPEG4) |
|
|
|
|
if (avctx->codec->id != AV_CODEC_ID_H263 && |
|
|
|
|
avctx->codec->id != AV_CODEC_ID_MPEG4) |
|
|
|
|
if (ff_MPV_common_init(s) < 0) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
@ -129,30 +129,40 @@ av_cold int ff_h263_decode_end(AVCodecContext *avctx) |
|
|
|
|
/**
|
|
|
|
|
* Return the number of bytes consumed for building the current frame. |
|
|
|
|
*/ |
|
|
|
|
static int get_consumed_bytes(MpegEncContext *s, int buf_size){ |
|
|
|
|
static int get_consumed_bytes(MpegEncContext *s, int buf_size) |
|
|
|
|
{ |
|
|
|
|
int pos = (get_bits_count(&s->gb) + 7) >> 3; |
|
|
|
|
|
|
|
|
|
if (s->divx_packed || s->avctx->hwaccel) { |
|
|
|
|
//we would have to scan through the whole buf to handle the weird reordering ...
|
|
|
|
|
/* We would have to scan through the whole buf to handle the weird
|
|
|
|
|
* reordering ... */ |
|
|
|
|
return buf_size; |
|
|
|
|
} else if (s->flags & CODEC_FLAG_TRUNCATED) { |
|
|
|
|
pos -= s->parse_context.last_index; |
|
|
|
|
if(pos<0) pos=0; // padding is not really read so this might be -1
|
|
|
|
|
// padding is not really read so this might be -1
|
|
|
|
|
if (pos < 0) |
|
|
|
|
pos = 0; |
|
|
|
|
return pos; |
|
|
|
|
} else { |
|
|
|
|
if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...)
|
|
|
|
|
if(pos+10>buf_size) pos=buf_size; // oops ;)
|
|
|
|
|
// avoid infinite loops (maybe not needed...)
|
|
|
|
|
if (pos == 0) |
|
|
|
|
pos = 1; |
|
|
|
|
// oops ;)
|
|
|
|
|
if (pos + 10 > buf_size) |
|
|
|
|
pos = buf_size; |
|
|
|
|
|
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int decode_slice(MpegEncContext *s){ |
|
|
|
|
const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F; |
|
|
|
|
static int decode_slice(MpegEncContext *s) |
|
|
|
|
{ |
|
|
|
|
const int part_mask = s->partitioned_frame |
|
|
|
|
? (ER_AC_END | ER_AC_ERROR) : 0x7F; |
|
|
|
|
const int mb_size = 16; |
|
|
|
|
|
|
|
|
|
s->last_resync_gb = s->gb; |
|
|
|
|
s->first_slice_line = 1; |
|
|
|
|
|
|
|
|
|
s->resync_mb_x = s->mb_x; |
|
|
|
|
s->resync_mb_y = s->mb_y; |
|
|
|
|
|
|
|
|
@ -160,7 +170,8 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
|
|
|
|
|
if (s->avctx->hwaccel) { |
|
|
|
|
const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8; |
|
|
|
|
const uint8_t *end = ff_h263_find_resync_marker(start + 1, s->gb.buffer_end); |
|
|
|
|
const uint8_t *end = ff_h263_find_resync_marker(start + 1, |
|
|
|
|
s->gb.buffer_end); |
|
|
|
|
skip_bits_long(&s->gb, 8 * (end - start)); |
|
|
|
|
return s->avctx->hwaccel->decode_slice(s->avctx, start, end - start); |
|
|
|
|
} |
|
|
|
@ -168,10 +179,9 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
if (s->partitioned_frame) { |
|
|
|
|
const int qscale = s->qscale; |
|
|
|
|
|
|
|
|
|
if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4){ |
|
|
|
|
if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4) |
|
|
|
|
if (ff_mpeg4_decode_partitions(s) < 0) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* restore variables which were modified */ |
|
|
|
|
s->first_slice_line = 1; |
|
|
|
@ -184,7 +194,8 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
/* per-row end of slice checks */ |
|
|
|
|
if (s->msmpeg4_version) { |
|
|
|
|
if (s->resync_mb_y + s->slice_height == s->mb_y) { |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, |
|
|
|
|
s->mb_x - 1, s->mb_y, ER_MB_END); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -202,9 +213,8 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
|
|
|
|
|
ff_update_block_index(s); |
|
|
|
|
|
|
|
|
|
if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){ |
|
|
|
|
if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y) |
|
|
|
|
s->first_slice_line = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* DCT & quantize */ |
|
|
|
|
|
|
|
|
@ -225,7 +235,8 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
if (s->loop_filter) |
|
|
|
|
ff_h263_loop_filter(s); |
|
|
|
|
|
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, |
|
|
|
|
s->mb_x, s->mb_y, ER_MB_END & part_mask); |
|
|
|
|
|
|
|
|
|
s->padding_bug_score--; |
|
|
|
|
|
|
|
|
@ -237,12 +248,16 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
} else if (ret == SLICE_NOEND) { |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy); |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask); |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
"Slice mismatch at MB: %d\n", xy); |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, |
|
|
|
|
s->mb_x + 1, s->mb_y, |
|
|
|
|
ER_MB_END & part_mask); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, |
|
|
|
|
s->mb_x, s->mb_y, ER_MB_ERROR & part_mask); |
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
@ -260,21 +275,20 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
|
|
|
|
|
assert(s->mb_x == 0 && s->mb_y == s->mb_height); |
|
|
|
|
|
|
|
|
|
if(s->codec_id==AV_CODEC_ID_MPEG4 |
|
|
|
|
&& (s->workaround_bugs&FF_BUG_AUTODETECT) |
|
|
|
|
&& get_bits_left(&s->gb) >= 48 |
|
|
|
|
&& show_bits(&s->gb, 24)==0x4010 |
|
|
|
|
&& !s->data_partitioning) |
|
|
|
|
if (s->codec_id == AV_CODEC_ID_MPEG4 && |
|
|
|
|
(s->workaround_bugs & FF_BUG_AUTODETECT) && |
|
|
|
|
get_bits_left(&s->gb) >= 48 && |
|
|
|
|
show_bits(&s->gb, 24) == 0x4010 && |
|
|
|
|
!s->data_partitioning) |
|
|
|
|
s->padding_bug_score += 32; |
|
|
|
|
|
|
|
|
|
/* try to detect the padding bug */ |
|
|
|
|
if( s->codec_id==AV_CODEC_ID_MPEG4 |
|
|
|
|
&& (s->workaround_bugs&FF_BUG_AUTODETECT) |
|
|
|
|
&& get_bits_left(&s->gb) >=0 |
|
|
|
|
&& get_bits_left(&s->gb) < 48 |
|
|
|
|
// && !s->resync_marker
|
|
|
|
|
&& !s->data_partitioning){ |
|
|
|
|
|
|
|
|
|
if (s->codec_id == AV_CODEC_ID_MPEG4 && |
|
|
|
|
(s->workaround_bugs & FF_BUG_AUTODETECT) && |
|
|
|
|
get_bits_left(&s->gb) >= 0 && |
|
|
|
|
get_bits_left(&s->gb) < 48 && |
|
|
|
|
// !s->resync_marker &&
|
|
|
|
|
!s->data_partitioning) { |
|
|
|
|
const int bits_count = get_bits_count(&s->gb); |
|
|
|
|
const int bits_left = s->gb.size_in_bits - bits_count; |
|
|
|
|
|
|
|
|
@ -286,7 +300,8 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
|
|
|
|
|
if (v == 0x7F && bits_left <= 8) |
|
|
|
|
s->padding_bug_score--; |
|
|
|
|
else if(v==0x7F && ((get_bits_count(&s->gb)+8)&8) && bits_left<=16) |
|
|
|
|
else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) && |
|
|
|
|
bits_left <= 16) |
|
|
|
|
s->padding_bug_score += 4; |
|
|
|
|
else |
|
|
|
|
s->padding_bug_score++; |
|
|
|
@ -294,7 +309,8 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->workaround_bugs & FF_BUG_AUTODETECT) { |
|
|
|
|
if(s->padding_bug_score > -2 && !s->data_partitioning /*&& (s->divx_version>=0 || !s->resync_marker)*/) |
|
|
|
|
if (s->padding_bug_score > -2 && !s->data_partitioning |
|
|
|
|
/* && (s->divx_version >= 0 || !s->resync_marker) */) |
|
|
|
|
s->workaround_bugs |= FF_BUG_NO_PADDING; |
|
|
|
|
else |
|
|
|
|
s->workaround_bugs &= ~FF_BUG_NO_PADDING; |
|
|
|
@ -309,34 +325,38 @@ static int decode_slice(MpegEncContext *s){ |
|
|
|
|
if (s->msmpeg4_version && s->pict_type == AV_PICTURE_TYPE_I) |
|
|
|
|
max_extra += 17; |
|
|
|
|
|
|
|
|
|
/* buggy padding but the frame should still end approximately at the bitstream end */ |
|
|
|
|
if((s->workaround_bugs&FF_BUG_NO_PADDING) && (s->err_recognition&AV_EF_BUFFER)) |
|
|
|
|
/* buggy padding but the frame should still end approximately at
|
|
|
|
|
* the bitstream end */ |
|
|
|
|
if ((s->workaround_bugs & FF_BUG_NO_PADDING) && |
|
|
|
|
(s->err_recognition & AV_EF_BUFFER)) |
|
|
|
|
max_extra += 48; |
|
|
|
|
else if ((s->workaround_bugs & FF_BUG_NO_PADDING)) |
|
|
|
|
max_extra += 256 * 256 * 256 * 64; |
|
|
|
|
|
|
|
|
|
if(left>max_extra){ |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24)); |
|
|
|
|
} |
|
|
|
|
else if(left<0){ |
|
|
|
|
if (left > max_extra) |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
"discarding %d junk bits at end, next would be %X\n", |
|
|
|
|
left, show_bits(&s->gb, 24)); |
|
|
|
|
else if (left < 0) |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left); |
|
|
|
|
}else |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); |
|
|
|
|
else |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, |
|
|
|
|
s->mb_x - 1, s->mb_y, ER_MB_END); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "slice end not reached but screenspace end (%d left %06X, score= %d)\n", |
|
|
|
|
get_bits_left(&s->gb), |
|
|
|
|
show_bits(&s->gb, 24), s->padding_bug_score); |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
"slice end not reached but screenspace end (%d left %06X, score= %d)\n", |
|
|
|
|
get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score); |
|
|
|
|
|
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); |
|
|
|
|
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, |
|
|
|
|
ER_MB_END & part_mask); |
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
void *data, int *got_frame, |
|
|
|
|
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, |
|
|
|
|
AVPacket *avpkt) |
|
|
|
|
{ |
|
|
|
|
const uint8_t *buf = avpkt->data; |
|
|
|
@ -370,25 +390,26 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
} else if (CONFIG_H263_DECODER && s->codec_id == AV_CODEC_ID_H263) { |
|
|
|
|
next = ff_h263_find_frame_end(&s->parse_context, buf, buf_size); |
|
|
|
|
} else { |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n"); |
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
"this codec does not support truncated bitstreams\n"); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) |
|
|
|
|
if (ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, |
|
|
|
|
&buf_size) < 0) |
|
|
|
|
return buf_size; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder
|
|
|
|
|
init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8); |
|
|
|
|
}else |
|
|
|
|
if (s->bitstream_buffer_size && (s->divx_packed || buf_size < 20)) // divx 5.01+/xvid frame reorder
|
|
|
|
|
init_get_bits(&s->gb, s->bitstream_buffer, |
|
|
|
|
s->bitstream_buffer_size * 8); |
|
|
|
|
else |
|
|
|
|
init_get_bits(&s->gb, buf, buf_size * 8); |
|
|
|
|
s->bitstream_buffer_size = 0; |
|
|
|
|
|
|
|
|
|
if (!s->context_initialized) { |
|
|
|
|
if (!s->context_initialized) |
|
|
|
|
if (ff_MPV_common_init(s) < 0) // we need the idct permutaton for reading a custom matrix
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* We need to set current_picture_ptr before reading the header,
|
|
|
|
|
* otherwise we cannot store anyting in there */ |
|
|
|
@ -408,7 +429,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
if (s->avctx->extradata_size && s->picture_number == 0) { |
|
|
|
|
GetBitContext gb; |
|
|
|
|
|
|
|
|
|
init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8); |
|
|
|
|
init_get_bits(&gb, s->avctx->extradata, |
|
|
|
|
s->avctx->extradata_size * 8); |
|
|
|
|
ret = ff_mpeg4_decode_picture_header(s, &gb); |
|
|
|
|
} |
|
|
|
|
ret = ff_mpeg4_decode_picture_header(s, &s->gb); |
|
|
|
@ -420,7 +442,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
ret = ff_h263_decode_picture_header(s); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size); |
|
|
|
|
if (ret == FRAME_SKIPPED) |
|
|
|
|
return get_consumed_bytes(s, buf_size); |
|
|
|
|
|
|
|
|
|
/* skip if the header was thrashed */ |
|
|
|
|
if (ret < 0) { |
|
|
|
@ -432,22 +455,24 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
|
|
|
|
|
if (s->xvid_build == -1 && s->divx_version == -1 && s->lavc_build == -1) { |
|
|
|
|
if (s->stream_codec_tag == AV_RL32("XVID") || |
|
|
|
|
s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") || |
|
|
|
|
s->codec_tag == AV_RL32("RMP4") || s->codec_tag == AV_RL32("ZMP4") || |
|
|
|
|
s->codec_tag == AV_RL32("SIPP") |
|
|
|
|
) |
|
|
|
|
s->codec_tag == AV_RL32("XVID") || |
|
|
|
|
s->codec_tag == AV_RL32("XVIX") || |
|
|
|
|
s->codec_tag == AV_RL32("RMP4") || |
|
|
|
|
s->codec_tag == AV_RL32("ZMP4") || |
|
|
|
|
s->codec_tag == AV_RL32("SIPP")) |
|
|
|
|
s->xvid_build = 0; |
|
|
|
|
#if 0 |
|
|
|
|
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1 |
|
|
|
|
&& s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc
|
|
|
|
|
if (s->codec_tag == AV_RL32("DIVX") && s->vo_type == 0 && |
|
|
|
|
s->vol_control_parameters == 1 && |
|
|
|
|
s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc
|
|
|
|
|
s->xvid_build = 0; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){ |
|
|
|
|
if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0) |
|
|
|
|
if (s->xvid_build == -1 && s->divx_version == -1 && s->lavc_build == -1) |
|
|
|
|
if (s->codec_tag == AV_RL32("DIVX") && s->vo_type == 0 && |
|
|
|
|
s->vol_control_parameters == 0) |
|
|
|
|
s->divx_version = 400; // divx 4
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->xvid_build >= 0 && s->divx_version >= 0) { |
|
|
|
|
s->divx_version = |
|
|
|
@ -458,17 +483,14 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
if (s->codec_tag == AV_RL32("XVIX")) |
|
|
|
|
s->workaround_bugs |= FF_BUG_XVID_ILACE; |
|
|
|
|
|
|
|
|
|
if(s->codec_tag == AV_RL32("UMP4")){ |
|
|
|
|
if (s->codec_tag == AV_RL32("UMP4")) |
|
|
|
|
s->workaround_bugs |= FF_BUG_UMP4; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(s->divx_version>=500 && s->divx_build<1814){ |
|
|
|
|
if (s->divx_version >= 500 && s->divx_build < 1814) |
|
|
|
|
s->workaround_bugs |= FF_BUG_QPEL_CHROMA; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(s->divx_version>502 && s->divx_build<1814){ |
|
|
|
|
if (s->divx_version > 502 && s->divx_build < 1814) |
|
|
|
|
s->workaround_bugs |= FF_BUG_QPEL_CHROMA2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->xvid_build <= 3U) |
|
|
|
|
s->padding_bug_score = 256 * 256 * 256 * 64; |
|
|
|
@ -493,9 +515,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
if (s->lavc_build < 4655U) |
|
|
|
|
s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; |
|
|
|
|
|
|
|
|
|
if(s->lavc_build<4670U){ |
|
|
|
|
if (s->lavc_build < 4670U) |
|
|
|
|
s->workaround_bugs |= FF_BUG_EDGE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->lavc_build <= 4712U) |
|
|
|
|
s->workaround_bugs |= FF_BUG_DC_CLIP; |
|
|
|
@ -505,9 +526,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
if (s->divx_version == 501 && s->divx_build == 20020416) |
|
|
|
|
s->padding_bug_score = 256 * 256 * 256 * 64; |
|
|
|
|
|
|
|
|
|
if(s->divx_version<500U){ |
|
|
|
|
if (s->divx_version < 500U) |
|
|
|
|
s->workaround_bugs |= FF_BUG_EDGE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->divx_version >= 0) |
|
|
|
|
s->workaround_bugs |= FF_BUG_HPEL_CHROMA; |
|
|
|
@ -516,13 +536,14 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
s->padding_bug_score = 256 * 256 * 256 * 64; |
|
|
|
|
|
|
|
|
|
/* very ugly XVID padding bug detection FIXME/XXX solve this differently
|
|
|
|
|
* Let us hope this at least works. |
|
|
|
|
*/ |
|
|
|
|
if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==-1 |
|
|
|
|
&& s->codec_id==AV_CODEC_ID_MPEG4 && s->vo_type==0) |
|
|
|
|
* Let us hope this at least works. */ |
|
|
|
|
if (s->resync_marker == 0 && s->data_partitioning == 0 && |
|
|
|
|
s->divx_version == -1 && s->codec_id == AV_CODEC_ID_MPEG4 && |
|
|
|
|
s->vo_type == 0) |
|
|
|
|
s->workaround_bugs |= FF_BUG_NO_PADDING; |
|
|
|
|
|
|
|
|
|
if(s->lavc_build<4609U) //FIXME not sure about the version num but a 4609 file seems ok
|
|
|
|
|
// FIXME not sure about the version num but a 4609 file seems ok
|
|
|
|
|
if (s->lavc_build < 4609U) |
|
|
|
|
s->workaround_bugs |= FF_BUG_NO_PADDING; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
@ -544,23 +565,25 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (avctx->debug & FF_DEBUG_BUGS) |
|
|
|
|
av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n", |
|
|
|
|
s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build, |
|
|
|
|
s->divx_packed ? "p" : ""); |
|
|
|
|
av_log(s->avctx, AV_LOG_DEBUG, |
|
|
|
|
"bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n", |
|
|
|
|
s->workaround_bugs, s->lavc_build, s->xvid_build, |
|
|
|
|
s->divx_version, s->divx_build, s->divx_packed ? "p" : ""); |
|
|
|
|
|
|
|
|
|
#if HAVE_MMX |
|
|
|
|
if (s->codec_id == AV_CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) { |
|
|
|
|
if (s->codec_id == AV_CODEC_ID_MPEG4 && s->xvid_build >= 0 && |
|
|
|
|
avctx->idct_algo == FF_IDCT_AUTO && |
|
|
|
|
(av_get_cpu_flags() & AV_CPU_FLAG_MMX)) { |
|
|
|
|
avctx->idct_algo = FF_IDCT_XVIDMMX; |
|
|
|
|
ff_dct_common_init(s); |
|
|
|
|
s->picture_number = 0; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* After H263 & mpeg4 header decode we have the height, width,*/ |
|
|
|
|
/* and other parameters. So then we could init the picture */ |
|
|
|
|
/* FIXME: By the way H263 decoder is evolving it should have */ |
|
|
|
|
/* an H263EncContext */ |
|
|
|
|
|
|
|
|
|
/* After H263 & mpeg4 header decode we have the height, width,
|
|
|
|
|
* and other parameters. So then we could init the picture. |
|
|
|
|
* FIXME: By the way H263 decoder is evolving it should have |
|
|
|
|
* an H263EncContext */ |
|
|
|
|
if (s->width != avctx->coded_width || |
|
|
|
|
s->height != avctx->coded_height || |
|
|
|
|
s->context_reinit) { |
|
|
|
@ -573,7 +596,9 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if((s->codec_id==AV_CODEC_ID_H263 || s->codec_id==AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_H263I)) |
|
|
|
|
if (s->codec_id == AV_CODEC_ID_H263 || |
|
|
|
|
s->codec_id == AV_CODEC_ID_H263P || |
|
|
|
|
s->codec_id == AV_CODEC_ID_H263I) |
|
|
|
|
s->gob_index = ff_h263_get_gob_height(s); |
|
|
|
|
|
|
|
|
|
// for skipping the frame
|
|
|
|
@ -584,9 +609,11 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
if (s->last_picture_ptr == NULL && |
|
|
|
|
(s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) |
|
|
|
|
return get_consumed_bytes(s, buf_size); |
|
|
|
|
if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B) |
|
|
|
|
|| (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I) |
|
|
|
|
|| avctx->skip_frame >= AVDISCARD_ALL) |
|
|
|
|
if ((avctx->skip_frame >= AVDISCARD_NONREF && |
|
|
|
|
s->pict_type == AV_PICTURE_TYPE_B) || |
|
|
|
|
(avctx->skip_frame >= AVDISCARD_NONKEY && |
|
|
|
|
s->pict_type != AV_PICTURE_TYPE_I) || |
|
|
|
|
avctx->skip_frame >= AVDISCARD_ALL) |
|
|
|
|
return get_consumed_bytes(s, buf_size); |
|
|
|
|
|
|
|
|
|
if (s->next_p_frame_damaged) { |
|
|
|
@ -610,19 +637,22 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
if (!s->divx_packed && !avctx->hwaccel) |
|
|
|
|
ff_thread_finish_setup(avctx); |
|
|
|
|
|
|
|
|
|
if (avctx->hwaccel) { |
|
|
|
|
if (avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.buffer_end - s->gb.buffer) < 0) |
|
|
|
|
if (avctx->hwaccel) |
|
|
|
|
if (avctx->hwaccel->start_frame(avctx, s->gb.buffer, |
|
|
|
|
s->gb.buffer_end - s->gb.buffer) < 0) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ff_mpeg_er_frame_start(s); |
|
|
|
|
|
|
|
|
|
//the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type
|
|
|
|
|
//which is not available before ff_MPV_frame_start()
|
|
|
|
|
/* the second part of the wmv2 header contains the MB skip bits which
|
|
|
|
|
* are stored in current_picture->mb_type which is not available before |
|
|
|
|
* ff_MPV_frame_start() */ |
|
|
|
|
if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) { |
|
|
|
|
ret = ff_wmv2_decode_secondary_picture_header(s); |
|
|
|
|
if(ret<0) return ret; |
|
|
|
|
if(ret==1) goto intrax8_decoded; |
|
|
|
|
if (ret < 0) |
|
|
|
|
return ret; |
|
|
|
|
if (ret == 1) |
|
|
|
|
goto intrax8_decoded; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* decode each macroblock */ |
|
|
|
@ -632,7 +662,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
ret = decode_slice(s); |
|
|
|
|
while (s->mb_y < s->mb_height) { |
|
|
|
|
if (s->msmpeg4_version) { |
|
|
|
|
if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_left(&s->gb)<0) |
|
|
|
|
if (s->slice_height == 0 || s->mb_x != 0 || |
|
|
|
|
(s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0) |
|
|
|
|
break; |
|
|
|
|
} else { |
|
|
|
|
int prev_x = s->mb_x, prev_y = s->mb_y; |
|
|
|
@ -645,13 +676,15 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
if (s->msmpeg4_version < 4 && s->h263_pred) |
|
|
|
|
ff_mpeg4_clean_buffers(s); |
|
|
|
|
|
|
|
|
|
if (decode_slice(s) < 0) ret = AVERROR_INVALIDDATA; |
|
|
|
|
if (decode_slice(s) < 0) |
|
|
|
|
ret = AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I) |
|
|
|
|
if(!CONFIG_MSMPEG4_DECODER || ff_msmpeg4_decode_ext_header(s, buf_size) < 0){ |
|
|
|
|
if (s->msmpeg4_version && s->msmpeg4_version < 4 && |
|
|
|
|
s->pict_type == AV_PICTURE_TYPE_I) |
|
|
|
|
if (!CONFIG_MSMPEG4_DECODER || |
|
|
|
|
ff_msmpeg4_decode_ext_header(s, buf_size) < 0) |
|
|
|
|
s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assert(s->bitstream_buffer_size == 0); |
|
|
|
|
/* divx 5.01+ bistream reorder stuff */ |
|
|
|
@ -661,26 +694,30 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
|
|
|
|
|
if (buf_size - current_pos > 5) { |
|
|
|
|
int i; |
|
|
|
|
for(i=current_pos; i<buf_size-3; i++){ |
|
|
|
|
if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){ |
|
|
|
|
for (i = current_pos; i < buf_size - 3; i++) |
|
|
|
|
if (buf[i] == 0 && |
|
|
|
|
buf[i + 1] == 0 && |
|
|
|
|
buf[i + 2] == 1 && |
|
|
|
|
buf[i + 3] == 0xB6) { |
|
|
|
|
startcode_found = 1; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(s->gb.buffer == s->bitstream_buffer && buf_size>7 && s->xvid_build>=0){ //xvid style
|
|
|
|
|
if (s->gb.buffer == s->bitstream_buffer && buf_size > 7 && |
|
|
|
|
s->xvid_build >= 0) { // xvid style
|
|
|
|
|
startcode_found = 1; |
|
|
|
|
current_pos = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (startcode_found) { |
|
|
|
|
av_fast_malloc( |
|
|
|
|
&s->bitstream_buffer, |
|
|
|
|
av_fast_malloc(&s->bitstream_buffer, |
|
|
|
|
&s->allocated_bitstream_buffer_size, |
|
|
|
|
buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE); |
|
|
|
|
buf_size - current_pos + |
|
|
|
|
FF_INPUT_BUFFER_PADDING_SIZE); |
|
|
|
|
if (!s->bitstream_buffer) |
|
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos); |
|
|
|
|
memcpy(s->bitstream_buffer, buf + current_pos, |
|
|
|
|
buf_size - current_pos); |
|
|
|
|
s->bitstream_buffer_size = buf_size - current_pos; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -688,17 +725,17 @@ int ff_h263_decode_frame(AVCodecContext *avctx, |
|
|
|
|
intrax8_decoded: |
|
|
|
|
ff_er_frame_end(&s->er); |
|
|
|
|
|
|
|
|
|
if (avctx->hwaccel) { |
|
|
|
|
if (avctx->hwaccel) |
|
|
|
|
if (avctx->hwaccel->end_frame(avctx) < 0) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ff_MPV_frame_end(s); |
|
|
|
|
|
|
|
|
|
if (!s->divx_packed && avctx->hwaccel) |
|
|
|
|
ff_thread_finish_setup(avctx); |
|
|
|
|
|
|
|
|
|
assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type); |
|
|
|
|
assert(s->current_picture.f.pict_type == |
|
|
|
|
s->current_picture_ptr->f.pict_type); |
|
|
|
|
assert(s->current_picture.f.pict_type == s->pict_type); |
|
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { |
|
|
|
|
if ((ret = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0) |
|
|
|
@ -710,11 +747,13 @@ intrax8_decoded: |
|
|
|
|
ff_print_debug_info(s, s->last_picture_ptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(s->last_picture_ptr || s->low_delay){ |
|
|
|
|
if (s->last_picture_ptr || s->low_delay) |
|
|
|
|
*got_frame = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return (ret && (avctx->err_recognition & AV_EF_EXPLODE))?ret:get_consumed_bytes(s, buf_size); |
|
|
|
|
if (ret && (avctx->err_recognition & AV_EF_EXPLODE)) |
|
|
|
|
return ret; |
|
|
|
|
else |
|
|
|
|
return get_consumed_bytes(s, buf_size); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[] = { |
|
|
|
|