xref: /btstack/src/le-audio/le_audio_base_parser.h (revision 2e624289f9e34d7048397ae659279a09d2636aca)
1 /*
2  * Copyright (C) 2022 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
21  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  */
31 
32 /**
33  * @title Broadcast Audio Source Endpoint AD Parser
34  */
35 
36 #ifndef LE_AUDIO_BASE_PARSER_H
37 #define LE_AUDIO_BASE_PARSER_H
38 
39 #include <stdint.h>
40 
41 #if defined __cplusplus
42 extern "C" {
43 #endif
44 
45 typedef struct {
46     const uint8_t * buffer;
47     uint16_t size;
48     uint8_t  subgroup_index;
49     uint8_t  subgroup_count;
50     uint16_t subgroup_offset;
51     uint8_t  subgroup_codec_specific_configuration_len;
52     uint8_t  subgroup_metadata_len;
53     uint8_t  bis_index;
54     uint8_t  bis_count;
55     uint16_t bis_offset;
56 } le_audio_base_parser_t;
57 
58 /**
59  * Initialize BASE
60  * @param parser
61  * @param buffer to setup BASE
62  * @param size of buffer
63  * @param presentation_delay_us
64  * @return valid BASE struct found
65  */
66 bool le_audio_base_parser_init(le_audio_base_parser_t * parser, const uint8_t * buffer, uint16_t size);
67 
68 /**
69  * Get number of subgroups in BASE
70  * @param parser
71  * @return
72  */
73 uint8_t le_audio_base_parser_get_num_subgroups(le_audio_base_parser_t * parser);
74 
75 /**
76  * Get Pressentation Delay in us
77  * @param parser
78  * @return
79  */
80 uint32_t le_audio_base_parser_get_presentation_delay(le_audio_base_parser_t * parser);
81 
82 /**
83  * Get Num BIS for current subgroup
84  * @param parser
85  * @return
86  */
87 uint8_t le_audio_base_parser_subgroup_get_num_bis(le_audio_base_parser_t * parser);
88 
89 /**
90  * Get Codec ID for current subgroup
91  * @param parser
92  * @return true if successful
93  */
94 const uint8_t * le_audio_base_parser_subgroup_get_codec_id(le_audio_base_parser_t * parser);
95 
96 /**
97  * Get Codec Specific Configuration Length for current subgroup
98  * @param parser
99  * @return
100  */
101 uint8_t le_audio_base_parser_subgroup_get_codec_specific_configuration_length(le_audio_base_parser_t * parser);
102 
103 /**
104  * Get Codec Specific Configuration for current subgroup
105  * @param parser
106  * @return
107  */
108 const uint8_t * le_audio_base_parser_subgroup_get_codec_specific_configuration(le_audio_base_parser_t * parser);
109 
110 /**
111  * Get Metadata Length for current subgroup
112  * @param parser
113  * @return
114  */
115 uint8_t le_audio_base_parser_subgroup_get_metadata_length(le_audio_base_parser_t * parser);
116 
117 /**
118  * Get Metadata for current subgroup
119  * @param parser
120  * @return
121  */
122 const uint8_t * le_audio_base_subgroup_parser_get_metadata(le_audio_base_parser_t * parser);
123 
124 /**
125  * Process next subgroup
126  * @param parser
127  */
128 void le_audio_base_parser_subgroup_next(le_audio_base_parser_t * parser);
129 
130 /**
131  * Get BIS Index for current BIS
132  * @param parser
133  * @return
134  */
135 uint8_t le_audio_base_parser_bis_get_index(le_audio_base_parser_t * parser);
136 
137 /**
138  * Get Codec Specific Configuration Length for current BIS
139  * @param parser
140  * @return
141  */
142 uint8_t le_audio_base_parser_bis_get_codec_specific_configuration_length(le_audio_base_parser_t * parser);
143 
144 /**
145  * Get Codec Specific Configuration for current BIS
146  * @param parser
147  * @return
148  */
149 const uint8_t * le_audio_base_bis_parser_get_codec_specific_configuration(le_audio_base_parser_t * parser);
150 
151 /**
152  * Process next BIS
153  * @param parser
154  */
155 void le_audio_base_parser_bis_next(le_audio_base_parser_t * parser);
156 
157 #if defined __cplusplus
158 }
159 #endif
160 
161 #endif // BASE_BUILDER_H
162