1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit '69f6f03cd16a09e4e848b4e82bae4993bc361cd0'

* commit '69f6f03cd16a09e4e848b4e82bae4993bc361cd0':
  rv10: cosmetics, reformat
  qdm2: check that the FFT size is a power of 2

Conflicts:
	libavcodec/rv10.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-04-17 16:04:38 +02:00
commit 8cff853b23
2 changed files with 278 additions and 284 deletions

View File

@ -1883,6 +1883,10 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "Unknown FFT order (%d), contact the developers!\n", s->fft_order);
return -1;
}
if (s->fft_size != (1 << (s->fft_order - 1))) {
av_log(avctx, AV_LOG_ERROR, "FFT size %d not power of 2.\n", s->fft_size);
return AVERROR_INVALIDDATA;
}
ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R);
ff_mpadsp_init(&s->mpadsp);

View File

@ -45,8 +45,7 @@ typedef struct RVDecContext {
int sub_id;
} RVDecContext;
static const uint16_t rv_lum_code[256] =
{
static const uint16_t rv_lum_code[256] = {
0x3e7f, 0x0f00, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05, 0x0f06,
0x0f07, 0x0f08, 0x0f09, 0x0f0a, 0x0f0b, 0x0f0c, 0x0f0d, 0x0f0e,
0x0f0f, 0x0f10, 0x0f11, 0x0f12, 0x0f13, 0x0f14, 0x0f15, 0x0f16,
@ -81,8 +80,7 @@ static const uint16_t rv_lum_code[256] =
0x0f78, 0x0f79, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f7e, 0x0f7f,
};
static const uint8_t rv_lum_bits[256] =
{
static const uint8_t rv_lum_bits[256] = {
14, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12,
@ -117,8 +115,7 @@ static const uint8_t rv_lum_bits[256] =
12, 12, 12, 12, 12, 12, 12, 12,
};
static const uint16_t rv_chrom_code[256] =
{
static const uint16_t rv_chrom_code[256] = {
0xfe7f, 0x3f00, 0x3f01, 0x3f02, 0x3f03, 0x3f04, 0x3f05, 0x3f06,
0x3f07, 0x3f08, 0x3f09, 0x3f0a, 0x3f0b, 0x3f0c, 0x3f0d, 0x3f0e,
0x3f0f, 0x3f10, 0x3f11, 0x3f12, 0x3f13, 0x3f14, 0x3f15, 0x3f16,
@ -153,8 +150,7 @@ static const uint16_t rv_chrom_code[256] =
0x3f78, 0x3f79, 0x3f7a, 0x3f7b, 0x3f7c, 0x3f7d, 0x3f7e, 0x3f7f,
};
static const uint8_t rv_chrom_bits[256] =
{
static const uint8_t rv_chrom_bits[256] = {
16, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14,
@ -252,18 +248,21 @@ static int rv10_decode_picture_header(MpegEncContext *s)
s->pict_type = AV_PICTURE_TYPE_P;
else
s->pict_type = AV_PICTURE_TYPE_I;
if(!marker) av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
if (!marker)
av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
pb_frame = get_bits1(&s->gb);
av_dlog(s->avctx, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
if (pb_frame){
if (pb_frame) {
av_log(s->avctx, AV_LOG_ERROR, "pb frame not supported\n");
return -1;
}
s->qscale = get_bits(&s->gb, 5);
if(s->qscale==0){
if (s->qscale == 0) {
av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
return -1;
}
@ -281,8 +280,8 @@ static int rv10_decode_picture_header(MpegEncContext *s)
/* if multiple packets per frame are sent, the position at which
to display the macroblocks is coded here */
mb_xy= s->mb_x + s->mb_y*s->mb_width;
if(show_bits(&s->gb, 12)==0 || (mb_xy && mb_xy < s->mb_num)){
mb_xy = s->mb_x + s->mb_y * s->mb_width;
if (show_bits(&s->gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) {
s->mb_x = get_bits(&s->gb, 6); /* mb_x */
s->mb_y = get_bits(&s->gb, 6); /* mb_y */
mb_count = get_bits(&s->gb, 12);
@ -304,79 +303,63 @@ static int rv20_decode_picture_header(RVDecContext *rv)
int seq, mb_pos, i;
int rpr_bits;
#if 0
GetBitContext gb= s->gb;
for(i=0; i<64; i++){
av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&gb));
if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
}
av_log(s->avctx, AV_LOG_DEBUG, "\n");
#endif
#if 0
av_log(s->avctx, AV_LOG_DEBUG, "%3dx%03d/%02Xx%02X ", s->width, s->height, s->width/4, s->height/4);
for(i=0; i<s->avctx->extradata_size; i++){
av_log(s->avctx, AV_LOG_DEBUG, "%02X ", ((uint8_t*)s->avctx->extradata)[i]);
if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
}
av_log(s->avctx, AV_LOG_DEBUG, "\n");
#endif
i= get_bits(&s->gb, 2);
switch(i){
case 0: s->pict_type= AV_PICTURE_TYPE_I; break;
case 1: s->pict_type= AV_PICTURE_TYPE_I; break; //hmm ...
case 2: s->pict_type= AV_PICTURE_TYPE_P; break;
case 3: s->pict_type= AV_PICTURE_TYPE_B; break;
i = get_bits(&s->gb, 2);
switch(i) {
case 0: s->pict_type = AV_PICTURE_TYPE_I; break;
case 1: s->pict_type = AV_PICTURE_TYPE_I; break; //hmm ...
case 2: s->pict_type = AV_PICTURE_TYPE_P; break;
case 3: s->pict_type = AV_PICTURE_TYPE_B; break;
default:
av_log(s->avctx, AV_LOG_ERROR, "unknown frame type\n");
return -1;
}
if(s->low_delay && s->pict_type==AV_PICTURE_TYPE_B){
if (s->low_delay && s->pict_type == AV_PICTURE_TYPE_B) {
av_log(s->avctx, AV_LOG_ERROR, "low delay B\n");
return -1;
}
if(s->last_picture_ptr==NULL && s->pict_type==AV_PICTURE_TYPE_B){
if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B) {
av_log(s->avctx, AV_LOG_ERROR, "early B pix\n");
return -1;
}
if (get_bits1(&s->gb)){
if (get_bits1(&s->gb)) {
av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n");
return -1;
}
s->qscale = get_bits(&s->gb, 5);
if(s->qscale==0){
if (s->qscale == 0) {
av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
return -1;
}
if(RV_GET_MINOR_VER(rv->sub_id) >= 2)
if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
s->loop_filter = get_bits1(&s->gb) && !s->avctx->lowres;
if(RV_GET_MINOR_VER(rv->sub_id) <= 1)
if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
seq = get_bits(&s->gb, 8) << 7;
else
seq = get_bits(&s->gb, 13) << 2;
rpr_bits = s->avctx->extradata[1] & 7;
if(rpr_bits){
if (rpr_bits) {
int f, new_w, new_h;
rpr_bits = FFMIN((rpr_bits >> 1) + 1, 3);
f = get_bits(&s->gb, rpr_bits);
if(f){
new_w= 4*((uint8_t*)s->avctx->extradata)[6+2*f];
new_h= 4*((uint8_t*)s->avctx->extradata)[7+2*f];
}else{
new_w= s->orig_width ;
new_h= s->orig_height;
if (f) {
new_w = 4 * ((uint8_t*)s->avctx->extradata)[6 + 2 * f];
new_h = 4 * ((uint8_t*)s->avctx->extradata)[7 + 2 * f];
} else {
new_w = s->orig_width ;
new_h = s->orig_height;
}
if(new_w != s->width || new_h != s->height){
if (new_w != s->width || new_h != s->height) {
AVRational old_aspect = s->avctx->sample_aspect_ratio;
av_log(s->avctx, AV_LOG_DEBUG, "attempting to change resolution to %dx%d\n", new_w, new_h);
av_log(s->avctx, AV_LOG_DEBUG,
"attempting to change resolution to %dx%d\n", new_w, new_h);
if (av_image_check_size(new_w, new_h, 0, s->avctx) < 0)
return -1;
ff_MPV_common_end(s);
@ -395,7 +378,7 @@ static int rv20_decode_picture_header(RVDecContext *rv)
return -1;
}
if(s->avctx->debug & FF_DEBUG_PICT_INFO){
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, rpr_bits);
}
}
@ -404,44 +387,45 @@ static int rv20_decode_picture_header(RVDecContext *rv)
mb_pos = ff_h263_decode_mba(s);
seq |= s->time &~0x7FFF;
if(seq - s->time > 0x4000) seq -= 0x8000;
if(seq - s->time < -0x4000) seq += 0x8000;
if(seq != s->time){
if(s->pict_type!=AV_PICTURE_TYPE_B){
s->time= seq;
s->pp_time= s->time - s->last_non_b_time;
s->last_non_b_time= s->time;
}else{
s->time= seq;
s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
seq |= s->time & ~0x7FFF;
if (seq - s->time > 0x4000)
seq -= 0x8000;
if (seq - s->time < -0x4000)
seq += 0x8000;
if (seq != s->time) {
if (s->pict_type != AV_PICTURE_TYPE_B) {
s->time = seq;
s->pp_time = s->time - s->last_non_b_time;
s->last_non_b_time = s->time;
} else {
s->time = seq;
s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
}
}
if (s->pict_type==AV_PICTURE_TYPE_B) {
if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){
av_log(s->avctx, AV_LOG_DEBUG, "messed up order, possible from seeking? skipping current b frame\n");
if (s->pict_type == AV_PICTURE_TYPE_B) {
if (s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0) {
av_log(s->avctx, AV_LOG_DEBUG,
"messed up order, possible from seeking? skipping current b frame\n");
#define ERROR_SKIP_FRAME -123
return ERROR_SKIP_FRAME;
}
ff_mpeg4_init_direct_mv(s);
}
s->no_rounding= get_bits1(&s->gb);
s->no_rounding = get_bits1(&s->gb);
if(RV_GET_MINOR_VER(rv->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
skip_bits(&s->gb, 5); // binary decoder reads 3+2 bits here but they don't seem to be used
s->f_code = 1;
s->unrestricted_mv = 1;
s->h263_aic= s->pict_type == AV_PICTURE_TYPE_I;
// s->alt_inter_vlc=1;
// s->obmc=1;
// s->umvplus=1;
s->modified_quant=1;
if(!s->avctx->lowres)
s->loop_filter=1;
s->h263_aic = s->pict_type == AV_PICTURE_TYPE_I;
s->modified_quant = 1;
if (!s->avctx->lowres)
s->loop_filter = 1;
if(s->avctx->debug & FF_DEBUG_PICT_INFO){
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(s->avctx, AV_LOG_INFO, "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
seq, s->mb_x, s->mb_y, s->pict_type, s->qscale, s->no_rounding);
}
@ -455,7 +439,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
{
RVDecContext *rv = avctx->priv_data;
MpegEncContext *s = &rv->m;
static int done=0;
static int done = 0;
int major_ver, minor_ver, micro_ver;
if (avctx->extradata_size < 8) {
@ -465,14 +449,14 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
ff_MPV_decode_defaults(s);
s->avctx= avctx;
s->avctx = avctx;
s->out_format = FMT_H263;
s->codec_id= avctx->codec_id;
s->codec_id = avctx->codec_id;
s->orig_width = s->width = avctx->coded_width;
s->orig_height= s->height = avctx->coded_height;
s->orig_height = s->height = avctx->coded_height;
s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1;
s->h263_long_vectors = ((uint8_t*)avctx->extradata)[3] & 1;
rv->sub_id = AV_RB32((uint8_t*)avctx->extradata + 4);
major_ver = RV_GET_MAJOR_VER(rv->sub_id);
@ -497,8 +481,9 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
return AVERROR_PATCHWELCOME;
}
if(avctx->debug & FF_DEBUG_PICT_INFO){
av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", rv->sub_id, ((uint32_t*)avctx->extradata)[0]);
if (avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", rv->sub_id,
((uint32_t*)avctx->extradata)[0]);
}
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
@ -539,7 +524,7 @@ static int rv10_decode_packet(AVCodecContext *avctx,
active_bits_size = buf_size * 8;
init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8);
if(s->codec_id ==AV_CODEC_ID_RV10)
if (s->codec_id == AV_CODEC_ID_RV10)
mb_count = rv10_decode_picture_header(s);
else
mb_count = rv20_decode_picture_header(rv);
@ -561,13 +546,13 @@ static int rv10_decode_packet(AVCodecContext *avctx,
return -1;
}
if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) {
if(s->current_picture_ptr){ //FIXME write parser so we always have complete frames?
if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr == NULL) {
if (s->current_picture_ptr) { // FIXME write parser so we always have complete frames?
ff_er_frame_end(&s->er);
ff_MPV_frame_end(s);
s->mb_x= s->mb_y = s->resync_mb_x = s->resync_mb_y= 0;
s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
}
if(ff_MPV_frame_start(s, avctx) < 0)
if (ff_MPV_frame_start(s, avctx) < 0)
return -1;
ff_mpeg_er_frame_start(s);
} else {
@ -581,47 +566,46 @@ static int rv10_decode_packet(AVCodecContext *avctx,
av_dlog(avctx, "qscale=%d\n", s->qscale);
/* default quantization values */
if(s->codec_id== AV_CODEC_ID_RV10){
if(s->mb_y==0) s->first_slice_line=1;
}else{
s->first_slice_line=1;
s->resync_mb_x= s->mb_x;
if (s->codec_id == AV_CODEC_ID_RV10) {
if (s->mb_y == 0)
s->first_slice_line = 1;
} else {
s->first_slice_line = 1;
s->resync_mb_x = s->mb_x;
}
start_mb_x= s->mb_x;
s->resync_mb_y= s->mb_y;
if(s->h263_aic){
s->y_dc_scale_table=
s->c_dc_scale_table= ff_aic_dc_scale_table;
}else{
s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
start_mb_x = s->mb_x;
s->resync_mb_y = s->mb_y;
if (s->h263_aic) {
s->y_dc_scale_table = s->c_dc_scale_table = ff_aic_dc_scale_table;
} else {
s->y_dc_scale_table = s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
}
if(s->modified_quant)
s->chroma_qscale_table= ff_h263_chroma_qscale_table;
if (s->modified_quant)
s->chroma_qscale_table = ff_h263_chroma_qscale_table;
ff_set_qscale(s, s->qscale);
s->rv10_first_dc_coded[0] = 0;
s->rv10_first_dc_coded[1] = 0;
s->rv10_first_dc_coded[2] = 0;
s->block_wrap[0]=
s->block_wrap[1]=
s->block_wrap[2]=
s->block_wrap[3]= s->b8_stride;
s->block_wrap[4]=
s->block_wrap[5]= s->mb_stride;
s->block_wrap[0] =
s->block_wrap[1] =
s->block_wrap[2] =
s->block_wrap[3] = s->b8_stride;
s->block_wrap[4] =
s->block_wrap[5] = s->mb_stride;
ff_init_block_index(s);
/* decode each macroblock */
for(s->mb_num_left= mb_count; s->mb_num_left>0; s->mb_num_left--) {
/* decode each macroblock */
for (s->mb_num_left = mb_count; s->mb_num_left > 0; s->mb_num_left--) {
int ret;
ff_update_block_index(s);
av_dlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y);
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
ret=ff_h263_decode_mb(s, s->block);
ret = ff_h263_decode_mb(s, s->block);
// Repeat the slice end check from ff_h263_decode_mb with our active
// bitstream size
@ -639,17 +623,17 @@ static int rv10_decode_packet(AVCodecContext *avctx,
active_bits_size = buf_size2 * 8;
av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
8 * buf_size, active_bits_size);
ret= SLICE_OK;
ret = SLICE_OK;
}
if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) {
av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
return -1;
}
if(s->pict_type != AV_PICTURE_TYPE_B)
if (s->pict_type != AV_PICTURE_TYPE_B)
ff_h263_update_motion_val(s);
ff_MPV_decode_mb(s, s->block);
if(s->loop_filter)
if (s->loop_filter)
ff_h263_loop_filter(s);
if (++s->mb_x == s->mb_width) {
@ -657,20 +641,24 @@ static int rv10_decode_packet(AVCodecContext *avctx,
s->mb_y++;
ff_init_block_index(s);
}
if(s->mb_x == s->resync_mb_x)
s->first_slice_line=0;
if(ret == SLICE_END) break;
if (s->mb_x == s->resync_mb_x)
s->first_slice_line = 0;
if (ret == SLICE_END)
break;
}
ff_er_add_slice(&s->er, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);
ff_er_add_slice(&s->er, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y,
ER_MB_END);
return active_bits_size;
}
static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
{
if(avctx->slice_count) return avctx->slice_offset[n];
else return AV_RL32(buf + n*8);
if (avctx->slice_count)
return avctx->slice_offset[n];
else
return AV_RL32(buf + n * 8);
}
static int rv10_decode_frame(AVCodecContext *avctx,
@ -680,8 +668,8 @@ static int rv10_decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MpegEncContext *s = avctx->priv_data;
int i, ret;
AVFrame *pict = data;
int i, ret;
int slice_count;
const uint8_t *slices_hdr = NULL;
@ -694,7 +682,7 @@ static int rv10_decode_frame(AVCodecContext *avctx,
return 0;
}
if(!avctx->slice_count){
if (!avctx->slice_count) {
slice_count = (*buf++) + 1;
buf_size--;
@ -706,35 +694,35 @@ static int rv10_decode_frame(AVCodecContext *avctx,
slices_hdr = buf + 4;
buf += 8 * slice_count;
buf_size -= 8 * slice_count;
}else
} else
slice_count = avctx->slice_count;
for(i=0; i<slice_count; i++){
for (i = 0; i < slice_count; i++) {
unsigned offset = get_slice_offset(avctx, slices_hdr, i);
int size, size2;
if (offset >= buf_size)
return AVERROR_INVALIDDATA;
if(i+1 == slice_count)
size= buf_size - offset;
if (i + 1 == slice_count)
size = buf_size - offset;
else
size= get_slice_offset(avctx, slices_hdr, i+1) - offset;
size = get_slice_offset(avctx, slices_hdr, i + 1) - offset;
if(i+2 >= slice_count)
size2= buf_size - offset;
if (i + 2 >= slice_count)
size2 = buf_size - offset;
else
size2= get_slice_offset(avctx, slices_hdr, i+2) - offset;
size2 = get_slice_offset(avctx, slices_hdr, i + 2) - offset;
if (size <= 0 || size2 <= 0 ||
offset + FFMAX(size, size2) > buf_size)
return AVERROR_INVALIDDATA;
if(rv10_decode_packet(avctx, buf+offset, size, size2) > 8*size)
if (rv10_decode_packet(avctx, buf + offset, size, size2) > 8 * size)
i++;
}
if(s->current_picture_ptr != NULL && s->mb_y>=s->mb_height){
if (s->current_picture_ptr != NULL && s->mb_y >= s->mb_height) {
ff_er_frame_end(&s->er);
ff_MPV_frame_end(s);
@ -750,10 +738,12 @@ static int rv10_decode_frame(AVCodecContext *avctx,
ff_mpv_export_qp_table(s, pict,s->last_picture_ptr, FF_QSCALE_TYPE_MPEG1);
}
if(s->last_picture_ptr || s->low_delay){
if (s->last_picture_ptr || s->low_delay) {
*got_frame = 1;
}
s->current_picture_ptr= NULL; // so we can detect if frame_end was not called (find some nicer solution...)
// so we can detect if frame_end was not called (find some nicer solution...)
s->current_picture_ptr = NULL;
}
return avpkt->size;