FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avdct.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "avcodec.h"
22 #include "idctdsp.h"
23 #include "fdctdsp.h"
24 #include "pixblockdsp.h"
25 #include "avdct.h"
26 
27 #define OFFSET(x) offsetof(AVDCT,x)
28 #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
29 //these names are too long to be readable
30 #define V AV_OPT_FLAG_VIDEO_PARAM
31 #define A AV_OPT_FLAG_AUDIO_PARAM
32 #define E AV_OPT_FLAG_ENCODING_PARAM
33 #define D AV_OPT_FLAG_DECODING_PARAM
34 
35 static const AVOption avdct_options[] = {
36 {"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E, "dct"},
37 {"auto", "autoselect a good one (default)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, "dct"},
38 {"fastint", "fast integer (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, "dct"},
39 {"int", "accurate integer", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, "dct"},
40 {"mmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, "dct"},
41 {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, "dct"},
42 {"faan", "floating point AAN DCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FAAN }, INT_MIN, INT_MAX, V|E, "dct"},
43 
44 {"idct", "select IDCT implementation", OFFSET(idct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E|D, "idct"},
45 {"auto", "autoselect a good one (default)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
46 {"int", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, "idct"},
47 {"simple", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, "idct"},
48 {"simplemmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
49 {"arm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
50 {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, "idct"},
51 #if FF_API_ARCH_SH4
52 {"sh4", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SH4 }, INT_MIN, INT_MAX, V|E|D, "idct"},
53 #endif
54 {"simplearm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
55 {"simplearmv5te", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, "idct"},
56 {"simplearmv6", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, "idct"},
57 {"simpleneon", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, "idct"},
58 #if FF_API_ARCH_ALPHA
59 {"simplealpha", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEALPHA }, INT_MIN, INT_MAX, V|E|D, "idct"},
60 #endif
61 {"ipp", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_IPP }, INT_MIN, INT_MAX, V|E|D, "idct"},
62 {"xvid", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, "idct"},
63 {"xvidmmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, "idct"},
64 {"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"},
65 {"simpleauto", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEAUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
66 
67 {"bits_per_sample", "", OFFSET(bits_per_sample), AV_OPT_TYPE_INT, {.i64 = 8 }, 0, 14, 0,},
68 {NULL},
69 };
70 
71 static const AVClass avdct_class = {
72  .class_name = "AVDCT",
73  .option = avdct_options,
74  .version = LIBAVUTIL_VERSION_INT,
75 };
76 
78 {
79  return &avdct_class;
80 }
81 
83 {
84  AVDCT *dsp = av_mallocz(sizeof(AVDCT));
85 
86  if (!dsp)
87  return NULL;
88 
89  dsp->av_class = &avdct_class;
91 
92  return dsp;
93 }
94 
96 {
98 
99  if (!avctx)
100  return AVERROR(ENOMEM);
101 
102  avctx->idct_algo = dsp->idct_algo;
103  avctx->dct_algo = dsp->dct_algo;
104  avctx->bits_per_raw_sample = dsp->bits_per_sample;
105 
106 #define COPY(src, name) memcpy(&dsp->name, &src.name, sizeof(dsp->name))
107 
108 #if CONFIG_IDCTDSP
109  {
110  IDCTDSPContext idsp;
111  ff_idctdsp_init(&idsp, avctx);
112  COPY(idsp, idct);
113  COPY(idsp, idct_permutation);
114  }
115 #endif
116 
117 #if CONFIG_FDCTDSP
118  {
119  FDCTDSPContext fdsp;
120  ff_fdctdsp_init(&fdsp, avctx);
121  COPY(fdsp, fdct);
122  }
123 #endif
124 
125 #if CONFIG_PIXBLOCKDSP
126  {
127  PixblockDSPContext pdsp;
128  ff_pixblockdsp_init(&pdsp, avctx);
129  COPY(pdsp, get_pixels);
130  }
131 #endif
132 
133  avcodec_close(avctx);
134  av_free(avctx);
135 
136  return 0;
137 }
#define NULL
Definition: coverity.c:32
static void FUNCC() get_pixels(int16_t *av_restrict block, const uint8_t *_pixels, ptrdiff_t line_size)
static void idct(int16_t block[64])
Definition: 4xm.c:163
int dct_algo
DCT algorithm, see FF_DCT_* below.
Definition: avcodec.h:2670
AVOption.
Definition: opt.h:255
#define FF_IDCT_ARM
Definition: avcodec.h:2690
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
#define FF_IDCT_IPP
Definition: avcodec.h:2697
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1178
#define FF_IDCT_SIMPLEARMV5TE
Definition: avcodec.h:2703
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2727
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
Definition: fdctdsp.c:26
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define FF_IDCT_SH4
Definition: avcodec.h:2693
#define DEFAULT
Definition: avdct.c:28
#define FF_DCT_FAAN
Definition: avcodec.h:2678
#define D
Definition: avdct.c:33
#define FF_IDCT_SIMPLEARM
Definition: avcodec.h:2695
#define FF_DCT_ALTIVEC
Definition: avcodec.h:2677
static const AVOption avdct_options[]
Definition: avdct.c:35
#define FF_IDCT_SIMPLEAUTO
Definition: avcodec.h:2713
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
Definition: utils.c:2843
#define FF_IDCT_SIMPLEALPHA
Definition: avcodec.h:2711
#define AVERROR(e)
Definition: error.h:43
static const AVClass avdct_class
Definition: avdct.c:71
int avcodec_dct_init(AVDCT *dsp)
Definition: avdct.c:95
Libavcodec external API header.
#define FF_IDCT_FAAN
Definition: avcodec.h:2708
#define FF_DCT_AUTO
Definition: avcodec.h:2671
#define FF_IDCT_SIMPLENEON
Definition: avcodec.h:2709
AVDCT * avcodec_dct_alloc(void)
Allocates a AVDCT context.
Definition: avdct.c:82
#define E
Definition: avdct.c:32
#define FF_IDCT_SIMPLE
Definition: avcodec.h:2688
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:147
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
Definition: avcodec.h:2685
#define FF_DCT_FASTINT
Definition: avcodec.h:2672
#define FF_IDCT_ALTIVEC
Definition: avcodec.h:2691
int dct_algo
DCT algorithm.
Definition: avdct.h:57
#define FF_IDCT_AUTO
Definition: avcodec.h:2686
const AVClass * avcodec_dct_get_class(void)
Definition: avdct.c:77
#define FF_IDCT_INT
Definition: avcodec.h:2687
main external API structure.
Definition: avcodec.h:1241
Describe the class of an AVClass context structure.
Definition: log.h:67
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
Definition: pixblockdsp.c:54
#define FF_IDCT_XVID
Definition: avcodec.h:2699
#define FF_DCT_INT
Definition: avcodec.h:2674
#define COPY(src, name)
#define OFFSET(x)
Definition: avdct.c:27
#define FF_IDCT_SIMPLEARMV6
Definition: avcodec.h:2704
AVDCT context.
Definition: avdct.h:29
#define FF_DCT_MMX
Definition: avcodec.h:2676
const AVClass * av_class
Definition: avdct.h:30
#define av_free(p)
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:241
int idct_algo
IDCT algorithm.
Definition: avdct.h:63
#define FF_IDCT_SIMPLEMMX
Definition: avcodec.h:2689
int bits_per_sample
Definition: avdct.h:69
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:250
#define V
Definition: avdct.c:30