FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/iamf.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 36 39 92.3%
Functions: 3 3 100.0%
Branches: 15 18 83.3%

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 #include "libavutil/channel_layout.h"
23 #include "libavutil/iamf.h"
24 #include "libavutil/mem.h"
25 #include "iamf.h"
26
27 const AVChannelLayout ff_iamf_scalable_ch_layouts[10] = {
28 AV_CHANNEL_LAYOUT_MONO,
29 AV_CHANNEL_LAYOUT_STEREO,
30 // "Loudspeaker configuration for Sound System B"
31 AV_CHANNEL_LAYOUT_5POINT1_BACK,
32 // "Loudspeaker configuration for Sound System C"
33 AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK,
34 // "Loudspeaker configuration for Sound System D"
35 AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK,
36 // "Loudspeaker configuration for Sound System I"
37 AV_CHANNEL_LAYOUT_7POINT1,
38 // "Loudspeaker configuration for Sound System I" + Ltf + Rtf
39 AV_CHANNEL_LAYOUT_7POINT1POINT2,
40 // "Loudspeaker configuration for Sound System J"
41 AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK,
42 // Front subset of "Loudspeaker configuration for Sound System J"
43 AV_CHANNEL_LAYOUT_3POINT1POINT2,
44 // Binaural
45 AV_CHANNEL_LAYOUT_STEREO,
46 };
47
48 const struct IAMFSoundSystemMap ff_iamf_sound_system_map[13] = {
49 { SOUND_SYSTEM_A_0_2_0, AV_CHANNEL_LAYOUT_STEREO },
50 { SOUND_SYSTEM_B_0_5_0, AV_CHANNEL_LAYOUT_5POINT1_BACK },
51 { SOUND_SYSTEM_C_2_5_0, AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK },
52 { SOUND_SYSTEM_D_4_5_0, AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK },
53 { SOUND_SYSTEM_E_4_5_1,
54 {
55 .nb_channels = 11,
56 .order = AV_CHANNEL_ORDER_NATIVE,
57 .u.mask = AV_CH_LAYOUT_5POINT1POINT4_BACK | AV_CH_BOTTOM_FRONT_CENTER,
58 },
59 },
60 { SOUND_SYSTEM_F_3_7_0, AV_CHANNEL_LAYOUT_7POINT2POINT3 },
61 { SOUND_SYSTEM_G_4_9_0, AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK },
62 { SOUND_SYSTEM_H_9_10_3, AV_CHANNEL_LAYOUT_22POINT2 },
63 { SOUND_SYSTEM_I_0_7_0, AV_CHANNEL_LAYOUT_7POINT1 },
64 { SOUND_SYSTEM_J_4_7_0, AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK },
65 { SOUND_SYSTEM_10_2_7_0, AV_CHANNEL_LAYOUT_7POINT1POINT2 },
66 { SOUND_SYSTEM_11_2_3_0, AV_CHANNEL_LAYOUT_3POINT1POINT2 },
67 { SOUND_SYSTEM_12_0_1_0, AV_CHANNEL_LAYOUT_MONO },
68 };
69
70 30 void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element)
71 {
72 30 IAMFAudioElement *audio_element = *paudio_element;
73
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (!audio_element)
75 return;
76
77
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 30 times.
162 for (int i = 0; i < audio_element->nb_substreams; i++)
78 132 avcodec_parameters_free(&audio_element->substreams[i].codecpar);
79 30 av_free(audio_element->substreams);
80 30 av_free(audio_element->layers);
81 30 av_iamf_audio_element_free(&audio_element->element);
82 30 av_freep(paudio_element);
83 }
84
85 30 void ff_iamf_free_mix_presentation(IAMFMixPresentation **pmix_presentation)
86 {
87 30 IAMFMixPresentation *mix_presentation = *pmix_presentation;
88
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (!mix_presentation)
90 return;
91
92
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 30 times.
51 for (int i = 0; i < mix_presentation->count_label; i++)
93 21 av_free(mix_presentation->language_label[i]);
94 30 av_free(mix_presentation->language_label);
95 30 av_iamf_mix_presentation_free(&mix_presentation->mix);
96 30 av_freep(pmix_presentation);
97 }
98
99 30 void ff_iamf_uninit_context(IAMFContext *c)
100 {
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (!c)
102 return;
103
104
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
60 for (int i = 0; i < c->nb_codec_configs; i++) {
105 30 av_free(c->codec_configs[i]->extradata);
106 30 av_free(c->codec_configs[i]);
107 }
108 30 av_freep(&c->codec_configs);
109 30 c->nb_codec_configs = 0;
110
111
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
60 for (int i = 0; i < c->nb_audio_elements; i++)
112 30 ff_iamf_free_audio_element(&c->audio_elements[i]);
113 30 av_freep(&c->audio_elements);
114 30 c->nb_audio_elements = 0;
115
116
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
60 for (int i = 0; i < c->nb_mix_presentations; i++)
117 30 ff_iamf_free_mix_presentation(&c->mix_presentations[i]);
118 30 av_freep(&c->mix_presentations);
119 30 c->nb_mix_presentations = 0;
120
121
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 30 times.
94 for (int i = 0; i < c->nb_param_definitions; i++)
122 64 av_free(c->param_definitions[i]);
123 30 av_freep(&c->param_definitions);
124 30 c->nb_param_definitions = 0;
125 }
126