Coverage Report

Created: 2026-05-23 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/iamf.h
Line
Count
Source
1
/*
2
 * Immersive Audio Model and Formats common helpers and structs
3
 * Copyright (c) 2023 James Almer <jamrial@gmail.com>
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
#ifndef AVFORMAT_IAMF_H
23
#define AVFORMAT_IAMF_H
24
25
#include <stddef.h>
26
#include <stdint.h>
27
28
#include "libavutil/attributes_internal.h"
29
#include "libavutil/channel_layout.h"
30
#include "libavutil/iamf.h"
31
#include "libavcodec/codec_id.h"
32
#include "libavcodec/codec_par.h"
33
34
#define MAX_IAMF_OBU_HEADER_SIZE (1 + 8 * 3)
35
36
// OBU types (section 3.2).
37
enum IAMF_OBU_Type {
38
    IAMF_OBU_IA_CODEC_CONFIG        = 0,
39
    IAMF_OBU_IA_AUDIO_ELEMENT       = 1,
40
    IAMF_OBU_IA_MIX_PRESENTATION    = 2,
41
    IAMF_OBU_IA_PARAMETER_BLOCK     = 3,
42
    IAMF_OBU_IA_TEMPORAL_DELIMITER  = 4,
43
    IAMF_OBU_IA_AUDIO_FRAME         = 5,
44
    IAMF_OBU_IA_AUDIO_FRAME_ID0     = 6,
45
    IAMF_OBU_IA_AUDIO_FRAME_ID1     = 7,
46
    IAMF_OBU_IA_AUDIO_FRAME_ID2     = 8,
47
    IAMF_OBU_IA_AUDIO_FRAME_ID3     = 9,
48
    IAMF_OBU_IA_AUDIO_FRAME_ID4     = 10,
49
    IAMF_OBU_IA_AUDIO_FRAME_ID5     = 11,
50
    IAMF_OBU_IA_AUDIO_FRAME_ID6     = 12,
51
    IAMF_OBU_IA_AUDIO_FRAME_ID7     = 13,
52
    IAMF_OBU_IA_AUDIO_FRAME_ID8     = 14,
53
    IAMF_OBU_IA_AUDIO_FRAME_ID9     = 15,
54
    IAMF_OBU_IA_AUDIO_FRAME_ID10    = 16,
55
    IAMF_OBU_IA_AUDIO_FRAME_ID11    = 17,
56
    IAMF_OBU_IA_AUDIO_FRAME_ID12    = 18,
57
    IAMF_OBU_IA_AUDIO_FRAME_ID13    = 19,
58
    IAMF_OBU_IA_AUDIO_FRAME_ID14    = 20,
59
    IAMF_OBU_IA_AUDIO_FRAME_ID15    = 21,
60
    IAMF_OBU_IA_AUDIO_FRAME_ID16    = 22,
61
    IAMF_OBU_IA_AUDIO_FRAME_ID17    = 23,
62
    // 24~30 reserved.
63
    IAMF_OBU_IA_SEQUENCE_HEADER     = 31,
64
};
65
66
typedef struct IAMFCodecConfig {
67
    unsigned codec_config_id;
68
    enum AVCodecID codec_id;
69
    uint32_t codec_tag;
70
    unsigned nb_samples;
71
    int audio_roll_distance;
72
    int sample_rate;
73
    int extradata_size;
74
    uint8_t *extradata;
75
} IAMFCodecConfig;
76
77
typedef struct IAMFLayer {
78
    unsigned int substream_count;
79
    unsigned int coupled_substream_count;
80
} IAMFLayer;
81
82
typedef struct IAMFSubStream {
83
    unsigned int audio_substream_id;
84
85
    // demux
86
    AVCodecParameters *codecpar;
87
} IAMFSubStream;
88
89
typedef struct IAMFAudioElement {
90
    const AVIAMFAudioElement *celement;
91
    /**
92
     * element backs celement iff the AVIAMFAudioElement
93
     * is owned by this structure.
94
     */
95
    AVIAMFAudioElement *element;
96
    unsigned int audio_element_id;
97
98
    IAMFSubStream *substreams;
99
    unsigned int nb_substreams;
100
101
    unsigned int codec_config_id;
102
103
    IAMFLayer *layers;
104
    unsigned int nb_layers;
105
} IAMFAudioElement;
106
107
typedef struct IAMFMixPresentation {
108
    const AVIAMFMixPresentation *cmix;
109
    /**
110
     * mix backs cmix iff the AVIAMFMixPresentation
111
     * is owned by this structure.
112
     */
113
    AVIAMFMixPresentation *mix;
114
    unsigned int mix_presentation_id;
115
116
    // demux
117
    unsigned int count_label;
118
    char **language_label;
119
} IAMFMixPresentation;
120
121
typedef struct IAMFParamDefinition {
122
    const IAMFAudioElement *audio_element;
123
    AVIAMFParamDefinition *param;
124
    int mode;
125
    size_t param_size;
126
} IAMFParamDefinition;
127
128
typedef struct IAMFContext {
129
    IAMFCodecConfig **codec_configs;
130
    int nb_codec_configs;
131
    IAMFAudioElement **audio_elements;
132
    int nb_audio_elements;
133
    IAMFMixPresentation **mix_presentations;
134
    int nb_mix_presentations;
135
    IAMFParamDefinition **param_definitions;
136
    int nb_param_definitions;
137
} IAMFContext;
138
139
enum IAMF_Anchor_Element {
140
    IAMF_ANCHOR_ELEMENT_UNKNWONW,
141
    IAMF_ANCHOR_ELEMENT_DIALOGUE,
142
    IAMF_ANCHOR_ELEMENT_ALBUM,
143
};
144
145
enum IAMF_Sound_System {
146
    SOUND_SYSTEM_A_0_2_0  = 0,  // "Loudspeaker configuration for Sound System A"
147
    SOUND_SYSTEM_B_0_5_0  = 1,  // "Loudspeaker configuration for Sound System B"
148
    SOUND_SYSTEM_C_2_5_0  = 2,  // "Loudspeaker configuration for Sound System C"
149
    SOUND_SYSTEM_D_4_5_0  = 3,  // "Loudspeaker configuration for Sound System D"
150
    SOUND_SYSTEM_E_4_5_1  = 4,  // "Loudspeaker configuration for Sound System E"
151
    SOUND_SYSTEM_F_3_7_0  = 5,  // "Loudspeaker configuration for Sound System F"
152
    SOUND_SYSTEM_G_4_9_0  = 6,  // "Loudspeaker configuration for Sound System G"
153
    SOUND_SYSTEM_H_9_10_3 = 7,  // "Loudspeaker configuration for Sound System H"
154
    SOUND_SYSTEM_I_0_7_0  = 8,  // "Loudspeaker configuration for Sound System I"
155
    SOUND_SYSTEM_J_4_7_0  = 9, // "Loudspeaker configuration for Sound System J"
156
    SOUND_SYSTEM_10_2_7_0 = 10, // "Loudspeaker configuration for Sound System I" + Ltf + Rtf
157
    SOUND_SYSTEM_11_2_3_0 = 11, // Front subset of "Loudspeaker configuration for Sound System J"
158
    SOUND_SYSTEM_12_0_1_0 = 12, // Mono
159
    SOUND_SYSTEM_13_9_1_6 = 13, // Subset of "Loudspeaker configuration for Sound System H"
160
};
161
162
struct IAMFSoundSystemMap {
163
    enum IAMF_Sound_System id;
164
    AVChannelLayout layout;
165
};
166
167
FF_VISIBILITY_PUSH_HIDDEN
168
extern const AVChannelLayout ff_iamf_scalable_ch_layouts[10];
169
extern const AVChannelLayout ff_iamf_expanded_scalable_ch_layouts[13];
170
extern const struct IAMFSoundSystemMap ff_iamf_sound_system_map[14];
171
172
static inline IAMFCodecConfig *ff_iamf_get_codec_config(const IAMFContext *c,
173
                                                        unsigned int codec_config_id)
174
5.32k
{
175
5.32k
    IAMFCodecConfig *codec_config = NULL;
176
177
11.7k
    for (int i = 0; i < c->nb_codec_configs; i++) {
178
6.42k
        if (c->codec_configs[i]->codec_config_id == codec_config_id)
179
5.29k
            codec_config = c->codec_configs[i];
180
6.42k
    }
181
182
5.32k
    return codec_config;
183
5.32k
}
Unexecuted instantiation: iamfdec.c:ff_iamf_get_codec_config
Unexecuted instantiation: mov.c:ff_iamf_get_codec_config
iamf_parse.c:ff_iamf_get_codec_config
Line
Count
Source
174
4.59k
{
175
4.59k
    IAMFCodecConfig *codec_config = NULL;
176
177
10.1k
    for (int i = 0; i < c->nb_codec_configs; i++) {
178
5.54k
        if (c->codec_configs[i]->codec_config_id == codec_config_id)
179
4.56k
            codec_config = c->codec_configs[i];
180
5.54k
    }
181
182
4.59k
    return codec_config;
183
4.59k
}
iamf_reader.c:ff_iamf_get_codec_config
Line
Count
Source
174
726
{
175
726
    IAMFCodecConfig *codec_config = NULL;
176
177
1.60k
    for (int i = 0; i < c->nb_codec_configs; i++) {
178
883
        if (c->codec_configs[i]->codec_config_id == codec_config_id)
179
726
            codec_config = c->codec_configs[i];
180
883
    }
181
182
726
    return codec_config;
183
726
}
Unexecuted instantiation: iamf.c:ff_iamf_get_codec_config
184
185
static inline IAMFParamDefinition *ff_iamf_get_param_definition(const IAMFContext *iamf,
186
                                                                unsigned int parameter_id)
187
4.45k
{
188
4.45k
    IAMFParamDefinition *param_definition = NULL;
189
190
12.4k
    for (int i = 0; i < iamf->nb_param_definitions; i++)
191
10.7k
        if (iamf->param_definitions[i]->param->parameter_id == parameter_id) {
192
2.73k
            param_definition = iamf->param_definitions[i];
193
2.73k
            break;
194
2.73k
        }
195
196
4.45k
    return param_definition;
197
4.45k
}
Unexecuted instantiation: iamfdec.c:ff_iamf_get_param_definition
Unexecuted instantiation: mov.c:ff_iamf_get_param_definition
Unexecuted instantiation: iamf_parse.c:ff_iamf_get_param_definition
iamf_reader.c:ff_iamf_get_param_definition
Line
Count
Source
187
4.45k
{
188
4.45k
    IAMFParamDefinition *param_definition = NULL;
189
190
12.4k
    for (int i = 0; i < iamf->nb_param_definitions; i++)
191
10.7k
        if (iamf->param_definitions[i]->param->parameter_id == parameter_id) {
192
2.73k
            param_definition = iamf->param_definitions[i];
193
2.73k
            break;
194
2.73k
        }
195
196
4.45k
    return param_definition;
197
4.45k
}
Unexecuted instantiation: iamf.c:ff_iamf_get_param_definition
198
199
void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element);
200
void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation);
201
void ff_iamf_uninit_context(IAMFContext *c);
202
FF_VISIBILITY_POP_HIDDEN
203
204
#endif /* AVFORMAT_IAMF_H */