4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #if !defined(_MMFW_I386_ALL_SIMULATOR)
23 #include <alsa/ascenario.h>
27 #include "avsys-audio-ascenario.h"
28 #include "avsys-types.h"
29 #include "avsys-error.h"
30 #include "avsys-debug.h"
31 #if defined(TIME_CHECK)
36 #define STR_BUFF_MAX 128
39 static int __avsys_audio_ascn_make_scenario_str(int input, char *buf, int buf_len)
41 char fromStr[P_STR_MAX] = { 0, };
42 char toStr[P_STR_MAX] = { 0, };
43 char optStr[O_STR_MAX] = { 0, };
46 avsys_error(AVAUDIO, "Input Buf is null\n");
47 return AVSYS_STATE_ERR_NULL_POINTER;
50 if (input & INPUT_MAIN_MIC) {
51 strncpy(fromStr, "mainmic", sizeof(fromStr) - 1);
53 if (input & INPUT_SUB_MIC) {
54 strncpy(fromStr, "submic", sizeof(fromStr) - 1);
56 if (input & INPUT_STEREO_MIC) {
57 strncpy(fromStr, "stereomic", sizeof(fromStr) - 1);
59 if (input & INPUT_EAR_MIC) {
60 strncpy(fromStr, "earmic", sizeof(fromStr) - 1);
62 if (input & INPUT_BT_MIC) {
63 strncpy(fromStr, "bt", sizeof(fromStr) - 1);
65 if (input & INPUT_AP) {
66 strncpy(fromStr, "ap", sizeof(fromStr) - 1);
68 if (input & INPUT_CP) {
69 strncpy(fromStr, "cp", sizeof(fromStr) - 1);
71 if (input & INPUT_FMRADIO) {
72 strncpy(fromStr, "fmradio", sizeof(fromStr) - 1);
75 if (input & OUTPUT_HEADSET) {
76 strncpy(toStr, "headset", sizeof(toStr) - 1);
78 if (input & OUTPUT_LEFT_SPK) {
79 strncpy(toStr, "speaker_left", sizeof(toStr) - 1);
81 if (input & OUTPUT_RIGHT_SPK) {
82 strncpy(toStr, "speaker_right", sizeof(toStr) - 1);
84 if (input & OUTPUT_STEREO_SPK) {
85 strncpy(toStr, "speaker", sizeof(toStr) - 1);
87 if (input & OUTPUT_RECV) {
88 strncpy(toStr, "receiver", sizeof(toStr) - 1);
90 if (input & OUTPUT_BT_HEADSET) {
91 strncpy(toStr, "bt", sizeof(toStr) - 1);
93 if (input & OUTPUT_CP) {
94 strncpy(toStr, "cp", sizeof(toStr) - 1);
96 if (input & OUTPUT_AP) {
97 strncpy(toStr, "ap", sizeof(toStr) - 1);
100 if (input & GAIN_MODE) {
101 strncpy(optStr, "_gain", sizeof(optStr) - 1);
103 if (input & GAIN_VIDEO_CALL) {
104 strncpy(optStr, "_videocall_gain", sizeof(optStr) - 1);
106 if (input & GAIN_VOICE_CALL) {
107 strncpy(optStr, "_voicecall_gain", sizeof(optStr) - 1);
109 if (input & GAIN_CALLALERT) {
110 strncpy(optStr, "_ringtone_gain", sizeof(optStr) - 1);
113 snprintf(buf, buf_len - 1, "%s_to_%s%s", fromStr, toStr, optStr);
114 //avsys_info(AVAUDIO, "rslt str : %s\n", buf);
115 return AVSYS_STATE_SUCCESS;
118 int avsys_audio_ascn_bulk_set(int * bulk, int bulk_cnt, AscnResetType clear)
120 struct snd_scenario *scn = NULL;
121 char card_name[STR_BUFF_MAX] = { 0, };
122 char str_buf[STR_BUFF_MAX] = { 0, };
123 char reset_str[STR_BUFF_MAX] = { 0, };
124 int err = AVSYS_STATE_SUCCESS;
126 #if defined(TIME_CHECK)
127 struct timeval t_start, t_stop;
128 unsigned long check = 0;
131 avsys_info(AVAUDIO, "<< %s, clear = %d\n", __func__, clear);
133 if (clear < ASCN_RESET_NONE || clear > ASCN_RESET_MODEM) {
134 avsys_error_r(AVAUDIO, "invalid clear type %d\n", clear);
135 return AVSYS_STATE_ERR_RANGE_OVER;
139 avsys_error_r(AVAUDIO, "input bulk is null\n");
140 return AVSYS_STATE_ERR_NULL_POINTER;
143 avsys_error_r(AVAUDIO, "bulk_cnt is negative\n");
144 return AVSYS_STATE_ERR_RANGE_OVER;
147 snprintf(card_name, sizeof(card_name) - 1, "default");
148 #if defined(TIME_CHECK)
149 gettimeofday(&t_start, NULL);
151 //avsys_info(AVAUDIO, "snd_scenario_open() with [%s]\n", card_name);
152 scn = snd_scenario_open(card_name);
153 #if defined(TIME_CHECK)
154 gettimeofday(&t_stop, NULL);
155 if (t_stop.tv_sec == t_start.tv_sec)
156 check = (t_stop.tv_usec - t_start.tv_usec) / 1000;
158 check = (t_stop.tv_sec - t_start.tv_sec) * 1000 + (t_stop.tv_usec - t_start.tv_usec) / 1000;
159 avsys_warning(AVAUDIO, "[snd_scenario_open()] takes %u msec\n", check);
162 avsys_error_r(AVAUDIO, "alsa scenario open failed %s\n", card_name);
163 return AVSYS_STATE_ERR_INTERNAL;
165 //avsys_info(AVAUDIO, "snd_scenario_open() success\n");
167 if (clear != ASCN_RESET_NONE) {
170 snprintf(reset_str, sizeof(reset_str) - 1, "%s", ASCN_STR_RESET);
172 case ASCN_RESET_PLAYBACK:
173 snprintf(reset_str, sizeof(reset_str) - 1, "%s", ASCN_STR_RESET_PLAYBACK);
175 case ASCN_RESET_CAPTURE:
176 snprintf(reset_str, sizeof(reset_str) - 1, "%s", ASCN_STR_RESET_CAPTURE);
179 #if defined(TIME_CHECK)
180 gettimeofday(&t_start, NULL);
182 err = snd_scenario_set_scn(scn, reset_str);
183 #if defined(TIME_CHECK)
184 gettimeofday(&t_stop, NULL);
185 if (t_stop.tv_sec == t_start.tv_sec)
186 check = (t_stop.tv_usec - t_start.tv_usec) / 1000;
188 check = (t_stop.tv_sec - t_start.tv_sec) * 1000 + (t_stop.tv_usec - t_start.tv_usec) / 1000;
189 avsys_warning(AVAUDIO, "[%s] takes %u msec\n", reset_str, check);
192 avsys_error(AVAUDIO, "Alsa sceanrio [%s] failed\n", reset_str);
194 avsys_warning(AVAUDIO, "Set [%s] success\n", reset_str);
198 for (i = 0; i < bulk_cnt; i++) {
201 memset(str_buf, '\0', sizeof(str_buf));
202 //avsys_info(AVAUDIO, "make string for 0x%X\n", bulk[i]);
203 __avsys_audio_ascn_make_scenario_str(bulk[i], str_buf, sizeof(str_buf));
204 //avsys_info(AVAUDIO, "result string [%s]\n", str_buf);
205 #if defined(TIME_CHECK)
206 gettimeofday(&t_start, NULL);
208 err = snd_scenario_set_scn(scn, str_buf);
209 #if defined(TIME_CHECK)
210 gettimeofday(&t_stop, NULL);
211 if (t_stop.tv_sec == t_start.tv_sec)
212 check = (t_stop.tv_usec - t_start.tv_usec) / 1000;
214 check = (t_stop.tv_sec - t_start.tv_sec) * 1000 + (t_stop.tv_usec - t_start.tv_usec) / 1000;
215 avsys_warning(AVAUDIO, "[%s] takes %u msec\n", str_buf, check);
218 avsys_error_r(AVAUDIO, "snd_scenario_set_scn(%s) failed with %d\n", str_buf, err);
221 avsys_warning(AVAUDIO, "* [0x%010X] Set [%s] success\n", bulk[i], str_buf);
225 #if defined(TIME_CHECK)
226 gettimeofday(&t_start, NULL);
228 snd_scenario_close(scn);
229 #if defined(TIME_CHECK)
230 gettimeofday(&t_stop, NULL);
231 if (t_stop.tv_sec == t_start.tv_sec)
232 check = (t_stop.tv_usec - t_start.tv_usec) / 1000;
234 check = (t_stop.tv_sec - t_start.tv_sec) * 1000 + (t_stop.tv_usec - t_start.tv_usec) / 1000;
235 avsys_warning(AVAUDIO, "[snd_scenario_close()] takes %u msec\n", check);
241 int avsys_audio_ascn_single_set(char * str)
243 struct snd_scenario *scn = NULL;
244 char card_name[STR_BUFF_MAX] = { 0, };
245 char cmd_str[STR_BUFF_MAX] = { 0, };
246 int err = AVSYS_STATE_SUCCESS;
249 avsys_error_r(AVAUDIO, "input str is null\n");
250 return AVSYS_STATE_ERR_NULL_POINTER;
253 snprintf(card_name, sizeof(card_name) - 1, "default");
254 // avsys_info(AVAUDIO, "snd_scenario_open() with [%s]\n", card_name);
255 scn = snd_scenario_open(card_name);
257 avsys_error_r(AVAUDIO, "alsa scenario open failed %s\n", card_name);
258 return AVSYS_STATE_ERR_INTERNAL;
260 // avsys_info(AVAUDIO, "snd_scenario_open() success\n");
262 strncpy(cmd_str, str, sizeof(cmd_str) - 1);
263 err = snd_scenario_set_scn(scn, str);
264 avsys_warning(AVAUDIO, "alsa scenario set [%s]\n", str);
267 avsys_error_r(AVAUDIO, "snd_scenario_set(%s) failed\n", str);
270 snd_scenario_close(scn);