FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/iamf.h
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 2 2 100.0%
Branches: 7 8 87.5%

Line Branch Exec 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 seek_preroll;
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 };
160
161 struct IAMFSoundSystemMap {
162 enum IAMF_Sound_System id;
163 AVChannelLayout layout;
164 };
165
166 FF_VISIBILITY_PUSH_HIDDEN
167 extern const AVChannelLayout ff_iamf_scalable_ch_layouts[10];
168 extern const struct IAMFSoundSystemMap ff_iamf_sound_system_map[13];
169
170 57 static inline IAMFCodecConfig *ff_iamf_get_codec_config(const IAMFContext *c,
171 unsigned int codec_config_id)
172 {
173 57 IAMFCodecConfig *codec_config = NULL;
174
175
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 57 times.
114 for (int i = 0; i < c->nb_codec_configs; i++) {
176
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 if (c->codec_configs[i]->codec_config_id == codec_config_id)
177 57 codec_config = c->codec_configs[i];
178 }
179
180 57 return codec_config;
181 }
182
183 192 static inline IAMFParamDefinition *ff_iamf_get_param_definition(const IAMFContext *iamf,
184 unsigned int parameter_id)
185 {
186 192 IAMFParamDefinition *param_definition = NULL;
187
188
2/2
✓ Branch 0 taken 441 times.
✓ Branch 1 taken 25 times.
466 for (int i = 0; i < iamf->nb_param_definitions; i++)
189
2/2
✓ Branch 0 taken 167 times.
✓ Branch 1 taken 274 times.
441 if (iamf->param_definitions[i]->param->parameter_id == parameter_id) {
190 167 param_definition = iamf->param_definitions[i];
191 167 break;
192 }
193
194 192 return param_definition;
195 }
196
197 void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element);
198 void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation);
199 void ff_iamf_uninit_context(IAMFContext *c);
200 FF_VISIBILITY_POP_HIDDEN
201
202 #endif /* AVFORMAT_IAMF_H */
203