avformat/matroskadec: Replace switch with array

This simplification reduces codesize.
(It even reduces the size of .rodata here, because
the jump table used by the compiler is bigger than
the actual array.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/390/head
Andreas Rheinhardt 1 year ago
parent 9c46faaf77
commit b3825bd711
  1. 47
      libavformat/matroskadec.c

@ -2165,6 +2165,15 @@ static void mkv_stereo_mode_display_mul(int stereo_mode,
static int mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mode)
{
static const struct {
char type;
char flags;
} stereo_mode_conv [] = {
#define STEREO_MODE_CONV(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
[(STEREOMODETYPE)] = { .type = (STEREO3DTYPE), .flags = (FLAGS) },
#define IGNORE(STEREOMODETYPE, WDIV, HDIV, WEBM)
STEREOMODE_STEREO3D_MAPPING(STEREO_MODE_CONV, IGNORE)
};
AVStereo3D *stereo;
int ret;
@ -2172,42 +2181,8 @@ static int mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mo
if (!stereo)
return AVERROR(ENOMEM);
// note: the missing breaks are intentional
switch (stereo_mode) {
case MATROSKA_VIDEO_STEREOMODE_TYPE_MONO:
stereo->type = AV_STEREO3D_2D;
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT:
stereo->flags |= AV_STEREO3D_FLAG_INVERT;
case MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT:
stereo->type = AV_STEREO3D_SIDEBYSIDE;
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTTOM_TOP:
stereo->flags |= AV_STEREO3D_FLAG_INVERT;
case MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM:
stereo->type = AV_STEREO3D_TOPBOTTOM;
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_RL:
stereo->flags |= AV_STEREO3D_FLAG_INVERT;
case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR:
stereo->type = AV_STEREO3D_CHECKERBOARD;
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_RL:
stereo->flags |= AV_STEREO3D_FLAG_INVERT;
case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR:
stereo->type = AV_STEREO3D_LINES;
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_RL:
stereo->flags |= AV_STEREO3D_FLAG_INVERT;
case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR:
stereo->type = AV_STEREO3D_COLUMNS;
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL:
stereo->flags |= AV_STEREO3D_FLAG_INVERT;
case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR:
stereo->type = AV_STEREO3D_FRAMESEQUENCE;
break;
}
stereo->type = stereo_mode_conv[stereo_mode].type;
stereo->flags = stereo_mode_conv[stereo_mode].flags;
ret = av_stream_add_side_data(st, AV_PKT_DATA_STEREO3D, (uint8_t *)stereo,
sizeof(*stereo));

Loading…
Cancel
Save