From c097a32e93b4b4d9cb576bf21014b19121806161 Mon Sep 17 00:00:00 2001 From: Martin Vignali Date: Sat, 17 Nov 2018 23:35:35 +0100 Subject: [PATCH] avcodec/proresdec : rename dsp part for 10b and check dspinit for supported bits per raw sample based on patch by Kieran Kunhya --- libavcodec/proresdec2.c | 9 +++++++-- libavcodec/proresdsp.c | 25 +++++++++++++++---------- libavcodec/proresdsp.h | 4 +--- libavcodec/simple_idct.c | 2 +- libavcodec/simple_idct.h | 2 +- libavcodec/tests/dct.c | 2 +- libavcodec/x86/proresdsp_init.c | 2 ++ 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c index 835df19418..12b2cba090 100644 --- a/libavcodec/proresdec2.c +++ b/libavcodec/proresdec2.c @@ -48,6 +48,7 @@ static void permute(uint8_t *dst, const uint8_t *src, const uint8_t permutation[ static av_cold int decode_init(AVCodecContext *avctx) { + int ret = 0; ProresContext *ctx = avctx->priv_data; uint8_t idct_permutation[64]; @@ -78,7 +79,11 @@ static av_cold int decode_init(AVCodecContext *avctx) } ff_blockdsp_init(&ctx->bdsp, avctx); - ff_proresdsp_init(&ctx->prodsp, avctx); + ret = ff_proresdsp_init(&ctx->prodsp, avctx); + 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_init_scantable_permutation(idct_permutation, ctx->prodsp.idct_permutation_type); @@ -86,7 +91,7 @@ static av_cold int decode_init(AVCodecContext *avctx) permute(ctx->progressive_scan, ff_prores_progressive_scan, idct_permutation); permute(ctx->interlaced_scan, ff_prores_interlaced_scan, idct_permutation); - return 0; + return ret; } static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, diff --git a/libavcodec/proresdsp.c b/libavcodec/proresdsp.c index 3c337dc433..6b15ed3add 100644 --- a/libavcodec/proresdsp.c +++ b/libavcodec/proresdsp.c @@ -27,15 +27,15 @@ #include "proresdsp.h" #include "simple_idct.h" -#define CLIP_MIN (1 << (PRORES_BITS_PER_SAMPLE - 8)) ///< minimum value for clipping resulting pixels -#define CLIP_MAX (1 << PRORES_BITS_PER_SAMPLE) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels +#define CLIP_MIN (1 << 2) ///< minimum value for clipping resulting pixels +#define CLIP_MAX_10 (1 << 10) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels -#define CLIP(x) (av_clip((x), CLIP_MIN, CLIP_MAX)) +#define CLIP_10(x) (av_clip((x), CLIP_MIN, CLIP_MAX_10)) /** * Add bias value, clamp and output pixels of a slice */ -static void put_pixels(uint16_t *dst, ptrdiff_t linesize, const int16_t *in) +static void put_pixels_10(uint16_t *dst, ptrdiff_t linesize, const int16_t *in) { int x, y, src_offset, dst_offset; @@ -43,25 +43,30 @@ static void put_pixels(uint16_t *dst, ptrdiff_t linesize, const int16_t *in) for (x = 0; x < 8; x++) { src_offset = (y << 3) + x; - dst[dst_offset + x] = CLIP(in[src_offset]); + dst[dst_offset + x] = CLIP_10(in[src_offset]); } } } -static void prores_idct_put_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat) +static void prores_idct_put_10_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat) { - ff_prores_idct(block, qmat); - put_pixels(out, linesize >> 1, block); + ff_prores_idct_10(block, qmat); + put_pixels_10(out, linesize >> 1, block); } -av_cold void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx) +av_cold int ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx) { - dsp->idct_put = prores_idct_put_c; + if (avctx->bits_per_raw_sample == 10) { + dsp->idct_put = prores_idct_put_10_c; dsp->idct_permutation_type = FF_IDCT_PERM_NONE; + } else { + return AVERROR_BUG; + } if (ARCH_X86) ff_proresdsp_init_x86(dsp, avctx); ff_init_scantable_permutation(dsp->idct_permutation, dsp->idct_permutation_type); + return 0; } diff --git a/libavcodec/proresdsp.h b/libavcodec/proresdsp.h index 558fae53bf..37ba76b8e4 100644 --- a/libavcodec/proresdsp.h +++ b/libavcodec/proresdsp.h @@ -27,15 +27,13 @@ #include #include "avcodec.h" -#define PRORES_BITS_PER_SAMPLE 10 ///< output precision of prores decoder - typedef struct ProresDSPContext { int idct_permutation_type; uint8_t idct_permutation[64]; void (*idct_put)(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat); } ProresDSPContext; -void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx); +int ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx); void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx); diff --git a/libavcodec/simple_idct.c b/libavcodec/simple_idct.c index 78b29c0fe3..2171d71d06 100644 --- a/libavcodec/simple_idct.c +++ b/libavcodec/simple_idct.c @@ -236,7 +236,7 @@ void ff_simple_idct44_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block) } } -void ff_prores_idct(int16_t *block, const int16_t *qmat) +void ff_prores_idct_10(int16_t *block, const int16_t *qmat) { int i; diff --git a/libavcodec/simple_idct.h b/libavcodec/simple_idct.h index 39df2308ca..634a78e59e 100644 --- a/libavcodec/simple_idct.h +++ b/libavcodec/simple_idct.h @@ -52,7 +52,7 @@ void ff_simple_idct_int16_12bit(int16_t *block); * and scales by a factor of 2 more between the two IDCTs to account * for larger scale of input coefficients. */ -void ff_prores_idct(int16_t *block, const int16_t *qmat); +void ff_prores_idct_10(int16_t *block, const int16_t *qmat); void ff_simple_idct248_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block); diff --git a/libavcodec/tests/dct.c b/libavcodec/tests/dct.c index e8fa4a3cc1..2ca8039c01 100644 --- a/libavcodec/tests/dct.c +++ b/libavcodec/tests/dct.c @@ -73,7 +73,7 @@ static void ff_prores_idct_wrap(int16_t *dst){ for(i=0; i<64; i++){ qmat[i]=4; } - ff_prores_idct(dst, qmat); + ff_prores_idct_10(dst, qmat); for(i=0; i<64; i++) { dst[i] -= 512; } diff --git a/libavcodec/x86/proresdsp_init.c b/libavcodec/x86/proresdsp_init.c index 8ca4d4d9b3..747aeb826e 100644 --- a/libavcodec/x86/proresdsp_init.c +++ b/libavcodec/x86/proresdsp_init.c @@ -35,6 +35,7 @@ av_cold void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx) #if ARCH_X86_64 int cpu_flags = av_get_cpu_flags(); + if (avctx->bits_per_raw_sample == 10){ if (EXTERNAL_SSE2(cpu_flags)) { dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE; dsp->idct_put = ff_prores_idct_put_10_sse2; @@ -44,5 +45,6 @@ av_cold void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx) dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE; dsp->idct_put = ff_prores_idct_put_10_avx; } + } #endif /* ARCH_X86_64 */ }