fixup! tizen-device: add sample spec and return it for connected device list
[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 #ifndef __TIZEN_TV_EXTERNAL_BT_SCO__
63     /* If this is sco device, this can be used to */
64     bool sco_opened;
65 #endif
66
67     /* Devices are contained in this list */
68     pa_idxset *list;
69
70     pa_communicator *comm;
71     pa_dbus_connection *dbus_conn;
72 };
73
74 struct pa_tz_device_new_data {
75     char *type;
76     char *name;
77     /* for multi-device type(bt, usb) */
78     char *system_id;
79
80     int vendor_id;
81     int product_id;
82
83     dm_device_direction_t direction;
84     bool use_internal_codec;
85     pa_hashmap *playback_pcms;
86     pa_hashmap *capture_pcms;
87
88     pa_idxset *list;
89     pa_communicator *comm;
90     pa_dbus_connection *dbus_conn;
91 };
92
93 typedef struct _hook_call_data_for_conn_changed {
94     uint32_t event_id;
95     bool is_connected;
96     pa_tz_device *device;
97 } pa_tz_device_hook_data_for_conn_changed;
98
99 typedef struct _hook_call_data_for_state_changed {
100     uint32_t event_id;
101     bool activated;
102     pa_tz_device *device;
103 } pa_tz_device_hook_data_for_state_changed;
104
105 typedef struct _hook_call_data_for_running_changed {
106     uint32_t event_id;
107     bool is_running;
108     pa_tz_device *device;
109 } pa_tz_device_hook_data_for_running_changed;
110
111 /*** For device manager ***/
112 void pa_tz_device_dump_info(pa_tz_device *device, pa_log_level_t log_level);
113 void pa_tz_device_new_data_init(pa_tz_device_new_data *data, pa_idxset *list, pa_communicator *comm, pa_dbus_connection *conn);
114 void pa_tz_device_new_data_set_type(pa_tz_device_new_data *data, const char *type);
115 void pa_tz_device_new_data_set_name(pa_tz_device_new_data *data, const char *name);
116 void pa_tz_device_new_data_set_direction(pa_tz_device_new_data *data, dm_device_direction_t direction);
117 /* deivce which is multi-device type should have system_id */
118 void pa_tz_device_new_data_set_system_id(pa_tz_device_new_data *data, const char *system_id);
119 void pa_tz_device_new_data_set_vendor_id(pa_tz_device_new_data *data, int vendor_id);
120 void pa_tz_device_new_data_set_product_id(pa_tz_device_new_data *data, int product_id);
121 void pa_tz_device_new_data_set_use_internal_codec(pa_tz_device_new_data *data, bool use_internal_codec);
122 void pa_tz_device_new_data_add_sink(pa_tz_device_new_data *data, const char *role, pa_sink *sink);
123 void pa_tz_device_new_data_add_source(pa_tz_device_new_data *data, const char *role, pa_source *source);
124 void pa_tz_device_new_data_done(pa_tz_device_new_data *data);
125
126 /* Create tizen device instance,
127  * device connected hook will be fired */
128 pa_tz_device* pa_tz_device_new(pa_tz_device_new_data *data);
129 /* Destroy tizen device instance,
130  * device disconnected hook will be fired */
131 void pa_tz_device_free(pa_tz_device *device);
132 /* Can be used add/remove sink/source in runtime */
133 int pa_tz_device_add_sink(pa_tz_device *device, const char *role, pa_sink *sink);
134 int pa_tz_device_add_source(pa_tz_device *device, const char *role, pa_source *source);
135 int pa_tz_device_remove_sink(pa_tz_device *device, pa_sink *sink);
136 int pa_tz_device_remove_source(pa_tz_device *device, pa_source *source);
137 int pa_tz_device_remove_sink_with_role(pa_tz_device *device, const char *role);
138 int pa_tz_device_remove_source_with_role(pa_tz_device *device, const char *role);
139
140 /* Exported API for other modules */
141 pa_sink* pa_tz_device_get_sink(pa_tz_device *device, const char *role);
142 pa_source* pa_tz_device_get_source(pa_tz_device *device, const char *role);
143 void pa_tz_device_set_state(pa_tz_device *device, dm_device_state_t state);
144 dm_device_state_t pa_tz_device_get_state(pa_tz_device *device);
145 void pa_tz_device_set_running_and_notify(pa_tz_device *device, bool running);
146 bool pa_tz_device_is_running(pa_tz_device *device);
147 uint32_t pa_tz_device_get_id(pa_tz_device *device);
148 char* pa_tz_device_get_type(pa_tz_device *device);
149 char* pa_tz_device_get_role(pa_tz_device *device, const char *preferred_role);
150 char* pa_tz_device_get_name(pa_tz_device *device);
151 char* pa_tz_device_get_system_id(pa_tz_device *device);
152 dm_device_direction_t pa_tz_device_get_direction(pa_tz_device *device);
153 pa_usec_t pa_tz_device_get_creation_time(pa_tz_device *device);
154 bool pa_tz_device_is_use_internal_codec(pa_tz_device *device);
155 const pa_sample_spec* pa_tz_device_get_sample_spec(pa_tz_device *device);
156 bool pa_tz_device_is_all_suspended(pa_tz_device *device);
157 pa_intset* pa_tz_device_get_stream_list(pa_tz_device *device);
158
159 #ifndef __TIZEN_TV_EXTERNAL_BT_SCO__
160 /* Only for BT SCO device */
161 int pa_tz_device_sco_enable_pcm(pa_tz_device *device, bool enable);
162 int pa_tz_device_sco_open(pa_tz_device *device);
163 int pa_tz_device_sco_close(pa_tz_device *device);
164 int pa_tz_device_sco_get_property(pa_tz_device *device, bool *is_wide_band, bool *nrec);
165 int pa_tz_device_sco_get_status(pa_tz_device *device, dm_device_bt_sco_status_t *status);
166 #endif
167
168 /* Only for USB device */
169 int pa_tz_device_get_vendor_id(pa_tz_device *device);
170 int pa_tz_device_get_product_id(pa_tz_device *device);
171 char* pa_tz_device_get_specified_stream_role(pa_tz_device *device);
172
173 void pa_intset_free(pa_intset *s);
174 int pa_intset_first(pa_intset *s, int *val);
175 int pa_intset_next(pa_intset *s, int *val);
176
177 #define PA_INTSET_FOREACH(i, s, r) \
178     for ((r) = pa_intset_first((s), &(i)); (r == 0); (r) = pa_intset_next((s), &(i)))
179
180 #endif