Просмотр исходного кода

avcodec/prores{dec,dsp}: Remove always-false checks

avctx->bits_per_raw_sample is always 10 or 12 here;
the checks have been added in preparation for making
bits_per_raw_sample user-settable via an AVOption,
but this never happened.

While just at it, also set unpack_alpha earlier
(where bits_per_raw_sample is set).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Andreas Rheinhardt 2 недель назад
Родитель
Сommit
57d892bd7b
3 измененных файлов с 10 добавлено и 21 удалено
  1. 5 15
      libavcodec/proresdec.c
  2. 4 5
      libavcodec/proresdsp.c
  3. 1 1
      libavcodec/proresdsp.h

+ 5 - 15
libavcodec/proresdec.c

@@ -132,7 +132,6 @@ static void unpack_alpha_12(GetBitContext *gb, uint16_t *dst, int num_coeffs,
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
-    int ret = 0;
     ProresContext *ctx = avctx->priv_data;
     uint8_t idct_permutation[64];
 
@@ -164,16 +163,15 @@ static av_cold int decode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_WARNING, "Unknown prores profile %d\n", avctx->codec_tag);
     }
 
+    ctx->unpack_alpha = avctx->bits_per_raw_sample == 10 ?
+                            unpack_alpha_10 : unpack_alpha_12;
+
     av_log(avctx, AV_LOG_DEBUG,
            "Auto bitdepth precision. Use %db decoding based on codec tag.\n",
            avctx->bits_per_raw_sample);
 
     ff_blockdsp_init(&ctx->bdsp);
-    ret = ff_proresdsp_init(&ctx->prodsp, avctx->bits_per_raw_sample);
-    if (ret < 0) {
-        av_log(avctx, AV_LOG_ERROR, "Fail to init proresdsp for bits per raw sample %d\n", avctx->bits_per_raw_sample);
-        return ret;
-    }
+    ff_proresdsp_init(&ctx->prodsp, avctx->bits_per_raw_sample);
 
     ff_init_scantable_permutation(idct_permutation,
                                   ctx->prodsp.idct_permutation_type);
@@ -183,15 +181,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     ctx->pix_fmt = AV_PIX_FMT_NONE;
 
-    if (avctx->bits_per_raw_sample == 10){
-        ctx->unpack_alpha = unpack_alpha_10;
-    } else if (avctx->bits_per_raw_sample == 12){
-        ctx->unpack_alpha = unpack_alpha_12;
-    } else {
-        av_log(avctx, AV_LOG_ERROR, "Fail to set unpack_alpha for bits per raw sample %d\n", avctx->bits_per_raw_sample);
-        return AVERROR_BUG;
-    }
-    return ret;
+    return 0;
 }
 
 static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,

+ 4 - 5
libavcodec/proresdsp.c

@@ -22,6 +22,7 @@
 
 #include "config.h"
 #include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "idctdsp.h"
 #include "proresdsp.h"
@@ -76,16 +77,15 @@ static void prores_idct_put_12_c(uint16_t *out, ptrdiff_t linesize, int16_t *blo
     put_pixels_12(out, linesize >> 1, block);
 }
 
-av_cold int ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample)
+av_cold void ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample)
 {
     if (bits_per_raw_sample == 10) {
         dsp->idct_put = prores_idct_put_10_c;
         dsp->idct_permutation_type = FF_IDCT_PERM_NONE;
-    } else if (bits_per_raw_sample == 12) {
+    } else {
+        av_assert1(bits_per_raw_sample == 12);
         dsp->idct_put = prores_idct_put_12_c;
         dsp->idct_permutation_type = FF_IDCT_PERM_NONE;
-    } else {
-        return AVERROR_BUG;
     }
 
 #if ARCH_X86
@@ -94,5 +94,4 @@ av_cold int ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample)
 
     ff_init_scantable_permutation(dsp->idct_permutation,
                                   dsp->idct_permutation_type);
-    return 0;
 }

+ 1 - 1
libavcodec/proresdsp.h

@@ -32,7 +32,7 @@ typedef struct ProresDSPContext {
     void (*idct_put)(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat);
 } ProresDSPContext;
 
-int ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample);
+void ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample);
 
 void ff_proresdsp_init_x86(ProresDSPContext *dsp, int bits_per_raw_sample);