PipeWire  1.6.4
layout-types.h
Go to the documentation of this file.
1 /* Simple Plugin API */
2 /* SPDX-FileCopyrightText: Copyright © 2025 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef SPA_AUDIO_LAYOUT_TYPES_H
6 #define SPA_AUDIO_LAYOUT_TYPES_H
7 
8 #include <spa/utils/type.h>
9 #include <spa/utils/string.h>
10 #include <spa/param/audio/layout.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
21 #ifndef SPA_API_AUDIO_LAYOUT_TYPES
22  #ifdef SPA_API_IMPL
23  #define SPA_API_AUDIO_LAYOUT_TYPES SPA_API_IMPL
24  #else
25  #define SPA_API_AUDIO_LAYOUT_TYPES static inline
26  #endif
27 #endif
28 
29 static const struct spa_type_audio_layout_info {
30  const char *name;
33  { "Mono", { SPA_AUDIO_LAYOUT_Mono } },
34  { "Stereo", { SPA_AUDIO_LAYOUT_Stereo } },
35  { "Quad", { SPA_AUDIO_LAYOUT_Quad } },
36  { "Pentagonal", { SPA_AUDIO_LAYOUT_Pentagonal } },
37  { "Hexagonal", { SPA_AUDIO_LAYOUT_Hexagonal } },
38  { "Octagonal", { SPA_AUDIO_LAYOUT_Octagonal } },
39  { "Cube", { SPA_AUDIO_LAYOUT_Cube } },
40  { "MPEG-1.0", { SPA_AUDIO_LAYOUT_MPEG_1_0 } },
41  { "MPEG-2.0", { SPA_AUDIO_LAYOUT_MPEG_2_0 } },
42  { "MPEG-3.0A", { SPA_AUDIO_LAYOUT_MPEG_3_0A } },
43  { "MPEG-3.0B", { SPA_AUDIO_LAYOUT_MPEG_3_0B } },
44  { "MPEG-4.0A", { SPA_AUDIO_LAYOUT_MPEG_4_0A } },
45  { "MPEG-4.0B", { SPA_AUDIO_LAYOUT_MPEG_4_0B } },
46  { "MPEG-5.0A", { SPA_AUDIO_LAYOUT_MPEG_5_0A } },
47  { "MPEG-5.0B", { SPA_AUDIO_LAYOUT_MPEG_5_0B } },
48  { "MPEG-5.0C", { SPA_AUDIO_LAYOUT_MPEG_5_0C } },
49  { "MPEG-5.0D", { SPA_AUDIO_LAYOUT_MPEG_5_0D } },
50  { "MPEG-5.1A", { SPA_AUDIO_LAYOUT_MPEG_5_1A } },
51  { "MPEG-5.1B", { SPA_AUDIO_LAYOUT_MPEG_5_1B } },
52  { "MPEG-5.1C", { SPA_AUDIO_LAYOUT_MPEG_5_1C } },
53  { "MPEG-5.1D", { SPA_AUDIO_LAYOUT_MPEG_5_1D } },
54  { "MPEG-6.1A", { SPA_AUDIO_LAYOUT_MPEG_6_1A } },
55  { "MPEG-7.1A", { SPA_AUDIO_LAYOUT_MPEG_7_1A } },
56  { "MPEG-7.1B", { SPA_AUDIO_LAYOUT_MPEG_7_1B } },
57  { "MPEG-7.1C", { SPA_AUDIO_LAYOUT_MPEG_7_1C } },
58  { "2.1", { SPA_AUDIO_LAYOUT_2_1 } },
59  { "2RC", { SPA_AUDIO_LAYOUT_2RC } },
60  { "2FC", { SPA_AUDIO_LAYOUT_2FC } },
61  { "3.1", { SPA_AUDIO_LAYOUT_3_1 } },
62  { "4.0", { SPA_AUDIO_LAYOUT_4_0 } },
63  { "2.2", { SPA_AUDIO_LAYOUT_2_2 } },
64  { "4.1", { SPA_AUDIO_LAYOUT_4_1 } },
65  { "5.0", { SPA_AUDIO_LAYOUT_5_0 } },
66  { "5.0R", { SPA_AUDIO_LAYOUT_5_0R } },
67  { "5.1", { SPA_AUDIO_LAYOUT_5_1 } },
68  { "5.1R", { SPA_AUDIO_LAYOUT_5_1R } },
69  { "6.0", { SPA_AUDIO_LAYOUT_6_0 } },
70  { "6.0F", { SPA_AUDIO_LAYOUT_6_0F } },
71  { "6.1", { SPA_AUDIO_LAYOUT_6_1 } },
72  { "6.1F", { SPA_AUDIO_LAYOUT_6_1F } },
73  { "7.0", { SPA_AUDIO_LAYOUT_7_0 } },
74  { "7.0F", { SPA_AUDIO_LAYOUT_7_0F } },
75  { "7.1", { SPA_AUDIO_LAYOUT_7_1 } },
76  { "7.1W", { SPA_AUDIO_LAYOUT_7_1W } },
77  { "7.1WR", { SPA_AUDIO_LAYOUT_7_1WR } },
78  { NULL, { 0, { SPA_AUDIO_CHANNEL_UNKNOWN } } },
79 };
80 
83  const char *name)
84 {
85  uint32_t max_position = SPA_AUDIO_LAYOUT_INFO_MAX_POSITION(size);
86  if (spa_strstartswith(name, "AUX")) {
87  uint32_t i, n_pos;
88  if (spa_atou32(name+3, &n_pos, 10)) {
89  if (n_pos > max_position)
90  return -ECHRNG;
91  for (i = 0; i < 0x1000 && i < n_pos; i++)
92  layout->position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
93  for (; i < n_pos; i++)
95  layout->n_channels = n_pos;
96  return n_pos;
97  }
98  }
100  if (spa_streq(name, i->name)) {
101  if (i->layout.n_channels > max_position)
102  return -ECHRNG;
103  *layout = i->layout;
104  return i->layout.n_channels;
105  }
106  }
107  return -ENOTSUP;
108 }
109 
114 #ifdef __cplusplus
115 } /* extern "C" */
116 #endif
117 
118 #endif /* SPA_AUDIO_LAYOUT_TYPES_H */
#define SPA_AUDIO_LAYOUT_MPEG_7_1A
Definition: layout.h:97
#define SPA_AUDIO_LAYOUT_Octagonal
Definition: layout.h:47
#define SPA_AUDIO_LAYOUT_MPEG_6_1A
Definition: layout.h:93
#define SPA_AUDIO_LAYOUT_6_0F
Definition: layout.h:144
#define SPA_AUDIO_LAYOUT_5_1
Definition: layout.h:135
#define SPA_AUDIO_LAYOUT_4_1
Definition: layout.h:126
#define SPA_AUDIO_LAYOUT_MPEG_7_1C
Definition: layout.h:105
#define SPA_AUDIO_LAYOUT_7_0F
Definition: layout.h:159
#define SPA_AUDIO_LAYOUT_7_1W
Definition: layout.h:167
#define SPA_AUDIO_LAYOUT_Cube
Definition: layout.h:51
#define SPA_AUDIO_LAYOUT_3_1
Definition: layout.h:119
#define SPA_AUDIO_LAYOUT_4_0
Definition: layout.h:121
#define SPA_AUDIO_LAYOUT_MPEG_5_1A
Definition: layout.h:81
#define SPA_AUDIO_LAYOUT_2_2
Definition: layout.h:123
#define SPA_AUDIO_LAYOUT_7_1
Definition: layout.h:163
#define SPA_AUDIO_LAYOUT_MPEG_5_0C
Definition: layout.h:75
#define SPA_AUDIO_LAYOUT_MPEG_5_1C
Definition: layout.h:87
#define SPA_AUDIO_LAYOUT_5_0R
Definition: layout.h:132
#define SPA_AUDIO_LAYOUT_Quad
Definition: layout.h:39
#define SPA_AUDIO_LAYOUT_MPEG_5_0A
Definition: layout.h:69
#define SPA_AUDIO_LAYOUT_MPEG_1_0
Definition: layout.h:58
#define SPA_AUDIO_LAYOUT_MPEG_2_0
Definition: layout.h:60
#define SPA_AUDIO_LAYOUT_MPEG_4_0B
Definition: layout.h:67
#define SPA_AUDIO_LAYOUT_Stereo
Definition: layout.h:38
#define SPA_AUDIO_LAYOUT_MPEG_3_0A
Definition: layout.h:61
#define SPA_AUDIO_LAYOUT_INFO_MAX_POSITION(size)
Definition: layout.h:33
#define SPA_AUDIO_LAYOUT_Mono
Definition: layout.h:36
#define SPA_AUDIO_LAYOUT_MPEG_5_0B
Definition: layout.h:72
#define SPA_AUDIO_LAYOUT_7_1WR
Definition: layout.h:171
#define SPA_AUDIO_LAYOUT_5_1R
Definition: layout.h:138
#define SPA_AUDIO_LAYOUT_MPEG_5_1B
Definition: layout.h:84
#define SPA_AUDIO_LAYOUT_MPEG_7_1B
Definition: layout.h:101
#define SPA_AUDIO_LAYOUT_6_0
Definition: layout.h:141
#define SPA_AUDIO_LAYOUT_Pentagonal
Definition: layout.h:41
SPA_API_AUDIO_LAYOUT_TYPES int spa_audio_layout_info_parse_name(struct spa_audio_layout_info *layout, size_t size, const char *name)
Definition: layout-types.h:89
#define SPA_AUDIO_LAYOUT_2FC
Definition: layout.h:116
#define SPA_AUDIO_LAYOUT_MPEG_5_0D
Definition: layout.h:78
#define SPA_AUDIO_LAYOUT_5_0
Definition: layout.h:129
#define SPA_AUDIO_LAYOUT_6_1F
Definition: layout.h:151
#define SPA_AUDIO_LAYOUT_MPEG_3_0B
Definition: layout.h:63
#define SPA_API_AUDIO_LAYOUT_TYPES
Definition: layout-types.h:32
#define SPA_AUDIO_LAYOUT_Hexagonal
Definition: layout.h:44
#define SPA_AUDIO_LAYOUT_2RC
Definition: layout.h:114
#define SPA_AUDIO_LAYOUT_2_1
Definition: layout.h:111
#define SPA_AUDIO_LAYOUT_MPEG_4_0A
Definition: layout.h:65
#define SPA_AUDIO_LAYOUT_7_0
Definition: layout.h:155
#define SPA_AUDIO_LAYOUT_6_1
Definition: layout.h:147
#define SPA_AUDIO_LAYOUT_MPEG_5_1D
Definition: layout.h:90
@ SPA_AUDIO_CHANNEL_AUX0
Definition: raw.h:205
@ SPA_AUDIO_CHANNEL_UNKNOWN
unspecified
Definition: raw.h:162
SPA_API_STRING bool spa_strstartswith(const char *s, const char *prefix)
Definition: string.h:73
SPA_API_STRING bool spa_atou32(const char *str, uint32_t *val, int base)
Convert str to an uint32_t with the given base and store the result in val.
Definition: string.h:139
SPA_API_STRING bool spa_streq(const char *s1, const char *s2)
Definition: string.h:52
#define SPA_FOR_EACH_ELEMENT_VAR(arr, var)
Definition: defs.h:157
spa/param/audio/layout.h
spa/utils/type.h
spa/utils/string.h
Definition: layout.h:26
uint32_t position[SPA_AUDIO_MAX_CHANNELS]
Definition: layout.h:28
uint32_t n_channels
Definition: layout.h:27
Definition: layout-types.h:36
struct spa_audio_layout_info layout
Definition: layout-types.h:38