FFmpeg
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 "libavutil/mem.h"
22 #include "avcodec.h"
23 #include "idctdsp.h"
24 #include "fdctdsp.h"
25 #include "pixblockdsp.h"
26 #include "avdct.h"
27 
28 #define OFFSET(x) offsetof(AVDCT,x)
29 #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
30 //these names are too long to be readable
31 #define V AV_OPT_FLAG_VIDEO_PARAM
32 #define A AV_OPT_FLAG_AUDIO_PARAM
33 #define E AV_OPT_FLAG_ENCODING_PARAM
34 #define D AV_OPT_FLAG_DECODING_PARAM
35 
36 static const AVOption avdct_options[] = {
37 {"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E, .unit = "dct"},
38 {"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
39 {"fastint", "fast integer (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
40 {"int", "accurate integer", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
41 {"mmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
42 {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
43 {"faan", "floating point AAN DCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FAAN }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
44 
45 {"idct", "select IDCT implementation", OFFSET(idct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E|D, .unit = "idct"},
46 {"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
47 {"int", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
48 {"simple", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
49 {"simplemmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
50 {"arm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
51 {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
52 {"simplearm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
53 {"simplearmv5te", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
54 {"simplearmv6", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
55 {"simpleneon", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
56 {"xvid", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
57 {"xvidmmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
58 {"faani", "floating point AAN IDCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, .unit = "idct"},
59 {"simpleauto", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEAUTO }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
60 
61 {"bits_per_sample", "", OFFSET(bits_per_sample), AV_OPT_TYPE_INT, {.i64 = 8 }, 0, 14, 0,},
62 {NULL},
63 };
64 
65 static const AVClass avdct_class = {
66  .class_name = "AVDCT",
67  .option = avdct_options,
68  .version = LIBAVUTIL_VERSION_INT,
69 };
70 
72 {
73  return &avdct_class;
74 }
75 
77 {
78  AVDCT *dsp = av_mallocz(sizeof(AVDCT));
79 
80  if (!dsp)
81  return NULL;
82 
83  dsp->av_class = &avdct_class;
85 
86  return dsp;
87 }
88 
90 {
92 
93  if (!avctx)
94  return AVERROR(ENOMEM);
95 
96  avctx->idct_algo = dsp->idct_algo;
97  avctx->dct_algo = dsp->dct_algo;
99 
100 #define COPY(src, name) memcpy(&dsp->name, &src.name, sizeof(dsp->name))
101 
102 #if CONFIG_IDCTDSP
103  {
104  IDCTDSPContext idsp = {0};
105  ff_idctdsp_init(&idsp, avctx);
106  COPY(idsp, idct);
107  COPY(idsp, idct_permutation);
108  }
109 #endif
110 
111 #if CONFIG_FDCTDSP
112  {
113  FDCTDSPContext fdsp;
114  ff_fdctdsp_init(&fdsp, avctx);
115  COPY(fdsp, fdct);
116  }
117 #endif
118 
119 #if CONFIG_PIXBLOCKDSP
120  {
121  PixblockDSPContext pdsp;
122  ff_pixblockdsp_init(&pdsp, avctx);
123  COPY(pdsp, get_pixels);
124  COPY(pdsp, get_pixels_unaligned);
125  }
126 #endif
127 
128  avcodec_free_context(&avctx);
129 
130  return 0;
131 }
FF_DCT_FAAN
#define FF_DCT_FAAN
Definition: avcodec.h:1550
D
#define D
Definition: avdct.c:34
avdct.h
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1670
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
FF_IDCT_ALTIVEC
#define FF_IDCT_ALTIVEC
Definition: avcodec.h:1564
FF_DCT_INT
#define FF_DCT_INT
Definition: avcodec.h:1547
AVDCT::dct_algo
int dct_algo
DCT algorithm.
Definition: avdct.h:57
AVOption
AVOption.
Definition: opt.h:429
ff_pixblockdsp_init
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
Definition: pixblockdsp.c:88
avdct_options
static const AVOption avdct_options[]
Definition: avdct.c:36
FF_IDCT_AUTO
#define FF_IDCT_AUTO
Definition: avcodec.h:1559
ff_idctdsp_init
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:228
avdct_class
static const AVClass avdct_class
Definition: avdct.c:65
FF_IDCT_XVID
#define FF_IDCT_XVID
Definition: avcodec.h:1566
FDCTDSPContext
Definition: fdctdsp.h:28
FF_IDCT_SIMPLE
#define FF_IDCT_SIMPLE
Definition: avcodec.h:1561
AVCodecContext::dct_algo
int dct_algo
DCT algorithm, see FF_DCT_* below.
Definition: avcodec.h:1544
idct
static void idct(int16_t block[64])
Definition: 4xm.c:167
FF_IDCT_INT
#define FF_IDCT_INT
Definition: avcodec.h:1560
FF_IDCT_SIMPLEAUTO
#define FF_IDCT_SIMPLEAUTO
Definition: avcodec.h:1571
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
FF_IDCT_ARM
#define FF_IDCT_ARM
Definition: avcodec.h:1563
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1585
COPY
#define COPY(src, name)
FF_DCT_MMX
#define FF_DCT_MMX
Definition: avcodec.h:1548
AVDCT::bits_per_sample
int bits_per_sample
Definition: avdct.h:69
E
#define E
Definition: avdct.c:33
PixblockDSPContext
Definition: pixblockdsp.h:26
AVDCT::av_class
const AVClass * av_class
Definition: avdct.h:30
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:164
V
#define V
Definition: avdct.c:31
avcodec_dct_init
int avcodec_dct_init(AVDCT *dsp)
Definition: avdct.c:89
FF_IDCT_SIMPLEARM
#define FF_IDCT_SIMPLEARM
Definition: avcodec.h:1565
OFFSET
#define OFFSET(x)
Definition: avdct.c:28
FF_DCT_ALTIVEC
#define FF_DCT_ALTIVEC
Definition: avcodec.h:1549
avcodec_dct_alloc
AVDCT * avcodec_dct_alloc(void)
Allocates a AVDCT context.
Definition: avdct.c:76
FF_IDCT_SIMPLEARMV6
#define FF_IDCT_SIMPLEARMV6
Definition: avcodec.h:1568
AVDCT
AVDCT context.
Definition: avdct.h:29
FF_IDCT_SIMPLENEON
#define FF_IDCT_SIMPLENEON
Definition: avcodec.h:1570
ff_fdctdsp_init
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
Definition: fdctdsp.c:25
avcodec_dct_get_class
const AVClass * avcodec_dct_get_class(void)
Definition: avdct.c:71
fdctdsp.h
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVCodecContext::idct_algo
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
Definition: avcodec.h:1558
FF_DCT_FASTINT
#define FF_DCT_FASTINT
Definition: avcodec.h:1546
idctdsp.h
avcodec.h
AVClass::class_name
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:80
FF_IDCT_FAAN
#define FF_IDCT_FAAN
Definition: avcodec.h:1569
IDCTDSPContext
Definition: idctdsp.h:43
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
FF_DCT_AUTO
#define FF_DCT_AUTO
Definition: avcodec.h:1545
FF_IDCT_SIMPLEARMV5TE
#define FF_IDCT_SIMPLEARMV5TE
Definition: avcodec.h:1567
mem.h
DEFAULT
#define DEFAULT
Definition: avdct.c:29
FF_IDCT_SIMPLEMMX
#define FF_IDCT_SIMPLEMMX
Definition: avcodec.h:1562
AVDCT::idct_algo
int idct_algo
IDCT algorithm.
Definition: avdct.h:63
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
pixblockdsp.h