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
104 y, picture_structure, h);104 y, picture_structure, h);
105}105}
106 106
107static char get_type_mv_char(int mb_type)107#define HAS_MV_EXT(mb_type, flags, dir) ((mb_type) & flags[(dir)])
108
109static char get_type_mv_char(int mb_type, const int mb_type_mv_flags[2])
108{110{
109 // Type & MV direction111 // Type & MV direction
110 if (IS_PCM(mb_type))112 if (IS_PCM(mb_type))
@@ -125,12 +127,12 @@ static char get_type_mv_char(int mb_type) · 14 unmodified lines
125 return 'G';127 return 'G';
126 else if (IS_SKIP(mb_type))128 else if (IS_SKIP(mb_type))
127 return 'S';129 return 'S';
128 else if (!USES_LIST(mb_type, 1))130 else if (!HAS_MV_EXT(mb_type, 1, mb_type_mv_flags))
129 return '>';131 return '>';
130 else if (!USES_LIST(mb_type, 0))132 else if (!HAS_MV_EXT(mb_type, 0, mb_type_mv_flags))
131 return '<';133 return '<';
132 else {134 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));
134 return 'X';136 return 'X';
135 }137 }
136}138}
@@ -162,12 +164,15 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, · 25 unmodified lines
162 const int8_t *qscale_table, int16_t (*const motion_val[2])[2],164 const int8_t *qscale_table, int16_t (*const motion_val[2])[2],
163 int mb_width, int mb_height, int mb_stride, int quarter_sample)165 int mb_width, int mb_height, int mb_stride, int quarter_sample)
164{166{
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
165 if ((avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) && mbtype_table && motion_val[0]) {171 if ((avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) && mbtype_table && motion_val[0]) {
166 const int shift = 1 + quarter_sample;172 const int shift = 1 + quarter_sample;
167 const int scale = 1 << shift;173 const int scale = 1 << shift;
168 const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 ? 2 : 1;174 const int mv_sample_log2 = is_h264 ? 2 : 1;
169 const int mv_stride = (mb_width << mv_sample_log2) +175 const int mv_stride = (mb_width << mv_sample_log2) + !is_h264;
170 (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
171 int mb_x, mb_y, mbcount = 0;176 int mb_x, mb_y, mbcount = 0;
172 177
173 /* size is width * height * 2 * 4 where 2 is for directions and 4 is178 /* 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
180 for (mb_x = 0; mb_x < mb_width; mb_x++) {185 for (mb_x = 0; mb_x < mb_width; mb_x++) {
181 int i, direction, mb_type = mbtype_table[mb_x + mb_y * mb_stride];186 int i, direction, mb_type = mbtype_table[mb_x + mb_y * mb_stride];
182 for (direction = 0; direction < 2; direction++) {187 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))
184 continue;189 continue;
185 if (IS_8X8(mb_type)) {190 if (IS_8X8(mb_type)) {
186 for (i = 0; i < 4; i++) {191 for (i = 0; i < 4; i++) {
@@ -299,7 +304,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, · 112 unmodified lines
299 int mb_type = mbtype_table[x + y * mb_stride];304 int mb_type = mbtype_table[x + y * mb_stride];
300 305
301 av_bprintf(&buf, "%c%c%c",306 av_bprintf(&buf, "%c%c%c",
302 get_type_mv_char(mb_type),307 get_type_mv_char(mb_type, mb_type_mv_flags),
303 get_segmentation_char(mb_type),308 get_segmentation_char(mb_type),
304 get_interlacement_char(mb_type));309 get_interlacement_char(mb_type));
305 }310 }

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