755
755
s->cbp_table[xy]&= 3; //remove dquant
756
756
s->cbp_table[xy]|= cbpy<<2;
757
s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
757
s->current_picture.f.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
758
758
s->pred_dir_table[xy]= dir;
759
}else if(IS_SKIP(s->current_picture.mb_type[xy])){
760
s->current_picture.qscale_table[xy]= s->qscale;
759
} else if (IS_SKIP(s->current_picture.f.mb_type[xy])) {
760
s->current_picture.f.qscale_table[xy] = s->qscale;
761
761
s->cbp_table[xy]= 0;
763
763
int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
787
* decodes the first & second partition
787
* Decode the first and second partition.
788
788
* @return <0 if error (and sets error type in the error_status_table)
790
790
int ff_mpeg4_decode_partitions(MpegEncContext *s)
793
const int part_a_error= s->pict_type==AV_PICTURE_TYPE_I ? (DC_ERROR|MV_ERROR) : MV_ERROR;
794
const int part_a_end = s->pict_type==AV_PICTURE_TYPE_I ? (DC_END |MV_END) : MV_END;
793
const int part_a_error= s->pict_type==AV_PICTURE_TYPE_I ? (ER_DC_ERROR|ER_MV_ERROR) : ER_MV_ERROR;
794
const int part_a_end = s->pict_type==AV_PICTURE_TYPE_I ? (ER_DC_END |ER_MV_END) : ER_MV_END;
796
796
mb_num= mpeg4_decode_partition_a(s);
827
827
if( mpeg4_decode_partition_b(s, mb_num) < 0){
828
828
if(s->pict_type==AV_PICTURE_TYPE_P)
829
ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR);
829
ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_DC_ERROR);
832
832
if(s->pict_type==AV_PICTURE_TYPE_P)
833
ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END);
833
ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_DC_END);
841
841
* @return <0 if an error occurred
843
843
static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
934
934
}; SKIP_CACHE(re, &s->gb, 1);
936
936
last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
937
run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
937
run= SHOW_UBITS(re, &s->gb, 6);
938
938
SKIP_COUNTER(re, &s->gb, 1+1+6);
939
939
UPDATE_CACHE(re, &s->gb);
951
951
}; SKIP_CACHE(re, &s->gb, 5);
953
953
level= level * qmul + qadd;
954
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1);
954
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
955
955
SKIP_COUNTER(re, &s->gb, 1+11+5+1);
968
968
/* third escape */
969
969
SKIP_CACHE(re, &s->gb, 2);
970
970
last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
971
run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
971
run= SHOW_UBITS(re, &s->gb, 6);
972
972
SKIP_COUNTER(re, &s->gb, 2+1+6);
973
973
UPDATE_CACHE(re, &s->gb);
985
985
if(SHOW_UBITS(re, &s->gb, 1)==0){
986
986
av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n");
988
}; LAST_SKIP_CACHE(re, &s->gb, 1);
990
990
SKIP_COUNTER(re, &s->gb, 1+12+1);
994
if(s->error_recognition >= FF_ER_COMPLIANT){
995
const int abs_level= FFABS(level);
996
if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
997
const int run1= run - rl->max_run[last][abs_level] - 1;
998
if(abs_level <= rl->max_level[last][run]){
999
av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
1002
if(s->error_recognition > FF_ER_COMPLIANT){
1003
if(abs_level <= rl->max_level[last][run]*2){
1004
av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
1007
if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
1008
av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
1015
993
if (level>0) level= level * qmul + qadd;
1016
994
else level= level * qmul - qadd;
1018
996
if((unsigned)(level + 2048) > 4095){
1019
if(s->error_recognition > FF_ER_COMPLIANT){
997
if(s->err_recognition & AV_EF_BITSTREAM){
1020
998
if(level > 2560 || level<-2560){
1021
999
av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale);
1091
1069
int cbp, mb_type;
1092
1070
const int xy= s->mb_x + s->mb_y*s->mb_stride;
1094
mb_type= s->current_picture.mb_type[xy];
1072
mb_type = s->current_picture.f.mb_type[xy];
1095
1073
cbp = s->cbp_table[xy];
1097
1075
s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
1099
if(s->current_picture.qscale_table[xy] != s->qscale){
1100
ff_set_qscale(s, s->current_picture.qscale_table[xy] );
1077
if (s->current_picture.f.qscale_table[xy] != s->qscale) {
1078
ff_set_qscale(s, s->current_picture.f.qscale_table[xy]);
1103
1081
if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) {
1105
1083
for(i=0; i<4; i++){
1106
s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0];
1107
s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1];
1084
s->mv[0][i][0] = s->current_picture.f.motion_val[0][s->block_index[i]][0];
1085
s->mv[0][i][1] = s->current_picture.f.motion_val[0][s->block_index[i]][1];
1109
1087
s->mb_intra = IS_INTRA(mb_type);
1188
1166
s->mv_dir = MV_DIR_FORWARD;
1189
1167
s->mv_type = MV_TYPE_16X16;
1190
1168
if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){
1191
s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
1169
s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
1193
1171
s->mv[0][0][0]= get_amv(s, 0);
1194
1172
s->mv[0][0][1]= get_amv(s, 1);
1196
1174
s->mb_skipped = 0;
1198
s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
1176
s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
1200
1178
s->mv[0][0][0] = 0;
1201
1179
s->mv[0][0][1] = 0;
1491
1469
if(mpeg4_is_resync(s)){
1492
1470
const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
1494
if(s->pict_type==AV_PICTURE_TYPE_B && s->next_picture.mbskip_table[xy + delta]){
1472
if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture.f.mbskip_table[xy + delta]) {
1495
1473
ff_thread_await_progress((AVFrame*)s->next_picture_ptr,
1496
1474
(s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y+1, s->mb_height-1) : s->mb_y, 0);
1499
if(s->pict_type==AV_PICTURE_TYPE_B && s->next_picture.mbskip_table[xy + delta])
1477
if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture.f.mbskip_table[xy + delta])
1500
1478
return SLICE_OK;
1501
1479
return SLICE_END;
1504
static int mpeg4_decode_profile_level(MpegEncContext * s, GetBitContext *gb){
1505
int profile_and_level_indication;
1507
profile_and_level_indication = get_bits(gb, 8);
1509
s->avctx->profile = (profile_and_level_indication & 0xf0) >> 4;
1510
s->avctx->level = (profile_and_level_indication & 0x0f);
1512
// for Simple profile, level 0
1513
if (s->avctx->profile == 0 && s->avctx->level == 8) {
1514
s->avctx->level = 0;
1526
1520
static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){
1527
1521
int width, height, vo_ver_id;
1963
1957
if(s->avctx->time_base.num)
1964
s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num;
1958
s->current_picture_ptr->f.pts = (s->time + s->avctx->time_base.num / 2) / s->avctx->time_base.num;
1966
s->current_picture_ptr->pts= AV_NOPTS_VALUE;
1960
s->current_picture_ptr->f.pts = AV_NOPTS_VALUE;
1967
1961
if(s->avctx->debug&FF_DEBUG_PTS)
1968
av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", s->current_picture_ptr->pts);
1962
av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n",
1963
s->current_picture_ptr->f.pts);
1970
1965
check_marker(gb, "before vop_coded");
2237
static const AVProfile mpeg4_video_profiles[] = {
2238
{ FF_PROFILE_MPEG4_SIMPLE, "Simple Profile" },
2239
{ FF_PROFILE_MPEG4_SIMPLE_SCALABLE, "Simple Scalable Profile" },
2240
{ FF_PROFILE_MPEG4_CORE, "Core Profile" },
2241
{ FF_PROFILE_MPEG4_MAIN, "Main Profile" },
2242
{ FF_PROFILE_MPEG4_N_BIT, "N-bit Profile" },
2243
{ FF_PROFILE_MPEG4_SCALABLE_TEXTURE, "Scalable Texture Profile" },
2244
{ FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION, "Simple Face Animation Profile" },
2245
{ FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE, "Basic Animated Texture Profile" },
2246
{ FF_PROFILE_MPEG4_HYBRID, "Hybrid Profile" },
2247
{ FF_PROFILE_MPEG4_ADVANCED_REAL_TIME, "Advanced Real Time Simple Profile" },
2248
{ FF_PROFILE_MPEG4_CORE_SCALABLE, "Code Scalable Profile" },
2249
{ FF_PROFILE_MPEG4_ADVANCED_CODING, "Advanced Coding Profile" },
2250
{ FF_PROFILE_MPEG4_ADVANCED_CORE, "Advanced Core Profile" },
2251
{ FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE, "Advanced Scalable Texture Profile" },
2252
{ FF_PROFILE_MPEG4_SIMPLE_STUDIO, "Simple Studio Profile" },
2253
{ FF_PROFILE_MPEG4_ADVANCED_SIMPLE, "Advanced Simple Profile" },
2239
2256
AVCodec ff_mpeg4_decoder = {
2243
sizeof(MpegEncContext),
2247
ff_h263_decode_frame,
2248
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS,
2258
.type = AVMEDIA_TYPE_VIDEO,
2259
.id = CODEC_ID_MPEG4,
2260
.priv_data_size = sizeof(MpegEncContext),
2261
.init = decode_init,
2262
.close = ff_h263_decode_end,
2263
.decode = ff_h263_decode_frame,
2264
.capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS,
2249
2265
.flush= ff_mpeg_flush,
2250
2266
.max_lowres= 3,
2251
2267
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
2252
2268
.pix_fmts= ff_hwaccel_pixfmt_list_420,
2269
.profiles = NULL_IF_CONFIG_SMALL(mpeg4_video_profiles),
2253
2270
.update_thread_context= ONLY_IF_THREADS_ENABLED(ff_mpeg_update_thread_context)
2257
2274
#if CONFIG_MPEG4_VDPAU_DECODER
2258
2275
AVCodec ff_mpeg4_vdpau_decoder = {
2262
sizeof(MpegEncContext),
2266
ff_h263_decode_frame,
2267
CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
2276
.name = "mpeg4_vdpau",
2277
.type = AVMEDIA_TYPE_VIDEO,
2278
.id = CODEC_ID_MPEG4,
2279
.priv_data_size = sizeof(MpegEncContext),
2280
.init = decode_init,
2281
.close = ff_h263_decode_end,
2282
.decode = ff_h263_decode_frame,
2283
.capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
2268
2284
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 (VDPAU)"),
2269
2285
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_VDPAU_MPEG4, PIX_FMT_NONE},