This is in preparation for moving the fields only used by H.263-based decoders from MPVContext to H263DecContext. For now only the decode_mb function pointer has been moved (to be able to switch said callback to use an H263DecContext*).
Unified · Split
| @@ -26,31 +26,31 @@ · 25 unmodified lines | |||
| 26 | #include "mpegvideo.h" | 26 | #include "mpegvideo.h" |
| 27 | #include "mpegvideodec.h" | 27 | #include "mpegvideodec.h" |
| 28 | 28 | ||
| 29 | int ff_flv_decode_picture_header(MpegEncContext *s) | 29 | int ff_flv_decode_picture_header(H263DecContext *const h) |
| 30 | { | 30 | { |
| 31 | int format, width, height; | 31 | int format, width, height; |
| 32 | 32 | ||
| 33 | /* picture header */ | 33 | /* picture header */ |
| 34 | if (get_bits(&s->gb, 17) != 1) { | 34 | if (get_bits(&h->c.gb, 17) != 1) { |
| 35 | av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); | 35 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
| 36 | return AVERROR_INVALIDDATA; | 36 | return AVERROR_INVALIDDATA; |
| 37 | } | 37 | } |
| 38 | format = get_bits(&s->gb, 5); | 38 | format = get_bits(&h->c.gb, 5); |
| 39 | if (format != 0 && format != 1) { | 39 | if (format != 0 && format != 1) { |
| 40 | av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n"); | 40 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n"); |
| 41 | return AVERROR_INVALIDDATA; | 41 | return AVERROR_INVALIDDATA; |
| 42 | } | 42 | } |
| 43 | s->h263_flv = format + 1; | 43 | h->c.h263_flv = format + 1; |
| 44 | s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ | 44 | h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */ |
| 45 | format = get_bits(&s->gb, 3); | 45 | format = get_bits(&h->c.gb, 3); |
| 46 | switch (format) { | 46 | switch (format) { |
| 47 | case 0: | 47 | case 0: |
| 48 | width = get_bits(&s->gb, 8); | 48 | width = get_bits(&h->c.gb, 8); |
| 49 | height = get_bits(&s->gb, 8); | 49 | height = get_bits(&h->c.gb, 8); |
| 50 | break; | 50 | break; |
| 51 | case 1: | 51 | case 1: |
| 52 | width = get_bits(&s->gb, 16); | 52 | width = get_bits(&h->c.gb, 16); |
| 53 | height = get_bits(&s->gb, 16); | 53 | height = get_bits(&h->c.gb, 16); |
| 54 | break; | 54 | break; |
| 55 | case 2: | 55 | case 2: |
| 56 | width = 352; | 56 | width = 352; |
| @@ -76,32 +76,32 @@ int ff_flv_decode_picture_header(MpegEncContext *s) · 19 unmodified lines | |||
| 76 | width = height = 0; | 76 | width = height = 0; |
| 77 | break; | 77 | break; |
| 78 | } | 78 | } |
| 79 | if (av_image_check_size(width, height, 0, s->avctx)) | 79 | if (av_image_check_size(width, height, 0, h->c.avctx)) |
| 80 | return AVERROR(EINVAL); | 80 | return AVERROR(EINVAL); |
| 81 | s->width = width; | 81 | h->c.width = width; |
| 82 | s->height = height; | 82 | h->c.height = height; |
| 83 | 83 | ||
| 84 | s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2); | 84 | h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->c.gb, 2); |
| 85 | s->droppable = s->pict_type > AV_PICTURE_TYPE_P; | 85 | h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P; |
| 86 | if (s->droppable) | 86 | if (h->c.droppable) |
| 87 | s->pict_type = AV_PICTURE_TYPE_P; | 87 | h->c.pict_type = AV_PICTURE_TYPE_P; |
| 88 | 88 | ||
| 89 | skip_bits1(&s->gb); /* deblocking flag */ | 89 | skip_bits1(&h->c.gb); /* deblocking flag */ |
| 90 | s->chroma_qscale = s->qscale = get_bits(&s->gb, 5); | 90 | h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); |
| 91 | 91 | ||
| 92 | s->h263_long_vectors = 0; | 92 | h->c.h263_long_vectors = 0; |
| 93 | 93 | ||
| 94 | /* PEI */ | 94 | /* PEI */ |
| 95 | if (skip_1stop_8data_bits(&s->gb) < 0) | 95 | if (skip_1stop_8data_bits(&h->c.gb) < 0) |
| 96 | return AVERROR_INVALIDDATA; | 96 | return AVERROR_INVALIDDATA; |
| 97 | 97 | ||
| 98 | if (s->ehc_mode) | 98 | if (h->c.ehc_mode) |
| 99 | s->avctx->sample_aspect_ratio= (AVRational){1,2}; | 99 | h->c.avctx->sample_aspect_ratio= (AVRational){1,2}; |
| 100 | 100 | ||
| 101 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | 101 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { |
| 102 | av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", | 102 | av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", |
| 103 | s->droppable ? 'D' : av_get_picture_type_char(s->pict_type), | 103 | h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type), |
| 104 | s->h263_flv - 1, s->qscale, s->picture_number); | 104 | h->c.h263_flv - 1, h->c.qscale, h->c.picture_number); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | return 0; | 107 | return 0; |
| @@ -112,7 +112,7 @@ const FFCodec ff_flv_decoder = { · 4 unmodified lines | |||
| 112 | CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"), | 112 | CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"), |
| 113 | .p.type = AVMEDIA_TYPE_VIDEO, | 113 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 114 | .p.id = AV_CODEC_ID_FLV1, | 114 | .p.id = AV_CODEC_ID_FLV1, |
| 115 | .priv_data_size = sizeof(MpegEncContext), | 115 | .priv_data_size = sizeof(H263DecContext), |
| 116 | .init = ff_h263_decode_init, | 116 | .init = ff_h263_decode_init, |
| 117 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), | 117 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 118 | .close = ff_mpv_decode_close, | 118 | .close = ff_mpv_decode_close, |
| @@ -21,8 +21,8 @@ · 20 unmodified lines | |||
| 21 | #ifndef AVCODEC_FLVDEC_H | 21 | #ifndef AVCODEC_FLVDEC_H |
| 22 | #define AVCODEC_FLVDEC_H | 22 | #define AVCODEC_FLVDEC_H |
| 23 | 23 | ||
| 24 | #include "mpegvideo.h" | 24 | struct H263DecContext; |
| 25 | 25 | ||
| 26 | int ff_flv_decode_picture_header(MpegEncContext *s); | 26 | int ff_flv_decode_picture_header(struct H263DecContext *const h); |
| 27 | 27 | ||
| 28 | #endif /* AVCODEC_FLVDEC_H */ | 28 | #endif /* AVCODEC_FLVDEC_H */ |
| @@ -90,7 +90,8 @@ static enum AVPixelFormat h263_get_format(AVCodecContext *avctx) · 89 unmodified lines | |||
| 90 | 90 | ||
| 91 | av_cold int ff_h263_decode_init(AVCodecContext *avctx) | 91 | av_cold int ff_h263_decode_init(AVCodecContext *avctx) |
| 92 | { | 92 | { |
| 93 | MpegEncContext *s = avctx->priv_data; | 93 | H263DecContext *const h = avctx->priv_data; |
| 94 | MPVContext *const s = &h->c; | ||
| 94 | MPVUnquantDSPContext unquant_dsp_ctx; | 95 | MPVUnquantDSPContext unquant_dsp_ctx; |
| 95 | int ret; | 96 | int ret; |
| 96 | 97 | ||
| @@ -101,7 +102,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) · 4 unmodified lines | |||
| 101 | if (ret < 0) | 102 | if (ret < 0) |
| 102 | return ret; | 103 | return ret; |
| 103 | 104 | ||
| 104 | s->decode_mb = ff_h263_decode_mb; | 105 | h->decode_mb = ff_h263_decode_mb; |
| 105 | s->low_delay = 1; | 106 | s->low_delay = 1; |
| 106 | 107 | ||
| 107 | s->y_dc_scale_table = | 108 | s->y_dc_scale_table = |
| @@ -179,239 +180,239 @@ static void report_decode_progress(MpegEncContext *s) · 71 unmodified lines | |||
| 179 | ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y); | 180 | ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y); |
| 180 | } | 181 | } |
| 181 | 182 | ||
| 182 | static int decode_slice(MpegEncContext *s) | 183 | static int decode_slice(H263DecContext *const h) |
| 183 | { | 184 | { |
| 184 | const int part_mask = s->partitioned_frame | 185 | const int part_mask = h->c.partitioned_frame |
| 185 | ? (ER_AC_END | ER_AC_ERROR) : 0x7F; | 186 | ? (ER_AC_END | ER_AC_ERROR) : 0x7F; |
| 186 | const int mb_size = 16 >> s->avctx->lowres; | 187 | const int mb_size = 16 >> h->c.avctx->lowres; |
| 187 | int ret; | 188 | int ret; |
| 188 | 189 | ||
| 189 | s->last_resync_gb = s->gb; | 190 | h->c.last_resync_gb = h->c.gb; |
| 190 | s->first_slice_line = 1; | 191 | h->c.first_slice_line = 1; |
| 191 | s->resync_mb_x = s->mb_x; | 192 | h->c.resync_mb_x = h->c.mb_x; |
| 192 | s->resync_mb_y = s->mb_y; | 193 | h->c.resync_mb_y = h->c.mb_y; |
| 193 | 194 | ||
| 194 | ff_set_qscale(s, s->qscale); | 195 | ff_set_qscale(&h->c, h->c.qscale); |
| 195 | 196 | ||
| 196 | if (s->studio_profile) { | 197 | if (h->c.studio_profile) { |
| 197 | if ((ret = ff_mpeg4_decode_studio_slice_header(s)) < 0) | 198 | if ((ret = ff_mpeg4_decode_studio_slice_header(h)) < 0) |
| 198 | return ret; | 199 | return ret; |
| 199 | } | 200 | } |
| 200 | 201 | ||
| 201 | if (s->avctx->hwaccel) { | 202 | if (h->c.avctx->hwaccel) { |
| 202 | const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8; | 203 | const uint8_t *start = h->c.gb.buffer + get_bits_count(&h->c.gb) / 8; |
| 203 | ret = FF_HW_CALL(s->avctx, decode_slice, start, s->gb.buffer_end - start); | 204 | ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->c.gb.buffer_end - start); |
| 204 | // ensure we exit decode loop | 205 | // ensure we exit decode loop |
| 205 | s->mb_y = s->mb_height; | 206 | h->c.mb_y = h->c.mb_height; |
| 206 | return ret; | 207 | return ret; |
| 207 | } | 208 | } |
| 208 | 209 | ||
| 209 | if (s->partitioned_frame) { | 210 | if (h->c.partitioned_frame) { |
| 210 | const int qscale = s->qscale; | 211 | const int qscale = h->c.qscale; |
| 211 | 212 | ||
| 212 | if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4) | 213 | if (CONFIG_MPEG4_DECODER && h->c.codec_id == AV_CODEC_ID_MPEG4) |
| 213 | if ((ret = ff_mpeg4_decode_partitions(s)) < 0) | 214 | if ((ret = ff_mpeg4_decode_partitions(h)) < 0) |
| 214 | return ret; | 215 | return ret; |
| 215 | 216 | ||
| 216 | /* restore variables which were modified */ | 217 | /* restore variables which were modified */ |
| 217 | s->first_slice_line = 1; | 218 | h->c.first_slice_line = 1; |
| 218 | s->mb_x = s->resync_mb_x; | 219 | h->c.mb_x = h->c.resync_mb_x; |
| 219 | s->mb_y = s->resync_mb_y; | 220 | h->c.mb_y = h->c.resync_mb_y; |
| 220 | ff_set_qscale(s, qscale); | 221 | ff_set_qscale(&h->c, qscale); |
| 221 | } | 222 | } |
| 222 | 223 | ||
| 223 | for (; s->mb_y < s->mb_height; s->mb_y++) { | 224 | for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) { |
| 224 | /* per-row end of slice checks */ | 225 | /* per-row end of slice checks */ |
| 225 | if (s->msmpeg4_version != MSMP4_UNUSED) { | 226 | if (h->c.msmpeg4_version != MSMP4_UNUSED) { |
| 226 | if (s->resync_mb_y + s->slice_height == s->mb_y) { | 227 | if (h->c.resync_mb_y + h->c.slice_height == h->c.mb_y) { |
| 227 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 228 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 228 | s->mb_x - 1, s->mb_y, ER_MB_END); | 229 | h->c.mb_x - 1, h->c.mb_y, ER_MB_END); |
| 229 | 230 | ||
| 230 | return 0; | 231 | return 0; |
| 231 | } | 232 | } |
| 232 | } | 233 | } |
| 233 | 234 | ||
| 234 | if (s->msmpeg4_version == MSMP4_V1) { | 235 | if (h->c.msmpeg4_version == MSMP4_V1) { |
| 235 | s->last_dc[0] = | 236 | h->c.last_dc[0] = |
| 236 | s->last_dc[1] = | 237 | h->c.last_dc[1] = |
| 237 | s->last_dc[2] = 128; | 238 | h->c.last_dc[2] = 128; |
| 238 | } | 239 | } |
| 239 | 240 | ||
| 240 | ff_init_block_index(s); | 241 | ff_init_block_index(&h->c); |
| 241 | for (; s->mb_x < s->mb_width; s->mb_x++) { | 242 | for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) { |
| 242 | int ret; | 243 | int ret; |
| 243 | 244 | ||
| 244 | ff_update_block_index(s, s->avctx->bits_per_raw_sample, | 245 | ff_update_block_index(&h->c, h->c.avctx->bits_per_raw_sample, |
| 245 | s->avctx->lowres, s->chroma_x_shift); | 246 | h->c.avctx->lowres, h->c.chroma_x_shift); |
| 246 | 247 | ||
| 247 | if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y) | 248 | if (h->c.resync_mb_x == h->c.mb_x && h->c.resync_mb_y + 1 == h->c.mb_y) |
| 248 | s->first_slice_line = 0; | 249 | h->c.first_slice_line = 0; |
| 249 | 250 | ||
| 250 | /* DCT & quantize */ | 251 | /* DCT & quantize */ |
| 251 | 252 | ||
| 252 | s->mv_dir = MV_DIR_FORWARD; | 253 | h->c.mv_dir = MV_DIR_FORWARD; |
| 253 | s->mv_type = MV_TYPE_16X16; | 254 | h->c.mv_type = MV_TYPE_16X16; |
| 254 | ff_dlog(s->avctx, "%d %06X\n", | 255 | ff_dlog(h->c.avctx, "%d %06X\n", |
| 255 | get_bits_count(&s->gb), show_bits(&s->gb, 24)); | 256 | get_bits_count(&h->c.gb), show_bits(&h->c.gb, 24)); |
| 256 | 257 | ||
| 257 | ff_tlog(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y); | 258 | ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y); |
| 258 | ret = s->decode_mb(s, s->block); | 259 | ret = h->decode_mb(h, h->c.block); |
| 259 | 260 | ||
| 260 | if (s->h263_pred || s->h263_aic) { | 261 | if (h->c.h263_pred || h->c.h263_aic) { |
| 261 | int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | 262 | int mb_xy = h->c.mb_y * h->c.mb_stride + h->c.mb_x; |
| 262 | if (!s->mb_intra) { | 263 | if (!h->c.mb_intra) { |
| 263 | ff_h263_clean_intra_table_entries(s, mb_xy); | 264 | ff_h263_clean_intra_table_entries(&h->c, mb_xy); |
| 264 | } else | 265 | } else |
| 265 | s->mbintra_table[mb_xy] = 1; | 266 | h->c.mbintra_table[mb_xy] = 1; |
| 266 | } | 267 | } |
| 267 | 268 | ||
| 268 | if (s->pict_type != AV_PICTURE_TYPE_B) | 269 | if (h->c.pict_type != AV_PICTURE_TYPE_B) |
| 269 | ff_h263_update_motion_val(s); | 270 | ff_h263_update_motion_val(&h->c); |
| 270 | 271 | ||
| 271 | if (ret < 0) { | 272 | if (ret < 0) { |
| 272 | const int xy = s->mb_x + s->mb_y * s->mb_stride; | 273 | const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; |
| 273 | if (ret == SLICE_END) { | 274 | if (ret == SLICE_END) { |
| 274 | ff_mpv_reconstruct_mb(s, s->block); | 275 | ff_mpv_reconstruct_mb(&h->c, h->c.block); |
| 275 | if (s->loop_filter) | 276 | if (h->c.loop_filter) |
| 276 | ff_h263_loop_filter(s); | 277 | ff_h263_loop_filter(&h->c); |
| 277 | 278 | ||
| 278 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 279 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 279 | s->mb_x, s->mb_y, ER_MB_END & part_mask); | 280 | h->c.mb_x, h->c.mb_y, ER_MB_END & part_mask); |
| 280 | 281 | ||
| 281 | s->padding_bug_score--; | 282 | h->c.padding_bug_score--; |
| 282 | 283 | ||
| 283 | if (++s->mb_x >= s->mb_width) { | 284 | if (++h->c.mb_x >= h->c.mb_width) { |
| 284 | s->mb_x = 0; | 285 | h->c.mb_x = 0; |
| 285 | report_decode_progress(s); | 286 | report_decode_progress(&h->c); |
| 286 | ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size); | 287 | ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size); |
| 287 | s->mb_y++; | 288 | h->c.mb_y++; |
| 288 | } | 289 | } |
| 289 | return 0; | 290 | return 0; |
| 290 | } else if (ret == SLICE_NOEND) { | 291 | } else if (ret == SLICE_NOEND) { |
| 291 | av_log(s->avctx, AV_LOG_ERROR, | 292 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 292 | "Slice mismatch at MB: %d\n", xy); | 293 | "Slice mismatch at MB: %d\n", xy); |
| 293 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 294 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 294 | s->mb_x + 1, s->mb_y, | 295 | h->c.mb_x + 1, h->c.mb_y, |
| 295 | ER_MB_END & part_mask); | 296 | ER_MB_END & part_mask); |
| 296 | return AVERROR_INVALIDDATA; | 297 | return AVERROR_INVALIDDATA; |
| 297 | } | 298 | } |
| 298 | av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); | 299 | av_log(h->c.avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); |
| 299 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 300 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 300 | s->mb_x, s->mb_y, ER_MB_ERROR & part_mask); | 301 | h->c.mb_x, h->c.mb_y, ER_MB_ERROR & part_mask); |
| 301 | 302 | ||
| 302 | if ((s->avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&s->gb) > 0) | 303 | if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->c.gb) > 0) |
| 303 | continue; | 304 | continue; |
| 304 | return AVERROR_INVALIDDATA; | 305 | return AVERROR_INVALIDDATA; |
| 305 | } | 306 | } |
| 306 | 307 | ||
| 307 | ff_mpv_reconstruct_mb(s, s->block); | 308 | ff_mpv_reconstruct_mb(&h->c, h->c.block); |
| 308 | if (s->loop_filter) | 309 | if (h->c.loop_filter) |
| 309 | ff_h263_loop_filter(s); | 310 | ff_h263_loop_filter(&h->c); |
| 310 | } | 311 | } |
| 311 | 312 | ||
| 312 | report_decode_progress(s); | 313 | report_decode_progress(&h->c); |
| 313 | ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size); | 314 | ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size); |
| 314 | 315 | ||
| 315 | s->mb_x = 0; | 316 | h->c.mb_x = 0; |
| 316 | } | 317 | } |
| 317 | 318 | ||
| 318 | av_assert1(s->mb_x == 0 && s->mb_y == s->mb_height); | 319 | av_assert1(h->c.mb_x == 0 && h->c.mb_y == h->c.mb_height); |
| 319 | 320 | ||
| 320 | // Detect incorrect padding with wrong stuffing codes used by NEC N-02B | 321 | // Detect incorrect padding with wrong stuffing codes used by NEC N-02B |
| 321 | if (s->codec_id == AV_CODEC_ID_MPEG4 && | 322 | if (h->c.codec_id == AV_CODEC_ID_MPEG4 && |
| 322 | (s->workaround_bugs & FF_BUG_AUTODETECT) && | 323 | (h->c.workaround_bugs & FF_BUG_AUTODETECT) && |
| 323 | get_bits_left(&s->gb) >= 48 && | 324 | get_bits_left(&h->c.gb) >= 48 && |
| 324 | show_bits(&s->gb, 24) == 0x4010 && | 325 | show_bits(&h->c.gb, 24) == 0x4010 && |
| 325 | !s->data_partitioning) | 326 | !h->c.data_partitioning) |
| 326 | s->padding_bug_score += 32; | 327 | h->c.padding_bug_score += 32; |
| 327 | 328 | ||
| 328 | /* try to detect the padding bug */ | 329 | /* try to detect the padding bug */ |
| 329 | if (s->codec_id == AV_CODEC_ID_MPEG4 && | 330 | if (h->c.codec_id == AV_CODEC_ID_MPEG4 && |
| 330 | (s->workaround_bugs & FF_BUG_AUTODETECT) && | 331 | (h->c.workaround_bugs & FF_BUG_AUTODETECT) && |
| 331 | get_bits_left(&s->gb) >= 0 && | 332 | get_bits_left(&h->c.gb) >= 0 && |
| 332 | get_bits_left(&s->gb) < 137 && | 333 | get_bits_left(&h->c.gb) < 137 && |
| 333 | !s->data_partitioning) { | 334 | !h->c.data_partitioning) { |
| 334 | const int bits_count = get_bits_count(&s->gb); | 335 | const int bits_count = get_bits_count(&h->c.gb); |
| 335 | const int bits_left = s->gb.size_in_bits - bits_count; | 336 | const int bits_left = h->c.gb.size_in_bits - bits_count; |
| 336 | 337 | ||
| 337 | if (bits_left == 0) { | 338 | if (bits_left == 0) { |
| 338 | s->padding_bug_score += 16; | 339 | h->c.padding_bug_score += 16; |
| 339 | } else if (bits_left != 1) { | 340 | } else if (bits_left != 1) { |
| 340 | int v = show_bits(&s->gb, 8); | 341 | int v = show_bits(&h->c.gb, 8); |
| 341 | v |= 0x7F >> (7 - (bits_count & 7)); | 342 | v |= 0x7F >> (7 - (bits_count & 7)); |
| 342 | 343 | ||
| 343 | if (v == 0x7F && bits_left <= 8) | 344 | if (v == 0x7F && bits_left <= 8) |
| 344 | s->padding_bug_score--; | 345 | h->c.padding_bug_score--; |
| 345 | else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) && | 346 | else if (v == 0x7F && ((get_bits_count(&h->c.gb) + 8) & 8) && |
| 346 | bits_left <= 16) | 347 | bits_left <= 16) |
| 347 | s->padding_bug_score += 4; | 348 | h->c.padding_bug_score += 4; |
| 348 | else | 349 | else |
| 349 | s->padding_bug_score++; | 350 | h->c.padding_bug_score++; |
| 350 | } | 351 | } |
| 351 | } | 352 | } |
| 352 | 353 | ||
| 353 | if (s->codec_id == AV_CODEC_ID_H263 && | 354 | if (h->c.codec_id == AV_CODEC_ID_H263 && |
| 354 | (s->workaround_bugs & FF_BUG_AUTODETECT) && | 355 | (h->c.workaround_bugs & FF_BUG_AUTODETECT) && |
| 355 | get_bits_left(&s->gb) >= 8 && | 356 | get_bits_left(&h->c.gb) >= 8 && |
| 356 | get_bits_left(&s->gb) < 300 && | 357 | get_bits_left(&h->c.gb) < 300 && |
| 357 | s->pict_type == AV_PICTURE_TYPE_I && | 358 | h->c.pict_type == AV_PICTURE_TYPE_I && |
| 358 | show_bits(&s->gb, 8) == 0 && | 359 | show_bits(&h->c.gb, 8) == 0 && |
| 359 | !s->data_partitioning) { | 360 | !h->c.data_partitioning) { |
| 360 | 361 | ||
| 361 | s->padding_bug_score += 32; | 362 | h->c.padding_bug_score += 32; |
| 362 | } | 363 | } |
| 363 | 364 | ||
| 364 | if (s->codec_id == AV_CODEC_ID_H263 && | 365 | if (h->c.codec_id == AV_CODEC_ID_H263 && |
| 365 | (s->workaround_bugs & FF_BUG_AUTODETECT) && | 366 | (h->c.workaround_bugs & FF_BUG_AUTODETECT) && |
| 366 | get_bits_left(&s->gb) >= 64 && | 367 | get_bits_left(&h->c.gb) >= 64 && |
| 367 | AV_RB64(s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) { | 368 | AV_RB64(h->c.gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) { |
| 368 | 369 | ||
| 369 | s->padding_bug_score += 32; | 370 | h->c.padding_bug_score += 32; |
| 370 | } | 371 | } |
| 371 | 372 | ||
| 372 | if (s->workaround_bugs & FF_BUG_AUTODETECT) { | 373 | if (h->c.workaround_bugs & FF_BUG_AUTODETECT) { |
| 373 | if ( | 374 | if ( |
| 374 | (s->padding_bug_score > -2 && !s->data_partitioning)) | 375 | (h->c.padding_bug_score > -2 && !h->c.data_partitioning)) |
| 375 | s->workaround_bugs |= FF_BUG_NO_PADDING; | 376 | h->c.workaround_bugs |= FF_BUG_NO_PADDING; |
| 376 | else | 377 | else |
| 377 | s->workaround_bugs &= ~FF_BUG_NO_PADDING; | 378 | h->c.workaround_bugs &= ~FF_BUG_NO_PADDING; |
| 378 | } | 379 | } |
| 379 | 380 | ||
| 380 | // handle formats which don't have unique end markers | 381 | // handle formats which don't have unique end markers |
| 381 | if (s->msmpeg4_version != MSMP4_UNUSED || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly | 382 | if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly |
| 382 | int left = get_bits_left(&s->gb); | 383 | int left = get_bits_left(&h->c.gb); |
| 383 | int max_extra = 7; | 384 | int max_extra = 7; |
| 384 | 385 | ||
| 385 | /* no markers in M$ crap */ | 386 | /* no markers in M$ crap */ |
| 386 | if (s->msmpeg4_version != MSMP4_UNUSED && s->pict_type == AV_PICTURE_TYPE_I) | 387 | if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.pict_type == AV_PICTURE_TYPE_I) |
| 387 | max_extra += 17; | 388 | max_extra += 17; |
| 388 | 389 | ||
| 389 | /* buggy padding but the frame should still end approximately at | 390 | /* buggy padding but the frame should still end approximately at |
| 390 | * the bitstream end */ | 391 | * the bitstream end */ |
| 391 | if ((s->workaround_bugs & FF_BUG_NO_PADDING) && | 392 | if ((h->c.workaround_bugs & FF_BUG_NO_PADDING) && |
| 392 | (s->avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) | 393 | (h->c.avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) |
| 393 | max_extra += 48; | 394 | max_extra += 48; |
| 394 | else if ((s->workaround_bugs & FF_BUG_NO_PADDING)) | 395 | else if ((h->c.workaround_bugs & FF_BUG_NO_PADDING)) |
| 395 | max_extra += 256 * 256 * 256 * 64; | 396 | max_extra += 256 * 256 * 256 * 64; |
| 396 | 397 | ||
| 397 | if (left > max_extra) | 398 | if (left > max_extra) |
| 398 | av_log(s->avctx, AV_LOG_ERROR, | 399 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 399 | "discarding %d junk bits at end, next would be %X\n", | 400 | "discarding %d junk bits at end, next would be %X\n", |
| 400 | left, show_bits(&s->gb, 24)); | 401 | left, show_bits(&h->c.gb, 24)); |
| 401 | else if (left < 0) | 402 | else if (left < 0) |
| 402 | av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left); | 403 | av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left); |
| 403 | else | 404 | else |
| 404 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 405 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 405 | s->mb_x - 1, s->mb_y, ER_MB_END); | 406 | h->c.mb_x - 1, h->c.mb_y, ER_MB_END); |
| 406 | 407 | ||
| 407 | return 0; | 408 | return 0; |
| 408 | } | 409 | } |
| 409 | 410 | ||
| 410 | av_log(s->avctx, AV_LOG_ERROR, | 411 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 411 | "slice end not reached but screenspace end (%d left %06X, score= %d)\n", | 412 | "slice end not reached but screenspace end (%d left %06X, score= %d)\n", |
| 412 | get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score); | 413 | get_bits_left(&h->c.gb), show_bits(&h->c.gb, 24), h->c.padding_bug_score); |
| 413 | 414 | ||
| 414 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, | 415 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, h->c.mb_x, h->c.mb_y, |
| 415 | ER_MB_END & part_mask); | 416 | ER_MB_END & part_mask); |
| 416 | 417 | ||
| 417 | return AVERROR_INVALIDDATA; | 418 | return AVERROR_INVALIDDATA; |
| @@ -420,9 +421,10 @@ static int decode_slice(MpegEncContext *s) · 2 unmodified lines | |||
| 420 | int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, | 421 | int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, |
| 421 | int *got_frame, AVPacket *avpkt) | 422 | int *got_frame, AVPacket *avpkt) |
| 422 | { | 423 | { |
| 424 | H263DecContext *const h = avctx->priv_data; | ||
| 425 | MPVContext *const s = &h->c; | ||
| 423 | const uint8_t *buf = avpkt->data; | 426 | const uint8_t *buf = avpkt->data; |
| 424 | int buf_size = avpkt->size; | 427 | int buf_size = avpkt->size; |
| 425 | MpegEncContext *s = avctx->priv_data; | ||
| 426 | int ret; | 428 | int ret; |
| 427 | int slice_ret = 0; | 429 | int slice_ret = 0; |
| 428 | int bak_width, bak_height; | 430 | int bak_width, bak_height; |
| @@ -430,10 +432,10 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1 unmodified line | |||
| 430 | /* no supplementary picture */ | 432 | /* no supplementary picture */ |
| 431 | if (buf_size == 0) { | 433 | if (buf_size == 0) { |
| 432 | /* special case for last picture */ | 434 | /* special case for last picture */ |
| 433 | if ((!s->low_delay || s->skipped_last_frame) && s->next_pic.ptr) { | 435 | if ((!h->c.low_delay || h->c.skipped_last_frame) && h->c.next_pic.ptr) { |
| 434 | if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0) | 436 | if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0) |
| 435 | return ret; | 437 | return ret; |
| 436 | if (s->skipped_last_frame) { | 438 | if (h->c.skipped_last_frame) { |
| 437 | /* If the stream ended with an NVOP, we output the last frame | 439 | /* If the stream ended with an NVOP, we output the last frame |
| 438 | * in display order, but with the props from the last input | 440 | * in display order, but with the props from the last input |
| 439 | * packet so that the stream's end time is correct. */ | 441 | * packet so that the stream's end time is correct. */ |
| @@ -442,7 +444,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 2 unmodified lines | |||
| 442 | return ret; | 444 | return ret; |
| 443 | } | 445 | } |
| 444 | 446 | ||
| 445 | ff_mpv_unref_picture(&s->next_pic); | 447 | ff_mpv_unref_picture(&h->c.next_pic); |
| 446 | 448 | ||
| 447 | *got_frame = 1; | 449 | *got_frame = 1; |
| 448 | } | 450 | } |
| @@ -450,37 +452,37 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1 unmodified line | |||
| 450 | return 0; | 452 | return 0; |
| 451 | } | 453 | } |
| 452 | 454 | ||
| 453 | // s->gb might be overridden in ff_mpeg4_decode_picture_header() below. | 455 | // h->c.gb might be overridden in ff_mpeg4_decode_picture_header() below. |
| 454 | ret = init_get_bits8(&s->gb, buf, buf_size); | 456 | ret = init_get_bits8(&h->c.gb, buf, buf_size); |
| 455 | if (ret < 0) | 457 | if (ret < 0) |
| 456 | return ret; | 458 | return ret; |
| 457 | 459 | ||
| 458 | bak_width = s->width; | 460 | bak_width = h->c.width; |
| 459 | bak_height = s->height; | 461 | bak_height = h->c.height; |
| 460 | 462 | ||
| 461 | /* let's go :-) */ | 463 | /* let's go :-) */ |
| 462 | if (CONFIG_WMV2_DECODER && s->msmpeg4_version == MSMP4_WMV2) { | 464 | if (CONFIG_WMV2_DECODER && h->c.msmpeg4_version == MSMP4_WMV2) { |
| 463 | ret = ff_wmv2_decode_picture_header(s); | 465 | ret = ff_wmv2_decode_picture_header(h); |
| 464 | #if CONFIG_MSMPEG4DEC | 466 | #if CONFIG_MSMPEG4DEC |
| 465 | } else if (s->msmpeg4_version != MSMP4_UNUSED) { | 467 | } else if (h->c.msmpeg4_version != MSMP4_UNUSED) { |
| 466 | ret = ff_msmpeg4_decode_picture_header(s); | 468 | ret = ff_msmpeg4_decode_picture_header(h); |
| 467 | #endif | 469 | #endif |
| 468 | } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) { | 470 | } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) { |
| 469 | ret = ff_mpeg4_decode_picture_header(s); | 471 | ret = ff_mpeg4_decode_picture_header(h); |
| 470 | } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) { | 472 | } else if (CONFIG_H263I_DECODER && h->c.codec_id == AV_CODEC_ID_H263I) { |
| 471 | ret = ff_intel_h263_decode_picture_header(s); | 473 | ret = ff_intel_h263_decode_picture_header(h); |
| 472 | } else if (CONFIG_FLV_DECODER && s->h263_flv) { | 474 | } else if (CONFIG_FLV_DECODER && h->c.h263_flv) { |
| 473 | ret = ff_flv_decode_picture_header(s); | 475 | ret = ff_flv_decode_picture_header(h); |
| 474 | } else { | 476 | } else { |
| 475 | ret = ff_h263_decode_picture_header(s); | 477 | ret = ff_h263_decode_picture_header(h); |
| 476 | } | 478 | } |
| 477 | 479 | ||
| 478 | if (ret < 0 || ret == FRAME_SKIPPED) { | 480 | if (ret < 0 || ret == FRAME_SKIPPED) { |
| 479 | if ( s->width != bak_width | 481 | if ( h->c.width != bak_width |
| 480 | || s->height != bak_height) { | 482 | || h->c.height != bak_height) { |
| 481 | av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n"); | 483 | av_log(h->c.avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n"); |
| 482 | s->width = bak_width; | 484 | h->c.width = bak_width; |
| 483 | s->height= bak_height; | 485 | h->c.height= bak_height; |
| 484 | 486 | ||
| 485 | } | 487 | } |
| 486 | } | 488 | } |
| @@ -489,37 +491,35 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 2 unmodified lines | |||
| 489 | 491 | ||
| 490 | /* skip if the header was thrashed */ | 492 | /* skip if the header was thrashed */ |
| 491 | if (ret < 0) { | 493 | if (ret < 0) { |
| 492 | av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); | 494 | av_log(h->c.avctx, AV_LOG_ERROR, "header damaged\n"); |
| 493 | return ret; | 495 | return ret; |
| 494 | } | 496 | } |
| 495 | 497 | ||
| 496 | if (!s->context_initialized) { | 498 | if (!h->c.context_initialized) { |
| 497 | avctx->pix_fmt = h263_get_format(avctx); | 499 | avctx->pix_fmt = h263_get_format(avctx); |
| 498 | if ((ret = ff_mpv_common_init(s)) < 0) | 500 | if ((ret = ff_mpv_common_init(s)) < 0) |
| 499 | return ret; | 501 | return ret; |
| 500 | } | 502 | } |
| 501 | 503 | ||
| 502 | avctx->has_b_frames = !s->low_delay; | 504 | avctx->has_b_frames = !h->c.low_delay; |
| 503 | 505 | ||
| 504 | if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) { | 506 | if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) { |
| 505 | if (s->pict_type != AV_PICTURE_TYPE_B && s->mb_num/2 > get_bits_left(&s->gb)) | 507 | if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->c.gb)) |
| 506 | return AVERROR_INVALIDDATA; | 508 | return AVERROR_INVALIDDATA; |
| 507 | ff_mpeg4_workaround_bugs(avctx); | 509 | ff_mpeg4_workaround_bugs(avctx); |
| 508 | if (s->studio_profile != (s->idsp.idct == NULL)) | 510 | if (h->c.studio_profile != (h->c.idsp.idct == NULL)) |
| 509 | ff_mpv_idct_init(s); | 511 | ff_mpv_idct_init(s); |
| 510 | } | 512 | } |
| 511 | 513 | ||
| 512 | /* After H.263 & MPEG-4 header decode we have the height, width, | 514 | /* After H.263 & MPEG-4 header decode we have the height, width, |
| 513 | * and other parameters. So then we could init the picture. | 515 | * and other parameters. So then we could init the picture. */ |
| 514 | * FIXME: By the way H.263 decoder is evolving it should have | 516 | if (h->c.width != avctx->coded_width || |
| 515 | * an H263EncContext */ | 517 | h->c.height != avctx->coded_height || |
| 516 | if (s->width != avctx->coded_width || | 518 | h->c.context_reinit) { |
| 517 | s->height != avctx->coded_height || | ||
| 518 | s->context_reinit) { | ||
| 519 | /* H.263 could change picture size any time */ | 519 | /* H.263 could change picture size any time */ |
| 520 | s->context_reinit = 0; | 520 | h->c.context_reinit = 0; |
| 521 | 521 | ||
| 522 | ret = ff_set_dimensions(avctx, s->width, s->height); | 522 | ret = ff_set_dimensions(avctx, h->c.width, h->c.height); |
| 523 | if (ret < 0) | 523 | if (ret < 0) |
| 524 | return ret; | 524 | return ret; |
| 525 | 525 | ||
| @@ -536,25 +536,25 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 10 unmodified lines | |||
| 536 | } | 536 | } |
| 537 | 537 | ||
| 538 | /* skip B-frames if we don't have reference frames */ | 538 | /* skip B-frames if we don't have reference frames */ |
| 539 | if (!s->last_pic.ptr && | 539 | if (!h->c.last_pic.ptr && |
| 540 | (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) | 540 | (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.droppable)) |
| 541 | return buf_size; | 541 | return buf_size; |
| 542 | if ((avctx->skip_frame >= AVDISCARD_NONREF && | 542 | if ((avctx->skip_frame >= AVDISCARD_NONREF && |
| 543 | s->pict_type == AV_PICTURE_TYPE_B) || | 543 | h->c.pict_type == AV_PICTURE_TYPE_B) || |
| 544 | (avctx->skip_frame >= AVDISCARD_NONKEY && | 544 | (avctx->skip_frame >= AVDISCARD_NONKEY && |
| 545 | s->pict_type != AV_PICTURE_TYPE_I) || | 545 | h->c.pict_type != AV_PICTURE_TYPE_I) || |
| 546 | avctx->skip_frame >= AVDISCARD_ALL) | 546 | avctx->skip_frame >= AVDISCARD_ALL) |
| 547 | return buf_size; | 547 | return buf_size; |
| 548 | 548 | ||
| 549 | if ((ret = ff_mpv_frame_start(s, avctx)) < 0) | 549 | if ((ret = ff_mpv_frame_start(s, avctx)) < 0) |
| 550 | return ret; | 550 | return ret; |
| 551 | 551 | ||
| 552 | if (!s->divx_packed) | 552 | if (!h->c.divx_packed) |
| 553 | ff_thread_finish_setup(avctx); | 553 | ff_thread_finish_setup(avctx); |
| 554 | 554 | ||
| 555 | if (avctx->hwaccel) { | 555 | if (avctx->hwaccel) { |
| 556 | ret = FF_HW_CALL(avctx, start_frame, NULL, | 556 | ret = FF_HW_CALL(avctx, start_frame, NULL, |
| 557 | s->gb.buffer, s->gb.buffer_end - s->gb.buffer); | 557 | h->c.gb.buffer, h->c.gb.buffer_end - h->c.gb.buffer); |
| 558 | if (ret < 0 ) | 558 | if (ret < 0 ) |
| 559 | return ret; | 559 | return ret; |
| 560 | } | 560 | } |
| @@ -565,8 +565,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 4 unmodified lines | |||
| 565 | * are stored in current_picture->mb_type which is not available before | 565 | * are stored in current_picture->mb_type which is not available before |
| 566 | * ff_mpv_frame_start() */ | 566 | * ff_mpv_frame_start() */ |
| 567 | #if CONFIG_WMV2_DECODER | 567 | #if CONFIG_WMV2_DECODER |
| 568 | if (s->msmpeg4_version == MSMP4_WMV2) { | 568 | if (h->c.msmpeg4_version == MSMP4_WMV2) { |
| 569 | ret = ff_wmv2_decode_secondary_picture_header(s); | 569 | ret = ff_wmv2_decode_secondary_picture_header(h); |
| 570 | if (ret < 0) | 570 | if (ret < 0) |
| 571 | return ret; | 571 | return ret; |
| 572 | if (ret == 1) | 572 | if (ret == 1) |
| @@ -575,39 +575,39 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 2 unmodified lines | |||
| 575 | #endif | 575 | #endif |
| 576 | 576 | ||
| 577 | /* decode each macroblock */ | 577 | /* decode each macroblock */ |
| 578 | s->mb_x = 0; | 578 | h->c.mb_x = 0; |
| 579 | s->mb_y = 0; | 579 | h->c.mb_y = 0; |
| 580 | 580 | ||
| 581 | slice_ret = decode_slice(s); | 581 | slice_ret = decode_slice(h); |
| 582 | while (s->mb_y < s->mb_height) { | 582 | while (h->c.mb_y < h->c.mb_height) { |
| 583 | if (s->msmpeg4_version != MSMP4_UNUSED) { | 583 | if (h->c.msmpeg4_version != MSMP4_UNUSED) { |
| 584 | if (s->slice_height == 0 || s->mb_x != 0 || slice_ret < 0 || | 584 | if (h->c.slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 || |
| 585 | (s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0) | 585 | (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->c.gb) < 0) |
| 586 | break; | 586 | break; |
| 587 | } else { | 587 | } else { |
| 588 | int prev_x = s->mb_x, prev_y = s->mb_y; | 588 | int prev_x = h->c.mb_x, prev_y = h->c.mb_y; |
| 589 | if (ff_h263_resync(s) < 0) | 589 | if (ff_h263_resync(h) < 0) |
| 590 | break; | 590 | break; |
| 591 | if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x) | 591 | if (prev_y * h->c.mb_width + prev_x < h->c.mb_y * h->c.mb_width + h->c.mb_x) |
| 592 | s->er.error_occurred = 1; | 592 | h->c.er.error_occurred = 1; |
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | if (s->msmpeg4_version < MSMP4_WMV1 && s->h263_pred) | 595 | if (h->c.msmpeg4_version < MSMP4_WMV1 && h->c.h263_pred) |
| 596 | ff_mpeg4_clean_buffers(s); | 596 | ff_mpeg4_clean_buffers(s); |
| 597 | 597 | ||
| 598 | if (decode_slice(s) < 0) | 598 | if (decode_slice(h) < 0) |
| 599 | slice_ret = AVERROR_INVALIDDATA; | 599 | slice_ret = AVERROR_INVALIDDATA; |
| 600 | } | 600 | } |
| 601 | 601 | ||
| 602 | if (s->msmpeg4_version != MSMP4_UNUSED && s->msmpeg4_version < MSMP4_WMV1 && | 602 | if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.msmpeg4_version < MSMP4_WMV1 && |
| 603 | s->pict_type == AV_PICTURE_TYPE_I) | 603 | h->c.pict_type == AV_PICTURE_TYPE_I) |
| 604 | if (!CONFIG_MSMPEG4DEC || | 604 | if (!CONFIG_MSMPEG4DEC || |
| 605 | ff_msmpeg4_decode_ext_header(s, buf_size) < 0) | 605 | ff_msmpeg4_decode_ext_header(h, buf_size) < 0) |
| 606 | s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR; | 606 | h->c.er.error_status_table[h->c.mb_num - 1] = ER_MB_ERROR; |
| 607 | 607 | ||
| 608 | frame_end: | 608 | frame_end: |
| 609 | if (!s->studio_profile) | 609 | if (!h->c.studio_profile) |
| 610 | ff_er_frame_end(&s->er, NULL); | 610 | ff_er_frame_end(&h->c.er, NULL); |
| 611 | 611 | ||
| 612 | if (avctx->hwaccel) { | 612 | if (avctx->hwaccel) { |
| 613 | ret = FF_HW_SIMPLE_CALL(avctx, end_frame); | 613 | ret = FF_HW_SIMPLE_CALL(avctx, end_frame); |
| @@ -620,22 +620,22 @@ frame_end: · 6 unmodified lines | |||
| 620 | if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) | 620 | if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) |
| 621 | ff_mpeg4_frame_end(avctx, avpkt); | 621 | ff_mpeg4_frame_end(avctx, avpkt); |
| 622 | 622 | ||
| 623 | av_assert1(s->pict_type == s->cur_pic.ptr->f->pict_type); | 623 | av_assert1(h->c.pict_type == h->c.cur_pic.ptr->f->pict_type); |
| 624 | if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { | 624 | if (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.low_delay) { |
| 625 | if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0) | 625 | if ((ret = av_frame_ref(pict, h->c.cur_pic.ptr->f)) < 0) |
| 626 | return ret; | 626 | return ret; |
| 627 | ff_print_debug_info(s, s->cur_pic.ptr, pict); | 627 | ff_print_debug_info(s, h->c.cur_pic.ptr, pict); |
| 628 | ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); | 628 | ff_mpv_export_qp_table(s, pict, h->c.cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); |
| 629 | } else if (s->last_pic.ptr) { | 629 | } else if (h->c.last_pic.ptr) { |
| 630 | if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0) | 630 | if ((ret = av_frame_ref(pict, h->c.last_pic.ptr->f)) < 0) |
| 631 | return ret; | 631 | return ret; |
| 632 | ff_print_debug_info(s, s->last_pic.ptr, pict); | 632 | ff_print_debug_info(s, h->c.last_pic.ptr, pict); |
| 633 | ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); | 633 | ff_mpv_export_qp_table(s, pict, h->c.last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); |
| 634 | } | 634 | } |
| 635 | 635 | ||
| 636 | if (s->last_pic.ptr || s->low_delay) { | 636 | if (h->c.last_pic.ptr || h->c.low_delay) { |
| 637 | if ( pict->format == AV_PIX_FMT_YUV420P | 637 | if ( pict->format == AV_PIX_FMT_YUV420P |
| 638 | && (s->codec_tag == AV_RL32("GEOV") || s->codec_tag == AV_RL32("GEOX"))) { | 638 | && (h->c.codec_tag == AV_RL32("GEOV") || h->c.codec_tag == AV_RL32("GEOX"))) { |
| 639 | for (int p = 0; p < 3; p++) { | 639 | for (int p = 0; p < 3; p++) { |
| 640 | int h = AV_CEIL_RSHIFT(pict->height, !!p); | 640 | int h = AV_CEIL_RSHIFT(pict->height, !!p); |
| 641 | 641 | ||
| @@ -673,7 +673,7 @@ const FFCodec ff_h263_decoder = { · 31 unmodified lines | |||
| 673 | CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), | 673 | CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), |
| 674 | .p.type = AVMEDIA_TYPE_VIDEO, | 674 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 675 | .p.id = AV_CODEC_ID_H263, | 675 | .p.id = AV_CODEC_ID_H263, |
| 676 | .priv_data_size = sizeof(MpegEncContext), | 676 | .priv_data_size = sizeof(H263DecContext), |
| 677 | .init = ff_h263_decode_init, | 677 | .init = ff_h263_decode_init, |
| 678 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), | 678 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 679 | .close = ff_mpv_decode_close, | 679 | .close = ff_mpv_decode_close, |
| @@ -691,7 +691,7 @@ const FFCodec ff_h263p_decoder = { · 11 unmodified lines | |||
| 691 | CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), | 691 | CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), |
| 692 | .p.type = AVMEDIA_TYPE_VIDEO, | 692 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 693 | .p.id = AV_CODEC_ID_H263P, | 693 | .p.id = AV_CODEC_ID_H263P, |
| 694 | .priv_data_size = sizeof(MpegEncContext), | 694 | .priv_data_size = sizeof(H263DecContext), |
| 695 | .init = ff_h263_decode_init, | 695 | .init = ff_h263_decode_init, |
| 696 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), | 696 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 697 | .close = ff_mpv_decode_close, | 697 | .close = ff_mpv_decode_close, |
| @@ -43,24 +43,30 @@ extern VLCElem ff_h263_inter_MCBPC_vlc[]; · 42 unmodified lines | |||
| 43 | extern VLCElem ff_h263_cbpy_vlc[]; | 43 | extern VLCElem ff_h263_cbpy_vlc[]; |
| 44 | extern VLCElem ff_h263_mv_vlc[]; | 44 | extern VLCElem ff_h263_mv_vlc[]; |
| 45 | 45 | ||
| 46 | int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code); | 46 | typedef struct H263DecContext { |
| 47 | MPVContext c; | ||
| 48 | |||
| 49 | int (*decode_mb)(struct H263DecContext *h, int16_t block[6][64]); | ||
| 50 | } H263DecContext; | ||
| 51 | |||
| 52 | int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code); | ||
| 47 | int ff_h263_decode_init(AVCodecContext *avctx); | 53 | int ff_h263_decode_init(AVCodecContext *avctx); |
| 48 | int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *frame, | 54 | int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *frame, |
| 49 | int *got_frame, AVPacket *avpkt); | 55 | int *got_frame, AVPacket *avpkt); |
| 50 | void ff_h263_decode_init_vlc(void); | 56 | void ff_h263_decode_init_vlc(void); |
| 51 | int ff_h263_decode_picture_header(MpegEncContext *s); | 57 | int ff_h263_decode_picture_header(H263DecContext *const h); |
| 52 | int ff_h263_decode_gob_header(MpegEncContext *s); | 58 | int ff_h263_decode_gob_header(H263DecContext *const h); |
| 53 | int ff_h263_decode_mba(MpegEncContext *s); | 59 | int ff_h263_decode_mba(H263DecContext *const h); |
| 54 | 60 | ||
| 55 | /** | 61 | /** |
| 56 | * Print picture info if FF_DEBUG_PICT_INFO is set. | 62 | * Print picture info if FF_DEBUG_PICT_INFO is set. |
| 57 | */ | 63 | */ |
| 58 | void ff_h263_show_pict_info(MpegEncContext *s, int h263_plus); | 64 | void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus); |
| 59 | 65 | ||
| 60 | int ff_intel_h263_decode_picture_header(MpegEncContext *s); | 66 | int ff_intel_h263_decode_picture_header(H263DecContext *const h); |
| 61 | int ff_h263_decode_mb(MpegEncContext *s, | 67 | int ff_h263_decode_mb(H263DecContext *const h, |
| 62 | int16_t block[6][64]); | 68 | int16_t block[6][64]); |
| 63 | 69 | ||
| 64 | int ff_h263_resync(MpegEncContext *s); | 70 | int ff_h263_resync(H263DecContext *const h); |
| 65 | 71 | ||
| 66 | #endif | 72 | #endif |
| @@ -26,102 +26,102 @@ · 25 unmodified lines | |||
| 26 | #include "h263dec.h" | 26 | #include "h263dec.h" |
| 27 | 27 | ||
| 28 | /* don't understand why they choose a different header ! */ | 28 | /* don't understand why they choose a different header ! */ |
| 29 | int ff_intel_h263_decode_picture_header(MpegEncContext *s) | 29 | int ff_intel_h263_decode_picture_header(H263DecContext *const h) |
| 30 | { | 30 | { |
| 31 | int format; | 31 | int format; |
| 32 | 32 | ||
| 33 | if (get_bits_left(&s->gb) == 64) { /* special dummy frames */ | 33 | if (get_bits_left(&h->c.gb) == 64) { /* special dummy frames */ |
| 34 | return FRAME_SKIPPED; | 34 | return FRAME_SKIPPED; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /* picture header */ | 37 | /* picture header */ |
| 38 | if (get_bits(&s->gb, 22) != 0x20) { | 38 | if (get_bits(&h->c.gb, 22) != 0x20) { |
| 39 | av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); | 39 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
| 40 | return -1; | 40 | return -1; |
| 41 | } | 41 | } |
| 42 | s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ | 42 | h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */ |
| 43 | 43 | ||
| 44 | if (check_marker(s->avctx, &s->gb, "after picture_number") != 1) { | 44 | if (check_marker(h->c.avctx, &h->c.gb, "after picture_number") != 1) { |
| 45 | return -1; /* marker */ | 45 | return -1; /* marker */ |
| 46 | } | 46 | } |
| 47 | if (get_bits1(&s->gb) != 0) { | 47 | if (get_bits1(&h->c.gb) != 0) { |
| 48 | av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n"); | 48 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n"); |
| 49 | return -1; /* H.263 id */ | 49 | return -1; /* H.263 id */ |
| 50 | } | 50 | } |
| 51 | skip_bits1(&s->gb); /* split screen off */ | 51 | skip_bits1(&h->c.gb); /* split screen off */ |
| 52 | skip_bits1(&s->gb); /* camera off */ | 52 | skip_bits1(&h->c.gb); /* camera off */ |
| 53 | skip_bits1(&s->gb); /* freeze picture release off */ | 53 | skip_bits1(&h->c.gb); /* freeze picture release off */ |
| 54 | 54 | ||
| 55 | format = get_bits(&s->gb, 3); | 55 | format = get_bits(&h->c.gb, 3); |
| 56 | if (format == 0 || format == 6) { | 56 | if (format == 0 || format == 6) { |
| 57 | av_log(s->avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n"); | 57 | av_log(h->c.avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n"); |
| 58 | return -1; | 58 | return -1; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); | 61 | h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb); |
| 62 | 62 | ||
| 63 | s->h263_long_vectors = get_bits1(&s->gb); | 63 | h->c.h263_long_vectors = get_bits1(&h->c.gb); |
| 64 | 64 | ||
| 65 | if (get_bits1(&s->gb) != 0) { | 65 | if (get_bits1(&h->c.gb) != 0) { |
| 66 | av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n"); | 66 | av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n"); |
| 67 | return -1; /* SAC: off */ | 67 | return -1; /* SAC: off */ |
| 68 | } | 68 | } |
| 69 | s->obmc= get_bits1(&s->gb); | 69 | h->c.obmc = get_bits1(&h->c.gb); |
| 70 | s->pb_frame = get_bits1(&s->gb); | 70 | h->c.pb_frame = get_bits1(&h->c.gb); |
| 71 | 71 | ||
| 72 | if (format < 6) { | 72 | if (format < 6) { |
| 73 | s->width = ff_h263_format[format][0]; | 73 | h->c.width = ff_h263_format[format][0]; |
| 74 | s->height = ff_h263_format[format][1]; | 74 | h->c.height = ff_h263_format[format][1]; |
| 75 | s->avctx->sample_aspect_ratio.num = 12; | 75 | h->c.avctx->sample_aspect_ratio.num = 12; |
| 76 | s->avctx->sample_aspect_ratio.den = 11; | 76 | h->c.avctx->sample_aspect_ratio.den = 11; |
| 77 | } else { | 77 | } else { |
| 78 | format = get_bits(&s->gb, 3); | 78 | format = get_bits(&h->c.gb, 3); |
| 79 | if(format == 0 || format == 7){ | 79 | if(format == 0 || format == 7){ |
| 80 | av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n"); | 80 | av_log(h->c.avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n"); |
| 81 | return -1; | 81 | return -1; |
| 82 | } | 82 | } |
| 83 | if(get_bits(&s->gb, 2)) | 83 | if (get_bits(&h->c.gb, 2)) |
| 84 | av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | 84 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); |
| 85 | s->loop_filter = get_bits1(&s->gb) * !s->avctx->lowres; | 85 | h->c.loop_filter = get_bits1(&h->c.gb) * !h->c.avctx->lowres; |
| 86 | if(get_bits1(&s->gb)) | 86 | if (get_bits1(&h->c.gb)) |
| 87 | av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | 87 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); |
| 88 | if(get_bits1(&s->gb)) | 88 | if (get_bits1(&h->c.gb)) |
| 89 | s->pb_frame = 2; | 89 | h->c.pb_frame = 2; |
| 90 | if(get_bits(&s->gb, 5)) | 90 | if (get_bits(&h->c.gb, 5)) |
| 91 | av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | 91 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); |
| 92 | if(get_bits(&s->gb, 5) != 1) | 92 | if (get_bits(&h->c.gb, 5) != 1) |
| 93 | av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n"); | 93 | av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n"); |
| 94 | } | 94 | } |
| 95 | if(format == 6){ | 95 | if(format == 6){ |
| 96 | int ar = get_bits(&s->gb, 4); | 96 | int ar = get_bits(&h->c.gb, 4); |
| 97 | skip_bits(&s->gb, 9); // display width | 97 | skip_bits(&h->c.gb, 9); // display width |
| 98 | check_marker(s->avctx, &s->gb, "in dimensions"); | 98 | check_marker(h->c.avctx, &h->c.gb, "in dimensions"); |
| 99 | skip_bits(&s->gb, 9); // display height | 99 | skip_bits(&h->c.gb, 9); // display height |
| 100 | if(ar == 15){ | 100 | if (ar == 15) { |
| 101 | s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width | 101 | h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); // aspect ratio - width |
| 102 | s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height | 102 | h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); // aspect ratio - height |
| 103 | } else { | 103 | } else { |
| 104 | s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar]; | 104 | h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar]; |
| 105 | } | 105 | } |
| 106 | if (s->avctx->sample_aspect_ratio.num == 0) | 106 | if (h->c.avctx->sample_aspect_ratio.num == 0) |
| 107 | av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n"); | 107 | av_log(h->c.avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n"); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); | 110 | h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); |
| 111 | skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | 111 | skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */ |
| 112 | 112 | ||
| 113 | if(s->pb_frame){ | 113 | if (h->c.pb_frame) { |
| 114 | skip_bits(&s->gb, 3); //temporal reference for B-frame | 114 | skip_bits(&h->c.gb, 3); //temporal reference for B-frame |
| 115 | skip_bits(&s->gb, 2); //dbquant | 115 | skip_bits(&h->c.gb, 2); //dbquant |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | /* PEI */ | 118 | /* PEI */ |
| 119 | if (skip_1stop_8data_bits(&s->gb) < 0) | 119 | if (skip_1stop_8data_bits(&h->c.gb) < 0) |
| 120 | return AVERROR_INVALIDDATA; | 120 | return AVERROR_INVALIDDATA; |
| 121 | 121 | ||
| 122 | s->gob_index = H263_GOB_HEIGHT(s->height); | 122 | h->c.gob_index = H263_GOB_HEIGHT(h->c.height); |
| 123 | 123 | ||
| 124 | ff_h263_show_pict_info(s, 0); | 124 | ff_h263_show_pict_info(h, 0); |
| 125 | 125 | ||
| 126 | return 0; | 126 | return 0; |
| 127 | } | 127 | } |
| @@ -131,7 +131,7 @@ const FFCodec ff_h263i_decoder = { · 3 unmodified lines | |||
| 131 | CODEC_LONG_NAME("Intel H.263"), | 131 | CODEC_LONG_NAME("Intel H.263"), |
| 132 | .p.type = AVMEDIA_TYPE_VIDEO, | 132 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 133 | .p.id = AV_CODEC_ID_H263I, | 133 | .p.id = AV_CODEC_ID_H263I, |
| 134 | .priv_data_size = sizeof(MpegEncContext), | 134 | .priv_data_size = sizeof(H263DecContext), |
| 135 | .init = ff_h263_decode_init, | 135 | .init = ff_h263_decode_init, |
| 136 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), | 136 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 137 | .close = ff_mpv_decode_close, | 137 | .close = ff_mpv_decode_close, |
| @@ -77,23 +77,22 @@ static const int16_t h263_mb_type_b_map[15]= { · 76 unmodified lines | |||
| 77 | MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT, | 77 | MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT, |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | void ff_h263_show_pict_info(MpegEncContext *s, int h263_plus) | 80 | void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus) |
| 81 | { | 81 | { |
| 82 | if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | 82 | if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) { |
| 83 | av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", | 83 | av_log(h->c.avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", |
| 84 | s->qscale, av_get_picture_type_char(s->pict_type), | 84 | h->c.qscale, av_get_picture_type_char(h->c.pict_type), |
| 85 | s->gb.size_in_bits, 1-s->no_rounding, | 85 | h->c.gb.size_in_bits, 1-h->c.no_rounding, |
| 86 | s->obmc ? " AP" : "", | 86 | h->c.obmc ? " AP" : "", |
| 87 | s->umvplus ? " UMV" : "", | 87 | h->c.umvplus ? " UMV" : "", |
| 88 | s->h263_long_vectors ? " LONG" : "", | 88 | h->c.h263_long_vectors ? " LONG" : "", |
| 89 | h263_plus ? " +" : "", | 89 | h263_plus ? " +" : "", |
| 90 | s->h263_aic ? " AIC" : "", | 90 | h->c.h263_aic ? " AIC" : "", |
| 91 | s->alt_inter_vlc ? " AIV" : "", | 91 | h->c.alt_inter_vlc ? " AIV" : "", |
| 92 | s->modified_quant ? " MQ" : "", | 92 | h->c.modified_quant ? " MQ" : "", |
| 93 | s->loop_filter ? " LOOP" : "", | 93 | h->c.loop_filter ? " LOOP" : "", |
| 94 | s->h263_slice_structured ? " SS" : "", | 94 | h->c.h263_slice_structured ? " SS" : "", |
| 95 | s->avctx->framerate.num, s->avctx->framerate.den | 95 | h->c.avctx->framerate.num, h->c.avctx->framerate.den); |
| 96 | ); | ||
| 97 | } | 96 | } |
| 98 | } | 97 | } |
| 99 | 98 | ||
| @@ -140,16 +139,16 @@ av_cold void ff_h263_decode_init_vlc(void) · 40 unmodified lines | |||
| 140 | ff_thread_once(&init_static_once, h263_decode_init_vlc); | 139 | ff_thread_once(&init_static_once, h263_decode_init_vlc); |
| 141 | } | 140 | } |
| 142 | 141 | ||
| 143 | int ff_h263_decode_mba(MpegEncContext *s) | 142 | int ff_h263_decode_mba(H263DecContext *const h) |
| 144 | { | 143 | { |
| 145 | int i, mb_pos; | 144 | int i, mb_pos; |
| 146 | 145 | ||
| 147 | for (i = 0; i < 6; i++) | 146 | for (i = 0; i < 6; i++) |
| 148 | if (s->mb_num - 1 <= ff_mba_max[i]) | 147 | if (h->c.mb_num - 1 <= ff_mba_max[i]) |
| 149 | break; | 148 | break; |
| 150 | mb_pos = get_bits(&s->gb, ff_mba_length[i]); | 149 | mb_pos = get_bits(&h->c.gb, ff_mba_length[i]); |
| 151 | s->mb_x = mb_pos % s->mb_width; | 150 | h->c.mb_x = mb_pos % h->c.mb_width; |
| 152 | s->mb_y = mb_pos / s->mb_width; | 151 | h->c.mb_y = mb_pos / h->c.mb_width; |
| 153 | 152 | ||
| 154 | return mb_pos; | 153 | return mb_pos; |
| 155 | } | 154 | } |
| @@ -158,53 +157,53 @@ int ff_h263_decode_mba(MpegEncContext *s) · 2 unmodified lines | |||
| 158 | * Decode the group of blocks header or slice header. | 157 | * Decode the group of blocks header or slice header. |
| 159 | * @return <0 if an error occurred | 158 | * @return <0 if an error occurred |
| 160 | */ | 159 | */ |
| 161 | static int h263_decode_gob_header(MpegEncContext *s) | 160 | static int h263_decode_gob_header(H263DecContext *const h) |
| 162 | { | 161 | { |
| 163 | unsigned int val, gob_number; | 162 | unsigned int val, gob_number; |
| 164 | int left; | 163 | int left; |
| 165 | 164 | ||
| 166 | /* Check for GOB Start Code */ | 165 | /* Check for GOB Start Code */ |
| 167 | val = show_bits(&s->gb, 16); | 166 | val = show_bits(&h->c.gb, 16); |
| 168 | if(val) | 167 | if(val) |
| 169 | return -1; | 168 | return -1; |
| 170 | 169 | ||
| 171 | /* We have a GBSC probably with GSTUFF */ | 170 | /* We have a GBSC probably with GSTUFF */ |
| 172 | skip_bits(&s->gb, 16); /* Drop the zeros */ | 171 | skip_bits(&h->c.gb, 16); /* Drop the zeros */ |
| 173 | left= get_bits_left(&s->gb); | 172 | left = get_bits_left(&h->c.gb); |
| 174 | left = FFMIN(left, 32); | 173 | left = FFMIN(left, 32); |
| 175 | //MN: we must check the bits left or we might end in an infinite loop (or segfault) | 174 | //MN: we must check the bits left or we might end in an infinite loop (or segfault) |
| 176 | for(;left>13; left--){ | 175 | for(;left>13; left--){ |
| 177 | if(get_bits1(&s->gb)) break; /* Seek the '1' bit */ | 176 | if (get_bits1(&h->c.gb)) break; /* Seek the '1' bit */ |
| 178 | } | 177 | } |
| 179 | if(left<=13) | 178 | if(left<=13) |
| 180 | return -1; | 179 | return -1; |
| 181 | 180 | ||
| 182 | if(s->h263_slice_structured){ | 181 | if (h->c.h263_slice_structured) { |
| 183 | if(check_marker(s->avctx, &s->gb, "before MBA")==0) | 182 | if (check_marker(h->c.avctx, &h->c.gb, "before MBA")==0) |
| 184 | return -1; | 183 | return -1; |
| 185 | 184 | ||
| 186 | ff_h263_decode_mba(s); | 185 | ff_h263_decode_mba(h); |
| 187 | 186 | ||
| 188 | if(s->mb_num > 1583) | 187 | if (h->c.mb_num > 1583) |
| 189 | if(check_marker(s->avctx, &s->gb, "after MBA")==0) | 188 | if (check_marker(h->c.avctx, &h->c.gb, "after MBA")==0) |
| 190 | return -1; | 189 | return -1; |
| 191 | 190 | ||
| 192 | s->qscale = get_bits(&s->gb, 5); /* SQUANT */ | 191 | h->c.qscale = get_bits(&h->c.gb, 5); /* SQUANT */ |
| 193 | if(check_marker(s->avctx, &s->gb, "after SQUANT")==0) | 192 | if (check_marker(h->c.avctx, &h->c.gb, "after SQUANT")==0) |
| 194 | return -1; | 193 | return -1; |
| 195 | skip_bits(&s->gb, 2); /* GFID */ | 194 | skip_bits(&h->c.gb, 2); /* GFID */ |
| 196 | }else{ | 195 | }else{ |
| 197 | gob_number = get_bits(&s->gb, 5); /* GN */ | 196 | gob_number = get_bits(&h->c.gb, 5); /* GN */ |
| 198 | s->mb_x= 0; | 197 | h->c.mb_x = 0; |
| 199 | s->mb_y= s->gob_index* gob_number; | 198 | h->c.mb_y = h->c.gob_index* gob_number; |
| 200 | skip_bits(&s->gb, 2); /* GFID */ | 199 | skip_bits(&h->c.gb, 2); /* GFID */ |
| 201 | s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | 200 | h->c.qscale = get_bits(&h->c.gb, 5); /* GQUANT */ |
| 202 | } | 201 | } |
| 203 | 202 | ||
| 204 | if(s->mb_y >= s->mb_height) | 203 | if (h->c.mb_y >= h->c.mb_height) |
| 205 | return -1; | 204 | return -1; |
| 206 | 205 | ||
| 207 | if(s->qscale==0) | 206 | if (h->c.qscale==0) |
| 208 | return -1; | 207 | return -1; |
| 209 | 208 | ||
| 210 | return 0; | 209 | return 0; |
| @@ -214,79 +213,80 @@ static int h263_decode_gob_header(MpegEncContext *s) · 3 unmodified lines | |||
| 214 | * Decode the group of blocks / video packet header / slice header (MPEG-4 Studio). | 213 | * Decode the group of blocks / video packet header / slice header (MPEG-4 Studio). |
| 215 | * @return bit position of the resync_marker, or <0 if none was found | 214 | * @return bit position of the resync_marker, or <0 if none was found |
| 216 | */ | 215 | */ |
| 217 | int ff_h263_resync(MpegEncContext *s){ | 216 | int ff_h263_resync(H263DecContext *const h) |
| 217 | { | ||
| 218 | int left, pos, ret; | 218 | int left, pos, ret; |
| 219 | 219 | ||
| 220 | /* In MPEG-4 studio mode look for a new slice startcode | 220 | /* In MPEG-4 studio mode look for a new slice startcode |
| 221 | * and decode slice header */ | 221 | * and decode slice header */ |
| 222 | if(s->codec_id==AV_CODEC_ID_MPEG4 && s->studio_profile) { | 222 | if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) { |
| 223 | align_get_bits(&s->gb); | 223 | align_get_bits(&h->c.gb); |
| 224 | 224 | ||
| 225 | while (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) != SLICE_STARTCODE) { | 225 | while (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) != SLICE_STARTCODE) { |
| 226 | get_bits(&s->gb, 8); | 226 | get_bits(&h->c.gb, 8); |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | if (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) == SLICE_STARTCODE) | 229 | if (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) == SLICE_STARTCODE) |
| 230 | return get_bits_count(&s->gb); | 230 | return get_bits_count(&h->c.gb); |
| 231 | else | 231 | else |
| 232 | return -1; | 232 | return -1; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | if(s->codec_id==AV_CODEC_ID_MPEG4){ | 235 | if (h->c.codec_id==AV_CODEC_ID_MPEG4){ |
| 236 | skip_bits1(&s->gb); | 236 | skip_bits1(&h->c.gb); |
| 237 | align_get_bits(&s->gb); | 237 | align_get_bits(&h->c.gb); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | if(show_bits(&s->gb, 16)==0){ | 240 | if (show_bits(&h->c.gb, 16) ==0) { |
| 241 | pos= get_bits_count(&s->gb); | 241 | pos = get_bits_count(&h->c.gb); |
| 242 | if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4) | 242 | if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4) |
| 243 | ret = ff_mpeg4_decode_video_packet_header(s); | 243 | ret = ff_mpeg4_decode_video_packet_header(h); |
| 244 | else | 244 | else |
| 245 | ret= h263_decode_gob_header(s); | 245 | ret = h263_decode_gob_header(h); |
| 246 | if(ret>=0) | 246 | if(ret>=0) |
| 247 | return pos; | 247 | return pos; |
| 248 | } | 248 | } |
| 249 | //OK, it's not where it is supposed to be ... | 249 | //OK, it's not where it is supposed to be ... |
| 250 | s->gb= s->last_resync_gb; | 250 | h->c.gb = h->c.last_resync_gb; |
| 251 | align_get_bits(&s->gb); | 251 | align_get_bits(&h->c.gb); |
| 252 | left= get_bits_left(&s->gb); | 252 | left = get_bits_left(&h->c.gb); |
| 253 | 253 | ||
| 254 | for(;left>16+1+5+5; left-=8){ | 254 | for(;left>16+1+5+5; left-=8){ |
| 255 | if(show_bits(&s->gb, 16)==0){ | 255 | if (show_bits(&h->c.gb, 16) == 0){ |
| 256 | GetBitContext bak= s->gb; | 256 | GetBitContext bak = h->c.gb; |
| 257 | 257 | ||
| 258 | pos= get_bits_count(&s->gb); | 258 | pos = get_bits_count(&h->c.gb); |
| 259 | if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4) | 259 | if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4) |
| 260 | ret = ff_mpeg4_decode_video_packet_header(s); | 260 | ret = ff_mpeg4_decode_video_packet_header(h); |
| 261 | else | 261 | else |
| 262 | ret= h263_decode_gob_header(s); | 262 | ret = h263_decode_gob_header(h); |
| 263 | if(ret>=0) | 263 | if(ret>=0) |
| 264 | return pos; | 264 | return pos; |
| 265 | 265 | ||
| 266 | s->gb= bak; | 266 | h->c.gb = bak; |
| 267 | } | 267 | } |
| 268 | skip_bits(&s->gb, 8); | 268 | skip_bits(&h->c.gb, 8); |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | return -1; | 271 | return -1; |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) | 274 | int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code) |
| 275 | { | 275 | { |
| 276 | int code, val, sign, shift; | 276 | int code, val, sign, shift; |
| 277 | code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2); | 277 | code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2); |
| 278 | 278 | ||
| 279 | if (code == 0) | 279 | if (code == 0) |
| 280 | return pred; | 280 | return pred; |
| 281 | if (code < 0) | 281 | if (code < 0) |
| 282 | return 0xffff; | 282 | return 0xffff; |
| 283 | 283 | ||
| 284 | sign = get_bits1(&s->gb); | 284 | sign = get_bits1(&h->c.gb); |
| 285 | shift = f_code - 1; | 285 | shift = f_code - 1; |
| 286 | val = code; | 286 | val = code; |
| 287 | if (shift) { | 287 | if (shift) { |
| 288 | val = (val - 1) << shift; | 288 | val = (val - 1) << shift; |
| 289 | val |= get_bits(&s->gb, shift); | 289 | val |= get_bits(&h->c.gb, shift); |
| 290 | val++; | 290 | val++; |
| 291 | } | 291 | } |
| 292 | if (sign) | 292 | if (sign) |
| @@ -294,7 +294,7 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) · 1 unmodified line | |||
| 294 | val += pred; | 294 | val += pred; |
| 295 | 295 | ||
| 296 | /* modulo decoding */ | 296 | /* modulo decoding */ |
| 297 | if (!s->h263_long_vectors) { | 297 | if (!h->c.h263_long_vectors) { |
| 298 | val = sign_extend(val, 5 + f_code); | 298 | val = sign_extend(val, 5 + f_code); |
| 299 | } else { | 299 | } else { |
| 300 | /* horrible H.263 long vector mode */ | 300 | /* horrible H.263 long vector mode */ |
| @@ -309,21 +309,21 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) · 8 unmodified lines | |||
| 309 | 309 | ||
| 310 | 310 | ||
| 311 | /* Decode RVLC of H.263+ UMV */ | 311 | /* Decode RVLC of H.263+ UMV */ |
| 312 | static int h263p_decode_umotion(MpegEncContext * s, int pred) | 312 | static int h263p_decode_umotion(H263DecContext *const h, int pred) |
| 313 | { | 313 | { |
| 314 | int code = 0, sign; | 314 | int code = 0, sign; |
| 315 | 315 | ||
| 316 | if (get_bits1(&s->gb)) /* Motion difference = 0 */ | 316 | if (get_bits1(&h->c.gb)) /* Motion difference = 0 */ |
| 317 | return pred; | 317 | return pred; |
| 318 | 318 | ||
| 319 | code = 2 + get_bits1(&s->gb); | 319 | code = 2 + get_bits1(&h->c.gb); |
| 320 | 320 | ||
| 321 | while (get_bits1(&s->gb)) | 321 | while (get_bits1(&h->c.gb)) |
| 322 | { | 322 | { |
| 323 | code <<= 1; | 323 | code <<= 1; |
| 324 | code += get_bits1(&s->gb); | 324 | code += get_bits1(&h->c.gb); |
| 325 | if (code >= 32768) { | 325 | if (code >= 32768) { |
| 326 | avpriv_request_sample(s->avctx, "Huge DMV"); | 326 | avpriv_request_sample(h->c.avctx, "Huge DMV"); |
| 327 | return 0xffff; | 327 | return 0xffff; |
| 328 | } | 328 | } |
| 329 | } | 329 | } |
| @@ -331,7 +331,7 @@ static int h263p_decode_umotion(MpegEncContext * s, int pred) · 1 unmodified line | |||
| 331 | code >>= 1; | 331 | code >>= 1; |
| 332 | 332 | ||
| 333 | code = (sign) ? (pred - code) : (pred + code); | 333 | code = (sign) ? (pred - code) : (pred + code); |
| 334 | ff_tlog(s->avctx,"H.263+ UMV Motion = %d\n", code); | 334 | ff_tlog(h->c.avctx,"H.263+ UMV Motion = %d\n", code); |
| 335 | return code; | 335 | return code; |
| 336 | 336 | ||
| 337 | } | 337 | } |
| @@ -339,82 +339,79 @@ static int h263p_decode_umotion(MpegEncContext * s, int pred) · 1 unmodified line | |||
| 339 | /** | 339 | /** |
| 340 | * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :) | 340 | * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :) |
| 341 | */ | 341 | */ |
| 342 | static void preview_obmc(MpegEncContext *s){ | 342 | static void preview_obmc(H263DecContext *const h) |
| 343 | GetBitContext gb= s->gb; | 343 | { |
| 344 | GetBitContext gb = h->c.gb; | ||
| 344 | 345 | ||
| 345 | int cbpc, i, pred_x, pred_y, mx, my; | 346 | int cbpc, i, pred_x, pred_y, mx, my; |
| 346 | int16_t *mot_val; | 347 | int16_t *mot_val; |
| 347 | const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; | 348 | const int xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride; |
| 348 | const int stride= s->b8_stride*2; | 349 | const int stride = h->c.b8_stride * 2; |
| 349 | 350 | ||
| 350 | for(i=0; i<4; i++) | 351 | for(i=0; i<4; i++) |
| 351 | s->block_index[i]+= 2; | 352 | h->c.block_index[i] += 2; |
| 352 | for(i=4; i<6; i++) | 353 | for(i=4; i<6; i++) |
| 353 | s->block_index[i]+= 1; | 354 | h->c.block_index[i] += 1; |
| 354 | s->mb_x++; | 355 | h->c.mb_x++; |
| 355 | 356 | ||
| 356 | av_assert2(s->pict_type == AV_PICTURE_TYPE_P); | 357 | av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P); |
| 357 | 358 | ||
| 358 | do{ | 359 | do{ |
| 359 | if (get_bits1(&s->gb)) { | 360 | if (get_bits1(&h->c.gb)) { |
| 360 | /* skip mb */ | 361 | /* skip mb */ |
| 361 | mot_val = s->cur_pic.motion_val[0][s->block_index[0]]; | 362 | mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]]; |
| 362 | mot_val[0 ]= mot_val[2 ]= | 363 | mot_val[0 ]= mot_val[2 ]= |
| 363 | mot_val[0+stride]= mot_val[2+stride]= 0; | 364 | mot_val[0+stride]= mot_val[2+stride]= 0; |
| 364 | mot_val[1 ]= mot_val[3 ]= | 365 | mot_val[1 ]= mot_val[3 ]= |
| 365 | mot_val[1+stride]= mot_val[3+stride]= 0; | 366 | mot_val[1+stride]= mot_val[3+stride]= 0; |
| 366 | 367 | ||
| 367 | s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 368 | h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 368 | goto end; | 369 | goto end; |
| 369 | } | 370 | } |
| 370 | cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); | 371 | cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); |
| 371 | }while(cbpc == 20); | 372 | }while(cbpc == 20); |
| 372 | 373 | ||
| 373 | if(cbpc & 4){ | 374 | if(cbpc & 4){ |
| 374 | s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | 375 | h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; |
| 375 | }else{ | 376 | }else{ |
| 376 | get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 377 | get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 377 | if (cbpc & 8) { | 378 | if (cbpc & 8) { |
| 378 | if(s->modified_quant){ | 379 | skip_bits(&h->c.gb, h->c.modified_quant ? (get_bits1(&h->c.gb) ? 1 : 5) : 2); |
| 379 | if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); | ||
| 380 | else skip_bits(&s->gb, 5); | ||
| 381 | }else | ||
| 382 | skip_bits(&s->gb, 2); | ||
| 383 | } | 380 | } |
| 384 | 381 | ||
| 385 | if ((cbpc & 16) == 0) { | 382 | if ((cbpc & 16) == 0) { |
| 386 | s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 383 | h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 387 | /* 16x16 motion prediction */ | 384 | /* 16x16 motion prediction */ |
| 388 | mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | 385 | mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); |
| 389 | if (s->umvplus) | 386 | if (h->c.umvplus) |
| 390 | mx = h263p_decode_umotion(s, pred_x); | 387 | mx = h263p_decode_umotion(h, pred_x); |
| 391 | else | 388 | else |
| 392 | mx = ff_h263_decode_motion(s, pred_x, 1); | 389 | mx = ff_h263_decode_motion(h, pred_x, 1); |
| 393 | 390 | ||
| 394 | if (s->umvplus) | 391 | if (h->c.umvplus) |
| 395 | my = h263p_decode_umotion(s, pred_y); | 392 | my = h263p_decode_umotion(h, pred_y); |
| 396 | else | 393 | else |
| 397 | my = ff_h263_decode_motion(s, pred_y, 1); | 394 | my = ff_h263_decode_motion(h, pred_y, 1); |
| 398 | 395 | ||
| 399 | mot_val[0 ]= mot_val[2 ]= | 396 | mot_val[0 ]= mot_val[2 ]= |
| 400 | mot_val[0+stride]= mot_val[2+stride]= mx; | 397 | mot_val[0+stride]= mot_val[2+stride]= mx; |
| 401 | mot_val[1 ]= mot_val[3 ]= | 398 | mot_val[1 ]= mot_val[3 ]= |
| 402 | mot_val[1+stride]= mot_val[3+stride]= my; | 399 | mot_val[1+stride]= mot_val[3+stride]= my; |
| 403 | } else { | 400 | } else { |
| 404 | s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; | 401 | h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; |
| 405 | for(i=0;i<4;i++) { | 402 | for(i=0;i<4;i++) { |
| 406 | mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | 403 | mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); |
| 407 | if (s->umvplus) | 404 | if (h->c.umvplus) |
| 408 | mx = h263p_decode_umotion(s, pred_x); | 405 | mx = h263p_decode_umotion(h, pred_x); |
| 409 | else | 406 | else |
| 410 | mx = ff_h263_decode_motion(s, pred_x, 1); | 407 | mx = ff_h263_decode_motion(h, pred_x, 1); |
| 411 | 408 | ||
| 412 | if (s->umvplus) | 409 | if (h->c.umvplus) |
| 413 | my = h263p_decode_umotion(s, pred_y); | 410 | my = h263p_decode_umotion(h, pred_y); |
| 414 | else | 411 | else |
| 415 | my = ff_h263_decode_motion(s, pred_y, 1); | 412 | my = ff_h263_decode_motion(h, pred_y, 1); |
| 416 | if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | 413 | if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 417 | skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 414 | skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ |
| 418 | mot_val[0] = mx; | 415 | mot_val[0] = mx; |
| 419 | mot_val[1] = my; | 416 | mot_val[1] = my; |
| 420 | } | 417 | } |
| @@ -423,26 +420,27 @@ static void preview_obmc(MpegEncContext *s){ · 2 unmodified lines | |||
| 423 | end: | 420 | end: |
| 424 | 421 | ||
| 425 | for(i=0; i<4; i++) | 422 | for(i=0; i<4; i++) |
| 426 | s->block_index[i]-= 2; | 423 | h->c.block_index[i] -= 2; |
| 427 | for(i=4; i<6; i++) | 424 | for(i=4; i<6; i++) |
| 428 | s->block_index[i]-= 1; | 425 | h->c.block_index[i] -= 1; |
| 429 | s->mb_x--; | 426 | h->c.mb_x--; |
| 430 | 427 | ||
| 431 | s->gb= gb; | 428 | h->c.gb = gb; |
| 432 | } | 429 | } |
| 433 | 430 | ||
| 434 | static void h263_decode_dquant(MpegEncContext *s){ | 431 | static void h263_decode_dquant(H263DecContext *const h) |
| 432 | { | ||
| 435 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; | 433 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
| 436 | int qscale; | 434 | int qscale; |
| 437 | 435 | ||
| 438 | if(s->modified_quant){ | 436 | if (h->c.modified_quant) { |
| 439 | if(get_bits1(&s->gb)) | 437 | if (get_bits1(&h->c.gb)) |
| 440 | qscale = ff_modified_quant_tab[get_bits1(&s->gb)][s->qscale]; | 438 | qscale = ff_modified_quant_tab[get_bits1(&h->c.gb)][h->c.qscale]; |
| 441 | else | 439 | else |
| 442 | qscale = get_bits(&s->gb, 5); | 440 | qscale = get_bits(&h->c.gb, 5); |
| 443 | }else | 441 | }else |
| 444 | qscale = s->qscale + quant_tab[get_bits(&s->gb, 2)]; | 442 | qscale = h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]; |
| 445 | ff_set_qscale(s, qscale); | 443 | ff_set_qscale(&h->c, qscale); |
| 446 | } | 444 | } |
| 447 | 445 | ||
| 448 | static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n) | 446 | static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n) |
| @@ -523,52 +521,53 @@ static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n) · 74 unmodified lines | |||
| 523 | ac_val[8 + i] = block[s->idsp.idct_permutation[i]]; | 521 | ac_val[8 + i] = block[s->idsp.idct_permutation[i]]; |
| 524 | } | 522 | } |
| 525 | 523 | ||
| 526 | static int h263_decode_block(MpegEncContext * s, int16_t * block, | 524 | static int h263_decode_block(H263DecContext *const h, int16_t block[64], |
| 527 | int n, int coded) | 525 | int n, int coded) |
| 528 | { | 526 | { |
| 529 | int level, i, j, run; | 527 | int level, i, j, run; |
| 530 | const RLTable *rl = &ff_h263_rl_inter; | 528 | const RLTable *rl = &ff_h263_rl_inter; |
| 531 | const uint8_t *scan_table; | 529 | const uint8_t *scan_table; |
| 532 | GetBitContext gb= s->gb; | 530 | GetBitContext gb = h->c.gb; |
| 533 | 531 | ||
| 534 | scan_table = s->intra_scantable.permutated; | 532 | scan_table = h->c.intra_scantable.permutated; |
| 535 | if (s->h263_aic && s->mb_intra) { | 533 | if (h->c.h263_aic && h->c.mb_intra) { |
| 536 | i = 0; | 534 | i = 0; |
| 537 | if (!coded) | 535 | if (!coded) |
| 538 | goto not_coded; | 536 | goto not_coded; |
| 539 | rl = &ff_rl_intra_aic; | 537 | rl = &ff_rl_intra_aic; |
| 540 | if (s->ac_pred) { | 538 | if (h->c.ac_pred) { |
| 541 | if (s->h263_aic_dir) | 539 | if (h->c.h263_aic_dir) |
| 542 | scan_table = s->permutated_intra_v_scantable; /* left */ | 540 | scan_table = h->c.permutated_intra_v_scantable; /* left */ |
| 543 | else | 541 | else |
| 544 | scan_table = s->permutated_intra_h_scantable; /* top */ | 542 | scan_table = h->c.permutated_intra_h_scantable; /* top */ |
| 545 | } | 543 | } |
| 546 | } else if (s->mb_intra) { | 544 | } else if (h->c.mb_intra) { |
| 547 | /* DC coef */ | 545 | /* DC coef */ |
| 548 | if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) { | 546 | if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) { |
| 549 | if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) { | 547 | if (h->c.rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 550 | int component = (n <= 3 ? 0 : n - 4 + 1); | 548 | int component = (n <= 3 ? 0 : n - 4 + 1); |
| 551 | level = s->last_dc[component]; | 549 | level = h->c.last_dc[component]; |
| 552 | if (s->rv10_first_dc_coded[component]) { | 550 | if (h->c.rv10_first_dc_coded[component]) { |
| 553 | int diff = ff_rv_decode_dc(s, n); | 551 | int diff = ff_rv_decode_dc(h, n); |
| 554 | if (diff < 0) | 552 | if (diff < 0) |
| 555 | return -1; | 553 | return -1; |
| 556 | level += diff; | 554 | level += diff; |
| 557 | level = level & 0xff; /* handle wrap round */ | 555 | level = level & 0xff; /* handle wrap round */ |
| 558 | s->last_dc[component] = level; | 556 | h->c.last_dc[component] = level; |
| 559 | } else { | 557 | } else { |
| 560 | s->rv10_first_dc_coded[component] = 1; | 558 | h->c.rv10_first_dc_coded[component] = 1; |
| 561 | } | 559 | } |
| 562 | } else { | 560 | } else { |
| 563 | level = get_bits(&s->gb, 8); | 561 | level = get_bits(&h->c.gb, 8); |
| 564 | if (level == 255) | 562 | if (level == 255) |
| 565 | level = 128; | 563 | level = 128; |
| 566 | } | 564 | } |
| 567 | }else{ | 565 | }else{ |
| 568 | level = get_bits(&s->gb, 8); | 566 | level = get_bits(&h->c.gb, 8); |
| 569 | if((level&0x7F) == 0){ | 567 | if((level&0x7F) == 0){ |
| 570 | av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); | 568 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", |
| 571 | if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) | 569 | level, h->c.mb_x, h->c.mb_y); |
| 570 | if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) | ||
| 572 | return -1; | 571 | return -1; |
| 573 | } | 572 | } |
| 574 | if (level == 255) | 573 | if (level == 255) |
| @@ -580,64 +579,65 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block, · 5 unmodified lines | |||
| 580 | i = 0; | 579 | i = 0; |
| 581 | } | 580 | } |
| 582 | if (!coded) { | 581 | if (!coded) { |
| 583 | s->block_last_index[n] = i - 1; | 582 | h->c.block_last_index[n] = i - 1; |
| 584 | return 0; | 583 | return 0; |
| 585 | } | 584 | } |
| 586 | retry: | 585 | retry: |
| 587 | { | 586 | { |
| 588 | OPEN_READER(re, &s->gb); | 587 | OPEN_READER(re, &h->c.gb); |
| 589 | i--; // offset by -1 to allow direct indexing of scan_table | 588 | i--; // offset by -1 to allow direct indexing of scan_table |
| 590 | for(;;) { | 589 | for(;;) { |
| 591 | UPDATE_CACHE(re, &s->gb); | 590 | UPDATE_CACHE(re, &h->c.gb); |
| 592 | GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | 591 | GET_RL_VLC(level, run, re, &h->c.gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
| 593 | if (run == 66) { | 592 | if (run == 66) { |
| 594 | if (level){ | 593 | if (level){ |
| 595 | CLOSE_READER(re, &s->gb); | 594 | CLOSE_READER(re, &h->c.gb); |
| 596 | av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); | 595 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", |
| 596 | h->c.mb_x, h->c.mb_y); | ||
| 597 | return -1; | 597 | return -1; |
| 598 | } | 598 | } |
| 599 | /* escape */ | 599 | /* escape */ |
| 600 | if (CONFIG_FLV_DECODER && s->h263_flv > 1) { | 600 | if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) { |
| 601 | int is11 = SHOW_UBITS(re, &s->gb, 1); | 601 | int is11 = SHOW_UBITS(re, &h->c.gb, 1); |
| 602 | SKIP_CACHE(re, &s->gb, 1); | 602 | SKIP_CACHE(re, &h->c.gb, 1); |
| 603 | run = SHOW_UBITS(re, &s->gb, 7) + 1; | 603 | run = SHOW_UBITS(re, &h->c.gb, 7) + 1; |
| 604 | if (is11) { | 604 | if (is11) { |
| 605 | SKIP_COUNTER(re, &s->gb, 1 + 7); | 605 | SKIP_COUNTER(re, &h->c.gb, 1 + 7); |
| 606 | UPDATE_CACHE(re, &s->gb); | 606 | UPDATE_CACHE(re, &h->c.gb); |
| 607 | level = SHOW_SBITS(re, &s->gb, 11); | 607 | level = SHOW_SBITS(re, &h->c.gb, 11); |
| 608 | SKIP_COUNTER(re, &s->gb, 11); | 608 | SKIP_COUNTER(re, &h->c.gb, 11); |
| 609 | } else { | 609 | } else { |
| 610 | SKIP_CACHE(re, &s->gb, 7); | 610 | SKIP_CACHE(re, &h->c.gb, 7); |
| 611 | level = SHOW_SBITS(re, &s->gb, 7); | 611 | level = SHOW_SBITS(re, &h->c.gb, 7); |
| 612 | SKIP_COUNTER(re, &s->gb, 1 + 7 + 7); | 612 | SKIP_COUNTER(re, &h->c.gb, 1 + 7 + 7); |
| 613 | } | 613 | } |
| 614 | } else { | 614 | } else { |
| 615 | run = SHOW_UBITS(re, &s->gb, 7) + 1; | 615 | run = SHOW_UBITS(re, &h->c.gb, 7) + 1; |
| 616 | SKIP_CACHE(re, &s->gb, 7); | 616 | SKIP_CACHE(re, &h->c.gb, 7); |
| 617 | level = (int8_t)SHOW_UBITS(re, &s->gb, 8); | 617 | level = (int8_t)SHOW_UBITS(re, &h->c.gb, 8); |
| 618 | SKIP_COUNTER(re, &s->gb, 7 + 8); | 618 | SKIP_COUNTER(re, &h->c.gb, 7 + 8); |
| 619 | if(level == -128){ | 619 | if(level == -128){ |
| 620 | UPDATE_CACHE(re, &s->gb); | 620 | UPDATE_CACHE(re, &h->c.gb); |
| 621 | if (s->codec_id == AV_CODEC_ID_RV10) { | 621 | if (h->c.codec_id == AV_CODEC_ID_RV10) { |
| 622 | /* XXX: should patch encoder too */ | 622 | /* XXX: should patch encoder too */ |
| 623 | level = SHOW_SBITS(re, &s->gb, 12); | 623 | level = SHOW_SBITS(re, &h->c.gb, 12); |
| 624 | SKIP_COUNTER(re, &s->gb, 12); | 624 | SKIP_COUNTER(re, &h->c.gb, 12); |
| 625 | }else{ | 625 | }else{ |
| 626 | level = SHOW_UBITS(re, &s->gb, 5); | 626 | level = SHOW_UBITS(re, &h->c.gb, 5); |
| 627 | SKIP_CACHE(re, &s->gb, 5); | 627 | SKIP_CACHE(re, &h->c.gb, 5); |
| 628 | level |= SHOW_SBITS(re, &s->gb, 6) * (1<<5); | 628 | level |= SHOW_SBITS(re, &h->c.gb, 6) * (1<<5); |
| 629 | SKIP_COUNTER(re, &s->gb, 5 + 6); | 629 | SKIP_COUNTER(re, &h->c.gb, 5 + 6); |
| 630 | } | 630 | } |
| 631 | } | 631 | } |
| 632 | } | 632 | } |
| 633 | } else { | 633 | } else { |
| 634 | if (SHOW_UBITS(re, &s->gb, 1)) | 634 | if (SHOW_UBITS(re, &h->c.gb, 1)) |
| 635 | level = -level; | 635 | level = -level; |
| 636 | SKIP_COUNTER(re, &s->gb, 1); | 636 | SKIP_COUNTER(re, &h->c.gb, 1); |
| 637 | } | 637 | } |
| 638 | i += run; | 638 | i += run; |
| 639 | if (i >= 64){ | 639 | if (i >= 64){ |
| 640 | CLOSE_READER(re, &s->gb); | 640 | CLOSE_READER(re, &h->c.gb); |
| 641 | // redo update without last flag, revert -1 offset | 641 | // redo update without last flag, revert -1 offset |
| 642 | i = i - run + ((run-1)&63) + 1; | 642 | i = i - run + ((run-1)&63) + 1; |
| 643 | if (i < 64) { | 643 | if (i < 64) { |
| @@ -645,48 +645,49 @@ retry: · 1 unmodified line | |||
| 645 | block[scan_table[i]] = level; | 645 | block[scan_table[i]] = level; |
| 646 | break; | 646 | break; |
| 647 | } | 647 | } |
| 648 | if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){ | 648 | if(h->c.alt_inter_vlc && rl == &ff_h263_rl_inter && !h->c.mb_intra){ |
| 649 | //Looks like a hack but no, it's the way it is supposed to work ... | 649 | //Looks like a hack but no, it's the way it is supposed to work ... |
| 650 | rl = &ff_rl_intra_aic; | 650 | rl = &ff_rl_intra_aic; |
| 651 | i = 0; | 651 | i = 0; |
| 652 | s->gb= gb; | 652 | h->c.gb = gb; |
| 653 | s->bdsp.clear_block(block); | 653 | h->c.bdsp.clear_block(block); |
| 654 | goto retry; | 654 | goto retry; |
| 655 | } | 655 | } |
| 656 | av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); | 656 | av_log(h->c.avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", |
| 657 | h->c.mb_x, h->c.mb_y, h->c.mb_intra); | ||
| 657 | return -1; | 658 | return -1; |
| 658 | } | 659 | } |
| 659 | j = scan_table[i]; | 660 | j = scan_table[i]; |
| 660 | block[j] = level; | 661 | block[j] = level; |
| 661 | } | 662 | } |
| 662 | } | 663 | } |
| 663 | if (s->mb_intra && s->h263_aic) { | 664 | if (h->c.mb_intra && h->c.h263_aic) { |
| 664 | not_coded: | 665 | not_coded: |
| 665 | h263_pred_acdc(s, block, n); | 666 | h263_pred_acdc(&h->c, block, n); |
| 666 | } | 667 | } |
| 667 | s->block_last_index[n] = i; | 668 | h->c.block_last_index[n] = i; |
| 668 | return 0; | 669 | return 0; |
| 669 | } | 670 | } |
| 670 | 671 | ||
| 671 | static int h263_skip_b_part(MpegEncContext *s, int cbp) | 672 | static int h263_skip_b_part(H263DecContext *const h, int cbp) |
| 672 | { | 673 | { |
| 673 | LOCAL_ALIGNED_32(int16_t, dblock, [64]); | 674 | LOCAL_ALIGNED_32(int16_t, dblock, [64]); |
| 674 | int i, mbi; | 675 | int i, mbi; |
| 675 | int bli[6]; | 676 | int bli[6]; |
| 676 | 677 | ||
| 677 | /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly | 678 | /* we have to set h->c.mb_intra to zero to decode B-part of PB-frame correctly |
| 678 | * but real value should be restored in order to be used later (in OBMC condition) | 679 | * but real value should be restored in order to be used later (in OBMC condition) |
| 679 | */ | 680 | */ |
| 680 | mbi = s->mb_intra; | 681 | mbi = h->c.mb_intra; |
| 681 | memcpy(bli, s->block_last_index, sizeof(bli)); | 682 | memcpy(bli, h->c.block_last_index, sizeof(bli)); |
| 682 | s->mb_intra = 0; | 683 | h->c.mb_intra = 0; |
| 683 | for (i = 0; i < 6; i++) { | 684 | for (i = 0; i < 6; i++) { |
| 684 | if (h263_decode_block(s, dblock, i, cbp&32) < 0) | 685 | if (h263_decode_block(h, dblock, i, cbp&32) < 0) |
| 685 | return -1; | 686 | return -1; |
| 686 | cbp+=cbp; | 687 | cbp+=cbp; |
| 687 | } | 688 | } |
| 688 | s->mb_intra = mbi; | 689 | h->c.mb_intra = mbi; |
| 689 | memcpy(s->block_last_index, bli, sizeof(bli)); | 690 | memcpy(h->c.block_last_index, bli, sizeof(bli)); |
| 690 | return 0; | 691 | return 0; |
| 691 | } | 692 | } |
| 692 | 693 | ||
| @@ -775,119 +776,121 @@ static int set_direct_mv(MpegEncContext *s) · 82 unmodified lines | |||
| 775 | } | 776 | } |
| 776 | } | 777 | } |
| 777 | 778 | ||
| 778 | int ff_h263_decode_mb(MpegEncContext *s, | 779 | int ff_h263_decode_mb(H263DecContext *const h, int16_t block[6][64]) |
| 779 | int16_t block[6][64]) | ||
| 780 | { | 780 | { |
| 781 | int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | 781 | int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; |
| 782 | int16_t *mot_val; | 782 | int16_t *mot_val; |
| 783 | const int xy= s->mb_x + s->mb_y * s->mb_stride; | 783 | const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; |
| 784 | int cbpb = 0, pb_mv_count = 0; | 784 | int cbpb = 0, pb_mv_count = 0; |
| 785 | 785 | ||
| 786 | av_assert2(!s->h263_pred); | 786 | av_assert2(!h->c.h263_pred); |
| 787 | 787 | ||
| 788 | if (s->pict_type == AV_PICTURE_TYPE_P) { | 788 | if (h->c.pict_type == AV_PICTURE_TYPE_P) { |
| 789 | do{ | 789 | do{ |
| 790 | if (get_bits1(&s->gb)) { | 790 | if (get_bits1(&h->c.gb)) { |
| 791 | /* skip mb */ | 791 | /* skip mb */ |
| 792 | s->mb_intra = 0; | 792 | h->c.mb_intra = 0; |
| 793 | for(i=0;i<6;i++) | 793 | for(i=0;i<6;i++) |
| 794 | s->block_last_index[i] = -1; | 794 | h->c.block_last_index[i] = -1; |
| 795 | s->mv_dir = MV_DIR_FORWARD; | 795 | h->c.mv_dir = MV_DIR_FORWARD; |
| 796 | s->mv_type = MV_TYPE_16X16; | 796 | h->c.mv_type = MV_TYPE_16X16; |
| 797 | s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 797 | h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 798 | s->mv[0][0][0] = 0; | 798 | h->c.mv[0][0][0] = 0; |
| 799 | s->mv[0][0][1] = 0; | 799 | h->c.mv[0][0][1] = 0; |
| 800 | s->mb_skipped = !(s->obmc | s->loop_filter); | 800 | h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter); |
| 801 | goto end; | 801 | goto end; |
| 802 | } | 802 | } |
| 803 | cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); | 803 | cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); |
| 804 | if (cbpc < 0){ | 804 | if (cbpc < 0){ |
| 805 | av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); | 805 | av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", |
| 806 | h->c.mb_x, h->c.mb_y); | ||
| 806 | return SLICE_ERROR; | 807 | return SLICE_ERROR; |
| 807 | } | 808 | } |
| 808 | }while(cbpc == 20); | 809 | }while(cbpc == 20); |
| 809 | 810 | ||
| 810 | s->bdsp.clear_blocks(s->block[0]); | 811 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 811 | 812 | ||
| 812 | dquant = cbpc & 8; | 813 | dquant = cbpc & 8; |
| 813 | s->mb_intra = ((cbpc & 4) != 0); | 814 | h->c.mb_intra = ((cbpc & 4) != 0); |
| 814 | if (s->mb_intra) goto intra; | 815 | if (h->c.mb_intra) |
| 816 | goto intra; | ||
| 815 | 817 | ||
| 816 | if(s->pb_frame && get_bits1(&s->gb)) | 818 | if(h->c.pb_frame && get_bits1(&h->c.gb)) |
| 817 | pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); | 819 | pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb); |
| 818 | cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 820 | cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 819 | 821 | ||
| 820 | if (cbpy < 0) { | 822 | if (cbpy < 0) { |
| 821 | av_log(s->avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | 823 | av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n", |
| 824 | h->c.mb_x, h->c.mb_y); | ||
| 822 | return SLICE_ERROR; | 825 | return SLICE_ERROR; |
| 823 | } | 826 | } |
| 824 | 827 | ||
| 825 | if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) | 828 | if (!h->c.alt_inter_vlc|| (cbpc & 3)!=3) |
| 826 | cbpy ^= 0xF; | 829 | cbpy ^= 0xF; |
| 827 | 830 | ||
| 828 | cbp = (cbpc & 3) | (cbpy << 2); | 831 | cbp = (cbpc & 3) | (cbpy << 2); |
| 829 | if (dquant) { | 832 | if (dquant) { |
| 830 | h263_decode_dquant(s); | 833 | h263_decode_dquant(h); |
| 831 | } | 834 | } |
| 832 | 835 | ||
| 833 | s->mv_dir = MV_DIR_FORWARD; | 836 | h->c.mv_dir = MV_DIR_FORWARD; |
| 834 | if ((cbpc & 16) == 0) { | 837 | if ((cbpc & 16) == 0) { |
| 835 | s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 838 | h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 836 | /* 16x16 motion prediction */ | 839 | /* 16x16 motion prediction */ |
| 837 | s->mv_type = MV_TYPE_16X16; | 840 | h->c.mv_type = MV_TYPE_16X16; |
| 838 | ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | 841 | ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); |
| 839 | if (s->umvplus) | 842 | if (h->c.umvplus) |
| 840 | mx = h263p_decode_umotion(s, pred_x); | 843 | mx = h263p_decode_umotion(h, pred_x); |
| 841 | else | 844 | else |
| 842 | mx = ff_h263_decode_motion(s, pred_x, 1); | 845 | mx = ff_h263_decode_motion(h, pred_x, 1); |
| 843 | 846 | ||
| 844 | if (mx >= 0xffff) | 847 | if (mx >= 0xffff) |
| 845 | return SLICE_ERROR; | 848 | return SLICE_ERROR; |
| 846 | 849 | ||
| 847 | if (s->umvplus) | 850 | if (h->c.umvplus) |
| 848 | my = h263p_decode_umotion(s, pred_y); | 851 | my = h263p_decode_umotion(h, pred_y); |
| 849 | else | 852 | else |
| 850 | my = ff_h263_decode_motion(s, pred_y, 1); | 853 | my = ff_h263_decode_motion(h, pred_y, 1); |
| 851 | 854 | ||
| 852 | if (my >= 0xffff) | 855 | if (my >= 0xffff) |
| 853 | return SLICE_ERROR; | 856 | return SLICE_ERROR; |
| 854 | s->mv[0][0][0] = mx; | 857 | h->c.mv[0][0][0] = mx; |
| 855 | s->mv[0][0][1] = my; | 858 | h->c.mv[0][0][1] = my; |
| 856 | 859 | ||
| 857 | if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | 860 | if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 858 | skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 861 | skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ |
| 859 | } else { | 862 | } else { |
| 860 | s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; | 863 | h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; |
| 861 | s->mv_type = MV_TYPE_8X8; | 864 | h->c.mv_type = MV_TYPE_8X8; |
| 862 | for(i=0;i<4;i++) { | 865 | for(i=0;i<4;i++) { |
| 863 | mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | 866 | mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); |
| 864 | if (s->umvplus) | 867 | if (h->c.umvplus) |
| 865 | mx = h263p_decode_umotion(s, pred_x); | 868 | mx = h263p_decode_umotion(h, pred_x); |
| 866 | else | 869 | else |
| 867 | mx = ff_h263_decode_motion(s, pred_x, 1); | 870 | mx = ff_h263_decode_motion(h, pred_x, 1); |
| 868 | if (mx >= 0xffff) | 871 | if (mx >= 0xffff) |
| 869 | return SLICE_ERROR; | 872 | return SLICE_ERROR; |
| 870 | 873 | ||
| 871 | if (s->umvplus) | 874 | if (h->c.umvplus) |
| 872 | my = h263p_decode_umotion(s, pred_y); | 875 | my = h263p_decode_umotion(h, pred_y); |
| 873 | else | 876 | else |
| 874 | my = ff_h263_decode_motion(s, pred_y, 1); | 877 | my = ff_h263_decode_motion(h, pred_y, 1); |
| 875 | if (my >= 0xffff) | 878 | if (my >= 0xffff) |
| 876 | return SLICE_ERROR; | 879 | return SLICE_ERROR; |
| 877 | s->mv[0][i][0] = mx; | 880 | h->c.mv[0][i][0] = mx; |
| 878 | s->mv[0][i][1] = my; | 881 | h->c.mv[0][i][1] = my; |
| 879 | if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | 882 | if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 880 | skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 883 | skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ |
| 881 | mot_val[0] = mx; | 884 | mot_val[0] = mx; |
| 882 | mot_val[1] = my; | 885 | mot_val[1] = my; |
| 883 | } | 886 | } |
| 884 | } | 887 | } |
| 885 | } else if(s->pict_type==AV_PICTURE_TYPE_B) { | 888 | } else if (h->c.pict_type==AV_PICTURE_TYPE_B) { |
| 886 | int mb_type; | 889 | int mb_type; |
| 887 | const int stride= s->b8_stride; | 890 | const int stride = h->c.b8_stride; |
| 888 | int16_t *mot_val0 = s->cur_pic.motion_val[0][2 * (s->mb_x + s->mb_y * stride)]; | 891 | int16_t *mot_val0 = h->c.cur_pic.motion_val[0][2 * (h->c.mb_x + h->c.mb_y * stride)]; |
| 889 | int16_t *mot_val1 = s->cur_pic.motion_val[1][2 * (s->mb_x + s->mb_y * stride)]; | 892 | int16_t *mot_val1 = h->c.cur_pic.motion_val[1][2 * (h->c.mb_x + h->c.mb_y * stride)]; |
| 890 | // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; | 893 | // const int mv_xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride; |
| 891 | 894 | ||
| 892 | //FIXME ugly | 895 | //FIXME ugly |
| 893 | mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= | 896 | mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= |
| @@ -896,176 +899,181 @@ int ff_h263_decode_mb(MpegEncContext *s, · 2 unmodified lines | |||
| 896 | mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; | 899 | mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; |
| 897 | 900 | ||
| 898 | do{ | 901 | do{ |
| 899 | mb_type = get_vlc2(&s->gb, h263_mbtype_b_vlc, | 902 | mb_type = get_vlc2(&h->c.gb, h263_mbtype_b_vlc, |
| 900 | H263_MBTYPE_B_VLC_BITS, 2); | 903 | H263_MBTYPE_B_VLC_BITS, 2); |
| 901 | if (mb_type < 0){ | 904 | if (mb_type < 0){ |
| 902 | av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); | 905 | av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", |
| 906 | h->c.mb_x, h->c.mb_y); | ||
| 903 | return SLICE_ERROR; | 907 | return SLICE_ERROR; |
| 904 | } | 908 | } |
| 905 | }while(!mb_type); | 909 | }while(!mb_type); |
| 906 | 910 | ||
| 907 | s->mb_intra = IS_INTRA(mb_type); | 911 | h->c.mb_intra = IS_INTRA(mb_type); |
| 908 | if(HAS_CBP(mb_type)){ | 912 | if(HAS_CBP(mb_type)){ |
| 909 | s->bdsp.clear_blocks(s->block[0]); | 913 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 910 | cbpc = get_vlc2(&s->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1); | 914 | cbpc = get_vlc2(&h->c.gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1); |
| 911 | if(s->mb_intra){ | 915 | if (h->c.mb_intra) { |
| 912 | dquant = IS_QUANT(mb_type); | 916 | dquant = IS_QUANT(mb_type); |
| 913 | goto intra; | 917 | goto intra; |
| 914 | } | 918 | } |
| 915 | 919 | ||
| 916 | cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 920 | cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 917 | 921 | ||
| 918 | if (cbpy < 0){ | 922 | if (cbpy < 0){ |
| 919 | av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | 923 | av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", |
| 924 | h->c.mb_x, h->c.mb_y); | ||
| 920 | return SLICE_ERROR; | 925 | return SLICE_ERROR; |
| 921 | } | 926 | } |
| 922 | 927 | ||
| 923 | if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) | 928 | if (!h->c.alt_inter_vlc || (cbpc & 3)!=3) |
| 924 | cbpy ^= 0xF; | 929 | cbpy ^= 0xF; |
| 925 | 930 | ||
| 926 | cbp = (cbpc & 3) | (cbpy << 2); | 931 | cbp = (cbpc & 3) | (cbpy << 2); |
| 927 | }else | 932 | }else |
| 928 | cbp=0; | 933 | cbp=0; |
| 929 | 934 | ||
| 930 | av_assert2(!s->mb_intra); | 935 | av_assert2(!h->c.mb_intra); |
| 931 | 936 | ||
| 932 | if(IS_QUANT(mb_type)){ | 937 | if(IS_QUANT(mb_type)){ |
| 933 | h263_decode_dquant(s); | 938 | h263_decode_dquant(h); |
| 934 | } | 939 | } |
| 935 | 940 | ||
| 936 | if(IS_DIRECT(mb_type)){ | 941 | if(IS_DIRECT(mb_type)){ |
| 937 | s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | 942 | h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
| 938 | mb_type |= set_direct_mv(s); | 943 | mb_type |= set_direct_mv(&h->c); |
| 939 | }else{ | 944 | }else{ |
| 940 | s->mv_dir = 0; | 945 | h->c.mv_dir = 0; |
| 941 | s->mv_type= MV_TYPE_16X16; | 946 | h->c.mv_type = MV_TYPE_16X16; |
| 942 | //FIXME UMV | 947 | //FIXME UMV |
| 943 | 948 | ||
| 944 | if (HAS_FORWARD_MV(mb_type)) { | 949 | if (HAS_FORWARD_MV(mb_type)) { |
| 945 | int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | 950 | int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); |
| 946 | s->mv_dir = MV_DIR_FORWARD; | 951 | h->c.mv_dir = MV_DIR_FORWARD; |
| 947 | 952 | ||
| 948 | if (s->umvplus) | 953 | if (h->c.umvplus) |
| 949 | mx = h263p_decode_umotion(s, pred_x); | 954 | mx = h263p_decode_umotion(h, pred_x); |
| 950 | else | 955 | else |
| 951 | mx = ff_h263_decode_motion(s, pred_x, 1); | 956 | mx = ff_h263_decode_motion(h, pred_x, 1); |
| 952 | if (mx >= 0xffff) | 957 | if (mx >= 0xffff) |
| 953 | return SLICE_ERROR; | 958 | return SLICE_ERROR; |
| 954 | 959 | ||
| 955 | if (s->umvplus) | 960 | if (h->c.umvplus) |
| 956 | my = h263p_decode_umotion(s, pred_y); | 961 | my = h263p_decode_umotion(h, pred_y); |
| 957 | else | 962 | else |
| 958 | my = ff_h263_decode_motion(s, pred_y, 1); | 963 | my = ff_h263_decode_motion(h, pred_y, 1); |
| 959 | if (my >= 0xffff) | 964 | if (my >= 0xffff) |
| 960 | return SLICE_ERROR; | 965 | return SLICE_ERROR; |
| 961 | 966 | ||
| 962 | if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | 967 | if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 963 | skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 968 | skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ |
| 964 | 969 | ||
| 965 | s->mv[0][0][0] = mx; | 970 | h->c.mv[0][0][0] = mx; |
| 966 | s->mv[0][0][1] = my; | 971 | h->c.mv[0][0][1] = my; |
| 967 | mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; | 972 | mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
| 968 | mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; | 973 | mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; |
| 969 | } | 974 | } |
| 970 | 975 | ||
| 971 | if (HAS_BACKWARD_MV(mb_type)) { | 976 | if (HAS_BACKWARD_MV(mb_type)) { |
| 972 | int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y); | 977 | int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y); |
| 973 | s->mv_dir |= MV_DIR_BACKWARD; | 978 | h->c.mv_dir |= MV_DIR_BACKWARD; |
| 974 | 979 | ||
| 975 | if (s->umvplus) | 980 | if (h->c.umvplus) |
| 976 | mx = h263p_decode_umotion(s, pred_x); | 981 | mx = h263p_decode_umotion(h, pred_x); |
| 977 | else | 982 | else |
| 978 | mx = ff_h263_decode_motion(s, pred_x, 1); | 983 | mx = ff_h263_decode_motion(h, pred_x, 1); |
| 979 | if (mx >= 0xffff) | 984 | if (mx >= 0xffff) |
| 980 | return SLICE_ERROR; | 985 | return SLICE_ERROR; |
| 981 | 986 | ||
| 982 | if (s->umvplus) | 987 | if (h->c.umvplus) |
| 983 | my = h263p_decode_umotion(s, pred_y); | 988 | my = h263p_decode_umotion(h, pred_y); |
| 984 | else | 989 | else |
| 985 | my = ff_h263_decode_motion(s, pred_y, 1); | 990 | my = ff_h263_decode_motion(h, pred_y, 1); |
| 986 | if (my >= 0xffff) | 991 | if (my >= 0xffff) |
| 987 | return SLICE_ERROR; | 992 | return SLICE_ERROR; |
| 988 | 993 | ||
| 989 | if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | 994 | if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 990 | skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 995 | skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ |
| 991 | 996 | ||
| 992 | s->mv[1][0][0] = mx; | 997 | h->c.mv[1][0][0] = mx; |
| 993 | s->mv[1][0][1] = my; | 998 | h->c.mv[1][0][1] = my; |
| 994 | mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; | 999 | mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
| 995 | mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; | 1000 | mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; |
| 996 | } | 1001 | } |
| 997 | } | 1002 | } |
| 998 | 1003 | ||
| 999 | s->cur_pic.mb_type[xy] = mb_type; | 1004 | h->c.cur_pic.mb_type[xy] = mb_type; |
| 1000 | } else { /* I-Frame */ | 1005 | } else { /* I-Frame */ |
| 1001 | do{ | 1006 | do{ |
| 1002 | cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); | 1007 | cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); |
| 1003 | if (cbpc < 0){ | 1008 | if (cbpc < 0){ |
| 1004 | av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); | 1009 | av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", |
| 1010 | h->c.mb_x, h->c.mb_y); | ||
| 1005 | return SLICE_ERROR; | 1011 | return SLICE_ERROR; |
| 1006 | } | 1012 | } |
| 1007 | }while(cbpc == 8); | 1013 | }while(cbpc == 8); |
| 1008 | 1014 | ||
| 1009 | s->bdsp.clear_blocks(s->block[0]); | 1015 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 1010 | 1016 | ||
| 1011 | dquant = cbpc & 4; | 1017 | dquant = cbpc & 4; |
| 1012 | s->mb_intra = 1; | 1018 | h->c.mb_intra = 1; |
| 1013 | intra: | 1019 | intra: |
| 1014 | s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | 1020 | h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; |
| 1015 | if (s->h263_aic) { | 1021 | if (h->c.h263_aic) { |
| 1016 | s->ac_pred = get_bits1(&s->gb); | 1022 | h->c.ac_pred = get_bits1(&h->c.gb); |
| 1017 | if(s->ac_pred){ | 1023 | if (h->c.ac_pred) { |
| 1018 | s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; | 1024 | h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; |
| 1019 | 1025 | ||
| 1020 | s->h263_aic_dir = get_bits1(&s->gb); | 1026 | h->c.h263_aic_dir = get_bits1(&h->c.gb); |
| 1021 | } | 1027 | } |
| 1022 | }else | 1028 | }else |
| 1023 | s->ac_pred = 0; | 1029 | h->c.ac_pred = 0; |
| 1024 | 1030 | ||
| 1025 | if(s->pb_frame && get_bits1(&s->gb)) | 1031 | if (h->c.pb_frame && get_bits1(&h->c.gb)) |
| 1026 | pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); | 1032 | pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb); |
| 1027 | cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 1033 | cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 1028 | if(cbpy<0){ | 1034 | if(cbpy<0){ |
| 1029 | av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | 1035 | av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", |
| 1036 | h->c.mb_x, h->c.mb_y); | ||
| 1030 | return SLICE_ERROR; | 1037 | return SLICE_ERROR; |
| 1031 | } | 1038 | } |
| 1032 | cbp = (cbpc & 3) | (cbpy << 2); | 1039 | cbp = (cbpc & 3) | (cbpy << 2); |
| 1033 | if (dquant) { | 1040 | if (dquant) { |
| 1034 | h263_decode_dquant(s); | 1041 | h263_decode_dquant(h); |
| 1035 | } | 1042 | } |
| 1036 | 1043 | ||
| 1037 | pb_mv_count += !!s->pb_frame; | 1044 | pb_mv_count += !!h->c.pb_frame; |
| 1038 | } | 1045 | } |
| 1039 | 1046 | ||
| 1040 | while(pb_mv_count--){ | 1047 | while(pb_mv_count--){ |
| 1041 | ff_h263_decode_motion(s, 0, 1); | 1048 | ff_h263_decode_motion(h, 0, 1); |
| 1042 | ff_h263_decode_motion(s, 0, 1); | 1049 | ff_h263_decode_motion(h, 0, 1); |
| 1043 | } | 1050 | } |
| 1044 | 1051 | ||
| 1045 | /* decode each block */ | 1052 | /* decode each block */ |
| 1046 | for (i = 0; i < 6; i++) { | 1053 | for (i = 0; i < 6; i++) { |
| 1047 | if (h263_decode_block(s, block[i], i, cbp&32) < 0) | 1054 | if (h263_decode_block(h, block[i], i, cbp&32) < 0) |
| 1048 | return -1; | 1055 | return -1; |
| 1049 | cbp+=cbp; | 1056 | cbp+=cbp; |
| 1050 | } | 1057 | } |
| 1051 | 1058 | ||
| 1052 | if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) | 1059 | if (h->c.pb_frame && h263_skip_b_part(h, cbpb) < 0) |
| 1053 | return -1; | 1060 | return -1; |
| 1054 | if(s->obmc && !s->mb_intra){ | 1061 | if (h->c.obmc && !h->c.mb_intra) { |
| 1055 | if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1) | 1062 | if (h->c.pict_type == AV_PICTURE_TYPE_P && |
| 1056 | preview_obmc(s); | 1063 | h->c.mb_x + 1 < h->c.mb_width && h->c.mb_num_left != 1) |
| 1064 | preview_obmc(h); | ||
| 1057 | } | 1065 | } |
| 1058 | end: | 1066 | end: |
| 1059 | 1067 | ||
| 1060 | if (get_bits_left(&s->gb) < 0) | 1068 | if (get_bits_left(&h->c.gb) < 0) |
| 1061 | return AVERROR_INVALIDDATA; | 1069 | return AVERROR_INVALIDDATA; |
| 1062 | 1070 | ||
| 1063 | /* per-MB end of slice check */ | 1071 | /* per-MB end of slice check */ |
| 1064 | { | 1072 | { |
| 1065 | int v= show_bits(&s->gb, 16); | 1073 | int v = show_bits(&h->c.gb, 16); |
| 1066 | 1074 | ||
| 1067 | if (get_bits_left(&s->gb) < 16) { | 1075 | if (get_bits_left(&h->c.gb) < 16) { |
| 1068 | v >>= 16 - get_bits_left(&s->gb); | 1076 | v >>= 16 - get_bits_left(&h->c.gb); |
| 1069 | } | 1077 | } |
| 1070 | 1078 | ||
| 1071 | if(v==0) | 1079 | if(v==0) |
| @@ -1076,51 +1084,50 @@ end: · 4 unmodified lines | |||
| 1076 | } | 1084 | } |
| 1077 | 1085 | ||
| 1078 | /* Most is hardcoded; should extend to handle all H.263 streams. */ | 1086 | /* Most is hardcoded; should extend to handle all H.263 streams. */ |
| 1079 | int ff_h263_decode_picture_header(MpegEncContext *s) | 1087 | int ff_h263_decode_picture_header(H263DecContext *const h) |
| 1080 | { | 1088 | { |
| 1081 | int format, width, height, i, ret; | 1089 | int width, height, i, ret; |
| 1082 | uint32_t startcode; | ||
| 1083 | int h263_plus; | 1090 | int h263_plus; |
| 1084 | 1091 | ||
| 1085 | align_get_bits(&s->gb); | 1092 | align_get_bits(&h->c.gb); |
| 1086 | 1093 | ||
| 1087 | if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_num == 0) { | 1094 | if (show_bits(&h->c.gb, 2) == 2 && h->c.avctx->frame_num == 0) { |
| 1088 | av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n"); | 1095 | av_log(h->c.avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n"); |
| 1089 | } | 1096 | } |
| 1090 | 1097 | ||
| 1091 | startcode= get_bits(&s->gb, 22-8); | 1098 | uint32_t startcode = get_bits(&h->c.gb, 22-8); |
| 1092 | 1099 | ||
| 1093 | for(i= get_bits_left(&s->gb); i>24; i-=8) { | 1100 | for (i = get_bits_left(&h->c.gb); i>24; i -= 8) { |
| 1094 | startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF; | 1101 | startcode = ((startcode << 8) | get_bits(&h->c.gb, 8)) & 0x003FFFFF; |
| 1095 | 1102 | ||
| 1096 | if(startcode == 0x20) | 1103 | if(startcode == 0x20) |
| 1097 | break; | 1104 | break; |
| 1098 | } | 1105 | } |
| 1099 | 1106 | ||
| 1100 | if (startcode != 0x20) { | 1107 | if (startcode != 0x20) { |
| 1101 | av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); | 1108 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
| 1102 | return -1; | 1109 | return -1; |
| 1103 | } | 1110 | } |
| 1104 | /* temporal reference */ | 1111 | /* temporal reference */ |
| 1105 | i = get_bits(&s->gb, 8); /* picture timestamp */ | 1112 | i = get_bits(&h->c.gb, 8); /* picture timestamp */ |
| 1106 | 1113 | ||
| 1107 | i -= (i - (s->picture_number & 0xFF) + 128) & ~0xFF; | 1114 | i -= (i - (h->c.picture_number & 0xFF) + 128) & ~0xFF; |
| 1108 | 1115 | ||
| 1109 | s->picture_number= (s->picture_number&~0xFF) + i; | 1116 | h->c.picture_number = (h->c.picture_number&~0xFF) + i; |
| 1110 | 1117 | ||
| 1111 | /* PTYPE starts here */ | 1118 | /* PTYPE starts here */ |
| 1112 | if (check_marker(s->avctx, &s->gb, "in PTYPE") != 1) { | 1119 | if (check_marker(h->c.avctx, &h->c.gb, "in PTYPE") != 1) { |
| 1113 | return -1; | 1120 | return -1; |
| 1114 | } | 1121 | } |
| 1115 | if (get_bits1(&s->gb) != 0) { | 1122 | if (get_bits1(&h->c.gb) != 0) { |
| 1116 | av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n"); | 1123 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n"); |
| 1117 | return -1; /* H.263 id */ | 1124 | return -1; /* H.263 id */ |
| 1118 | } | 1125 | } |
| 1119 | skip_bits1(&s->gb); /* split screen off */ | 1126 | skip_bits1(&h->c.gb); /* split screen off */ |
| 1120 | skip_bits1(&s->gb); /* camera off */ | 1127 | skip_bits1(&h->c.gb); /* camera off */ |
| 1121 | skip_bits1(&s->gb); /* freeze picture release off */ | 1128 | skip_bits1(&h->c.gb); /* freeze picture release off */ |
| 1122 | 1129 | ||
| 1123 | format = get_bits(&s->gb, 3); | 1130 | int format = get_bits(&h->c.gb, 3); |
| 1124 | /* | 1131 | /* |
| 1125 | 0 forbidden | 1132 | 0 forbidden |
| 1126 | 1 sub-QCIF | 1133 | 1 sub-QCIF |
| @@ -1136,88 +1143,88 @@ int ff_h263_decode_picture_header(MpegEncContext *s) · 9 unmodified lines | |||
| 1136 | if (!width) | 1143 | if (!width) |
| 1137 | return -1; | 1144 | return -1; |
| 1138 | 1145 | ||
| 1139 | s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); | 1146 | h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb); |
| 1140 | 1147 | ||
| 1141 | s->h263_long_vectors = get_bits1(&s->gb); | 1148 | h->c.h263_long_vectors = get_bits1(&h->c.gb); |
| 1142 | 1149 | ||
| 1143 | if (get_bits1(&s->gb) != 0) { | 1150 | if (get_bits1(&h->c.gb) != 0) { |
| 1144 | av_log(s->avctx, AV_LOG_ERROR, "H.263 SAC not supported\n"); | 1151 | av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n"); |
| 1145 | return -1; /* SAC: off */ | 1152 | return -1; /* SAC: off */ |
| 1146 | } | 1153 | } |
| 1147 | s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ | 1154 | h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */ |
| 1148 | 1155 | ||
| 1149 | s->pb_frame = get_bits1(&s->gb); | 1156 | h->c.pb_frame = get_bits1(&h->c.gb); |
| 1150 | s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); | 1157 | h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); |
| 1151 | skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | 1158 | skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */ |
| 1152 | 1159 | ||
| 1153 | s->width = width; | 1160 | h->c.width = width; |
| 1154 | s->height = height; | 1161 | h->c.height = height; |
| 1155 | s->avctx->sample_aspect_ratio= (AVRational){12,11}; | 1162 | h->c.avctx->sample_aspect_ratio= (AVRational){12,11}; |
| 1156 | s->avctx->framerate = (AVRational){ 30000, 1001 }; | 1163 | h->c.avctx->framerate = (AVRational){ 30000, 1001 }; |
| 1157 | } else { | 1164 | } else { |
| 1158 | int ufep; | 1165 | int ufep; |
| 1159 | 1166 | ||
| 1160 | /* H.263v2 */ | 1167 | /* H.263v2 */ |
| 1161 | h263_plus = 1; | 1168 | h263_plus = 1; |
| 1162 | ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | 1169 | ufep = get_bits(&h->c.gb, 3); /* Update Full Extended PTYPE */ |
| 1163 | 1170 | ||
| 1164 | /* ufep other than 0 and 1 are reserved */ | 1171 | /* ufep other than 0 and 1 are reserved */ |
| 1165 | if (ufep == 1) { | 1172 | if (ufep == 1) { |
| 1166 | /* OPPTYPE */ | 1173 | /* OPPTYPE */ |
| 1167 | format = get_bits(&s->gb, 3); | 1174 | format = get_bits(&h->c.gb, 3); |
| 1168 | ff_dlog(s->avctx, "ufep=1, format: %d\n", format); | 1175 | ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format); |
| 1169 | s->custom_pcf= get_bits1(&s->gb); | 1176 | h->c.custom_pcf = get_bits1(&h->c.gb); |
| 1170 | s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */ | 1177 | h->c.umvplus = get_bits1(&h->c.gb); /* Unrestricted Motion Vector */ |
| 1171 | if (get_bits1(&s->gb) != 0) { | 1178 | if (get_bits1(&h->c.gb) != 0) { |
| 1172 | av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); | 1179 | av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); |
| 1173 | } | 1180 | } |
| 1174 | s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ | 1181 | h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */ |
| 1175 | s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ | 1182 | h->c.h263_aic = get_bits1(&h->c.gb); /* Advanced Intra Coding (AIC) */ |
| 1176 | s->loop_filter= get_bits1(&s->gb); | 1183 | h->c.loop_filter = get_bits1(&h->c.gb); |
| 1177 | if(s->avctx->lowres) | 1184 | if (h->c.avctx->lowres) |
| 1178 | s->loop_filter = 0; | 1185 | h->c.loop_filter = 0; |
| 1179 | 1186 | ||
| 1180 | s->h263_slice_structured= get_bits1(&s->gb); | 1187 | h->c.h263_slice_structured= get_bits1(&h->c.gb); |
| 1181 | if (get_bits1(&s->gb) != 0) { | 1188 | if (get_bits1(&h->c.gb) != 0) { |
| 1182 | av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); | 1189 | av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); |
| 1183 | } | 1190 | } |
| 1184 | if (get_bits1(&s->gb) != 0) { | 1191 | if (get_bits1(&h->c.gb) != 0) { |
| 1185 | av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); | 1192 | av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); |
| 1186 | } | 1193 | } |
| 1187 | s->alt_inter_vlc= get_bits1(&s->gb); | 1194 | h->c.alt_inter_vlc = get_bits1(&h->c.gb); |
| 1188 | s->modified_quant= get_bits1(&s->gb); | 1195 | h->c.modified_quant = get_bits1(&h->c.gb); |
| 1189 | if(s->modified_quant) | 1196 | if (h->c.modified_quant) |
| 1190 | s->chroma_qscale_table= ff_h263_chroma_qscale_table; | 1197 | h->c.chroma_qscale_table= ff_h263_chroma_qscale_table; |
| 1191 | 1198 | ||
| 1192 | skip_bits(&s->gb, 1); /* Prevent start code emulation */ | 1199 | skip_bits(&h->c.gb, 1); /* Prevent start code emulation */ |
| 1193 | 1200 | ||
| 1194 | skip_bits(&s->gb, 3); /* Reserved */ | 1201 | skip_bits(&h->c.gb, 3); /* Reserved */ |
| 1195 | } else if (ufep != 0) { | 1202 | } else if (ufep != 0) { |
| 1196 | av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep); | 1203 | av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep); |
| 1197 | return -1; | 1204 | return -1; |
| 1198 | } | 1205 | } |
| 1199 | 1206 | ||
| 1200 | /* MPPTYPE */ | 1207 | /* MPPTYPE */ |
| 1201 | s->pict_type = get_bits(&s->gb, 3); | 1208 | h->c.pict_type = get_bits(&h->c.gb, 3); |
| 1202 | switch(s->pict_type){ | 1209 | switch (h->c.pict_type) { |
| 1203 | case 0: s->pict_type= AV_PICTURE_TYPE_I;break; | 1210 | case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break; |
| 1204 | case 1: s->pict_type= AV_PICTURE_TYPE_P;break; | 1211 | case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break; |
| 1205 | case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break; | 1212 | case 2: h->c.pict_type = AV_PICTURE_TYPE_P; h->c.pb_frame = 3; break; |
| 1206 | case 3: s->pict_type= AV_PICTURE_TYPE_B;break; | 1213 | case 3: h->c.pict_type = AV_PICTURE_TYPE_B; break; |
| 1207 | case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO | 1214 | case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO |
| 1208 | default: | 1215 | default: |
| 1209 | return -1; | 1216 | return -1; |
| 1210 | } | 1217 | } |
| 1211 | skip_bits(&s->gb, 2); | 1218 | skip_bits(&h->c.gb, 2); |
| 1212 | s->no_rounding = get_bits1(&s->gb); | 1219 | h->c.no_rounding = get_bits1(&h->c.gb); |
| 1213 | skip_bits(&s->gb, 4); | 1220 | skip_bits(&h->c.gb, 4); |
| 1214 | 1221 | ||
| 1215 | /* Get the picture dimensions */ | 1222 | /* Get the picture dimensions */ |
| 1216 | if (ufep) { | 1223 | if (ufep) { |
| 1217 | if (format == 6) { | 1224 | if (format == 6) { |
| 1218 | /* Custom Picture Format (CPFMT) */ | 1225 | /* Custom Picture Format (CPFMT) */ |
| 1219 | int aspect_ratio_info = get_bits(&s->gb, 4); | 1226 | int aspect_ratio_info = get_bits(&h->c.gb, 4); |
| 1220 | ff_dlog(s->avctx, "aspect: %d\n", aspect_ratio_info); | 1227 | ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info); |
| 1221 | /* aspect ratios: | 1228 | /* aspect ratios: |
| 1222 | 0 - forbidden | 1229 | 0 - forbidden |
| 1223 | 1 - 1:1 | 1230 | 1 - 1:1 |
| @@ -1227,153 +1234,151 @@ int ff_h263_decode_picture_header(MpegEncContext *s) · 3 unmodified lines | |||
| 1227 | 5 - 40:33 (525-type 16:9) | 1234 | 5 - 40:33 (525-type 16:9) |
| 1228 | 6-14 - reserved | 1235 | 6-14 - reserved |
| 1229 | */ | 1236 | */ |
| 1230 | width = (get_bits(&s->gb, 9) + 1) * 4; | 1237 | width = (get_bits(&h->c.gb, 9) + 1) * 4; |
| 1231 | check_marker(s->avctx, &s->gb, "in dimensions"); | 1238 | check_marker(h->c.avctx, &h->c.gb, "in dimensions"); |
| 1232 | height = get_bits(&s->gb, 9) * 4; | 1239 | height = get_bits(&h->c.gb, 9) * 4; |
| 1233 | ff_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); | 1240 | ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); |
| 1234 | if (aspect_ratio_info == FF_ASPECT_EXTENDED) { | 1241 | if (aspect_ratio_info == FF_ASPECT_EXTENDED) { |
| 1235 | /* expected dimensions */ | 1242 | /* expected dimensions */ |
| 1236 | s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8); | 1243 | h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); |
| 1237 | s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8); | 1244 | h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); |
| 1238 | }else{ | 1245 | }else{ |
| 1239 | s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info]; | 1246 | h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info]; |
| 1240 | } | 1247 | } |
| 1241 | } else { | 1248 | } else { |
| 1242 | width = ff_h263_format[format][0]; | 1249 | width = ff_h263_format[format][0]; |
| 1243 | height = ff_h263_format[format][1]; | 1250 | height = ff_h263_format[format][1]; |
| 1244 | s->avctx->sample_aspect_ratio= (AVRational){12,11}; | 1251 | h->c.avctx->sample_aspect_ratio = (AVRational){12,11}; |
| 1245 | } | 1252 | } |
| 1246 | s->avctx->sample_aspect_ratio.den <<= s->ehc_mode; | 1253 | h->c.avctx->sample_aspect_ratio.den <<= h->c.ehc_mode; |
| 1247 | if ((width == 0) || (height == 0)) | 1254 | if ((width == 0) || (height == 0)) |
| 1248 | return -1; | 1255 | return -1; |
| 1249 | s->width = width; | 1256 | h->c.width = width; |
| 1250 | s->height = height; | 1257 | h->c.height = height; |
| 1251 | 1258 | ||
| 1252 | if(s->custom_pcf){ | 1259 | if (h->c.custom_pcf) { |
| 1253 | int gcd; | 1260 | h->c.avctx->framerate.num = 1800000; |
| 1254 | s->avctx->framerate.num = 1800000; | 1261 | h->c.avctx->framerate.den = 1000 + get_bits1(&h->c.gb); |
| 1255 | s->avctx->framerate.den = 1000 + get_bits1(&s->gb); | 1262 | h->c.avctx->framerate.den *= get_bits(&h->c.gb, 7); |
| 1256 | s->avctx->framerate.den *= get_bits(&s->gb, 7); | 1263 | if (h->c.avctx->framerate.den == 0) { |
| 1257 | if(s->avctx->framerate.den == 0){ | 1264 | av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n"); |
| 1258 | av_log(s->avctx, AV_LOG_ERROR, "zero framerate\n"); | ||
| 1259 | return -1; | 1265 | return -1; |
| 1260 | } | 1266 | } |
| 1261 | gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num); | 1267 | int gcd = av_gcd(h->c.avctx->framerate.den, h->c.avctx->framerate.num); |
| 1262 | s->avctx->framerate.den /= gcd; | 1268 | h->c.avctx->framerate.den /= gcd; |
| 1263 | s->avctx->framerate.num /= gcd; | 1269 | h->c.avctx->framerate.num /= gcd; |
| 1264 | }else{ | 1270 | }else{ |
| 1265 | s->avctx->framerate = (AVRational){ 30000, 1001 }; | 1271 | h->c.avctx->framerate = (AVRational){ 30000, 1001 }; |
| 1266 | } | 1272 | } |
| 1267 | } | 1273 | } |
| 1268 | 1274 | ||
| 1269 | if(s->custom_pcf){ | 1275 | if (h->c.custom_pcf) |
| 1270 | skip_bits(&s->gb, 2); //extended Temporal reference | 1276 | skip_bits(&h->c.gb, 2); //extended Temporal reference |
| 1271 | } | ||
| 1272 | 1277 | ||
| 1273 | if (ufep) { | 1278 | if (ufep) { |
| 1274 | if (s->umvplus) { | 1279 | if (h->c.umvplus) { |
| 1275 | if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | 1280 | if(get_bits1(&h->c.gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
| 1276 | skip_bits1(&s->gb); | 1281 | skip_bits1(&h->c.gb); |
| 1277 | } | 1282 | } |
| 1278 | if(s->h263_slice_structured){ | 1283 | if (h->c.h263_slice_structured) { |
| 1279 | if (get_bits1(&s->gb) != 0) { | 1284 | if (get_bits1(&h->c.gb) != 0) { |
| 1280 | av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); | 1285 | av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); |
| 1281 | } | 1286 | } |
| 1282 | if (get_bits1(&s->gb) != 0) { | 1287 | if (get_bits1(&h->c.gb) != 0) { |
| 1283 | av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n"); | 1288 | av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n"); |
| 1284 | } | 1289 | } |
| 1285 | } | 1290 | } |
| 1286 | if (s->pict_type == AV_PICTURE_TYPE_B) { | 1291 | if (h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 1287 | skip_bits(&s->gb, 4); //ELNUM | 1292 | skip_bits(&h->c.gb, 4); //ELNUM |
| 1288 | if (ufep == 1) { | 1293 | if (ufep == 1) { |
| 1289 | skip_bits(&s->gb, 4); // RLNUM | 1294 | skip_bits(&h->c.gb, 4); // RLNUM |
| 1290 | } | 1295 | } |
| 1291 | } | 1296 | } |
| 1292 | } | 1297 | } |
| 1293 | 1298 | ||
| 1294 | s->qscale = get_bits(&s->gb, 5); | 1299 | h->c.qscale = get_bits(&h->c.gb, 5); |
| 1295 | } | 1300 | } |
| 1296 | 1301 | ||
| 1297 | ret = av_image_check_size(s->width, s->height, 0, s->avctx); | 1302 | ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx); |
| 1298 | if (ret < 0) | 1303 | if (ret < 0) |
| 1299 | return ret; | 1304 | return ret; |
| 1300 | 1305 | ||
| 1301 | if (!(s->avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) { | 1306 | if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) { |
| 1302 | if ((s->width * s->height / 256 / 8) > get_bits_left(&s->gb)) | 1307 | if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->c.gb)) |
| 1303 | return AVERROR_INVALIDDATA; | 1308 | return AVERROR_INVALIDDATA; |
| 1304 | } | 1309 | } |
| 1305 | 1310 | ||
| 1306 | s->mb_width = (s->width + 15) / 16; | 1311 | h->c.mb_width = (h->c.width + 15U) / 16; |
| 1307 | s->mb_height = (s->height + 15) / 16; | 1312 | h->c.mb_height = (h->c.height + 15U) / 16; |
| 1308 | s->mb_num = s->mb_width * s->mb_height; | 1313 | h->c.mb_num = h->c.mb_width * h->c.mb_height; |
| 1309 | 1314 | ||
| 1310 | s->gob_index = H263_GOB_HEIGHT(s->height); | 1315 | h->c.gob_index = H263_GOB_HEIGHT(h->c.height); |
| 1311 | 1316 | ||
| 1312 | if (s->pb_frame) { | 1317 | if (h->c.pb_frame) { |
| 1313 | skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */ | 1318 | skip_bits(&h->c.gb, 3); /* Temporal reference for B-pictures */ |
| 1314 | if (s->custom_pcf) | 1319 | if (h->c.custom_pcf) |
| 1315 | skip_bits(&s->gb, 2); //extended Temporal reference | 1320 | skip_bits(&h->c.gb, 2); //extended Temporal reference |
| 1316 | skip_bits(&s->gb, 2); /* Quantization information for B-pictures */ | 1321 | skip_bits(&h->c.gb, 2); /* Quantization information for B-pictures */ |
| 1317 | } | 1322 | } |
| 1318 | 1323 | ||
| 1319 | if (s->pict_type!=AV_PICTURE_TYPE_B) { | 1324 | if (h->c.pict_type!=AV_PICTURE_TYPE_B) { |
| 1320 | s->time = s->picture_number; | 1325 | h->c.time = h->c.picture_number; |
| 1321 | s->pp_time = s->time - s->last_non_b_time; | 1326 | h->c.pp_time = h->c.time - h->c.last_non_b_time; |
| 1322 | s->last_non_b_time = s->time; | 1327 | h->c.last_non_b_time = h->c.time; |
| 1323 | }else{ | 1328 | }else{ |
| 1324 | s->time = s->picture_number; | 1329 | h->c.time = h->c.picture_number; |
| 1325 | s->pb_time = s->pp_time - (s->last_non_b_time - s->time); | 1330 | h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time); |
| 1326 | if (s->pp_time <=s->pb_time || | 1331 | if (h->c.pp_time <= h->c.pb_time || |
| 1327 | s->pp_time <= s->pp_time - s->pb_time || | 1332 | h->c.pp_time <= h->c.pp_time - h->c.pb_time || |
| 1328 | s->pp_time <= 0){ | 1333 | h->c.pp_time <= 0) { |
| 1329 | s->pp_time = 2; | 1334 | h->c.pp_time = 2; |
| 1330 | s->pb_time = 1; | 1335 | h->c.pb_time = 1; |
| 1331 | } | 1336 | } |
| 1332 | ff_mpeg4_init_direct_mv(s); | 1337 | ff_mpeg4_init_direct_mv(&h->c); |
| 1333 | } | 1338 | } |
| 1334 | 1339 | ||
| 1335 | /* PEI */ | 1340 | /* PEI */ |
| 1336 | if (skip_1stop_8data_bits(&s->gb) < 0) | 1341 | if (skip_1stop_8data_bits(&h->c.gb) < 0) |
| 1337 | return AVERROR_INVALIDDATA; | 1342 | return AVERROR_INVALIDDATA; |
| 1338 | 1343 | ||
| 1339 | if(s->h263_slice_structured){ | 1344 | if (h->c.h263_slice_structured) { |
| 1340 | if (check_marker(s->avctx, &s->gb, "SEPB1") != 1) { | 1345 | if (check_marker(h->c.avctx, &h->c.gb, "SEPB1") != 1) { |
| 1341 | return -1; | 1346 | return -1; |
| 1342 | } | 1347 | } |
| 1343 | 1348 | ||
| 1344 | ff_h263_decode_mba(s); | 1349 | ff_h263_decode_mba(h); |
| 1345 | 1350 | ||
| 1346 | if (check_marker(s->avctx, &s->gb, "SEPB2") != 1) { | 1351 | if (check_marker(h->c.avctx, &h->c.gb, "SEPB2") != 1) { |
| 1347 | return -1; | 1352 | return -1; |
| 1348 | } | 1353 | } |
| 1349 | } | 1354 | } |
| 1350 | 1355 | ||
| 1351 | if (s->pict_type == AV_PICTURE_TYPE_B) | 1356 | if (h->c.pict_type == AV_PICTURE_TYPE_B) |
| 1352 | s->low_delay = 0; | 1357 | h->c.low_delay = 0; |
| 1353 | 1358 | ||
| 1354 | if(s->h263_aic){ | 1359 | if (h->c.h263_aic) { |
| 1355 | s->y_dc_scale_table= | 1360 | h->c.y_dc_scale_table = |
| 1356 | s->c_dc_scale_table= ff_aic_dc_scale_table; | 1361 | h->c.c_dc_scale_table = ff_aic_dc_scale_table; |
| 1357 | }else{ | 1362 | }else{ |
| 1358 | s->y_dc_scale_table= | 1363 | h->c.y_dc_scale_table = |
| 1359 | s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | 1364 | h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table; |
| 1360 | } | 1365 | } |
| 1361 | 1366 | ||
| 1362 | ff_h263_show_pict_info(s, h263_plus); | 1367 | ff_h263_show_pict_info(h, h263_plus); |
| 1363 | 1368 | ||
| 1364 | if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){ | 1369 | if (h->c.pict_type == AV_PICTURE_TYPE_I && h->c.codec_tag == AV_RL32("ZYGO") && get_bits_left(&h->c.gb) >= 85 + 13*3*16 + 50){ |
| 1365 | int i,j; | 1370 | int i,j; |
| 1366 | for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); | 1371 | for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb)); |
| 1367 | av_log(s->avctx, AV_LOG_DEBUG, "\n"); | 1372 | av_log(h->c.avctx, AV_LOG_DEBUG, "\n"); |
| 1368 | for(i=0; i<13; i++){ | 1373 | for(i=0; i<13; i++){ |
| 1369 | for(j=0; j<3; j++){ | 1374 | for(j=0; j<3; j++){ |
| 1370 | int v= get_bits(&s->gb, 8); | 1375 | int v= get_bits(&h->c.gb, 8); |
| 1371 | v |= get_sbits(&s->gb, 8) * (1 << 8); | 1376 | v |= get_sbits(&h->c.gb, 8) * (1 << 8); |
| 1372 | av_log(s->avctx, AV_LOG_DEBUG, " %5d", v); | 1377 | av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v); |
| 1373 | } | 1378 | } |
| 1374 | av_log(s->avctx, AV_LOG_DEBUG, "\n"); | 1379 | av_log(h->c.avctx, AV_LOG_DEBUG, "\n"); |
| 1375 | } | 1380 | } |
| 1376 | for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); | 1381 | for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb)); |
| 1377 | } | 1382 | } |
| 1378 | 1383 | ||
| 1379 | return 0; | 1384 | return 0; |
| @@ -84,7 +84,7 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, · 83 unmodified lines | |||
| 84 | { | 84 | { |
| 85 | struct Mp4vParseContext *pc = s1->priv_data; | 85 | struct Mp4vParseContext *pc = s1->priv_data; |
| 86 | Mpeg4DecContext *dec_ctx = &pc->dec_ctx; | 86 | Mpeg4DecContext *dec_ctx = &pc->dec_ctx; |
| 87 | MpegEncContext *s = &dec_ctx->m; | 87 | MPVContext *const s = &dec_ctx->h.c; |
| 88 | GetBitContext gb1, *gb = &gb1; | 88 | GetBitContext gb1, *gb = &gb1; |
| 89 | int ret; | 89 | int ret; |
| 90 | 90 | ||
| @@ -124,7 +124,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s) · 33 unmodified lines | |||
| 124 | 124 | ||
| 125 | pc->first_picture = 1; | 125 | pc->first_picture = 1; |
| 126 | pc->dec_ctx.quant_precision = 5; | 126 | pc->dec_ctx.quant_precision = 5; |
| 127 | pc->dec_ctx.m.slice_context_count = 1; | 127 | pc->dec_ctx.h.c.slice_context_count = 1; |
| 128 | pc->dec_ctx.showed_packed_warning = 1; | 128 | pc->dec_ctx.showed_packed_warning = 1; |
| 129 | return 0; | 129 | return 0; |
| 130 | } | 130 | } |
| @@ -81,6 +81,12 @@ static const int16_t mb_type_b_map[4] = { · 80 unmodified lines | |||
| 81 | MB_TYPE_FORWARD_MV | MB_TYPE_16x16, | 81 | MB_TYPE_FORWARD_MV | MB_TYPE_16x16, |
| 82 | }; | 82 | }; |
| 83 | 83 | ||
| 84 | static inline Mpeg4DecContext *h263_to_mpeg4(H263DecContext *h) | ||
| 85 | { | ||
| 86 | av_assert2(h->c.codec_id == AV_CODEC_ID_MPEG4 && h->c.avctx->priv_data == h); | ||
| 87 | return (Mpeg4DecContext*)h; | ||
| 88 | } | ||
| 89 | |||
| 84 | static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx, | 90 | static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx, |
| 85 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | 91 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
| 86 | uint8_t *const *ref_picture) | 92 | uint8_t *const *ref_picture) |
| @@ -319,55 +325,55 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb · 232 unmodified lines | |||
| 319 | * @param n block index (0-3 are luma, 4-5 are chroma) | 325 | * @param n block index (0-3 are luma, 4-5 are chroma) |
| 320 | * @param dir the ac prediction direction | 326 | * @param dir the ac prediction direction |
| 321 | */ | 327 | */ |
| 322 | void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir) | 328 | void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir) |
| 323 | { | 329 | { |
| 324 | int i; | 330 | int i; |
| 325 | int16_t *ac_val, *ac_val1; | 331 | int16_t *ac_val, *ac_val1; |
| 326 | int8_t *const qscale_table = s->cur_pic.qscale_table; | 332 | int8_t *const qscale_table = h->c.cur_pic.qscale_table; |
| 327 | 333 | ||
| 328 | /* find prediction */ | 334 | /* find prediction */ |
| 329 | ac_val = &s->ac_val[0][0] + s->block_index[n] * 16; | 335 | ac_val = &h->c.ac_val[0][0] + h->c.block_index[n] * 16; |
| 330 | ac_val1 = ac_val; | 336 | ac_val1 = ac_val; |
| 331 | if (s->ac_pred) { | 337 | if (h->c.ac_pred) { |
| 332 | if (dir == 0) { | 338 | if (dir == 0) { |
| 333 | const int xy = s->mb_x - 1 + s->mb_y * s->mb_stride; | 339 | const int xy = h->c.mb_x - 1 + h->c.mb_y * h->c.mb_stride; |
| 334 | /* left prediction */ | 340 | /* left prediction */ |
| 335 | ac_val -= 16; | 341 | ac_val -= 16; |
| 336 | 342 | ||
| 337 | if (s->mb_x == 0 || s->qscale == qscale_table[xy] || | 343 | if (h->c.mb_x == 0 || h->c.qscale == qscale_table[xy] || |
| 338 | n == 1 || n == 3) { | 344 | n == 1 || n == 3) { |
| 339 | /* same qscale */ | 345 | /* same qscale */ |
| 340 | for (i = 1; i < 8; i++) | 346 | for (i = 1; i < 8; i++) |
| 341 | block[s->idsp.idct_permutation[i << 3]] += ac_val[i]; | 347 | block[h->c.idsp.idct_permutation[i << 3]] += ac_val[i]; |
| 342 | } else { | 348 | } else { |
| 343 | /* different qscale, we must rescale */ | 349 | /* different qscale, we must rescale */ |
| 344 | for (i = 1; i < 8; i++) | 350 | for (i = 1; i < 8; i++) |
| 345 | block[s->idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], s->qscale); | 351 | block[h->c.idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], h->c.qscale); |
| 346 | } | 352 | } |
| 347 | } else { | 353 | } else { |
| 348 | const int xy = s->mb_x + s->mb_y * s->mb_stride - s->mb_stride; | 354 | const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride - h->c.mb_stride; |
| 349 | /* top prediction */ | 355 | /* top prediction */ |
| 350 | ac_val -= 16 * s->block_wrap[n]; | 356 | ac_val -= 16 * h->c.block_wrap[n]; |
| 351 | 357 | ||
| 352 | if (s->mb_y == 0 || s->qscale == qscale_table[xy] || | 358 | if (h->c.mb_y == 0 || h->c.qscale == qscale_table[xy] || |
| 353 | n == 2 || n == 3) { | 359 | n == 2 || n == 3) { |
| 354 | /* same qscale */ | 360 | /* same qscale */ |
| 355 | for (i = 1; i < 8; i++) | 361 | for (i = 1; i < 8; i++) |
| 356 | block[s->idsp.idct_permutation[i]] += ac_val[i + 8]; | 362 | block[h->c.idsp.idct_permutation[i]] += ac_val[i + 8]; |
| 357 | } else { | 363 | } else { |
| 358 | /* different qscale, we must rescale */ | 364 | /* different qscale, we must rescale */ |
| 359 | for (i = 1; i < 8; i++) | 365 | for (i = 1; i < 8; i++) |
| 360 | block[s->idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], s->qscale); | 366 | block[h->c.idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], h->c.qscale); |
| 361 | } | 367 | } |
| 362 | } | 368 | } |
| 363 | } | 369 | } |
| 364 | /* left copy */ | 370 | /* left copy */ |
| 365 | for (i = 1; i < 8; i++) | 371 | for (i = 1; i < 8; i++) |
| 366 | ac_val1[i] = block[s->idsp.idct_permutation[i << 3]]; | 372 | ac_val1[i] = block[h->c.idsp.idct_permutation[i << 3]]; |
| 367 | 373 | ||
| 368 | /* top copy */ | 374 | /* top copy */ |
| 369 | for (i = 1; i < 8; i++) | 375 | for (i = 1; i < 8; i++) |
| 370 | ac_val1[8 + i] = block[s->idsp.idct_permutation[i]]; | 376 | ac_val1[8 + i] = block[h->c.idsp.idct_permutation[i]]; |
| 371 | } | 377 | } |
| 372 | 378 | ||
| 373 | /** | 379 | /** |
| @@ -376,28 +382,28 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir) · 2 unmodified lines | |||
| 376 | */ | 382 | */ |
| 377 | static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) | 383 | static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) |
| 378 | { | 384 | { |
| 379 | MpegEncContext *s = &ctx->m; | 385 | H263DecContext *const h = &ctx->h; |
| 380 | int bits_count = get_bits_count(&s->gb); | 386 | int bits_count = get_bits_count(&h->c.gb); |
| 381 | int v = show_bits(&s->gb, 16); | 387 | int v = show_bits(&h->c.gb, 16); |
| 382 | 388 | ||
| 383 | if (s->workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker) | 389 | if (h->c.workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker) |
| 384 | return 0; | 390 | return 0; |
| 385 | 391 | ||
| 386 | while (v <= 0xFF) { | 392 | while (v <= 0xFF) { |
| 387 | if (s->pict_type == AV_PICTURE_TYPE_B || | 393 | if (h->c.pict_type == AV_PICTURE_TYPE_B || |
| 388 | (v >> (8 - s->pict_type) != 1) || s->partitioned_frame) | 394 | (v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame) |
| 389 | break; | 395 | break; |
| 390 | skip_bits(&s->gb, 8 + s->pict_type); | 396 | skip_bits(&h->c.gb, 8 + h->c.pict_type); |
| 391 | bits_count += 8 + s->pict_type; | 397 | bits_count += 8 + h->c.pict_type; |
| 392 | v = show_bits(&s->gb, 16); | 398 | v = show_bits(&h->c.gb, 16); |
| 393 | } | 399 | } |
| 394 | 400 | ||
| 395 | if (bits_count + 8 >= s->gb.size_in_bits) { | 401 | if (bits_count + 8 >= h->c.gb.size_in_bits) { |
| 396 | v >>= 8; | 402 | v >>= 8; |
| 397 | v |= 0x7F >> (7 - (bits_count & 7)); | 403 | v |= 0x7F >> (7 - (bits_count & 7)); |
| 398 | 404 | ||
| 399 | if (v == 0x7F) | 405 | if (v == 0x7F) |
| 400 | return s->mb_num; | 406 | return h->c.mb_num; |
| 401 | } else { | 407 | } else { |
| 402 | static const uint16_t mpeg4_resync_prefix[8] = { | 408 | static const uint16_t mpeg4_resync_prefix[8] = { |
| 403 | 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000 | 409 | 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000 |
| @@ -405,23 +411,23 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) · 1 unmodified line | |||
| 405 | 411 | ||
| 406 | if (v == mpeg4_resync_prefix[bits_count & 7]) { | 412 | if (v == mpeg4_resync_prefix[bits_count & 7]) { |
| 407 | int len, mb_num; | 413 | int len, mb_num; |
| 408 | int mb_num_bits = av_log2(s->mb_num - 1) + 1; | 414 | int mb_num_bits = av_log2(h->c.mb_num - 1) + 1; |
| 409 | GetBitContext gb = s->gb; | 415 | GetBitContext gb = h->c.gb; |
| 410 | 416 | ||
| 411 | skip_bits(&s->gb, 1); | 417 | skip_bits(&h->c.gb, 1); |
| 412 | align_get_bits(&s->gb); | 418 | align_get_bits(&h->c.gb); |
| 413 | 419 | ||
| 414 | for (len = 0; len < 32; len++) | 420 | for (len = 0; len < 32; len++) |
| 415 | if (get_bits1(&s->gb)) | 421 | if (get_bits1(&h->c.gb)) |
| 416 | break; | 422 | break; |
| 417 | 423 | ||
| 418 | mb_num = get_bits(&s->gb, mb_num_bits); | 424 | mb_num = get_bits(&h->c.gb, mb_num_bits); |
| 419 | if (!mb_num || mb_num > s->mb_num || get_bits_count(&s->gb)+6 > s->gb.size_in_bits) | 425 | if (!mb_num || mb_num > h->c.mb_num || get_bits_count(&h->c.gb) + 6 > h->c.gb.size_in_bits) |
| 420 | mb_num= -1; | 426 | mb_num= -1; |
| 421 | 427 | ||
| 422 | s->gb = gb; | 428 | h->c.gb = gb; |
| 423 | 429 | ||
| 424 | if (len >= ff_mpeg4_get_video_packet_prefix_length(s->pict_type, ctx->f_code, ctx->b_code)) | 430 | if (len >= ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) |
| 425 | return mb_num; | 431 | return mb_num; |
| 426 | } | 432 | } |
| 427 | } | 433 | } |
| @@ -430,7 +436,7 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) · 2 unmodified lines | |||
| 430 | 436 | ||
| 431 | static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb) | 437 | static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 432 | { | 438 | { |
| 433 | MpegEncContext *s = &ctx->m; | 439 | MpegEncContext *s = &ctx->h.c; |
| 434 | int a = 2 << ctx->sprite_warping_accuracy; | 440 | int a = 2 << ctx->sprite_warping_accuracy; |
| 435 | int rho = 3 - ctx->sprite_warping_accuracy; | 441 | int rho = 3 - ctx->sprite_warping_accuracy; |
| 436 | int r = 16 / a; | 442 | int r = 16 / a; |
| @@ -685,13 +691,12 @@ overflow: · 248 unmodified lines | |||
| 685 | } | 691 | } |
| 686 | 692 | ||
| 687 | static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) { | 693 | static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) { |
| 688 | MpegEncContext *s = &ctx->m; | ||
| 689 | int len = FFMIN(ctx->time_increment_bits + 3, 15); | 694 | int len = FFMIN(ctx->time_increment_bits + 3, 15); |
| 690 | 695 | ||
| 691 | get_bits(gb, len); | 696 | get_bits(gb, len); |
| 692 | if (get_bits1(gb)) | 697 | if (get_bits1(gb)) |
| 693 | get_bits(gb, len); | 698 | get_bits(gb, len); |
| 694 | check_marker(s->avctx, gb, "after new_pred"); | 699 | check_marker(ctx->h.c.avctx, gb, "after new_pred"); |
| 695 | 700 | ||
| 696 | return 0; | 701 | return 0; |
| 697 | } | 702 | } |
| @@ -700,96 +705,96 @@ static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) { · 2 unmodified lines | |||
| 700 | * Decode the next video packet. | 705 | * Decode the next video packet. |
| 701 | * @return <0 if something went wrong | 706 | * @return <0 if something went wrong |
| 702 | */ | 707 | */ |
| 703 | int ff_mpeg4_decode_video_packet_header(MPVContext *const s) | 708 | int ff_mpeg4_decode_video_packet_header(H263DecContext *const h) |
| 704 | { | 709 | { |
| 705 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 710 | Mpeg4DecContext *const ctx = h263_to_mpeg4(h); |
| 706 | 711 | ||
| 707 | int mb_num_bits = av_log2(s->mb_num - 1) + 1; | 712 | int mb_num_bits = av_log2(h->c.mb_num - 1) + 1; |
| 708 | int header_extension = 0, mb_num, len; | 713 | int header_extension = 0, mb_num, len; |
| 709 | 714 | ||
| 710 | /* is there enough space left for a video packet + header */ | 715 | /* is there enough space left for a video packet + header */ |
| 711 | if (get_bits_count(&s->gb) > s->gb.size_in_bits - 20) | 716 | if (get_bits_count(&h->c.gb) > h->c.gb.size_in_bits - 20) |
| 712 | return AVERROR_INVALIDDATA; | 717 | return AVERROR_INVALIDDATA; |
| 713 | 718 | ||
| 714 | for (len = 0; len < 32; len++) | 719 | for (len = 0; len < 32; len++) |
| 715 | if (get_bits1(&s->gb)) | 720 | if (get_bits1(&h->c.gb)) |
| 716 | break; | 721 | break; |
| 717 | 722 | ||
| 718 | if (len != ff_mpeg4_get_video_packet_prefix_length(s->pict_type, ctx->f_code, ctx->b_code)) { | 723 | if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) { |
| 719 | av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n"); | 724 | av_log(h->c.avctx, AV_LOG_ERROR, "marker does not match f_code\n"); |
| 720 | return AVERROR_INVALIDDATA; | 725 | return AVERROR_INVALIDDATA; |
| 721 | } | 726 | } |
| 722 | 727 | ||
| 723 | if (ctx->shape != RECT_SHAPE) { | 728 | if (ctx->shape != RECT_SHAPE) { |
| 724 | header_extension = get_bits1(&s->gb); | 729 | header_extension = get_bits1(&h->c.gb); |
| 725 | // FIXME more stuff here | 730 | // FIXME more stuff here |
| 726 | } | 731 | } |
| 727 | 732 | ||
| 728 | mb_num = get_bits(&s->gb, mb_num_bits); | 733 | mb_num = get_bits(&h->c.gb, mb_num_bits); |
| 729 | if (mb_num >= s->mb_num || !mb_num) { | 734 | if (mb_num >= h->c.mb_num || !mb_num) { |
| 730 | av_log(s->avctx, AV_LOG_ERROR, | 735 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 731 | "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num); | 736 | "illegal mb_num in video packet (%d %d) \n", mb_num, h->c.mb_num); |
| 732 | return AVERROR_INVALIDDATA; | 737 | return AVERROR_INVALIDDATA; |
| 733 | } | 738 | } |
| 734 | 739 | ||
| 735 | s->mb_x = mb_num % s->mb_width; | 740 | h->c.mb_x = mb_num % h->c.mb_width; |
| 736 | s->mb_y = mb_num / s->mb_width; | 741 | h->c.mb_y = mb_num / h->c.mb_width; |
| 737 | 742 | ||
| 738 | if (ctx->shape != BIN_ONLY_SHAPE) { | 743 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 739 | int qscale = get_bits(&s->gb, ctx->quant_precision); | 744 | int qscale = get_bits(&h->c.gb, ctx->quant_precision); |
| 740 | if (qscale) | 745 | if (qscale) |
| 741 | s->chroma_qscale = s->qscale = qscale; | 746 | h->c.chroma_qscale = h->c.qscale = qscale; |
| 742 | } | 747 | } |
| 743 | 748 | ||
| 744 | if (ctx->shape == RECT_SHAPE) | 749 | if (ctx->shape == RECT_SHAPE) |
| 745 | header_extension = get_bits1(&s->gb); | 750 | header_extension = get_bits1(&h->c.gb); |
| 746 | 751 | ||
| 747 | if (header_extension) { | 752 | if (header_extension) { |
| 748 | while (get_bits1(&s->gb) != 0) | 753 | while (get_bits1(&h->c.gb) != 0) |
| 749 | ; | 754 | ; |
| 750 | 755 | ||
| 751 | check_marker(s->avctx, &s->gb, "before time_increment in video packed header"); | 756 | check_marker(h->c.avctx, &h->c.gb, "before time_increment in video packed header"); |
| 752 | skip_bits(&s->gb, ctx->time_increment_bits); /* time_increment */ | 757 | skip_bits(&h->c.gb, ctx->time_increment_bits); /* time_increment */ |
| 753 | check_marker(s->avctx, &s->gb, "before vop_coding_type in video packed header"); | 758 | check_marker(h->c.avctx, &h->c.gb, "before vop_coding_type in video packed header"); |
| 754 | 759 | ||
| 755 | skip_bits(&s->gb, 2); /* vop coding type */ | 760 | skip_bits(&h->c.gb, 2); /* vop coding type */ |
| 756 | // FIXME not rect stuff here | 761 | // FIXME not rect stuff here |
| 757 | 762 | ||
| 758 | if (ctx->shape != BIN_ONLY_SHAPE) { | 763 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 759 | skip_bits(&s->gb, 3); /* intra dc vlc threshold */ | 764 | skip_bits(&h->c.gb, 3); /* intra dc vlc threshold */ |
| 760 | // FIXME don't just ignore everything | 765 | // FIXME don't just ignore everything |
| 761 | if (s->pict_type == AV_PICTURE_TYPE_S && | 766 | if (h->c.pict_type == AV_PICTURE_TYPE_S && |
| 762 | ctx->vol_sprite_usage == GMC_SPRITE) { | 767 | ctx->vol_sprite_usage == GMC_SPRITE) { |
| 763 | if (mpeg4_decode_sprite_trajectory(ctx, &s->gb) < 0) | 768 | if (mpeg4_decode_sprite_trajectory(ctx, &h->c.gb) < 0) |
| 764 | return AVERROR_INVALIDDATA; | 769 | return AVERROR_INVALIDDATA; |
| 765 | av_log(s->avctx, AV_LOG_ERROR, "untested\n"); | 770 | av_log(h->c.avctx, AV_LOG_ERROR, "untested\n"); |
| 766 | } | 771 | } |
| 767 | 772 | ||
| 768 | // FIXME reduced res stuff here | 773 | // FIXME reduced res stuff here |
| 769 | 774 | ||
| 770 | if (s->pict_type != AV_PICTURE_TYPE_I) { | 775 | if (h->c.pict_type != AV_PICTURE_TYPE_I) { |
| 771 | int f_code = get_bits(&s->gb, 3); /* fcode_for */ | 776 | int f_code = get_bits(&h->c.gb, 3); /* fcode_for */ |
| 772 | if (f_code == 0) | 777 | if (f_code == 0) |
| 773 | av_log(s->avctx, AV_LOG_ERROR, | 778 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 774 | "Error, video packet header damaged (f_code=0)\n"); | 779 | "Error, video packet header damaged (f_code=0)\n"); |
| 775 | } | 780 | } |
| 776 | if (s->pict_type == AV_PICTURE_TYPE_B) { | 781 | if (h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 777 | int b_code = get_bits(&s->gb, 3); | 782 | int b_code = get_bits(&h->c.gb, 3); |
| 778 | if (b_code == 0) | 783 | if (b_code == 0) |
| 779 | av_log(s->avctx, AV_LOG_ERROR, | 784 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 780 | "Error, video packet header damaged (b_code=0)\n"); | 785 | "Error, video packet header damaged (b_code=0)\n"); |
| 781 | } | 786 | } |
| 782 | } | 787 | } |
| 783 | } | 788 | } |
| 784 | if (ctx->new_pred) | 789 | if (ctx->new_pred) |
| 785 | decode_new_pred(ctx, &s->gb); | 790 | decode_new_pred(ctx, &h->c.gb); |
| 786 | 791 | ||
| 787 | return 0; | 792 | return 0; |
| 788 | } | 793 | } |
| 789 | 794 | ||
| 790 | static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx) | 795 | static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx) |
| 791 | { | 796 | { |
| 792 | MPVContext *const s = &ctx->m; | 797 | MPVContext *const s = &ctx->h.c; |
| 793 | /* Reset DC Predictors */ | 798 | /* Reset DC Predictors */ |
| 794 | s->last_dc[0] = | 799 | s->last_dc[0] = |
| 795 | s->last_dc[1] = | 800 | s->last_dc[1] = |
| @@ -800,25 +805,25 @@ static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx) · 4 unmodified lines | |||
| 800 | * Decode the next video packet. | 805 | * Decode the next video packet. |
| 801 | * @return <0 if something went wrong | 806 | * @return <0 if something went wrong |
| 802 | */ | 807 | */ |
| 803 | int ff_mpeg4_decode_studio_slice_header(MPVContext *const s) | 808 | int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h) |
| 804 | { | 809 | { |
| 805 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 810 | Mpeg4DecContext *const ctx = h263_to_mpeg4(h); |
| 806 | GetBitContext *gb = &s->gb; | 811 | GetBitContext *gb = &h->c.gb; |
| 807 | unsigned vlc_len; | 812 | unsigned vlc_len; |
| 808 | uint16_t mb_num; | 813 | uint16_t mb_num; |
| 809 | 814 | ||
| 810 | if (get_bits_left(gb) >= 32 && get_bits_long(gb, 32) == SLICE_STARTCODE) { | 815 | if (get_bits_left(gb) >= 32 && get_bits_long(gb, 32) == SLICE_STARTCODE) { |
| 811 | vlc_len = av_log2(s->mb_width * s->mb_height) + 1; | 816 | vlc_len = av_log2(h->c.mb_width * h->c.mb_height) + 1; |
| 812 | mb_num = get_bits(gb, vlc_len); | 817 | mb_num = get_bits(gb, vlc_len); |
| 813 | 818 | ||
| 814 | if (mb_num >= s->mb_num) | 819 | if (mb_num >= h->c.mb_num) |
| 815 | return AVERROR_INVALIDDATA; | 820 | return AVERROR_INVALIDDATA; |
| 816 | 821 | ||
| 817 | s->mb_x = mb_num % s->mb_width; | 822 | h->c.mb_x = mb_num % h->c.mb_width; |
| 818 | s->mb_y = mb_num / s->mb_width; | 823 | h->c.mb_y = mb_num / h->c.mb_width; |
| 819 | 824 | ||
| 820 | if (ctx->shape != BIN_ONLY_SHAPE) | 825 | if (ctx->shape != BIN_ONLY_SHAPE) |
| 821 | s->qscale = mpeg_get_qscale(s); | 826 | h->c.qscale = mpeg_get_qscale(&h->c); |
| 822 | 827 | ||
| 823 | if (get_bits1(gb)) { /* slice_extension_flag */ | 828 | if (get_bits1(gb)) { /* slice_extension_flag */ |
| 824 | skip_bits1(gb); /* intra_slice */ | 829 | skip_bits1(gb); /* intra_slice */ |
| @@ -844,7 +849,7 @@ int ff_mpeg4_decode_studio_slice_header(MPVContext *const s) · 19 unmodified lines | |||
| 844 | */ | 849 | */ |
| 845 | static inline int get_amv(Mpeg4DecContext *ctx, int n) | 850 | static inline int get_amv(Mpeg4DecContext *ctx, int n) |
| 846 | { | 851 | { |
| 847 | MpegEncContext *s = &ctx->m; | 852 | MPVContext *const s = &ctx->h.c; |
| 848 | int x, y, mb_v, sum, dx, dy, shift; | 853 | int x, y, mb_v, sum, dx, dy, shift; |
| 849 | int len = 1 << (ctx->f_code + 4); | 854 | int len = 1 << (ctx->f_code + 4); |
| 850 | const int a = ctx->sprite_warping_accuracy; | 855 | const int a = ctx->sprite_warping_accuracy; |
| @@ -975,17 +980,17 @@ static inline int mpeg4_get_level_dc(MpegEncContext *s, int n, int pred, int lev · 124 unmodified lines | |||
| 975 | * @param dir_ptr the prediction direction will be stored here | 980 | * @param dir_ptr the prediction direction will be stored here |
| 976 | * @return the quantized dc | 981 | * @return the quantized dc |
| 977 | */ | 982 | */ |
| 978 | static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr) | 983 | static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr) |
| 979 | { | 984 | { |
| 980 | int level, code, pred; | 985 | int level, code, pred; |
| 981 | 986 | ||
| 982 | if (n < 4) | 987 | if (n < 4) |
| 983 | code = get_vlc2(&s->gb, dc_lum, DC_VLC_BITS, 1); | 988 | code = get_vlc2(&h->c.gb, dc_lum, DC_VLC_BITS, 1); |
| 984 | else | 989 | else |
| 985 | code = get_vlc2(&s->gb, dc_chrom, DC_VLC_BITS, 1); | 990 | code = get_vlc2(&h->c.gb, dc_chrom, DC_VLC_BITS, 1); |
| 986 | 991 | ||
| 987 | if (code < 0) { | 992 | if (code < 0) { |
| 988 | av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); | 993 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n"); |
| 989 | return AVERROR_INVALIDDATA; | 994 | return AVERROR_INVALIDDATA; |
| 990 | } | 995 | } |
| 991 | 996 | ||
| @@ -994,29 +999,29 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr) · 2 unmodified lines | |||
| 994 | } else { | 999 | } else { |
| 995 | if (IS_3IV1) { | 1000 | if (IS_3IV1) { |
| 996 | if (code == 1) | 1001 | if (code == 1) |
| 997 | level = 2 * get_bits1(&s->gb) - 1; | 1002 | level = 2 * get_bits1(&h->c.gb) - 1; |
| 998 | else { | 1003 | else { |
| 999 | if (get_bits1(&s->gb)) | 1004 | if (get_bits1(&h->c.gb)) |
| 1000 | level = get_bits(&s->gb, code - 1) + (1 << (code - 1)); | 1005 | level = get_bits(&h->c.gb, code - 1) + (1 << (code - 1)); |
| 1001 | else | 1006 | else |
| 1002 | level = -get_bits(&s->gb, code - 1) - (1 << (code - 1)); | 1007 | level = -get_bits(&h->c.gb, code - 1) - (1 << (code - 1)); |
| 1003 | } | 1008 | } |
| 1004 | } else { | 1009 | } else { |
| 1005 | level = get_xbits(&s->gb, code); | 1010 | level = get_xbits(&h->c.gb, code); |
| 1006 | } | 1011 | } |
| 1007 | 1012 | ||
| 1008 | if (code > 8) { | 1013 | if (code > 8) { |
| 1009 | if (get_bits1(&s->gb) == 0) { /* marker */ | 1014 | if (get_bits1(&h->c.gb) == 0) { /* marker */ |
| 1010 | if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) { | 1015 | if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) { |
| 1011 | av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n"); | 1016 | av_log(h->c.avctx, AV_LOG_ERROR, "dc marker bit missing\n"); |
| 1012 | return AVERROR_INVALIDDATA; | 1017 | return AVERROR_INVALIDDATA; |
| 1013 | } | 1018 | } |
| 1014 | } | 1019 | } |
| 1015 | } | 1020 | } |
| 1016 | } | 1021 | } |
| 1017 | 1022 | ||
| 1018 | pred = mpeg4_pred_dc(s, n, dir_ptr); | 1023 | pred = mpeg4_pred_dc(&h->c, n, dir_ptr); |
| 1019 | return mpeg4_get_level_dc(s, n, pred, level); | 1024 | return mpeg4_get_level_dc(&h->c, n, pred, level); |
| 1020 | } | 1025 | } |
| 1021 | 1026 | ||
| 1022 | /** | 1027 | /** |
| @@ -1025,85 +1030,85 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr) · 2 unmodified lines | |||
| 1025 | */ | 1030 | */ |
| 1026 | static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) | 1031 | static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) |
| 1027 | { | 1032 | { |
| 1028 | MpegEncContext *s = &ctx->m; | 1033 | H263DecContext *const h = &ctx->h; |
| 1029 | int mb_num = 0; | 1034 | int mb_num = 0; |
| 1030 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; | 1035 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
| 1031 | 1036 | ||
| 1032 | /* decode first partition */ | 1037 | /* decode first partition */ |
| 1033 | s->first_slice_line = 1; | 1038 | h->c.first_slice_line = 1; |
| 1034 | for (; s->mb_y < s->mb_height; s->mb_y++) { | 1039 | for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) { |
| 1035 | ff_init_block_index(s); | 1040 | ff_init_block_index(&h->c); |
| 1036 | for (; s->mb_x < s->mb_width; s->mb_x++) { | 1041 | for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) { |
| 1037 | const int xy = s->mb_x + s->mb_y * s->mb_stride; | 1042 | const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; |
| 1038 | int cbpc; | 1043 | int cbpc; |
| 1039 | int dir = 0; | 1044 | int dir = 0; |
| 1040 | 1045 | ||
| 1041 | mb_num++; | 1046 | mb_num++; |
| 1042 | ff_update_block_index(s, 8, s->avctx->lowres, 1); | 1047 | ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1); |
| 1043 | if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) | 1048 | if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1) |
| 1044 | s->first_slice_line = 0; | 1049 | h->c.first_slice_line = 0; |
| 1045 | 1050 | ||
| 1046 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 1051 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 1047 | int i; | 1052 | int i; |
| 1048 | 1053 | ||
| 1049 | do { | 1054 | do { |
| 1050 | if (show_bits(&s->gb, 19) == DC_MARKER) | 1055 | if (show_bits(&h->c.gb, 19) == DC_MARKER) |
| 1051 | return mb_num - 1; | 1056 | return mb_num - 1; |
| 1052 | 1057 | ||
| 1053 | cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); | 1058 | cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); |
| 1054 | if (cbpc < 0) { | 1059 | if (cbpc < 0) { |
| 1055 | av_log(s->avctx, AV_LOG_ERROR, | 1060 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1056 | "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | 1061 | "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1057 | return AVERROR_INVALIDDATA; | 1062 | return AVERROR_INVALIDDATA; |
| 1058 | } | 1063 | } |
| 1059 | } while (cbpc == 8); | 1064 | } while (cbpc == 8); |
| 1060 | 1065 | ||
| 1061 | s->cbp_table[xy] = cbpc & 3; | 1066 | h->c.cbp_table[xy] = cbpc & 3; |
| 1062 | s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | 1067 | h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; |
| 1063 | s->mb_intra = 1; | 1068 | h->c.mb_intra = 1; |
| 1064 | 1069 | ||
| 1065 | if (cbpc & 4) | 1070 | if (cbpc & 4) |
| 1066 | ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | 1071 | ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); |
| 1067 | 1072 | ||
| 1068 | s->cur_pic.qscale_table[xy] = s->qscale; | 1073 | h->c.cur_pic.qscale_table[xy] = h->c.qscale; |
| 1069 | 1074 | ||
| 1070 | s->mbintra_table[xy] = 1; | 1075 | h->c.mbintra_table[xy] = 1; |
| 1071 | for (i = 0; i < 6; i++) { | 1076 | for (i = 0; i < 6; i++) { |
| 1072 | int dc_pred_dir; | 1077 | int dc_pred_dir; |
| 1073 | int dc = mpeg4_decode_dc(s, i, &dc_pred_dir); | 1078 | int dc = mpeg4_decode_dc(h, i, &dc_pred_dir); |
| 1074 | if (dc < 0) { | 1079 | if (dc < 0) { |
| 1075 | av_log(s->avctx, AV_LOG_ERROR, | 1080 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1076 | "DC corrupted at %d %d\n", s->mb_x, s->mb_y); | 1081 | "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1077 | return dc; | 1082 | return dc; |
| 1078 | } | 1083 | } |
| 1079 | dir <<= 1; | 1084 | dir <<= 1; |
| 1080 | if (dc_pred_dir) | 1085 | if (dc_pred_dir) |
| 1081 | dir |= 1; | 1086 | dir |= 1; |
| 1082 | } | 1087 | } |
| 1083 | s->pred_dir_table[xy] = dir; | 1088 | h->c.pred_dir_table[xy] = dir; |
| 1084 | } else { /* P/S_TYPE */ | 1089 | } else { /* P/S_TYPE */ |
| 1085 | int mx, my, pred_x, pred_y, bits; | 1090 | int mx, my, pred_x, pred_y, bits; |
| 1086 | int16_t *const mot_val = s->cur_pic.motion_val[0][s->block_index[0]]; | 1091 | int16_t *const mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]]; |
| 1087 | const int stride = s->b8_stride * 2; | 1092 | const int stride = h->c.b8_stride * 2; |
| 1088 | 1093 | ||
| 1089 | try_again: | 1094 | try_again: |
| 1090 | bits = show_bits(&s->gb, 17); | 1095 | bits = show_bits(&h->c.gb, 17); |
| 1091 | if (bits == MOTION_MARKER) | 1096 | if (bits == MOTION_MARKER) |
| 1092 | return mb_num - 1; | 1097 | return mb_num - 1; |
| 1093 | 1098 | ||
| 1094 | skip_bits1(&s->gb); | 1099 | skip_bits1(&h->c.gb); |
| 1095 | if (bits & 0x10000) { | 1100 | if (bits & 0x10000) { |
| 1096 | /* skip mb */ | 1101 | /* skip mb */ |
| 1097 | if (s->pict_type == AV_PICTURE_TYPE_S && | 1102 | if (h->c.pict_type == AV_PICTURE_TYPE_S && |
| 1098 | ctx->vol_sprite_usage == GMC_SPRITE) { | 1103 | ctx->vol_sprite_usage == GMC_SPRITE) { |
| 1099 | s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | | 1104 | h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | |
| 1100 | MB_TYPE_16x16 | | 1105 | MB_TYPE_16x16 | |
| 1101 | MB_TYPE_GMC | | 1106 | MB_TYPE_GMC | |
| 1102 | MB_TYPE_FORWARD_MV; | 1107 | MB_TYPE_FORWARD_MV; |
| 1103 | mx = get_amv(ctx, 0); | 1108 | mx = get_amv(ctx, 0); |
| 1104 | my = get_amv(ctx, 1); | 1109 | my = get_amv(ctx, 1); |
| 1105 | } else { | 1110 | } else { |
| 1106 | s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | | 1111 | h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | |
| 1107 | MB_TYPE_16x16 | | 1112 | MB_TYPE_16x16 | |
| 1108 | MB_TYPE_FORWARD_MV; | 1113 | MB_TYPE_FORWARD_MV; |
| 1109 | mx = my = 0; | 1114 | mx = my = 0; |
| @@ -1117,26 +1122,26 @@ try_again: · 7 unmodified lines | |||
| 1117 | mot_val[1 + stride] = | 1122 | mot_val[1 + stride] = |
| 1118 | mot_val[3 + stride] = my; | 1123 | mot_val[3 + stride] = my; |
| 1119 | 1124 | ||
| 1120 | ff_h263_clean_intra_table_entries(s, xy); | 1125 | ff_h263_clean_intra_table_entries(&h->c, xy); |
| 1121 | continue; | 1126 | continue; |
| 1122 | } | 1127 | } |
| 1123 | 1128 | ||
| 1124 | cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); | 1129 | cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); |
| 1125 | if (cbpc < 0) { | 1130 | if (cbpc < 0) { |
| 1126 | av_log(s->avctx, AV_LOG_ERROR, | 1131 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1127 | "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | 1132 | "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1128 | return AVERROR_INVALIDDATA; | 1133 | return AVERROR_INVALIDDATA; |
| 1129 | } | 1134 | } |
| 1130 | if (cbpc == 20) | 1135 | if (cbpc == 20) |
| 1131 | goto try_again; | 1136 | goto try_again; |
| 1132 | 1137 | ||
| 1133 | s->cbp_table[xy] = cbpc & (8 + 3); // 8 is dquant | 1138 | h->c.cbp_table[xy] = cbpc & (8 + 3); // 8 is dquant |
| 1134 | 1139 | ||
| 1135 | s->mb_intra = ((cbpc & 4) != 0); | 1140 | h->c.mb_intra = ((cbpc & 4) != 0); |
| 1136 | 1141 | ||
| 1137 | if (s->mb_intra) { | 1142 | if (h->c.mb_intra) { |
| 1138 | s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | 1143 | h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; |
| 1139 | s->mbintra_table[xy] = 1; | 1144 | h->c.mbintra_table[xy] = 1; |
| 1140 | mot_val[0] = | 1145 | mot_val[0] = |
| 1141 | mot_val[2] = | 1146 | mot_val[2] = |
| 1142 | mot_val[0 + stride] = | 1147 | mot_val[0 + stride] = |
| @@ -1146,33 +1151,33 @@ try_again: · 3 unmodified lines | |||
| 1146 | mot_val[1 + stride] = | 1151 | mot_val[1 + stride] = |
| 1147 | mot_val[3 + stride] = 0; | 1152 | mot_val[3 + stride] = 0; |
| 1148 | } else { | 1153 | } else { |
| 1149 | ff_h263_clean_intra_table_entries(s, xy); | 1154 | ff_h263_clean_intra_table_entries(&h->c, xy); |
| 1150 | 1155 | ||
| 1151 | if (s->pict_type == AV_PICTURE_TYPE_S && | 1156 | if (h->c.pict_type == AV_PICTURE_TYPE_S && |
| 1152 | ctx->vol_sprite_usage == GMC_SPRITE && | 1157 | ctx->vol_sprite_usage == GMC_SPRITE && |
| 1153 | (cbpc & 16) == 0) | 1158 | (cbpc & 16) == 0) |
| 1154 | s->mcsel = get_bits1(&s->gb); | 1159 | h->c.mcsel = get_bits1(&h->c.gb); |
| 1155 | else | 1160 | else |
| 1156 | s->mcsel = 0; | 1161 | h->c.mcsel = 0; |
| 1157 | 1162 | ||
| 1158 | if ((cbpc & 16) == 0) { | 1163 | if ((cbpc & 16) == 0) { |
| 1159 | /* 16x16 motion prediction */ | 1164 | /* 16x16 motion prediction */ |
| 1160 | 1165 | ||
| 1161 | ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | 1166 | ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); |
| 1162 | if (!s->mcsel) { | 1167 | if (!h->c.mcsel) { |
| 1163 | mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | 1168 | mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); |
| 1164 | if (mx >= 0xffff) | 1169 | if (mx >= 0xffff) |
| 1165 | return AVERROR_INVALIDDATA; | 1170 | return AVERROR_INVALIDDATA; |
| 1166 | 1171 | ||
| 1167 | my = ff_h263_decode_motion(s, pred_y, ctx->f_code); | 1172 | my = ff_h263_decode_motion(h, pred_y, ctx->f_code); |
| 1168 | if (my >= 0xffff) | 1173 | if (my >= 0xffff) |
| 1169 | return AVERROR_INVALIDDATA; | 1174 | return AVERROR_INVALIDDATA; |
| 1170 | s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | | 1175 | h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | |
| 1171 | MB_TYPE_FORWARD_MV; | 1176 | MB_TYPE_FORWARD_MV; |
| 1172 | } else { | 1177 | } else { |
| 1173 | mx = get_amv(ctx, 0); | 1178 | mx = get_amv(ctx, 0); |
| 1174 | my = get_amv(ctx, 1); | 1179 | my = get_amv(ctx, 1); |
| 1175 | s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | | 1180 | h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | |
| 1176 | MB_TYPE_GMC | | 1181 | MB_TYPE_GMC | |
| 1177 | MB_TYPE_FORWARD_MV; | 1182 | MB_TYPE_FORWARD_MV; |
| 1178 | } | 1183 | } |
| @@ -1187,15 +1192,15 @@ try_again: · 8 unmodified lines | |||
| 1187 | mot_val[3 + stride] = my; | 1192 | mot_val[3 + stride] = my; |
| 1188 | } else { | 1193 | } else { |
| 1189 | int i; | 1194 | int i; |
| 1190 | s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | | 1195 | h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | |
| 1191 | MB_TYPE_FORWARD_MV; | 1196 | MB_TYPE_FORWARD_MV; |
| 1192 | for (i = 0; i < 4; i++) { | 1197 | for (i = 0; i < 4; i++) { |
| 1193 | int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | 1198 | int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); |
| 1194 | mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | 1199 | mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); |
| 1195 | if (mx >= 0xffff) | 1200 | if (mx >= 0xffff) |
| 1196 | return AVERROR_INVALIDDATA; | 1201 | return AVERROR_INVALIDDATA; |
| 1197 | 1202 | ||
| 1198 | my = ff_h263_decode_motion(s, pred_y, ctx->f_code); | 1203 | my = ff_h263_decode_motion(h, pred_y, ctx->f_code); |
| 1199 | if (my >= 0xffff) | 1204 | if (my >= 0xffff) |
| 1200 | return AVERROR_INVALIDDATA; | 1205 | return AVERROR_INVALIDDATA; |
| 1201 | mot_val[0] = mx; | 1206 | mot_val[0] = mx; |
| @@ -1205,7 +1210,7 @@ try_again: · 3 unmodified lines | |||
| 1205 | } | 1210 | } |
| 1206 | } | 1211 | } |
| 1207 | } | 1212 | } |
| 1208 | s->mb_x = 0; | 1213 | h->c.mb_x = 0; |
| 1209 | } | 1214 | } |
| 1210 | 1215 | ||
| 1211 | return mb_num; | 1216 | return mb_num; |
| @@ -1215,91 +1220,91 @@ try_again: · 3 unmodified lines | |||
| 1215 | * decode second partition. | 1220 | * decode second partition. |
| 1216 | * @return <0 if an error occurred | 1221 | * @return <0 if an error occurred |
| 1217 | */ | 1222 | */ |
| 1218 | static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) | 1223 | static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count) |
| 1219 | { | 1224 | { |
| 1220 | int mb_num = 0; | 1225 | int mb_num = 0; |
| 1221 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; | 1226 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
| 1222 | 1227 | ||
| 1223 | s->mb_x = s->resync_mb_x; | 1228 | h->c.mb_x = h->c.resync_mb_x; |
| 1224 | s->first_slice_line = 1; | 1229 | h->c.first_slice_line = 1; |
| 1225 | for (s->mb_y = s->resync_mb_y; mb_num < mb_count; s->mb_y++) { | 1230 | for (h->c.mb_y = h->c.resync_mb_y; mb_num < mb_count; h->c.mb_y++) { |
| 1226 | ff_init_block_index(s); | 1231 | ff_init_block_index(&h->c); |
| 1227 | for (; mb_num < mb_count && s->mb_x < s->mb_width; s->mb_x++) { | 1232 | for (; mb_num < mb_count && h->c.mb_x < h->c.mb_width; h->c.mb_x++) { |
| 1228 | const int xy = s->mb_x + s->mb_y * s->mb_stride; | 1233 | const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; |
| 1229 | 1234 | ||
| 1230 | mb_num++; | 1235 | mb_num++; |
| 1231 | ff_update_block_index(s, 8, s->avctx->lowres, 1); | 1236 | ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1); |
| 1232 | if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) | 1237 | if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1) |
| 1233 | s->first_slice_line = 0; | 1238 | h->c.first_slice_line = 0; |
| 1234 | 1239 | ||
| 1235 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 1240 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 1236 | int ac_pred = get_bits1(&s->gb); | 1241 | int ac_pred = get_bits1(&h->c.gb); |
| 1237 | int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 1242 | int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 1238 | if (cbpy < 0) { | 1243 | if (cbpy < 0) { |
| 1239 | av_log(s->avctx, AV_LOG_ERROR, | 1244 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1240 | "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | 1245 | "cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1241 | return AVERROR_INVALIDDATA; | 1246 | return AVERROR_INVALIDDATA; |
| 1242 | } | 1247 | } |
| 1243 | 1248 | ||
| 1244 | s->cbp_table[xy] |= cbpy << 2; | 1249 | h->c.cbp_table[xy] |= cbpy << 2; |
| 1245 | s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; | 1250 | h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; |
| 1246 | } else { /* P || S_TYPE */ | 1251 | } else { /* P || S_TYPE */ |
| 1247 | if (IS_INTRA(s->cur_pic.mb_type[xy])) { | 1252 | if (IS_INTRA(h->c.cur_pic.mb_type[xy])) { |
| 1248 | int i; | 1253 | int i; |
| 1249 | int dir = 0; | 1254 | int dir = 0; |
| 1250 | int ac_pred = get_bits1(&s->gb); | 1255 | int ac_pred = get_bits1(&h->c.gb); |
| 1251 | int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 1256 | int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 1252 | 1257 | ||
| 1253 | if (cbpy < 0) { | 1258 | if (cbpy < 0) { |
| 1254 | av_log(s->avctx, AV_LOG_ERROR, | 1259 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1255 | "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | 1260 | "I cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1256 | return AVERROR_INVALIDDATA; | 1261 | return AVERROR_INVALIDDATA; |
| 1257 | } | 1262 | } |
| 1258 | 1263 | ||
| 1259 | if (s->cbp_table[xy] & 8) | 1264 | if (h->c.cbp_table[xy] & 8) |
| 1260 | ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | 1265 | ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); |
| 1261 | s->cur_pic.qscale_table[xy] = s->qscale; | 1266 | h->c.cur_pic.qscale_table[xy] = h->c.qscale; |
| 1262 | 1267 | ||
| 1263 | for (i = 0; i < 6; i++) { | 1268 | for (i = 0; i < 6; i++) { |
| 1264 | int dc_pred_dir; | 1269 | int dc_pred_dir; |
| 1265 | int dc = mpeg4_decode_dc(s, i, &dc_pred_dir); | 1270 | int dc = mpeg4_decode_dc(h, i, &dc_pred_dir); |
| 1266 | if (dc < 0) { | 1271 | if (dc < 0) { |
| 1267 | av_log(s->avctx, AV_LOG_ERROR, | 1272 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1268 | "DC corrupted at %d %d\n", s->mb_x, s->mb_y); | 1273 | "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1269 | return dc; | 1274 | return dc; |
| 1270 | } | 1275 | } |
| 1271 | dir <<= 1; | 1276 | dir <<= 1; |
| 1272 | if (dc_pred_dir) | 1277 | if (dc_pred_dir) |
| 1273 | dir |= 1; | 1278 | dir |= 1; |
| 1274 | } | 1279 | } |
| 1275 | s->cbp_table[xy] &= 3; // remove dquant | 1280 | h->c.cbp_table[xy] &= 3; // remove dquant |
| 1276 | s->cbp_table[xy] |= cbpy << 2; | 1281 | h->c.cbp_table[xy] |= cbpy << 2; |
| 1277 | s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; | 1282 | h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; |
| 1278 | s->pred_dir_table[xy] = dir; | 1283 | h->c.pred_dir_table[xy] = dir; |
| 1279 | } else if (IS_SKIP(s->cur_pic.mb_type[xy])) { | 1284 | } else if (IS_SKIP(h->c.cur_pic.mb_type[xy])) { |
| 1280 | s->cur_pic.qscale_table[xy] = s->qscale; | 1285 | h->c.cur_pic.qscale_table[xy] = h->c.qscale; |
| 1281 | s->cbp_table[xy] = 0; | 1286 | h->c.cbp_table[xy] = 0; |
| 1282 | } else { | 1287 | } else { |
| 1283 | int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 1288 | int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 1284 | 1289 | ||
| 1285 | if (cbpy < 0) { | 1290 | if (cbpy < 0) { |
| 1286 | av_log(s->avctx, AV_LOG_ERROR, | 1291 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1287 | "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | 1292 | "P cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1288 | return AVERROR_INVALIDDATA; | 1293 | return AVERROR_INVALIDDATA; |
| 1289 | } | 1294 | } |
| 1290 | 1295 | ||
| 1291 | if (s->cbp_table[xy] & 8) | 1296 | if (h->c.cbp_table[xy] & 8) |
| 1292 | ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | 1297 | ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); |
| 1293 | s->cur_pic.qscale_table[xy] = s->qscale; | 1298 | h->c.cur_pic.qscale_table[xy] = h->c.qscale; |
| 1294 | 1299 | ||
| 1295 | s->cbp_table[xy] &= 3; // remove dquant | 1300 | h->c.cbp_table[xy] &= 3; // remove dquant |
| 1296 | s->cbp_table[xy] |= (cbpy ^ 0xf) << 2; | 1301 | h->c.cbp_table[xy] |= (cbpy ^ 0xf) << 2; |
| 1297 | } | 1302 | } |
| 1298 | } | 1303 | } |
| 1299 | } | 1304 | } |
| 1300 | if (mb_num >= mb_count) | 1305 | if (mb_num >= mb_count) |
| 1301 | return 0; | 1306 | return 0; |
| 1302 | s->mb_x = 0; | 1307 | h->c.mb_x = 0; |
| 1303 | } | 1308 | } |
| 1304 | return 0; | 1309 | return 0; |
| 1305 | } | 1310 | } |
| @@ -1308,62 +1313,62 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) · 2 unmodified lines | |||
| 1308 | * Decode the first and second partition. | 1313 | * Decode the first and second partition. |
| 1309 | * @return <0 if error (and sets error type in the error_status_table) | 1314 | * @return <0 if error (and sets error type in the error_status_table) |
| 1310 | */ | 1315 | */ |
| 1311 | int ff_mpeg4_decode_partitions(MPVContext *const s) | 1316 | int ff_mpeg4_decode_partitions(H263DecContext *const h) |
| 1312 | { | 1317 | { |
| 1313 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 1318 | Mpeg4DecContext *const ctx = h263_to_mpeg4(h); |
| 1314 | int mb_num; | 1319 | int mb_num; |
| 1315 | int ret; | 1320 | int ret; |
| 1316 | const int part_a_error = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR; | 1321 | const int part_a_error = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR; |
| 1317 | const int part_a_end = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END; | 1322 | const int part_a_end = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END; |
| 1318 | 1323 | ||
| 1319 | mb_num = mpeg4_decode_partition_a(ctx); | 1324 | mb_num = mpeg4_decode_partition_a(ctx); |
| 1320 | if (mb_num <= 0) { | 1325 | if (mb_num <= 0) { |
| 1321 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 1326 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 1322 | s->mb_x, s->mb_y, part_a_error); | 1327 | h->c.mb_x, h->c.mb_y, part_a_error); |
| 1323 | return mb_num ? mb_num : AVERROR_INVALIDDATA; | 1328 | return mb_num ? mb_num : AVERROR_INVALIDDATA; |
| 1324 | } | 1329 | } |
| 1325 | 1330 | ||
| 1326 | if (s->resync_mb_x + s->resync_mb_y * s->mb_width + mb_num > s->mb_num) { | 1331 | if (h->c.resync_mb_x + h->c.resync_mb_y * h->c.mb_width + mb_num > h->c.mb_num) { |
| 1327 | av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n"); | 1332 | av_log(h->c.avctx, AV_LOG_ERROR, "slice below monitor ...\n"); |
| 1328 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 1333 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 1329 | s->mb_x, s->mb_y, part_a_error); | 1334 | h->c.mb_x, h->c.mb_y, part_a_error); |
| 1330 | return AVERROR_INVALIDDATA; | 1335 | return AVERROR_INVALIDDATA; |
| 1331 | } | 1336 | } |
| 1332 | 1337 | ||
| 1333 | s->mb_num_left = mb_num; | 1338 | h->c.mb_num_left = mb_num; |
| 1334 | 1339 | ||
| 1335 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 1340 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 1336 | while (show_bits(&s->gb, 9) == 1) | 1341 | while (show_bits(&h->c.gb, 9) == 1) |
| 1337 | skip_bits(&s->gb, 9); | 1342 | skip_bits(&h->c.gb, 9); |
| 1338 | if (get_bits(&s->gb, 19) != DC_MARKER) { | 1343 | if (get_bits(&h->c.gb, 19) != DC_MARKER) { |
| 1339 | av_log(s->avctx, AV_LOG_ERROR, | 1344 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1340 | "marker missing after first I partition at %d %d\n", | 1345 | "marker missing after first I partition at %d %d\n", |
| 1341 | s->mb_x, s->mb_y); | 1346 | h->c.mb_x, h->c.mb_y); |
| 1342 | return AVERROR_INVALIDDATA; | 1347 | return AVERROR_INVALIDDATA; |
| 1343 | } | 1348 | } |
| 1344 | } else { | 1349 | } else { |
| 1345 | while (show_bits(&s->gb, 10) == 1) | 1350 | while (show_bits(&h->c.gb, 10) == 1) |
| 1346 | skip_bits(&s->gb, 10); | 1351 | skip_bits(&h->c.gb, 10); |
| 1347 | if (get_bits(&s->gb, 17) != MOTION_MARKER) { | 1352 | if (get_bits(&h->c.gb, 17) != MOTION_MARKER) { |
| 1348 | av_log(s->avctx, AV_LOG_ERROR, | 1353 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1349 | "marker missing after first P partition at %d %d\n", | 1354 | "marker missing after first P partition at %d %d\n", |
| 1350 | s->mb_x, s->mb_y); | 1355 | h->c.mb_x, h->c.mb_y); |
| 1351 | return AVERROR_INVALIDDATA; | 1356 | return AVERROR_INVALIDDATA; |
| 1352 | } | 1357 | } |
| 1353 | } | 1358 | } |
| 1354 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 1359 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 1355 | s->mb_x - 1, s->mb_y, part_a_end); | 1360 | h->c.mb_x - 1, h->c.mb_y, part_a_end); |
| 1356 | 1361 | ||
| 1357 | ret = mpeg4_decode_partition_b(s, mb_num); | 1362 | ret = mpeg4_decode_partition_b(h, mb_num); |
| 1358 | if (ret < 0) { | 1363 | if (ret < 0) { |
| 1359 | if (s->pict_type == AV_PICTURE_TYPE_P) | 1364 | if (h->c.pict_type == AV_PICTURE_TYPE_P) |
| 1360 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 1365 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 1361 | s->mb_x, s->mb_y, ER_DC_ERROR); | 1366 | h->c.mb_x, h->c.mb_y, ER_DC_ERROR); |
| 1362 | return ret; | 1367 | return ret; |
| 1363 | } else { | 1368 | } else { |
| 1364 | if (s->pict_type == AV_PICTURE_TYPE_P) | 1369 | if (h->c.pict_type == AV_PICTURE_TYPE_P) |
| 1365 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | 1370 | ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, |
| 1366 | s->mb_x - 1, s->mb_y, ER_DC_END); | 1371 | h->c.mb_x - 1, h->c.mb_y, ER_DC_END); |
| 1367 | } | 1372 | } |
| 1368 | 1373 | ||
| 1369 | return 0; | 1374 | return 0; |
| @@ -1377,7 +1382,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 7 unmodified lines | |||
| 1377 | int n, int coded, int intra, | 1382 | int n, int coded, int intra, |
| 1378 | int use_intra_dc_vlc, int rvlc) | 1383 | int use_intra_dc_vlc, int rvlc) |
| 1379 | { | 1384 | { |
| 1380 | MpegEncContext *s = &ctx->m; | 1385 | H263DecContext *const h = &ctx->h; |
| 1381 | int level, i, last, run, qmul, qadd, pred; | 1386 | int level, i, last, run, qmul, qadd, pred; |
| 1382 | int av_uninit(dc_pred_dir); | 1387 | int av_uninit(dc_pred_dir); |
| 1383 | const RLTable *rl; | 1388 | const RLTable *rl; |
| @@ -1390,15 +1395,15 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 6 unmodified lines | |||
| 1390 | // FIXME add short header support | 1395 | // FIXME add short header support |
| 1391 | if (use_intra_dc_vlc) { | 1396 | if (use_intra_dc_vlc) { |
| 1392 | /* DC coef */ | 1397 | /* DC coef */ |
| 1393 | if (s->partitioned_frame) { | 1398 | if (h->c.partitioned_frame) { |
| 1394 | level = s->dc_val[s->block_index[n]]; | 1399 | level = h->c.dc_val[h->c.block_index[n]]; |
| 1395 | if (n < 4) | 1400 | if (n < 4) |
| 1396 | level = FASTDIV((level + (s->y_dc_scale >> 1)), s->y_dc_scale); | 1401 | level = FASTDIV((level + (h->c.y_dc_scale >> 1)), h->c.y_dc_scale); |
| 1397 | else | 1402 | else |
| 1398 | level = FASTDIV((level + (s->c_dc_scale >> 1)), s->c_dc_scale); | 1403 | level = FASTDIV((level + (h->c.c_dc_scale >> 1)), h->c.c_dc_scale); |
| 1399 | dc_pred_dir = (s->pred_dir_table[s->mb_x + s->mb_y * s->mb_stride] << n) & 32; | 1404 | dc_pred_dir = (h->c.pred_dir_table[h->c.mb_x + h->c.mb_y * h->c.mb_stride] << n) & 32; |
| 1400 | } else { | 1405 | } else { |
| 1401 | level = mpeg4_decode_dc(s, n, &dc_pred_dir); | 1406 | level = mpeg4_decode_dc(h, n, &dc_pred_dir); |
| 1402 | if (level < 0) | 1407 | if (level < 0) |
| 1403 | return level; | 1408 | return level; |
| 1404 | } | 1409 | } |
| @@ -1406,7 +1411,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line | |||
| 1406 | i = 0; | 1411 | i = 0; |
| 1407 | } else { | 1412 | } else { |
| 1408 | i = -1; | 1413 | i = -1; |
| 1409 | pred = mpeg4_pred_dc(s, n, &dc_pred_dir); | 1414 | pred = mpeg4_pred_dc(&h->c, n, &dc_pred_dir); |
| 1410 | } | 1415 | } |
| 1411 | if (!coded) | 1416 | if (!coded) |
| 1412 | goto not_coded; | 1417 | goto not_coded; |
| @@ -1418,20 +1423,20 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 5 unmodified lines | |||
| 1418 | rl = &ff_mpeg4_rl_intra; | 1423 | rl = &ff_mpeg4_rl_intra; |
| 1419 | rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0]; | 1424 | rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0]; |
| 1420 | } | 1425 | } |
| 1421 | if (s->ac_pred) { | 1426 | if (h->c.ac_pred) { |
| 1422 | if (dc_pred_dir == 0) | 1427 | if (dc_pred_dir == 0) |
| 1423 | scan_table = s->permutated_intra_v_scantable; /* left */ | 1428 | scan_table = h->c.permutated_intra_v_scantable; /* left */ |
| 1424 | else | 1429 | else |
| 1425 | scan_table = s->permutated_intra_h_scantable; /* top */ | 1430 | scan_table = h->c.permutated_intra_h_scantable; /* top */ |
| 1426 | } else { | 1431 | } else { |
| 1427 | scan_table = s->intra_scantable.permutated; | 1432 | scan_table = h->c.intra_scantable.permutated; |
| 1428 | } | 1433 | } |
| 1429 | qmul = 1; | 1434 | qmul = 1; |
| 1430 | qadd = 0; | 1435 | qadd = 0; |
| 1431 | } else { | 1436 | } else { |
| 1432 | i = -1; | 1437 | i = -1; |
| 1433 | if (!coded) { | 1438 | if (!coded) { |
| 1434 | s->block_last_index[n] = i; | 1439 | h->c.block_last_index[n] = i; |
| 1435 | return 0; | 1440 | return 0; |
| 1436 | } | 1441 | } |
| 1437 | if (rvlc) | 1442 | if (rvlc) |
| @@ -1439,7 +1444,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line | |||
| 1439 | else | 1444 | else |
| 1440 | rl = &ff_h263_rl_inter; | 1445 | rl = &ff_h263_rl_inter; |
| 1441 | 1446 | ||
| 1442 | scan_table = s->intra_scantable.permutated; | 1447 | scan_table = h->c.intra_scantable.permutated; |
| 1443 | 1448 | ||
| 1444 | if (ctx->mpeg_quant) { | 1449 | if (ctx->mpeg_quant) { |
| 1445 | qmul = 1; | 1450 | qmul = 1; |
| @@ -1449,61 +1454,61 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 3 unmodified lines | |||
| 1449 | else | 1454 | else |
| 1450 | rl_vlc = ff_h263_rl_inter.rl_vlc[0]; | 1455 | rl_vlc = ff_h263_rl_inter.rl_vlc[0]; |
| 1451 | } else { | 1456 | } else { |
| 1452 | qmul = s->qscale << 1; | 1457 | qmul = h->c.qscale << 1; |
| 1453 | qadd = (s->qscale - 1) | 1; | 1458 | qadd = (h->c.qscale - 1) | 1; |
| 1454 | if (rvlc) | 1459 | if (rvlc) |
| 1455 | rl_vlc = ff_rvlc_rl_inter.rl_vlc[s->qscale]; | 1460 | rl_vlc = ff_rvlc_rl_inter.rl_vlc[h->c.qscale]; |
| 1456 | else | 1461 | else |
| 1457 | rl_vlc = ff_h263_rl_inter.rl_vlc[s->qscale]; | 1462 | rl_vlc = ff_h263_rl_inter.rl_vlc[h->c.qscale]; |
| 1458 | } | 1463 | } |
| 1459 | } | 1464 | } |
| 1460 | { | 1465 | { |
| 1461 | OPEN_READER(re, &s->gb); | 1466 | OPEN_READER(re, &h->c.gb); |
| 1462 | for (;;) { | 1467 | for (;;) { |
| 1463 | UPDATE_CACHE(re, &s->gb); | 1468 | UPDATE_CACHE(re, &h->c.gb); |
| 1464 | GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); | 1469 | GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0); |
| 1465 | if (level == 0) { | 1470 | if (level == 0) { |
| 1466 | /* escape */ | 1471 | /* escape */ |
| 1467 | if (rvlc) { | 1472 | if (rvlc) { |
| 1468 | if (SHOW_UBITS(re, &s->gb, 1) == 0) { | 1473 | if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { |
| 1469 | av_log(s->avctx, AV_LOG_ERROR, | 1474 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1470 | "1. marker bit missing in rvlc esc\n"); | 1475 | "1. marker bit missing in rvlc esc\n"); |
| 1471 | return AVERROR_INVALIDDATA; | 1476 | return AVERROR_INVALIDDATA; |
| 1472 | } | 1477 | } |
| 1473 | SKIP_CACHE(re, &s->gb, 1); | 1478 | SKIP_CACHE(re, &h->c.gb, 1); |
| 1474 | 1479 | ||
| 1475 | last = SHOW_UBITS(re, &s->gb, 1); | 1480 | last = SHOW_UBITS(re, &h->c.gb, 1); |
| 1476 | SKIP_CACHE(re, &s->gb, 1); | 1481 | SKIP_CACHE(re, &h->c.gb, 1); |
| 1477 | run = SHOW_UBITS(re, &s->gb, 6); | 1482 | run = SHOW_UBITS(re, &h->c.gb, 6); |
| 1478 | SKIP_COUNTER(re, &s->gb, 1 + 1 + 6); | 1483 | SKIP_COUNTER(re, &h->c.gb, 1 + 1 + 6); |
| 1479 | UPDATE_CACHE(re, &s->gb); | 1484 | UPDATE_CACHE(re, &h->c.gb); |
| 1480 | 1485 | ||
| 1481 | if (SHOW_UBITS(re, &s->gb, 1) == 0) { | 1486 | if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { |
| 1482 | av_log(s->avctx, AV_LOG_ERROR, | 1487 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1483 | "2. marker bit missing in rvlc esc\n"); | 1488 | "2. marker bit missing in rvlc esc\n"); |
| 1484 | return AVERROR_INVALIDDATA; | 1489 | return AVERROR_INVALIDDATA; |
| 1485 | } | 1490 | } |
| 1486 | SKIP_CACHE(re, &s->gb, 1); | 1491 | SKIP_CACHE(re, &h->c.gb, 1); |
| 1487 | 1492 | ||
| 1488 | level = SHOW_UBITS(re, &s->gb, 11); | 1493 | level = SHOW_UBITS(re, &h->c.gb, 11); |
| 1489 | SKIP_CACHE(re, &s->gb, 11); | 1494 | SKIP_CACHE(re, &h->c.gb, 11); |
| 1490 | 1495 | ||
| 1491 | if (SHOW_UBITS(re, &s->gb, 5) != 0x10) { | 1496 | if (SHOW_UBITS(re, &h->c.gb, 5) != 0x10) { |
| 1492 | av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n"); | 1497 | av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n"); |
| 1493 | return AVERROR_INVALIDDATA; | 1498 | return AVERROR_INVALIDDATA; |
| 1494 | } | 1499 | } |
| 1495 | SKIP_CACHE(re, &s->gb, 5); | 1500 | SKIP_CACHE(re, &h->c.gb, 5); |
| 1496 | 1501 | ||
| 1497 | level = level * qmul + qadd; | 1502 | level = level * qmul + qadd; |
| 1498 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1503 | level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); |
| 1499 | SKIP_COUNTER(re, &s->gb, 1 + 11 + 5 + 1); | 1504 | SKIP_COUNTER(re, &h->c.gb, 1 + 11 + 5 + 1); |
| 1500 | 1505 | ||
| 1501 | i += run + 1; | 1506 | i += run + 1; |
| 1502 | if (last) | 1507 | if (last) |
| 1503 | i += 192; | 1508 | i += 192; |
| 1504 | } else { | 1509 | } else { |
| 1505 | int cache; | 1510 | int cache; |
| 1506 | cache = GET_CACHE(re, &s->gb); | 1511 | cache = GET_CACHE(re, &h->c.gb); |
| 1507 | 1512 | ||
| 1508 | if (IS_3IV1) | 1513 | if (IS_3IV1) |
| 1509 | cache ^= 0xC0000000; | 1514 | cache ^= 0xC0000000; |
| @@ -1511,54 +1516,54 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line | |||
| 1511 | if (cache & 0x80000000) { | 1516 | if (cache & 0x80000000) { |
| 1512 | if (cache & 0x40000000) { | 1517 | if (cache & 0x40000000) { |
| 1513 | /* third escape */ | 1518 | /* third escape */ |
| 1514 | SKIP_CACHE(re, &s->gb, 2); | 1519 | SKIP_CACHE(re, &h->c.gb, 2); |
| 1515 | last = SHOW_UBITS(re, &s->gb, 1); | 1520 | last = SHOW_UBITS(re, &h->c.gb, 1); |
| 1516 | SKIP_CACHE(re, &s->gb, 1); | 1521 | SKIP_CACHE(re, &h->c.gb, 1); |
| 1517 | run = SHOW_UBITS(re, &s->gb, 6); | 1522 | run = SHOW_UBITS(re, &h->c.gb, 6); |
| 1518 | SKIP_COUNTER(re, &s->gb, 2 + 1 + 6); | 1523 | SKIP_COUNTER(re, &h->c.gb, 2 + 1 + 6); |
| 1519 | UPDATE_CACHE(re, &s->gb); | 1524 | UPDATE_CACHE(re, &h->c.gb); |
| 1520 | 1525 | ||
| 1521 | if (IS_3IV1) { | 1526 | if (IS_3IV1) { |
| 1522 | level = SHOW_SBITS(re, &s->gb, 12); | 1527 | level = SHOW_SBITS(re, &h->c.gb, 12); |
| 1523 | LAST_SKIP_BITS(re, &s->gb, 12); | 1528 | LAST_SKIP_BITS(re, &h->c.gb, 12); |
| 1524 | } else { | 1529 | } else { |
| 1525 | if (SHOW_UBITS(re, &s->gb, 1) == 0) { | 1530 | if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { |
| 1526 | av_log(s->avctx, AV_LOG_ERROR, | 1531 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1527 | "1. marker bit missing in 3. esc\n"); | 1532 | "1. marker bit missing in 3. esc\n"); |
| 1528 | if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0) | 1533 | if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0) |
| 1529 | return AVERROR_INVALIDDATA; | 1534 | return AVERROR_INVALIDDATA; |
| 1530 | } | 1535 | } |
| 1531 | SKIP_CACHE(re, &s->gb, 1); | 1536 | SKIP_CACHE(re, &h->c.gb, 1); |
| 1532 | 1537 | ||
| 1533 | level = SHOW_SBITS(re, &s->gb, 12); | 1538 | level = SHOW_SBITS(re, &h->c.gb, 12); |
| 1534 | SKIP_CACHE(re, &s->gb, 12); | 1539 | SKIP_CACHE(re, &h->c.gb, 12); |
| 1535 | 1540 | ||
| 1536 | if (SHOW_UBITS(re, &s->gb, 1) == 0) { | 1541 | if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { |
| 1537 | av_log(s->avctx, AV_LOG_ERROR, | 1542 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1538 | "2. marker bit missing in 3. esc\n"); | 1543 | "2. marker bit missing in 3. esc\n"); |
| 1539 | if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0) | 1544 | if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0) |
| 1540 | return AVERROR_INVALIDDATA; | 1545 | return AVERROR_INVALIDDATA; |
| 1541 | } | 1546 | } |
| 1542 | 1547 | ||
| 1543 | SKIP_COUNTER(re, &s->gb, 1 + 12 + 1); | 1548 | SKIP_COUNTER(re, &h->c.gb, 1 + 12 + 1); |
| 1544 | } | 1549 | } |
| 1545 | 1550 | ||
| 1546 | #if 0 | 1551 | #if 0 |
| 1547 | if (s->error_recognition >= FF_ER_COMPLIANT) { | 1552 | if (h->c.error_recognition >= FF_ER_COMPLIANT) { |
| 1548 | const int abs_level= FFABS(level); | 1553 | const int abs_level= FFABS(level); |
| 1549 | if (abs_level<=MAX_LEVEL && run<=MAX_RUN) { | 1554 | if (abs_level<=MAX_LEVEL && run<=MAX_RUN) { |
| 1550 | const int run1= run - rl->max_run[last][abs_level] - 1; | 1555 | const int run1= run - rl->max_run[last][abs_level] - 1; |
| 1551 | if (abs_level <= rl->max_level[last][run]) { | 1556 | if (abs_level <= rl->max_level[last][run]) { |
| 1552 | av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); | 1557 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); |
| 1553 | return AVERROR_INVALIDDATA; | 1558 | return AVERROR_INVALIDDATA; |
| 1554 | } | 1559 | } |
| 1555 | if (s->error_recognition > FF_ER_COMPLIANT) { | 1560 | if (h->c.error_recognition > FF_ER_COMPLIANT) { |
| 1556 | if (abs_level <= rl->max_level[last][run]*2) { | 1561 | if (abs_level <= rl->max_level[last][run]*2) { |
| 1557 | av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); | 1562 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); |
| 1558 | return AVERROR_INVALIDDATA; | 1563 | return AVERROR_INVALIDDATA; |
| 1559 | } | 1564 | } |
| 1560 | if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) { | 1565 | if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) { |
| 1561 | av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); | 1566 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); |
| 1562 | return AVERROR_INVALIDDATA; | 1567 | return AVERROR_INVALIDDATA; |
| 1563 | } | 1568 | } |
| 1564 | } | 1569 | } |
| @@ -1571,11 +1576,11 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 6 unmodified lines | |||
| 1571 | level = level * qmul - qadd; | 1576 | level = level * qmul - qadd; |
| 1572 | 1577 | ||
| 1573 | if ((unsigned)(level + 2048) > 4095) { | 1578 | if ((unsigned)(level + 2048) > 4095) { |
| 1574 | if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) { | 1579 | if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) { |
| 1575 | if (level > 2560 || level < -2560) { | 1580 | if (level > 2560 || level < -2560) { |
| 1576 | av_log(s->avctx, AV_LOG_ERROR, | 1581 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1577 | "|level| overflow in 3. esc, qp=%d\n", | 1582 | "|level| overflow in 3. esc, qp=%d\n", |
| 1578 | s->qscale); | 1583 | h->c.qscale); |
| 1579 | return AVERROR_INVALIDDATA; | 1584 | return AVERROR_INVALIDDATA; |
| 1580 | } | 1585 | } |
| 1581 | } | 1586 | } |
| @@ -1587,33 +1592,33 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 5 unmodified lines | |||
| 1587 | i += 192; | 1592 | i += 192; |
| 1588 | } else { | 1593 | } else { |
| 1589 | /* second escape */ | 1594 | /* second escape */ |
| 1590 | SKIP_BITS(re, &s->gb, 2); | 1595 | SKIP_BITS(re, &h->c.gb, 2); |
| 1591 | GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | 1596 | GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
| 1592 | i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing | 1597 | i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing |
| 1593 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1598 | level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); |
| 1594 | LAST_SKIP_BITS(re, &s->gb, 1); | 1599 | LAST_SKIP_BITS(re, &h->c.gb, 1); |
| 1595 | } | 1600 | } |
| 1596 | } else { | 1601 | } else { |
| 1597 | /* first escape */ | 1602 | /* first escape */ |
| 1598 | SKIP_BITS(re, &s->gb, 1); | 1603 | SKIP_BITS(re, &h->c.gb, 1); |
| 1599 | GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | 1604 | GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
| 1600 | i += run; | 1605 | i += run; |
| 1601 | level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing | 1606 | level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing |
| 1602 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1607 | level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); |
| 1603 | LAST_SKIP_BITS(re, &s->gb, 1); | 1608 | LAST_SKIP_BITS(re, &h->c.gb, 1); |
| 1604 | } | 1609 | } |
| 1605 | } | 1610 | } |
| 1606 | } else { | 1611 | } else { |
| 1607 | i += run; | 1612 | i += run; |
| 1608 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 1613 | level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); |
| 1609 | LAST_SKIP_BITS(re, &s->gb, 1); | 1614 | LAST_SKIP_BITS(re, &h->c.gb, 1); |
| 1610 | } | 1615 | } |
| 1611 | ff_tlog(s->avctx, "dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62); | 1616 | ff_tlog(h->c.avctx, "dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62); |
| 1612 | if (i > 62) { | 1617 | if (i > 62) { |
| 1613 | i -= 192; | 1618 | i -= 192; |
| 1614 | if (i & (~63)) { | 1619 | if (i & (~63)) { |
| 1615 | av_log(s->avctx, AV_LOG_ERROR, | 1620 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1616 | "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | 1621 | "ac-tex damaged at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1617 | return AVERROR_INVALIDDATA; | 1622 | return AVERROR_INVALIDDATA; |
| 1618 | } | 1623 | } |
| 1619 | 1624 | ||
| @@ -1623,22 +1628,22 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 3 unmodified lines | |||
| 1623 | 1628 | ||
| 1624 | block[scan_table[i]] = level; | 1629 | block[scan_table[i]] = level; |
| 1625 | } | 1630 | } |
| 1626 | CLOSE_READER(re, &s->gb); | 1631 | CLOSE_READER(re, &h->c.gb); |
| 1627 | } | 1632 | } |
| 1628 | 1633 | ||
| 1629 | not_coded: | 1634 | not_coded: |
| 1630 | if (intra) { | 1635 | if (intra) { |
| 1631 | if (!use_intra_dc_vlc) { | 1636 | if (!use_intra_dc_vlc) { |
| 1632 | block[0] = mpeg4_get_level_dc(s, n, pred, block[0]); | 1637 | block[0] = mpeg4_get_level_dc(&h->c, n, pred, block[0]); |
| 1633 | 1638 | ||
| 1634 | i -= i >> 31; // if (i == -1) i = 0; | 1639 | i -= i >> 31; // if (i == -1) i = 0; |
| 1635 | } | 1640 | } |
| 1636 | 1641 | ||
| 1637 | ff_mpeg4_pred_ac(s, block, n, dc_pred_dir); | 1642 | ff_mpeg4_pred_ac(h, block, n, dc_pred_dir); |
| 1638 | if (s->ac_pred) | 1643 | if (h->c.ac_pred) |
| 1639 | i = 63; // FIXME not optimal | 1644 | i = 63; // FIXME not optimal |
| 1640 | } | 1645 | } |
| 1641 | s->block_last_index[n] = i; | 1646 | h->c.block_last_index[n] = i; |
| 1642 | return 0; | 1647 | return 0; |
| 1643 | } | 1648 | } |
| 1644 | 1649 | ||
| @@ -1646,72 +1651,71 @@ not_coded: · 1 unmodified line | |||
| 1646 | * decode partition C of one MB. | 1651 | * decode partition C of one MB. |
| 1647 | * @return <0 if an error occurred | 1652 | * @return <0 if an error occurred |
| 1648 | */ | 1653 | */ |
| 1649 | static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64]) | 1654 | static int mpeg4_decode_partitioned_mb(H263DecContext *const h, int16_t block[6][64]) |
| 1650 | { | 1655 | { |
| 1651 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 1656 | Mpeg4DecContext *const ctx = h263_to_mpeg4(h); |
| 1652 | int cbp, mb_type, use_intra_dc_vlc; | 1657 | const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; |
| 1653 | const int xy = s->mb_x + s->mb_y * s->mb_stride; | ||
| 1654 | 1658 | ||
| 1655 | mb_type = s->cur_pic.mb_type[xy]; | 1659 | const int mb_type = h->c.cur_pic.mb_type[xy]; |
| 1656 | cbp = s->cbp_table[xy]; | 1660 | int cbp = h->c.cbp_table[xy]; |
| 1657 | 1661 | ||
| 1658 | use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold; | 1662 | const int use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold; |
| 1659 | 1663 | ||
| 1660 | if (s->cur_pic.qscale_table[xy] != s->qscale) | 1664 | if (h->c.cur_pic.qscale_table[xy] != h->c.qscale) |
| 1661 | ff_set_qscale(s, s->cur_pic.qscale_table[xy]); | 1665 | ff_set_qscale(&h->c, h->c.cur_pic.qscale_table[xy]); |
| 1662 | 1666 | ||
| 1663 | if (s->pict_type == AV_PICTURE_TYPE_P || | 1667 | if (h->c.pict_type == AV_PICTURE_TYPE_P || |
| 1664 | s->pict_type == AV_PICTURE_TYPE_S) { | 1668 | h->c.pict_type == AV_PICTURE_TYPE_S) { |
| 1665 | int i; | 1669 | int i; |
| 1666 | for (i = 0; i < 4; i++) { | 1670 | for (i = 0; i < 4; i++) { |
| 1667 | s->mv[0][i][0] = s->cur_pic.motion_val[0][s->block_index[i]][0]; | 1671 | h->c.mv[0][i][0] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][0]; |
| 1668 | s->mv[0][i][1] = s->cur_pic.motion_val[0][s->block_index[i]][1]; | 1672 | h->c.mv[0][i][1] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][1]; |
| 1669 | } | 1673 | } |
| 1670 | s->mb_intra = IS_INTRA(mb_type); | 1674 | h->c.mb_intra = IS_INTRA(mb_type); |
| 1671 | 1675 | ||
| 1672 | if (IS_SKIP(mb_type)) { | 1676 | if (IS_SKIP(mb_type)) { |
| 1673 | /* skip mb */ | 1677 | /* skip mb */ |
| 1674 | for (i = 0; i < 6; i++) | 1678 | for (i = 0; i < 6; i++) |
| 1675 | s->block_last_index[i] = -1; | 1679 | h->c.block_last_index[i] = -1; |
| 1676 | s->mv_dir = MV_DIR_FORWARD; | 1680 | h->c.mv_dir = MV_DIR_FORWARD; |
| 1677 | s->mv_type = MV_TYPE_16X16; | 1681 | h->c.mv_type = MV_TYPE_16X16; |
| 1678 | if (s->pict_type == AV_PICTURE_TYPE_S | 1682 | if (h->c.pict_type == AV_PICTURE_TYPE_S |
| 1679 | && ctx->vol_sprite_usage == GMC_SPRITE) { | 1683 | && ctx->vol_sprite_usage == GMC_SPRITE) { |
| 1680 | s->mcsel = 1; | 1684 | h->c.mcsel = 1; |
| 1681 | s->mb_skipped = 0; | 1685 | h->c.mb_skipped = 0; |
| 1682 | s->cur_pic.mbskip_table[xy] = 0; | 1686 | h->c.cur_pic.mbskip_table[xy] = 0; |
| 1683 | } else { | 1687 | } else { |
| 1684 | s->mcsel = 0; | 1688 | h->c.mcsel = 0; |
| 1685 | s->mb_skipped = 1; | 1689 | h->c.mb_skipped = 1; |
| 1686 | s->cur_pic.mbskip_table[xy] = 1; | 1690 | h->c.cur_pic.mbskip_table[xy] = 1; |
| 1687 | } | 1691 | } |
| 1688 | } else if (s->mb_intra) { | 1692 | } else if (h->c.mb_intra) { |
| 1689 | s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]); | 1693 | h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]); |
| 1690 | } else if (!s->mb_intra) { | 1694 | } else if (!h->c.mb_intra) { |
| 1691 | // s->mcsel = 0; // FIXME do we need to init that? | 1695 | // h->c.mcsel = 0; // FIXME do we need to init that? |
| 1692 | 1696 | ||
| 1693 | s->mv_dir = MV_DIR_FORWARD; | 1697 | h->c.mv_dir = MV_DIR_FORWARD; |
| 1694 | if (IS_8X8(mb_type)) { | 1698 | if (IS_8X8(mb_type)) { |
| 1695 | s->mv_type = MV_TYPE_8X8; | 1699 | h->c.mv_type = MV_TYPE_8X8; |
| 1696 | } else { | 1700 | } else { |
| 1697 | s->mv_type = MV_TYPE_16X16; | 1701 | h->c.mv_type = MV_TYPE_16X16; |
| 1698 | } | 1702 | } |
| 1699 | } | 1703 | } |
| 1700 | } else { /* I-Frame */ | 1704 | } else { /* I-Frame */ |
| 1701 | s->mb_intra = 1; | 1705 | h->c.mb_intra = 1; |
| 1702 | s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]); | 1706 | h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]); |
| 1703 | } | 1707 | } |
| 1704 | 1708 | ||
| 1705 | if (!IS_SKIP(mb_type)) { | 1709 | if (!IS_SKIP(mb_type)) { |
| 1706 | int i; | 1710 | int i; |
| 1707 | s->bdsp.clear_blocks(s->block[0]); | 1711 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 1708 | /* decode each block */ | 1712 | /* decode each block */ |
| 1709 | for (i = 0; i < 6; i++) { | 1713 | for (i = 0; i < 6; i++) { |
| 1710 | if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, s->mb_intra, | 1714 | if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, h->c.mb_intra, |
| 1711 | use_intra_dc_vlc, ctx->rvlc) < 0) { | 1715 | use_intra_dc_vlc, ctx->rvlc) < 0) { |
| 1712 | av_log(s->avctx, AV_LOG_ERROR, | 1716 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1713 | "texture corrupted at %d %d %d\n", | 1717 | "texture corrupted at %d %d %d\n", |
| 1714 | s->mb_x, s->mb_y, s->mb_intra); | 1718 | h->c.mb_x, h->c.mb_y, h->c.mb_intra); |
| 1715 | return AVERROR_INVALIDDATA; | 1719 | return AVERROR_INVALIDDATA; |
| 1716 | } | 1720 | } |
| 1717 | cbp += cbp; | 1721 | cbp += cbp; |
| @@ -1719,300 +1723,300 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line | |||
| 1719 | } | 1723 | } |
| 1720 | 1724 | ||
| 1721 | /* per-MB end of slice check */ | 1725 | /* per-MB end of slice check */ |
| 1722 | if (--s->mb_num_left <= 0) { | 1726 | if (--h->c.mb_num_left <= 0) { |
| 1723 | if (mpeg4_is_resync(ctx)) | 1727 | if (mpeg4_is_resync(ctx)) |
| 1724 | return SLICE_END; | 1728 | return SLICE_END; |
| 1725 | else | 1729 | else |
| 1726 | return SLICE_NOEND; | 1730 | return SLICE_NOEND; |
| 1727 | } else { | 1731 | } else { |
| 1728 | if (mpeg4_is_resync(ctx)) { | 1732 | if (mpeg4_is_resync(ctx)) { |
| 1729 | const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1; | 1733 | const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1; |
| 1730 | if (s->cbp_table[xy + delta]) | 1734 | if (h->c.cbp_table[xy + delta]) |
| 1731 | return SLICE_END; | 1735 | return SLICE_END; |
| 1732 | } | 1736 | } |
| 1733 | return SLICE_OK; | 1737 | return SLICE_OK; |
| 1734 | } | 1738 | } |
| 1735 | } | 1739 | } |
| 1736 | 1740 | ||
| 1737 | static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) | 1741 | static int mpeg4_decode_mb(H263DecContext *const h, int16_t block[6][64]) |
| 1738 | { | 1742 | { |
| 1739 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 1743 | Mpeg4DecContext *const ctx = h263_to_mpeg4(h); |
| 1740 | int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | 1744 | int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; |
| 1741 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; | 1745 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
| 1742 | const int xy = s->mb_x + s->mb_y * s->mb_stride; | 1746 | const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; |
| 1743 | int next; | 1747 | int next; |
| 1744 | 1748 | ||
| 1745 | av_assert2(s->h263_pred); | 1749 | av_assert2(h->c.h263_pred); |
| 1746 | 1750 | ||
| 1747 | if (s->pict_type == AV_PICTURE_TYPE_P || | 1751 | if (h->c.pict_type == AV_PICTURE_TYPE_P || |
| 1748 | s->pict_type == AV_PICTURE_TYPE_S) { | 1752 | h->c.pict_type == AV_PICTURE_TYPE_S) { |
| 1749 | do { | 1753 | do { |
| 1750 | if (get_bits1(&s->gb)) { | 1754 | if (get_bits1(&h->c.gb)) { |
| 1751 | /* skip mb */ | 1755 | /* skip mb */ |
| 1752 | s->mb_intra = 0; | 1756 | h->c.mb_intra = 0; |
| 1753 | for (i = 0; i < 6; i++) | 1757 | for (i = 0; i < 6; i++) |
| 1754 | s->block_last_index[i] = -1; | 1758 | h->c.block_last_index[i] = -1; |
| 1755 | s->mv_dir = MV_DIR_FORWARD; | 1759 | h->c.mv_dir = MV_DIR_FORWARD; |
| 1756 | s->mv_type = MV_TYPE_16X16; | 1760 | h->c.mv_type = MV_TYPE_16X16; |
| 1757 | if (s->pict_type == AV_PICTURE_TYPE_S && | 1761 | if (h->c.pict_type == AV_PICTURE_TYPE_S && |
| 1758 | ctx->vol_sprite_usage == GMC_SPRITE) { | 1762 | ctx->vol_sprite_usage == GMC_SPRITE) { |
| 1759 | s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | | 1763 | h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | |
| 1760 | MB_TYPE_GMC | | 1764 | MB_TYPE_GMC | |
| 1761 | MB_TYPE_16x16 | | 1765 | MB_TYPE_16x16 | |
| 1762 | MB_TYPE_FORWARD_MV; | 1766 | MB_TYPE_FORWARD_MV; |
| 1763 | s->mcsel = 1; | 1767 | h->c.mcsel = 1; |
| 1764 | s->mv[0][0][0] = get_amv(ctx, 0); | 1768 | h->c.mv[0][0][0] = get_amv(ctx, 0); |
| 1765 | s->mv[0][0][1] = get_amv(ctx, 1); | 1769 | h->c.mv[0][0][1] = get_amv(ctx, 1); |
| 1766 | s->cur_pic.mbskip_table[xy] = 0; | 1770 | h->c.cur_pic.mbskip_table[xy] = 0; |
| 1767 | s->mb_skipped = 0; | 1771 | h->c.mb_skipped = 0; |
| 1768 | } else { | 1772 | } else { |
| 1769 | s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | | 1773 | h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | |
| 1770 | MB_TYPE_FORWARD_MV; | 1774 | MB_TYPE_FORWARD_MV; |
| 1771 | s->mcsel = 0; | 1775 | h->c.mcsel = 0; |
| 1772 | s->mv[0][0][0] = 0; | 1776 | h->c.mv[0][0][0] = 0; |
| 1773 | s->mv[0][0][1] = 0; | 1777 | h->c.mv[0][0][1] = 0; |
| 1774 | s->cur_pic.mbskip_table[xy] = 1; | 1778 | h->c.cur_pic.mbskip_table[xy] = 1; |
| 1775 | s->mb_skipped = 1; | 1779 | h->c.mb_skipped = 1; |
| 1776 | } | 1780 | } |
| 1777 | goto end; | 1781 | goto end; |
| 1778 | } | 1782 | } |
| 1779 | cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); | 1783 | cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); |
| 1780 | if (cbpc < 0) { | 1784 | if (cbpc < 0) { |
| 1781 | av_log(s->avctx, AV_LOG_ERROR, | 1785 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1782 | "mcbpc damaged at %d %d\n", s->mb_x, s->mb_y); | 1786 | "mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1783 | return AVERROR_INVALIDDATA; | 1787 | return AVERROR_INVALIDDATA; |
| 1784 | } | 1788 | } |
| 1785 | } while (cbpc == 20); | 1789 | } while (cbpc == 20); |
| 1786 | 1790 | ||
| 1787 | dquant = cbpc & 8; | 1791 | dquant = cbpc & 8; |
| 1788 | s->mb_intra = ((cbpc & 4) != 0); | 1792 | h->c.mb_intra = ((cbpc & 4) != 0); |
| 1789 | if (s->mb_intra) | 1793 | if (h->c.mb_intra) |
| 1790 | goto intra; | 1794 | goto intra; |
| 1791 | s->bdsp.clear_blocks(s->block[0]); | 1795 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 1792 | 1796 | ||
| 1793 | if (s->pict_type == AV_PICTURE_TYPE_S && | 1797 | if (h->c.pict_type == AV_PICTURE_TYPE_S && |
| 1794 | ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0) | 1798 | ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0) |
| 1795 | s->mcsel = get_bits1(&s->gb); | 1799 | h->c.mcsel = get_bits1(&h->c.gb); |
| 1796 | else | 1800 | else |
| 1797 | s->mcsel = 0; | 1801 | h->c.mcsel = 0; |
| 1798 | cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F; | 1802 | cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F; |
| 1799 | if (cbpy < 0) { | 1803 | if (cbpy < 0) { |
| 1800 | av_log(s->avctx, AV_LOG_ERROR, | 1804 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 1801 | "P cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | 1805 | "P cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 1802 | return AVERROR_INVALIDDATA; | 1806 | return AVERROR_INVALIDDATA; |
| 1803 | } | 1807 | } |
| 1804 | 1808 | ||
| 1805 | cbp = (cbpc & 3) | (cbpy << 2); | 1809 | cbp = (cbpc & 3) | (cbpy << 2); |
| 1806 | if (dquant) | 1810 | if (dquant) |
| 1807 | ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | 1811 | ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); |
| 1808 | if ((!s->progressive_sequence) && | 1812 | if ((!h->c.progressive_sequence) && |
| 1809 | (cbp || (s->workaround_bugs & FF_BUG_XVID_ILACE))) | 1813 | (cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE))) |
| 1810 | s->interlaced_dct = get_bits1(&s->gb); | 1814 | h->c.interlaced_dct = get_bits1(&h->c.gb); |
| 1811 | 1815 | ||
| 1812 | s->mv_dir = MV_DIR_FORWARD; | 1816 | h->c.mv_dir = MV_DIR_FORWARD; |
| 1813 | if ((cbpc & 16) == 0) { | 1817 | if ((cbpc & 16) == 0) { |
| 1814 | if (s->mcsel) { | 1818 | if (h->c.mcsel) { |
| 1815 | s->cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 | | 1819 | h->c.cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 | |
| 1816 | MB_TYPE_FORWARD_MV; | 1820 | MB_TYPE_FORWARD_MV; |
| 1817 | /* 16x16 global motion prediction */ | 1821 | /* 16x16 global motion prediction */ |
| 1818 | s->mv_type = MV_TYPE_16X16; | 1822 | h->c.mv_type = MV_TYPE_16X16; |
| 1819 | mx = get_amv(ctx, 0); | 1823 | mx = get_amv(ctx, 0); |
| 1820 | my = get_amv(ctx, 1); | 1824 | my = get_amv(ctx, 1); |
| 1821 | s->mv[0][0][0] = mx; | 1825 | h->c.mv[0][0][0] = mx; |
| 1822 | s->mv[0][0][1] = my; | 1826 | h->c.mv[0][0][1] = my; |
| 1823 | } else if ((!s->progressive_sequence) && get_bits1(&s->gb)) { | 1827 | } else if ((!h->c.progressive_sequence) && get_bits1(&h->c.gb)) { |
| 1824 | s->cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV | | 1828 | h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV | |
| 1825 | MB_TYPE_INTERLACED; | 1829 | MB_TYPE_INTERLACED; |
| 1826 | /* 16x8 field motion prediction */ | 1830 | /* 16x8 field motion prediction */ |
| 1827 | s->mv_type = MV_TYPE_FIELD; | 1831 | h->c.mv_type = MV_TYPE_FIELD; |
| 1828 | 1832 | ||
| 1829 | s->field_select[0][0] = get_bits1(&s->gb); | 1833 | h->c.field_select[0][0] = get_bits1(&h->c.gb); |
| 1830 | s->field_select[0][1] = get_bits1(&s->gb); | 1834 | h->c.field_select[0][1] = get_bits1(&h->c.gb); |
| 1831 | 1835 | ||
| 1832 | ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | 1836 | ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); |
| 1833 | 1837 | ||
| 1834 | for (i = 0; i < 2; i++) { | 1838 | for (i = 0; i < 2; i++) { |
| 1835 | mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | 1839 | mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); |
| 1836 | if (mx >= 0xffff) | 1840 | if (mx >= 0xffff) |
| 1837 | return AVERROR_INVALIDDATA; | 1841 | return AVERROR_INVALIDDATA; |
| 1838 | 1842 | ||
| 1839 | my = ff_h263_decode_motion(s, pred_y / 2, ctx->f_code); | 1843 | my = ff_h263_decode_motion(h, pred_y / 2, ctx->f_code); |
| 1840 | if (my >= 0xffff) | 1844 | if (my >= 0xffff) |
| 1841 | return AVERROR_INVALIDDATA; | 1845 | return AVERROR_INVALIDDATA; |
| 1842 | 1846 | ||
| 1843 | s->mv[0][i][0] = mx; | 1847 | h->c.mv[0][i][0] = mx; |
| 1844 | s->mv[0][i][1] = my; | 1848 | h->c.mv[0][i][1] = my; |
| 1845 | } | 1849 | } |
| 1846 | } else { | 1850 | } else { |
| 1847 | s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 1851 | h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 1848 | /* 16x16 motion prediction */ | 1852 | /* 16x16 motion prediction */ |
| 1849 | s->mv_type = MV_TYPE_16X16; | 1853 | h->c.mv_type = MV_TYPE_16X16; |
| 1850 | ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | 1854 | ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); |
| 1851 | mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | 1855 | mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); |
| 1852 | 1856 | ||
| 1853 | if (mx >= 0xffff) | 1857 | if (mx >= 0xffff) |
| 1854 | return AVERROR_INVALIDDATA; | 1858 | return AVERROR_INVALIDDATA; |
| 1855 | 1859 | ||
| 1856 | my = ff_h263_decode_motion(s, pred_y, ctx->f_code); | 1860 | my = ff_h263_decode_motion(h, pred_y, ctx->f_code); |
| 1857 | 1861 | ||
| 1858 | if (my >= 0xffff) | 1862 | if (my >= 0xffff) |
| 1859 | return AVERROR_INVALIDDATA; | 1863 | return AVERROR_INVALIDDATA; |
| 1860 | s->mv[0][0][0] = mx; | 1864 | h->c.mv[0][0][0] = mx; |
| 1861 | s->mv[0][0][1] = my; | 1865 | h->c.mv[0][0][1] = my; |
| 1862 | } | 1866 | } |
| 1863 | } else { | 1867 | } else { |
| 1864 | s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; | 1868 | h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; |
| 1865 | s->mv_type = MV_TYPE_8X8; | 1869 | h->c.mv_type = MV_TYPE_8X8; |
| 1866 | for (i = 0; i < 4; i++) { | 1870 | for (i = 0; i < 4; i++) { |
| 1867 | int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | 1871 | int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); |
| 1868 | mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | 1872 | mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); |
| 1869 | if (mx >= 0xffff) | 1873 | if (mx >= 0xffff) |
| 1870 | return AVERROR_INVALIDDATA; | 1874 | return AVERROR_INVALIDDATA; |
| 1871 | 1875 | ||
| 1872 | my = ff_h263_decode_motion(s, pred_y, ctx->f_code); | 1876 | my = ff_h263_decode_motion(h, pred_y, ctx->f_code); |
| 1873 | if (my >= 0xffff) | 1877 | if (my >= 0xffff) |
| 1874 | return AVERROR_INVALIDDATA; | 1878 | return AVERROR_INVALIDDATA; |
| 1875 | s->mv[0][i][0] = mx; | 1879 | h->c.mv[0][i][0] = mx; |
| 1876 | s->mv[0][i][1] = my; | 1880 | h->c.mv[0][i][1] = my; |
| 1877 | mot_val[0] = mx; | 1881 | mot_val[0] = mx; |
| 1878 | mot_val[1] = my; | 1882 | mot_val[1] = my; |
| 1879 | } | 1883 | } |
| 1880 | } | 1884 | } |
| 1881 | } else if (s->pict_type == AV_PICTURE_TYPE_B) { | 1885 | } else if (h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 1882 | int modb1; // first bit of modb | 1886 | int modb1; // first bit of modb |
| 1883 | int modb2; // second bit of modb | 1887 | int modb2; // second bit of modb |
| 1884 | int mb_type; | 1888 | int mb_type; |
| 1885 | 1889 | ||
| 1886 | s->mb_intra = 0; // B-frames never contain intra blocks | 1890 | h->c.mb_intra = 0; // B-frames never contain intra blocks |
| 1887 | s->mcsel = 0; // ... true gmc blocks | 1891 | h->c.mcsel = 0; // ... true gmc blocks |
| 1888 | 1892 | ||
| 1889 | if (s->mb_x == 0) { | 1893 | if (h->c.mb_x == 0) { |
| 1890 | for (i = 0; i < 2; i++) { | 1894 | for (i = 0; i < 2; i++) { |
| 1891 | s->last_mv[i][0][0] = | 1895 | h->c.last_mv[i][0][0] = |
| 1892 | s->last_mv[i][0][1] = | 1896 | h->c.last_mv[i][0][1] = |
| 1893 | s->last_mv[i][1][0] = | 1897 | h->c.last_mv[i][1][0] = |
| 1894 | s->last_mv[i][1][1] = 0; | 1898 | h->c.last_mv[i][1][1] = 0; |
| 1895 | } | 1899 | } |
| 1896 | 1900 | ||
| 1897 | ff_thread_progress_await(&s->next_pic.ptr->progress, s->mb_y); | 1901 | ff_thread_progress_await(&h->c.next_pic.ptr->progress, h->c.mb_y); |
| 1898 | } | 1902 | } |
| 1899 | 1903 | ||
| 1900 | /* if we skipped it in the future P-frame than skip it now too */ | 1904 | /* if we skipped it in the future P-frame than skip it now too */ |
| 1901 | s->mb_skipped = s->next_pic.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC | 1905 | h->c.mb_skipped = h->c.next_pic.mbskip_table[h->c.mb_y * h->c.mb_stride + h->c.mb_x]; // Note, skiptab=0 if last was GMC |
| 1902 | 1906 | ||
| 1903 | if (s->mb_skipped) { | 1907 | if (h->c.mb_skipped) { |
| 1904 | /* skip mb */ | 1908 | /* skip mb */ |
| 1905 | for (i = 0; i < 6; i++) | 1909 | for (i = 0; i < 6; i++) |
| 1906 | s->block_last_index[i] = -1; | 1910 | h->c.block_last_index[i] = -1; |
| 1907 | 1911 | ||
| 1908 | s->mv_dir = MV_DIR_FORWARD; | 1912 | h->c.mv_dir = MV_DIR_FORWARD; |
| 1909 | s->mv_type = MV_TYPE_16X16; | 1913 | h->c.mv_type = MV_TYPE_16X16; |
| 1910 | s->mv[0][0][0] = | 1914 | h->c.mv[0][0][0] = |
| 1911 | s->mv[0][0][1] = | 1915 | h->c.mv[0][0][1] = |
| 1912 | s->mv[1][0][0] = | 1916 | h->c.mv[1][0][0] = |
| 1913 | s->mv[1][0][1] = 0; | 1917 | h->c.mv[1][0][1] = 0; |
| 1914 | s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | | 1918 | h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | |
| 1915 | MB_TYPE_16x16 | | 1919 | MB_TYPE_16x16 | |
| 1916 | MB_TYPE_FORWARD_MV; | 1920 | MB_TYPE_FORWARD_MV; |
| 1917 | goto end; | 1921 | goto end; |
| 1918 | } | 1922 | } |
| 1919 | 1923 | ||
| 1920 | modb1 = get_bits1(&s->gb); | 1924 | modb1 = get_bits1(&h->c.gb); |
| 1921 | if (modb1) { | 1925 | if (modb1) { |
| 1922 | // like MB_TYPE_B_DIRECT but no vectors coded | 1926 | // like MB_TYPE_B_DIRECT but no vectors coded |
| 1923 | mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV; | 1927 | mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV; |
| 1924 | cbp = 0; | 1928 | cbp = 0; |
| 1925 | } else { | 1929 | } else { |
| 1926 | modb2 = get_bits1(&s->gb); | 1930 | modb2 = get_bits1(&h->c.gb); |
| 1927 | mb_type = get_vlc2(&s->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1); | 1931 | mb_type = get_vlc2(&h->c.gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1); |
| 1928 | if (mb_type < 0) { | 1932 | if (mb_type < 0) { |
| 1929 | av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n"); | 1933 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal MB_type\n"); |
| 1930 | return AVERROR_INVALIDDATA; | 1934 | return AVERROR_INVALIDDATA; |
| 1931 | } | 1935 | } |
| 1932 | if (modb2) { | 1936 | if (modb2) { |
| 1933 | cbp = 0; | 1937 | cbp = 0; |
| 1934 | } else { | 1938 | } else { |
| 1935 | s->bdsp.clear_blocks(s->block[0]); | 1939 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 1936 | cbp = get_bits(&s->gb, 6); | 1940 | cbp = get_bits(&h->c.gb, 6); |
| 1937 | } | 1941 | } |
| 1938 | 1942 | ||
| 1939 | if ((!IS_DIRECT(mb_type)) && cbp) { | 1943 | if ((!IS_DIRECT(mb_type)) && cbp) { |
| 1940 | if (get_bits1(&s->gb)) | 1944 | if (get_bits1(&h->c.gb)) |
| 1941 | ff_set_qscale(s, s->qscale + get_bits1(&s->gb) * 4 - 2); | 1945 | ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->c.gb) * 4 - 2); |
| 1942 | } | 1946 | } |
| 1943 | 1947 | ||
| 1944 | if (!s->progressive_sequence) { | 1948 | if (!h->c.progressive_sequence) { |
| 1945 | if (cbp) | 1949 | if (cbp) |
| 1946 | s->interlaced_dct = get_bits1(&s->gb); | 1950 | h->c.interlaced_dct = get_bits1(&h->c.gb); |
| 1947 | 1951 | ||
| 1948 | if (!IS_DIRECT(mb_type) && get_bits1(&s->gb)) { | 1952 | if (!IS_DIRECT(mb_type) && get_bits1(&h->c.gb)) { |
| 1949 | mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; | 1953 | mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; |
| 1950 | mb_type &= ~MB_TYPE_16x16; | 1954 | mb_type &= ~MB_TYPE_16x16; |
| 1951 | 1955 | ||
| 1952 | if (HAS_FORWARD_MV(mb_type)) { | 1956 | if (HAS_FORWARD_MV(mb_type)) { |
| 1953 | s->field_select[0][0] = get_bits1(&s->gb); | 1957 | h->c.field_select[0][0] = get_bits1(&h->c.gb); |
| 1954 | s->field_select[0][1] = get_bits1(&s->gb); | 1958 | h->c.field_select[0][1] = get_bits1(&h->c.gb); |
| 1955 | } | 1959 | } |
| 1956 | if (HAS_BACKWARD_MV(mb_type)) { | 1960 | if (HAS_BACKWARD_MV(mb_type)) { |
| 1957 | s->field_select[1][0] = get_bits1(&s->gb); | 1961 | h->c.field_select[1][0] = get_bits1(&h->c.gb); |
| 1958 | s->field_select[1][1] = get_bits1(&s->gb); | 1962 | h->c.field_select[1][1] = get_bits1(&h->c.gb); |
| 1959 | } | 1963 | } |
| 1960 | } | 1964 | } |
| 1961 | } | 1965 | } |
| 1962 | 1966 | ||
| 1963 | s->mv_dir = 0; | 1967 | h->c.mv_dir = 0; |
| 1964 | if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) { | 1968 | if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) { |
| 1965 | s->mv_type = MV_TYPE_16X16; | 1969 | h->c.mv_type = MV_TYPE_16X16; |
| 1966 | 1970 | ||
| 1967 | if (HAS_FORWARD_MV(mb_type)) { | 1971 | if (HAS_FORWARD_MV(mb_type)) { |
| 1968 | s->mv_dir = MV_DIR_FORWARD; | 1972 | h->c.mv_dir = MV_DIR_FORWARD; |
| 1969 | 1973 | ||
| 1970 | mx = ff_h263_decode_motion(s, s->last_mv[0][0][0], ctx->f_code); | 1974 | mx = ff_h263_decode_motion(h, h->c.last_mv[0][0][0], ctx->f_code); |
| 1971 | my = ff_h263_decode_motion(s, s->last_mv[0][0][1], ctx->f_code); | 1975 | my = ff_h263_decode_motion(h, h->c.last_mv[0][0][1], ctx->f_code); |
| 1972 | s->last_mv[0][1][0] = | 1976 | h->c.last_mv[0][1][0] = |
| 1973 | s->last_mv[0][0][0] = | 1977 | h->c.last_mv[0][0][0] = |
| 1974 | s->mv[0][0][0] = mx; | 1978 | h->c.mv[0][0][0] = mx; |
| 1975 | s->last_mv[0][1][1] = | 1979 | h->c.last_mv[0][1][1] = |
| 1976 | s->last_mv[0][0][1] = | 1980 | h->c.last_mv[0][0][1] = |
| 1977 | s->mv[0][0][1] = my; | 1981 | h->c.mv[0][0][1] = my; |
| 1978 | } | 1982 | } |
| 1979 | 1983 | ||
| 1980 | if (HAS_BACKWARD_MV(mb_type)) { | 1984 | if (HAS_BACKWARD_MV(mb_type)) { |
| 1981 | s->mv_dir |= MV_DIR_BACKWARD; | 1985 | h->c.mv_dir |= MV_DIR_BACKWARD; |
| 1982 | 1986 | ||
| 1983 | mx = ff_h263_decode_motion(s, s->last_mv[1][0][0], ctx->b_code); | 1987 | mx = ff_h263_decode_motion(h, h->c.last_mv[1][0][0], ctx->b_code); |
| 1984 | my = ff_h263_decode_motion(s, s->last_mv[1][0][1], ctx->b_code); | 1988 | my = ff_h263_decode_motion(h, h->c.last_mv[1][0][1], ctx->b_code); |
| 1985 | s->last_mv[1][1][0] = | 1989 | h->c.last_mv[1][1][0] = |
| 1986 | s->last_mv[1][0][0] = | 1990 | h->c.last_mv[1][0][0] = |
| 1987 | s->mv[1][0][0] = mx; | 1991 | h->c.mv[1][0][0] = mx; |
| 1988 | s->last_mv[1][1][1] = | 1992 | h->c.last_mv[1][1][1] = |
| 1989 | s->last_mv[1][0][1] = | 1993 | h->c.last_mv[1][0][1] = |
| 1990 | s->mv[1][0][1] = my; | 1994 | h->c.mv[1][0][1] = my; |
| 1991 | } | 1995 | } |
| 1992 | } else if (!IS_DIRECT(mb_type)) { | 1996 | } else if (!IS_DIRECT(mb_type)) { |
| 1993 | s->mv_type = MV_TYPE_FIELD; | 1997 | h->c.mv_type = MV_TYPE_FIELD; |
| 1994 | 1998 | ||
| 1995 | if (HAS_FORWARD_MV(mb_type)) { | 1999 | if (HAS_FORWARD_MV(mb_type)) { |
| 1996 | s->mv_dir = MV_DIR_FORWARD; | 2000 | h->c.mv_dir = MV_DIR_FORWARD; |
| 1997 | 2001 | ||
| 1998 | for (i = 0; i < 2; i++) { | 2002 | for (i = 0; i < 2; i++) { |
| 1999 | mx = ff_h263_decode_motion(s, s->last_mv[0][i][0], ctx->f_code); | 2003 | mx = ff_h263_decode_motion(h, h->c.last_mv[0][i][0], ctx->f_code); |
| 2000 | my = ff_h263_decode_motion(s, s->last_mv[0][i][1] / 2, ctx->f_code); | 2004 | my = ff_h263_decode_motion(h, h->c.last_mv[0][i][1] / 2, ctx->f_code); |
| 2001 | s->last_mv[0][i][0] = | 2005 | h->c.last_mv[0][i][0] = |
| 2002 | s->mv[0][i][0] = mx; | 2006 | h->c.mv[0][i][0] = mx; |
| 2003 | s->last_mv[0][i][1] = (s->mv[0][i][1] = my) * 2; | 2007 | h->c.last_mv[0][i][1] = (h->c.mv[0][i][1] = my) * 2; |
| 2004 | } | 2008 | } |
| 2005 | } | 2009 | } |
| 2006 | 2010 | ||
| 2007 | if (HAS_BACKWARD_MV(mb_type)) { | 2011 | if (HAS_BACKWARD_MV(mb_type)) { |
| 2008 | s->mv_dir |= MV_DIR_BACKWARD; | 2012 | h->c.mv_dir |= MV_DIR_BACKWARD; |
| 2009 | 2013 | ||
| 2010 | for (i = 0; i < 2; i++) { | 2014 | for (i = 0; i < 2; i++) { |
| 2011 | mx = ff_h263_decode_motion(s, s->last_mv[1][i][0], ctx->b_code); | 2015 | mx = ff_h263_decode_motion(h, h->c.last_mv[1][i][0], ctx->b_code); |
| 2012 | my = ff_h263_decode_motion(s, s->last_mv[1][i][1] / 2, ctx->b_code); | 2016 | my = ff_h263_decode_motion(h, h->c.last_mv[1][i][1] / 2, ctx->b_code); |
| 2013 | s->last_mv[1][i][0] = | 2017 | h->c.last_mv[1][i][0] = |
| 2014 | s->mv[1][i][0] = mx; | 2018 | h->c.mv[1][i][0] = mx; |
| 2015 | s->last_mv[1][i][1] = (s->mv[1][i][1] = my) * 2; | 2019 | h->c.last_mv[1][i][1] = (h->c.mv[1][i][1] = my) * 2; |
| 2016 | } | 2020 | } |
| 2017 | } | 2021 | } |
| 2018 | } | 2022 | } |
| @@ -2023,53 +2027,53 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 4 unmodified lines | |||
| 2023 | mx = | 2027 | mx = |
| 2024 | my = 0; | 2028 | my = 0; |
| 2025 | } else { | 2029 | } else { |
| 2026 | mx = ff_h263_decode_motion(s, 0, 1); | 2030 | mx = ff_h263_decode_motion(h, 0, 1); |
| 2027 | my = ff_h263_decode_motion(s, 0, 1); | 2031 | my = ff_h263_decode_motion(h, 0, 1); |
| 2028 | } | 2032 | } |
| 2029 | 2033 | ||
| 2030 | s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | 2034 | h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
| 2031 | mb_type |= ff_mpeg4_set_direct_mv(s, mx, my); | 2035 | mb_type |= ff_mpeg4_set_direct_mv(&h->c, mx, my); |
| 2032 | } | 2036 | } |
| 2033 | s->cur_pic.mb_type[xy] = mb_type; | 2037 | h->c.cur_pic.mb_type[xy] = mb_type; |
| 2034 | } else { /* I-Frame */ | 2038 | } else { /* I-Frame */ |
| 2035 | int use_intra_dc_vlc; | 2039 | int use_intra_dc_vlc; |
| 2036 | 2040 | ||
| 2037 | do { | 2041 | do { |
| 2038 | cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); | 2042 | cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); |
| 2039 | if (cbpc < 0) { | 2043 | if (cbpc < 0) { |
| 2040 | av_log(s->avctx, AV_LOG_ERROR, | 2044 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 2041 | "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); | 2045 | "I cbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 2042 | return AVERROR_INVALIDDATA; | 2046 | return AVERROR_INVALIDDATA; |
| 2043 | } | 2047 | } |
| 2044 | } while (cbpc == 8); | 2048 | } while (cbpc == 8); |
| 2045 | 2049 | ||
| 2046 | dquant = cbpc & 4; | 2050 | dquant = cbpc & 4; |
| 2047 | s->mb_intra = 1; | 2051 | h->c.mb_intra = 1; |
| 2048 | 2052 | ||
| 2049 | intra: | 2053 | intra: |
| 2050 | s->ac_pred = get_bits1(&s->gb); | 2054 | h->c.ac_pred = get_bits1(&h->c.gb); |
| 2051 | if (s->ac_pred) | 2055 | if (h->c.ac_pred) |
| 2052 | s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; | 2056 | h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; |
| 2053 | else | 2057 | else |
| 2054 | s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | 2058 | h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; |
| 2055 | 2059 | ||
| 2056 | cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 2060 | cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 2057 | if (cbpy < 0) { | 2061 | if (cbpy < 0) { |
| 2058 | av_log(s->avctx, AV_LOG_ERROR, | 2062 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 2059 | "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | 2063 | "I cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y); |
| 2060 | return AVERROR_INVALIDDATA; | 2064 | return AVERROR_INVALIDDATA; |
| 2061 | } | 2065 | } |
| 2062 | cbp = (cbpc & 3) | (cbpy << 2); | 2066 | cbp = (cbpc & 3) | (cbpy << 2); |
| 2063 | 2067 | ||
| 2064 | use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold; | 2068 | use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold; |
| 2065 | 2069 | ||
| 2066 | if (dquant) | 2070 | if (dquant) |
| 2067 | ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | 2071 | ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); |
| 2068 | 2072 | ||
| 2069 | if (!s->progressive_sequence) | 2073 | if (!h->c.progressive_sequence) |
| 2070 | s->interlaced_dct = get_bits1(&s->gb); | 2074 | h->c.interlaced_dct = get_bits1(&h->c.gb); |
| 2071 | 2075 | ||
| 2072 | s->bdsp.clear_blocks(s->block[0]); | 2076 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 2073 | /* decode each block */ | 2077 | /* decode each block */ |
| 2074 | for (i = 0; i < 6; i++) { | 2078 | for (i = 0; i < 6; i++) { |
| 2075 | if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, | 2079 | if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, |
| @@ -2091,18 +2095,18 @@ end: · 15 unmodified lines | |||
| 2091 | /* per-MB end of slice check */ | 2095 | /* per-MB end of slice check */ |
| 2092 | next = mpeg4_is_resync(ctx); | 2096 | next = mpeg4_is_resync(ctx); |
| 2093 | if (next) { | 2097 | if (next) { |
| 2094 | if (s->mb_x + s->mb_y*s->mb_width + 1 > next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) { | 2098 | if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 > next && (h->c.avctx->err_recognition & AV_EF_AGGRESSIVE)) { |
| 2095 | return AVERROR_INVALIDDATA; | 2099 | return AVERROR_INVALIDDATA; |
| 2096 | } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next) | 2100 | } else if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 >= next) |
| 2097 | return SLICE_END; | 2101 | return SLICE_END; |
| 2098 | 2102 | ||
| 2099 | if (s->pict_type == AV_PICTURE_TYPE_B) { | 2103 | if (h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 2100 | const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1; | 2104 | const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1; |
| 2101 | ff_thread_progress_await(&s->next_pic.ptr->progress, | 2105 | ff_thread_progress_await(&h->c.next_pic.ptr->progress, |
| 2102 | (s->mb_x + delta >= s->mb_width) | 2106 | (h->c.mb_x + delta >= h->c.mb_width) |
| 2103 | ? FFMIN(s->mb_y + 1, s->mb_height - 1) | 2107 | ? FFMIN(h->c.mb_y + 1, h->c.mb_height - 1) |
| 2104 | : s->mb_y); | 2108 | : h->c.mb_y); |
| 2105 | if (s->next_pic.mbskip_table[xy + delta]) | 2109 | if (h->c.next_pic.mbskip_table[xy + delta]) |
| 2106 | return SLICE_OK; | 2110 | return SLICE_OK; |
| 2107 | } | 2111 | } |
| 2108 | 2112 | ||
| @@ -2149,19 +2153,19 @@ static const uint8_t ac_state_tab[22][2] = · 40 unmodified lines | |||
| 2149 | {0, 11} | 2153 | {0, 11} |
| 2150 | }; | 2154 | }; |
| 2151 | 2155 | ||
| 2152 | static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n) | 2156 | static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[64], int n) |
| 2153 | { | 2157 | { |
| 2154 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 2158 | H263DecContext *const h = &ctx->h; |
| 2155 | 2159 | ||
| 2156 | int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0, | 2160 | int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0, |
| 2157 | additional_code_len, sign, mismatch; | 2161 | additional_code_len, sign, mismatch; |
| 2158 | const VLCElem *cur_vlc = studio_intra_tab[0]; | 2162 | const VLCElem *cur_vlc = studio_intra_tab[0]; |
| 2159 | const uint8_t *const scantable = s->intra_scantable.permutated; | 2163 | const uint8_t *const scantable = h->c.intra_scantable.permutated; |
| 2160 | const uint16_t *quant_matrix; | 2164 | const uint16_t *quant_matrix; |
| 2161 | uint32_t flc; | 2165 | uint32_t flc; |
| 2162 | const int min = -1 * (1 << (s->avctx->bits_per_raw_sample + 6)); | 2166 | const int min = -1 * (1 << (h->c.avctx->bits_per_raw_sample + 6)); |
| 2163 | const int max = ((1 << (s->avctx->bits_per_raw_sample + 6)) - 1); | 2167 | const int max = ((1 << (h->c.avctx->bits_per_raw_sample + 6)) - 1); |
| 2164 | int shift = 3 - ctx->dct_precision; | 2168 | int shift = 3 - ctx->dct_precision; |
| 2165 | 2169 | ||
| 2166 | mismatch = 1; | 2170 | mismatch = 1; |
| 2167 | 2171 | ||
| @@ -2169,35 +2173,35 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 1 unmodified line | |||
| 2169 | 2173 | ||
| 2170 | if (n < 4) { | 2174 | if (n < 4) { |
| 2171 | cc = 0; | 2175 | cc = 0; |
| 2172 | dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2); | 2176 | dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2); |
| 2173 | quant_matrix = s->intra_matrix; | 2177 | quant_matrix = h->c.intra_matrix; |
| 2174 | } else { | 2178 | } else { |
| 2175 | cc = (n & 1) + 1; | 2179 | cc = (n & 1) + 1; |
| 2176 | if (ctx->rgb) | 2180 | if (ctx->rgb) |
| 2177 | dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2); | 2181 | dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2); |
| 2178 | else | 2182 | else |
| 2179 | dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2); | 2183 | dct_dc_size = get_vlc2(&h->c.gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2); |
| 2180 | quant_matrix = s->chroma_intra_matrix; | 2184 | quant_matrix = h->c.chroma_intra_matrix; |
| 2181 | } | 2185 | } |
| 2182 | 2186 | ||
| 2183 | if (dct_dc_size == 0) { | 2187 | if (dct_dc_size == 0) { |
| 2184 | dct_diff = 0; | 2188 | dct_diff = 0; |
| 2185 | } else { | 2189 | } else { |
| 2186 | dct_diff = get_xbits(&s->gb, dct_dc_size); | 2190 | dct_diff = get_xbits(&h->c.gb, dct_dc_size); |
| 2187 | 2191 | ||
| 2188 | if (dct_dc_size > 8) { | 2192 | if (dct_dc_size > 8) { |
| 2189 | if(!check_marker(s->avctx, &s->gb, "dct_dc_size > 8")) | 2193 | if(!check_marker(h->c.avctx, &h->c.gb, "dct_dc_size > 8")) |
| 2190 | return AVERROR_INVALIDDATA; | 2194 | return AVERROR_INVALIDDATA; |
| 2191 | } | 2195 | } |
| 2192 | 2196 | ||
| 2193 | } | 2197 | } |
| 2194 | 2198 | ||
| 2195 | s->last_dc[cc] += dct_diff; | 2199 | h->c.last_dc[cc] += dct_diff; |
| 2196 | 2200 | ||
| 2197 | if (ctx->mpeg_quant) | 2201 | if (ctx->mpeg_quant) |
| 2198 | block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision); | 2202 | block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision); |
| 2199 | else | 2203 | else |
| 2200 | block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision) * (8 >> ctx->dct_precision); | 2204 | block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision); |
| 2201 | /* TODO: support mpeg_quant for AC coefficients */ | 2205 | /* TODO: support mpeg_quant for AC coefficients */ |
| 2202 | 2206 | ||
| 2203 | block[0] = av_clip(block[0], min, max); | 2207 | block[0] = av_clip(block[0], min, max); |
| @@ -2205,10 +2209,10 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 1 unmodified line | |||
| 2205 | 2209 | ||
| 2206 | /* AC Coefficients */ | 2210 | /* AC Coefficients */ |
| 2207 | while (1) { | 2211 | while (1) { |
| 2208 | group = get_vlc2(&s->gb, cur_vlc, STUDIO_INTRA_BITS, 2); | 2212 | group = get_vlc2(&h->c.gb, cur_vlc, STUDIO_INTRA_BITS, 2); |
| 2209 | 2213 | ||
| 2210 | if (group < 0) { | 2214 | if (group < 0) { |
| 2211 | av_log(s->avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n"); | 2215 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n"); |
| 2212 | return AVERROR_INVALIDDATA; | 2216 | return AVERROR_INVALIDDATA; |
| 2213 | } | 2217 | } |
| 2214 | 2218 | ||
| @@ -2222,12 +2226,12 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 7 unmodified lines | |||
| 2222 | /* Zero run length (Table B.47) */ | 2226 | /* Zero run length (Table B.47) */ |
| 2223 | run = 1 << additional_code_len; | 2227 | run = 1 << additional_code_len; |
| 2224 | if (additional_code_len) | 2228 | if (additional_code_len) |
| 2225 | run += get_bits(&s->gb, additional_code_len); | 2229 | run += get_bits(&h->c.gb, additional_code_len); |
| 2226 | idx += run; | 2230 | idx += run; |
| 2227 | continue; | 2231 | continue; |
| 2228 | } else if (group >= 7 && group <= 12) { | 2232 | } else if (group >= 7 && group <= 12) { |
| 2229 | /* Zero run length and +/-1 level (Table B.48) */ | 2233 | /* Zero run length and +/-1 level (Table B.48) */ |
| 2230 | code = get_bits(&s->gb, additional_code_len); | 2234 | code = get_bits(&h->c.gb, additional_code_len); |
| 2231 | sign = code & 1; | 2235 | sign = code & 1; |
| 2232 | code >>= 1; | 2236 | code >>= 1; |
| 2233 | run = (1 << (additional_code_len - 1)) + code; | 2237 | run = (1 << (additional_code_len - 1)) + code; |
| @@ -2241,20 +2245,20 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 7 unmodified lines | |||
| 2241 | if (idx > 63) | 2245 | if (idx > 63) |
| 2242 | return AVERROR_INVALIDDATA; | 2246 | return AVERROR_INVALIDDATA; |
| 2243 | j = scantable[idx++]; | 2247 | j = scantable[idx++]; |
| 2244 | block[j] = get_xbits(&s->gb, additional_code_len); | 2248 | block[j] = get_xbits(&h->c.gb, additional_code_len); |
| 2245 | } else if (group == 21) { | 2249 | } else if (group == 21) { |
| 2246 | /* Escape */ | 2250 | /* Escape */ |
| 2247 | if (idx > 63) | 2251 | if (idx > 63) |
| 2248 | return AVERROR_INVALIDDATA; | 2252 | return AVERROR_INVALIDDATA; |
| 2249 | j = scantable[idx++]; | 2253 | j = scantable[idx++]; |
| 2250 | additional_code_len = s->avctx->bits_per_raw_sample + ctx->dct_precision + 4; | 2254 | additional_code_len = h->c.avctx->bits_per_raw_sample + ctx->dct_precision + 4; |
| 2251 | flc = get_bits(&s->gb, additional_code_len); | 2255 | flc = get_bits(&h->c.gb, additional_code_len); |
| 2252 | if (flc >> (additional_code_len-1)) | 2256 | if (flc >> (additional_code_len-1)) |
| 2253 | block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1); | 2257 | block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1); |
| 2254 | else | 2258 | else |
| 2255 | block[j] = flc; | 2259 | block[j] = flc; |
| 2256 | } | 2260 | } |
| 2257 | block[j] = ((block[j] * quant_matrix[j] * s->qscale) * (1 << shift)) / 16; | 2261 | block[j] = ((block[j] * quant_matrix[j] * h->c.qscale) * (1 << shift)) / 16; |
| 2258 | block[j] = av_clip(block[j], min, max); | 2262 | block[j] = av_clip(block[j], min, max); |
| 2259 | mismatch ^= block[j]; | 2263 | mismatch ^= block[j]; |
| 2260 | } | 2264 | } |
| @@ -2267,23 +2271,23 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 6 unmodified lines | |||
| 2267 | static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, | 2271 | static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, |
| 2268 | int16_t macroblock[256], int n) | 2272 | int16_t macroblock[256], int n) |
| 2269 | { | 2273 | { |
| 2270 | MPVContext *const s = &ctx->m; | 2274 | H263DecContext *const h = &ctx->h; |
| 2271 | int i, j, w, h, idx = 0; | 2275 | int j, w, height, idx = 0; |
| 2272 | int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code, | 2276 | int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code, |
| 2273 | dpcm_residual, left, top, topleft, min_left_top, max_left_top, p, p2, output; | 2277 | dpcm_residual, left, top, topleft, min_left_top, max_left_top, p, p2, output; |
| 2274 | h = 16 >> (n ? s->chroma_y_shift : 0); | 2278 | height = 16 >> (n ? h->c.chroma_y_shift : 0); |
| 2275 | w = 16 >> (n ? s->chroma_x_shift : 0); | 2279 | w = 16 >> (n ? h->c.chroma_x_shift : 0); |
| 2276 | 2280 | ||
| 2277 | block_mean = get_bits(&s->gb, s->avctx->bits_per_raw_sample); | 2281 | block_mean = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample); |
| 2278 | if (block_mean == 0){ | 2282 | if (block_mean == 0){ |
| 2279 | av_log(s->avctx, AV_LOG_ERROR, "Forbidden block_mean\n"); | 2283 | av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n"); |
| 2280 | return AVERROR_INVALIDDATA; | 2284 | return AVERROR_INVALIDDATA; |
| 2281 | } | 2285 | } |
| 2282 | s->last_dc[n] = block_mean * (1 << (ctx->dct_precision + s->intra_dc_precision)); | 2286 | h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision)); |
| 2283 | 2287 | ||
| 2284 | rice_parameter = get_bits(&s->gb, 4); | 2288 | rice_parameter = get_bits(&h->c.gb, 4); |
| 2285 | if (rice_parameter == 0) { | 2289 | if (rice_parameter == 0) { |
| 2286 | av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n"); | 2290 | av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n"); |
| 2287 | return AVERROR_INVALIDDATA; | 2291 | return AVERROR_INVALIDDATA; |
| 2288 | } | 2292 | } |
| 2289 | 2293 | ||
| @@ -2291,29 +2295,29 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, · 1 unmodified line | |||
| 2291 | rice_parameter = 0; | 2295 | rice_parameter = 0; |
| 2292 | 2296 | ||
| 2293 | if (rice_parameter > 11) { | 2297 | if (rice_parameter > 11) { |
| 2294 | av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n"); | 2298 | av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n"); |
| 2295 | return AVERROR_INVALIDDATA; | 2299 | return AVERROR_INVALIDDATA; |
| 2296 | } | 2300 | } |
| 2297 | 2301 | ||
| 2298 | for (i = 0; i < h; i++) { | 2302 | for (int i = 0; i < height; i++) { |
| 2299 | output = 1 << (s->avctx->bits_per_raw_sample - 1); | 2303 | output = 1 << (h->c.avctx->bits_per_raw_sample - 1); |
| 2300 | top = 1 << (s->avctx->bits_per_raw_sample - 1); | 2304 | top = 1 << (h->c.avctx->bits_per_raw_sample - 1); |
| 2301 | 2305 | ||
| 2302 | for (j = 0; j < w; j++) { | 2306 | for (j = 0; j < w; j++) { |
| 2303 | left = output; | 2307 | left = output; |
| 2304 | topleft = top; | 2308 | topleft = top; |
| 2305 | 2309 | ||
| 2306 | rice_prefix_code = get_unary(&s->gb, 1, 12); | 2310 | rice_prefix_code = get_unary(&h->c.gb, 1, 12); |
| 2307 | 2311 | ||
| 2308 | /* Escape */ | 2312 | /* Escape */ |
| 2309 | if (rice_prefix_code == 11) | 2313 | if (rice_prefix_code == 11) |
| 2310 | dpcm_residual = get_bits(&s->gb, s->avctx->bits_per_raw_sample); | 2314 | dpcm_residual = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample); |
| 2311 | else { | 2315 | else { |
| 2312 | if (rice_prefix_code == 12) { | 2316 | if (rice_prefix_code == 12) { |
| 2313 | av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n"); | 2317 | av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n"); |
| 2314 | return AVERROR_INVALIDDATA; | 2318 | return AVERROR_INVALIDDATA; |
| 2315 | } | 2319 | } |
| 2316 | rice_suffix_code = get_bitsz(&s->gb, rice_parameter); | 2320 | rice_suffix_code = get_bitsz(&h->c.gb, rice_parameter); |
| 2317 | dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code; | 2321 | dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code; |
| 2318 | } | 2322 | } |
| 2319 | 2323 | ||
| @@ -2342,56 +2346,56 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, · 22 unmodified lines | |||
| 2342 | if (p2 > p) | 2346 | if (p2 > p) |
| 2343 | dpcm_residual *= -1; | 2347 | dpcm_residual *= -1; |
| 2344 | 2348 | ||
| 2345 | macroblock[idx++] = output = (dpcm_residual + p) & ((1 << s->avctx->bits_per_raw_sample) - 1); | 2349 | macroblock[idx++] = output = (dpcm_residual + p) & ((1 << h->c.avctx->bits_per_raw_sample) - 1); |
| 2346 | } | 2350 | } |
| 2347 | } | 2351 | } |
| 2348 | 2352 | ||
| 2349 | return 0; | 2353 | return 0; |
| 2350 | } | 2354 | } |
| 2351 | 2355 | ||
| 2352 | static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64]) | 2356 | static int mpeg4_decode_studio_mb(H263DecContext *const h, int16_t block_[12][64]) |
| 2353 | { | 2357 | { |
| 2354 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 2358 | Mpeg4DecContext *const ctx = h263_to_mpeg4(h); |
| 2355 | int i; | 2359 | int i; |
| 2356 | 2360 | ||
| 2357 | ctx->dpcm_direction = 0; | 2361 | ctx->dpcm_direction = 0; |
| 2358 | 2362 | ||
| 2359 | /* StudioMacroblock */ | 2363 | /* StudioMacroblock */ |
| 2360 | /* Assumes I-VOP */ | 2364 | /* Assumes I-VOP */ |
| 2361 | s->mb_intra = 1; | 2365 | h->c.mb_intra = 1; |
| 2362 | if (get_bits1(&s->gb)) { /* compression_mode */ | 2366 | if (get_bits1(&h->c.gb)) { /* compression_mode */ |
| 2363 | /* DCT */ | 2367 | /* DCT */ |
| 2364 | /* macroblock_type, 1 or 2-bit VLC */ | 2368 | /* macroblock_type, 1 or 2-bit VLC */ |
| 2365 | if (!get_bits1(&s->gb)) { | 2369 | if (!get_bits1(&h->c.gb)) { |
| 2366 | skip_bits1(&s->gb); | 2370 | skip_bits1(&h->c.gb); |
| 2367 | s->qscale = mpeg_get_qscale(s); | 2371 | h->c.qscale = mpeg_get_qscale(&h->c); |
| 2368 | } | 2372 | } |
| 2369 | 2373 | ||
| 2370 | for (i = 0; i < mpeg4_block_count[s->chroma_format]; i++) { | 2374 | for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) { |
| 2371 | if (mpeg4_decode_studio_block(s, ctx->block32[i], i) < 0) | 2375 | if (mpeg4_decode_studio_block(ctx, ctx->block32[i], i) < 0) |
| 2372 | return AVERROR_INVALIDDATA; | 2376 | return AVERROR_INVALIDDATA; |
| 2373 | } | 2377 | } |
| 2374 | } else { | 2378 | } else { |
| 2375 | /* DPCM */ | 2379 | /* DPCM */ |
| 2376 | check_marker(s->avctx, &s->gb, "DPCM block start"); | 2380 | check_marker(h->c.avctx, &h->c.gb, "DPCM block start"); |
| 2377 | ctx->dpcm_direction = get_bits1(&s->gb) ? -1 : 1; | 2381 | ctx->dpcm_direction = get_bits1(&h->c.gb) ? -1 : 1; |
| 2378 | for (i = 0; i < 3; i++) { | 2382 | for (i = 0; i < 3; i++) { |
| 2379 | if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0) | 2383 | if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0) |
| 2380 | return AVERROR_INVALIDDATA; | 2384 | return AVERROR_INVALIDDATA; |
| 2381 | } | 2385 | } |
| 2382 | } | 2386 | } |
| 2383 | 2387 | ||
| 2384 | if (get_bits_left(&s->gb) >= 24 && show_bits(&s->gb, 23) == 0) { | 2388 | if (get_bits_left(&h->c.gb) >= 24 && show_bits(&h->c.gb, 23) == 0) { |
| 2385 | next_start_code_studio(&s->gb); | 2389 | next_start_code_studio(&h->c.gb); |
| 2386 | return SLICE_END; | 2390 | return SLICE_END; |
| 2387 | } | 2391 | } |
| 2388 | 2392 | ||
| 2389 | //vcon-stp9L1.bits (first frame) | 2393 | //vcon-stp9L1.bits (first frame) |
| 2390 | if (get_bits_left(&s->gb) == 0) | 2394 | if (get_bits_left(&h->c.gb) == 0) |
| 2391 | return SLICE_END; | 2395 | return SLICE_END; |
| 2392 | 2396 | ||
| 2393 | //vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame) | 2397 | //vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame) |
| 2394 | if (get_bits_left(&s->gb) < 8U && show_bits(&s->gb, get_bits_left(&s->gb)) == 0) | 2398 | if (get_bits_left(&h->c.gb) < 8U && show_bits(&h->c.gb, get_bits_left(&h->c.gb)) == 0) |
| 2395 | return SLICE_END; | 2399 | return SLICE_END; |
| 2396 | 2400 | ||
| 2397 | return SLICE_OK; | 2401 | return SLICE_OK; |
| @@ -2550,7 +2554,7 @@ static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id · 152 unmodified lines | |||
| 2550 | 2554 | ||
| 2551 | static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) | 2555 | static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 2552 | { | 2556 | { |
| 2553 | MpegEncContext *s = &ctx->m; | 2557 | MPVContext *const s = &ctx->h.c; |
| 2554 | int width, height, aspect_ratio_info; | 2558 | int width, height, aspect_ratio_info; |
| 2555 | int bits_per_raw_sample; | 2559 | int bits_per_raw_sample; |
| 2556 | int rgb, chroma_format; | 2560 | int rgb, chroma_format; |
| @@ -2636,7 +2640,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 79 unmodified lines | |||
| 2636 | 2640 | ||
| 2637 | static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) | 2641 | static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 2638 | { | 2642 | { |
| 2639 | MpegEncContext *s = &ctx->m; | 2643 | H263DecContext *const h = &ctx->h; |
| 2640 | int width, height, vo_ver_id, aspect_ratio_info; | 2644 | int width, height, vo_ver_id, aspect_ratio_info; |
| 2641 | 2645 | ||
| 2642 | /* vol header */ | 2646 | /* vol header */ |
| @@ -2650,12 +2654,12 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 7 unmodified lines | |||
| 2650 | */ | 2654 | */ |
| 2651 | if (ctx->vo_type == CORE_STUDIO_VO_TYPE || | 2655 | if (ctx->vo_type == CORE_STUDIO_VO_TYPE || |
| 2652 | ctx->vo_type == SIMPLE_STUDIO_VO_TYPE) { | 2656 | ctx->vo_type == SIMPLE_STUDIO_VO_TYPE) { |
| 2653 | if (s->avctx->profile != AV_PROFILE_UNKNOWN && s->avctx->profile != AV_PROFILE_MPEG4_SIMPLE_STUDIO) | 2657 | if (h->c.avctx->profile != AV_PROFILE_UNKNOWN && h->c.avctx->profile != AV_PROFILE_MPEG4_SIMPLE_STUDIO) |
| 2654 | return AVERROR_INVALIDDATA; | 2658 | return AVERROR_INVALIDDATA; |
| 2655 | s->studio_profile = 1; | 2659 | h->c.studio_profile = 1; |
| 2656 | s->avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO; | 2660 | h->c.avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO; |
| 2657 | return decode_studio_vol_header(ctx, gb); | 2661 | return decode_studio_vol_header(ctx, gb); |
| 2658 | } else if (s->studio_profile) { | 2662 | } else if (h->c.studio_profile) { |
| 2659 | return AVERROR_PATCHWELCOME; | 2663 | return AVERROR_PATCHWELCOME; |
| 2660 | } | 2664 | } |
| 2661 | 2665 | ||
| @@ -2667,97 +2671,97 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 5 unmodified lines | |||
| 2667 | } | 2671 | } |
| 2668 | aspect_ratio_info = get_bits(gb, 4); | 2672 | aspect_ratio_info = get_bits(gb, 4); |
| 2669 | if (aspect_ratio_info == FF_ASPECT_EXTENDED) { | 2673 | if (aspect_ratio_info == FF_ASPECT_EXTENDED) { |
| 2670 | s->avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width | 2674 | h->c.avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width |
| 2671 | s->avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height | 2675 | h->c.avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height |
| 2672 | } else { | 2676 | } else { |
| 2673 | s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info]; | 2677 | h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info]; |
| 2674 | } | 2678 | } |
| 2675 | 2679 | ||
| 2676 | if ((ctx->vol_control_parameters = get_bits1(gb))) { /* vol control parameter */ | 2680 | if ((ctx->vol_control_parameters = get_bits1(gb))) { /* vol control parameter */ |
| 2677 | int chroma_format = get_bits(gb, 2); | 2681 | int chroma_format = get_bits(gb, 2); |
| 2678 | if (chroma_format != CHROMA_420) | 2682 | if (chroma_format != CHROMA_420) |
| 2679 | av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n"); | 2683 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal chroma format\n"); |
| 2680 | 2684 | ||
| 2681 | s->low_delay = get_bits1(gb); | 2685 | h->c.low_delay = get_bits1(gb); |
| 2682 | if (get_bits1(gb)) { /* vbv parameters */ | 2686 | if (get_bits1(gb)) { /* vbv parameters */ |
| 2683 | get_bits(gb, 15); /* first_half_bitrate */ | 2687 | get_bits(gb, 15); /* first_half_bitrate */ |
| 2684 | check_marker(s->avctx, gb, "after first_half_bitrate"); | 2688 | check_marker(h->c.avctx, gb, "after first_half_bitrate"); |
| 2685 | get_bits(gb, 15); /* latter_half_bitrate */ | 2689 | get_bits(gb, 15); /* latter_half_bitrate */ |
| 2686 | check_marker(s->avctx, gb, "after latter_half_bitrate"); | 2690 | check_marker(h->c.avctx, gb, "after latter_half_bitrate"); |
| 2687 | get_bits(gb, 15); /* first_half_vbv_buffer_size */ | 2691 | get_bits(gb, 15); /* first_half_vbv_buffer_size */ |
| 2688 | check_marker(s->avctx, gb, "after first_half_vbv_buffer_size"); | 2692 | check_marker(h->c.avctx, gb, "after first_half_vbv_buffer_size"); |
| 2689 | get_bits(gb, 3); /* latter_half_vbv_buffer_size */ | 2693 | get_bits(gb, 3); /* latter_half_vbv_buffer_size */ |
| 2690 | get_bits(gb, 11); /* first_half_vbv_occupancy */ | 2694 | get_bits(gb, 11); /* first_half_vbv_occupancy */ |
| 2691 | check_marker(s->avctx, gb, "after first_half_vbv_occupancy"); | 2695 | check_marker(h->c.avctx, gb, "after first_half_vbv_occupancy"); |
| 2692 | get_bits(gb, 15); /* latter_half_vbv_occupancy */ | 2696 | get_bits(gb, 15); /* latter_half_vbv_occupancy */ |
| 2693 | check_marker(s->avctx, gb, "after latter_half_vbv_occupancy"); | 2697 | check_marker(h->c.avctx, gb, "after latter_half_vbv_occupancy"); |
| 2694 | } | 2698 | } |
| 2695 | } else { | 2699 | } else { |
| 2696 | /* is setting low delay flag only once the smartest thing to do? | 2700 | /* is setting low delay flag only once the smartest thing to do? |
| 2697 | * low delay detection will not be overridden. */ | 2701 | * low delay detection will not be overridden. */ |
| 2698 | if (s->picture_number == 0) { | 2702 | if (h->c.picture_number == 0) { |
| 2699 | switch (ctx->vo_type) { | 2703 | switch (ctx->vo_type) { |
| 2700 | case SIMPLE_VO_TYPE: | 2704 | case SIMPLE_VO_TYPE: |
| 2701 | case ADV_SIMPLE_VO_TYPE: | 2705 | case ADV_SIMPLE_VO_TYPE: |
| 2702 | s->low_delay = 1; | 2706 | h->c.low_delay = 1; |
| 2703 | break; | 2707 | break; |
| 2704 | default: | 2708 | default: |
| 2705 | s->low_delay = 0; | 2709 | h->c.low_delay = 0; |
| 2706 | } | 2710 | } |
| 2707 | } | 2711 | } |
| 2708 | } | 2712 | } |
| 2709 | 2713 | ||
| 2710 | ctx->shape = get_bits(gb, 2); /* vol shape */ | 2714 | ctx->shape = get_bits(gb, 2); /* vol shape */ |
| 2711 | if (ctx->shape != RECT_SHAPE) | 2715 | if (ctx->shape != RECT_SHAPE) |
| 2712 | av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n"); | 2716 | av_log(h->c.avctx, AV_LOG_ERROR, "only rectangular vol supported\n"); |
| 2713 | if (ctx->shape == GRAY_SHAPE && vo_ver_id != 1) { | 2717 | if (ctx->shape == GRAY_SHAPE && vo_ver_id != 1) { |
| 2714 | av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n"); | 2718 | av_log(h->c.avctx, AV_LOG_ERROR, "Gray shape not supported\n"); |
| 2715 | skip_bits(gb, 4); /* video_object_layer_shape_extension */ | 2719 | skip_bits(gb, 4); /* video_object_layer_shape_extension */ |
| 2716 | } | 2720 | } |
| 2717 | 2721 | ||
| 2718 | check_marker(s->avctx, gb, "before time_increment_resolution"); | 2722 | check_marker(h->c.avctx, gb, "before time_increment_resolution"); |
| 2719 | 2723 | ||
| 2720 | s->avctx->framerate.num = get_bits(gb, 16); | 2724 | h->c.avctx->framerate.num = get_bits(gb, 16); |
| 2721 | if (!s->avctx->framerate.num) { | 2725 | if (!h->c.avctx->framerate.num) { |
| 2722 | av_log(s->avctx, AV_LOG_ERROR, "framerate==0\n"); | 2726 | av_log(h->c.avctx, AV_LOG_ERROR, "framerate==0\n"); |
| 2723 | return AVERROR_INVALIDDATA; | 2727 | return AVERROR_INVALIDDATA; |
| 2724 | } | 2728 | } |
| 2725 | 2729 | ||
| 2726 | ctx->time_increment_bits = av_log2(s->avctx->framerate.num - 1) + 1; | 2730 | ctx->time_increment_bits = av_log2(h->c.avctx->framerate.num - 1) + 1; |
| 2727 | if (ctx->time_increment_bits < 1) | 2731 | if (ctx->time_increment_bits < 1) |
| 2728 | ctx->time_increment_bits = 1; | 2732 | ctx->time_increment_bits = 1; |
| 2729 | 2733 | ||
| 2730 | check_marker(s->avctx, gb, "before fixed_vop_rate"); | 2734 | check_marker(h->c.avctx, gb, "before fixed_vop_rate"); |
| 2731 | 2735 | ||
| 2732 | if (get_bits1(gb) != 0) /* fixed_vop_rate */ | 2736 | if (get_bits1(gb) != 0) /* fixed_vop_rate */ |
| 2733 | s->avctx->framerate.den = get_bits(gb, ctx->time_increment_bits); | 2737 | h->c.avctx->framerate.den = get_bits(gb, ctx->time_increment_bits); |
| 2734 | else | 2738 | else |
| 2735 | s->avctx->framerate.den = 1; | 2739 | h->c.avctx->framerate.den = 1; |
| 2736 | 2740 | ||
| 2737 | ctx->t_frame = 0; | 2741 | ctx->t_frame = 0; |
| 2738 | 2742 | ||
| 2739 | if (ctx->shape != BIN_ONLY_SHAPE) { | 2743 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 2740 | if (ctx->shape == RECT_SHAPE) { | 2744 | if (ctx->shape == RECT_SHAPE) { |
| 2741 | check_marker(s->avctx, gb, "before width"); | 2745 | check_marker(h->c.avctx, gb, "before width"); |
| 2742 | width = get_bits(gb, 13); | 2746 | width = get_bits(gb, 13); |
| 2743 | check_marker(s->avctx, gb, "before height"); | 2747 | check_marker(h->c.avctx, gb, "before height"); |
| 2744 | height = get_bits(gb, 13); | 2748 | height = get_bits(gb, 13); |
| 2745 | check_marker(s->avctx, gb, "after height"); | 2749 | check_marker(h->c.avctx, gb, "after height"); |
| 2746 | if (width && height && /* they should be non zero but who knows */ | 2750 | if (width && height && /* they should be non zero but who knows */ |
| 2747 | !(s->width && s->codec_tag == AV_RL32("MP4S"))) { | 2751 | !(h->c.width && h->c.codec_tag == AV_RL32("MP4S"))) { |
| 2748 | if (s->width && s->height && | 2752 | if (h->c.width && h->c.height && |
| 2749 | (s->width != width || s->height != height)) | 2753 | (h->c.width != width || h->c.height != height)) |
| 2750 | s->context_reinit = 1; | 2754 | h->c.context_reinit = 1; |
| 2751 | s->width = width; | 2755 | h->c.width = width; |
| 2752 | s->height = height; | 2756 | h->c.height = height; |
| 2753 | } | 2757 | } |
| 2754 | } | 2758 | } |
| 2755 | 2759 | ||
| 2756 | s->progressive_sequence = | 2760 | h->c.progressive_sequence = |
| 2757 | s->progressive_frame = get_bits1(gb) ^ 1; | 2761 | h->c.progressive_frame = get_bits1(gb) ^ 1; |
| 2758 | s->interlaced_dct = 0; | 2762 | h->c.interlaced_dct = 0; |
| 2759 | if (!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO)) | 2763 | if (!get_bits1(gb) && (h->c.avctx->debug & FF_DEBUG_PICT_INFO)) |
| 2760 | av_log(s->avctx, AV_LOG_INFO, /* OBMC Disable */ | 2764 | av_log(h->c.avctx, AV_LOG_INFO, /* OBMC Disable */ |
| 2761 | "MPEG-4 OBMC not supported (very likely buggy encoder)\n"); | 2765 | "MPEG-4 OBMC not supported (very likely buggy encoder)\n"); |
| 2762 | if (vo_ver_id == 1) | 2766 | if (vo_ver_id == 1) |
| 2763 | ctx->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */ | 2767 | ctx->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */ |
| @@ -2765,22 +2769,22 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | |||
| 2765 | ctx->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ | 2769 | ctx->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ |
| 2766 | 2770 | ||
| 2767 | if (ctx->vol_sprite_usage == STATIC_SPRITE) | 2771 | if (ctx->vol_sprite_usage == STATIC_SPRITE) |
| 2768 | av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n"); | 2772 | av_log(h->c.avctx, AV_LOG_ERROR, "Static Sprites not supported\n"); |
| 2769 | if (ctx->vol_sprite_usage == STATIC_SPRITE || | 2773 | if (ctx->vol_sprite_usage == STATIC_SPRITE || |
| 2770 | ctx->vol_sprite_usage == GMC_SPRITE) { | 2774 | ctx->vol_sprite_usage == GMC_SPRITE) { |
| 2771 | if (ctx->vol_sprite_usage == STATIC_SPRITE) { | 2775 | if (ctx->vol_sprite_usage == STATIC_SPRITE) { |
| 2772 | skip_bits(gb, 13); // sprite_width | 2776 | skip_bits(gb, 13); // sprite_width |
| 2773 | check_marker(s->avctx, gb, "after sprite_width"); | 2777 | check_marker(h->c.avctx, gb, "after sprite_width"); |
| 2774 | skip_bits(gb, 13); // sprite_height | 2778 | skip_bits(gb, 13); // sprite_height |
| 2775 | check_marker(s->avctx, gb, "after sprite_height"); | 2779 | check_marker(h->c.avctx, gb, "after sprite_height"); |
| 2776 | skip_bits(gb, 13); // sprite_left | 2780 | skip_bits(gb, 13); // sprite_left |
| 2777 | check_marker(s->avctx, gb, "after sprite_left"); | 2781 | check_marker(h->c.avctx, gb, "after sprite_left"); |
| 2778 | skip_bits(gb, 13); // sprite_top | 2782 | skip_bits(gb, 13); // sprite_top |
| 2779 | check_marker(s->avctx, gb, "after sprite_top"); | 2783 | check_marker(h->c.avctx, gb, "after sprite_top"); |
| 2780 | } | 2784 | } |
| 2781 | ctx->num_sprite_warping_points = get_bits(gb, 6); | 2785 | ctx->num_sprite_warping_points = get_bits(gb, 6); |
| 2782 | if (ctx->num_sprite_warping_points > 3) { | 2786 | if (ctx->num_sprite_warping_points > 3) { |
| 2783 | av_log(s->avctx, AV_LOG_ERROR, | 2787 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 2784 | "%d sprite_warping_points\n", | 2788 | "%d sprite_warping_points\n", |
| 2785 | ctx->num_sprite_warping_points); | 2789 | ctx->num_sprite_warping_points); |
| 2786 | ctx->num_sprite_warping_points = 0; | 2790 | ctx->num_sprite_warping_points = 0; |
| @@ -2796,9 +2800,9 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 9 unmodified lines | |||
| 2796 | if (get_bits1(gb) == 1) { /* not_8_bit */ | 2800 | if (get_bits1(gb) == 1) { /* not_8_bit */ |
| 2797 | ctx->quant_precision = get_bits(gb, 4); /* quant_precision */ | 2801 | ctx->quant_precision = get_bits(gb, 4); /* quant_precision */ |
| 2798 | if (get_bits(gb, 4) != 8) /* bits_per_pixel */ | 2802 | if (get_bits(gb, 4) != 8) /* bits_per_pixel */ |
| 2799 | av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n"); | 2803 | av_log(h->c.avctx, AV_LOG_ERROR, "N-bit not supported\n"); |
| 2800 | if (ctx->quant_precision != 5) | 2804 | if (ctx->quant_precision != 5) |
| 2801 | av_log(s->avctx, AV_LOG_ERROR, | 2805 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 2802 | "quant precision %d\n", ctx->quant_precision); | 2806 | "quant precision %d\n", ctx->quant_precision); |
| 2803 | if (ctx->quant_precision < 3 || ctx->quant_precision > 9) | 2807 | if (ctx->quant_precision < 3 || ctx->quant_precision > 9) |
| 2804 | ctx->quant_precision = 5; | 2808 | ctx->quant_precision = 5; |
| @@ -2811,7 +2815,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 6 unmodified lines | |||
| 2811 | if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */ | 2815 | if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */ |
| 2812 | int i, v; | 2816 | int i, v; |
| 2813 | 2817 | ||
| 2814 | mpeg4_load_default_matrices(s); | 2818 | mpeg4_load_default_matrices(&h->c); |
| 2815 | 2819 | ||
| 2816 | /* load custom intra matrix */ | 2820 | /* load custom intra matrix */ |
| 2817 | if (get_bits1(gb)) { | 2821 | if (get_bits1(gb)) { |
| @@ -2819,7 +2823,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | |||
| 2819 | for (i = 0; i < 64; i++) { | 2823 | for (i = 0; i < 64; i++) { |
| 2820 | int j; | 2824 | int j; |
| 2821 | if (get_bits_left(gb) < 8) { | 2825 | if (get_bits_left(gb) < 8) { |
| 2822 | av_log(s->avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n"); | 2826 | av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n"); |
| 2823 | return AVERROR_INVALIDDATA; | 2827 | return AVERROR_INVALIDDATA; |
| 2824 | } | 2828 | } |
| 2825 | v = get_bits(gb, 8); | 2829 | v = get_bits(gb, 8); |
| @@ -2827,14 +2831,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | |||
| 2827 | break; | 2831 | break; |
| 2828 | 2832 | ||
| 2829 | last = v; | 2833 | last = v; |
| 2830 | j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | 2834 | j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; |
| 2831 | s->intra_matrix[j] = last; | 2835 | h->c.intra_matrix[j] = last; |
| 2832 | } | 2836 | } |
| 2833 | 2837 | ||
| 2834 | /* replicate last value */ | 2838 | /* replicate last value */ |
| 2835 | for (; i < 64; i++) { | 2839 | for (; i < 64; i++) { |
| 2836 | int j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | 2840 | int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; |
| 2837 | s->intra_matrix[j] = last; | 2841 | h->c.intra_matrix[j] = last; |
| 2838 | } | 2842 | } |
| 2839 | } | 2843 | } |
| 2840 | 2844 | ||
| @@ -2844,7 +2848,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 3 unmodified lines | |||
| 2844 | for (i = 0; i < 64; i++) { | 2848 | for (i = 0; i < 64; i++) { |
| 2845 | int j; | 2849 | int j; |
| 2846 | if (get_bits_left(gb) < 8) { | 2850 | if (get_bits_left(gb) < 8) { |
| 2847 | av_log(s->avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n"); | 2851 | av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n"); |
| 2848 | return AVERROR_INVALIDDATA; | 2852 | return AVERROR_INVALIDDATA; |
| 2849 | } | 2853 | } |
| 2850 | v = get_bits(gb, 8); | 2854 | v = get_bits(gb, 8); |
| @@ -2852,14 +2856,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | |||
| 2852 | break; | 2856 | break; |
| 2853 | 2857 | ||
| 2854 | last = v; | 2858 | last = v; |
| 2855 | j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | 2859 | j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; |
| 2856 | s->inter_matrix[j] = v; | 2860 | h->c.inter_matrix[j] = v; |
| 2857 | } | 2861 | } |
| 2858 | 2862 | ||
| 2859 | /* replicate last value */ | 2863 | /* replicate last value */ |
| 2860 | for (; i < 64; i++) { | 2864 | for (; i < 64; i++) { |
| 2861 | int j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | 2865 | int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; |
| 2862 | s->inter_matrix[j] = last; | 2866 | h->c.inter_matrix[j] = last; |
| 2863 | } | 2867 | } |
| 2864 | } | 2868 | } |
| 2865 | 2869 | ||
| @@ -2867,12 +2871,12 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | |||
| 2867 | } | 2871 | } |
| 2868 | 2872 | ||
| 2869 | if (vo_ver_id != 1) | 2873 | if (vo_ver_id != 1) |
| 2870 | s->quarter_sample = get_bits1(gb); | 2874 | h->c.quarter_sample = get_bits1(gb); |
| 2871 | else | 2875 | else |
| 2872 | s->quarter_sample = 0; | 2876 | h->c.quarter_sample = 0; |
| 2873 | 2877 | ||
| 2874 | if (get_bits_left(gb) < 4) { | 2878 | if (get_bits_left(gb) < 4) { |
| 2875 | av_log(s->avctx, AV_LOG_ERROR, "VOL Header truncated\n"); | 2879 | av_log(h->c.avctx, AV_LOG_ERROR, "VOL Header truncated\n"); |
| 2876 | return AVERROR_INVALIDDATA; | 2880 | return AVERROR_INVALIDDATA; |
| 2877 | } | 2881 | } |
| 2878 | 2882 | ||
| @@ -2894,7 +2898,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 15 unmodified lines | |||
| 2894 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter4v_blocks */ | 2898 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter4v_blocks */ |
| 2895 | ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* not coded blocks */ | 2899 | ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* not coded blocks */ |
| 2896 | } | 2900 | } |
| 2897 | if (!check_marker(s->avctx, gb, "in complexity estimation part 1")) { | 2901 | if (!check_marker(h->c.avctx, gb, "in complexity estimation part 1")) { |
| 2898 | skip_bits_long(gb, pos - get_bits_count(gb)); | 2902 | skip_bits_long(gb, pos - get_bits_count(gb)); |
| 2899 | goto no_cplx_est; | 2903 | goto no_cplx_est; |
| 2900 | } | 2904 | } |
| @@ -2912,7 +2916,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 11 unmodified lines | |||
| 2912 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel2 */ | 2916 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel2 */ |
| 2913 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel4 */ | 2917 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel4 */ |
| 2914 | } | 2918 | } |
| 2915 | if (!check_marker(s->avctx, gb, "in complexity estimation part 2")) { | 2919 | if (!check_marker(h->c.avctx, gb, "in complexity estimation part 2")) { |
| 2916 | skip_bits_long(gb, pos - get_bits_count(gb)); | 2920 | skip_bits_long(gb, pos - get_bits_count(gb)); |
| 2917 | goto no_cplx_est; | 2921 | goto no_cplx_est; |
| 2918 | } | 2922 | } |
| @@ -2921,7 +2925,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 2 unmodified lines | |||
| 2921 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* qpel */ | 2925 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* qpel */ |
| 2922 | } | 2926 | } |
| 2923 | } else | 2927 | } else |
| 2924 | av_log(s->avctx, AV_LOG_ERROR, | 2928 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 2925 | "Invalid Complexity estimation method %d\n", | 2929 | "Invalid Complexity estimation method %d\n", |
| 2926 | estimation_method); | 2930 | estimation_method); |
| 2927 | } else { | 2931 | } else { |
| @@ -2934,19 +2938,19 @@ no_cplx_est: · 6 unmodified lines | |||
| 2934 | 2938 | ||
| 2935 | ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */ | 2939 | ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */ |
| 2936 | 2940 | ||
| 2937 | s->data_partitioning = get_bits1(gb); | 2941 | h->c.data_partitioning = get_bits1(gb); |
| 2938 | if (s->data_partitioning) | 2942 | if (h->c.data_partitioning) |
| 2939 | ctx->rvlc = get_bits1(gb); | 2943 | ctx->rvlc = get_bits1(gb); |
| 2940 | 2944 | ||
| 2941 | if (vo_ver_id != 1) { | 2945 | if (vo_ver_id != 1) { |
| 2942 | ctx->new_pred = get_bits1(gb); | 2946 | ctx->new_pred = get_bits1(gb); |
| 2943 | if (ctx->new_pred) { | 2947 | if (ctx->new_pred) { |
| 2944 | av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n"); | 2948 | av_log(h->c.avctx, AV_LOG_ERROR, "new pred not supported\n"); |
| 2945 | skip_bits(gb, 2); /* requested upstream message type */ | 2949 | skip_bits(gb, 2); /* requested upstream message type */ |
| 2946 | skip_bits1(gb); /* newpred segment type */ | 2950 | skip_bits1(gb); /* newpred segment type */ |
| 2947 | } | 2951 | } |
| 2948 | if (get_bits1(gb)) // reduced_res_vop | 2952 | if (get_bits1(gb)) // reduced_res_vop |
| 2949 | av_log(s->avctx, AV_LOG_ERROR, | 2953 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 2950 | "reduced resolution VOP not supported\n"); | 2954 | "reduced resolution VOP not supported\n"); |
| 2951 | } else { | 2955 | } else { |
| 2952 | ctx->new_pred = 0; | 2956 | ctx->new_pred = 0; |
| @@ -2977,21 +2981,23 @@ no_cplx_est: · 24 unmodified lines | |||
| 2977 | ctx->scalability = 0; | 2981 | ctx->scalability = 0; |
| 2978 | *gb = bak; | 2982 | *gb = bak; |
| 2979 | } else | 2983 | } else |
| 2980 | av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n"); | 2984 | av_log(h->c.avctx, AV_LOG_ERROR, "scalability not supported\n"); |
| 2981 | 2985 | ||
| 2982 | // bin shape stuff FIXME | 2986 | // bin shape stuff FIXME |
| 2983 | } | 2987 | } |
| 2984 | } | 2988 | } |
| 2985 | 2989 | ||
| 2986 | if (s->avctx->debug&FF_DEBUG_PICT_INFO) { | 2990 | if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) { |
| 2987 | av_log(s->avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n", | 2991 | av_log(h->c.avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n", |
| 2988 | s->avctx->framerate.den, s->avctx->framerate.num, | 2992 | h->c.avctx->framerate.den, h->c.avctx->framerate.num, |
| 2989 | ctx->time_increment_bits, | 2993 | ctx->time_increment_bits, |
| 2990 | ctx->quant_precision, | 2994 | ctx->quant_precision, |
| 2991 | s->progressive_sequence, | 2995 | h->c.progressive_sequence, |
| 2992 | s->low_delay, | 2996 | h->c.low_delay, |
| 2993 | ctx->scalability ? "scalability " :"" , s->quarter_sample ? "qpel " : "", | 2997 | ctx->scalability ? "scalability " :"" , |
| 2994 | s->data_partitioning ? "partition " : "", ctx->rvlc ? "rvlc " : "" | 2998 | h->c.quarter_sample ? "qpel " : "", |
| 2999 | h->c.data_partitioning ? "partition " : "", | ||
| 3000 | ctx->rvlc ? "rvlc " : "" | ||
| 2995 | ); | 3001 | ); |
| 2996 | } | 3002 | } |
| 2997 | 3003 | ||
| @@ -3004,7 +3010,7 @@ no_cplx_est: · 6 unmodified lines | |||
| 3004 | */ | 3010 | */ |
| 3005 | static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) | 3011 | static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 3006 | { | 3012 | { |
| 3007 | MpegEncContext *s = &ctx->m; | 3013 | H263DecContext *const h = &ctx->h; |
| 3008 | char buf[256]; | 3014 | char buf[256]; |
| 3009 | int i; | 3015 | int i; |
| 3010 | int e; | 3016 | int e; |
| @@ -3025,7 +3031,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) · 14 unmodified lines | |||
| 3025 | if (e >= 2) { | 3031 | if (e >= 2) { |
| 3026 | ctx->divx_version = ver; | 3032 | ctx->divx_version = ver; |
| 3027 | ctx->divx_build = build; | 3033 | ctx->divx_build = build; |
| 3028 | s->divx_packed = e == 3 && last == 'p'; | 3034 | h->c.divx_packed = e == 3 && last == 'p'; |
| 3029 | } | 3035 | } |
| 3030 | 3036 | ||
| 3031 | /* libavcodec detection */ | 3037 | /* libavcodec detection */ |
| @@ -3036,7 +3042,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) · 4 unmodified lines | |||
| 3036 | e = sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1; | 3042 | e = sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1; |
| 3037 | if (e > 1) { | 3043 | if (e > 1) { |
| 3038 | if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) { | 3044 | if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) { |
| 3039 | av_log(s->avctx, AV_LOG_WARNING, | 3045 | av_log(h->c.avctx, AV_LOG_WARNING, |
| 3040 | "Unknown Lavc version string encountered, %d.%d.%d; " | 3046 | "Unknown Lavc version string encountered, %d.%d.%d; " |
| 3041 | "clamping sub-version values to 8-bits.\n", | 3047 | "clamping sub-version values to 8-bits.\n", |
| 3042 | ver, ver2, ver3); | 3048 | ver, ver2, ver3); |
| @@ -3091,19 +3097,19 @@ static av_cold void switch_to_xvid_idct(AVCodecContext *const avctx, · 48 unmodified lines | |||
| 3091 | void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) | 3097 | void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) |
| 3092 | { | 3098 | { |
| 3093 | Mpeg4DecContext *ctx = avctx->priv_data; | 3099 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 3094 | MpegEncContext *s = &ctx->m; | 3100 | H263DecContext *const h = &ctx->h; |
| 3095 | 3101 | ||
| 3096 | if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) { | 3102 | if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) { |
| 3097 | if (s->codec_tag == AV_RL32("XVID") || | 3103 | if (h->c.codec_tag == AV_RL32("XVID") || |
| 3098 | s->codec_tag == AV_RL32("XVIX") || | 3104 | h->c.codec_tag == AV_RL32("XVIX") || |
| 3099 | s->codec_tag == AV_RL32("RMP4") || | 3105 | h->c.codec_tag == AV_RL32("RMP4") || |
| 3100 | s->codec_tag == AV_RL32("ZMP4") || | 3106 | h->c.codec_tag == AV_RL32("ZMP4") || |
| 3101 | s->codec_tag == AV_RL32("SIPP")) | 3107 | h->c.codec_tag == AV_RL32("SIPP")) |
| 3102 | ctx->xvid_build = 0; | 3108 | ctx->xvid_build = 0; |
| 3103 | } | 3109 | } |
| 3104 | 3110 | ||
| 3105 | if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) | 3111 | if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) |
| 3106 | if (s->codec_tag == AV_RL32("DIVX") && ctx->vo_type == 0 && | 3112 | if (h->c.codec_tag == AV_RL32("DIVX") && ctx->vo_type == 0 && |
| 3107 | ctx->vol_control_parameters == 0) | 3113 | ctx->vol_control_parameters == 0) |
| 3108 | ctx->divx_version = 400; // divx 4 | 3114 | ctx->divx_version = 400; // divx 4 |
| 3109 | 3115 | ||
| @@ -3112,68 +3118,68 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) · 2 unmodified lines | |||
| 3112 | ctx->divx_build = -1; | 3118 | ctx->divx_build = -1; |
| 3113 | } | 3119 | } |
| 3114 | 3120 | ||
| 3115 | if (s->workaround_bugs & FF_BUG_AUTODETECT) { | 3121 | if (h->c.workaround_bugs & FF_BUG_AUTODETECT) { |
| 3116 | if (s->codec_tag == AV_RL32("XVIX")) | 3122 | if (h->c.codec_tag == AV_RL32("XVIX")) |
| 3117 | s->workaround_bugs |= FF_BUG_XVID_ILACE; | 3123 | h->c.workaround_bugs |= FF_BUG_XVID_ILACE; |
| 3118 | 3124 | ||
| 3119 | if (s->codec_tag == AV_RL32("UMP4")) | 3125 | if (h->c.codec_tag == AV_RL32("UMP4")) |
| 3120 | s->workaround_bugs |= FF_BUG_UMP4; | 3126 | h->c.workaround_bugs |= FF_BUG_UMP4; |
| 3121 | 3127 | ||
| 3122 | if (ctx->divx_version >= 500 && ctx->divx_build < 1814) | 3128 | if (ctx->divx_version >= 500 && ctx->divx_build < 1814) |
| 3123 | s->workaround_bugs |= FF_BUG_QPEL_CHROMA; | 3129 | h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA; |
| 3124 | 3130 | ||
| 3125 | if (ctx->divx_version > 502 && ctx->divx_build < 1814) | 3131 | if (ctx->divx_version > 502 && ctx->divx_build < 1814) |
| 3126 | s->workaround_bugs |= FF_BUG_QPEL_CHROMA2; | 3132 | h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA2; |
| 3127 | 3133 | ||
| 3128 | if (ctx->xvid_build <= 3U) | 3134 | if (ctx->xvid_build <= 3U) |
| 3129 | s->padding_bug_score = 256 * 256 * 256 * 64; | 3135 | h->c.padding_bug_score = 256 * 256 * 256 * 64; |
| 3130 | 3136 | ||
| 3131 | if (ctx->xvid_build <= 1U) | 3137 | if (ctx->xvid_build <= 1U) |
| 3132 | s->workaround_bugs |= FF_BUG_QPEL_CHROMA; | 3138 | h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA; |
| 3133 | 3139 | ||
| 3134 | if (ctx->xvid_build <= 12U) | 3140 | if (ctx->xvid_build <= 12U) |
| 3135 | s->workaround_bugs |= FF_BUG_EDGE; | 3141 | h->c.workaround_bugs |= FF_BUG_EDGE; |
| 3136 | 3142 | ||
| 3137 | if (ctx->xvid_build <= 32U) | 3143 | if (ctx->xvid_build <= 32U) |
| 3138 | s->workaround_bugs |= FF_BUG_DC_CLIP; | 3144 | h->c.workaround_bugs |= FF_BUG_DC_CLIP; |
| 3139 | 3145 | ||
| 3140 | #define SET_QPEL_FUNC(postfix1, postfix2) \ | 3146 | #define SET_QPEL_FUNC(postfix1, postfix2) \ |
| 3141 | s->qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \ | 3147 | h->c.qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \ |
| 3142 | s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \ | 3148 | h->c.qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \ |
| 3143 | s->qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2; | 3149 | h->c.qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2; |
| 3144 | 3150 | ||
| 3145 | if (ctx->lavc_build < 4653U) | 3151 | if (ctx->lavc_build < 4653U) |
| 3146 | s->workaround_bugs |= FF_BUG_STD_QPEL; | 3152 | h->c.workaround_bugs |= FF_BUG_STD_QPEL; |
| 3147 | 3153 | ||
| 3148 | if (ctx->lavc_build < 4655U) | 3154 | if (ctx->lavc_build < 4655U) |
| 3149 | s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; | 3155 | h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; |
| 3150 | 3156 | ||
| 3151 | if (ctx->lavc_build < 4670U) | 3157 | if (ctx->lavc_build < 4670U) |
| 3152 | s->workaround_bugs |= FF_BUG_EDGE; | 3158 | h->c.workaround_bugs |= FF_BUG_EDGE; |
| 3153 | 3159 | ||
| 3154 | if (ctx->lavc_build <= 4712U) | 3160 | if (ctx->lavc_build <= 4712U) |
| 3155 | s->workaround_bugs |= FF_BUG_DC_CLIP; | 3161 | h->c.workaround_bugs |= FF_BUG_DC_CLIP; |
| 3156 | 3162 | ||
| 3157 | if ((ctx->lavc_build&0xFF) >= 100) { | 3163 | if ((ctx->lavc_build&0xFF) >= 100) { |
| 3158 | if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752552 && | 3164 | if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752552 && |
| 3159 | (ctx->lavc_build < 3752037 || ctx->lavc_build > 3752191) // 3.2.1+ | 3165 | (ctx->lavc_build < 3752037 || ctx->lavc_build > 3752191) // 3.2.1+ |
| 3160 | ) | 3166 | ) |
| 3161 | s->workaround_bugs |= FF_BUG_IEDGE; | 3167 | h->c.workaround_bugs |= FF_BUG_IEDGE; |
| 3162 | } | 3168 | } |
| 3163 | 3169 | ||
| 3164 | if (ctx->divx_version >= 0) | 3170 | if (ctx->divx_version >= 0) |
| 3165 | s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; | 3171 | h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; |
| 3166 | if (ctx->divx_version == 501 && ctx->divx_build == 20020416) | 3172 | if (ctx->divx_version == 501 && ctx->divx_build == 20020416) |
| 3167 | s->padding_bug_score = 256 * 256 * 256 * 64; | 3173 | h->c.padding_bug_score = 256 * 256 * 256 * 64; |
| 3168 | 3174 | ||
| 3169 | if (ctx->divx_version < 500U) | 3175 | if (ctx->divx_version < 500U) |
| 3170 | s->workaround_bugs |= FF_BUG_EDGE; | 3176 | h->c.workaround_bugs |= FF_BUG_EDGE; |
| 3171 | 3177 | ||
| 3172 | if (ctx->divx_version >= 0) | 3178 | if (ctx->divx_version >= 0) |
| 3173 | s->workaround_bugs |= FF_BUG_HPEL_CHROMA; | 3179 | h->c.workaround_bugs |= FF_BUG_HPEL_CHROMA; |
| 3174 | } | 3180 | } |
| 3175 | 3181 | ||
| 3176 | if (s->workaround_bugs & FF_BUG_STD_QPEL) { | 3182 | if (h->c.workaround_bugs & FF_BUG_STD_QPEL) { |
| 3177 | SET_QPEL_FUNC(qpel_pixels_tab[0][5], qpel16_mc11_old_c) | 3183 | SET_QPEL_FUNC(qpel_pixels_tab[0][5], qpel16_mc11_old_c) |
| 3178 | SET_QPEL_FUNC(qpel_pixels_tab[0][7], qpel16_mc31_old_c) | 3184 | SET_QPEL_FUNC(qpel_pixels_tab[0][7], qpel16_mc31_old_c) |
| 3179 | SET_QPEL_FUNC(qpel_pixels_tab[0][9], qpel16_mc12_old_c) | 3185 | SET_QPEL_FUNC(qpel_pixels_tab[0][9], qpel16_mc12_old_c) |
| @@ -3190,54 +3196,54 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) · 10 unmodified lines | |||
| 3190 | } | 3196 | } |
| 3191 | 3197 | ||
| 3192 | if (avctx->debug & FF_DEBUG_BUGS) | 3198 | if (avctx->debug & FF_DEBUG_BUGS) |
| 3193 | av_log(s->avctx, AV_LOG_DEBUG, | 3199 | av_log(h->c.avctx, AV_LOG_DEBUG, |
| 3194 | "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n", | 3200 | "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n", |
| 3195 | s->workaround_bugs, ctx->lavc_build, ctx->xvid_build, | 3201 | h->c.workaround_bugs, ctx->lavc_build, ctx->xvid_build, |
| 3196 | ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : ""); | 3202 | ctx->divx_version, ctx->divx_build, h->c.divx_packed ? "p" : ""); |
| 3197 | 3203 | ||
| 3198 | if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 && | 3204 | if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 && |
| 3199 | avctx->idct_algo == FF_IDCT_AUTO && !s->studio_profile) { | 3205 | avctx->idct_algo == FF_IDCT_AUTO && !h->c.studio_profile) { |
| 3200 | switch_to_xvid_idct(avctx, s); | 3206 | switch_to_xvid_idct(avctx, &h->c); |
| 3201 | } | 3207 | } |
| 3202 | } | 3208 | } |
| 3203 | 3209 | ||
| 3204 | static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, | 3210 | static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, |
| 3205 | int parse_only) | 3211 | int parse_only) |
| 3206 | { | 3212 | { |
| 3207 | MpegEncContext *s = &ctx->m; | 3213 | H263DecContext *const h = &ctx->h; |
| 3208 | int time_incr, time_increment; | 3214 | int time_incr, time_increment; |
| 3209 | int64_t pts; | 3215 | int64_t pts; |
| 3210 | 3216 | ||
| 3211 | s->mcsel = 0; | 3217 | h->c.mcsel = 0; |
| 3212 | s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */ | 3218 | h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */ |
| 3213 | if (s->pict_type == AV_PICTURE_TYPE_B && s->low_delay && | 3219 | if (h->c.pict_type == AV_PICTURE_TYPE_B && h->c.low_delay && |
| 3214 | ctx->vol_control_parameters == 0 && !(s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) { | 3220 | ctx->vol_control_parameters == 0 && !(h->c.avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) { |
| 3215 | av_log(s->avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n"); | 3221 | av_log(h->c.avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n"); |
| 3216 | s->low_delay = 0; | 3222 | h->c.low_delay = 0; |
| 3217 | } | 3223 | } |
| 3218 | 3224 | ||
| 3219 | s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B; | 3225 | h->c.partitioned_frame = h->c.data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B; |
| 3220 | if (s->partitioned_frame) | 3226 | if (h->c.partitioned_frame) |
| 3221 | s->decode_mb = mpeg4_decode_partitioned_mb; | 3227 | h->decode_mb = mpeg4_decode_partitioned_mb; |
| 3222 | else | 3228 | else |
| 3223 | s->decode_mb = mpeg4_decode_mb; | 3229 | h->decode_mb = mpeg4_decode_mb; |
| 3224 | 3230 | ||
| 3225 | time_incr = 0; | 3231 | time_incr = 0; |
| 3226 | while (get_bits1(gb) != 0) | 3232 | while (get_bits1(gb) != 0) |
| 3227 | time_incr++; | 3233 | time_incr++; |
| 3228 | 3234 | ||
| 3229 | check_marker(s->avctx, gb, "before time_increment"); | 3235 | check_marker(h->c.avctx, gb, "before time_increment"); |
| 3230 | 3236 | ||
| 3231 | if (ctx->time_increment_bits == 0 || | 3237 | if (ctx->time_increment_bits == 0 || |
| 3232 | !(show_bits(gb, ctx->time_increment_bits + 1) & 1)) { | 3238 | !(show_bits(gb, ctx->time_increment_bits + 1) & 1)) { |
| 3233 | av_log(s->avctx, AV_LOG_WARNING, | 3239 | av_log(h->c.avctx, AV_LOG_WARNING, |
| 3234 | "time_increment_bits %d is invalid in relation to the current bitstream, this is likely caused by a missing VOL header\n", ctx->time_increment_bits); | 3240 | "time_increment_bits %d is invalid in relation to the current bitstream, this is likely caused by a missing VOL header\n", ctx->time_increment_bits); |
| 3235 | 3241 | ||
| 3236 | for (ctx->time_increment_bits = 1; | 3242 | for (ctx->time_increment_bits = 1; |
| 3237 | ctx->time_increment_bits < 16; | 3243 | ctx->time_increment_bits < 16; |
| 3238 | ctx->time_increment_bits++) { | 3244 | ctx->time_increment_bits++) { |
| 3239 | if (s->pict_type == AV_PICTURE_TYPE_P || | 3245 | if (h->c.pict_type == AV_PICTURE_TYPE_P || |
| 3240 | (s->pict_type == AV_PICTURE_TYPE_S && | 3246 | (h->c.pict_type == AV_PICTURE_TYPE_S && |
| 3241 | ctx->vol_sprite_usage == GMC_SPRITE)) { | 3247 | ctx->vol_sprite_usage == GMC_SPRITE)) { |
| 3242 | if ((show_bits(gb, ctx->time_increment_bits + 6) & 0x37) == 0x30) | 3248 | if ((show_bits(gb, ctx->time_increment_bits + 6) & 0x37) == 0x30) |
| 3243 | break; | 3249 | break; |
| @@ -3245,7 +3251,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 1 unmodified line | |||
| 3245 | break; | 3251 | break; |
| 3246 | } | 3252 | } |
| 3247 | 3253 | ||
| 3248 | av_log(s->avctx, AV_LOG_WARNING, | 3254 | av_log(h->c.avctx, AV_LOG_WARNING, |
| 3249 | "time_increment_bits set to %d bits, based on bitstream analysis\n", ctx->time_increment_bits); | 3255 | "time_increment_bits set to %d bits, based on bitstream analysis\n", ctx->time_increment_bits); |
| 3250 | } | 3256 | } |
| 3251 | 3257 | ||
| @@ -3254,84 +3260,84 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 2 unmodified lines | |||
| 3254 | else | 3260 | else |
| 3255 | time_increment = get_bits(gb, ctx->time_increment_bits); | 3261 | time_increment = get_bits(gb, ctx->time_increment_bits); |
| 3256 | 3262 | ||
| 3257 | if (s->pict_type != AV_PICTURE_TYPE_B) { | 3263 | if (h->c.pict_type != AV_PICTURE_TYPE_B) { |
| 3258 | s->last_time_base = s->time_base; | 3264 | h->c.last_time_base = h->c.time_base; |
| 3259 | s->time_base += time_incr; | 3265 | h->c.time_base += time_incr; |
| 3260 | s->time = s->time_base * (int64_t)s->avctx->framerate.num + time_increment; | 3266 | h->c.time = h->c.time_base * (int64_t)h->c.avctx->framerate.num + time_increment; |
| 3261 | if (s->workaround_bugs & FF_BUG_UMP4) { | 3267 | if (h->c.workaround_bugs & FF_BUG_UMP4) { |
| 3262 | if (s->time < s->last_non_b_time) { | 3268 | if (h->c.time < h->c.last_non_b_time) { |
| 3263 | /* header is not mpeg-4-compatible, broken encoder, | 3269 | /* header is not mpeg-4-compatible, broken encoder, |
| 3264 | * trying to workaround */ | 3270 | * trying to workaround */ |
| 3265 | s->time_base++; | 3271 | h->c.time_base++; |
| 3266 | s->time += s->avctx->framerate.num; | 3272 | h->c.time += h->c.avctx->framerate.num; |
| 3267 | } | 3273 | } |
| 3268 | } | 3274 | } |
| 3269 | s->pp_time = s->time - s->last_non_b_time; | 3275 | h->c.pp_time = h->c.time - h->c.last_non_b_time; |
| 3270 | s->last_non_b_time = s->time; | 3276 | h->c.last_non_b_time = h->c.time; |
| 3271 | } else { | 3277 | } else { |
| 3272 | s->time = (s->last_time_base + time_incr) * (int64_t)s->avctx->framerate.num + time_increment; | 3278 | h->c.time = (h->c.last_time_base + time_incr) * (int64_t)h->c.avctx->framerate.num + time_increment; |
| 3273 | s->pb_time = s->pp_time - (s->last_non_b_time - s->time); | 3279 | h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time); |
| 3274 | if (s->pp_time <= s->pb_time || | 3280 | if (h->c.pp_time <= h->c.pb_time || |
| 3275 | s->pp_time <= s->pp_time - s->pb_time || | 3281 | h->c.pp_time <= h->c.pp_time - h->c.pb_time || |
| 3276 | s->pp_time <= 0) { | 3282 | h->c.pp_time <= 0) { |
| 3277 | /* messed up order, maybe after seeking? skipping current B-frame */ | 3283 | /* messed up order, maybe after seeking? skipping current B-frame */ |
| 3278 | return FRAME_SKIPPED; | 3284 | return FRAME_SKIPPED; |
| 3279 | } | 3285 | } |
| 3280 | ff_mpeg4_init_direct_mv(s); | 3286 | ff_mpeg4_init_direct_mv(&h->c); |
| 3281 | 3287 | ||
| 3282 | if (ctx->t_frame == 0) | 3288 | if (ctx->t_frame == 0) |
| 3283 | ctx->t_frame = s->pb_time; | 3289 | ctx->t_frame = h->c.pb_time; |
| 3284 | if (ctx->t_frame == 0) | 3290 | if (ctx->t_frame == 0) |
| 3285 | ctx->t_frame = 1; // 1/0 protection | 3291 | ctx->t_frame = 1; // 1/0 protection |
| 3286 | s->pp_field_time = (ROUNDED_DIV(s->last_non_b_time, ctx->t_frame) - | 3292 | h->c.pp_field_time = (ROUNDED_DIV(h->c.last_non_b_time, ctx->t_frame) - |
| 3287 | ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2; | 3293 | ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2; |
| 3288 | s->pb_field_time = (ROUNDED_DIV(s->time, ctx->t_frame) - | 3294 | h->c.pb_field_time = (ROUNDED_DIV(h->c.time, ctx->t_frame) - |
| 3289 | ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2; | 3295 | ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2; |
| 3290 | if (s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) { | 3296 | if (h->c.pp_field_time <= h->c.pb_field_time || h->c.pb_field_time <= 1) { |
| 3291 | s->pb_field_time = 2; | 3297 | h->c.pb_field_time = 2; |
| 3292 | s->pp_field_time = 4; | 3298 | h->c.pp_field_time = 4; |
| 3293 | if (!s->progressive_sequence) | 3299 | if (!h->c.progressive_sequence) |
| 3294 | return FRAME_SKIPPED; | 3300 | return FRAME_SKIPPED; |
| 3295 | } | 3301 | } |
| 3296 | } | 3302 | } |
| 3297 | 3303 | ||
| 3298 | if (s->avctx->framerate.den) | 3304 | if (h->c.avctx->framerate.den) |
| 3299 | pts = ROUNDED_DIV(s->time, s->avctx->framerate.den); | 3305 | pts = ROUNDED_DIV(h->c.time, h->c.avctx->framerate.den); |
| 3300 | else | 3306 | else |
| 3301 | pts = AV_NOPTS_VALUE; | 3307 | pts = AV_NOPTS_VALUE; |
| 3302 | ff_dlog(s->avctx, "MPEG4 PTS: %"PRId64"\n", pts); | 3308 | ff_dlog(h->c.avctx, "MPEG4 PTS: %"PRId64"\n", pts); |
| 3303 | 3309 | ||
| 3304 | check_marker(s->avctx, gb, "before vop_coded"); | 3310 | check_marker(h->c.avctx, gb, "before vop_coded"); |
| 3305 | 3311 | ||
| 3306 | /* vop coded */ | 3312 | /* vop coded */ |
| 3307 | if (get_bits1(gb) != 1) { | 3313 | if (get_bits1(gb) != 1) { |
| 3308 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) | 3314 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) |
| 3309 | av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n"); | 3315 | av_log(h->c.avctx, AV_LOG_ERROR, "vop not coded\n"); |
| 3310 | s->skipped_last_frame = 1; | 3316 | h->c.skipped_last_frame = 1; |
| 3311 | return FRAME_SKIPPED; | 3317 | return FRAME_SKIPPED; |
| 3312 | } | 3318 | } |
| 3313 | if (ctx->new_pred) | 3319 | if (ctx->new_pred) |
| 3314 | decode_new_pred(ctx, gb); | 3320 | decode_new_pred(ctx, gb); |
| 3315 | 3321 | ||
| 3316 | if (ctx->shape != BIN_ONLY_SHAPE && | 3322 | if (ctx->shape != BIN_ONLY_SHAPE && |
| 3317 | (s->pict_type == AV_PICTURE_TYPE_P || | 3323 | (h->c.pict_type == AV_PICTURE_TYPE_P || |
| 3318 | (s->pict_type == AV_PICTURE_TYPE_S && | 3324 | (h->c.pict_type == AV_PICTURE_TYPE_S && |
| 3319 | ctx->vol_sprite_usage == GMC_SPRITE))) { | 3325 | ctx->vol_sprite_usage == GMC_SPRITE))) { |
| 3320 | /* rounding type for motion estimation */ | 3326 | /* rounding type for motion estimation */ |
| 3321 | s->no_rounding = get_bits1(gb); | 3327 | h->c.no_rounding = get_bits1(gb); |
| 3322 | } else { | 3328 | } else { |
| 3323 | s->no_rounding = 0; | 3329 | h->c.no_rounding = 0; |
| 3324 | } | 3330 | } |
| 3325 | // FIXME reduced res stuff | 3331 | // FIXME reduced res stuff |
| 3326 | 3332 | ||
| 3327 | if (ctx->shape != RECT_SHAPE) { | 3333 | if (ctx->shape != RECT_SHAPE) { |
| 3328 | if (ctx->vol_sprite_usage != 1 || s->pict_type != AV_PICTURE_TYPE_I) { | 3334 | if (ctx->vol_sprite_usage != 1 || h->c.pict_type != AV_PICTURE_TYPE_I) { |
| 3329 | skip_bits(gb, 13); /* width */ | 3335 | skip_bits(gb, 13); /* width */ |
| 3330 | check_marker(s->avctx, gb, "after width"); | 3336 | check_marker(h->c.avctx, gb, "after width"); |
| 3331 | skip_bits(gb, 13); /* height */ | 3337 | skip_bits(gb, 13); /* height */ |
| 3332 | check_marker(s->avctx, gb, "after height"); | 3338 | check_marker(h->c.avctx, gb, "after height"); |
| 3333 | skip_bits(gb, 13); /* hor_spat_ref */ | 3339 | skip_bits(gb, 13); /* hor_spat_ref */ |
| 3334 | check_marker(s->avctx, gb, "after hor_spat_ref"); | 3340 | check_marker(h->c.avctx, gb, "after hor_spat_ref"); |
| 3335 | skip_bits(gb, 13); /* ver_spat_ref */ | 3341 | skip_bits(gb, 13); /* ver_spat_ref */ |
| 3336 | } | 3342 | } |
| 3337 | skip_bits1(gb); /* change_CR_disable */ | 3343 | skip_bits1(gb); /* change_CR_disable */ |
| @@ -3344,21 +3350,21 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 6 unmodified lines | |||
| 3344 | 3350 | ||
| 3345 | if (ctx->shape != BIN_ONLY_SHAPE) { | 3351 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 3346 | skip_bits_long(gb, ctx->cplx_estimation_trash_i); | 3352 | skip_bits_long(gb, ctx->cplx_estimation_trash_i); |
| 3347 | if (s->pict_type != AV_PICTURE_TYPE_I) | 3353 | if (h->c.pict_type != AV_PICTURE_TYPE_I) |
| 3348 | skip_bits_long(gb, ctx->cplx_estimation_trash_p); | 3354 | skip_bits_long(gb, ctx->cplx_estimation_trash_p); |
| 3349 | if (s->pict_type == AV_PICTURE_TYPE_B) | 3355 | if (h->c.pict_type == AV_PICTURE_TYPE_B) |
| 3350 | skip_bits_long(gb, ctx->cplx_estimation_trash_b); | 3356 | skip_bits_long(gb, ctx->cplx_estimation_trash_b); |
| 3351 | 3357 | ||
| 3352 | if (get_bits_left(gb) < 3) { | 3358 | if (get_bits_left(gb) < 3) { |
| 3353 | av_log(s->avctx, AV_LOG_ERROR, "Header truncated\n"); | 3359 | av_log(h->c.avctx, AV_LOG_ERROR, "Header truncated\n"); |
| 3354 | return AVERROR_INVALIDDATA; | 3360 | return AVERROR_INVALIDDATA; |
| 3355 | } | 3361 | } |
| 3356 | ctx->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)]; | 3362 | ctx->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)]; |
| 3357 | if (!s->progressive_sequence) { | 3363 | if (!h->c.progressive_sequence) { |
| 3358 | s->top_field_first = get_bits1(gb); | 3364 | h->c.top_field_first = get_bits1(gb); |
| 3359 | s->alternate_scan = get_bits1(gb); | 3365 | h->c.alternate_scan = get_bits1(gb); |
| 3360 | } else | 3366 | } else |
| 3361 | s->alternate_scan = 0; | 3367 | h->c.alternate_scan = 0; |
| 3362 | } | 3368 | } |
| 3363 | /* Skip at this point when only parsing since the remaining | 3369 | /* Skip at this point when only parsing since the remaining |
| 3364 | * data is not useful for a parser and requires the | 3370 | * data is not useful for a parser and requires the |
| @@ -3366,28 +3372,28 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 1 unmodified line | |||
| 3366 | if (parse_only) | 3372 | if (parse_only) |
| 3367 | goto end; | 3373 | goto end; |
| 3368 | 3374 | ||
| 3369 | if (s->alternate_scan) { | 3375 | if (h->c.alternate_scan) { |
| 3370 | ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan); | 3376 | ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_alternate_vertical_scan); |
| 3371 | ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_vertical_scan, | 3377 | ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_vertical_scan, |
| 3372 | s->idsp.idct_permutation); | 3378 | h->c.idsp.idct_permutation); |
| 3373 | } else { | 3379 | } else { |
| 3374 | ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct); | 3380 | ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_zigzag_direct); |
| 3375 | ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_horizontal_scan, | 3381 | ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_horizontal_scan, |
| 3376 | s->idsp.idct_permutation); | 3382 | h->c.idsp.idct_permutation); |
| 3377 | } | 3383 | } |
| 3378 | ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan, | 3384 | ff_permute_scantable(h->c.permutated_intra_v_scantable, ff_alternate_vertical_scan, |
| 3379 | s->idsp.idct_permutation); | 3385 | h->c.idsp.idct_permutation); |
| 3380 | 3386 | ||
| 3381 | if (s->pict_type == AV_PICTURE_TYPE_S) { | 3387 | if (h->c.pict_type == AV_PICTURE_TYPE_S) { |
| 3382 | if((ctx->vol_sprite_usage == STATIC_SPRITE || | 3388 | if((ctx->vol_sprite_usage == STATIC_SPRITE || |
| 3383 | ctx->vol_sprite_usage == GMC_SPRITE)) { | 3389 | ctx->vol_sprite_usage == GMC_SPRITE)) { |
| 3384 | if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0) | 3390 | if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0) |
| 3385 | return AVERROR_INVALIDDATA; | 3391 | return AVERROR_INVALIDDATA; |
| 3386 | if (ctx->sprite_brightness_change) | 3392 | if (ctx->sprite_brightness_change) |
| 3387 | av_log(s->avctx, AV_LOG_ERROR, | 3393 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 3388 | "sprite_brightness_change not supported\n"); | 3394 | "sprite_brightness_change not supported\n"); |
| 3389 | if (ctx->vol_sprite_usage == STATIC_SPRITE) | 3395 | if (ctx->vol_sprite_usage == STATIC_SPRITE) |
| 3390 | av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n"); | 3396 | av_log(h->c.avctx, AV_LOG_ERROR, "static sprite not supported\n"); |
| 3391 | } else { | 3397 | } else { |
| 3392 | memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset)); | 3398 | memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset)); |
| 3393 | memset(ctx->sprite_delta, 0, sizeof(ctx->sprite_delta)); | 3399 | memset(ctx->sprite_delta, 0, sizeof(ctx->sprite_delta)); |
| @@ -3397,102 +3403,102 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 3 unmodified lines | |||
| 3397 | ctx->f_code = 1; | 3403 | ctx->f_code = 1; |
| 3398 | ctx->b_code = 1; | 3404 | ctx->b_code = 1; |
| 3399 | if (ctx->shape != BIN_ONLY_SHAPE) { | 3405 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 3400 | s->chroma_qscale = s->qscale = get_bits(gb, ctx->quant_precision); | 3406 | h->c.chroma_qscale = h->c.qscale = get_bits(gb, ctx->quant_precision); |
| 3401 | if (s->qscale == 0) { | 3407 | if (h->c.qscale == 0) { |
| 3402 | av_log(s->avctx, AV_LOG_ERROR, | 3408 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 3403 | "Error, header damaged or not MPEG-4 header (qscale=0)\n"); | 3409 | "Error, header damaged or not MPEG-4 header (qscale=0)\n"); |
| 3404 | return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then | 3410 | return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then |
| 3405 | } | 3411 | } |
| 3406 | 3412 | ||
| 3407 | if (s->pict_type != AV_PICTURE_TYPE_I) { | 3413 | if (h->c.pict_type != AV_PICTURE_TYPE_I) { |
| 3408 | ctx->f_code = get_bits(gb, 3); /* fcode_for */ | 3414 | ctx->f_code = get_bits(gb, 3); /* fcode_for */ |
| 3409 | if (ctx->f_code == 0) { | 3415 | if (ctx->f_code == 0) { |
| 3410 | av_log(s->avctx, AV_LOG_ERROR, | 3416 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 3411 | "Error, header damaged or not MPEG-4 header (f_code=0)\n"); | 3417 | "Error, header damaged or not MPEG-4 header (f_code=0)\n"); |
| 3412 | ctx->f_code = 1; | 3418 | ctx->f_code = 1; |
| 3413 | return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then | 3419 | return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then |
| 3414 | } | 3420 | } |
| 3415 | } | 3421 | } |
| 3416 | 3422 | ||
| 3417 | if (s->pict_type == AV_PICTURE_TYPE_B) { | 3423 | if (h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 3418 | ctx->b_code = get_bits(gb, 3); | 3424 | ctx->b_code = get_bits(gb, 3); |
| 3419 | if (ctx->b_code == 0) { | 3425 | if (ctx->b_code == 0) { |
| 3420 | av_log(s->avctx, AV_LOG_ERROR, | 3426 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 3421 | "Error, header damaged or not MPEG4 header (b_code=0)\n"); | 3427 | "Error, header damaged or not MPEG4 header (b_code=0)\n"); |
| 3422 | ctx->b_code=1; | 3428 | ctx->b_code=1; |
| 3423 | return AVERROR_INVALIDDATA; // makes no sense to continue, as the MV decoding will break very quickly | 3429 | return AVERROR_INVALIDDATA; // makes no sense to continue, as the MV decoding will break very quickly |
| 3424 | } | 3430 | } |
| 3425 | } | 3431 | } |
| 3426 | 3432 | ||
| 3427 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | 3433 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { |
| 3428 | av_log(s->avctx, AV_LOG_DEBUG, | 3434 | av_log(h->c.avctx, AV_LOG_DEBUG, |
| 3429 | "qp:%d fc:%d,%d %c size:%d pro:%d alt:%d top:%d %cpel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64" tincr:%d\n", | 3435 | "qp:%d fc:%d,%d %c size:%d pro:%d alt:%d top:%d %cpel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64" tincr:%d\n", |
| 3430 | s->qscale, ctx->f_code, ctx->b_code, | 3436 | h->c.qscale, ctx->f_code, ctx->b_code, |
| 3431 | s->pict_type == AV_PICTURE_TYPE_I ? 'I' : (s->pict_type == AV_PICTURE_TYPE_P ? 'P' : (s->pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')), | 3437 | h->c.pict_type == AV_PICTURE_TYPE_I ? 'I' : (h->c.pict_type == AV_PICTURE_TYPE_P ? 'P' : (h->c.pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')), |
| 3432 | gb->size_in_bits,s->progressive_sequence, s->alternate_scan, | 3438 | gb->size_in_bits,h->c.progressive_sequence, h->c.alternate_scan, |
| 3433 | s->top_field_first, s->quarter_sample ? 'q' : 'h', | 3439 | h->c.top_field_first, h->c.quarter_sample ? 'q' : 'h', |
| 3434 | s->data_partitioning, ctx->resync_marker, | 3440 | h->c.data_partitioning, ctx->resync_marker, |
| 3435 | ctx->num_sprite_warping_points, ctx->sprite_warping_accuracy, | 3441 | ctx->num_sprite_warping_points, ctx->sprite_warping_accuracy, |
| 3436 | 1 - s->no_rounding, ctx->vo_type, | 3442 | 1 - h->c.no_rounding, ctx->vo_type, |
| 3437 | ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold, | 3443 | ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold, |
| 3438 | ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p, | 3444 | ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p, |
| 3439 | ctx->cplx_estimation_trash_b, | 3445 | ctx->cplx_estimation_trash_b, |
| 3440 | s->time, | 3446 | h->c.time, |
| 3441 | time_increment | 3447 | time_increment |
| 3442 | ); | 3448 | ); |
| 3443 | } | 3449 | } |
| 3444 | 3450 | ||
| 3445 | if (!ctx->scalability) { | 3451 | if (!ctx->scalability) { |
| 3446 | if (ctx->shape != RECT_SHAPE && s->pict_type != AV_PICTURE_TYPE_I) | 3452 | if (ctx->shape != RECT_SHAPE && h->c.pict_type != AV_PICTURE_TYPE_I) |
| 3447 | skip_bits1(gb); // vop shape coding type | 3453 | skip_bits1(gb); // vop shape coding type |
| 3448 | } else { | 3454 | } else { |
| 3449 | if (ctx->enhancement_type) { | 3455 | if (ctx->enhancement_type) { |
| 3450 | int load_backward_shape = get_bits1(gb); | 3456 | int load_backward_shape = get_bits1(gb); |
| 3451 | if (load_backward_shape) | 3457 | if (load_backward_shape) |
| 3452 | av_log(s->avctx, AV_LOG_ERROR, | 3458 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 3453 | "load backward shape isn't supported\n"); | 3459 | "load backward shape isn't supported\n"); |
| 3454 | } | 3460 | } |
| 3455 | skip_bits(gb, 2); // ref_select_code | 3461 | skip_bits(gb, 2); // ref_select_code |
| 3456 | } | 3462 | } |
| 3457 | } | 3463 | } |
| 3458 | 3464 | ||
| 3459 | s->dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra | 3465 | h->c.dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra |
| 3460 | : ctx->dct_unquantize_h263_intra; | 3466 | : ctx->dct_unquantize_h263_intra; |
| 3461 | // The following tells ff_mpv_reconstruct_mb() to unquantize iff mpeg_quant | 3467 | // The following tells ff_mpv_reconstruct_mb() to unquantize iff mpeg_quant |
| 3462 | s->dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL; | 3468 | h->c.dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL; |
| 3463 | 3469 | ||
| 3464 | end: | 3470 | end: |
| 3465 | /* detect buggy encoders which don't set the low_delay flag | 3471 | /* detect buggy encoders which don't set the low_delay flag |
| 3466 | * (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames | 3472 | * (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames |
| 3467 | * easily (although it's buggy too) */ | 3473 | * easily (although it's buggy too) */ |
| 3468 | if (ctx->vo_type == 0 && ctx->vol_control_parameters == 0 && | 3474 | if (ctx->vo_type == 0 && ctx->vol_control_parameters == 0 && |
| 3469 | ctx->divx_version == -1 && s->picture_number == 0) { | 3475 | ctx->divx_version == -1 && h->c.picture_number == 0) { |
| 3470 | av_log(s->avctx, AV_LOG_WARNING, | 3476 | av_log(h->c.avctx, AV_LOG_WARNING, |
| 3471 | "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); | 3477 | "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); |
| 3472 | s->low_delay = 1; | 3478 | h->c.low_delay = 1; |
| 3473 | } | 3479 | } |
| 3474 | 3480 | ||
| 3475 | s->picture_number++; // better than pic number==0 always ;) | 3481 | h->c.picture_number++; // better than pic number==0 always ;) |
| 3476 | 3482 | ||
| 3477 | if (s->workaround_bugs & FF_BUG_EDGE) { | 3483 | if (h->c.workaround_bugs & FF_BUG_EDGE) { |
| 3478 | s->h_edge_pos = s->width; | 3484 | h->c.h_edge_pos = h->c.width; |
| 3479 | s->v_edge_pos = s->height; | 3485 | h->c.v_edge_pos = h->c.height; |
| 3480 | } | 3486 | } |
| 3481 | return 0; | 3487 | return 0; |
| 3482 | } | 3488 | } |
| 3483 | 3489 | ||
| 3484 | static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb) | 3490 | static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 3485 | { | 3491 | { |
| 3486 | MpegEncContext *s = &ctx->m; | 3492 | AVCodecContext *const avctx = ctx->h.c.avctx; |
| 3487 | 3493 | ||
| 3488 | skip_bits(gb, 16); /* Time_code[63..48] */ | 3494 | skip_bits(gb, 16); /* Time_code[63..48] */ |
| 3489 | check_marker(s->avctx, gb, "after Time_code[63..48]"); | 3495 | check_marker(avctx, gb, "after Time_code[63..48]"); |
| 3490 | skip_bits(gb, 16); /* Time_code[47..32] */ | 3496 | skip_bits(gb, 16); /* Time_code[47..32] */ |
| 3491 | check_marker(s->avctx, gb, "after Time_code[47..32]"); | 3497 | check_marker(avctx, gb, "after Time_code[47..32]"); |
| 3492 | skip_bits(gb, 16); /* Time_code[31..16] */ | 3498 | skip_bits(gb, 16); /* Time_code[31..16] */ |
| 3493 | check_marker(s->avctx, gb, "after Time_code[31..16]"); | 3499 | check_marker(avctx, gb, "after Time_code[31..16]"); |
| 3494 | skip_bits(gb, 16); /* Time_code[15..0] */ | 3500 | skip_bits(gb, 16); /* Time_code[15..0] */ |
| 3495 | check_marker(s->avctx, gb, "after Time_code[15..0]"); | 3501 | check_marker(avctx, gb, "after Time_code[15..0]"); |
| 3496 | skip_bits(gb, 4); /* reserved_bits */ | 3502 | skip_bits(gb, 4); /* reserved_bits */ |
| 3497 | } | 3503 | } |
| 3498 | 3504 | ||
| @@ -3502,64 +3508,63 @@ static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb) · 3 unmodified lines | |||
| 3502 | */ | 3508 | */ |
| 3503 | static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb) | 3509 | static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 3504 | { | 3510 | { |
| 3505 | MpegEncContext *s = &ctx->m; | 3511 | H263DecContext *const h = &ctx->h; |
| 3506 | 3512 | ||
| 3507 | if (get_bits_left(gb) <= 32) | 3513 | if (get_bits_left(gb) <= 32) |
| 3508 | return 0; | 3514 | return 0; |
| 3509 | 3515 | ||
| 3510 | s->partitioned_frame = 0; | 3516 | h->c.partitioned_frame = 0; |
| 3511 | s->interlaced_dct = 0; | 3517 | h->c.interlaced_dct = 0; |
| 3512 | s->decode_mb = mpeg4_decode_studio_mb; | 3518 | h->decode_mb = mpeg4_decode_studio_mb; |
| 3513 | 3519 | ||
| 3514 | decode_smpte_tc(ctx, gb); | 3520 | decode_smpte_tc(ctx, gb); |
| 3515 | 3521 | ||
| 3516 | skip_bits(gb, 10); /* temporal_reference */ | 3522 | skip_bits(gb, 10); /* temporal_reference */ |
| 3517 | skip_bits(gb, 2); /* vop_structure */ | 3523 | skip_bits(gb, 2); /* vop_structure */ |
| 3518 | s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */ | 3524 | h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */ |
| 3519 | if (get_bits1(gb)) { /* vop_coded */ | 3525 | if (get_bits1(gb)) { /* vop_coded */ |
| 3520 | skip_bits1(gb); /* top_field_first */ | 3526 | skip_bits1(gb); /* top_field_first */ |
| 3521 | skip_bits1(gb); /* repeat_first_field */ | 3527 | skip_bits1(gb); /* repeat_first_field */ |
| 3522 | s->progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */ | 3528 | h->c.progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */ |
| 3523 | } | 3529 | } |
| 3524 | 3530 | ||
| 3525 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 3531 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 3526 | if (get_bits1(gb)) | 3532 | if (get_bits1(gb)) |
| 3527 | reset_studio_dc_predictors(ctx); | 3533 | reset_studio_dc_predictors(ctx); |
| 3528 | } | 3534 | } |
| 3529 | 3535 | ||
| 3530 | if (ctx->shape != BIN_ONLY_SHAPE) { | 3536 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 3531 | s->alternate_scan = get_bits1(gb); | 3537 | h->c.alternate_scan = get_bits1(gb); |
| 3532 | s->frame_pred_frame_dct = get_bits1(gb); | 3538 | h->c.frame_pred_frame_dct = get_bits1(gb); |
| 3533 | ctx->dct_precision = get_bits(gb, 2); | 3539 | ctx->dct_precision = get_bits(gb, 2); |
| 3534 | s->intra_dc_precision = get_bits(gb, 2); | 3540 | h->c.intra_dc_precision = get_bits(gb, 2); |
| 3535 | s->q_scale_type = get_bits1(gb); | 3541 | h->c.q_scale_type = get_bits1(gb); |
| 3536 | } | 3542 | } |
| 3537 | 3543 | ||
| 3538 | ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, | 3544 | ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, |
| 3539 | s->alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct); | 3545 | h->c.alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct); |
| 3540 | 3546 | ||
| 3541 | mpeg4_load_default_matrices(s); | 3547 | mpeg4_load_default_matrices(&h->c); |
| 3542 | 3548 | ||
| 3543 | next_start_code_studio(gb); | 3549 | next_start_code_studio(gb); |
| 3544 | extension_and_user_data(s, gb, 4); | 3550 | extension_and_user_data(&h->c, gb, 4); |
| 3545 | 3551 | ||
| 3546 | return 0; | 3552 | return 0; |
| 3547 | } | 3553 | } |
| 3548 | 3554 | ||
| 3549 | static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb) | 3555 | static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 3550 | { | 3556 | { |
| 3551 | MpegEncContext *s = &ctx->m; | ||
| 3552 | int visual_object_type; | 3557 | int visual_object_type; |
| 3553 | 3558 | ||
| 3554 | skip_bits(gb, 4); /* visual_object_verid */ | 3559 | skip_bits(gb, 4); /* visual_object_verid */ |
| 3555 | visual_object_type = get_bits(gb, 4); | 3560 | visual_object_type = get_bits(gb, 4); |
| 3556 | if (visual_object_type != VOT_VIDEO_ID) { | 3561 | if (visual_object_type != VOT_VIDEO_ID) { |
| 3557 | avpriv_request_sample(s->avctx, "VO type %u", visual_object_type); | 3562 | avpriv_request_sample(ctx->h.c.avctx, "VO type %u", visual_object_type); |
| 3558 | return AVERROR_PATCHWELCOME; | 3563 | return AVERROR_PATCHWELCOME; |
| 3559 | } | 3564 | } |
| 3560 | 3565 | ||
| 3561 | next_start_code_studio(gb); | 3566 | next_start_code_studio(gb); |
| 3562 | extension_and_user_data(s, gb, 1); | 3567 | extension_and_user_data(&ctx->h.c, gb, 1); |
| 3563 | 3568 | ||
| 3564 | return 0; | 3569 | return 0; |
| 3565 | } | 3570 | } |
| @@ -3577,7 +3582,7 @@ static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb) · 11 unmodified lines | |||
| 3577 | int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, | 3582 | int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, |
| 3578 | int header, int parse_only) | 3583 | int header, int parse_only) |
| 3579 | { | 3584 | { |
| 3580 | MpegEncContext *s = &ctx->m; | 3585 | MPVContext *const s = &ctx->h.c; |
| 3581 | unsigned startcode, v; | 3586 | unsigned startcode, v; |
| 3582 | int ret; | 3587 | int ret; |
| 3583 | int vol = 0; | 3588 | int vol = 0; |
| @@ -3731,22 +3736,22 @@ end: · 147 unmodified lines | |||
| 3731 | return decode_vop_header(ctx, gb, parse_only); | 3736 | return decode_vop_header(ctx, gb, parse_only); |
| 3732 | } | 3737 | } |
| 3733 | 3738 | ||
| 3734 | int ff_mpeg4_decode_picture_header(MpegEncContext *s) | 3739 | int ff_mpeg4_decode_picture_header(H263DecContext *const h) |
| 3735 | { | 3740 | { |
| 3736 | Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; | 3741 | Mpeg4DecContext *const ctx = h263_to_mpeg4(h); |
| 3737 | 3742 | ||
| 3738 | s->skipped_last_frame = 0; | 3743 | h->c.skipped_last_frame = 0; |
| 3739 | 3744 | ||
| 3740 | if (ctx->bitstream_buffer) { | 3745 | if (ctx->bitstream_buffer) { |
| 3741 | int buf_size = get_bits_left(&s->gb) / 8U; | 3746 | int buf_size = get_bits_left(&h->c.gb) / 8U; |
| 3742 | int bitstream_buffer_size = ctx->bitstream_buffer->size; | 3747 | int bitstream_buffer_size = ctx->bitstream_buffer->size; |
| 3743 | const uint8_t *buf = s->gb.buffer; | 3748 | const uint8_t *buf = h->c.gb.buffer; |
| 3744 | 3749 | ||
| 3745 | if (s->divx_packed) { | 3750 | if (h->c.divx_packed) { |
| 3746 | for (int i = 0; i < buf_size - 3; i++) { | 3751 | for (int i = 0; i < buf_size - 3; i++) { |
| 3747 | if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) { | 3752 | if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) { |
| 3748 | if (buf[i+3] == 0xB0) { | 3753 | if (buf[i+3] == 0xB0) { |
| 3749 | av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n"); | 3754 | av_log(h->c.avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n"); |
| 3750 | bitstream_buffer_size = 0; | 3755 | bitstream_buffer_size = 0; |
| 3751 | } | 3756 | } |
| 3752 | break; | 3757 | break; |
| @@ -3754,8 +3759,8 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s) · 1 unmodified line | |||
| 3754 | } | 3759 | } |
| 3755 | } | 3760 | } |
| 3756 | ctx->bitstream_buffer->size = 0; | 3761 | ctx->bitstream_buffer->size = 0; |
| 3757 | if (bitstream_buffer_size && (s->divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder | 3762 | if (bitstream_buffer_size && (h->c.divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder |
| 3758 | int ret = init_get_bits8(&s->gb, ctx->bitstream_buffer->data, | 3763 | int ret = init_get_bits8(&h->c.gb, ctx->bitstream_buffer->data, |
| 3759 | bitstream_buffer_size); | 3764 | bitstream_buffer_size); |
| 3760 | if (ret < 0) | 3765 | if (ret < 0) |
| 3761 | return ret; | 3766 | return ret; |
| @@ -3763,20 +3768,20 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s) · 1 unmodified line | |||
| 3763 | av_buffer_unref(&ctx->bitstream_buffer); | 3768 | av_buffer_unref(&ctx->bitstream_buffer); |
| 3764 | } | 3769 | } |
| 3765 | 3770 | ||
| 3766 | return ff_mpeg4_parse_picture_header(ctx, &s->gb, 0, 0); | 3771 | return ff_mpeg4_parse_picture_header(ctx, &h->c.gb, 0, 0); |
| 3767 | } | 3772 | } |
| 3768 | 3773 | ||
| 3769 | int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt) | 3774 | int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt) |
| 3770 | { | 3775 | { |
| 3771 | Mpeg4DecContext *ctx = avctx->priv_data; | 3776 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 3772 | MpegEncContext *s = &ctx->m; | 3777 | H263DecContext *const h = &ctx->h; |
| 3773 | int ret; | 3778 | int ret; |
| 3774 | 3779 | ||
| 3775 | av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size); | 3780 | av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size); |
| 3776 | 3781 | ||
| 3777 | /* divx 5.01+ bitstream reorder stuff */ | 3782 | /* divx 5.01+ bitstream reorder stuff */ |
| 3778 | if (s->divx_packed) { | 3783 | if (h->c.divx_packed) { |
| 3779 | int current_pos = ctx->bitstream_buffer && s->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&s->gb) >> 3); | 3784 | int current_pos = ctx->bitstream_buffer && h->c.gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->c.gb) >> 3); |
| 3780 | int startcode_found = 0; | 3785 | int startcode_found = 0; |
| 3781 | uint8_t *buf = pkt->data; | 3786 | uint8_t *buf = pkt->data; |
| 3782 | int buf_size = pkt->size; | 3787 | int buf_size = pkt->size; |
| @@ -3797,7 +3802,7 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt) · 14 unmodified lines | |||
| 3797 | 3802 | ||
| 3798 | if (startcode_found) { | 3803 | if (startcode_found) { |
| 3799 | if (!ctx->showed_packed_warning) { | 3804 | if (!ctx->showed_packed_warning) { |
| 3800 | av_log(s->avctx, AV_LOG_INFO, "Video uses a non-standard and " | 3805 | av_log(h->c.avctx, AV_LOG_INFO, "Video uses a non-standard and " |
| 3801 | "wasteful way to store B-frames ('packed B-frames'). " | 3806 | "wasteful way to store B-frames ('packed B-frames'). " |
| 3802 | "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n"); | 3807 | "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n"); |
| 3803 | ctx->showed_packed_warning = 1; | 3808 | ctx->showed_packed_warning = 1; |
| @@ -3874,11 +3879,11 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 70 unmodified lines | |||
| 3874 | { | 3879 | { |
| 3875 | Mpeg4DecContext *s = dst->priv_data; | 3880 | Mpeg4DecContext *s = dst->priv_data; |
| 3876 | const Mpeg4DecContext *s1 = src->priv_data; | 3881 | const Mpeg4DecContext *s1 = src->priv_data; |
| 3877 | int init = s->m.context_initialized; | 3882 | int init = s->h.c.context_initialized; |
| 3878 | int ret; | 3883 | int ret; |
| 3879 | 3884 | ||
| 3880 | if (!init) { | 3885 | if (!init) { |
| 3881 | ret = update_mpvctx(&s->m, &s1->m); | 3886 | ret = update_mpvctx(&s->h.c, &s1->h.c); |
| 3882 | if (ret < 0) | 3887 | if (ret < 0) |
| 3883 | return ret; | 3888 | return ret; |
| 3884 | } | 3889 | } |
| @@ -3894,7 +3899,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 9 unmodified lines | |||
| 3894 | s->sprite_brightness_change = s1->sprite_brightness_change; | 3899 | s->sprite_brightness_change = s1->sprite_brightness_change; |
| 3895 | s->sprite_warping_accuracy = s1->sprite_warping_accuracy; | 3900 | s->sprite_warping_accuracy = s1->sprite_warping_accuracy; |
| 3896 | s->num_sprite_warping_points = s1->num_sprite_warping_points; | 3901 | s->num_sprite_warping_points = s1->num_sprite_warping_points; |
| 3897 | s->m.data_partitioning = s1->m.data_partitioning; | 3902 | s->h.c.data_partitioning = s1->h.c.data_partitioning; |
| 3898 | s->mpeg_quant = s1->mpeg_quant; | 3903 | s->mpeg_quant = s1->mpeg_quant; |
| 3899 | s->rvlc = s1->rvlc; | 3904 | s->rvlc = s1->rvlc; |
| 3900 | s->resync_marker = s1->resync_marker; | 3905 | s->resync_marker = s1->resync_marker; |
| @@ -3903,7 +3908,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 2 unmodified lines | |||
| 3903 | s->enhancement_type = s1->enhancement_type; | 3908 | s->enhancement_type = s1->enhancement_type; |
| 3904 | s->scalability = s1->scalability; | 3909 | s->scalability = s1->scalability; |
| 3905 | s->intra_dc_threshold = s1->intra_dc_threshold; | 3910 | s->intra_dc_threshold = s1->intra_dc_threshold; |
| 3906 | s->m.divx_packed = s1->m.divx_packed; | 3911 | s->h.c.divx_packed = s1->h.c.divx_packed; |
| 3907 | s->divx_version = s1->divx_version; | 3912 | s->divx_version = s1->divx_version; |
| 3908 | s->divx_build = s1->divx_build; | 3913 | s->divx_build = s1->divx_build; |
| 3909 | s->xvid_build = s1->xvid_build; | 3914 | s->xvid_build = s1->xvid_build; |
| @@ -3915,7 +3920,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 5 unmodified lines | |||
| 3915 | s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p; | 3920 | s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p; |
| 3916 | s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b; | 3921 | s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b; |
| 3917 | s->rgb = s1->rgb; | 3922 | s->rgb = s1->rgb; |
| 3918 | s->m.skipped_last_frame = s1->m.skipped_last_frame; | 3923 | s->h.c.skipped_last_frame = s1->h.c.skipped_last_frame; |
| 3919 | 3924 | ||
| 3920 | memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift)); | 3925 | memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift)); |
| 3921 | memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj)); | 3926 | memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj)); |
| @@ -3985,7 +3990,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 63 unmodified lines | |||
| 3985 | { | 3990 | { |
| 3986 | static AVOnce init_static_once = AV_ONCE_INIT; | 3991 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 3987 | Mpeg4DecContext *ctx = avctx->priv_data; | 3992 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 3988 | MpegEncContext *s = &ctx->m; | 3993 | H263DecContext *const h = &ctx->h; |
| 3989 | MPVUnquantDSPContext unquant_dsp_ctx; | 3994 | MPVUnquantDSPContext unquant_dsp_ctx; |
| 3990 | int ret; | 3995 | int ret; |
| 3991 | 3996 | ||
| @@ -4006,18 +4011,18 @@ static av_cold int decode_init(AVCodecContext *avctx) · 14 unmodified lines | |||
| 4006 | // so that is all we keep. | 4011 | // so that is all we keep. |
| 4007 | ctx->dct_unquantize_mpeg2_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter; | 4012 | ctx->dct_unquantize_mpeg2_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter; |
| 4008 | 4013 | ||
| 4009 | s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table; | 4014 | h->c.y_dc_scale_table = ff_mpeg4_y_dc_scale_table; |
| 4010 | s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table; | 4015 | h->c.c_dc_scale_table = ff_mpeg4_c_dc_scale_table; |
| 4011 | 4016 | ||
| 4012 | s->h263_pred = 1; | 4017 | h->c.h263_pred = 1; |
| 4013 | s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */ | 4018 | h->c.low_delay = 0; /* default, might be overridden in the vol header during header parsing */ |
| 4014 | s->decode_mb = mpeg4_decode_mb; | 4019 | h->decode_mb = mpeg4_decode_mb; |
| 4015 | ctx->time_increment_bits = 4; /* default value for broken headers */ | 4020 | ctx->time_increment_bits = 4; /* default value for broken headers */ |
| 4016 | ctx->quant_precision = 5; | 4021 | ctx->quant_precision = 5; |
| 4017 | 4022 | ||
| 4018 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; | 4023 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; |
| 4019 | 4024 | ||
| 4020 | ff_qpeldsp_init(&s->qdsp); | 4025 | ff_qpeldsp_init(&h->c.qdsp); |
| 4021 | ff_mpeg4videodsp_init(&ctx->mdsp); | 4026 | ff_mpeg4videodsp_init(&ctx->mdsp); |
| 4022 | 4027 | ||
| 4023 | ff_thread_once(&init_static_once, mpeg4_init_static); | 4028 | ff_thread_once(&init_static_once, mpeg4_init_static); |
| @@ -26,13 +26,14 @@ · 25 unmodified lines | |||
| 26 | #include <stdint.h> | 26 | #include <stdint.h> |
| 27 | 27 | ||
| 28 | #include "get_bits.h" | 28 | #include "get_bits.h" |
| 29 | #include "h263dec.h" | ||
| 29 | #include "mpegvideo.h" | 30 | #include "mpegvideo.h" |
| 30 | #include "mpeg4videodsp.h" | 31 | #include "mpeg4videodsp.h" |
| 31 | 32 | ||
| 32 | #include "libavutil/mem_internal.h" | 33 | #include "libavutil/mem_internal.h" |
| 33 | 34 | ||
| 34 | typedef struct Mpeg4DecContext { | 35 | typedef struct Mpeg4DecContext { |
| 35 | MpegEncContext m; | 36 | H263DecContext h; |
| 36 | 37 | ||
| 37 | int f_code; ///< forward MV resolution | 38 | int f_code; ///< forward MV resolution |
| 38 | int b_code; ///< backward MV resolution for B-frames | 39 | int b_code; ///< backward MV resolution for B-frames |
| @@ -108,7 +109,7 @@ typedef struct Mpeg4DecContext { · 69 unmodified lines | |||
| 108 | int dct_precision; | 109 | int dct_precision; |
| 109 | } Mpeg4DecContext; | 110 | } Mpeg4DecContext; |
| 110 | 111 | ||
| 111 | int ff_mpeg4_decode_picture_header(MpegEncContext *s); | 112 | int ff_mpeg4_decode_picture_header(H263DecContext *const h); |
| 112 | int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, | 113 | int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, |
| 113 | int header, int parse_only); | 114 | int header, int parse_only); |
| 114 | void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, | 115 | void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, |
| @@ -117,11 +118,11 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb · 2 unmodified lines | |||
| 117 | void ff_mpeg4_mcsel_motion(MpegEncContext *s, | 118 | void ff_mpeg4_mcsel_motion(MpegEncContext *s, |
| 118 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | 119 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
| 119 | uint8_t *const *ref_picture); | 120 | uint8_t *const *ref_picture); |
| 120 | int ff_mpeg4_decode_partitions(MPVContext *const s); | 121 | int ff_mpeg4_decode_partitions(H263DecContext *const h); |
| 121 | int ff_mpeg4_decode_video_packet_header(MPVContext *const s); | 122 | int ff_mpeg4_decode_video_packet_header(H263DecContext *const h); |
| 122 | int ff_mpeg4_decode_studio_slice_header(MPVContext *const s); | 123 | int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h); |
| 123 | void ff_mpeg4_workaround_bugs(AVCodecContext *avctx); | 124 | void ff_mpeg4_workaround_bugs(AVCodecContext *avctx); |
| 124 | void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, | 125 | void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, |
| 125 | int dir); | 126 | int dir); |
| 126 | int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt); | 127 | int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt); |
| 127 | 128 | ||
| @@ -307,7 +307,6 @@ typedef struct MpegEncContext { · 306 unmodified lines | |||
| 307 | int first_field; ///< is 1 for the first field of a field picture 0 otherwise | 307 | int first_field; ///< is 1 for the first field of a field picture 0 otherwise |
| 308 | 308 | ||
| 309 | int16_t (*block)[64]; | 309 | int16_t (*block)[64]; |
| 310 | int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch() | ||
| 311 | 310 | ||
| 312 | #define SLICE_OK 0 | 311 | #define SLICE_OK 0 |
| 313 | #define SLICE_ERROR -1 | 312 | #define SLICE_ERROR -1 |
| @@ -74,23 +74,24 @@ static VLCElem v2_mb_type_vlc[128]; · 73 unmodified lines | |||
| 74 | VLCElem ff_inter_intra_vlc[8]; | 74 | VLCElem ff_inter_intra_vlc[8]; |
| 75 | 75 | ||
| 76 | /* This is identical to H.263 except that its range is multiplied by 2. */ | 76 | /* This is identical to H.263 except that its range is multiplied by 2. */ |
| 77 | static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) | 77 | static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code) |
| 78 | { | 78 | { |
| 79 | int code, val, sign, shift; | 79 | int code, val, sign, shift; |
| 80 | 80 | ||
| 81 | code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2); | 81 | code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2); |
| 82 | ff_dlog(s->avctx, "MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred); | 82 | ff_dlog(h->c.avctx, "MV code %d at %d %d pred: %d\n", |
| 83 | code, h->c.mb_x,h->c.mb_y, pred); | ||
| 83 | if (code < 0) | 84 | if (code < 0) |
| 84 | return 0xffff; | 85 | return 0xffff; |
| 85 | 86 | ||
| 86 | if (code == 0) | 87 | if (code == 0) |
| 87 | return pred; | 88 | return pred; |
| 88 | sign = get_bits1(&s->gb); | 89 | sign = get_bits1(&h->c.gb); |
| 89 | shift = f_code - 1; | 90 | shift = f_code - 1; |
| 90 | val = code; | 91 | val = code; |
| 91 | if (shift) { | 92 | if (shift) { |
| 92 | val = (val - 1) << shift; | 93 | val = (val - 1) << shift; |
| 93 | val |= get_bits(&s->gb, shift); | 94 | val |= get_bits(&h->c.gb, shift); |
| 94 | val++; | 95 | val++; |
| 95 | } | 96 | } |
| 96 | if (sign) | 97 | if (sign) |
| @@ -105,151 +106,155 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) · 8 unmodified lines | |||
| 105 | return val; | 106 | return val; |
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64]) | 109 | static int msmpeg4v12_decode_mb(H263DecContext *const h, int16_t block[6][64]) |
| 109 | { | 110 | { |
| 110 | MSMP4DecContext *const ms = mpv_to_msmpeg4(s); | 111 | MSMP4DecContext *const ms = mpv_to_msmpeg4(h); |
| 111 | int cbp, code, i; | 112 | int cbp, code, i; |
| 112 | uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride]; | 113 | uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride]; |
| 113 | 114 | ||
| 114 | if (s->pict_type == AV_PICTURE_TYPE_P) { | 115 | if (h->c.pict_type == AV_PICTURE_TYPE_P) { |
| 115 | if (ms->use_skip_mb_code) { | 116 | if (ms->use_skip_mb_code) { |
| 116 | if (get_bits1(&s->gb)) { | 117 | if (get_bits1(&h->c.gb)) { |
| 117 | /* skip mb */ | 118 | /* skip mb */ |
| 118 | s->mb_intra = 0; | 119 | h->c.mb_intra = 0; |
| 119 | for(i=0;i<6;i++) | 120 | for(i=0;i<6;i++) |
| 120 | s->block_last_index[i] = -1; | 121 | h->c.block_last_index[i] = -1; |
| 121 | s->mv_dir = MV_DIR_FORWARD; | 122 | h->c.mv_dir = MV_DIR_FORWARD; |
| 122 | s->mv_type = MV_TYPE_16X16; | 123 | h->c.mv_type = MV_TYPE_16X16; |
| 123 | s->mv[0][0][0] = 0; | 124 | h->c.mv[0][0][0] = 0; |
| 124 | s->mv[0][0][1] = 0; | 125 | h->c.mv[0][0][1] = 0; |
| 125 | s->mb_skipped = 1; | 126 | h->c.mb_skipped = 1; |
| 126 | *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16; | 127 | *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 127 | return 0; | 128 | return 0; |
| 128 | } | 129 | } |
| 129 | } | 130 | } |
| 130 | 131 | ||
| 131 | if (s->msmpeg4_version == MSMP4_V2) | 132 | if (h->c.msmpeg4_version == MSMP4_V2) |
| 132 | code = get_vlc2(&s->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1); | 133 | code = get_vlc2(&h->c.gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1); |
| 133 | else | 134 | else |
| 134 | code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); | 135 | code = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); |
| 135 | if(code<0 || code>7){ | 136 | if(code<0 || code>7){ |
| 136 | av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y); | 137 | av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", |
| 138 | code, h->c.mb_x, h->c.mb_y); | ||
| 137 | return -1; | 139 | return -1; |
| 138 | } | 140 | } |
| 139 | 141 | ||
| 140 | s->mb_intra = code >>2; | 142 | h->c.mb_intra = code >>2; |
| 141 | 143 | ||
| 142 | cbp = code & 0x3; | 144 | cbp = code & 0x3; |
| 143 | } else { | 145 | } else { |
| 144 | s->mb_intra = 1; | 146 | h->c.mb_intra = 1; |
| 145 | if (s->msmpeg4_version == MSMP4_V2) | 147 | if (h->c.msmpeg4_version == MSMP4_V2) |
| 146 | cbp = get_vlc2(&s->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1); | 148 | cbp = get_vlc2(&h->c.gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1); |
| 147 | else | 149 | else |
| 148 | cbp = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); | 150 | cbp = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); |
| 149 | if(cbp<0 || cbp>3){ | 151 | if(cbp<0 || cbp>3){ |
| 150 | av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); | 152 | av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", |
| 153 | cbp, h->c.mb_x, h->c.mb_y); | ||
| 151 | return -1; | 154 | return -1; |
| 152 | } | 155 | } |
| 153 | } | 156 | } |
| 154 | 157 | ||
| 155 | if (!s->mb_intra) { | 158 | if (!h->c.mb_intra) { |
| 156 | int mx, my, cbpy; | 159 | int mx, my, cbpy; |
| 157 | 160 | ||
| 158 | cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 161 | cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 159 | if(cbpy<0){ | 162 | if(cbpy<0){ |
| 160 | av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); | 163 | av_log(h->c.avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", |
| 164 | cbp, h->c.mb_x, h->c.mb_y); | ||
| 161 | return -1; | 165 | return -1; |
| 162 | } | 166 | } |
| 163 | 167 | ||
| 164 | cbp|= cbpy<<2; | 168 | cbp|= cbpy<<2; |
| 165 | if (s->msmpeg4_version == MSMP4_V1 || (cbp&3) != 3) | 169 | if (h->c.msmpeg4_version == MSMP4_V1 || (cbp&3) != 3) |
| 166 | cbp ^= 0x3C; | 170 | cbp ^= 0x3C; |
| 167 | 171 | ||
| 168 | ff_h263_pred_motion(s, 0, 0, &mx, &my); | 172 | ff_h263_pred_motion(&h->c, 0, 0, &mx, &my); |
| 169 | mx= msmpeg4v2_decode_motion(s, mx, 1); | 173 | mx = msmpeg4v2_decode_motion(h, mx, 1); |
| 170 | my= msmpeg4v2_decode_motion(s, my, 1); | 174 | my = msmpeg4v2_decode_motion(h, my, 1); |
| 171 | 175 | ||
| 172 | s->mv_dir = MV_DIR_FORWARD; | 176 | h->c.mv_dir = MV_DIR_FORWARD; |
| 173 | s->mv_type = MV_TYPE_16X16; | 177 | h->c.mv_type = MV_TYPE_16X16; |
| 174 | s->mv[0][0][0] = mx; | 178 | h->c.mv[0][0][0] = mx; |
| 175 | s->mv[0][0][1] = my; | 179 | h->c.mv[0][0][1] = my; |
| 176 | *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16; | 180 | *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 177 | } else { | 181 | } else { |
| 178 | int v; | 182 | int v; |
| 179 | if (s->msmpeg4_version == MSMP4_V2) { | 183 | if (h->c.msmpeg4_version == MSMP4_V2) { |
| 180 | s->ac_pred = get_bits1(&s->gb); | 184 | h->c.ac_pred = get_bits1(&h->c.gb); |
| 181 | v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 185 | v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 182 | if (v < 0) { | 186 | if (v < 0) { |
| 183 | av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n"); | 187 | av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n"); |
| 184 | return -1; | 188 | return -1; |
| 185 | } | 189 | } |
| 186 | cbp|= v<<2; | 190 | cbp|= v<<2; |
| 187 | } else{ | 191 | } else{ |
| 188 | s->ac_pred = 0; | 192 | h->c.ac_pred = 0; |
| 189 | v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | 193 | v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); |
| 190 | if (v < 0) { | 194 | if (v < 0) { |
| 191 | av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n"); | 195 | av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n"); |
| 192 | return -1; | 196 | return -1; |
| 193 | } | 197 | } |
| 194 | cbp|= v<<2; | 198 | cbp|= v<<2; |
| 195 | if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C; | 199 | if (h->c.pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C; |
| 196 | } | 200 | } |
| 197 | *mb_type_ptr = MB_TYPE_INTRA; | 201 | *mb_type_ptr = MB_TYPE_INTRA; |
| 198 | } | 202 | } |
| 199 | 203 | ||
| 200 | s->bdsp.clear_blocks(s->block[0]); | 204 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 201 | for (i = 0; i < 6; i++) { | 205 | for (i = 0; i < 6; i++) { |
| 202 | if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) | 206 | if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) |
| 203 | { | 207 | { |
| 204 | av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); | 208 | av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", |
| 209 | h->c.mb_x, h->c.mb_y, i); | ||
| 205 | return -1; | 210 | return -1; |
| 206 | } | 211 | } |
| 207 | } | 212 | } |
| 208 | return 0; | 213 | return 0; |
| 209 | } | 214 | } |
| 210 | 215 | ||
| 211 | static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64]) | 216 | static int msmpeg4v34_decode_mb(H263DecContext *const h, int16_t block[6][64]) |
| 212 | { | 217 | { |
| 213 | MSMP4DecContext *const ms = mpv_to_msmpeg4(s); | 218 | MSMP4DecContext *const ms = mpv_to_msmpeg4(h); |
| 214 | int cbp, code, i; | 219 | int cbp, code, i; |
| 215 | uint8_t *coded_val; | 220 | uint8_t *coded_val; |
| 216 | uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride]; | 221 | uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride]; |
| 217 | 222 | ||
| 218 | if (get_bits_left(&s->gb) <= 0) | 223 | if (get_bits_left(&h->c.gb) <= 0) |
| 219 | return AVERROR_INVALIDDATA; | 224 | return AVERROR_INVALIDDATA; |
| 220 | 225 | ||
| 221 | if (s->pict_type == AV_PICTURE_TYPE_P) { | 226 | if (h->c.pict_type == AV_PICTURE_TYPE_P) { |
| 222 | if (ms->use_skip_mb_code) { | 227 | if (ms->use_skip_mb_code) { |
| 223 | if (get_bits1(&s->gb)) { | 228 | if (get_bits1(&h->c.gb)) { |
| 224 | /* skip mb */ | 229 | /* skip mb */ |
| 225 | s->mb_intra = 0; | 230 | h->c.mb_intra = 0; |
| 226 | for(i=0;i<6;i++) | 231 | for(i=0;i<6;i++) |
| 227 | s->block_last_index[i] = -1; | 232 | h->c.block_last_index[i] = -1; |
| 228 | s->mv_dir = MV_DIR_FORWARD; | 233 | h->c.mv_dir = MV_DIR_FORWARD; |
| 229 | s->mv_type = MV_TYPE_16X16; | 234 | h->c.mv_type = MV_TYPE_16X16; |
| 230 | s->mv[0][0][0] = 0; | 235 | h->c.mv[0][0][0] = 0; |
| 231 | s->mv[0][0][1] = 0; | 236 | h->c.mv[0][0][1] = 0; |
| 232 | s->mb_skipped = 1; | 237 | h->c.mb_skipped = 1; |
| 233 | *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16; | 238 | *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 234 | 239 | ||
| 235 | return 0; | 240 | return 0; |
| 236 | } | 241 | } |
| 237 | } | 242 | } |
| 238 | 243 | ||
| 239 | code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3); | 244 | code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3); |
| 240 | //s->mb_intra = (code & 0x40) ? 0 : 1; | 245 | //h->c.mb_intra = (code & 0x40) ? 0 : 1; |
| 241 | s->mb_intra = (~code & 0x40) >> 6; | 246 | h->c.mb_intra = (~code & 0x40) >> 6; |
| 242 | 247 | ||
| 243 | cbp = code & 0x3f; | 248 | cbp = code & 0x3f; |
| 244 | } else { | 249 | } else { |
| 245 | s->mb_intra = 1; | 250 | h->c.mb_intra = 1; |
| 246 | code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2); | 251 | code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2); |
| 247 | /* predict coded block pattern */ | 252 | /* predict coded block pattern */ |
| 248 | cbp = 0; | 253 | cbp = 0; |
| 249 | for(i=0;i<6;i++) { | 254 | for(i=0;i<6;i++) { |
| 250 | int val = ((code >> (5 - i)) & 1); | 255 | int val = ((code >> (5 - i)) & 1); |
| 251 | if (i < 4) { | 256 | if (i < 4) { |
| 252 | int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val); | 257 | int pred = ff_msmpeg4_coded_block_pred(&h->c, i, &coded_val); |
| 253 | val = val ^ pred; | 258 | val = val ^ pred; |
| 254 | *coded_val = val; | 259 | *coded_val = val; |
| 255 | } | 260 | } |
| @@ -257,41 +262,42 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line | |||
| 257 | } | 262 | } |
| 258 | } | 263 | } |
| 259 | 264 | ||
| 260 | if (!s->mb_intra) { | 265 | if (!h->c.mb_intra) { |
| 261 | int mx, my; | 266 | int mx, my; |
| 262 | if (ms->per_mb_rl_table && cbp) { | 267 | if (ms->per_mb_rl_table && cbp) { |
| 263 | ms->rl_table_index = decode012(&s->gb); | 268 | ms->rl_table_index = decode012(&h->c.gb); |
| 264 | ms->rl_chroma_table_index = ms->rl_table_index; | 269 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 265 | } | 270 | } |
| 266 | ff_h263_pred_motion(s, 0, 0, &mx, &my); | 271 | ff_h263_pred_motion(&h->c, 0, 0, &mx, &my); |
| 267 | ff_msmpeg4_decode_motion(ms, &mx, &my); | 272 | ff_msmpeg4_decode_motion(ms, &mx, &my); |
| 268 | s->mv_dir = MV_DIR_FORWARD; | 273 | h->c.mv_dir = MV_DIR_FORWARD; |
| 269 | s->mv_type = MV_TYPE_16X16; | 274 | h->c.mv_type = MV_TYPE_16X16; |
| 270 | s->mv[0][0][0] = mx; | 275 | h->c.mv[0][0][0] = mx; |
| 271 | s->mv[0][0][1] = my; | 276 | h->c.mv[0][0][1] = my; |
| 272 | *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16; | 277 | *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 273 | } else { | 278 | } else { |
| 274 | ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y, | 279 | ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y, |
| 275 | ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0), | 280 | ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0), |
| 276 | show_bits(&s->gb, 24)); | 281 | show_bits(&h->c.gb, 24)); |
| 277 | s->ac_pred = get_bits1(&s->gb); | 282 | h->c.ac_pred = get_bits1(&h->c.gb); |
| 278 | *mb_type_ptr = MB_TYPE_INTRA; | 283 | *mb_type_ptr = MB_TYPE_INTRA; |
| 279 | if(s->inter_intra_pred){ | 284 | if (h->c.inter_intra_pred) { |
| 280 | s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1); | 285 | h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1); |
| 281 | ff_dlog(s->avctx, "%d%d %d %d/", | 286 | ff_dlog(h->c.avctx, "%d%d %d %d/", |
| 282 | s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); | 287 | h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y); |
| 283 | } | 288 | } |
| 284 | if (ms->per_mb_rl_table && cbp) { | 289 | if (ms->per_mb_rl_table && cbp) { |
| 285 | ms->rl_table_index = decode012(&s->gb); | 290 | ms->rl_table_index = decode012(&h->c.gb); |
| 286 | ms->rl_chroma_table_index = ms->rl_table_index; | 291 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 287 | } | 292 | } |
| 288 | } | 293 | } |
| 289 | 294 | ||
| 290 | s->bdsp.clear_blocks(s->block[0]); | 295 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 291 | for (i = 0; i < 6; i++) { | 296 | for (i = 0; i < 6; i++) { |
| 292 | if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) | 297 | if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) |
| 293 | { | 298 | { |
| 294 | av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); | 299 | av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", |
| 300 | h->c.mb_x, h->c.mb_y, i); | ||
| 295 | return -1; | 301 | return -1; |
| 296 | } | 302 | } |
| 297 | } | 303 | } |
| @@ -357,7 +363,7 @@ static av_cold void msmpeg4_decode_init_static(void) · 59 unmodified lines | |||
| 357 | av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) | 363 | av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) |
| 358 | { | 364 | { |
| 359 | static AVOnce init_static_once = AV_ONCE_INIT; | 365 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 360 | MpegEncContext *s = avctx->priv_data; | 366 | H263DecContext *const h = avctx->priv_data; |
| 361 | int ret; | 367 | int ret; |
| 362 | 368 | ||
| 363 | if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) | 369 | if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) |
| @@ -367,18 +373,18 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) · 3 unmodified lines | |||
| 367 | return -1; | 373 | return -1; |
| 368 | 374 | ||
| 369 | // We unquantize inter blocks as we parse them. | 375 | // We unquantize inter blocks as we parse them. |
| 370 | s->dct_unquantize_inter = NULL; | 376 | h->c.dct_unquantize_inter = NULL; |
| 371 | 377 | ||
| 372 | ff_msmpeg4_common_init(s); | 378 | ff_msmpeg4_common_init(&h->c); |
| 373 | 379 | ||
| 374 | switch (s->msmpeg4_version) { | 380 | switch (h->c.msmpeg4_version) { |
| 375 | case MSMP4_V1: | 381 | case MSMP4_V1: |
| 376 | case MSMP4_V2: | 382 | case MSMP4_V2: |
| 377 | s->decode_mb= msmpeg4v12_decode_mb; | 383 | h->decode_mb = msmpeg4v12_decode_mb; |
| 378 | break; | 384 | break; |
| 379 | case MSMP4_V3: | 385 | case MSMP4_V3: |
| 380 | case MSMP4_WMV1: | 386 | case MSMP4_WMV1: |
| 381 | s->decode_mb= msmpeg4v34_decode_mb; | 387 | h->decode_mb = msmpeg4v34_decode_mb; |
| 382 | break; | 388 | break; |
| 383 | case MSMP4_WMV2: | 389 | case MSMP4_WMV2: |
| 384 | break; | 390 | break; |
| @@ -386,16 +392,16 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) · 1 unmodified line | |||
| 386 | av_unreachable("List contains all cases using ff_msmpeg4_decode_init()"); | 392 | av_unreachable("List contains all cases using ff_msmpeg4_decode_init()"); |
| 387 | } | 393 | } |
| 388 | 394 | ||
| 389 | s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe | 395 | h->c.slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe |
| 390 | 396 | ||
| 391 | ff_thread_once(&init_static_once, msmpeg4_decode_init_static); | 397 | ff_thread_once(&init_static_once, msmpeg4_decode_init_static); |
| 392 | 398 | ||
| 393 | return 0; | 399 | return 0; |
| 394 | } | 400 | } |
| 395 | 401 | ||
| 396 | int ff_msmpeg4_decode_picture_header(MpegEncContext * s) | 402 | int ff_msmpeg4_decode_picture_header(H263DecContext *const h) |
| 397 | { | 403 | { |
| 398 | MSMP4DecContext *const ms = mpv_to_msmpeg4(s); | 404 | MSMP4DecContext *const ms = mpv_to_msmpeg4(h); |
| 399 | int code; | 405 | int code; |
| 400 | 406 | ||
| 401 | // at minimum one bit per macroblock is required at least in a valid frame, | 407 | // at minimum one bit per macroblock is required at least in a valid frame, |
| @@ -403,51 +409,51 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) · 1 unmodified line | |||
| 403 | // smallest "black/skip" frame generally contain not much recoverable content | 409 | // smallest "black/skip" frame generally contain not much recoverable content |
| 404 | // while at the same time they have the highest computational requirements | 410 | // while at the same time they have the highest computational requirements |
| 405 | // per byte | 411 | // per byte |
| 406 | if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16)) | 412 | if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16)) |
| 407 | return AVERROR_INVALIDDATA; | 413 | return AVERROR_INVALIDDATA; |
| 408 | 414 | ||
| 409 | if (s->msmpeg4_version == MSMP4_V1) { | 415 | if (h->c.msmpeg4_version == MSMP4_V1) { |
| 410 | int start_code = get_bits_long(&s->gb, 32); | 416 | int start_code = get_bits_long(&h->c.gb, 32); |
| 411 | if(start_code!=0x00000100){ | 417 | if(start_code!=0x00000100){ |
| 412 | av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n"); | 418 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n"); |
| 413 | return -1; | 419 | return -1; |
| 414 | } | 420 | } |
| 415 | 421 | ||
| 416 | skip_bits(&s->gb, 5); // frame number */ | 422 | skip_bits(&h->c.gb, 5); // frame number */ |
| 417 | } | 423 | } |
| 418 | 424 | ||
| 419 | s->pict_type = get_bits(&s->gb, 2) + 1; | 425 | h->c.pict_type = get_bits(&h->c.gb, 2) + 1; |
| 420 | if (s->pict_type != AV_PICTURE_TYPE_I && | 426 | if (h->c.pict_type != AV_PICTURE_TYPE_I && |
| 421 | s->pict_type != AV_PICTURE_TYPE_P){ | 427 | h->c.pict_type != AV_PICTURE_TYPE_P){ |
| 422 | av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n"); | 428 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n"); |
| 423 | return -1; | 429 | return -1; |
| 424 | } | 430 | } |
| 425 | s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); | 431 | h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); |
| 426 | if(s->qscale==0){ | 432 | if (h->c.qscale == 0) { |
| 427 | av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n"); | 433 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n"); |
| 428 | return -1; | 434 | return -1; |
| 429 | } | 435 | } |
| 430 | 436 | ||
| 431 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 437 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 432 | code = get_bits(&s->gb, 5); | 438 | code = get_bits(&h->c.gb, 5); |
| 433 | if (s->msmpeg4_version == MSMP4_V1) { | 439 | if (h->c.msmpeg4_version == MSMP4_V1) { |
| 434 | if(code==0 || code>s->mb_height){ | 440 | if(code==0 || code>h->c.mb_height) { |
| 435 | av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code); | 441 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code); |
| 436 | return -1; | 442 | return -1; |
| 437 | } | 443 | } |
| 438 | 444 | ||
| 439 | s->slice_height = code; | 445 | h->c.slice_height = code; |
| 440 | }else{ | 446 | }else{ |
| 441 | /* 0x17: one slice, 0x18: two slices, ... */ | 447 | /* 0x17: one slice, 0x18: two slices, ... */ |
| 442 | if (code < 0x17){ | 448 | if (code < 0x17){ |
| 443 | av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code); | 449 | av_log(h->c.avctx, AV_LOG_ERROR, "error, slice code was %X\n", code); |
| 444 | return -1; | 450 | return -1; |
| 445 | } | 451 | } |
| 446 | 452 | ||
| 447 | s->slice_height = s->mb_height / (code - 0x16); | 453 | h->c.slice_height = h->c.mb_height / (code - 0x16); |
| 448 | } | 454 | } |
| 449 | 455 | ||
| 450 | switch(s->msmpeg4_version){ | 456 | switch (h->c.msmpeg4_version) { |
| 451 | case MSMP4_V1: | 457 | case MSMP4_V1: |
| 452 | case MSMP4_V2: | 458 | case MSMP4_V2: |
| 453 | ms->rl_chroma_table_index = 2; | 459 | ms->rl_chroma_table_index = 2; |
| @@ -456,102 +462,102 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) · 2 unmodified lines | |||
| 456 | ms->dc_table_index = 0; //not used | 462 | ms->dc_table_index = 0; //not used |
| 457 | break; | 463 | break; |
| 458 | case MSMP4_V3: | 464 | case MSMP4_V3: |
| 459 | ms->rl_chroma_table_index = decode012(&s->gb); | 465 | ms->rl_chroma_table_index = decode012(&h->c.gb); |
| 460 | ms->rl_table_index = decode012(&s->gb); | 466 | ms->rl_table_index = decode012(&h->c.gb); |
| 461 | 467 | ||
| 462 | ms->dc_table_index = get_bits1(&s->gb); | 468 | ms->dc_table_index = get_bits1(&h->c.gb); |
| 463 | break; | 469 | break; |
| 464 | case MSMP4_WMV1: | 470 | case MSMP4_WMV1: |
| 465 | ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8); | 471 | ff_msmpeg4_decode_ext_header(h, (2+5+5+17+7)/8); |
| 466 | 472 | ||
| 467 | if (ms->bit_rate > MBAC_BITRATE) | 473 | if (ms->bit_rate > MBAC_BITRATE) |
| 468 | ms->per_mb_rl_table = get_bits1(&s->gb); | 474 | ms->per_mb_rl_table = get_bits1(&h->c.gb); |
| 469 | else | 475 | else |
| 470 | ms->per_mb_rl_table = 0; | 476 | ms->per_mb_rl_table = 0; |
| 471 | 477 | ||
| 472 | if (!ms->per_mb_rl_table) { | 478 | if (!ms->per_mb_rl_table) { |
| 473 | ms->rl_chroma_table_index = decode012(&s->gb); | 479 | ms->rl_chroma_table_index = decode012(&h->c.gb); |
| 474 | ms->rl_table_index = decode012(&s->gb); | 480 | ms->rl_table_index = decode012(&h->c.gb); |
| 475 | } | 481 | } |
| 476 | 482 | ||
| 477 | ms->dc_table_index = get_bits1(&s->gb); | 483 | ms->dc_table_index = get_bits1(&h->c.gb); |
| 478 | s->inter_intra_pred= 0; | 484 | h->c.inter_intra_pred= 0; |
| 479 | break; | 485 | break; |
| 480 | default: | 486 | default: |
| 481 | av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1"); | 487 | av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1"); |
| 482 | } | 488 | } |
| 483 | s->no_rounding = 1; | 489 | h->c.no_rounding = 1; |
| 484 | if(s->avctx->debug&FF_DEBUG_PICT_INFO) | 490 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) |
| 485 | av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n", | 491 | av_log(h->c.avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n", |
| 486 | s->qscale, | 492 | h->c.qscale, |
| 487 | ms->rl_chroma_table_index, | 493 | ms->rl_chroma_table_index, |
| 488 | ms->rl_table_index, | 494 | ms->rl_table_index, |
| 489 | ms->dc_table_index, | 495 | ms->dc_table_index, |
| 490 | ms->per_mb_rl_table, | 496 | ms->per_mb_rl_table, |
| 491 | s->slice_height); | 497 | h->c.slice_height); |
| 492 | } else { | 498 | } else { |
| 493 | switch(s->msmpeg4_version){ | 499 | switch (h->c.msmpeg4_version) { |
| 494 | case MSMP4_V1: | 500 | case MSMP4_V1: |
| 495 | case MSMP4_V2: | 501 | case MSMP4_V2: |
| 496 | if (s->msmpeg4_version == MSMP4_V1) | 502 | if (h->c.msmpeg4_version == MSMP4_V1) |
| 497 | ms->use_skip_mb_code = 1; | 503 | ms->use_skip_mb_code = 1; |
| 498 | else | 504 | else |
| 499 | ms->use_skip_mb_code = get_bits1(&s->gb); | 505 | ms->use_skip_mb_code = get_bits1(&h->c.gb); |
| 500 | ms->rl_table_index = 2; | 506 | ms->rl_table_index = 2; |
| 501 | ms->rl_chroma_table_index = ms->rl_table_index; | 507 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 502 | ms->dc_table_index = 0; //not used | 508 | ms->dc_table_index = 0; //not used |
| 503 | ms->mv_table_index = 0; | 509 | ms->mv_table_index = 0; |
| 504 | break; | 510 | break; |
| 505 | case MSMP4_V3: | 511 | case MSMP4_V3: |
| 506 | ms->use_skip_mb_code = get_bits1(&s->gb); | 512 | ms->use_skip_mb_code = get_bits1(&h->c.gb); |
| 507 | ms->rl_table_index = decode012(&s->gb); | 513 | ms->rl_table_index = decode012(&h->c.gb); |
| 508 | ms->rl_chroma_table_index = ms->rl_table_index; | 514 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 509 | 515 | ||
| 510 | ms->dc_table_index = get_bits1(&s->gb); | 516 | ms->dc_table_index = get_bits1(&h->c.gb); |
| 511 | 517 | ||
| 512 | ms->mv_table_index = get_bits1(&s->gb); | 518 | ms->mv_table_index = get_bits1(&h->c.gb); |
| 513 | break; | 519 | break; |
| 514 | case MSMP4_WMV1: | 520 | case MSMP4_WMV1: |
| 515 | ms->use_skip_mb_code = get_bits1(&s->gb); | 521 | ms->use_skip_mb_code = get_bits1(&h->c.gb); |
| 516 | 522 | ||
| 517 | if (ms->bit_rate > MBAC_BITRATE) | 523 | if (ms->bit_rate > MBAC_BITRATE) |
| 518 | ms->per_mb_rl_table = get_bits1(&s->gb); | 524 | ms->per_mb_rl_table = get_bits1(&h->c.gb); |
| 519 | else | 525 | else |
| 520 | ms->per_mb_rl_table = 0; | 526 | ms->per_mb_rl_table = 0; |
| 521 | 527 | ||
| 522 | if (!ms->per_mb_rl_table) { | 528 | if (!ms->per_mb_rl_table) { |
| 523 | ms->rl_table_index = decode012(&s->gb); | 529 | ms->rl_table_index = decode012(&h->c.gb); |
| 524 | ms->rl_chroma_table_index = ms->rl_table_index; | 530 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 525 | } | 531 | } |
| 526 | 532 | ||
| 527 | ms->dc_table_index = get_bits1(&s->gb); | 533 | ms->dc_table_index = get_bits1(&h->c.gb); |
| 528 | 534 | ||
| 529 | ms->mv_table_index = get_bits1(&s->gb); | 535 | ms->mv_table_index = get_bits1(&h->c.gb); |
| 530 | s->inter_intra_pred = s->width*s->height < 320*240 && | 536 | h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 && |
| 531 | ms->bit_rate <= II_BITRATE; | 537 | ms->bit_rate <= II_BITRATE; |
| 532 | break; | 538 | break; |
| 533 | default: | 539 | default: |
| 534 | av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1"); | 540 | av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1"); |
| 535 | } | 541 | } |
| 536 | 542 | ||
| 537 | if(s->avctx->debug&FF_DEBUG_PICT_INFO) | 543 | if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) |
| 538 | av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n", | 544 | av_log(h->c.avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n", |
| 539 | ms->use_skip_mb_code, | 545 | ms->use_skip_mb_code, |
| 540 | ms->rl_table_index, | 546 | ms->rl_table_index, |
| 541 | ms->rl_chroma_table_index, | 547 | ms->rl_chroma_table_index, |
| 542 | ms->dc_table_index, | 548 | ms->dc_table_index, |
| 543 | ms->mv_table_index, | 549 | ms->mv_table_index, |
| 544 | ms->per_mb_rl_table, | 550 | ms->per_mb_rl_table, |
| 545 | s->qscale); | 551 | h->c.qscale); |
| 546 | 552 | ||
| 547 | if (ms->flipflop_rounding) { | 553 | if (ms->flipflop_rounding) { |
| 548 | s->no_rounding ^= 1; | 554 | h->c.no_rounding ^= 1; |
| 549 | }else{ | 555 | }else{ |
| 550 | s->no_rounding = 0; | 556 | h->c.no_rounding = 0; |
| 551 | } | 557 | } |
| 552 | } | 558 | } |
| 553 | ff_dlog(s->avctx, "%d %d %d %d %d\n", s->pict_type, ms->bit_rate, | 559 | ff_dlog(h->c.avctx, "%d %d %d %d %d\n", h->c.pict_type, ms->bit_rate, |
| 554 | s->inter_intra_pred, s->width, s->height); | 560 | h->c.inter_intra_pred, h->c.width, h->c.height); |
| 555 | 561 | ||
| 556 | ms->esc3_level_length = 0; | 562 | ms->esc3_level_length = 0; |
| 557 | ms->esc3_run_length = 0; | 563 | ms->esc3_run_length = 0; |
| @@ -559,30 +565,30 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) · 1 unmodified line | |||
| 559 | return 0; | 565 | return 0; |
| 560 | } | 566 | } |
| 561 | 567 | ||
| 562 | int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) | 568 | int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size) |
| 563 | { | 569 | { |
| 564 | MSMP4DecContext *const ms = mpv_to_msmpeg4(s); | 570 | MSMP4DecContext *const ms = mpv_to_msmpeg4(h); |
| 565 | int left= buf_size*8 - get_bits_count(&s->gb); | 571 | int left= buf_size*8 - get_bits_count(&h->c.gb); |
| 566 | int length = s->msmpeg4_version >= MSMP4_V3 ? 17 : 16; | 572 | int length = h->c.msmpeg4_version >= MSMP4_V3 ? 17 : 16; |
| 567 | /* the alt_bitstream reader could read over the end so we need to check it */ | 573 | /* the alt_bitstream reader could read over the end so we need to check it */ |
| 568 | if(left>=length && left<length+8) | 574 | if(left>=length && left<length+8) |
| 569 | { | 575 | { |
| 570 | skip_bits(&s->gb, 5); /* fps */ | 576 | skip_bits(&h->c.gb, 5); /* fps */ |
| 571 | ms->bit_rate = get_bits(&s->gb, 11) * 1024; | 577 | ms->bit_rate = get_bits(&h->c.gb, 11) * 1024; |
| 572 | if (s->msmpeg4_version >= MSMP4_V3) | 578 | if (h->c.msmpeg4_version >= MSMP4_V3) |
| 573 | ms->flipflop_rounding = get_bits1(&s->gb); | 579 | ms->flipflop_rounding = get_bits1(&h->c.gb); |
| 574 | else | 580 | else |
| 575 | ms->flipflop_rounding = 0; | 581 | ms->flipflop_rounding = 0; |
| 576 | } | 582 | } |
| 577 | else if(left<length+8) | 583 | else if(left<length+8) |
| 578 | { | 584 | { |
| 579 | ms->flipflop_rounding = 0; | 585 | ms->flipflop_rounding = 0; |
| 580 | if (s->msmpeg4_version != MSMP4_V2) | 586 | if (h->c.msmpeg4_version != MSMP4_V2) |
| 581 | av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left); | 587 | av_log(h->c.avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left); |
| 582 | } | 588 | } |
| 583 | else | 589 | else |
| 584 | { | 590 | { |
| 585 | av_log(s->avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n"); | 591 | av_log(h->c.avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n"); |
| 586 | } | 592 | } |
| 587 | 593 | ||
| 588 | return 0; | 594 | return 0; |
| @@ -590,52 +596,52 @@ int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) · 1 unmodified line | |||
| 590 | 596 | ||
| 591 | static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr) | 597 | static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr) |
| 592 | { | 598 | { |
| 593 | MpegEncContext *const s = &ms->m; | 599 | H263DecContext *const h = &ms->h; |
| 594 | int level, pred; | 600 | int level, pred; |
| 595 | 601 | ||
| 596 | if (s->msmpeg4_version <= MSMP4_V2) { | 602 | if (h->c.msmpeg4_version <= MSMP4_V2) { |
| 597 | if (n < 4) { | 603 | if (n < 4) { |
| 598 | level = get_vlc2(&s->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3); | 604 | level = get_vlc2(&h->c.gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3); |
| 599 | } else { | 605 | } else { |
| 600 | level = get_vlc2(&s->gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3); | 606 | level = get_vlc2(&h->c.gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3); |
| 601 | } | 607 | } |
| 602 | if (level < 0) { | 608 | if (level < 0) { |
| 603 | av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); | 609 | av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n"); |
| 604 | *dir_ptr = 0; | 610 | *dir_ptr = 0; |
| 605 | return -1; | 611 | return -1; |
| 606 | } | 612 | } |
| 607 | level-=256; | 613 | level-=256; |
| 608 | } else { | 614 | } else { |
| 609 | level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4], | 615 | level = get_vlc2(&h->c.gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4], |
| 610 | MSMP4_DC_VLC_BITS, 3); | 616 | MSMP4_DC_VLC_BITS, 3); |
| 611 | 617 | ||
| 612 | if (level == DC_MAX) { | 618 | if (level == DC_MAX) { |
| 613 | level = get_bits(&s->gb, 8); | 619 | level = get_bits(&h->c.gb, 8); |
| 614 | if (get_bits1(&s->gb)) | 620 | if (get_bits1(&h->c.gb)) |
| 615 | level = -level; | 621 | level = -level; |
| 616 | } else if (level != 0) { | 622 | } else if (level != 0) { |
| 617 | if (get_bits1(&s->gb)) | 623 | if (get_bits1(&h->c.gb)) |
| 618 | level = -level; | 624 | level = -level; |
| 619 | } | 625 | } |
| 620 | } | 626 | } |
| 621 | 627 | ||
| 622 | if (s->msmpeg4_version == MSMP4_V1) { | 628 | if (h->c.msmpeg4_version == MSMP4_V1) { |
| 623 | int32_t *dc_val; | 629 | int32_t *dc_val; |
| 624 | pred = msmpeg4v1_pred_dc(s, n, &dc_val); | 630 | pred = msmpeg4v1_pred_dc(&h->c, n, &dc_val); |
| 625 | level += pred; | 631 | level += pred; |
| 626 | 632 | ||
| 627 | /* update predictor */ | 633 | /* update predictor */ |
| 628 | *dc_val= level; | 634 | *dc_val= level; |
| 629 | }else{ | 635 | }else{ |
| 630 | int16_t *dc_val; | 636 | int16_t *dc_val; |
| 631 | pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); | 637 | pred = ff_msmpeg4_pred_dc(&h->c, n, &dc_val, dir_ptr); |
| 632 | level += pred; | 638 | level += pred; |
| 633 | 639 | ||
| 634 | /* update predictor */ | 640 | /* update predictor */ |
| 635 | if (n < 4) { | 641 | if (n < 4) { |
| 636 | *dc_val = level * s->y_dc_scale; | 642 | *dc_val = level * h->c.y_dc_scale; |
| 637 | } else { | 643 | } else { |
| 638 | *dc_val = level * s->c_dc_scale; | 644 | *dc_val = level * h->c.c_dc_scale; |
| 639 | } | 645 | } |
| 640 | } | 646 | } |
| 641 | 647 | ||
| @@ -645,14 +651,14 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr) · 3 unmodified lines | |||
| 645 | int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, | 651 | int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, |
| 646 | int n, int coded, const uint8_t *scan_table) | 652 | int n, int coded, const uint8_t *scan_table) |
| 647 | { | 653 | { |
| 648 | MpegEncContext *const s = &ms->m; | 654 | H263DecContext *const h = &ms->h; |
| 649 | int level, i, last, run, run_diff; | 655 | int level, i, last, run, run_diff; |
| 650 | int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized | 656 | int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized |
| 651 | const RLTable *rl; | 657 | const RLTable *rl; |
| 652 | const RL_VLC_ELEM *rl_vlc; | 658 | const RL_VLC_ELEM *rl_vlc; |
| 653 | int qmul, qadd; | 659 | int qmul, qadd; |
| 654 | 660 | ||
| 655 | if (s->mb_intra) { | 661 | if (h->c.mb_intra) { |
| 656 | qmul=1; | 662 | qmul=1; |
| 657 | qadd=0; | 663 | qadd=0; |
| 658 | 664 | ||
| @@ -660,110 +666,113 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 1 unmodified line | |||
| 660 | level = msmpeg4_decode_dc(ms, n, &dc_pred_dir); | 666 | level = msmpeg4_decode_dc(ms, n, &dc_pred_dir); |
| 661 | 667 | ||
| 662 | if (level < 0){ | 668 | if (level < 0){ |
| 663 | av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale); | 669 | av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, h->c.qscale); |
| 664 | if(s->inter_intra_pred) level=0; | 670 | if (h->c.inter_intra_pred) |
| 671 | level = 0; | ||
| 665 | } | 672 | } |
| 666 | if (n < 4) { | 673 | if (n < 4) { |
| 667 | rl = &ff_rl_table[ms->rl_table_index]; | 674 | rl = &ff_rl_table[ms->rl_table_index]; |
| 668 | if(level > 256*s->y_dc_scale){ | 675 | if (level > 256 * h->c.y_dc_scale) { |
| 669 | av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale); | 676 | av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", h->c.qscale); |
| 670 | if(!s->inter_intra_pred) return -1; | 677 | if (!h->c.inter_intra_pred) |
| 678 | return -1; | ||
| 671 | } | 679 | } |
| 672 | } else { | 680 | } else { |
| 673 | rl = &ff_rl_table[3 + ms->rl_chroma_table_index]; | 681 | rl = &ff_rl_table[3 + ms->rl_chroma_table_index]; |
| 674 | if(level > 256*s->c_dc_scale){ | 682 | if (level > 256 * h->c.c_dc_scale) { |
| 675 | av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale); | 683 | av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", h->c.qscale); |
| 676 | if(!s->inter_intra_pred) return -1; | 684 | if (!h->c.inter_intra_pred) |
| 685 | return -1; | ||
| 677 | } | 686 | } |
| 678 | } | 687 | } |
| 679 | block[0] = level; | 688 | block[0] = level; |
| 680 | 689 | ||
| 681 | run_diff = s->msmpeg4_version >= MSMP4_WMV1; | 690 | run_diff = h->c.msmpeg4_version >= MSMP4_WMV1; |
| 682 | i = 0; | 691 | i = 0; |
| 683 | if (!coded) { | 692 | if (!coded) { |
| 684 | goto not_coded; | 693 | goto not_coded; |
| 685 | } | 694 | } |
| 686 | if (s->ac_pred) { | 695 | if (h->c.ac_pred) { |
| 687 | if (dc_pred_dir == 0) | 696 | if (dc_pred_dir == 0) |
| 688 | scan_table = s->permutated_intra_v_scantable; /* left */ | 697 | scan_table = h->c.permutated_intra_v_scantable; /* left */ |
| 689 | else | 698 | else |
| 690 | scan_table = s->permutated_intra_h_scantable; /* top */ | 699 | scan_table = h->c.permutated_intra_h_scantable; /* top */ |
| 691 | } else { | 700 | } else { |
| 692 | scan_table = s->intra_scantable.permutated; | 701 | scan_table = h->c.intra_scantable.permutated; |
| 693 | } | 702 | } |
| 694 | rl_vlc= rl->rl_vlc[0]; | 703 | rl_vlc= rl->rl_vlc[0]; |
| 695 | } else { | 704 | } else { |
| 696 | qmul = s->qscale << 1; | 705 | qmul = h->c.qscale << 1; |
| 697 | qadd = (s->qscale - 1) | 1; | 706 | qadd = (h->c.qscale - 1) | 1; |
| 698 | i = -1; | 707 | i = -1; |
| 699 | rl = &ff_rl_table[3 + ms->rl_table_index]; | 708 | rl = &ff_rl_table[3 + ms->rl_table_index]; |
| 700 | 709 | ||
| 701 | if (s->msmpeg4_version == MSMP4_V2) | 710 | if (h->c.msmpeg4_version == MSMP4_V2) |
| 702 | run_diff = 0; | 711 | run_diff = 0; |
| 703 | else | 712 | else |
| 704 | run_diff = 1; | 713 | run_diff = 1; |
| 705 | 714 | ||
| 706 | if (!coded) { | 715 | if (!coded) { |
| 707 | s->block_last_index[n] = i; | 716 | h->c.block_last_index[n] = i; |
| 708 | return 0; | 717 | return 0; |
| 709 | } | 718 | } |
| 710 | if(!scan_table) | 719 | if(!scan_table) |
| 711 | scan_table = s->inter_scantable.permutated; | 720 | scan_table = h->c.inter_scantable.permutated; |
| 712 | rl_vlc= rl->rl_vlc[s->qscale]; | 721 | rl_vlc= rl->rl_vlc[h->c.qscale]; |
| 713 | } | 722 | } |
| 714 | { | 723 | { |
| 715 | OPEN_READER(re, &s->gb); | 724 | OPEN_READER(re, &h->c.gb); |
| 716 | for(;;) { | 725 | for(;;) { |
| 717 | UPDATE_CACHE(re, &s->gb); | 726 | UPDATE_CACHE(re, &h->c.gb); |
| 718 | GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); | 727 | GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0); |
| 719 | if (level==0) { | 728 | if (level==0) { |
| 720 | int cache; | 729 | int cache; |
| 721 | cache= GET_CACHE(re, &s->gb); | 730 | cache= GET_CACHE(re, &h->c.gb); |
| 722 | /* escape */ | 731 | /* escape */ |
| 723 | if (s->msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) { | 732 | if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) { |
| 724 | if (s->msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) { | 733 | if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) { |
| 725 | /* third escape */ | 734 | /* third escape */ |
| 726 | if (s->msmpeg4_version != MSMP4_V1) | 735 | if (h->c.msmpeg4_version != MSMP4_V1) |
| 727 | LAST_SKIP_BITS(re, &s->gb, 2); | 736 | LAST_SKIP_BITS(re, &h->c.gb, 2); |
| 728 | UPDATE_CACHE(re, &s->gb); | 737 | UPDATE_CACHE(re, &h->c.gb); |
| 729 | if (s->msmpeg4_version <= MSMP4_V3) { | 738 | if (h->c.msmpeg4_version <= MSMP4_V3) { |
| 730 | last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); | 739 | last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_CACHE(re, &h->c.gb, 1); |
| 731 | run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); | 740 | run = SHOW_UBITS(re, &h->c.gb, 6); SKIP_CACHE(re, &h->c.gb, 6); |
| 732 | level= SHOW_SBITS(re, &s->gb, 8); | 741 | level = SHOW_SBITS(re, &h->c.gb, 8); |
| 733 | SKIP_COUNTER(re, &s->gb, 1+6+8); | 742 | SKIP_COUNTER(re, &h->c.gb, 1 + 6 + 8); |
| 734 | }else{ | 743 | }else{ |
| 735 | int sign; | 744 | int sign; |
| 736 | last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); | 745 | last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1); |
| 737 | if (!ms->esc3_level_length) { | 746 | if (!ms->esc3_level_length) { |
| 738 | int ll; | 747 | int ll; |
| 739 | ff_dlog(s->avctx, "ESC-3 %X at %d %d\n", | 748 | ff_dlog(h->c.avctx, "ESC-3 %X at %d %d\n", |
| 740 | show_bits(&s->gb, 24), s->mb_x, s->mb_y); | 749 | show_bits(&h->c.gb, 24), h->c.mb_x, h->c.mb_y); |
| 741 | if(s->qscale<8){ | 750 | if (h->c.qscale < 8) { |
| 742 | ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3); | 751 | ll = SHOW_UBITS(re, &h->c.gb, 3); SKIP_BITS(re, &h->c.gb, 3); |
| 743 | if(ll==0){ | 752 | if(ll==0){ |
| 744 | ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); | 753 | ll = 8+SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1); |
| 745 | } | 754 | } |
| 746 | }else{ | 755 | }else{ |
| 747 | ll=2; | 756 | ll=2; |
| 748 | while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){ | 757 | while (ll < 8 && SHOW_UBITS(re, &h->c.gb, 1) == 0) { |
| 749 | ll++; | 758 | ll++; |
| 750 | SKIP_BITS(re, &s->gb, 1); | 759 | SKIP_BITS(re, &h->c.gb, 1); |
| 751 | } | 760 | } |
| 752 | if(ll<8) SKIP_BITS(re, &s->gb, 1); | 761 | if (ll<8) SKIP_BITS(re, &h->c.gb, 1); |
| 753 | } | 762 | } |
| 754 | 763 | ||
| 755 | ms->esc3_level_length = ll; | 764 | ms->esc3_level_length = ll; |
| 756 | ms->esc3_run_length = SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2); | 765 | ms->esc3_run_length = SHOW_UBITS(re, &h->c.gb, 2) + 3; SKIP_BITS(re, &h->c.gb, 2); |
| 757 | UPDATE_CACHE(re, &s->gb); | 766 | UPDATE_CACHE(re, &h->c.gb); |
| 758 | } | 767 | } |
| 759 | run = SHOW_UBITS(re, &s->gb, ms->esc3_run_length); | 768 | run = SHOW_UBITS(re, &h->c.gb, ms->esc3_run_length); |
| 760 | SKIP_BITS(re, &s->gb, ms->esc3_run_length); | 769 | SKIP_BITS(re, &h->c.gb, ms->esc3_run_length); |
| 761 | 770 | ||
| 762 | sign= SHOW_UBITS(re, &s->gb, 1); | 771 | sign= SHOW_UBITS(re, &h->c.gb, 1); |
| 763 | SKIP_BITS(re, &s->gb, 1); | 772 | SKIP_BITS(re, &h->c.gb, 1); |
| 764 | 773 | ||
| 765 | level = SHOW_UBITS(re, &s->gb, ms->esc3_level_length); | 774 | level = SHOW_UBITS(re, &h->c.gb, ms->esc3_level_length); |
| 766 | SKIP_BITS(re, &s->gb, ms->esc3_level_length); | 775 | SKIP_BITS(re, &h->c.gb, ms->esc3_level_length); |
| 767 | if(sign) level= -level; | 776 | if(sign) level= -level; |
| 768 | } | 777 | } |
| 769 | 778 | ||
| @@ -774,38 +783,40 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 4 unmodified lines | |||
| 774 | if(last) i+=192; | 783 | if(last) i+=192; |
| 775 | } else { | 784 | } else { |
| 776 | /* second escape */ | 785 | /* second escape */ |
| 777 | SKIP_BITS(re, &s->gb, 2); | 786 | SKIP_BITS(re, &h->c.gb, 2); |
| 778 | GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | 787 | GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
| 779 | i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing | 788 | i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing |
| 780 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 789 | level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); |
| 781 | LAST_SKIP_BITS(re, &s->gb, 1); | 790 | LAST_SKIP_BITS(re, &h->c.gb, 1); |
| 782 | } | 791 | } |
| 783 | } else { | 792 | } else { |
| 784 | /* first escape */ | 793 | /* first escape */ |
| 785 | SKIP_BITS(re, &s->gb, 1); | 794 | SKIP_BITS(re, &h->c.gb, 1); |
| 786 | GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | 795 | GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
| 787 | i+= run; | 796 | i+= run; |
| 788 | level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing | 797 | level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing |
| 789 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 798 | level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); |
| 790 | LAST_SKIP_BITS(re, &s->gb, 1); | 799 | LAST_SKIP_BITS(re, &h->c.gb, 1); |
| 791 | } | 800 | } |
| 792 | } else { | 801 | } else { |
| 793 | i+= run; | 802 | i+= run; |
| 794 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 803 | level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); |
| 795 | LAST_SKIP_BITS(re, &s->gb, 1); | 804 | LAST_SKIP_BITS(re, &h->c.gb, 1); |
| 796 | } | 805 | } |
| 797 | if (i > 62){ | 806 | if (i > 62){ |
| 798 | i-= 192; | 807 | i-= 192; |
| 799 | if(i&(~63)){ | 808 | if(i&(~63)){ |
| 800 | const int left= get_bits_left(&s->gb); | 809 | const int left = get_bits_left(&h->c.gb); |
| 801 | if (((i + 192 == 64 && level / qmul == -1) || | 810 | if (((i + 192 == 64 && level / qmul == -1) || |
| 802 | !(s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && | 811 | !(h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && |
| 803 | left >= 0) { | 812 | left >= 0) { |
| 804 | av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y); | 813 | av_log(h->c.avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", |
| 814 | h->c.mb_x, h->c.mb_y); | ||
| 805 | i = 63; | 815 | i = 63; |
| 806 | break; | 816 | break; |
| 807 | }else{ | 817 | }else{ |
| 808 | av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | 818 | av_log(h->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", |
| 819 | h->c.mb_x, h->c.mb_y); | ||
| 809 | return -1; | 820 | return -1; |
| 810 | } | 821 | } |
| 811 | } | 822 | } |
| @@ -816,13 +827,13 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 4 unmodified lines | |||
| 816 | 827 | ||
| 817 | block[scan_table[i]] = level; | 828 | block[scan_table[i]] = level; |
| 818 | } | 829 | } |
| 819 | CLOSE_READER(re, &s->gb); | 830 | CLOSE_READER(re, &h->c.gb); |
| 820 | } | 831 | } |
| 821 | if (s->mb_intra) { | 832 | if (h->c.mb_intra) { |
| 822 | not_coded: | 833 | not_coded: |
| 823 | ff_mpeg4_pred_ac(s, block, n, dc_pred_dir); | 834 | ff_mpeg4_pred_ac(h, block, n, dc_pred_dir); |
| 824 | } | 835 | } |
| 825 | s->block_last_index[n] = i; | 836 | h->c.block_last_index[n] = i; |
| 826 | 837 | ||
| 827 | return 0; | 838 | return 0; |
| 828 | } | 839 | } |
| @@ -830,17 +841,17 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 1 unmodified line | |||
| 830 | void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr) | 841 | void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr) |
| 831 | { | 842 | { |
| 832 | const VLCElem *const mv_vlc = mv_tables[ms->mv_table_index]; | 843 | const VLCElem *const mv_vlc = mv_tables[ms->mv_table_index]; |
| 833 | MpegEncContext *const s = &ms->m; | 844 | H263DecContext *const h = &ms->h; |
| 834 | int sym, mx, my; | 845 | int sym, mx, my; |
| 835 | 846 | ||
| 836 | sym = get_vlc2(&s->gb, mv_vlc, MV_VLC_BITS, 2); | 847 | sym = get_vlc2(&h->c.gb, mv_vlc, MV_VLC_BITS, 2); |
| 837 | if (sym) { | 848 | if (sym) { |
| 838 | mx = sym >> 8; | 849 | mx = sym >> 8; |
| 839 | my = sym & 0xFF; | 850 | my = sym & 0xFF; |
| 840 | } else { | 851 | } else { |
| 841 | /* Escape */ | 852 | /* Escape */ |
| 842 | mx = get_bits(&s->gb, 6); | 853 | mx = get_bits(&h->c.gb, 6); |
| 843 | my = get_bits(&s->gb, 6); | 854 | my = get_bits(&h->c.gb, 6); |
| 844 | } | 855 | } |
| 845 | 856 | ||
| 846 | mx += *mx_ptr - 32; | 857 | mx += *mx_ptr - 32; |
| @@ -23,13 +23,14 @@ · 22 unmodified lines | |||
| 23 | #define AVCODEC_MSMPEG4DEC_H | 23 | #define AVCODEC_MSMPEG4DEC_H |
| 24 | 24 | ||
| 25 | #include "avcodec.h" | 25 | #include "avcodec.h" |
| 26 | #include "h263dec.h" | ||
| 26 | #include "mpegvideo.h" | 27 | #include "mpegvideo.h" |
| 27 | 28 | ||
| 28 | #define INTER_INTRA_VLC_BITS 3 | 29 | #define INTER_INTRA_VLC_BITS 3 |
| 29 | #define MB_NON_INTRA_VLC_BITS 9 | 30 | #define MB_NON_INTRA_VLC_BITS 9 |
| 30 | 31 | ||
| 31 | typedef struct MSMP4DecContext { | 32 | typedef struct MSMP4DecContext { |
| 32 | MpegEncContext m; | 33 | H263DecContext h; |
| 33 | int bit_rate; | 34 | int bit_rate; |
| 34 | int flipflop_rounding; | 35 | int flipflop_rounding; |
| 35 | int mv_table_index; | 36 | int mv_table_index; |
| @@ -42,18 +43,18 @@ typedef struct MSMP4DecContext { · 6 unmodified lines | |||
| 42 | int esc3_run_length; | 43 | int esc3_run_length; |
| 43 | } MSMP4DecContext; | 44 | } MSMP4DecContext; |
| 44 | 45 | ||
| 45 | static inline MSMP4DecContext *mpv_to_msmpeg4(MpegEncContext *s) | 46 | static inline MSMP4DecContext *mpv_to_msmpeg4(H263DecContext *const h) |
| 46 | { | 47 | { |
| 47 | // Only legal because no MSMPEG-4 decoder uses slice-threading. | 48 | // Only legal because no MSMPEG-4 decoder uses slice-threading. |
| 48 | return (MSMP4DecContext*)s; | 49 | return (MSMP4DecContext*)h; |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | extern const VLCElem *ff_mb_non_intra_vlc[4]; | 52 | extern const VLCElem *ff_mb_non_intra_vlc[4]; |
| 52 | extern VLCElem ff_inter_intra_vlc[8]; | 53 | extern VLCElem ff_inter_intra_vlc[8]; |
| 53 | 54 | ||
| 54 | int ff_msmpeg4_decode_init(AVCodecContext *avctx); | 55 | int ff_msmpeg4_decode_init(AVCodecContext *avctx); |
| 55 | int ff_msmpeg4_decode_picture_header(MpegEncContext *s); | 56 | int ff_msmpeg4_decode_picture_header(H263DecContext *const h); |
| 56 | int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size); | 57 | int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size); |
| 57 | void ff_msmpeg4_decode_motion(MSMP4DecContext *ms, int *mx_ptr, int *my_ptr); | 58 | void ff_msmpeg4_decode_motion(MSMP4DecContext *ms, int *mx_ptr, int *my_ptr); |
| 58 | int ff_msmpeg4_decode_block(MSMP4DecContext *ms, int16_t * block, | 59 | int ff_msmpeg4_decode_block(MSMP4DecContext *ms, int16_t * block, |
| 59 | int n, int coded, const uint8_t *scan_table); | 60 | int n, int coded, const uint8_t *scan_table); |
| @@ -33,7 +33,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, · 32 unmodified lines | |||
| 33 | const uint8_t *buffer, uint32_t size) | 33 | const uint8_t *buffer, uint32_t size) |
| 34 | { | 34 | { |
| 35 | Mpeg4DecContext *m = avctx->priv_data; | 35 | Mpeg4DecContext *m = avctx->priv_data; |
| 36 | MpegEncContext *s = &m->m; | 36 | MPVContext *const s = &m->h.c; |
| 37 | 37 | ||
| 38 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; | 38 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; |
| 39 | CUVIDPICPARAMS *pp = &ctx->pic_params; | 39 | CUVIDPICPARAMS *pp = &ctx->pic_params; |
| @@ -52,7 +52,7 @@ · 51 unmodified lines | |||
| 52 | #define DC_VLC_BITS 9 | 52 | #define DC_VLC_BITS 9 |
| 53 | 53 | ||
| 54 | typedef struct RVDecContext { | 54 | typedef struct RVDecContext { |
| 55 | MpegEncContext m; | 55 | H263DecContext h; |
| 56 | int sub_id; | 56 | int sub_id; |
| 57 | int orig_width, orig_height; | 57 | int orig_width, orig_height; |
| 58 | } RVDecContext; | 58 | } RVDecContext; |
| @@ -80,16 +80,16 @@ static const uint16_t rv_chrom_len_count[15] = { · 21 unmodified lines | |||
| 80 | 80 | ||
| 81 | static VLCElem rv_dc_lum[1472], rv_dc_chrom[992]; | 81 | static VLCElem rv_dc_lum[1472], rv_dc_chrom[992]; |
| 82 | 82 | ||
| 83 | int ff_rv_decode_dc(MpegEncContext *s, int n) | 83 | int ff_rv_decode_dc(H263DecContext *const h, int n) |
| 84 | { | 84 | { |
| 85 | int code; | 85 | int code; |
| 86 | 86 | ||
| 87 | if (n < 4) { | 87 | if (n < 4) { |
| 88 | code = get_vlc2(&s->gb, rv_dc_lum, DC_VLC_BITS, 2); | 88 | code = get_vlc2(&h->c.gb, rv_dc_lum, DC_VLC_BITS, 2); |
| 89 | } else { | 89 | } else { |
| 90 | code = get_vlc2(&s->gb, rv_dc_chrom, DC_VLC_BITS, 2); | 90 | code = get_vlc2(&h->c.gb, rv_dc_chrom, DC_VLC_BITS, 2); |
| 91 | if (code < 0) { | 91 | if (code < 0) { |
| 92 | av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n"); | 92 | av_log(h->c.avctx, AV_LOG_ERROR, "chroma dc error\n"); |
| 93 | return -1; | 93 | return -1; |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| @@ -97,59 +97,59 @@ int ff_rv_decode_dc(MpegEncContext *s, int n) · 1 unmodified line | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | /* read RV 1.0 compatible frame header */ | 99 | /* read RV 1.0 compatible frame header */ |
| 100 | static int rv10_decode_picture_header(MpegEncContext *s) | 100 | static int rv10_decode_picture_header(H263DecContext *const h) |
| 101 | { | 101 | { |
| 102 | int mb_count, pb_frame, marker, mb_xy; | 102 | int mb_count, pb_frame, marker, mb_xy; |
| 103 | 103 | ||
| 104 | marker = get_bits1(&s->gb); | 104 | marker = get_bits1(&h->c.gb); |
| 105 | 105 | ||
| 106 | if (get_bits1(&s->gb)) | 106 | if (get_bits1(&h->c.gb)) |
| 107 | s->pict_type = AV_PICTURE_TYPE_P; | 107 | h->c.pict_type = AV_PICTURE_TYPE_P; |
| 108 | else | 108 | else |
| 109 | s->pict_type = AV_PICTURE_TYPE_I; | 109 | h->c.pict_type = AV_PICTURE_TYPE_I; |
| 110 | 110 | ||
| 111 | if (!marker) | 111 | if (!marker) |
| 112 | av_log(s->avctx, AV_LOG_ERROR, "marker missing\n"); | 112 | av_log(h->c.avctx, AV_LOG_ERROR, "marker missing\n"); |
| 113 | 113 | ||
| 114 | pb_frame = get_bits1(&s->gb); | 114 | pb_frame = get_bits1(&h->c.gb); |
| 115 | 115 | ||
| 116 | ff_dlog(s->avctx, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame); | 116 | ff_dlog(h->c.avctx, "pict_type=%d pb_frame=%d\n", h->c.pict_type, pb_frame); |
| 117 | 117 | ||
| 118 | if (pb_frame) { | 118 | if (pb_frame) { |
| 119 | avpriv_request_sample(s->avctx, "PB-frame"); | 119 | avpriv_request_sample(h->c.avctx, "PB-frame"); |
| 120 | return AVERROR_PATCHWELCOME; | 120 | return AVERROR_PATCHWELCOME; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | s->qscale = get_bits(&s->gb, 5); | 123 | h->c.qscale = get_bits(&h->c.gb, 5); |
| 124 | if (s->qscale == 0) { | 124 | if (h->c.qscale == 0) { |
| 125 | av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); | 125 | av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); |
| 126 | return AVERROR_INVALIDDATA; | 126 | return AVERROR_INVALIDDATA; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 129 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 130 | if (s->rv10_version == 3) { | 130 | if (h->c.rv10_version == 3) { |
| 131 | /* specific MPEG like DC coding not used */ | 131 | /* specific MPEG like DC coding not used */ |
| 132 | s->last_dc[0] = get_bits(&s->gb, 8); | 132 | h->c.last_dc[0] = get_bits(&h->c.gb, 8); |
| 133 | s->last_dc[1] = get_bits(&s->gb, 8); | 133 | h->c.last_dc[1] = get_bits(&h->c.gb, 8); |
| 134 | s->last_dc[2] = get_bits(&s->gb, 8); | 134 | h->c.last_dc[2] = get_bits(&h->c.gb, 8); |
| 135 | ff_dlog(s->avctx, "DC:%d %d %d\n", s->last_dc[0], | 135 | ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0], |
| 136 | s->last_dc[1], s->last_dc[2]); | 136 | h->c.last_dc[1], h->c.last_dc[2]); |
| 137 | } | 137 | } |
| 138 | } | 138 | } |
| 139 | /* if multiple packets per frame are sent, the position at which | 139 | /* if multiple packets per frame are sent, the position at which |
| 140 | * to display the macroblocks is coded here */ | 140 | * to display the macroblocks is coded here */ |
| 141 | 141 | ||
| 142 | mb_xy = s->mb_x + s->mb_y * s->mb_width; | 142 | mb_xy = h->c.mb_x + h->c.mb_y * h->c.mb_width; |
| 143 | if (show_bits(&s->gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) { | 143 | if (show_bits(&h->c.gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) { |
| 144 | s->mb_x = get_bits(&s->gb, 6); /* mb_x */ | 144 | h->c.mb_x = get_bits(&h->c.gb, 6); /* mb_x */ |
| 145 | s->mb_y = get_bits(&s->gb, 6); /* mb_y */ | 145 | h->c.mb_y = get_bits(&h->c.gb, 6); /* mb_y */ |
| 146 | mb_count = get_bits(&s->gb, 12); | 146 | mb_count = get_bits(&h->c.gb, 12); |
| 147 | } else { | 147 | } else { |
| 148 | s->mb_x = 0; | 148 | h->c.mb_x = 0; |
| 149 | s->mb_y = 0; | 149 | h->c.mb_y = 0; |
| 150 | mb_count = s->mb_width * s->mb_height; | 150 | mb_count = h->c.mb_width * h->c.mb_height; |
| 151 | } | 151 | } |
| 152 | skip_bits(&s->gb, 3); /* ignored */ | 152 | skip_bits(&h->c.gb, 3); /* ignored */ |
| 153 | 153 | ||
| 154 | return mb_count; | 154 | return mb_count; |
| 155 | } | 155 | } |
| @@ -159,151 +159,151 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size) · 3 unmodified lines | |||
| 159 | static const enum AVPictureType pict_types[] = | 159 | static const enum AVPictureType pict_types[] = |
| 160 | { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */, | 160 | { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */, |
| 161 | AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B }; | 161 | AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B }; |
| 162 | MpegEncContext *s = &rv->m; | 162 | H263DecContext *const h = &rv->h; |
| 163 | int seq, mb_pos, ret; | 163 | int seq, mb_pos, ret; |
| 164 | int rpr_max; | 164 | int rpr_max; |
| 165 | 165 | ||
| 166 | s->pict_type = pict_types[get_bits(&s->gb, 2)]; | 166 | h->c.pict_type = pict_types[get_bits(&h->c.gb, 2)]; |
| 167 | 167 | ||
| 168 | if (s->low_delay && s->pict_type == AV_PICTURE_TYPE_B) { | 168 | if (h->c.low_delay && h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 169 | av_log(s->avctx, AV_LOG_ERROR, "low delay B\n"); | 169 | av_log(h->c.avctx, AV_LOG_ERROR, "low delay B\n"); |
| 170 | return -1; | 170 | return -1; |
| 171 | } | 171 | } |
| 172 | if (!s->last_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) { | 172 | if (!h->c.last_pic.ptr && h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 173 | av_log(s->avctx, AV_LOG_ERROR, "early B-frame\n"); | 173 | av_log(h->c.avctx, AV_LOG_ERROR, "early B-frame\n"); |
| 174 | return AVERROR_INVALIDDATA; | 174 | return AVERROR_INVALIDDATA; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | if (get_bits1(&s->gb)) { | 177 | if (get_bits1(&h->c.gb)) { |
| 178 | av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n"); | 178 | av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n"); |
| 179 | return AVERROR_INVALIDDATA; | 179 | return AVERROR_INVALIDDATA; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | s->qscale = get_bits(&s->gb, 5); | 182 | h->c.qscale = get_bits(&h->c.gb, 5); |
| 183 | if (s->qscale == 0) { | 183 | if (h->c.qscale == 0) { |
| 184 | av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); | 184 | av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); |
| 185 | return AVERROR_INVALIDDATA; | 185 | return AVERROR_INVALIDDATA; |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | if (RV_GET_MINOR_VER(rv->sub_id) >= 2) | 188 | if (RV_GET_MINOR_VER(rv->sub_id) >= 2) |
| 189 | s->loop_filter = get_bits1(&s->gb) && !s->avctx->lowres; | 189 | h->c.loop_filter = get_bits1(&h->c.gb) && !h->c.avctx->lowres; |
| 190 | 190 | ||
| 191 | if (RV_GET_MINOR_VER(rv->sub_id) <= 1) | 191 | if (RV_GET_MINOR_VER(rv->sub_id) <= 1) |
| 192 | seq = get_bits(&s->gb, 8) << 7; | 192 | seq = get_bits(&h->c.gb, 8) << 7; |
| 193 | else | 193 | else |
| 194 | seq = get_bits(&s->gb, 13) << 2; | 194 | seq = get_bits(&h->c.gb, 13) << 2; |
| 195 | 195 | ||
| 196 | rpr_max = s->avctx->extradata[1] & 7; | 196 | rpr_max = h->c.avctx->extradata[1] & 7; |
| 197 | if (rpr_max) { | 197 | if (rpr_max) { |
| 198 | int f, new_w, new_h; | 198 | int f, new_w, new_h; |
| 199 | int rpr_bits = av_log2(rpr_max) + 1; | 199 | int rpr_bits = av_log2(rpr_max) + 1; |
| 200 | 200 | ||
| 201 | f = get_bits(&s->gb, rpr_bits); | 201 | f = get_bits(&h->c.gb, rpr_bits); |
| 202 | 202 | ||
| 203 | if (f) { | 203 | if (f) { |
| 204 | if (s->avctx->extradata_size < 8 + 2 * f) { | 204 | if (h->c.avctx->extradata_size < 8 + 2 * f) { |
| 205 | av_log(s->avctx, AV_LOG_ERROR, "Extradata too small.\n"); | 205 | av_log(h->c.avctx, AV_LOG_ERROR, "Extradata too small.\n"); |
| 206 | return AVERROR_INVALIDDATA; | 206 | return AVERROR_INVALIDDATA; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | new_w = 4 * s->avctx->extradata[6 + 2 * f]; | 209 | new_w = 4 * h->c.avctx->extradata[6 + 2 * f]; |
| 210 | new_h = 4 * s->avctx->extradata[7 + 2 * f]; | 210 | new_h = 4 * h->c.avctx->extradata[7 + 2 * f]; |
| 211 | } else { | 211 | } else { |
| 212 | new_w = rv->orig_width; | 212 | new_w = rv->orig_width; |
| 213 | new_h = rv->orig_height; | 213 | new_h = rv->orig_height; |
| 214 | } | 214 | } |
| 215 | if (new_w != s->width || new_h != s->height || !s->context_initialized) { | 215 | if (new_w != h->c.width || new_h != h->c.height || !h->c.context_initialized) { |
| 216 | AVRational old_aspect = s->avctx->sample_aspect_ratio; | 216 | AVRational old_aspect = h->c.avctx->sample_aspect_ratio; |
| 217 | av_log(s->avctx, AV_LOG_DEBUG, | 217 | av_log(h->c.avctx, AV_LOG_DEBUG, |
| 218 | "attempting to change resolution to %dx%d\n", new_w, new_h); | 218 | "attempting to change resolution to %dx%d\n", new_w, new_h); |
| 219 | if (av_image_check_size(new_w, new_h, 0, s->avctx) < 0) | 219 | if (av_image_check_size(new_w, new_h, 0, h->c.avctx) < 0) |
| 220 | return AVERROR_INVALIDDATA; | 220 | return AVERROR_INVALIDDATA; |
| 221 | 221 | ||
| 222 | if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8) | 222 | if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8) |
| 223 | return AVERROR_INVALIDDATA; | 223 | return AVERROR_INVALIDDATA; |
| 224 | 224 | ||
| 225 | ff_mpv_common_end(s); | 225 | ff_mpv_common_end(&h->c); |
| 226 | 226 | ||
| 227 | // attempt to keep aspect during typical resolution switches | 227 | // attempt to keep aspect during typical resolution switches |
| 228 | if (!old_aspect.num) | 228 | if (!old_aspect.num) |
| 229 | old_aspect = (AVRational){1, 1}; | 229 | old_aspect = (AVRational){1, 1}; |
| 230 | if (2 * (int64_t)new_w * s->height == (int64_t)new_h * s->width) | 230 | if (2 * (int64_t)new_w * h->c.height == (int64_t)new_h * h->c.width) |
| 231 | s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1}); | 231 | h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1}); |
| 232 | if ((int64_t)new_w * s->height == 2 * (int64_t)new_h * s->width) | 232 | if ((int64_t)new_w * h->c.height == 2 * (int64_t)new_h * h->c.width) |
| 233 | s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2}); | 233 | h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2}); |
| 234 | 234 | ||
| 235 | ret = ff_set_dimensions(s->avctx, new_w, new_h); | 235 | ret = ff_set_dimensions(h->c.avctx, new_w, new_h); |
| 236 | if (ret < 0) | 236 | if (ret < 0) |
| 237 | return ret; | 237 | return ret; |
| 238 | 238 | ||
| 239 | s->width = new_w; | 239 | h->c.width = new_w; |
| 240 | s->height = new_h; | 240 | h->c.height = new_h; |
| 241 | if ((ret = ff_mpv_common_init(s)) < 0) | 241 | if ((ret = ff_mpv_common_init(&h->c)) < 0) |
| 242 | return ret; | 242 | return ret; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | 245 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { |
| 246 | av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max); | 246 | av_log(h->c.avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max); |
| 247 | } | 247 | } |
| 248 | } | 248 | } |
| 249 | if (av_image_check_size(s->width, s->height, 0, s->avctx) < 0) | 249 | if (av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx) < 0) |
| 250 | return AVERROR_INVALIDDATA; | 250 | return AVERROR_INVALIDDATA; |
| 251 | 251 | ||
| 252 | mb_pos = ff_h263_decode_mba(s); | 252 | mb_pos = ff_h263_decode_mba(h); |
| 253 | 253 | ||
| 254 | seq |= s->time & ~0x7FFF; | 254 | seq |= h->c.time & ~0x7FFF; |
| 255 | if (seq - s->time > 0x4000) | 255 | if (seq - h->c.time > 0x4000) |
| 256 | seq -= 0x8000; | 256 | seq -= 0x8000; |
| 257 | if (seq - s->time < -0x4000) | 257 | if (seq - h->c.time < -0x4000) |
| 258 | seq += 0x8000; | 258 | seq += 0x8000; |
| 259 | 259 | ||
| 260 | if (seq != s->time) { | 260 | if (seq != h->c.time) { |
| 261 | if (s->pict_type != AV_PICTURE_TYPE_B) { | 261 | if (h->c.pict_type != AV_PICTURE_TYPE_B) { |
| 262 | s->time = seq; | 262 | h->c.time = seq; |
| 263 | s->pp_time = s->time - s->last_non_b_time; | 263 | h->c.pp_time = h->c.time - h->c.last_non_b_time; |
| 264 | s->last_non_b_time = s->time; | 264 | h->c.last_non_b_time = h->c.time; |
| 265 | } else { | 265 | } else { |
| 266 | s->time = seq; | 266 | h->c.time = seq; |
| 267 | s->pb_time = s->pp_time - (s->last_non_b_time - s->time); | 267 | h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time); |
| 268 | } | 268 | } |
| 269 | } | 269 | } |
| 270 | if (s->pict_type == AV_PICTURE_TYPE_B) { | 270 | if (h->c.pict_type == AV_PICTURE_TYPE_B) { |
| 271 | if (s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0) { | 271 | if (h->c.pp_time <=h->c.pb_time || h->c.pp_time <= h->c.pp_time - h->c.pb_time || h->c.pp_time<=0) { |
| 272 | av_log(s->avctx, AV_LOG_DEBUG, | 272 | av_log(h->c.avctx, AV_LOG_DEBUG, |
| 273 | "messed up order, possible from seeking? skipping current B-frame\n"); | 273 | "messed up order, possible from seeking? skipping current B-frame\n"); |
| 274 | #define ERROR_SKIP_FRAME -123 | 274 | #define ERROR_SKIP_FRAME -123 |
| 275 | return ERROR_SKIP_FRAME; | 275 | return ERROR_SKIP_FRAME; |
| 276 | } | 276 | } |
| 277 | ff_mpeg4_init_direct_mv(s); | 277 | ff_mpeg4_init_direct_mv(&h->c); |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | s->no_rounding = get_bits1(&s->gb); | 280 | h->c.no_rounding = get_bits1(&h->c.gb); |
| 281 | 281 | ||
| 282 | if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B) | 282 | if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && h->c.pict_type == AV_PICTURE_TYPE_B) |
| 283 | // binary decoder reads 3+2 bits here but they don't seem to be used | 283 | // binary decoder reads 3+2 bits here but they don't seem to be used |
| 284 | skip_bits(&s->gb, 5); | 284 | skip_bits(&h->c.gb, 5); |
| 285 | 285 | ||
| 286 | s->h263_aic = s->pict_type == AV_PICTURE_TYPE_I; | 286 | h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I; |
| 287 | if (s->h263_aic) { | 287 | if (h->c.h263_aic) { |
| 288 | s->y_dc_scale_table = | 288 | h->c.y_dc_scale_table = |
| 289 | s->c_dc_scale_table = ff_aic_dc_scale_table; | 289 | h->c.c_dc_scale_table = ff_aic_dc_scale_table; |
| 290 | } else { | 290 | } else { |
| 291 | s->y_dc_scale_table = | 291 | h->c.y_dc_scale_table = |
| 292 | s->c_dc_scale_table = ff_mpeg1_dc_scale_table; | 292 | h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table; |
| 293 | } | 293 | } |
| 294 | if (!s->avctx->lowres) | 294 | if (!h->c.avctx->lowres) |
| 295 | s->loop_filter = 1; | 295 | h->c.loop_filter = 1; |
| 296 | 296 | ||
| 297 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | 297 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { |
| 298 | av_log(s->avctx, AV_LOG_INFO, | 298 | av_log(h->c.avctx, AV_LOG_INFO, |
| 299 | "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n", | 299 | "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n", |
| 300 | seq, s->mb_x, s->mb_y, s->pict_type, s->qscale, | 300 | seq, h->c.mb_x, h->c.mb_y, h->c.pict_type, h->c.qscale, |
| 301 | s->no_rounding); | 301 | h->c.no_rounding); |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | av_assert0(s->pict_type != AV_PICTURE_TYPE_B || !s->low_delay); | 304 | av_assert0(h->c.pict_type != AV_PICTURE_TYPE_B || !h->c.low_delay); |
| 305 | 305 | ||
| 306 | return s->mb_width * s->mb_height - mb_pos; | 306 | return h->c.mb_width * h->c.mb_height - mb_pos; |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | static av_cold void rv10_build_vlc(VLCElem vlc[], int table_size, | 309 | static av_cold void rv10_build_vlc(VLCElem vlc[], int table_size, |
| @@ -351,7 +351,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) · 41 unmodified lines | |||
| 351 | { | 351 | { |
| 352 | static AVOnce init_static_once = AV_ONCE_INIT; | 352 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 353 | RVDecContext *rv = avctx->priv_data; | 353 | RVDecContext *rv = avctx->priv_data; |
| 354 | MpegEncContext *s = &rv->m; | 354 | H263DecContext *const h = &rv->h; |
| 355 | int major_ver, minor_ver, micro_ver, ret; | 355 | int major_ver, minor_ver, micro_ver, ret; |
| 356 | 356 | ||
| 357 | if (avctx->extradata_size < 8) { | 357 | if (avctx->extradata_size < 8) { |
| @@ -369,11 +369,11 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) · 11 unmodified lines | |||
| 369 | rv->orig_width = avctx->coded_width; | 369 | rv->orig_width = avctx->coded_width; |
| 370 | rv->orig_height = avctx->coded_height; | 370 | rv->orig_height = avctx->coded_height; |
| 371 | 371 | ||
| 372 | s->h263_long_vectors = avctx->extradata[3] & 1; | 372 | h->c.h263_long_vectors = avctx->extradata[3] & 1; |
| 373 | rv->sub_id = AV_RB32A(avctx->extradata + 4); | 373 | rv->sub_id = AV_RB32A(avctx->extradata + 4); |
| 374 | if (avctx->codec_id == AV_CODEC_ID_RV20) { | 374 | if (avctx->codec_id == AV_CODEC_ID_RV20) { |
| 375 | s->modified_quant = 1; | 375 | h->c.modified_quant = 1; |
| 376 | s->chroma_qscale_table = ff_h263_chroma_qscale_table; | 376 | h->c.chroma_qscale_table = ff_h263_chroma_qscale_table; |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | major_ver = RV_GET_MAJOR_VER(rv->sub_id); | 379 | major_ver = RV_GET_MAJOR_VER(rv->sub_id); |
| @@ -382,12 +382,12 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) · 2 unmodified lines | |||
| 382 | 382 | ||
| 383 | switch (major_ver) { | 383 | switch (major_ver) { |
| 384 | case 1: | 384 | case 1: |
| 385 | s->rv10_version = micro_ver ? 3 : 1; | 385 | h->c.rv10_version = micro_ver ? 3 : 1; |
| 386 | s->obmc = micro_ver == 2; | 386 | h->c.obmc = micro_ver == 2; |
| 387 | break; | 387 | break; |
| 388 | case 2: | 388 | case 2: |
| 389 | if (minor_ver >= 2) { | 389 | if (minor_ver >= 2) { |
| 390 | s->low_delay = 0; | 390 | h->c.low_delay = 0; |
| 391 | avctx->has_b_frames = 1; | 391 | avctx->has_b_frames = 1; |
| 392 | } | 392 | } |
| 393 | break; | 393 | break; |
| @@ -412,126 +412,126 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 18 unmodified lines | |||
| 412 | int buf_size, int buf_size2, int whole_size) | 412 | int buf_size, int buf_size2, int whole_size) |
| 413 | { | 413 | { |
| 414 | RVDecContext *rv = avctx->priv_data; | 414 | RVDecContext *rv = avctx->priv_data; |
| 415 | MpegEncContext *s = &rv->m; | 415 | H263DecContext *const h = &rv->h; |
| 416 | int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret; | 416 | int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret; |
| 417 | 417 | ||
| 418 | active_bits_size = buf_size * 8; | 418 | active_bits_size = buf_size * 8; |
| 419 | init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8); | 419 | init_get_bits(&h->c.gb, buf, FFMAX(buf_size, buf_size2) * 8); |
| 420 | if (s->codec_id == AV_CODEC_ID_RV10) | 420 | if (h->c.codec_id == AV_CODEC_ID_RV10) |
| 421 | mb_count = rv10_decode_picture_header(s); | 421 | mb_count = rv10_decode_picture_header(h); |
| 422 | else | 422 | else |
| 423 | mb_count = rv20_decode_picture_header(rv, whole_size); | 423 | mb_count = rv20_decode_picture_header(rv, whole_size); |
| 424 | if (mb_count < 0) { | 424 | if (mb_count < 0) { |
| 425 | if (mb_count != ERROR_SKIP_FRAME) | 425 | if (mb_count != ERROR_SKIP_FRAME) |
| 426 | av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n"); | 426 | av_log(h->c.avctx, AV_LOG_ERROR, "HEADER ERROR\n"); |
| 427 | return AVERROR_INVALIDDATA; | 427 | return AVERROR_INVALIDDATA; |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | if (s->mb_x >= s->mb_width || | 430 | if (h->c.mb_x >= h->c.mb_width || |
| 431 | s->mb_y >= s->mb_height) { | 431 | h->c.mb_y >= h->c.mb_height) { |
| 432 | av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y); | 432 | av_log(h->c.avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", h->c.mb_x, h->c.mb_y); |
| 433 | return AVERROR_INVALIDDATA; | 433 | return AVERROR_INVALIDDATA; |
| 434 | } | 434 | } |
| 435 | mb_pos = s->mb_y * s->mb_width + s->mb_x; | 435 | mb_pos = h->c.mb_y * h->c.mb_width + h->c.mb_x; |
| 436 | left = s->mb_width * s->mb_height - mb_pos; | 436 | left = h->c.mb_width * h->c.mb_height - mb_pos; |
| 437 | if (mb_count > left) { | 437 | if (mb_count > left) { |
| 438 | av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n"); | 438 | av_log(h->c.avctx, AV_LOG_ERROR, "COUNT ERROR\n"); |
| 439 | return AVERROR_INVALIDDATA; | 439 | return AVERROR_INVALIDDATA; |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | if (whole_size < s->mb_width * s->mb_height / 8) | 442 | if (whole_size < h->c.mb_width * h->c.mb_height / 8) |
| 443 | return AVERROR_INVALIDDATA; | 443 | return AVERROR_INVALIDDATA; |
| 444 | 444 | ||
| 445 | if ((s->mb_x == 0 && s->mb_y == 0) || !s->cur_pic.ptr) { | 445 | if ((h->c.mb_x == 0 && h->c.mb_y == 0) || !h->c.cur_pic.ptr) { |
| 446 | // FIXME write parser so we always have complete frames? | 446 | // FIXME write parser so we always have complete frames? |
| 447 | if (s->cur_pic.ptr) { | 447 | if (h->c.cur_pic.ptr) { |
| 448 | ff_er_frame_end(&s->er, NULL); | 448 | ff_er_frame_end(&h->c.er, NULL); |
| 449 | ff_mpv_frame_end(s); | 449 | ff_mpv_frame_end(&h->c); |
| 450 | s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0; | 450 | h->c.mb_x = h->c.mb_y = h->c.resync_mb_x = h->c.resync_mb_y = 0; |
| 451 | } | 451 | } |
| 452 | if ((ret = ff_mpv_frame_start(s, avctx)) < 0) | 452 | if ((ret = ff_mpv_frame_start(&h->c, avctx)) < 0) |
| 453 | return ret; | 453 | return ret; |
| 454 | ff_mpeg_er_frame_start(s); | 454 | ff_mpeg_er_frame_start(&h->c); |
| 455 | } else { | 455 | } else { |
| 456 | if (s->cur_pic.ptr->f->pict_type != s->pict_type) { | 456 | if (h->c.cur_pic.ptr->f->pict_type != h->c.pict_type) { |
| 457 | av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n"); | 457 | av_log(h->c.avctx, AV_LOG_ERROR, "Slice type mismatch\n"); |
| 458 | return AVERROR_INVALIDDATA; | 458 | return AVERROR_INVALIDDATA; |
| 459 | } | 459 | } |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | 462 | ||
| 463 | ff_dlog(avctx, "qscale=%d\n", s->qscale); | 463 | ff_dlog(avctx, "qscale=%d\n", h->c.qscale); |
| 464 | 464 | ||
| 465 | /* default quantization values */ | 465 | /* default quantization values */ |
| 466 | if (s->codec_id == AV_CODEC_ID_RV10) { | 466 | if (h->c.codec_id == AV_CODEC_ID_RV10) { |
| 467 | if (s->mb_y == 0) | 467 | if (h->c.mb_y == 0) |
| 468 | s->first_slice_line = 1; | 468 | h->c.first_slice_line = 1; |
| 469 | } else { | 469 | } else { |
| 470 | s->first_slice_line = 1; | 470 | h->c.first_slice_line = 1; |
| 471 | s->resync_mb_x = s->mb_x; | 471 | h->c.resync_mb_x = h->c.mb_x; |
| 472 | } | 472 | } |
| 473 | start_mb_x = s->mb_x; | 473 | start_mb_x = h->c.mb_x; |
| 474 | s->resync_mb_y = s->mb_y; | 474 | h->c.resync_mb_y = h->c.mb_y; |
| 475 | 475 | ||
| 476 | ff_set_qscale(s, s->qscale); | 476 | ff_set_qscale(&h->c, h->c.qscale); |
| 477 | 477 | ||
| 478 | s->rv10_first_dc_coded[0] = 0; | 478 | h->c.rv10_first_dc_coded[0] = 0; |
| 479 | s->rv10_first_dc_coded[1] = 0; | 479 | h->c.rv10_first_dc_coded[1] = 0; |
| 480 | s->rv10_first_dc_coded[2] = 0; | 480 | h->c.rv10_first_dc_coded[2] = 0; |
| 481 | ff_init_block_index(s); | 481 | ff_init_block_index(&h->c); |
| 482 | 482 | ||
| 483 | /* decode each macroblock */ | 483 | /* decode each macroblock */ |
| 484 | for (s->mb_num_left = mb_count; s->mb_num_left > 0; s->mb_num_left--) { | 484 | for (h->c.mb_num_left = mb_count; h->c.mb_num_left > 0; h->c.mb_num_left--) { |
| 485 | int ret; | 485 | int ret; |
| 486 | ff_update_block_index(s, 8, s->avctx->lowres, 1); | 486 | ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1); |
| 487 | ff_tlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y); | 487 | ff_tlog(avctx, "**mb x=%d y=%d\n", h->c.mb_x, h->c.mb_y); |
| 488 | 488 | ||
| 489 | s->mv_dir = MV_DIR_FORWARD; | 489 | h->c.mv_dir = MV_DIR_FORWARD; |
| 490 | s->mv_type = MV_TYPE_16X16; | 490 | h->c.mv_type = MV_TYPE_16X16; |
| 491 | ret = ff_h263_decode_mb(s, s->block); | 491 | ret = ff_h263_decode_mb(h, h->c.block); |
| 492 | 492 | ||
| 493 | // Repeat the slice end check from ff_h263_decode_mb with our active | 493 | // Repeat the slice end check from ff_h263_decode_mb with our active |
| 494 | // bitstream size | 494 | // bitstream size |
| 495 | if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&s->gb)) { | 495 | if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->c.gb)) { |
| 496 | int v = show_bits(&s->gb, 16); | 496 | int v = show_bits(&h->c.gb, 16); |
| 497 | 497 | ||
| 498 | if (get_bits_count(&s->gb) + 16 > active_bits_size) | 498 | if (get_bits_count(&h->c.gb) + 16 > active_bits_size) |
| 499 | v >>= get_bits_count(&s->gb) + 16 - active_bits_size; | 499 | v >>= get_bits_count(&h->c.gb) + 16 - active_bits_size; |
| 500 | 500 | ||
| 501 | if (!v) | 501 | if (!v) |
| 502 | ret = SLICE_END; | 502 | ret = SLICE_END; |
| 503 | } | 503 | } |
| 504 | if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) && | 504 | if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->c.gb) && |
| 505 | 8 * buf_size2 >= get_bits_count(&s->gb)) { | 505 | 8 * buf_size2 >= get_bits_count(&h->c.gb)) { |
| 506 | active_bits_size = buf_size2 * 8; | 506 | active_bits_size = buf_size2 * 8; |
| 507 | av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", | 507 | av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", |
| 508 | 8 * buf_size, active_bits_size); | 508 | 8 * buf_size, active_bits_size); |
| 509 | ret = SLICE_OK; | 509 | ret = SLICE_OK; |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) { | 512 | if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->c.gb)) { |
| 513 | av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, | 513 | av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x, |
| 514 | s->mb_y); | 514 | h->c.mb_y); |
| 515 | return AVERROR_INVALIDDATA; | 515 | return AVERROR_INVALIDDATA; |
| 516 | } | 516 | } |
| 517 | if (s->pict_type != AV_PICTURE_TYPE_B) | 517 | if (h->c.pict_type != AV_PICTURE_TYPE_B) |
| 518 | ff_h263_update_motion_val(s); | 518 | ff_h263_update_motion_val(&h->c); |
| 519 | ff_mpv_reconstruct_mb(s, s->block); | 519 | ff_mpv_reconstruct_mb(&h->c, h->c.block); |
| 520 | if (s->loop_filter) | 520 | if (h->c.loop_filter) |
| 521 | ff_h263_loop_filter(s); | 521 | ff_h263_loop_filter(&h->c); |
| 522 | 522 | ||
| 523 | if (++s->mb_x == s->mb_width) { | 523 | if (++h->c.mb_x == h->c.mb_width) { |
| 524 | s->mb_x = 0; | 524 | h->c.mb_x = 0; |
| 525 | s->mb_y++; | 525 | h->c.mb_y++; |
| 526 | ff_init_block_index(s); | 526 | ff_init_block_index(&h->c); |
| 527 | } | 527 | } |
| 528 | if (s->mb_x == s->resync_mb_x) | 528 | if (h->c.mb_x == h->c.resync_mb_x) |
| 529 | s->first_slice_line = 0; | 529 | h->c.first_slice_line = 0; |
| 530 | if (ret == SLICE_END) | 530 | if (ret == SLICE_END) |
| 531 | break; | 531 | break; |
| 532 | } | 532 | } |
| 533 | 533 | ||
| 534 | ff_er_add_slice(&s->er, start_mb_x, s->resync_mb_y, s->mb_x - 1, s->mb_y, | 534 | ff_er_add_slice(&h->c.er, start_mb_x, h->c.resync_mb_y, h->c.mb_x - 1, h->c.mb_y, |
| 535 | ER_MB_END); | 535 | ER_MB_END); |
| 536 | 536 | ||
| 537 | return active_bits_size; | 537 | return active_bits_size; |
| @@ -21,8 +21,8 @@ · 20 unmodified lines | |||
| 21 | #ifndef AVCODEC_RV10DEC_H | 21 | #ifndef AVCODEC_RV10DEC_H |
| 22 | #define AVCODEC_RV10DEC_H | 22 | #define AVCODEC_RV10DEC_H |
| 23 | 23 | ||
| 24 | #include "mpegvideo.h" | 24 | struct H263DecContext; |
| 25 | 25 | ||
| 26 | int ff_rv_decode_dc(MpegEncContext *s, int n); | 26 | int ff_rv_decode_dc(struct H263DecContext *const h, int n); |
| 27 | 27 | ||
| 28 | #endif /* AVCODEC_RV10DEC_H */ | 28 | #endif /* AVCODEC_RV10DEC_H */ |
| @@ -51,7 +51,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, · 50 unmodified lines | |||
| 51 | av_unused uint32_t size) | 51 | av_unused uint32_t size) |
| 52 | { | 52 | { |
| 53 | Mpeg4DecContext *ctx = avctx->priv_data; | 53 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 54 | MpegEncContext *s = &ctx->m; | 54 | MPVContext *const s = &ctx->h.c; |
| 55 | VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private; | 55 | VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private; |
| 56 | VAPictureParameterBufferMPEG4 pic_param; | 56 | VAPictureParameterBufferMPEG4 pic_param; |
| 57 | int i, err; | 57 | int i, err; |
| @@ -34,7 +34,7 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, · 33 unmodified lines | |||
| 34 | const uint8_t *buffer, uint32_t size) | 34 | const uint8_t *buffer, uint32_t size) |
| 35 | { | 35 | { |
| 36 | Mpeg4DecContext *ctx = avctx->priv_data; | 36 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 37 | MpegEncContext * const s = &ctx->m; | 37 | MPVContext *const s = &ctx->h.c; |
| 38 | MPVPicture *pic = s->cur_pic.ptr; | 38 | MPVPicture *pic = s->cur_pic.ptr; |
| 39 | struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private; | 39 | struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private; |
| 40 | VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4; | 40 | VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4; |
| @@ -44,7 +44,7 @@ void ff_mspel_motion(MpegEncContext *s, · 43 unmodified lines | |||
| 44 | int motion_x, int motion_y, int h); | 44 | int motion_x, int motion_y, int h); |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | static av_always_inline int wmv2_get_cbp_table_index(MpegEncContext *s, int cbp_index) | 47 | static av_always_inline int wmv2_get_cbp_table_index(int qscale, int cbp_index) |
| 48 | { | 48 | { |
| 49 | static const uint8_t map[3][3] = { | 49 | static const uint8_t map[3][3] = { |
| 50 | { 0, 2, 1 }, | 50 | { 0, 2, 1 }, |
| @@ -52,7 +52,7 @@ static av_always_inline int wmv2_get_cbp_table_index(MpegEncContext *s, int cbp_ · 1 unmodified line | |||
| 52 | { 2, 1, 0 }, | 52 | { 2, 1, 0 }, |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | return map[(s->qscale > 10) + (s->qscale > 20)][cbp_index]; | 55 | return map[(qscale > 10) + (qscale > 20)][cbp_index]; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | #endif /* AVCODEC_WMV2_H */ | 58 | #endif /* AVCODEC_WMV2_H */ |
| @@ -59,9 +59,9 @@ typedef struct WMV2DecContext { · 58 unmodified lines | |||
| 59 | static void wmv2_add_block(WMV2DecContext *w, int16_t *block1, | 59 | static void wmv2_add_block(WMV2DecContext *w, int16_t *block1, |
| 60 | uint8_t *dst, int stride, int n) | 60 | uint8_t *dst, int stride, int n) |
| 61 | { | 61 | { |
| 62 | MpegEncContext *const s = &w->ms.m; | 62 | H263DecContext *const h = &w->ms.h; |
| 63 | 63 | ||
| 64 | if (s->block_last_index[n] >= 0) { | 64 | if (h->c.block_last_index[n] >= 0) { |
| 65 | switch (w->abt_type_table[n]) { | 65 | switch (w->abt_type_table[n]) { |
| 66 | case 0: | 66 | case 0: |
| 67 | w->common.wdsp.idct_add(dst, stride, block1); | 67 | w->common.wdsp.idct_add(dst, stride, block1); |
| @@ -69,15 +69,15 @@ static void wmv2_add_block(WMV2DecContext *w, int16_t *block1, · 1 unmodified line | |||
| 69 | case 1: | 69 | case 1: |
| 70 | ff_simple_idct84_add(dst, stride, block1); | 70 | ff_simple_idct84_add(dst, stride, block1); |
| 71 | ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]); | 71 | ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]); |
| 72 | s->bdsp.clear_block(w->abt_block2[n]); | 72 | h->c.bdsp.clear_block(w->abt_block2[n]); |
| 73 | break; | 73 | break; |
| 74 | case 2: | 74 | case 2: |
| 75 | ff_simple_idct48_add(dst, stride, block1); | 75 | ff_simple_idct48_add(dst, stride, block1); |
| 76 | ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]); | 76 | ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]); |
| 77 | s->bdsp.clear_block(w->abt_block2[n]); | 77 | h->c.bdsp.clear_block(w->abt_block2[n]); |
| 78 | break; | 78 | break; |
| 79 | default: | 79 | default: |
| 80 | av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n"); | 80 | av_log(h->c.avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n"); |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | } | 83 | } |
| @@ -101,64 +101,63 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], · 17 unmodified lines | |||
| 101 | 101 | ||
| 102 | static int parse_mb_skip(WMV2DecContext *w) | 102 | static int parse_mb_skip(WMV2DecContext *w) |
| 103 | { | 103 | { |
| 104 | int mb_x, mb_y; | 104 | H263DecContext *const h = &w->ms.h; |
| 105 | int coded_mb_count = 0; | 105 | int coded_mb_count = 0; |
| 106 | MpegEncContext *const s = &w->ms.m; | 106 | uint32_t *const mb_type = h->c.cur_pic.mb_type; |
| 107 | uint32_t *const mb_type = s->cur_pic.mb_type; | ||
| 108 | 107 | ||
| 109 | w->skip_type = get_bits(&s->gb, 2); | 108 | w->skip_type = get_bits(&h->c.gb, 2); |
| 110 | switch (w->skip_type) { | 109 | switch (w->skip_type) { |
| 111 | case SKIP_TYPE_NONE: | 110 | case SKIP_TYPE_NONE: |
| 112 | for (mb_y = 0; mb_y < s->mb_height; mb_y++) | 111 | for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) |
| 113 | for (mb_x = 0; mb_x < s->mb_width; mb_x++) | 112 | for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) |
| 114 | mb_type[mb_y * s->mb_stride + mb_x] = | 113 | mb_type[mb_y * h->c.mb_stride + mb_x] = |
| 115 | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 114 | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 116 | break; | 115 | break; |
| 117 | case SKIP_TYPE_MPEG: | 116 | case SKIP_TYPE_MPEG: |
| 118 | if (get_bits_left(&s->gb) < s->mb_height * s->mb_width) | 117 | if (get_bits_left(&h->c.gb) < h->c.mb_height * h->c.mb_width) |
| 119 | return AVERROR_INVALIDDATA; | 118 | return AVERROR_INVALIDDATA; |
| 120 | for (mb_y = 0; mb_y < s->mb_height; mb_y++) | 119 | for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) |
| 121 | for (mb_x = 0; mb_x < s->mb_width; mb_x++) | 120 | for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) |
| 122 | mb_type[mb_y * s->mb_stride + mb_x] = | 121 | mb_type[mb_y * h->c.mb_stride + mb_x] = |
| 123 | (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 122 | (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 124 | break; | 123 | break; |
| 125 | case SKIP_TYPE_ROW: | 124 | case SKIP_TYPE_ROW: |
| 126 | for (mb_y = 0; mb_y < s->mb_height; mb_y++) { | 125 | for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) { |
| 127 | if (get_bits_left(&s->gb) < 1) | 126 | if (get_bits_left(&h->c.gb) < 1) |
| 128 | return AVERROR_INVALIDDATA; | 127 | return AVERROR_INVALIDDATA; |
| 129 | if (get_bits1(&s->gb)) { | 128 | if (get_bits1(&h->c.gb)) { |
| 130 | for (mb_x = 0; mb_x < s->mb_width; mb_x++) | 129 | for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) |
| 131 | mb_type[mb_y * s->mb_stride + mb_x] = | 130 | mb_type[mb_y * h->c.mb_stride + mb_x] = |
| 132 | MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 131 | MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 133 | } else { | 132 | } else { |
| 134 | for (mb_x = 0; mb_x < s->mb_width; mb_x++) | 133 | for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) |
| 135 | mb_type[mb_y * s->mb_stride + mb_x] = | 134 | mb_type[mb_y * h->c.mb_stride + mb_x] = |
| 136 | (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 135 | (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 137 | } | 136 | } |
| 138 | } | 137 | } |
| 139 | break; | 138 | break; |
| 140 | case SKIP_TYPE_COL: | 139 | case SKIP_TYPE_COL: |
| 141 | for (mb_x = 0; mb_x < s->mb_width; mb_x++) { | 140 | for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) { |
| 142 | if (get_bits_left(&s->gb) < 1) | 141 | if (get_bits_left(&h->c.gb) < 1) |
| 143 | return AVERROR_INVALIDDATA; | 142 | return AVERROR_INVALIDDATA; |
| 144 | if (get_bits1(&s->gb)) { | 143 | if (get_bits1(&h->c.gb)) { |
| 145 | for (mb_y = 0; mb_y < s->mb_height; mb_y++) | 144 | for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) |
| 146 | mb_type[mb_y * s->mb_stride + mb_x] = | 145 | mb_type[mb_y * h->c.mb_stride + mb_x] = |
| 147 | MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 146 | MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 148 | } else { | 147 | } else { |
| 149 | for (mb_y = 0; mb_y < s->mb_height; mb_y++) | 148 | for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) |
| 150 | mb_type[mb_y * s->mb_stride + mb_x] = | 149 | mb_type[mb_y * h->c.mb_stride + mb_x] = |
| 151 | (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | 150 | (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 152 | } | 151 | } |
| 153 | } | 152 | } |
| 154 | break; | 153 | break; |
| 155 | } | 154 | } |
| 156 | 155 | ||
| 157 | for (mb_y = 0; mb_y < s->mb_height; mb_y++) | 156 | for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) |
| 158 | for (mb_x = 0; mb_x < s->mb_width; mb_x++) | 157 | for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) |
| 159 | coded_mb_count += !IS_SKIP(mb_type[mb_y * s->mb_stride + mb_x]); | 158 | coded_mb_count += !IS_SKIP(mb_type[mb_y * h->c.mb_stride + mb_x]); |
| 160 | 159 | ||
| 161 | if (coded_mb_count > get_bits_left(&s->gb)) | 160 | if (coded_mb_count > get_bits_left(&h->c.gb)) |
| 162 | return AVERROR_INVALIDDATA; | 161 | return AVERROR_INVALIDDATA; |
| 163 | 162 | ||
| 164 | return 0; | 163 | return 0; |
| @@ -166,20 +165,20 @@ static int parse_mb_skip(WMV2DecContext *w) · 1 unmodified line | |||
| 166 | 165 | ||
| 167 | static int decode_ext_header(WMV2DecContext *w) | 166 | static int decode_ext_header(WMV2DecContext *w) |
| 168 | { | 167 | { |
| 169 | MpegEncContext *const s = &w->ms.m; | 168 | H263DecContext *const h = &w->ms.h; |
| 170 | GetBitContext gb; | 169 | GetBitContext gb; |
| 171 | int fps; | 170 | int fps; |
| 172 | int code; | 171 | int code; |
| 173 | 172 | ||
| 174 | if (s->avctx->extradata_size < 4) | 173 | if (h->c.avctx->extradata_size < 4) |
| 175 | return AVERROR_INVALIDDATA; | 174 | return AVERROR_INVALIDDATA; |
| 176 | 175 | ||
| 177 | init_get_bits(&gb, s->avctx->extradata, 32); | 176 | init_get_bits(&gb, h->c.avctx->extradata, 32); |
| 178 | 177 | ||
| 179 | fps = get_bits(&gb, 5); | 178 | fps = get_bits(&gb, 5); |
| 180 | w->ms.bit_rate = get_bits(&gb, 11) * 1024; | 179 | w->ms.bit_rate = get_bits(&gb, 11) * 1024; |
| 181 | w->mspel_bit = get_bits1(&gb); | 180 | w->mspel_bit = get_bits1(&gb); |
| 182 | s->loop_filter = get_bits1(&gb); | 181 | h->c.loop_filter = get_bits1(&gb); |
| 183 | w->abt_flag = get_bits1(&gb); | 182 | w->abt_flag = get_bits1(&gb); |
| 184 | w->j_type_bit = get_bits1(&gb); | 183 | w->j_type_bit = get_bits1(&gb); |
| 185 | w->top_left_mv_flag = get_bits1(&gb); | 184 | w->top_left_mv_flag = get_bits1(&gb); |
| @@ -189,36 +188,36 @@ static int decode_ext_header(WMV2DecContext *w) · 3 unmodified lines | |||
| 189 | if (code == 0) | 188 | if (code == 0) |
| 190 | return AVERROR_INVALIDDATA; | 189 | return AVERROR_INVALIDDATA; |
| 191 | 190 | ||
| 192 | s->slice_height = s->mb_height / code; | 191 | h->c.slice_height = h->c.mb_height / code; |
| 193 | 192 | ||
| 194 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) | 193 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) |
| 195 | av_log(s->avctx, AV_LOG_DEBUG, | 194 | av_log(h->c.avctx, AV_LOG_DEBUG, |
| 196 | "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, " | 195 | "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, " |
| 197 | "tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, " | 196 | "tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, " |
| 198 | "slices:%d\n", | 197 | "slices:%d\n", |
| 199 | fps, w->ms.bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, | 198 | fps, w->ms.bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, |
| 200 | w->top_left_mv_flag, w->per_mb_rl_bit, code, s->loop_filter, | 199 | w->top_left_mv_flag, w->per_mb_rl_bit, code, h->c.loop_filter, |
| 201 | code); | 200 | code); |
| 202 | return 0; | 201 | return 0; |
| 203 | } | 202 | } |
| 204 | 203 | ||
| 205 | int ff_wmv2_decode_picture_header(MpegEncContext *s) | 204 | int ff_wmv2_decode_picture_header(H263DecContext *const h) |
| 206 | { | 205 | { |
| 207 | int code; | 206 | int code; |
| 208 | 207 | ||
| 209 | s->pict_type = get_bits1(&s->gb) + 1; | 208 | h->c.pict_type = get_bits1(&h->c.gb) + 1; |
| 210 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 209 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 211 | code = get_bits(&s->gb, 7); | 210 | code = get_bits(&h->c.gb, 7); |
| 212 | av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code); | 211 | av_log(h->c.avctx, AV_LOG_DEBUG, "I7:%X/\n", code); |
| 213 | } | 212 | } |
| 214 | s->chroma_qscale = s->qscale = get_bits(&s->gb, 5); | 213 | h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); |
| 215 | if (s->qscale <= 0) | 214 | if (h->c.qscale <= 0) |
| 216 | return AVERROR_INVALIDDATA; | 215 | return AVERROR_INVALIDDATA; |
| 217 | 216 | ||
| 218 | if (s->pict_type != AV_PICTURE_TYPE_I && show_bits(&s->gb, 1)) { | 217 | if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->c.gb, 1)) { |
| 219 | GetBitContext gb = s->gb; | 218 | GetBitContext gb = h->c.gb; |
| 220 | int skip_type = get_bits(&gb, 2); | 219 | int skip_type = get_bits(&gb, 2); |
| 221 | int run = skip_type == SKIP_TYPE_COL ? s->mb_width : s->mb_height; | 220 | int run = skip_type == SKIP_TYPE_COL ? h->c.mb_width : h->c.mb_height; |
| 222 | 221 | ||
| 223 | while (run > 0) { | 222 | while (run > 0) { |
| 224 | int block = FFMIN(run, 25); | 223 | int block = FFMIN(run, 25); |
| @@ -233,46 +232,46 @@ int ff_wmv2_decode_picture_header(MpegEncContext *s) · 8 unmodified lines | |||
| 233 | return 0; | 232 | return 0; |
| 234 | } | 233 | } |
| 235 | 234 | ||
| 236 | int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) | 235 | int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h) |
| 237 | { | 236 | { |
| 238 | WMV2DecContext *const w = (WMV2DecContext *) s; | 237 | WMV2DecContext *const w = (WMV2DecContext *)h; |
| 239 | 238 | ||
| 240 | if (s->pict_type == AV_PICTURE_TYPE_I) { | 239 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 241 | /* Is filling with zeroes really the right thing to do? */ | 240 | /* Is filling with zeroes really the right thing to do? */ |
| 242 | memset(s->cur_pic.mb_type, 0, | 241 | memset(h->c.cur_pic.mb_type, 0, |
| 243 | sizeof(*s->cur_pic.mb_type) * s->mb_height * s->mb_stride); | 242 | sizeof(*h->c.cur_pic.mb_type) * h->c.mb_height * h->c.mb_stride); |
| 244 | if (w->j_type_bit) | 243 | if (w->j_type_bit) |
| 245 | w->j_type = get_bits1(&s->gb); | 244 | w->j_type = get_bits1(&h->c.gb); |
| 246 | else | 245 | else |
| 247 | w->j_type = 0; // FIXME check | 246 | w->j_type = 0; // FIXME check |
| 248 | 247 | ||
| 249 | if (!w->j_type) { | 248 | if (!w->j_type) { |
| 250 | if (w->per_mb_rl_bit) | 249 | if (w->per_mb_rl_bit) |
| 251 | w->ms.per_mb_rl_table = get_bits1(&s->gb); | 250 | w->ms.per_mb_rl_table = get_bits1(&h->c.gb); |
| 252 | else | 251 | else |
| 253 | w->ms.per_mb_rl_table = 0; | 252 | w->ms.per_mb_rl_table = 0; |
| 254 | 253 | ||
| 255 | if (!w->ms.per_mb_rl_table) { | 254 | if (!w->ms.per_mb_rl_table) { |
| 256 | w->ms.rl_chroma_table_index = decode012(&s->gb); | 255 | w->ms.rl_chroma_table_index = decode012(&h->c.gb); |
| 257 | w->ms.rl_table_index = decode012(&s->gb); | 256 | w->ms.rl_table_index = decode012(&h->c.gb); |
| 258 | } | 257 | } |
| 259 | 258 | ||
| 260 | w->ms.dc_table_index = get_bits1(&s->gb); | 259 | w->ms.dc_table_index = get_bits1(&h->c.gb); |
| 261 | 260 | ||
| 262 | // at minimum one bit per macroblock is required at least in a valid frame, | 261 | // at minimum one bit per macroblock is required at least in a valid frame, |
| 263 | // we discard frames much smaller than this. Frames smaller than 1/8 of the | 262 | // we discard frames much smaller than this. Frames smaller than 1/8 of the |
| 264 | // smallest "black/skip" frame generally contain not much recoverable content | 263 | // smallest "black/skip" frame generally contain not much recoverable content |
| 265 | // while at the same time they have the highest computational requirements | 264 | // while at the same time they have the highest computational requirements |
| 266 | // per byte | 265 | // per byte |
| 267 | if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16)) | 266 | if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16)) |
| 268 | return AVERROR_INVALIDDATA; | 267 | return AVERROR_INVALIDDATA; |
| 269 | } | 268 | } |
| 270 | s->inter_intra_pred = 0; | 269 | h->c.inter_intra_pred = 0; |
| 271 | s->no_rounding = 1; | 270 | h->c.no_rounding = 1; |
| 272 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | 271 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { |
| 273 | av_log(s->avctx, AV_LOG_DEBUG, | 272 | av_log(h->c.avctx, AV_LOG_DEBUG, |
| 274 | "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n", | 273 | "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n", |
| 275 | s->qscale, w->ms.rl_chroma_table_index, w->ms.rl_table_index, | 274 | h->c.qscale, w->ms.rl_chroma_table_index, w->ms.rl_table_index, |
| 276 | w->ms.dc_table_index, w->ms.per_mb_rl_table, w->j_type); | 275 | w->ms.dc_table_index, w->ms.per_mb_rl_table, w->j_type); |
| 277 | } | 276 | } |
| 278 | } else { | 277 | } else { |
| @@ -283,61 +282,61 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) · 4 unmodified lines | |||
| 283 | ret = parse_mb_skip(w); | 282 | ret = parse_mb_skip(w); |
| 284 | if (ret < 0) | 283 | if (ret < 0) |
| 285 | return ret; | 284 | return ret; |
| 286 | cbp_index = decode012(&s->gb); | 285 | cbp_index = decode012(&h->c.gb); |
| 287 | w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index); | 286 | w->cbp_table_index = wmv2_get_cbp_table_index(h->c.qscale, cbp_index); |
| 288 | 287 | ||
| 289 | if (w->mspel_bit) | 288 | if (w->mspel_bit) |
| 290 | s->mspel = get_bits1(&s->gb); | 289 | h->c.mspel = get_bits1(&h->c.gb); |
| 291 | else | 290 | else |
| 292 | s->mspel = 0; // FIXME check | 291 | h->c.mspel = 0; // FIXME check |
| 293 | 292 | ||
| 294 | if (w->abt_flag) { | 293 | if (w->abt_flag) { |
| 295 | w->per_mb_abt = get_bits1(&s->gb) ^ 1; | 294 | w->per_mb_abt = get_bits1(&h->c.gb) ^ 1; |
| 296 | if (!w->per_mb_abt) | 295 | if (!w->per_mb_abt) |
| 297 | w->abt_type = decode012(&s->gb); | 296 | w->abt_type = decode012(&h->c.gb); |
| 298 | } | 297 | } |
| 299 | 298 | ||
| 300 | if (w->per_mb_rl_bit) | 299 | if (w->per_mb_rl_bit) |
| 301 | w->ms.per_mb_rl_table = get_bits1(&s->gb); | 300 | w->ms.per_mb_rl_table = get_bits1(&h->c.gb); |
| 302 | else | 301 | else |
| 303 | w->ms.per_mb_rl_table = 0; | 302 | w->ms.per_mb_rl_table = 0; |
| 304 | 303 | ||
| 305 | if (!w->ms.per_mb_rl_table) { | 304 | if (!w->ms.per_mb_rl_table) { |
| 306 | w->ms.rl_table_index = decode012(&s->gb); | 305 | w->ms.rl_table_index = decode012(&h->c.gb); |
| 307 | w->ms.rl_chroma_table_index = w->ms.rl_table_index; | 306 | w->ms.rl_chroma_table_index = w->ms.rl_table_index; |
| 308 | } | 307 | } |
| 309 | 308 | ||
| 310 | if (get_bits_left(&s->gb) < 2) | 309 | if (get_bits_left(&h->c.gb) < 2) |
| 311 | return AVERROR_INVALIDDATA; | 310 | return AVERROR_INVALIDDATA; |
| 312 | 311 | ||
| 313 | w->ms.dc_table_index = get_bits1(&s->gb); | 312 | w->ms.dc_table_index = get_bits1(&h->c.gb); |
| 314 | w->ms.mv_table_index = get_bits1(&s->gb); | 313 | w->ms.mv_table_index = get_bits1(&h->c.gb); |
| 315 | 314 | ||
| 316 | s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && w->ms.bit_rate <= II_BITRATE); | 315 | h->c.inter_intra_pred = 0; // (h->c.width * h->c.height < 320 * 240 && w->ms.bit_rate <= II_BITRATE); |
| 317 | s->no_rounding ^= 1; | 316 | h->c.no_rounding ^= 1; |
| 318 | 317 | ||
| 319 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | 318 | if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { |
| 320 | av_log(s->avctx, AV_LOG_DEBUG, | 319 | av_log(h->c.avctx, AV_LOG_DEBUG, |
| 321 | "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d " | 320 | "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d " |
| 322 | "per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n", | 321 | "per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n", |
| 323 | w->ms.rl_table_index, w->ms.rl_chroma_table_index, | 322 | w->ms.rl_table_index, w->ms.rl_chroma_table_index, |
| 324 | w->ms.dc_table_index, w->ms.mv_table_index, | 323 | w->ms.dc_table_index, w->ms.mv_table_index, |
| 325 | w->ms.per_mb_rl_table, s->qscale, s->mspel, | 324 | w->ms.per_mb_rl_table, h->c.qscale, h->c.mspel, |
| 326 | w->per_mb_abt, w->abt_type, w->cbp_table_index, | 325 | w->per_mb_abt, w->abt_type, w->cbp_table_index, |
| 327 | s->inter_intra_pred); | 326 | h->c.inter_intra_pred); |
| 328 | } | 327 | } |
| 329 | } | 328 | } |
| 330 | w->ms.esc3_level_length = 0; | 329 | w->ms.esc3_level_length = 0; |
| 331 | w->ms.esc3_run_length = 0; | 330 | w->ms.esc3_run_length = 0; |
| 332 | 331 | ||
| 333 | if (w->j_type) { | 332 | if (w->j_type) { |
| 334 | ff_intrax8_decode_picture(&w->x8, s->cur_pic.ptr, | 333 | ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr, |
| 335 | &s->gb, &s->mb_x, &s->mb_y, | 334 | &h->c.gb, &h->c.mb_x, &h->c.mb_y, |
| 336 | 2 * s->qscale, (s->qscale - 1) | 1, | 335 | 2 * h->c.qscale, (h->c.qscale - 1) | 1, |
| 337 | s->loop_filter, s->low_delay); | 336 | h->c.loop_filter, h->c.low_delay); |
| 338 | 337 | ||
| 339 | ff_er_add_slice(&s->er, 0, 0, | 338 | ff_er_add_slice(&h->c.er, 0, 0, |
| 340 | (s->mb_x >> 1) - 1, (s->mb_y >> 1) - 1, | 339 | (h->c.mb_x >> 1) - 1, (h->c.mb_y >> 1) - 1, |
| 341 | ER_MB_END); | 340 | ER_MB_END); |
| 342 | return 1; | 341 | return 1; |
| 343 | } | 342 | } |
| @@ -347,38 +346,37 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) · 3 unmodified lines | |||
| 347 | 346 | ||
| 348 | static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_ptr) | 347 | static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_ptr) |
| 349 | { | 348 | { |
| 350 | MpegEncContext *const s = &w->ms.m; | 349 | H263DecContext *const h = &w->ms.h; |
| 351 | 350 | ||
| 352 | ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr); | 351 | ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr); |
| 353 | 352 | ||
| 354 | if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel) | 353 | if ((((*mx_ptr) | (*my_ptr)) & 1) && h->c.mspel) |
| 355 | w->common.hshift = get_bits1(&s->gb); | 354 | w->common.hshift = get_bits1(&h->c.gb); |
| 356 | else | 355 | else |
| 357 | w->common.hshift = 0; | 356 | w->common.hshift = 0; |
| 358 | } | 357 | } |
| 359 | 358 | ||
| 360 | static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) | 359 | static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) |
| 361 | { | 360 | { |
| 362 | MpegEncContext *const s = &w->ms.m; | 361 | H263DecContext *const h = &w->ms.h; |
| 363 | int xy, wrap, diff, type; | 362 | int diff, type; |
| 364 | int16_t *A, *B, *C, *mot_val; | ||
| 365 | 363 | ||
| 366 | wrap = s->b8_stride; | 364 | int wrap = h->c.b8_stride; |
| 367 | xy = s->block_index[0]; | 365 | int xy = h->c.block_index[0]; |
| 368 | 366 | ||
| 369 | mot_val = s->cur_pic.motion_val[0][xy]; | 367 | int16_t *mot_val = h->c.cur_pic.motion_val[0][xy]; |
| 370 | 368 | ||
| 371 | A = s->cur_pic.motion_val[0][xy - 1]; | 369 | const int16_t *A = h->c.cur_pic.motion_val[0][xy - 1]; |
| 372 | B = s->cur_pic.motion_val[0][xy - wrap]; | 370 | const int16_t *B = h->c.cur_pic.motion_val[0][xy - wrap]; |
| 373 | C = s->cur_pic.motion_val[0][xy + 2 - wrap]; | 371 | const int16_t *C = h->c.cur_pic.motion_val[0][xy + 2 - wrap]; |
| 374 | 372 | ||
| 375 | if (s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag) | 373 | if (h->c.mb_x && !h->c.first_slice_line && !h->c.mspel && w->top_left_mv_flag) |
| 376 | diff = FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1])); | 374 | diff = FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1])); |
| 377 | else | 375 | else |
| 378 | diff = 0; | 376 | diff = 0; |
| 379 | 377 | ||
| 380 | if (diff >= 8) | 378 | if (diff >= 8) |
| 381 | type = get_bits1(&s->gb); | 379 | type = get_bits1(&h->c.gb); |
| 382 | else | 380 | else |
| 383 | type = 2; | 381 | type = 2; |
| 384 | 382 | ||
| @@ -390,7 +388,7 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) · 5 unmodified lines | |||
| 390 | *py = B[1]; | 388 | *py = B[1]; |
| 391 | } else { | 389 | } else { |
| 392 | /* special case for first (slice) line */ | 390 | /* special case for first (slice) line */ |
| 393 | if (s->first_slice_line) { | 391 | if (h->c.first_slice_line) { |
| 394 | *px = A[0]; | 392 | *px = A[0]; |
| 395 | *py = A[1]; | 393 | *py = A[1]; |
| 396 | } else { | 394 | } else { |
| @@ -405,23 +403,23 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) · 8 unmodified lines | |||
| 405 | static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block, | 403 | static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block, |
| 406 | int n, int cbp) | 404 | int n, int cbp) |
| 407 | { | 405 | { |
| 408 | MpegEncContext *const s = &w->ms.m; | 406 | H263DecContext *const h = &w->ms.h; |
| 409 | static const int sub_cbp_table[3] = { 2, 3, 1 }; | 407 | static const int sub_cbp_table[3] = { 2, 3, 1 }; |
| 410 | int sub_cbp, ret; | 408 | int sub_cbp, ret; |
| 411 | 409 | ||
| 412 | if (!cbp) { | 410 | if (!cbp) { |
| 413 | s->block_last_index[n] = -1; | 411 | h->c.block_last_index[n] = -1; |
| 414 | return 0; | 412 | return 0; |
| 415 | } | 413 | } |
| 416 | 414 | ||
| 417 | if (w->per_block_abt) | 415 | if (w->per_block_abt) |
| 418 | w->abt_type = decode012(&s->gb); | 416 | w->abt_type = decode012(&h->c.gb); |
| 419 | w->abt_type_table[n] = w->abt_type; | 417 | w->abt_type_table[n] = w->abt_type; |
| 420 | 418 | ||
| 421 | if (w->abt_type) { | 419 | if (w->abt_type) { |
| 422 | const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : ff_wmv2_scantableB; | 420 | const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : ff_wmv2_scantableB; |
| 423 | 421 | ||
| 424 | sub_cbp = sub_cbp_table[decode012(&s->gb)]; | 422 | sub_cbp = sub_cbp_table[decode012(&h->c.gb)]; |
| 425 | 423 | ||
| 426 | if (sub_cbp & 1) { | 424 | if (sub_cbp & 1) { |
| 427 | ret = ff_msmpeg4_decode_block(&w->ms, block, n, 1, scantable); | 425 | ret = ff_msmpeg4_decode_block(&w->ms, block, n, 1, scantable); |
| @@ -435,20 +433,20 @@ static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block, · 7 unmodified lines | |||
| 435 | return ret; | 433 | return ret; |
| 436 | } | 434 | } |
| 437 | 435 | ||
| 438 | s->block_last_index[n] = 63; | 436 | h->c.block_last_index[n] = 63; |
| 439 | 437 | ||
| 440 | return 0; | 438 | return 0; |
| 441 | } else { | 439 | } else { |
| 442 | return ff_msmpeg4_decode_block(&w->ms, block, n, 1, | 440 | return ff_msmpeg4_decode_block(&w->ms, block, n, 1, |
| 443 | s->inter_scantable.permutated); | 441 | h->c.inter_scantable.permutated); |
| 444 | } | 442 | } |
| 445 | } | 443 | } |
| 446 | 444 | ||
| 447 | static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) | 445 | static int wmv2_decode_mb(H263DecContext *const h, int16_t block[6][64]) |
| 448 | { | 446 | { |
| 449 | /* The following is only allowed because this encoder | 447 | /* The following is only allowed because this decoder |
| 450 | * does not use slice threading. */ | 448 | * does not use slice threading. */ |
| 451 | WMV2DecContext *const w = (WMV2DecContext *) s; | 449 | WMV2DecContext *const w = (WMV2DecContext *) h; |
| 452 | MSMP4DecContext *const ms = &w->ms; | 450 | MSMP4DecContext *const ms = &w->ms; |
| 453 | int cbp, code, i, ret; | 451 | int cbp, code, i, ret; |
| 454 | uint8_t *coded_val; | 452 | uint8_t *coded_val; |
| @@ -456,40 +454,40 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line | |||
| 456 | if (w->j_type) | 454 | if (w->j_type) |
| 457 | return 0; | 455 | return 0; |
| 458 | 456 | ||
| 459 | if (s->pict_type == AV_PICTURE_TYPE_P) { | 457 | if (h->c.pict_type == AV_PICTURE_TYPE_P) { |
| 460 | if (IS_SKIP(s->cur_pic.mb_type[s->mb_y * s->mb_stride + s->mb_x])) { | 458 | if (IS_SKIP(h->c.cur_pic.mb_type[h->c.mb_y * h->c.mb_stride + h->c.mb_x])) { |
| 461 | /* skip mb */ | 459 | /* skip mb */ |
| 462 | s->mb_intra = 0; | 460 | h->c.mb_intra = 0; |
| 463 | for (i = 0; i < 6; i++) | 461 | for (i = 0; i < 6; i++) |
| 464 | s->block_last_index[i] = -1; | 462 | h->c.block_last_index[i] = -1; |
| 465 | s->mv_dir = MV_DIR_FORWARD; | 463 | h->c.mv_dir = MV_DIR_FORWARD; |
| 466 | s->mv_type = MV_TYPE_16X16; | 464 | h->c.mv_type = MV_TYPE_16X16; |
| 467 | s->mv[0][0][0] = 0; | 465 | h->c.mv[0][0][0] = 0; |
| 468 | s->mv[0][0][1] = 0; | 466 | h->c.mv[0][0][1] = 0; |
| 469 | s->mb_skipped = 1; | 467 | h->c.mb_skipped = 1; |
| 470 | w->common.hshift = 0; | 468 | w->common.hshift = 0; |
| 471 | return 0; | 469 | return 0; |
| 472 | } | 470 | } |
| 473 | if (get_bits_left(&s->gb) <= 0) | 471 | if (get_bits_left(&h->c.gb) <= 0) |
| 474 | return AVERROR_INVALIDDATA; | 472 | return AVERROR_INVALIDDATA; |
| 475 | 473 | ||
| 476 | code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[w->cbp_table_index], | 474 | code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[w->cbp_table_index], |
| 477 | MB_NON_INTRA_VLC_BITS, 3); | 475 | MB_NON_INTRA_VLC_BITS, 3); |
| 478 | s->mb_intra = (~code & 0x40) >> 6; | 476 | h->c.mb_intra = (~code & 0x40) >> 6; |
| 479 | 477 | ||
| 480 | cbp = code & 0x3f; | 478 | cbp = code & 0x3f; |
| 481 | } else { | 479 | } else { |
| 482 | s->mb_intra = 1; | 480 | h->c.mb_intra = 1; |
| 483 | if (get_bits_left(&s->gb) <= 0) | 481 | if (get_bits_left(&h->c.gb) <= 0) |
| 484 | return AVERROR_INVALIDDATA; | 482 | return AVERROR_INVALIDDATA; |
| 485 | code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, | 483 | code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc, |
| 486 | MSMP4_MB_INTRA_VLC_BITS, 2); | 484 | MSMP4_MB_INTRA_VLC_BITS, 2); |
| 487 | /* predict coded block pattern */ | 485 | /* predict coded block pattern */ |
| 488 | cbp = 0; | 486 | cbp = 0; |
| 489 | for (i = 0; i < 6; i++) { | 487 | for (i = 0; i < 6; i++) { |
| 490 | int val = ((code >> (5 - i)) & 1); | 488 | int val = ((code >> (5 - i)) & 1); |
| 491 | if (i < 4) { | 489 | if (i < 4) { |
| 492 | int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val); | 490 | int pred = ff_msmpeg4_coded_block_pred(&h->c, i, &coded_val); |
| 493 | val = val ^ pred; | 491 | val = val ^ pred; |
| 494 | *coded_val = val; | 492 | *coded_val = val; |
| 495 | } | 493 | } |
| @@ -497,65 +495,65 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line | |||
| 497 | } | 495 | } |
| 498 | } | 496 | } |
| 499 | 497 | ||
| 500 | if (!s->mb_intra) { | 498 | if (!h->c.mb_intra) { |
| 501 | int mx, my; | 499 | int mx, my; |
| 502 | wmv2_pred_motion(w, &mx, &my); | 500 | wmv2_pred_motion(w, &mx, &my); |
| 503 | 501 | ||
| 504 | if (cbp) { | 502 | if (cbp) { |
| 505 | s->bdsp.clear_blocks(s->block[0]); | 503 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 506 | if (ms->per_mb_rl_table) { | 504 | if (ms->per_mb_rl_table) { |
| 507 | ms->rl_table_index = decode012(&s->gb); | 505 | ms->rl_table_index = decode012(&h->c.gb); |
| 508 | ms->rl_chroma_table_index = ms->rl_table_index; | 506 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 509 | } | 507 | } |
| 510 | 508 | ||
| 511 | if (w->abt_flag && w->per_mb_abt) { | 509 | if (w->abt_flag && w->per_mb_abt) { |
| 512 | w->per_block_abt = get_bits1(&s->gb); | 510 | w->per_block_abt = get_bits1(&h->c.gb); |
| 513 | if (!w->per_block_abt) | 511 | if (!w->per_block_abt) |
| 514 | w->abt_type = decode012(&s->gb); | 512 | w->abt_type = decode012(&h->c.gb); |
| 515 | } else | 513 | } else |
| 516 | w->per_block_abt = 0; | 514 | w->per_block_abt = 0; |
| 517 | } | 515 | } |
| 518 | 516 | ||
| 519 | wmv2_decode_motion(w, &mx, &my); | 517 | wmv2_decode_motion(w, &mx, &my); |
| 520 | 518 | ||
| 521 | s->mv_dir = MV_DIR_FORWARD; | 519 | h->c.mv_dir = MV_DIR_FORWARD; |
| 522 | s->mv_type = MV_TYPE_16X16; | 520 | h->c.mv_type = MV_TYPE_16X16; |
| 523 | s->mv[0][0][0] = mx; | 521 | h->c.mv[0][0][0] = mx; |
| 524 | s->mv[0][0][1] = my; | 522 | h->c.mv[0][0][1] = my; |
| 525 | 523 | ||
| 526 | for (i = 0; i < 6; i++) { | 524 | for (i = 0; i < 6; i++) { |
| 527 | if ((ret = wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1)) < 0) { | 525 | if ((ret = wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1)) < 0) { |
| 528 | av_log(s->avctx, AV_LOG_ERROR, | 526 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 529 | "\nerror while decoding inter block: %d x %d (%d)\n", | 527 | "\nerror while decoding inter block: %d x %d (%d)\n", |
| 530 | s->mb_x, s->mb_y, i); | 528 | h->c.mb_x, h->c.mb_y, i); |
| 531 | return ret; | 529 | return ret; |
| 532 | } | 530 | } |
| 533 | } | 531 | } |
| 534 | } else { | 532 | } else { |
| 535 | if (s->pict_type == AV_PICTURE_TYPE_P) | 533 | if (h->c.pict_type == AV_PICTURE_TYPE_P) |
| 536 | ff_dlog(s->avctx, "%d%d ", s->inter_intra_pred, cbp); | 534 | ff_dlog(h->c.avctx, "%d%d ", h->c.inter_intra_pred, cbp); |
| 537 | ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y, | 535 | ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y, |
| 538 | ((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0), | 536 | ((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0), |
| 539 | show_bits(&s->gb, 24)); | 537 | show_bits(&h->c.gb, 24)); |
| 540 | s->ac_pred = get_bits1(&s->gb); | 538 | h->c.ac_pred = get_bits1(&h->c.gb); |
| 541 | if (s->inter_intra_pred) { | 539 | if (h->c.inter_intra_pred) { |
| 542 | s->h263_aic_dir = get_vlc2(&s->gb, ff_inter_intra_vlc, | 540 | h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc, |
| 543 | INTER_INTRA_VLC_BITS, 1); | 541 | INTER_INTRA_VLC_BITS, 1); |
| 544 | ff_dlog(s->avctx, "%d%d %d %d/", | 542 | ff_dlog(h->c.avctx, "%d%d %d %d/", |
| 545 | s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); | 543 | h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y); |
| 546 | } | 544 | } |
| 547 | if (ms->per_mb_rl_table && cbp) { | 545 | if (ms->per_mb_rl_table && cbp) { |
| 548 | ms->rl_table_index = decode012(&s->gb); | 546 | ms->rl_table_index = decode012(&h->c.gb); |
| 549 | ms->rl_chroma_table_index = ms->rl_table_index; | 547 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 550 | } | 548 | } |
| 551 | 549 | ||
| 552 | s->bdsp.clear_blocks(s->block[0]); | 550 | h->c.bdsp.clear_blocks(h->c.block[0]); |
| 553 | for (i = 0; i < 6; i++) { | 551 | for (i = 0; i < 6; i++) { |
| 554 | ret = ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL); | 552 | ret = ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL); |
| 555 | if (ret < 0) { | 553 | if (ret < 0) { |
| 556 | av_log(s->avctx, AV_LOG_ERROR, | 554 | av_log(h->c.avctx, AV_LOG_ERROR, |
| 557 | "\nerror while decoding intra block: %d x %d (%d)\n", | 555 | "\nerror while decoding intra block: %d x %d (%d)\n", |
| 558 | s->mb_x, s->mb_y, i); | 556 | h->c.mb_x, h->c.mb_y, i); |
| 559 | return ret; | 557 | return ret; |
| 560 | } | 558 | } |
| 561 | } | 559 | } |
| @@ -567,7 +565,8 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 5 unmodified lines | |||
| 567 | static av_cold int wmv2_decode_init(AVCodecContext *avctx) | 565 | static av_cold int wmv2_decode_init(AVCodecContext *avctx) |
| 568 | { | 566 | { |
| 569 | WMV2DecContext *const w = avctx->priv_data; | 567 | WMV2DecContext *const w = avctx->priv_data; |
| 570 | MpegEncContext *const s = &w->ms.m; | 568 | H263DecContext *const h = &w->ms.h; |
| 569 | MpegEncContext *const s = &h->c; | ||
| 571 | int ret; | 570 | int ret; |
| 572 | 571 | ||
| 573 | s->private_ctx = &w->common; | 572 | s->private_ctx = &w->common; |
| @@ -575,13 +574,13 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx) · 1 unmodified line | |||
| 575 | if ((ret = ff_msmpeg4_decode_init(avctx)) < 0) | 574 | if ((ret = ff_msmpeg4_decode_init(avctx)) < 0) |
| 576 | return ret; | 575 | return ret; |
| 577 | 576 | ||
| 578 | s->decode_mb = wmv2_decode_mb; | 577 | h->decode_mb = wmv2_decode_mb; |
| 579 | 578 | ||
| 580 | ff_wmv2_common_init(s); | 579 | ff_wmv2_common_init(s); |
| 581 | 580 | ||
| 582 | decode_ext_header(w); | 581 | decode_ext_header(w); |
| 583 | 582 | ||
| 584 | return ff_intrax8_common_init(avctx, &w->x8, s->block[0], | 583 | return ff_intrax8_common_init(avctx, &w->x8, h->c.block[0], |
| 585 | s->mb_width, s->mb_height); | 584 | s->mb_width, s->mb_height); |
| 586 | } | 585 | } |
| 587 | 586 | ||
| @@ -22,9 +22,10 @@ · 21 unmodified lines | |||
| 22 | #define AVCODEC_WMV2DEC_H | 22 | #define AVCODEC_WMV2DEC_H |
| 23 | 23 | ||
| 24 | #include "mpegvideo.h" | 24 | #include "mpegvideo.h" |
| 25 | struct H263DecContext; | ||
| 25 | 26 | ||
| 26 | int ff_wmv2_decode_picture_header(MpegEncContext * s); | 27 | int ff_wmv2_decode_picture_header(struct H263DecContext *const h); |
| 27 | int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s); | 28 | int ff_wmv2_decode_secondary_picture_header(struct H263DecContext *const h); |
| 28 | void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], | 29 | void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], |
| 29 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr); | 30 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr); |
| 30 | 31 | ||
| @@ -118,7 +118,7 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m) · 117 unmodified lines | |||
| 118 | put_bits(&s->pb, 2, SKIP_TYPE_NONE); | 118 | put_bits(&s->pb, 2, SKIP_TYPE_NONE); |
| 119 | 119 | ||
| 120 | ff_msmpeg4_code012(&s->pb, cbp_index = 0); | 120 | ff_msmpeg4_code012(&s->pb, cbp_index = 0); |
| 121 | w->cbp_table_index = wmv2_get_cbp_table_index(&s->c, cbp_index); | 121 | w->cbp_table_index = wmv2_get_cbp_table_index(s->c.qscale, cbp_index); |
| 122 | 122 | ||
| 123 | if (w->mspel_bit) | 123 | if (w->mspel_bit) |
| 124 | put_bits(&s->pb, 1, s->c.mspel); | 124 | put_bits(&s->pb, 1, s->c.mspel); |