avcodec/proresdec : rename dsp part for 10b and check dspinit for supported bits per raw sample

based on patch by Kieran Kunhya
This commit is contained in:
Martin Vignali 2018-11-17 23:35:35 +01:00
parent a970920026
commit c097a32e93
7 changed files with 28 additions and 18 deletions

View File

@ -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,

View File

@ -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;
}

View File

@ -27,15 +27,13 @@
#include <stdint.h>
#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);

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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 */
}