FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/avdct.c
Date: 2025-10-10 03:51:19
Exec Total Coverage
Lines: 23 27 85.2%
Functions: 2 3 66.7%
Branches: 2 4 50.0%

Line Branch Exec Source
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/attributes.h"
22 #include "libavutil/mem.h"
23 #include "avcodec.h"
24 #include "idctdsp.h"
25 #include "fdctdsp.h"
26 #include "pixblockdsp.h"
27 #include "avdct.h"
28
29 #define OFFSET(x) offsetof(AVDCT,x)
30 #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
31 //these names are too long to be readable
32 #define V AV_OPT_FLAG_VIDEO_PARAM
33 #define A AV_OPT_FLAG_AUDIO_PARAM
34 #define E AV_OPT_FLAG_ENCODING_PARAM
35 #define D AV_OPT_FLAG_DECODING_PARAM
36
37 static const AVOption avdct_options[] = {
38 {"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E, .unit = "dct"},
39 {"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
40 {"fastint", "fast integer (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
41 {"int", "accurate integer", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
42 {"mmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
43 {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, .unit = "dct"},
44 {"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"},
45
46 {"idct", "select IDCT implementation", OFFSET(idct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E|D, .unit = "idct"},
47 {"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
48 {"int", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
49 {"simple", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
50 {"simplemmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
51 {"arm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
52 {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
53 {"simplearm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
54 {"simplearmv5te", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
55 {"simplearmv6", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
56 {"simpleneon", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
57 {"xvid", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
58 {"xvidmmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
59 {"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"},
60 {"simpleauto", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEAUTO }, INT_MIN, INT_MAX, V|E|D, .unit = "idct"},
61
62 {"bits_per_sample", "", OFFSET(bits_per_sample), AV_OPT_TYPE_INT, {.i64 = 8 }, 0, 14, 0,},
63 {NULL},
64 };
65
66 static const AVClass avdct_class = {
67 .class_name = "AVDCT",
68 .option = avdct_options,
69 .version = LIBAVUTIL_VERSION_INT,
70 };
71
72 av_cold const AVClass *avcodec_dct_get_class(void)
73 {
74 return &avdct_class;
75 }
76
77 2 av_cold AVDCT *avcodec_dct_alloc(void)
78 {
79 2 AVDCT *dsp = av_mallocz(sizeof(AVDCT));
80
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!dsp)
82 return NULL;
83
84 2 dsp->av_class = &avdct_class;
85 2 av_opt_set_defaults(dsp);
86
87 2 return dsp;
88 }
89
90 1 av_cold int avcodec_dct_init(AVDCT *dsp)
91 {
92 1 AVCodecContext *avctx = avcodec_alloc_context3(NULL);
93
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!avctx)
95 return AVERROR(ENOMEM);
96
97 1 avctx->idct_algo = dsp->idct_algo;
98 1 avctx->dct_algo = dsp->dct_algo;
99 1 avctx->bits_per_raw_sample = dsp->bits_per_sample;
100
101 #define COPY(src, name) memcpy(&dsp->name, &src.name, sizeof(dsp->name))
102
103 #if CONFIG_IDCTDSP
104 {
105 1 IDCTDSPContext idsp = {0};
106 1 ff_idctdsp_init(&idsp, avctx);
107 1 COPY(idsp, idct);
108 1 COPY(idsp, idct_permutation);
109 }
110 #endif
111
112 #if CONFIG_FDCTDSP
113 {
114 FDCTDSPContext fdsp;
115 1 ff_fdctdsp_init(&fdsp, avctx);
116 1 COPY(fdsp, fdct);
117 }
118 #endif
119
120 #if CONFIG_PIXBLOCKDSP
121 {
122 PixblockDSPContext pdsp;
123 1 ff_pixblockdsp_init(&pdsp, dsp->bits_per_sample);
124 1 COPY(pdsp, get_pixels);
125 1 COPY(pdsp, get_pixels_unaligned);
126 }
127 #endif
128
129 1 avcodec_free_context(&avctx);
130
131 1 return 0;
132 }
133