device-manager: Add Dbus interfaces to specify stream role to usb device
[platform/core/multimedia/pulseaudio-modules-tizen.git] / src / tizen-device.h
1 #ifndef footizendevicefoo
2 #define footizendevicefoo
3
4 #include <pulsecore/core.h>
5 #include "tizen-device-def.h"
6 #include "communicator.h"
7 #ifdef HAVE_DBUS
8 #include <pulsecore/dbus-shared.h>
9 #include <pulsecore/dbus-util.h>
10 #endif
11
12 #define MAX_INTSET_NUM 32
13
14 typedef struct pa_tz_device pa_tz_device;
15 typedef struct pa_tz_device_new_data pa_tz_device_new_data;
16 typedef struct pa_intset pa_intset;
17
18 /* structures for represent device items which can be connected/disconnected */
19
20 /*
21     If this is created or freed, device connected/disconnected
22     hook(for internal)/callback(for apps) will be called.
23 */
24 struct pa_tz_device {
25     char *type;
26     char *name;
27     /* Decimal ID which is unique in device list
28      * This will be exported up to sound_manager_get_device_id */
29     uint32_t id;
30     /* String ID which will be used internally
31      * In multi-Device case(bt, usb), this will be used to classify
32      * each physicall device */
33     char *system_id;
34
35     /* Additional information for USB device
36      * This comes from udev */
37     int vendor_id;
38     int product_id;
39
40     dm_device_direction_t direction;
41
42     /* Set by stream-manager
43      * If this is changed, will notify via callback.
44      * It will be replaced by is_running variable */
45     dm_device_state_t state;
46
47     char *specified_stream_role;
48
49     /* If it is changed, will notify via callback */
50     bool is_running;
51
52     /* Can get proper sink/source in hashmaps with key(=device_role) */
53     pa_hashmap *playback_devices;
54     pa_hashmap *capture_devices;
55
56     /* creation time */
57     pa_usec_t creation_time;
58
59     /* Will be true, if this device uses internal codec(card),
60      * false, if this device uses external card(bt-a2dp, usb */
61     bool use_internal_codec;
62     /* If this is sco device, this can be used to */
63     bool sco_opened;
64
65     /* Devices are contained in this list */
66     pa_idxset *list;
67
68     pa_communicator *comm;
69     pa_dbus_connection *dbus_conn;
70 };
71
72 struct pa_tz_device_new_data {
73     char *type;
74     char *name;
75     /* for multi-device type(bt, usb) */
76     char *system_id;
77
78     int vendor_id;
79     int product_id;
80
81     dm_device_direction_t direction;
82     bool use_internal_codec;
83     pa_hashmap *playback_pcms;
84     pa_hashmap *capture_pcms;
85
86     pa_idxset *list;
87     pa_communicator *comm;
88     pa_dbus_connection *dbus_conn;
89 };
90
91 typedef struct _hook_call_data_for_conn_changed {
92     uint32_t event_id;
93     bool is_connected;
94     pa_tz_device *device;
95 } pa_tz_device_hook_data_for_conn_changed;
96
97 typedef struct _hook_call_data_for_state_changed {
98     uint32_t event_id;
99     bool activated;
100     pa_tz_device *device;
101 } pa_tz_device_hook_data_for_state_changed;
102
103 typedef struct _hook_call_data_for_running_changed {
104     uint32_t event_id;
105     bool is_running;
106     pa_tz_device *device;
107 } pa_tz_device_hook_data_for_running_changed;
108
109 /*** For device manager ***/
110 void pa_tz_device_dump_info(pa_tz_device *device, pa_log_level_t log_level);
111 void pa_tz_device_new_data_init(pa_tz_device_new_data *data, pa_idxset *list, pa_communicator *comm, pa_dbus_connection *conn);
112 void pa_tz_device_new_data_set_type(pa_tz_device_new_data *data, const char *type);
113 void pa_tz_device_new_data_set_name(pa_tz_device_new_data *data, const char *name);
114 void pa_tz_device_new_data_set_direction(pa_tz_device_new_data *data, dm_device_direction_t direction);
115 /* deivce which is multi-device type should have system_id */
116 void pa_tz_device_new_data_set_system_id(pa_tz_device_new_data *data, const char *system_id);
117 void pa_tz_device_new_data_set_vendor_id(pa_tz_device_new_data *data, int vendor_id);
118 void pa_tz_device_new_data_set_product_id(pa_tz_device_new_data *data, int product_id);
119 void pa_tz_device_new_data_set_use_internal_codec(pa_tz_device_new_data *data, bool use_internal_codec);
120 void pa_tz_device_new_data_add_sink(pa_tz_device_new_data *data, const char *role, pa_sink *sink);
121 void pa_tz_device_new_data_add_source(pa_tz_device_new_data *data, const char *role, pa_source *source);
122 void pa_tz_device_new_data_done(pa_tz_device_new_data *data);
123
124 /* Create tizen device instance,
125  * device connected hook will be fired */
126 pa_tz_device* pa_tz_device_new(pa_tz_device_new_data *data);
127 /* Destroy tizen device instance,
128  * device disconnected hook will be fired */
129 void pa_tz_device_free(pa_tz_device *device);
130 /* Can be used add/remove sink/source in runtime */
131 int pa_tz_device_add_sink(pa_tz_device *device, const char *role, pa_sink *sink);
132 int pa_tz_device_add_source(pa_tz_device *device, const char *role, pa_source *source);
133 int pa_tz_device_remove_sink(pa_tz_device *device, pa_sink *sink);
134 int pa_tz_device_remove_source(pa_tz_device *device, pa_source *source);
135 int pa_tz_device_remove_sink_with_role(pa_tz_device *device, const char *role);
136 int pa_tz_device_remove_source_with_role(pa_tz_device *device, const char *role);
137
138 /* Exported API for other modules */
139 pa_sink* pa_tz_device_get_sink(pa_tz_device *device, const char *role);
140 pa_source* pa_tz_device_get_source(pa_tz_device *device, const char *role);
141 void pa_tz_device_set_state(pa_tz_device *device, dm_device_state_t state);
142 dm_device_state_t pa_tz_device_get_state(pa_tz_device *device);
143 void pa_tz_device_set_running_and_notify(pa_tz_device *device, bool running);
144 bool pa_tz_device_is_running(pa_tz_device *device);
145 uint32_t pa_tz_device_get_id(pa_tz_device *device);
146 char* pa_tz_device_get_type(pa_tz_device *device);
147 char* pa_tz_device_get_name(pa_tz_device *device);
148 char* pa_tz_device_get_system_id(pa_tz_device *device);
149 dm_device_direction_t pa_tz_device_get_direction(pa_tz_device *device);
150 pa_usec_t pa_tz_device_get_creation_time(pa_tz_device *device);
151 bool pa_tz_device_is_use_internal_codec(pa_tz_device *device);
152 bool pa_tz_device_is_all_suspended(pa_tz_device *device);
153 pa_intset* pa_tz_device_get_stream_list(pa_tz_device *device);
154
155 /* Only for BT SCO device */
156 int pa_tz_device_sco_enable_pcm(pa_tz_device *device, bool enable);
157 int pa_tz_device_sco_open(pa_tz_device *device);
158 int pa_tz_device_sco_close(pa_tz_device *device);
159 int pa_tz_device_sco_get_property(pa_tz_device *device, bool *is_wide_band, bool *nrec);
160 int pa_tz_device_sco_get_status(pa_tz_device *device, dm_device_bt_sco_status_t *status);
161
162 /* Only for USB device */
163 int pa_tz_device_get_vendor_id(pa_tz_device *device);
164 int pa_tz_device_get_product_id(pa_tz_device *device);
165 char* pa_tz_device_get_specified_stream_role(pa_tz_device *device);
166
167 void pa_intset_free(pa_intset *s);
168 int pa_intset_first(pa_intset *s, int *val);
169 int pa_intset_next(pa_intset *s, int *val);
170
171 #define PA_INTSET_FOREACH(i, s, r) \
172     for ((r) = pa_intset_first((s), &(i)); (r == 0); (r) = pa_intset_next((s), &(i)))
173
174 #endif