Skip to content

Commit 524ff53

Browse files
committed
nimble/services: add PACS
This commit adds Published Audio Capabilities Service/Prifile. In pair ble_audio_codec module is added, that supports registering supported codecs with their corresponding configurations.
1 parent e5acfe0 commit 524ff53

File tree

16 files changed

+851
-10
lines changed

16 files changed

+851
-10
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_BLE_AUDIO_CODEC_
21+
#define H_BLE_AUDIO_CODEC_
22+
23+
#include "stdint.h"
24+
#include "ble_audio_common.h"
25+
26+
#define BLE_AUDIO_CODEC_FLAG_SOURCE 0x01
27+
#define BLE_AUDIO_CODEC_FLAG_SINK 0x02
28+
29+
typedef int ble_audio_codec_parser(uint8_t codec_spec_caps_len,
30+
uint8_t *codec_spec_caps,
31+
void *cb_arg);
32+
33+
struct ble_audio_codec_record {
34+
STAILQ_ENTRY(ble_audio_codec_record) next;
35+
struct ble_audio_codec_id codec_id;
36+
uint8_t codec_spec_caps_len;
37+
uint8_t *codec_spec_caps;
38+
uint8_t metadata_len;
39+
uint8_t *metadata;
40+
uint8_t flags;
41+
ble_audio_codec_parser *parser;
42+
void *parser_arg;
43+
};
44+
45+
/** Type definition for GATT service iteration callback function. */
46+
typedef int ble_audio_codec_foreach_fn(struct ble_audio_codec_record *
47+
record, void *arg);
48+
49+
int ble_audio_codec_register(struct ble_audio_codec_id codec_id,
50+
uint8_t codec_spec_caps_len,
51+
uint8_t *codec_spec_caps,
52+
uint8_t metadata_len,
53+
uint8_t *metadata,
54+
uint8_t flags,
55+
ble_audio_codec_parser *cb,
56+
void *cb_arg);
57+
58+
int ble_audio_codec_unregister(struct ble_audio_codec_record *codec_record);
59+
60+
int ble_audio_codec_foreach(ble_audio_codec_foreach_fn *cb, void *arg);
61+
62+
#endif /* H_BLE_AUDIO_CODEC_ */

nimble/host/include/host/ble_audio_common.h

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,45 @@
9191
#define BLE_AUDIO_LOCATION_LEFT_SURROUND (1ULL << 23)
9292
#define BLE_AUDIO_LOCATION_RIGHT_SURROUND (1ULL << 24)
9393

94-
#define BLE_AUDIO_CODEC_SAMPLING_FREQ_TYPE 0x01
95-
#define BLE_AUDIO_CODEC_FRAME_DURATION_TYPE 0x02
96-
#define BLE_AUDIO_CODEC_AUDIO_CHANNEL_ALLOCATION_TYPE 0x03
97-
#define BLE_AUDIO_CODEC_OCTETS_PER_CODEC_FRAME_TYPE 0x04
98-
#define BLE_AUDIO_CODEC_FRAME_BLOCKS_PER_SDU_TYPE 0x05
94+
#define BLE_AUDIO_CODEC_CONF_SAMPLING_FREQ_TYPE 0x01
95+
#define BLE_AUDIO_CODEC_CONF_FRAME_DURATION_TYPE 0x02
96+
#define BLE_AUDIO_CODEC_CONF_AUDIO_CHANNEL_ALLOCATION_TYPE 0x03
97+
#define BLE_AUDIO_CODEC_CONF_OCTETS_PER_CODEC_FRAME_TYPE 0x04
98+
#define BLE_AUDIO_CODEC_CONF_FRAME_BLOCKS_PER_SDU_TYPE 0x05
9999

100+
#define BLE_AUDIO_CODEC_CAPS_SAMPLING_FREQS_TYPE 0x01
101+
#define BLE_AUDIO_CODEC_CAPS_FRAME_DURATIONS_TYPE 0x02
102+
#define BLE_AUDIO_CODEC_CAPS_SUP_AUDIO_CHANNEL_COUNTS_TYPE 0x03
103+
#define BLE_AUDIO_CODEC_CAPS_OCTETS_PER_CODEC_FRAME_TYPE 0x04
104+
#define BLE_AUDIO_CODEC_CAPS_FRAMES_PER_SDU_TYPE 0x05
105+
106+
#define BLE_AUDIO_CONTEXT_TYPE_PROHIBITED 0x0000
107+
#define BLE_AUDIO_CONTEXT_TYPE_UNSPECIFIED 0x0001
108+
#define BLE_AUDIO_CONTEXT_TYPE_CONVERSATIONAL 0x0002
109+
#define BLE_AUDIO_CONTEXT_TYPE_MEDIA 0x0004
110+
#define BLE_AUDIO_CONTEXT_TYPE_GAME 0x0008
111+
#define BLE_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL 0x0010
112+
#define BLE_AUDIO_CONTEXT_TYPE_VOICE_ASSISTANTS 0x0020
113+
#define BLE_AUDIO_CONTEXT_TYPE_LIVE 0x0040
114+
#define BLE_AUDIO_CONTEXT_TYPE_SOUND_EFFECTS 0x0080
115+
#define BLE_AUDIO_CONTEXT_TYPE_NOTIFICATIONS 0x0100
116+
#define BLE_AUDIO_CONTEXT_TYPE_RINGTONE 0x0200
117+
#define BLE_AUDIO_CONTEXT_TYPE_ALERTS 0x0400
118+
#define BLE_AUDIO_CONTEXT_TYPE_EMERGENCY_ALARM 0x0800
119+
120+
#define BLE_AUDIO_CODEC_SUPPORTED_FRAME_DURATION_7_5_MS 0x0001
121+
#define BLE_AUDIO_CODEC_SUPPORTED_FRAME_DURATION_10_MS 0x0002
122+
#define BLE_AUDIO_CODEC_PREFERED_FRAME_DURATION_7_5_MS 0x0004
123+
#define BLE_AUDIO_CODEC_PREFERED_FRAME_DURATION_10_MS 0x0008
124+
125+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_1 0x0001
126+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_2 0x0002
127+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_3 0x0004
128+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_4 0x0008
129+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_5 0x0010
130+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_6 0x0020
131+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_7 0x0040
132+
#define BLE_AUDIO_CODEC_SUPPORTED_CHANNEL_COUNT_8 0x0080
100133
/**
101134
* @brief Helper macro used to build LTV array of Codec_Specific_Configuration.
102135
*
@@ -117,16 +150,54 @@
117150
_octets_per_codec_frame, \
118151
_codec_frame_blocks_per_sdu) \
119152
{ \
120-
2, BLE_AUDIO_CODEC_SAMPLING_FREQ_TYPE, _sampling_freq, \
121-
2, BLE_AUDIO_CODEC_FRAME_DURATION_TYPE, _frame_duration, \
122-
OPTIONAL_FIELD(5, BLE_AUDIO_CODEC_AUDIO_CHANNEL_ALLOCATION_TYPE, \
153+
2, BLE_AUDIO_CODEC_CAPS_SAMPLING_FREQS_TYPE, _sampling_freq, \
154+
2, BLE_AUDIO_CODEC_CAPS_FRAME_DURATIONS_TYPE, _frame_duration, \
155+
OPTIONAL_FIELD(5, BLE_AUDIO_CODEC_CONF_AUDIO_CHANNEL_ALLOCATION_TYPE, \
123156
_audio_channel_alloc) \
124-
3, BLE_AUDIO_CODEC_OCTETS_PER_CODEC_FRAME_TYPE, \
157+
3, BLE_AUDIO_CODEC_CONF_OCTETS_PER_CODEC_FRAME_TYPE, \
125158
(_octets_per_codec_frame), ((_octets_per_codec_frame) >> 8), \
126-
OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_FRAME_BLOCKS_PER_SDU_TYPE, \
159+
OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CONF_FRAME_BLOCKS_PER_SDU_TYPE, \
127160
_codec_frame_blocks_per_sdu) \
128161
}
129162

163+
/**
164+
* @brief Helper macro used to build LTV array of Codec_Specific_Capabilities.
165+
*
166+
* @param _sampling_freq Supported_Sampling_Frequencies -
167+
* single octet value
168+
* @param _frame_duration Supported_Frame_Durations - single
169+
* octet value
170+
* @param _audio_channel_counts Supported_Audio_Channel_Counts -
171+
* single octet value
172+
* @param _min_octets_per_codec_frame minimum value of
173+
* Supported_Octets_Per_Codec_Frame -
174+
* two octet value
175+
* @param _max_octets_per_codec_frame maximum value of
176+
* Supported_Octets_Per_Codec_Frame -
177+
* two octet value
178+
* @param _codec_frames_per_sdu Supported_Max_Codec_Frames_Per_SDU -
179+
* single octet value
180+
*
181+
* @return Pointer to a `ble_uuid16_t` structure.
182+
*/
183+
#define BLE_AUDIO_BUILD_CODEC_CAPS(_sampling_freq, \
184+
_frame_duration, \
185+
_audio_channel_counts, \
186+
_min_octets_per_codec_frame, \
187+
_max_octets_per_codec_frame, \
188+
_codec_frames_per_sdu) \
189+
{ \
190+
2, BLE_AUDIO_CODEC_CAPS_SAMPLING_FREQS_TYPE, _sampling_freq, \
191+
2, BLE_AUDIO_CODEC_CAPS_FRAME_DURATIONS_TYPE, _frame_duration, \
192+
OPTIONAL_FIELD(5, BLE_AUDIO_CODEC_CAPS_SUP_AUDIO_CHANNEL_COUNTS_TYPE, \
193+
_audio_channel_counts) \
194+
3, BLE_AUDIO_CODEC_CAPS_OCTETS_PER_CODEC_FRAME_TYPE, \
195+
(_min_octets_per_codec_frame), ((_min_octets_per_codec_frame) >> 8), \
196+
(_max_octets_per_codec_frame), ((_max_octets_per_codec_frame) >> 8), \
197+
OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CAPS_FRAMES_PER_SDU_TYPE, \
198+
_codec_frames_per_sdu) \
199+
}
200+
130201
struct ble_audio_codec_id {
131202
/** Coding Fromat */
132203
uint8_t format;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_BLE_AUDIO_SVC_PACS_
21+
#define H_BLE_AUDIO_SVC_PACS_
22+
23+
#define BLE_SVC_AUDIO_PACS_UUID16 0x1850
24+
#define BLE_SVC_AUDIO_PACS_CHR_UUID16_SINK_PAC 0x2BC9
25+
#define BLE_SVC_AUDIO_PACS_CHR_UUID16_SINK_AUDIO_LOCATIONS 0x2BCA
26+
#define BLE_SVC_AUDIO_PACS_CHR_UUID16_SOURCE_PAC 0x2BCB
27+
#define BLE_SVC_AUDIO_PACS_CHR_UUID16_SOURCE_AUDIO_LOCATIONS 0x2BCC
28+
#define BLE_SVC_AUDIO_PACS_CHR_UUID16_AVAILABLE_AUDIO_CONTEXTS 0x2BCD
29+
#define BLE_SVC_AUDIO_PACS_CHR_UUID16_SUPPORTED_AUDIO_CONTEXTS 0x2BCE
30+
31+
int ble_svc_audio_pacs_set_sink_audio_loc(uint32_t audio_locations);
32+
int ble_svc_audio_pacs_set_source_audio_loc(uint32_t audio_locations);
33+
int ble_svc_audio_pacs_set_sup_contexts(uint16_t sink_contexts,
34+
uint16_t source_contexts);
35+
int ble_svc_audio_pacs_set_avail_contexts(uint16_t conn_handle,
36+
uint16_t sink_contexts,
37+
uint16_t source_contexts);
38+
39+
#endif /* H_BLE_AUDIO_SVC_PACS_ */
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
pkg.name: nimble/host/services/audio/pacs
19+
pkg.description: Published Audio Capabilities Service
20+
pkg.author: "Apache Mynewt <[email protected]>"
21+
pkg.homepage: "http://mynewt.apache.org/"
22+
pkg.keywords:
23+
- ble
24+
- bluetooth
25+
- pacs
26+
- nimble
27+
28+
pkg.deps:
29+
- nimble/host
30+
31+
pkg.init:
32+
ble_svc_audio_pacs_init: 'MYNEWT_VAL(BLE_SVC_AUDIO_PACS_SYSINIT_STAGE)'

0 commit comments

Comments
 (0)