Coverage Report

Created: 2026-04-01 07:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/psymodel.c
Line
Count
Source
1
/*
2
 * audio encoder psychoacoustic model
3
 * Copyright (C) 2008 Konstantin Shishkov
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
22
#include "avcodec.h"
23
#include "psymodel.h"
24
#include "libavutil/mem.h"
25
26
extern const FFPsyModel ff_aac_psy_model;
27
28
av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
29
                        const uint8_t **bands, const int* num_bands,
30
                        int num_groups, const uint8_t *group_map)
31
0
{
32
0
    int i, j, k = 0;
33
34
0
    ctx->avctx = avctx;
35
0
    ctx->ch        = av_calloc(avctx->ch_layout.nb_channels, 2 * sizeof(ctx->ch[0]));
36
0
    ctx->group     = av_calloc(num_groups, sizeof(ctx->group[0]));
37
0
    ctx->bands     = av_memdup(bands,     num_lens * sizeof(ctx->bands[0]));
38
0
    ctx->num_bands = av_memdup(num_bands, num_lens * sizeof(ctx->num_bands[0]));
39
0
    ctx->cutoff    = avctx->cutoff;
40
41
0
    if (!ctx->ch || !ctx->group || !ctx->bands || !ctx->num_bands) {
42
0
        ff_psy_end(ctx);
43
0
        return AVERROR(ENOMEM);
44
0
    }
45
46
    /* assign channels to groups (with virtual channels for coupling) */
47
0
    for (i = 0; i < num_groups; i++) {
48
        /* NOTE: Add 1 to handle the AAC chan_config without modification.
49
         *       This has the side effect of allowing an array of 0s to map
50
         *       to one channel per group.
51
         */
52
0
        ctx->group[i].num_ch = group_map[i] + 1;
53
0
        for (j = 0; j < ctx->group[i].num_ch * 2; j++)
54
0
            ctx->group[i].ch[j]  = &ctx->ch[k++];
55
0
    }
56
57
0
    switch (ctx->avctx->codec_id) {
58
0
    case AV_CODEC_ID_AAC:
59
0
        ctx->model = &ff_aac_psy_model;
60
0
        break;
61
0
    }
62
0
    if (ctx->model->init)
63
0
        return ctx->model->init(ctx);
64
0
    return 0;
65
0
}
66
67
FFPsyChannelGroup *ff_psy_find_group(FFPsyContext *ctx, int channel)
68
0
{
69
0
    int i = 0, ch = 0;
70
71
0
    while (ch <= channel)
72
0
        ch += ctx->group[i++].num_ch;
73
74
0
    return &ctx->group[i-1];
75
0
}
76
77
av_cold void ff_psy_end(FFPsyContext *ctx)
78
0
{
79
0
    if (ctx->model && ctx->model->end)
80
0
        ctx->model->end(ctx);
81
0
    av_freep(&ctx->bands);
82
0
    av_freep(&ctx->num_bands);
83
0
    av_freep(&ctx->group);
84
0
    av_freep(&ctx->ch);
85
0
}