h263: K&R formatting cosmetics

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Signed-off-by: Diego Biurrun <diego@biurrun.de>
This commit is contained in:
Luca Barbato 2013-10-22 19:37:44 +02:00 committed by Diego Biurrun
parent 0d6d4a9e4a
commit 1ce3ec24b3

View File

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