Coverage Report

Created: 2026-03-27 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mpv/audio/fmt-conversion.c
Line
Count
Source
1
/*
2
 * This file is part of mpv.
3
 *
4
 * mpv is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * mpv is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include <libavutil/avutil.h>
19
#include <libavutil/samplefmt.h>
20
#include "format.h"
21
#include "fmt-conversion.h"
22
23
static const struct {
24
    enum AVSampleFormat sample_fmt;
25
    int fmt;
26
} audio_conversion_map[] = {
27
    {AV_SAMPLE_FMT_U8,    AF_FORMAT_U8},
28
    {AV_SAMPLE_FMT_S16,   AF_FORMAT_S16},
29
    {AV_SAMPLE_FMT_S32,   AF_FORMAT_S32},
30
    {AV_SAMPLE_FMT_S64,   AF_FORMAT_S64},
31
    {AV_SAMPLE_FMT_FLT,   AF_FORMAT_FLOAT},
32
    {AV_SAMPLE_FMT_DBL,   AF_FORMAT_DOUBLE},
33
34
    {AV_SAMPLE_FMT_U8P,   AF_FORMAT_U8P},
35
    {AV_SAMPLE_FMT_S16P,  AF_FORMAT_S16P},
36
    {AV_SAMPLE_FMT_S32P,  AF_FORMAT_S32P},
37
    {AV_SAMPLE_FMT_S64P,  AF_FORMAT_S64P},
38
    {AV_SAMPLE_FMT_FLTP,  AF_FORMAT_FLOATP},
39
    {AV_SAMPLE_FMT_DBLP,  AF_FORMAT_DOUBLEP},
40
41
    {AV_SAMPLE_FMT_NONE,  0},
42
};
43
44
enum AVSampleFormat af_to_avformat(int fmt)
45
79.5k
{
46
440k
    for (int i = 0; audio_conversion_map[i].fmt; i++) {
47
440k
        if (audio_conversion_map[i].fmt == fmt)
48
79.5k
            return audio_conversion_map[i].sample_fmt;
49
440k
    }
50
1
    return AV_SAMPLE_FMT_NONE;
51
79.5k
}
52
53
int af_from_avformat(enum AVSampleFormat sample_fmt)
54
2.77M
{
55
26.1M
    for (int i = 0; audio_conversion_map[i].fmt; i++) {
56
26.1M
        if (audio_conversion_map[i].sample_fmt == sample_fmt)
57
2.77M
            return audio_conversion_map[i].fmt;
58
26.1M
    }
59
0
    return 0;
60
2.77M
}