1 #ifndef footizenaudiointernalfoo
2 #define footizenaudiointernalfoo
7 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
25 #include <sys/types.h>
26 #include <asoundlib.h>
27 #ifdef __USE_TINYALSA__
28 #include <tinyalsa/asoundlib.h>
33 #include "tizen-audio.h"
34 #include "vb_control_parameters.h"
39 #define PROPERTY_VALUE_MAX 92
41 #define AUDIO_DUMP_STR_LEN 256
42 #define AUDIO_DEVICE_INFO_LIST_MAX 16
47 #define DLOG_TAG "AUDIO_HAL"
48 #define AUDIO_LOG_ERROR(...) SLOG(LOG_ERROR, DLOG_TAG, __VA_ARGS__)
49 #define AUDIO_LOG_WARN(...) SLOG(LOG_WARN, DLOG_TAG, __VA_ARGS__)
50 #define AUDIO_LOG_INFO(...) SLOG(LOG_INFO, DLOG_TAG, __VA_ARGS__)
51 #define AUDIO_LOG_DEBUG(...) SLOG(LOG_DEBUG, DLOG_TAG, __VA_ARGS__)
52 #define AUDIO_LOG_VERBOSE(...) SLOG(LOG_DEBUG, DLOG_TAG, __VA_ARGS__)
54 #define AUDIO_LOG_ERROR(...) fprintf(stderr, __VA_ARGS__)
55 #define AUDIO_LOG_WARN(...) fprintf(stderr, __VA_ARGS__)
56 #define AUDIO_LOG_INFO(...) fprintf(stdout, __VA_ARGS__)
57 #define AUDIO_LOG_DEBUG(...) fprintf(stdout, __VA_ARGS__)
58 #define AUDIO_LOG_VERBOSE(...) fprintf(stdout, __VA_ARGS__)
61 #define AUDIO_RETURN_IF_FAIL(expr) do { \
63 AUDIO_LOG_ERROR("%s failed", #expr); \
67 #define AUDIO_RETURN_VAL_IF_FAIL(expr, val) do { \
69 AUDIO_LOG_ERROR("%s failed", #expr); \
73 #define AUDIO_RETURN_NULL_IF_FAIL(expr) do { \
75 AUDIO_LOG_ERROR("%s failed", #expr); \
80 #define MUTEX_LOCK(x_lock, lock_name) { \
81 AUDIO_LOG_DEBUG("try lock [%s]", lock_name); \
82 pthread_mutex_lock(&(x_lock)); \
83 AUDIO_LOG_DEBUG("after lock [%s]", lock_name); \
85 #define MUTEX_UNLOCK(x_lock, lock_name) { \
86 AUDIO_LOG_DEBUG("try unlock [%s]", lock_name); \
87 pthread_mutex_unlock(&(x_lock)); \
88 AUDIO_LOG_DEBUG("after unlock [%s]", lock_name); \
90 #define COND_TIMEDWAIT(x_cond, x_lock, x_cond_name, x_timeout_sec) { \
91 AUDIO_LOG_DEBUG("try cond wait [%s]", x_cond_name); \
93 clock_gettime(CLOCK_REALTIME, &ts); \
94 ts.tv_sec += x_timeout_sec; \
95 if (!pthread_cond_timedwait(&(x_cond), &(x_lock), &ts)) \
96 AUDIO_LOG_DEBUG("awaken cond [%s]", x_cond_name); \
98 AUDIO_LOG_ERROR("awaken cond [%s] by timeout(%d sec)", x_cond_name, x_timeout_sec); \
100 #define COND_SIGNAL(x_cond, x_cond_name) { \
101 AUDIO_LOG_DEBUG("send signal to cond [%s]", x_cond_name); \
102 pthread_cond_signal(&(x_cond)); \
104 #define TIMEOUT_SEC 5
107 #define SIGNAL_ROUTING_FOR_VOICE_CALL "routing_voice_call"
109 /* Devices : Normal */
110 #define AUDIO_DEVICE_OUT 0x00000000
111 #define AUDIO_DEVICE_IN 0x80000000
112 enum audio_device_type {
113 AUDIO_DEVICE_NONE = 0,
116 AUDIO_DEVICE_OUT_SPEAKER = AUDIO_DEVICE_OUT | 0x00000001,
117 AUDIO_DEVICE_OUT_RECEIVER = AUDIO_DEVICE_OUT | 0x00000002,
118 AUDIO_DEVICE_OUT_JACK = AUDIO_DEVICE_OUT | 0x00000004,
119 AUDIO_DEVICE_OUT_BT_SCO = AUDIO_DEVICE_OUT | 0x00000008,
120 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_SPEAKER |
121 AUDIO_DEVICE_OUT_RECEIVER |
122 AUDIO_DEVICE_OUT_JACK |
123 AUDIO_DEVICE_OUT_BT_SCO),
125 AUDIO_DEVICE_IN_MAIN_MIC = AUDIO_DEVICE_IN | 0x00000001,
126 AUDIO_DEVICE_IN_SUB_MIC = AUDIO_DEVICE_IN | 0x00000002,
127 AUDIO_DEVICE_IN_JACK = AUDIO_DEVICE_IN | 0x00000004,
128 AUDIO_DEVICE_IN_BT_SCO = AUDIO_DEVICE_IN | 0x00000008,
129 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_MAIN_MIC |
130 AUDIO_DEVICE_IN_SUB_MIC |
131 AUDIO_DEVICE_IN_JACK |
132 AUDIO_DEVICE_IN_BT_SCO),
135 typedef struct device_type {
141 #define AUDIO_USE_CASE_VERB_INACTIVE "Inactive"
142 #define AUDIO_USE_CASE_VERB_HIFI "HiFi"
143 #define AUDIO_USE_CASE_VERB_VOICECALL "Voice"
144 #define AUDIO_USE_CASE_VERB_VIDEOCALL "Video"
145 #define AUDIO_USE_CASE_VERB_VOIP "VoIP"
146 #define AUDIO_USE_CASE_VERB_FMRADIO "DigitalFM"
149 #define AUDIO_USE_CASE_MODIFIER_VOICESEARCH "VoiceSearch"
150 #define AUDIO_USE_CASE_MODIFIER_CAMCORDING "Camcording"
151 #define AUDIO_USE_CASE_MODIFIER_RINGTONE "Ringtone"
153 #define streq !strcmp
154 #define strneq strcmp
156 #define ALSA_DEFAULT_CARD "sprdphone"
157 #define VOICE_PCM_DEVICE "hw:sprdphone,1"
159 #define MAX_DEVICES 5
160 #define MAX_MODIFIERS 5
161 #define MAX_NAME_LEN 32
163 /* type definitions */
164 typedef signed char int8_t;
168 snd_pcm_format_t format;
171 } audio_pcm_sample_spec_s;
174 typedef enum audio_route_mode {
180 } audio_route_mode_e;
182 typedef struct audio_hal_device {
187 snd_pcm_t *fmradio_pcm_out;
188 pthread_mutex_t pcm_lock;
190 device_info_s *init_call_devices;
191 uint32_t num_of_call_devices;
192 audio_route_mode_e mode;
193 uint32_t is_radio_on;
194 pthread_cond_t device_cond;
195 pthread_mutex_t device_lock;
196 } audio_hal_device_s;
199 #define AUDIO_VOLUME_LEVEL_MAX 16
200 #define RADIO_VOLUME_LEVEL_MAX 100
202 typedef enum audio_volume {
203 AUDIO_VOLUME_TYPE_SYSTEM, /**< System volume type */
204 AUDIO_VOLUME_TYPE_NOTIFICATION, /**< Notification volume type */
205 AUDIO_VOLUME_TYPE_ALARM, /**< Alarm volume type */
206 AUDIO_VOLUME_TYPE_RINGTONE, /**< Ringtone volume type */
207 AUDIO_VOLUME_TYPE_MEDIA, /**< Media volume type */
208 AUDIO_VOLUME_TYPE_CALL, /**< Call volume type */
209 AUDIO_VOLUME_TYPE_VOIP, /**< VOIP volume type */
210 AUDIO_VOLUME_TYPE_VOICE, /**< Voice volume type */
211 AUDIO_VOLUME_TYPE_MAX, /**< Volume type count */
214 typedef enum audio_gain {
215 AUDIO_GAIN_TYPE_DEFAULT,
216 AUDIO_GAIN_TYPE_DIALER,
217 AUDIO_GAIN_TYPE_TOUCH,
219 AUDIO_GAIN_TYPE_SHUTTER1,
220 AUDIO_GAIN_TYPE_SHUTTER2,
221 AUDIO_GAIN_TYPE_CAMCODING,
222 AUDIO_GAIN_TYPE_MIDI,
223 AUDIO_GAIN_TYPE_BOOTING,
224 AUDIO_GAIN_TYPE_VIDEO,
229 typedef struct audio_volume_value_table {
230 double volume[AUDIO_VOLUME_TYPE_MAX][AUDIO_VOLUME_LEVEL_MAX];
231 double gain[AUDIO_GAIN_TYPE_MAX];
232 } audio_volume_value_table_s;
235 AUDIO_VOLUME_DEVICE_DEFAULT,
236 AUDIO_VOLUME_DEVICE_MAX,
239 typedef struct audio_hal_volume {
240 uint32_t volume_level_max[AUDIO_VOLUME_LEVEL_MAX];
241 uint32_t volume_level[AUDIO_VOLUME_TYPE_MAX];
242 audio_volume_value_table_s *volume_value_table;
243 int32_t radio_volume_value_table[RADIO_VOLUME_LEVEL_MAX];
244 int32_t radio_volume_num_of_levels;
245 } audio_hal_volume_s;
248 typedef struct audio_hal_ucm {
249 snd_use_case_mgr_t* uc_mgr;
253 typedef struct audio_hal_mixer {
255 pthread_mutex_t mutex;
257 snd_ctl_elem_value_t *value;
258 snd_ctl_elem_id_t *id;
259 snd_ctl_elem_info_t *info;
264 typedef enum audio_sample_format {
270 AUDIO_SAMPLE_FLOAT32LE,
271 AUDIO_SAMPLE_FLOAT32BE,
276 AUDIO_SAMPLE_S24_32LE,
277 AUDIO_SAMPLE_S24_32BE,
279 AUDIO_SAMPLE_INVALID = -1
280 } audio_sample_format_s;
283 typedef struct audio_hal_modem {
285 pthread_t voice_thread_handle;
286 pthread_t voip_thread_handle;
287 snd_pcm_t *voice_pcm_handle_p;
288 snd_pcm_t *voice_pcm_handle_c;
292 unsigned short vbpipe_count;
307 typedef struct audio_hal_comm {
313 typedef struct audio_hal {
314 audio_hal_device_s device;
315 audio_hal_volume_s volume;
317 audio_hal_mixer_s mixer;
318 audio_hal_modem_t modem;
319 audio_hal_comm_s comm;
322 audio_return_e _audio_ctrl_init(audio_hal_s *ah);
323 audio_return_e _audio_ctrl_deinit(audio_hal_s *ah);
324 audio_return_e _audio_volume_init(audio_hal_s *ah);
325 audio_return_e _audio_volume_deinit(audio_hal_s *ah);
326 audio_return_e _audio_routing_init(audio_hal_s *ah);
327 audio_return_e _audio_routing_deinit(audio_hal_s *ah);
328 audio_return_e _audio_stream_init(audio_hal_s *ah);
329 audio_return_e _audio_stream_deinit(audio_hal_s *ah);
330 audio_return_e _audio_pcm_init(audio_hal_s *ah);
331 audio_return_e _audio_pcm_deinit(audio_hal_s *ah);
332 audio_return_e _audio_modem_init(audio_hal_s *ah);
333 audio_return_e _audio_modem_deinit(audio_hal_s *ah);
334 audio_return_e _audio_comm_init(audio_hal_s *ah);
335 audio_return_e _audio_comm_deinit(audio_hal_s *ah);
337 audio_return_e _audio_update_route_voicecall(audio_hal_s *ah, device_info_s *devices, int32_t num_of_devices);
338 int _audio_modem_is_call_connected(audio_hal_s *ah);
339 audio_return_e _audio_comm_send_message(audio_hal_s *ah, const char *name, int value);
341 typedef struct _dump_data {
347 dump_data_t* _audio_dump_new(int length);
348 void _audio_dump_add_str(dump_data_t *dump, const char *fmt, ...);
349 char* _audio_dump_get_str(dump_data_t *dump);
350 void _audio_dump_free(dump_data_t *dump);