Git init
[framework/multimedia/pulseaudio.git] / src / modules / bluetooth / bluetooth-util.h
1 #ifndef foobluetoothutilhfoo
2 #define foobluetoothutilhfoo
3
4 /***
5   This file is part of PulseAudio.
6
7   Copyright 2008-2009 Joao Paulo Rechi Vita
8
9   PulseAudio is free software; you can redistribute it and/or modify
10   it under the terms of the GNU Lesser General Public License as
11   published by the Free Software Foundation; either version 2.1 of the
12   License, or (at your option) any later version.
13
14   PulseAudio is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   General Public License for more details.
18
19   You should have received a copy of the GNU Lesser General Public
20   License along with PulseAudio; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22   USA.
23 ***/
24
25 #include <dbus/dbus.h>
26
27 #include <pulsecore/llist.h>
28 #include <pulsecore/strlist.h>
29 #include <pulsecore/macro.h>
30 #include <pulsecore/core-util.h>
31
32 #define PA_BLUETOOTH_ERROR_NOT_SUPPORTED "org.bluez.Error.NotSupported"
33
34 /* UUID copied from bluez/audio/device.h */
35 #define GENERIC_AUDIO_UUID      "00001203-0000-1000-8000-00805f9b34fb"
36
37 #define HSP_HS_UUID             "00001108-0000-1000-8000-00805f9b34fb"
38 #define HSP_AG_UUID             "00001112-0000-1000-8000-00805f9b34fb"
39
40 #define HFP_HS_UUID             "0000111e-0000-1000-8000-00805f9b34fb"
41 #define HFP_AG_UUID             "0000111f-0000-1000-8000-00805f9b34fb"
42
43 #define ADVANCED_AUDIO_UUID     "0000110d-0000-1000-8000-00805f9b34fb"
44
45 #define A2DP_SOURCE_UUID        "0000110a-0000-1000-8000-00805f9b34fb"
46 #define A2DP_SINK_UUID          "0000110b-0000-1000-8000-00805f9b34fb"
47
48 typedef struct pa_bluetooth_uuid pa_bluetooth_uuid;
49 typedef struct pa_bluetooth_device pa_bluetooth_device;
50 typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
51 typedef struct pa_bluetooth_transport pa_bluetooth_transport;
52
53 struct userdata;
54
55 struct pa_bluetooth_uuid {
56     char *uuid;
57     PA_LLIST_FIELDS(pa_bluetooth_uuid);
58 };
59
60 enum profile {
61     PROFILE_A2DP,
62     PROFILE_A2DP_SOURCE,
63     PROFILE_HSP,
64     PROFILE_HFGW,
65     PROFILE_OFF
66 };
67
68 struct pa_bluetooth_transport {
69     pa_bluetooth_discovery *y;
70     char *path;
71     enum profile profile;
72     uint8_t codec;
73     uint8_t *config;
74     int config_size;
75     pa_bool_t nrec;
76 };
77
78 /* This enum is shared among Audio, Headset, AudioSink, and AudioSource, although not all values are acceptable in all profiles */
79 typedef enum pa_bt_audio_state {
80     PA_BT_AUDIO_STATE_INVALID = -1,
81     PA_BT_AUDIO_STATE_DISCONNECTED,
82     PA_BT_AUDIO_STATE_CONNECTING,
83     PA_BT_AUDIO_STATE_CONNECTED,
84     PA_BT_AUDIO_STATE_PLAYING
85 } pa_bt_audio_state_t;
86
87 struct pa_bluetooth_device {
88     pa_bool_t dead;
89
90     int device_info_valid;      /* 0: no results yet; 1: good results; -1: bad results ... */
91
92     /* Device information */
93     char *name;
94     char *path;
95     pa_hashmap *transports;
96     int paired;
97     char *alias;
98     int device_connected;
99     PA_LLIST_HEAD(pa_bluetooth_uuid, uuids);
100     char *address;
101     int class;
102     int trusted;
103
104     /* Audio state */
105     pa_bt_audio_state_t audio_state;
106
107     /* AudioSink state */
108     pa_bt_audio_state_t audio_sink_state;
109
110     /* AudioSource state */
111     pa_bt_audio_state_t audio_source_state;
112
113     /* Headset state */
114     pa_bt_audio_state_t headset_state;
115
116     /* HandsfreeGateway state */
117     pa_bt_audio_state_t hfgw_state;
118 };
119
120 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
121 pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
122 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *d);
123
124 void pa_bluetooth_discovery_sync(pa_bluetooth_discovery *d);
125
126 const pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery *d, const char* path);
127 const pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discovery *d, const char* address);
128
129 const pa_bluetooth_transport* pa_bluetooth_discovery_get_transport(pa_bluetooth_discovery *y, const char *path);
130 const pa_bluetooth_transport* pa_bluetooth_device_get_transport(const pa_bluetooth_device *d, enum profile profile);
131
132 int pa_bluetooth_transport_acquire(const pa_bluetooth_transport *t, const char *accesstype, size_t *imtu, size_t *omtu);
133 void pa_bluetooth_transport_release(const pa_bluetooth_transport *t, const char *accesstype);
134 int pa_bluetooth_transport_parse_property(pa_bluetooth_transport *t, DBusMessageIter *i);
135
136 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *d);
137
138 const char* pa_bluetooth_get_form_factor(uint32_t class);
139
140 char *pa_bluetooth_cleanup_name(const char *name);
141
142 pa_bool_t pa_bluetooth_uuid_has(pa_bluetooth_uuid *uuids, const char *uuid);
143
144 #endif