Coverage Report

Created: 2025-06-12 07:21

/src/mpv/audio/chmap_avchannel.c
Line
Count
Source (jump to first uncovered line)
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/channel_layout.h>
19
20
#include "chmap.h"
21
#include "chmap_avchannel.h"
22
23
bool mp_chmap_from_av_layout(struct mp_chmap *dst, const AVChannelLayout *src)
24
76.3M
{
25
76.3M
    *dst = (struct mp_chmap) {0};
26
27
76.3M
    switch (src->order) {
28
265k
    case AV_CHANNEL_ORDER_UNSPEC:
29
265k
        mp_chmap_from_channels(dst, src->nb_channels);
30
265k
        return dst->num == src->nb_channels;
31
76.1M
    case AV_CHANNEL_ORDER_NATIVE:
32
76.1M
        mp_chmap_from_lavc(dst, src->u.mask);
33
76.1M
        return dst->num == src->nb_channels;
34
0
    default:
35
        // TODO: handle custom layouts
36
0
        return false;
37
76.3M
    }
38
76.3M
}
39
40
void mp_chmap_to_av_layout(AVChannelLayout *dst, const struct mp_chmap *src)
41
495k
{
42
495k
    *dst = (AVChannelLayout){
43
495k
        .order = AV_CHANNEL_ORDER_UNSPEC,
44
495k
        .nb_channels = src->num,
45
495k
    };
46
47
    // TODO: handle custom layouts
48
495k
    if (!mp_chmap_is_unknown(src)) {
49
482k
        av_channel_layout_from_mask(dst, mp_chmap_to_lavc(src));
50
482k
    }
51
495k
}