Line | Branch | Exec | 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 | 10 | 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 | { | ||
32 | 10 | int i, j, k = 0; | |
33 | |||
34 | 10 | ctx->avctx = avctx; | |
35 | 10 | ctx->ch = av_calloc(avctx->ch_layout.nb_channels, 2 * sizeof(ctx->ch[0])); | |
36 | 10 | ctx->group = av_calloc(num_groups, sizeof(ctx->group[0])); | |
37 | 10 | ctx->bands = av_memdup(bands, num_lens * sizeof(ctx->bands[0])); | |
38 | 10 | ctx->num_bands = av_memdup(num_bands, num_lens * sizeof(ctx->num_bands[0])); | |
39 | 10 | ctx->cutoff = avctx->cutoff; | |
40 | |||
41 |
4/8✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
|
10 | if (!ctx->ch || !ctx->group || !ctx->bands || !ctx->num_bands) { |
42 | ✗ | ff_psy_end(ctx); | |
43 | ✗ | return AVERROR(ENOMEM); | |
44 | } | ||
45 | |||
46 | /* assign channels to groups (with virtual channels for coupling) */ | ||
47 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 10 times.
|
23 | 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 | 13 | ctx->group[i].num_ch = group_map[i] + 1; | |
53 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 13 times.
|
59 | for (j = 0; j < ctx->group[i].num_ch * 2; j++) |
54 | 46 | ctx->group[i].ch[j] = &ctx->ch[k++]; | |
55 | } | ||
56 | |||
57 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | switch (ctx->avctx->codec_id) { |
58 | 10 | case AV_CODEC_ID_AAC: | |
59 | 10 | ctx->model = &ff_aac_psy_model; | |
60 | 10 | break; | |
61 | } | ||
62 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (ctx->model->init) |
63 | 10 | return ctx->model->init(ctx); | |
64 | ✗ | return 0; | |
65 | } | ||
66 | |||
67 | 5032 | FFPsyChannelGroup *ff_psy_find_group(FFPsyContext *ctx, int channel) | |
68 | { | ||
69 | 5032 | int i = 0, ch = 0; | |
70 | |||
71 |
2/2✓ Branch 0 taken 5464 times.
✓ Branch 1 taken 5032 times.
|
10496 | while (ch <= channel) |
72 | 5464 | ch += ctx->group[i++].num_ch; | |
73 | |||
74 | 5032 | return &ctx->group[i-1]; | |
75 | } | ||
76 | |||
77 | 10 | av_cold void ff_psy_end(FFPsyContext *ctx) | |
78 | { | ||
79 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | if (ctx->model && ctx->model->end) |
80 | 10 | ctx->model->end(ctx); | |
81 | 10 | av_freep(&ctx->bands); | |
82 | 10 | av_freep(&ctx->num_bands); | |
83 | 10 | av_freep(&ctx->group); | |
84 | 10 | av_freep(&ctx->ch); | |
85 | 10 | } | |
86 |