History

avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo

MB_TYPE_L[01] is based upon H.264 terminology (it stands for list); yet the mpegvideo based decoders don't have lists of reference frames, they have at most one forward and one backward reference. So use terminology based upon this. This also has a second advantage: MB_TYPE_L[01] is actually an OR of two flags (which are set independently for H.264, but aren't for mpegvideo). Switching to different flags makes the flags fit into an int16_t, which will be useful in future commits. The only downside to this is a very small amount of code in error_resilience.c and mpegutils.c (the only code shared between the H.264 decoder and mpegvideo).

Andreas Rheinhardt committed 2 years ago

Commit f5d5b801 parent 07ae09b12 files · +123 −111Browse files

Showing the changes to libavcodec/mpegutils.c (1 of 12 files). Show all

Unified · Split

libavcodec/mpegutils.c+14−9
@@ -104,7 +104,9 @@ void ff_draw_horiz_band(AVCodecContext *avctx, · 103 unmodified lines
104104 y, picture_structure, h);
105105 }
106106
107−static char get_type_mv_char(int mb_type)
107+#define HAS_MV_EXT(mb_type, flags, dir) ((mb_type) & flags[(dir)])
108+
109+static char get_type_mv_char(int mb_type, const int mb_type_mv_flags[2])
108110 {
109111 // Type & MV direction
110112 if (IS_PCM(mb_type))
@@ -125,12 +127,12 @@ static char get_type_mv_char(int mb_type) · 14 unmodified lines
125127 return 'G';
126128 else if (IS_SKIP(mb_type))
127129 return 'S';
128− else if (!USES_LIST(mb_type, 1))
130+ else if (!HAS_MV_EXT(mb_type, 1, mb_type_mv_flags))
129131 return '>';
130− else if (!USES_LIST(mb_type, 0))
132+ else if (!HAS_MV_EXT(mb_type, 0, mb_type_mv_flags))
131133 return '<';
132134 else {
133− av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
135+ av_assert2(HAS_MV_EXT(mb_type, 0, mb_type_mv_flags) && HAS_MV_EXT(mb_type, 1, mb_type_mv_flags));
134136 return 'X';
135137 }
136138 }
@@ -162,12 +164,15 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, · 25 unmodified lines
162164 const int8_t *qscale_table, int16_t (*const motion_val[2])[2],
163165 int mb_width, int mb_height, int mb_stride, int quarter_sample)
164166 {
167+ const int is_h264 = avctx->codec_id == AV_CODEC_ID_H264;
168+ const int mb_type_mv_flags[2] = { is_h264 ? MB_TYPE_L0 : MB_TYPE_FORWARD_MV,
169+ is_h264 ? MB_TYPE_L1 : MB_TYPE_BACKWARD_MV };
170+
165171 if ((avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) && mbtype_table && motion_val[0]) {
166172 const int shift = 1 + quarter_sample;
167173 const int scale = 1 << shift;
168− const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 ? 2 : 1;
169− const int mv_stride = (mb_width << mv_sample_log2) +
170− (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
174+ const int mv_sample_log2 = is_h264 ? 2 : 1;
175+ const int mv_stride = (mb_width << mv_sample_log2) + !is_h264;
171176 int mb_x, mb_y, mbcount = 0;
172177
173178 /* size is width * height * 2 * 4 where 2 is for directions and 4 is
@@ -180,7 +185,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, · 6 unmodified lines
180185 for (mb_x = 0; mb_x < mb_width; mb_x++) {
181186 int i, direction, mb_type = mbtype_table[mb_x + mb_y * mb_stride];
182187 for (direction = 0; direction < 2; direction++) {
183− if (!USES_LIST(mb_type, direction))
188+ if (!HAS_MV_EXT(mb_type, direction, mb_type_mv_flags))
184189 continue;
185190 if (IS_8X8(mb_type)) {
186191 for (i = 0; i < 4; i++) {
@@ -299,7 +304,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, · 112 unmodified lines
299304 int mb_type = mbtype_table[x + y * mb_stride];
300305
301306 av_bprintf(&buf, "%c%c%c",
302− get_type_mv_char(mb_type),
307+ get_type_mv_char(mb_type, mb_type_mv_flags),
303308 get_segmentation_char(mb_type),
304309 get_interlacement_char(mb_type));
305310 }

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