hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * BlueALSA - bluealsa.h
 * Copyright (c) 2016-2018 Arkadiusz Bokowy
 *
 * This file is a part of bluez-alsa.
 *
 * This project is licensed under the terms of the MIT license.
 *
 */
 
#ifndef BLUEALSA_BLUEALSA_H
#define BLUEALSA_BLUEALSA_H
 
#if HAVE_CONFIG_H
# include "config.h"
#endif
 
#include <poll.h>
#include <pthread.h>
#include <stdbool.h>
 
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
 
#include <glib.h>
#include <gio/gio.h>
 
#include "bluez.h"
#include "bluez-a2dp.h"
#include "shared/ctl-proto.h"
 
/* Maximal number of clients connected to the controller. */
#define BLUEALSA_MAX_CLIENTS 7
 
/* Indexes of special file descriptors in the poll array. */
#define CTL_IDX_SRV 0
#define CTL_IDX_EVT 1
#define __CTL_IDX_MAX 2
 
struct ba_config {
 
   /* used HCI device */
   struct hci_dev_info hci_dev;
 
   /* set of enabled profiles */
   struct {
       bool a2dp_source;
       bool a2dp_sink;
       bool hsp_hs;
       bool hsp_ag;
       bool hfp_hf;
       bool hfp_ag;
   } enable;
 
   /* established D-Bus connection */
   GDBusConnection *dbus;
 
   /* used for main thread identification */
   pthread_t main_thread;
 
   /* collection of connected devices */
   pthread_mutex_t devices_mutex;
   GHashTable *devices;
 
   /* registered D-Bus objects */
   GHashTable *dbus_objects;
 
   /* audio group ID */
   gid_t gid_audio;
 
   struct {
 
       pthread_t thread;
       bool socket_created;
       bool thread_created;
 
       struct pollfd pfds[__CTL_IDX_MAX + BLUEALSA_MAX_CLIENTS];
       /* event subscriptions for connected clients */
       enum ba_event subs[BLUEALSA_MAX_CLIENTS];
 
       /* PIPE for transferring events */
       int evt[2];
 
   } ctl;
 
   struct {
       /* set of features exposed via Service Discovery */
       int features_sdp_hf;
       int features_sdp_ag;
       /* set of features exposed via RFCOMM connection */
       int features_rfcomm_hf;
       int features_rfcomm_ag;
   } hfp;
 
   struct {
 
       /* NULL-terminated list of available A2DP codecs */
       const struct bluez_a2dp_codec **codecs;
 
       /* Control audio volume natively by the connected device. The disadvantage
        * of this control type is a monophonic volume change. */
       bool volume;
 
       /* Support for monophonic sound in the A2DP profile is mandatory for
        * sink and semi-mandatory for source. So, if one wants only the bare
        * minimum, it would be possible - e.g. due to bandwidth limitations. */
       bool force_mono;
       /* The sampling rates of 44.1 kHz (aka Audio CD) and 48 kHz are mandatory
        * for sink endpoint and semi-mandatory for source. It is then possible
        * to force lower sampling in order to save Bluetooth bandwidth. */
       bool force_44100;
 
       /* The number of seconds for keeping A2DP transport alive after PCM has
        * been closed. One might set this value to negative number for infinite
        * time. This option applies for the source profile only. */
       int keep_alive;
 
   } a2dp;
 
#if ENABLE_AAC
   bool aac_afterburner;
   uint8_t aac_vbr_mode;
#endif
 
#if ENABLE_LDAC
   bool ldac_abr;
   uint8_t ldac_eqmid;
#endif
 
};
 
/* Structure describing registered D-Bus object. */
struct ba_dbus_object {
   /* D-Bus object registration ID */
   unsigned int id;
   enum bluetooth_profile profile;
   uint16_t codec;
   /* determine whether profile is used */
   bool connected;
};
 
/* Global BlueALSA configuration. */
extern struct ba_config config;
 
int bluealsa_config_init(void);
void bluealsa_config_free(void);
 
#endif