diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-10-10 20:28:16 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-10-10 20:59:05 +0200 |
commit | 8227f60fee0b2ae0924ee6f9b1ed505d3a443526 (patch) | |
tree | 36a9ee3d370a7a567f4a73485dd35c5f6bbe97de /libavcodec/sheervideo.c | |
parent | d3f35224a91e2f32c45a9d09f0867c688e590231 (diff) | |
download | ffmpeg-8227f60fee0b2ae0924ee6f9b1ed505d3a443526.tar.gz |
avcodec/sheervideo: Avoid code duplication when creating VLC tables
The SheerVideo decoder uses two VLC tables and these are in turn created
from structures (called SheerTable) that are naturally paired. This
commit unifies these pairs of SheerTables to arrays and unifies creating
the VLC tables.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/sheervideo.c')
-rw-r--r-- | libavcodec/sheervideo.c | 129 |
1 files changed, 28 insertions, 101 deletions
diff --git a/libavcodec/sheervideo.c b/libavcodec/sheervideo.c index 3471fdcff9..976c21c445 100644 --- a/libavcodec/sheervideo.c +++ b/libavcodec/sheervideo.c @@ -1816,6 +1816,7 @@ static int decode_frame(AVCodecContext *avctx, { SheerVideoContext *s = avctx->priv_data; ThreadFrame frame = { .f = data }; + const SheerTable *table; AVFrame *p = data; GetBitContext gb; unsigned format; @@ -1835,210 +1836,135 @@ static int decode_frame(AVCodecContext *avctx, case MKTAG(' ', 'R', 'G', 'B'): avctx->pix_fmt = AV_PIX_FMT_RGB0; s->decode_frame = decode_rgb; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgb); - ret |= build_vlc(&s->vlc[1], &l_g_rgb); - } + table = rgb; break; case MKTAG(' ', 'r', 'G', 'B'): avctx->pix_fmt = AV_PIX_FMT_RGB0; s->decode_frame = decode_rgbi; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgbi); - ret |= build_vlc(&s->vlc[1], &l_g_rgbi); - } + table = rgbi; break; case MKTAG('A', 'R', 'G', 'X'): avctx->pix_fmt = AV_PIX_FMT_GBRAP10; s->decode_frame = decode_argx; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgbx); - ret |= build_vlc(&s->vlc[1], &l_g_rgbx); - } + table = rgbx; break; case MKTAG('A', 'r', 'G', 'X'): avctx->pix_fmt = AV_PIX_FMT_GBRAP10; s->decode_frame = decode_argxi; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgbxi); - ret |= build_vlc(&s->vlc[1], &l_g_rgbxi); - } + table = rgbxi; break; case MKTAG('R', 'G', 'B', 'X'): avctx->pix_fmt = AV_PIX_FMT_GBRP10; s->decode_frame = decode_rgbx; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgbx); - ret |= build_vlc(&s->vlc[1], &l_g_rgbx); - } + table = rgbx; break; case MKTAG('r', 'G', 'B', 'X'): avctx->pix_fmt = AV_PIX_FMT_GBRP10; s->decode_frame = decode_rgbxi; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgbxi); - ret |= build_vlc(&s->vlc[1], &l_g_rgbxi); - } + table = rgbxi; break; case MKTAG('A', 'R', 'G', 'B'): avctx->pix_fmt = AV_PIX_FMT_ARGB; s->decode_frame = decode_argb; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgb); - ret |= build_vlc(&s->vlc[1], &l_g_rgb); - } + table = rgb; break; case MKTAG('A', 'r', 'G', 'B'): avctx->pix_fmt = AV_PIX_FMT_ARGB; s->decode_frame = decode_argbi; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_r_rgbi); - ret |= build_vlc(&s->vlc[1], &l_g_rgbi); - } + table = rgbi; break; case MKTAG('A', 'Y', 'B', 'R'): s->alt = 1; case MKTAG('A', 'Y', 'b', 'R'): avctx->pix_fmt = AV_PIX_FMT_YUVA444P; s->decode_frame = decode_aybr; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybr); - ret |= build_vlc(&s->vlc[1], &l_u_ybr); - } + table = ybr; break; case MKTAG('A', 'y', 'B', 'R'): s->alt = 1; case MKTAG('A', 'y', 'b', 'R'): avctx->pix_fmt = AV_PIX_FMT_YUVA444P; s->decode_frame = decode_aybri; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybri); - ret |= build_vlc(&s->vlc[1], &l_u_ybri); - } + table = ybri; break; case MKTAG(' ', 'Y', 'B', 'R'): s->alt = 1; case MKTAG(' ', 'Y', 'b', 'R'): avctx->pix_fmt = AV_PIX_FMT_YUV444P; s->decode_frame = decode_ybr; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybr); - ret |= build_vlc(&s->vlc[1], &l_u_ybr); - } + table = ybr; break; case MKTAG(' ', 'y', 'B', 'R'): s->alt = 1; case MKTAG(' ', 'y', 'b', 'R'): avctx->pix_fmt = AV_PIX_FMT_YUV444P; s->decode_frame = decode_ybri; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybri); - ret |= build_vlc(&s->vlc[1], &l_u_ybri); - } + table = ybri; break; case MKTAG('Y', 'B', 'R', 0x0a): avctx->pix_fmt = AV_PIX_FMT_YUV444P10; s->decode_frame = decode_ybr10; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybr10); - ret |= build_vlc(&s->vlc[1], &l_u_ybr10); - } + table = ybr10; break; case MKTAG('y', 'B', 'R', 0x0a): avctx->pix_fmt = AV_PIX_FMT_YUV444P10; s->decode_frame = decode_ybr10i; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybr10i); - ret |= build_vlc(&s->vlc[1], &l_u_ybr10i); - } + table = ybr10i; break; case MKTAG('C', 'A', '4', 'p'): avctx->pix_fmt = AV_PIX_FMT_YUVA444P10; s->decode_frame = decode_ca4p; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybr10); - ret |= build_vlc(&s->vlc[1], &l_u_ybr10); - } + table = ybr10; break; case MKTAG('C', 'A', '4', 'i'): avctx->pix_fmt = AV_PIX_FMT_YUVA444P10; s->decode_frame = decode_ca4i; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybr10i); - ret |= build_vlc(&s->vlc[1], &l_u_ybr10i); - } + table = ybr10i; break; case MKTAG('B', 'Y', 'R', 'Y'): avctx->pix_fmt = AV_PIX_FMT_YUV422P; s->decode_frame = decode_byry; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_byry); - ret |= build_vlc(&s->vlc[1], &l_u_byry); - } + table = byry; break; case MKTAG('B', 'Y', 'R', 'y'): avctx->pix_fmt = AV_PIX_FMT_YUV422P; s->decode_frame = decode_byryi; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_byryi); - ret |= build_vlc(&s->vlc[1], &l_u_byryi); - } + table = byryi; break; case MKTAG('Y', 'b', 'Y', 'r'): avctx->pix_fmt = AV_PIX_FMT_YUV422P; s->decode_frame = decode_ybyr; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_ybyr); - ret |= build_vlc(&s->vlc[1], &l_u_ybyr); - } + table = ybyr; break; case MKTAG('C', '8', '2', 'p'): avctx->pix_fmt = AV_PIX_FMT_YUVA422P; s->decode_frame = decode_c82p; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_byry); - ret |= build_vlc(&s->vlc[1], &l_u_byry); - } + table = byry; break; case MKTAG('C', '8', '2', 'i'): avctx->pix_fmt = AV_PIX_FMT_YUVA422P; s->decode_frame = decode_c82i; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_byryi); - ret |= build_vlc(&s->vlc[1], &l_u_byryi); - } + table = byryi; break; case MKTAG(0xa2, 'Y', 'R', 'Y'): avctx->pix_fmt = AV_PIX_FMT_YUV422P10; s->decode_frame = decode_yry10; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_yry10); - ret |= build_vlc(&s->vlc[1], &l_u_yry10); - } + table = yry10; break; case MKTAG(0xa2, 'Y', 'R', 'y'): avctx->pix_fmt = AV_PIX_FMT_YUV422P10; s->decode_frame = decode_yry10i; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_yry10i); - ret |= build_vlc(&s->vlc[1], &l_u_yry10i); - } + table = yry10i; break; case MKTAG('C', 'A', '2', 'p'): avctx->pix_fmt = AV_PIX_FMT_YUVA422P10; s->decode_frame = decode_ca2p; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_yry10); - ret |= build_vlc(&s->vlc[1], &l_u_yry10); - } + table = yry10; break; case MKTAG('C', 'A', '2', 'i'): avctx->pix_fmt = AV_PIX_FMT_YUVA422P10; s->decode_frame = decode_ca2i; - if (s->format != format) { - ret = build_vlc(&s->vlc[0], &l_y_yry10i); - ret |= build_vlc(&s->vlc[1], &l_u_yry10i); - } + table = yry10i; break; default: avpriv_request_sample(avctx, "unsupported format: 0x%X", format); @@ -2046,7 +1972,8 @@ static int decode_frame(AVCodecContext *avctx, } if (s->format != format) { - if (ret < 0) { + if ((ret = build_vlc(&s->vlc[0], &table[0])) < 0 || + (ret = build_vlc(&s->vlc[1], &table[1])) < 0) { s->format = 0; return ret; } |