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 | 26 | #include "mpegvideo.h" |
| 27 | 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 | 31 | int format, width, height; |
| 32 | 32 | |
| 33 | 33 | /* picture header */ |
| 34 | − if (get_bits(&s->gb, 17) != 1) { | |
| 35 | − av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); | |
| 34 | + if (get_bits(&h->c.gb, 17) != 1) { | |
| 35 | + av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n"); | |
| 36 | 36 | return AVERROR_INVALIDDATA; |
| 37 | 37 | } |
| 38 | − format = get_bits(&s->gb, 5); | |
| 38 | + format = get_bits(&h->c.gb, 5); | |
| 39 | 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 | 41 | return AVERROR_INVALIDDATA; |
| 42 | 42 | } |
| 43 | − s->h263_flv = format + 1; | |
| 44 | − s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ | |
| 45 | − format = get_bits(&s->gb, 3); | |
| 43 | + h->c.h263_flv = format + 1; | |
| 44 | + h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */ | |
| 45 | + format = get_bits(&h->c.gb, 3); | |
| 46 | 46 | switch (format) { |
| 47 | 47 | case 0: |
| 48 | − width = get_bits(&s->gb, 8); | |
| 49 | − height = get_bits(&s->gb, 8); | |
| 48 | + width = get_bits(&h->c.gb, 8); | |
| 49 | + height = get_bits(&h->c.gb, 8); | |
| 50 | 50 | break; |
| 51 | 51 | case 1: |
| 52 | − width = get_bits(&s->gb, 16); | |
| 53 | − height = get_bits(&s->gb, 16); | |
| 52 | + width = get_bits(&h->c.gb, 16); | |
| 53 | + height = get_bits(&h->c.gb, 16); | |
| 54 | 54 | break; |
| 55 | 55 | case 2: |
| 56 | 56 | width = 352; |
| @@ -76,32 +76,32 @@ int ff_flv_decode_picture_header(MpegEncContext *s) · 19 unmodified lines | ||
| 76 | 76 | width = height = 0; |
| 77 | 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 | 80 | return AVERROR(EINVAL); |
| 81 | − s->width = width; | |
| 82 | − s->height = height; | |
| 81 | + h->c.width = width; | |
| 82 | + h->c.height = height; | |
| 83 | 83 | |
| 84 | − s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2); | |
| 85 | − s->droppable = s->pict_type > AV_PICTURE_TYPE_P; | |
| 86 | − if (s->droppable) | |
| 87 | − s->pict_type = AV_PICTURE_TYPE_P; | |
| 84 | + h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->c.gb, 2); | |
| 85 | + h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P; | |
| 86 | + if (h->c.droppable) | |
| 87 | + h->c.pict_type = AV_PICTURE_TYPE_P; | |
| 88 | 88 | |
| 89 | − skip_bits1(&s->gb); /* deblocking flag */ | |
| 90 | − s->chroma_qscale = s->qscale = get_bits(&s->gb, 5); | |
| 89 | + skip_bits1(&h->c.gb); /* deblocking flag */ | |
| 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 | 94 | /* PEI */ |
| 95 | − if (skip_1stop_8data_bits(&s->gb) < 0) | |
| 95 | + if (skip_1stop_8data_bits(&h->c.gb) < 0) | |
| 96 | 96 | return AVERROR_INVALIDDATA; |
| 97 | 97 | |
| 98 | − if (s->ehc_mode) | |
| 99 | − s->avctx->sample_aspect_ratio= (AVRational){1,2}; | |
| 98 | + if (h->c.ehc_mode) | |
| 99 | + h->c.avctx->sample_aspect_ratio= (AVRational){1,2}; | |
| 100 | 100 | |
| 101 | − if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 102 | − av_log(s->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), | |
| 104 | − s->h263_flv - 1, s->qscale, s->picture_number); | |
| 101 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 102 | + av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", | |
| 103 | + h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type), | |
| 104 | + h->c.h263_flv - 1, h->c.qscale, h->c.picture_number); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | return 0; |
| @@ -112,7 +112,7 @@ const FFCodec ff_flv_decoder = { · 4 unmodified lines | ||
| 112 | 112 | CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"), |
| 113 | 113 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 114 | 114 | .p.id = AV_CODEC_ID_FLV1, |
| 115 | − .priv_data_size = sizeof(MpegEncContext), | |
| 115 | + .priv_data_size = sizeof(H263DecContext), | |
| 116 | 116 | .init = ff_h263_decode_init, |
| 117 | 117 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 118 | 118 | .close = ff_mpv_decode_close, |
| @@ -21,8 +21,8 @@ · 20 unmodified lines | ||
| 21 | 21 | #ifndef AVCODEC_FLVDEC_H |
| 22 | 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 | 28 | #endif /* AVCODEC_FLVDEC_H */ |
| @@ -90,7 +90,8 @@ static enum AVPixelFormat h263_get_format(AVCodecContext *avctx) · 89 unmodified lines | ||
| 90 | 90 | |
| 91 | 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 | 95 | MPVUnquantDSPContext unquant_dsp_ctx; |
| 95 | 96 | int ret; |
| 96 | 97 | |
| @@ -101,7 +102,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) · 4 unmodified lines | ||
| 101 | 102 | if (ret < 0) |
| 102 | 103 | return ret; |
| 103 | 104 | |
| 104 | − s->decode_mb = ff_h263_decode_mb; | |
| 105 | + h->decode_mb = ff_h263_decode_mb; | |
| 105 | 106 | s->low_delay = 1; |
| 106 | 107 | |
| 107 | 108 | s->y_dc_scale_table = |
| @@ -179,239 +180,239 @@ static void report_decode_progress(MpegEncContext *s) · 71 unmodified lines | ||
| 179 | 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 | 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 | 188 | int ret; |
| 188 | 189 | |
| 189 | − s->last_resync_gb = s->gb; | |
| 190 | − s->first_slice_line = 1; | |
| 191 | − s->resync_mb_x = s->mb_x; | |
| 192 | − s->resync_mb_y = s->mb_y; | |
| 190 | + h->c.last_resync_gb = h->c.gb; | |
| 191 | + h->c.first_slice_line = 1; | |
| 192 | + h->c.resync_mb_x = h->c.mb_x; | |
| 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 ((ret = ff_mpeg4_decode_studio_slice_header(s)) < 0) | |
| 197 | + if (h->c.studio_profile) { | |
| 198 | + if ((ret = ff_mpeg4_decode_studio_slice_header(h)) < 0) | |
| 198 | 199 | return ret; |
| 199 | 200 | } |
| 200 | 201 | |
| 201 | − if (s->avctx->hwaccel) { | |
| 202 | − const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8; | |
| 203 | − ret = FF_HW_CALL(s->avctx, decode_slice, start, s->gb.buffer_end - start); | |
| 202 | + if (h->c.avctx->hwaccel) { | |
| 203 | + const uint8_t *start = h->c.gb.buffer + get_bits_count(&h->c.gb) / 8; | |
| 204 | + ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->c.gb.buffer_end - start); | |
| 204 | 205 | // ensure we exit decode loop |
| 205 | − s->mb_y = s->mb_height; | |
| 206 | + h->c.mb_y = h->c.mb_height; | |
| 206 | 207 | return ret; |
| 207 | 208 | } |
| 208 | 209 | |
| 209 | − if (s->partitioned_frame) { | |
| 210 | − const int qscale = s->qscale; | |
| 210 | + if (h->c.partitioned_frame) { | |
| 211 | + const int qscale = h->c.qscale; | |
| 211 | 212 | |
| 212 | − if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4) | |
| 213 | − if ((ret = ff_mpeg4_decode_partitions(s)) < 0) | |
| 213 | + if (CONFIG_MPEG4_DECODER && h->c.codec_id == AV_CODEC_ID_MPEG4) | |
| 214 | + if ((ret = ff_mpeg4_decode_partitions(h)) < 0) | |
| 214 | 215 | return ret; |
| 215 | 216 | |
| 216 | 217 | /* restore variables which were modified */ |
| 217 | − s->first_slice_line = 1; | |
| 218 | − s->mb_x = s->resync_mb_x; | |
| 219 | − s->mb_y = s->resync_mb_y; | |
| 220 | − ff_set_qscale(s, qscale); | |
| 218 | + h->c.first_slice_line = 1; | |
| 219 | + h->c.mb_x = h->c.resync_mb_x; | |
| 220 | + h->c.mb_y = h->c.resync_mb_y; | |
| 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 | 225 | /* per-row end of slice checks */ |
| 225 | − if (s->msmpeg4_version != MSMP4_UNUSED) { | |
| 226 | − if (s->resync_mb_y + s->slice_height == s->mb_y) { | |
| 227 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 228 | − s->mb_x - 1, s->mb_y, ER_MB_END); | |
| 226 | + if (h->c.msmpeg4_version != MSMP4_UNUSED) { | |
| 227 | + if (h->c.resync_mb_y + h->c.slice_height == h->c.mb_y) { | |
| 228 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 229 | + h->c.mb_x - 1, h->c.mb_y, ER_MB_END); | |
| 229 | 230 | |
| 230 | 231 | return 0; |
| 231 | 232 | } |
| 232 | 233 | } |
| 233 | 234 | |
| 234 | − if (s->msmpeg4_version == MSMP4_V1) { | |
| 235 | − s->last_dc[0] = | |
| 236 | − s->last_dc[1] = | |
| 237 | − s->last_dc[2] = 128; | |
| 235 | + if (h->c.msmpeg4_version == MSMP4_V1) { | |
| 236 | + h->c.last_dc[0] = | |
| 237 | + h->c.last_dc[1] = | |
| 238 | + h->c.last_dc[2] = 128; | |
| 238 | 239 | } |
| 239 | 240 | |
| 240 | − ff_init_block_index(s); | |
| 241 | − for (; s->mb_x < s->mb_width; s->mb_x++) { | |
| 241 | + ff_init_block_index(&h->c); | |
| 242 | + for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) { | |
| 242 | 243 | int ret; |
| 243 | 244 | |
| 244 | − ff_update_block_index(s, s->avctx->bits_per_raw_sample, | |
| 245 | − s->avctx->lowres, s->chroma_x_shift); | |
| 245 | + ff_update_block_index(&h->c, h->c.avctx->bits_per_raw_sample, | |
| 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 | − s->first_slice_line = 0; | |
| 248 | + if (h->c.resync_mb_x == h->c.mb_x && h->c.resync_mb_y + 1 == h->c.mb_y) | |
| 249 | + h->c.first_slice_line = 0; | |
| 249 | 250 | |
| 250 | 251 | /* DCT & quantize */ |
| 251 | 252 | |
| 252 | − s->mv_dir = MV_DIR_FORWARD; | |
| 253 | − s->mv_type = MV_TYPE_16X16; | |
| 254 | − ff_dlog(s->avctx, "%d %06X\n", | |
| 255 | − get_bits_count(&s->gb), show_bits(&s->gb, 24)); | |
| 253 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 254 | + h->c.mv_type = MV_TYPE_16X16; | |
| 255 | + ff_dlog(h->c.avctx, "%d %06X\n", | |
| 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 | − ret = s->decode_mb(s, s->block); | |
| 258 | + ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y); | |
| 259 | + ret = h->decode_mb(h, h->c.block); | |
| 259 | 260 | |
| 260 | − if (s->h263_pred || s->h263_aic) { | |
| 261 | − int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | |
| 262 | − if (!s->mb_intra) { | |
| 263 | − ff_h263_clean_intra_table_entries(s, mb_xy); | |
| 261 | + if (h->c.h263_pred || h->c.h263_aic) { | |
| 262 | + int mb_xy = h->c.mb_y * h->c.mb_stride + h->c.mb_x; | |
| 263 | + if (!h->c.mb_intra) { | |
| 264 | + ff_h263_clean_intra_table_entries(&h->c, mb_xy); | |
| 264 | 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 | − ff_h263_update_motion_val(s); | |
| 269 | + if (h->c.pict_type != AV_PICTURE_TYPE_B) | |
| 270 | + ff_h263_update_motion_val(&h->c); | |
| 270 | 271 | |
| 271 | 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 | 274 | if (ret == SLICE_END) { |
| 274 | − ff_mpv_reconstruct_mb(s, s->block); | |
| 275 | − if (s->loop_filter) | |
| 276 | − ff_h263_loop_filter(s); | |
| 275 | + ff_mpv_reconstruct_mb(&h->c, h->c.block); | |
| 276 | + if (h->c.loop_filter) | |
| 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 | − s->mb_x, s->mb_y, ER_MB_END & part_mask); | |
| 279 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 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 | − s->mb_x = 0; | |
| 285 | − report_decode_progress(s); | |
| 286 | − ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size); | |
| 287 | − s->mb_y++; | |
| 284 | + if (++h->c.mb_x >= h->c.mb_width) { | |
| 285 | + h->c.mb_x = 0; | |
| 286 | + report_decode_progress(&h->c); | |
| 287 | + ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size); | |
| 288 | + h->c.mb_y++; | |
| 288 | 289 | } |
| 289 | 290 | return 0; |
| 290 | 291 | } else if (ret == SLICE_NOEND) { |
| 291 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 292 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 292 | 293 | "Slice mismatch at MB: %d\n", xy); |
| 293 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 294 | − s->mb_x + 1, s->mb_y, | |
| 294 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 295 | + h->c.mb_x + 1, h->c.mb_y, | |
| 295 | 296 | ER_MB_END & part_mask); |
| 296 | 297 | return AVERROR_INVALIDDATA; |
| 297 | 298 | } |
| 298 | − av_log(s->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 | − s->mb_x, s->mb_y, ER_MB_ERROR & part_mask); | |
| 299 | + av_log(h->c.avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); | |
| 300 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 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 | 304 | continue; |
| 304 | 305 | return AVERROR_INVALIDDATA; |
| 305 | 306 | } |
| 306 | 307 | |
| 307 | − ff_mpv_reconstruct_mb(s, s->block); | |
| 308 | − if (s->loop_filter) | |
| 309 | − ff_h263_loop_filter(s); | |
| 308 | + ff_mpv_reconstruct_mb(&h->c, h->c.block); | |
| 309 | + if (h->c.loop_filter) | |
| 310 | + ff_h263_loop_filter(&h->c); | |
| 310 | 311 | } |
| 311 | 312 | |
| 312 | − report_decode_progress(s); | |
| 313 | − ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size); | |
| 313 | + report_decode_progress(&h->c); | |
| 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 | 321 | // Detect incorrect padding with wrong stuffing codes used by NEC N-02B |
| 321 | − if (s->codec_id == AV_CODEC_ID_MPEG4 && | |
| 322 | − (s->workaround_bugs & FF_BUG_AUTODETECT) && | |
| 323 | − get_bits_left(&s->gb) >= 48 && | |
| 324 | − show_bits(&s->gb, 24) == 0x4010 && | |
| 325 | − !s->data_partitioning) | |
| 326 | − s->padding_bug_score += 32; | |
| 322 | + if (h->c.codec_id == AV_CODEC_ID_MPEG4 && | |
| 323 | + (h->c.workaround_bugs & FF_BUG_AUTODETECT) && | |
| 324 | + get_bits_left(&h->c.gb) >= 48 && | |
| 325 | + show_bits(&h->c.gb, 24) == 0x4010 && | |
| 326 | + !h->c.data_partitioning) | |
| 327 | + h->c.padding_bug_score += 32; | |
| 327 | 328 | |
| 328 | 329 | /* try to detect the padding bug */ |
| 329 | − if (s->codec_id == AV_CODEC_ID_MPEG4 && | |
| 330 | − (s->workaround_bugs & FF_BUG_AUTODETECT) && | |
| 331 | − get_bits_left(&s->gb) >= 0 && | |
| 332 | − get_bits_left(&s->gb) < 137 && | |
| 333 | − !s->data_partitioning) { | |
| 334 | − const int bits_count = get_bits_count(&s->gb); | |
| 335 | − const int bits_left = s->gb.size_in_bits - bits_count; | |
| 330 | + if (h->c.codec_id == AV_CODEC_ID_MPEG4 && | |
| 331 | + (h->c.workaround_bugs & FF_BUG_AUTODETECT) && | |
| 332 | + get_bits_left(&h->c.gb) >= 0 && | |
| 333 | + get_bits_left(&h->c.gb) < 137 && | |
| 334 | + !h->c.data_partitioning) { | |
| 335 | + const int bits_count = get_bits_count(&h->c.gb); | |
| 336 | + const int bits_left = h->c.gb.size_in_bits - bits_count; | |
| 336 | 337 | |
| 337 | 338 | if (bits_left == 0) { |
| 338 | − s->padding_bug_score += 16; | |
| 339 | + h->c.padding_bug_score += 16; | |
| 339 | 340 | } else if (bits_left != 1) { |
| 340 | − int v = show_bits(&s->gb, 8); | |
| 341 | + int v = show_bits(&h->c.gb, 8); | |
| 341 | 342 | v |= 0x7F >> (7 - (bits_count & 7)); |
| 342 | 343 | |
| 343 | 344 | if (v == 0x7F && bits_left <= 8) |
| 344 | − s->padding_bug_score--; | |
| 345 | − else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) && | |
| 345 | + h->c.padding_bug_score--; | |
| 346 | + else if (v == 0x7F && ((get_bits_count(&h->c.gb) + 8) & 8) && | |
| 346 | 347 | bits_left <= 16) |
| 347 | − s->padding_bug_score += 4; | |
| 348 | + h->c.padding_bug_score += 4; | |
| 348 | 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 | − (s->workaround_bugs & FF_BUG_AUTODETECT) && | |
| 355 | − get_bits_left(&s->gb) >= 8 && | |
| 356 | − get_bits_left(&s->gb) < 300 && | |
| 357 | − s->pict_type == AV_PICTURE_TYPE_I && | |
| 358 | − show_bits(&s->gb, 8) == 0 && | |
| 359 | − !s->data_partitioning) { | |
| 354 | + if (h->c.codec_id == AV_CODEC_ID_H263 && | |
| 355 | + (h->c.workaround_bugs & FF_BUG_AUTODETECT) && | |
| 356 | + get_bits_left(&h->c.gb) >= 8 && | |
| 357 | + get_bits_left(&h->c.gb) < 300 && | |
| 358 | + h->c.pict_type == AV_PICTURE_TYPE_I && | |
| 359 | + show_bits(&h->c.gb, 8) == 0 && | |
| 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 | − (s->workaround_bugs & FF_BUG_AUTODETECT) && | |
| 366 | − get_bits_left(&s->gb) >= 64 && | |
| 367 | − AV_RB64(s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) { | |
| 365 | + if (h->c.codec_id == AV_CODEC_ID_H263 && | |
| 366 | + (h->c.workaround_bugs & FF_BUG_AUTODETECT) && | |
| 367 | + get_bits_left(&h->c.gb) >= 64 && | |
| 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 | 374 | if ( |
| 374 | − (s->padding_bug_score > -2 && !s->data_partitioning)) | |
| 375 | − s->workaround_bugs |= FF_BUG_NO_PADDING; | |
| 375 | + (h->c.padding_bug_score > -2 && !h->c.data_partitioning)) | |
| 376 | + h->c.workaround_bugs |= FF_BUG_NO_PADDING; | |
| 376 | 377 | else |
| 377 | − s->workaround_bugs &= ~FF_BUG_NO_PADDING; | |
| 378 | + h->c.workaround_bugs &= ~FF_BUG_NO_PADDING; | |
| 378 | 379 | } |
| 379 | 380 | |
| 380 | 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 | − int left = get_bits_left(&s->gb); | |
| 382 | + if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly | |
| 383 | + int left = get_bits_left(&h->c.gb); | |
| 383 | 384 | int max_extra = 7; |
| 384 | 385 | |
| 385 | 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 | 388 | max_extra += 17; |
| 388 | 389 | |
| 389 | 390 | /* buggy padding but the frame should still end approximately at |
| 390 | 391 | * the bitstream end */ |
| 391 | − if ((s->workaround_bugs & FF_BUG_NO_PADDING) && | |
| 392 | − (s->avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) | |
| 392 | + if ((h->c.workaround_bugs & FF_BUG_NO_PADDING) && | |
| 393 | + (h->c.avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) | |
| 393 | 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 | 396 | max_extra += 256 * 256 * 256 * 64; |
| 396 | 397 | |
| 397 | 398 | if (left > max_extra) |
| 398 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 399 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 399 | 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 | 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 | 404 | else |
| 404 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 405 | − s->mb_x - 1, s->mb_y, ER_MB_END); | |
| 405 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 406 | + h->c.mb_x - 1, h->c.mb_y, ER_MB_END); | |
| 406 | 407 | |
| 407 | 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 | 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 | 416 | ER_MB_END & part_mask); |
| 416 | 417 | |
| 417 | 418 | return AVERROR_INVALIDDATA; |
| @@ -420,9 +421,10 @@ static int decode_slice(MpegEncContext *s) · 2 unmodified lines | ||
| 420 | 421 | int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, |
| 421 | 422 | int *got_frame, AVPacket *avpkt) |
| 422 | 423 | { |
| 424 | + H263DecContext *const h = avctx->priv_data; | |
| 425 | + MPVContext *const s = &h->c; | |
| 423 | 426 | const uint8_t *buf = avpkt->data; |
| 424 | 427 | int buf_size = avpkt->size; |
| 425 | − MpegEncContext *s = avctx->priv_data; | |
| 426 | 428 | int ret; |
| 427 | 429 | int slice_ret = 0; |
| 428 | 430 | int bak_width, bak_height; |
| @@ -430,10 +432,10 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1 unmodified line | ||
| 430 | 432 | /* no supplementary picture */ |
| 431 | 433 | if (buf_size == 0) { |
| 432 | 434 | /* special case for last picture */ |
| 433 | − if ((!s->low_delay || s->skipped_last_frame) && s->next_pic.ptr) { | |
| 434 | − if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0) | |
| 435 | + if ((!h->c.low_delay || h->c.skipped_last_frame) && h->c.next_pic.ptr) { | |
| 436 | + if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0) | |
| 435 | 437 | return ret; |
| 436 | − if (s->skipped_last_frame) { | |
| 438 | + if (h->c.skipped_last_frame) { | |
| 437 | 439 | /* If the stream ended with an NVOP, we output the last frame |
| 438 | 440 | * in display order, but with the props from the last input |
| 439 | 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 | 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 | 449 | *got_frame = 1; |
| 448 | 450 | } |
| @@ -450,37 +452,37 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1 unmodified line | ||
| 450 | 452 | return 0; |
| 451 | 453 | } |
| 452 | 454 | |
| 453 | − // s->gb might be overridden in ff_mpeg4_decode_picture_header() below. | |
| 454 | − ret = init_get_bits8(&s->gb, buf, buf_size); | |
| 455 | + // h->c.gb might be overridden in ff_mpeg4_decode_picture_header() below. | |
| 456 | + ret = init_get_bits8(&h->c.gb, buf, buf_size); | |
| 455 | 457 | if (ret < 0) |
| 456 | 458 | return ret; |
| 457 | 459 | |
| 458 | − bak_width = s->width; | |
| 459 | − bak_height = s->height; | |
| 460 | + bak_width = h->c.width; | |
| 461 | + bak_height = h->c.height; | |
| 460 | 462 | |
| 461 | 463 | /* let's go :-) */ |
| 462 | − if (CONFIG_WMV2_DECODER && s->msmpeg4_version == MSMP4_WMV2) { | |
| 463 | − ret = ff_wmv2_decode_picture_header(s); | |
| 464 | + if (CONFIG_WMV2_DECODER && h->c.msmpeg4_version == MSMP4_WMV2) { | |
| 465 | + ret = ff_wmv2_decode_picture_header(h); | |
| 464 | 466 | #if CONFIG_MSMPEG4DEC |
| 465 | − } else if (s->msmpeg4_version != MSMP4_UNUSED) { | |
| 466 | − ret = ff_msmpeg4_decode_picture_header(s); | |
| 467 | + } else if (h->c.msmpeg4_version != MSMP4_UNUSED) { | |
| 468 | + ret = ff_msmpeg4_decode_picture_header(h); | |
| 467 | 469 | #endif |
| 468 | 470 | } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) { |
| 469 | − ret = ff_mpeg4_decode_picture_header(s); | |
| 470 | − } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) { | |
| 471 | − ret = ff_intel_h263_decode_picture_header(s); | |
| 472 | − } else if (CONFIG_FLV_DECODER && s->h263_flv) { | |
| 473 | − ret = ff_flv_decode_picture_header(s); | |
| 471 | + ret = ff_mpeg4_decode_picture_header(h); | |
| 472 | + } else if (CONFIG_H263I_DECODER && h->c.codec_id == AV_CODEC_ID_H263I) { | |
| 473 | + ret = ff_intel_h263_decode_picture_header(h); | |
| 474 | + } else if (CONFIG_FLV_DECODER && h->c.h263_flv) { | |
| 475 | + ret = ff_flv_decode_picture_header(h); | |
| 474 | 476 | } else { |
| 475 | − ret = ff_h263_decode_picture_header(s); | |
| 477 | + ret = ff_h263_decode_picture_header(h); | |
| 476 | 478 | } |
| 477 | 479 | |
| 478 | 480 | if (ret < 0 || ret == FRAME_SKIPPED) { |
| 479 | − if ( s->width != bak_width | |
| 480 | − || s->height != bak_height) { | |
| 481 | − av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n"); | |
| 482 | − s->width = bak_width; | |
| 483 | − s->height= bak_height; | |
| 481 | + if ( h->c.width != bak_width | |
| 482 | + || h->c.height != bak_height) { | |
| 483 | + av_log(h->c.avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n"); | |
| 484 | + h->c.width = bak_width; | |
| 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 | 492 | /* skip if the header was thrashed */ |
| 491 | 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 | 495 | return ret; |
| 494 | 496 | } |
| 495 | 497 | |
| 496 | − if (!s->context_initialized) { | |
| 498 | + if (!h->c.context_initialized) { | |
| 497 | 499 | avctx->pix_fmt = h263_get_format(avctx); |
| 498 | 500 | if ((ret = ff_mpv_common_init(s)) < 0) |
| 499 | 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 | 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 | 508 | return AVERROR_INVALIDDATA; |
| 507 | 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 | 511 | ff_mpv_idct_init(s); |
| 510 | 512 | } |
| 511 | 513 | |
| 512 | 514 | /* After H.263 & MPEG-4 header decode we have the height, width, |
| 513 | − * and other parameters. So then we could init the picture. | |
| 514 | − * FIXME: By the way H.263 decoder is evolving it should have | |
| 515 | − * an H263EncContext */ | |
| 516 | − if (s->width != avctx->coded_width || | |
| 517 | − s->height != avctx->coded_height || | |
| 518 | − s->context_reinit) { | |
| 515 | + * and other parameters. So then we could init the picture. */ | |
| 516 | + if (h->c.width != avctx->coded_width || | |
| 517 | + h->c.height != avctx->coded_height || | |
| 518 | + h->c.context_reinit) { | |
| 519 | 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 | 523 | if (ret < 0) |
| 524 | 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 | 538 | /* skip B-frames if we don't have reference frames */ |
| 539 | − if (!s->last_pic.ptr && | |
| 540 | − (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) | |
| 539 | + if (!h->c.last_pic.ptr && | |
| 540 | + (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.droppable)) | |
| 541 | 541 | return buf_size; |
| 542 | 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 | 544 | (avctx->skip_frame >= AVDISCARD_NONKEY && |
| 545 | − s->pict_type != AV_PICTURE_TYPE_I) || | |
| 545 | + h->c.pict_type != AV_PICTURE_TYPE_I) || | |
| 546 | 546 | avctx->skip_frame >= AVDISCARD_ALL) |
| 547 | 547 | return buf_size; |
| 548 | 548 | |
| 549 | 549 | if ((ret = ff_mpv_frame_start(s, avctx)) < 0) |
| 550 | 550 | return ret; |
| 551 | 551 | |
| 552 | − if (!s->divx_packed) | |
| 552 | + if (!h->c.divx_packed) | |
| 553 | 553 | ff_thread_finish_setup(avctx); |
| 554 | 554 | |
| 555 | 555 | if (avctx->hwaccel) { |
| 556 | 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 | 558 | if (ret < 0 ) |
| 559 | 559 | return ret; |
| 560 | 560 | } |
| @@ -565,8 +565,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 4 unmodified lines | ||
| 565 | 565 | * are stored in current_picture->mb_type which is not available before |
| 566 | 566 | * ff_mpv_frame_start() */ |
| 567 | 567 | #if CONFIG_WMV2_DECODER |
| 568 | − if (s->msmpeg4_version == MSMP4_WMV2) { | |
| 569 | − ret = ff_wmv2_decode_secondary_picture_header(s); | |
| 568 | + if (h->c.msmpeg4_version == MSMP4_WMV2) { | |
| 569 | + ret = ff_wmv2_decode_secondary_picture_header(h); | |
| 570 | 570 | if (ret < 0) |
| 571 | 571 | return ret; |
| 572 | 572 | if (ret == 1) |
| @@ -575,39 +575,39 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 2 unmodified lines | ||
| 575 | 575 | #endif |
| 576 | 576 | |
| 577 | 577 | /* decode each macroblock */ |
| 578 | − s->mb_x = 0; | |
| 579 | − s->mb_y = 0; | |
| 580 | − | |
| 581 | − slice_ret = decode_slice(s); | |
| 582 | − while (s->mb_y < s->mb_height) { | |
| 583 | − if (s->msmpeg4_version != MSMP4_UNUSED) { | |
| 584 | − if (s->slice_height == 0 || s->mb_x != 0 || slice_ret < 0 || | |
| 585 | − (s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0) | |
| 578 | + h->c.mb_x = 0; | |
| 579 | + h->c.mb_y = 0; | |
| 580 | + | |
| 581 | + slice_ret = decode_slice(h); | |
| 582 | + while (h->c.mb_y < h->c.mb_height) { | |
| 583 | + if (h->c.msmpeg4_version != MSMP4_UNUSED) { | |
| 584 | + if (h->c.slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 || | |
| 585 | + (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->c.gb) < 0) | |
| 586 | 586 | break; |
| 587 | 587 | } else { |
| 588 | − int prev_x = s->mb_x, prev_y = s->mb_y; | |
| 589 | − if (ff_h263_resync(s) < 0) | |
| 588 | + int prev_x = h->c.mb_x, prev_y = h->c.mb_y; | |
| 589 | + if (ff_h263_resync(h) < 0) | |
| 590 | 590 | break; |
| 591 | − if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x) | |
| 592 | − s->er.error_occurred = 1; | |
| 591 | + if (prev_y * h->c.mb_width + prev_x < h->c.mb_y * h->c.mb_width + h->c.mb_x) | |
| 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 | 596 | ff_mpeg4_clean_buffers(s); |
| 597 | 597 | |
| 598 | − if (decode_slice(s) < 0) | |
| 598 | + if (decode_slice(h) < 0) | |
| 599 | 599 | slice_ret = AVERROR_INVALIDDATA; |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | − if (s->msmpeg4_version != MSMP4_UNUSED && s->msmpeg4_version < MSMP4_WMV1 && | |
| 603 | − s->pict_type == AV_PICTURE_TYPE_I) | |
| 602 | + if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.msmpeg4_version < MSMP4_WMV1 && | |
| 603 | + h->c.pict_type == AV_PICTURE_TYPE_I) | |
| 604 | 604 | if (!CONFIG_MSMPEG4DEC || |
| 605 | − ff_msmpeg4_decode_ext_header(s, buf_size) < 0) | |
| 606 | − s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR; | |
| 605 | + ff_msmpeg4_decode_ext_header(h, buf_size) < 0) | |
| 606 | + h->c.er.error_status_table[h->c.mb_num - 1] = ER_MB_ERROR; | |
| 607 | 607 | |
| 608 | 608 | frame_end: |
| 609 | − if (!s->studio_profile) | |
| 610 | − ff_er_frame_end(&s->er, NULL); | |
| 609 | + if (!h->c.studio_profile) | |
| 610 | + ff_er_frame_end(&h->c.er, NULL); | |
| 611 | 611 | |
| 612 | 612 | if (avctx->hwaccel) { |
| 613 | 613 | ret = FF_HW_SIMPLE_CALL(avctx, end_frame); |
| @@ -620,22 +620,22 @@ frame_end: · 6 unmodified lines | ||
| 620 | 620 | if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) |
| 621 | 621 | ff_mpeg4_frame_end(avctx, avpkt); |
| 622 | 622 | |
| 623 | − av_assert1(s->pict_type == s->cur_pic.ptr->f->pict_type); | |
| 624 | − if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { | |
| 625 | − if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0) | |
| 623 | + av_assert1(h->c.pict_type == h->c.cur_pic.ptr->f->pict_type); | |
| 624 | + if (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.low_delay) { | |
| 625 | + if ((ret = av_frame_ref(pict, h->c.cur_pic.ptr->f)) < 0) | |
| 626 | 626 | return ret; |
| 627 | − ff_print_debug_info(s, s->cur_pic.ptr, pict); | |
| 628 | − ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); | |
| 629 | − } else if (s->last_pic.ptr) { | |
| 630 | − if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0) | |
| 627 | + ff_print_debug_info(s, h->c.cur_pic.ptr, pict); | |
| 628 | + ff_mpv_export_qp_table(s, pict, h->c.cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); | |
| 629 | + } else if (h->c.last_pic.ptr) { | |
| 630 | + if ((ret = av_frame_ref(pict, h->c.last_pic.ptr->f)) < 0) | |
| 631 | 631 | return ret; |
| 632 | − ff_print_debug_info(s, s->last_pic.ptr, pict); | |
| 633 | − ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); | |
| 632 | + ff_print_debug_info(s, h->c.last_pic.ptr, pict); | |
| 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 | 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 | 639 | for (int p = 0; p < 3; p++) { |
| 640 | 640 | int h = AV_CEIL_RSHIFT(pict->height, !!p); |
| 641 | 641 | |
| @@ -673,7 +673,7 @@ const FFCodec ff_h263_decoder = { · 31 unmodified lines | ||
| 673 | 673 | CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), |
| 674 | 674 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 675 | 675 | .p.id = AV_CODEC_ID_H263, |
| 676 | − .priv_data_size = sizeof(MpegEncContext), | |
| 676 | + .priv_data_size = sizeof(H263DecContext), | |
| 677 | 677 | .init = ff_h263_decode_init, |
| 678 | 678 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 679 | 679 | .close = ff_mpv_decode_close, |
| @@ -691,7 +691,7 @@ const FFCodec ff_h263p_decoder = { · 11 unmodified lines | ||
| 691 | 691 | CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), |
| 692 | 692 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 693 | 693 | .p.id = AV_CODEC_ID_H263P, |
| 694 | − .priv_data_size = sizeof(MpegEncContext), | |
| 694 | + .priv_data_size = sizeof(H263DecContext), | |
| 695 | 695 | .init = ff_h263_decode_init, |
| 696 | 696 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 697 | 697 | .close = ff_mpv_decode_close, |
| @@ -43,24 +43,30 @@ extern VLCElem ff_h263_inter_MCBPC_vlc[]; · 42 unmodified lines | ||
| 43 | 43 | extern VLCElem ff_h263_cbpy_vlc[]; |
| 44 | 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 | 53 | int ff_h263_decode_init(AVCodecContext *avctx); |
| 48 | 54 | int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *frame, |
| 49 | 55 | int *got_frame, AVPacket *avpkt); |
| 50 | 56 | void ff_h263_decode_init_vlc(void); |
| 51 | −int ff_h263_decode_picture_header(MpegEncContext *s); | |
| 52 | −int ff_h263_decode_gob_header(MpegEncContext *s); | |
| 53 | −int ff_h263_decode_mba(MpegEncContext *s); | |
| 57 | +int ff_h263_decode_picture_header(H263DecContext *const h); | |
| 58 | +int ff_h263_decode_gob_header(H263DecContext *const h); | |
| 59 | +int ff_h263_decode_mba(H263DecContext *const h); | |
| 54 | 60 | |
| 55 | 61 | /** |
| 56 | 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); | |
| 61 | −int ff_h263_decode_mb(MpegEncContext *s, | |
| 66 | +int ff_intel_h263_decode_picture_header(H263DecContext *const h); | |
| 67 | +int ff_h263_decode_mb(H263DecContext *const h, | |
| 62 | 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 | 72 | #endif |
| @@ -26,102 +26,102 @@ · 25 unmodified lines | ||
| 26 | 26 | #include "h263dec.h" |
| 27 | 27 | |
| 28 | 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 | 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 | 34 | return FRAME_SKIPPED; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /* picture header */ |
| 38 | − if (get_bits(&s->gb, 22) != 0x20) { | |
| 39 | − av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); | |
| 38 | + if (get_bits(&h->c.gb, 22) != 0x20) { | |
| 39 | + av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n"); | |
| 40 | 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 | 45 | return -1; /* marker */ |
| 46 | 46 | } |
| 47 | − if (get_bits1(&s->gb) != 0) { | |
| 48 | − av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n"); | |
| 47 | + if (get_bits1(&h->c.gb) != 0) { | |
| 48 | + av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n"); | |
| 49 | 49 | return -1; /* H.263 id */ |
| 50 | 50 | } |
| 51 | − skip_bits1(&s->gb); /* split screen off */ | |
| 52 | − skip_bits1(&s->gb); /* camera off */ | |
| 53 | − skip_bits1(&s->gb); /* freeze picture release off */ | |
| 51 | + skip_bits1(&h->c.gb); /* split screen off */ | |
| 52 | + skip_bits1(&h->c.gb); /* camera 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 | 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 | 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) { | |
| 66 | − av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n"); | |
| 65 | + if (get_bits1(&h->c.gb) != 0) { | |
| 66 | + av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n"); | |
| 67 | 67 | return -1; /* SAC: off */ |
| 68 | 68 | } |
| 69 | − s->obmc= get_bits1(&s->gb); | |
| 70 | − s->pb_frame = get_bits1(&s->gb); | |
| 69 | + h->c.obmc = get_bits1(&h->c.gb); | |
| 70 | + h->c.pb_frame = get_bits1(&h->c.gb); | |
| 71 | 71 | |
| 72 | 72 | if (format < 6) { |
| 73 | − s->width = ff_h263_format[format][0]; | |
| 74 | − s->height = ff_h263_format[format][1]; | |
| 75 | − s->avctx->sample_aspect_ratio.num = 12; | |
| 76 | − s->avctx->sample_aspect_ratio.den = 11; | |
| 73 | + h->c.width = ff_h263_format[format][0]; | |
| 74 | + h->c.height = ff_h263_format[format][1]; | |
| 75 | + h->c.avctx->sample_aspect_ratio.num = 12; | |
| 76 | + h->c.avctx->sample_aspect_ratio.den = 11; | |
| 77 | 77 | } else { |
| 78 | − format = get_bits(&s->gb, 3); | |
| 78 | + format = get_bits(&h->c.gb, 3); | |
| 79 | 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 | 81 | return -1; |
| 82 | 82 | } |
| 83 | − if(get_bits(&s->gb, 2)) | |
| 84 | − av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
| 85 | − s->loop_filter = get_bits1(&s->gb) * !s->avctx->lowres; | |
| 86 | − if(get_bits1(&s->gb)) | |
| 87 | − av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
| 88 | − if(get_bits1(&s->gb)) | |
| 89 | − s->pb_frame = 2; | |
| 90 | − if(get_bits(&s->gb, 5)) | |
| 91 | − av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
| 92 | − if(get_bits(&s->gb, 5) != 1) | |
| 93 | − av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n"); | |
| 83 | + if (get_bits(&h->c.gb, 2)) | |
| 84 | + av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
| 85 | + h->c.loop_filter = get_bits1(&h->c.gb) * !h->c.avctx->lowres; | |
| 86 | + if (get_bits1(&h->c.gb)) | |
| 87 | + av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
| 88 | + if (get_bits1(&h->c.gb)) | |
| 89 | + h->c.pb_frame = 2; | |
| 90 | + if (get_bits(&h->c.gb, 5)) | |
| 91 | + av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
| 92 | + if (get_bits(&h->c.gb, 5) != 1) | |
| 93 | + av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n"); | |
| 94 | 94 | } |
| 95 | 95 | if(format == 6){ |
| 96 | − int ar = get_bits(&s->gb, 4); | |
| 97 | − skip_bits(&s->gb, 9); // display width | |
| 98 | − check_marker(s->avctx, &s->gb, "in dimensions"); | |
| 99 | − skip_bits(&s->gb, 9); // display height | |
| 100 | − if(ar == 15){ | |
| 101 | − s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width | |
| 102 | − s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height | |
| 96 | + int ar = get_bits(&h->c.gb, 4); | |
| 97 | + skip_bits(&h->c.gb, 9); // display width | |
| 98 | + check_marker(h->c.avctx, &h->c.gb, "in dimensions"); | |
| 99 | + skip_bits(&h->c.gb, 9); // display height | |
| 100 | + if (ar == 15) { | |
| 101 | + h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); // aspect ratio - width | |
| 102 | + h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); // aspect ratio - height | |
| 103 | 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) | |
| 107 | − av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n"); | |
| 106 | + if (h->c.avctx->sample_aspect_ratio.num == 0) | |
| 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); | |
| 111 | − skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | |
| 110 | + h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); | |
| 111 | + skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */ | |
| 112 | 112 | |
| 113 | − if(s->pb_frame){ | |
| 114 | − skip_bits(&s->gb, 3); //temporal reference for B-frame | |
| 115 | − skip_bits(&s->gb, 2); //dbquant | |
| 113 | + if (h->c.pb_frame) { | |
| 114 | + skip_bits(&h->c.gb, 3); //temporal reference for B-frame | |
| 115 | + skip_bits(&h->c.gb, 2); //dbquant | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /* PEI */ |
| 119 | − if (skip_1stop_8data_bits(&s->gb) < 0) | |
| 119 | + if (skip_1stop_8data_bits(&h->c.gb) < 0) | |
| 120 | 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 | 126 | return 0; |
| 127 | 127 | } |
| @@ -131,7 +131,7 @@ const FFCodec ff_h263i_decoder = { · 3 unmodified lines | ||
| 131 | 131 | CODEC_LONG_NAME("Intel H.263"), |
| 132 | 132 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 133 | 133 | .p.id = AV_CODEC_ID_H263I, |
| 134 | − .priv_data_size = sizeof(MpegEncContext), | |
| 134 | + .priv_data_size = sizeof(H263DecContext), | |
| 135 | 135 | .init = ff_h263_decode_init, |
| 136 | 136 | FF_CODEC_DECODE_CB(ff_h263_decode_frame), |
| 137 | 137 | .close = ff_mpv_decode_close, |
| @@ -77,23 +77,22 @@ static const int16_t h263_mb_type_b_map[15]= { · 76 unmodified lines | ||
| 77 | 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){ | |
| 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", | |
| 84 | − s->qscale, av_get_picture_type_char(s->pict_type), | |
| 85 | − s->gb.size_in_bits, 1-s->no_rounding, | |
| 86 | − s->obmc ? " AP" : "", | |
| 87 | − s->umvplus ? " UMV" : "", | |
| 88 | − s->h263_long_vectors ? " LONG" : "", | |
| 89 | − h263_plus ? " +" : "", | |
| 90 | − s->h263_aic ? " AIC" : "", | |
| 91 | − s->alt_inter_vlc ? " AIV" : "", | |
| 92 | − s->modified_quant ? " MQ" : "", | |
| 93 | − s->loop_filter ? " LOOP" : "", | |
| 94 | − s->h263_slice_structured ? " SS" : "", | |
| 95 | − s->avctx->framerate.num, s->avctx->framerate.den | |
| 96 | − ); | |
| 82 | + if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) { | |
| 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 | + h->c.qscale, av_get_picture_type_char(h->c.pict_type), | |
| 85 | + h->c.gb.size_in_bits, 1-h->c.no_rounding, | |
| 86 | + h->c.obmc ? " AP" : "", | |
| 87 | + h->c.umvplus ? " UMV" : "", | |
| 88 | + h->c.h263_long_vectors ? " LONG" : "", | |
| 89 | + h263_plus ? " +" : "", | |
| 90 | + h->c.h263_aic ? " AIC" : "", | |
| 91 | + h->c.alt_inter_vlc ? " AIV" : "", | |
| 92 | + h->c.modified_quant ? " MQ" : "", | |
| 93 | + h->c.loop_filter ? " LOOP" : "", | |
| 94 | + h->c.h263_slice_structured ? " SS" : "", | |
| 95 | + h->c.avctx->framerate.num, h->c.avctx->framerate.den); | |
| 97 | 96 | } |
| 98 | 97 | } |
| 99 | 98 | |
| @@ -140,16 +139,16 @@ av_cold void ff_h263_decode_init_vlc(void) · 40 unmodified lines | ||
| 140 | 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 | 144 | int i, mb_pos; |
| 146 | 145 | |
| 147 | 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 | 148 | break; |
| 150 | − mb_pos = get_bits(&s->gb, ff_mba_length[i]); | |
| 151 | − s->mb_x = mb_pos % s->mb_width; | |
| 152 | − s->mb_y = mb_pos / s->mb_width; | |
| 149 | + mb_pos = get_bits(&h->c.gb, ff_mba_length[i]); | |
| 150 | + h->c.mb_x = mb_pos % h->c.mb_width; | |
| 151 | + h->c.mb_y = mb_pos / h->c.mb_width; | |
| 153 | 152 | |
| 154 | 153 | return mb_pos; |
| 155 | 154 | } |
| @@ -158,53 +157,53 @@ int ff_h263_decode_mba(MpegEncContext *s) · 2 unmodified lines | ||
| 158 | 157 | * Decode the group of blocks header or slice header. |
| 159 | 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 | 162 | unsigned int val, gob_number; |
| 164 | 163 | int left; |
| 165 | 164 | |
| 166 | 165 | /* Check for GOB Start Code */ |
| 167 | − val = show_bits(&s->gb, 16); | |
| 166 | + val = show_bits(&h->c.gb, 16); | |
| 168 | 167 | if(val) |
| 169 | 168 | return -1; |
| 170 | 169 | |
| 171 | 170 | /* We have a GBSC probably with GSTUFF */ |
| 172 | − skip_bits(&s->gb, 16); /* Drop the zeros */ | |
| 173 | − left= get_bits_left(&s->gb); | |
| 171 | + skip_bits(&h->c.gb, 16); /* Drop the zeros */ | |
| 172 | + left = get_bits_left(&h->c.gb); | |
| 174 | 173 | left = FFMIN(left, 32); |
| 175 | 174 | //MN: we must check the bits left or we might end in an infinite loop (or segfault) |
| 176 | 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 | 178 | if(left<=13) |
| 180 | 179 | return -1; |
| 181 | 180 | |
| 182 | − if(s->h263_slice_structured){ | |
| 183 | − if(check_marker(s->avctx, &s->gb, "before MBA")==0) | |
| 181 | + if (h->c.h263_slice_structured) { | |
| 182 | + if (check_marker(h->c.avctx, &h->c.gb, "before MBA")==0) | |
| 184 | 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) | |
| 189 | − if(check_marker(s->avctx, &s->gb, "after MBA")==0) | |
| 187 | + if (h->c.mb_num > 1583) | |
| 188 | + if (check_marker(h->c.avctx, &h->c.gb, "after MBA")==0) | |
| 190 | 189 | return -1; |
| 191 | 190 | |
| 192 | − s->qscale = get_bits(&s->gb, 5); /* SQUANT */ | |
| 193 | − if(check_marker(s->avctx, &s->gb, "after SQUANT")==0) | |
| 191 | + h->c.qscale = get_bits(&h->c.gb, 5); /* SQUANT */ | |
| 192 | + if (check_marker(h->c.avctx, &h->c.gb, "after SQUANT")==0) | |
| 194 | 193 | return -1; |
| 195 | − skip_bits(&s->gb, 2); /* GFID */ | |
| 194 | + skip_bits(&h->c.gb, 2); /* GFID */ | |
| 196 | 195 | }else{ |
| 197 | − gob_number = get_bits(&s->gb, 5); /* GN */ | |
| 198 | − s->mb_x= 0; | |
| 199 | − s->mb_y= s->gob_index* gob_number; | |
| 200 | − skip_bits(&s->gb, 2); /* GFID */ | |
| 201 | − s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | |
| 196 | + gob_number = get_bits(&h->c.gb, 5); /* GN */ | |
| 197 | + h->c.mb_x = 0; | |
| 198 | + h->c.mb_y = h->c.gob_index* gob_number; | |
| 199 | + skip_bits(&h->c.gb, 2); /* GFID */ | |
| 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 | 204 | return -1; |
| 206 | 205 | |
| 207 | − if(s->qscale==0) | |
| 206 | + if (h->c.qscale==0) | |
| 208 | 207 | return -1; |
| 209 | 208 | |
| 210 | 209 | return 0; |
| @@ -214,79 +213,80 @@ static int h263_decode_gob_header(MpegEncContext *s) · 3 unmodified lines | ||
| 214 | 213 | * Decode the group of blocks / video packet header / slice header (MPEG-4 Studio). |
| 215 | 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 | 218 | int left, pos, ret; |
| 219 | 219 | |
| 220 | 220 | /* In MPEG-4 studio mode look for a new slice startcode |
| 221 | 221 | * and decode slice header */ |
| 222 | − if(s->codec_id==AV_CODEC_ID_MPEG4 && s->studio_profile) { | |
| 223 | − align_get_bits(&s->gb); | |
| 222 | + if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) { | |
| 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) { | |
| 226 | − get_bits(&s->gb, 8); | |
| 225 | + while (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) != SLICE_STARTCODE) { | |
| 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) | |
| 230 | − return get_bits_count(&s->gb); | |
| 229 | + if (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) == SLICE_STARTCODE) | |
| 230 | + return get_bits_count(&h->c.gb); | |
| 231 | 231 | else |
| 232 | 232 | return -1; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | − if(s->codec_id==AV_CODEC_ID_MPEG4){ | |
| 236 | − skip_bits1(&s->gb); | |
| 237 | − align_get_bits(&s->gb); | |
| 235 | + if (h->c.codec_id==AV_CODEC_ID_MPEG4){ | |
| 236 | + skip_bits1(&h->c.gb); | |
| 237 | + align_get_bits(&h->c.gb); | |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | − if(show_bits(&s->gb, 16)==0){ | |
| 241 | − pos= get_bits_count(&s->gb); | |
| 242 | − if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4) | |
| 243 | − ret = ff_mpeg4_decode_video_packet_header(s); | |
| 240 | + if (show_bits(&h->c.gb, 16) ==0) { | |
| 241 | + pos = get_bits_count(&h->c.gb); | |
| 242 | + if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4) | |
| 243 | + ret = ff_mpeg4_decode_video_packet_header(h); | |
| 244 | 244 | else |
| 245 | − ret= h263_decode_gob_header(s); | |
| 245 | + ret = h263_decode_gob_header(h); | |
| 246 | 246 | if(ret>=0) |
| 247 | 247 | return pos; |
| 248 | 248 | } |
| 249 | 249 | //OK, it's not where it is supposed to be ... |
| 250 | − s->gb= s->last_resync_gb; | |
| 251 | − align_get_bits(&s->gb); | |
| 252 | − left= get_bits_left(&s->gb); | |
| 250 | + h->c.gb = h->c.last_resync_gb; | |
| 251 | + align_get_bits(&h->c.gb); | |
| 252 | + left = get_bits_left(&h->c.gb); | |
| 253 | 253 | |
| 254 | 254 | for(;left>16+1+5+5; left-=8){ |
| 255 | − if(show_bits(&s->gb, 16)==0){ | |
| 256 | − GetBitContext bak= s->gb; | |
| 255 | + if (show_bits(&h->c.gb, 16) == 0){ | |
| 256 | + GetBitContext bak = h->c.gb; | |
| 257 | 257 | |
| 258 | − pos= get_bits_count(&s->gb); | |
| 259 | − if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4) | |
| 260 | − ret = ff_mpeg4_decode_video_packet_header(s); | |
| 258 | + pos = get_bits_count(&h->c.gb); | |
| 259 | + if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4) | |
| 260 | + ret = ff_mpeg4_decode_video_packet_header(h); | |
| 261 | 261 | else |
| 262 | − ret= h263_decode_gob_header(s); | |
| 262 | + ret = h263_decode_gob_header(h); | |
| 263 | 263 | if(ret>=0) |
| 264 | 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 | 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 | 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 | 279 | if (code == 0) |
| 280 | 280 | return pred; |
| 281 | 281 | if (code < 0) |
| 282 | 282 | return 0xffff; |
| 283 | 283 | |
| 284 | − sign = get_bits1(&s->gb); | |
| 284 | + sign = get_bits1(&h->c.gb); | |
| 285 | 285 | shift = f_code - 1; |
| 286 | 286 | val = code; |
| 287 | 287 | if (shift) { |
| 288 | 288 | val = (val - 1) << shift; |
| 289 | − val |= get_bits(&s->gb, shift); | |
| 289 | + val |= get_bits(&h->c.gb, shift); | |
| 290 | 290 | val++; |
| 291 | 291 | } |
| 292 | 292 | if (sign) |
| @@ -294,7 +294,7 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) · 1 unmodified line | ||
| 294 | 294 | val += pred; |
| 295 | 295 | |
| 296 | 296 | /* modulo decoding */ |
| 297 | − if (!s->h263_long_vectors) { | |
| 297 | + if (!h->c.h263_long_vectors) { | |
| 298 | 298 | val = sign_extend(val, 5 + f_code); |
| 299 | 299 | } else { |
| 300 | 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 | 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 | 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 | 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 | 323 | code <<= 1; |
| 324 | − code += get_bits1(&s->gb); | |
| 324 | + code += get_bits1(&h->c.gb); | |
| 325 | 325 | if (code >= 32768) { |
| 326 | − avpriv_request_sample(s->avctx, "Huge DMV"); | |
| 326 | + avpriv_request_sample(h->c.avctx, "Huge DMV"); | |
| 327 | 327 | return 0xffff; |
| 328 | 328 | } |
| 329 | 329 | } |
| @@ -331,7 +331,7 @@ static int h263p_decode_umotion(MpegEncContext * s, int pred) · 1 unmodified line | ||
| 331 | 331 | code >>= 1; |
| 332 | 332 | |
| 333 | 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 | 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 | 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){ | |
| 343 | − GetBitContext gb= s->gb; | |
| 342 | +static void preview_obmc(H263DecContext *const h) | |
| 343 | +{ | |
| 344 | + GetBitContext gb = h->c.gb; | |
| 344 | 345 | |
| 345 | 346 | int cbpc, i, pred_x, pred_y, mx, my; |
| 346 | 347 | int16_t *mot_val; |
| 347 | − const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; | |
| 348 | − const int stride= s->b8_stride*2; | |
| 348 | + const int xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride; | |
| 349 | + const int stride = h->c.b8_stride * 2; | |
| 349 | 350 | |
| 350 | 351 | for(i=0; i<4; i++) |
| 351 | − s->block_index[i]+= 2; | |
| 352 | + h->c.block_index[i] += 2; | |
| 352 | 353 | for(i=4; i<6; i++) |
| 353 | − s->block_index[i]+= 1; | |
| 354 | − s->mb_x++; | |
| 354 | + h->c.block_index[i] += 1; | |
| 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 | 359 | do{ |
| 359 | − if (get_bits1(&s->gb)) { | |
| 360 | + if (get_bits1(&h->c.gb)) { | |
| 360 | 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 | 363 | mot_val[0 ]= mot_val[2 ]= |
| 363 | 364 | mot_val[0+stride]= mot_val[2+stride]= 0; |
| 364 | 365 | mot_val[1 ]= mot_val[3 ]= |
| 365 | 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 | 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 | 372 | }while(cbpc == 20); |
| 372 | 373 | |
| 373 | 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 | 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 | 378 | if (cbpc & 8) { |
| 378 | − if(s->modified_quant){ | |
| 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); | |
| 379 | + skip_bits(&h->c.gb, h->c.modified_quant ? (get_bits1(&h->c.gb) ? 1 : 5) : 2); | |
| 383 | 380 | } |
| 384 | 381 | |
| 385 | 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 | 384 | /* 16x16 motion prediction */ |
| 388 | − mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | |
| 389 | − if (s->umvplus) | |
| 390 | − mx = h263p_decode_umotion(s, pred_x); | |
| 385 | + mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); | |
| 386 | + if (h->c.umvplus) | |
| 387 | + mx = h263p_decode_umotion(h, pred_x); | |
| 391 | 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) | |
| 395 | − my = h263p_decode_umotion(s, pred_y); | |
| 391 | + if (h->c.umvplus) | |
| 392 | + my = h263p_decode_umotion(h, pred_y); | |
| 396 | 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 | 396 | mot_val[0 ]= mot_val[2 ]= |
| 400 | 397 | mot_val[0+stride]= mot_val[2+stride]= mx; |
| 401 | 398 | mot_val[1 ]= mot_val[3 ]= |
| 402 | 399 | mot_val[1+stride]= mot_val[3+stride]= my; |
| 403 | 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 | 402 | for(i=0;i<4;i++) { |
| 406 | − mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | |
| 407 | − if (s->umvplus) | |
| 408 | − mx = h263p_decode_umotion(s, pred_x); | |
| 403 | + mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); | |
| 404 | + if (h->c.umvplus) | |
| 405 | + mx = h263p_decode_umotion(h, pred_x); | |
| 409 | 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) | |
| 413 | − my = h263p_decode_umotion(s, pred_y); | |
| 409 | + if (h->c.umvplus) | |
| 410 | + my = h263p_decode_umotion(h, pred_y); | |
| 414 | 411 | else |
| 415 | − my = ff_h263_decode_motion(s, pred_y, 1); | |
| 416 | − if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 417 | − skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | |
| 412 | + my = ff_h263_decode_motion(h, pred_y, 1); | |
| 413 | + if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 414 | + skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ | |
| 418 | 415 | mot_val[0] = mx; |
| 419 | 416 | mot_val[1] = my; |
| 420 | 417 | } |
| @@ -423,26 +420,27 @@ static void preview_obmc(MpegEncContext *s){ · 2 unmodified lines | ||
| 423 | 420 | end: |
| 424 | 421 | |
| 425 | 422 | for(i=0; i<4; i++) |
| 426 | − s->block_index[i]-= 2; | |
| 423 | + h->c.block_index[i] -= 2; | |
| 427 | 424 | for(i=4; i<6; i++) |
| 428 | − s->block_index[i]-= 1; | |
| 429 | − s->mb_x--; | |
| 425 | + h->c.block_index[i] -= 1; | |
| 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 | 433 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
| 436 | 434 | int qscale; |
| 437 | 435 | |
| 438 | − if(s->modified_quant){ | |
| 439 | − if(get_bits1(&s->gb)) | |
| 440 | − qscale = ff_modified_quant_tab[get_bits1(&s->gb)][s->qscale]; | |
| 436 | + if (h->c.modified_quant) { | |
| 437 | + if (get_bits1(&h->c.gb)) | |
| 438 | + qscale = ff_modified_quant_tab[get_bits1(&h->c.gb)][h->c.qscale]; | |
| 441 | 439 | else |
| 442 | − qscale = get_bits(&s->gb, 5); | |
| 440 | + qscale = get_bits(&h->c.gb, 5); | |
| 443 | 441 | }else |
| 444 | − qscale = s->qscale + quant_tab[get_bits(&s->gb, 2)]; | |
| 445 | − ff_set_qscale(s, qscale); | |
| 442 | + qscale = h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]; | |
| 443 | + ff_set_qscale(&h->c, qscale); | |
| 446 | 444 | } |
| 447 | 445 | |
| 448 | 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 | 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 | 525 | int n, int coded) |
| 528 | 526 | { |
| 529 | 527 | int level, i, j, run; |
| 530 | 528 | const RLTable *rl = &ff_h263_rl_inter; |
| 531 | 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; | |
| 535 | − if (s->h263_aic && s->mb_intra) { | |
| 532 | + scan_table = h->c.intra_scantable.permutated; | |
| 533 | + if (h->c.h263_aic && h->c.mb_intra) { | |
| 536 | 534 | i = 0; |
| 537 | 535 | if (!coded) |
| 538 | 536 | goto not_coded; |
| 539 | 537 | rl = &ff_rl_intra_aic; |
| 540 | − if (s->ac_pred) { | |
| 541 | − if (s->h263_aic_dir) | |
| 542 | − scan_table = s->permutated_intra_v_scantable; /* left */ | |
| 538 | + if (h->c.ac_pred) { | |
| 539 | + if (h->c.h263_aic_dir) | |
| 540 | + scan_table = h->c.permutated_intra_v_scantable; /* left */ | |
| 543 | 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 | 545 | /* DC coef */ |
| 548 | − if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) { | |
| 549 | − if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) { | |
| 546 | + if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) { | |
| 547 | + if (h->c.rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) { | |
| 550 | 548 | int component = (n <= 3 ? 0 : n - 4 + 1); |
| 551 | − level = s->last_dc[component]; | |
| 552 | − if (s->rv10_first_dc_coded[component]) { | |
| 553 | − int diff = ff_rv_decode_dc(s, n); | |
| 549 | + level = h->c.last_dc[component]; | |
| 550 | + if (h->c.rv10_first_dc_coded[component]) { | |
| 551 | + int diff = ff_rv_decode_dc(h, n); | |
| 554 | 552 | if (diff < 0) |
| 555 | 553 | return -1; |
| 556 | 554 | level += diff; |
| 557 | 555 | level = level & 0xff; /* handle wrap round */ |
| 558 | − s->last_dc[component] = level; | |
| 556 | + h->c.last_dc[component] = level; | |
| 559 | 557 | } else { |
| 560 | − s->rv10_first_dc_coded[component] = 1; | |
| 558 | + h->c.rv10_first_dc_coded[component] = 1; | |
| 561 | 559 | } |
| 562 | 560 | } else { |
| 563 | − level = get_bits(&s->gb, 8); | |
| 561 | + level = get_bits(&h->c.gb, 8); | |
| 564 | 562 | if (level == 255) |
| 565 | 563 | level = 128; |
| 566 | 564 | } |
| 567 | 565 | }else{ |
| 568 | − level = get_bits(&s->gb, 8); | |
| 566 | + level = get_bits(&h->c.gb, 8); | |
| 569 | 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); | |
| 571 | − if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) | |
| 568 | + av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", | |
| 569 | + level, h->c.mb_x, h->c.mb_y); | |
| 570 | + if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) | |
| 572 | 571 | return -1; |
| 573 | 572 | } |
| 574 | 573 | if (level == 255) |
| @@ -580,64 +579,65 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block, · 5 unmodified lines | ||
| 580 | 579 | i = 0; |
| 581 | 580 | } |
| 582 | 581 | if (!coded) { |
| 583 | − s->block_last_index[n] = i - 1; | |
| 582 | + h->c.block_last_index[n] = i - 1; | |
| 584 | 583 | return 0; |
| 585 | 584 | } |
| 586 | 585 | retry: |
| 587 | 586 | { |
| 588 | − OPEN_READER(re, &s->gb); | |
| 587 | + OPEN_READER(re, &h->c.gb); | |
| 589 | 588 | i--; // offset by -1 to allow direct indexing of scan_table |
| 590 | 589 | for(;;) { |
| 591 | − UPDATE_CACHE(re, &s->gb); | |
| 592 | − GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | |
| 590 | + UPDATE_CACHE(re, &h->c.gb); | |
| 591 | + GET_RL_VLC(level, run, re, &h->c.gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | |
| 593 | 592 | if (run == 66) { |
| 594 | 593 | if (level){ |
| 595 | − CLOSE_READER(re, &s->gb); | |
| 596 | − av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); | |
| 594 | + CLOSE_READER(re, &h->c.gb); | |
| 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 | 597 | return -1; |
| 598 | 598 | } |
| 599 | 599 | /* escape */ |
| 600 | − if (CONFIG_FLV_DECODER && s->h263_flv > 1) { | |
| 601 | − int is11 = SHOW_UBITS(re, &s->gb, 1); | |
| 602 | − SKIP_CACHE(re, &s->gb, 1); | |
| 603 | − run = SHOW_UBITS(re, &s->gb, 7) + 1; | |
| 600 | + if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) { | |
| 601 | + int is11 = SHOW_UBITS(re, &h->c.gb, 1); | |
| 602 | + SKIP_CACHE(re, &h->c.gb, 1); | |
| 603 | + run = SHOW_UBITS(re, &h->c.gb, 7) + 1; | |
| 604 | 604 | if (is11) { |
| 605 | − SKIP_COUNTER(re, &s->gb, 1 + 7); | |
| 606 | − UPDATE_CACHE(re, &s->gb); | |
| 607 | − level = SHOW_SBITS(re, &s->gb, 11); | |
| 608 | − SKIP_COUNTER(re, &s->gb, 11); | |
| 605 | + SKIP_COUNTER(re, &h->c.gb, 1 + 7); | |
| 606 | + UPDATE_CACHE(re, &h->c.gb); | |
| 607 | + level = SHOW_SBITS(re, &h->c.gb, 11); | |
| 608 | + SKIP_COUNTER(re, &h->c.gb, 11); | |
| 609 | 609 | } else { |
| 610 | − SKIP_CACHE(re, &s->gb, 7); | |
| 611 | − level = SHOW_SBITS(re, &s->gb, 7); | |
| 612 | − SKIP_COUNTER(re, &s->gb, 1 + 7 + 7); | |
| 610 | + SKIP_CACHE(re, &h->c.gb, 7); | |
| 611 | + level = SHOW_SBITS(re, &h->c.gb, 7); | |
| 612 | + SKIP_COUNTER(re, &h->c.gb, 1 + 7 + 7); | |
| 613 | 613 | } |
| 614 | 614 | } else { |
| 615 | − run = SHOW_UBITS(re, &s->gb, 7) + 1; | |
| 616 | − SKIP_CACHE(re, &s->gb, 7); | |
| 617 | − level = (int8_t)SHOW_UBITS(re, &s->gb, 8); | |
| 618 | − SKIP_COUNTER(re, &s->gb, 7 + 8); | |
| 615 | + run = SHOW_UBITS(re, &h->c.gb, 7) + 1; | |
| 616 | + SKIP_CACHE(re, &h->c.gb, 7); | |
| 617 | + level = (int8_t)SHOW_UBITS(re, &h->c.gb, 8); | |
| 618 | + SKIP_COUNTER(re, &h->c.gb, 7 + 8); | |
| 619 | 619 | if(level == -128){ |
| 620 | − UPDATE_CACHE(re, &s->gb); | |
| 621 | − if (s->codec_id == AV_CODEC_ID_RV10) { | |
| 620 | + UPDATE_CACHE(re, &h->c.gb); | |
| 621 | + if (h->c.codec_id == AV_CODEC_ID_RV10) { | |
| 622 | 622 | /* XXX: should patch encoder too */ |
| 623 | − level = SHOW_SBITS(re, &s->gb, 12); | |
| 624 | − SKIP_COUNTER(re, &s->gb, 12); | |
| 623 | + level = SHOW_SBITS(re, &h->c.gb, 12); | |
| 624 | + SKIP_COUNTER(re, &h->c.gb, 12); | |
| 625 | 625 | }else{ |
| 626 | − level = SHOW_UBITS(re, &s->gb, 5); | |
| 627 | − SKIP_CACHE(re, &s->gb, 5); | |
| 628 | − level |= SHOW_SBITS(re, &s->gb, 6) * (1<<5); | |
| 629 | − SKIP_COUNTER(re, &s->gb, 5 + 6); | |
| 626 | + level = SHOW_UBITS(re, &h->c.gb, 5); | |
| 627 | + SKIP_CACHE(re, &h->c.gb, 5); | |
| 628 | + level |= SHOW_SBITS(re, &h->c.gb, 6) * (1<<5); | |
| 629 | + SKIP_COUNTER(re, &h->c.gb, 5 + 6); | |
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | } else { |
| 634 | − if (SHOW_UBITS(re, &s->gb, 1)) | |
| 634 | + if (SHOW_UBITS(re, &h->c.gb, 1)) | |
| 635 | 635 | level = -level; |
| 636 | − SKIP_COUNTER(re, &s->gb, 1); | |
| 636 | + SKIP_COUNTER(re, &h->c.gb, 1); | |
| 637 | 637 | } |
| 638 | 638 | i += run; |
| 639 | 639 | if (i >= 64){ |
| 640 | − CLOSE_READER(re, &s->gb); | |
| 640 | + CLOSE_READER(re, &h->c.gb); | |
| 641 | 641 | // redo update without last flag, revert -1 offset |
| 642 | 642 | i = i - run + ((run-1)&63) + 1; |
| 643 | 643 | if (i < 64) { |
| @@ -645,48 +645,49 @@ retry: · 1 unmodified line | ||
| 645 | 645 | block[scan_table[i]] = level; |
| 646 | 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 | 649 | //Looks like a hack but no, it's the way it is supposed to work ... |
| 650 | 650 | rl = &ff_rl_intra_aic; |
| 651 | 651 | i = 0; |
| 652 | − s->gb= gb; | |
| 653 | − s->bdsp.clear_block(block); | |
| 652 | + h->c.gb = gb; | |
| 653 | + h->c.bdsp.clear_block(block); | |
| 654 | 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 | 658 | return -1; |
| 658 | 659 | } |
| 659 | 660 | j = scan_table[i]; |
| 660 | 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 | 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 | 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 | 674 | LOCAL_ALIGNED_32(int16_t, dblock, [64]); |
| 674 | 675 | int i, mbi; |
| 675 | 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 | 679 | * but real value should be restored in order to be used later (in OBMC condition) |
| 679 | 680 | */ |
| 680 | − mbi = s->mb_intra; | |
| 681 | − memcpy(bli, s->block_last_index, sizeof(bli)); | |
| 682 | − s->mb_intra = 0; | |
| 681 | + mbi = h->c.mb_intra; | |
| 682 | + memcpy(bli, h->c.block_last_index, sizeof(bli)); | |
| 683 | + h->c.mb_intra = 0; | |
| 683 | 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 | 686 | return -1; |
| 686 | 687 | cbp+=cbp; |
| 687 | 688 | } |
| 688 | − s->mb_intra = mbi; | |
| 689 | − memcpy(s->block_last_index, bli, sizeof(bli)); | |
| 689 | + h->c.mb_intra = mbi; | |
| 690 | + memcpy(h->c.block_last_index, bli, sizeof(bli)); | |
| 690 | 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 | − int16_t block[6][64]) | |
| 779 | +int ff_h263_decode_mb(H263DecContext *const h, int16_t block[6][64]) | |
| 780 | 780 | { |
| 781 | 781 | int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; |
| 782 | 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 | 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 | 789 | do{ |
| 790 | − if (get_bits1(&s->gb)) { | |
| 790 | + if (get_bits1(&h->c.gb)) { | |
| 791 | 791 | /* skip mb */ |
| 792 | − s->mb_intra = 0; | |
| 792 | + h->c.mb_intra = 0; | |
| 793 | 793 | for(i=0;i<6;i++) |
| 794 | − s->block_last_index[i] = -1; | |
| 795 | − s->mv_dir = MV_DIR_FORWARD; | |
| 796 | − s->mv_type = MV_TYPE_16X16; | |
| 797 | − s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 798 | − s->mv[0][0][0] = 0; | |
| 799 | − s->mv[0][0][1] = 0; | |
| 800 | − s->mb_skipped = !(s->obmc | s->loop_filter); | |
| 794 | + h->c.block_last_index[i] = -1; | |
| 795 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 796 | + h->c.mv_type = MV_TYPE_16X16; | |
| 797 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 798 | + h->c.mv[0][0][0] = 0; | |
| 799 | + h->c.mv[0][0][1] = 0; | |
| 800 | + h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter); | |
| 801 | 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 | 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 | 807 | return SLICE_ERROR; |
| 807 | 808 | } |
| 808 | 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 | 813 | dquant = cbpc & 8; |
| 813 | − s->mb_intra = ((cbpc & 4) != 0); | |
| 814 | − if (s->mb_intra) goto intra; | |
| 814 | + h->c.mb_intra = ((cbpc & 4) != 0); | |
| 815 | + if (h->c.mb_intra) | |
| 816 | + goto intra; | |
| 815 | 817 | |
| 816 | − if(s->pb_frame && get_bits1(&s->gb)) | |
| 817 | − pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); | |
| 818 | − cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 818 | + if(h->c.pb_frame && get_bits1(&h->c.gb)) | |
| 819 | + pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb); | |
| 820 | + cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 819 | 821 | |
| 820 | 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 | 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 | 829 | cbpy ^= 0xF; |
| 827 | 830 | |
| 828 | 831 | cbp = (cbpc & 3) | (cbpy << 2); |
| 829 | 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 | 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 | 839 | /* 16x16 motion prediction */ |
| 837 | − s->mv_type = MV_TYPE_16X16; | |
| 838 | − ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | |
| 839 | − if (s->umvplus) | |
| 840 | − mx = h263p_decode_umotion(s, pred_x); | |
| 840 | + h->c.mv_type = MV_TYPE_16X16; | |
| 841 | + ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); | |
| 842 | + if (h->c.umvplus) | |
| 843 | + mx = h263p_decode_umotion(h, pred_x); | |
| 841 | 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 | 847 | if (mx >= 0xffff) |
| 845 | 848 | return SLICE_ERROR; |
| 846 | 849 | |
| 847 | − if (s->umvplus) | |
| 848 | − my = h263p_decode_umotion(s, pred_y); | |
| 850 | + if (h->c.umvplus) | |
| 851 | + my = h263p_decode_umotion(h, pred_y); | |
| 849 | 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 | 855 | if (my >= 0xffff) |
| 853 | 856 | return SLICE_ERROR; |
| 854 | − s->mv[0][0][0] = mx; | |
| 855 | − s->mv[0][0][1] = my; | |
| 857 | + h->c.mv[0][0][0] = mx; | |
| 858 | + h->c.mv[0][0][1] = my; | |
| 856 | 859 | |
| 857 | − if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 858 | − skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | |
| 860 | + if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 861 | + skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ | |
| 859 | 862 | } else { |
| 860 | − s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; | |
| 861 | − s->mv_type = MV_TYPE_8X8; | |
| 863 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; | |
| 864 | + h->c.mv_type = MV_TYPE_8X8; | |
| 862 | 865 | for(i=0;i<4;i++) { |
| 863 | − mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | |
| 864 | − if (s->umvplus) | |
| 865 | − mx = h263p_decode_umotion(s, pred_x); | |
| 866 | + mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); | |
| 867 | + if (h->c.umvplus) | |
| 868 | + mx = h263p_decode_umotion(h, pred_x); | |
| 866 | 869 | else |
| 867 | − mx = ff_h263_decode_motion(s, pred_x, 1); | |
| 870 | + mx = ff_h263_decode_motion(h, pred_x, 1); | |
| 868 | 871 | if (mx >= 0xffff) |
| 869 | 872 | return SLICE_ERROR; |
| 870 | 873 | |
| 871 | − if (s->umvplus) | |
| 872 | − my = h263p_decode_umotion(s, pred_y); | |
| 874 | + if (h->c.umvplus) | |
| 875 | + my = h263p_decode_umotion(h, pred_y); | |
| 873 | 876 | else |
| 874 | − my = ff_h263_decode_motion(s, pred_y, 1); | |
| 877 | + my = ff_h263_decode_motion(h, pred_y, 1); | |
| 875 | 878 | if (my >= 0xffff) |
| 876 | 879 | return SLICE_ERROR; |
| 877 | − s->mv[0][i][0] = mx; | |
| 878 | − s->mv[0][i][1] = my; | |
| 879 | − if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 880 | − skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | |
| 880 | + h->c.mv[0][i][0] = mx; | |
| 881 | + h->c.mv[0][i][1] = my; | |
| 882 | + if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 883 | + skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ | |
| 881 | 884 | mot_val[0] = mx; |
| 882 | 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 | 889 | int mb_type; |
| 887 | − const int stride= s->b8_stride; | |
| 888 | − int16_t *mot_val0 = s->cur_pic.motion_val[0][2 * (s->mb_x + s->mb_y * stride)]; | |
| 889 | − int16_t *mot_val1 = s->cur_pic.motion_val[1][2 * (s->mb_x + s->mb_y * stride)]; | |
| 890 | −// const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; | |
| 890 | + const int stride = h->c.b8_stride; | |
| 891 | + int16_t *mot_val0 = h->c.cur_pic.motion_val[0][2 * (h->c.mb_x + h->c.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)]; | |
| 893 | +// const int mv_xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride; | |
| 891 | 894 | |
| 892 | 895 | //FIXME ugly |
| 893 | 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 | 899 | mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; |
| 897 | 900 | |
| 898 | 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 | 903 | H263_MBTYPE_B_VLC_BITS, 2); |
| 901 | 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 | 907 | return SLICE_ERROR; |
| 904 | 908 | } |
| 905 | 909 | }while(!mb_type); |
| 906 | 910 | |
| 907 | − s->mb_intra = IS_INTRA(mb_type); | |
| 911 | + h->c.mb_intra = IS_INTRA(mb_type); | |
| 908 | 912 | if(HAS_CBP(mb_type)){ |
| 909 | − s->bdsp.clear_blocks(s->block[0]); | |
| 910 | − cbpc = get_vlc2(&s->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1); | |
| 911 | − if(s->mb_intra){ | |
| 913 | + h->c.bdsp.clear_blocks(h->c.block[0]); | |
| 914 | + cbpc = get_vlc2(&h->c.gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1); | |
| 915 | + if (h->c.mb_intra) { | |
| 912 | 916 | dquant = IS_QUANT(mb_type); |
| 913 | 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 | 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 | 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 | 929 | cbpy ^= 0xF; |
| 925 | 930 | |
| 926 | 931 | cbp = (cbpc & 3) | (cbpy << 2); |
| 927 | 932 | }else |
| 928 | 933 | cbp=0; |
| 929 | 934 | |
| 930 | − av_assert2(!s->mb_intra); | |
| 935 | + av_assert2(!h->c.mb_intra); | |
| 931 | 936 | |
| 932 | 937 | if(IS_QUANT(mb_type)){ |
| 933 | − h263_decode_dquant(s); | |
| 938 | + h263_decode_dquant(h); | |
| 934 | 939 | } |
| 935 | 940 | |
| 936 | 941 | if(IS_DIRECT(mb_type)){ |
| 937 | − s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
| 938 | − mb_type |= set_direct_mv(s); | |
| 942 | + h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
| 943 | + mb_type |= set_direct_mv(&h->c); | |
| 939 | 944 | }else{ |
| 940 | − s->mv_dir = 0; | |
| 941 | − s->mv_type= MV_TYPE_16X16; | |
| 945 | + h->c.mv_dir = 0; | |
| 946 | + h->c.mv_type = MV_TYPE_16X16; | |
| 942 | 947 | //FIXME UMV |
| 943 | 948 | |
| 944 | 949 | if (HAS_FORWARD_MV(mb_type)) { |
| 945 | − int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | |
| 946 | − s->mv_dir = MV_DIR_FORWARD; | |
| 950 | + int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); | |
| 951 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 947 | 952 | |
| 948 | − if (s->umvplus) | |
| 949 | − mx = h263p_decode_umotion(s, pred_x); | |
| 953 | + if (h->c.umvplus) | |
| 954 | + mx = h263p_decode_umotion(h, pred_x); | |
| 950 | 955 | else |
| 951 | − mx = ff_h263_decode_motion(s, pred_x, 1); | |
| 956 | + mx = ff_h263_decode_motion(h, pred_x, 1); | |
| 952 | 957 | if (mx >= 0xffff) |
| 953 | 958 | return SLICE_ERROR; |
| 954 | 959 | |
| 955 | − if (s->umvplus) | |
| 956 | − my = h263p_decode_umotion(s, pred_y); | |
| 960 | + if (h->c.umvplus) | |
| 961 | + my = h263p_decode_umotion(h, pred_y); | |
| 957 | 962 | else |
| 958 | − my = ff_h263_decode_motion(s, pred_y, 1); | |
| 963 | + my = ff_h263_decode_motion(h, pred_y, 1); | |
| 959 | 964 | if (my >= 0xffff) |
| 960 | 965 | return SLICE_ERROR; |
| 961 | 966 | |
| 962 | − if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 963 | − skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | |
| 967 | + if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 968 | + skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ | |
| 964 | 969 | |
| 965 | − s->mv[0][0][0] = mx; | |
| 966 | − s->mv[0][0][1] = my; | |
| 970 | + h->c.mv[0][0][0] = mx; | |
| 971 | + h->c.mv[0][0][1] = my; | |
| 967 | 972 | mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
| 968 | 973 | mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; |
| 969 | 974 | } |
| 970 | 975 | |
| 971 | 976 | if (HAS_BACKWARD_MV(mb_type)) { |
| 972 | − int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y); | |
| 973 | − s->mv_dir |= MV_DIR_BACKWARD; | |
| 977 | + int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y); | |
| 978 | + h->c.mv_dir |= MV_DIR_BACKWARD; | |
| 974 | 979 | |
| 975 | − if (s->umvplus) | |
| 976 | − mx = h263p_decode_umotion(s, pred_x); | |
| 980 | + if (h->c.umvplus) | |
| 981 | + mx = h263p_decode_umotion(h, pred_x); | |
| 977 | 982 | else |
| 978 | − mx = ff_h263_decode_motion(s, pred_x, 1); | |
| 983 | + mx = ff_h263_decode_motion(h, pred_x, 1); | |
| 979 | 984 | if (mx >= 0xffff) |
| 980 | 985 | return SLICE_ERROR; |
| 981 | 986 | |
| 982 | − if (s->umvplus) | |
| 983 | − my = h263p_decode_umotion(s, pred_y); | |
| 987 | + if (h->c.umvplus) | |
| 988 | + my = h263p_decode_umotion(h, pred_y); | |
| 984 | 989 | else |
| 985 | − my = ff_h263_decode_motion(s, pred_y, 1); | |
| 990 | + my = ff_h263_decode_motion(h, pred_y, 1); | |
| 986 | 991 | if (my >= 0xffff) |
| 987 | 992 | return SLICE_ERROR; |
| 988 | 993 | |
| 989 | − if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 990 | − skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | |
| 994 | + if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) | |
| 995 | + skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */ | |
| 991 | 996 | |
| 992 | − s->mv[1][0][0] = mx; | |
| 993 | − s->mv[1][0][1] = my; | |
| 997 | + h->c.mv[1][0][0] = mx; | |
| 998 | + h->c.mv[1][0][1] = my; | |
| 994 | 999 | mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
| 995 | 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 | 1005 | } else { /* I-Frame */ |
| 1001 | 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 | 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 | 1011 | return SLICE_ERROR; |
| 1006 | 1012 | } |
| 1007 | 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 | 1017 | dquant = cbpc & 4; |
| 1012 | − s->mb_intra = 1; | |
| 1018 | + h->c.mb_intra = 1; | |
| 1013 | 1019 | intra: |
| 1014 | − s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | |
| 1015 | − if (s->h263_aic) { | |
| 1016 | − s->ac_pred = get_bits1(&s->gb); | |
| 1017 | − if(s->ac_pred){ | |
| 1018 | − s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; | |
| 1020 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; | |
| 1021 | + if (h->c.h263_aic) { | |
| 1022 | + h->c.ac_pred = get_bits1(&h->c.gb); | |
| 1023 | + if (h->c.ac_pred) { | |
| 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 | 1028 | }else |
| 1023 | − s->ac_pred = 0; | |
| 1029 | + h->c.ac_pred = 0; | |
| 1024 | 1030 | |
| 1025 | − if(s->pb_frame && get_bits1(&s->gb)) | |
| 1026 | − pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); | |
| 1027 | − cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 1031 | + if (h->c.pb_frame && get_bits1(&h->c.gb)) | |
| 1032 | + pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb); | |
| 1033 | + cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 1028 | 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 | 1037 | return SLICE_ERROR; |
| 1031 | 1038 | } |
| 1032 | 1039 | cbp = (cbpc & 3) | (cbpy << 2); |
| 1033 | 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 | 1047 | while(pb_mv_count--){ |
| 1041 | − ff_h263_decode_motion(s, 0, 1); | |
| 1042 | − ff_h263_decode_motion(s, 0, 1); | |
| 1048 | + ff_h263_decode_motion(h, 0, 1); | |
| 1049 | + ff_h263_decode_motion(h, 0, 1); | |
| 1043 | 1050 | } |
| 1044 | 1051 | |
| 1045 | 1052 | /* decode each block */ |
| 1046 | 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 | 1055 | return -1; |
| 1049 | 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 | 1060 | return -1; |
| 1054 | − if(s->obmc && !s->mb_intra){ | |
| 1055 | − if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1) | |
| 1056 | − preview_obmc(s); | |
| 1061 | + if (h->c.obmc && !h->c.mb_intra) { | |
| 1062 | + if (h->c.pict_type == AV_PICTURE_TYPE_P && | |
| 1063 | + h->c.mb_x + 1 < h->c.mb_width && h->c.mb_num_left != 1) | |
| 1064 | + preview_obmc(h); | |
| 1057 | 1065 | } |
| 1058 | 1066 | end: |
| 1059 | 1067 | |
| 1060 | − if (get_bits_left(&s->gb) < 0) | |
| 1068 | + if (get_bits_left(&h->c.gb) < 0) | |
| 1061 | 1069 | return AVERROR_INVALIDDATA; |
| 1062 | 1070 | |
| 1063 | 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) { | |
| 1068 | − v >>= 16 - get_bits_left(&s->gb); | |
| 1075 | + if (get_bits_left(&h->c.gb) < 16) { | |
| 1076 | + v >>= 16 - get_bits_left(&h->c.gb); | |
| 1069 | 1077 | } |
| 1070 | 1078 | |
| 1071 | 1079 | if(v==0) |
| @@ -1076,51 +1084,50 @@ end: · 4 unmodified lines | ||
| 1076 | 1084 | } |
| 1077 | 1085 | |
| 1078 | 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; | |
| 1082 | − uint32_t startcode; | |
| 1089 | + int width, height, i, ret; | |
| 1083 | 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) { | |
| 1088 | − av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n"); | |
| 1094 | + if (show_bits(&h->c.gb, 2) == 2 && h->c.avctx->frame_num == 0) { | |
| 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) { | |
| 1094 | − startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF; | |
| 1100 | + for (i = get_bits_left(&h->c.gb); i>24; i -= 8) { | |
| 1101 | + startcode = ((startcode << 8) | get_bits(&h->c.gb, 8)) & 0x003FFFFF; | |
| 1095 | 1102 | |
| 1096 | 1103 | if(startcode == 0x20) |
| 1097 | 1104 | break; |
| 1098 | 1105 | } |
| 1099 | 1106 | |
| 1100 | 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 | 1109 | return -1; |
| 1103 | 1110 | } |
| 1104 | 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 | 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 | 1120 | return -1; |
| 1114 | 1121 | } |
| 1115 | − if (get_bits1(&s->gb) != 0) { | |
| 1116 | − av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n"); | |
| 1122 | + if (get_bits1(&h->c.gb) != 0) { | |
| 1123 | + av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n"); | |
| 1117 | 1124 | return -1; /* H.263 id */ |
| 1118 | 1125 | } |
| 1119 | − skip_bits1(&s->gb); /* split screen off */ | |
| 1120 | − skip_bits1(&s->gb); /* camera off */ | |
| 1121 | − skip_bits1(&s->gb); /* freeze picture release off */ | |
| 1126 | + skip_bits1(&h->c.gb); /* split screen off */ | |
| 1127 | + skip_bits1(&h->c.gb); /* camera 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 | 1132 | 0 forbidden |
| 1126 | 1133 | 1 sub-QCIF |
| @@ -1136,88 +1143,88 @@ int ff_h263_decode_picture_header(MpegEncContext *s) · 9 unmodified lines | ||
| 1136 | 1143 | if (!width) |
| 1137 | 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) { | |
| 1144 | − av_log(s->avctx, AV_LOG_ERROR, "H.263 SAC not supported\n"); | |
| 1150 | + if (get_bits1(&h->c.gb) != 0) { | |
| 1151 | + av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n"); | |
| 1145 | 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); | |
| 1150 | − s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); | |
| 1151 | − skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | |
| 1156 | + h->c.pb_frame = get_bits1(&h->c.gb); | |
| 1157 | + h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); | |
| 1158 | + skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */ | |
| 1152 | 1159 | |
| 1153 | − s->width = width; | |
| 1154 | − s->height = height; | |
| 1155 | − s->avctx->sample_aspect_ratio= (AVRational){12,11}; | |
| 1156 | − s->avctx->framerate = (AVRational){ 30000, 1001 }; | |
| 1160 | + h->c.width = width; | |
| 1161 | + h->c.height = height; | |
| 1162 | + h->c.avctx->sample_aspect_ratio= (AVRational){12,11}; | |
| 1163 | + h->c.avctx->framerate = (AVRational){ 30000, 1001 }; | |
| 1157 | 1164 | } else { |
| 1158 | 1165 | int ufep; |
| 1159 | 1166 | |
| 1160 | 1167 | /* H.263v2 */ |
| 1161 | 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 | 1171 | /* ufep other than 0 and 1 are reserved */ |
| 1165 | 1172 | if (ufep == 1) { |
| 1166 | 1173 | /* OPPTYPE */ |
| 1167 | − format = get_bits(&s->gb, 3); | |
| 1168 | − ff_dlog(s->avctx, "ufep=1, format: %d\n", format); | |
| 1169 | − s->custom_pcf= get_bits1(&s->gb); | |
| 1170 | − s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */ | |
| 1171 | − if (get_bits1(&s->gb) != 0) { | |
| 1172 | − av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); | |
| 1174 | + format = get_bits(&h->c.gb, 3); | |
| 1175 | + ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format); | |
| 1176 | + h->c.custom_pcf = get_bits1(&h->c.gb); | |
| 1177 | + h->c.umvplus = get_bits1(&h->c.gb); /* Unrestricted Motion Vector */ | |
| 1178 | + if (get_bits1(&h->c.gb) != 0) { | |
| 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 */ | |
| 1175 | − s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ | |
| 1176 | − s->loop_filter= get_bits1(&s->gb); | |
| 1177 | − if(s->avctx->lowres) | |
| 1178 | − s->loop_filter = 0; | |
| 1179 | − | |
| 1180 | − s->h263_slice_structured= get_bits1(&s->gb); | |
| 1181 | − if (get_bits1(&s->gb) != 0) { | |
| 1182 | − av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); | |
| 1181 | + h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */ | |
| 1182 | + h->c.h263_aic = get_bits1(&h->c.gb); /* Advanced Intra Coding (AIC) */ | |
| 1183 | + h->c.loop_filter = get_bits1(&h->c.gb); | |
| 1184 | + if (h->c.avctx->lowres) | |
| 1185 | + h->c.loop_filter = 0; | |
| 1186 | + | |
| 1187 | + h->c.h263_slice_structured= get_bits1(&h->c.gb); | |
| 1188 | + if (get_bits1(&h->c.gb) != 0) { | |
| 1189 | + av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); | |
| 1183 | 1190 | } |
| 1184 | − if (get_bits1(&s->gb) != 0) { | |
| 1185 | − av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); | |
| 1191 | + if (get_bits1(&h->c.gb) != 0) { | |
| 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); | |
| 1188 | − s->modified_quant= get_bits1(&s->gb); | |
| 1189 | − if(s->modified_quant) | |
| 1190 | − s->chroma_qscale_table= ff_h263_chroma_qscale_table; | |
| 1194 | + h->c.alt_inter_vlc = get_bits1(&h->c.gb); | |
| 1195 | + h->c.modified_quant = get_bits1(&h->c.gb); | |
| 1196 | + if (h->c.modified_quant) | |
| 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 | 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 | 1204 | return -1; |
| 1198 | 1205 | } |
| 1199 | 1206 | |
| 1200 | 1207 | /* MPPTYPE */ |
| 1201 | − s->pict_type = get_bits(&s->gb, 3); | |
| 1202 | − switch(s->pict_type){ | |
| 1203 | − case 0: s->pict_type= AV_PICTURE_TYPE_I;break; | |
| 1204 | − case 1: s->pict_type= AV_PICTURE_TYPE_P;break; | |
| 1205 | − case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break; | |
| 1206 | − case 3: s->pict_type= AV_PICTURE_TYPE_B;break; | |
| 1207 | − case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO | |
| 1208 | + h->c.pict_type = get_bits(&h->c.gb, 3); | |
| 1209 | + switch (h->c.pict_type) { | |
| 1210 | + case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break; | |
| 1211 | + case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break; | |
| 1212 | + case 2: h->c.pict_type = AV_PICTURE_TYPE_P; h->c.pb_frame = 3; break; | |
| 1213 | + case 3: h->c.pict_type = AV_PICTURE_TYPE_B; break; | |
| 1214 | + case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO | |
| 1208 | 1215 | default: |
| 1209 | 1216 | return -1; |
| 1210 | 1217 | } |
| 1211 | − skip_bits(&s->gb, 2); | |
| 1212 | − s->no_rounding = get_bits1(&s->gb); | |
| 1213 | − skip_bits(&s->gb, 4); | |
| 1218 | + skip_bits(&h->c.gb, 2); | |
| 1219 | + h->c.no_rounding = get_bits1(&h->c.gb); | |
| 1220 | + skip_bits(&h->c.gb, 4); | |
| 1214 | 1221 | |
| 1215 | 1222 | /* Get the picture dimensions */ |
| 1216 | 1223 | if (ufep) { |
| 1217 | 1224 | if (format == 6) { |
| 1218 | 1225 | /* Custom Picture Format (CPFMT) */ |
| 1219 | − int aspect_ratio_info = get_bits(&s->gb, 4); | |
| 1220 | − ff_dlog(s->avctx, "aspect: %d\n", aspect_ratio_info); | |
| 1226 | + int aspect_ratio_info = get_bits(&h->c.gb, 4); | |
| 1227 | + ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info); | |
| 1221 | 1228 | /* aspect ratios: |
| 1222 | 1229 | 0 - forbidden |
| 1223 | 1230 | 1 - 1:1 |
| @@ -1227,153 +1234,151 @@ int ff_h263_decode_picture_header(MpegEncContext *s) · 3 unmodified lines | ||
| 1227 | 1234 | 5 - 40:33 (525-type 16:9) |
| 1228 | 1235 | 6-14 - reserved |
| 1229 | 1236 | */ |
| 1230 | − width = (get_bits(&s->gb, 9) + 1) * 4; | |
| 1231 | − check_marker(s->avctx, &s->gb, "in dimensions"); | |
| 1232 | − height = get_bits(&s->gb, 9) * 4; | |
| 1233 | − ff_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); | |
| 1237 | + width = (get_bits(&h->c.gb, 9) + 1) * 4; | |
| 1238 | + check_marker(h->c.avctx, &h->c.gb, "in dimensions"); | |
| 1239 | + height = get_bits(&h->c.gb, 9) * 4; | |
| 1240 | + ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); | |
| 1234 | 1241 | if (aspect_ratio_info == FF_ASPECT_EXTENDED) { |
| 1235 | 1242 | /* expected dimensions */ |
| 1236 | − s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8); | |
| 1237 | − s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8); | |
| 1243 | + h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); | |
| 1244 | + h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); | |
| 1238 | 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 | 1248 | } else { |
| 1242 | 1249 | width = ff_h263_format[format][0]; |
| 1243 | 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 | 1254 | if ((width == 0) || (height == 0)) |
| 1248 | 1255 | return -1; |
| 1249 | − s->width = width; | |
| 1250 | − s->height = height; | |
| 1251 | − | |
| 1252 | − if(s->custom_pcf){ | |
| 1253 | − int gcd; | |
| 1254 | − s->avctx->framerate.num = 1800000; | |
| 1255 | − s->avctx->framerate.den = 1000 + get_bits1(&s->gb); | |
| 1256 | − s->avctx->framerate.den *= get_bits(&s->gb, 7); | |
| 1257 | − if(s->avctx->framerate.den == 0){ | |
| 1258 | − av_log(s->avctx, AV_LOG_ERROR, "zero framerate\n"); | |
| 1256 | + h->c.width = width; | |
| 1257 | + h->c.height = height; | |
| 1258 | + | |
| 1259 | + if (h->c.custom_pcf) { | |
| 1260 | + h->c.avctx->framerate.num = 1800000; | |
| 1261 | + h->c.avctx->framerate.den = 1000 + get_bits1(&h->c.gb); | |
| 1262 | + h->c.avctx->framerate.den *= get_bits(&h->c.gb, 7); | |
| 1263 | + if (h->c.avctx->framerate.den == 0) { | |
| 1264 | + av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n"); | |
| 1259 | 1265 | return -1; |
| 1260 | 1266 | } |
| 1261 | − gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num); | |
| 1262 | − s->avctx->framerate.den /= gcd; | |
| 1263 | − s->avctx->framerate.num /= gcd; | |
| 1267 | + int gcd = av_gcd(h->c.avctx->framerate.den, h->c.avctx->framerate.num); | |
| 1268 | + h->c.avctx->framerate.den /= gcd; | |
| 1269 | + h->c.avctx->framerate.num /= gcd; | |
| 1264 | 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){ | |
| 1270 | − skip_bits(&s->gb, 2); //extended Temporal reference | |
| 1271 | − } | |
| 1275 | + if (h->c.custom_pcf) | |
| 1276 | + skip_bits(&h->c.gb, 2); //extended Temporal reference | |
| 1272 | 1277 | |
| 1273 | 1278 | if (ufep) { |
| 1274 | − if (s->umvplus) { | |
| 1275 | − if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
| 1276 | − skip_bits1(&s->gb); | |
| 1279 | + if (h->c.umvplus) { | |
| 1280 | + if(get_bits1(&h->c.gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
| 1281 | + skip_bits1(&h->c.gb); | |
| 1277 | 1282 | } |
| 1278 | − if(s->h263_slice_structured){ | |
| 1279 | − if (get_bits1(&s->gb) != 0) { | |
| 1280 | − av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); | |
| 1283 | + if (h->c.h263_slice_structured) { | |
| 1284 | + if (get_bits1(&h->c.gb) != 0) { | |
| 1285 | + av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); | |
| 1281 | 1286 | } |
| 1282 | − if (get_bits1(&s->gb) != 0) { | |
| 1283 | − av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n"); | |
| 1287 | + if (get_bits1(&h->c.gb) != 0) { | |
| 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) { | |
| 1287 | − skip_bits(&s->gb, 4); //ELNUM | |
| 1291 | + if (h->c.pict_type == AV_PICTURE_TYPE_B) { | |
| 1292 | + skip_bits(&h->c.gb, 4); //ELNUM | |
| 1288 | 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 | 1303 | if (ret < 0) |
| 1299 | 1304 | return ret; |
| 1300 | 1305 | |
| 1301 | − if (!(s->avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) { | |
| 1302 | − if ((s->width * s->height / 256 / 8) > get_bits_left(&s->gb)) | |
| 1306 | + if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) { | |
| 1307 | + if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->c.gb)) | |
| 1303 | 1308 | return AVERROR_INVALIDDATA; |
| 1304 | 1309 | } |
| 1305 | 1310 | |
| 1306 | − s->mb_width = (s->width + 15) / 16; | |
| 1307 | − s->mb_height = (s->height + 15) / 16; | |
| 1308 | − s->mb_num = s->mb_width * s->mb_height; | |
| 1311 | + h->c.mb_width = (h->c.width + 15U) / 16; | |
| 1312 | + h->c.mb_height = (h->c.height + 15U) / 16; | |
| 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) { | |
| 1313 | − skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */ | |
| 1314 | − if (s->custom_pcf) | |
| 1315 | − skip_bits(&s->gb, 2); //extended Temporal reference | |
| 1316 | − skip_bits(&s->gb, 2); /* Quantization information for B-pictures */ | |
| 1317 | + if (h->c.pb_frame) { | |
| 1318 | + skip_bits(&h->c.gb, 3); /* Temporal reference for B-pictures */ | |
| 1319 | + if (h->c.custom_pcf) | |
| 1320 | + skip_bits(&h->c.gb, 2); //extended Temporal reference | |
| 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) { | |
| 1320 | − s->time = s->picture_number; | |
| 1321 | − s->pp_time = s->time - s->last_non_b_time; | |
| 1322 | − s->last_non_b_time = s->time; | |
| 1324 | + if (h->c.pict_type!=AV_PICTURE_TYPE_B) { | |
| 1325 | + h->c.time = h->c.picture_number; | |
| 1326 | + h->c.pp_time = h->c.time - h->c.last_non_b_time; | |
| 1327 | + h->c.last_non_b_time = h->c.time; | |
| 1323 | 1328 | }else{ |
| 1324 | − s->time = s->picture_number; | |
| 1325 | − s->pb_time = s->pp_time - (s->last_non_b_time - s->time); | |
| 1326 | − if (s->pp_time <=s->pb_time || | |
| 1327 | − s->pp_time <= s->pp_time - s->pb_time || | |
| 1328 | − s->pp_time <= 0){ | |
| 1329 | − s->pp_time = 2; | |
| 1330 | − s->pb_time = 1; | |
| 1329 | + h->c.time = h->c.picture_number; | |
| 1330 | + h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time); | |
| 1331 | + if (h->c.pp_time <= h->c.pb_time || | |
| 1332 | + h->c.pp_time <= h->c.pp_time - h->c.pb_time || | |
| 1333 | + h->c.pp_time <= 0) { | |
| 1334 | + h->c.pp_time = 2; | |
| 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 | 1340 | /* PEI */ |
| 1336 | − if (skip_1stop_8data_bits(&s->gb) < 0) | |
| 1341 | + if (skip_1stop_8data_bits(&h->c.gb) < 0) | |
| 1337 | 1342 | return AVERROR_INVALIDDATA; |
| 1338 | 1343 | |
| 1339 | − if(s->h263_slice_structured){ | |
| 1340 | − if (check_marker(s->avctx, &s->gb, "SEPB1") != 1) { | |
| 1344 | + if (h->c.h263_slice_structured) { | |
| 1345 | + if (check_marker(h->c.avctx, &h->c.gb, "SEPB1") != 1) { | |
| 1341 | 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 | 1352 | return -1; |
| 1348 | 1353 | } |
| 1349 | 1354 | } |
| 1350 | 1355 | |
| 1351 | − if (s->pict_type == AV_PICTURE_TYPE_B) | |
| 1352 | − s->low_delay = 0; | |
| 1356 | + if (h->c.pict_type == AV_PICTURE_TYPE_B) | |
| 1357 | + h->c.low_delay = 0; | |
| 1353 | 1358 | |
| 1354 | − if(s->h263_aic){ | |
| 1355 | − s->y_dc_scale_table= | |
| 1356 | − s->c_dc_scale_table= ff_aic_dc_scale_table; | |
| 1359 | + if (h->c.h263_aic) { | |
| 1360 | + h->c.y_dc_scale_table = | |
| 1361 | + h->c.c_dc_scale_table = ff_aic_dc_scale_table; | |
| 1357 | 1362 | }else{ |
| 1358 | − s->y_dc_scale_table= | |
| 1359 | − s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
| 1363 | + h->c.y_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 | 1370 | int i,j; |
| 1366 | − for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); | |
| 1367 | − av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 1371 | + for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb)); | |
| 1372 | + av_log(h->c.avctx, AV_LOG_DEBUG, "\n"); | |
| 1368 | 1373 | for(i=0; i<13; i++){ |
| 1369 | 1374 | for(j=0; j<3; j++){ |
| 1370 | − int v= get_bits(&s->gb, 8); | |
| 1371 | − v |= get_sbits(&s->gb, 8) * (1 << 8); | |
| 1372 | − av_log(s->avctx, AV_LOG_DEBUG, " %5d", v); | |
| 1375 | + int v= get_bits(&h->c.gb, 8); | |
| 1376 | + v |= get_sbits(&h->c.gb, 8) * (1 << 8); | |
| 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 | 1384 | return 0; |
| @@ -84,7 +84,7 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, · 83 unmodified lines | ||
| 84 | 84 | { |
| 85 | 85 | struct Mp4vParseContext *pc = s1->priv_data; |
| 86 | 86 | Mpeg4DecContext *dec_ctx = &pc->dec_ctx; |
| 87 | − MpegEncContext *s = &dec_ctx->m; | |
| 87 | + MPVContext *const s = &dec_ctx->h.c; | |
| 88 | 88 | GetBitContext gb1, *gb = &gb1; |
| 89 | 89 | int ret; |
| 90 | 90 | |
| @@ -124,7 +124,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s) · 33 unmodified lines | ||
| 124 | 124 | |
| 125 | 125 | pc->first_picture = 1; |
| 126 | 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 | 128 | pc->dec_ctx.showed_packed_warning = 1; |
| 129 | 129 | return 0; |
| 130 | 130 | } |
| @@ -81,6 +81,12 @@ static const int16_t mb_type_b_map[4] = { · 80 unmodified lines | ||
| 81 | 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 | 90 | static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx, |
| 85 | 91 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
| 86 | 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 | 325 | * @param n block index (0-3 are luma, 4-5 are chroma) |
| 320 | 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 | 330 | int i; |
| 325 | 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 | 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 | 336 | ac_val1 = ac_val; |
| 331 | − if (s->ac_pred) { | |
| 337 | + if (h->c.ac_pred) { | |
| 332 | 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 | 340 | /* left prediction */ |
| 335 | 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 | 344 | n == 1 || n == 3) { |
| 339 | 345 | /* same qscale */ |
| 340 | 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 | 348 | } else { |
| 343 | 349 | /* different qscale, we must rescale */ |
| 344 | 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 | 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 | 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 | 359 | n == 2 || n == 3) { |
| 354 | 360 | /* same qscale */ |
| 355 | 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 | 363 | } else { |
| 358 | 364 | /* different qscale, we must rescale */ |
| 359 | 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 | 370 | /* left copy */ |
| 365 | 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 | 374 | /* top copy */ |
| 369 | 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 | 383 | static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) |
| 378 | 384 | { |
| 379 | − MpegEncContext *s = &ctx->m; | |
| 380 | − int bits_count = get_bits_count(&s->gb); | |
| 381 | − int v = show_bits(&s->gb, 16); | |
| 385 | + H263DecContext *const h = &ctx->h; | |
| 386 | + int bits_count = get_bits_count(&h->c.gb); | |
| 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 | 390 | return 0; |
| 385 | 391 | |
| 386 | 392 | while (v <= 0xFF) { |
| 387 | − if (s->pict_type == AV_PICTURE_TYPE_B || | |
| 388 | − (v >> (8 - s->pict_type) != 1) || s->partitioned_frame) | |
| 393 | + if (h->c.pict_type == AV_PICTURE_TYPE_B || | |
| 394 | + (v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame) | |
| 389 | 395 | break; |
| 390 | − skip_bits(&s->gb, 8 + s->pict_type); | |
| 391 | − bits_count += 8 + s->pict_type; | |
| 392 | − v = show_bits(&s->gb, 16); | |
| 396 | + skip_bits(&h->c.gb, 8 + h->c.pict_type); | |
| 397 | + bits_count += 8 + h->c.pict_type; | |
| 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 | 402 | v >>= 8; |
| 397 | 403 | v |= 0x7F >> (7 - (bits_count & 7)); |
| 398 | 404 | |
| 399 | 405 | if (v == 0x7F) |
| 400 | − return s->mb_num; | |
| 406 | + return h->c.mb_num; | |
| 401 | 407 | } else { |
| 402 | 408 | static const uint16_t mpeg4_resync_prefix[8] = { |
| 403 | 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 | 412 | if (v == mpeg4_resync_prefix[bits_count & 7]) { |
| 407 | 413 | int len, mb_num; |
| 408 | − int mb_num_bits = av_log2(s->mb_num - 1) + 1; | |
| 409 | − GetBitContext gb = s->gb; | |
| 414 | + int mb_num_bits = av_log2(h->c.mb_num - 1) + 1; | |
| 415 | + GetBitContext gb = h->c.gb; | |
| 410 | 416 | |
| 411 | − skip_bits(&s->gb, 1); | |
| 412 | − align_get_bits(&s->gb); | |
| 417 | + skip_bits(&h->c.gb, 1); | |
| 418 | + align_get_bits(&h->c.gb); | |
| 413 | 419 | |
| 414 | 420 | for (len = 0; len < 32; len++) |
| 415 | − if (get_bits1(&s->gb)) | |
| 421 | + if (get_bits1(&h->c.gb)) | |
| 416 | 422 | break; |
| 417 | 423 | |
| 418 | − mb_num = get_bits(&s->gb, mb_num_bits); | |
| 419 | − if (!mb_num || mb_num > s->mb_num || get_bits_count(&s->gb)+6 > s->gb.size_in_bits) | |
| 424 | + mb_num = get_bits(&h->c.gb, mb_num_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 | 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 | 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 | 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 | 440 | int a = 2 << ctx->sprite_warping_accuracy; |
| 435 | 441 | int rho = 3 - ctx->sprite_warping_accuracy; |
| 436 | 442 | int r = 16 / a; |
| @@ -685,13 +691,12 @@ overflow: · 248 unmodified lines | ||
| 685 | 691 | } |
| 686 | 692 | |
| 687 | 693 | static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) { |
| 688 | − MpegEncContext *s = &ctx->m; | |
| 689 | 694 | int len = FFMIN(ctx->time_increment_bits + 3, 15); |
| 690 | 695 | |
| 691 | 696 | get_bits(gb, len); |
| 692 | 697 | if (get_bits1(gb)) |
| 693 | 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 | 701 | return 0; |
| 697 | 702 | } |
| @@ -700,96 +705,96 @@ static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) { · 2 unmodified lines | ||
| 700 | 705 | * Decode the next video packet. |
| 701 | 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 | 713 | int header_extension = 0, mb_num, len; |
| 709 | 714 | |
| 710 | 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 | 717 | return AVERROR_INVALIDDATA; |
| 713 | 718 | |
| 714 | 719 | for (len = 0; len < 32; len++) |
| 715 | − if (get_bits1(&s->gb)) | |
| 720 | + if (get_bits1(&h->c.gb)) | |
| 716 | 721 | break; |
| 717 | 722 | |
| 718 | − if (len != ff_mpeg4_get_video_packet_prefix_length(s->pict_type, ctx->f_code, ctx->b_code)) { | |
| 719 | − av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n"); | |
| 723 | + if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) { | |
| 724 | + av_log(h->c.avctx, AV_LOG_ERROR, "marker does not match f_code\n"); | |
| 720 | 725 | return AVERROR_INVALIDDATA; |
| 721 | 726 | } |
| 722 | 727 | |
| 723 | 728 | if (ctx->shape != RECT_SHAPE) { |
| 724 | − header_extension = get_bits1(&s->gb); | |
| 729 | + header_extension = get_bits1(&h->c.gb); | |
| 725 | 730 | // FIXME more stuff here |
| 726 | 731 | } |
| 727 | 732 | |
| 728 | − mb_num = get_bits(&s->gb, mb_num_bits); | |
| 729 | − if (mb_num >= s->mb_num || !mb_num) { | |
| 730 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 731 | − "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num); | |
| 733 | + mb_num = get_bits(&h->c.gb, mb_num_bits); | |
| 734 | + if (mb_num >= h->c.mb_num || !mb_num) { | |
| 735 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 736 | + "illegal mb_num in video packet (%d %d) \n", mb_num, h->c.mb_num); | |
| 732 | 737 | return AVERROR_INVALIDDATA; |
| 733 | 738 | } |
| 734 | 739 | |
| 735 | − s->mb_x = mb_num % s->mb_width; | |
| 736 | − s->mb_y = mb_num / s->mb_width; | |
| 740 | + h->c.mb_x = mb_num % h->c.mb_width; | |
| 741 | + h->c.mb_y = mb_num / h->c.mb_width; | |
| 737 | 742 | |
| 738 | 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 | 745 | if (qscale) |
| 741 | − s->chroma_qscale = s->qscale = qscale; | |
| 746 | + h->c.chroma_qscale = h->c.qscale = qscale; | |
| 742 | 747 | } |
| 743 | 748 | |
| 744 | 749 | if (ctx->shape == RECT_SHAPE) |
| 745 | − header_extension = get_bits1(&s->gb); | |
| 750 | + header_extension = get_bits1(&h->c.gb); | |
| 746 | 751 | |
| 747 | 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"); | |
| 752 | − skip_bits(&s->gb, ctx->time_increment_bits); /* time_increment */ | |
| 753 | − check_marker(s->avctx, &s->gb, "before vop_coding_type in video packed header"); | |
| 756 | + check_marker(h->c.avctx, &h->c.gb, "before time_increment in video packed header"); | |
| 757 | + skip_bits(&h->c.gb, ctx->time_increment_bits); /* time_increment */ | |
| 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 | 761 | // FIXME not rect stuff here |
| 757 | 762 | |
| 758 | 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 | 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 | 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 | 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 | 773 | // FIXME reduced res stuff here |
| 769 | 774 | |
| 770 | − if (s->pict_type != AV_PICTURE_TYPE_I) { | |
| 771 | − int f_code = get_bits(&s->gb, 3); /* fcode_for */ | |
| 775 | + if (h->c.pict_type != AV_PICTURE_TYPE_I) { | |
| 776 | + int f_code = get_bits(&h->c.gb, 3); /* fcode_for */ | |
| 772 | 777 | if (f_code == 0) |
| 773 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 778 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 774 | 779 | "Error, video packet header damaged (f_code=0)\n"); |
| 775 | 780 | } |
| 776 | − if (s->pict_type == AV_PICTURE_TYPE_B) { | |
| 777 | − int b_code = get_bits(&s->gb, 3); | |
| 781 | + if (h->c.pict_type == AV_PICTURE_TYPE_B) { | |
| 782 | + int b_code = get_bits(&h->c.gb, 3); | |
| 778 | 783 | if (b_code == 0) |
| 779 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 784 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 780 | 785 | "Error, video packet header damaged (b_code=0)\n"); |
| 781 | 786 | } |
| 782 | 787 | } |
| 783 | 788 | } |
| 784 | 789 | if (ctx->new_pred) |
| 785 | − decode_new_pred(ctx, &s->gb); | |
| 790 | + decode_new_pred(ctx, &h->c.gb); | |
| 786 | 791 | |
| 787 | 792 | return 0; |
| 788 | 793 | } |
| 789 | 794 | |
| 790 | 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 | 798 | /* Reset DC Predictors */ |
| 794 | 799 | s->last_dc[0] = |
| 795 | 800 | s->last_dc[1] = |
| @@ -800,25 +805,25 @@ static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx) · 4 unmodified lines | ||
| 800 | 805 | * Decode the next video packet. |
| 801 | 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; | |
| 806 | − GetBitContext *gb = &s->gb; | |
| 810 | + Mpeg4DecContext *const ctx = h263_to_mpeg4(h); | |
| 811 | + GetBitContext *gb = &h->c.gb; | |
| 807 | 812 | unsigned vlc_len; |
| 808 | 813 | uint16_t mb_num; |
| 809 | 814 | |
| 810 | 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 | 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 | 820 | return AVERROR_INVALIDDATA; |
| 816 | 821 | |
| 817 | − s->mb_x = mb_num % s->mb_width; | |
| 818 | − s->mb_y = mb_num / s->mb_width; | |
| 822 | + h->c.mb_x = mb_num % h->c.mb_width; | |
| 823 | + h->c.mb_y = mb_num / h->c.mb_width; | |
| 819 | 824 | |
| 820 | 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 | 828 | if (get_bits1(gb)) { /* slice_extension_flag */ |
| 824 | 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 | 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 | 853 | int x, y, mb_v, sum, dx, dy, shift; |
| 849 | 854 | int len = 1 << (ctx->f_code + 4); |
| 850 | 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 | 980 | * @param dir_ptr the prediction direction will be stored here |
| 976 | 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 | 985 | int level, code, pred; |
| 981 | 986 | |
| 982 | 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 | 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 | 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 | 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 | 999 | } else { |
| 995 | 1000 | if (IS_3IV1) { |
| 996 | 1001 | if (code == 1) |
| 997 | − level = 2 * get_bits1(&s->gb) - 1; | |
| 1002 | + level = 2 * get_bits1(&h->c.gb) - 1; | |
| 998 | 1003 | else { |
| 999 | − if (get_bits1(&s->gb)) | |
| 1000 | − level = get_bits(&s->gb, code - 1) + (1 << (code - 1)); | |
| 1004 | + if (get_bits1(&h->c.gb)) | |
| 1005 | + level = get_bits(&h->c.gb, code - 1) + (1 << (code - 1)); | |
| 1001 | 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 | 1009 | } else { |
| 1005 | − level = get_xbits(&s->gb, code); | |
| 1010 | + level = get_xbits(&h->c.gb, code); | |
| 1006 | 1011 | } |
| 1007 | 1012 | |
| 1008 | 1013 | if (code > 8) { |
| 1009 | − if (get_bits1(&s->gb) == 0) { /* marker */ | |
| 1010 | − if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) { | |
| 1011 | − av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n"); | |
| 1014 | + if (get_bits1(&h->c.gb) == 0) { /* marker */ | |
| 1015 | + if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) { | |
| 1016 | + av_log(h->c.avctx, AV_LOG_ERROR, "dc marker bit missing\n"); | |
| 1012 | 1017 | return AVERROR_INVALIDDATA; |
| 1013 | 1018 | } |
| 1014 | 1019 | } |
| 1015 | 1020 | } |
| 1016 | 1021 | } |
| 1017 | 1022 | |
| 1018 | − pred = mpeg4_pred_dc(s, n, dir_ptr); | |
| 1019 | − return mpeg4_get_level_dc(s, n, pred, level); | |
| 1023 | + pred = mpeg4_pred_dc(&h->c, n, dir_ptr); | |
| 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 | 1031 | static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) |
| 1027 | 1032 | { |
| 1028 | − MpegEncContext *s = &ctx->m; | |
| 1033 | + H263DecContext *const h = &ctx->h; | |
| 1029 | 1034 | int mb_num = 0; |
| 1030 | 1035 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
| 1031 | 1036 | |
| 1032 | 1037 | /* decode first partition */ |
| 1033 | − s->first_slice_line = 1; | |
| 1034 | − for (; s->mb_y < s->mb_height; s->mb_y++) { | |
| 1035 | − ff_init_block_index(s); | |
| 1036 | − for (; s->mb_x < s->mb_width; s->mb_x++) { | |
| 1037 | − const int xy = s->mb_x + s->mb_y * s->mb_stride; | |
| 1038 | + h->c.first_slice_line = 1; | |
| 1039 | + for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) { | |
| 1040 | + ff_init_block_index(&h->c); | |
| 1041 | + for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) { | |
| 1042 | + const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; | |
| 1038 | 1043 | int cbpc; |
| 1039 | 1044 | int dir = 0; |
| 1040 | 1045 | |
| 1041 | 1046 | mb_num++; |
| 1042 | − ff_update_block_index(s, 8, s->avctx->lowres, 1); | |
| 1043 | − if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) | |
| 1044 | − s->first_slice_line = 0; | |
| 1047 | + ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1); | |
| 1048 | + if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1) | |
| 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 | 1052 | int i; |
| 1048 | 1053 | |
| 1049 | 1054 | do { |
| 1050 | − if (show_bits(&s->gb, 19) == DC_MARKER) | |
| 1055 | + if (show_bits(&h->c.gb, 19) == DC_MARKER) | |
| 1051 | 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 | 1059 | if (cbpc < 0) { |
| 1055 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1056 | − "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | |
| 1060 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1061 | + "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1057 | 1062 | return AVERROR_INVALIDDATA; |
| 1058 | 1063 | } |
| 1059 | 1064 | } while (cbpc == 8); |
| 1060 | 1065 | |
| 1061 | − s->cbp_table[xy] = cbpc & 3; | |
| 1062 | − s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | |
| 1063 | − s->mb_intra = 1; | |
| 1066 | + h->c.cbp_table[xy] = cbpc & 3; | |
| 1067 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; | |
| 1068 | + h->c.mb_intra = 1; | |
| 1064 | 1069 | |
| 1065 | 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 | 1076 | for (i = 0; i < 6; i++) { |
| 1072 | 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 | 1079 | if (dc < 0) { |
| 1075 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1076 | − "DC corrupted at %d %d\n", s->mb_x, s->mb_y); | |
| 1080 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1081 | + "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1077 | 1082 | return dc; |
| 1078 | 1083 | } |
| 1079 | 1084 | dir <<= 1; |
| 1080 | 1085 | if (dc_pred_dir) |
| 1081 | 1086 | dir |= 1; |
| 1082 | 1087 | } |
| 1083 | − s->pred_dir_table[xy] = dir; | |
| 1088 | + h->c.pred_dir_table[xy] = dir; | |
| 1084 | 1089 | } else { /* P/S_TYPE */ |
| 1085 | 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]]; | |
| 1087 | − const int stride = s->b8_stride * 2; | |
| 1091 | + int16_t *const mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]]; | |
| 1092 | + const int stride = h->c.b8_stride * 2; | |
| 1088 | 1093 | |
| 1089 | 1094 | try_again: |
| 1090 | − bits = show_bits(&s->gb, 17); | |
| 1095 | + bits = show_bits(&h->c.gb, 17); | |
| 1091 | 1096 | if (bits == MOTION_MARKER) |
| 1092 | 1097 | return mb_num - 1; |
| 1093 | 1098 | |
| 1094 | − skip_bits1(&s->gb); | |
| 1099 | + skip_bits1(&h->c.gb); | |
| 1095 | 1100 | if (bits & 0x10000) { |
| 1096 | 1101 | /* skip mb */ |
| 1097 | − if (s->pict_type == AV_PICTURE_TYPE_S && | |
| 1102 | + if (h->c.pict_type == AV_PICTURE_TYPE_S && | |
| 1098 | 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 | 1105 | MB_TYPE_16x16 | |
| 1101 | 1106 | MB_TYPE_GMC | |
| 1102 | 1107 | MB_TYPE_FORWARD_MV; |
| 1103 | 1108 | mx = get_amv(ctx, 0); |
| 1104 | 1109 | my = get_amv(ctx, 1); |
| 1105 | 1110 | } else { |
| 1106 | − s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | | |
| 1111 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | | |
| 1107 | 1112 | MB_TYPE_16x16 | |
| 1108 | 1113 | MB_TYPE_FORWARD_MV; |
| 1109 | 1114 | mx = my = 0; |
| @@ -1117,26 +1122,26 @@ try_again: · 7 unmodified lines | ||
| 1117 | 1122 | mot_val[1 + stride] = |
| 1118 | 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 | 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 | 1130 | if (cbpc < 0) { |
| 1126 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1127 | − "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | |
| 1131 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1132 | + "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1128 | 1133 | return AVERROR_INVALIDDATA; |
| 1129 | 1134 | } |
| 1130 | 1135 | if (cbpc == 20) |
| 1131 | 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) { | |
| 1138 | − s->cur_pic.mb_type[xy] = MB_TYPE_INTRA; | |
| 1139 | − s->mbintra_table[xy] = 1; | |
| 1142 | + if (h->c.mb_intra) { | |
| 1143 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA; | |
| 1144 | + h->c.mbintra_table[xy] = 1; | |
| 1140 | 1145 | mot_val[0] = |
| 1141 | 1146 | mot_val[2] = |
| 1142 | 1147 | mot_val[0 + stride] = |
| @@ -1146,33 +1151,33 @@ try_again: · 3 unmodified lines | ||
| 1146 | 1151 | mot_val[1 + stride] = |
| 1147 | 1152 | mot_val[3 + stride] = 0; |
| 1148 | 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 | 1157 | ctx->vol_sprite_usage == GMC_SPRITE && |
| 1153 | 1158 | (cbpc & 16) == 0) |
| 1154 | − s->mcsel = get_bits1(&s->gb); | |
| 1159 | + h->c.mcsel = get_bits1(&h->c.gb); | |
| 1155 | 1160 | else |
| 1156 | − s->mcsel = 0; | |
| 1161 | + h->c.mcsel = 0; | |
| 1157 | 1162 | |
| 1158 | 1163 | if ((cbpc & 16) == 0) { |
| 1159 | 1164 | /* 16x16 motion prediction */ |
| 1160 | 1165 | |
| 1161 | − ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | |
| 1162 | − if (!s->mcsel) { | |
| 1163 | − mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | |
| 1166 | + ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); | |
| 1167 | + if (!h->c.mcsel) { | |
| 1168 | + mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); | |
| 1164 | 1169 | if (mx >= 0xffff) |
| 1165 | 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 | 1173 | if (my >= 0xffff) |
| 1169 | 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 | 1176 | MB_TYPE_FORWARD_MV; |
| 1172 | 1177 | } else { |
| 1173 | 1178 | mx = get_amv(ctx, 0); |
| 1174 | 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 | 1181 | MB_TYPE_GMC | |
| 1177 | 1182 | MB_TYPE_FORWARD_MV; |
| 1178 | 1183 | } |
| @@ -1187,15 +1192,15 @@ try_again: · 8 unmodified lines | ||
| 1187 | 1192 | mot_val[3 + stride] = my; |
| 1188 | 1193 | } else { |
| 1189 | 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 | 1196 | MB_TYPE_FORWARD_MV; |
| 1192 | 1197 | for (i = 0; i < 4; i++) { |
| 1193 | − int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | |
| 1194 | − mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | |
| 1198 | + int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); | |
| 1199 | + mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); | |
| 1195 | 1200 | if (mx >= 0xffff) |
| 1196 | 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 | 1204 | if (my >= 0xffff) |
| 1200 | 1205 | return AVERROR_INVALIDDATA; |
| 1201 | 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 | 1216 | return mb_num; |
| @@ -1215,91 +1220,91 @@ try_again: · 3 unmodified lines | ||
| 1215 | 1220 | * decode second partition. |
| 1216 | 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 | 1225 | int mb_num = 0; |
| 1221 | 1226 | static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
| 1222 | 1227 | |
| 1223 | − s->mb_x = s->resync_mb_x; | |
| 1224 | − s->first_slice_line = 1; | |
| 1225 | − for (s->mb_y = s->resync_mb_y; mb_num < mb_count; s->mb_y++) { | |
| 1226 | − ff_init_block_index(s); | |
| 1227 | − for (; mb_num < mb_count && s->mb_x < s->mb_width; s->mb_x++) { | |
| 1228 | − const int xy = s->mb_x + s->mb_y * s->mb_stride; | |
| 1228 | + h->c.mb_x = h->c.resync_mb_x; | |
| 1229 | + h->c.first_slice_line = 1; | |
| 1230 | + for (h->c.mb_y = h->c.resync_mb_y; mb_num < mb_count; h->c.mb_y++) { | |
| 1231 | + ff_init_block_index(&h->c); | |
| 1232 | + for (; mb_num < mb_count && h->c.mb_x < h->c.mb_width; h->c.mb_x++) { | |
| 1233 | + const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; | |
| 1229 | 1234 | |
| 1230 | 1235 | mb_num++; |
| 1231 | − ff_update_block_index(s, 8, s->avctx->lowres, 1); | |
| 1232 | − if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) | |
| 1233 | − s->first_slice_line = 0; | |
| 1236 | + ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1); | |
| 1237 | + if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1) | |
| 1238 | + h->c.first_slice_line = 0; | |
| 1234 | 1239 | |
| 1235 | − if (s->pict_type == AV_PICTURE_TYPE_I) { | |
| 1236 | − int ac_pred = get_bits1(&s->gb); | |
| 1237 | − int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 1240 | + if (h->c.pict_type == AV_PICTURE_TYPE_I) { | |
| 1241 | + int ac_pred = get_bits1(&h->c.gb); | |
| 1242 | + int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 1238 | 1243 | if (cbpy < 0) { |
| 1239 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1240 | − "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | |
| 1244 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1245 | + "cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1241 | 1246 | return AVERROR_INVALIDDATA; |
| 1242 | 1247 | } |
| 1243 | 1248 | |
| 1244 | − s->cbp_table[xy] |= cbpy << 2; | |
| 1245 | − s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; | |
| 1249 | + h->c.cbp_table[xy] |= cbpy << 2; | |
| 1250 | + h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; | |
| 1246 | 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 | 1253 | int i; |
| 1249 | 1254 | int dir = 0; |
| 1250 | − int ac_pred = get_bits1(&s->gb); | |
| 1251 | − int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 1255 | + int ac_pred = get_bits1(&h->c.gb); | |
| 1256 | + int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 1252 | 1257 | |
| 1253 | 1258 | if (cbpy < 0) { |
| 1254 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1255 | − "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | |
| 1259 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1260 | + "I cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1256 | 1261 | return AVERROR_INVALIDDATA; |
| 1257 | 1262 | } |
| 1258 | 1263 | |
| 1259 | − if (s->cbp_table[xy] & 8) | |
| 1260 | − ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | |
| 1261 | − s->cur_pic.qscale_table[xy] = s->qscale; | |
| 1264 | + if (h->c.cbp_table[xy] & 8) | |
| 1265 | + ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); | |
| 1266 | + h->c.cur_pic.qscale_table[xy] = h->c.qscale; | |
| 1262 | 1267 | |
| 1263 | 1268 | for (i = 0; i < 6; i++) { |
| 1264 | 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 | 1271 | if (dc < 0) { |
| 1267 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1268 | − "DC corrupted at %d %d\n", s->mb_x, s->mb_y); | |
| 1272 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1273 | + "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1269 | 1274 | return dc; |
| 1270 | 1275 | } |
| 1271 | 1276 | dir <<= 1; |
| 1272 | 1277 | if (dc_pred_dir) |
| 1273 | 1278 | dir |= 1; |
| 1274 | 1279 | } |
| 1275 | − s->cbp_table[xy] &= 3; // remove dquant | |
| 1276 | − s->cbp_table[xy] |= cbpy << 2; | |
| 1277 | − s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; | |
| 1278 | − s->pred_dir_table[xy] = dir; | |
| 1279 | − } else if (IS_SKIP(s->cur_pic.mb_type[xy])) { | |
| 1280 | − s->cur_pic.qscale_table[xy] = s->qscale; | |
| 1281 | − s->cbp_table[xy] = 0; | |
| 1280 | + h->c.cbp_table[xy] &= 3; // remove dquant | |
| 1281 | + h->c.cbp_table[xy] |= cbpy << 2; | |
| 1282 | + h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED; | |
| 1283 | + h->c.pred_dir_table[xy] = dir; | |
| 1284 | + } else if (IS_SKIP(h->c.cur_pic.mb_type[xy])) { | |
| 1285 | + h->c.cur_pic.qscale_table[xy] = h->c.qscale; | |
| 1286 | + h->c.cbp_table[xy] = 0; | |
| 1282 | 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 | 1290 | if (cbpy < 0) { |
| 1286 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1287 | − "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | |
| 1291 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1292 | + "P cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1288 | 1293 | return AVERROR_INVALIDDATA; |
| 1289 | 1294 | } |
| 1290 | 1295 | |
| 1291 | − if (s->cbp_table[xy] & 8) | |
| 1292 | − ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | |
| 1293 | − s->cur_pic.qscale_table[xy] = s->qscale; | |
| 1296 | + if (h->c.cbp_table[xy] & 8) | |
| 1297 | + ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); | |
| 1298 | + h->c.cur_pic.qscale_table[xy] = h->c.qscale; | |
| 1294 | 1299 | |
| 1295 | − s->cbp_table[xy] &= 3; // remove dquant | |
| 1296 | − s->cbp_table[xy] |= (cbpy ^ 0xf) << 2; | |
| 1300 | + h->c.cbp_table[xy] &= 3; // remove dquant | |
| 1301 | + h->c.cbp_table[xy] |= (cbpy ^ 0xf) << 2; | |
| 1297 | 1302 | } |
| 1298 | 1303 | } |
| 1299 | 1304 | } |
| 1300 | 1305 | if (mb_num >= mb_count) |
| 1301 | 1306 | return 0; |
| 1302 | − s->mb_x = 0; | |
| 1307 | + h->c.mb_x = 0; | |
| 1303 | 1308 | } |
| 1304 | 1309 | return 0; |
| 1305 | 1310 | } |
| @@ -1308,62 +1313,62 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) · 2 unmodified lines | ||
| 1308 | 1313 | * Decode the first and second partition. |
| 1309 | 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 | 1319 | int mb_num; |
| 1315 | 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; | |
| 1317 | − const int part_a_end = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END; | |
| 1321 | + const int part_a_error = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR; | |
| 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 | 1324 | mb_num = mpeg4_decode_partition_a(ctx); |
| 1320 | 1325 | if (mb_num <= 0) { |
| 1321 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 1322 | − s->mb_x, s->mb_y, part_a_error); | |
| 1326 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 1327 | + h->c.mb_x, h->c.mb_y, part_a_error); | |
| 1323 | 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) { | |
| 1327 | − av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n"); | |
| 1328 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 1329 | − s->mb_x, s->mb_y, part_a_error); | |
| 1331 | + if (h->c.resync_mb_x + h->c.resync_mb_y * h->c.mb_width + mb_num > h->c.mb_num) { | |
| 1332 | + av_log(h->c.avctx, AV_LOG_ERROR, "slice below monitor ...\n"); | |
| 1333 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 1334 | + h->c.mb_x, h->c.mb_y, part_a_error); | |
| 1330 | 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) { | |
| 1336 | − while (show_bits(&s->gb, 9) == 1) | |
| 1337 | − skip_bits(&s->gb, 9); | |
| 1338 | − if (get_bits(&s->gb, 19) != DC_MARKER) { | |
| 1339 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1340 | + if (h->c.pict_type == AV_PICTURE_TYPE_I) { | |
| 1341 | + while (show_bits(&h->c.gb, 9) == 1) | |
| 1342 | + skip_bits(&h->c.gb, 9); | |
| 1343 | + if (get_bits(&h->c.gb, 19) != DC_MARKER) { | |
| 1344 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1340 | 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 | 1347 | return AVERROR_INVALIDDATA; |
| 1343 | 1348 | } |
| 1344 | 1349 | } else { |
| 1345 | − while (show_bits(&s->gb, 10) == 1) | |
| 1346 | − skip_bits(&s->gb, 10); | |
| 1347 | − if (get_bits(&s->gb, 17) != MOTION_MARKER) { | |
| 1348 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1350 | + while (show_bits(&h->c.gb, 10) == 1) | |
| 1351 | + skip_bits(&h->c.gb, 10); | |
| 1352 | + if (get_bits(&h->c.gb, 17) != MOTION_MARKER) { | |
| 1353 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1349 | 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 | 1356 | return AVERROR_INVALIDDATA; |
| 1352 | 1357 | } |
| 1353 | 1358 | } |
| 1354 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 1355 | − s->mb_x - 1, s->mb_y, part_a_end); | |
| 1359 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 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 | 1363 | if (ret < 0) { |
| 1359 | − if (s->pict_type == AV_PICTURE_TYPE_P) | |
| 1360 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 1361 | − s->mb_x, s->mb_y, ER_DC_ERROR); | |
| 1364 | + if (h->c.pict_type == AV_PICTURE_TYPE_P) | |
| 1365 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 1366 | + h->c.mb_x, h->c.mb_y, ER_DC_ERROR); | |
| 1362 | 1367 | return ret; |
| 1363 | 1368 | } else { |
| 1364 | − if (s->pict_type == AV_PICTURE_TYPE_P) | |
| 1365 | − ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, | |
| 1366 | − s->mb_x - 1, s->mb_y, ER_DC_END); | |
| 1369 | + if (h->c.pict_type == AV_PICTURE_TYPE_P) | |
| 1370 | + ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, | |
| 1371 | + h->c.mb_x - 1, h->c.mb_y, ER_DC_END); | |
| 1367 | 1372 | } |
| 1368 | 1373 | |
| 1369 | 1374 | return 0; |
| @@ -1377,7 +1382,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 7 unmodified lines | ||
| 1377 | 1382 | int n, int coded, int intra, |
| 1378 | 1383 | int use_intra_dc_vlc, int rvlc) |
| 1379 | 1384 | { |
| 1380 | − MpegEncContext *s = &ctx->m; | |
| 1385 | + H263DecContext *const h = &ctx->h; | |
| 1381 | 1386 | int level, i, last, run, qmul, qadd, pred; |
| 1382 | 1387 | int av_uninit(dc_pred_dir); |
| 1383 | 1388 | const RLTable *rl; |
| @@ -1390,15 +1395,15 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 6 unmodified lines | ||
| 1390 | 1395 | // FIXME add short header support |
| 1391 | 1396 | if (use_intra_dc_vlc) { |
| 1392 | 1397 | /* DC coef */ |
| 1393 | − if (s->partitioned_frame) { | |
| 1394 | − level = s->dc_val[s->block_index[n]]; | |
| 1398 | + if (h->c.partitioned_frame) { | |
| 1399 | + level = h->c.dc_val[h->c.block_index[n]]; | |
| 1395 | 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 | 1402 | else |
| 1398 | − level = FASTDIV((level + (s->c_dc_scale >> 1)), s->c_dc_scale); | |
| 1399 | − dc_pred_dir = (s->pred_dir_table[s->mb_x + s->mb_y * s->mb_stride] << n) & 32; | |
| 1403 | + level = FASTDIV((level + (h->c.c_dc_scale >> 1)), h->c.c_dc_scale); | |
| 1404 | + dc_pred_dir = (h->c.pred_dir_table[h->c.mb_x + h->c.mb_y * h->c.mb_stride] << n) & 32; | |
| 1400 | 1405 | } else { |
| 1401 | − level = mpeg4_decode_dc(s, n, &dc_pred_dir); | |
| 1406 | + level = mpeg4_decode_dc(h, n, &dc_pred_dir); | |
| 1402 | 1407 | if (level < 0) |
| 1403 | 1408 | return level; |
| 1404 | 1409 | } |
| @@ -1406,7 +1411,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line | ||
| 1406 | 1411 | i = 0; |
| 1407 | 1412 | } else { |
| 1408 | 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 | 1416 | if (!coded) |
| 1412 | 1417 | goto not_coded; |
| @@ -1418,20 +1423,20 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 5 unmodified lines | ||
| 1418 | 1423 | rl = &ff_mpeg4_rl_intra; |
| 1419 | 1424 | rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0]; |
| 1420 | 1425 | } |
| 1421 | − if (s->ac_pred) { | |
| 1426 | + if (h->c.ac_pred) { | |
| 1422 | 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 | 1429 | else |
| 1425 | − scan_table = s->permutated_intra_h_scantable; /* top */ | |
| 1430 | + scan_table = h->c.permutated_intra_h_scantable; /* top */ | |
| 1426 | 1431 | } else { |
| 1427 | − scan_table = s->intra_scantable.permutated; | |
| 1432 | + scan_table = h->c.intra_scantable.permutated; | |
| 1428 | 1433 | } |
| 1429 | 1434 | qmul = 1; |
| 1430 | 1435 | qadd = 0; |
| 1431 | 1436 | } else { |
| 1432 | 1437 | i = -1; |
| 1433 | 1438 | if (!coded) { |
| 1434 | − s->block_last_index[n] = i; | |
| 1439 | + h->c.block_last_index[n] = i; | |
| 1435 | 1440 | return 0; |
| 1436 | 1441 | } |
| 1437 | 1442 | if (rvlc) |
| @@ -1439,7 +1444,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line | ||
| 1439 | 1444 | else |
| 1440 | 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 | 1449 | if (ctx->mpeg_quant) { |
| 1445 | 1450 | qmul = 1; |
| @@ -1449,61 +1454,61 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 3 unmodified lines | ||
| 1449 | 1454 | else |
| 1450 | 1455 | rl_vlc = ff_h263_rl_inter.rl_vlc[0]; |
| 1451 | 1456 | } else { |
| 1452 | − qmul = s->qscale << 1; | |
| 1453 | − qadd = (s->qscale - 1) | 1; | |
| 1457 | + qmul = h->c.qscale << 1; | |
| 1458 | + qadd = (h->c.qscale - 1) | 1; | |
| 1454 | 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 | 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 | 1467 | for (;;) { |
| 1463 | − UPDATE_CACHE(re, &s->gb); | |
| 1464 | − GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); | |
| 1468 | + UPDATE_CACHE(re, &h->c.gb); | |
| 1469 | + GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0); | |
| 1465 | 1470 | if (level == 0) { |
| 1466 | 1471 | /* escape */ |
| 1467 | 1472 | if (rvlc) { |
| 1468 | − if (SHOW_UBITS(re, &s->gb, 1) == 0) { | |
| 1469 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1473 | + if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { | |
| 1474 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1470 | 1475 | "1. marker bit missing in rvlc esc\n"); |
| 1471 | 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); | |
| 1476 | − SKIP_CACHE(re, &s->gb, 1); | |
| 1477 | − run = SHOW_UBITS(re, &s->gb, 6); | |
| 1478 | − SKIP_COUNTER(re, &s->gb, 1 + 1 + 6); | |
| 1479 | − UPDATE_CACHE(re, &s->gb); | |
| 1480 | + last = SHOW_UBITS(re, &h->c.gb, 1); | |
| 1481 | + SKIP_CACHE(re, &h->c.gb, 1); | |
| 1482 | + run = SHOW_UBITS(re, &h->c.gb, 6); | |
| 1483 | + SKIP_COUNTER(re, &h->c.gb, 1 + 1 + 6); | |
| 1484 | + UPDATE_CACHE(re, &h->c.gb); | |
| 1480 | 1485 | |
| 1481 | − if (SHOW_UBITS(re, &s->gb, 1) == 0) { | |
| 1482 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1486 | + if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { | |
| 1487 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1483 | 1488 | "2. marker bit missing in rvlc esc\n"); |
| 1484 | 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); | |
| 1489 | − SKIP_CACHE(re, &s->gb, 11); | |
| 1493 | + level = SHOW_UBITS(re, &h->c.gb, 11); | |
| 1494 | + SKIP_CACHE(re, &h->c.gb, 11); | |
| 1490 | 1495 | |
| 1491 | − if (SHOW_UBITS(re, &s->gb, 5) != 0x10) { | |
| 1492 | − av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n"); | |
| 1496 | + if (SHOW_UBITS(re, &h->c.gb, 5) != 0x10) { | |
| 1497 | + av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n"); | |
| 1493 | 1498 | return AVERROR_INVALIDDATA; |
| 1494 | 1499 | } |
| 1495 | − SKIP_CACHE(re, &s->gb, 5); | |
| 1500 | + SKIP_CACHE(re, &h->c.gb, 5); | |
| 1496 | 1501 | |
| 1497 | 1502 | level = level * qmul + qadd; |
| 1498 | − level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
| 1499 | − SKIP_COUNTER(re, &s->gb, 1 + 11 + 5 + 1); | |
| 1503 | + level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); | |
| 1504 | + SKIP_COUNTER(re, &h->c.gb, 1 + 11 + 5 + 1); | |
| 1500 | 1505 | |
| 1501 | 1506 | i += run + 1; |
| 1502 | 1507 | if (last) |
| 1503 | 1508 | i += 192; |
| 1504 | 1509 | } else { |
| 1505 | 1510 | int cache; |
| 1506 | − cache = GET_CACHE(re, &s->gb); | |
| 1511 | + cache = GET_CACHE(re, &h->c.gb); | |
| 1507 | 1512 | |
| 1508 | 1513 | if (IS_3IV1) |
| 1509 | 1514 | cache ^= 0xC0000000; |
| @@ -1511,54 +1516,54 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line | ||
| 1511 | 1516 | if (cache & 0x80000000) { |
| 1512 | 1517 | if (cache & 0x40000000) { |
| 1513 | 1518 | /* third escape */ |
| 1514 | − SKIP_CACHE(re, &s->gb, 2); | |
| 1515 | − last = SHOW_UBITS(re, &s->gb, 1); | |
| 1516 | − SKIP_CACHE(re, &s->gb, 1); | |
| 1517 | − run = SHOW_UBITS(re, &s->gb, 6); | |
| 1518 | − SKIP_COUNTER(re, &s->gb, 2 + 1 + 6); | |
| 1519 | − UPDATE_CACHE(re, &s->gb); | |
| 1519 | + SKIP_CACHE(re, &h->c.gb, 2); | |
| 1520 | + last = SHOW_UBITS(re, &h->c.gb, 1); | |
| 1521 | + SKIP_CACHE(re, &h->c.gb, 1); | |
| 1522 | + run = SHOW_UBITS(re, &h->c.gb, 6); | |
| 1523 | + SKIP_COUNTER(re, &h->c.gb, 2 + 1 + 6); | |
| 1524 | + UPDATE_CACHE(re, &h->c.gb); | |
| 1520 | 1525 | |
| 1521 | 1526 | if (IS_3IV1) { |
| 1522 | − level = SHOW_SBITS(re, &s->gb, 12); | |
| 1523 | − LAST_SKIP_BITS(re, &s->gb, 12); | |
| 1527 | + level = SHOW_SBITS(re, &h->c.gb, 12); | |
| 1528 | + LAST_SKIP_BITS(re, &h->c.gb, 12); | |
| 1524 | 1529 | } else { |
| 1525 | − if (SHOW_UBITS(re, &s->gb, 1) == 0) { | |
| 1526 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1530 | + if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { | |
| 1531 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1527 | 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 | 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); | |
| 1534 | − SKIP_CACHE(re, &s->gb, 12); | |
| 1538 | + level = SHOW_SBITS(re, &h->c.gb, 12); | |
| 1539 | + SKIP_CACHE(re, &h->c.gb, 12); | |
| 1535 | 1540 | |
| 1536 | − if (SHOW_UBITS(re, &s->gb, 1) == 0) { | |
| 1537 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1541 | + if (SHOW_UBITS(re, &h->c.gb, 1) == 0) { | |
| 1542 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1538 | 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 | 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 | 1551 | #if 0 |
| 1547 | − if (s->error_recognition >= FF_ER_COMPLIANT) { | |
| 1552 | + if (h->c.error_recognition >= FF_ER_COMPLIANT) { | |
| 1548 | 1553 | const int abs_level= FFABS(level); |
| 1549 | 1554 | if (abs_level<=MAX_LEVEL && run<=MAX_RUN) { |
| 1550 | 1555 | const int run1= run - rl->max_run[last][abs_level] - 1; |
| 1551 | 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 | 1558 | return AVERROR_INVALIDDATA; |
| 1554 | 1559 | } |
| 1555 | − if (s->error_recognition > FF_ER_COMPLIANT) { | |
| 1560 | + if (h->c.error_recognition > FF_ER_COMPLIANT) { | |
| 1556 | 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 | 1563 | return AVERROR_INVALIDDATA; |
| 1559 | 1564 | } |
| 1560 | 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 | 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 | 1576 | level = level * qmul - qadd; |
| 1572 | 1577 | |
| 1573 | 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 | 1580 | if (level > 2560 || level < -2560) { |
| 1576 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1581 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1577 | 1582 | "|level| overflow in 3. esc, qp=%d\n", |
| 1578 | − s->qscale); | |
| 1583 | + h->c.qscale); | |
| 1579 | 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 | 1592 | i += 192; |
| 1588 | 1593 | } else { |
| 1589 | 1594 | /* second escape */ |
| 1590 | − SKIP_BITS(re, &s->gb, 2); | |
| 1591 | − GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 1595 | + SKIP_BITS(re, &h->c.gb, 2); | |
| 1596 | + GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 1592 | 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); | |
| 1594 | − LAST_SKIP_BITS(re, &s->gb, 1); | |
| 1598 | + level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); | |
| 1599 | + LAST_SKIP_BITS(re, &h->c.gb, 1); | |
| 1595 | 1600 | } |
| 1596 | 1601 | } else { |
| 1597 | 1602 | /* first escape */ |
| 1598 | − SKIP_BITS(re, &s->gb, 1); | |
| 1599 | − GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 1603 | + SKIP_BITS(re, &h->c.gb, 1); | |
| 1604 | + GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 1600 | 1605 | i += run; |
| 1601 | 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); | |
| 1603 | − LAST_SKIP_BITS(re, &s->gb, 1); | |
| 1607 | + level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); | |
| 1608 | + LAST_SKIP_BITS(re, &h->c.gb, 1); | |
| 1604 | 1609 | } |
| 1605 | 1610 | } |
| 1606 | 1611 | } else { |
| 1607 | 1612 | i += run; |
| 1608 | − level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
| 1609 | − LAST_SKIP_BITS(re, &s->gb, 1); | |
| 1613 | + level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.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 | 1617 | if (i > 62) { |
| 1613 | 1618 | i -= 192; |
| 1614 | 1619 | if (i & (~63)) { |
| 1615 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1616 | − "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | |
| 1620 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1621 | + "ac-tex damaged at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1617 | 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 | 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 | 1634 | not_coded: |
| 1630 | 1635 | if (intra) { |
| 1631 | 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 | 1639 | i -= i >> 31; // if (i == -1) i = 0; |
| 1635 | 1640 | } |
| 1636 | 1641 | |
| 1637 | − ff_mpeg4_pred_ac(s, block, n, dc_pred_dir); | |
| 1638 | − if (s->ac_pred) | |
| 1642 | + ff_mpeg4_pred_ac(h, block, n, dc_pred_dir); | |
| 1643 | + if (h->c.ac_pred) | |
| 1639 | 1644 | i = 63; // FIXME not optimal |
| 1640 | 1645 | } |
| 1641 | − s->block_last_index[n] = i; | |
| 1646 | + h->c.block_last_index[n] = i; | |
| 1642 | 1647 | return 0; |
| 1643 | 1648 | } |
| 1644 | 1649 | |
| @@ -1646,72 +1651,71 @@ not_coded: · 1 unmodified line | ||
| 1646 | 1651 | * decode partition C of one MB. |
| 1647 | 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; | |
| 1652 | − int cbp, mb_type, use_intra_dc_vlc; | |
| 1653 | − const int xy = s->mb_x + s->mb_y * s->mb_stride; | |
| 1656 | + Mpeg4DecContext *const ctx = h263_to_mpeg4(h); | |
| 1657 | + const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride; | |
| 1654 | 1658 | |
| 1655 | − mb_type = s->cur_pic.mb_type[xy]; | |
| 1656 | − cbp = s->cbp_table[xy]; | |
| 1659 | + const int mb_type = h->c.cur_pic.mb_type[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) | |
| 1661 | − ff_set_qscale(s, s->cur_pic.qscale_table[xy]); | |
| 1664 | + if (h->c.cur_pic.qscale_table[xy] != h->c.qscale) | |
| 1665 | + ff_set_qscale(&h->c, h->c.cur_pic.qscale_table[xy]); | |
| 1662 | 1666 | |
| 1663 | − if (s->pict_type == AV_PICTURE_TYPE_P || | |
| 1664 | − s->pict_type == AV_PICTURE_TYPE_S) { | |
| 1667 | + if (h->c.pict_type == AV_PICTURE_TYPE_P || | |
| 1668 | + h->c.pict_type == AV_PICTURE_TYPE_S) { | |
| 1665 | 1669 | int i; |
| 1666 | 1670 | for (i = 0; i < 4; i++) { |
| 1667 | − s->mv[0][i][0] = s->cur_pic.motion_val[0][s->block_index[i]][0]; | |
| 1668 | − s->mv[0][i][1] = s->cur_pic.motion_val[0][s->block_index[i]][1]; | |
| 1671 | + h->c.mv[0][i][0] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][0]; | |
| 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 | 1676 | if (IS_SKIP(mb_type)) { |
| 1673 | 1677 | /* skip mb */ |
| 1674 | 1678 | for (i = 0; i < 6; i++) |
| 1675 | − s->block_last_index[i] = -1; | |
| 1676 | − s->mv_dir = MV_DIR_FORWARD; | |
| 1677 | − s->mv_type = MV_TYPE_16X16; | |
| 1678 | − if (s->pict_type == AV_PICTURE_TYPE_S | |
| 1679 | + h->c.block_last_index[i] = -1; | |
| 1680 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 1681 | + h->c.mv_type = MV_TYPE_16X16; | |
| 1682 | + if (h->c.pict_type == AV_PICTURE_TYPE_S | |
| 1679 | 1683 | && ctx->vol_sprite_usage == GMC_SPRITE) { |
| 1680 | − s->mcsel = 1; | |
| 1681 | − s->mb_skipped = 0; | |
| 1682 | − s->cur_pic.mbskip_table[xy] = 0; | |
| 1684 | + h->c.mcsel = 1; | |
| 1685 | + h->c.mb_skipped = 0; | |
| 1686 | + h->c.cur_pic.mbskip_table[xy] = 0; | |
| 1683 | 1687 | } else { |
| 1684 | − s->mcsel = 0; | |
| 1685 | − s->mb_skipped = 1; | |
| 1686 | − s->cur_pic.mbskip_table[xy] = 1; | |
| 1688 | + h->c.mcsel = 0; | |
| 1689 | + h->c.mb_skipped = 1; | |
| 1690 | + h->c.cur_pic.mbskip_table[xy] = 1; | |
| 1687 | 1691 | } |
| 1688 | − } else if (s->mb_intra) { | |
| 1689 | − s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]); | |
| 1690 | − } else if (!s->mb_intra) { | |
| 1691 | − // s->mcsel = 0; // FIXME do we need to init that? | |
| 1692 | + } else if (h->c.mb_intra) { | |
| 1693 | + h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]); | |
| 1694 | + } else if (!h->c.mb_intra) { | |
| 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 | 1698 | if (IS_8X8(mb_type)) { |
| 1695 | − s->mv_type = MV_TYPE_8X8; | |
| 1699 | + h->c.mv_type = MV_TYPE_8X8; | |
| 1696 | 1700 | } else { |
| 1697 | − s->mv_type = MV_TYPE_16X16; | |
| 1701 | + h->c.mv_type = MV_TYPE_16X16; | |
| 1698 | 1702 | } |
| 1699 | 1703 | } |
| 1700 | 1704 | } else { /* I-Frame */ |
| 1701 | − s->mb_intra = 1; | |
| 1702 | − s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]); | |
| 1705 | + h->c.mb_intra = 1; | |
| 1706 | + h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]); | |
| 1703 | 1707 | } |
| 1704 | 1708 | |
| 1705 | 1709 | if (!IS_SKIP(mb_type)) { |
| 1706 | 1710 | int i; |
| 1707 | − s->bdsp.clear_blocks(s->block[0]); | |
| 1711 | + h->c.bdsp.clear_blocks(h->c.block[0]); | |
| 1708 | 1712 | /* decode each block */ |
| 1709 | 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 | 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 | 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 | 1719 | return AVERROR_INVALIDDATA; |
| 1716 | 1720 | } |
| 1717 | 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 | 1725 | /* per-MB end of slice check */ |
| 1722 | − if (--s->mb_num_left <= 0) { | |
| 1726 | + if (--h->c.mb_num_left <= 0) { | |
| 1723 | 1727 | if (mpeg4_is_resync(ctx)) |
| 1724 | 1728 | return SLICE_END; |
| 1725 | 1729 | else |
| 1726 | 1730 | return SLICE_NOEND; |
| 1727 | 1731 | } else { |
| 1728 | 1732 | if (mpeg4_is_resync(ctx)) { |
| 1729 | − const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1; | |
| 1730 | − if (s->cbp_table[xy + delta]) | |
| 1733 | + const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1; | |
| 1734 | + if (h->c.cbp_table[xy + delta]) | |
| 1731 | 1735 | return SLICE_END; |
| 1732 | 1736 | } |
| 1733 | 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 | 1744 | int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; |
| 1741 | 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 | 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 || | |
| 1748 | − s->pict_type == AV_PICTURE_TYPE_S) { | |
| 1751 | + if (h->c.pict_type == AV_PICTURE_TYPE_P || | |
| 1752 | + h->c.pict_type == AV_PICTURE_TYPE_S) { | |
| 1749 | 1753 | do { |
| 1750 | − if (get_bits1(&s->gb)) { | |
| 1754 | + if (get_bits1(&h->c.gb)) { | |
| 1751 | 1755 | /* skip mb */ |
| 1752 | − s->mb_intra = 0; | |
| 1756 | + h->c.mb_intra = 0; | |
| 1753 | 1757 | for (i = 0; i < 6; i++) |
| 1754 | − s->block_last_index[i] = -1; | |
| 1755 | − s->mv_dir = MV_DIR_FORWARD; | |
| 1756 | − s->mv_type = MV_TYPE_16X16; | |
| 1757 | − if (s->pict_type == AV_PICTURE_TYPE_S && | |
| 1758 | + h->c.block_last_index[i] = -1; | |
| 1759 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 1760 | + h->c.mv_type = MV_TYPE_16X16; | |
| 1761 | + if (h->c.pict_type == AV_PICTURE_TYPE_S && | |
| 1758 | 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 | 1764 | MB_TYPE_GMC | |
| 1761 | 1765 | MB_TYPE_16x16 | |
| 1762 | 1766 | MB_TYPE_FORWARD_MV; |
| 1763 | − s->mcsel = 1; | |
| 1764 | − s->mv[0][0][0] = get_amv(ctx, 0); | |
| 1765 | − s->mv[0][0][1] = get_amv(ctx, 1); | |
| 1766 | − s->cur_pic.mbskip_table[xy] = 0; | |
| 1767 | − s->mb_skipped = 0; | |
| 1767 | + h->c.mcsel = 1; | |
| 1768 | + h->c.mv[0][0][0] = get_amv(ctx, 0); | |
| 1769 | + h->c.mv[0][0][1] = get_amv(ctx, 1); | |
| 1770 | + h->c.cur_pic.mbskip_table[xy] = 0; | |
| 1771 | + h->c.mb_skipped = 0; | |
| 1768 | 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 | 1774 | MB_TYPE_FORWARD_MV; |
| 1771 | − s->mcsel = 0; | |
| 1772 | − s->mv[0][0][0] = 0; | |
| 1773 | − s->mv[0][0][1] = 0; | |
| 1774 | − s->cur_pic.mbskip_table[xy] = 1; | |
| 1775 | − s->mb_skipped = 1; | |
| 1775 | + h->c.mcsel = 0; | |
| 1776 | + h->c.mv[0][0][0] = 0; | |
| 1777 | + h->c.mv[0][0][1] = 0; | |
| 1778 | + h->c.cur_pic.mbskip_table[xy] = 1; | |
| 1779 | + h->c.mb_skipped = 1; | |
| 1776 | 1780 | } |
| 1777 | 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 | 1784 | if (cbpc < 0) { |
| 1781 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1782 | − "mcbpc damaged at %d %d\n", s->mb_x, s->mb_y); | |
| 1785 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1786 | + "mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1783 | 1787 | return AVERROR_INVALIDDATA; |
| 1784 | 1788 | } |
| 1785 | 1789 | } while (cbpc == 20); |
| 1786 | 1790 | |
| 1787 | 1791 | dquant = cbpc & 8; |
| 1788 | − s->mb_intra = ((cbpc & 4) != 0); | |
| 1789 | − if (s->mb_intra) | |
| 1792 | + h->c.mb_intra = ((cbpc & 4) != 0); | |
| 1793 | + if (h->c.mb_intra) | |
| 1790 | 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 | 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 | 1800 | else |
| 1797 | − s->mcsel = 0; | |
| 1798 | − cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F; | |
| 1801 | + h->c.mcsel = 0; | |
| 1802 | + cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F; | |
| 1799 | 1803 | if (cbpy < 0) { |
| 1800 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 1801 | − "P cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | |
| 1804 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 1805 | + "P cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 1802 | 1806 | return AVERROR_INVALIDDATA; |
| 1803 | 1807 | } |
| 1804 | 1808 | |
| 1805 | 1809 | cbp = (cbpc & 3) | (cbpy << 2); |
| 1806 | 1810 | if (dquant) |
| 1807 | − ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); | |
| 1808 | − if ((!s->progressive_sequence) && | |
| 1809 | − (cbp || (s->workaround_bugs & FF_BUG_XVID_ILACE))) | |
| 1810 | − s->interlaced_dct = get_bits1(&s->gb); | |
| 1811 | + ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]); | |
| 1812 | + if ((!h->c.progressive_sequence) && | |
| 1813 | + (cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE))) | |
| 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 | 1817 | if ((cbpc & 16) == 0) { |
| 1814 | − if (s->mcsel) { | |
| 1815 | − s->cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 | | |
| 1818 | + if (h->c.mcsel) { | |
| 1819 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 | | |
| 1816 | 1820 | MB_TYPE_FORWARD_MV; |
| 1817 | 1821 | /* 16x16 global motion prediction */ |
| 1818 | − s->mv_type = MV_TYPE_16X16; | |
| 1822 | + h->c.mv_type = MV_TYPE_16X16; | |
| 1819 | 1823 | mx = get_amv(ctx, 0); |
| 1820 | 1824 | my = get_amv(ctx, 1); |
| 1821 | − s->mv[0][0][0] = mx; | |
| 1822 | − s->mv[0][0][1] = my; | |
| 1823 | − } else if ((!s->progressive_sequence) && get_bits1(&s->gb)) { | |
| 1824 | − s->cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV | | |
| 1825 | + h->c.mv[0][0][0] = mx; | |
| 1826 | + h->c.mv[0][0][1] = my; | |
| 1827 | + } else if ((!h->c.progressive_sequence) && get_bits1(&h->c.gb)) { | |
| 1828 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV | | |
| 1825 | 1829 | MB_TYPE_INTERLACED; |
| 1826 | 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); | |
| 1830 | − s->field_select[0][1] = get_bits1(&s->gb); | |
| 1833 | + h->c.field_select[0][0] = get_bits1(&h->c.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 | 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 | 1840 | if (mx >= 0xffff) |
| 1837 | 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 | 1844 | if (my >= 0xffff) |
| 1841 | 1845 | return AVERROR_INVALIDDATA; |
| 1842 | 1846 | |
| 1843 | − s->mv[0][i][0] = mx; | |
| 1844 | − s->mv[0][i][1] = my; | |
| 1847 | + h->c.mv[0][i][0] = mx; | |
| 1848 | + h->c.mv[0][i][1] = my; | |
| 1845 | 1849 | } |
| 1846 | 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 | 1852 | /* 16x16 motion prediction */ |
| 1849 | − s->mv_type = MV_TYPE_16X16; | |
| 1850 | − ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); | |
| 1851 | − mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | |
| 1853 | + h->c.mv_type = MV_TYPE_16X16; | |
| 1854 | + ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y); | |
| 1855 | + mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); | |
| 1852 | 1856 | |
| 1853 | 1857 | if (mx >= 0xffff) |
| 1854 | 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 | 1862 | if (my >= 0xffff) |
| 1859 | 1863 | return AVERROR_INVALIDDATA; |
| 1860 | − s->mv[0][0][0] = mx; | |
| 1861 | − s->mv[0][0][1] = my; | |
| 1864 | + h->c.mv[0][0][0] = mx; | |
| 1865 | + h->c.mv[0][0][1] = my; | |
| 1862 | 1866 | } |
| 1863 | 1867 | } else { |
| 1864 | − s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; | |
| 1865 | − s->mv_type = MV_TYPE_8X8; | |
| 1868 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV; | |
| 1869 | + h->c.mv_type = MV_TYPE_8X8; | |
| 1866 | 1870 | for (i = 0; i < 4; i++) { |
| 1867 | − int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); | |
| 1868 | − mx = ff_h263_decode_motion(s, pred_x, ctx->f_code); | |
| 1871 | + int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y); | |
| 1872 | + mx = ff_h263_decode_motion(h, pred_x, ctx->f_code); | |
| 1869 | 1873 | if (mx >= 0xffff) |
| 1870 | 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 | 1877 | if (my >= 0xffff) |
| 1874 | 1878 | return AVERROR_INVALIDDATA; |
| 1875 | − s->mv[0][i][0] = mx; | |
| 1876 | − s->mv[0][i][1] = my; | |
| 1879 | + h->c.mv[0][i][0] = mx; | |
| 1880 | + h->c.mv[0][i][1] = my; | |
| 1877 | 1881 | mot_val[0] = mx; |
| 1878 | 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 | 1886 | int modb1; // first bit of modb |
| 1883 | 1887 | int modb2; // second bit of modb |
| 1884 | 1888 | int mb_type; |
| 1885 | 1889 | |
| 1886 | − s->mb_intra = 0; // B-frames never contain intra blocks | |
| 1887 | − s->mcsel = 0; // ... true gmc blocks | |
| 1890 | + h->c.mb_intra = 0; // B-frames never contain intra 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 | 1894 | for (i = 0; i < 2; i++) { |
| 1891 | − s->last_mv[i][0][0] = | |
| 1892 | − s->last_mv[i][0][1] = | |
| 1893 | − s->last_mv[i][1][0] = | |
| 1894 | − s->last_mv[i][1][1] = 0; | |
| 1895 | + h->c.last_mv[i][0][0] = | |
| 1896 | + h->c.last_mv[i][0][1] = | |
| 1897 | + h->c.last_mv[i][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 | 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 | 1908 | /* skip mb */ |
| 1905 | 1909 | for (i = 0; i < 6; i++) |
| 1906 | − s->block_last_index[i] = -1; | |
| 1907 | − | |
| 1908 | − s->mv_dir = MV_DIR_FORWARD; | |
| 1909 | − s->mv_type = MV_TYPE_16X16; | |
| 1910 | − s->mv[0][0][0] = | |
| 1911 | − s->mv[0][0][1] = | |
| 1912 | − s->mv[1][0][0] = | |
| 1913 | − s->mv[1][0][1] = 0; | |
| 1914 | − s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | | |
| 1910 | + h->c.block_last_index[i] = -1; | |
| 1911 | + | |
| 1912 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 1913 | + h->c.mv_type = MV_TYPE_16X16; | |
| 1914 | + h->c.mv[0][0][0] = | |
| 1915 | + h->c.mv[0][0][1] = | |
| 1916 | + h->c.mv[1][0][0] = | |
| 1917 | + h->c.mv[1][0][1] = 0; | |
| 1918 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | | |
| 1915 | 1919 | MB_TYPE_16x16 | |
| 1916 | 1920 | MB_TYPE_FORWARD_MV; |
| 1917 | 1921 | goto end; |
| 1918 | 1922 | } |
| 1919 | 1923 | |
| 1920 | − modb1 = get_bits1(&s->gb); | |
| 1924 | + modb1 = get_bits1(&h->c.gb); | |
| 1921 | 1925 | if (modb1) { |
| 1922 | 1926 | // like MB_TYPE_B_DIRECT but no vectors coded |
| 1923 | 1927 | mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV; |
| 1924 | 1928 | cbp = 0; |
| 1925 | 1929 | } else { |
| 1926 | − modb2 = get_bits1(&s->gb); | |
| 1927 | − mb_type = get_vlc2(&s->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1); | |
| 1930 | + modb2 = get_bits1(&h->c.gb); | |
| 1931 | + mb_type = get_vlc2(&h->c.gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1); | |
| 1928 | 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 | 1934 | return AVERROR_INVALIDDATA; |
| 1931 | 1935 | } |
| 1932 | 1936 | if (modb2) { |
| 1933 | 1937 | cbp = 0; |
| 1934 | 1938 | } else { |
| 1935 | − s->bdsp.clear_blocks(s->block[0]); | |
| 1936 | − cbp = get_bits(&s->gb, 6); | |
| 1939 | + h->c.bdsp.clear_blocks(h->c.block[0]); | |
| 1940 | + cbp = get_bits(&h->c.gb, 6); | |
| 1937 | 1941 | } |
| 1938 | 1942 | |
| 1939 | 1943 | if ((!IS_DIRECT(mb_type)) && cbp) { |
| 1940 | − if (get_bits1(&s->gb)) | |
| 1941 | − ff_set_qscale(s, s->qscale + get_bits1(&s->gb) * 4 - 2); | |
| 1944 | + if (get_bits1(&h->c.gb)) | |
| 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 | 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 | 1953 | mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; |
| 1950 | 1954 | mb_type &= ~MB_TYPE_16x16; |
| 1951 | 1955 | |
| 1952 | 1956 | if (HAS_FORWARD_MV(mb_type)) { |
| 1953 | − s->field_select[0][0] = get_bits1(&s->gb); | |
| 1954 | − s->field_select[0][1] = get_bits1(&s->gb); | |
| 1957 | + h->c.field_select[0][0] = get_bits1(&h->c.gb); | |
| 1958 | + h->c.field_select[0][1] = get_bits1(&h->c.gb); | |
| 1955 | 1959 | } |
| 1956 | 1960 | if (HAS_BACKWARD_MV(mb_type)) { |
| 1957 | − s->field_select[1][0] = get_bits1(&s->gb); | |
| 1958 | − s->field_select[1][1] = get_bits1(&s->gb); | |
| 1961 | + h->c.field_select[1][0] = get_bits1(&h->c.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 | 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 | 1971 | if (HAS_FORWARD_MV(mb_type)) { |
| 1968 | − s->mv_dir = MV_DIR_FORWARD; | |
| 1969 | − | |
| 1970 | − mx = ff_h263_decode_motion(s, s->last_mv[0][0][0], ctx->f_code); | |
| 1971 | − my = ff_h263_decode_motion(s, s->last_mv[0][0][1], ctx->f_code); | |
| 1972 | − s->last_mv[0][1][0] = | |
| 1973 | − s->last_mv[0][0][0] = | |
| 1974 | − s->mv[0][0][0] = mx; | |
| 1975 | − s->last_mv[0][1][1] = | |
| 1976 | − s->last_mv[0][0][1] = | |
| 1977 | − s->mv[0][0][1] = my; | |
| 1972 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 1973 | + | |
| 1974 | + mx = ff_h263_decode_motion(h, h->c.last_mv[0][0][0], ctx->f_code); | |
| 1975 | + my = ff_h263_decode_motion(h, h->c.last_mv[0][0][1], ctx->f_code); | |
| 1976 | + h->c.last_mv[0][1][0] = | |
| 1977 | + h->c.last_mv[0][0][0] = | |
| 1978 | + h->c.mv[0][0][0] = mx; | |
| 1979 | + h->c.last_mv[0][1][1] = | |
| 1980 | + h->c.last_mv[0][0][1] = | |
| 1981 | + h->c.mv[0][0][1] = my; | |
| 1978 | 1982 | } |
| 1979 | 1983 | |
| 1980 | 1984 | if (HAS_BACKWARD_MV(mb_type)) { |
| 1981 | − s->mv_dir |= MV_DIR_BACKWARD; | |
| 1982 | − | |
| 1983 | − mx = ff_h263_decode_motion(s, s->last_mv[1][0][0], ctx->b_code); | |
| 1984 | − my = ff_h263_decode_motion(s, s->last_mv[1][0][1], ctx->b_code); | |
| 1985 | − s->last_mv[1][1][0] = | |
| 1986 | − s->last_mv[1][0][0] = | |
| 1987 | − s->mv[1][0][0] = mx; | |
| 1988 | − s->last_mv[1][1][1] = | |
| 1989 | − s->last_mv[1][0][1] = | |
| 1990 | − s->mv[1][0][1] = my; | |
| 1985 | + h->c.mv_dir |= MV_DIR_BACKWARD; | |
| 1986 | + | |
| 1987 | + mx = ff_h263_decode_motion(h, h->c.last_mv[1][0][0], ctx->b_code); | |
| 1988 | + my = ff_h263_decode_motion(h, h->c.last_mv[1][0][1], ctx->b_code); | |
| 1989 | + h->c.last_mv[1][1][0] = | |
| 1990 | + h->c.last_mv[1][0][0] = | |
| 1991 | + h->c.mv[1][0][0] = mx; | |
| 1992 | + h->c.last_mv[1][1][1] = | |
| 1993 | + h->c.last_mv[1][0][1] = | |
| 1994 | + h->c.mv[1][0][1] = my; | |
| 1991 | 1995 | } |
| 1992 | 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 | 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 | 2002 | for (i = 0; i < 2; i++) { |
| 1999 | − mx = ff_h263_decode_motion(s, s->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); | |
| 2001 | − s->last_mv[0][i][0] = | |
| 2002 | − s->mv[0][i][0] = mx; | |
| 2003 | − s->last_mv[0][i][1] = (s->mv[0][i][1] = my) * 2; | |
| 2003 | + mx = ff_h263_decode_motion(h, h->c.last_mv[0][i][0], ctx->f_code); | |
| 2004 | + my = ff_h263_decode_motion(h, h->c.last_mv[0][i][1] / 2, ctx->f_code); | |
| 2005 | + h->c.last_mv[0][i][0] = | |
| 2006 | + h->c.mv[0][i][0] = mx; | |
| 2007 | + h->c.last_mv[0][i][1] = (h->c.mv[0][i][1] = my) * 2; | |
| 2004 | 2008 | } |
| 2005 | 2009 | } |
| 2006 | 2010 | |
| 2007 | 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 | 2014 | for (i = 0; i < 2; i++) { |
| 2011 | − mx = ff_h263_decode_motion(s, s->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); | |
| 2013 | − s->last_mv[1][i][0] = | |
| 2014 | − s->mv[1][i][0] = mx; | |
| 2015 | − s->last_mv[1][i][1] = (s->mv[1][i][1] = my) * 2; | |
| 2015 | + mx = ff_h263_decode_motion(h, h->c.last_mv[1][i][0], ctx->b_code); | |
| 2016 | + my = ff_h263_decode_motion(h, h->c.last_mv[1][i][1] / 2, ctx->b_code); | |
| 2017 | + h->c.last_mv[1][i][0] = | |
| 2018 | + h->c.mv[1][i][0] = mx; | |
| 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 | 2027 | mx = |
| 2024 | 2028 | my = 0; |
| 2025 | 2029 | } else { |
| 2026 | − mx = ff_h263_decode_motion(s, 0, 1); | |
| 2027 | − my = ff_h263_decode_motion(s, 0, 1); | |
| 2030 | + mx = ff_h263_decode_motion(h, 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; | |
| 2031 | − mb_type |= ff_mpeg4_set_direct_mv(s, mx, my); | |
| 2034 | + h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
| 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 | 2038 | } else { /* I-Frame */ |
| 2035 | 2039 | int use_intra_dc_vlc; |
| 2036 | 2040 | |
| 2037 | 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 | 2043 | if (cbpc < 0) { |
| 2040 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 2041 | − "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); | |
| 2044 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 2045 | + "I cbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 2042 | 2046 | return AVERROR_INVALIDDATA; |
| 2043 | 2047 | } |
| 2044 | 2048 | } while (cbpc == 8); |
| 2045 | 2049 | |
| 2046 | 2050 | dquant = cbpc & 4; |
| 2047 | − s->mb_intra = 1; | |
| 2051 | + h->c.mb_intra = 1; | |
| 2048 | 2052 | |
| 2049 | 2053 | intra: |
| 2050 | − s->ac_pred = get_bits1(&s->gb); | |
| 2051 | − if (s->ac_pred) | |
| 2052 | − s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; | |
| 2054 | + h->c.ac_pred = get_bits1(&h->c.gb); | |
| 2055 | + if (h->c.ac_pred) | |
| 2056 | + h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; | |
| 2053 | 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 | 2061 | if (cbpy < 0) { |
| 2058 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 2059 | − "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | |
| 2062 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 2063 | + "I cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 2060 | 2064 | return AVERROR_INVALIDDATA; |
| 2061 | 2065 | } |
| 2062 | 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 | 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) | |
| 2070 | − s->interlaced_dct = get_bits1(&s->gb); | |
| 2073 | + if (!h->c.progressive_sequence) | |
| 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 | 2077 | /* decode each block */ |
| 2074 | 2078 | for (i = 0; i < 6; i++) { |
| 2075 | 2079 | if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, |
| @@ -2091,18 +2095,18 @@ end: · 15 unmodified lines | ||
| 2091 | 2095 | /* per-MB end of slice check */ |
| 2092 | 2096 | next = mpeg4_is_resync(ctx); |
| 2093 | 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 | 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 | 2101 | return SLICE_END; |
| 2098 | 2102 | |
| 2099 | − if (s->pict_type == AV_PICTURE_TYPE_B) { | |
| 2100 | − const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1; | |
| 2101 | − ff_thread_progress_await(&s->next_pic.ptr->progress, | |
| 2102 | − (s->mb_x + delta >= s->mb_width) | |
| 2103 | − ? FFMIN(s->mb_y + 1, s->mb_height - 1) | |
| 2104 | − : s->mb_y); | |
| 2105 | − if (s->next_pic.mbskip_table[xy + delta]) | |
| 2103 | + if (h->c.pict_type == AV_PICTURE_TYPE_B) { | |
| 2104 | + const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1; | |
| 2105 | + ff_thread_progress_await(&h->c.next_pic.ptr->progress, | |
| 2106 | + (h->c.mb_x + delta >= h->c.mb_width) | |
| 2107 | + ? FFMIN(h->c.mb_y + 1, h->c.mb_height - 1) | |
| 2108 | + : h->c.mb_y); | |
| 2109 | + if (h->c.next_pic.mbskip_table[xy + delta]) | |
| 2106 | 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 | 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 | 2160 | int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0, |
| 2157 | 2161 | additional_code_len, sign, mismatch; |
| 2158 | 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 | 2164 | const uint16_t *quant_matrix; |
| 2161 | 2165 | uint32_t flc; |
| 2162 | − const int min = -1 * (1 << (s->avctx->bits_per_raw_sample + 6)); | |
| 2163 | − const int max = ((1 << (s->avctx->bits_per_raw_sample + 6)) - 1); | |
| 2164 | − int shift = 3 - ctx->dct_precision; | |
| 2166 | + const int min = -1 * (1 << (h->c.avctx->bits_per_raw_sample + 6)); | |
| 2167 | + const int max = ((1 << (h->c.avctx->bits_per_raw_sample + 6)) - 1); | |
| 2168 | + int shift = 3 - ctx->dct_precision; | |
| 2165 | 2169 | |
| 2166 | 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 | 2174 | if (n < 4) { |
| 2171 | 2175 | cc = 0; |
| 2172 | − dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2); | |
| 2173 | − quant_matrix = s->intra_matrix; | |
| 2176 | + dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2); | |
| 2177 | + quant_matrix = h->c.intra_matrix; | |
| 2174 | 2178 | } else { |
| 2175 | 2179 | cc = (n & 1) + 1; |
| 2176 | 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 | 2182 | else |
| 2179 | − dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2); | |
| 2180 | − quant_matrix = s->chroma_intra_matrix; | |
| 2183 | + dct_dc_size = get_vlc2(&h->c.gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2); | |
| 2184 | + quant_matrix = h->c.chroma_intra_matrix; | |
| 2181 | 2185 | } |
| 2182 | 2186 | |
| 2183 | 2187 | if (dct_dc_size == 0) { |
| 2184 | 2188 | dct_diff = 0; |
| 2185 | 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 | 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 | 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 | 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 | 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 | 2205 | /* TODO: support mpeg_quant for AC coefficients */ |
| 2202 | 2206 | |
| 2203 | 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 | 2210 | /* AC Coefficients */ |
| 2207 | 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 | 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 | 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 | 2226 | /* Zero run length (Table B.47) */ |
| 2223 | 2227 | run = 1 << additional_code_len; |
| 2224 | 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 | 2230 | idx += run; |
| 2227 | 2231 | continue; |
| 2228 | 2232 | } else if (group >= 7 && group <= 12) { |
| 2229 | 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 | 2235 | sign = code & 1; |
| 2232 | 2236 | code >>= 1; |
| 2233 | 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 | 2245 | if (idx > 63) |
| 2242 | 2246 | return AVERROR_INVALIDDATA; |
| 2243 | 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 | 2249 | } else if (group == 21) { |
| 2246 | 2250 | /* Escape */ |
| 2247 | 2251 | if (idx > 63) |
| 2248 | 2252 | return AVERROR_INVALIDDATA; |
| 2249 | 2253 | j = scantable[idx++]; |
| 2250 | − additional_code_len = s->avctx->bits_per_raw_sample + ctx->dct_precision + 4; | |
| 2251 | − flc = get_bits(&s->gb, additional_code_len); | |
| 2254 | + additional_code_len = h->c.avctx->bits_per_raw_sample + ctx->dct_precision + 4; | |
| 2255 | + flc = get_bits(&h->c.gb, additional_code_len); | |
| 2252 | 2256 | if (flc >> (additional_code_len-1)) |
| 2253 | 2257 | block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1); |
| 2254 | 2258 | else |
| 2255 | 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 | 2262 | block[j] = av_clip(block[j], min, max); |
| 2259 | 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 | 2271 | static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, |
| 2268 | 2272 | int16_t macroblock[256], int n) |
| 2269 | 2273 | { |
| 2270 | − MPVContext *const s = &ctx->m; | |
| 2271 | − int i, j, w, h, idx = 0; | |
| 2274 | + H263DecContext *const h = &ctx->h; | |
| 2275 | + int j, w, height, idx = 0; | |
| 2272 | 2276 | int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code, |
| 2273 | 2277 | dpcm_residual, left, top, topleft, min_left_top, max_left_top, p, p2, output; |
| 2274 | − h = 16 >> (n ? s->chroma_y_shift : 0); | |
| 2275 | − w = 16 >> (n ? s->chroma_x_shift : 0); | |
| 2278 | + height = 16 >> (n ? h->c.chroma_y_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 | 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 | 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 | 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 | 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 | 2295 | rice_parameter = 0; |
| 2292 | 2296 | |
| 2293 | 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 | 2299 | return AVERROR_INVALIDDATA; |
| 2296 | 2300 | } |
| 2297 | 2301 | |
| 2298 | − for (i = 0; i < h; i++) { | |
| 2299 | − output = 1 << (s->avctx->bits_per_raw_sample - 1); | |
| 2300 | − top = 1 << (s->avctx->bits_per_raw_sample - 1); | |
| 2302 | + for (int i = 0; i < height; i++) { | |
| 2303 | + output = 1 << (h->c.avctx->bits_per_raw_sample - 1); | |
| 2304 | + top = 1 << (h->c.avctx->bits_per_raw_sample - 1); | |
| 2301 | 2305 | |
| 2302 | 2306 | for (j = 0; j < w; j++) { |
| 2303 | 2307 | left = output; |
| 2304 | 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 | 2312 | /* Escape */ |
| 2309 | 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 | 2315 | else { |
| 2312 | 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 | 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 | 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 | 2346 | if (p2 > p) |
| 2343 | 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 | 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 | 2359 | int i; |
| 2356 | 2360 | |
| 2357 | 2361 | ctx->dpcm_direction = 0; |
| 2358 | 2362 | |
| 2359 | 2363 | /* StudioMacroblock */ |
| 2360 | 2364 | /* Assumes I-VOP */ |
| 2361 | − s->mb_intra = 1; | |
| 2362 | − if (get_bits1(&s->gb)) { /* compression_mode */ | |
| 2365 | + h->c.mb_intra = 1; | |
| 2366 | + if (get_bits1(&h->c.gb)) { /* compression_mode */ | |
| 2363 | 2367 | /* DCT */ |
| 2364 | 2368 | /* macroblock_type, 1 or 2-bit VLC */ |
| 2365 | − if (!get_bits1(&s->gb)) { | |
| 2366 | − skip_bits1(&s->gb); | |
| 2367 | − s->qscale = mpeg_get_qscale(s); | |
| 2369 | + if (!get_bits1(&h->c.gb)) { | |
| 2370 | + skip_bits1(&h->c.gb); | |
| 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++) { | |
| 2371 | − if (mpeg4_decode_studio_block(s, ctx->block32[i], i) < 0) | |
| 2374 | + for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) { | |
| 2375 | + if (mpeg4_decode_studio_block(ctx, ctx->block32[i], i) < 0) | |
| 2372 | 2376 | return AVERROR_INVALIDDATA; |
| 2373 | 2377 | } |
| 2374 | 2378 | } else { |
| 2375 | 2379 | /* DPCM */ |
| 2376 | − check_marker(s->avctx, &s->gb, "DPCM block start"); | |
| 2377 | − ctx->dpcm_direction = get_bits1(&s->gb) ? -1 : 1; | |
| 2380 | + check_marker(h->c.avctx, &h->c.gb, "DPCM block start"); | |
| 2381 | + ctx->dpcm_direction = get_bits1(&h->c.gb) ? -1 : 1; | |
| 2378 | 2382 | for (i = 0; i < 3; i++) { |
| 2379 | 2383 | if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0) |
| 2380 | 2384 | return AVERROR_INVALIDDATA; |
| 2381 | 2385 | } |
| 2382 | 2386 | } |
| 2383 | 2387 | |
| 2384 | − if (get_bits_left(&s->gb) >= 24 && show_bits(&s->gb, 23) == 0) { | |
| 2385 | − next_start_code_studio(&s->gb); | |
| 2388 | + if (get_bits_left(&h->c.gb) >= 24 && show_bits(&h->c.gb, 23) == 0) { | |
| 2389 | + next_start_code_studio(&h->c.gb); | |
| 2386 | 2390 | return SLICE_END; |
| 2387 | 2391 | } |
| 2388 | 2392 | |
| 2389 | 2393 | //vcon-stp9L1.bits (first frame) |
| 2390 | − if (get_bits_left(&s->gb) == 0) | |
| 2394 | + if (get_bits_left(&h->c.gb) == 0) | |
| 2391 | 2395 | return SLICE_END; |
| 2392 | 2396 | |
| 2393 | 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 | 2399 | return SLICE_END; |
| 2396 | 2400 | |
| 2397 | 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 | 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 | 2558 | int width, height, aspect_ratio_info; |
| 2555 | 2559 | int bits_per_raw_sample; |
| 2556 | 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 | 2641 | static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 2638 | 2642 | { |
| 2639 | − MpegEncContext *s = &ctx->m; | |
| 2643 | + H263DecContext *const h = &ctx->h; | |
| 2640 | 2644 | int width, height, vo_ver_id, aspect_ratio_info; |
| 2641 | 2645 | |
| 2642 | 2646 | /* vol header */ |
| @@ -2650,12 +2654,12 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 7 unmodified lines | ||
| 2650 | 2654 | */ |
| 2651 | 2655 | if (ctx->vo_type == CORE_STUDIO_VO_TYPE || |
| 2652 | 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 | 2658 | return AVERROR_INVALIDDATA; |
| 2655 | − s->studio_profile = 1; | |
| 2656 | − s->avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO; | |
| 2659 | + h->c.studio_profile = 1; | |
| 2660 | + h->c.avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO; | |
| 2657 | 2661 | return decode_studio_vol_header(ctx, gb); |
| 2658 | − } else if (s->studio_profile) { | |
| 2662 | + } else if (h->c.studio_profile) { | |
| 2659 | 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 | 2672 | aspect_ratio_info = get_bits(gb, 4); |
| 2669 | 2673 | if (aspect_ratio_info == FF_ASPECT_EXTENDED) { |
| 2670 | − s->avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width | |
| 2671 | − s->avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height | |
| 2674 | + h->c.avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width | |
| 2675 | + h->c.avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height | |
| 2672 | 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 | 2680 | if ((ctx->vol_control_parameters = get_bits1(gb))) { /* vol control parameter */ |
| 2677 | 2681 | int chroma_format = get_bits(gb, 2); |
| 2678 | 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 | 2686 | if (get_bits1(gb)) { /* vbv parameters */ |
| 2683 | 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 | 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 | 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 | 2693 | get_bits(gb, 3); /* latter_half_vbv_buffer_size */ |
| 2690 | 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 | 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 | 2699 | } else { |
| 2696 | 2700 | /* is setting low delay flag only once the smartest thing to do? |
| 2697 | 2701 | * low delay detection will not be overridden. */ |
| 2698 | − if (s->picture_number == 0) { | |
| 2702 | + if (h->c.picture_number == 0) { | |
| 2699 | 2703 | switch (ctx->vo_type) { |
| 2700 | 2704 | case SIMPLE_VO_TYPE: |
| 2701 | 2705 | case ADV_SIMPLE_VO_TYPE: |
| 2702 | − s->low_delay = 1; | |
| 2706 | + h->c.low_delay = 1; | |
| 2703 | 2707 | break; |
| 2704 | 2708 | default: |
| 2705 | − s->low_delay = 0; | |
| 2709 | + h->c.low_delay = 0; | |
| 2706 | 2710 | } |
| 2707 | 2711 | } |
| 2708 | 2712 | } |
| 2709 | 2713 | |
| 2710 | 2714 | ctx->shape = get_bits(gb, 2); /* vol shape */ |
| 2711 | 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 | 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 | 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); | |
| 2721 | − if (!s->avctx->framerate.num) { | |
| 2722 | − av_log(s->avctx, AV_LOG_ERROR, "framerate==0\n"); | |
| 2724 | + h->c.avctx->framerate.num = get_bits(gb, 16); | |
| 2725 | + if (!h->c.avctx->framerate.num) { | |
| 2726 | + av_log(h->c.avctx, AV_LOG_ERROR, "framerate==0\n"); | |
| 2723 | 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 | 2731 | if (ctx->time_increment_bits < 1) |
| 2728 | 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 | 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 | 2738 | else |
| 2735 | − s->avctx->framerate.den = 1; | |
| 2739 | + h->c.avctx->framerate.den = 1; | |
| 2736 | 2740 | |
| 2737 | 2741 | ctx->t_frame = 0; |
| 2738 | 2742 | |
| 2739 | 2743 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 2740 | 2744 | if (ctx->shape == RECT_SHAPE) { |
| 2741 | − check_marker(s->avctx, gb, "before width"); | |
| 2745 | + check_marker(h->c.avctx, gb, "before width"); | |
| 2742 | 2746 | width = get_bits(gb, 13); |
| 2743 | − check_marker(s->avctx, gb, "before height"); | |
| 2747 | + check_marker(h->c.avctx, gb, "before height"); | |
| 2744 | 2748 | height = get_bits(gb, 13); |
| 2745 | − check_marker(s->avctx, gb, "after height"); | |
| 2749 | + check_marker(h->c.avctx, gb, "after height"); | |
| 2746 | 2750 | if (width && height && /* they should be non zero but who knows */ |
| 2747 | − !(s->width && s->codec_tag == AV_RL32("MP4S"))) { | |
| 2748 | − if (s->width && s->height && | |
| 2749 | − (s->width != width || s->height != height)) | |
| 2750 | − s->context_reinit = 1; | |
| 2751 | − s->width = width; | |
| 2752 | − s->height = height; | |
| 2751 | + !(h->c.width && h->c.codec_tag == AV_RL32("MP4S"))) { | |
| 2752 | + if (h->c.width && h->c.height && | |
| 2753 | + (h->c.width != width || h->c.height != height)) | |
| 2754 | + h->c.context_reinit = 1; | |
| 2755 | + h->c.width = width; | |
| 2756 | + h->c.height = height; | |
| 2753 | 2757 | } |
| 2754 | 2758 | } |
| 2755 | 2759 | |
| 2756 | − s->progressive_sequence = | |
| 2757 | − s->progressive_frame = get_bits1(gb) ^ 1; | |
| 2758 | − s->interlaced_dct = 0; | |
| 2759 | − if (!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO)) | |
| 2760 | − av_log(s->avctx, AV_LOG_INFO, /* OBMC Disable */ | |
| 2760 | + h->c.progressive_sequence = | |
| 2761 | + h->c.progressive_frame = get_bits1(gb) ^ 1; | |
| 2762 | + h->c.interlaced_dct = 0; | |
| 2763 | + if (!get_bits1(gb) && (h->c.avctx->debug & FF_DEBUG_PICT_INFO)) | |
| 2764 | + av_log(h->c.avctx, AV_LOG_INFO, /* OBMC Disable */ | |
| 2761 | 2765 | "MPEG-4 OBMC not supported (very likely buggy encoder)\n"); |
| 2762 | 2766 | if (vo_ver_id == 1) |
| 2763 | 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 | 2769 | ctx->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ |
| 2766 | 2770 | |
| 2767 | 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 | 2773 | if (ctx->vol_sprite_usage == STATIC_SPRITE || |
| 2770 | 2774 | ctx->vol_sprite_usage == GMC_SPRITE) { |
| 2771 | 2775 | if (ctx->vol_sprite_usage == STATIC_SPRITE) { |
| 2772 | 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 | 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 | 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 | 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 | 2785 | ctx->num_sprite_warping_points = get_bits(gb, 6); |
| 2782 | 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 | 2788 | "%d sprite_warping_points\n", |
| 2785 | 2789 | ctx->num_sprite_warping_points); |
| 2786 | 2790 | ctx->num_sprite_warping_points = 0; |
| @@ -2796,9 +2800,9 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 9 unmodified lines | ||
| 2796 | 2800 | if (get_bits1(gb) == 1) { /* not_8_bit */ |
| 2797 | 2801 | ctx->quant_precision = get_bits(gb, 4); /* quant_precision */ |
| 2798 | 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 | 2804 | if (ctx->quant_precision != 5) |
| 2801 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 2805 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 2802 | 2806 | "quant precision %d\n", ctx->quant_precision); |
| 2803 | 2807 | if (ctx->quant_precision < 3 || ctx->quant_precision > 9) |
| 2804 | 2808 | ctx->quant_precision = 5; |
| @@ -2811,7 +2815,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 6 unmodified lines | ||
| 2811 | 2815 | if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */ |
| 2812 | 2816 | int i, v; |
| 2813 | 2817 | |
| 2814 | − mpeg4_load_default_matrices(s); | |
| 2818 | + mpeg4_load_default_matrices(&h->c); | |
| 2815 | 2819 | |
| 2816 | 2820 | /* load custom intra matrix */ |
| 2817 | 2821 | if (get_bits1(gb)) { |
| @@ -2819,7 +2823,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | ||
| 2819 | 2823 | for (i = 0; i < 64; i++) { |
| 2820 | 2824 | int j; |
| 2821 | 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 | 2827 | return AVERROR_INVALIDDATA; |
| 2824 | 2828 | } |
| 2825 | 2829 | v = get_bits(gb, 8); |
| @@ -2827,14 +2831,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | ||
| 2827 | 2831 | break; |
| 2828 | 2832 | |
| 2829 | 2833 | last = v; |
| 2830 | − j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 2831 | − s->intra_matrix[j] = last; | |
| 2834 | + j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 2835 | + h->c.intra_matrix[j] = last; | |
| 2832 | 2836 | } |
| 2833 | 2837 | |
| 2834 | 2838 | /* replicate last value */ |
| 2835 | 2839 | for (; i < 64; i++) { |
| 2836 | − int j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 2837 | − s->intra_matrix[j] = last; | |
| 2840 | + int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 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 | 2848 | for (i = 0; i < 64; i++) { |
| 2845 | 2849 | int j; |
| 2846 | 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 | 2852 | return AVERROR_INVALIDDATA; |
| 2849 | 2853 | } |
| 2850 | 2854 | v = get_bits(gb, 8); |
| @@ -2852,14 +2856,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line | ||
| 2852 | 2856 | break; |
| 2853 | 2857 | |
| 2854 | 2858 | last = v; |
| 2855 | − j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 2856 | − s->inter_matrix[j] = v; | |
| 2859 | + j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 2860 | + h->c.inter_matrix[j] = v; | |
| 2857 | 2861 | } |
| 2858 | 2862 | |
| 2859 | 2863 | /* replicate last value */ |
| 2860 | 2864 | for (; i < 64; i++) { |
| 2861 | − int j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 2862 | − s->inter_matrix[j] = last; | |
| 2865 | + int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]]; | |
| 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 | 2873 | if (vo_ver_id != 1) |
| 2870 | − s->quarter_sample = get_bits1(gb); | |
| 2874 | + h->c.quarter_sample = get_bits1(gb); | |
| 2871 | 2875 | else |
| 2872 | − s->quarter_sample = 0; | |
| 2876 | + h->c.quarter_sample = 0; | |
| 2873 | 2877 | |
| 2874 | 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 | 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 | 2898 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter4v_blocks */ |
| 2895 | 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 | 2902 | skip_bits_long(gb, pos - get_bits_count(gb)); |
| 2899 | 2903 | goto no_cplx_est; |
| 2900 | 2904 | } |
| @@ -2912,7 +2916,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 11 unmodified lines | ||
| 2912 | 2916 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel2 */ |
| 2913 | 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 | 2920 | skip_bits_long(gb, pos - get_bits_count(gb)); |
| 2917 | 2921 | goto no_cplx_est; |
| 2918 | 2922 | } |
| @@ -2921,7 +2925,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 2 unmodified lines | ||
| 2921 | 2925 | ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* qpel */ |
| 2922 | 2926 | } |
| 2923 | 2927 | } else |
| 2924 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 2928 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 2925 | 2929 | "Invalid Complexity estimation method %d\n", |
| 2926 | 2930 | estimation_method); |
| 2927 | 2931 | } else { |
| @@ -2934,19 +2938,19 @@ no_cplx_est: · 6 unmodified lines | ||
| 2934 | 2938 | |
| 2935 | 2939 | ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */ |
| 2936 | 2940 | |
| 2937 | − s->data_partitioning = get_bits1(gb); | |
| 2938 | − if (s->data_partitioning) | |
| 2941 | + h->c.data_partitioning = get_bits1(gb); | |
| 2942 | + if (h->c.data_partitioning) | |
| 2939 | 2943 | ctx->rvlc = get_bits1(gb); |
| 2940 | 2944 | |
| 2941 | 2945 | if (vo_ver_id != 1) { |
| 2942 | 2946 | ctx->new_pred = get_bits1(gb); |
| 2943 | 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 | 2949 | skip_bits(gb, 2); /* requested upstream message type */ |
| 2946 | 2950 | skip_bits1(gb); /* newpred segment type */ |
| 2947 | 2951 | } |
| 2948 | 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 | 2954 | "reduced resolution VOP not supported\n"); |
| 2951 | 2955 | } else { |
| 2952 | 2956 | ctx->new_pred = 0; |
| @@ -2977,21 +2981,23 @@ no_cplx_est: · 24 unmodified lines | ||
| 2977 | 2981 | ctx->scalability = 0; |
| 2978 | 2982 | *gb = bak; |
| 2979 | 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 | 2986 | // bin shape stuff FIXME |
| 2983 | 2987 | } |
| 2984 | 2988 | } |
| 2985 | 2989 | |
| 2986 | − if (s->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", | |
| 2988 | − s->avctx->framerate.den, s->avctx->framerate.num, | |
| 2990 | + if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) { | |
| 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", | |
| 2992 | + h->c.avctx->framerate.den, h->c.avctx->framerate.num, | |
| 2989 | 2993 | ctx->time_increment_bits, |
| 2990 | 2994 | ctx->quant_precision, |
| 2991 | − s->progressive_sequence, | |
| 2992 | − s->low_delay, | |
| 2993 | − ctx->scalability ? "scalability " :"" , s->quarter_sample ? "qpel " : "", | |
| 2994 | − s->data_partitioning ? "partition " : "", ctx->rvlc ? "rvlc " : "" | |
| 2995 | + h->c.progressive_sequence, | |
| 2996 | + h->c.low_delay, | |
| 2997 | + ctx->scalability ? "scalability " :"" , | |
| 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 | 3011 | static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 3006 | 3012 | { |
| 3007 | − MpegEncContext *s = &ctx->m; | |
| 3013 | + H263DecContext *const h = &ctx->h; | |
| 3008 | 3014 | char buf[256]; |
| 3009 | 3015 | int i; |
| 3010 | 3016 | int e; |
| @@ -3025,7 +3031,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) · 14 unmodified lines | ||
| 3025 | 3031 | if (e >= 2) { |
| 3026 | 3032 | ctx->divx_version = ver; |
| 3027 | 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 | 3037 | /* libavcodec detection */ |
| @@ -3036,7 +3042,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) · 4 unmodified lines | ||
| 3036 | 3042 | e = sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1; |
| 3037 | 3043 | if (e > 1) { |
| 3038 | 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 | 3046 | "Unknown Lavc version string encountered, %d.%d.%d; " |
| 3041 | 3047 | "clamping sub-version values to 8-bits.\n", |
| 3042 | 3048 | ver, ver2, ver3); |
| @@ -3091,19 +3097,19 @@ static av_cold void switch_to_xvid_idct(AVCodecContext *const avctx, · 48 unmodified lines | ||
| 3091 | 3097 | void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) |
| 3092 | 3098 | { |
| 3093 | 3099 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 3094 | − MpegEncContext *s = &ctx->m; | |
| 3100 | + H263DecContext *const h = &ctx->h; | |
| 3095 | 3101 | |
| 3096 | 3102 | if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) { |
| 3097 | − if (s->codec_tag == AV_RL32("XVID") || | |
| 3098 | − s->codec_tag == AV_RL32("XVIX") || | |
| 3099 | − s->codec_tag == AV_RL32("RMP4") || | |
| 3100 | − s->codec_tag == AV_RL32("ZMP4") || | |
| 3101 | − s->codec_tag == AV_RL32("SIPP")) | |
| 3103 | + if (h->c.codec_tag == AV_RL32("XVID") || | |
| 3104 | + h->c.codec_tag == AV_RL32("XVIX") || | |
| 3105 | + h->c.codec_tag == AV_RL32("RMP4") || | |
| 3106 | + h->c.codec_tag == AV_RL32("ZMP4") || | |
| 3107 | + h->c.codec_tag == AV_RL32("SIPP")) | |
| 3102 | 3108 | ctx->xvid_build = 0; |
| 3103 | 3109 | } |
| 3104 | 3110 | |
| 3105 | 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 | 3113 | ctx->vol_control_parameters == 0) |
| 3108 | 3114 | ctx->divx_version = 400; // divx 4 |
| 3109 | 3115 | |
| @@ -3112,68 +3118,68 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) · 2 unmodified lines | ||
| 3112 | 3118 | ctx->divx_build = -1; |
| 3113 | 3119 | } |
| 3114 | 3120 | |
| 3115 | − if (s->workaround_bugs & FF_BUG_AUTODETECT) { | |
| 3116 | − if (s->codec_tag == AV_RL32("XVIX")) | |
| 3117 | − s->workaround_bugs |= FF_BUG_XVID_ILACE; | |
| 3121 | + if (h->c.workaround_bugs & FF_BUG_AUTODETECT) { | |
| 3122 | + if (h->c.codec_tag == AV_RL32("XVIX")) | |
| 3123 | + h->c.workaround_bugs |= FF_BUG_XVID_ILACE; | |
| 3118 | 3124 | |
| 3119 | − if (s->codec_tag == AV_RL32("UMP4")) | |
| 3120 | − s->workaround_bugs |= FF_BUG_UMP4; | |
| 3125 | + if (h->c.codec_tag == AV_RL32("UMP4")) | |
| 3126 | + h->c.workaround_bugs |= FF_BUG_UMP4; | |
| 3121 | 3127 | |
| 3122 | 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 | 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 | 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 | 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 | 3140 | if (ctx->xvid_build <= 12U) |
| 3135 | − s->workaround_bugs |= FF_BUG_EDGE; | |
| 3141 | + h->c.workaround_bugs |= FF_BUG_EDGE; | |
| 3136 | 3142 | |
| 3137 | 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 | 3146 | #define SET_QPEL_FUNC(postfix1, postfix2) \ |
| 3141 | − s->qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \ | |
| 3142 | − s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \ | |
| 3143 | − s->qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2; | |
| 3147 | + h->c.qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \ | |
| 3148 | + h->c.qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \ | |
| 3149 | + h->c.qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2; | |
| 3144 | 3150 | |
| 3145 | 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 | 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 | 3157 | if (ctx->lavc_build < 4670U) |
| 3152 | − s->workaround_bugs |= FF_BUG_EDGE; | |
| 3158 | + h->c.workaround_bugs |= FF_BUG_EDGE; | |
| 3153 | 3159 | |
| 3154 | 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 | 3163 | if ((ctx->lavc_build&0xFF) >= 100) { |
| 3158 | 3164 | if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752552 && |
| 3159 | 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 | 3170 | if (ctx->divx_version >= 0) |
| 3165 | − s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; | |
| 3171 | + h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; | |
| 3166 | 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 | 3175 | if (ctx->divx_version < 500U) |
| 3170 | − s->workaround_bugs |= FF_BUG_EDGE; | |
| 3176 | + h->c.workaround_bugs |= FF_BUG_EDGE; | |
| 3171 | 3177 | |
| 3172 | 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 | 3183 | SET_QPEL_FUNC(qpel_pixels_tab[0][5], qpel16_mc11_old_c) |
| 3178 | 3184 | SET_QPEL_FUNC(qpel_pixels_tab[0][7], qpel16_mc31_old_c) |
| 3179 | 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 | 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 | 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, | |
| 3196 | − ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : ""); | |
| 3201 | + h->c.workaround_bugs, ctx->lavc_build, ctx->xvid_build, | |
| 3202 | + ctx->divx_version, ctx->divx_build, h->c.divx_packed ? "p" : ""); | |
| 3197 | 3203 | |
| 3198 | 3204 | if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 && |
| 3199 | − avctx->idct_algo == FF_IDCT_AUTO && !s->studio_profile) { | |
| 3200 | − switch_to_xvid_idct(avctx, s); | |
| 3205 | + avctx->idct_algo == FF_IDCT_AUTO && !h->c.studio_profile) { | |
| 3206 | + switch_to_xvid_idct(avctx, &h->c); | |
| 3201 | 3207 | } |
| 3202 | 3208 | } |
| 3203 | 3209 | |
| 3204 | 3210 | static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, |
| 3205 | 3211 | int parse_only) |
| 3206 | 3212 | { |
| 3207 | − MpegEncContext *s = &ctx->m; | |
| 3213 | + H263DecContext *const h = &ctx->h; | |
| 3208 | 3214 | int time_incr, time_increment; |
| 3209 | 3215 | int64_t pts; |
| 3210 | 3216 | |
| 3211 | − s->mcsel = 0; | |
| 3212 | − s->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 && | |
| 3214 | − ctx->vol_control_parameters == 0 && !(s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) { | |
| 3215 | − av_log(s->avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n"); | |
| 3216 | − s->low_delay = 0; | |
| 3217 | + h->c.mcsel = 0; | |
| 3218 | + h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */ | |
| 3219 | + if (h->c.pict_type == AV_PICTURE_TYPE_B && h->c.low_delay && | |
| 3220 | + ctx->vol_control_parameters == 0 && !(h->c.avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) { | |
| 3221 | + av_log(h->c.avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n"); | |
| 3222 | + h->c.low_delay = 0; | |
| 3217 | 3223 | } |
| 3218 | 3224 | |
| 3219 | − s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B; | |
| 3220 | − if (s->partitioned_frame) | |
| 3221 | − s->decode_mb = mpeg4_decode_partitioned_mb; | |
| 3225 | + h->c.partitioned_frame = h->c.data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B; | |
| 3226 | + if (h->c.partitioned_frame) | |
| 3227 | + h->decode_mb = mpeg4_decode_partitioned_mb; | |
| 3222 | 3228 | else |
| 3223 | − s->decode_mb = mpeg4_decode_mb; | |
| 3229 | + h->decode_mb = mpeg4_decode_mb; | |
| 3224 | 3230 | |
| 3225 | 3231 | time_incr = 0; |
| 3226 | 3232 | while (get_bits1(gb) != 0) |
| 3227 | 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 | 3237 | if (ctx->time_increment_bits == 0 || |
| 3232 | 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 | 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 | 3242 | for (ctx->time_increment_bits = 1; |
| 3237 | 3243 | ctx->time_increment_bits < 16; |
| 3238 | 3244 | ctx->time_increment_bits++) { |
| 3239 | − if (s->pict_type == AV_PICTURE_TYPE_P || | |
| 3240 | − (s->pict_type == AV_PICTURE_TYPE_S && | |
| 3245 | + if (h->c.pict_type == AV_PICTURE_TYPE_P || | |
| 3246 | + (h->c.pict_type == AV_PICTURE_TYPE_S && | |
| 3241 | 3247 | ctx->vol_sprite_usage == GMC_SPRITE)) { |
| 3242 | 3248 | if ((show_bits(gb, ctx->time_increment_bits + 6) & 0x37) == 0x30) |
| 3243 | 3249 | break; |
| @@ -3245,7 +3251,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 1 unmodified line | ||
| 3245 | 3251 | break; |
| 3246 | 3252 | } |
| 3247 | 3253 | |
| 3248 | − av_log(s->avctx, AV_LOG_WARNING, | |
| 3254 | + av_log(h->c.avctx, AV_LOG_WARNING, | |
| 3249 | 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 | 3260 | else |
| 3255 | 3261 | time_increment = get_bits(gb, ctx->time_increment_bits); |
| 3256 | 3262 | |
| 3257 | − if (s->pict_type != AV_PICTURE_TYPE_B) { | |
| 3258 | − s->last_time_base = s->time_base; | |
| 3259 | − s->time_base += time_incr; | |
| 3260 | − s->time = s->time_base * (int64_t)s->avctx->framerate.num + time_increment; | |
| 3261 | − if (s->workaround_bugs & FF_BUG_UMP4) { | |
| 3262 | − if (s->time < s->last_non_b_time) { | |
| 3263 | + if (h->c.pict_type != AV_PICTURE_TYPE_B) { | |
| 3264 | + h->c.last_time_base = h->c.time_base; | |
| 3265 | + h->c.time_base += time_incr; | |
| 3266 | + h->c.time = h->c.time_base * (int64_t)h->c.avctx->framerate.num + time_increment; | |
| 3267 | + if (h->c.workaround_bugs & FF_BUG_UMP4) { | |
| 3268 | + if (h->c.time < h->c.last_non_b_time) { | |
| 3263 | 3269 | /* header is not mpeg-4-compatible, broken encoder, |
| 3264 | 3270 | * trying to workaround */ |
| 3265 | − s->time_base++; | |
| 3266 | − s->time += s->avctx->framerate.num; | |
| 3271 | + h->c.time_base++; | |
| 3272 | + h->c.time += h->c.avctx->framerate.num; | |
| 3267 | 3273 | } |
| 3268 | 3274 | } |
| 3269 | − s->pp_time = s->time - s->last_non_b_time; | |
| 3270 | − s->last_non_b_time = s->time; | |
| 3275 | + h->c.pp_time = h->c.time - h->c.last_non_b_time; | |
| 3276 | + h->c.last_non_b_time = h->c.time; | |
| 3271 | 3277 | } else { |
| 3272 | − s->time = (s->last_time_base + time_incr) * (int64_t)s->avctx->framerate.num + time_increment; | |
| 3273 | − s->pb_time = s->pp_time - (s->last_non_b_time - s->time); | |
| 3274 | − if (s->pp_time <= s->pb_time || | |
| 3275 | − s->pp_time <= s->pp_time - s->pb_time || | |
| 3276 | − s->pp_time <= 0) { | |
| 3278 | + h->c.time = (h->c.last_time_base + time_incr) * (int64_t)h->c.avctx->framerate.num + time_increment; | |
| 3279 | + h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time); | |
| 3280 | + if (h->c.pp_time <= h->c.pb_time || | |
| 3281 | + h->c.pp_time <= h->c.pp_time - h->c.pb_time || | |
| 3282 | + h->c.pp_time <= 0) { | |
| 3277 | 3283 | /* messed up order, maybe after seeking? skipping current B-frame */ |
| 3278 | 3284 | return FRAME_SKIPPED; |
| 3279 | 3285 | } |
| 3280 | − ff_mpeg4_init_direct_mv(s); | |
| 3286 | + ff_mpeg4_init_direct_mv(&h->c); | |
| 3281 | 3287 | |
| 3282 | 3288 | if (ctx->t_frame == 0) |
| 3283 | − ctx->t_frame = s->pb_time; | |
| 3289 | + ctx->t_frame = h->c.pb_time; | |
| 3284 | 3290 | if (ctx->t_frame == 0) |
| 3285 | 3291 | ctx->t_frame = 1; // 1/0 protection |
| 3286 | − s->pp_field_time = (ROUNDED_DIV(s->last_non_b_time, ctx->t_frame) - | |
| 3287 | − ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2; | |
| 3288 | − s->pb_field_time = (ROUNDED_DIV(s->time, ctx->t_frame) - | |
| 3289 | − ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2; | |
| 3290 | − if (s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) { | |
| 3291 | − s->pb_field_time = 2; | |
| 3292 | − s->pp_field_time = 4; | |
| 3293 | − if (!s->progressive_sequence) | |
| 3292 | + h->c.pp_field_time = (ROUNDED_DIV(h->c.last_non_b_time, ctx->t_frame) - | |
| 3293 | + ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2; | |
| 3294 | + h->c.pb_field_time = (ROUNDED_DIV(h->c.time, ctx->t_frame) - | |
| 3295 | + ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2; | |
| 3296 | + if (h->c.pp_field_time <= h->c.pb_field_time || h->c.pb_field_time <= 1) { | |
| 3297 | + h->c.pb_field_time = 2; | |
| 3298 | + h->c.pp_field_time = 4; | |
| 3299 | + if (!h->c.progressive_sequence) | |
| 3294 | 3300 | return FRAME_SKIPPED; |
| 3295 | 3301 | } |
| 3296 | 3302 | } |
| 3297 | 3303 | |
| 3298 | − if (s->avctx->framerate.den) | |
| 3299 | − pts = ROUNDED_DIV(s->time, s->avctx->framerate.den); | |
| 3304 | + if (h->c.avctx->framerate.den) | |
| 3305 | + pts = ROUNDED_DIV(h->c.time, h->c.avctx->framerate.den); | |
| 3300 | 3306 | else |
| 3301 | 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 | 3312 | /* vop coded */ |
| 3307 | 3313 | if (get_bits1(gb) != 1) { |
| 3308 | − if (s->avctx->debug & FF_DEBUG_PICT_INFO) | |
| 3309 | − av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n"); | |
| 3310 | − s->skipped_last_frame = 1; | |
| 3314 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) | |
| 3315 | + av_log(h->c.avctx, AV_LOG_ERROR, "vop not coded\n"); | |
| 3316 | + h->c.skipped_last_frame = 1; | |
| 3311 | 3317 | return FRAME_SKIPPED; |
| 3312 | 3318 | } |
| 3313 | 3319 | if (ctx->new_pred) |
| 3314 | 3320 | decode_new_pred(ctx, gb); |
| 3315 | 3321 | |
| 3316 | 3322 | if (ctx->shape != BIN_ONLY_SHAPE && |
| 3317 | − (s->pict_type == AV_PICTURE_TYPE_P || | |
| 3318 | − (s->pict_type == AV_PICTURE_TYPE_S && | |
| 3323 | + (h->c.pict_type == AV_PICTURE_TYPE_P || | |
| 3324 | + (h->c.pict_type == AV_PICTURE_TYPE_S && | |
| 3319 | 3325 | ctx->vol_sprite_usage == GMC_SPRITE))) { |
| 3320 | 3326 | /* rounding type for motion estimation */ |
| 3321 | − s->no_rounding = get_bits1(gb); | |
| 3327 | + h->c.no_rounding = get_bits1(gb); | |
| 3322 | 3328 | } else { |
| 3323 | − s->no_rounding = 0; | |
| 3329 | + h->c.no_rounding = 0; | |
| 3324 | 3330 | } |
| 3325 | 3331 | // FIXME reduced res stuff |
| 3326 | 3332 | |
| 3327 | 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 | 3335 | skip_bits(gb, 13); /* width */ |
| 3330 | − check_marker(s->avctx, gb, "after width"); | |
| 3336 | + check_marker(h->c.avctx, gb, "after width"); | |
| 3331 | 3337 | skip_bits(gb, 13); /* height */ |
| 3332 | − check_marker(s->avctx, gb, "after height"); | |
| 3338 | + check_marker(h->c.avctx, gb, "after height"); | |
| 3333 | 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 | 3341 | skip_bits(gb, 13); /* ver_spat_ref */ |
| 3336 | 3342 | } |
| 3337 | 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 | 3351 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 3346 | 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 | 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 | 3356 | skip_bits_long(gb, ctx->cplx_estimation_trash_b); |
| 3351 | 3357 | |
| 3352 | 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 | 3360 | return AVERROR_INVALIDDATA; |
| 3355 | 3361 | } |
| 3356 | 3362 | ctx->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)]; |
| 3357 | − if (!s->progressive_sequence) { | |
| 3358 | − s->top_field_first = get_bits1(gb); | |
| 3359 | − s->alternate_scan = get_bits1(gb); | |
| 3363 | + if (!h->c.progressive_sequence) { | |
| 3364 | + h->c.top_field_first = get_bits1(gb); | |
| 3365 | + h->c.alternate_scan = get_bits1(gb); | |
| 3360 | 3366 | } else |
| 3361 | − s->alternate_scan = 0; | |
| 3367 | + h->c.alternate_scan = 0; | |
| 3362 | 3368 | } |
| 3363 | 3369 | /* Skip at this point when only parsing since the remaining |
| 3364 | 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 | 3372 | if (parse_only) |
| 3367 | 3373 | goto end; |
| 3368 | 3374 | |
| 3369 | − if (s->alternate_scan) { | |
| 3370 | − ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan); | |
| 3371 | − ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_vertical_scan, | |
| 3372 | − s->idsp.idct_permutation); | |
| 3375 | + if (h->c.alternate_scan) { | |
| 3376 | + ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_alternate_vertical_scan); | |
| 3377 | + ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_vertical_scan, | |
| 3378 | + h->c.idsp.idct_permutation); | |
| 3373 | 3379 | } else { |
| 3374 | − ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct); | |
| 3375 | − ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_horizontal_scan, | |
| 3376 | − s->idsp.idct_permutation); | |
| 3380 | + ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_zigzag_direct); | |
| 3381 | + ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_horizontal_scan, | |
| 3382 | + h->c.idsp.idct_permutation); | |
| 3377 | 3383 | } |
| 3378 | − ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan, | |
| 3379 | − s->idsp.idct_permutation); | |
| 3384 | + ff_permute_scantable(h->c.permutated_intra_v_scantable, ff_alternate_vertical_scan, | |
| 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 | 3388 | if((ctx->vol_sprite_usage == STATIC_SPRITE || |
| 3383 | 3389 | ctx->vol_sprite_usage == GMC_SPRITE)) { |
| 3384 | 3390 | if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0) |
| 3385 | 3391 | return AVERROR_INVALIDDATA; |
| 3386 | 3392 | if (ctx->sprite_brightness_change) |
| 3387 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 3393 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 3388 | 3394 | "sprite_brightness_change not supported\n"); |
| 3389 | 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 | 3397 | } else { |
| 3392 | 3398 | memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset)); |
| 3393 | 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 | 3403 | ctx->f_code = 1; |
| 3398 | 3404 | ctx->b_code = 1; |
| 3399 | 3405 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 3400 | − s->chroma_qscale = s->qscale = get_bits(gb, ctx->quant_precision); | |
| 3401 | − if (s->qscale == 0) { | |
| 3402 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 3406 | + h->c.chroma_qscale = h->c.qscale = get_bits(gb, ctx->quant_precision); | |
| 3407 | + if (h->c.qscale == 0) { | |
| 3408 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 3403 | 3409 | "Error, header damaged or not MPEG-4 header (qscale=0)\n"); |
| 3404 | 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 | 3414 | ctx->f_code = get_bits(gb, 3); /* fcode_for */ |
| 3409 | 3415 | if (ctx->f_code == 0) { |
| 3410 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 3416 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 3411 | 3417 | "Error, header damaged or not MPEG-4 header (f_code=0)\n"); |
| 3412 | 3418 | ctx->f_code = 1; |
| 3413 | 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 | 3424 | ctx->b_code = get_bits(gb, 3); |
| 3419 | 3425 | if (ctx->b_code == 0) { |
| 3420 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 3426 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 3421 | 3427 | "Error, header damaged or not MPEG4 header (b_code=0)\n"); |
| 3422 | 3428 | ctx->b_code=1; |
| 3423 | 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) { | |
| 3428 | − av_log(s->avctx, AV_LOG_DEBUG, | |
| 3433 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 3434 | + av_log(h->c.avctx, AV_LOG_DEBUG, | |
| 3429 | 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, | |
| 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')), | |
| 3432 | − gb->size_in_bits,s->progressive_sequence, s->alternate_scan, | |
| 3433 | − s->top_field_first, s->quarter_sample ? 'q' : 'h', | |
| 3434 | − s->data_partitioning, ctx->resync_marker, | |
| 3436 | + h->c.qscale, ctx->f_code, ctx->b_code, | |
| 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')), | |
| 3438 | + gb->size_in_bits,h->c.progressive_sequence, h->c.alternate_scan, | |
| 3439 | + h->c.top_field_first, h->c.quarter_sample ? 'q' : 'h', | |
| 3440 | + h->c.data_partitioning, ctx->resync_marker, | |
| 3435 | 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 | 3443 | ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold, |
| 3438 | 3444 | ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p, |
| 3439 | 3445 | ctx->cplx_estimation_trash_b, |
| 3440 | − s->time, | |
| 3446 | + h->c.time, | |
| 3441 | 3447 | time_increment |
| 3442 | 3448 | ); |
| 3443 | 3449 | } |
| 3444 | 3450 | |
| 3445 | 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 | 3453 | skip_bits1(gb); // vop shape coding type |
| 3448 | 3454 | } else { |
| 3449 | 3455 | if (ctx->enhancement_type) { |
| 3450 | 3456 | int load_backward_shape = get_bits1(gb); |
| 3451 | 3457 | if (load_backward_shape) |
| 3452 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 3458 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 3453 | 3459 | "load backward shape isn't supported\n"); |
| 3454 | 3460 | } |
| 3455 | 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 | |
| 3460 | − : ctx->dct_unquantize_h263_intra; | |
| 3465 | + h->c.dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra | |
| 3466 | + : ctx->dct_unquantize_h263_intra; | |
| 3461 | 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 | 3470 | end: |
| 3465 | 3471 | /* detect buggy encoders which don't set the low_delay flag |
| 3466 | 3472 | * (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames |
| 3467 | 3473 | * easily (although it's buggy too) */ |
| 3468 | 3474 | if (ctx->vo_type == 0 && ctx->vol_control_parameters == 0 && |
| 3469 | − ctx->divx_version == -1 && s->picture_number == 0) { | |
| 3470 | − av_log(s->avctx, AV_LOG_WARNING, | |
| 3475 | + ctx->divx_version == -1 && h->c.picture_number == 0) { | |
| 3476 | + av_log(h->c.avctx, AV_LOG_WARNING, | |
| 3471 | 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) { | |
| 3478 | − s->h_edge_pos = s->width; | |
| 3479 | − s->v_edge_pos = s->height; | |
| 3483 | + if (h->c.workaround_bugs & FF_BUG_EDGE) { | |
| 3484 | + h->c.h_edge_pos = h->c.width; | |
| 3485 | + h->c.v_edge_pos = h->c.height; | |
| 3480 | 3486 | } |
| 3481 | 3487 | return 0; |
| 3482 | 3488 | } |
| 3483 | 3489 | |
| 3484 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 3513 | if (get_bits_left(gb) <= 32) |
| 3508 | 3514 | return 0; |
| 3509 | 3515 | |
| 3510 | − s->partitioned_frame = 0; | |
| 3511 | − s->interlaced_dct = 0; | |
| 3512 | − s->decode_mb = mpeg4_decode_studio_mb; | |
| 3516 | + h->c.partitioned_frame = 0; | |
| 3517 | + h->c.interlaced_dct = 0; | |
| 3518 | + h->decode_mb = mpeg4_decode_studio_mb; | |
| 3513 | 3519 | |
| 3514 | 3520 | decode_smpte_tc(ctx, gb); |
| 3515 | 3521 | |
| 3516 | 3522 | skip_bits(gb, 10); /* temporal_reference */ |
| 3517 | 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 | 3525 | if (get_bits1(gb)) { /* vop_coded */ |
| 3520 | 3526 | skip_bits1(gb); /* top_field_first */ |
| 3521 | 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 | 3532 | if (get_bits1(gb)) |
| 3527 | 3533 | reset_studio_dc_predictors(ctx); |
| 3528 | 3534 | } |
| 3529 | 3535 | |
| 3530 | 3536 | if (ctx->shape != BIN_ONLY_SHAPE) { |
| 3531 | − s->alternate_scan = get_bits1(gb); | |
| 3532 | − s->frame_pred_frame_dct = get_bits1(gb); | |
| 3533 | − ctx->dct_precision = get_bits(gb, 2); | |
| 3534 | − s->intra_dc_precision = get_bits(gb, 2); | |
| 3535 | − s->q_scale_type = get_bits1(gb); | |
| 3537 | + h->c.alternate_scan = get_bits1(gb); | |
| 3538 | + h->c.frame_pred_frame_dct = get_bits1(gb); | |
| 3539 | + ctx->dct_precision = get_bits(gb, 2); | |
| 3540 | + h->c.intra_dc_precision = get_bits(gb, 2); | |
| 3541 | + h->c.q_scale_type = get_bits1(gb); | |
| 3536 | 3542 | } |
| 3537 | 3543 | |
| 3538 | − ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, | |
| 3539 | − s->alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct); | |
| 3544 | + ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, | |
| 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 | 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 | 3552 | return 0; |
| 3547 | 3553 | } |
| 3548 | 3554 | |
| 3549 | 3555 | static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb) |
| 3550 | 3556 | { |
| 3551 | − MpegEncContext *s = &ctx->m; | |
| 3552 | 3557 | int visual_object_type; |
| 3553 | 3558 | |
| 3554 | 3559 | skip_bits(gb, 4); /* visual_object_verid */ |
| 3555 | 3560 | visual_object_type = get_bits(gb, 4); |
| 3556 | 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 | 3563 | return AVERROR_PATCHWELCOME; |
| 3559 | 3564 | } |
| 3560 | 3565 | |
| 3561 | 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 | 3569 | return 0; |
| 3565 | 3570 | } |
| @@ -3577,7 +3582,7 @@ static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb) · 11 unmodified lines | ||
| 3577 | 3582 | int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, |
| 3578 | 3583 | int header, int parse_only) |
| 3579 | 3584 | { |
| 3580 | − MpegEncContext *s = &ctx->m; | |
| 3585 | + MPVContext *const s = &ctx->h.c; | |
| 3581 | 3586 | unsigned startcode, v; |
| 3582 | 3587 | int ret; |
| 3583 | 3588 | int vol = 0; |
| @@ -3731,22 +3736,22 @@ end: · 147 unmodified lines | ||
| 3731 | 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 | 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 | 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 | 3751 | for (int i = 0; i < buf_size - 3; i++) { |
| 3747 | 3752 | if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) { |
| 3748 | 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 | 3755 | bitstream_buffer_size = 0; |
| 3751 | 3756 | } |
| 3752 | 3757 | break; |
| @@ -3754,8 +3759,8 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s) · 1 unmodified line | ||
| 3754 | 3759 | } |
| 3755 | 3760 | } |
| 3756 | 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 | |
| 3758 | − int ret = init_get_bits8(&s->gb, ctx->bitstream_buffer->data, | |
| 3762 | + if (bitstream_buffer_size && (h->c.divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder | |
| 3763 | + int ret = init_get_bits8(&h->c.gb, ctx->bitstream_buffer->data, | |
| 3759 | 3764 | bitstream_buffer_size); |
| 3760 | 3765 | if (ret < 0) |
| 3761 | 3766 | return ret; |
| @@ -3763,20 +3768,20 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s) · 1 unmodified line | ||
| 3763 | 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 | 3774 | int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt) |
| 3770 | 3775 | { |
| 3771 | 3776 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 3772 | − MpegEncContext *s = &ctx->m; | |
| 3777 | + H263DecContext *const h = &ctx->h; | |
| 3773 | 3778 | int ret; |
| 3774 | 3779 | |
| 3775 | 3780 | av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size); |
| 3776 | 3781 | |
| 3777 | 3782 | /* divx 5.01+ bitstream reorder stuff */ |
| 3778 | − if (s->divx_packed) { | |
| 3779 | − int current_pos = ctx->bitstream_buffer && s->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&s->gb) >> 3); | |
| 3783 | + if (h->c.divx_packed) { | |
| 3784 | + int current_pos = ctx->bitstream_buffer && h->c.gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->c.gb) >> 3); | |
| 3780 | 3785 | int startcode_found = 0; |
| 3781 | 3786 | uint8_t *buf = pkt->data; |
| 3782 | 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 | 3803 | if (startcode_found) { |
| 3799 | 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 | 3806 | "wasteful way to store B-frames ('packed B-frames'). " |
| 3802 | 3807 | "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n"); |
| 3803 | 3808 | ctx->showed_packed_warning = 1; |
| @@ -3874,11 +3879,11 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 70 unmodified lines | ||
| 3874 | 3879 | { |
| 3875 | 3880 | Mpeg4DecContext *s = dst->priv_data; |
| 3876 | 3881 | const Mpeg4DecContext *s1 = src->priv_data; |
| 3877 | − int init = s->m.context_initialized; | |
| 3882 | + int init = s->h.c.context_initialized; | |
| 3878 | 3883 | int ret; |
| 3879 | 3884 | |
| 3880 | 3885 | if (!init) { |
| 3881 | − ret = update_mpvctx(&s->m, &s1->m); | |
| 3886 | + ret = update_mpvctx(&s->h.c, &s1->h.c); | |
| 3882 | 3887 | if (ret < 0) |
| 3883 | 3888 | return ret; |
| 3884 | 3889 | } |
| @@ -3894,7 +3899,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 9 unmodified lines | ||
| 3894 | 3899 | s->sprite_brightness_change = s1->sprite_brightness_change; |
| 3895 | 3900 | s->sprite_warping_accuracy = s1->sprite_warping_accuracy; |
| 3896 | 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 | 3903 | s->mpeg_quant = s1->mpeg_quant; |
| 3899 | 3904 | s->rvlc = s1->rvlc; |
| 3900 | 3905 | s->resync_marker = s1->resync_marker; |
| @@ -3903,7 +3908,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 2 unmodified lines | ||
| 3903 | 3908 | s->enhancement_type = s1->enhancement_type; |
| 3904 | 3909 | s->scalability = s1->scalability; |
| 3905 | 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 | 3912 | s->divx_version = s1->divx_version; |
| 3908 | 3913 | s->divx_build = s1->divx_build; |
| 3909 | 3914 | s->xvid_build = s1->xvid_build; |
| @@ -3915,7 +3920,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 5 unmodified lines | ||
| 3915 | 3920 | s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p; |
| 3916 | 3921 | s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b; |
| 3917 | 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 | 3925 | memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift)); |
| 3921 | 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 | 3991 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 3987 | 3992 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 3988 | − MpegEncContext *s = &ctx->m; | |
| 3993 | + H263DecContext *const h = &ctx->h; | |
| 3989 | 3994 | MPVUnquantDSPContext unquant_dsp_ctx; |
| 3990 | 3995 | int ret; |
| 3991 | 3996 | |
| @@ -4006,18 +4011,18 @@ static av_cold int decode_init(AVCodecContext *avctx) · 14 unmodified lines | ||
| 4006 | 4011 | // so that is all we keep. |
| 4007 | 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; | |
| 4010 | − s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table; | |
| 4014 | + h->c.y_dc_scale_table = ff_mpeg4_y_dc_scale_table; | |
| 4015 | + h->c.c_dc_scale_table = ff_mpeg4_c_dc_scale_table; | |
| 4011 | 4016 | |
| 4012 | − s->h263_pred = 1; | |
| 4013 | − s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */ | |
| 4014 | − s->decode_mb = mpeg4_decode_mb; | |
| 4017 | + h->c.h263_pred = 1; | |
| 4018 | + h->c.low_delay = 0; /* default, might be overridden in the vol header during header parsing */ | |
| 4019 | + h->decode_mb = mpeg4_decode_mb; | |
| 4015 | 4020 | ctx->time_increment_bits = 4; /* default value for broken headers */ |
| 4016 | 4021 | ctx->quant_precision = 5; |
| 4017 | 4022 | |
| 4018 | 4023 | avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; |
| 4019 | 4024 | |
| 4020 | − ff_qpeldsp_init(&s->qdsp); | |
| 4025 | + ff_qpeldsp_init(&h->c.qdsp); | |
| 4021 | 4026 | ff_mpeg4videodsp_init(&ctx->mdsp); |
| 4022 | 4027 | |
| 4023 | 4028 | ff_thread_once(&init_static_once, mpeg4_init_static); |
| @@ -26,13 +26,14 @@ · 25 unmodified lines | ||
| 26 | 26 | #include <stdint.h> |
| 27 | 27 | |
| 28 | 28 | #include "get_bits.h" |
| 29 | +#include "h263dec.h" | |
| 29 | 30 | #include "mpegvideo.h" |
| 30 | 31 | #include "mpeg4videodsp.h" |
| 31 | 32 | |
| 32 | 33 | #include "libavutil/mem_internal.h" |
| 33 | 34 | |
| 34 | 35 | typedef struct Mpeg4DecContext { |
| 35 | − MpegEncContext m; | |
| 36 | + H263DecContext h; | |
| 36 | 37 | |
| 37 | 38 | int f_code; ///< forward MV resolution |
| 38 | 39 | int b_code; ///< backward MV resolution for B-frames |
| @@ -108,7 +109,7 @@ typedef struct Mpeg4DecContext { · 69 unmodified lines | ||
| 108 | 109 | int dct_precision; |
| 109 | 110 | } Mpeg4DecContext; |
| 110 | 111 | |
| 111 | −int ff_mpeg4_decode_picture_header(MpegEncContext *s); | |
| 112 | +int ff_mpeg4_decode_picture_header(H263DecContext *const h); | |
| 112 | 113 | int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, |
| 113 | 114 | int header, int parse_only); |
| 114 | 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 | 118 | void ff_mpeg4_mcsel_motion(MpegEncContext *s, |
| 118 | 119 | uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
| 119 | 120 | uint8_t *const *ref_picture); |
| 120 | −int ff_mpeg4_decode_partitions(MPVContext *const s); | |
| 121 | −int ff_mpeg4_decode_video_packet_header(MPVContext *const s); | |
| 122 | −int ff_mpeg4_decode_studio_slice_header(MPVContext *const s); | |
| 121 | +int ff_mpeg4_decode_partitions(H263DecContext *const h); | |
| 122 | +int ff_mpeg4_decode_video_packet_header(H263DecContext *const h); | |
| 123 | +int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h); | |
| 123 | 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 | 126 | int dir); |
| 126 | 127 | int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt); |
| 127 | 128 | |
| @@ -307,7 +307,6 @@ typedef struct MpegEncContext { · 306 unmodified lines | ||
| 307 | 307 | int first_field; ///< is 1 for the first field of a field picture 0 otherwise |
| 308 | 308 | |
| 309 | 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 | 311 | #define SLICE_OK 0 |
| 313 | 312 | #define SLICE_ERROR -1 |
| @@ -74,23 +74,24 @@ static VLCElem v2_mb_type_vlc[128]; · 73 unmodified lines | ||
| 74 | 74 | VLCElem ff_inter_intra_vlc[8]; |
| 75 | 75 | |
| 76 | 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 | 79 | int code, val, sign, shift; |
| 80 | 80 | |
| 81 | − code = get_vlc2(&s->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); | |
| 81 | + code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2); | |
| 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 | 84 | if (code < 0) |
| 84 | 85 | return 0xffff; |
| 85 | 86 | |
| 86 | 87 | if (code == 0) |
| 87 | 88 | return pred; |
| 88 | − sign = get_bits1(&s->gb); | |
| 89 | + sign = get_bits1(&h->c.gb); | |
| 89 | 90 | shift = f_code - 1; |
| 90 | 91 | val = code; |
| 91 | 92 | if (shift) { |
| 92 | 93 | val = (val - 1) << shift; |
| 93 | − val |= get_bits(&s->gb, shift); | |
| 94 | + val |= get_bits(&h->c.gb, shift); | |
| 94 | 95 | val++; |
| 95 | 96 | } |
| 96 | 97 | if (sign) |
| @@ -105,151 +106,155 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) · 8 unmodified lines | ||
| 105 | 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 | 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 | 116 | if (ms->use_skip_mb_code) { |
| 116 | − if (get_bits1(&s->gb)) { | |
| 117 | + if (get_bits1(&h->c.gb)) { | |
| 117 | 118 | /* skip mb */ |
| 118 | − s->mb_intra = 0; | |
| 119 | + h->c.mb_intra = 0; | |
| 119 | 120 | for(i=0;i<6;i++) |
| 120 | − s->block_last_index[i] = -1; | |
| 121 | − s->mv_dir = MV_DIR_FORWARD; | |
| 122 | − s->mv_type = MV_TYPE_16X16; | |
| 123 | − s->mv[0][0][0] = 0; | |
| 124 | − s->mv[0][0][1] = 0; | |
| 125 | − s->mb_skipped = 1; | |
| 121 | + h->c.block_last_index[i] = -1; | |
| 122 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 123 | + h->c.mv_type = MV_TYPE_16X16; | |
| 124 | + h->c.mv[0][0][0] = 0; | |
| 125 | + h->c.mv[0][0][1] = 0; | |
| 126 | + h->c.mb_skipped = 1; | |
| 126 | 127 | *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 127 | 128 | return 0; |
| 128 | 129 | } |
| 129 | 130 | } |
| 130 | 131 | |
| 131 | − if (s->msmpeg4_version == MSMP4_V2) | |
| 132 | − code = get_vlc2(&s->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1); | |
| 132 | + if (h->c.msmpeg4_version == MSMP4_V2) | |
| 133 | + code = get_vlc2(&h->c.gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1); | |
| 133 | 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 | 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 | 139 | return -1; |
| 138 | 140 | } |
| 139 | 141 | |
| 140 | − s->mb_intra = code >>2; | |
| 142 | + h->c.mb_intra = code >>2; | |
| 141 | 143 | |
| 142 | 144 | cbp = code & 0x3; |
| 143 | 145 | } else { |
| 144 | − s->mb_intra = 1; | |
| 145 | − if (s->msmpeg4_version == MSMP4_V2) | |
| 146 | − cbp = get_vlc2(&s->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1); | |
| 146 | + h->c.mb_intra = 1; | |
| 147 | + if (h->c.msmpeg4_version == MSMP4_V2) | |
| 148 | + cbp = get_vlc2(&h->c.gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1); | |
| 147 | 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 | 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 | 154 | return -1; |
| 152 | 155 | } |
| 153 | 156 | } |
| 154 | 157 | |
| 155 | − if (!s->mb_intra) { | |
| 158 | + if (!h->c.mb_intra) { | |
| 156 | 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 | 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 | 165 | return -1; |
| 162 | 166 | } |
| 163 | 167 | |
| 164 | 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 | 170 | cbp ^= 0x3C; |
| 167 | 171 | |
| 168 | − ff_h263_pred_motion(s, 0, 0, &mx, &my); | |
| 169 | − mx= msmpeg4v2_decode_motion(s, mx, 1); | |
| 170 | − my= msmpeg4v2_decode_motion(s, my, 1); | |
| 172 | + ff_h263_pred_motion(&h->c, 0, 0, &mx, &my); | |
| 173 | + mx = msmpeg4v2_decode_motion(h, mx, 1); | |
| 174 | + my = msmpeg4v2_decode_motion(h, my, 1); | |
| 171 | 175 | |
| 172 | − s->mv_dir = MV_DIR_FORWARD; | |
| 173 | − s->mv_type = MV_TYPE_16X16; | |
| 174 | − s->mv[0][0][0] = mx; | |
| 175 | − s->mv[0][0][1] = my; | |
| 176 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 177 | + h->c.mv_type = MV_TYPE_16X16; | |
| 178 | + h->c.mv[0][0][0] = mx; | |
| 179 | + h->c.mv[0][0][1] = my; | |
| 176 | 180 | *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 177 | 181 | } else { |
| 178 | 182 | int v; |
| 179 | − if (s->msmpeg4_version == MSMP4_V2) { | |
| 180 | − s->ac_pred = get_bits1(&s->gb); | |
| 181 | − v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 183 | + if (h->c.msmpeg4_version == MSMP4_V2) { | |
| 184 | + h->c.ac_pred = get_bits1(&h->c.gb); | |
| 185 | + v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 182 | 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 | 188 | return -1; |
| 185 | 189 | } |
| 186 | 190 | cbp|= v<<2; |
| 187 | 191 | } else{ |
| 188 | − s->ac_pred = 0; | |
| 189 | − v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 192 | + h->c.ac_pred = 0; | |
| 193 | + v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); | |
| 190 | 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 | 196 | return -1; |
| 193 | 197 | } |
| 194 | 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 | 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 | 205 | for (i = 0; i < 6; i++) { |
| 202 | 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 | 210 | return -1; |
| 206 | 211 | } |
| 207 | 212 | } |
| 208 | 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 | 219 | int cbp, code, i; |
| 215 | 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 | 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 | 227 | if (ms->use_skip_mb_code) { |
| 223 | − if (get_bits1(&s->gb)) { | |
| 228 | + if (get_bits1(&h->c.gb)) { | |
| 224 | 229 | /* skip mb */ |
| 225 | − s->mb_intra = 0; | |
| 230 | + h->c.mb_intra = 0; | |
| 226 | 231 | for(i=0;i<6;i++) |
| 227 | − s->block_last_index[i] = -1; | |
| 228 | − s->mv_dir = MV_DIR_FORWARD; | |
| 229 | − s->mv_type = MV_TYPE_16X16; | |
| 230 | − s->mv[0][0][0] = 0; | |
| 231 | − s->mv[0][0][1] = 0; | |
| 232 | − s->mb_skipped = 1; | |
| 232 | + h->c.block_last_index[i] = -1; | |
| 233 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 234 | + h->c.mv_type = MV_TYPE_16X16; | |
| 235 | + h->c.mv[0][0][0] = 0; | |
| 236 | + h->c.mv[0][0][1] = 0; | |
| 237 | + h->c.mb_skipped = 1; | |
| 233 | 238 | *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 234 | 239 | |
| 235 | 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); | |
| 240 | − //s->mb_intra = (code & 0x40) ? 0 : 1; | |
| 241 | − s->mb_intra = (~code & 0x40) >> 6; | |
| 244 | + code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3); | |
| 245 | + //h->c.mb_intra = (code & 0x40) ? 0 : 1; | |
| 246 | + h->c.mb_intra = (~code & 0x40) >> 6; | |
| 242 | 247 | |
| 243 | 248 | cbp = code & 0x3f; |
| 244 | 249 | } else { |
| 245 | − s->mb_intra = 1; | |
| 246 | − code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2); | |
| 250 | + h->c.mb_intra = 1; | |
| 251 | + code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2); | |
| 247 | 252 | /* predict coded block pattern */ |
| 248 | 253 | cbp = 0; |
| 249 | 254 | for(i=0;i<6;i++) { |
| 250 | 255 | int val = ((code >> (5 - i)) & 1); |
| 251 | 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 | 258 | val = val ^ pred; |
| 254 | 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 | 266 | int mx, my; |
| 262 | 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 | 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 | 272 | ff_msmpeg4_decode_motion(ms, &mx, &my); |
| 268 | − s->mv_dir = MV_DIR_FORWARD; | |
| 269 | − s->mv_type = MV_TYPE_16X16; | |
| 270 | − s->mv[0][0][0] = mx; | |
| 271 | − s->mv[0][0][1] = my; | |
| 273 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 274 | + h->c.mv_type = MV_TYPE_16X16; | |
| 275 | + h->c.mv[0][0][0] = mx; | |
| 276 | + h->c.mv[0][0][1] = my; | |
| 272 | 277 | *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16; |
| 273 | 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 | 280 | ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0), |
| 276 | − show_bits(&s->gb, 24)); | |
| 277 | − s->ac_pred = get_bits1(&s->gb); | |
| 281 | + show_bits(&h->c.gb, 24)); | |
| 282 | + h->c.ac_pred = get_bits1(&h->c.gb); | |
| 278 | 283 | *mb_type_ptr = MB_TYPE_INTRA; |
| 279 | − if(s->inter_intra_pred){ | |
| 280 | − s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1); | |
| 281 | − ff_dlog(s->avctx, "%d%d %d %d/", | |
| 282 | − s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); | |
| 284 | + if (h->c.inter_intra_pred) { | |
| 285 | + h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1); | |
| 286 | + ff_dlog(h->c.avctx, "%d%d %d %d/", | |
| 287 | + h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y); | |
| 283 | 288 | } |
| 284 | 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 | 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 | 296 | for (i = 0; i < 6; i++) { |
| 292 | 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 | 301 | return -1; |
| 296 | 302 | } |
| 297 | 303 | } |
| @@ -357,7 +363,7 @@ static av_cold void msmpeg4_decode_init_static(void) · 59 unmodified lines | ||
| 357 | 363 | av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) |
| 358 | 364 | { |
| 359 | 365 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 360 | − MpegEncContext *s = avctx->priv_data; | |
| 366 | + H263DecContext *const h = avctx->priv_data; | |
| 361 | 367 | int ret; |
| 362 | 368 | |
| 363 | 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 | 373 | return -1; |
| 368 | 374 | |
| 369 | 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 | 381 | case MSMP4_V1: |
| 376 | 382 | case MSMP4_V2: |
| 377 | − s->decode_mb= msmpeg4v12_decode_mb; | |
| 383 | + h->decode_mb = msmpeg4v12_decode_mb; | |
| 378 | 384 | break; |
| 379 | 385 | case MSMP4_V3: |
| 380 | 386 | case MSMP4_WMV1: |
| 381 | − s->decode_mb= msmpeg4v34_decode_mb; | |
| 387 | + h->decode_mb = msmpeg4v34_decode_mb; | |
| 382 | 388 | break; |
| 383 | 389 | case MSMP4_WMV2: |
| 384 | 390 | break; |
| @@ -386,16 +392,16 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) · 1 unmodified line | ||
| 386 | 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 | 397 | ff_thread_once(&init_static_once, msmpeg4_decode_init_static); |
| 392 | 398 | |
| 393 | 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 | 405 | int code; |
| 400 | 406 | |
| 401 | 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 | 409 | // smallest "black/skip" frame generally contain not much recoverable content |
| 404 | 410 | // while at the same time they have the highest computational requirements |
| 405 | 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 | 413 | return AVERROR_INVALIDDATA; |
| 408 | 414 | |
| 409 | − if (s->msmpeg4_version == MSMP4_V1) { | |
| 410 | − int start_code = get_bits_long(&s->gb, 32); | |
| 415 | + if (h->c.msmpeg4_version == MSMP4_V1) { | |
| 416 | + int start_code = get_bits_long(&h->c.gb, 32); | |
| 411 | 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 | 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; | |
| 420 | − if (s->pict_type != AV_PICTURE_TYPE_I && | |
| 421 | − s->pict_type != AV_PICTURE_TYPE_P){ | |
| 422 | − av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n"); | |
| 425 | + h->c.pict_type = get_bits(&h->c.gb, 2) + 1; | |
| 426 | + if (h->c.pict_type != AV_PICTURE_TYPE_I && | |
| 427 | + h->c.pict_type != AV_PICTURE_TYPE_P){ | |
| 428 | + av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n"); | |
| 423 | 429 | return -1; |
| 424 | 430 | } |
| 425 | − s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); | |
| 426 | − if(s->qscale==0){ | |
| 427 | − av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n"); | |
| 431 | + h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); | |
| 432 | + if (h->c.qscale == 0) { | |
| 433 | + av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n"); | |
| 428 | 434 | return -1; |
| 429 | 435 | } |
| 430 | 436 | |
| 431 | − if (s->pict_type == AV_PICTURE_TYPE_I) { | |
| 432 | − code = get_bits(&s->gb, 5); | |
| 433 | − if (s->msmpeg4_version == MSMP4_V1) { | |
| 434 | − if(code==0 || code>s->mb_height){ | |
| 435 | − av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code); | |
| 437 | + if (h->c.pict_type == AV_PICTURE_TYPE_I) { | |
| 438 | + code = get_bits(&h->c.gb, 5); | |
| 439 | + if (h->c.msmpeg4_version == MSMP4_V1) { | |
| 440 | + if(code==0 || code>h->c.mb_height) { | |
| 441 | + av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code); | |
| 436 | 442 | return -1; |
| 437 | 443 | } |
| 438 | 444 | |
| 439 | − s->slice_height = code; | |
| 445 | + h->c.slice_height = code; | |
| 440 | 446 | }else{ |
| 441 | 447 | /* 0x17: one slice, 0x18: two slices, ... */ |
| 442 | 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 | 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 | 457 | case MSMP4_V1: |
| 452 | 458 | case MSMP4_V2: |
| 453 | 459 | ms->rl_chroma_table_index = 2; |
| @@ -456,102 +462,102 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) · 2 unmodified lines | ||
| 456 | 462 | ms->dc_table_index = 0; //not used |
| 457 | 463 | break; |
| 458 | 464 | case MSMP4_V3: |
| 459 | − ms->rl_chroma_table_index = decode012(&s->gb); | |
| 460 | − ms->rl_table_index = decode012(&s->gb); | |
| 465 | + ms->rl_chroma_table_index = decode012(&h->c.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 | 469 | break; |
| 464 | 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 | 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 | 475 | else |
| 470 | 476 | ms->per_mb_rl_table = 0; |
| 471 | 477 | |
| 472 | 478 | if (!ms->per_mb_rl_table) { |
| 473 | − ms->rl_chroma_table_index = decode012(&s->gb); | |
| 474 | − ms->rl_table_index = decode012(&s->gb); | |
| 479 | + ms->rl_chroma_table_index = decode012(&h->c.gb); | |
| 480 | + ms->rl_table_index = decode012(&h->c.gb); | |
| 475 | 481 | } |
| 476 | 482 | |
| 477 | − ms->dc_table_index = get_bits1(&s->gb); | |
| 478 | − s->inter_intra_pred= 0; | |
| 483 | + ms->dc_table_index = get_bits1(&h->c.gb); | |
| 484 | + h->c.inter_intra_pred= 0; | |
| 479 | 485 | break; |
| 480 | 486 | default: |
| 481 | 487 | av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1"); |
| 482 | 488 | } |
| 483 | − s->no_rounding = 1; | |
| 484 | − if(s->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", | |
| 486 | − s->qscale, | |
| 489 | + h->c.no_rounding = 1; | |
| 490 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) | |
| 491 | + av_log(h->c.avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n", | |
| 492 | + h->c.qscale, | |
| 487 | 493 | ms->rl_chroma_table_index, |
| 488 | 494 | ms->rl_table_index, |
| 489 | 495 | ms->dc_table_index, |
| 490 | 496 | ms->per_mb_rl_table, |
| 491 | − s->slice_height); | |
| 497 | + h->c.slice_height); | |
| 492 | 498 | } else { |
| 493 | − switch(s->msmpeg4_version){ | |
| 499 | + switch (h->c.msmpeg4_version) { | |
| 494 | 500 | case MSMP4_V1: |
| 495 | 501 | case MSMP4_V2: |
| 496 | − if (s->msmpeg4_version == MSMP4_V1) | |
| 502 | + if (h->c.msmpeg4_version == MSMP4_V1) | |
| 497 | 503 | ms->use_skip_mb_code = 1; |
| 498 | 504 | else |
| 499 | − ms->use_skip_mb_code = get_bits1(&s->gb); | |
| 505 | + ms->use_skip_mb_code = get_bits1(&h->c.gb); | |
| 500 | 506 | ms->rl_table_index = 2; |
| 501 | 507 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 502 | 508 | ms->dc_table_index = 0; //not used |
| 503 | 509 | ms->mv_table_index = 0; |
| 504 | 510 | break; |
| 505 | 511 | case MSMP4_V3: |
| 506 | − ms->use_skip_mb_code = get_bits1(&s->gb); | |
| 507 | − ms->rl_table_index = decode012(&s->gb); | |
| 512 | + ms->use_skip_mb_code = get_bits1(&h->c.gb); | |
| 513 | + ms->rl_table_index = decode012(&h->c.gb); | |
| 508 | 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 | 519 | break; |
| 514 | 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 | 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 | 525 | else |
| 520 | 526 | ms->per_mb_rl_table = 0; |
| 521 | 527 | |
| 522 | 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 | 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); | |
| 530 | − s->inter_intra_pred = s->width*s->height < 320*240 && | |
| 535 | + ms->mv_table_index = get_bits1(&h->c.gb); | |
| 536 | + h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 && | |
| 531 | 537 | ms->bit_rate <= II_BITRATE; |
| 532 | 538 | break; |
| 533 | 539 | default: |
| 534 | 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) | |
| 538 | − av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n", | |
| 543 | + if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) | |
| 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 | 545 | ms->use_skip_mb_code, |
| 540 | 546 | ms->rl_table_index, |
| 541 | 547 | ms->rl_chroma_table_index, |
| 542 | 548 | ms->dc_table_index, |
| 543 | 549 | ms->mv_table_index, |
| 544 | 550 | ms->per_mb_rl_table, |
| 545 | − s->qscale); | |
| 551 | + h->c.qscale); | |
| 546 | 552 | |
| 547 | 553 | if (ms->flipflop_rounding) { |
| 548 | − s->no_rounding ^= 1; | |
| 554 | + h->c.no_rounding ^= 1; | |
| 549 | 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, | |
| 554 | − s->inter_intra_pred, s->width, s->height); | |
| 559 | + ff_dlog(h->c.avctx, "%d %d %d %d %d\n", h->c.pict_type, ms->bit_rate, | |
| 560 | + h->c.inter_intra_pred, h->c.width, h->c.height); | |
| 555 | 561 | |
| 556 | 562 | ms->esc3_level_length = 0; |
| 557 | 563 | ms->esc3_run_length = 0; |
| @@ -559,30 +565,30 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) · 1 unmodified line | ||
| 559 | 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); | |
| 565 | − int left= buf_size*8 - get_bits_count(&s->gb); | |
| 566 | − int length = s->msmpeg4_version >= MSMP4_V3 ? 17 : 16; | |
| 570 | + MSMP4DecContext *const ms = mpv_to_msmpeg4(h); | |
| 571 | + int left= buf_size*8 - get_bits_count(&h->c.gb); | |
| 572 | + int length = h->c.msmpeg4_version >= MSMP4_V3 ? 17 : 16; | |
| 567 | 573 | /* the alt_bitstream reader could read over the end so we need to check it */ |
| 568 | 574 | if(left>=length && left<length+8) |
| 569 | 575 | { |
| 570 | − skip_bits(&s->gb, 5); /* fps */ | |
| 571 | − ms->bit_rate = get_bits(&s->gb, 11) * 1024; | |
| 572 | − if (s->msmpeg4_version >= MSMP4_V3) | |
| 573 | − ms->flipflop_rounding = get_bits1(&s->gb); | |
| 576 | + skip_bits(&h->c.gb, 5); /* fps */ | |
| 577 | + ms->bit_rate = get_bits(&h->c.gb, 11) * 1024; | |
| 578 | + if (h->c.msmpeg4_version >= MSMP4_V3) | |
| 579 | + ms->flipflop_rounding = get_bits1(&h->c.gb); | |
| 574 | 580 | else |
| 575 | 581 | ms->flipflop_rounding = 0; |
| 576 | 582 | } |
| 577 | 583 | else if(left<length+8) |
| 578 | 584 | { |
| 579 | 585 | ms->flipflop_rounding = 0; |
| 580 | − if (s->msmpeg4_version != MSMP4_V2) | |
| 581 | − av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left); | |
| 586 | + if (h->c.msmpeg4_version != MSMP4_V2) | |
| 587 | + av_log(h->c.avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left); | |
| 582 | 588 | } |
| 583 | 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 | 594 | return 0; |
| @@ -590,52 +596,52 @@ int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) · 1 unmodified line | ||
| 590 | 596 | |
| 591 | 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 | 600 | int level, pred; |
| 595 | 601 | |
| 596 | − if (s->msmpeg4_version <= MSMP4_V2) { | |
| 602 | + if (h->c.msmpeg4_version <= MSMP4_V2) { | |
| 597 | 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 | 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 | 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 | 610 | *dir_ptr = 0; |
| 605 | 611 | return -1; |
| 606 | 612 | } |
| 607 | 613 | level-=256; |
| 608 | 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 | 616 | MSMP4_DC_VLC_BITS, 3); |
| 611 | 617 | |
| 612 | 618 | if (level == DC_MAX) { |
| 613 | − level = get_bits(&s->gb, 8); | |
| 614 | − if (get_bits1(&s->gb)) | |
| 619 | + level = get_bits(&h->c.gb, 8); | |
| 620 | + if (get_bits1(&h->c.gb)) | |
| 615 | 621 | level = -level; |
| 616 | 622 | } else if (level != 0) { |
| 617 | − if (get_bits1(&s->gb)) | |
| 623 | + if (get_bits1(&h->c.gb)) | |
| 618 | 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 | 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 | 631 | level += pred; |
| 626 | 632 | |
| 627 | 633 | /* update predictor */ |
| 628 | 634 | *dc_val= level; |
| 629 | 635 | }else{ |
| 630 | 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 | 638 | level += pred; |
| 633 | 639 | |
| 634 | 640 | /* update predictor */ |
| 635 | 641 | if (n < 4) { |
| 636 | − *dc_val = level * s->y_dc_scale; | |
| 642 | + *dc_val = level * h->c.y_dc_scale; | |
| 637 | 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 | 651 | int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, |
| 646 | 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 | 655 | int level, i, last, run, run_diff; |
| 650 | 656 | int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized |
| 651 | 657 | const RLTable *rl; |
| 652 | 658 | const RL_VLC_ELEM *rl_vlc; |
| 653 | 659 | int qmul, qadd; |
| 654 | 660 | |
| 655 | − if (s->mb_intra) { | |
| 661 | + if (h->c.mb_intra) { | |
| 656 | 662 | qmul=1; |
| 657 | 663 | qadd=0; |
| 658 | 664 | |
| @@ -660,110 +666,113 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 1 unmodified line | ||
| 660 | 666 | level = msmpeg4_decode_dc(ms, n, &dc_pred_dir); |
| 661 | 667 | |
| 662 | 668 | if (level < 0){ |
| 663 | − av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale); | |
| 664 | − if(s->inter_intra_pred) level=0; | |
| 669 | + av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, h->c.qscale); | |
| 670 | + if (h->c.inter_intra_pred) | |
| 671 | + level = 0; | |
| 665 | 672 | } |
| 666 | 673 | if (n < 4) { |
| 667 | 674 | rl = &ff_rl_table[ms->rl_table_index]; |
| 668 | − if(level > 256*s->y_dc_scale){ | |
| 669 | − av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale); | |
| 670 | − if(!s->inter_intra_pred) return -1; | |
| 675 | + if (level > 256 * h->c.y_dc_scale) { | |
| 676 | + av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", h->c.qscale); | |
| 677 | + if (!h->c.inter_intra_pred) | |
| 678 | + return -1; | |
| 671 | 679 | } |
| 672 | 680 | } else { |
| 673 | 681 | rl = &ff_rl_table[3 + ms->rl_chroma_table_index]; |
| 674 | − if(level > 256*s->c_dc_scale){ | |
| 675 | − av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale); | |
| 676 | − if(!s->inter_intra_pred) return -1; | |
| 682 | + if (level > 256 * h->c.c_dc_scale) { | |
| 683 | + av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", h->c.qscale); | |
| 684 | + if (!h->c.inter_intra_pred) | |
| 685 | + return -1; | |
| 677 | 686 | } |
| 678 | 687 | } |
| 679 | 688 | block[0] = level; |
| 680 | 689 | |
| 681 | − run_diff = s->msmpeg4_version >= MSMP4_WMV1; | |
| 690 | + run_diff = h->c.msmpeg4_version >= MSMP4_WMV1; | |
| 682 | 691 | i = 0; |
| 683 | 692 | if (!coded) { |
| 684 | 693 | goto not_coded; |
| 685 | 694 | } |
| 686 | − if (s->ac_pred) { | |
| 695 | + if (h->c.ac_pred) { | |
| 687 | 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 | 698 | else |
| 690 | − scan_table = s->permutated_intra_h_scantable; /* top */ | |
| 699 | + scan_table = h->c.permutated_intra_h_scantable; /* top */ | |
| 691 | 700 | } else { |
| 692 | − scan_table = s->intra_scantable.permutated; | |
| 701 | + scan_table = h->c.intra_scantable.permutated; | |
| 693 | 702 | } |
| 694 | 703 | rl_vlc= rl->rl_vlc[0]; |
| 695 | 704 | } else { |
| 696 | − qmul = s->qscale << 1; | |
| 697 | − qadd = (s->qscale - 1) | 1; | |
| 705 | + qmul = h->c.qscale << 1; | |
| 706 | + qadd = (h->c.qscale - 1) | 1; | |
| 698 | 707 | i = -1; |
| 699 | 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 | 711 | run_diff = 0; |
| 703 | 712 | else |
| 704 | 713 | run_diff = 1; |
| 705 | 714 | |
| 706 | 715 | if (!coded) { |
| 707 | − s->block_last_index[n] = i; | |
| 716 | + h->c.block_last_index[n] = i; | |
| 708 | 717 | return 0; |
| 709 | 718 | } |
| 710 | 719 | if(!scan_table) |
| 711 | − scan_table = s->inter_scantable.permutated; | |
| 712 | − rl_vlc= rl->rl_vlc[s->qscale]; | |
| 720 | + scan_table = h->c.inter_scantable.permutated; | |
| 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 | 725 | for(;;) { |
| 717 | − UPDATE_CACHE(re, &s->gb); | |
| 718 | − GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); | |
| 726 | + UPDATE_CACHE(re, &h->c.gb); | |
| 727 | + GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0); | |
| 719 | 728 | if (level==0) { |
| 720 | 729 | int cache; |
| 721 | − cache= GET_CACHE(re, &s->gb); | |
| 730 | + cache= GET_CACHE(re, &h->c.gb); | |
| 722 | 731 | /* escape */ |
| 723 | − if (s->msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) { | |
| 724 | − if (s->msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) { | |
| 732 | + if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) { | |
| 733 | + if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) { | |
| 725 | 734 | /* third escape */ |
| 726 | − if (s->msmpeg4_version != MSMP4_V1) | |
| 727 | − LAST_SKIP_BITS(re, &s->gb, 2); | |
| 728 | − UPDATE_CACHE(re, &s->gb); | |
| 729 | − if (s->msmpeg4_version <= MSMP4_V3) { | |
| 730 | − last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); | |
| 731 | − run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); | |
| 732 | − level= SHOW_SBITS(re, &s->gb, 8); | |
| 733 | − SKIP_COUNTER(re, &s->gb, 1+6+8); | |
| 735 | + if (h->c.msmpeg4_version != MSMP4_V1) | |
| 736 | + LAST_SKIP_BITS(re, &h->c.gb, 2); | |
| 737 | + UPDATE_CACHE(re, &h->c.gb); | |
| 738 | + if (h->c.msmpeg4_version <= MSMP4_V3) { | |
| 739 | + last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_CACHE(re, &h->c.gb, 1); | |
| 740 | + run = SHOW_UBITS(re, &h->c.gb, 6); SKIP_CACHE(re, &h->c.gb, 6); | |
| 741 | + level = SHOW_SBITS(re, &h->c.gb, 8); | |
| 742 | + SKIP_COUNTER(re, &h->c.gb, 1 + 6 + 8); | |
| 734 | 743 | }else{ |
| 735 | 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 | 746 | if (!ms->esc3_level_length) { |
| 738 | 747 | int ll; |
| 739 | − ff_dlog(s->avctx, "ESC-3 %X at %d %d\n", | |
| 740 | − show_bits(&s->gb, 24), s->mb_x, s->mb_y); | |
| 741 | − if(s->qscale<8){ | |
| 742 | − ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3); | |
| 748 | + ff_dlog(h->c.avctx, "ESC-3 %X at %d %d\n", | |
| 749 | + show_bits(&h->c.gb, 24), h->c.mb_x, h->c.mb_y); | |
| 750 | + if (h->c.qscale < 8) { | |
| 751 | + ll = SHOW_UBITS(re, &h->c.gb, 3); SKIP_BITS(re, &h->c.gb, 3); | |
| 743 | 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 | 755 | }else{ |
| 747 | 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 | 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 | 764 | ms->esc3_level_length = ll; |
| 756 | − ms->esc3_run_length = SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2); | |
| 757 | − UPDATE_CACHE(re, &s->gb); | |
| 765 | + ms->esc3_run_length = SHOW_UBITS(re, &h->c.gb, 2) + 3; SKIP_BITS(re, &h->c.gb, 2); | |
| 766 | + UPDATE_CACHE(re, &h->c.gb); | |
| 758 | 767 | } |
| 759 | − run = SHOW_UBITS(re, &s->gb, ms->esc3_run_length); | |
| 760 | − SKIP_BITS(re, &s->gb, ms->esc3_run_length); | |
| 768 | + run = SHOW_UBITS(re, &h->c.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); | |
| 763 | − SKIP_BITS(re, &s->gb, 1); | |
| 771 | + sign= SHOW_UBITS(re, &h->c.gb, 1); | |
| 772 | + SKIP_BITS(re, &h->c.gb, 1); | |
| 764 | 773 | |
| 765 | − level = SHOW_UBITS(re, &s->gb, ms->esc3_level_length); | |
| 766 | − SKIP_BITS(re, &s->gb, ms->esc3_level_length); | |
| 774 | + level = SHOW_UBITS(re, &h->c.gb, ms->esc3_level_length); | |
| 775 | + SKIP_BITS(re, &h->c.gb, ms->esc3_level_length); | |
| 767 | 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 | 783 | if(last) i+=192; |
| 775 | 784 | } else { |
| 776 | 785 | /* second escape */ |
| 777 | − SKIP_BITS(re, &s->gb, 2); | |
| 778 | − GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 786 | + SKIP_BITS(re, &h->c.gb, 2); | |
| 787 | + GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 779 | 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); | |
| 781 | − LAST_SKIP_BITS(re, &s->gb, 1); | |
| 789 | + level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); | |
| 790 | + LAST_SKIP_BITS(re, &h->c.gb, 1); | |
| 782 | 791 | } |
| 783 | 792 | } else { |
| 784 | 793 | /* first escape */ |
| 785 | − SKIP_BITS(re, &s->gb, 1); | |
| 786 | − GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 794 | + SKIP_BITS(re, &h->c.gb, 1); | |
| 795 | + GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1); | |
| 787 | 796 | i+= run; |
| 788 | 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); | |
| 790 | − LAST_SKIP_BITS(re, &s->gb, 1); | |
| 798 | + level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); | |
| 799 | + LAST_SKIP_BITS(re, &h->c.gb, 1); | |
| 791 | 800 | } |
| 792 | 801 | } else { |
| 793 | 802 | i+= run; |
| 794 | − level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
| 795 | − LAST_SKIP_BITS(re, &s->gb, 1); | |
| 803 | + level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1); | |
| 804 | + LAST_SKIP_BITS(re, &h->c.gb, 1); | |
| 796 | 805 | } |
| 797 | 806 | if (i > 62){ |
| 798 | 807 | i-= 192; |
| 799 | 808 | if(i&(~63)){ |
| 800 | − const int left= get_bits_left(&s->gb); | |
| 809 | + const int left = get_bits_left(&h->c.gb); | |
| 801 | 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 | 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 | 815 | i = 63; |
| 806 | 816 | break; |
| 807 | 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 | 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 | 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 | 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 | 838 | return 0; |
| 828 | 839 | } |
| @@ -830,17 +841,17 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 1 unmodified line | ||
| 830 | 841 | void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr) |
| 831 | 842 | { |
| 832 | 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 | 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 | 848 | if (sym) { |
| 838 | 849 | mx = sym >> 8; |
| 839 | 850 | my = sym & 0xFF; |
| 840 | 851 | } else { |
| 841 | 852 | /* Escape */ |
| 842 | − mx = get_bits(&s->gb, 6); | |
| 843 | − my = get_bits(&s->gb, 6); | |
| 853 | + mx = get_bits(&h->c.gb, 6); | |
| 854 | + my = get_bits(&h->c.gb, 6); | |
| 844 | 855 | } |
| 845 | 856 | |
| 846 | 857 | mx += *mx_ptr - 32; |
| @@ -23,13 +23,14 @@ · 22 unmodified lines | ||
| 23 | 23 | #define AVCODEC_MSMPEG4DEC_H |
| 24 | 24 | |
| 25 | 25 | #include "avcodec.h" |
| 26 | +#include "h263dec.h" | |
| 26 | 27 | #include "mpegvideo.h" |
| 27 | 28 | |
| 28 | 29 | #define INTER_INTRA_VLC_BITS 3 |
| 29 | 30 | #define MB_NON_INTRA_VLC_BITS 9 |
| 30 | 31 | |
| 31 | 32 | typedef struct MSMP4DecContext { |
| 32 | − MpegEncContext m; | |
| 33 | + H263DecContext h; | |
| 33 | 34 | int bit_rate; |
| 34 | 35 | int flipflop_rounding; |
| 35 | 36 | int mv_table_index; |
| @@ -42,18 +43,18 @@ typedef struct MSMP4DecContext { · 6 unmodified lines | ||
| 42 | 43 | int esc3_run_length; |
| 43 | 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 | 48 | // Only legal because no MSMPEG-4 decoder uses slice-threading. |
| 48 | − return (MSMP4DecContext*)s; | |
| 49 | + return (MSMP4DecContext*)h; | |
| 49 | 50 | } |
| 50 | 51 | |
| 51 | 52 | extern const VLCElem *ff_mb_non_intra_vlc[4]; |
| 52 | 53 | extern VLCElem ff_inter_intra_vlc[8]; |
| 53 | 54 | |
| 54 | 55 | int ff_msmpeg4_decode_init(AVCodecContext *avctx); |
| 55 | −int ff_msmpeg4_decode_picture_header(MpegEncContext *s); | |
| 56 | −int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size); | |
| 56 | +int ff_msmpeg4_decode_picture_header(H263DecContext *const h); | |
| 57 | +int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size); | |
| 57 | 58 | void ff_msmpeg4_decode_motion(MSMP4DecContext *ms, int *mx_ptr, int *my_ptr); |
| 58 | 59 | int ff_msmpeg4_decode_block(MSMP4DecContext *ms, int16_t * block, |
| 59 | 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 | 33 | const uint8_t *buffer, uint32_t size) |
| 34 | 34 | { |
| 35 | 35 | Mpeg4DecContext *m = avctx->priv_data; |
| 36 | − MpegEncContext *s = &m->m; | |
| 36 | + MPVContext *const s = &m->h.c; | |
| 37 | 37 | |
| 38 | 38 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; |
| 39 | 39 | CUVIDPICPARAMS *pp = &ctx->pic_params; |
| @@ -52,7 +52,7 @@ · 51 unmodified lines | ||
| 52 | 52 | #define DC_VLC_BITS 9 |
| 53 | 53 | |
| 54 | 54 | typedef struct RVDecContext { |
| 55 | − MpegEncContext m; | |
| 55 | + H263DecContext h; | |
| 56 | 56 | int sub_id; |
| 57 | 57 | int orig_width, orig_height; |
| 58 | 58 | } RVDecContext; |
| @@ -80,16 +80,16 @@ static const uint16_t rv_chrom_len_count[15] = { · 21 unmodified lines | ||
| 80 | 80 | |
| 81 | 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 | 85 | int code; |
| 86 | 86 | |
| 87 | 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 | 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 | 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 | 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 | 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 | 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)) | |
| 107 | − s->pict_type = AV_PICTURE_TYPE_P; | |
| 106 | + if (get_bits1(&h->c.gb)) | |
| 107 | + h->c.pict_type = AV_PICTURE_TYPE_P; | |
| 108 | 108 | else |
| 109 | − s->pict_type = AV_PICTURE_TYPE_I; | |
| 109 | + h->c.pict_type = AV_PICTURE_TYPE_I; | |
| 110 | 110 | |
| 111 | 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 | 118 | if (pb_frame) { |
| 119 | − avpriv_request_sample(s->avctx, "PB-frame"); | |
| 119 | + avpriv_request_sample(h->c.avctx, "PB-frame"); | |
| 120 | 120 | return AVERROR_PATCHWELCOME; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | − s->qscale = get_bits(&s->gb, 5); | |
| 124 | − if (s->qscale == 0) { | |
| 125 | − av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); | |
| 123 | + h->c.qscale = get_bits(&h->c.gb, 5); | |
| 124 | + if (h->c.qscale == 0) { | |
| 125 | + av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); | |
| 126 | 126 | return AVERROR_INVALIDDATA; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | − if (s->pict_type == AV_PICTURE_TYPE_I) { | |
| 130 | − if (s->rv10_version == 3) { | |
| 129 | + if (h->c.pict_type == AV_PICTURE_TYPE_I) { | |
| 130 | + if (h->c.rv10_version == 3) { | |
| 131 | 131 | /* specific MPEG like DC coding not used */ |
| 132 | − s->last_dc[0] = get_bits(&s->gb, 8); | |
| 133 | − s->last_dc[1] = get_bits(&s->gb, 8); | |
| 134 | − s->last_dc[2] = get_bits(&s->gb, 8); | |
| 135 | − ff_dlog(s->avctx, "DC:%d %d %d\n", s->last_dc[0], | |
| 136 | − s->last_dc[1], s->last_dc[2]); | |
| 132 | + h->c.last_dc[0] = get_bits(&h->c.gb, 8); | |
| 133 | + h->c.last_dc[1] = get_bits(&h->c.gb, 8); | |
| 134 | + h->c.last_dc[2] = get_bits(&h->c.gb, 8); | |
| 135 | + ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0], | |
| 136 | + h->c.last_dc[1], h->c.last_dc[2]); | |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | /* if multiple packets per frame are sent, the position at which |
| 140 | 140 | * to display the macroblocks is coded here */ |
| 141 | 141 | |
| 142 | − mb_xy = s->mb_x + s->mb_y * s->mb_width; | |
| 143 | − if (show_bits(&s->gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) { | |
| 144 | − s->mb_x = get_bits(&s->gb, 6); /* mb_x */ | |
| 145 | − s->mb_y = get_bits(&s->gb, 6); /* mb_y */ | |
| 146 | − mb_count = get_bits(&s->gb, 12); | |
| 142 | + mb_xy = h->c.mb_x + h->c.mb_y * h->c.mb_width; | |
| 143 | + if (show_bits(&h->c.gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) { | |
| 144 | + h->c.mb_x = get_bits(&h->c.gb, 6); /* mb_x */ | |
| 145 | + h->c.mb_y = get_bits(&h->c.gb, 6); /* mb_y */ | |
| 146 | + mb_count = get_bits(&h->c.gb, 12); | |
| 147 | 147 | } else { |
| 148 | − s->mb_x = 0; | |
| 149 | − s->mb_y = 0; | |
| 150 | − mb_count = s->mb_width * s->mb_height; | |
| 148 | + h->c.mb_x = 0; | |
| 149 | + h->c.mb_y = 0; | |
| 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 | 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 | 159 | static const enum AVPictureType pict_types[] = |
| 160 | 160 | { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */, |
| 161 | 161 | AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B }; |
| 162 | − MpegEncContext *s = &rv->m; | |
| 162 | + H263DecContext *const h = &rv->h; | |
| 163 | 163 | int seq, mb_pos, ret; |
| 164 | 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) { | |
| 169 | − av_log(s->avctx, AV_LOG_ERROR, "low delay B\n"); | |
| 168 | + if (h->c.low_delay && h->c.pict_type == AV_PICTURE_TYPE_B) { | |
| 169 | + av_log(h->c.avctx, AV_LOG_ERROR, "low delay B\n"); | |
| 170 | 170 | return -1; |
| 171 | 171 | } |
| 172 | − if (!s->last_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) { | |
| 173 | − av_log(s->avctx, AV_LOG_ERROR, "early B-frame\n"); | |
| 172 | + if (!h->c.last_pic.ptr && h->c.pict_type == AV_PICTURE_TYPE_B) { | |
| 173 | + av_log(h->c.avctx, AV_LOG_ERROR, "early B-frame\n"); | |
| 174 | 174 | return AVERROR_INVALIDDATA; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | − if (get_bits1(&s->gb)) { | |
| 178 | − av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n"); | |
| 177 | + if (get_bits1(&h->c.gb)) { | |
| 178 | + av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n"); | |
| 179 | 179 | return AVERROR_INVALIDDATA; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | − s->qscale = get_bits(&s->gb, 5); | |
| 183 | − if (s->qscale == 0) { | |
| 184 | − av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); | |
| 182 | + h->c.qscale = get_bits(&h->c.gb, 5); | |
| 183 | + if (h->c.qscale == 0) { | |
| 184 | + av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n"); | |
| 185 | 185 | return AVERROR_INVALIDDATA; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 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 | 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 | 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 | 197 | if (rpr_max) { |
| 198 | 198 | int f, new_w, new_h; |
| 199 | 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 | 203 | if (f) { |
| 204 | − if (s->avctx->extradata_size < 8 + 2 * f) { | |
| 205 | − av_log(s->avctx, AV_LOG_ERROR, "Extradata too small.\n"); | |
| 204 | + if (h->c.avctx->extradata_size < 8 + 2 * f) { | |
| 205 | + av_log(h->c.avctx, AV_LOG_ERROR, "Extradata too small.\n"); | |
| 206 | 206 | return AVERROR_INVALIDDATA; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | − new_w = 4 * s->avctx->extradata[6 + 2 * f]; | |
| 210 | − new_h = 4 * s->avctx->extradata[7 + 2 * f]; | |
| 209 | + new_w = 4 * h->c.avctx->extradata[6 + 2 * f]; | |
| 210 | + new_h = 4 * h->c.avctx->extradata[7 + 2 * f]; | |
| 211 | 211 | } else { |
| 212 | 212 | new_w = rv->orig_width; |
| 213 | 213 | new_h = rv->orig_height; |
| 214 | 214 | } |
| 215 | − if (new_w != s->width || new_h != s->height || !s->context_initialized) { | |
| 216 | − AVRational old_aspect = s->avctx->sample_aspect_ratio; | |
| 217 | − av_log(s->avctx, AV_LOG_DEBUG, | |
| 215 | + if (new_w != h->c.width || new_h != h->c.height || !h->c.context_initialized) { | |
| 216 | + AVRational old_aspect = h->c.avctx->sample_aspect_ratio; | |
| 217 | + av_log(h->c.avctx, AV_LOG_DEBUG, | |
| 218 | 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 | 220 | return AVERROR_INVALIDDATA; |
| 221 | 221 | |
| 222 | 222 | if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8) |
| 223 | 223 | return AVERROR_INVALIDDATA; |
| 224 | 224 | |
| 225 | − ff_mpv_common_end(s); | |
| 225 | + ff_mpv_common_end(&h->c); | |
| 226 | 226 | |
| 227 | 227 | // attempt to keep aspect during typical resolution switches |
| 228 | 228 | if (!old_aspect.num) |
| 229 | 229 | old_aspect = (AVRational){1, 1}; |
| 230 | − if (2 * (int64_t)new_w * s->height == (int64_t)new_h * s->width) | |
| 231 | − s->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) | |
| 233 | − s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2}); | |
| 230 | + if (2 * (int64_t)new_w * h->c.height == (int64_t)new_h * h->c.width) | |
| 231 | + h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1}); | |
| 232 | + if ((int64_t)new_w * h->c.height == 2 * (int64_t)new_h * h->c.width) | |
| 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 | 236 | if (ret < 0) |
| 237 | 237 | return ret; |
| 238 | 238 | |
| 239 | − s->width = new_w; | |
| 240 | − s->height = new_h; | |
| 241 | − if ((ret = ff_mpv_common_init(s)) < 0) | |
| 239 | + h->c.width = new_w; | |
| 240 | + h->c.height = new_h; | |
| 241 | + if ((ret = ff_mpv_common_init(&h->c)) < 0) | |
| 242 | 242 | return ret; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | − if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 246 | − av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max); | |
| 245 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 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 | 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; | |
| 255 | − if (seq - s->time > 0x4000) | |
| 254 | + seq |= h->c.time & ~0x7FFF; | |
| 255 | + if (seq - h->c.time > 0x4000) | |
| 256 | 256 | seq -= 0x8000; |
| 257 | − if (seq - s->time < -0x4000) | |
| 257 | + if (seq - h->c.time < -0x4000) | |
| 258 | 258 | seq += 0x8000; |
| 259 | 259 | |
| 260 | − if (seq != s->time) { | |
| 261 | − if (s->pict_type != AV_PICTURE_TYPE_B) { | |
| 262 | − s->time = seq; | |
| 263 | − s->pp_time = s->time - s->last_non_b_time; | |
| 264 | − s->last_non_b_time = s->time; | |
| 260 | + if (seq != h->c.time) { | |
| 261 | + if (h->c.pict_type != AV_PICTURE_TYPE_B) { | |
| 262 | + h->c.time = seq; | |
| 263 | + h->c.pp_time = h->c.time - h->c.last_non_b_time; | |
| 264 | + h->c.last_non_b_time = h->c.time; | |
| 265 | 265 | } else { |
| 266 | − s->time = seq; | |
| 267 | − s->pb_time = s->pp_time - (s->last_non_b_time - s->time); | |
| 266 | + h->c.time = seq; | |
| 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) { | |
| 271 | − if (s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0) { | |
| 272 | − av_log(s->avctx, AV_LOG_DEBUG, | |
| 270 | + if (h->c.pict_type == AV_PICTURE_TYPE_B) { | |
| 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(h->c.avctx, AV_LOG_DEBUG, | |
| 273 | 273 | "messed up order, possible from seeking? skipping current B-frame\n"); |
| 274 | 274 | #define ERROR_SKIP_FRAME -123 |
| 275 | 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 | 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; | |
| 287 | − if (s->h263_aic) { | |
| 288 | − s->y_dc_scale_table = | |
| 289 | − s->c_dc_scale_table = ff_aic_dc_scale_table; | |
| 286 | + h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I; | |
| 287 | + if (h->c.h263_aic) { | |
| 288 | + h->c.y_dc_scale_table = | |
| 289 | + h->c.c_dc_scale_table = ff_aic_dc_scale_table; | |
| 290 | 290 | } else { |
| 291 | − s->y_dc_scale_table = | |
| 292 | − s->c_dc_scale_table = ff_mpeg1_dc_scale_table; | |
| 291 | + h->c.y_dc_scale_table = | |
| 292 | + h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table; | |
| 293 | 293 | } |
| 294 | − if (!s->avctx->lowres) | |
| 295 | − s->loop_filter = 1; | |
| 294 | + if (!h->c.avctx->lowres) | |
| 295 | + h->c.loop_filter = 1; | |
| 296 | 296 | |
| 297 | − if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 298 | − av_log(s->avctx, AV_LOG_INFO, | |
| 297 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 298 | + av_log(h->c.avctx, AV_LOG_INFO, | |
| 299 | 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, | |
| 301 | − s->no_rounding); | |
| 300 | + seq, h->c.mb_x, h->c.mb_y, h->c.pict_type, h->c.qscale, | |
| 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 | 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 | 352 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 353 | 353 | RVDecContext *rv = avctx->priv_data; |
| 354 | − MpegEncContext *s = &rv->m; | |
| 354 | + H263DecContext *const h = &rv->h; | |
| 355 | 355 | int major_ver, minor_ver, micro_ver, ret; |
| 356 | 356 | |
| 357 | 357 | if (avctx->extradata_size < 8) { |
| @@ -369,11 +369,11 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) · 11 unmodified lines | ||
| 369 | 369 | rv->orig_width = avctx->coded_width; |
| 370 | 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 | 373 | rv->sub_id = AV_RB32A(avctx->extradata + 4); |
| 374 | 374 | if (avctx->codec_id == AV_CODEC_ID_RV20) { |
| 375 | − s->modified_quant = 1; | |
| 376 | − s->chroma_qscale_table = ff_h263_chroma_qscale_table; | |
| 375 | + h->c.modified_quant = 1; | |
| 376 | + h->c.chroma_qscale_table = ff_h263_chroma_qscale_table; | |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 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 | 383 | switch (major_ver) { |
| 384 | 384 | case 1: |
| 385 | − s->rv10_version = micro_ver ? 3 : 1; | |
| 386 | − s->obmc = micro_ver == 2; | |
| 385 | + h->c.rv10_version = micro_ver ? 3 : 1; | |
| 386 | + h->c.obmc = micro_ver == 2; | |
| 387 | 387 | break; |
| 388 | 388 | case 2: |
| 389 | 389 | if (minor_ver >= 2) { |
| 390 | − s->low_delay = 0; | |
| 390 | + h->c.low_delay = 0; | |
| 391 | 391 | avctx->has_b_frames = 1; |
| 392 | 392 | } |
| 393 | 393 | break; |
| @@ -412,126 +412,126 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 18 unmodified lines | ||
| 412 | 412 | int buf_size, int buf_size2, int whole_size) |
| 413 | 413 | { |
| 414 | 414 | RVDecContext *rv = avctx->priv_data; |
| 415 | − MpegEncContext *s = &rv->m; | |
| 415 | + H263DecContext *const h = &rv->h; | |
| 416 | 416 | int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret; |
| 417 | 417 | |
| 418 | 418 | active_bits_size = buf_size * 8; |
| 419 | − init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8); | |
| 420 | − if (s->codec_id == AV_CODEC_ID_RV10) | |
| 421 | − mb_count = rv10_decode_picture_header(s); | |
| 419 | + init_get_bits(&h->c.gb, buf, FFMAX(buf_size, buf_size2) * 8); | |
| 420 | + if (h->c.codec_id == AV_CODEC_ID_RV10) | |
| 421 | + mb_count = rv10_decode_picture_header(h); | |
| 422 | 422 | else |
| 423 | 423 | mb_count = rv20_decode_picture_header(rv, whole_size); |
| 424 | 424 | if (mb_count < 0) { |
| 425 | 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 | 427 | return AVERROR_INVALIDDATA; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | − if (s->mb_x >= s->mb_width || | |
| 431 | − s->mb_y >= s->mb_height) { | |
| 432 | − av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y); | |
| 430 | + if (h->c.mb_x >= h->c.mb_width || | |
| 431 | + h->c.mb_y >= h->c.mb_height) { | |
| 432 | + av_log(h->c.avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", h->c.mb_x, h->c.mb_y); | |
| 433 | 433 | return AVERROR_INVALIDDATA; |
| 434 | 434 | } |
| 435 | − mb_pos = s->mb_y * s->mb_width + s->mb_x; | |
| 436 | − left = s->mb_width * s->mb_height - mb_pos; | |
| 435 | + mb_pos = h->c.mb_y * h->c.mb_width + h->c.mb_x; | |
| 436 | + left = h->c.mb_width * h->c.mb_height - mb_pos; | |
| 437 | 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 | 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 | 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 | 446 | // FIXME write parser so we always have complete frames? |
| 447 | − if (s->cur_pic.ptr) { | |
| 448 | − ff_er_frame_end(&s->er, NULL); | |
| 449 | − ff_mpv_frame_end(s); | |
| 450 | − s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0; | |
| 447 | + if (h->c.cur_pic.ptr) { | |
| 448 | + ff_er_frame_end(&h->c.er, NULL); | |
| 449 | + ff_mpv_frame_end(&h->c); | |
| 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 | 453 | return ret; |
| 454 | − ff_mpeg_er_frame_start(s); | |
| 454 | + ff_mpeg_er_frame_start(&h->c); | |
| 455 | 455 | } else { |
| 456 | − if (s->cur_pic.ptr->f->pict_type != s->pict_type) { | |
| 457 | − av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n"); | |
| 456 | + if (h->c.cur_pic.ptr->f->pict_type != h->c.pict_type) { | |
| 457 | + av_log(h->c.avctx, AV_LOG_ERROR, "Slice type mismatch\n"); | |
| 458 | 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 | 465 | /* default quantization values */ |
| 466 | − if (s->codec_id == AV_CODEC_ID_RV10) { | |
| 467 | − if (s->mb_y == 0) | |
| 468 | − s->first_slice_line = 1; | |
| 466 | + if (h->c.codec_id == AV_CODEC_ID_RV10) { | |
| 467 | + if (h->c.mb_y == 0) | |
| 468 | + h->c.first_slice_line = 1; | |
| 469 | 469 | } else { |
| 470 | − s->first_slice_line = 1; | |
| 471 | − s->resync_mb_x = s->mb_x; | |
| 470 | + h->c.first_slice_line = 1; | |
| 471 | + h->c.resync_mb_x = h->c.mb_x; | |
| 472 | 472 | } |
| 473 | − start_mb_x = s->mb_x; | |
| 474 | − s->resync_mb_y = s->mb_y; | |
| 473 | + start_mb_x = h->c.mb_x; | |
| 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; | |
| 479 | − s->rv10_first_dc_coded[1] = 0; | |
| 480 | − s->rv10_first_dc_coded[2] = 0; | |
| 481 | − ff_init_block_index(s); | |
| 478 | + h->c.rv10_first_dc_coded[0] = 0; | |
| 479 | + h->c.rv10_first_dc_coded[1] = 0; | |
| 480 | + h->c.rv10_first_dc_coded[2] = 0; | |
| 481 | + ff_init_block_index(&h->c); | |
| 482 | 482 | |
| 483 | 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 | 485 | int ret; |
| 486 | − ff_update_block_index(s, 8, s->avctx->lowres, 1); | |
| 487 | − ff_tlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y); | |
| 486 | + ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1); | |
| 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; | |
| 490 | − s->mv_type = MV_TYPE_16X16; | |
| 491 | − ret = ff_h263_decode_mb(s, s->block); | |
| 489 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 490 | + h->c.mv_type = MV_TYPE_16X16; | |
| 491 | + ret = ff_h263_decode_mb(h, h->c.block); | |
| 492 | 492 | |
| 493 | 493 | // Repeat the slice end check from ff_h263_decode_mb with our active |
| 494 | 494 | // bitstream size |
| 495 | − if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&s->gb)) { | |
| 496 | − int v = show_bits(&s->gb, 16); | |
| 495 | + if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->c.gb)) { | |
| 496 | + int v = show_bits(&h->c.gb, 16); | |
| 497 | 497 | |
| 498 | − if (get_bits_count(&s->gb) + 16 > active_bits_size) | |
| 499 | − v >>= 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(&h->c.gb) + 16 - active_bits_size; | |
| 500 | 500 | |
| 501 | 501 | if (!v) |
| 502 | 502 | ret = SLICE_END; |
| 503 | 503 | } |
| 504 | − if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) && | |
| 505 | − 8 * buf_size2 >= 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(&h->c.gb)) { | |
| 506 | 506 | active_bits_size = buf_size2 * 8; |
| 507 | 507 | av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", |
| 508 | 508 | 8 * buf_size, active_bits_size); |
| 509 | 509 | ret = SLICE_OK; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | − if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) { | |
| 513 | − av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, | |
| 514 | − s->mb_y); | |
| 512 | + if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->c.gb)) { | |
| 513 | + av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x, | |
| 514 | + h->c.mb_y); | |
| 515 | 515 | return AVERROR_INVALIDDATA; |
| 516 | 516 | } |
| 517 | − if (s->pict_type != AV_PICTURE_TYPE_B) | |
| 518 | − ff_h263_update_motion_val(s); | |
| 519 | − ff_mpv_reconstruct_mb(s, s->block); | |
| 520 | − if (s->loop_filter) | |
| 521 | − ff_h263_loop_filter(s); | |
| 522 | − | |
| 523 | − if (++s->mb_x == s->mb_width) { | |
| 524 | − s->mb_x = 0; | |
| 525 | − s->mb_y++; | |
| 526 | − ff_init_block_index(s); | |
| 517 | + if (h->c.pict_type != AV_PICTURE_TYPE_B) | |
| 518 | + ff_h263_update_motion_val(&h->c); | |
| 519 | + ff_mpv_reconstruct_mb(&h->c, h->c.block); | |
| 520 | + if (h->c.loop_filter) | |
| 521 | + ff_h263_loop_filter(&h->c); | |
| 522 | + | |
| 523 | + if (++h->c.mb_x == h->c.mb_width) { | |
| 524 | + h->c.mb_x = 0; | |
| 525 | + h->c.mb_y++; | |
| 526 | + ff_init_block_index(&h->c); | |
| 527 | 527 | } |
| 528 | − if (s->mb_x == s->resync_mb_x) | |
| 529 | − s->first_slice_line = 0; | |
| 528 | + if (h->c.mb_x == h->c.resync_mb_x) | |
| 529 | + h->c.first_slice_line = 0; | |
| 530 | 530 | if (ret == SLICE_END) |
| 531 | 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 | 535 | ER_MB_END); |
| 536 | 536 | |
| 537 | 537 | return active_bits_size; |
| @@ -21,8 +21,8 @@ · 20 unmodified lines | ||
| 21 | 21 | #ifndef AVCODEC_RV10DEC_H |
| 22 | 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 | 28 | #endif /* AVCODEC_RV10DEC_H */ |
| @@ -51,7 +51,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, · 50 unmodified lines | ||
| 51 | 51 | av_unused uint32_t size) |
| 52 | 52 | { |
| 53 | 53 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 54 | − MpegEncContext *s = &ctx->m; | |
| 54 | + MPVContext *const s = &ctx->h.c; | |
| 55 | 55 | VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private; |
| 56 | 56 | VAPictureParameterBufferMPEG4 pic_param; |
| 57 | 57 | int i, err; |
| @@ -34,7 +34,7 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, · 33 unmodified lines | ||
| 34 | 34 | const uint8_t *buffer, uint32_t size) |
| 35 | 35 | { |
| 36 | 36 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 37 | − MpegEncContext * const s = &ctx->m; | |
| 37 | + MPVContext *const s = &ctx->h.c; | |
| 38 | 38 | MPVPicture *pic = s->cur_pic.ptr; |
| 39 | 39 | struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private; |
| 40 | 40 | VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4; |
| @@ -44,7 +44,7 @@ void ff_mspel_motion(MpegEncContext *s, · 43 unmodified lines | ||
| 44 | 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 | 49 | static const uint8_t map[3][3] = { |
| 50 | 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 | 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 | 58 | #endif /* AVCODEC_WMV2_H */ |
| @@ -59,9 +59,9 @@ typedef struct WMV2DecContext { · 58 unmodified lines | ||
| 59 | 59 | static void wmv2_add_block(WMV2DecContext *w, int16_t *block1, |
| 60 | 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 | 65 | switch (w->abt_type_table[n]) { |
| 66 | 66 | case 0: |
| 67 | 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 | 69 | case 1: |
| 70 | 70 | ff_simple_idct84_add(dst, stride, block1); |
| 71 | 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 | 73 | break; |
| 74 | 74 | case 2: |
| 75 | 75 | ff_simple_idct48_add(dst, stride, block1); |
| 76 | 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 | 78 | break; |
| 79 | 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 | 102 | static int parse_mb_skip(WMV2DecContext *w) |
| 103 | 103 | { |
| 104 | − int mb_x, mb_y; | |
| 104 | + H263DecContext *const h = &w->ms.h; | |
| 105 | 105 | int coded_mb_count = 0; |
| 106 | − MpegEncContext *const s = &w->ms.m; | |
| 107 | − uint32_t *const mb_type = s->cur_pic.mb_type; | |
| 106 | + uint32_t *const mb_type = h->c.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 | 109 | switch (w->skip_type) { |
| 111 | 110 | case SKIP_TYPE_NONE: |
| 112 | − for (mb_y = 0; mb_y < s->mb_height; mb_y++) | |
| 113 | − for (mb_x = 0; mb_x < s->mb_width; mb_x++) | |
| 114 | − mb_type[mb_y * s->mb_stride + mb_x] = | |
| 111 | + for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) | |
| 112 | + for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) | |
| 113 | + mb_type[mb_y * h->c.mb_stride + mb_x] = | |
| 115 | 114 | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 116 | 115 | break; |
| 117 | 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 | 118 | return AVERROR_INVALIDDATA; |
| 120 | − for (mb_y = 0; mb_y < s->mb_height; mb_y++) | |
| 121 | − for (mb_x = 0; mb_x < s->mb_width; mb_x++) | |
| 122 | − mb_type[mb_y * s->mb_stride + mb_x] = | |
| 123 | − (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 119 | + for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) | |
| 120 | + for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) | |
| 121 | + mb_type[mb_y * h->c.mb_stride + mb_x] = | |
| 122 | + (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 124 | 123 | break; |
| 125 | 124 | case SKIP_TYPE_ROW: |
| 126 | − for (mb_y = 0; mb_y < s->mb_height; mb_y++) { | |
| 127 | − if (get_bits_left(&s->gb) < 1) | |
| 125 | + for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) { | |
| 126 | + if (get_bits_left(&h->c.gb) < 1) | |
| 128 | 127 | return AVERROR_INVALIDDATA; |
| 129 | − if (get_bits1(&s->gb)) { | |
| 130 | − for (mb_x = 0; mb_x < s->mb_width; mb_x++) | |
| 131 | − mb_type[mb_y * s->mb_stride + mb_x] = | |
| 128 | + if (get_bits1(&h->c.gb)) { | |
| 129 | + for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) | |
| 130 | + mb_type[mb_y * h->c.mb_stride + mb_x] = | |
| 132 | 131 | MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 133 | 132 | } else { |
| 134 | − for (mb_x = 0; mb_x < s->mb_width; mb_x++) | |
| 135 | − mb_type[mb_y * s->mb_stride + mb_x] = | |
| 136 | − (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 133 | + for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) | |
| 134 | + mb_type[mb_y * h->c.mb_stride + mb_x] = | |
| 135 | + (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 137 | 136 | } |
| 138 | 137 | } |
| 139 | 138 | break; |
| 140 | 139 | case SKIP_TYPE_COL: |
| 141 | − for (mb_x = 0; mb_x < s->mb_width; mb_x++) { | |
| 142 | − if (get_bits_left(&s->gb) < 1) | |
| 140 | + for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) { | |
| 141 | + if (get_bits_left(&h->c.gb) < 1) | |
| 143 | 142 | return AVERROR_INVALIDDATA; |
| 144 | − if (get_bits1(&s->gb)) { | |
| 145 | − for (mb_y = 0; mb_y < s->mb_height; mb_y++) | |
| 146 | − mb_type[mb_y * s->mb_stride + mb_x] = | |
| 143 | + if (get_bits1(&h->c.gb)) { | |
| 144 | + for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) | |
| 145 | + mb_type[mb_y * h->c.mb_stride + mb_x] = | |
| 147 | 146 | MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; |
| 148 | 147 | } else { |
| 149 | − for (mb_y = 0; mb_y < s->mb_height; mb_y++) | |
| 150 | − mb_type[mb_y * s->mb_stride + mb_x] = | |
| 151 | − (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 148 | + for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) | |
| 149 | + mb_type[mb_y * h->c.mb_stride + mb_x] = | |
| 150 | + (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV; | |
| 152 | 151 | } |
| 153 | 152 | } |
| 154 | 153 | break; |
| 155 | 154 | } |
| 156 | 155 | |
| 157 | − for (mb_y = 0; mb_y < s->mb_height; mb_y++) | |
| 158 | − for (mb_x = 0; mb_x < s->mb_width; mb_x++) | |
| 159 | − coded_mb_count += !IS_SKIP(mb_type[mb_y * s->mb_stride + mb_x]); | |
| 156 | + for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) | |
| 157 | + for (int mb_x = 0; mb_x < h->c.mb_width; 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 | 161 | return AVERROR_INVALIDDATA; |
| 163 | 162 | |
| 164 | 163 | return 0; |
| @@ -166,20 +165,20 @@ static int parse_mb_skip(WMV2DecContext *w) · 1 unmodified line | ||
| 166 | 165 | |
| 167 | 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 | 169 | GetBitContext gb; |
| 171 | 170 | int fps; |
| 172 | 171 | int code; |
| 173 | 172 | |
| 174 | − if (s->avctx->extradata_size < 4) | |
| 173 | + if (h->c.avctx->extradata_size < 4) | |
| 175 | 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 | 178 | fps = get_bits(&gb, 5); |
| 180 | 179 | w->ms.bit_rate = get_bits(&gb, 11) * 1024; |
| 181 | 180 | w->mspel_bit = get_bits1(&gb); |
| 182 | − s->loop_filter = get_bits1(&gb); | |
| 181 | + h->c.loop_filter = get_bits1(&gb); | |
| 183 | 182 | w->abt_flag = get_bits1(&gb); |
| 184 | 183 | w->j_type_bit = get_bits1(&gb); |
| 185 | 184 | w->top_left_mv_flag = get_bits1(&gb); |
| @@ -189,36 +188,36 @@ static int decode_ext_header(WMV2DecContext *w) · 3 unmodified lines | ||
| 189 | 188 | if (code == 0) |
| 190 | 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) | |
| 195 | − av_log(s->avctx, AV_LOG_DEBUG, | |
| 193 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) | |
| 194 | + av_log(h->c.avctx, AV_LOG_DEBUG, | |
| 196 | 195 | "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, " |
| 197 | 196 | "tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, " |
| 198 | 197 | "slices:%d\n", |
| 199 | 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 | 200 | code); |
| 202 | 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 | 206 | int code; |
| 208 | 207 | |
| 209 | − s->pict_type = get_bits1(&s->gb) + 1; | |
| 210 | − if (s->pict_type == AV_PICTURE_TYPE_I) { | |
| 211 | − code = get_bits(&s->gb, 7); | |
| 212 | − av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code); | |
| 208 | + h->c.pict_type = get_bits1(&h->c.gb) + 1; | |
| 209 | + if (h->c.pict_type == AV_PICTURE_TYPE_I) { | |
| 210 | + code = get_bits(&h->c.gb, 7); | |
| 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); | |
| 215 | − if (s->qscale <= 0) | |
| 213 | + h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5); | |
| 214 | + if (h->c.qscale <= 0) | |
| 216 | 215 | return AVERROR_INVALIDDATA; |
| 217 | 216 | |
| 218 | − if (s->pict_type != AV_PICTURE_TYPE_I && show_bits(&s->gb, 1)) { | |
| 219 | − GetBitContext gb = s->gb; | |
| 217 | + if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->c.gb, 1)) { | |
| 218 | + GetBitContext gb = h->c.gb; | |
| 220 | 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 | 222 | while (run > 0) { |
| 224 | 223 | int block = FFMIN(run, 25); |
| @@ -233,46 +232,46 @@ int ff_wmv2_decode_picture_header(MpegEncContext *s) · 8 unmodified lines | ||
| 233 | 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 | 240 | /* Is filling with zeroes really the right thing to do? */ |
| 242 | − memset(s->cur_pic.mb_type, 0, | |
| 243 | − sizeof(*s->cur_pic.mb_type) * s->mb_height * s->mb_stride); | |
| 241 | + memset(h->c.cur_pic.mb_type, 0, | |
| 242 | + sizeof(*h->c.cur_pic.mb_type) * h->c.mb_height * h->c.mb_stride); | |
| 244 | 243 | if (w->j_type_bit) |
| 245 | − w->j_type = get_bits1(&s->gb); | |
| 244 | + w->j_type = get_bits1(&h->c.gb); | |
| 246 | 245 | else |
| 247 | 246 | w->j_type = 0; // FIXME check |
| 248 | 247 | |
| 249 | 248 | if (!w->j_type) { |
| 250 | 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 | 251 | else |
| 253 | 252 | w->ms.per_mb_rl_table = 0; |
| 254 | 253 | |
| 255 | 254 | if (!w->ms.per_mb_rl_table) { |
| 256 | − w->ms.rl_chroma_table_index = decode012(&s->gb); | |
| 257 | − w->ms.rl_table_index = decode012(&s->gb); | |
| 255 | + w->ms.rl_chroma_table_index = decode012(&h->c.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 | 261 | // at minimum one bit per macroblock is required at least in a valid frame, |
| 263 | 262 | // we discard frames much smaller than this. Frames smaller than 1/8 of the |
| 264 | 263 | // smallest "black/skip" frame generally contain not much recoverable content |
| 265 | 264 | // while at the same time they have the highest computational requirements |
| 266 | 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 | 267 | return AVERROR_INVALIDDATA; |
| 269 | 268 | } |
| 270 | − s->inter_intra_pred = 0; | |
| 271 | − s->no_rounding = 1; | |
| 272 | − if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 273 | − av_log(s->avctx, AV_LOG_DEBUG, | |
| 269 | + h->c.inter_intra_pred = 0; | |
| 270 | + h->c.no_rounding = 1; | |
| 271 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 272 | + av_log(h->c.avctx, AV_LOG_DEBUG, | |
| 274 | 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 | 275 | w->ms.dc_table_index, w->ms.per_mb_rl_table, w->j_type); |
| 277 | 276 | } |
| 278 | 277 | } else { |
| @@ -283,61 +282,61 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) · 4 unmodified lines | ||
| 283 | 282 | ret = parse_mb_skip(w); |
| 284 | 283 | if (ret < 0) |
| 285 | 284 | return ret; |
| 286 | − cbp_index = decode012(&s->gb); | |
| 287 | − w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index); | |
| 285 | + cbp_index = decode012(&h->c.gb); | |
| 286 | + w->cbp_table_index = wmv2_get_cbp_table_index(h->c.qscale, cbp_index); | |
| 288 | 287 | |
| 289 | 288 | if (w->mspel_bit) |
| 290 | − s->mspel = get_bits1(&s->gb); | |
| 289 | + h->c.mspel = get_bits1(&h->c.gb); | |
| 291 | 290 | else |
| 292 | − s->mspel = 0; // FIXME check | |
| 291 | + h->c.mspel = 0; // FIXME check | |
| 293 | 292 | |
| 294 | 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 | 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 | 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 | 301 | else |
| 303 | 302 | w->ms.per_mb_rl_table = 0; |
| 304 | 303 | |
| 305 | 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 | 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 | 310 | return AVERROR_INVALIDDATA; |
| 312 | 311 | |
| 313 | − w->ms.dc_table_index = get_bits1(&s->gb); | |
| 314 | − w->ms.mv_table_index = get_bits1(&s->gb); | |
| 312 | + w->ms.dc_table_index = get_bits1(&h->c.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); | |
| 317 | − s->no_rounding ^= 1; | |
| 315 | + h->c.inter_intra_pred = 0; // (h->c.width * h->c.height < 320 * 240 && w->ms.bit_rate <= II_BITRATE); | |
| 316 | + h->c.no_rounding ^= 1; | |
| 318 | 317 | |
| 319 | − if (s->avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 320 | − av_log(s->avctx, AV_LOG_DEBUG, | |
| 318 | + if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { | |
| 319 | + av_log(h->c.avctx, AV_LOG_DEBUG, | |
| 321 | 320 | "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d " |
| 322 | 321 | "per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n", |
| 323 | 322 | w->ms.rl_table_index, w->ms.rl_chroma_table_index, |
| 324 | 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 | 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 | 329 | w->ms.esc3_level_length = 0; |
| 331 | 330 | w->ms.esc3_run_length = 0; |
| 332 | 331 | |
| 333 | 332 | if (w->j_type) { |
| 334 | − ff_intrax8_decode_picture(&w->x8, s->cur_pic.ptr, | |
| 335 | − &s->gb, &s->mb_x, &s->mb_y, | |
| 336 | − 2 * s->qscale, (s->qscale - 1) | 1, | |
| 337 | − s->loop_filter, s->low_delay); | |
| 333 | + ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr, | |
| 334 | + &h->c.gb, &h->c.mb_x, &h->c.mb_y, | |
| 335 | + 2 * h->c.qscale, (h->c.qscale - 1) | 1, | |
| 336 | + h->c.loop_filter, h->c.low_delay); | |
| 338 | 337 | |
| 339 | − ff_er_add_slice(&s->er, 0, 0, | |
| 340 | − (s->mb_x >> 1) - 1, (s->mb_y >> 1) - 1, | |
| 338 | + ff_er_add_slice(&h->c.er, 0, 0, | |
| 339 | + (h->c.mb_x >> 1) - 1, (h->c.mb_y >> 1) - 1, | |
| 341 | 340 | ER_MB_END); |
| 342 | 341 | return 1; |
| 343 | 342 | } |
| @@ -347,38 +346,37 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) · 3 unmodified lines | ||
| 347 | 346 | |
| 348 | 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 | 351 | ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr); |
| 353 | 352 | |
| 354 | − if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel) | |
| 355 | − w->common.hshift = get_bits1(&s->gb); | |
| 353 | + if ((((*mx_ptr) | (*my_ptr)) & 1) && h->c.mspel) | |
| 354 | + w->common.hshift = get_bits1(&h->c.gb); | |
| 356 | 355 | else |
| 357 | 356 | w->common.hshift = 0; |
| 358 | 357 | } |
| 359 | 358 | |
| 360 | 359 | static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) |
| 361 | 360 | { |
| 362 | − MpegEncContext *const s = &w->ms.m; | |
| 363 | − int xy, wrap, diff, type; | |
| 364 | − int16_t *A, *B, *C, *mot_val; | |
| 361 | + H263DecContext *const h = &w->ms.h; | |
| 362 | + int diff, type; | |
| 365 | 363 | |
| 366 | − wrap = s->b8_stride; | |
| 367 | − xy = s->block_index[0]; | |
| 364 | + int wrap = h->c.b8_stride; | |
| 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]; | |
| 372 | − B = s->cur_pic.motion_val[0][xy - wrap]; | |
| 373 | − C = s->cur_pic.motion_val[0][xy + 2 - wrap]; | |
| 369 | + const int16_t *A = h->c.cur_pic.motion_val[0][xy - 1]; | |
| 370 | + const int16_t *B = h->c.cur_pic.motion_val[0][xy - 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 | 374 | diff = FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1])); |
| 377 | 375 | else |
| 378 | 376 | diff = 0; |
| 379 | 377 | |
| 380 | 378 | if (diff >= 8) |
| 381 | − type = get_bits1(&s->gb); | |
| 379 | + type = get_bits1(&h->c.gb); | |
| 382 | 380 | else |
| 383 | 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 | 388 | *py = B[1]; |
| 391 | 389 | } else { |
| 392 | 390 | /* special case for first (slice) line */ |
| 393 | − if (s->first_slice_line) { | |
| 391 | + if (h->c.first_slice_line) { | |
| 394 | 392 | *px = A[0]; |
| 395 | 393 | *py = A[1]; |
| 396 | 394 | } else { |
| @@ -405,23 +403,23 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) · 8 unmodified lines | ||
| 405 | 403 | static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block, |
| 406 | 404 | int n, int cbp) |
| 407 | 405 | { |
| 408 | − MpegEncContext *const s = &w->ms.m; | |
| 406 | + H263DecContext *const h = &w->ms.h; | |
| 409 | 407 | static const int sub_cbp_table[3] = { 2, 3, 1 }; |
| 410 | 408 | int sub_cbp, ret; |
| 411 | 409 | |
| 412 | 410 | if (!cbp) { |
| 413 | − s->block_last_index[n] = -1; | |
| 411 | + h->c.block_last_index[n] = -1; | |
| 414 | 412 | return 0; |
| 415 | 413 | } |
| 416 | 414 | |
| 417 | 415 | if (w->per_block_abt) |
| 418 | − w->abt_type = decode012(&s->gb); | |
| 416 | + w->abt_type = decode012(&h->c.gb); | |
| 419 | 417 | w->abt_type_table[n] = w->abt_type; |
| 420 | 418 | |
| 421 | 419 | if (w->abt_type) { |
| 422 | 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 | 424 | if (sub_cbp & 1) { |
| 427 | 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 | 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 | 438 | return 0; |
| 441 | 439 | } else { |
| 442 | 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 | 448 | * does not use slice threading. */ |
| 451 | − WMV2DecContext *const w = (WMV2DecContext *) s; | |
| 449 | + WMV2DecContext *const w = (WMV2DecContext *) h; | |
| 452 | 450 | MSMP4DecContext *const ms = &w->ms; |
| 453 | 451 | int cbp, code, i, ret; |
| 454 | 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 | 454 | if (w->j_type) |
| 457 | 455 | return 0; |
| 458 | 456 | |
| 459 | − if (s->pict_type == AV_PICTURE_TYPE_P) { | |
| 460 | − if (IS_SKIP(s->cur_pic.mb_type[s->mb_y * s->mb_stride + s->mb_x])) { | |
| 457 | + if (h->c.pict_type == AV_PICTURE_TYPE_P) { | |
| 458 | + if (IS_SKIP(h->c.cur_pic.mb_type[h->c.mb_y * h->c.mb_stride + h->c.mb_x])) { | |
| 461 | 459 | /* skip mb */ |
| 462 | − s->mb_intra = 0; | |
| 460 | + h->c.mb_intra = 0; | |
| 463 | 461 | for (i = 0; i < 6; i++) |
| 464 | − s->block_last_index[i] = -1; | |
| 465 | − s->mv_dir = MV_DIR_FORWARD; | |
| 466 | − s->mv_type = MV_TYPE_16X16; | |
| 467 | − s->mv[0][0][0] = 0; | |
| 468 | − s->mv[0][0][1] = 0; | |
| 469 | − s->mb_skipped = 1; | |
| 462 | + h->c.block_last_index[i] = -1; | |
| 463 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 464 | + h->c.mv_type = MV_TYPE_16X16; | |
| 465 | + h->c.mv[0][0][0] = 0; | |
| 466 | + h->c.mv[0][0][1] = 0; | |
| 467 | + h->c.mb_skipped = 1; | |
| 470 | 468 | w->common.hshift = 0; |
| 471 | 469 | return 0; |
| 472 | 470 | } |
| 473 | − if (get_bits_left(&s->gb) <= 0) | |
| 471 | + if (get_bits_left(&h->c.gb) <= 0) | |
| 474 | 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 | 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 | 478 | cbp = code & 0x3f; |
| 481 | 479 | } else { |
| 482 | − s->mb_intra = 1; | |
| 483 | − if (get_bits_left(&s->gb) <= 0) | |
| 480 | + h->c.mb_intra = 1; | |
| 481 | + if (get_bits_left(&h->c.gb) <= 0) | |
| 484 | 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 | 484 | MSMP4_MB_INTRA_VLC_BITS, 2); |
| 487 | 485 | /* predict coded block pattern */ |
| 488 | 486 | cbp = 0; |
| 489 | 487 | for (i = 0; i < 6; i++) { |
| 490 | 488 | int val = ((code >> (5 - i)) & 1); |
| 491 | 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 | 491 | val = val ^ pred; |
| 494 | 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 | 499 | int mx, my; |
| 502 | 500 | wmv2_pred_motion(w, &mx, &my); |
| 503 | 501 | |
| 504 | 502 | if (cbp) { |
| 505 | − s->bdsp.clear_blocks(s->block[0]); | |
| 503 | + h->c.bdsp.clear_blocks(h->c.block[0]); | |
| 506 | 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 | 506 | ms->rl_chroma_table_index = ms->rl_table_index; |
| 509 | 507 | } |
| 510 | 508 | |
| 511 | 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 | 511 | if (!w->per_block_abt) |
| 514 | − w->abt_type = decode012(&s->gb); | |
| 512 | + w->abt_type = decode012(&h->c.gb); | |
| 515 | 513 | } else |
| 516 | 514 | w->per_block_abt = 0; |
| 517 | 515 | } |
| 518 | 516 | |
| 519 | 517 | wmv2_decode_motion(w, &mx, &my); |
| 520 | 518 | |
| 521 | − s->mv_dir = MV_DIR_FORWARD; | |
| 522 | − s->mv_type = MV_TYPE_16X16; | |
| 523 | − s->mv[0][0][0] = mx; | |
| 524 | − s->mv[0][0][1] = my; | |
| 519 | + h->c.mv_dir = MV_DIR_FORWARD; | |
| 520 | + h->c.mv_type = MV_TYPE_16X16; | |
| 521 | + h->c.mv[0][0][0] = mx; | |
| 522 | + h->c.mv[0][0][1] = my; | |
| 525 | 523 | |
| 526 | 524 | for (i = 0; i < 6; i++) { |
| 527 | 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 | 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 | 529 | return ret; |
| 532 | 530 | } |
| 533 | 531 | } |
| 534 | 532 | } else { |
| 535 | − if (s->pict_type == AV_PICTURE_TYPE_P) | |
| 536 | − ff_dlog(s->avctx, "%d%d ", s->inter_intra_pred, cbp); | |
| 537 | − ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y, | |
| 533 | + if (h->c.pict_type == AV_PICTURE_TYPE_P) | |
| 534 | + ff_dlog(h->c.avctx, "%d%d ", h->c.inter_intra_pred, cbp); | |
| 535 | + ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y, | |
| 538 | 536 | ((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0), |
| 539 | − show_bits(&s->gb, 24)); | |
| 540 | − s->ac_pred = get_bits1(&s->gb); | |
| 541 | − if (s->inter_intra_pred) { | |
| 542 | − s->h263_aic_dir = get_vlc2(&s->gb, ff_inter_intra_vlc, | |
| 537 | + show_bits(&h->c.gb, 24)); | |
| 538 | + h->c.ac_pred = get_bits1(&h->c.gb); | |
| 539 | + if (h->c.inter_intra_pred) { | |
| 540 | + h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc, | |
| 543 | 541 | INTER_INTRA_VLC_BITS, 1); |
| 544 | − ff_dlog(s->avctx, "%d%d %d %d/", | |
| 545 | − s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); | |
| 542 | + ff_dlog(h->c.avctx, "%d%d %d %d/", | |
| 543 | + h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y); | |
| 546 | 544 | } |
| 547 | 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 | 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 | 551 | for (i = 0; i < 6; i++) { |
| 554 | 552 | ret = ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL); |
| 555 | 553 | if (ret < 0) { |
| 556 | − av_log(s->avctx, AV_LOG_ERROR, | |
| 554 | + av_log(h->c.avctx, AV_LOG_ERROR, | |
| 557 | 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 | 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 | 565 | static av_cold int wmv2_decode_init(AVCodecContext *avctx) |
| 568 | 566 | { |
| 569 | 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 | 570 | int ret; |
| 572 | 571 | |
| 573 | 572 | s->private_ctx = &w->common; |
| @@ -575,13 +574,13 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx) · 1 unmodified line | ||
| 575 | 574 | if ((ret = ff_msmpeg4_decode_init(avctx)) < 0) |
| 576 | 575 | return ret; |
| 577 | 576 | |
| 578 | − s->decode_mb = wmv2_decode_mb; | |
| 577 | + h->decode_mb = wmv2_decode_mb; | |
| 579 | 578 | |
| 580 | 579 | ff_wmv2_common_init(s); |
| 581 | 580 | |
| 582 | 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 | 584 | s->mb_width, s->mb_height); |
| 586 | 585 | } |
| 587 | 586 | |
| @@ -22,9 +22,10 @@ · 21 unmodified lines | ||
| 22 | 22 | #define AVCODEC_WMV2DEC_H |
| 23 | 23 | |
| 24 | 24 | #include "mpegvideo.h" |
| 25 | +struct H263DecContext; | |
| 25 | 26 | |
| 26 | −int ff_wmv2_decode_picture_header(MpegEncContext * s); | |
| 27 | −int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s); | |
| 27 | +int ff_wmv2_decode_picture_header(struct H263DecContext *const h); | |
| 28 | +int ff_wmv2_decode_secondary_picture_header(struct H263DecContext *const h); | |
| 28 | 29 | void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], |
| 29 | 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 | 118 | put_bits(&s->pb, 2, SKIP_TYPE_NONE); |
| 119 | 119 | |
| 120 | 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 | 123 | if (w->mspel_bit) |
| 124 | 124 | put_bits(&s->pb, 1, s->c.mspel); |