xref: /third_party/ffmpeg/libavcodec/avdct.c (revision cabdff1a)
1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2014 Michael Niedermayer <michaelni@gmx.at>
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14cabdff1aSopenharmony_ci * Lesser General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci#include "avcodec.h"
22cabdff1aSopenharmony_ci#include "idctdsp.h"
23cabdff1aSopenharmony_ci#include "fdctdsp.h"
24cabdff1aSopenharmony_ci#include "pixblockdsp.h"
25cabdff1aSopenharmony_ci#include "avdct.h"
26cabdff1aSopenharmony_ci
27cabdff1aSopenharmony_ci#define OFFSET(x) offsetof(AVDCT,x)
28cabdff1aSopenharmony_ci#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
29cabdff1aSopenharmony_ci//these names are too long to be readable
30cabdff1aSopenharmony_ci#define V AV_OPT_FLAG_VIDEO_PARAM
31cabdff1aSopenharmony_ci#define A AV_OPT_FLAG_AUDIO_PARAM
32cabdff1aSopenharmony_ci#define E AV_OPT_FLAG_ENCODING_PARAM
33cabdff1aSopenharmony_ci#define D AV_OPT_FLAG_DECODING_PARAM
34cabdff1aSopenharmony_ci
35cabdff1aSopenharmony_cistatic const AVOption avdct_options[] = {
36cabdff1aSopenharmony_ci{"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E, "dct"},
37cabdff1aSopenharmony_ci{"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, "dct"},
38cabdff1aSopenharmony_ci{"fastint", "fast integer (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, "dct"},
39cabdff1aSopenharmony_ci{"int", "accurate integer", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, "dct"},
40cabdff1aSopenharmony_ci{"mmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, "dct"},
41cabdff1aSopenharmony_ci{"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, "dct"},
42cabdff1aSopenharmony_ci{"faan", "floating point AAN DCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FAAN }, INT_MIN, INT_MAX, V|E, "dct"},
43cabdff1aSopenharmony_ci
44cabdff1aSopenharmony_ci{"idct", "select IDCT implementation", OFFSET(idct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E|D, "idct"},
45cabdff1aSopenharmony_ci{"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
46cabdff1aSopenharmony_ci{"int", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, "idct"},
47cabdff1aSopenharmony_ci{"simple", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, "idct"},
48cabdff1aSopenharmony_ci{"simplemmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
49cabdff1aSopenharmony_ci{"arm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
50cabdff1aSopenharmony_ci{"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, "idct"},
51cabdff1aSopenharmony_ci{"simplearm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
52cabdff1aSopenharmony_ci{"simplearmv5te", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, "idct"},
53cabdff1aSopenharmony_ci{"simplearmv6", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, "idct"},
54cabdff1aSopenharmony_ci{"simpleneon", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, "idct"},
55cabdff1aSopenharmony_ci{"xvid", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, "idct"},
56cabdff1aSopenharmony_ci{"xvidmmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, "idct"},
57cabdff1aSopenharmony_ci{"faani", "floating point AAN IDCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, "idct"},
58cabdff1aSopenharmony_ci{"simpleauto", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEAUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
59cabdff1aSopenharmony_ci
60cabdff1aSopenharmony_ci{"bits_per_sample", "", OFFSET(bits_per_sample), AV_OPT_TYPE_INT, {.i64 = 8 }, 0, 14, 0,},
61cabdff1aSopenharmony_ci{NULL},
62cabdff1aSopenharmony_ci};
63cabdff1aSopenharmony_ci
64cabdff1aSopenharmony_cistatic const AVClass avdct_class = {
65cabdff1aSopenharmony_ci    .class_name              = "AVDCT",
66cabdff1aSopenharmony_ci    .option                  = avdct_options,
67cabdff1aSopenharmony_ci    .version                 = LIBAVUTIL_VERSION_INT,
68cabdff1aSopenharmony_ci};
69cabdff1aSopenharmony_ci
70cabdff1aSopenharmony_ciconst AVClass *avcodec_dct_get_class(void)
71cabdff1aSopenharmony_ci{
72cabdff1aSopenharmony_ci    return &avdct_class;
73cabdff1aSopenharmony_ci}
74cabdff1aSopenharmony_ci
75cabdff1aSopenharmony_ciAVDCT *avcodec_dct_alloc(void)
76cabdff1aSopenharmony_ci{
77cabdff1aSopenharmony_ci    AVDCT *dsp = av_mallocz(sizeof(AVDCT));
78cabdff1aSopenharmony_ci
79cabdff1aSopenharmony_ci    if (!dsp)
80cabdff1aSopenharmony_ci        return NULL;
81cabdff1aSopenharmony_ci
82cabdff1aSopenharmony_ci    dsp->av_class = &avdct_class;
83cabdff1aSopenharmony_ci    av_opt_set_defaults(dsp);
84cabdff1aSopenharmony_ci
85cabdff1aSopenharmony_ci    return dsp;
86cabdff1aSopenharmony_ci}
87cabdff1aSopenharmony_ci
88cabdff1aSopenharmony_ciint avcodec_dct_init(AVDCT *dsp)
89cabdff1aSopenharmony_ci{
90cabdff1aSopenharmony_ci    AVCodecContext *avctx = avcodec_alloc_context3(NULL);
91cabdff1aSopenharmony_ci
92cabdff1aSopenharmony_ci    if (!avctx)
93cabdff1aSopenharmony_ci        return AVERROR(ENOMEM);
94cabdff1aSopenharmony_ci
95cabdff1aSopenharmony_ci    avctx->idct_algo = dsp->idct_algo;
96cabdff1aSopenharmony_ci    avctx->dct_algo  = dsp->dct_algo;
97cabdff1aSopenharmony_ci    avctx->bits_per_raw_sample = dsp->bits_per_sample;
98cabdff1aSopenharmony_ci
99cabdff1aSopenharmony_ci#define COPY(src, name) memcpy(&dsp->name, &src.name, sizeof(dsp->name))
100cabdff1aSopenharmony_ci
101cabdff1aSopenharmony_ci#if CONFIG_IDCTDSP
102cabdff1aSopenharmony_ci    {
103cabdff1aSopenharmony_ci        IDCTDSPContext idsp = {0};
104cabdff1aSopenharmony_ci        ff_idctdsp_init(&idsp, avctx);
105cabdff1aSopenharmony_ci        COPY(idsp, idct);
106cabdff1aSopenharmony_ci        COPY(idsp, idct_permutation);
107cabdff1aSopenharmony_ci    }
108cabdff1aSopenharmony_ci#endif
109cabdff1aSopenharmony_ci
110cabdff1aSopenharmony_ci#if CONFIG_FDCTDSP
111cabdff1aSopenharmony_ci    {
112cabdff1aSopenharmony_ci        FDCTDSPContext fdsp;
113cabdff1aSopenharmony_ci        ff_fdctdsp_init(&fdsp, avctx);
114cabdff1aSopenharmony_ci        COPY(fdsp, fdct);
115cabdff1aSopenharmony_ci    }
116cabdff1aSopenharmony_ci#endif
117cabdff1aSopenharmony_ci
118cabdff1aSopenharmony_ci#if CONFIG_PIXBLOCKDSP
119cabdff1aSopenharmony_ci    {
120cabdff1aSopenharmony_ci        PixblockDSPContext pdsp;
121cabdff1aSopenharmony_ci        ff_pixblockdsp_init(&pdsp, avctx);
122cabdff1aSopenharmony_ci        COPY(pdsp, get_pixels);
123cabdff1aSopenharmony_ci        COPY(pdsp, get_pixels_unaligned);
124cabdff1aSopenharmony_ci    }
125cabdff1aSopenharmony_ci#endif
126cabdff1aSopenharmony_ci
127cabdff1aSopenharmony_ci    avcodec_free_context(&avctx);
128cabdff1aSopenharmony_ci
129cabdff1aSopenharmony_ci    return 0;
130cabdff1aSopenharmony_ci}
131