History

avcodec/h263dec: Stop using MpegEncContext.gb

Add a GetBitContext to H263DecContext instead. This is in preparation for removing MpegEncContext.gb. Also move last_resync_gb to H263DecContext.

Andreas Rheinhardt committed 1 year ago

Commit 8a4accc1 parent 77add2613 files · +588 −583Browse files

Showing the changes to libavcodec (13 of 13 files). Show all

Unified · Split

13 files
  1. libavcodec/flvdec.c +12 −12
  2. libavcodec/h263dec.c +26 −26
  3. libavcodec/h263dec.h +5 −0
  4. libavcodec/intelh263dec.c +32 −32
  5. libavcodec/ituh263dec.c +170 −169
  6. libavcodec/mpeg12dec.c +5 −5
  7. libavcodec/mpeg4videodec.c +160 −160
  8. libavcodec/mpegvideo.h +0 −1
  9. libavcodec/mpegvideodec.h +3 −3
  10. libavcodec/msmpeg4dec.c +94 −94
  11. libavcodec/rv10.c +31 −31
  12. libavcodec/vaapi_mpeg4.c +4 −4
  13. libavcodec/wmv2dec.c +46 −46
libavcodec/flvdec.c+12−12
@@ -31,26 +31,26 @@ int ff_flv_decode_picture_header(H263DecContext *const h) · 30 unmodified lines
31 int format, width, height;31 int format, width, height;
32 32
33 /* picture header */33 /* picture header */
34 if (get_bits(&h->c.gb, 17) != 1) {34 if (get_bits(&h->gb, 17) != 1) {
35 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");35 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
36 return AVERROR_INVALIDDATA;36 return AVERROR_INVALIDDATA;
37 }37 }
38 format = get_bits(&h->c.gb, 5);38 format = get_bits(&h->gb, 5);
39 if (format != 0 && format != 1) {39 if (format != 0 && format != 1) {
40 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");40 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
41 return AVERROR_INVALIDDATA;41 return AVERROR_INVALIDDATA;
42 }42 }
43 h->c.h263_flv = format + 1;43 h->c.h263_flv = format + 1;
44 h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */44 h->c.picture_number = get_bits(&h->gb, 8); /* picture timestamp */
45 format = get_bits(&h->c.gb, 3);45 format = get_bits(&h->gb, 3);
46 switch (format) {46 switch (format) {
47 case 0:47 case 0:
48 width = get_bits(&h->c.gb, 8);48 width = get_bits(&h->gb, 8);
49 height = get_bits(&h->c.gb, 8);49 height = get_bits(&h->gb, 8);
50 break;50 break;
51 case 1:51 case 1:
52 width = get_bits(&h->c.gb, 16);52 width = get_bits(&h->gb, 16);
53 height = get_bits(&h->c.gb, 16);53 height = get_bits(&h->gb, 16);
54 break;54 break;
55 case 2:55 case 2:
56 width = 352;56 width = 352;
@@ -81,18 +81,18 @@ int ff_flv_decode_picture_header(H263DecContext *const h) · 24 unmodified lines
81 h->c.width = width;81 h->c.width = width;
82 h->c.height = height;82 h->c.height = height;
83 83
84 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->c.gb, 2);84 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->gb, 2);
85 h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P;85 h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P;
86 if (h->c.droppable)86 if (h->c.droppable)
87 h->c.pict_type = AV_PICTURE_TYPE_P;87 h->c.pict_type = AV_PICTURE_TYPE_P;
88 88
89 skip_bits1(&h->c.gb); /* deblocking flag */89 skip_bits1(&h->gb); /* deblocking flag */
90 h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);90 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
91 91
92 h->c.h263_long_vectors = 0;92 h->c.h263_long_vectors = 0;
93 93
94 /* PEI */94 /* PEI */
95 if (skip_1stop_8data_bits(&h->c.gb) < 0)95 if (skip_1stop_8data_bits(&h->gb) < 0)
96 return AVERROR_INVALIDDATA;96 return AVERROR_INVALIDDATA;
97 97
98 if (h->c.ehc_mode)98 if (h->c.ehc_mode)
libavcodec/h263dec.c+26−26
@@ -187,7 +187,7 @@ static int decode_slice(H263DecContext *const h) · 186 unmodified lines
187 const int mb_size = 16 >> h->c.avctx->lowres;187 const int mb_size = 16 >> h->c.avctx->lowres;
188 int ret;188 int ret;
189 189
190 h->c.last_resync_gb = h->c.gb;190 h->last_resync_gb = h->gb;
191 h->c.first_slice_line = 1;191 h->c.first_slice_line = 1;
192 h->c.resync_mb_x = h->c.mb_x;192 h->c.resync_mb_x = h->c.mb_x;
193 h->c.resync_mb_y = h->c.mb_y;193 h->c.resync_mb_y = h->c.mb_y;
@@ -200,8 +200,8 @@ static int decode_slice(H263DecContext *const h) · 6 unmodified lines
200 }200 }
201 201
202 if (h->c.avctx->hwaccel) {202 if (h->c.avctx->hwaccel) {
203 const uint8_t *start = h->c.gb.buffer + get_bits_count(&h->c.gb) / 8;203 const uint8_t *start = h->gb.buffer + get_bits_count(&h->gb) / 8;
204 ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->c.gb.buffer_end - start);204 ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->gb.buffer_end - start);
205 // ensure we exit decode loop205 // ensure we exit decode loop
206 h->c.mb_y = h->c.mb_height;206 h->c.mb_y = h->c.mb_height;
207 return ret;207 return ret;
@@ -253,7 +253,7 @@ static int decode_slice(H263DecContext *const h) · 45 unmodified lines
253 h->c.mv_dir = MV_DIR_FORWARD;253 h->c.mv_dir = MV_DIR_FORWARD;
254 h->c.mv_type = MV_TYPE_16X16;254 h->c.mv_type = MV_TYPE_16X16;
255 ff_dlog(h->c.avctx, "%d %06X\n",255 ff_dlog(h->c.avctx, "%d %06X\n",
256 get_bits_count(&h->c.gb), show_bits(&h->c.gb, 24));256 get_bits_count(&h->gb), show_bits(&h->gb, 24));
257 257
258 ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);258 ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);
259 ret = h->decode_mb(h);259 ret = h->decode_mb(h);
@@ -300,7 +300,7 @@ static int decode_slice(H263DecContext *const h) · 40 unmodified lines
300 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,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 h->c.mb_x, h->c.mb_y, ER_MB_ERROR & part_mask);
302 302
303 if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->c.gb) > 0)303 if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->gb) > 0)
304 continue;304 continue;
305 return AVERROR_INVALIDDATA;305 return AVERROR_INVALIDDATA;
306 }306 }
@@ -321,29 +321,29 @@ static int decode_slice(H263DecContext *const h) · 14 unmodified lines
321 // Detect incorrect padding with wrong stuffing codes used by NEC N-02B321 // Detect incorrect padding with wrong stuffing codes used by NEC N-02B
322 if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&322 if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
323 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&323 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
324 get_bits_left(&h->c.gb) >= 48 &&324 get_bits_left(&h->gb) >= 48 &&
325 show_bits(&h->c.gb, 24) == 0x4010 &&325 show_bits(&h->gb, 24) == 0x4010 &&
326 !h->c.data_partitioning)326 !h->c.data_partitioning)
327 h->c.padding_bug_score += 32;327 h->c.padding_bug_score += 32;
328 328
329 /* try to detect the padding bug */329 /* try to detect the padding bug */
330 if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&330 if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
331 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&331 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
332 get_bits_left(&h->c.gb) >= 0 &&332 get_bits_left(&h->gb) >= 0 &&
333 get_bits_left(&h->c.gb) < 137 &&333 get_bits_left(&h->gb) < 137 &&
334 !h->c.data_partitioning) {334 !h->c.data_partitioning) {
335 const int bits_count = get_bits_count(&h->c.gb);335 const int bits_count = get_bits_count(&h->gb);
336 const int bits_left = h->c.gb.size_in_bits - bits_count;336 const int bits_left = h->gb.size_in_bits - bits_count;
337 337
338 if (bits_left == 0) {338 if (bits_left == 0) {
339 h->c.padding_bug_score += 16;339 h->c.padding_bug_score += 16;
340 } else if (bits_left != 1) {340 } else if (bits_left != 1) {
341 int v = show_bits(&h->c.gb, 8);341 int v = show_bits(&h->gb, 8);
342 v |= 0x7F >> (7 - (bits_count & 7));342 v |= 0x7F >> (7 - (bits_count & 7));
343 343
344 if (v == 0x7F && bits_left <= 8)344 if (v == 0x7F && bits_left <= 8)
345 h->c.padding_bug_score--;345 h->c.padding_bug_score--;
346 else if (v == 0x7F && ((get_bits_count(&h->c.gb) + 8) & 8) &&346 else if (v == 0x7F && ((get_bits_count(&h->gb) + 8) & 8) &&
347 bits_left <= 16)347 bits_left <= 16)
348 h->c.padding_bug_score += 4;348 h->c.padding_bug_score += 4;
349 else349 else
@@ -353,10 +353,10 @@ static int decode_slice(H263DecContext *const h) · 3 unmodified lines
353 353
354 if (h->c.codec_id == AV_CODEC_ID_H263 &&354 if (h->c.codec_id == AV_CODEC_ID_H263 &&
355 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&355 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
356 get_bits_left(&h->c.gb) >= 8 &&356 get_bits_left(&h->gb) >= 8 &&
357 get_bits_left(&h->c.gb) < 300 &&357 get_bits_left(&h->gb) < 300 &&
358 h->c.pict_type == AV_PICTURE_TYPE_I &&358 h->c.pict_type == AV_PICTURE_TYPE_I &&
359 show_bits(&h->c.gb, 8) == 0 &&359 show_bits(&h->gb, 8) == 0 &&
360 !h->c.data_partitioning) {360 !h->c.data_partitioning) {
361 361
362 h->c.padding_bug_score += 32;362 h->c.padding_bug_score += 32;
@@ -364,8 +364,8 @@ static int decode_slice(H263DecContext *const h) · 1 unmodified line
364 364
365 if (h->c.codec_id == AV_CODEC_ID_H263 &&365 if (h->c.codec_id == AV_CODEC_ID_H263 &&
366 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&366 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
367 get_bits_left(&h->c.gb) >= 64 &&367 get_bits_left(&h->gb) >= 64 &&
368 AV_RB64(h->c.gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {368 AV_RB64(h->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
369 369
370 h->c.padding_bug_score += 32;370 h->c.padding_bug_score += 32;
371 }371 }
@@ -380,7 +380,7 @@ static int decode_slice(H263DecContext *const h) · 8 unmodified lines
380 380
381 // handle formats which don't have unique end markers381 // handle formats which don't have unique end markers
382 if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly382 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 int left = get_bits_left(&h->gb);
384 int max_extra = 7;384 int max_extra = 7;
385 385
386 /* no markers in M$ crap */386 /* no markers in M$ crap */
@@ -398,7 +398,7 @@ static int decode_slice(H263DecContext *const h) · 11 unmodified lines
398 if (left > max_extra)398 if (left > max_extra)
399 av_log(h->c.avctx, AV_LOG_ERROR,399 av_log(h->c.avctx, AV_LOG_ERROR,
400 "discarding %d junk bits at end, next would be %X\n",400 "discarding %d junk bits at end, next would be %X\n",
401 left, show_bits(&h->c.gb, 24));401 left, show_bits(&h->gb, 24));
402 else if (left < 0)402 else if (left < 0)
403 av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);403 av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
404 else404 else
@@ -410,7 +410,7 @@ static int decode_slice(H263DecContext *const h) · 5 unmodified lines
410 410
411 av_log(h->c.avctx, AV_LOG_ERROR,411 av_log(h->c.avctx, AV_LOG_ERROR,
412 "slice end not reached but screenspace end (%d left %06X, score= %d)\n",412 "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
413 get_bits_left(&h->c.gb), show_bits(&h->c.gb, 24), h->c.padding_bug_score);413 get_bits_left(&h->gb), show_bits(&h->gb, 24), h->c.padding_bug_score);
414 414
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 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,
416 ER_MB_END & part_mask);416 ER_MB_END & part_mask);
@@ -452,8 +452,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 35 unmodified lines
452 return 0;452 return 0;
453 }453 }
454 454
455 // h->c.gb might be overridden in ff_mpeg4_decode_picture_header() below.455 // h->gb might be overridden in ff_mpeg4_decode_picture_header() below.
456 ret = init_get_bits8(&h->c.gb, buf, buf_size);456 ret = init_get_bits8(&h->gb, buf, buf_size);
457 if (ret < 0)457 if (ret < 0)
458 return ret;458 return ret;
459 459
@@ -504,7 +504,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 44 unmodified lines
504 avctx->has_b_frames = !h->c.low_delay;504 avctx->has_b_frames = !h->c.low_delay;
505 505
506 if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {506 if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
507 if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->c.gb))507 if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->gb))
508 return AVERROR_INVALIDDATA;508 return AVERROR_INVALIDDATA;
509 ff_mpeg4_workaround_bugs(avctx);509 ff_mpeg4_workaround_bugs(avctx);
510 if (h->c.studio_profile != (h->c.idsp.idct == NULL))510 if (h->c.studio_profile != (h->c.idsp.idct == NULL))
@@ -554,7 +554,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 43 unmodified lines
554 554
555 if (avctx->hwaccel) {555 if (avctx->hwaccel) {
556 ret = FF_HW_CALL(avctx, start_frame, NULL,556 ret = FF_HW_CALL(avctx, start_frame, NULL,
557 h->c.gb.buffer, h->c.gb.buffer_end - h->c.gb.buffer);557 h->gb.buffer, h->gb.buffer_end - h->gb.buffer);
558 if (ret < 0 )558 if (ret < 0 )
559 return ret;559 return ret;
560 }560 }
@@ -582,7 +582,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 21 unmodified lines
582 while (h->c.mb_y < h->c.mb_height) {582 while (h->c.mb_y < h->c.mb_height) {
583 if (h->c.msmpeg4_version != MSMP4_UNUSED) {583 if (h->c.msmpeg4_version != MSMP4_UNUSED) {
584 if (h->c.slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||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)585 (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->gb) < 0)
586 break;586 break;
587 } else {587 } else {
588 int prev_x = h->c.mb_x, prev_y = h->c.mb_y;588 int prev_x = h->c.mb_x, prev_y = h->c.mb_y;
libavcodec/h263dec.h+5−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
20#ifndef AVCODEC_H263DEC_H20#ifndef AVCODEC_H263DEC_H
21#define AVCODEC_H263DEC_H21#define AVCODEC_H263DEC_H
22 22
23#include "get_bits.h"
23#include "mpegvideo.h"24#include "mpegvideo.h"
24#include "vlc.h"25#include "vlc.h"
25#include "libavutil/mem_internal.h"26#include "libavutil/mem_internal.h"
@@ -47,8 +48,12 @@ extern VLCElem ff_h263_mv_vlc[]; · 21 unmodified lines
47typedef struct H263DecContext {48typedef struct H263DecContext {
48 MPVContext c;49 MPVContext c;
49 50
51 GetBitContext gb;
52
50 int (*decode_mb)(struct H263DecContext *h);53 int (*decode_mb)(struct H263DecContext *h);
51 54
55 GetBitContext last_resync_gb; ///< used to search for the next resync marker
56
52 DECLARE_ALIGNED_32(int16_t, block)[6][64];57 DECLARE_ALIGNED_32(int16_t, block)[6][64];
53} H263DecContext;58} H263DecContext;
54 59
libavcodec/intelh263dec.c+32−32
@@ -30,44 +30,44 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h) · 29 unmodified lines
30{30{
31 int format;31 int format;
32 32
33 if (get_bits_left(&h->c.gb) == 64) { /* special dummy frames */33 if (get_bits_left(&h->gb) == 64) { /* special dummy frames */
34 return FRAME_SKIPPED;34 return FRAME_SKIPPED;
35 }35 }
36 36
37 /* picture header */37 /* picture header */
38 if (get_bits(&h->c.gb, 22) != 0x20) {38 if (get_bits(&h->gb, 22) != 0x20) {
39 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");39 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
40 return -1;40 return -1;
41 }41 }
42 h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */42 h->c.picture_number = get_bits(&h->gb, 8); /* picture timestamp */
43 43
44 if (check_marker(h->c.avctx, &h->c.gb, "after picture_number") != 1) {44 if (check_marker(h->c.avctx, &h->gb, "after picture_number") != 1) {
45 return -1; /* marker */45 return -1; /* marker */
46 }46 }
47 if (get_bits1(&h->c.gb) != 0) {47 if (get_bits1(&h->gb) != 0) {
48 av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");48 av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
49 return -1; /* H.263 id */49 return -1; /* H.263 id */
50 }50 }
51 skip_bits1(&h->c.gb); /* split screen off */51 skip_bits1(&h->gb); /* split screen off */
52 skip_bits1(&h->c.gb); /* camera off */52 skip_bits1(&h->gb); /* camera off */
53 skip_bits1(&h->c.gb); /* freeze picture release off */53 skip_bits1(&h->gb); /* freeze picture release off */
54 54
55 format = get_bits(&h->c.gb, 3);55 format = get_bits(&h->gb, 3);
56 if (format == 0 || format == 6) {56 if (format == 0 || format == 6) {
57 av_log(h->c.avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");57 av_log(h->c.avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
58 return -1;58 return -1;
59 }59 }
60 60
61 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);61 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
62 62
63 h->c.h263_long_vectors = get_bits1(&h->c.gb);63 h->c.h263_long_vectors = get_bits1(&h->gb);
64 64
65 if (get_bits1(&h->c.gb) != 0) {65 if (get_bits1(&h->gb) != 0) {
66 av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");66 av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");
67 return -1; /* SAC: off */67 return -1; /* SAC: off */
68 }68 }
69 h->c.obmc = get_bits1(&h->c.gb);69 h->c.obmc = get_bits1(&h->gb);
70 h->c.pb_frame = get_bits1(&h->c.gb);70 h->c.pb_frame = get_bits1(&h->gb);
71 71
72 if (format < 6) {72 if (format < 6) {
73 h->c.width = ff_h263_format[format][0];73 h->c.width = ff_h263_format[format][0];
@@ -75,31 +75,31 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h) · 1 unmodified line
75 h->c.avctx->sample_aspect_ratio.num = 12;75 h->c.avctx->sample_aspect_ratio.num = 12;
76 h->c.avctx->sample_aspect_ratio.den = 11;76 h->c.avctx->sample_aspect_ratio.den = 11;
77 } else {77 } else {
78 format = get_bits(&h->c.gb, 3);78 format = get_bits(&h->gb, 3);
79 if(format == 0 || format == 7){79 if(format == 0 || format == 7){
80 av_log(h->c.avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");80 av_log(h->c.avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
81 return -1;81 return -1;
82 }82 }
83 if (get_bits(&h->c.gb, 2))83 if (get_bits(&h->gb, 2))
84 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");84 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
85 h->c.loop_filter = get_bits1(&h->c.gb) * !h->c.avctx->lowres;85 h->c.loop_filter = get_bits1(&h->gb) * !h->c.avctx->lowres;
86 if (get_bits1(&h->c.gb))86 if (get_bits1(&h->gb))
87 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");87 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
88 if (get_bits1(&h->c.gb))88 if (get_bits1(&h->gb))
89 h->c.pb_frame = 2;89 h->c.pb_frame = 2;
90 if (get_bits(&h->c.gb, 5))90 if (get_bits(&h->gb, 5))
91 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");91 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
92 if (get_bits(&h->c.gb, 5) != 1)92 if (get_bits(&h->gb, 5) != 1)
93 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n");93 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n");
94 }94 }
95 if(format == 6){95 if(format == 6){
96 int ar = get_bits(&h->c.gb, 4);96 int ar = get_bits(&h->gb, 4);
97 skip_bits(&h->c.gb, 9); // display width97 skip_bits(&h->gb, 9); // display width
98 check_marker(h->c.avctx, &h->c.gb, "in dimensions");98 check_marker(h->c.avctx, &h->gb, "in dimensions");
99 skip_bits(&h->c.gb, 9); // display height99 skip_bits(&h->gb, 9); // display height
100 if (ar == 15) {100 if (ar == 15) {
101 h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); // aspect ratio - width101 h->c.avctx->sample_aspect_ratio.num = get_bits(&h->gb, 8); // aspect ratio - width
102 h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); // aspect ratio - height102 h->c.avctx->sample_aspect_ratio.den = get_bits(&h->gb, 8); // aspect ratio - height
103 } else {103 } else {
104 h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];104 h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
105 }105 }
@@ -107,16 +107,16 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h) · 1 unmodified line
107 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");107 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
108 }108 }
109 109
110 h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);110 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
111 skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */111 skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
112 112
113 if (h->c.pb_frame) {113 if (h->c.pb_frame) {
114 skip_bits(&h->c.gb, 3); //temporal reference for B-frame114 skip_bits(&h->gb, 3); //temporal reference for B-frame
115 skip_bits(&h->c.gb, 2); //dbquant115 skip_bits(&h->gb, 2); //dbquant
116 }116 }
117 117
118 /* PEI */118 /* PEI */
119 if (skip_1stop_8data_bits(&h->c.gb) < 0)119 if (skip_1stop_8data_bits(&h->gb) < 0)
120 return AVERROR_INVALIDDATA;120 return AVERROR_INVALIDDATA;
121 121
122 h->c.gob_index = H263_GOB_HEIGHT(h->c.height);122 h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
libavcodec/ituh263dec.c+170−169
@@ -82,7 +82,7 @@ void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus) · 81 unmodified lines
82 if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {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",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),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,85 h->gb.size_in_bits, 1-h->c.no_rounding,
86 h->c.obmc ? " AP" : "",86 h->c.obmc ? " AP" : "",
87 h->c.umvplus ? " UMV" : "",87 h->c.umvplus ? " UMV" : "",
88 h->c.h263_long_vectors ? " LONG" : "",88 h->c.h263_long_vectors ? " LONG" : "",
@@ -146,7 +146,7 @@ int ff_h263_decode_mba(H263DecContext *const h) · 57 unmodified lines
146 for (i = 0; i < 6; i++)146 for (i = 0; i < 6; i++)
147 if (h->c.mb_num - 1 <= ff_mba_max[i])147 if (h->c.mb_num - 1 <= ff_mba_max[i])
148 break;148 break;
149 mb_pos = get_bits(&h->c.gb, ff_mba_length[i]);149 mb_pos = get_bits(&h->gb, ff_mba_length[i]);
150 h->c.mb_x = mb_pos % h->c.mb_width;150 h->c.mb_x = mb_pos % h->c.mb_width;
151 h->c.mb_y = mb_pos / h->c.mb_width;151 h->c.mb_y = mb_pos / h->c.mb_width;
152 152
@@ -163,41 +163,42 @@ static int h263_decode_gob_header(H263DecContext *const h) · 10 unmodified lines
163 int left;163 int left;
164 164
165 /* Check for GOB Start Code */165 /* Check for GOB Start Code */
166 val = show_bits(&h->c.gb, 16);166 val = show_bits(&h->gb, 16);
167 if(val)167 if(val)
168 return -1;168 return -1;
169 169
170 /* We have a GBSC probably with GSTUFF */170 /* We have a GBSC probably with GSTUFF */
171 skip_bits(&h->c.gb, 16); /* Drop the zeros */171 skip_bits(&h->gb, 16); /* Drop the zeros */
172 left = get_bits_left(&h->c.gb);172 left = get_bits_left(&h->gb);
173 left = FFMIN(left, 32);173 left = FFMIN(left, 32);
174 //MN: we must check the bits left or we might end in an infinite loop (or segfault)174 //MN: we must check the bits left or we might end in an infinite loop (or segfault)
175 for(;left>13; left--){175 for(;left>13; left--){
176 if (get_bits1(&h->c.gb)) break; /* Seek the '1' bit */176 if (get_bits1(&h->gb))
177 break; /* Seek the '1' bit */
177 }178 }
178 if(left<=13)179 if(left<=13)
179 return -1;180 return -1;
180 181
181 if (h->c.h263_slice_structured) {182 if (h->c.h263_slice_structured) {
182 if (check_marker(h->c.avctx, &h->c.gb, "before MBA")==0)183 if (check_marker(h->c.avctx, &h->gb, "before MBA")==0)
183 return -1;184 return -1;
184 185
185 ff_h263_decode_mba(h);186 ff_h263_decode_mba(h);
186 187
187 if (h->c.mb_num > 1583)188 if (h->c.mb_num > 1583)
188 if (check_marker(h->c.avctx, &h->c.gb, "after MBA")==0)189 if (check_marker(h->c.avctx, &h->gb, "after MBA")==0)
189 return -1;190 return -1;
190 191
191 h->c.qscale = get_bits(&h->c.gb, 5); /* SQUANT */192 h->c.qscale = get_bits(&h->gb, 5); /* SQUANT */
192 if (check_marker(h->c.avctx, &h->c.gb, "after SQUANT")==0)193 if (check_marker(h->c.avctx, &h->gb, "after SQUANT")==0)
193 return -1;194 return -1;
194 skip_bits(&h->c.gb, 2); /* GFID */195 skip_bits(&h->gb, 2); /* GFID */
195 }else{196 }else{
196 gob_number = get_bits(&h->c.gb, 5); /* GN */197 gob_number = get_bits(&h->gb, 5); /* GN */
197 h->c.mb_x = 0;198 h->c.mb_x = 0;
198 h->c.mb_y = h->c.gob_index* gob_number;199 h->c.mb_y = h->c.gob_index* gob_number;
199 skip_bits(&h->c.gb, 2); /* GFID */200 skip_bits(&h->gb, 2); /* GFID */
200 h->c.qscale = get_bits(&h->c.gb, 5); /* GQUANT */201 h->c.qscale = get_bits(&h->gb, 5); /* GQUANT */
201 }202 }
202 203
203 if (h->c.mb_y >= h->c.mb_height)204 if (h->c.mb_y >= h->c.mb_height)
@@ -220,25 +221,25 @@ int ff_h263_resync(H263DecContext *const h) · 16 unmodified lines
220 /* In MPEG-4 studio mode look for a new slice startcode221 /* In MPEG-4 studio mode look for a new slice startcode
221 * and decode slice header */222 * and decode slice header */
222 if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) {223 if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) {
223 align_get_bits(&h->c.gb);224 align_get_bits(&h->gb);
224 225
225 while (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) != SLICE_STARTCODE) {226 while (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) != SLICE_STARTCODE) {
226 get_bits(&h->c.gb, 8);227 get_bits(&h->gb, 8);
227 }228 }
228 229
229 if (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) == SLICE_STARTCODE)230 if (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) == SLICE_STARTCODE)
230 return get_bits_count(&h->c.gb);231 return get_bits_count(&h->gb);
231 else232 else
232 return -1;233 return -1;
233 }234 }
234 235
235 if (h->c.codec_id==AV_CODEC_ID_MPEG4){236 if (h->c.codec_id==AV_CODEC_ID_MPEG4){
236 skip_bits1(&h->c.gb);237 skip_bits1(&h->gb);
237 align_get_bits(&h->c.gb);238 align_get_bits(&h->gb);
238 }239 }
239 240
240 if (show_bits(&h->c.gb, 16) ==0) {241 if (show_bits(&h->gb, 16) ==0) {
241 pos = get_bits_count(&h->c.gb);242 pos = get_bits_count(&h->gb);
242 if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)243 if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
243 ret = ff_mpeg4_decode_video_packet_header(h);244 ret = ff_mpeg4_decode_video_packet_header(h);
244 else245 else
@@ -247,15 +248,15 @@ int ff_h263_resync(H263DecContext *const h) · 2 unmodified lines
247 return pos;248 return pos;
248 }249 }
249 //OK, it's not where it is supposed to be ...250 //OK, it's not where it is supposed to be ...
250 h->c.gb = h->c.last_resync_gb;251 h->gb = h->last_resync_gb;
251 align_get_bits(&h->c.gb);252 align_get_bits(&h->gb);
252 left = get_bits_left(&h->c.gb);253 left = get_bits_left(&h->gb);
253 254
254 for(;left>16+1+5+5; left-=8){255 for(;left>16+1+5+5; left-=8){
255 if (show_bits(&h->c.gb, 16) == 0){256 if (show_bits(&h->gb, 16) == 0){
256 GetBitContext bak = h->c.gb;257 GetBitContext bak = h->gb;
257 258
258 pos = get_bits_count(&h->c.gb);259 pos = get_bits_count(&h->gb);
259 if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)260 if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
260 ret = ff_mpeg4_decode_video_packet_header(h);261 ret = ff_mpeg4_decode_video_packet_header(h);
261 else262 else
@@ -263,9 +264,9 @@ int ff_h263_resync(H263DecContext *const h) · 1 unmodified line
263 if(ret>=0)264 if(ret>=0)
264 return pos;265 return pos;
265 266
266 h->c.gb = bak;267 h->gb = bak;
267 }268 }
268 skip_bits(&h->c.gb, 8);269 skip_bits(&h->gb, 8);
269 }270 }
270 271
271 return -1;272 return -1;
@@ -274,19 +275,19 @@ int ff_h263_resync(H263DecContext *const h) · 2 unmodified lines
274int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)275int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
275{276{
276 int code, val, sign, shift;277 int code, val, sign, shift;
277 code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);278 code = get_vlc2(&h->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
278 279
279 if (code == 0)280 if (code == 0)
280 return pred;281 return pred;
281 if (code < 0)282 if (code < 0)
282 return 0xffff;283 return 0xffff;
283 284
284 sign = get_bits1(&h->c.gb);285 sign = get_bits1(&h->gb);
285 shift = f_code - 1;286 shift = f_code - 1;
286 val = code;287 val = code;
287 if (shift) {288 if (shift) {
288 val = (val - 1) << shift;289 val = (val - 1) << shift;
289 val |= get_bits(&h->c.gb, shift);290 val |= get_bits(&h->gb, shift);
290 val++;291 val++;
291 }292 }
292 if (sign)293 if (sign)
@@ -313,15 +314,15 @@ static int h263p_decode_umotion(H263DecContext *const h, int pred) · 20 unmodified lines
313{314{
314 int code = 0, sign;315 int code = 0, sign;
315 316
316 if (get_bits1(&h->c.gb)) /* Motion difference = 0 */317 if (get_bits1(&h->gb)) /* Motion difference = 0 */
317 return pred;318 return pred;
318 319
319 code = 2 + get_bits1(&h->c.gb);320 code = 2 + get_bits1(&h->gb);
320 321
321 while (get_bits1(&h->c.gb))322 while (get_bits1(&h->gb))
322 {323 {
323 code <<= 1;324 code <<= 1;
324 code += get_bits1(&h->c.gb);325 code += get_bits1(&h->gb);
325 if (code >= 32768) {326 if (code >= 32768) {
326 avpriv_request_sample(h->c.avctx, "Huge DMV");327 avpriv_request_sample(h->c.avctx, "Huge DMV");
327 return 0xffff;328 return 0xffff;
@@ -341,7 +342,7 @@ static int h263p_decode_umotion(H263DecContext *const h, int pred) · 13 unmodified lines
341 */342 */
342static void preview_obmc(H263DecContext *const h)343static void preview_obmc(H263DecContext *const h)
343{344{
344 GetBitContext gb = h->c.gb;345 GetBitContext gb = h->gb;
345 346
346 int cbpc, i, pred_x, pred_y, mx, my;347 int cbpc, i, pred_x, pred_y, mx, my;
347 int16_t *mot_val;348 int16_t *mot_val;
@@ -357,7 +358,7 @@ static void preview_obmc(H263DecContext *const h) · 9 unmodified lines
357 av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P);358 av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P);
358 359
359 do{360 do{
360 if (get_bits1(&h->c.gb)) {361 if (get_bits1(&h->gb)) {
361 /* skip mb */362 /* skip mb */
362 mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];363 mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
363 mot_val[0 ]= mot_val[2 ]=364 mot_val[0 ]= mot_val[2 ]=
@@ -368,15 +369,15 @@ static void preview_obmc(H263DecContext *const h) · 4 unmodified lines
368 h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;369 h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
369 goto end;370 goto end;
370 }371 }
371 cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);372 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
372 }while(cbpc == 20);373 }while(cbpc == 20);
373 374
374 if(cbpc & 4){375 if(cbpc & 4){
375 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;376 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
376 }else{377 }else{
377 get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);378 get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
378 if (cbpc & 8) {379 if (cbpc & 8) {
379 skip_bits(&h->c.gb, h->c.modified_quant ? (get_bits1(&h->c.gb) ? 1 : 5) : 2);380 skip_bits(&h->gb, h->c.modified_quant ? (get_bits1(&h->gb) ? 1 : 5) : 2);
380 }381 }
381 382
382 if ((cbpc & 16) == 0) {383 if ((cbpc & 16) == 0) {
@@ -411,7 +412,7 @@ static void preview_obmc(H263DecContext *const h) · 28 unmodified lines
411 else412 else
412 my = ff_h263_decode_motion(h, pred_y, 1);413 my = ff_h263_decode_motion(h, pred_y, 1);
413 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)414 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
414 skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */415 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
415 mot_val[0] = mx;416 mot_val[0] = mx;
416 mot_val[1] = my;417 mot_val[1] = my;
417 }418 }
@@ -425,7 +426,7 @@ end: · 7 unmodified lines
425 h->c.block_index[i] -= 1;426 h->c.block_index[i] -= 1;
426 h->c.mb_x--;427 h->c.mb_x--;
427 428
428 h->c.gb = gb;429 h->gb = gb;
429}430}
430 431
431static void h263_decode_dquant(H263DecContext *const h)432static void h263_decode_dquant(H263DecContext *const h)
@@ -434,12 +435,12 @@ static void h263_decode_dquant(H263DecContext *const h) · 2 unmodified lines
434 int qscale;435 int qscale;
435 436
436 if (h->c.modified_quant) {437 if (h->c.modified_quant) {
437 if (get_bits1(&h->c.gb))438 if (get_bits1(&h->gb))
438 qscale = ff_modified_quant_tab[get_bits1(&h->c.gb)][h->c.qscale];439 qscale = ff_modified_quant_tab[get_bits1(&h->gb)][h->c.qscale];
439 else440 else
440 qscale = get_bits(&h->c.gb, 5);441 qscale = get_bits(&h->gb, 5);
441 }else442 }else
442 qscale = h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)];443 qscale = h->c.qscale + quant_tab[get_bits(&h->gb, 2)];
443 ff_set_qscale(&h->c, qscale);444 ff_set_qscale(&h->c, qscale);
444}445}
445 446
@@ -527,7 +528,7 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64], · 81 unmodified lines
527 int level, i, j, run;528 int level, i, j, run;
528 const RLTable *rl = &ff_h263_rl_inter;529 const RLTable *rl = &ff_h263_rl_inter;
529 const uint8_t *scan_table;530 const uint8_t *scan_table;
530 GetBitContext gb = h->c.gb;531 GetBitContext gb = h->gb;
531 532
532 scan_table = h->c.intra_scantable.permutated;533 scan_table = h->c.intra_scantable.permutated;
533 if (h->c.h263_aic && h->c.mb_intra) {534 if (h->c.h263_aic && h->c.mb_intra) {
@@ -558,12 +559,12 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64], · 24 unmodified lines
558 h->c.rv10_first_dc_coded[component] = 1;559 h->c.rv10_first_dc_coded[component] = 1;
559 }560 }
560 } else {561 } else {
561 level = get_bits(&h->c.gb, 8);562 level = get_bits(&h->gb, 8);
562 if (level == 255)563 if (level == 255)
563 level = 128;564 level = 128;
564 }565 }
565 }else{566 }else{
566 level = get_bits(&h->c.gb, 8);567 level = get_bits(&h->gb, 8);
567 if((level&0x7F) == 0){568 if((level&0x7F) == 0){
568 av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",569 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 level, h->c.mb_x, h->c.mb_y);
@@ -584,60 +585,60 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64], · 14 unmodified lines
584 }585 }
585retry:586retry:
586 {587 {
587 OPEN_READER(re, &h->c.gb);588 OPEN_READER(re, &h->gb);
588 i--; // offset by -1 to allow direct indexing of scan_table589 i--; // offset by -1 to allow direct indexing of scan_table
589 for(;;) {590 for(;;) {
590 UPDATE_CACHE(re, &h->c.gb);591 UPDATE_CACHE(re, &h->gb);
591 GET_RL_VLC(level, run, re, &h->c.gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);592 GET_RL_VLC(level, run, re, &h->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
592 if (run == 66) {593 if (run == 66) {
593 if (level){594 if (level){
594 CLOSE_READER(re, &h->c.gb);595 CLOSE_READER(re, &h->gb);
595 av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",596 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 h->c.mb_x, h->c.mb_y);
597 return -1;598 return -1;
598 }599 }
599 /* escape */600 /* escape */
600 if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) {601 if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) {
601 int is11 = SHOW_UBITS(re, &h->c.gb, 1);602 int is11 = SHOW_UBITS(re, &h->gb, 1);
602 SKIP_CACHE(re, &h->c.gb, 1);603 SKIP_CACHE(re, &h->gb, 1);
603 run = SHOW_UBITS(re, &h->c.gb, 7) + 1;604 run = SHOW_UBITS(re, &h->gb, 7) + 1;
604 if (is11) {605 if (is11) {
605 SKIP_COUNTER(re, &h->c.gb, 1 + 7);606 SKIP_COUNTER(re, &h->gb, 1 + 7);
606 UPDATE_CACHE(re, &h->c.gb);607 UPDATE_CACHE(re, &h->gb);
607 level = SHOW_SBITS(re, &h->c.gb, 11);608 level = SHOW_SBITS(re, &h->gb, 11);
608 SKIP_COUNTER(re, &h->c.gb, 11);609 SKIP_COUNTER(re, &h->gb, 11);
609 } else {610 } else {
610 SKIP_CACHE(re, &h->c.gb, 7);611 SKIP_CACHE(re, &h->gb, 7);
611 level = SHOW_SBITS(re, &h->c.gb, 7);612 level = SHOW_SBITS(re, &h->gb, 7);
612 SKIP_COUNTER(re, &h->c.gb, 1 + 7 + 7);613 SKIP_COUNTER(re, &h->gb, 1 + 7 + 7);
613 }614 }
614 } else {615 } else {
615 run = SHOW_UBITS(re, &h->c.gb, 7) + 1;616 run = SHOW_UBITS(re, &h->gb, 7) + 1;
616 SKIP_CACHE(re, &h->c.gb, 7);617 SKIP_CACHE(re, &h->gb, 7);
617 level = (int8_t)SHOW_UBITS(re, &h->c.gb, 8);618 level = (int8_t)SHOW_UBITS(re, &h->gb, 8);
618 SKIP_COUNTER(re, &h->c.gb, 7 + 8);619 SKIP_COUNTER(re, &h->gb, 7 + 8);
619 if(level == -128){620 if(level == -128){
620 UPDATE_CACHE(re, &h->c.gb);621 UPDATE_CACHE(re, &h->gb);
621 if (h->c.codec_id == AV_CODEC_ID_RV10) {622 if (h->c.codec_id == AV_CODEC_ID_RV10) {
622 /* XXX: should patch encoder too */623 /* XXX: should patch encoder too */
623 level = SHOW_SBITS(re, &h->c.gb, 12);624 level = SHOW_SBITS(re, &h->gb, 12);
624 SKIP_COUNTER(re, &h->c.gb, 12);625 SKIP_COUNTER(re, &h->gb, 12);
625 }else{626 }else{
626 level = SHOW_UBITS(re, &h->c.gb, 5);627 level = SHOW_UBITS(re, &h->gb, 5);
627 SKIP_CACHE(re, &h->c.gb, 5);628 SKIP_CACHE(re, &h->gb, 5);
628 level |= SHOW_SBITS(re, &h->c.gb, 6) * (1<<5);629 level |= SHOW_SBITS(re, &h->gb, 6) * (1<<5);
629 SKIP_COUNTER(re, &h->c.gb, 5 + 6);630 SKIP_COUNTER(re, &h->gb, 5 + 6);
630 }631 }
631 }632 }
632 }633 }
633 } else {634 } else {
634 if (SHOW_UBITS(re, &h->c.gb, 1))635 if (SHOW_UBITS(re, &h->gb, 1))
635 level = -level;636 level = -level;
636 SKIP_COUNTER(re, &h->c.gb, 1);637 SKIP_COUNTER(re, &h->gb, 1);
637 }638 }
638 i += run;639 i += run;
639 if (i >= 64){640 if (i >= 64){
640 CLOSE_READER(re, &h->c.gb);641 CLOSE_READER(re, &h->gb);
641 // redo update without last flag, revert -1 offset642 // redo update without last flag, revert -1 offset
642 i = i - run + ((run-1)&63) + 1;643 i = i - run + ((run-1)&63) + 1;
643 if (i < 64) {644 if (i < 64) {
@@ -649,7 +650,7 @@ retry: · 5 unmodified lines
649 //Looks like a hack but no, it's the way it is supposed to work ...650 //Looks like a hack but no, it's the way it is supposed to work ...
650 rl = &ff_rl_intra_aic;651 rl = &ff_rl_intra_aic;
651 i = 0;652 i = 0;
652 h->c.gb = gb;653 h->gb = gb;
653 h->c.bdsp.clear_block(block);654 h->c.bdsp.clear_block(block);
654 goto retry;655 goto retry;
655 }656 }
@@ -787,7 +788,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 131 unmodified lines
787 788
788 if (h->c.pict_type == AV_PICTURE_TYPE_P) {789 if (h->c.pict_type == AV_PICTURE_TYPE_P) {
789 do{790 do{
790 if (get_bits1(&h->c.gb)) {791 if (get_bits1(&h->gb)) {
791 /* skip mb */792 /* skip mb */
792 h->c.mb_intra = 0;793 h->c.mb_intra = 0;
793 for(i=0;i<6;i++)794 for(i=0;i<6;i++)
@@ -800,7 +801,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 6 unmodified lines
800 h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter);801 h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter);
801 goto end;802 goto end;
802 }803 }
803 cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);804 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
804 if (cbpc < 0){805 if (cbpc < 0){
805 av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n",806 av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n",
806 h->c.mb_x, h->c.mb_y);807 h->c.mb_x, h->c.mb_y);
@@ -815,9 +816,9 @@ int ff_h263_decode_mb(H263DecContext *const h) · 8 unmodified lines
815 if (h->c.mb_intra)816 if (h->c.mb_intra)
816 goto intra;817 goto intra;
817 818
818 if(h->c.pb_frame && get_bits1(&h->c.gb))819 if (h->c.pb_frame && get_bits1(&h->gb))
819 pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);820 pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb);
820 cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);821 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
821 822
822 if (cbpy < 0) {823 if (cbpy < 0) {
823 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n",824 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n",
@@ -858,7 +859,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 34 unmodified lines
858 h->c.mv[0][0][1] = my;859 h->c.mv[0][0][1] = my;
859 860
860 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)861 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
861 skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */862 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
862 } else {863 } else {
863 h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;864 h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
864 h->c.mv_type = MV_TYPE_8X8;865 h->c.mv_type = MV_TYPE_8X8;
@@ -880,7 +881,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 15 unmodified lines
880 h->c.mv[0][i][0] = mx;881 h->c.mv[0][i][0] = mx;
881 h->c.mv[0][i][1] = my;882 h->c.mv[0][i][1] = my;
882 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)883 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
883 skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */884 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
884 mot_val[0] = mx;885 mot_val[0] = mx;
885 mot_val[1] = my;886 mot_val[1] = my;
886 }887 }
@@ -899,7 +900,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 12 unmodified lines
899 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;900 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
900 901
901 do{902 do{
902 mb_type = get_vlc2(&h->c.gb, h263_mbtype_b_vlc,903 mb_type = get_vlc2(&h->gb, h263_mbtype_b_vlc,
903 H263_MBTYPE_B_VLC_BITS, 2);904 H263_MBTYPE_B_VLC_BITS, 2);
904 if (mb_type < 0){905 if (mb_type < 0){
905 av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n",906 av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n",
@@ -911,13 +912,13 @@ int ff_h263_decode_mb(H263DecContext *const h) · 5 unmodified lines
911 h->c.mb_intra = IS_INTRA(mb_type);912 h->c.mb_intra = IS_INTRA(mb_type);
912 if(HAS_CBP(mb_type)){913 if(HAS_CBP(mb_type)){
913 h->c.bdsp.clear_blocks(h->block[0]);914 h->c.bdsp.clear_blocks(h->block[0]);
914 cbpc = get_vlc2(&h->c.gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);915 cbpc = get_vlc2(&h->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
915 if (h->c.mb_intra) {916 if (h->c.mb_intra) {
916 dquant = IS_QUANT(mb_type);917 dquant = IS_QUANT(mb_type);
917 goto intra;918 goto intra;
918 }919 }
919 920
920 cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);921 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
921 922
922 if (cbpy < 0){923 if (cbpy < 0){
923 av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n",924 av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n",
@@ -965,7 +966,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 41 unmodified lines
965 return SLICE_ERROR;966 return SLICE_ERROR;
966 967
967 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)968 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
968 skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */969 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
969 970
970 h->c.mv[0][0][0] = mx;971 h->c.mv[0][0][0] = mx;
971 h->c.mv[0][0][1] = my;972 h->c.mv[0][0][1] = my;
@@ -992,7 +993,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 20 unmodified lines
992 return SLICE_ERROR;993 return SLICE_ERROR;
993 994
994 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)995 if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
995 skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */996 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
996 997
997 h->c.mv[1][0][0] = mx;998 h->c.mv[1][0][0] = mx;
998 h->c.mv[1][0][1] = my;999 h->c.mv[1][0][1] = my;
@@ -1004,7 +1005,7 @@ int ff_h263_decode_mb(H263DecContext *const h) · 5 unmodified lines
1004 h->c.cur_pic.mb_type[xy] = mb_type;1005 h->c.cur_pic.mb_type[xy] = mb_type;
1005 } else { /* I-Frame */1006 } else { /* I-Frame */
1006 do{1007 do{
1007 cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);1008 cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
1008 if (cbpc < 0){1009 if (cbpc < 0){
1009 av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n",1010 av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n",
1010 h->c.mb_x, h->c.mb_y);1011 h->c.mb_x, h->c.mb_y);
@@ -1019,18 +1020,18 @@ int ff_h263_decode_mb(H263DecContext *const h) · 8 unmodified lines
1019intra:1020intra:
1020 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;1021 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1021 if (h->c.h263_aic) {1022 if (h->c.h263_aic) {
1022 h->c.ac_pred = get_bits1(&h->c.gb);1023 h->c.ac_pred = get_bits1(&h->gb);
1023 if (h->c.ac_pred) {1024 if (h->c.ac_pred) {
1024 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;1025 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
1025 1026
1026 h->c.h263_aic_dir = get_bits1(&h->c.gb);1027 h->c.h263_aic_dir = get_bits1(&h->gb);
1027 }1028 }
1028 }else1029 }else
1029 h->c.ac_pred = 0;1030 h->c.ac_pred = 0;
1030 1031
1031 if (h->c.pb_frame && get_bits1(&h->c.gb))1032 if (h->c.pb_frame && get_bits1(&h->gb))
1032 pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);1033 pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb);
1033 cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);1034 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1034 if(cbpy<0){1035 if(cbpy<0){
1035 av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",1036 av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
1036 h->c.mb_x, h->c.mb_y);1037 h->c.mb_x, h->c.mb_y);
@@ -1065,15 +1066,15 @@ intra: · 28 unmodified lines
1065 }1066 }
1066end:1067end:
1067 1068
1068 if (get_bits_left(&h->c.gb) < 0)1069 if (get_bits_left(&h->gb) < 0)
1069 return AVERROR_INVALIDDATA;1070 return AVERROR_INVALIDDATA;
1070 1071
1071 /* per-MB end of slice check */1072 /* per-MB end of slice check */
1072 {1073 {
1073 int v = show_bits(&h->c.gb, 16);1074 int v = show_bits(&h->gb, 16);
1074 1075
1075 if (get_bits_left(&h->c.gb) < 16) {1076 if (get_bits_left(&h->gb) < 16) {
1076 v >>= 16 - get_bits_left(&h->c.gb);1077 v >>= 16 - get_bits_left(&h->gb);
1077 }1078 }
1078 1079
1079 if(v==0)1080 if(v==0)
@@ -1089,16 +1090,16 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 9 unmodified lines
1089 int width, height, i, ret;1090 int width, height, i, ret;
1090 int h263_plus;1091 int h263_plus;
1091 1092
1092 align_get_bits(&h->c.gb);1093 align_get_bits(&h->gb);
1093 1094
1094 if (show_bits(&h->c.gb, 2) == 2 && h->c.avctx->frame_num == 0) {1095 if (show_bits(&h->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");1096 av_log(h->c.avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
1096 }1097 }
1097 1098
1098 uint32_t startcode = get_bits(&h->c.gb, 22-8);1099 uint32_t startcode = get_bits(&h->gb, 22-8);
1099 1100
1100 for (i = get_bits_left(&h->c.gb); i>24; i -= 8) {1101 for (i = get_bits_left(&h->gb); i>24; i -= 8) {
1101 startcode = ((startcode << 8) | get_bits(&h->c.gb, 8)) & 0x003FFFFF;1102 startcode = ((startcode << 8) | get_bits(&h->gb, 8)) & 0x003FFFFF;
1102 1103
1103 if(startcode == 0x20)1104 if(startcode == 0x20)
1104 break;1105 break;
@@ -1109,25 +1110,25 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 4 unmodified lines
1109 return -1;1110 return -1;
1110 }1111 }
1111 /* temporal reference */1112 /* temporal reference */
1112 i = get_bits(&h->c.gb, 8); /* picture timestamp */1113 i = get_bits(&h->gb, 8); /* picture timestamp */
1113 1114
1114 i -= (i - (h->c.picture_number & 0xFF) + 128) & ~0xFF;1115 i -= (i - (h->c.picture_number & 0xFF) + 128) & ~0xFF;
1115 1116
1116 h->c.picture_number = (h->c.picture_number&~0xFF) + i;1117 h->c.picture_number = (h->c.picture_number&~0xFF) + i;
1117 1118
1118 /* PTYPE starts here */1119 /* PTYPE starts here */
1119 if (check_marker(h->c.avctx, &h->c.gb, "in PTYPE") != 1) {1120 if (check_marker(h->c.avctx, &h->gb, "in PTYPE") != 1) {
1120 return -1;1121 return -1;
1121 }1122 }
1122 if (get_bits1(&h->c.gb) != 0) {1123 if (get_bits1(&h->gb) != 0) {
1123 av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");1124 av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
1124 return -1; /* H.263 id */1125 return -1; /* H.263 id */
1125 }1126 }
1126 skip_bits1(&h->c.gb); /* split screen off */1127 skip_bits1(&h->gb); /* split screen off */
1127 skip_bits1(&h->c.gb); /* camera off */1128 skip_bits1(&h->gb); /* camera off */
1128 skip_bits1(&h->c.gb); /* freeze picture release off */1129 skip_bits1(&h->gb); /* freeze picture release off */
1129 1130
1130 int format = get_bits(&h->c.gb, 3);1131 int format = get_bits(&h->gb, 3);
1131 /*1132 /*
1132 0 forbidden1133 0 forbidden
1133 1 sub-QCIF1134 1 sub-QCIF
@@ -1143,19 +1144,19 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 9 unmodified lines
1143 if (!width)1144 if (!width)
1144 return -1;1145 return -1;
1145 1146
1146 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);1147 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
1147 1148
1148 h->c.h263_long_vectors = get_bits1(&h->c.gb);1149 h->c.h263_long_vectors = get_bits1(&h->gb);
1149 1150
1150 if (get_bits1(&h->c.gb) != 0) {1151 if (get_bits1(&h->gb) != 0) {
1151 av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");1152 av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
1152 return -1; /* SAC: off */1153 return -1; /* SAC: off */
1153 }1154 }
1154 h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */1155 h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
1155 1156
1156 h->c.pb_frame = get_bits1(&h->c.gb);1157 h->c.pb_frame = get_bits1(&h->gb);
1157 h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);1158 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
1158 skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */1159 skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
1159 1160
1160 h->c.width = width;1161 h->c.width = width;
1161 h->c.height = height;1162 h->c.height = height;
@@ -1166,46 +1167,46 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 4 unmodified lines
1166 1167
1167 /* H.263v2 */1168 /* H.263v2 */
1168 h263_plus = 1;1169 h263_plus = 1;
1169 ufep = get_bits(&h->c.gb, 3); /* Update Full Extended PTYPE */1170 ufep = get_bits(&h->gb, 3); /* Update Full Extended PTYPE */
1170 1171
1171 /* ufep other than 0 and 1 are reserved */1172 /* ufep other than 0 and 1 are reserved */
1172 if (ufep == 1) {1173 if (ufep == 1) {
1173 /* OPPTYPE */1174 /* OPPTYPE */
1174 format = get_bits(&h->c.gb, 3);1175 format = get_bits(&h->gb, 3);
1175 ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);1176 ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
1176 h->c.custom_pcf = get_bits1(&h->c.gb);1177 h->c.custom_pcf = get_bits1(&h->gb);
1177 h->c.umvplus = get_bits1(&h->c.gb); /* Unrestricted Motion Vector */1178 h->c.umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */
1178 if (get_bits1(&h->c.gb) != 0) {1179 if (get_bits1(&h->gb) != 0) {
1179 av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");1180 av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
1180 }1181 }
1181 h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */1182 h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
1182 h->c.h263_aic = get_bits1(&h->c.gb); /* Advanced Intra Coding (AIC) */1183 h->c.h263_aic = get_bits1(&h->gb); /* Advanced Intra Coding (AIC) */
1183 h->c.loop_filter = get_bits1(&h->c.gb);1184 h->c.loop_filter = get_bits1(&h->gb);
1184 if (h->c.avctx->lowres)1185 if (h->c.avctx->lowres)
1185 h->c.loop_filter = 0;1186 h->c.loop_filter = 0;
1186 1187
1187 h->c.h263_slice_structured= get_bits1(&h->c.gb);1188 h->c.h263_slice_structured = get_bits1(&h->gb);
1188 if (get_bits1(&h->c.gb) != 0) {1189 if (get_bits1(&h->gb) != 0) {
1189 av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");1190 av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
1190 }1191 }
1191 if (get_bits1(&h->c.gb) != 0) {1192 if (get_bits1(&h->gb) != 0) {
1192 av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");1193 av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
1193 }1194 }
1194 h->c.alt_inter_vlc = get_bits1(&h->c.gb);1195 h->c.alt_inter_vlc = get_bits1(&h->gb);
1195 h->c.modified_quant = get_bits1(&h->c.gb);1196 h->c.modified_quant = get_bits1(&h->gb);
1196 if (h->c.modified_quant)1197 if (h->c.modified_quant)
1197 h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;1198 h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;
1198 1199
1199 skip_bits(&h->c.gb, 1); /* Prevent start code emulation */1200 skip_bits(&h->gb, 1); /* Prevent start code emulation */
1200 1201
1201 skip_bits(&h->c.gb, 3); /* Reserved */1202 skip_bits(&h->gb, 3); /* Reserved */
1202 } else if (ufep != 0) {1203 } else if (ufep != 0) {
1203 av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);1204 av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
1204 return -1;1205 return -1;
1205 }1206 }
1206 1207
1207 /* MPPTYPE */1208 /* MPPTYPE */
1208 h->c.pict_type = get_bits(&h->c.gb, 3);1209 h->c.pict_type = get_bits(&h->gb, 3);
1209 switch (h->c.pict_type) {1210 switch (h->c.pict_type) {
1210 case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break;1211 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 1: h->c.pict_type = AV_PICTURE_TYPE_P; break;
@@ -1215,15 +1216,15 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 3 unmodified lines
1215 default:1216 default:
1216 return -1;1217 return -1;
1217 }1218 }
1218 skip_bits(&h->c.gb, 2);1219 skip_bits(&h->gb, 2);
1219 h->c.no_rounding = get_bits1(&h->c.gb);1220 h->c.no_rounding = get_bits1(&h->gb);
1220 skip_bits(&h->c.gb, 4);1221 skip_bits(&h->gb, 4);
1221 1222
1222 /* Get the picture dimensions */1223 /* Get the picture dimensions */
1223 if (ufep) {1224 if (ufep) {
1224 if (format == 6) {1225 if (format == 6) {
1225 /* Custom Picture Format (CPFMT) */1226 /* Custom Picture Format (CPFMT) */
1226 int aspect_ratio_info = get_bits(&h->c.gb, 4);1227 int aspect_ratio_info = get_bits(&h->gb, 4);
1227 ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info);1228 ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info);
1228 /* aspect ratios:1229 /* aspect ratios:
1229 0 - forbidden1230 0 - forbidden
@@ -1234,14 +1235,14 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 4 unmodified lines
1234 5 - 40:33 (525-type 16:9)1235 5 - 40:33 (525-type 16:9)
1235 6-14 - reserved1236 6-14 - reserved
1236 */1237 */
1237 width = (get_bits(&h->c.gb, 9) + 1) * 4;1238 width = (get_bits(&h->gb, 9) + 1) * 4;
1238 check_marker(h->c.avctx, &h->c.gb, "in dimensions");1239 check_marker(h->c.avctx, &h->gb, "in dimensions");
1239 height = get_bits(&h->c.gb, 9) * 4;1240 height = get_bits(&h->gb, 9) * 4;
1240 ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);1241 ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1241 if (aspect_ratio_info == FF_ASPECT_EXTENDED) {1242 if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
1242 /* expected dimensions */1243 /* expected dimensions */
1243 h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8);1244 h->c.avctx->sample_aspect_ratio.num = get_bits(&h->gb, 8);
1244 h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8);1245 h->c.avctx->sample_aspect_ratio.den = get_bits(&h->gb, 8);
1245 }else{1246 }else{
1246 h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];1247 h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
1247 }1248 }
@@ -1258,8 +1259,8 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 10 unmodified lines
1258 1259
1259 if (h->c.custom_pcf) {1260 if (h->c.custom_pcf) {
1260 h->c.avctx->framerate.num = 1800000;1261 h->c.avctx->framerate.num = 1800000;
1261 h->c.avctx->framerate.den = 1000 + get_bits1(&h->c.gb);1262 h->c.avctx->framerate.den = 1000 + get_bits1(&h->gb);
1262 h->c.avctx->framerate.den *= get_bits(&h->c.gb, 7);1263 h->c.avctx->framerate.den *= get_bits(&h->gb, 7);
1263 if (h->c.avctx->framerate.den == 0) {1264 if (h->c.avctx->framerate.den == 0) {
1264 av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n");1265 av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n");
1265 return -1;1266 return -1;
@@ -1273,30 +1274,30 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 7 unmodified lines
1273 }1274 }
1274 1275
1275 if (h->c.custom_pcf)1276 if (h->c.custom_pcf)
1276 skip_bits(&h->c.gb, 2); //extended Temporal reference1277 skip_bits(&h->gb, 2); //extended Temporal reference
1277 1278
1278 if (ufep) {1279 if (ufep) {
1279 if (h->c.umvplus) {1280 if (h->c.umvplus) {
1280 if(get_bits1(&h->c.gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */1281 if (get_bits1(&h->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1281 skip_bits1(&h->c.gb);1282 skip_bits1(&h->gb);
1282 }1283 }
1283 if (h->c.h263_slice_structured) {1284 if (h->c.h263_slice_structured) {
1284 if (get_bits1(&h->c.gb) != 0) {1285 if (get_bits1(&h->gb) != 0) {
1285 av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");1286 av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1286 }1287 }
1287 if (get_bits1(&h->c.gb) != 0) {1288 if (get_bits1(&h->gb) != 0) {
1288 av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n");1289 av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1289 }1290 }
1290 }1291 }
1291 if (h->c.pict_type == AV_PICTURE_TYPE_B) {1292 if (h->c.pict_type == AV_PICTURE_TYPE_B) {
1292 skip_bits(&h->c.gb, 4); //ELNUM1293 skip_bits(&h->gb, 4); //ELNUM
1293 if (ufep == 1) {1294 if (ufep == 1) {
1294 skip_bits(&h->c.gb, 4); // RLNUM1295 skip_bits(&h->gb, 4); // RLNUM
1295 }1296 }
1296 }1297 }
1297 }1298 }
1298 1299
1299 h->c.qscale = get_bits(&h->c.gb, 5);1300 h->c.qscale = get_bits(&h->gb, 5);
1300 }1301 }
1301 1302
1302 ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx);1303 ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx);
@@ -1304,7 +1305,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 1 unmodified line
1304 return ret;1305 return ret;
1305 1306
1306 if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {1307 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))1308 if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->gb))
1308 return AVERROR_INVALIDDATA;1309 return AVERROR_INVALIDDATA;
1309 }1310 }
1310 1311
@@ -1315,10 +1316,10 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 4 unmodified lines
1315 h->c.gob_index = H263_GOB_HEIGHT(h->c.height);1316 h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
1316 1317
1317 if (h->c.pb_frame) {1318 if (h->c.pb_frame) {
1318 skip_bits(&h->c.gb, 3); /* Temporal reference for B-pictures */1319 skip_bits(&h->gb, 3); /* Temporal reference for B-pictures */
1319 if (h->c.custom_pcf)1320 if (h->c.custom_pcf)
1320 skip_bits(&h->c.gb, 2); //extended Temporal reference1321 skip_bits(&h->gb, 2); //extended Temporal reference
1321 skip_bits(&h->c.gb, 2); /* Quantization information for B-pictures */1322 skip_bits(&h->gb, 2); /* Quantization information for B-pictures */
1322 }1323 }
1323 1324
1324 if (h->c.pict_type!=AV_PICTURE_TYPE_B) {1325 if (h->c.pict_type!=AV_PICTURE_TYPE_B) {
@@ -1338,17 +1339,17 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 13 unmodified lines
1338 }1339 }
1339 1340
1340 /* PEI */1341 /* PEI */
1341 if (skip_1stop_8data_bits(&h->c.gb) < 0)1342 if (skip_1stop_8data_bits(&h->gb) < 0)
1342 return AVERROR_INVALIDDATA;1343 return AVERROR_INVALIDDATA;
1343 1344
1344 if (h->c.h263_slice_structured) {1345 if (h->c.h263_slice_structured) {
1345 if (check_marker(h->c.avctx, &h->c.gb, "SEPB1") != 1) {1346 if (check_marker(h->c.avctx, &h->gb, "SEPB1") != 1) {
1346 return -1;1347 return -1;
1347 }1348 }
1348 1349
1349 ff_h263_decode_mba(h);1350 ff_h263_decode_mba(h);
1350 1351
1351 if (check_marker(h->c.avctx, &h->c.gb, "SEPB2") != 1) {1352 if (check_marker(h->c.avctx, &h->gb, "SEPB2") != 1) {
1352 return -1;1353 return -1;
1353 }1354 }
1354 }1355 }
@@ -1366,19 +1367,19 @@ int ff_h263_decode_picture_header(H263DecContext *const h) · 11 unmodified lines
1366 1367
1367 ff_h263_show_pict_info(h, h263_plus);1368 ff_h263_show_pict_info(h, h263_plus);
1368 1369
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){1370 if (h->c.pict_type == AV_PICTURE_TYPE_I && h->c.codec_tag == AV_RL32("ZYGO") && get_bits_left(&h->gb) >= 85 + 13*3*16 + 50){
1370 int i,j;1371 int i,j;
1371 for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));1372 for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
1372 av_log(h->c.avctx, AV_LOG_DEBUG, "\n");1373 av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
1373 for(i=0; i<13; i++){1374 for(i=0; i<13; i++){
1374 for(j=0; j<3; j++){1375 for(j=0; j<3; j++){
1375 int v= get_bits(&h->c.gb, 8);1376 int v= get_bits(&h->gb, 8);
1376 v |= get_sbits(&h->c.gb, 8) * (1 << 8);1377 v |= get_sbits(&h->gb, 8) * (1 << 8);
1377 av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v);1378 av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v);
1378 }1379 }
1379 av_log(h->c.avctx, AV_LOG_DEBUG, "\n");1380 av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
1380 }1381 }
1381 for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));1382 for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
1382 }1383 }
1383 1384
1384 return 0;1385 return 0;
libavcodec/mpeg12dec.c+5−5
@@ -479,7 +479,7 @@ static int mpeg_decode_mb(MPVContext *const s) · 478 unmodified lines
479 s->interlaced_dct = get_bits1(&s->gb);479 s->interlaced_dct = get_bits1(&s->gb);
480 480
481 if (IS_QUANT(mb_type))481 if (IS_QUANT(mb_type))
482 s->qscale = mpeg_get_qscale(s);482 s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
483 483
484 if (s->concealment_motion_vectors) {484 if (s->concealment_motion_vectors) {
485 /* just parse them */485 /* just parse them */
@@ -537,7 +537,7 @@ static int mpeg_decode_mb(MPVContext *const s) · 51 unmodified lines
537 }537 }
538 538
539 if (IS_QUANT(mb_type))539 if (IS_QUANT(mb_type))
540 s->qscale = mpeg_get_qscale(s);540 s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
541 541
542 s->last_mv[0][0][0] = 0;542 s->last_mv[0][0][0] = 0;
543 s->last_mv[0][0][1] = 0;543 s->last_mv[0][0][1] = 0;
@@ -558,7 +558,7 @@ static int mpeg_decode_mb(MPVContext *const s) · 14 unmodified lines
558 }558 }
559 559
560 if (IS_QUANT(mb_type))560 if (IS_QUANT(mb_type))
561 s->qscale = mpeg_get_qscale(s);561 s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
562 562
563 /* motion vectors */563 /* motion vectors */
564 s->mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);564 s->mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);
@@ -1370,7 +1370,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, · 805 unmodified lines
1370 ff_mpeg1_clean_buffers(s);1370 ff_mpeg1_clean_buffers(s);
1371 s->interlaced_dct = 0;1371 s->interlaced_dct = 0;
1372 1372
1373 s->qscale = mpeg_get_qscale(s);1373 s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
1374 1374
1375 if (s->qscale == 0) {1375 if (s->qscale == 0) {
1376 av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");1376 av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
@@ -2805,7 +2805,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 1428 unmodified lines
2805 skip_bits1(gb);2805 skip_bits1(gb);
2806 2806
2807 if (intraquant)2807 if (intraquant)
2808 m->qscale = mpeg_get_qscale(m);2808 m->qscale = mpeg_get_qscale(&m->gb, m->q_scale_type);
2809 2809
2810 memset(s->block, 0, sizeof(s->block));2810 memset(s->block, 0, sizeof(s->block));
2811 2811
libavcodec/mpeg4videodec.c+160−160
@@ -383,8 +383,8 @@ void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir) · 382 unmodified lines
383static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)383static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
384{384{
385 H263DecContext *const h = &ctx->h;385 H263DecContext *const h = &ctx->h;
386 int bits_count = get_bits_count(&h->c.gb);386 int bits_count = get_bits_count(&h->gb);
387 int v = show_bits(&h->c.gb, 16);387 int v = show_bits(&h->gb, 16);
388 388
389 if (h->c.workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)389 if (h->c.workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
390 return 0;390 return 0;
@@ -393,12 +393,12 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) · 2 unmodified lines
393 if (h->c.pict_type == AV_PICTURE_TYPE_B ||393 if (h->c.pict_type == AV_PICTURE_TYPE_B ||
394 (v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame)394 (v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame)
395 break;395 break;
396 skip_bits(&h->c.gb, 8 + h->c.pict_type);396 skip_bits(&h->gb, 8 + h->c.pict_type);
397 bits_count += 8 + h->c.pict_type;397 bits_count += 8 + h->c.pict_type;
398 v = show_bits(&h->c.gb, 16);398 v = show_bits(&h->gb, 16);
399 }399 }
400 400
401 if (bits_count + 8 >= h->c.gb.size_in_bits) {401 if (bits_count + 8 >= h->gb.size_in_bits) {
402 v >>= 8;402 v >>= 8;
403 v |= 0x7F >> (7 - (bits_count & 7));403 v |= 0x7F >> (7 - (bits_count & 7));
404 404
@@ -412,20 +412,20 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) · 7 unmodified lines
412 if (v == mpeg4_resync_prefix[bits_count & 7]) {412 if (v == mpeg4_resync_prefix[bits_count & 7]) {
413 int len, mb_num;413 int len, mb_num;
414 int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;414 int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
415 GetBitContext gb = h->c.gb;415 GetBitContext gb = h->gb;
416 416
417 skip_bits(&h->c.gb, 1);417 skip_bits(&h->gb, 1);
418 align_get_bits(&h->c.gb);418 align_get_bits(&h->gb);
419 419
420 for (len = 0; len < 32; len++)420 for (len = 0; len < 32; len++)
421 if (get_bits1(&h->c.gb))421 if (get_bits1(&h->gb))
422 break;422 break;
423 423
424 mb_num = get_bits(&h->c.gb, mb_num_bits);424 mb_num = get_bits(&h->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)425 if (!mb_num || mb_num > h->c.mb_num || get_bits_count(&h->gb) + 6 > h->gb.size_in_bits)
426 mb_num= -1;426 mb_num= -1;
427 427
428 h->c.gb = gb;428 h->gb = gb;
429 429
430 if (len >= ff_mpeg4_get_video_packet_prefix_length(h->c.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))
431 return mb_num;431 return mb_num;
@@ -713,11 +713,11 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h) · 281 unmodified lines
713 int header_extension = 0, mb_num, len;713 int header_extension = 0, mb_num, len;
714 714
715 /* is there enough space left for a video packet + header */715 /* is there enough space left for a video packet + header */
716 if (get_bits_count(&h->c.gb) > h->c.gb.size_in_bits - 20)716 if (get_bits_count(&h->gb) > h->gb.size_in_bits - 20)
717 return AVERROR_INVALIDDATA;717 return AVERROR_INVALIDDATA;
718 718
719 for (len = 0; len < 32; len++)719 for (len = 0; len < 32; len++)
720 if (get_bits1(&h->c.gb))720 if (get_bits1(&h->gb))
721 break;721 break;
722 722
723 if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) {723 if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) {
@@ -726,11 +726,11 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h) · 2 unmodified lines
726 }726 }
727 727
728 if (ctx->shape != RECT_SHAPE) {728 if (ctx->shape != RECT_SHAPE) {
729 header_extension = get_bits1(&h->c.gb);729 header_extension = get_bits1(&h->gb);
730 // FIXME more stuff here730 // FIXME more stuff here
731 }731 }
732 732
733 mb_num = get_bits(&h->c.gb, mb_num_bits);733 mb_num = get_bits(&h->gb, mb_num_bits);
734 if (mb_num >= h->c.mb_num || !mb_num) {734 if (mb_num >= h->c.mb_num || !mb_num) {
735 av_log(h->c.avctx, AV_LOG_ERROR,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);736 "illegal mb_num in video packet (%d %d) \n", mb_num, h->c.mb_num);
@@ -741,31 +741,31 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h) · 4 unmodified lines
741 h->c.mb_y = mb_num / h->c.mb_width;741 h->c.mb_y = mb_num / h->c.mb_width;
742 742
743 if (ctx->shape != BIN_ONLY_SHAPE) {743 if (ctx->shape != BIN_ONLY_SHAPE) {
744 int qscale = get_bits(&h->c.gb, ctx->quant_precision);744 int qscale = get_bits(&h->gb, ctx->quant_precision);
745 if (qscale)745 if (qscale)
746 h->c.chroma_qscale = h->c.qscale = qscale;746 h->c.chroma_qscale = h->c.qscale = qscale;
747 }747 }
748 748
749 if (ctx->shape == RECT_SHAPE)749 if (ctx->shape == RECT_SHAPE)
750 header_extension = get_bits1(&h->c.gb);750 header_extension = get_bits1(&h->gb);
751 751
752 if (header_extension) {752 if (header_extension) {
753 while (get_bits1(&h->c.gb) != 0)753 while (get_bits1(&h->gb) != 0)
754 ;754 ;
755 755
756 check_marker(h->c.avctx, &h->c.gb, "before time_increment in video packed header");756 check_marker(h->c.avctx, &h->gb, "before time_increment in video packed header");
757 skip_bits(&h->c.gb, ctx->time_increment_bits); /* time_increment */757 skip_bits(&h->gb, ctx->time_increment_bits); /* time_increment */
758 check_marker(h->c.avctx, &h->c.gb, "before vop_coding_type in video packed header");758 check_marker(h->c.avctx, &h->gb, "before vop_coding_type in video packed header");
759 759
760 skip_bits(&h->c.gb, 2); /* vop coding type */760 skip_bits(&h->gb, 2); /* vop coding type */
761 // FIXME not rect stuff here761 // FIXME not rect stuff here
762 762
763 if (ctx->shape != BIN_ONLY_SHAPE) {763 if (ctx->shape != BIN_ONLY_SHAPE) {
764 skip_bits(&h->c.gb, 3); /* intra dc vlc threshold */764 skip_bits(&h->gb, 3); /* intra dc vlc threshold */
765 // FIXME don't just ignore everything765 // FIXME don't just ignore everything
766 if (h->c.pict_type == AV_PICTURE_TYPE_S &&766 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
767 ctx->vol_sprite_usage == GMC_SPRITE) {767 ctx->vol_sprite_usage == GMC_SPRITE) {
768 if (mpeg4_decode_sprite_trajectory(ctx, &h->c.gb) < 0)768 if (mpeg4_decode_sprite_trajectory(ctx, &h->gb) < 0)
769 return AVERROR_INVALIDDATA;769 return AVERROR_INVALIDDATA;
770 av_log(h->c.avctx, AV_LOG_ERROR, "untested\n");770 av_log(h->c.avctx, AV_LOG_ERROR, "untested\n");
771 }771 }
@@ -773,13 +773,13 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h) · 1 unmodified line
773 // FIXME reduced res stuff here773 // FIXME reduced res stuff here
774 774
775 if (h->c.pict_type != AV_PICTURE_TYPE_I) {775 if (h->c.pict_type != AV_PICTURE_TYPE_I) {
776 int f_code = get_bits(&h->c.gb, 3); /* fcode_for */776 int f_code = get_bits(&h->gb, 3); /* fcode_for */
777 if (f_code == 0)777 if (f_code == 0)
778 av_log(h->c.avctx, AV_LOG_ERROR,778 av_log(h->c.avctx, AV_LOG_ERROR,
779 "Error, video packet header damaged (f_code=0)\n");779 "Error, video packet header damaged (f_code=0)\n");
780 }780 }
781 if (h->c.pict_type == AV_PICTURE_TYPE_B) {781 if (h->c.pict_type == AV_PICTURE_TYPE_B) {
782 int b_code = get_bits(&h->c.gb, 3);782 int b_code = get_bits(&h->gb, 3);
783 if (b_code == 0)783 if (b_code == 0)
784 av_log(h->c.avctx, AV_LOG_ERROR,784 av_log(h->c.avctx, AV_LOG_ERROR,
785 "Error, video packet header damaged (b_code=0)\n");785 "Error, video packet header damaged (b_code=0)\n");
@@ -787,7 +787,7 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h) · 1 unmodified line
787 }787 }
788 }788 }
789 if (ctx->new_pred)789 if (ctx->new_pred)
790 decode_new_pred(ctx, &h->c.gb);790 decode_new_pred(ctx, &h->gb);
791 791
792 return 0;792 return 0;
793}793}
@@ -808,7 +808,7 @@ static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx) · 14 unmodified lines
808int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)808int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
809{809{
810 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);810 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
811 GetBitContext *gb = &h->c.gb;811 GetBitContext *gb = &h->gb;
812 unsigned vlc_len;812 unsigned vlc_len;
813 uint16_t mb_num;813 uint16_t mb_num;
814 814
@@ -823,7 +823,7 @@ int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h) · 8 unmodified lines
823 h->c.mb_y = mb_num / h->c.mb_width;823 h->c.mb_y = mb_num / h->c.mb_width;
824 824
825 if (ctx->shape != BIN_ONLY_SHAPE)825 if (ctx->shape != BIN_ONLY_SHAPE)
826 h->c.qscale = mpeg_get_qscale(&h->c);826 h->c.qscale = mpeg_get_qscale(&h->gb, h->c.q_scale_type);
827 827
828 if (get_bits1(gb)) { /* slice_extension_flag */828 if (get_bits1(gb)) { /* slice_extension_flag */
829 skip_bits1(gb); /* intra_slice */829 skip_bits1(gb); /* intra_slice */
@@ -985,9 +985,9 @@ static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr) · 155 unmodified lines
985 int level, code, pred;985 int level, code, pred;
986 986
987 if (n < 4)987 if (n < 4)
988 code = get_vlc2(&h->c.gb, dc_lum, DC_VLC_BITS, 1);988 code = get_vlc2(&h->gb, dc_lum, DC_VLC_BITS, 1);
989 else989 else
990 code = get_vlc2(&h->c.gb, dc_chrom, DC_VLC_BITS, 1);990 code = get_vlc2(&h->gb, dc_chrom, DC_VLC_BITS, 1);
991 991
992 if (code < 0) {992 if (code < 0) {
993 av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");993 av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
@@ -999,19 +999,19 @@ static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr) · 5 unmodified lines
999 } else {999 } else {
1000 if (IS_3IV1) {1000 if (IS_3IV1) {
1001 if (code == 1)1001 if (code == 1)
1002 level = 2 * get_bits1(&h->c.gb) - 1;1002 level = 2 * get_bits1(&h->gb) - 1;
1003 else {1003 else {
1004 if (get_bits1(&h->c.gb))1004 if (get_bits1(&h->gb))
1005 level = get_bits(&h->c.gb, code - 1) + (1 << (code - 1));1005 level = get_bits(&h->gb, code - 1) + (1 << (code - 1));
1006 else1006 else
1007 level = -get_bits(&h->c.gb, code - 1) - (1 << (code - 1));1007 level = -get_bits(&h->gb, code - 1) - (1 << (code - 1));
1008 }1008 }
1009 } else {1009 } else {
1010 level = get_xbits(&h->c.gb, code);1010 level = get_xbits(&h->gb, code);
1011 }1011 }
1012 1012
1013 if (code > 8) {1013 if (code > 8) {
1014 if (get_bits1(&h->c.gb) == 0) { /* marker */1014 if (get_bits1(&h->gb) == 0) { /* marker */
1015 if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {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");1016 av_log(h->c.avctx, AV_LOG_ERROR, "dc marker bit missing\n");
1017 return AVERROR_INVALIDDATA;1017 return AVERROR_INVALIDDATA;
@@ -1052,10 +1052,10 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) · 34 unmodified lines
1052 int i;1052 int i;
1053 1053
1054 do {1054 do {
1055 if (show_bits(&h->c.gb, 19) == DC_MARKER)1055 if (show_bits(&h->gb, 19) == DC_MARKER)
1056 return mb_num - 1;1056 return mb_num - 1;
1057 1057
1058 cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);1058 cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
1059 if (cbpc < 0) {1059 if (cbpc < 0) {
1060 av_log(h->c.avctx, AV_LOG_ERROR,1060 av_log(h->c.avctx, AV_LOG_ERROR,
1061 "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);1061 "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1068,7 +1068,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) · 6 unmodified lines
1068 h->c.mb_intra = 1;1068 h->c.mb_intra = 1;
1069 1069
1070 if (cbpc & 4)1070 if (cbpc & 4)
1071 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);1071 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1072 1072
1073 h->c.cur_pic.qscale_table[xy] = h->c.qscale;1073 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1074 1074
@@ -1092,11 +1092,11 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) · 17 unmodified lines
1092 const int stride = h->c.b8_stride * 2;1092 const int stride = h->c.b8_stride * 2;
1093 1093
1094try_again:1094try_again:
1095 bits = show_bits(&h->c.gb, 17);1095 bits = show_bits(&h->gb, 17);
1096 if (bits == MOTION_MARKER)1096 if (bits == MOTION_MARKER)
1097 return mb_num - 1;1097 return mb_num - 1;
1098 1098
1099 skip_bits1(&h->c.gb);1099 skip_bits1(&h->gb);
1100 if (bits & 0x10000) {1100 if (bits & 0x10000) {
1101 /* skip mb */1101 /* skip mb */
1102 if (h->c.pict_type == AV_PICTURE_TYPE_S &&1102 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
@@ -1126,7 +1126,7 @@ try_again: · 23 unmodified lines
1126 continue;1126 continue;
1127 }1127 }
1128 1128
1129 cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);1129 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
1130 if (cbpc < 0) {1130 if (cbpc < 0) {
1131 av_log(h->c.avctx, AV_LOG_ERROR,1131 av_log(h->c.avctx, AV_LOG_ERROR,
1132 "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);1132 "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1156,7 +1156,7 @@ try_again: · 23 unmodified lines
1156 if (h->c.pict_type == AV_PICTURE_TYPE_S &&1156 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
1157 ctx->vol_sprite_usage == GMC_SPRITE &&1157 ctx->vol_sprite_usage == GMC_SPRITE &&
1158 (cbpc & 16) == 0)1158 (cbpc & 16) == 0)
1159 h->c.mcsel = get_bits1(&h->c.gb);1159 h->c.mcsel = get_bits1(&h->gb);
1160 else1160 else
1161 h->c.mcsel = 0;1161 h->c.mcsel = 0;
1162 1162
@@ -1238,8 +1238,8 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count) · 75 unmodified lines
1238 h->c.first_slice_line = 0;1238 h->c.first_slice_line = 0;
1239 1239
1240 if (h->c.pict_type == AV_PICTURE_TYPE_I) {1240 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
1241 int ac_pred = get_bits1(&h->c.gb);1241 int ac_pred = get_bits1(&h->gb);
1242 int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);1242 int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1243 if (cbpy < 0) {1243 if (cbpy < 0) {
1244 av_log(h->c.avctx, AV_LOG_ERROR,1244 av_log(h->c.avctx, AV_LOG_ERROR,
1245 "cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);1245 "cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1252,8 +1252,8 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count) · 6 unmodified lines
1252 if (IS_INTRA(h->c.cur_pic.mb_type[xy])) {1252 if (IS_INTRA(h->c.cur_pic.mb_type[xy])) {
1253 int i;1253 int i;
1254 int dir = 0;1254 int dir = 0;
1255 int ac_pred = get_bits1(&h->c.gb);1255 int ac_pred = get_bits1(&h->gb);
1256 int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);1256 int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1257 1257
1258 if (cbpy < 0) {1258 if (cbpy < 0) {
1259 av_log(h->c.avctx, AV_LOG_ERROR,1259 av_log(h->c.avctx, AV_LOG_ERROR,
@@ -1262,7 +1262,7 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count) · 2 unmodified lines
1262 }1262 }
1263 1263
1264 if (h->c.cbp_table[xy] & 8)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)]);1265 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1266 h->c.cur_pic.qscale_table[xy] = h->c.qscale;1266 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1267 1267
1268 for (i = 0; i < 6; i++) {1268 for (i = 0; i < 6; i++) {
@@ -1285,7 +1285,7 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count) · 16 unmodified lines
1285 h->c.cur_pic.qscale_table[xy] = h->c.qscale;1285 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1286 h->c.cbp_table[xy] = 0;1286 h->c.cbp_table[xy] = 0;
1287 } else {1287 } else {
1288 int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);1288 int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1289 1289
1290 if (cbpy < 0) {1290 if (cbpy < 0) {
1291 av_log(h->c.avctx, AV_LOG_ERROR,1291 av_log(h->c.avctx, AV_LOG_ERROR,
@@ -1294,7 +1294,7 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count) · 2 unmodified lines
1294 }1294 }
1295 1295
1296 if (h->c.cbp_table[xy] & 8)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)]);1297 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1298 h->c.cur_pic.qscale_table[xy] = h->c.qscale;1298 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1299 1299
1300 h->c.cbp_table[xy] &= 3; // remove dquant1300 h->c.cbp_table[xy] &= 3; // remove dquant
@@ -1338,18 +1338,18 @@ int ff_mpeg4_decode_partitions(H263DecContext *const h) · 37 unmodified lines
1338 h->c.mb_num_left = mb_num;1338 h->c.mb_num_left = mb_num;
1339 1339
1340 if (h->c.pict_type == AV_PICTURE_TYPE_I) {1340 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
1341 while (show_bits(&h->c.gb, 9) == 1)1341 while (show_bits(&h->gb, 9) == 1)
1342 skip_bits(&h->c.gb, 9);1342 skip_bits(&h->gb, 9);
1343 if (get_bits(&h->c.gb, 19) != DC_MARKER) {1343 if (get_bits(&h->gb, 19) != DC_MARKER) {
1344 av_log(h->c.avctx, AV_LOG_ERROR,1344 av_log(h->c.avctx, AV_LOG_ERROR,
1345 "marker missing after first I partition at %d %d\n",1345 "marker missing after first I partition at %d %d\n",
1346 h->c.mb_x, h->c.mb_y);1346 h->c.mb_x, h->c.mb_y);
1347 return AVERROR_INVALIDDATA;1347 return AVERROR_INVALIDDATA;
1348 }1348 }
1349 } else {1349 } else {
1350 while (show_bits(&h->c.gb, 10) == 1)1350 while (show_bits(&h->gb, 10) == 1)
1351 skip_bits(&h->c.gb, 10);1351 skip_bits(&h->gb, 10);
1352 if (get_bits(&h->c.gb, 17) != MOTION_MARKER) {1352 if (get_bits(&h->gb, 17) != MOTION_MARKER) {
1353 av_log(h->c.avctx, AV_LOG_ERROR,1353 av_log(h->c.avctx, AV_LOG_ERROR,
1354 "marker missing after first P partition at %d %d\n",1354 "marker missing after first P partition at %d %d\n",
1355 h->c.mb_x, h->c.mb_y);1355 h->c.mb_x, h->c.mb_y);
@@ -1463,52 +1463,52 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 107 unmodified lines
1463 }1463 }
1464 }1464 }
1465 {1465 {
1466 OPEN_READER(re, &h->c.gb);1466 OPEN_READER(re, &h->gb);
1467 for (;;) {1467 for (;;) {
1468 UPDATE_CACHE(re, &h->c.gb);1468 UPDATE_CACHE(re, &h->gb);
1469 GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);1469 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
1470 if (level == 0) {1470 if (level == 0) {
1471 /* escape */1471 /* escape */
1472 if (rvlc) {1472 if (rvlc) {
1473 if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {1473 if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1474 av_log(h->c.avctx, AV_LOG_ERROR,1474 av_log(h->c.avctx, AV_LOG_ERROR,
1475 "1. marker bit missing in rvlc esc\n");1475 "1. marker bit missing in rvlc esc\n");
1476 return AVERROR_INVALIDDATA;1476 return AVERROR_INVALIDDATA;
1477 }1477 }
1478 SKIP_CACHE(re, &h->c.gb, 1);1478 SKIP_CACHE(re, &h->gb, 1);
1479 1479
1480 last = SHOW_UBITS(re, &h->c.gb, 1);1480 last = SHOW_UBITS(re, &h->gb, 1);
1481 SKIP_CACHE(re, &h->c.gb, 1);1481 SKIP_CACHE(re, &h->gb, 1);
1482 run = SHOW_UBITS(re, &h->c.gb, 6);1482 run = SHOW_UBITS(re, &h->gb, 6);
1483 SKIP_COUNTER(re, &h->c.gb, 1 + 1 + 6);1483 SKIP_COUNTER(re, &h->gb, 1 + 1 + 6);
1484 UPDATE_CACHE(re, &h->c.gb);1484 UPDATE_CACHE(re, &h->gb);
1485 1485
1486 if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {1486 if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1487 av_log(h->c.avctx, AV_LOG_ERROR,1487 av_log(h->c.avctx, AV_LOG_ERROR,
1488 "2. marker bit missing in rvlc esc\n");1488 "2. marker bit missing in rvlc esc\n");
1489 return AVERROR_INVALIDDATA;1489 return AVERROR_INVALIDDATA;
1490 }1490 }
1491 SKIP_CACHE(re, &h->c.gb, 1);1491 SKIP_CACHE(re, &h->gb, 1);
1492 1492
1493 level = SHOW_UBITS(re, &h->c.gb, 11);1493 level = SHOW_UBITS(re, &h->gb, 11);
1494 SKIP_CACHE(re, &h->c.gb, 11);1494 SKIP_CACHE(re, &h->gb, 11);
1495 1495
1496 if (SHOW_UBITS(re, &h->c.gb, 5) != 0x10) {1496 if (SHOW_UBITS(re, &h->gb, 5) != 0x10) {
1497 av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n");1497 av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n");
1498 return AVERROR_INVALIDDATA;1498 return AVERROR_INVALIDDATA;
1499 }1499 }
1500 SKIP_CACHE(re, &h->c.gb, 5);1500 SKIP_CACHE(re, &h->gb, 5);
1501 1501
1502 level = level * qmul + qadd;1502 level = level * qmul + qadd;
1503 level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);1503 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1504 SKIP_COUNTER(re, &h->c.gb, 1 + 11 + 5 + 1);1504 SKIP_COUNTER(re, &h->gb, 1 + 11 + 5 + 1);
1505 1505
1506 i += run + 1;1506 i += run + 1;
1507 if (last)1507 if (last)
1508 i += 192;1508 i += 192;
1509 } else {1509 } else {
1510 int cache;1510 int cache;
1511 cache = GET_CACHE(re, &h->c.gb);1511 cache = GET_CACHE(re, &h->gb);
1512 1512
1513 if (IS_3IV1)1513 if (IS_3IV1)
1514 cache ^= 0xC0000000;1514 cache ^= 0xC0000000;
@@ -1516,36 +1516,36 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line
1516 if (cache & 0x80000000) {1516 if (cache & 0x80000000) {
1517 if (cache & 0x40000000) {1517 if (cache & 0x40000000) {
1518 /* third escape */1518 /* third escape */
1519 SKIP_CACHE(re, &h->c.gb, 2);1519 SKIP_CACHE(re, &h->gb, 2);
1520 last = SHOW_UBITS(re, &h->c.gb, 1);1520 last = SHOW_UBITS(re, &h->gb, 1);
1521 SKIP_CACHE(re, &h->c.gb, 1);1521 SKIP_CACHE(re, &h->gb, 1);
1522 run = SHOW_UBITS(re, &h->c.gb, 6);1522 run = SHOW_UBITS(re, &h->gb, 6);
1523 SKIP_COUNTER(re, &h->c.gb, 2 + 1 + 6);1523 SKIP_COUNTER(re, &h->gb, 2 + 1 + 6);
1524 UPDATE_CACHE(re, &h->c.gb);1524 UPDATE_CACHE(re, &h->gb);
1525 1525
1526 if (IS_3IV1) {1526 if (IS_3IV1) {
1527 level = SHOW_SBITS(re, &h->c.gb, 12);1527 level = SHOW_SBITS(re, &h->gb, 12);
1528 LAST_SKIP_BITS(re, &h->c.gb, 12);1528 LAST_SKIP_BITS(re, &h->gb, 12);
1529 } else {1529 } else {
1530 if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {1530 if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1531 av_log(h->c.avctx, AV_LOG_ERROR,1531 av_log(h->c.avctx, AV_LOG_ERROR,
1532 "1. marker bit missing in 3. esc\n");1532 "1. marker bit missing in 3. esc\n");
1533 if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)1533 if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->gb) <= 0)
1534 return AVERROR_INVALIDDATA;1534 return AVERROR_INVALIDDATA;
1535 }1535 }
1536 SKIP_CACHE(re, &h->c.gb, 1);1536 SKIP_CACHE(re, &h->gb, 1);
1537 1537
1538 level = SHOW_SBITS(re, &h->c.gb, 12);1538 level = SHOW_SBITS(re, &h->gb, 12);
1539 SKIP_CACHE(re, &h->c.gb, 12);1539 SKIP_CACHE(re, &h->gb, 12);
1540 1540
1541 if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {1541 if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1542 av_log(h->c.avctx, AV_LOG_ERROR,1542 av_log(h->c.avctx, AV_LOG_ERROR,
1543 "2. marker bit missing in 3. esc\n");1543 "2. marker bit missing in 3. esc\n");
1544 if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)1544 if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->gb) <= 0)
1545 return AVERROR_INVALIDDATA;1545 return AVERROR_INVALIDDATA;
1546 }1546 }
1547 1547
1548 SKIP_COUNTER(re, &h->c.gb, 1 + 12 + 1);1548 SKIP_COUNTER(re, &h->gb, 1 + 12 + 1);
1549 }1549 }
1550 1550
1551#if 01551#if 0
@@ -1592,26 +1592,26 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 40 unmodified lines
1592 i += 192;1592 i += 192;
1593 } else {1593 } else {
1594 /* second escape */1594 /* second escape */
1595 SKIP_BITS(re, &h->c.gb, 2);1595 SKIP_BITS(re, &h->gb, 2);
1596 GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);1596 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1597 i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing1597 i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing
1598 level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);1598 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1599 LAST_SKIP_BITS(re, &h->c.gb, 1);1599 LAST_SKIP_BITS(re, &h->gb, 1);
1600 }1600 }
1601 } else {1601 } else {
1602 /* first escape */1602 /* first escape */
1603 SKIP_BITS(re, &h->c.gb, 1);1603 SKIP_BITS(re, &h->gb, 1);
1604 GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);1604 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1605 i += run;1605 i += run;
1606 level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing1606 level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing
1607 level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);1607 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1608 LAST_SKIP_BITS(re, &h->c.gb, 1);1608 LAST_SKIP_BITS(re, &h->gb, 1);
1609 }1609 }
1610 }1610 }
1611 } else {1611 } else {
1612 i += run;1612 i += run;
1613 level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);1613 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1614 LAST_SKIP_BITS(re, &h->c.gb, 1);1614 LAST_SKIP_BITS(re, &h->gb, 1);
1615 }1615 }
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);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);
1617 if (i > 62) {1617 if (i > 62) {
@@ -1628,7 +1628,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 10 unmodified lines
1628 1628
1629 block[scan_table[i]] = level;1629 block[scan_table[i]] = level;
1630 }1630 }
1631 CLOSE_READER(re, &h->c.gb);1631 CLOSE_READER(re, &h->gb);
1632 }1632 }
1633 1633
1634not_coded:1634not_coded:
@@ -1751,7 +1751,7 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 116 unmodified lines
1751 if (h->c.pict_type == AV_PICTURE_TYPE_P ||1751 if (h->c.pict_type == AV_PICTURE_TYPE_P ||
1752 h->c.pict_type == AV_PICTURE_TYPE_S) {1752 h->c.pict_type == AV_PICTURE_TYPE_S) {
1753 do {1753 do {
1754 if (get_bits1(&h->c.gb)) {1754 if (get_bits1(&h->gb)) {
1755 /* skip mb */1755 /* skip mb */
1756 h->c.mb_intra = 0;1756 h->c.mb_intra = 0;
1757 for (i = 0; i < 6; i++)1757 for (i = 0; i < 6; i++)
@@ -1780,7 +1780,7 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 22 unmodified lines
1780 }1780 }
1781 goto end;1781 goto end;
1782 }1782 }
1783 cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);1783 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
1784 if (cbpc < 0) {1784 if (cbpc < 0) {
1785 av_log(h->c.avctx, AV_LOG_ERROR,1785 av_log(h->c.avctx, AV_LOG_ERROR,
1786 "mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);1786 "mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1796,10 +1796,10 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 9 unmodified lines
1796 1796
1797 if (h->c.pict_type == AV_PICTURE_TYPE_S &&1797 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
1798 ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)1798 ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)
1799 h->c.mcsel = get_bits1(&h->c.gb);1799 h->c.mcsel = get_bits1(&h->gb);
1800 else1800 else
1801 h->c.mcsel = 0;1801 h->c.mcsel = 0;
1802 cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;1802 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
1803 if (cbpy < 0) {1803 if (cbpy < 0) {
1804 av_log(h->c.avctx, AV_LOG_ERROR,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);1805 "P cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1808,10 +1808,10 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 2 unmodified lines
1808 1808
1809 cbp = (cbpc & 3) | (cbpy << 2);1809 cbp = (cbpc & 3) | (cbpy << 2);
1810 if (dquant)1810 if (dquant)
1811 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);1811 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1812 if ((!h->c.progressive_sequence) &&1812 if ((!h->c.progressive_sequence) &&
1813 (cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE)))1813 (cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE)))
1814 h->c.interlaced_dct = get_bits1(&h->c.gb);1814 h->c.interlaced_dct = get_bits1(&h->gb);
1815 1815
1816 h->c.mv_dir = MV_DIR_FORWARD;1816 h->c.mv_dir = MV_DIR_FORWARD;
1817 if ((cbpc & 16) == 0) {1817 if ((cbpc & 16) == 0) {
@@ -1824,14 +1824,14 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 6 unmodified lines
1824 my = get_amv(ctx, 1);1824 my = get_amv(ctx, 1);
1825 h->c.mv[0][0][0] = mx;1825 h->c.mv[0][0][0] = mx;
1826 h->c.mv[0][0][1] = my;1826 h->c.mv[0][0][1] = my;
1827 } else if ((!h->c.progressive_sequence) && get_bits1(&h->c.gb)) {1827 } else if ((!h->c.progressive_sequence) && get_bits1(&h->gb)) {
1828 h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |1828 h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
1829 MB_TYPE_INTERLACED;1829 MB_TYPE_INTERLACED;
1830 /* 16x8 field motion prediction */1830 /* 16x8 field motion prediction */
1831 h->c.mv_type = MV_TYPE_FIELD;1831 h->c.mv_type = MV_TYPE_FIELD;
1832 1832
1833 h->c.field_select[0][0] = get_bits1(&h->c.gb);1833 h->c.field_select[0][0] = get_bits1(&h->gb);
1834 h->c.field_select[0][1] = get_bits1(&h->c.gb);1834 h->c.field_select[0][1] = get_bits1(&h->gb);
1835 1835
1836 ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);1836 ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
1837 1837
@@ -1921,14 +1921,14 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 83 unmodified lines
1921 goto end;1921 goto end;
1922 }1922 }
1923 1923
1924 modb1 = get_bits1(&h->c.gb);1924 modb1 = get_bits1(&h->gb);
1925 if (modb1) {1925 if (modb1) {
1926 // like MB_TYPE_B_DIRECT but no vectors coded1926 // like MB_TYPE_B_DIRECT but no vectors coded
1927 mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV;1927 mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV;
1928 cbp = 0;1928 cbp = 0;
1929 } else {1929 } else {
1930 modb2 = get_bits1(&h->c.gb);1930 modb2 = get_bits1(&h->gb);
1931 mb_type = get_vlc2(&h->c.gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);1931 mb_type = get_vlc2(&h->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
1932 if (mb_type < 0) {1932 if (mb_type < 0) {
1933 av_log(h->c.avctx, AV_LOG_ERROR, "illegal MB_type\n");1933 av_log(h->c.avctx, AV_LOG_ERROR, "illegal MB_type\n");
1934 return AVERROR_INVALIDDATA;1934 return AVERROR_INVALIDDATA;
@@ -1937,29 +1937,29 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 2 unmodified lines
1937 cbp = 0;1937 cbp = 0;
1938 } else {1938 } else {
1939 h->c.bdsp.clear_blocks(h->block[0]);1939 h->c.bdsp.clear_blocks(h->block[0]);
1940 cbp = get_bits(&h->c.gb, 6);1940 cbp = get_bits(&h->gb, 6);
1941 }1941 }
1942 1942
1943 if ((!IS_DIRECT(mb_type)) && cbp) {1943 if ((!IS_DIRECT(mb_type)) && cbp) {
1944 if (get_bits1(&h->c.gb))1944 if (get_bits1(&h->gb))
1945 ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->c.gb) * 4 - 2);1945 ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->gb) * 4 - 2);
1946 }1946 }
1947 1947
1948 if (!h->c.progressive_sequence) {1948 if (!h->c.progressive_sequence) {
1949 if (cbp)1949 if (cbp)
1950 h->c.interlaced_dct = get_bits1(&h->c.gb);1950 h->c.interlaced_dct = get_bits1(&h->gb);
1951 1951
1952 if (!IS_DIRECT(mb_type) && get_bits1(&h->c.gb)) {1952 if (!IS_DIRECT(mb_type) && get_bits1(&h->gb)) {
1953 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;1953 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
1954 mb_type &= ~MB_TYPE_16x16;1954 mb_type &= ~MB_TYPE_16x16;
1955 1955
1956 if (HAS_FORWARD_MV(mb_type)) {1956 if (HAS_FORWARD_MV(mb_type)) {
1957 h->c.field_select[0][0] = get_bits1(&h->c.gb);1957 h->c.field_select[0][0] = get_bits1(&h->gb);
1958 h->c.field_select[0][1] = get_bits1(&h->c.gb);1958 h->c.field_select[0][1] = get_bits1(&h->gb);
1959 }1959 }
1960 if (HAS_BACKWARD_MV(mb_type)) {1960 if (HAS_BACKWARD_MV(mb_type)) {
1961 h->c.field_select[1][0] = get_bits1(&h->c.gb);1961 h->c.field_select[1][0] = get_bits1(&h->gb);
1962 h->c.field_select[1][1] = get_bits1(&h->c.gb);1962 h->c.field_select[1][1] = get_bits1(&h->gb);
1963 }1963 }
1964 }1964 }
1965 }1965 }
@@ -2039,7 +2039,7 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 73 unmodified lines
2039 int use_intra_dc_vlc;2039 int use_intra_dc_vlc;
2040 2040
2041 do {2041 do {
2042 cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);2042 cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
2043 if (cbpc < 0) {2043 if (cbpc < 0) {
2044 av_log(h->c.avctx, AV_LOG_ERROR,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);2045 "I cbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -2051,13 +2051,13 @@ static int mpeg4_decode_mb(H263DecContext *const h) · 5 unmodified lines
2051 h->c.mb_intra = 1;2051 h->c.mb_intra = 1;
2052 2052
2053intra:2053intra:
2054 h->c.ac_pred = get_bits1(&h->c.gb);2054 h->c.ac_pred = get_bits1(&h->gb);
2055 if (h->c.ac_pred)2055 if (h->c.ac_pred)
2056 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;2056 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
2057 else2057 else
2058 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;2058 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
2059 2059
2060 cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);2060 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
2061 if (cbpy < 0) {2061 if (cbpy < 0) {
2062 av_log(h->c.avctx, AV_LOG_ERROR,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);2063 "I cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -2068,10 +2068,10 @@ intra: · 4 unmodified lines
2068 use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;2068 use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
2069 2069
2070 if (dquant)2070 if (dquant)
2071 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);2071 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
2072 2072
2073 if (!h->c.progressive_sequence)2073 if (!h->c.progressive_sequence)
2074 h->c.interlaced_dct = get_bits1(&h->c.gb);2074 h->c.interlaced_dct = get_bits1(&h->gb);
2075 2075
2076 h->c.bdsp.clear_blocks(h->block[0]);2076 h->c.bdsp.clear_blocks(h->block[0]);
2077 /* decode each block */2077 /* decode each block */
@@ -2173,24 +2173,24 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6 · 95 unmodified lines
2173 2173
2174 if (n < 4) {2174 if (n < 4) {
2175 cc = 0;2175 cc = 0;
2176 dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);2176 dct_dc_size = get_vlc2(&h->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
2177 quant_matrix = h->c.intra_matrix;2177 quant_matrix = h->c.intra_matrix;
2178 } else {2178 } else {
2179 cc = (n & 1) + 1;2179 cc = (n & 1) + 1;
2180 if (ctx->rgb)2180 if (ctx->rgb)
2181 dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);2181 dct_dc_size = get_vlc2(&h->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
2182 else2182 else
2183 dct_dc_size = get_vlc2(&h->c.gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);2183 dct_dc_size = get_vlc2(&h->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
2184 quant_matrix = h->c.chroma_intra_matrix;2184 quant_matrix = h->c.chroma_intra_matrix;
2185 }2185 }
2186 2186
2187 if (dct_dc_size == 0) {2187 if (dct_dc_size == 0) {
2188 dct_diff = 0;2188 dct_diff = 0;
2189 } else {2189 } else {
2190 dct_diff = get_xbits(&h->c.gb, dct_dc_size);2190 dct_diff = get_xbits(&h->gb, dct_dc_size);
2191 2191
2192 if (dct_dc_size > 8) {2192 if (dct_dc_size > 8) {
2193 if(!check_marker(h->c.avctx, &h->c.gb, "dct_dc_size > 8"))2193 if(!check_marker(h->c.avctx, &h->gb, "dct_dc_size > 8"))
2194 return AVERROR_INVALIDDATA;2194 return AVERROR_INVALIDDATA;
2195 }2195 }
2196 2196
@@ -2209,7 +2209,7 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6 · 12 unmodified lines
2209 2209
2210 /* AC Coefficients */2210 /* AC Coefficients */
2211 while (1) {2211 while (1) {
2212 group = get_vlc2(&h->c.gb, cur_vlc, STUDIO_INTRA_BITS, 2);2212 group = get_vlc2(&h->gb, cur_vlc, STUDIO_INTRA_BITS, 2);
2213 2213
2214 if (group < 0) {2214 if (group < 0) {
2215 av_log(h->c.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");
@@ -2226,12 +2226,12 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6 · 10 unmodified lines
2226 /* Zero run length (Table B.47) */2226 /* Zero run length (Table B.47) */
2227 run = 1 << additional_code_len;2227 run = 1 << additional_code_len;
2228 if (additional_code_len)2228 if (additional_code_len)
2229 run += get_bits(&h->c.gb, additional_code_len);2229 run += get_bits(&h->gb, additional_code_len);
2230 idx += run;2230 idx += run;
2231 continue;2231 continue;
2232 } else if (group >= 7 && group <= 12) {2232 } else if (group >= 7 && group <= 12) {
2233 /* Zero run length and +/-1 level (Table B.48) */2233 /* Zero run length and +/-1 level (Table B.48) */
2234 code = get_bits(&h->c.gb, additional_code_len);2234 code = get_bits(&h->gb, additional_code_len);
2235 sign = code & 1;2235 sign = code & 1;
2236 code >>= 1;2236 code >>= 1;
2237 run = (1 << (additional_code_len - 1)) + code;2237 run = (1 << (additional_code_len - 1)) + code;
@@ -2245,14 +2245,14 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6 · 7 unmodified lines
2245 if (idx > 63)2245 if (idx > 63)
2246 return AVERROR_INVALIDDATA;2246 return AVERROR_INVALIDDATA;
2247 j = scantable[idx++];2247 j = scantable[idx++];
2248 block[j] = get_xbits(&h->c.gb, additional_code_len);2248 block[j] = get_xbits(&h->gb, additional_code_len);
2249 } else if (group == 21) {2249 } else if (group == 21) {
2250 /* Escape */2250 /* Escape */
2251 if (idx > 63)2251 if (idx > 63)
2252 return AVERROR_INVALIDDATA;2252 return AVERROR_INVALIDDATA;
2253 j = scantable[idx++];2253 j = scantable[idx++];
2254 additional_code_len = h->c.avctx->bits_per_raw_sample + ctx->dct_precision + 4;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);2255 flc = get_bits(&h->gb, additional_code_len);
2256 if (flc >> (additional_code_len-1))2256 if (flc >> (additional_code_len-1))
2257 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);2257 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
2258 else2258 else
@@ -2278,14 +2278,14 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, · 19 unmodified lines
2278 height = 16 >> (n ? h->c.chroma_y_shift : 0);2278 height = 16 >> (n ? h->c.chroma_y_shift : 0);
2279 w = 16 >> (n ? h->c.chroma_x_shift : 0);2279 w = 16 >> (n ? h->c.chroma_x_shift : 0);
2280 2280
2281 block_mean = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);2281 block_mean = get_bits(&h->gb, h->c.avctx->bits_per_raw_sample);
2282 if (block_mean == 0){2282 if (block_mean == 0){
2283 av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");2283 av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
2284 return AVERROR_INVALIDDATA;2284 return AVERROR_INVALIDDATA;
2285 }2285 }
2286 h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));2286 h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
2287 2287
2288 rice_parameter = get_bits(&h->c.gb, 4);2288 rice_parameter = get_bits(&h->gb, 4);
2289 if (rice_parameter == 0) {2289 if (rice_parameter == 0) {
2290 av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");2290 av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
2291 return AVERROR_INVALIDDATA;2291 return AVERROR_INVALIDDATA;
@@ -2307,17 +2307,17 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, · 15 unmodified lines
2307 left = output;2307 left = output;
2308 topleft = top;2308 topleft = top;
2309 2309
2310 rice_prefix_code = get_unary(&h->c.gb, 1, 12);2310 rice_prefix_code = get_unary(&h->gb, 1, 12);
2311 2311
2312 /* Escape */2312 /* Escape */
2313 if (rice_prefix_code == 11)2313 if (rice_prefix_code == 11)
2314 dpcm_residual = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);2314 dpcm_residual = get_bits(&h->gb, h->c.avctx->bits_per_raw_sample);
2315 else {2315 else {
2316 if (rice_prefix_code == 12) {2316 if (rice_prefix_code == 12) {
2317 av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");2317 av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");
2318 return AVERROR_INVALIDDATA;2318 return AVERROR_INVALIDDATA;
2319 }2319 }
2320 rice_suffix_code = get_bitsz(&h->c.gb, rice_parameter);2320 rice_suffix_code = get_bitsz(&h->gb, rice_parameter);
2321 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;2321 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
2322 }2322 }
2323 2323
@@ -2363,12 +2363,12 @@ static int mpeg4_decode_studio_mb(H263DecContext *const h) · 39 unmodified lines
2363 /* StudioMacroblock */2363 /* StudioMacroblock */
2364 /* Assumes I-VOP */2364 /* Assumes I-VOP */
2365 h->c.mb_intra = 1;2365 h->c.mb_intra = 1;
2366 if (get_bits1(&h->c.gb)) { /* compression_mode */2366 if (get_bits1(&h->gb)) { /* compression_mode */
2367 /* DCT */2367 /* DCT */
2368 /* macroblock_type, 1 or 2-bit VLC */2368 /* macroblock_type, 1 or 2-bit VLC */
2369 if (!get_bits1(&h->c.gb)) {2369 if (!get_bits1(&h->gb)) {
2370 skip_bits1(&h->c.gb);2370 skip_bits1(&h->gb);
2371 h->c.qscale = mpeg_get_qscale(&h->c);2371 h->c.qscale = mpeg_get_qscale(&h->gb, h->c.q_scale_type);
2372 }2372 }
2373 2373
2374 for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) {2374 for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) {
@@ -2377,25 +2377,25 @@ static int mpeg4_decode_studio_mb(H263DecContext *const h) · 2 unmodified lines
2377 }2377 }
2378 } else {2378 } else {
2379 /* DPCM */2379 /* DPCM */
2380 check_marker(h->c.avctx, &h->c.gb, "DPCM block start");2380 check_marker(h->c.avctx, &h->gb, "DPCM block start");
2381 ctx->dpcm_direction = get_bits1(&h->c.gb) ? -1 : 1;2381 ctx->dpcm_direction = get_bits1(&h->gb) ? -1 : 1;
2382 for (i = 0; i < 3; i++) {2382 for (i = 0; i < 3; i++) {
2383 if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0)2383 if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0)
2384 return AVERROR_INVALIDDATA;2384 return AVERROR_INVALIDDATA;
2385 }2385 }
2386 }2386 }
2387 2387
2388 if (get_bits_left(&h->c.gb) >= 24 && show_bits(&h->c.gb, 23) == 0) {2388 if (get_bits_left(&h->gb) >= 24 && show_bits(&h->gb, 23) == 0) {
2389 next_start_code_studio(&h->c.gb);2389 next_start_code_studio(&h->gb);
2390 return SLICE_END;2390 return SLICE_END;
2391 }2391 }
2392 2392
2393 //vcon-stp9L1.bits (first frame)2393 //vcon-stp9L1.bits (first frame)
2394 if (get_bits_left(&h->c.gb) == 0)2394 if (get_bits_left(&h->gb) == 0)
2395 return SLICE_END;2395 return SLICE_END;
2396 2396
2397 //vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame)2397 //vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame)
2398 if (get_bits_left(&h->c.gb) < 8U && show_bits(&h->c.gb, get_bits_left(&h->c.gb)) == 0)2398 if (get_bits_left(&h->gb) < 8U && show_bits(&h->gb, get_bits_left(&h->gb)) == 0)
2399 return SLICE_END;2399 return SLICE_END;
2400 2400
2401 return SLICE_OK;2401 return SLICE_OK;
@@ -3743,9 +3743,9 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h) · 1341 unmodified lines
3743 h->c.skipped_last_frame = 0;3743 h->c.skipped_last_frame = 0;
3744 3744
3745 if (ctx->bitstream_buffer) {3745 if (ctx->bitstream_buffer) {
3746 int buf_size = get_bits_left(&h->c.gb) / 8U;3746 int buf_size = get_bits_left(&h->gb) / 8U;
3747 int bitstream_buffer_size = ctx->bitstream_buffer->size;3747 int bitstream_buffer_size = ctx->bitstream_buffer->size;
3748 const uint8_t *buf = h->c.gb.buffer;3748 const uint8_t *buf = h->gb.buffer;
3749 3749
3750 if (h->c.divx_packed) {3750 if (h->c.divx_packed) {
3751 for (int i = 0; i < buf_size - 3; i++) {3751 for (int i = 0; i < buf_size - 3; i++) {
@@ -3760,7 +3760,7 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h) · 8 unmodified lines
3760 }3760 }
3761 ctx->bitstream_buffer->size = 0;3761 ctx->bitstream_buffer->size = 0;
3762 if (bitstream_buffer_size && (h->c.divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder3762 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,3763 int ret = init_get_bits8(&h->gb, ctx->bitstream_buffer->data,
3764 bitstream_buffer_size);3764 bitstream_buffer_size);
3765 if (ret < 0)3765 if (ret < 0)
3766 return ret;3766 return ret;
@@ -3768,7 +3768,7 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h) · 1 unmodified line
3768 av_buffer_unref(&ctx->bitstream_buffer);3768 av_buffer_unref(&ctx->bitstream_buffer);
3769 }3769 }
3770 3770
3771 return ff_mpeg4_parse_picture_header(ctx, &h->c.gb, 0, 0);3771 return ff_mpeg4_parse_picture_header(ctx, &h->gb, 0, 0);
3772}3772}
3773 3773
3774int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)3774int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
@@ -3781,7 +3781,7 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt) · 6 unmodified lines
3781 3781
3782 /* divx 5.01+ bitstream reorder stuff */3782 /* divx 5.01+ bitstream reorder stuff */
3783 if (h->c.divx_packed) {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);3784 int current_pos = ctx->bitstream_buffer && h->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->gb) >> 3);
3785 int startcode_found = 0;3785 int startcode_found = 0;
3786 uint8_t *buf = pkt->data;3786 uint8_t *buf = pkt->data;
3787 int buf_size = pkt->size;3787 int buf_size = pkt->size;
libavcodec/mpegvideo.h+0−1
@@ -219,7 +219,6 @@ typedef struct MpegEncContext { · 218 unmodified lines
219 /* error concealment / resync */219 /* error concealment / resync */
220 int resync_mb_x; ///< x position of last resync marker220 int resync_mb_x; ///< x position of last resync marker
221 int resync_mb_y; ///< y position of last resync marker221 int resync_mb_y; ///< y position of last resync marker
222 GetBitContext last_resync_gb; ///< used to search for the next resync marker
223 int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)222 int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
224 223
225 /* H.263 specific */224 /* H.263 specific */
libavcodec/mpegvideodec.h+3−3
@@ -77,10 +77,10 @@ int ff_mpv_decode_close(AVCodecContext *avctx); · 76 unmodified lines
77 77
78void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict);78void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict);
79 79
80static inline int mpeg_get_qscale(MpegEncContext *s)80static inline int mpeg_get_qscale(GetBitContext *const gb, int q_scale_type)
81{81{
82 int qscale = get_bits(&s->gb, 5);82 int qscale = get_bits(gb, 5);
83 if (s->q_scale_type)83 if (q_scale_type)
84 return ff_mpeg2_non_linear_qscale[qscale];84 return ff_mpeg2_non_linear_qscale[qscale];
85 else85 else
86 return qscale << 1;86 return qscale << 1;
libavcodec/msmpeg4dec.c+94−94
@@ -78,7 +78,7 @@ static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code · 77 unmodified lines
78{78{
79 int code, val, sign, shift;79 int code, val, sign, shift;
80 80
81 code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);81 code = get_vlc2(&h->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",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 code, h->c.mb_x,h->c.mb_y, pred);
84 if (code < 0)84 if (code < 0)
@@ -86,12 +86,12 @@ static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code · 1 unmodified line
86 86
87 if (code == 0)87 if (code == 0)
88 return pred;88 return pred;
89 sign = get_bits1(&h->c.gb);89 sign = get_bits1(&h->gb);
90 shift = f_code - 1;90 shift = f_code - 1;
91 val = code;91 val = code;
92 if (shift) {92 if (shift) {
93 val = (val - 1) << shift;93 val = (val - 1) << shift;
94 val |= get_bits(&h->c.gb, shift);94 val |= get_bits(&h->gb, shift);
95 val++;95 val++;
96 }96 }
97 if (sign)97 if (sign)
@@ -114,7 +114,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h) · 16 unmodified lines
114 114
115 if (h->c.pict_type == AV_PICTURE_TYPE_P) {115 if (h->c.pict_type == AV_PICTURE_TYPE_P) {
116 if (ms->use_skip_mb_code) {116 if (ms->use_skip_mb_code) {
117 if (get_bits1(&h->c.gb)) {117 if (get_bits1(&h->gb)) {
118 /* skip mb */118 /* skip mb */
119 h->c.mb_intra = 0;119 h->c.mb_intra = 0;
120 for(i=0;i<6;i++)120 for(i=0;i<6;i++)
@@ -130,9 +130,9 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h) · 9 unmodified lines
130 }130 }
131 131
132 if (h->c.msmpeg4_version == MSMP4_V2)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 code = get_vlc2(&h->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
134 else134 else
135 code = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);135 code = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
136 if(code<0 || code>7){136 if(code<0 || code>7){
137 av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",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);138 code, h->c.mb_x, h->c.mb_y);
@@ -145,9 +145,9 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h) · 6 unmodified lines
145 } else {145 } else {
146 h->c.mb_intra = 1;146 h->c.mb_intra = 1;
147 if (h->c.msmpeg4_version == MSMP4_V2)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);148 cbp = get_vlc2(&h->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
149 else149 else
150 cbp = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);150 cbp = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
151 if(cbp<0 || cbp>3){151 if(cbp<0 || cbp>3){
152 av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",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);153 cbp, h->c.mb_x, h->c.mb_y);
@@ -158,7 +158,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h) · 4 unmodified lines
158 if (!h->c.mb_intra) {158 if (!h->c.mb_intra) {
159 int mx, my, cbpy;159 int mx, my, cbpy;
160 160
161 cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);161 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
162 if(cbpy<0){162 if(cbpy<0){
163 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n",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);164 cbp, h->c.mb_x, h->c.mb_y);
@@ -181,8 +181,8 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h) · 16 unmodified lines
181 } else {181 } else {
182 int v;182 int v;
183 if (h->c.msmpeg4_version == MSMP4_V2) {183 if (h->c.msmpeg4_version == MSMP4_V2) {
184 h->c.ac_pred = get_bits1(&h->c.gb);184 h->c.ac_pred = get_bits1(&h->gb);
185 v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);185 v = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
186 if (v < 0) {186 if (v < 0) {
187 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");187 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
188 return -1;188 return -1;
@@ -190,7 +190,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h) · 1 unmodified line
190 cbp|= v<<2;190 cbp|= v<<2;
191 } else{191 } else{
192 h->c.ac_pred = 0;192 h->c.ac_pred = 0;
193 v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);193 v = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
194 if (v < 0) {194 if (v < 0) {
195 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");195 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
196 return -1;196 return -1;
@@ -220,12 +220,12 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h) · 23 unmodified lines
220 uint8_t *coded_val;220 uint8_t *coded_val;
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];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];
222 222
223 if (get_bits_left(&h->c.gb) <= 0)223 if (get_bits_left(&h->gb) <= 0)
224 return AVERROR_INVALIDDATA;224 return AVERROR_INVALIDDATA;
225 225
226 if (h->c.pict_type == AV_PICTURE_TYPE_P) {226 if (h->c.pict_type == AV_PICTURE_TYPE_P) {
227 if (ms->use_skip_mb_code) {227 if (ms->use_skip_mb_code) {
228 if (get_bits1(&h->c.gb)) {228 if (get_bits1(&h->gb)) {
229 /* skip mb */229 /* skip mb */
230 h->c.mb_intra = 0;230 h->c.mb_intra = 0;
231 for(i=0;i<6;i++)231 for(i=0;i<6;i++)
@@ -241,14 +241,14 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h) · 9 unmodified lines
241 }241 }
242 }242 }
243 243
244 code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);244 code = get_vlc2(&h->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
245 //h->c.mb_intra = (code & 0x40) ? 0 : 1;245 //h->c.mb_intra = (code & 0x40) ? 0 : 1;
246 h->c.mb_intra = (~code & 0x40) >> 6;246 h->c.mb_intra = (~code & 0x40) >> 6;
247 247
248 cbp = code & 0x3f;248 cbp = code & 0x3f;
249 } else {249 } else {
250 h->c.mb_intra = 1;250 h->c.mb_intra = 1;
251 code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);251 code = get_vlc2(&h->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
252 /* predict coded block pattern */252 /* predict coded block pattern */
253 cbp = 0;253 cbp = 0;
254 for(i=0;i<6;i++) {254 for(i=0;i<6;i++) {
@@ -265,7 +265,7 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h) · 10 unmodified lines
265 if (!h->c.mb_intra) {265 if (!h->c.mb_intra) {
266 int mx, my;266 int mx, my;
267 if (ms->per_mb_rl_table && cbp) {267 if (ms->per_mb_rl_table && cbp) {
268 ms->rl_table_index = decode012(&h->c.gb);268 ms->rl_table_index = decode012(&h->gb);
269 ms->rl_chroma_table_index = ms->rl_table_index;269 ms->rl_chroma_table_index = ms->rl_table_index;
270 }270 }
271 ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);271 ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
@@ -278,16 +278,16 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h) · 6 unmodified lines
278 } else {278 } else {
279 ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,279 ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
280 ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),280 ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
281 show_bits(&h->c.gb, 24));281 show_bits(&h->gb, 24));
282 h->c.ac_pred = get_bits1(&h->c.gb);282 h->c.ac_pred = get_bits1(&h->gb);
283 *mb_type_ptr = MB_TYPE_INTRA;283 *mb_type_ptr = MB_TYPE_INTRA;
284 if (h->c.inter_intra_pred) {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);285 h->c.h263_aic_dir = get_vlc2(&h->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
286 ff_dlog(h->c.avctx, "%d%d %d %d/",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);287 h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
288 }288 }
289 if (ms->per_mb_rl_table && cbp) {289 if (ms->per_mb_rl_table && cbp) {
290 ms->rl_table_index = decode012(&h->c.gb);290 ms->rl_table_index = decode012(&h->gb);
291 ms->rl_chroma_table_index = ms->rl_table_index;291 ms->rl_chroma_table_index = ms->rl_table_index;
292 }292 }
293 }293 }
@@ -409,33 +409,33 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h) · 115 unmodified lines
409 // smallest "black/skip" frame generally contain not much recoverable content409 // smallest "black/skip" frame generally contain not much recoverable content
410 // while at the same time they have the highest computational requirements410 // while at the same time they have the highest computational requirements
411 // per byte411 // per byte
412 if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))412 if (get_bits_left(&h->gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
413 return AVERROR_INVALIDDATA;413 return AVERROR_INVALIDDATA;
414 414
415 if (h->c.msmpeg4_version == MSMP4_V1) {415 if (h->c.msmpeg4_version == MSMP4_V1) {
416 int start_code = get_bits_long(&h->c.gb, 32);416 int start_code = get_bits_long(&h->gb, 32);
417 if(start_code!=0x00000100){417 if(start_code!=0x00000100){
418 av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n");418 av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n");
419 return -1;419 return -1;
420 }420 }
421 421
422 skip_bits(&h->c.gb, 5); // frame number */422 skip_bits(&h->gb, 5); // frame number */
423 }423 }
424 424
425 h->c.pict_type = get_bits(&h->c.gb, 2) + 1;425 h->c.pict_type = get_bits(&h->gb, 2) + 1;
426 if (h->c.pict_type != AV_PICTURE_TYPE_I &&426 if (h->c.pict_type != AV_PICTURE_TYPE_I &&
427 h->c.pict_type != AV_PICTURE_TYPE_P){427 h->c.pict_type != AV_PICTURE_TYPE_P){
428 av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n");428 av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n");
429 return -1;429 return -1;
430 }430 }
431 h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);431 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
432 if (h->c.qscale == 0) {432 if (h->c.qscale == 0) {
433 av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n");433 av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n");
434 return -1;434 return -1;
435 }435 }
436 436
437 if (h->c.pict_type == AV_PICTURE_TYPE_I) {437 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
438 code = get_bits(&h->c.gb, 5);438 code = get_bits(&h->gb, 5);
439 if (h->c.msmpeg4_version == MSMP4_V1) {439 if (h->c.msmpeg4_version == MSMP4_V1) {
440 if(code==0 || code>h->c.mb_height) {440 if(code==0 || code>h->c.mb_height) {
441 av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);441 av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
@@ -462,25 +462,25 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h) · 20 unmodified lines
462 ms->dc_table_index = 0; //not used462 ms->dc_table_index = 0; //not used
463 break;463 break;
464 case MSMP4_V3:464 case MSMP4_V3:
465 ms->rl_chroma_table_index = decode012(&h->c.gb);465 ms->rl_chroma_table_index = decode012(&h->gb);
466 ms->rl_table_index = decode012(&h->c.gb);466 ms->rl_table_index = decode012(&h->gb);
467 467
468 ms->dc_table_index = get_bits1(&h->c.gb);468 ms->dc_table_index = get_bits1(&h->gb);
469 break;469 break;
470 case MSMP4_WMV1:470 case MSMP4_WMV1:
471 ff_msmpeg4_decode_ext_header(h, (2+5+5+17+7)/8);471 ff_msmpeg4_decode_ext_header(h, (2+5+5+17+7)/8);
472 472
473 if (ms->bit_rate > MBAC_BITRATE)473 if (ms->bit_rate > MBAC_BITRATE)
474 ms->per_mb_rl_table = get_bits1(&h->c.gb);474 ms->per_mb_rl_table = get_bits1(&h->gb);
475 else475 else
476 ms->per_mb_rl_table = 0;476 ms->per_mb_rl_table = 0;
477 477
478 if (!ms->per_mb_rl_table) {478 if (!ms->per_mb_rl_table) {
479 ms->rl_chroma_table_index = decode012(&h->c.gb);479 ms->rl_chroma_table_index = decode012(&h->gb);
480 ms->rl_table_index = decode012(&h->c.gb);480 ms->rl_table_index = decode012(&h->gb);
481 }481 }
482 482
483 ms->dc_table_index = get_bits1(&h->c.gb);483 ms->dc_table_index = get_bits1(&h->gb);
484 h->c.inter_intra_pred= 0;484 h->c.inter_intra_pred= 0;
485 break;485 break;
486 default:486 default:
@@ -502,37 +502,37 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h) · 15 unmodified lines
502 if (h->c.msmpeg4_version == MSMP4_V1)502 if (h->c.msmpeg4_version == MSMP4_V1)
503 ms->use_skip_mb_code = 1;503 ms->use_skip_mb_code = 1;
504 else504 else
505 ms->use_skip_mb_code = get_bits1(&h->c.gb);505 ms->use_skip_mb_code = get_bits1(&h->gb);
506 ms->rl_table_index = 2;506 ms->rl_table_index = 2;
507 ms->rl_chroma_table_index = ms->rl_table_index;507 ms->rl_chroma_table_index = ms->rl_table_index;
508 ms->dc_table_index = 0; //not used508 ms->dc_table_index = 0; //not used
509 ms->mv_table_index = 0;509 ms->mv_table_index = 0;
510 break;510 break;
511 case MSMP4_V3:511 case MSMP4_V3:
512 ms->use_skip_mb_code = get_bits1(&h->c.gb);512 ms->use_skip_mb_code = get_bits1(&h->gb);
513 ms->rl_table_index = decode012(&h->c.gb);513 ms->rl_table_index = decode012(&h->gb);
514 ms->rl_chroma_table_index = ms->rl_table_index;514 ms->rl_chroma_table_index = ms->rl_table_index;
515 515
516 ms->dc_table_index = get_bits1(&h->c.gb);516 ms->dc_table_index = get_bits1(&h->gb);
517 517
518 ms->mv_table_index = get_bits1(&h->c.gb);518 ms->mv_table_index = get_bits1(&h->gb);
519 break;519 break;
520 case MSMP4_WMV1:520 case MSMP4_WMV1:
521 ms->use_skip_mb_code = get_bits1(&h->c.gb);521 ms->use_skip_mb_code = get_bits1(&h->gb);
522 522
523 if (ms->bit_rate > MBAC_BITRATE)523 if (ms->bit_rate > MBAC_BITRATE)
524 ms->per_mb_rl_table = get_bits1(&h->c.gb);524 ms->per_mb_rl_table = get_bits1(&h->gb);
525 else525 else
526 ms->per_mb_rl_table = 0;526 ms->per_mb_rl_table = 0;
527 527
528 if (!ms->per_mb_rl_table) {528 if (!ms->per_mb_rl_table) {
529 ms->rl_table_index = decode012(&h->c.gb);529 ms->rl_table_index = decode012(&h->gb);
530 ms->rl_chroma_table_index = ms->rl_table_index;530 ms->rl_chroma_table_index = ms->rl_table_index;
531 }531 }
532 532
533 ms->dc_table_index = get_bits1(&h->c.gb);533 ms->dc_table_index = get_bits1(&h->gb);
534 534
535 ms->mv_table_index = get_bits1(&h->c.gb);535 ms->mv_table_index = get_bits1(&h->gb);
536 h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 &&536 h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 &&
537 ms->bit_rate <= II_BITRATE;537 ms->bit_rate <= II_BITRATE;
538 break;538 break;
@@ -568,15 +568,15 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h) · 29 unmodified lines
568int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)568int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
569{569{
570 MSMP4DecContext *const ms = mpv_to_msmpeg4(h);570 MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
571 int left= buf_size*8 - get_bits_count(&h->c.gb);571 int left = buf_size*8 - get_bits_count(&h->gb);
572 int length = h->c.msmpeg4_version >= MSMP4_V3 ? 17 : 16;572 int length = h->c.msmpeg4_version >= MSMP4_V3 ? 17 : 16;
573 /* the alt_bitstream reader could read over the end so we need to check it */573 /* the alt_bitstream reader could read over the end so we need to check it */
574 if(left>=length && left<length+8)574 if(left>=length && left<length+8)
575 {575 {
576 skip_bits(&h->c.gb, 5); /* fps */576 skip_bits(&h->gb, 5); /* fps */
577 ms->bit_rate = get_bits(&h->c.gb, 11) * 1024;577 ms->bit_rate = get_bits(&h->gb, 11) * 1024;
578 if (h->c.msmpeg4_version >= MSMP4_V3)578 if (h->c.msmpeg4_version >= MSMP4_V3)
579 ms->flipflop_rounding = get_bits1(&h->c.gb);579 ms->flipflop_rounding = get_bits1(&h->gb);
580 else580 else
581 ms->flipflop_rounding = 0;581 ms->flipflop_rounding = 0;
582 }582 }
@@ -601,9 +601,9 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr) · 18 unmodified lines
601 601
602 if (h->c.msmpeg4_version <= MSMP4_V2) {602 if (h->c.msmpeg4_version <= MSMP4_V2) {
603 if (n < 4) {603 if (n < 4) {
604 level = get_vlc2(&h->c.gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);604 level = get_vlc2(&h->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
605 } else {605 } else {
606 level = get_vlc2(&h->c.gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);606 level = get_vlc2(&h->gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
607 }607 }
608 if (level < 0) {608 if (level < 0) {
609 av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");609 av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
@@ -612,15 +612,15 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr) · 2 unmodified lines
612 }612 }
613 level-=256;613 level-=256;
614 } else {614 } else {
615 level = get_vlc2(&h->c.gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],615 level = get_vlc2(&h->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
616 MSMP4_DC_VLC_BITS, 3);616 MSMP4_DC_VLC_BITS, 3);
617 617
618 if (level == DC_MAX) {618 if (level == DC_MAX) {
619 level = get_bits(&h->c.gb, 8);619 level = get_bits(&h->gb, 8);
620 if (get_bits1(&h->c.gb))620 if (get_bits1(&h->gb))
621 level = -level;621 level = -level;
622 } else if (level != 0) {622 } else if (level != 0) {
623 if (get_bits1(&h->c.gb))623 if (get_bits1(&h->gb))
624 level = -level;624 level = -level;
625 }625 }
626 }626 }
@@ -721,58 +721,58 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 94 unmodified lines
721 rl_vlc= rl->rl_vlc[h->c.qscale];721 rl_vlc= rl->rl_vlc[h->c.qscale];
722 }722 }
723 {723 {
724 OPEN_READER(re, &h->c.gb);724 OPEN_READER(re, &h->gb);
725 for(;;) {725 for(;;) {
726 UPDATE_CACHE(re, &h->c.gb);726 UPDATE_CACHE(re, &h->gb);
727 GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);727 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
728 if (level==0) {728 if (level==0) {
729 int cache;729 int cache;
730 cache= GET_CACHE(re, &h->c.gb);730 cache= GET_CACHE(re, &h->gb);
731 /* escape */731 /* escape */
732 if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {732 if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
733 if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {733 if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
734 /* third escape */734 /* third escape */
735 if (h->c.msmpeg4_version != MSMP4_V1)735 if (h->c.msmpeg4_version != MSMP4_V1)
736 LAST_SKIP_BITS(re, &h->c.gb, 2);736 LAST_SKIP_BITS(re, &h->gb, 2);
737 UPDATE_CACHE(re, &h->c.gb);737 UPDATE_CACHE(re, &h->gb);
738 if (h->c.msmpeg4_version <= MSMP4_V3) {738 if (h->c.msmpeg4_version <= MSMP4_V3) {
739 last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_CACHE(re, &h->c.gb, 1);739 last = SHOW_UBITS(re, &h->gb, 1); SKIP_CACHE(re, &h->gb, 1);
740 run = SHOW_UBITS(re, &h->c.gb, 6); SKIP_CACHE(re, &h->c.gb, 6);740 run = SHOW_UBITS(re, &h->gb, 6); SKIP_CACHE(re, &h->gb, 6);
741 level = SHOW_SBITS(re, &h->c.gb, 8);741 level = SHOW_SBITS(re, &h->gb, 8);
742 SKIP_COUNTER(re, &h->c.gb, 1 + 6 + 8);742 SKIP_COUNTER(re, &h->gb, 1 + 6 + 8);
743 }else{743 }else{
744 int sign;744 int sign;
745 last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);745 last = SHOW_UBITS(re, &h->gb, 1); SKIP_BITS(re, &h->gb, 1);
746 if (!ms->esc3_level_length) {746 if (!ms->esc3_level_length) {
747 int ll;747 int ll;
748 ff_dlog(h->c.avctx, "ESC-3 %X at %d %d\n",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);749 show_bits(&h->gb, 24), h->c.mb_x, h->c.mb_y);
750 if (h->c.qscale < 8) {750 if (h->c.qscale < 8) {
751 ll = SHOW_UBITS(re, &h->c.gb, 3); SKIP_BITS(re, &h->c.gb, 3);751 ll = SHOW_UBITS(re, &h->gb, 3); SKIP_BITS(re, &h->gb, 3);
752 if(ll==0){752 if(ll==0){
753 ll = 8+SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);753 ll = 8+SHOW_UBITS(re, &h->gb, 1); SKIP_BITS(re, &h->gb, 1);
754 }754 }
755 }else{755 }else{
756 ll=2;756 ll=2;
757 while (ll < 8 && SHOW_UBITS(re, &h->c.gb, 1) == 0) {757 while (ll < 8 && SHOW_UBITS(re, &h->gb, 1) == 0) {
758 ll++;758 ll++;
759 SKIP_BITS(re, &h->c.gb, 1);759 SKIP_BITS(re, &h->gb, 1);
760 }760 }
761 if (ll<8) SKIP_BITS(re, &h->c.gb, 1);761 if (ll<8) SKIP_BITS(re, &h->gb, 1);
762 }762 }
763 763
764 ms->esc3_level_length = ll;764 ms->esc3_level_length = ll;
765 ms->esc3_run_length = SHOW_UBITS(re, &h->c.gb, 2) + 3; SKIP_BITS(re, &h->c.gb, 2);765 ms->esc3_run_length = SHOW_UBITS(re, &h->gb, 2) + 3; SKIP_BITS(re, &h->gb, 2);
766 UPDATE_CACHE(re, &h->c.gb);766 UPDATE_CACHE(re, &h->gb);
767 }767 }
768 run = SHOW_UBITS(re, &h->c.gb, ms->esc3_run_length);768 run = SHOW_UBITS(re, &h->gb, ms->esc3_run_length);
769 SKIP_BITS(re, &h->c.gb, ms->esc3_run_length);769 SKIP_BITS(re, &h->gb, ms->esc3_run_length);
770 770
771 sign= SHOW_UBITS(re, &h->c.gb, 1);771 sign= SHOW_UBITS(re, &h->gb, 1);
772 SKIP_BITS(re, &h->c.gb, 1);772 SKIP_BITS(re, &h->gb, 1);
773 773
774 level = SHOW_UBITS(re, &h->c.gb, ms->esc3_level_length);774 level = SHOW_UBITS(re, &h->gb, ms->esc3_level_length);
775 SKIP_BITS(re, &h->c.gb, ms->esc3_level_length);775 SKIP_BITS(re, &h->gb, ms->esc3_level_length);
776 if(sign) level= -level;776 if(sign) level= -level;
777 }777 }
778 778
@@ -783,30 +783,30 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 4 unmodified lines
783 if(last) i+=192;783 if(last) i+=192;
784 } else {784 } else {
785 /* second escape */785 /* second escape */
786 SKIP_BITS(re, &h->c.gb, 2);786 SKIP_BITS(re, &h->gb, 2);
787 GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);787 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
788 i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing788 i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
789 level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);789 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
790 LAST_SKIP_BITS(re, &h->c.gb, 1);790 LAST_SKIP_BITS(re, &h->gb, 1);
791 }791 }
792 } else {792 } else {
793 /* first escape */793 /* first escape */
794 SKIP_BITS(re, &h->c.gb, 1);794 SKIP_BITS(re, &h->gb, 1);
795 GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);795 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
796 i+= run;796 i+= run;
797 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing797 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
798 level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);798 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
799 LAST_SKIP_BITS(re, &h->c.gb, 1);799 LAST_SKIP_BITS(re, &h->gb, 1);
800 }800 }
801 } else {801 } else {
802 i+= run;802 i+= run;
803 level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);803 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
804 LAST_SKIP_BITS(re, &h->c.gb, 1);804 LAST_SKIP_BITS(re, &h->gb, 1);
805 }805 }
806 if (i > 62){806 if (i > 62){
807 i-= 192;807 i-= 192;
808 if(i&(~63)){808 if(i&(~63)){
809 const int left = get_bits_left(&h->c.gb);809 const int left = get_bits_left(&h->gb);
810 if (((i + 192 == 64 && level / qmul == -1) ||810 if (((i + 192 == 64 && level / qmul == -1) ||
811 !(h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&811 !(h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
812 left >= 0) {812 left >= 0) {
@@ -827,7 +827,7 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 14 unmodified lines
827 827
828 block[scan_table[i]] = level;828 block[scan_table[i]] = level;
829 }829 }
830 CLOSE_READER(re, &h->c.gb);830 CLOSE_READER(re, &h->gb);
831 }831 }
832 if (h->c.mb_intra) {832 if (h->c.mb_intra) {
833 not_coded:833 not_coded:
@@ -844,14 +844,14 @@ void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_pt · 10 unmodified lines
844 H263DecContext *const h = &ms->h;844 H263DecContext *const h = &ms->h;
845 int sym, mx, my;845 int sym, mx, my;
846 846
847 sym = get_vlc2(&h->c.gb, mv_vlc, MV_VLC_BITS, 2);847 sym = get_vlc2(&h->gb, mv_vlc, MV_VLC_BITS, 2);
848 if (sym) {848 if (sym) {
849 mx = sym >> 8;849 mx = sym >> 8;
850 my = sym & 0xFF;850 my = sym & 0xFF;
851 } else {851 } else {
852 /* Escape */852 /* Escape */
853 mx = get_bits(&h->c.gb, 6);853 mx = get_bits(&h->gb, 6);
854 my = get_bits(&h->c.gb, 6);854 my = get_bits(&h->gb, 6);
855 }855 }
856 856
857 mx += *mx_ptr - 32;857 mx += *mx_ptr - 32;
libavcodec/rv10.c+31−31
@@ -85,9 +85,9 @@ int ff_rv_decode_dc(H263DecContext *const h, int n) · 84 unmodified lines
85 int code;85 int code;
86 86
87 if (n < 4) {87 if (n < 4) {
88 code = get_vlc2(&h->c.gb, rv_dc_lum, DC_VLC_BITS, 2);88 code = get_vlc2(&h->gb, rv_dc_lum, DC_VLC_BITS, 2);
89 } else {89 } else {
90 code = get_vlc2(&h->c.gb, rv_dc_chrom, DC_VLC_BITS, 2);90 code = get_vlc2(&h->gb, rv_dc_chrom, DC_VLC_BITS, 2);
91 if (code < 0) {91 if (code < 0) {
92 av_log(h->c.avctx, AV_LOG_ERROR, "chroma dc error\n");92 av_log(h->c.avctx, AV_LOG_ERROR, "chroma dc error\n");
93 return -1;93 return -1;
@@ -101,9 +101,9 @@ static int rv10_decode_picture_header(H263DecContext *const h) · 7 unmodified lines
101{101{
102 int mb_count, pb_frame, marker, mb_xy;102 int mb_count, pb_frame, marker, mb_xy;
103 103
104 marker = get_bits1(&h->c.gb);104 marker = get_bits1(&h->gb);
105 105
106 if (get_bits1(&h->c.gb))106 if (get_bits1(&h->gb))
107 h->c.pict_type = AV_PICTURE_TYPE_P;107 h->c.pict_type = AV_PICTURE_TYPE_P;
108 else108 else
109 h->c.pict_type = AV_PICTURE_TYPE_I;109 h->c.pict_type = AV_PICTURE_TYPE_I;
@@ -111,7 +111,7 @@ static int rv10_decode_picture_header(H263DecContext *const h) · 1 unmodified line
111 if (!marker)111 if (!marker)
112 av_log(h->c.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(&h->c.gb);114 pb_frame = get_bits1(&h->gb);
115 115
116 ff_dlog(h->c.avctx, "pict_type=%d pb_frame=%d\n", h->c.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
@@ -120,7 +120,7 @@ static int rv10_decode_picture_header(H263DecContext *const h) · 2 unmodified lines
120 return AVERROR_PATCHWELCOME;120 return AVERROR_PATCHWELCOME;
121 }121 }
122 122
123 h->c.qscale = get_bits(&h->c.gb, 5);123 h->c.qscale = get_bits(&h->gb, 5);
124 if (h->c.qscale == 0) {124 if (h->c.qscale == 0) {
125 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");125 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
126 return AVERROR_INVALIDDATA;126 return AVERROR_INVALIDDATA;
@@ -129,9 +129,9 @@ static int rv10_decode_picture_header(H263DecContext *const h) · 2 unmodified lines
129 if (h->c.pict_type == AV_PICTURE_TYPE_I) {129 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
130 if (h->c.rv10_version == 3) {130 if (h->c.rv10_version == 3) {
131 /* specific MPEG like DC coding not used */131 /* specific MPEG like DC coding not used */
132 h->c.last_dc[0] = get_bits(&h->c.gb, 8);132 h->c.last_dc[0] = get_bits(&h->gb, 8);
133 h->c.last_dc[1] = get_bits(&h->c.gb, 8);133 h->c.last_dc[1] = get_bits(&h->gb, 8);
134 h->c.last_dc[2] = get_bits(&h->c.gb, 8);134 h->c.last_dc[2] = get_bits(&h->gb, 8);
135 ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0],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]);136 h->c.last_dc[1], h->c.last_dc[2]);
137 }137 }
@@ -140,16 +140,16 @@ static int rv10_decode_picture_header(H263DecContext *const h) · 2 unmodified lines
140 * to display the macroblocks is coded here */140 * to display the macroblocks is coded here */
141 141
142 mb_xy = h->c.mb_x + h->c.mb_y * h->c.mb_width;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)) {143 if (show_bits(&h->gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) {
144 h->c.mb_x = get_bits(&h->c.gb, 6); /* mb_x */144 h->c.mb_x = get_bits(&h->gb, 6); /* mb_x */
145 h->c.mb_y = get_bits(&h->c.gb, 6); /* mb_y */145 h->c.mb_y = get_bits(&h->gb, 6); /* mb_y */
146 mb_count = get_bits(&h->c.gb, 12);146 mb_count = get_bits(&h->gb, 12);
147 } else {147 } else {
148 h->c.mb_x = 0;148 h->c.mb_x = 0;
149 h->c.mb_y = 0;149 h->c.mb_y = 0;
150 mb_count = h->c.mb_width * h->c.mb_height;150 mb_count = h->c.mb_width * h->c.mb_height;
151 }151 }
152 skip_bits(&h->c.gb, 3); /* ignored */152 skip_bits(&h->gb, 3); /* ignored */
153 153
154 return mb_count;154 return mb_count;
155}155}
@@ -163,7 +163,7 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size) · 7 unmodified lines
163 int seq, mb_pos, ret;163 int seq, mb_pos, ret;
164 int rpr_max;164 int rpr_max;
165 165
166 h->c.pict_type = pict_types[get_bits(&h->c.gb, 2)];166 h->c.pict_type = pict_types[get_bits(&h->gb, 2)];
167 167
168 if (h->c.low_delay && h->c.pict_type == AV_PICTURE_TYPE_B) {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");169 av_log(h->c.avctx, AV_LOG_ERROR, "low delay B\n");
@@ -174,31 +174,31 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size) · 4 unmodified lines
174 return AVERROR_INVALIDDATA;174 return AVERROR_INVALIDDATA;
175 }175 }
176 176
177 if (get_bits1(&h->c.gb)) {177 if (get_bits1(&h->gb)) {
178 av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n");178 av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n");
179 return AVERROR_INVALIDDATA;179 return AVERROR_INVALIDDATA;
180 }180 }
181 181
182 h->c.qscale = get_bits(&h->c.gb, 5);182 h->c.qscale = get_bits(&h->gb, 5);
183 if (h->c.qscale == 0) {183 if (h->c.qscale == 0) {
184 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");184 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
185 return AVERROR_INVALIDDATA;185 return AVERROR_INVALIDDATA;
186 }186 }
187 187
188 if (RV_GET_MINOR_VER(rv->sub_id) >= 2)188 if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
189 h->c.loop_filter = get_bits1(&h->c.gb) && !h->c.avctx->lowres;189 h->c.loop_filter = get_bits1(&h->gb) && !h->c.avctx->lowres;
190 190
191 if (RV_GET_MINOR_VER(rv->sub_id) <= 1)191 if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
192 seq = get_bits(&h->c.gb, 8) << 7;192 seq = get_bits(&h->gb, 8) << 7;
193 else193 else
194 seq = get_bits(&h->c.gb, 13) << 2;194 seq = get_bits(&h->gb, 13) << 2;
195 195
196 rpr_max = h->c.avctx->extradata[1] & 7;196 rpr_max = h->c.avctx->extradata[1] & 7;
197 if (rpr_max) {197 if (rpr_max) {
198 int f, new_w, new_h;198 int f, new_w, new_h;
199 int rpr_bits = av_log2(rpr_max) + 1;199 int rpr_bits = av_log2(rpr_max) + 1;
200 200
201 f = get_bits(&h->c.gb, rpr_bits);201 f = get_bits(&h->gb, rpr_bits);
202 202
203 if (f) {203 if (f) {
204 if (h->c.avctx->extradata_size < 8 + 2 * f) {204 if (h->c.avctx->extradata_size < 8 + 2 * f) {
@@ -277,11 +277,11 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size) · 72 unmodified lines
277 ff_mpeg4_init_direct_mv(&h->c);277 ff_mpeg4_init_direct_mv(&h->c);
278 }278 }
279 279
280 h->c.no_rounding = get_bits1(&h->c.gb);280 h->c.no_rounding = get_bits1(&h->gb);
281 281
282 if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && h->c.pict_type == AV_PICTURE_TYPE_B)282 if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && h->c.pict_type == AV_PICTURE_TYPE_B)
283 // binary decoder reads 3+2 bits here but they don't seem to be used283 // binary decoder reads 3+2 bits here but they don't seem to be used
284 skip_bits(&h->c.gb, 5);284 skip_bits(&h->gb, 5);
285 285
286 h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I;286 h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I;
287 if (h->c.h263_aic) {287 if (h->c.h263_aic) {
@@ -416,7 +416,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 128 unmodified lines
416 int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;416 int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;
417 417
418 active_bits_size = buf_size * 8;418 active_bits_size = buf_size * 8;
419 init_get_bits(&h->c.gb, buf, FFMAX(buf_size, buf_size2) * 8);419 init_get_bits(&h->gb, buf, FFMAX(buf_size, buf_size2) * 8);
420 if (h->c.codec_id == AV_CODEC_ID_RV10)420 if (h->c.codec_id == AV_CODEC_ID_RV10)
421 mb_count = rv10_decode_picture_header(h);421 mb_count = rv10_decode_picture_header(h);
422 else422 else
@@ -492,24 +492,24 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 69 unmodified lines
492 492
493 // Repeat the slice end check from ff_h263_decode_mb with our active493 // Repeat the slice end check from ff_h263_decode_mb with our active
494 // bitstream size494 // bitstream size
495 if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->c.gb)) {495 if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->gb)) {
496 int v = show_bits(&h->c.gb, 16);496 int v = show_bits(&h->gb, 16);
497 497
498 if (get_bits_count(&h->c.gb) + 16 > active_bits_size)498 if (get_bits_count(&h->gb) + 16 > active_bits_size)
499 v >>= get_bits_count(&h->c.gb) + 16 - active_bits_size;499 v >>= get_bits_count(&h->gb) + 16 - active_bits_size;
500 500
501 if (!v)501 if (!v)
502 ret = SLICE_END;502 ret = SLICE_END;
503 }503 }
504 if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->c.gb) &&504 if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->gb) &&
505 8 * buf_size2 >= get_bits_count(&h->c.gb)) {505 8 * buf_size2 >= get_bits_count(&h->gb)) {
506 active_bits_size = buf_size2 * 8;506 active_bits_size = buf_size2 * 8;
507 av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",507 av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
508 8 * buf_size, active_bits_size);508 8 * buf_size, active_bits_size);
509 ret = SLICE_OK;509 ret = SLICE_OK;
510 }510 }
511 511
512 if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->c.gb)) {512 if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->gb)) {
513 av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x,513 av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x,
514 h->c.mb_y);514 h->c.mb_y);
515 return AVERROR_INVALIDDATA;515 return AVERROR_INVALIDDATA;
libavcodec/vaapi_mpeg4.c+4−4
@@ -157,8 +157,8 @@ fail: · 156 unmodified lines
157 157
158static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)158static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
159{159{
160 MpegEncContext *s = avctx->priv_data;160 H263DecContext *const h = avctx->priv_data;
161 VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;161 VAAPIDecodePicture *pic = h->c.cur_pic.ptr->hwaccel_picture_private;
162 VASliceParameterBufferMPEG4 slice_param;162 VASliceParameterBufferMPEG4 slice_param;
163 int err;163 int err;
164 164
@@ -166,9 +166,9 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer · 1 unmodified line
166 .slice_data_size = size,166 .slice_data_size = size,
167 .slice_data_offset = 0,167 .slice_data_offset = 0,
168 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,168 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
169 .macroblock_offset = get_bits_count(&s->gb) % 8,169 .macroblock_offset = get_bits_count(&h->gb) % 8,
170 .macroblock_number = 0,170 .macroblock_number = 0,
171 .quant_scale = s->qscale,171 .quant_scale = h->c.qscale,
172 };172 };
173 173
174 err = ff_vaapi_decode_make_slice_buffer(avctx, pic,174 err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
libavcodec/wmv2dec.c+46−46
@@ -105,7 +105,7 @@ static int parse_mb_skip(WMV2DecContext *w) · 104 unmodified lines
105 int coded_mb_count = 0;105 int coded_mb_count = 0;
106 uint32_t *const mb_type = h->c.cur_pic.mb_type;106 uint32_t *const mb_type = h->c.cur_pic.mb_type;
107 107
108 w->skip_type = get_bits(&h->c.gb, 2);108 w->skip_type = get_bits(&h->gb, 2);
109 switch (w->skip_type) {109 switch (w->skip_type) {
110 case SKIP_TYPE_NONE:110 case SKIP_TYPE_NONE:
111 for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)111 for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
@@ -114,40 +114,40 @@ static int parse_mb_skip(WMV2DecContext *w) · 2 unmodified lines
114 MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;114 MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
115 break;115 break;
116 case SKIP_TYPE_MPEG:116 case SKIP_TYPE_MPEG:
117 if (get_bits_left(&h->c.gb) < h->c.mb_height * h->c.mb_width)117 if (get_bits_left(&h->gb) < h->c.mb_height * h->c.mb_width)
118 return AVERROR_INVALIDDATA;118 return AVERROR_INVALIDDATA;
119 for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)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++)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] =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;122 (get_bits1(&h->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
123 break;123 break;
124 case SKIP_TYPE_ROW:124 case SKIP_TYPE_ROW:
125 for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) {125 for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) {
126 if (get_bits_left(&h->c.gb) < 1)126 if (get_bits_left(&h->gb) < 1)
127 return AVERROR_INVALIDDATA;127 return AVERROR_INVALIDDATA;
128 if (get_bits1(&h->c.gb)) {128 if (get_bits1(&h->gb)) {
129 for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)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] =130 mb_type[mb_y * h->c.mb_stride + mb_x] =
131 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;131 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
132 } else {132 } else {
133 for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)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] =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;135 (get_bits1(&h->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
136 }136 }
137 }137 }
138 break;138 break;
139 case SKIP_TYPE_COL:139 case SKIP_TYPE_COL:
140 for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) {140 for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) {
141 if (get_bits_left(&h->c.gb) < 1)141 if (get_bits_left(&h->gb) < 1)
142 return AVERROR_INVALIDDATA;142 return AVERROR_INVALIDDATA;
143 if (get_bits1(&h->c.gb)) {143 if (get_bits1(&h->gb)) {
144 for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)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] =145 mb_type[mb_y * h->c.mb_stride + mb_x] =
146 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;146 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
147 } else {147 } else {
148 for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)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] =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;150 (get_bits1(&h->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
151 }151 }
152 }152 }
153 break;153 break;
@@ -157,7 +157,7 @@ static int parse_mb_skip(WMV2DecContext *w) · 3 unmodified lines
157 for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)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]);158 coded_mb_count += !IS_SKIP(mb_type[mb_y * h->c.mb_stride + mb_x]);
159 159
160 if (coded_mb_count > get_bits_left(&h->c.gb))160 if (coded_mb_count > get_bits_left(&h->gb))
161 return AVERROR_INVALIDDATA;161 return AVERROR_INVALIDDATA;
162 162
163 return 0;163 return 0;
@@ -205,17 +205,17 @@ int ff_wmv2_decode_picture_header(H263DecContext *const h) · 41 unmodified lines
205{205{
206 int code;206 int code;
207 207
208 h->c.pict_type = get_bits1(&h->c.gb) + 1;208 h->c.pict_type = get_bits1(&h->gb) + 1;
209 if (h->c.pict_type == AV_PICTURE_TYPE_I) {209 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
210 code = get_bits(&h->c.gb, 7);210 code = get_bits(&h->gb, 7);
211 av_log(h->c.avctx, AV_LOG_DEBUG, "I7:%X/\n", code);211 av_log(h->c.avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
212 }212 }
213 h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);213 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
214 if (h->c.qscale <= 0)214 if (h->c.qscale <= 0)
215 return AVERROR_INVALIDDATA;215 return AVERROR_INVALIDDATA;
216 216
217 if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->c.gb, 1)) {217 if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->gb, 1)) {
218 GetBitContext gb = h->c.gb;218 GetBitContext gb = h->gb;
219 int skip_type = get_bits(&gb, 2);219 int skip_type = get_bits(&gb, 2);
220 int run = skip_type == SKIP_TYPE_COL ? h->c.mb_width : h->c.mb_height;220 int run = skip_type == SKIP_TYPE_COL ? h->c.mb_width : h->c.mb_height;
221 221
@@ -241,29 +241,29 @@ int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h) · 19 unmodified lines
241 memset(h->c.cur_pic.mb_type, 0,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);242 sizeof(*h->c.cur_pic.mb_type) * h->c.mb_height * h->c.mb_stride);
243 if (w->j_type_bit)243 if (w->j_type_bit)
244 w->j_type = get_bits1(&h->c.gb);244 w->j_type = get_bits1(&h->gb);
245 else245 else
246 w->j_type = 0; // FIXME check246 w->j_type = 0; // FIXME check
247 247
248 if (!w->j_type) {248 if (!w->j_type) {
249 if (w->per_mb_rl_bit)249 if (w->per_mb_rl_bit)
250 w->ms.per_mb_rl_table = get_bits1(&h->c.gb);250 w->ms.per_mb_rl_table = get_bits1(&h->gb);
251 else251 else
252 w->ms.per_mb_rl_table = 0;252 w->ms.per_mb_rl_table = 0;
253 253
254 if (!w->ms.per_mb_rl_table) {254 if (!w->ms.per_mb_rl_table) {
255 w->ms.rl_chroma_table_index = decode012(&h->c.gb);255 w->ms.rl_chroma_table_index = decode012(&h->gb);
256 w->ms.rl_table_index = decode012(&h->c.gb);256 w->ms.rl_table_index = decode012(&h->gb);
257 }257 }
258 258
259 w->ms.dc_table_index = get_bits1(&h->c.gb);259 w->ms.dc_table_index = get_bits1(&h->gb);
260 260
261 // at minimum one bit per macroblock is required at least in a valid frame,261 // at minimum one bit per macroblock is required at least in a valid frame,
262 // we discard frames much smaller than this. Frames smaller than 1/8 of the262 // we discard frames much smaller than this. Frames smaller than 1/8 of the
263 // smallest "black/skip" frame generally contain not much recoverable content263 // smallest "black/skip" frame generally contain not much recoverable content
264 // while at the same time they have the highest computational requirements264 // while at the same time they have the highest computational requirements
265 // per byte265 // per byte
266 if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))266 if (get_bits_left(&h->gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
267 return AVERROR_INVALIDDATA;267 return AVERROR_INVALIDDATA;
268 }268 }
269 h->c.inter_intra_pred = 0;269 h->c.inter_intra_pred = 0;
@@ -282,35 +282,35 @@ int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h) · 12 unmodified lines
282 ret = parse_mb_skip(w);282 ret = parse_mb_skip(w);
283 if (ret < 0)283 if (ret < 0)
284 return ret;284 return ret;
285 cbp_index = decode012(&h->c.gb);285 cbp_index = decode012(&h->gb);
286 w->cbp_table_index = wmv2_get_cbp_table_index(h->c.qscale, cbp_index);286 w->cbp_table_index = wmv2_get_cbp_table_index(h->c.qscale, cbp_index);
287 287
288 if (w->mspel_bit)288 if (w->mspel_bit)
289 h->c.mspel = get_bits1(&h->c.gb);289 h->c.mspel = get_bits1(&h->gb);
290 else290 else
291 h->c.mspel = 0; // FIXME check291 h->c.mspel = 0; // FIXME check
292 292
293 if (w->abt_flag) {293 if (w->abt_flag) {
294 w->per_mb_abt = get_bits1(&h->c.gb) ^ 1;294 w->per_mb_abt = get_bits1(&h->gb) ^ 1;
295 if (!w->per_mb_abt)295 if (!w->per_mb_abt)
296 w->abt_type = decode012(&h->c.gb);296 w->abt_type = decode012(&h->gb);
297 }297 }
298 298
299 if (w->per_mb_rl_bit)299 if (w->per_mb_rl_bit)
300 w->ms.per_mb_rl_table = get_bits1(&h->c.gb);300 w->ms.per_mb_rl_table = get_bits1(&h->gb);
301 else301 else
302 w->ms.per_mb_rl_table = 0;302 w->ms.per_mb_rl_table = 0;
303 303
304 if (!w->ms.per_mb_rl_table) {304 if (!w->ms.per_mb_rl_table) {
305 w->ms.rl_table_index = decode012(&h->c.gb);305 w->ms.rl_table_index = decode012(&h->gb);
306 w->ms.rl_chroma_table_index = w->ms.rl_table_index;306 w->ms.rl_chroma_table_index = w->ms.rl_table_index;
307 }307 }
308 308
309 if (get_bits_left(&h->c.gb) < 2)309 if (get_bits_left(&h->gb) < 2)
310 return AVERROR_INVALIDDATA;310 return AVERROR_INVALIDDATA;
311 311
312 w->ms.dc_table_index = get_bits1(&h->c.gb);312 w->ms.dc_table_index = get_bits1(&h->gb);
313 w->ms.mv_table_index = get_bits1(&h->c.gb);313 w->ms.mv_table_index = get_bits1(&h->gb);
314 314
315 h->c.inter_intra_pred = 0; // (h->c.width * h->c.height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);315 h->c.inter_intra_pred = 0; // (h->c.width * h->c.height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);
316 h->c.no_rounding ^= 1;316 h->c.no_rounding ^= 1;
@@ -331,7 +331,7 @@ int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h) · 14 unmodified lines
331 331
332 if (w->j_type) {332 if (w->j_type) {
333 ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr,333 ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr,
334 &h->c.gb, &h->c.mb_x, &h->c.mb_y,334 &h->gb, &h->c.mb_x, &h->c.mb_y,
335 2 * h->c.qscale, (h->c.qscale - 1) | 1,335 2 * h->c.qscale, (h->c.qscale - 1) | 1,
336 h->c.loop_filter, h->c.low_delay);336 h->c.loop_filter, h->c.low_delay);
337 337
@@ -351,7 +351,7 @@ static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_pt · 13 unmodified lines
351 ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr);351 ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr);
352 352
353 if ((((*mx_ptr) | (*my_ptr)) & 1) && h->c.mspel)353 if ((((*mx_ptr) | (*my_ptr)) & 1) && h->c.mspel)
354 w->common.hshift = get_bits1(&h->c.gb);354 w->common.hshift = get_bits1(&h->gb);
355 else355 else
356 w->common.hshift = 0;356 w->common.hshift = 0;
357}357}
@@ -376,7 +376,7 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) · 18 unmodified lines
376 diff = 0;376 diff = 0;
377 377
378 if (diff >= 8)378 if (diff >= 8)
379 type = get_bits1(&h->c.gb);379 type = get_bits1(&h->gb);
380 else380 else
381 type = 2;381 type = 2;
382 382
@@ -413,13 +413,13 @@ static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block, · 30 unmodified lines
413 }413 }
414 414
415 if (w->per_block_abt)415 if (w->per_block_abt)
416 w->abt_type = decode012(&h->c.gb);416 w->abt_type = decode012(&h->gb);
417 w->abt_type_table[n] = w->abt_type;417 w->abt_type_table[n] = w->abt_type;
418 418
419 if (w->abt_type) {419 if (w->abt_type) {
420 const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : ff_wmv2_scantableB;420 const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : ff_wmv2_scantableB;
421 421
422 sub_cbp = sub_cbp_table[decode012(&h->c.gb)];422 sub_cbp = sub_cbp_table[decode012(&h->gb)];
423 423
424 if (sub_cbp & 1) {424 if (sub_cbp & 1) {
425 ret = ff_msmpeg4_decode_block(&w->ms, block, n, 1, scantable);425 ret = ff_msmpeg4_decode_block(&w->ms, block, n, 1, scantable);
@@ -468,19 +468,19 @@ static int wmv2_decode_mb(H263DecContext *const h) · 42 unmodified lines
468 w->common.hshift = 0;468 w->common.hshift = 0;
469 return 0;469 return 0;
470 }470 }
471 if (get_bits_left(&h->c.gb) <= 0)471 if (get_bits_left(&h->gb) <= 0)
472 return AVERROR_INVALIDDATA;472 return AVERROR_INVALIDDATA;
473 473
474 code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[w->cbp_table_index],474 code = get_vlc2(&h->gb, ff_mb_non_intra_vlc[w->cbp_table_index],
475 MB_NON_INTRA_VLC_BITS, 3);475 MB_NON_INTRA_VLC_BITS, 3);
476 h->c.mb_intra = (~code & 0x40) >> 6;476 h->c.mb_intra = (~code & 0x40) >> 6;
477 477
478 cbp = code & 0x3f;478 cbp = code & 0x3f;
479 } else {479 } else {
480 h->c.mb_intra = 1;480 h->c.mb_intra = 1;
481 if (get_bits_left(&h->c.gb) <= 0)481 if (get_bits_left(&h->gb) <= 0)
482 return AVERROR_INVALIDDATA;482 return AVERROR_INVALIDDATA;
483 code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc,483 code = get_vlc2(&h->gb, ff_msmp4_mb_i_vlc,
484 MSMP4_MB_INTRA_VLC_BITS, 2);484 MSMP4_MB_INTRA_VLC_BITS, 2);
485 /* predict coded block pattern */485 /* predict coded block pattern */
486 cbp = 0;486 cbp = 0;
@@ -502,14 +502,14 @@ static int wmv2_decode_mb(H263DecContext *const h) · 15 unmodified lines
502 if (cbp) {502 if (cbp) {
503 h->c.bdsp.clear_blocks(h->block[0]);503 h->c.bdsp.clear_blocks(h->block[0]);
504 if (ms->per_mb_rl_table) {504 if (ms->per_mb_rl_table) {
505 ms->rl_table_index = decode012(&h->c.gb);505 ms->rl_table_index = decode012(&h->gb);
506 ms->rl_chroma_table_index = ms->rl_table_index;506 ms->rl_chroma_table_index = ms->rl_table_index;
507 }507 }
508 508
509 if (w->abt_flag && w->per_mb_abt) {509 if (w->abt_flag && w->per_mb_abt) {
510 w->per_block_abt = get_bits1(&h->c.gb);510 w->per_block_abt = get_bits1(&h->gb);
511 if (!w->per_block_abt)511 if (!w->per_block_abt)
512 w->abt_type = decode012(&h->c.gb);512 w->abt_type = decode012(&h->gb);
513 } else513 } else
514 w->per_block_abt = 0;514 w->per_block_abt = 0;
515 }515 }
@@ -534,16 +534,16 @@ static int wmv2_decode_mb(H263DecContext *const h) · 18 unmodified lines
534 ff_dlog(h->c.avctx, "%d%d ", h->c.inter_intra_pred, cbp);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,535 ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
536 ((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0),536 ((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0),
537 show_bits(&h->c.gb, 24));537 show_bits(&h->gb, 24));
538 h->c.ac_pred = get_bits1(&h->c.gb);538 h->c.ac_pred = get_bits1(&h->gb);
539 if (h->c.inter_intra_pred) {539 if (h->c.inter_intra_pred) {
540 h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc,540 h->c.h263_aic_dir = get_vlc2(&h->gb, ff_inter_intra_vlc,
541 INTER_INTRA_VLC_BITS, 1);541 INTER_INTRA_VLC_BITS, 1);
542 ff_dlog(h->c.avctx, "%d%d %d %d/",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);543 h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
544 }544 }
545 if (ms->per_mb_rl_table && cbp) {545 if (ms->per_mb_rl_table && cbp) {
546 ms->rl_table_index = decode012(&h->c.gb);546 ms->rl_table_index = decode012(&h->gb);
547 ms->rl_chroma_table_index = ms->rl_table_index;547 ms->rl_chroma_table_index = ms->rl_table_index;
548 }548 }
549 549

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t