From 785814c493c819a9f94a083a69ad42a63f221386 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 01:48:53 +0900 Subject: [PATCH] Tizen 2.1 base --- AUTHORS | 2 + LICENSE.APLv2 | 206 ++++++ Makefile.am | 4 +- NOTICE | 3 + audiotest/avsys-audio-test.c | 8 +- audiotest/avsys-audio-volume-dump.c | 2 +- avsys-audio-alsa.c | 80 ++- avsys-audio-ascenario.c | 100 ++- avsys-audio-handle.c | 106 ++-- avsys-audio-logical-volume.c | 452 ++++++++------ avsys-audio-pasimple.c | 104 +++- avsys-audio-path.c | 1144 +++++++++++++++------------------- avsys-audio-shm.c | 2 +- avsys-audio-sync.c | 2 - avsys-audio.c | 207 ++++-- avsystem.manifest | 11 + configure.ac | 4 + include/avsys-audio-alsa.h | 26 +- include/avsys-audio-ascenario.h | 6 +- include/avsys-audio-handle.h | 4 +- include/avsys-audio-logical-volume.h | 62 +- include/avsys-audio-pasimple.h | 3 + include/avsys-audio-path.h | 92 +-- include/avsys-audio-sync.h | 2 - include/avsys-audio.h | 72 ++- include/avsys-debug.h | 22 +- packaging/avsystem.service | 11 + packaging/avsystem.spec | 77 ++- 28 files changed, 1616 insertions(+), 1198 deletions(-) create mode 100644 AUTHORS create mode 100644 LICENSE.APLv2 create mode 100644 NOTICE create mode 100755 avsystem.manifest create mode 100644 packaging/avsystem.service diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..349b012 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Seungbae Shin +Hyunseok Lee diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..f94008a --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,206 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/Makefile.am b/Makefile.am index 1fba2b0..b41e175 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,8 +49,8 @@ libavsysaudio_la_CFLAGS += $(MMLOG_CFLAGS) \ -D__USE_LOGMANAGER__ \ -DMM_DEBUG_FLAG -libavsysaudio_la_LIBADD += $(MMLOG_LIBS) - +libavsysaudio_la_LIBADD += $(MMLOG_LIBS) \ + $(INIPARSER_LIBS) bin_PROGRAMS = sound_initializer sound_initializer_SOURCES = avsys-audio-initializer.c diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..ccdad52 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE file for Apache License terms and conditions. diff --git a/audiotest/avsys-audio-test.c b/audiotest/avsys-audio-test.c index c6a53d5..be17305 100644 --- a/audiotest/avsys-audio-test.c +++ b/audiotest/avsys-audio-test.c @@ -76,7 +76,7 @@ int __make_param(int op, int mode, int routing, avsys_audio_param_t *param) param->priority = AVSYS_AUDIO_PRIORITY_NORMAL; param->vol_type = AVSYS_AUDIO_VOLUME_TYPE_SYSTEM; - param->bluetooth = routing; + param->handle_route = routing; switch (mode) { case 0: @@ -118,7 +118,7 @@ int _playback(int mode, int routing, char *filename) if (!filename) return -1; - memset(¶m, sizeof(avsys_audio_param_t), '\0'); + memset(¶m, '\0', sizeof(avsys_audio_param_t)); if (__make_param(OP_PLAYBACK, mode, routing, ¶m)) { printf("Can not make audio parameter\n"); @@ -177,7 +177,7 @@ int _capture(int mode, int routing, char *filename) printf("[%s] real filename :%s\n", __func__, namebuffer); - memset(¶m, sizeof(avsys_audio_param_t), '\0'); + memset(¶m, '\0', sizeof(avsys_audio_param_t)); if (__make_param(OP_CAPTURE, mode, routing, ¶m)) { printf("Can not make audio parameter\n"); @@ -196,7 +196,7 @@ int _capture(int mode, int routing, char *filename) goto FAIL; } - fd = open(namebuffer, O_WRONLY | O_CREAT); + fd = open(namebuffer, O_WRONLY | O_CREAT, 0644); if (fd == -1) { printf("Can not open file %s, %s\n", namebuffer, strerror(errno)); goto FAIL; diff --git a/audiotest/avsys-audio-volume-dump.c b/audiotest/avsys-audio-volume-dump.c index 76a97a5..793f77f 100644 --- a/audiotest/avsys-audio-volume-dump.c +++ b/audiotest/avsys-audio-volume-dump.c @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) } else if(argc == 1) { - strncpy(filepath, VOLUME_FILE_PATH, sizeof(filepath)-1); + strncpy(filepath, AVSYS_VOLUME_INI_TEMP_PATH, sizeof(filepath)-1); fprintf(stderr,"Use default file path %s\n", filepath); } diff --git a/avsys-audio-alsa.c b/avsys-audio-alsa.c index 7e7916a..4b8072e 100644 --- a/avsys-audio-alsa.c +++ b/avsys-audio-alsa.c @@ -27,14 +27,16 @@ #include "avsys-debug.h" #if defined(_MMFW_I386_ALL_SIMULATOR) -#define AIF2_DEVICE_NAME "default" -#define AIF3_DEVICE_NAME "default" +#define AIF_CP_DEVICE_NAME "default" +#define AIF_BT_DEVICE_NAME "default" +#define AIF_RADIO_DEVICE_NAME "default" #else -#define AIF2_DEVICE_NAME "AIF2" -#define AIF3_DEVICE_NAME "AIF3" +#define AIF_CP_DEVICE_NAME "AIF2" +#define AIF_BT_DEVICE_NAME "AIF3" +#define AIF_RADIO_DEVICE_NAME "AIF4" #endif -int avsys_audio_alsa_open_AIF_device(const int AIF_type, avsys_audio_alsa_aif_handle_t *handle) +int avsys_audio_alsa_open_AIF_device(aif_device_type_t aif_type, avsys_audio_alsa_aif_handle_t *handle) { snd_pcm_t *ahandle = NULL; int err = -1; @@ -46,25 +48,29 @@ int avsys_audio_alsa_open_AIF_device(const int AIF_type, avsys_audio_alsa_aif_ha return AVSYS_STATE_ERR_NULL_POINTER; memset(dev_name, '\0', sizeof(dev_name)); - switch (AIF_type) { - case AIF2_CAPTURE: - strncpy(dev_name, AIF2_DEVICE_NAME, sizeof(dev_name) - 1); + switch (aif_type) { + case AIF_CP_CAPTURE: + strncpy(dev_name, AIF_CP_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_CAPTURE; break; - case AIF2_PLAYBACK: - strncpy(dev_name, AIF2_DEVICE_NAME, sizeof(dev_name) - 1); + case AIF_CP_PLAYBACK: + strncpy(dev_name, AIF_CP_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_PLAYBACK; break; - case AIF3_CAPTURE: - strncpy(dev_name, AIF3_DEVICE_NAME, sizeof(dev_name) - 1); + case AIF_BT_CAPTURE: + strncpy(dev_name, AIF_BT_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_CAPTURE; break; - case AIF3_PLAYBACK: - strncpy(dev_name, AIF3_DEVICE_NAME, sizeof(dev_name) - 1); + case AIF_BT_PLAYBACK: + strncpy(dev_name, AIF_BT_DEVICE_NAME, sizeof(dev_name) - 1); + stream = SND_PCM_STREAM_PLAYBACK; + break; + case AIF_RADIO_PLAYBACK: + strncpy(dev_name, AIF_RADIO_DEVICE_NAME, sizeof(dev_name) - 1); stream = SND_PCM_STREAM_PLAYBACK; break; default: - avsys_critical_r(AVAUDIO, "Invalid AIF device %d\n", AIF_type); + avsys_critical_r(AVAUDIO, "Invalid AIF device %d\n", aif_type); return AVSYS_STATE_ERR_INVALID_MODE; break; } @@ -81,7 +87,7 @@ int avsys_audio_alsa_open_AIF_device(const int AIF_type, avsys_audio_alsa_aif_ha } handle->alsa_handle = (void *)ahandle; - handle->type = AIF_type; + handle->type = aif_type; return AVSYS_STATE_SUCCESS; } @@ -116,7 +122,7 @@ int avsys_audio_alsa_close_AIF_device(avsys_audio_alsa_aif_handle_t* handle) return AVSYS_STATE_SUCCESS; } -int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) +int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle, aif_rate_t rate) { #if defined(_MMFW_I386_ALL_SIMULATOR) return AVSYS_STATE_SUCCESS; @@ -124,8 +130,8 @@ int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) int err = 0; snd_pcm_t *ahandle = NULL; snd_pcm_hw_params_t *params; - unsigned int val; - int dir; + unsigned int val = 0; + int dir = 0; avsys_info(AVAUDIO, "%s\n", __func__); if (!handle) @@ -135,14 +141,39 @@ int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) if (!ahandle) return AVSYS_STATE_ERR_NULL_POINTER; + /* Skip parameter setting to null device. */ + if (snd_pcm_type(ahandle) == SND_PCM_TYPE_NULL) + return AVSYS_STATE_SUCCESS; + /* Allocate a hardware parameters object. */ snd_pcm_hw_params_alloca(¶ms); /* Fill it in with default values. */ - snd_pcm_hw_params_any(ahandle, params); + err = snd_pcm_hw_params_any(ahandle, params); + if (err < 0) { + avsys_error_r(AVAUDIO, "snd_pcm_hw_params_any() : failed! - %s\n", snd_strerror(err)); + return AVSYS_STATE_ERR_INTERNAL; + } /* Set the desired hardware parameters. */ /* Interleaved mode */ - snd_pcm_hw_params_set_access(ahandle, params, SND_PCM_ACCESS_RW_INTERLEAVED); + err = snd_pcm_hw_params_set_access(ahandle, params, SND_PCM_ACCESS_RW_INTERLEAVED); + if (err < 0) { + avsys_error_r(AVAUDIO, "snd_pcm_hw_params_set_access() : failed! - %s\n", snd_strerror(err)); + return AVSYS_STATE_ERR_INTERNAL; + } + + if (rate == AIF_CONF_RATE) { + /* Auto rate by conf */ + avsys_info(AVAUDIO, "Let rate by configuration\n"); + } else { + /* Force input rate */ + avsys_info(AVAUDIO, "Force rate (%d)\n", rate); + err = snd_pcm_hw_params_set_rate(ahandle, params, rate, 0); + if (err < 0) { + avsys_error_r(AVAUDIO, "snd_pcm_hw_params_set_rate() : failed! - %s\n", snd_strerror(err)); + return AVSYS_STATE_ERR_INTERNAL; + } + } err = snd_pcm_hw_params(ahandle, params); if (err < 0) { @@ -168,8 +199,11 @@ int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle) avsys_info(AVAUDIO, "channels = %d\n", val); snd_pcm_hw_params_get_rate(params, &val, &dir); - avsys_info(AVAUDIO, "rate = %d bps\n", val); + avsys_info(AVAUDIO, "rate = %d(%d) Hz\n", val, dir); + + /* Save current rate for later check */ + handle->rate = val; return AVSYS_STATE_SUCCESS; -#endif +#endif /* _MMFW_I386_ALL_SIMULATOR */ } diff --git a/avsys-audio-ascenario.c b/avsys-audio-ascenario.c index c78f155..0b9f1ac 100644 --- a/avsys-audio-ascenario.c +++ b/avsys-audio-ascenario.c @@ -36,6 +36,8 @@ #define STR_BUFF_MAX 128 #define P_STR_MAX 42 #define O_STR_MAX 44 +#define CARD_NUMBER 0 /* ALSA card number */ + static int __avsys_audio_ascn_make_scenario_str(int input, char *buf, int buf_len) { char fromStr[P_STR_MAX] = { 0, }; @@ -96,7 +98,12 @@ static int __avsys_audio_ascn_make_scenario_str(int input, char *buf, int buf_le if (input & OUTPUT_AP) { strncpy(toStr, "ap", sizeof(toStr) - 1); } - + if (input & OUTPUT_HDMI) { + strncpy(toStr, "hdmi", sizeof(toStr) - 1); + } + if (input & OUTPUT_DOCK) { + strncpy(toStr, "dock", sizeof(toStr) - 1); + } if (input & GAIN_MODE) { strncpy(optStr, "_gain", sizeof(optStr) - 1); } @@ -118,7 +125,8 @@ static int __avsys_audio_ascn_make_scenario_str(int input, char *buf, int buf_le int avsys_audio_ascn_bulk_set(int * bulk, int bulk_cnt, AscnResetType clear) { struct snd_scenario *scn = NULL; - char card_name[STR_BUFF_MAX] = { 0, }; + int card = CARD_NUMBER; + char *name = NULL; char str_buf[STR_BUFF_MAX] = { 0, }; char reset_str[STR_BUFF_MAX] = { 0, }; int err = AVSYS_STATE_SUCCESS; @@ -144,12 +152,31 @@ int avsys_audio_ascn_bulk_set(int * bulk, int bulk_cnt, AscnResetType clear) return AVSYS_STATE_ERR_RANGE_OVER; } - snprintf(card_name, sizeof(card_name) - 1, "default"); + /* Try to get card name from CARD_NUMBER. */ + snd_card_get_name(card, &name); #if defined(TIME_CHECK) gettimeofday(&t_start, NULL); #endif - //avsys_info(AVAUDIO, "snd_scenario_open() with [%s]\n", card_name); - scn = snd_scenario_open(card_name); + if (name == NULL) { + scn = snd_scenario_open("default"); + if (scn == NULL) + { + avsys_error(AVAUDIO, "snd_scenario_open() failed to open with default\n"); + return AVSYS_STATE_ERR_INTERNAL; + } + } else { + scn = snd_scenario_open(name); + free(name); + if (scn == NULL) + { + scn = snd_scenario_open("default"); + if (scn == NULL) + { + avsys_error(AVAUDIO, "snd_scenario_open() failed to open with default\n"); + return AVSYS_STATE_ERR_INTERNAL; + } + } + } #if defined(TIME_CHECK) gettimeofday(&t_stop, NULL); if (t_stop.tv_sec == t_start.tv_sec) @@ -158,12 +185,6 @@ int avsys_audio_ascn_bulk_set(int * bulk, int bulk_cnt, AscnResetType clear) check = (t_stop.tv_sec - t_start.tv_sec) * 1000 + (t_stop.tv_usec - t_start.tv_usec) / 1000; avsys_warning(AVAUDIO, "[snd_scenario_open()] takes %u msec\n", check); #endif - if (scn == NULL) { - avsys_error_r(AVAUDIO, "alsa scenario open failed %s\n", card_name); - return AVSYS_STATE_ERR_INTERNAL; - } - //avsys_info(AVAUDIO, "snd_scenario_open() success\n"); - if (clear != ASCN_RESET_NONE) { switch (clear) { case ASCN_RESET_ALL: @@ -241,33 +262,68 @@ bulk_error: int avsys_audio_ascn_single_set(char * str) { struct snd_scenario *scn = NULL; - char card_name[STR_BUFF_MAX] = { 0, }; + int card = CARD_NUMBER; + char *name = NULL; char cmd_str[STR_BUFF_MAX] = { 0, }; int err = AVSYS_STATE_SUCCESS; +#if defined(TIME_CHECK) + struct timeval t_start, t_stop; + unsigned long check = 0; +#endif if (str == NULL) { avsys_error_r(AVAUDIO, "input str is null\n"); return AVSYS_STATE_ERR_NULL_POINTER; } - snprintf(card_name, sizeof(card_name) - 1, "default"); -// avsys_info(AVAUDIO, "snd_scenario_open() with [%s]\n", card_name); - scn = snd_scenario_open(card_name); - if (scn == NULL) { - avsys_error_r(AVAUDIO, "alsa scenario open failed %s\n", card_name); - return AVSYS_STATE_ERR_INTERNAL; - } -// avsys_info(AVAUDIO, "snd_scenario_open() success\n"); +#if defined(TIME_CHECK) + gettimeofday(&t_start, NULL); +#endif + + /* Try to get card name from CARD_NUMBER. */ + snd_card_get_name(card, &name); + if (name == NULL) { + scn = snd_scenario_open("default"); + if (scn == NULL) + { + avsys_error(AVAUDIO, "snd_scenario_open() failed to open with default\n"); + return AVSYS_STATE_ERR_INTERNAL; + } + } else { + scn = snd_scenario_open(name); + free(name); + if (scn == NULL) + { + scn = snd_scenario_open("default"); + if (scn == NULL) + { + avsys_error(AVAUDIO, "snd_scenario_open() failed to open with default\n"); + return AVSYS_STATE_ERR_INTERNAL; + } + } + } + + /* Set scenario */ strncpy(cmd_str, str, sizeof(cmd_str) - 1); err = snd_scenario_set_scn(scn, str); - avsys_warning(AVAUDIO, "alsa scenario set [%s]\n", str); + avsys_info(AVAUDIO, "alsa scenario set [%s]\n", str); if (err < 0) { - avsys_error_r(AVAUDIO, "snd_scenario_set(%s) failed\n", str); + avsys_error(AVAUDIO, "snd_scenario_set(%s) failed\n", str); } + /* Close scenario manager core */ snd_scenario_close(scn); +#if defined(TIME_CHECK) + gettimeofday(&t_stop, NULL); + if (t_stop.tv_sec == t_start.tv_sec) + check = (t_stop.tv_usec - t_start.tv_usec) / 1000; + else + check = (t_stop.tv_sec - t_start.tv_sec) * 1000 + (t_stop.tv_usec - t_start.tv_usec) / 1000; + avsys_warning(AVAUDIO, "[%s] takes %u msec\n", str, check); +#endif + return err; } diff --git a/avsys-audio-handle.c b/avsys-audio-handle.c index fbfa441..3cbe050 100644 --- a/avsys-audio-handle.c +++ b/avsys-audio-handle.c @@ -34,12 +34,13 @@ #include "avsys-audio-logical-volume.h" #include "avsys-audio-pactrl.h" -#define DEFAULT_VOLUME_SYSTEM 2 -#define DEFAULT_VOLUME_RINGTONE 6 -#define DEFAULT_VOLUME_MEDIA 11 -#define DEFAULT_VOLUME_NOTIFICATION 6 -#define DEFAULT_VOLUME_ALARM 6 -#define DEFAULT_VOLUME_CALL 6 +#define DEFAULT_VOLUME_SYSTEM 5 +#define DEFAULT_VOLUME_NOTIFICATION 7 +#define DEFAULT_VOLUME_ALARM 7 +#define DEFAULT_VOLUME_RINGTONE 13 +#define DEFAULT_VOLUME_MEDIA 7 +#define DEFAULT_VOLUME_CALL 7 +#define DEFAULT_VOLUME_VOIP 7 #define DEFAULT_VOLUME_FIXED 0 #define DEFAULT_VOLUME_JAVA 11 @@ -64,6 +65,18 @@ } \ } while (0) +static int g_default_volume[AVSYS_AUDIO_VOLUME_TYPE_MAX] = { + DEFAULT_VOLUME_SYSTEM, /* AVSYS_AUDIO_VOLUME_TYPE_SYSTEM */ + DEFAULT_VOLUME_NOTIFICATION, /* AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION */ + DEFAULT_VOLUME_ALARM, /* AVSYS_AUDIO_VOLUME_TYPE_ALARM */ + DEFAULT_VOLUME_RINGTONE, /* AVSYS_AUDIO_VOLUME_TYPE_RINGTONE */ + DEFAULT_VOLUME_MEDIA, /* AVSYS_AUDIO_VOLUME_TYPE_MEDIA */ + DEFAULT_VOLUME_CALL, /* AVSYS_AUDIO_VOLUME_TYPE_CALL */ + DEFAULT_VOLUME_VOIP, /* AVSYS_AUDIO_VOLUME_TYPE_VOIP */ + DEFAULT_VOLUME_FIXED, /* AVSYS_AUDIO_VOLUME_TYPE_FIXED */ + DEFAULT_VOLUME_JAVA, /* AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA */ +}; + EXPORT_API int avsys_audio_handle_init(void) { @@ -96,15 +109,7 @@ int avsys_audio_handle_init(void) /* init allocted bits */ control->allocated = 0; control->handle_amp = 0; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_0] = DEFAULT_VOLUME_SYSTEM; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_1] = DEFAULT_VOLUME_NOTIFICATION; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_2] = DEFAULT_VOLUME_ALARM; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_3] = DEFAULT_VOLUME_RINGTONE; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_4] = DEFAULT_VOLUME_MEDIA; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_5] = DEFAULT_VOLUME_CALL; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_6] = DEFAULT_VOLUME_FIXED; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_7] = DEFAULT_VOLUME_JAVA; - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_8] = DEFAULT_VOLUME_MEDIA; + memcpy(control->volume_value, (int *)g_default_volume, sizeof(int) * AVSYS_AUDIO_VOLUME_TYPE_MAX); control->ext_device_amp = AVSYS_AUDIO_HANDLE_EXT_DEV_NONE; control->primary_volume_pid = 0; control->primary_volume_type = -1; @@ -146,11 +151,7 @@ int avsys_audio_handle_reset(int *volume_value) long long int flag = 0x01; avsys_audio_handle_info_t *control = NULL; avsys_audio_handle_info_t **temp = NULL; - int *lvolume = NULL; - int default_volume[] = { DEFAULT_VOLUME_SYSTEM, DEFAULT_VOLUME_NOTIFICATION, - DEFAULT_VOLUME_ALARM, DEFAULT_VOLUME_RINGTONE, - DEFAULT_VOLUME_MEDIA, DEFAULT_VOLUME_CALL, - DEFAULT_VOLUME_FIXED, DEFAULT_VOLUME_JAVA}; + int * volumes; temp = &control; /* Check root user */ @@ -165,11 +166,7 @@ int avsys_audio_handle_reset(int *volume_value) return AVSYS_STATE_ERR_NULL_POINTER; } - if (volume_value == NULL) { - lvolume = default_volume; - } else { - lvolume = volume_value; - } + volumes = (volume_value) ? volume_value : (int *)g_default_volume; for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) { if (control->allocated & (flag << i)) { /* allocated condition */ @@ -182,6 +179,7 @@ int avsys_audio_handle_reset(int *volume_value) } } +#ifdef USE_HIBERNATION while (control->allocated) { if (++i > 5) break; @@ -189,21 +187,14 @@ int avsys_audio_handle_reset(int *volume_value) printf("(%d)Waiting...0.5 sec for resume from hibernation\n", i); usleep(500); } +#endif AVSYS_LOCK_SYNC(); if (volume_value == NULL) { control->allocated = 0; control->handle_amp = 0; } - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_0] = lvolume[0]; /* DEFAULT_VOLUME_SYSTEM */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_1] = lvolume[1]; /* DEFAULT_VOLUME_NOTIFICATION */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_2] = lvolume[2]; /* DEFAULT_VOLUME_ALARM */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_3] = lvolume[3]; /* DEFAULT_VOLUME_RINGTONE */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_4] = lvolume[4]; /* DEFAULT_VOLUME_MEDIA */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_5] = lvolume[5]; /* DEFAULT_VOLUME_CALL */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_6] = lvolume[6]; /* DEFAULT_VOLUME_FIXED */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_7] = lvolume[7]; /* DEFAULT_VOLUME_JAVA */ - control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_8] = lvolume[4]; /* DEFAULT_VOLUME_MEDIA */ + memcpy(control->volume_value, volumes, sizeof(int) * AVSYS_AUDIO_VOLUME_TYPE_MAX); control->ext_device_amp = AVSYS_AUDIO_HANDLE_EXT_DEV_NONE; control->primary_volume_pid = 0; control->primary_volume_type = -1; @@ -362,13 +353,14 @@ int avsys_audio_handle_dump(void) if(control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_CLOCK || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_VIDEO || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_AP_CALL) { + int vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(control->handles[i].gain_setting.volume_config); if (control->handles[i].dirty_volume) { - fprintf(stdout, " Dirty volume : %s\n", vol_str[control->handles[i].gain_setting.vol_type]); + fprintf(stdout, " Dirty volume : %s\n", vol_str[vol_conf_type]); } else { - fprintf(stdout, " Volume Type : %s\n", vol_str[control->handles[i].gain_setting.vol_type]); + fprintf(stdout, " Volume Type : %s\n", vol_str[vol_conf_type]); } fprintf(stdout, " Target device : %s\n", dev_str[control->handles[i].gain_setting.dev_type]); - fprintf(stdout, " Maximum Len : %2d\n", control->handles[i].gain_setting.max_len); + fprintf(stdout, " Maximum Level : %2d\n", control->handles[i].gain_setting.max_level); fprintf(stdout, " UI setted volume : L:%3d R:%3d\n", control->handles[i].setting_vol.level[0], control->handles[i].setting_vol.level[1]); fprintf(stdout, " Real working volume : L:%3d R:%3d\n", control->handles[i].working_vol.level[0], control->handles[i].working_vol.level[1]); } @@ -402,14 +394,14 @@ int avsys_audio_handle_dump(void) for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_MEDIA]; i++) fprintf(stdout, "+"); fprintf(stdout, "\n"); - fprintf(stdout, " Volume [MediaHL] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL]); - for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL]; i++) - fprintf(stdout, "+"); - fprintf(stdout, "\n"); fprintf(stdout, " Volume [Call] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_CALL]); for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_CALL]; i++) fprintf(stdout, "+"); fprintf(stdout, "\n"); + fprintf(stdout, " Volume [VOIP] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_VOIP]); + for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_VOIP]; i++) + fprintf(stdout, "+"); + fprintf(stdout, "\n"); fprintf(stdout, " Volume [Android] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID]); for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID]; i++) fprintf(stdout, "+"); @@ -799,11 +791,12 @@ int avsys_audio_handle_current_playing_volume_type(int *type) long long int flag = 0x01; flag <<= i; if (control->allocated & flag) { + int vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(control->handles[i].gain_setting.volume_config); if(control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_CLOCK || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_VIDEO || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY ) { - used_table[control->handles[i].gain_setting.vol_type] = 1; + used_table[vol_conf_type] = 1; } else if(control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT || control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT_HIGH_LATENCY || @@ -816,11 +809,11 @@ int avsys_audio_handle_current_playing_volume_type(int *type) used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA] = 1; } - avsys_warning(AVAUDIO,"Call[%d] Ringtone[%d] Media[%d] MediaHL[%d] Alarm[%d] Notification[%d] System[%d] Android[%d] Java[%d] Capture[%d]\n", + avsys_warning(AVAUDIO,"Call[%d] VOIP[%d] Ringtone[%d] Media[%d] Alarm[%d] Notification[%d] System[%d] Android[%d] Java[%d] Capture[%d]\n", used_table[AVSYS_AUDIO_VOLUME_TYPE_CALL], + used_table[AVSYS_AUDIO_VOLUME_TYPE_VOIP], used_table[AVSYS_AUDIO_VOLUME_TYPE_RINGTONE], used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA], - used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL], used_table[AVSYS_AUDIO_VOLUME_TYPE_ALARM], used_table[AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION], used_table[AVSYS_AUDIO_VOLUME_TYPE_SYSTEM], @@ -830,7 +823,7 @@ int avsys_audio_handle_current_playing_volume_type(int *type) if (control->primary_volume_pid > 2 && AVSYS_FAIL(avsys_check_process(control->primary_volume_pid))) { avsys_warning(AVAUDIO, "Primary volume set pid does not exist anymore. clean primary volume\n"); - control->primary_volume_type = 1; + control->primary_volume_type = -1; control->primary_volume_pid = 0; } @@ -839,12 +832,12 @@ int avsys_audio_handle_current_playing_volume_type(int *type) avsys_warning(AVAUDIO, "Primary volume is %d\n", control->primary_volume_type); } else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_CALL]) { *type = AVSYS_AUDIO_VOLUME_TYPE_CALL; + } else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_VOIP]) { + *type = AVSYS_AUDIO_VOLUME_TYPE_VOIP; } else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_RINGTONE]) { *type = AVSYS_AUDIO_VOLUME_TYPE_RINGTONE; } else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA]) { *type = AVSYS_AUDIO_VOLUME_TYPE_MEDIA; - } else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL]) { - *type = AVSYS_AUDIO_VOLUME_TYPE_MEDIA; } else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_ALARM]) { *type = AVSYS_AUDIO_VOLUME_TYPE_ALARM; } else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION]) { @@ -869,23 +862,22 @@ int avsys_audio_handle_current_playing_volume_type(int *type) } -int avsys_audio_handle_update_volume(avsys_audio_handle_t *p, const int vol_type) +int avsys_audio_handle_update_volume(avsys_audio_handle_t *p, const int volume_config) { int result = AVSYS_STATE_SUCCESS; avsys_audio_handle_info_t *control = NULL; avsys_audio_handle_info_t **temp = NULL; - temp = &control; - avsys_audio_volume_t *set_volume = NULL; - int volume_type = vol_type; + int vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(volume_config); + temp = &control; AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL); AVSYS_LOCK_SYNC(); set_volume = &(p->setting_vol); - set_volume->level[AVSYS_AUDIO_CHANNEL_LEFT] = control->volume_value[volume_type]; - set_volume->level[AVSYS_AUDIO_CHANNEL_RIGHT] = control->volume_value[volume_type]; + set_volume->level[AVSYS_AUDIO_CHANNEL_LEFT] = control->volume_value[vol_conf_type]; + set_volume->level[AVSYS_AUDIO_CHANNEL_RIGHT] = control->volume_value[vol_conf_type]; result = avsys_audio_logical_volume_convert(set_volume, &(p->working_vol), &(p->gain_setting)); AVSYS_UNLOCK_SYNC(); @@ -912,8 +904,9 @@ int avsys_audio_handle_update_volume_by_type(const int volume_type, const int vo int mode; avsys_audio_volume_t *set_volume = NULL; long long int flag = 0x01; - flag <<= i; + int vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(control->handles[i].gain_setting.volume_config); + flag <<= i; if ((control->allocated & flag) == 0) { continue; } @@ -924,7 +917,7 @@ int avsys_audio_handle_update_volume_by_type(const int volume_type, const int vo continue; } - if (control->handles[i].gain_setting.vol_type != volume_type) { + if (vol_conf_type != volume_type) { continue; } @@ -1000,13 +993,12 @@ int avsys_audio_handle_set_primary_volume_type(const int pid, const int type, co int avsys_audio_handle_update_priority(int handle, int priority, int handle_route, int cmd) { long long int flag = 0x01; - int path_mute = 0, i = 0; + int i = 0; char high_priority_exist = 0; char transition_effect = 0; int lpriority = AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0; avsys_audio_handle_info_t *control = NULL; avsys_audio_handle_info_t **temp = NULL; - int sink_info = 0; temp = &control; diff --git a/avsys-audio-logical-volume.c b/avsys-audio-logical-volume.c index c9bf544..bf4861e 100644 --- a/avsys-audio-logical-volume.c +++ b/avsys-audio-logical-volume.c @@ -22,209 +22,245 @@ #include #include #include +#include #include "avsys-audio-logical-volume.h" #include "avsys-audio-shm.h" #include "avsys-error.h" #include "avsys-debug.h" /* {TYPE, {MAXLEN, {MAXLEN, SPK{L,R}...}, {MAXLEN, RECV {L,R}...}, {MAXLEN, HEADSET{L,R}...}, {MAXLEN, BT{L,R}...}}} */ -static const avsys_logical_gain_t g_volume_table[AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX] = { - { AVSYS_AUDIO_LVOL_GAIN_TYPE_0, /* system : 0~15, default : 5 */ - { /* FNT DEFAULT */ +static const avsys_audio_lvol_volume_info_t g_volume_table[AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX] = { + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_0 */ /* system : 0~15, default : 5 */ + { + { {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{19000,19000}}, {{22323,22323}}, {{25647,25647}}, {{28971,28971}}, {{32295,32295}}, {{35619,35619}}, {{38943,38943}}, {{42267,42267}}, {{45591,45591}}, {{48915,48915}}, {{52239,52239}}, {{55563,55563}}, {{58887,58887}}, {{62211,62211}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_1, /* notification : 0~15, default : 7 */ - { /* FNT DEFAULT */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_1 */ /* notification : 0~15, default : 7 */ + { + { {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{19000,19000}}, {{22323,22323}}, {{25647,25647}}, {{28971,28971}}, {{32295,32295}}, {{35619,35619}}, {{38943,38943}}, {{42267,42267}}, {{45591,45591}}, {{48915,48915}}, {{52239,52239}}, {{55563,55563}}, {{58887,58887}}, {{62211,62211}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_2, /* alarm */ - { /* FNT DEFAULT */ - {LVOLUME_MAX_BASIC, {{{0,0}}, {{19000,19000}}, {{25991,25991}}, {{32982,32982}}, {{39973,39973}}, {{46964,46964}}, {{53955,53955}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_BASIC, {{{0,0}}, {{20480,20480}}, {{27225,27225}}, {{33969,33969}}, {{40714,40714}}, {{47458,47458}}, {{54203,54203}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ - {LVOLUME_MAX_BASIC, {{{0,0}}, {{20480,20480}}, {{27225,27225}}, {{33969,33969}}, {{40714,40714}}, {{47458,47458}}, {{54203,54203}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_2 */ /* alarm : 0~15, default : 7 */ + { + { + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{19000,19000}}, {{22323,22323}}, {{25647,25647}}, {{28971,28971}}, {{32295,32295}}, {{35619,35619}}, {{38943,38943}}, {{42267,42267}}, {{45591,45591}}, {{48915,48915}}, {{52239,52239}}, {{55563,55563}}, {{58887,58887}}, {{62211,62211}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_3, /* ringtone : 0~15, default : 13 */ - { /* FNT DEFAULT */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_3 */ /* ringtone : 0~15, default : 13 */ + { + { {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{19000,19000}}, {{22323,22323}}, {{25647,25647}}, {{28971,28971}}, {{32295,32295}}, {{35619,35619}}, {{38943,38943}}, {{42267,42267}}, {{45591,45591}}, {{48915,48915}}, {{52239,52239}}, {{55563,55563}}, {{58887,58887}}, {{62211,62211}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_4, /* media */ - { /* FNT DEFAULT */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_4 */ /* media */ + { + { {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{19000,19000}}, {{22323,22323}}, {{25647,25647}}, {{28971,28971}}, {{32295,32295}}, {{35619,35619}}, {{38943,38943}}, {{42267,42267}}, {{45591,45591}}, {{48915,48915}}, {{52239,52239}}, {{55563,55563}}, {{58887,58887}}, {{62211,62211}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_5, /* call */ - { /* FNT DEFAULT */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_5 */ /* call */ + { + { {LVOLUME_MAX_BASIC, {{{0,0}}, {{19000,19000}}, {{25991,25991}}, {{32982,32982}}, {{39973,39973}}, {{46964,46964}}, {{53955,53955}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_BASIC, {{{0,0}}, {{20480,20480}}, {{27225,27225}}, {{33969,33969}}, {{40714,40714}}, {{47458,47458}}, {{54203,54203}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ + {LVOLUME_MAX_BASIC, {{{0,0}}, {{20480,20480}}, {{27225,27225}}, {{33969,33969}}, {{40714,40714}}, {{47458,47458}}, {{54203,54203}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ {LVOLUME_MAX_BASIC, {{{0,0}}, {{20480,20480}}, {{27225,27225}}, {{33969,33969}}, {{40714,40714}}, {{47458,47458}}, {{54203,54203}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_6, /* fixed */ - { /* FNT DEFAULT */ - {LVOLUME_MAX_SINGLE, {{{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_SINGLE, {{{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ - {LVOLUME_MAX_SINGLE, {{{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_6 */ /* voip */ + { + { + {LVOLUME_MAX_BASIC, {{{0,0}}, {{19000,19000}}, {{25991,25991}}, {{32982,32982}}, {{39973,39973}}, {{46964,46964}}, {{53955,53955}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ + {LVOLUME_MAX_BASIC, {{{0,0}}, {{20480,20480}}, {{27225,27225}}, {{33969,33969}}, {{40714,40714}}, {{47458,47458}}, {{54203,54203}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ + {LVOLUME_MAX_BASIC, {{{0,0}}, {{20480,20480}}, {{27225,27225}}, {{33969,33969}}, {{40714,40714}}, {{47458,47458}}, {{54203,54203}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}, {{60947,60947}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_7, /* java */ - { /* FNT DEFAULT */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{19000,19000}}, {{22323,22323}}, {{25647,25647}}, {{28971,28971}}, {{32295,32295}}, {{35619,35619}}, {{38943,38943}}, {{42267,42267}}, {{45591,45591}}, {{48915,48915}}, {{52239,52239}}, {{55563,55563}}, {{58887,58887}}, {{62211,62211}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_7 */ /* fixed */ + { + { + {LVOLUME_MAX_SINGLE, {{{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ + {LVOLUME_MAX_SINGLE, {{{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ + {LVOLUME_MAX_SINGLE, {{{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, - { AVSYS_AUDIO_LVOL_GAIN_TYPE_8, /* music only (max level) */ - { /* FNT DEFAULT */ + /* AVSYS_AUDIO_LVOL_GAIN_TYPE_8 */ /* java */ + { + { {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{19000,19000}}, {{22323,22323}}, {{25647,25647}}, {{28971,28971}}, {{32295,32295}}, {{35619,35619}}, {{38943,38943}}, {{42267,42267}}, {{45591,45591}}, {{48915,48915}}, {{52239,52239}}, {{55563,55563}}, {{58887,58887}}, {{62211,62211}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ - {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET0 */ + {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ {LVOLUME_MAX_MULTIMEDIA, {{{0,0}}, {{20480,20480}}, {{23698,23698}}, {{26916,26916}}, {{30135,30135}}, {{33353,33353}}, {{36571,36571}}, {{39789,39789}}, {{43008,43008}}, {{46226,46226}}, {{49444,49444}}, {{52662,52662}}, {{55880,55880}}, {{59099,59099}}, {{62317,62317}}, {{65535,65535}}}}, /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ }, }, }; -int avsys_audio_logical_volume_get_max(int vol_type, int dev_type, int *max) +static const avsys_audio_lvol_gain_info_t g_gain_table[AVSYS_AUDIO_LVOL_GAIN_EXT_TYPE_MAX_IDX] = { + /* AVSYS_AUDIO_LVOL_GAIN_EXT_DIALER */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_TOUCH */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_AF */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_SHUTTER1 */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_SHUTTER2 */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_CAMCORDING */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_MIDI */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_BOOTING */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_VIDEO */ + { 1.0, 1.0, 1.0 }, + /* AVSYS_AUDIO_LVOL_GAIN_EXT_VIDEO_HDMI */ + { 1.0, 1.0, 1.0 }, +}; + +int avsys_audio_logical_volume_get_max(int volume_type, int dev_type, int *max_level) { void **data = NULL; - avsys_logical_gain_t *table = NULL; - data = (void **)&table; + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_volume_info_t *volume_table; + + data = (void **)&info; if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { avsys_error(AVAUDIO, "attach shared memory failed\n"); return AVSYS_STATE_ERR_ALLOCATION; } + volume_table = info->volume_table; - if (vol_type < 0 || vol_type >= AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX || - dev_type < 0 || dev_type >= AVSYS_AUDIO_LVOL_DEV_TYPE_MAX || - max == NULL) { + if ((max_level == NULL) + || (volume_type < 0 || volume_type >= AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX) + || (dev_type < 0 || dev_type >= AVSYS_AUDIO_LVOL_DEV_TYPE_MAX)) { avsys_error(AVAUDIO, "Input param wrong. Please check params\n\t type %d\n\tdevicetype %d\n", - vol_type, dev_type); + volume_type, dev_type); return AVSYS_STATE_ERR_INVALID_PARAMETER; } - *max = table[vol_type].devices[dev_type].max_len; + *max_level = volume_table[volume_type].devices[dev_type].max_level; return AVSYS_STATE_SUCCESS; } -int avsys_audio_logical_volume_set_table(int vol_type, int dev_type, avsys_audio_volume_setting_t *setting) +int avsys_audio_logical_volume_set_table(int volume_config, int dev_type, avsys_audio_volume_setting_t *setting) { void **data = NULL; - avsys_logical_gain_t *table = NULL; - data = (void**)&table; + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_volume_info_t *volume_table; + int vol_conf_type, vol_conf_gain; + + data = (void**)&info; if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { avsys_error(AVAUDIO, "attach shared memory failed\n"); return AVSYS_STATE_ERR_ALLOCATION; } + volume_table = info->volume_table; + vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(volume_config); + vol_conf_gain = AVSYS_AUDIO_VOLUME_CONFIG_GAIN(volume_config); - avsys_info(AVAUDIO, "Set Logical gain table\n"); - avsys_info(AVAUDIO, "\t vol_type %d dev_type %d\n", vol_type, dev_type); + avsys_info(AVAUDIO, "Set Logical volume table\n"); + avsys_info(AVAUDIO, "\t vol_type %d vol_gain %x dev_type %d\n", vol_conf_type, vol_conf_gain, dev_type); if (setting == NULL) { avsys_error(AVAUDIO, "setting is null in %s\n", __func__); return AVSYS_STATE_ERR_NULL_POINTER; } - - /* Change ">" -> ">=" for CRASH LOGGER */ - if ((vol_type < 0 || vol_type >= AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX) || - (dev_type < 0 || dev_type >= AVSYS_AUDIO_LVOL_DEV_TYPE_MAX)) { + if ((vol_conf_type < 0 || vol_conf_type >= AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX) + || (dev_type < 0 || dev_type >= AVSYS_AUDIO_LVOL_DEV_TYPE_MAX)) { avsys_error(AVAUDIO, "Input param wrong. Please check params\n\ttype %d\n\tdevicetype %d\n", - vol_type, dev_type); - return AVSYS_STATE_ERR_INVALID_PARAMETER; - } - - if (table[vol_type].type != vol_type) { - avsys_error(AVAUDIO, "volume type does not match (%d, %d)in %s\n", table[vol_type].type, vol_type, __func__); + vol_conf_type, dev_type); return AVSYS_STATE_ERR_INVALID_PARAMETER; } - setting->vol_type = vol_type; + setting->volume_config = volume_config; setting->dev_type = dev_type; - setting->max_len = table[vol_type].devices[dev_type].max_len; - setting->table = (avsys_audio_volume_t *)(((int)table[vol_type].devices[dev_type].gain) - (int)table); + setting->max_level = volume_table[vol_conf_type].devices[dev_type].max_level; - avsys_info(AVAUDIO, "vol %d, dev%d table setted.\n", vol_type, dev_type); + avsys_info(AVAUDIO, "vol %d, dev%d table setted.\n", vol_conf_type, dev_type); return AVSYS_STATE_SUCCESS; } int avsys_audio_logical_volume_update_table(int dev_type, avsys_audio_volume_setting_t *setting) { void **data = NULL; - avsys_logical_gain_t *table = NULL; - data = (void **)&table; - if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { - avsys_error(AVAUDIO, "attach shared memory failed\n"); - return AVSYS_STATE_ERR_ALLOCATION; - } - - avsys_info(AVAUDIO, "Update Logical gain table\n"); - avsys_info(AVAUDIO, "\t dev_type %d\n", dev_type); + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_volume_info_t *volume_table; + int vol_conf_type; if (setting == NULL) { avsys_error(AVAUDIO, "setting is null in %s\n", __func__); return AVSYS_STATE_ERR_NULL_POINTER; } - if (table[setting->vol_type].type != setting->vol_type) { - avsys_error(AVAUDIO, "volume type does not match in %s\n", __func__); - return AVSYS_STATE_ERR_INVALID_PARAMETER; - } - if (dev_type < 0 || dev_type >= AVSYS_AUDIO_LVOL_DEV_TYPE_MAX) { avsys_error(AVAUDIO, "Input param wrong. Please check params\tdevicetype %d\n", dev_type); return AVSYS_STATE_ERR_INVALID_PARAMETER; } + + data = (void **)&info; + if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { + avsys_error(AVAUDIO, "attach shared memory failed\n"); + return AVSYS_STATE_ERR_ALLOCATION; + } + volume_table = info->volume_table; + vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(setting->volume_config); + + avsys_info(AVAUDIO, "Update Logical volume table\n"); + avsys_info(AVAUDIO, "\t dev_type %d\n", dev_type); + setting->dev_type = dev_type; - setting->max_len = table[setting->vol_type].devices[dev_type].max_len; - setting->table = (avsys_audio_volume_t *)(((int)table[setting->vol_type].devices[dev_type].gain) - (int)table); + setting->max_level = volume_table[vol_conf_type].devices[dev_type].max_level; + return AVSYS_STATE_SUCCESS; } int avsys_audio_logical_volume_convert(avsys_audio_volume_t *level, avsys_audio_volume_t *converted, avsys_audio_volume_setting_t *setting) { void **data = NULL; - avsys_logical_gain_t *table = NULL; - data = (void **)&table; + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_volume_info_t *volume_table; + avsys_audio_lvol_gain_info_t *gain_table; + int vol_conf_type, vol_conf_gain, volume_gain_idx; + + data = (void **)&info; if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { avsys_error(AVAUDIO, "attach shared memory failed\n"); return AVSYS_STATE_ERR_ALLOCATION; } + volume_table = info->volume_table; + gain_table = info->gain_table; + vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(setting->volume_config); + vol_conf_gain = AVSYS_AUDIO_VOLUME_CONFIG_GAIN(setting->volume_config); + volume_gain_idx = AVSYS_AUDIO_VOLUME_GAIN_IDX(vol_conf_gain); if (level == NULL) { avsys_error(AVAUDIO, "level is null in %s\n", __func__); return AVSYS_STATE_ERR_NULL_POINTER; } - if (level->level[AVSYS_AUDIO_CHANNEL_LEFT] < 0) { - avsys_error(AVAUDIO, "negative volume level (left) in %s : %d\n", __func__, level->level[AVSYS_AUDIO_CHANNEL_LEFT]); - return AVSYS_STATE_ERR_INVALID_PARAMETER; - } - if (level->level[AVSYS_AUDIO_CHANNEL_RIGHT] < 0) { - avsys_error(AVAUDIO, "negative volume level (right) in %s : %d\n", __func__, level->level[AVSYS_AUDIO_CHANNEL_RIGHT]); - return AVSYS_STATE_ERR_INVALID_PARAMETER; - } - - if (setting->max_len <= level->level[AVSYS_AUDIO_CHANNEL_LEFT] || - setting->max_len <= level->level[AVSYS_AUDIO_CHANNEL_RIGHT] || - 0 > level->level[AVSYS_AUDIO_CHANNEL_LEFT] || - 0 > level->level[AVSYS_AUDIO_CHANNEL_RIGHT]) - { + if ((level->level[AVSYS_AUDIO_CHANNEL_LEFT] < 0 || level->level[AVSYS_AUDIO_CHANNEL_LEFT] >= setting->max_level) + || (level->level[AVSYS_AUDIO_CHANNEL_RIGHT] < 0 || level->level[AVSYS_AUDIO_CHANNEL_RIGHT] >= setting->max_level)) { avsys_error(AVAUDIO, "Input param wrong. Please check params\n\t level %d %d\n", level->level[AVSYS_AUDIO_CHANNEL_LEFT], level->level[AVSYS_AUDIO_CHANNEL_RIGHT]); - return AVSYS_STATE_ERR_INVALID_VALUE; } - converted->level[AVSYS_AUDIO_CHANNEL_LEFT] = ((avsys_audio_volume_t *)((int)table + (int)setting->table))[level->level[AVSYS_AUDIO_CHANNEL_LEFT]].level[AVSYS_AUDIO_CHANNEL_LEFT]; - converted->level[AVSYS_AUDIO_CHANNEL_RIGHT] = ((avsys_audio_volume_t *)((int)table + (int)setting->table))[level->level[AVSYS_AUDIO_CHANNEL_RIGHT]].level[AVSYS_AUDIO_CHANNEL_RIGHT]; + converted->level[AVSYS_AUDIO_CHANNEL_LEFT] = volume_table[vol_conf_type].devices[setting->dev_type].logical_values[level->level[AVSYS_AUDIO_CHANNEL_LEFT]].level[AVSYS_AUDIO_CHANNEL_LEFT]; + converted->level[AVSYS_AUDIO_CHANNEL_RIGHT] = volume_table[vol_conf_type].devices[setting->dev_type].logical_values[level->level[AVSYS_AUDIO_CHANNEL_RIGHT]].level[AVSYS_AUDIO_CHANNEL_RIGHT]; - avsys_warning(AVAUDIO, "Volume converted vol_type %d dev_type %d\n", setting->vol_type, setting->dev_type); + if (volume_gain_idx >= 0) { + converted->level[AVSYS_AUDIO_CHANNEL_LEFT] *= gain_table[volume_gain_idx].devices[setting->dev_type]; + converted->level[AVSYS_AUDIO_CHANNEL_RIGHT] *= gain_table[volume_gain_idx].devices[setting->dev_type]; + } + + avsys_warning(AVAUDIO, "Volume converted vol_type %d vol_gain %x dev_type %d\n", vol_conf_type, vol_conf_gain, setting->dev_type); avsys_warning(AVAUDIO, "\tL: %d to %d\n", level->level[AVSYS_AUDIO_CHANNEL_LEFT], converted->level[AVSYS_AUDIO_CHANNEL_LEFT]); avsys_warning(AVAUDIO, "\tR: %d to %d\n", level->level[AVSYS_AUDIO_CHANNEL_RIGHT], converted->level[AVSYS_AUDIO_CHANNEL_RIGHT]); @@ -233,133 +269,175 @@ int avsys_audio_logical_volume_convert(avsys_audio_volume_t *level, avsys_audio_ int avsys_audio_logical_volume_init(void) { - void *data = NULL; + void **data = NULL; + avsys_audio_lvol_info_t *info = NULL; + + data = (void **)&info; avsys_audio_create_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME); - if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, &data))) { + if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { avsys_error(AVAUDIO, "attach shared memory failed\n"); return AVSYS_STATE_ERR_ALLOCATION; } - memcpy(data, g_volume_table, sizeof(avsys_logical_gain_t) * AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX); - if (AVSYS_FAIL(avsys_audio_load_volume_from_file())) { + + memcpy(info->volume_table, g_volume_table, sizeof(avsys_audio_lvol_volume_info_t) * AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX); + memcpy(info->gain_table, g_gain_table, sizeof(avsys_audio_lvol_gain_info_t) * AVSYS_AUDIO_LVOL_GAIN_EXT_TYPE_MAX_IDX); + + if (AVSYS_FAIL(avsys_audio_load_volume_from_ini())) { avsys_error(AVAUDIO, "Loading volume table from file failed. use default table\n"); } + + return AVSYS_STATE_SUCCESS; +} + +int avsys_audio_logical_volume_set_to_table(int volume_type, int dev_type, int step, int lv, int rv) +{ + void **data = NULL; + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_volume_info_t *volume_table; + + data = (void **)&info; + if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { + avsys_error(AVAUDIO, "attach shared memory failed\n"); + return AVSYS_STATE_ERR_ALLOCATION; + } + volume_table = info->volume_table; + + volume_table[volume_type].devices[dev_type].logical_values[step].level[AVSYS_AUDIO_CHANNEL_LEFT] = lv; + volume_table[volume_type].devices[dev_type].logical_values[step].level[AVSYS_AUDIO_CHANNEL_RIGHT] = rv; return AVSYS_STATE_SUCCESS; } -int avsys_audio_logical_volume_set_to_table(int gain_type, int dev_type, int step, int lv, int rv) +int avsys_audio_logical_volume_get_from_table(int volume_type, int dev_type, int step, int *lv, int *rv) { void **data = NULL; - avsys_logical_gain_t *table = NULL; - data = (void **)&table; + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_volume_info_t *volume_table; + + data = (void **)&info; if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { avsys_error(AVAUDIO, "attach shared memory failed\n"); return AVSYS_STATE_ERR_ALLOCATION; } + volume_table = info->volume_table; + + *lv = volume_table[volume_type].devices[dev_type].logical_values[step].level[AVSYS_AUDIO_CHANNEL_LEFT]; + *rv = volume_table[volume_type].devices[dev_type].logical_values[step].level[AVSYS_AUDIO_CHANNEL_RIGHT]; - table[gain_type].devices[dev_type].gain[step].level[0] = lv; - table[gain_type].devices[dev_type].gain[step].level[1] = rv; return AVSYS_STATE_SUCCESS; } -int avsys_audio_logical_volume_get_from_table(int gain_type, int dev_type, int step, int *lv, int *rv) +int avsys_audio_logical_volume_set_gain_to_table(int volume_gain_idx, int dev_type, float lv, float rv) { void **data = NULL; - avsys_logical_gain_t *table = NULL; - data = (void **)&table; + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_gain_info_t *gain_table; + + data = (void **)&info; if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { avsys_error(AVAUDIO, "attach shared memory failed\n"); return AVSYS_STATE_ERR_ALLOCATION; } + gain_table = info->gain_table; + + gain_table[volume_gain_idx].devices[dev_type] = lv; + gain_table[volume_gain_idx].devices[dev_type] = rv; - *lv = table[gain_type].devices[dev_type].gain[step].level[0]; - *rv = table[gain_type].devices[dev_type].gain[step].level[1]; return AVSYS_STATE_SUCCESS; } -int avsys_audio_load_volume_from_file() +int avsys_audio_logical_volume_get_gain_from_table(int volume_gain_idx, int dev_type, float *lv, float *rv) { - FILE *fp = NULL; - int result = AVSYS_STATE_SUCCESS; - char strBuffer[128]; - - fp = fopen(VOLUME_FILE_PATH, "r"); - if (fp == NULL) { - printf("Loading volume table from file failed\n"); - return AVSYS_STATE_ERR_INTERNAL; + void **data = NULL; + avsys_audio_lvol_info_t *info = NULL; + avsys_audio_lvol_gain_info_t *gain_table; + + data = (void **)&info; + if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, data))) { + avsys_error(AVAUDIO, "attach shared memory failed\n"); + return AVSYS_STATE_ERR_ALLOCATION; } + gain_table = info->gain_table; - memset(strBuffer, '\0', sizeof(strBuffer)); - while (fgets(strBuffer, sizeof(strBuffer), fp) != NULL) { - char *pEnd = NULL; - char *pStart = NULL; - int volumetable = 0; - int device = 0; - int level = 0; - int lvalue = 0, rvalue = 0; - char parseBuf[10] = ""; - - /* remove newline */ - if (strBuffer[strlen(strBuffer) - 1] == '\n') - strBuffer[strlen(strBuffer) - 1] = '\0'; - if (strBuffer[strlen(strBuffer) - 1] == '\r') - strBuffer[strlen(strBuffer) - 1] = '\0'; - if (strBuffer[0] == '#') - continue; - - pStart = strBuffer; - pEnd = strstr(pStart, ":"); - if (pEnd) { - memset(parseBuf, '\0', sizeof(parseBuf)); - memcpy(parseBuf, pStart, pEnd - pStart); - volumetable = atoi(parseBuf); - } else { - result = AVSYS_STATE_ERR_INTERNAL; - break; - } + *lv = gain_table[volume_gain_idx].devices[dev_type]; + *rv = gain_table[volume_gain_idx].devices[dev_type]; - pStart = ++pEnd; - pEnd = strstr(pStart, ":"); - if (pEnd) { - memset(parseBuf, '\0', sizeof(parseBuf)); - memcpy(parseBuf, pStart, pEnd - pStart); - if (strcmp(parseBuf, "SPK") == 0) - device = 0; - else if (strcmp(parseBuf, "HEADSET") == 0) - device = 1; - else if (strcmp(parseBuf, "BTHEADSET") == 0) - device = 2; - } else { - result = AVSYS_STATE_ERR_INTERNAL; - break; - } + return AVSYS_STATE_SUCCESS; +} - pStart = ++pEnd; - pEnd = strstr(pStart, ":"); - if (pEnd) { - memset(parseBuf, '\0', sizeof(parseBuf)); - memcpy(parseBuf, pStart, pEnd - pStart); - level = atoi(parseBuf); - } else { - result = AVSYS_STATE_ERR_INTERNAL; - break; +int avsys_audio_load_volume_from_ini(void) +{ + const char *dev_str[] = { + "speaker", /* AVSYS_AUDIO_LVOL_DEV_TYPE_SPK */ + "headset", /* AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET */ + "btheadset" /* AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET */ + }; + const char *vol_type_str[] = { + "system", /* AVSYS_AUDIO_LVOL_GAIN_TYPE_0 */ + "notification", /* AVSYS_AUDIO_LVOL_GAIN_TYPE_1 */ + "alarm", /* AVSYS_AUDIO_LVOL_GAIN_TYPE_2 */ + "ringtone", /* AVSYS_AUDIO_LVOL_GAIN_TYPE_3 */ + "media", /* AVSYS_AUDIO_LVOL_GAIN_TYPE_4 */ + "call" /* AVSYS_AUDIO_LVOL_GAIN_TYPE_5 */ + }; + dictionary * dict = NULL; + int dev_idx, vol_type_idx, dev_cnt, vol_type_cnt; + + dict = iniparser_load(AVSYS_VOLUME_INI_DEFAULT_PATH); + if (!dict) { + avsys_info(AVAUDIO, "Use temporary volume ini file"); + dict = iniparser_load(AVSYS_VOLUME_INI_TEMP_PATH); + if (!dict) { + avsys_warning(AVAUDIO, "Loading volume table from ini file failed"); + return AVSYS_STATE_ERR_INTERNAL; } + } - pStart = ++pEnd; - if (pEnd) { - pEnd = strstr(pStart, ":"); - memset(parseBuf, '\0', sizeof(parseBuf)); - memcpy(parseBuf, pStart, pEnd - pStart); - lvalue = atoi(parseBuf); - } else { - result = AVSYS_STATE_ERR_INTERNAL; - break; + dev_cnt = sizeof(dev_str) / sizeof(char *); + vol_type_cnt = sizeof(vol_type_str) / sizeof(char *); + + for (dev_idx = 0; dev_idx < dev_cnt; dev_idx++) { + const char delimiter[] = ", "; + char *key, *list_str, *token, *ptr = NULL; + int vol_gain_idx = 0; + float gain_value = 1.0f; + + /* Get volume table */ + for (vol_type_idx = 0; vol_type_idx < vol_type_cnt; vol_type_idx++) { + int step_idx = 0, volume_value; + + key = malloc(strlen(dev_str[dev_idx]) + strlen(vol_type_str[vol_type_idx]) + 2); + if (key) { + sprintf(key, "%s:%s", dev_str[dev_idx], vol_type_str[vol_type_idx]); + list_str = iniparser_getstr(dict, key); + if (list_str) { + token = strtok_r(list_str, delimiter, &ptr); + while (token) { + volume_value = atoi(token); + avsys_audio_logical_volume_set_to_table(vol_type_idx, dev_idx, step_idx++, volume_value, volume_value); + token = strtok_r(NULL, delimiter, &ptr); + } + } + free(key); + } } - pStart = ++pEnd; - rvalue = atoi(pStart); - avsys_audio_set_volume_table(volumetable, device, level, lvalue, rvalue); + /* Get gain table */ + key = malloc(strlen(dev_str[dev_idx]) + strlen("gain") + 2); + if (key) { + sprintf(key, "%s:gain", dev_str[dev_idx]); + list_str = iniparser_getstr(dict, key); + if (list_str) { + token = strtok_r(list_str, delimiter, &ptr); + while (token) { + gain_value = (float)atof(token); + avsys_audio_logical_volume_set_gain_to_table(vol_gain_idx++, dev_idx, gain_value, gain_value); + token = strtok_r(NULL, delimiter, &ptr); + } + } + free(key); + } } - fclose(fp); - //avsys_info(AVAUDIO,"Load volume table from file success\n"); - return result; + + iniparser_freedict(dict); + return AVSYS_STATE_SUCCESS; } diff --git a/avsys-audio-pasimple.c b/avsys-audio-pasimple.c index 29c4593..aeeb999 100644 --- a/avsys-audio-pasimple.c +++ b/avsys-audio-pasimple.c @@ -67,6 +67,10 @@ do { \ attr.fragsize = fs; \ } while (0) +#define MEDIA_POLICY_AUTO "auto" +#define MEDIA_POLICY_PHONE "phone" +#define MEDIA_POLICY_ALL "all" + int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, const unsigned int channel, const unsigned int samplerate, avsys_audio_handle_t *handle, int policy) { pa_simple *s = NULL; @@ -75,14 +79,24 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, pa_buffer_attr attr; int err = AVSYS_STATE_SUCCESS; int period_time = PA_SIMPLE_PERIOD_TIME_FOR_MID_LATENCY_MSEC; - int samples_per_period = PA_SIMPLE_SAMPLES_PER_PERIOD_DEFAULT; int periods_per_buffer = PA_SIMPLE_PERIODS_PER_BUFFER_DEFAULT; + int vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(handle->gain_setting.volume_config); + pa_channel_map channel_map; + + int p_time = PA_SIMPLE_PERIOD_TIME_FOR_HIGH_LATENCY_MSEC; + int p_count = PA_SIMPLE_PERIODS_PER_BUFFER_PLAYBACK; + char *time = getenv("AVSYS_PERIOD_TIME"); + char *count = getenv("AVSYS_PERIOD_COUNT"); + if(time) + p_time = atoi(time); + if(count) + p_count = atoi(count); avsys_info(AVAUDIO, ">>>[%s] mode=%d, format=%d, channel=%d, samplerate=%d\n", __func__, mode, format, channel, samplerate); avsys_assert(handle != NULL); - if (channel < 1 || channel > 2) + if (channel < AVSYS_CHANNEL_MIN || channel > AVSYS_CHANNEL_MAX) return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT; device = (avsys_audio_pasimple_handle_t *)malloc(sizeof(avsys_audio_pasimple_handle_t)); @@ -94,6 +108,8 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, ss.rate = samplerate; ss.channels = channel; + pa_channel_map_init_auto(&channel_map, ss.channels, PA_CHANNEL_MAP_ALSA); + switch (format) { case AVSYS_AUDIO_FORMAT_8BIT: ss.format = PA_SAMPLE_U8; @@ -114,20 +130,31 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, pa_proplist *proplist = pa_proplist_new(); /* Set policy property */ - avsys_info(AVAUDIO, ">>>[%s] policy=[%d], vol_type=[%d]\n", __func__, policy, handle->gain_setting.vol_type); + avsys_info(AVAUDIO, ">>>[%s] policy=[%d], vol_type=[%d]\n", __func__, policy, vol_conf_type); if (policy == AVSYS_AUDIO_HANDLE_ROUTE_HANDSET_ONLY) { avsys_info(AVAUDIO, ": set media plicy to PHONE\n"); - pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, "phone"); + pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, MEDIA_POLICY_PHONE); } else { /* AVSYS_AUDIO_HANDLE_ROUTE_FOLLOWING_POLICY */ /* check stream type (vol type) */ - if (handle->gain_setting.vol_type == AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION || - handle->gain_setting.vol_type == AVSYS_AUDIO_VOLUME_TYPE_ALARM) { + + switch (vol_conf_type) + { + case AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION: + case AVSYS_AUDIO_VOLUME_TYPE_ALARM: avsys_info(AVAUDIO, ": set media plicy to ALL\n"); - pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, "all"); - } else { + pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, MEDIA_POLICY_ALL); + break; + + case AVSYS_AUDIO_VOLUME_TYPE_FIXED: /* Used for Emergency */ + avsys_info(AVAUDIO, ": set media plicy to PHONE\n"); + pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, MEDIA_POLICY_PHONE); + break; + + default: avsys_info(AVAUDIO, ": set media plicy to AUTO\n"); - pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, "auto"); + pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, MEDIA_POLICY_AUTO); + break; } } @@ -142,7 +169,7 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, PA_SIMPLE_PERIODS_PER_BUFFER_DEFAULT, 0, -1, -1, -1, samples_per_period * device->samplesize); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "CAPTURE", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "CAPTURE", &ss, &channel_map, &attr, proplist, &err); break; case AVSYS_AUDIO_MODE_INPUT_LOW_LATENCY: @@ -151,7 +178,7 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, PA_SIMPLE_PERIODS_PER_BUFFER_FASTMODE, 0, -1, -1, -1, samples_per_period * device->samplesize); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "LOW LATENCY CAPTURE", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "LOW LATENCY CAPTURE", &ss, &channel_map, &attr, proplist, &err); break; case AVSYS_AUDIO_MODE_INPUT_HIGH_LATENCY: @@ -160,7 +187,7 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, PA_SIMPLE_PERIODS_PER_BUFFER_CAPTURE, 0, -1, -1, -1, samples_per_period * device->samplesize); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "HIGH LATENCY CAPTURE", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "HIGH LATENCY CAPTURE", &ss, &channel_map, &attr, proplist, &err); break; case AVSYS_AUDIO_MODE_OUTPUT: /* mid latency playback for normal audio case. */ @@ -169,7 +196,7 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, PA_SIMPLE_PERIODS_PER_BUFFER_DEFAULT, -1, -1, periods_per_buffer * samples_per_period * device->samplesize, attr.tlength, 0); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "PLAYBACK", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "PLAYBACK", &ss, &channel_map, &attr, proplist, &err); break; case AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY: /* This is special case for touch sound playback */ @@ -178,15 +205,15 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, PA_SIMPLE_PERIODS_PER_BUFFER_FASTMODE, samples_per_period * device->samplesize, -1, samples_per_period * device->samplesize + 3430, (uint32_t)-1, 0); - s = pa_simple_new_proplist(NULL,"AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "LOW LATENCY PLAYBACK", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL,"AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "LOW LATENCY PLAYBACK", &ss, &channel_map, &attr, proplist, &err); break; case AVSYS_AUDIO_MODE_OUTPUT_CLOCK: /* high latency playback - lager buffer size */ - SET_PA_ATTR(PA_SIMPLE_PERIOD_TIME_FOR_HIGH_LATENCY_MSEC, + SET_PA_ATTR(p_time, MSEC_TO_SAMPLE(samplerate,period_time), - PA_SIMPLE_PERIODS_PER_BUFFER_PLAYBACK, + p_count, (uint32_t) -1, (uint32_t) -1, periods_per_buffer * samples_per_period * device->samplesize, (uint32_t)-1, 0); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "HIGH LATENCY PLAYBACK", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "HIGH LATENCY PLAYBACK", &ss, &channel_map, &attr, proplist, &err); break; case AVSYS_AUDIO_MODE_OUTPUT_VIDEO: /* low latency playback */ @@ -195,7 +222,7 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, PA_SIMPLE_PERIODS_PER_BUFFER_VIDEO, 4*(samples_per_period * device->samplesize), samples_per_period * device->samplesize, periods_per_buffer * samples_per_period * device->samplesize, (uint32_t)-1, 0); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "LOW LATENCY PLAYBACK", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "LOW LATENCY PLAYBACK", &ss, &channel_map, &attr, proplist, &err); break; case AVSYS_AUDIO_MODE_OUTPUT_AP_CALL: @@ -209,7 +236,7 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, (uint32_t) -1, (uint32_t) -1, periods_per_buffer * samples_per_period * device->samplesize, attr.tlength, 0); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "VoIP PLAYBACK", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_PLAYBACK, NULL, "VoIP PLAYBACK", &ss, &channel_map, &attr, proplist, &err); #endif break; case AVSYS_AUDIO_MODE_INPUT_AP_CALL: @@ -222,7 +249,7 @@ int avsys_audio_pasimple_open_device(const int mode, const unsigned int format, PA_SIMPLE_PERIODS_PER_BUFFER_DEFAULT, 0, (uint32_t) -1, (uint32_t) -1, (uint32_t) -1, samples_per_period * device->samplesize); - s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "VoIP CAPTURE", &ss, NULL, &attr, proplist, &err); + s = pa_simple_new_proplist(NULL, "AVSYSTEM", PA_STREAM_RECORD, NULL, "VoIP CAPTURE", &ss, &channel_map, &attr, proplist, &err); #endif break; case AVSYS_AUDIO_MODE_CALL_OUT: @@ -473,3 +500,40 @@ int avsys_audio_pasimple_get_period_buffer_time(avsys_audio_handle_t *handle, un return AVSYS_STATE_SUCCESS; } +int avsys_audio_pasimple_cork(avsys_audio_handle_t *handle, int cork) +{ + pa_simple *s = NULL; + avsys_audio_pasimple_handle_t *device = NULL; + int err = 0; + + CHECK_VALID_HANDLE(handle); + + s = (pa_simple *)device->pasimple_handle; + + if (0 > pa_simple_cork(s, cork, &err)) { + avsys_error(AVAUDIO, "pa_simple_cork() failed with %s\n", pa_strerror(err)); + return AVSYS_STATE_ERR_INTERNAL; + } + + return AVSYS_STATE_SUCCESS; +} + +int avsys_audio_pasimple_is_corked(avsys_audio_handle_t *handle, int *is_corked) +{ + pa_simple *s = NULL; + avsys_audio_pasimple_handle_t *device = NULL; + int err = 0; + + if (is_corked == NULL) + return AVSYS_STATE_ERR_INTERNAL; + + CHECK_VALID_HANDLE(handle); + + s = (pa_simple *)device->pasimple_handle; + + *is_corked = pa_simple_is_corked(s); + + return AVSYS_STATE_SUCCESS; +} + + diff --git a/avsys-audio-path.c b/avsys-audio-path.c index 7967842..7b37ae2 100644 --- a/avsys-audio-path.c +++ b/avsys-audio-path.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "avsys-audio-shm.h" #include "avsys-audio-sync.h" @@ -46,28 +48,26 @@ return AVSYS_STATE_ERR_IO_CONTROL; \ } } -#define OPEN_AIF_BEFORE_SCENARIO_SET - static int g_playback_path_select_data[AVSYS_AUDIO_PLAYBACK_GAIN_MAX][AVSYS_AUDIO_PATH_EX_OUTMAX] = { { /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */ - /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */ - 0, 1, 0, 1, 0, 0, 0, 0 + /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI DOCK USBAUDIO */ + 0, 1, 0, 1, 0, 0, 0, 1, 1, 0 }, { /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */ /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */ - 1, 1, 0, 1, 0, 0, 0, 0 + 1, 1, 0, 1, 0, 1, 0, 0, 0, 0 }, { /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */ /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */ - 1, 1, 1, 1, 1, 0, 0, 0 + 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, { /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */ /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */ - 1, 1, 1, 1, 1, 0, 0, 0 + 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, { /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */ /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */ - 0, 1, 1, 1, 1, 0, 0, 0 + 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 } }; @@ -161,32 +161,22 @@ static int __avsys_audio_path_set_ascn_voicecall(avsys_audio_path_ex_info_t *con static int __avsys_audio_path_set_ascn_videocall(avsys_audio_path_ex_info_t *control); static int __avsys_audio_path_set_ascn_fmradio(avsys_audio_path_ex_info_t *control); static int __avsys_audio_path_set_ascn_ap_capture(avsys_audio_path_ex_info_t *control); - - -typedef int (*_internal_gain_func)(avsys_audio_path_ex_info_t *control); -static _internal_gain_func playback_gain_func_table[AVSYS_AUDIO_PLAYBACK_GAIN_MAX] = -{ - __avsys_audio_path_set_ascn_ap_playback, - __avsys_audio_path_set_ascn_fmradio, - __avsys_audio_path_set_ascn_voicecall, - __avsys_audio_path_set_ascn_videocall, - __avsys_audio_path_set_ascn_ap_playback, -}; - -static _internal_gain_func capture_gain_func_table[AVSYS_AUDIO_CAPTURE_GAIN_MAX] = -{ - __avsys_audio_path_set_ascn_ap_capture, - __avsys_audio_path_set_ascn_fmradio, - __avsys_audio_path_set_ascn_voicecall, - __avsys_audio_path_set_ascn_videocall, -}; - static int __avsys_audio_path_set_hw_controls(avsys_audio_path_ex_info_t *control); static int __avsys_audio_path_get_earjack_type(void); #define AUDIOSYSTEM_CONF "/opt/etc/audio_system.conf" #define CONF_ITEM_COUNT 2 #define INPUT_DEV_MAX 20 + +#define EARJACK_EVENT_PATH "/dev/input/event" + +#define AVSYS_AUDIO_INI_DEFAULT_PATH "/usr/etc/mmfw_avsystem.ini" +#define AVSYS_AUDIO_DEFAULT_CONTROL_AIF_BEFORE_PATH_SET 0 +#define AVSYS_AUDIO_DEFAULT_GAIN_DEBUG_MODE 0 + +#define CP_STATUS "/sys/class/audio/caps/cp_caps" +#define CP_WB_STRING "wb" + static char *conf_string[] = { "headset_detection", "headset_node", @@ -195,10 +185,14 @@ static char *conf_string[] = { typedef struct { char headset_detection; char headset_node_number; -} AudioSystemConf; + bool control_aif_before_path_set; + bool gain_debug_mode; +} avsys_audio_conf; -static int __load_conf(AudioSystemConf *data) +static int __load_conf(avsys_audio_conf *data) { + dictionary *dict = NULL; + #if defined(_MMFW_I386_ALL_SIMULATOR) if (data == NULL) return AVSYS_STATE_ERR_NULL_POINTER; @@ -279,9 +273,46 @@ static int __load_conf(AudioSystemConf *data) data->headset_detection = conf_data[0]; data->headset_node_number = conf_data[1]; #endif + + /* first, try to load existing ini file */ + dict = iniparser_load(AVSYS_AUDIO_INI_DEFAULT_PATH); + if (dict) { /* if dict is available */ + data->control_aif_before_path_set = iniparser_getboolean(dict, "aif:control aif before path set", AVSYS_AUDIO_DEFAULT_CONTROL_AIF_BEFORE_PATH_SET); + data->gain_debug_mode = iniparser_getboolean(dict, "debug:gain debug mode", AVSYS_AUDIO_DEFAULT_GAIN_DEBUG_MODE); + + /* free dict as we got our own structure */ + iniparser_freedict (dict); + } else { /* if no file exists. create one with set of default values */ + data->control_aif_before_path_set = AVSYS_AUDIO_DEFAULT_CONTROL_AIF_BEFORE_PATH_SET; + data->gain_debug_mode = AVSYS_AUDIO_DEFAULT_GAIN_DEBUG_MODE; + } + return AVSYS_STATE_SUCCESS; } +static bool __is_cp_wb () +{ + bool ret = false; + char str[10] = { 0, }; + FILE* fp = NULL; + + avsys_info(AVAUDIO, "Checking [%s] for WB capability...\n", CP_STATUS); + fp = fopen (CP_STATUS, "r"); + if (fp) { + if (fgets (str, sizeof(str)-1, fp)) { + if (strstr (str, CP_WB_STRING)) { + ret = true; + } + } + fclose(fp); + } else { + avsys_warning (AVAUDIO, "failed to open [%s]...errno=[%d]\n", CP_STATUS, errno); + } + + avsys_info(AVAUDIO, "Result [%d] : [%s] capability!!!\n", ret, (ret)? "WB" : "NB"); + return ret; +} + EXPORT_API int avsys_audio_path_ex_init(void) { @@ -289,12 +320,10 @@ int avsys_audio_path_ex_init(void) avsys_audio_path_ex_info_t **temp = NULL; gain_info_t default_gain = { AVSYS_AUDIO_PLAYBACK_GAIN_AP, AVSYS_AUDIO_CAPTURE_GAIN_AP }; path_info_t default_path = { AVSYS_AUDIO_PATH_EX_SPK, AVSYS_AUDIO_PATH_EX_MIC }; - gain_status_t clean_gain_status = { GS_GAIN_NONE, GS_GAIN_NONE }; - path_status_t clean_path_status = { PS_PATH_NONE, PS_PATH_NONE }; - option_info_t default_option = { AVSYS_AUDIO_PATH_OPTION_JACK_AUTO, AVSYS_AUDIO_PATH_OPTION_JACK_AUTO }; + option_info_t default_option = { AVSYS_AUDIO_PATH_OPTION_NONE, AVSYS_AUDIO_PATH_OPTION_NONE }; int index = 0; int err = AVSYS_STATE_SUCCESS; - AudioSystemConf conf = { 1, 4 }; + avsys_audio_conf conf = { 0, }; /* Check root user */ err = avsys_check_root_privilege(); @@ -304,7 +333,6 @@ int avsys_audio_path_ex_init(void) temp = &control; avsys_assert(AVSYS_SUCCESS(avsys_audio_create_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - avsys_assert(AVSYS_SUCCESS(avsys_audio_create_sync(AVSYS_AUDIO_SYNC_IDEN_SOUNDPATH))); /* for audio route policy */ avsys_assert(AVSYS_SUCCESS(avsys_audio_create_shm(AVSYS_AUDIO_SHM_IDEN_PATH))); avsys_assert(AVSYS_SUCCESS(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))); @@ -319,14 +347,10 @@ int avsys_audio_path_ex_init(void) control->backup_gain = default_gain; control->backup_path = default_path; control->option = default_option; - control->gain_status = clean_gain_status; - control->path_status = clean_path_status; - control->p_gain_status = clean_gain_status; - control->p_path_status = clean_path_status; control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; control->inserted = AVSYS_AUDIO_INSERTED_NONE; - control->route_policy = AVSYS_AUDIO_ROUTE_POLICY_DEFAULT; + if (AVSYS_FAIL(__load_conf(&conf))) avsys_error_r(AVAUDIO, "Can not load audio system configuration file\n"); @@ -344,29 +368,10 @@ int avsys_audio_path_ex_init(void) avsys_error_r(AVAUDIO, "Earjack init value is %d\n", control->inserted); - { - /* Gain tunning Debug mode */ - FILE *gainTunningFp = NULL; - if (NULL != (gainTunningFp = fopen("/opt/etc/gain_tuner.ini", "r"))) { - char buffer[32] = ""; - avsys_warning(AVAUDIO, "GAIN TUNNING DEBUG MODE...This degrade sound path performance\n"); - memset(buffer, '\0', sizeof(buffer)); - if (NULL == fgets(buffer, sizeof(buffer) - 1, gainTunningFp)) { - fclose(gainTunningFp); - control->gain_debug_mode = 0; - } else { - fclose(gainTunningFp); - if (0 == strncmp("debug=1", buffer, 7)) { - control->gain_debug_mode = 1; - } else { - control->gain_debug_mode = 0; - } - } - } else { - control->gain_debug_mode = 0; - } - } - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; + control->control_aif_before_path_set = conf.control_aif_before_path_set; + control->wb_enabled = __is_cp_wb(); + control->gain_debug_mode = conf.gain_debug_mode; + control->mute = AVSYS_AUDIO_UNMUTE; control->path_fixed = PATH_FIXED_NONE; @@ -414,13 +419,11 @@ int avsys_audio_path_ex_reset(int forced) avsys_audio_path_ex_info_t **temp = NULL; gain_info_t default_gain = { AVSYS_AUDIO_PLAYBACK_GAIN_AP, AVSYS_AUDIO_CAPTURE_GAIN_AP }; path_info_t default_path = { AVSYS_AUDIO_PATH_EX_SPK, AVSYS_AUDIO_PATH_EX_MIC }; - gain_status_t clean_gain_status = { GS_GAIN_NONE, GS_GAIN_NONE }; - path_status_t clean_path_status = { PS_PATH_NONE, PS_PATH_NONE }; - option_info_t default_option = { AVSYS_AUDIO_PATH_OPTION_JACK_AUTO, AVSYS_AUDIO_PATH_OPTION_JACK_AUTO }; + option_info_t default_option = { AVSYS_AUDIO_PATH_OPTION_NONE, AVSYS_AUDIO_PATH_OPTION_NONE }; int index = 0; int err = AVSYS_STATE_SUCCESS; int backup_debug = 0; - AudioSystemConf conf = { 1, 4 }; + avsys_audio_conf conf = { 0, }; /* Check root user */ err = avsys_check_root_privilege(); @@ -449,14 +452,10 @@ int avsys_audio_path_ex_reset(int forced) control->backup_gain = default_gain; control->backup_path = default_path; control->option = default_option; - control->gain_status = clean_gain_status; - control->path_status = clean_path_status; - control->p_gain_status = clean_gain_status; - control->p_path_status = clean_path_status; control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; control->inserted = AVSYS_AUDIO_INSERTED_NONE; - control->route_policy = AVSYS_AUDIO_ROUTE_POLICY_DEFAULT; + if (AVSYS_FAIL(__load_conf(&conf))) avsys_error_r(AVAUDIO, "Can not load audio system configuration file\n"); @@ -464,8 +463,13 @@ int avsys_audio_path_ex_reset(int forced) control->inserted = __avsys_audio_path_get_earjack_type(); if (control->inserted == AVSYS_AUDIO_INSERTED_NONE) control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - else + else { control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; + control->path.playback = AVSYS_AUDIO_PATH_EX_HEADSET; + + if (control->inserted == AVSYS_AUDIO_INSERTED_4) + control->path.capture = AVSYS_AUDIO_PATH_EX_HEADSETMIC; + } } else { avsys_warning(AVAUDIO, "Ignore headset detection. Use speaker device\n"); control->inserted = AVSYS_AUDIO_INSERTED_NONE; @@ -474,29 +478,9 @@ int avsys_audio_path_ex_reset(int forced) avsys_error_r(AVAUDIO, "Earjack init value is %d\n", control->inserted); - { - /* Gain tunning Debug mode */ - FILE *gainTunningFp = NULL; - if (NULL != (gainTunningFp = fopen("/opt/etc/gain_tuner.ini", "r"))) { - char buffer[32] = ""; - avsys_warning(AVAUDIO, "GAIN TUNNING DEBUG MODE...This degrade sound path performance\n"); - memset(buffer, '\0', sizeof(buffer)); - if (NULL == fgets(buffer, sizeof(buffer) - 1, gainTunningFp)) { - fclose(gainTunningFp); - control->gain_debug_mode = 0; - } else { - fclose(gainTunningFp); - if (0 == strncmp("debug=1", buffer, 7)) { - control->gain_debug_mode = 1; - } else { - control->gain_debug_mode = 0; - } - } - } else { - control->gain_debug_mode = 0; - } - } - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; + control->control_aif_before_path_set = conf.control_aif_before_path_set; + control->gain_debug_mode = conf.gain_debug_mode; + control->mute = AVSYS_AUDIO_UNMUTE; control->path_fixed = PATH_FIXED_NONE; @@ -545,7 +529,7 @@ int avsys_audio_path_ex_dump(void) const static char *str_yn[] = { "NO", "YES" }; const static char *str_ear[] = { "MANUAL", "AUTO_MUTE", "AUTO_NOMUTE" }; const static char *str_out[AVSYS_AUDIO_PATH_EX_OUTMAX] = { - "NONE", "SPK", "RECV", "HEADSET", "BTHEADSET", "A2DP", "HANSFREE" + "NONE", "SPK", "RECV", "HEADSET", "BTHEADSET", "A2DP", "HANSFREE", "HDMI", "DOCK", "USBAUDIO" }; const static char *str_in[AVSYS_AUDIO_PATH_EX_INMAX] = { "NONE", "MIC", "HEADMIC", "BTMIC", "FMINPUT", "HANSFREEMIC" @@ -589,10 +573,7 @@ int avsys_audio_path_ex_dump(void) str_playback_gain[control->gain.playback], str_capture_gain[control->gain.capture]); fprintf(stdout, " Current Out / In : %-s / %-s\n", str_out[control->path.playback], str_in[control->path.capture] ); fprintf(stdout, " Gain debug mode : 0x%-x\n", control->gain_debug_mode); - fprintf(stdout, " Gain status : 0x%x 0x%x\n", control->gain_status.playback, control->gain_status.capture); - fprintf(stdout, " Path status : 0x%x 0x%x\n", control->path_status.playback, control->path_status.capture); fprintf(stdout, " Auto EarJack Control : %-s\n", str_ear[control->ear_auto]); - fprintf(stdout, " Audio Route Policy : %-s\n", str_route[control->route_policy]); fprintf(stdout, " Physical Earjack? [type] : %-s [%-s]\n", str_yn[control->inserted != AVSYS_AUDIO_INSERTED_NONE], str_earType[control->inserted]); fprintf(stdout, " Path Fixed State : 0x%-x\n", control->path_fixed); fprintf(stdout, " Mute status : %d\n", control->mute); @@ -607,9 +588,6 @@ int avsys_audio_path_ex_dump(void) fprintf(stdout, " Path sync lock required PIDs : %d\n", control->pathlock_pid[index]); index++; } while (index < AVSYS_AUDIO_LOCK_SLOT_MAX); - fprintf(stdout, " Option Lagacy : %-s\n", str_yn[(control->option.playback & AVSYS_AUDIO_PATH_OPTION_LEGACY_MODE) ? 1 : 0]); - fprintf(stdout, " Option Jack Playback : %-s\n", str_yn[(control->option.playback & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) ? 1 : 0]); - fprintf(stdout, " Option Jack Capture : %-s\n", str_yn[(control->option.capture & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) ? 1 : 0]); fprintf(stdout, " Option Dual out : %-s\n", str_yn[(control->option.playback & AVSYS_AUDIO_PATH_OPTION_DUAL_OUT) ? 1 : 0]); fprintf(stdout, " Option Forced : %-s\n", str_yn[(control->option.playback & AVSYS_AUDIO_PATH_OPTION_FORCED) ? 1 : 0]); @@ -668,7 +646,7 @@ int avsys_audio_path_earjack_init(int *init_type, int *outfd) #if !defined(_MMFW_I386_ALL_SIMULATOR) char eventnode_filename[32] = { 0, }; int fd = 0; - AudioSystemConf conf = { 1, 4 }; + avsys_audio_conf conf = { 0, }; if (outfd == NULL || init_type == NULL) { avsys_error(AVAUDIO, "input parameter is null\n"); @@ -681,10 +659,10 @@ int avsys_audio_path_earjack_init(int *init_type, int *outfd) if (!conf.headset_detection) { avsys_error(AVAUDIO, "Earjack control daemon will be closed by user option...\n"); - return AVSYS_STATE_SUCCESS; + return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT; } - snprintf(eventnode_filename, sizeof(eventnode_filename), "/dev/event%01d", conf.headset_node_number); + snprintf(eventnode_filename, sizeof(eventnode_filename), "%s%01d", EARJACK_EVENT_PATH, conf.headset_node_number); fd = open(eventnode_filename, O_RDONLY); if (fd == -1) { @@ -699,14 +677,17 @@ int avsys_audio_path_earjack_init(int *init_type, int *outfd) if(AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, &vol_data))) { avsys_error(AVAUDIO,"attach logical volume shared memory failed\n"); + close(fd); return AVSYS_STATE_ERR_ALLOCATION; } if(AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE, &handle_data))) { avsys_error(AVAUDIO,"attach handle shared memory failed\n"); + close(fd); return AVSYS_STATE_ERR_ALLOCATION; } if(AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void**)temp))) { avsys_error_r(AVAUDIO,"avsys_audio_get_shm() failed in %s\n", __func__); + close(fd); return AVSYS_STATE_ERR_INTERNAL; } @@ -725,9 +706,8 @@ int avsys_audio_path_earjack_wait(int fd, int *current_type, int *new_type, int fd_set set; int readtemp; int select_ret = 0; - struct avsys_audio_jack_event jevent; + struct input_event jevent; int res = AVSYS_STATE_SUCCESS; - int set_flag = 0; int cur_type = -1; if (new_type == NULL || is_auto_mute == NULL) @@ -774,8 +754,6 @@ int avsys_audio_path_earjack_wait(int fd, int *current_type, int *new_type, int } else { readtemp = 0; } - - set_flag = 1; /* need change earphone status */ break; default: readtemp = cur_type; /* same value */ @@ -802,17 +780,10 @@ int avsys_audio_path_earjack_wait(int fd, int *current_type, int *new_type, int *current_type = control->inserted; *is_auto_mute = 0; res = AVSYS_STATE_SUCCESS; - } else if (control->ear_auto == AVSYS_AUDIO_EAR_SWITCH_MANUAL) { - *is_auto_mute = 0; - /* return warning */ - if (set_flag) { - control->inserted = *new_type; - set_flag = 0; - } - res = AVSYS_STATE_WAR_INTERNAL; } return res; + #else return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT; #endif @@ -834,27 +805,6 @@ int avsys_audio_path_earjack_process(int new_type) control->inserted = new_type; - if (control->ear_auto == AVSYS_AUDIO_EAR_SWITCH_MANUAL) { - return AVSYS_STATE_SUCCESS; - } - - /* Capture/Playback Gain Control */ - avsys_warning(AVAUDIO, "Gain C(%d), P(%d)\n", control->gain.capture, control->gain.playback); - err = capture_gain_func_table[control->gain.capture] (control); - if (AVSYS_FAIL(err)) { - avsys_error_r(AVAUDIO, "earjack change failed for %d gain : error 0x%x\n", control->gain.capture, err); - } - - err = playback_gain_func_table[control->gain.playback] (control); - if (AVSYS_SUCCESS(err)) { - /* H/W Control */ - err = __avsys_audio_path_set_hw_controls(control); - if (AVSYS_FAIL(err)) { - avsys_error_r(AVAUDIO, "__avsys_audio_path_set_hw_controls() failed in %s\n", __func__); - } - } else - avsys_error_r(AVAUDIO, "earjack change failed for %d gain : error 0x%x\n", control->gain.playback, err); - return err; #else return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT; @@ -889,58 +839,119 @@ int avsys_audio_path_earjack_unlock() enum { CMD_DEVICE_NONE = 0, CMD_DEVICE_OPEN, - CMD_DEVICE_CLOSE, + CMD_DEVICE_CLOSE, /* Not used */ CMD_DEVICE_MAX }; -avsys_audio_alsa_aif_handle_t *g_hAIF[AIF_DEVICE_MAX] = { NULL, NULL, NULL, NULL }; -char *strAIF[AIF_DEVICE_MAX] = { "AIF2 Capture", "AIF2 Playback", "AIF3 Capture", "AIF3 Playback" }; +avsys_audio_alsa_aif_handle_t *g_hAIF[AIF_DEVICE_MAX] = { NULL, NULL, NULL, NULL, NULL }; +char *strAIF[AIF_DEVICE_MAX] = { "AIF CP Capture", "AIF CP Playback", "AIF BT Capture", "AIF BT Playback", "AIF RADIO Playback" }; -#define SET_AIF(index) \ -do { \ - if(g_hAIF[index]) { \ - avsys_warning(AVAUDIO,#index" device already opened\n"); \ - AIF_control[index] = CMD_DEVICE_NONE; \ - } else { \ - AIF_control[index] = CMD_DEVICE_OPEN; \ - } \ -} while (0) +#define SET_AIF(index) do { AIF_control[index] = CMD_DEVICE_OPEN; } while (0) + +static int __is_cp_aif (int type) +{ + return ((type == AIF_CP_PLAYBACK || type == AIF_CP_CAPTURE)); +} -static int __avsys_open_aif(char AIF_control[]) +static int __avsys_open_aif(char AIF_control[], bool wb_enabled) { int iAIF = 0; int err = AVSYS_STATE_SUCCESS; + bool bt_enabled = 0; + aif_rate_t rate = 0; + /* Check If BT is enabled */ + for (iAIF = 0; iAIF < AIF_DEVICE_MAX; iAIF++) { + if (AIF_control[iAIF] == CMD_DEVICE_OPEN && (iAIF == AIF_BT_PLAYBACK || iAIF== AIF_BT_CAPTURE)) { + bt_enabled = true; + break; + } + } + + /* Iterate control command */ + avsys_info(AVAUDIO, "================== Close if reopen is needed (bt[%d] wb[%d]) ================== \n", bt_enabled, wb_enabled); for (iAIF = 0; iAIF < AIF_DEVICE_MAX; iAIF++) { /* check command */ if (AIF_control[iAIF] != CMD_DEVICE_OPEN) continue; - /* check handle allocation */ + avsys_info(AVAUDIO, "%d. [%s]\n", iAIF, strAIF[iAIF]); + + /* check handle exists */ if (g_hAIF[iAIF]) { - avsys_warning(AVAUDIO, "Oops! Free %s device handle first", strAIF[iAIF]); - free(g_hAIF[iAIF]); - g_hAIF[iAIF] = NULL; + /* Handle is already opened. + * Check if WB is supported and CP handle case */ + if (wb_enabled && __is_cp_aif(g_hAIF[iAIF]->type)) { + /* CP Handle is already opened with WB enabled . + * Determine whether re-open is needed */ + if ((bt_enabled && g_hAIF[iAIF]->rate != AIF_NB_RATE) || + (!bt_enabled && g_hAIF[iAIF]->rate == AIF_NB_RATE)) { + /* CP handle exists and BT enabled with not NB opened => close for reopen + CP handle exists and BT disabled with NB opened => close for reopen */ + avsys_info(AVAUDIO, "=> Close device for reopen :: %s\n", strAIF[iAIF]); + if (AVSYS_FAIL(avsys_audio_alsa_close_AIF_device(g_hAIF[iAIF]))) { + avsys_error_r(AVAUDIO, "close %s device failed\n", strAIF[iAIF]); + } + free(g_hAIF[iAIF]); + g_hAIF[iAIF] = NULL; + } else { + /* CP handle exists and BT enabled with NB opened || + CP handle exists and BT disabled with not NB opened */ + avsys_info(AVAUDIO, "=> Skip device :: %s\n", strAIF[iAIF]); + continue; + } + + } else { + /* Not CP case or WB is disabled. No need to reopen */ + avsys_info(AVAUDIO, "=> Skip device :: %s\n", strAIF[iAIF]); + continue; + } + } + } + + avsys_info(AVAUDIO, "================== Open & Set Param ================== \n"); + /* Iterate control command */ + for (iAIF = 0; iAIF < AIF_DEVICE_MAX; iAIF++) { + /* check command */ + if (AIF_control[iAIF] != CMD_DEVICE_OPEN) + continue; + + avsys_info(AVAUDIO, "%d. [%s]\n", iAIF, strAIF[iAIF]); + + /* check handle exists */ + if (g_hAIF[iAIF]) { + /* Not CP case or WB is disabled. No need to reopen */ + avsys_info(AVAUDIO, "=> Skip device Already opened!!! :: %s\n", strAIF[iAIF]); + continue; } + /* memory allocation for handle */ - avsys_warning(AVAUDIO, "%s handle alloc", strAIF[iAIF]); + avsys_warning(AVAUDIO, "=> [%s] handle alloc", strAIF[iAIF]); g_hAIF[iAIF] = calloc(sizeof(avsys_audio_handle_t), 1); if (!g_hAIF[iAIF]) { - avsys_error_r(AVAUDIO, "Can not alloc memory for %s device handle", strAIF[iAIF]); + avsys_error_r(AVAUDIO, "=> Can not alloc memory for [%s] device handle", strAIF[iAIF]); err = AVSYS_STATE_ERR_ALLOCATION; continue; } if (AVSYS_FAIL(avsys_audio_alsa_open_AIF_device(iAIF, g_hAIF[iAIF]))) { - avsys_error_r(AVAUDIO, "open %s device failed\n", strAIF[iAIF]); + avsys_error_r(AVAUDIO, "=> open [%s] device failed\n", strAIF[iAIF]); err = AVSYS_STATE_ERR_INVALID_HANDLE; } else { - avsys_warning(AVAUDIO, "open %s device success\n", strAIF[iAIF]); - if (AVSYS_FAIL(avsys_audio_alsa_set_AIF_params(g_hAIF[iAIF]))) { - avsys_error_r(AVAUDIO, "%s device set parameter failed\n", strAIF[iAIF]); + avsys_warning(AVAUDIO, "=> open [%s] device success\n", strAIF[iAIF]); + + /* Select RATE */ + if (__is_cp_aif(g_hAIF[iAIF]->type)) { + rate = (wb_enabled && !bt_enabled)? AIF_WB_RATE : AIF_NB_RATE; + } else { + rate = AIF_CONF_RATE; + } + + if (AVSYS_FAIL(avsys_audio_alsa_set_AIF_params(g_hAIF[iAIF],rate))) { + avsys_error_r(AVAUDIO, "=> [%s] device set parameter failed\n", strAIF[iAIF]); err = AVSYS_STATE_ERR_INVALID_PARAMETER; } else { - avsys_warning(AVAUDIO, "%s device set parameter success\n", strAIF[iAIF]); + avsys_warning(AVAUDIO, "=> [%s] device set parameter success\n", strAIF[iAIF]); } } } @@ -970,6 +981,7 @@ static int __avsys_audio_release_path (gain_info_t local_gain, avsys_audio_path_ { int err = AVSYS_STATE_SUCCESS; int iAIF = 0; + bool close_aif_later = false; avsys_warning(AVAUDIO, "Release path for %d %d\n", local_gain.playback, local_gain.capture); @@ -977,14 +989,15 @@ static int __avsys_audio_release_path (gain_info_t local_gain, avsys_audio_path_ case AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL: case AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL: if (getpid() == control->path_fixed_pid[PATH_FIXED_TYPE_CALL]) { -#ifndef OPEN_AIF_BEFORE_SCENARIO_SET /* FIXME : disable here, close after scenario set */ - __avsys_close_aif(); -#endif + if (!control->control_aif_before_path_set) { + __avsys_close_aif(); + } else { + close_aif_later = true; + } if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_CODEC_DISABLE_ON_SUSPEND))) { avsys_error_r(AVAUDIO, "[%s] failed to set codec_disable_on_suspend\n", __func__); } - control->p_path_status.playback |= PS_CODEC_DISABLE_ON_SUSPEND; } else { if (control->path_fixed_pid[PATH_FIXED_TYPE_CALL] < 0) { avsys_warning(AVAUDIO, "Sound path for call released already\n"); @@ -1007,20 +1020,11 @@ static int __avsys_audio_release_path (gain_info_t local_gain, avsys_audio_path_ if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_CODEC_DISABLE_ON_SUSPEND))) { avsys_error_r(AVAUDIO, "[%s] failed to set codec_disable_on_suspend\n", __func__); } - control->p_path_status.playback |= PS_CODEC_DISABLE_ON_SUSPEND; - if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET))) { + if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET_CAPTURE))) { avsys_error_r(AVAUDIO, "[%s] failed to set reset\n", __func__); - } else { - control->p_path_status.playback = PS_PATH_NONE; } - /* TODO: Path fixed clear (path_fixed, path_fixed_pid) */ - if ((control->path_fixed & PATH_FIXED_WITH_FMRADIO) == 0) { - avsys_error(AVAUDIO, "FM-Radio path release without radio path request\n"); - } - control->path_fixed &= ~PATH_FIXED_WITH_FMRADIO; - control->path_fixed_pid[PATH_FIXED_TYPE_FMRADIO] = -1; break; default: @@ -1037,31 +1041,12 @@ static int __avsys_audio_release_path (gain_info_t local_gain, avsys_audio_path_ control->gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_AP; control->path.playback = AVSYS_AUDIO_PATH_EX_SPK; control->path.capture = AVSYS_AUDIO_PATH_EX_MIC; - - switch(control->route_policy) - { - case AVSYS_AUDIO_ROUTE_POLICY_DEFAULT: - case AVSYS_AUDIO_ROUTE_POLICY_IGNORE_A2DP: - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE; - control->option.playback = AVSYS_AUDIO_PATH_OPTION_JACK_AUTO; - control->option.capture = AVSYS_AUDIO_PATH_OPTION_JACK_AUTO; - break; - - case AVSYS_AUDIO_ROUTE_POLICY_HANDSET_ONLY: - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE; - control->option.playback = AVSYS_AUDIO_PATH_OPTION_NONE; - control->option.capture = AVSYS_AUDIO_PATH_OPTION_NONE; - break; - - default: - break; + if (control->inserted != AVSYS_AUDIO_INSERTED_NONE) { + control->path.playback = AVSYS_AUDIO_PATH_EX_HEADSET; + if (control->inserted == AVSYS_AUDIO_INSERTED_4) + control->path.capture = AVSYS_AUDIO_PATH_EX_HEADSETMIC; } - control->p_path_status.playback = PS_PATH_NONE; - control->p_path_status.capture = PS_PATH_NONE; - control->p_gain_status.playback = GS_GAIN_NONE; - control->p_gain_status.capture = GS_GAIN_NONE; - /* Playback */ err = __avsys_audio_path_set_ascn_ap_playback(control); if (AVSYS_SUCCESS(err)) { @@ -1080,17 +1065,43 @@ static int __avsys_audio_release_path (gain_info_t local_gain, avsys_audio_path_ } } - /* FIXME : Close AIF, this will be moved before scneario set */ -#ifdef OPEN_AIF_BEFORE_SCENARIO_SET - if ((local_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL || local_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL) && - getpid() == control->path_fixed_pid[PATH_FIXED_TYPE_CALL]) { - __avsys_close_aif(); + if (close_aif_later == true) { + __avsys_close_aif(); } -#endif return err; } +int avsys_audio_path_earjack_get_type() +{ + avsys_audio_path_ex_info_t *control = NULL; + avsys_audio_path_ex_info_t **temp = NULL; + int err = AVSYS_STATE_SUCCESS; + int ret = 0; + + temp = &control; + if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) { + avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__); + return AVSYS_STATE_ERR_INTERNAL; + } + if (control == NULL) + return AVSYS_STATE_ERR_NULL_POINTER; + + if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) { + avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__); + return AVSYS_STATE_ERR_INTERNAL; + } + + ret = control->inserted; + + if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) { + avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__); + return AVSYS_STATE_ERR_INTERNAL; + } + + return ret; +} + int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) { avsys_audio_path_ex_info_t *control = NULL; @@ -1100,7 +1111,7 @@ int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) pid_t current_pid; int err = AVSYS_STATE_SUCCESS; char req_release_path = 0; - char AIF_control[AIF_DEVICE_MAX] = { CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE }; + char AIF_control[AIF_DEVICE_MAX] = { CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE }; int iAIF = 0; avsys_warning(AVAUDIO, "=================== [Input Param] gain %d, out %d, in %d, opt 0x%x ====================\n", gain, out, in, option); @@ -1114,6 +1125,7 @@ int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) case AVSYS_AUDIO_GAIN_EX_CAMERA: case AVSYS_AUDIO_GAIN_EX_GAME: req_gain.playback = AVSYS_AUDIO_PLAYBACK_GAIN_AP; + req_gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_AP; break; case AVSYS_AUDIO_GAIN_EX_RINGTONE: @@ -1179,11 +1191,6 @@ int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) control->path_fixed &= ~PATH_FIXED_WITH_CALL; } } - if (control->path_fixed & PATH_FIXED_WITH_FMRADIO) { - if (AVSYS_FAIL(avsys_check_process(control->path_fixed_pid[PATH_FIXED_TYPE_FMRADIO]))) { - control->path_fixed &= ~PATH_FIXED_WITH_FMRADIO; - } - } if (control->path_fixed == PATH_FIXED_NONE) { /* forced gain setting when path fixed by dead process */ if (req_gain.playback != local_gain.playback) { @@ -1246,26 +1253,30 @@ int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) control->backup_path.playback = out; switch (local_gain.playback) { - case AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL: - control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid; case AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT: if (control->path.playback == AVSYS_AUDIO_PATH_EX_BTHEADSET) { - SET_AIF(AIF3_PLAYBACK); - SET_AIF(AIF3_CAPTURE); + SET_AIF(AIF_BT_PLAYBACK); + SET_AIF(AIF_BT_CAPTURE); } break; case AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL: - control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid; - SET_AIF(AIF2_PLAYBACK); + case AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL: + /* Set CP only for voicecall */ + if (local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL) { + SET_AIF(AIF_CP_PLAYBACK); + } + /* Voicecall / Videocall Common setting */ + control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid; if (control->path.playback == AVSYS_AUDIO_PATH_EX_BTHEADSET) { - SET_AIF(AIF3_PLAYBACK); + SET_AIF(AIF_BT_PLAYBACK); } break; case AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO: control->path_fixed_pid[PATH_FIXED_TYPE_FMRADIO] = current_pid; + SET_AIF(AIF_RADIO_PLAYBACK); break; } } @@ -1285,19 +1296,17 @@ int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) control->backup_path.capture = in; switch (local_gain.capture) { + case AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL: case AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL: - control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid; - if (control->path.capture == AVSYS_AUDIO_PATH_EX_BTMIC) { - SET_AIF(AIF3_CAPTURE); + /* Set CP only for voicecall */ + if (local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL) { + SET_AIF(AIF_CP_CAPTURE); } - break; - case AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL: + /* Voicecall / Videocall Common setting */ control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid; - SET_AIF(AIF2_CAPTURE); - if (control->path.capture == AVSYS_AUDIO_PATH_EX_BTMIC) { - SET_AIF(AIF3_CAPTURE); + SET_AIF(AIF_BT_CAPTURE); } break; @@ -1309,10 +1318,9 @@ int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) } /* Open AIFs */ - /* FIXME: this will be moved to after alsa scenraio set */ -#ifdef OPEN_AIF_BEFORE_SCENARIO_SET - err = __avsys_open_aif(AIF_control); -#endif + if (control->control_aif_before_path_set) { + err = __avsys_open_aif(AIF_control, control->wb_enabled); + } /* Do ALSA scenario control based on gain */ /* Playback */ @@ -1346,9 +1354,10 @@ int avsys_audio_path_ex_set_path(int gain, int out, int in, int option) avsys_warning(AVAUDIO, "capture gain : ap\n"); err = __avsys_audio_path_set_ascn_ap_capture(control); } -#ifndef OPEN_AIF_BEFORE_SCENARIO_SET - err = __avsys_open_aif(AIF_control); -#endif + + if (!control->control_aif_before_path_set) { + err = __avsys_open_aif(AIF_control, control->wb_enabled); + } FINISHED: /* UnLOCK */ @@ -1566,129 +1575,61 @@ static int __avsys_audio_path_set_ascn_ap_playback(avsys_audio_path_ex_info_t *c switch (control->path.playback) { case AVSYS_AUDIO_PATH_EX_SPK: - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_LEGACY_MODE) { - avsys_warning(AVAUDIO, "Does not support legacy mode anymore\n"); - } - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_DUAL_OUT) { if (callalert_mode) { - control->gain_status.playback = GS_AP_TO_SPK_CALLALERT; cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_CALLALERT; + cmd_gain[1] = INPUT_AP | OUTPUT_HEADSET | GAIN_CALLALERT; } else { - control->gain_status.playback = GS_AP_TO_SPK; cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; + cmd_gain[1] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; } - if (control->inserted == AVSYS_AUDIO_INSERTED_NONE) { - control->path_status.playback = PS_AP_TO_SPK; - cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; - } else { - control->path_status.playback = PS_AP_TO_SPK | PS_AP_TO_HEADSET; - cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; - cmd_path[1] = INPUT_AP | OUTPUT_HEADSET; - } + cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; + cmd_path[1] = INPUT_AP | OUTPUT_HEADSET; + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; } else { - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE; - if (control->inserted == AVSYS_AUDIO_INSERTED_NONE) { - if (callalert_mode) { - control->gain_status.playback = GS_AP_TO_SPK_CALLALERT; - cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_CALLALERT; - } else { - control->gain_status.playback = GS_AP_TO_SPK; - cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; - } - control->path_status.playback = PS_AP_TO_SPK; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; - } else { - if (callalert_mode) { - control->gain_status.playback = GS_AP_TO_HEADSET_CALLALERT; - cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_CALLALERT; - } else { - control->gain_status.playback = GS_AP_TO_HEADSET; - cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; - } - control->path_status.playback = PS_AP_TO_HEADSET; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; - cmd_path[0] = INPUT_AP | OUTPUT_HEADSET; - } + if (callalert_mode) { + cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_CALLALERT; } else { - if (callalert_mode) { - control->gain_status.playback = GS_AP_TO_SPK_CALLALERT; - cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_CALLALERT; - } else { - control->gain_status.playback = GS_AP_TO_SPK; - cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; - } - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE; - control->path_status.playback = PS_AP_TO_SPK; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - - cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; + cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; } + control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE; + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + + cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; } break; case AVSYS_AUDIO_PATH_EX_RECV: - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_LEGACY_MODE) { - avsys_warning(AVAUDIO, "Does not support legacy mode anymore\n"); - } - - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE; - if (control->inserted == AVSYS_AUDIO_INSERTED_NONE) { - control->gain_status.playback = GS_AP_TO_RECV; - control->path_status.playback = PS_AP_TO_RECV; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - cmd_gain[0] = INPUT_AP | OUTPUT_RECV | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_RECV; - } else { - if (callalert_mode) { - control->gain_status.playback = GS_AP_TO_HEADSET_CALLALERT; - cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_CALLALERT; - } else { - control->gain_status.playback = GS_AP_TO_HEADSET; - cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; - } - control->path_status.playback = PS_AP_TO_HEADSET; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; - cmd_path[0] = INPUT_AP | OUTPUT_HEADSET; - } - } else { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.playback = GS_AP_TO_RECV; - control->path_status.playback = PS_AP_TO_RECV; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - cmd_gain[0] = INPUT_AP | OUTPUT_RECV | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_RECV; - } + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + cmd_gain[0] = INPUT_AP | OUTPUT_RECV | GAIN_MODE; + cmd_path[0] = INPUT_AP | OUTPUT_RECV; break; case AVSYS_AUDIO_PATH_EX_HEADSET: - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; if (callalert_mode) { - control->gain_status.playback = GS_AP_TO_HEADSET_CALLALERT; cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_CALLALERT; } else { - control->gain_status.playback = GS_AP_TO_HEADSET; cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; } - control->path_status.playback = PS_AP_TO_HEADSET; control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; cmd_path[0] = INPUT_AP | OUTPUT_HEADSET; break; case AVSYS_AUDIO_PATH_EX_HDMI: - avsys_warning(AVAUDIO, "Does not support dedicated HDMI sound path\n"); control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + cmd_gain[0] = INPUT_AP | OUTPUT_HDMI | GAIN_MODE; + cmd_path[0] = INPUT_AP | OUTPUT_HDMI; + break; + + case AVSYS_AUDIO_PATH_EX_DOCK: + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + cmd_gain[0] = INPUT_AP | OUTPUT_DOCK | GAIN_MODE; + cmd_path[0] = INPUT_AP | OUTPUT_DOCK; break; case AVSYS_AUDIO_PATH_EX_BTHEADSET: - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.playback = GS_AP_TO_BT; - control->path_status.playback = PS_AP_TO_BT; control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET; cmd_gain[0] = INPUT_AP | OUTPUT_BT_HEADSET | GAIN_MODE; cmd_path[0] = INPUT_AP | OUTPUT_BT_HEADSET; @@ -1699,14 +1640,9 @@ static int __avsys_audio_path_set_ascn_ap_playback(avsys_audio_path_ex_info_t *c break; } - //avsys_warning(AVAUDIO,"pg(0x%X), g(0x%X), pp(0x%X), p(0x%X)\n", control->p_gain_status, control->gain_status, control->p_path_status, control->path_status); - if ((control->p_path_status.playback != control->path_status.playback) || control->gain_debug_mode == 1) { - avsys_warning(AVAUDIO, "Run Alsa Scenario Script\n"); - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 1, ASCN_RESET_PLAYBACK)) - control->p_gain_status.playback = control->gain_status.playback; - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE)) - control->p_path_status.playback = control->path_status.playback; - } + avsys_warning(AVAUDIO, "Run Alsa Scenario Script\n"); + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_PLAYBACK)) + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE)) avsys_info(AVAUDIO, ">> leave"); return AVSYS_STATE_SUCCESS; @@ -1714,6 +1650,139 @@ static int __avsys_audio_path_set_ascn_ap_playback(avsys_audio_path_ex_info_t *c static int __avsys_audio_path_set_ascn_voicecall(avsys_audio_path_ex_info_t *control) { + int cmd_gain[6] = { 0, 0, 0, 0, 0, 0 }; + int cmd_path[6] = { 0, 0, 0, 0, 0, 0 }; + int gain_idx = 0; + int path_idx = 0; + control->path_fixed = PATH_FIXED_WITH_CALL; + + avsys_info(AVAUDIO, "<< path.playback = %d, option = %x, gain.playback = %d, inserted = %d\n", + control->path.playback, control->option.playback, control->gain.playback, control->inserted); + + /* PLAYBACK */ + switch (control->path.playback) { + case AVSYS_AUDIO_PATH_EX_NONE: + avsys_warning(AVAUDIO, "[SZ] playback AVSYS_AUDIO_PATH_EX_NONE\n"); + break; + + case AVSYS_AUDIO_PATH_EX_SPK: + if (control->reqgain.playback == control->gain.playback) { + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; + cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_STEREO_SPK | GAIN_VOICE_CALL; + cmd_path[path_idx++] = INPUT_CP | OUTPUT_STEREO_SPK; + } else { + avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n"); + } + break; + + case AVSYS_AUDIO_PATH_EX_RECV: + if (control->gain.playback == control->reqgain.playback) { + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_RECV | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_RECV; + cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_RECV | GAIN_VOICE_CALL; + cmd_path[path_idx++] = INPUT_CP | OUTPUT_RECV; + } else { + avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n"); + } + break; + + case AVSYS_AUDIO_PATH_EX_HEADSET: + if (control->reqgain.playback == control->gain.playback) { + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET; + cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_HEADSET | GAIN_VOICE_CALL; + cmd_path[path_idx++] = INPUT_CP | OUTPUT_HEADSET; + } else { + avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n"); + } + break; + + case AVSYS_AUDIO_PATH_EX_BTHEADSET: + + if (control->reqgain.playback == control->gain.playback) { + control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE; + cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_BT_HEADSET | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_BT_HEADSET; + cmd_path[path_idx++] = INPUT_CP | OUTPUT_BT_HEADSET; + } else { + avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n"); + } + break; + + case AVSYS_AUDIO_PATH_EX_HANDSFREE: + default: + if (control->reqgain.playback == control->gain.playback) { + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + } + break; + } + + + /* Add sound path CP to AP (Rx recording) */ + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) { + avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n"); + //cmd_path[path_idx++] = INPUT_CP | OUTPUT_AP; + } + + + /* CAPTURE */ + switch (control->path.capture) { + case AVSYS_AUDIO_PATH_EX_NONE: + avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_EX_NONE\n"); + break; + + case AVSYS_AUDIO_PATH_EX_MIC: + if (control->reqgain.capture == control->gain.capture) { + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) { + cmd_gain[gain_idx++] = INPUT_SUB_MIC | OUTPUT_CP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_SUB_MIC | OUTPUT_CP; + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) { + avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n"); + //cmd_path[path_idx++] = INPUT_SUB_MIC | OUTPUT_AP; + } + } else { + cmd_gain[gain_idx++] = INPUT_MAIN_MIC | OUTPUT_CP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_MAIN_MIC | OUTPUT_CP; + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) { + avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n"); + //cmd_path[path_idx++] = INPUT_MAIN_MIC | OUTPUT_AP; + } + } + } + break; + + case AVSYS_AUDIO_PATH_EX_HEADSETMIC: + if (control->reqgain.capture == control->gain.capture) { + cmd_gain[gain_idx++] = INPUT_EAR_MIC | OUTPUT_CP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_EAR_MIC | OUTPUT_CP; + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) { + avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n"); + //cmd_path[path_idx++] = INPUT_EAR_MIC | OUTPUT_AP; + } + } + break; + + case AVSYS_AUDIO_PATH_EX_BTMIC: + if (control->reqgain.capture == control->gain.capture) { + cmd_gain[gain_idx++] = INPUT_BT_MIC | OUTPUT_CP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_BT_MIC | OUTPUT_CP; + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) { + avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n"); + //avsys_error(AVAUDIO, "BT Call recording is not supported"); + } + } + break; + case AVSYS_AUDIO_PATH_EX_HANDSFREE: + default: + break; + } + + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET)); + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 6, ASCN_RESET_NONE)); + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 6, ASCN_RESET_NONE)); + + avsys_info(AVAUDIO, ">> leave"); return AVSYS_STATE_SUCCESS; } @@ -1721,90 +1790,39 @@ static int __avsys_audio_path_set_ascn_videocall(avsys_audio_path_ex_info_t *con { int cmd_gain[2] = { 0, 0 }; int cmd_path[3] = { 0, 0, 0 }; - int skip_clear = 0; + int gain_idx = 0; + int path_idx = 0; + control->path_fixed = PATH_FIXED_WITH_CALL; switch (control->path.playback) { case AVSYS_AUDIO_PATH_EX_NONE: - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_LEGACY_MODE) { - /* Legacy mode does not effect here... */ - avsys_warning(AVAUDIO, "legacy mode option %s\n", __func__); - } - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - if (control->reqgain.playback == control->gain.playback) { - avsys_warning(AVAUDIO, "Output block on videocall"); - } else { - avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall"); - } - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + avsys_warning(AVAUDIO, "[SZ] playback AVSYS_AUDIO_PATH_EX_NONE\n"); break; case AVSYS_AUDIO_PATH_EX_SPK: if (control->reqgain.playback == control->gain.playback) { - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE; - if (control->inserted != AVSYS_AUDIO_INSERTED_NONE) { - control->gain_status.playback = GS_AP_TO_HEADSET; - control->path_status.playback = PS_AP_TO_HEADSET; - cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_HEADSET; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; - } else { - control->gain_status.playback = GS_AP_TO_SPK; - control->path_status.playback = PS_AP_TO_SPK; - cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - } - } else { /* ear jack manual */ - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.playback = GS_AP_TO_SPK; - control->path_status.playback = PS_AP_TO_SPK; - cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - } - } else { /* changed by priority */ + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + } else { avsys_warning(AVAUDIO, "Sound Path request during VT call ignored."); } break; case AVSYS_AUDIO_PATH_EX_RECV: if (control->gain.playback == control->reqgain.playback) { - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE; - if (control->inserted != AVSYS_AUDIO_INSERTED_NONE) { - control->gain_status.playback = GS_AP_TO_HEADSET; - control->path_status.playback = PS_AP_TO_HEADSET; - cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_HEADSET; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; - } else { - control->gain_status.playback = GS_AP_TO_RECV; - control->path_status.playback = PS_AP_TO_RECV; - cmd_gain[0] = INPUT_AP | OUTPUT_RECV | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_RECV; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - } - } else { /* ear jack manual */ - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.playback = GS_AP_TO_RECV; - control->path_status.playback = PS_AP_TO_RECV; - cmd_gain[0] = INPUT_AP | OUTPUT_RECV | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_RECV; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - } - } else { /* changed by priority */ + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_RECV | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_RECV; + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + } else { avsys_warning(AVAUDIO, "Sound Path request during VT call ignored."); - } /* reqgain, gain */ + } break; case AVSYS_AUDIO_PATH_EX_HEADSET: if (control->reqgain.playback == control->gain.playback) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.playback = GS_AP_TO_HEADSET; - control->path_status.playback = PS_AP_TO_HEADSET; - cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_HEADSET; + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET; control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; } else { avsys_warning(AVAUDIO, "Sound Path request during VT call ignored."); @@ -1813,11 +1831,8 @@ static int __avsys_audio_path_set_ascn_videocall(avsys_audio_path_ex_info_t *con case AVSYS_AUDIO_PATH_EX_BTHEADSET: if (control->reqgain.playback == control->gain.playback) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.playback = GS_AP_TO_BT; - control->path_status.playback = PS_AP_TO_BT; - cmd_gain[0] = INPUT_AP | OUTPUT_BT_HEADSET | GAIN_MODE; - cmd_path[0] = INPUT_AP | OUTPUT_BT_HEADSET; + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_BT_HEADSET | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_BT_HEADSET; control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET; } else { avsys_warning(AVAUDIO, "Sound Path request during VT call ignored."); @@ -1834,61 +1849,27 @@ static int __avsys_audio_path_set_ascn_videocall(avsys_audio_path_ex_info_t *con switch (control->path.capture) { case AVSYS_AUDIO_PATH_EX_NONE: - if (control->reqgain.capture == control->gain.capture) { - /* Clear modem input */ - control->path_status.capture &= ~(PS_MAINMIC_TO_AP | PS_SUBMIC_TO_AP | PS_EARMIC_TO_AP | PS_BTMIC_TO_AP); - } else { - avsys_warning(AVAUDIO, "Ignore another path setting request during VT call (input)\n"); - } + avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_EX_NONE\n"); break; case AVSYS_AUDIO_PATH_EX_MIC: - if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) { - if ((control->inserted == AVSYS_AUDIO_INSERTED_4) && (control->path_status.playback & PS_AP_TO_HEADSET)) { - control->gain_status.capture |= GS_EARMIC_TO_AP; - control->path_status.capture |= PS_EARMIC_TO_AP; - cmd_gain[1] = INPUT_EAR_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[1] = INPUT_EAR_MIC | OUTPUT_AP; - } else { - if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) { - control->gain_status.capture |= GS_SUBMIC_TO_AP; - control->path_status.capture |= PS_SUBMIC_TO_AP; - cmd_gain[1] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[1] = INPUT_SUB_MIC | OUTPUT_AP; - } else { - control->gain_status.capture |= GS_MAINMIC_TO_AP; - control->path_status.capture |= PS_MAINMIC_TO_AP; - cmd_gain[1] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[1] = INPUT_MAIN_MIC | OUTPUT_AP; - } - } + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) { + cmd_gain[gain_idx++] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_SUB_MIC | OUTPUT_AP; } else { - if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) { - control->gain_status.capture |= GS_SUBMIC_TO_AP; - control->path_status.capture |= PS_SUBMIC_TO_AP; - cmd_gain[1] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[1] = INPUT_SUB_MIC | OUTPUT_AP; - } else { - control->gain_status.capture |= GS_MAINMIC_TO_AP; - control->path_status.capture |= PS_MAINMIC_TO_AP; - cmd_gain[1] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[1] = INPUT_MAIN_MIC | OUTPUT_AP; - } + cmd_gain[gain_idx++] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_MAIN_MIC | OUTPUT_AP; } break; case AVSYS_AUDIO_PATH_EX_HEADSETMIC: - control->gain_status.capture |= GS_EARMIC_TO_AP; - control->path_status.capture |= PS_EARMIC_TO_AP; - cmd_gain[1] = INPUT_EAR_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[1] = INPUT_EAR_MIC | OUTPUT_AP; + cmd_gain[gain_idx++] = INPUT_EAR_MIC | OUTPUT_AP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_EAR_MIC | OUTPUT_AP; break; case AVSYS_AUDIO_PATH_EX_BTMIC: - control->gain_status.capture |= GS_BTMIC_TO_AP; - control->path_status.capture |= PS_BTMIC_TO_AP; - cmd_gain[1] = INPUT_BT_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[1] = INPUT_BT_MIC | OUTPUT_AP; + cmd_gain[gain_idx++] = INPUT_BT_MIC | OUTPUT_AP | GAIN_MODE; + cmd_path[path_idx++] = INPUT_BT_MIC | OUTPUT_AP; break; case AVSYS_AUDIO_PATH_EX_HANDSFREE: @@ -1896,16 +1877,9 @@ static int __avsys_audio_path_set_ascn_videocall(avsys_audio_path_ex_info_t *con break; } - if((control->p_path_status.playback != control->path_status.playback) - || ((control->p_path_status.capture != control->path_status.capture)) || control->gain_debug_mode == 1) { - if(!skip_clear) { - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET)) - } - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_NONE)) - control->p_gain_status = control->gain_status; /* both playback and capture */ - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE)) - control->p_path_status = control->path_status; /* both playback and capture */ - } + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET)); + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_NONE)); + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE)); return AVSYS_STATE_SUCCESS; } @@ -1919,82 +1893,56 @@ static int __avsys_audio_path_set_ascn_fmradio(avsys_audio_path_ex_info_t *contr int skip_clear_record = 0; int gain_idx = 0; int path_idx = 0; - control->path_fixed = PATH_FIXED_WITH_FMRADIO; + + avsys_warning(AVAUDIO, "req gain playback [%x], control gain playback [%x]\n", + control->reqgain.playback, control->gain.playback); + avsys_warning(AVAUDIO, "req gain capture [%x], control gain capture [%x]\n", + control->reqgain.capture, control->gain.capture); + switch (control->path.playback) { case AVSYS_AUDIO_PATH_EX_NONE: - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.playback = GS_FMRADIO_TO_SPK; - control->path_status.playback = PS_PATH_NONE; - cmd_gain[gain_idx++] = INPUT_FMRADIO | OUTPUT_STEREO_SPK | GAIN_MODE; + avsys_warning(AVAUDIO, "[SZ] playback AVSYS_AUDIO_PATH_EX_NONE\n"); break; case AVSYS_AUDIO_PATH_EX_SPK: - if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE; - if (control->reqgain.playback == control->gain.playback) { - if (control->inserted != AVSYS_AUDIO_INSERTED_NONE) { - control->gain_status.playback = GS_FMRADIO_TO_HEADSET; - control->path_status.playback = PS_FMRADIO_TO_HEADSET; - cmd_gain[gain_idx++] = INPUT_FMRADIO | OUTPUT_HEADSET | GAIN_MODE; - cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_HEADSET; - cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET; - } else { - control->gain_status.playback = GS_FMRADIO_TO_SPK; - control->path_status.playback = PS_FMRADIO_TO_SPK; - cmd_gain[gain_idx++] = INPUT_FMRADIO | OUTPUT_STEREO_SPK | GAIN_MODE; - cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_STEREO_SPK; - cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; - } - } else { - /* append ap playback sound path */ - control->path_status.playback = control->p_path_status.playback; - if (control->inserted != AVSYS_AUDIO_INSERTED_NONE) { - control->path_status.playback |= PS_AP_TO_HEADSET; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; - cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET; - } else { - control->path_status.playback |= PS_AP_TO_SPK; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; - } - skip_clear = 1; - } - } else { /* ear jack manual */ - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - if (control->reqgain.playback == control->gain.playback) { - control->gain_status.playback = GS_FMRADIO_TO_SPK; - control->path_status.playback = PS_FMRADIO_TO_SPK; - cmd_gain[gain_idx++] = INPUT_FMRADIO | OUTPUT_STEREO_SPK | GAIN_MODE; - cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_STEREO_SPK; - cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; - } else { - /* append ap playback sound path */ - control->path_status.playback = control->p_path_status.playback; - control->path_status.playback |= PS_AP_TO_SPK; - control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; - skip_clear = 1; - } + if (control->reqgain.playback == control->gain.playback) { + avsys_warning(AVAUDIO, "req gain playback == control gain playback\n"); + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; + } else { + avsys_warning(AVAUDIO, "req gain playback != control gain playback\n"); + /* append ap playback sound path */ + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; + cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK; + skip_clear = 1; } break; case AVSYS_AUDIO_PATH_EX_HEADSET: - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; if (control->reqgain.playback == control->gain.playback) { - control->gain_status.playback = GS_FMRADIO_TO_HEADSET; - control->path_status.playback = PS_FMRADIO_TO_HEADSET; - cmd_gain[gain_idx++] = INPUT_FMRADIO | OUTPUT_HEADSET | GAIN_MODE; - cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_HEADSET; + avsys_warning(AVAUDIO, "req gain playback == control gain playback\n"); + cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE; cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET; } else { - /* append ap playback */ - control->path_status.playback = control->p_path_status.playback; - control->path_status.playback |= PS_AP_TO_HEADSET; + //append ap playback + avsys_warning(AVAUDIO, "req gain playback != control gain playback\n"); control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET; cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET; skip_clear = 1; } break; + + case AVSYS_AUDIO_PATH_EX_A2DP: + if (control->reqgain.playback == control->gain.playback) { + avsys_warning(AVAUDIO, "req gain playback == control gain playback\n"); + //control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; + } else { + avsys_warning(AVAUDIO, "req gain playback != control gain playback\n"); + control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET; + skip_clear = 1; + } + break; + default: break; } @@ -2002,9 +1950,11 @@ static int __avsys_audio_path_set_ascn_fmradio(avsys_audio_path_ex_info_t *contr switch (control->path.capture) { case AVSYS_AUDIO_PATH_EX_FMINPUT: if (control->reqgain.capture == control->gain.capture) { - control->path_status.capture |= PS_FMRADIO_TO_AP; + avsys_warning(AVAUDIO, "req gain capture == control gain capture\n"); + cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_AP | GAIN_MODE; cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_AP; if (control->reqgain.capture == control->pregain.capture) { + avsys_warning(AVAUDIO, "req gain capture == control pregain capture\n"); skip_clear_record = 1; } } @@ -2013,18 +1963,13 @@ static int __avsys_audio_path_set_ascn_fmradio(avsys_audio_path_ex_info_t *contr break; } - if((control->p_path_status.playback != control->path_status.playback) - || (control->p_path_status.capture != control->path_status.capture) || control->gain_debug_mode == 1) { - if (skip_clear_record) { - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET_PLAYBACK)) - } else if (!skip_clear) { - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET)) - } - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, gain_idx, ASCN_RESET_NONE)) - control->p_gain_status = control->gain_status; /* both playback & capture */ - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, path_idx, ASCN_RESET_NONE)) - control->p_path_status = control->path_status; /* both playback & capture */ + if (skip_clear_record) { + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET_PLAYBACK)) + } else if (!skip_clear) { + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET)) } + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, gain_idx, ASCN_RESET_NONE)) + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, path_idx, ASCN_RESET_NONE)) return AVSYS_STATE_SUCCESS; } @@ -2038,56 +1983,20 @@ static int __avsys_audio_path_set_ascn_ap_capture(avsys_audio_path_ex_info_t *co control->path.capture, control->option.capture, control->gain.capture, control->inserted); switch(control->path.capture) { case AVSYS_AUDIO_PATH_EX_MIC: - if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_JACK_AUTO) { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE; - if (control->inserted == AVSYS_AUDIO_INSERTED_4) { - control->gain_status.capture = GS_EARMIC_TO_AP; - control->path_status.capture = PS_EARMIC_TO_AP; - cmd_gain[0] = INPUT_EAR_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[0] = INPUT_EAR_MIC | OUTPUT_AP; - } else { - if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) { - control->gain_status.capture = GS_SUBMIC_TO_AP; - control->path_status.capture = PS_SUBMIC_TO_AP; - cmd_gain[0] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[0] = INPUT_SUB_MIC | OUTPUT_AP; - } else if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_STEREOMIC) { - control->gain_status.capture = GS_STEREOMIC_TO_AP; - control->path_status.capture = PS_STEREOMIC_TO_AP; - cmd_gain[0] = INPUT_STEREO_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[0] = INPUT_STEREO_MIC | OUTPUT_AP; - } else { - control->gain_status.capture = GS_MAINMIC_TO_AP; - control->path_status.capture = PS_MAINMIC_TO_AP; - cmd_gain[0] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[0] = INPUT_MAIN_MIC | OUTPUT_AP; - } - } + control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE; + if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) { + cmd_gain[0] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE; + cmd_path[0] = INPUT_SUB_MIC | OUTPUT_AP; + } else if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_STEREOMIC) { + cmd_gain[0] = INPUT_STEREO_MIC | OUTPUT_AP | GAIN_MODE; + cmd_path[0] = INPUT_STEREO_MIC | OUTPUT_AP; } else { - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE; - if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) { - control->gain_status.capture = GS_SUBMIC_TO_AP; - control->path_status.capture = PS_SUBMIC_TO_AP; - cmd_gain[0] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[0] = INPUT_SUB_MIC | OUTPUT_AP; - } else if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_STEREOMIC) { - control->gain_status.capture = GS_STEREOMIC_TO_AP; - control->path_status.capture = PS_STEREOMIC_TO_AP; - cmd_gain[0] = INPUT_STEREO_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[0] = INPUT_STEREO_MIC | OUTPUT_AP; - } else { - control->gain_status.capture = GS_MAINMIC_TO_AP; - control->path_status.capture = PS_MAINMIC_TO_AP; - cmd_gain[0] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE; - cmd_path[0] = INPUT_MAIN_MIC | OUTPUT_AP; - } + cmd_gain[0] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE; + cmd_path[0] = INPUT_MAIN_MIC | OUTPUT_AP; } break; case AVSYS_AUDIO_PATH_EX_HEADSETMIC: - control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL; - control->gain_status.capture = GS_EARMIC_TO_AP; - control->path_status.capture = PS_EARMIC_TO_AP; cmd_gain[0] = INPUT_EAR_MIC | OUTPUT_AP | GAIN_MODE; cmd_path[0] = INPUT_EAR_MIC | OUTPUT_AP; break; @@ -2096,12 +2005,8 @@ static int __avsys_audio_path_set_ascn_ap_capture(avsys_audio_path_ex_info_t *co break; } - if ((control->p_path_status.capture != control->path_status.capture) || control->gain_debug_mode == 1) { - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_CAPTURE)) - control->p_gain_status.capture = control->gain_status.capture; - RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE)) - control->p_path_status.capture = control->path_status.capture; - } + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_CAPTURE)) + RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE)) avsys_info (AVAUDIO, ">> leave"); @@ -2149,11 +2054,6 @@ static int __avsys_audio_path_set_hw_controls(avsys_audio_path_ex_info_t *contro } ptr->path_off = 0; out_device = control->lvol_dev_type; - if (control->path_status.playback == PS_PATH_NONE) { - ptr->path_off = 1; - avsys_warning(AVAUDIO, "Path off status...set logical volume device type to speaker\n"); - out_device = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - } avsys_audio_logical_volume_update_table(out_device, &ptr->gain_setting); avsys_audio_logical_volume_convert(&ptr->setting_vol, &ptr->working_vol, &ptr->gain_setting); } @@ -2182,7 +2082,7 @@ int avsys_audio_path_set_volume(int handle) avsys_audio_path_ex_info_t **temp = NULL; avsys_audio_handle_t *ptr = NULL; int err; - int gain_type; + int vol_conf, vol_conf_type; int out_device = AVSYS_AUDIO_DEVICE_TYPE_SPK; err = avsys_audio_handle_get_ptr(handle, &ptr, HANDLE_PTR_MODE_NORMAL); @@ -2202,82 +2102,26 @@ int avsys_audio_path_set_volume(int handle) else ptr->during_cp_audio = 0; - gain_type = ptr->gain_setting.vol_type; + vol_conf = ptr->gain_setting.volume_config; + vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(vol_conf); out_device = control->lvol_dev_type; - if (control->path_status.playback == PS_PATH_NONE) { - ptr->path_off = 1; - avsys_warning(AVAUDIO, "Path off status...set logical volume device type to speaker\n"); - out_device = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK; - } avsys_assert(AVSYS_SUCCESS(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - avsys_warning(AVAUDIO, "set path volume : gain(%d), out_dev(%d)\n", gain_type, out_device); - err = avsys_audio_logical_volume_set_table(gain_type, out_device, &ptr->gain_setting); + avsys_warning(AVAUDIO, "set path volume : gain(%d), out_dev(%d)\n", vol_conf_type, out_device); + err = avsys_audio_logical_volume_set_table(vol_conf, out_device, &ptr->gain_setting); avsys_audio_handle_release_ptr(handle, HANDLE_PTR_MODE_NORMAL); return err; } int avsys_audio_path_set_route_policy(avsys_audio_route_policy_t route) { - avsys_audio_path_ex_info_t *control = NULL; - avsys_audio_path_ex_info_t **temp = NULL; - int err = AVSYS_STATE_SUCCESS; - - temp = &control; - avsys_assert(AVSYS_SUCCESS(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))); - avsys_assert(control != NULL); - avsys_assert(AVSYS_SUCCESS(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - - control->route_policy = route; - - avsys_assert(AVSYS_SUCCESS(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - return err; + /* Deprecated */ + return 0; } int avsys_audio_path_get_route_policy(avsys_audio_route_policy_t *route) { - avsys_audio_path_ex_info_t *control = NULL; - avsys_audio_path_ex_info_t **temp = NULL; - int err = AVSYS_STATE_SUCCESS; - - if (!route) - return AVSYS_STATE_ERR_INVALID_PARAMETER; - - temp = &control; - avsys_assert(AVSYS_SUCCESS(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))); - avsys_assert(control != NULL); - avsys_assert(AVSYS_SUCCESS(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - - *route = control->route_policy; - - avsys_assert(AVSYS_SUCCESS(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - return err; -} - -int avsys_audio_path_check_loud(bool *loud) -{ - avsys_audio_path_ex_info_t *control = NULL; - avsys_audio_path_ex_info_t **temp = NULL; - int err = AVSYS_STATE_SUCCESS; - - if (!loud) - return AVSYS_STATE_ERR_INVALID_PARAMETER; - - temp = &control; - avsys_assert(AVSYS_SUCCESS(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))); - avsys_assert(control != NULL); - avsys_assert(AVSYS_SUCCESS(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - - if ((control->path_status.playback & PS_AP_TO_SPK) || - (control->path_status.playback & PS_AP_TO_RECV) || - (control->path_status.playback & PS_FMRADIO_TO_SPK)) { - *loud = true; - } else { - avsys_info(AVAUDIO, "playback path status 0x%x\n", control->path_status.playback); - *loud = false; - } - - avsys_assert(AVSYS_SUCCESS(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))); - return err; + /* Deprecated */ + return 0; } int avsys_audio_path_check_cp_audio(bool *cpaudio, bool *btpath) diff --git a/avsys-audio-shm.c b/avsys-audio-shm.c index 850f59f..e6dcf4b 100644 --- a/avsys-audio-shm.c +++ b/avsys-audio-shm.c @@ -36,7 +36,7 @@ typedef struct { static _avsys_audio_shm_control_t g_presettings[AVSYS_AUDIO_SHM_IDEN_CNT] = { {{SHM_KEY_PATH, AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO,AVSYS_AUDIO_SHM_IDEN_HANDLE) + 0x10,sizeof(avsys_audio_handle_info_t)}, NULL}, {{SHM_KEY_PATH, AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO,AVSYS_AUDIO_SHM_IDEN_PATH) + 0x10,sizeof(avsys_audio_path_ex_info_t)}, NULL}, - {{SHM_KEY_PATH, AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO,AVSYS_AUDIO_SHM_IDEN_LVOLUME) + 0x10,sizeof(avsys_logical_gain_t) * AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX}, NULL}, + {{SHM_KEY_PATH, AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO,AVSYS_AUDIO_SHM_IDEN_LVOLUME) + 0x10,sizeof(avsys_audio_lvol_info_t)}, NULL}, }; int avsys_audio_create_shm(const avsys_audio_shm_iden_t iden) diff --git a/avsys-audio-sync.c b/avsys-audio-sync.c index dac16db..f0db338 100644 --- a/avsys-audio-sync.c +++ b/avsys-audio-sync.c @@ -35,8 +35,6 @@ static avsys_sync_param_t g_presettings[AVSYS_AUDIO_SYNC_IDEN_CNT] = { {"audio_handle_lock", AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO, AVSYS_AUDIO_SYNC_IDEN_HANDLE)}, {"audio_path_lock", AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO, AVSYS_AUDIO_SYNC_IDEN_PATH)}, - {"audio_route_policy_lock", AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO, AVSYS_AUDIO_SYNC_IDEN_SOUNDPATH)}, - {"av_volume_sem", AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO, AVSYS_AUDIO_SYNC_IDEN_VOLUME)}, }; int avsys_audio_create_sync(const avsys_audio_sync_iden_t iden) diff --git a/avsys-audio.c b/avsys-audio.c index 8ce7538..029d93a 100644 --- a/avsys-audio.c +++ b/avsys-audio.c @@ -68,9 +68,21 @@ void __fini_module(void); } \ } while (0) +#define AVSYS_STREAM_LOCK() do { \ + pthread_mutex_lock(&gmutex);\ + avsys_info(AVAUDIO, "(+) LOCKED\n"); \ +} while (0) + +#define AVSYS_STREAM_UNLOCK() do { \ + pthread_mutex_unlock(&gmutex);\ + avsys_info(AVAUDIO, "(-) UNLOCKED\n"); \ +} while (0) + /** * Internal global variable */ +static pthread_mutex_t gmutex = PTHREAD_MUTEX_INITIALIZER; + /**************************************************************************** * @@ -91,7 +103,7 @@ int avsys_audio_open(avsys_audio_param_t *param, avsys_handle_t *phandle, int *s return AVSYS_STATE_ERR_NULL_POINTER; } - if (param->channels > 2 || param->channels < 1) { + if (param->channels > AVSYS_CHANNEL_MAX || param->channels < AVSYS_CHANNEL_MIN) { return AVSYS_STATE_ERR_INVALID_CHANNEL; } @@ -103,6 +115,8 @@ int avsys_audio_open(avsys_audio_param_t *param, avsys_handle_t *phandle, int *s return AVSYS_STATE_ERR_INVALID_FORMAT; } + AVSYS_STREAM_LOCK(); + err = avsys_audio_handle_rejuvenation(); if (AVSYS_FAIL(err)) { avsys_error(AVAUDIO, "Unused handle cleanup before handle allocation failed in %s\n", __func__); @@ -147,18 +161,18 @@ int avsys_audio_open(avsys_audio_param_t *param, avsys_handle_t *phandle, int *s } /* update volume by type */ - err = avsys_audio_handle_update_volume(p, p->gain_setting.vol_type); + err = avsys_audio_handle_update_volume(p, p->gain_setting.volume_config); if (AVSYS_FAIL(err)) { goto error; } - err = avsys_audio_handle_update_priority(handle, param->priority, param->bluetooth, AVSYS_AUDIO_SET_PRIORITY); + err = avsys_audio_handle_update_priority(handle, param->priority, param->handle_route, AVSYS_AUDIO_SET_PRIORITY); if (AVSYS_FAIL(err)) { goto error; } } /* open device */ - err = avsys_audio_pasimple_open_device(p->mode, p->format, p->channels, p->samplerate, p, param->bluetooth); + err = avsys_audio_pasimple_open_device(p->mode, p->format, p->channels, p->samplerate, p, param->handle_route); if (AVSYS_FAIL(err)) { goto error; } @@ -187,7 +201,7 @@ int avsys_audio_open(avsys_audio_param_t *param, avsys_handle_t *phandle, int *s if (AVSYS_FAIL(err)) { goto error; } - + AVSYS_STREAM_UNLOCK(); return AVSYS_STATE_SUCCESS; error: @@ -201,10 +215,10 @@ error: } } - avsys_error(AVAUDIO, "failed to open : RESION %x\n", err); + avsys_error(AVAUDIO, "failed to open : REASON %x\n", err); *phandle = (avsys_handle_t)-1; - + AVSYS_STREAM_UNLOCK(); return err; } @@ -216,9 +230,14 @@ int avsys_audio_close(avsys_handle_t handle) bool cp_audio = false; bool bt_path = false; + AVSYS_STREAM_LOCK(); avsys_info(AVAUDIO, "%s, handle=[%d]\n", __func__, (int)handle); - AVSYS_GET_HANDLE_PTR(HANDLE_PTR_MODE_NORMAL); + err = avsys_audio_handle_get_ptr((int)handle, &p, HANDLE_PTR_MODE_NORMAL); + if (AVSYS_FAIL(err)) { + AVSYS_STREAM_UNLOCK(); + return err; + } if (AVSYS_FAIL(avsys_audio_handle_update_priority((int)handle, p->priority, AVSYS_AUDIO_HANDLE_ROUTE_FOLLOWING_POLICY, AVSYS_AUDIO_UNSET_PRIORITY))) { avsys_error(AVAUDIO, "unset priority of handle %d error: %x\n", handle, err); @@ -238,10 +257,51 @@ int avsys_audio_close(avsys_handle_t handle) avsys_audio_path_set_single_ascn("cp_to_bt"); } - AVSYS_RELEASE_HANDLE_PTR(HANDLE_PTR_MODE_NORMAL); + if (AVSYS_FAIL(avsys_audio_handle_release_ptr((int)handle, HANDLE_PTR_MODE_NORMAL))) { + avsys_error(AVAUDIO, "audio handle release failed\n"); + AVSYS_STREAM_UNLOCK(); + return AVSYS_STATE_ERR_INTERNAL; + } avsys_audio_handle_free((int)handle); + AVSYS_STREAM_UNLOCK(); + + return err; +} + +EXPORT_API +int avsys_audio_update_volume_config(avsys_handle_t handle, int volume_config) +{ + avsys_audio_handle_t *p = NULL; + int err = AVSYS_STATE_ERR_UNKNOWN; + + AVSYS_STREAM_LOCK(); + avsys_info(AVAUDIO, "%s, handle=[%d]\n", __func__, (int)handle); + + err = avsys_audio_handle_get_ptr((int)handle, &p, HANDLE_PTR_MODE_NORMAL); + if (AVSYS_FAIL(err)) { + AVSYS_STREAM_UNLOCK(); + return err; + } + + if (p->mode == AVSYS_AUDIO_MODE_OUTPUT || p->mode == AVSYS_AUDIO_MODE_OUTPUT_CLOCK + || p->mode == AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY || p->mode == AVSYS_AUDIO_MODE_OUTPUT_AP_CALL + || p->mode == AVSYS_AUDIO_MODE_OUTPUT_VIDEO) { + p->gain_setting.volume_config = volume_config; + /* update volume by type */ + err = avsys_audio_handle_update_volume(p, p->gain_setting.volume_config); + if (AVSYS_FAIL(err)) { + AVSYS_STREAM_UNLOCK(); + return err; + } + err = avsys_audio_pasimple_set_volume(p, p->working_vol.level[AVSYS_AUDIO_CHANNEL_LEFT]); + if (AVSYS_FAIL(err)) { + avsys_error(AVAUDIO, "can not set volume in %s\n", __func__); + } + } + + AVSYS_STREAM_UNLOCK(); return err; } @@ -486,9 +546,9 @@ int avsys_audio_set_mute_fadedown(avsys_handle_t handle) /* Tuning part */ EXPORT_API -int avsys_audio_set_volume_table(int gain_type, int dev_type, int step, int lv, int rv) +int avsys_audio_set_volume_table(int volume_type, int dev_type, int step, int lv, int rv) { - int ret = avsys_audio_logical_volume_set_to_table(gain_type, dev_type, step, lv, rv); + int ret = avsys_audio_logical_volume_set_to_table(volume_type, dev_type, step, lv, rv); avsys_audio_handle_t *ptr = NULL; int handle = -1; @@ -508,22 +568,47 @@ int avsys_audio_set_volume_table(int gain_type, int dev_type, int step, int lv, } EXPORT_API -int avsys_audio_get_volume_table(int gain_type, int dev_type, int step, int *lv, int *rv) +int avsys_audio_get_volume_table(int volume_type, int dev_type, int step, int *lv, int *rv) { - return avsys_audio_logical_volume_get_from_table(gain_type, dev_type, step, lv, rv); + return avsys_audio_logical_volume_get_from_table(volume_type, dev_type, step, lv, rv); } EXPORT_API int avsys_audio_get_volume_max_ex(int volume_type, int *max_step) { - int volume_table = 0; if (max_step == NULL) { return AVSYS_STATE_ERR_NULL_POINTER; } - volume_table = volume_type; + return avsys_audio_logical_volume_get_max(volume_type, AVSYS_AUDIO_LVOL_DEV_TYPE_SPK, max_step); +} + +EXPORT_API +int avsys_audio_set_volume_gain_table(int volume_gain_idx, int dev_type, float lv, float rv) +{ + int ret = avsys_audio_logical_volume_set_gain_to_table(volume_gain_idx, dev_type, lv, rv); + avsys_audio_handle_t *ptr = NULL; + int handle = -1; + + if (AVSYS_FAIL(ret)) { + return ret; + } + + while(++handle < AVSYS_AUDIO_HANDLE_MAX) { + ptr = NULL; - return avsys_audio_logical_volume_get_max(volume_table, AVSYS_AUDIO_LVOL_DEV_TYPE_SPK, max_step); + if (AVSYS_SUCCESS(avsys_audio_handle_get_ptr(handle, &ptr, HANDLE_PTR_MODE_NORMAL))) { + avsys_audio_logical_volume_convert(&ptr->setting_vol, &ptr->working_vol, &ptr->gain_setting); + avsys_audio_handle_release_ptr(handle, HANDLE_PTR_MODE_NORMAL); + } + } + return AVSYS_STATE_SUCCESS; +} + +EXPORT_API +int avsys_audio_get_volume_gain_table(int volume_gain_idx, int dev_type, float *lv, float *rv) +{ + return avsys_audio_logical_volume_get_gain_from_table(volume_gain_idx, dev_type, lv, rv); } EXPORT_API @@ -631,6 +716,9 @@ int avsys_audio_get_global_mute(int *pmute) static int __avsys_audio_set_info(avsys_audio_handle_t *p, avsys_audio_param_t *param) { + int vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(param->vol_type); + int vol_conf_gain = AVSYS_AUDIO_VOLUME_CONFIG_GAIN(param->vol_type); + avsys_info(AVAUDIO, "%s\n", __func__); avsys_info(AVAUDIO, "=============================================\n"); @@ -640,8 +728,9 @@ static int __avsys_audio_set_info(avsys_audio_handle_t *p, avsys_audio_param_t * avsys_info(AVAUDIO, " format = %d (0: 8bits, 1:16bits, 2:32bits)\n", param->format); avsys_info(AVAUDIO, " channel = %d\n", param->channels); avsys_info(AVAUDIO, " samplerate = %d\n", param->samplerate); - avsys_info(AVAUDIO, " route = %d (0: default, 1: handset)\n", param->bluetooth); - avsys_info(AVAUDIO, " Vol type = %d\n", param->vol_type); + avsys_info(AVAUDIO, " route = %d (0: default, 1: handset)\n", param->handle_route); + avsys_info(AVAUDIO, " volume type= %d\n", vol_conf_type); + avsys_info(AVAUDIO, " volume gain= %d\n", vol_conf_gain); avsys_info(AVAUDIO, "=============================================\n"); p->mode = param->mode; @@ -650,11 +739,11 @@ static int __avsys_audio_set_info(avsys_audio_handle_t *p, avsys_audio_param_t * p->format = param->format; p->priority = param->priority; - if ((param->vol_type < 0) || (param->vol_type >= AVSYS_AUDIO_VOLUME_TYPE_MAX)) { - avsys_error(AVAUDIO, "[%s] Invalid volume type %d. use default system type\n", __func__, param->vol_type); - p->gain_setting.vol_type = AVSYS_AUDIO_VOLUME_TYPE_SYSTEM; + if ((vol_conf_type < 0) || (vol_conf_type >= AVSYS_AUDIO_VOLUME_TYPE_MAX)) { + avsys_error(AVAUDIO, "[%s] Invalid volume type %d. use default system type\n", __func__, vol_conf_type); + p->gain_setting.volume_config = AVSYS_AUDIO_VOLUME_TYPE_SYSTEM; } else { - p->gain_setting.vol_type = param->vol_type; + p->gain_setting.volume_config = param->vol_type; } /* trivial volume value */ @@ -692,6 +781,12 @@ int avsys_audio_earjack_manager_deinit(int waitfd) } EXPORT_API +int avsys_audio_earjack_manager_get_type(void) +{ + return avsys_audio_path_earjack_get_type(); +} + +EXPORT_API int avsys_audio_earjack_manager_unlock(void) { return avsys_audio_path_earjack_unlock(); @@ -700,15 +795,15 @@ int avsys_audio_earjack_manager_unlock(void) EXPORT_API int avsys_audio_set_route_policy(avsys_audio_route_policy_t route) { - return avsys_audio_path_set_route_policy(route); + /* Deprecated */ + return 0; } EXPORT_API int avsys_audio_get_route_policy(avsys_audio_route_policy_t *route) { - if (route == NULL) - return AVSYS_STATE_ERR_NULL_POINTER; - return avsys_audio_path_get_route_policy(route); + /* Deprecated */ + return 0; } EXPORT_API @@ -724,17 +819,17 @@ static inline int __avsys_audio_validate_volume(const int type, const int value) if (value < 0) return -1; switch (type) { - case AVSYS_AUDIO_VOLUME_TYPE_ALARM: case AVSYS_AUDIO_VOLUME_TYPE_CALL: + case AVSYS_AUDIO_VOLUME_TYPE_VOIP: if (value >= LVOLUME_MAX_BASIC) { return -1; } break; + case AVSYS_AUDIO_VOLUME_TYPE_ALARM: case AVSYS_AUDIO_VOLUME_TYPE_RINGTONE: case AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION: case AVSYS_AUDIO_VOLUME_TYPE_SYSTEM: case AVSYS_AUDIO_VOLUME_TYPE_MEDIA: - case AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL: case AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA: if (value >= LVOLUME_MAX_MULTIMEDIA) { return -1; @@ -778,6 +873,7 @@ EXPORT_API int avsys_audio_hibernation_reset(int *vol) { int err = AVSYS_STATE_SUCCESS; + err = avsys_audio_path_ex_reset(1); if (AVSYS_FAIL(err)) { avsys_error(AVAUDIO, "avsys_audio_path_ex_reset(forced) failed 0x%x\n", err); @@ -789,6 +885,7 @@ int avsys_audio_hibernation_reset(int *vol) avsys_error(AVAUDIO, "avsys_audio_handle_reset() failed 0x%x\n", err); return err; } + return err; } @@ -856,38 +953,42 @@ int avsys_audio_get_period_buffer_time(avsys_handle_t handle, unsigned int *peri } EXPORT_API -int avsys_audio_get_playing_device_info(avsys_audio_playing_devcie_t *dev) +int avsys_audio_cork (avsys_handle_t handle, int cork) { int err = AVSYS_STATE_SUCCESS; - int sink_info = 0; - bool alsa_loud = false; + avsys_audio_handle_t *p = NULL; - if (!dev) - return AVSYS_STATE_ERR_INVALID_PARAMETER; + AVSYS_GET_HANDLE_PTR(HANDLE_PTR_MODE_NORMAL); - err = avsys_audio_pa_ctrl_get_default_sink(&sink_info); - if (AVSYS_FAIL(err)) - return err; + err = avsys_audio_pasimple_cork(p, cork); + if(AVSYS_FAIL(err)) { + avsys_error(AVAUDIO, "avsys_audio_pasimple_cork() failed, 0x%X\n",err); + } - switch (sink_info) { - case AVSYS_AUDIO_PA_CTL_SINK_UNKNOWN: - avsys_error_r(AVAUDIO, "Unexpected sink information\n"); - err = AVSYS_STATE_ERR_UNAVAILABLE_DEVICE; - break; - case AVSYS_AUDIO_PA_CTL_SINK_ALSA: - err = avsys_audio_path_check_loud(&alsa_loud); - if (AVSYS_FAIL(err)) - break; - if (alsa_loud == true) - *dev = AVSYS_AUDIO_ROUTE_DEVICE_HANDSET; - else - *dev = AVSYS_AUDIO_ROUTE_DEVICE_EARPHONE; - break; - case AVSYS_AUDIO_PA_CTL_SINK_BLUEZ: - *dev = AVSYS_AUDIO_ROUTE_DEVICE_BLUETOOTH; - break; + AVSYS_RELEASE_HANDLE_PTR(HANDLE_PTR_MODE_NORMAL); + + return err; +} + +EXPORT_API +int avsys_audio_is_corked (avsys_handle_t handle, int *is_corked) +{ + int err = AVSYS_STATE_SUCCESS; + avsys_audio_handle_t *p = NULL; + + if (is_corked == NULL) { + return AVSYS_STATE_ERR_NULL_POINTER; + } + + AVSYS_GET_HANDLE_PTR(HANDLE_PTR_MODE_NORMAL); + + err = avsys_audio_pasimple_is_corked(p, is_corked); + if(AVSYS_FAIL(err)) { + avsys_error(AVAUDIO, "avsys_audio_pasimple_cork() failed, 0x%X\n",err); } + AVSYS_RELEASE_HANDLE_PTR(HANDLE_PTR_MODE_NORMAL); + return err; } diff --git a/avsystem.manifest b/avsystem.manifest new file mode 100755 index 0000000..e56ae9f --- /dev/null +++ b/avsystem.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/configure.ac b/configure.ac index cd205b4..0b681de 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,10 @@ PKG_CHECK_MODULES(ASCN, libascenario) AC_SUBST(ASCN_CFLAGS) AC_SUBST(ASCN_LIBS) +PKG_CHECK_MODULES(INIPARSER, iniparser) +AC_SUBST(INIPARSER_CFLAGS) +AC_SUBST(INIPARSER_LIBS) + # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([fcntl.h memory.h stdlib.h string.h sys/time.h unistd.h errno.h sys/types.h sys/stat.h]) diff --git a/include/avsys-audio-alsa.h b/include/avsys-audio-alsa.h index 1711f84..7e2dea0 100644 --- a/include/avsys-audio-alsa.h +++ b/include/avsys-audio-alsa.h @@ -27,22 +27,30 @@ #endif #include -enum AIF_device_type_t { - AIF2_CAPTURE, - AIF2_PLAYBACK, - AIF3_CAPTURE, - AIF3_PLAYBACK, +typedef enum { + AIF_CP_CAPTURE, + AIF_CP_PLAYBACK, + AIF_BT_CAPTURE, + AIF_BT_PLAYBACK, + AIF_RADIO_PLAYBACK, AIF_DEVICE_MAX, -}; +} aif_device_type_t; + +typedef enum { + AIF_CONF_RATE = 0, + AIF_NB_RATE = 8000, + AIF_WB_RATE = 16000, +} aif_rate_t; typedef struct { void *alsa_handle; int type; -} avsys_audio_alsa_aif_handle_t;; + int rate; +} avsys_audio_alsa_aif_handle_t; -int avsys_audio_alsa_open_AIF_device(const int AIF_type, avsys_audio_alsa_aif_handle_t *handle); +int avsys_audio_alsa_open_AIF_device(aif_device_type_t aif_type, avsys_audio_alsa_aif_handle_t *handle); int avsys_audio_alsa_close_AIF_device(avsys_audio_alsa_aif_handle_t* handle); -int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle); +int avsys_audio_alsa_set_AIF_params(avsys_audio_alsa_aif_handle_t *handle, aif_rate_t rate); #ifdef __cplusplus } diff --git a/include/avsys-audio-ascenario.h b/include/avsys-audio-ascenario.h index a5f8c24..3e01df7 100644 --- a/include/avsys-audio-ascenario.h +++ b/include/avsys-audio-ascenario.h @@ -62,8 +62,8 @@ typedef enum { #define OUTPUT_CH_8 ((1 << (8 + OUT))) /* Gain */ #define OUTPUT_CH_9 ((1 << (9 + OUT))) /* Video call gain */ #define OUTPUT_CH_10 ((1 << (10 + OUT))) /* Video call gain */ -#define OUTPUT_CH_11 ((1 << (11 + OUT))) /* Reserved */ -#define OUTPUT_CH_12 ((1 << (12 + OUT))) /* Reserved */ +#define OUTPUT_CH_11 ((1 << (11 + OUT))) /* HDMI */ +#define OUTPUT_CH_12 ((1 << (12 + OUT))) /* Dock */ #define OUTPUT_CH_13 ((1 << (13 + OUT))) /* Call alert Gain */ #define INPUT_MAIN_MIC (INPUT_CH_0) @@ -83,6 +83,8 @@ typedef enum { #define OUTPUT_BT_HEADSET (OUTPUT_CH_5) #define OUTPUT_CP (OUTPUT_CH_6) #define OUTPUT_AP (OUTPUT_CH_7) +#define OUTPUT_HDMI (OUTPUT_CH_11) +#define OUTPUT_DOCK (OUTPUT_CH_12) #define GAIN_MODE (OUTPUT_CH_8) #define GAIN_VIDEO_CALL (OUTPUT_CH_9) diff --git a/include/avsys-audio-handle.h b/include/avsys-audio-handle.h index b05c099..41db071 100644 --- a/include/avsys-audio-handle.h +++ b/include/avsys-audio-handle.h @@ -97,7 +97,7 @@ enum { int avsys_audio_handle_init(void); int avsys_audio_handle_fini(void); -int avsys_audio_handle_reset(int *); +int avsys_audio_handle_reset(int *volume_value); int avsys_audio_handle_dump(void); int avsys_audio_handle_rejuvenation(void); int avsys_audio_handle_alloc(int *handle); @@ -109,7 +109,7 @@ int avsys_audio_handle_ext_dev_set_mute(avsysaudio_ext_device_t device_type, int int avsys_audio_handle_ext_dev_status(avsysaudio_ext_device_t device_type, int *onoff); int avsys_audio_handle_ext_dev_status_update(avsysaudio_ext_device_t device_type, int onoff); int avsys_audio_handle_current_playing_volume_type(int *type); -int avsys_audio_handle_update_volume(avsys_audio_handle_t *p, const int vol_type); +int avsys_audio_handle_update_volume(avsys_audio_handle_t *p, const int volume_config); int avsys_audio_handle_update_volume_by_type(const int volume_type, const int volume_value); int avsys_audio_handle_set_primary_volume_type(const int pid, const int type, const int command); int avsys_audio_handle_update_priority(int handle, int priority, int handle_route, int cmd); diff --git a/include/avsys-audio-logical-volume.h b/include/avsys-audio-logical-volume.h index 1b4ad52..e20f896 100644 --- a/include/avsys-audio-logical-volume.h +++ b/include/avsys-audio-logical-volume.h @@ -31,22 +31,37 @@ #define FADE_UP_MULTIPLIER 1//2 #define FADE_DOWN_MULTIPLIER 1 -#define VOLUME_FILE_PATH "/opt/system/volume.txt" +#define AVSYS_VOLUME_INI_DEFAULT_PATH "/usr/etc/mmfw_audio_volume.ini" +#define AVSYS_VOLUME_INI_TEMP_PATH "/opt/system/mmfw_audio_volume.ini" -enum -{ +enum { AVSYS_AUDIO_LVOL_GAIN_TYPE_0 = 0, /* system */ AVSYS_AUDIO_LVOL_GAIN_TYPE_1, /* notification */ AVSYS_AUDIO_LVOL_GAIN_TYPE_2, /* alarm */ AVSYS_AUDIO_LVOL_GAIN_TYPE_3, /* ringtone */ AVSYS_AUDIO_LVOL_GAIN_TYPE_4, /* media */ AVSYS_AUDIO_LVOL_GAIN_TYPE_5, /* call */ - AVSYS_AUDIO_LVOL_GAIN_TYPE_6, /* android */ - AVSYS_AUDIO_LVOL_GAIN_TYPE_7, /* java */ - AVSYS_AUDIO_LVOL_GAIN_TYPE_8, /* music (media2) */ + AVSYS_AUDIO_LVOL_GAIN_TYPE_6, /* voip */ + AVSYS_AUDIO_LVOL_GAIN_TYPE_7, /* android */ + AVSYS_AUDIO_LVOL_GAIN_TYPE_8, /* java */ AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX, }; +enum { + AVSYS_AUDIO_LVOL_GAIN_EXT_DIALER = 1<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_TOUCH = 2<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_AF = 3<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_SHUTTER1 = 4<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_SHUTTER2 = 5<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_CAMCORDING = 6<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_MIDI = 7<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_BOOTING = 8<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_VIDEO = 9<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_VIDEO_HDMI = 10<<8, + AVSYS_AUDIO_LVOL_GAIN_EXT_TYPE_MAX, + AVSYS_AUDIO_LVOL_GAIN_EXT_TYPE_MAX_IDX = AVSYS_AUDIO_LVOL_GAIN_EXT_TYPE_MAX>>8 +}; + enum { AVSYS_AUDIO_LVOL_DEV_TYPE_SPK, @@ -55,33 +70,38 @@ enum AVSYS_AUDIO_LVOL_DEV_TYPE_MAX, }; - typedef struct { - int max_len; - avsys_audio_volume_t gain[LVOLUME_MAX_MULTIMEDIA]; -} avsys_a_logical_volume_t; + struct { + int max_level; + avsys_audio_volume_t logical_values[LVOLUME_MAX_MULTIMEDIA]; + } devices[AVSYS_AUDIO_LVOL_DEV_TYPE_MAX]; +} avsys_audio_lvol_volume_info_t; +typedef struct { + float devices[AVSYS_AUDIO_LVOL_DEV_TYPE_MAX]; +} avsys_audio_lvol_gain_info_t; typedef struct { - int type; - avsys_a_logical_volume_t devices[AVSYS_AUDIO_LVOL_DEV_TYPE_MAX]; -} avsys_logical_gain_t; + avsys_audio_lvol_volume_info_t volume_table[AVSYS_AUDIO_LVOL_GAIN_TYPE_MAX]; + avsys_audio_lvol_gain_info_t gain_table[AVSYS_AUDIO_LVOL_GAIN_EXT_TYPE_MAX_IDX]; +} avsys_audio_lvol_info_t; typedef struct { - int vol_type; + int volume_config; int dev_type; - int max_len; - avsys_audio_volume_t *table; + int max_level; } avsys_audio_volume_setting_t; -int avsys_audio_logical_volume_get_max(int vol_type, int dev_type, int *max); -int avsys_audio_logical_volume_set_table(int vol_type, int dev_type, avsys_audio_volume_setting_t *setting); +int avsys_audio_logical_volume_get_max(int volume_type, int dev_type, int *max_level); +int avsys_audio_logical_volume_set_table(int volume_config, int dev_type, avsys_audio_volume_setting_t *setting); int avsys_audio_logical_volume_update_table(int dev_type, avsys_audio_volume_setting_t *setting); int avsys_audio_logical_volume_convert(avsys_audio_volume_t *level, avsys_audio_volume_t *converted, avsys_audio_volume_setting_t *setting); /* Tuning */ int avsys_audio_logical_volume_init(void); -int avsys_audio_logical_volume_set_to_table(int gain_type, int dev_type, int step, int lv, int rv); -int avsys_audio_logical_volume_get_from_table(int gain_type, int dev_type, int step, int *lv, int *rv); -int avsys_audio_load_volume_from_file(void); +int avsys_audio_logical_volume_set_to_table(int volume_type, int dev_type, int step, int lv, int rv); +int avsys_audio_logical_volume_get_from_table(int volume_type, int dev_type, int step, int *lv, int *rv); +int avsys_audio_logical_volume_set_gain_to_table(int volume_gain, int dev_type, float lv, float rv); +int avsys_audio_logical_volume_get_gain_from_table(int volume_gain, int dev_type, float*lv, float *rv); +int avsys_audio_load_volume_from_ini(void); #endif /* __AVSYS_AUDIO_LOGICAL_VOLUME_H__ */ diff --git a/include/avsys-audio-pasimple.h b/include/avsys-audio-pasimple.h index 06fec34..53e1525 100644 --- a/include/avsys-audio-pasimple.h +++ b/include/avsys-audio-pasimple.h @@ -30,6 +30,7 @@ #include #include #include +#include typedef struct { void *pasimple_handle; @@ -49,6 +50,8 @@ int avsys_audio_pasimple_drain(avsys_audio_handle_t *handle); int avsys_audio_pasimple_delay(avsys_audio_handle_t *handle, int *delay_frames); int avsys_audio_pasimple_set_volume(avsys_audio_handle_t *handle, int volume); int avsys_audio_pasimple_get_period_buffer_time(avsys_audio_handle_t *handle, unsigned int *period_time, unsigned int *buffer_time); +int avsys_audio_pasimple_cork(avsys_audio_handle_t *handle, int cork); +int avsys_audio_pasimple_is_corked(avsys_audio_handle_t *handle, int *is_corked); #ifdef __cplusplus } diff --git a/include/avsys-audio-path.h b/include/avsys-audio-path.h index 2f20b46..cf99e66 100644 --- a/include/avsys-audio-path.h +++ b/include/avsys-audio-path.h @@ -53,82 +53,10 @@ enum avsys_audio_capture_gain{ }; enum avsys_audio_ear_ctrl { - AVSYS_AUDIO_EAR_SWITCH_MANUAL, - AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE, + AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE = 1, AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE, }; -struct avsys_audio_jack_event { - struct timeval time; - unsigned short type; - unsigned short code; - int value; -}; - -#define PATH_MASK_MAX 23 -#define GAIN_MASK_MAX 30 -/* sound path status bit */ -#define PS_PATH_NONE (0) -#define PS_AP_TO_SPK (1 << 0) -#define PS_AP_TO_HEADSET (1 << 1) -#define PS_AP_TO_RECV (1 << 2) -#define PS_AP_TO_HDMI (1 << 3) -#define PS_AP_TO_BT (1 << 4) -#define PS_AP_TO_MODEM (1 << 5) -#define PS_MODEM_TO_SPK (1 << 6) -#define PS_MODEM_TO_HEADSET (1 << 7) -#define PS_MODEM_TO_RECV (1 << 8) -#define PS_MODEM_TO_BT (1 << 9) -#define PS_MODEM_TO_AP (1 << 10) -#define PS_FMRADIO_TO_SPK (1 << 11) -#define PS_FMRADIO_TO_HEADSET (1 << 12) -#define PS_MAINMIC_TO_AP (1 << 13) -#define PS_MAINMIC_TO_MODEM (1 << 14) -#define PS_SUBMIC_TO_AP (1 << 15) -#define PS_SUBMIC_TO_MODEM (1 << 16) -#define PS_STEREOMIC_TO_AP (1 << 17) -#define PS_EARMIC_TO_AP (1 << 18) -#define PS_EARMIC_TO_MODEM (1 << 19) -#define PS_BTMIC_TO_AP (1 << 20) -#define PS_BTMIC_TO_MODEM (1 << 21) -#define PS_FMRADIO_TO_AP (1 << 22) -#define PS_CODEC_DISABLE_ON_SUSPEND (1 << 23) -#define PS_CP_TO_AP (1 << PATH_MASK_MAX) - - -/* hw gain status enum */ -#define GS_GAIN_NONE (0) -#define GS_AP_TO_SPK (1 << 0) -#define GS_AP_TO_SPK_CALLALERT (1 << 1) -#define GS_AP_TO_HEADSET (1 << 2) -#define GS_AP_TO_HEADSET_CALLALERT (1 << 3) -#define GS_AP_TO_RECV (1 << 4) -#define GS_AP_TO_HDMI (1 << 5) -#define GS_AP_TO_BT (1 << 6) -#define GS_AP_TO_MODEM (1 << 7) -#define GS_MODEM_TO_SPK_VOICE (1 << 8) -#define GS_MODEM_TO_HEADSET_VOICE (1 << 9) -#define GS_MODEM_TO_RECV_VOICE (1 << 10) -#define GS_MODEM_TO_BT_VOICE (1 << 11) -#define GS_MODEM_TO_AP_VOICE (1 << 12) -#define GS_MODEM_TO_SPK_VIDEO (1 << 13) -#define GS_MODEM_TO_HEADSET_VIDEO (1 << 14) -#define GS_MODEM_TO_RECV_VIDEO (1 << 15) -#define GS_MODEM_TO_BT_VIDEO (1 << 16) -#define GS_MODEM_TO_AP_VIDEO (1 << 17) -#define GS_FMRADIO_TO_SPK (1 << 18) -#define GS_FMRADIO_TO_HEADSET (1 << 19) -#define GS_MAINMIC_TO_AP (1 << 20) -#define GS_MAINMIC_TO_MODEM_VOICE (1 << 21) -#define GS_SUBMIC_TO_AP (1 << 22) -#define GS_SUBMIC_TO_MODEM_VOICE (1 << 23) -#define GS_STEREOMIC_TO_AP (1 << 24) -#define GS_EARMIC_TO_AP (1 << 25) -#define GS_EARMIC_TO_MODEM_VOICE (1 << 26) -#define GS_BTMIC_TO_AP (1 << 27) -#define GS_BTMIC_TO_MODEM_VOICE (1 << 28) -#define GS_FMRADIO_TO_AP (1 << 29) -#define GS_CP_TO_AP (1 << GAIN_MASK_MAX) #define TYPE_EVENT_SWITCH 0x05 #define CODE_HEADPHONE_INSERT 0x02 @@ -137,7 +65,6 @@ struct avsys_audio_jack_event { #define CODE_JACK_PHYSICAL_INSERT 0x07 #define PATH_FIXED_NONE (0x00000000) -#define PATH_FIXED_WITH_FMRADIO (1 << PATH_FIXED_TYPE_FMRADIO) /* 0x00000001 */ #define PATH_FIXED_WITH_CALL (1 << PATH_FIXED_TYPE_CALL) /* 0x00000002 */ enum avsys_audio_amp_t { @@ -186,23 +113,13 @@ typedef struct { int inserted; int ear_auto; - /* for alsa scenario, aquila */ - gain_status_t gain_status; - path_status_t path_status; - - gain_status_t p_gain_status; - path_status_t p_path_status; - int lvol_dev_type; - int gain_debug_mode; + bool control_aif_before_path_set; + bool wb_enabled; + bool gain_debug_mode; /* For Lock debugging */ pid_t pathlock_pid[AVSYS_AUDIO_LOCK_SLOT_MAX]; - - /* system route policy */ - avsys_audio_route_policy_t route_policy; - int a2dp_status; - int earpiece_on; } avsys_audio_path_ex_info_t; int avsys_audio_path_ex_init(void); @@ -225,7 +142,6 @@ int avsys_audio_path_earjack_unlock(void); int avsys_audio_path_set_route_policy(avsys_audio_route_policy_t route); int avsys_audio_path_get_route_policy(avsys_audio_route_policy_t *route); -int avsys_audio_path_check_loud(bool *loud); int avsys_audio_path_check_cp_audio(bool *cpaudio, bool *btpath); int avsys_audio_path_set_single_ascn(char *str); diff --git a/include/avsys-audio-sync.h b/include/avsys-audio-sync.h index d55d5a1..cab7221 100644 --- a/include/avsys-audio-sync.h +++ b/include/avsys-audio-sync.h @@ -29,8 +29,6 @@ typedef enum { AVSYS_AUDIO_SYNC_IDEN_HANDLE, AVSYS_AUDIO_SYNC_IDEN_PATH, - AVSYS_AUDIO_SYNC_IDEN_SOUNDPATH, - AVSYS_AUDIO_SYNC_IDEN_VOLUME, AVSYS_AUDIO_SYNC_IDEN_CNT } avsys_audio_sync_iden_t; diff --git a/include/avsys-audio.h b/include/avsys-audio.h index 3853f46..51b151c 100644 --- a/include/avsys-audio.h +++ b/include/avsys-audio.h @@ -41,6 +41,13 @@ #define AVSYS_AUDIO_VOLUME_MAX_BASIC 8 #define AVSYS_AUDIO_VOLUME_MAX_SINGLE 1 +#define AVSYS_AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF) +#define AVSYS_AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00) +#define AVSYS_AUDIO_VOLUME_GAIN_IDX(gain) ((gain >> 8) - 1) + +#define AVSYS_CHANNEL_MIN 1 +#define AVSYS_CHANNEL_MAX 6 + /** * Enumerations for audio mode */ @@ -81,14 +88,28 @@ enum avsys_audio_volume_type_t { AVSYS_AUDIO_VOLUME_TYPE_RINGTONE, AVSYS_AUDIO_VOLUME_TYPE_MEDIA, AVSYS_AUDIO_VOLUME_TYPE_CALL, + AVSYS_AUDIO_VOLUME_TYPE_VOIP, AVSYS_AUDIO_VOLUME_TYPE_FIXED, AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA, - AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL, AVSYS_AUDIO_VOLUME_TYPE_NUM, AVSYS_AUDIO_VOLUME_TYPE_MAX = AVSYS_AUDIO_VOLUME_TYPE_NUM, AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID = AVSYS_AUDIO_VOLUME_TYPE_FIXED, }; +enum avsys_audio_volume_gain_t { + AVSYS_AUDIO_VOLUME_GAIN_DIALER = 1<<8, + AVSYS_AUDIO_VOLUME_GAIN_TOUCH = 2<<8, + AVSYS_AUDIO_VOLUME_GAIN_AF = 3<<8, + AVSYS_AUDIO_VOLUME_GAIN_SHUTTER1 = 4<<8, + AVSYS_AUDIO_VOLUME_GAIN_SHUTTER2 = 5<<8, + AVSYS_AUDIO_VOLUME_GAIN_CAMCORDING = 6<<8, + AVSYS_AUDIO_VOLUME_GAIN_MIDI = 7<<8, + AVSYS_AUDIO_VOLUME_GAIN_BOOTING = 8<<8, + AVSYS_AUDIO_VOLUME_GAIN_VIDEO = 9<<8, + AVSYS_AUDIO_VOLUME_GAIN_VIDEO_HDMI = 10<<8, + AVSYS_AUDIO_VOLUME_GAIN_TYPE_MAX, +}; + enum avsys_audio_priority_t { AVSYS_AUDIO_PRIORITY_0 = 0, /*< deprecated. use AVSYS_AUDIO_PRIORITY_NORMAL or AVSYS_AUDIO_PRIORITY_SOLO instead */ AVSYS_AUDIO_PRIORITY_NORMAL = AVSYS_AUDIO_PRIORITY_0, @@ -143,7 +164,7 @@ typedef struct { int channels; /**< Number of channels */ int samplerate; /**< Sampling rate */ int format; /**< Sampling format */ - int bluetooth; /**< Handle route information. refer. avsys_audio_handle_route_t */ + int handle_route; /**< Handle route information. refer. avsys_audio_handle_route_t */ int vol_type; /**< volume type */ int allow_mix; } avsys_audio_param_t; @@ -169,6 +190,8 @@ enum avsys_audio_path_ex { AVSYS_AUDIO_PATH_EX_A2DP, AVSYS_AUDIO_PATH_EX_HANDSFREE, AVSYS_AUDIO_PATH_EX_HDMI, + AVSYS_AUDIO_PATH_EX_DOCK, + AVSYS_AUDIO_PATH_EX_USBAUDIO, AVSYS_AUDIO_PATH_EX_OUTMAX, AVSYS_AUDIO_PATH_EX_MIC = 1, AVSYS_AUDIO_PATH_EX_HEADSETMIC, @@ -224,15 +247,11 @@ typedef enum { /* path option */ #define AVSYS_AUDIO_PATH_OPTION_NONE 0x00000000 /*!< Sound path option none */ -#define AVSYS_AUDIO_PATH_OPTION_JACK_AUTO 0x00000001 /*!< Sound path auto change between SPK/Recv and headset */ #define AVSYS_AUDIO_PATH_OPTION_DUAL_OUT 0x00000002 /*!< SPK or Recv with headset sound path. used for Ringtone or Alarm */ -#define AVSYS_AUDIO_PATH_OPTION_LEFT_SPK_ONLY 0x00000004 /*!< AP playback left speaker only */ -#define AVSYS_AUDIO_PATH_OPTION_RIGHT_SPK_ONLY 0x00000008 /*!< AP playback right speaker only */ #define AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC 0x00000010 /*!< Voice call recording path option */ #define AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC 0x00000020 /*!< Use sub-mic when call or recording */ #define AVSYS_AUDIO_PATH_OPTION_USE_STEREOMIC 0x00000040 /*!< Use stereo mic when recording */ #define AVSYS_AUDIO_PATH_OPTION_FORCED 0x01000000 /*!< Forced sound path setting. only for booting animation */ -#define AVSYS_AUDIO_PATH_OPTION_LEGACY_MODE 0x10000000 /*!< Now Plus Style */ /** @@ -263,6 +282,18 @@ int avsys_audio_open(avsys_audio_param_t *param, avsys_handle_t *phandle, int *s int avsys_audio_close(avsys_handle_t handle); /** + * This function is to update volume type & volume gain. + * + * @param handle [in] Handle of audio system + * + * @return This function returns AVSYS_STATE_SUCCESS on success, or negative + * value with error code. + * @remark + * @see + */ +int avsys_audio_update_volume_config(avsys_handle_t handle, int volume_config); + +/** * This function is to stop playback stream immediately. this drops all buffer remaining data. * * @param handle [in] Playback handle of audio system @@ -335,8 +366,10 @@ int avsys_audio_read(avsys_handle_t handle, void *buf, int size); */ int avsys_audio_write(avsys_handle_t handle, void *buf, int size); -int avsys_audio_set_volume_table(int gain_type, int dev_type, int step, int lv, int rv); -int avsys_audio_get_volume_table(int gain_type, int dev_type, int step, int *lv, int *rv); +int avsys_audio_set_volume_table(int volume_type, int dev_type, int step, int lv, int rv); +int avsys_audio_get_volume_table(int volume_type, int dev_type, int step, int *lv, int *rv); +int avsys_audio_set_volume_gain_table(int volume_gain_idx, int dev_type, float lv, float rv); +int avsys_audio_get_volume_gain_table(int volume_gain_idx, int dev_type, float *lv, float *rv); int avsys_audio_set_volume_fadeup(avsys_handle_t handle); @@ -551,16 +584,30 @@ int avsys_audio_reset(avsys_handle_t handle); int avsys_audio_get_period_buffer_time(avsys_handle_t handle, unsigned int *period_time, unsigned int *buffer_time); /** - * This function is to get playback audio device information of system. + * This function is to cork stream. + * + * @param handle [in] handle to cork + * @param cork [in] cork=1, uncork=0 + * + * @return This function returns AVSYS_STATE_SUCCESS on success, or negative + * value with error code. + * @remark + * @see + */ +int avsys_audio_cork (avsys_handle_t handle, int cork); + +/** + * This function is to check whether stream is corked or not. * - * @param dev [out] current playback device type + * @param handle [in] handle to cork + * @param is_corked [out] corked is 1, otherwise 0 * * @return This function returns AVSYS_STATE_SUCCESS on success, or negative * value with error code. * @remark - * @see avsys_audio_playing_devcie_t + * @see */ -int avsys_audio_get_playing_device_info(avsys_audio_playing_devcie_t *dev); +int avsys_audio_is_corked (avsys_handle_t handle, int *is_corked); /** * This function is to get audio capturing status of system. @@ -580,6 +627,7 @@ int avsys_audio_earjack_manager_init(int *earjack_type, int *waitfd); int avsys_audio_earjack_manager_wait(int waitfd, int *current_earjack_type, int *new_earjack_type, int *need_mute); int avsys_audio_earjack_manager_process(int new_earjack_type); int avsys_audio_earjack_manager_deinit(int waitfd); +int avsys_audio_earjack_manager_get_type(void); int avsys_audio_earjack_manager_unlock(void); int avsys_audio_set_route_policy(avsys_audio_route_policy_t route); diff --git a/include/avsys-debug.h b/include/avsys-debug.h index 6f19daa..d7ded66 100644 --- a/include/avsys-debug.h +++ b/include/avsys-debug.h @@ -32,28 +32,24 @@ #ifdef __USE_LOGMANAGER__ #include #include -#define AVAUDIO LOG_AVAUDIO -#define AVVIDEO LOG_AVVIDEO -#define AVCAMERA LOG_AVCAMERA +#define AVAUDIO LOG_AVSYSTEM #else #define AVAUDIO -#define AVVIDEO -#define AVCAMERA #endif #ifdef __DEBUG_MODE__ #ifdef __USE_LOGMANAGER__ -#define avsys_info_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_INFO, "[%05d:%s] "msg, __LINE__, __func__, ##args ) -#define avsys_warning_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_WARNING, "[%05d:%s] "msg, __LINE__, __func__, ##args ) -#define avsys_error_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_ERR, "[%05d:%s] "msg, __LINE__, __func__, ##args ) -#define avsys_critical_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_CRITICAL, "[%05d:%s] "msg, __LINE__, __func__, ##args ) +#define avsys_info_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_INFO, msg, ##args ) +#define avsys_warning_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_WARNING, msg, ##args ) +#define avsys_error_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_ERR, msg, ##args ) +#define avsys_critical_r(owner, msg, args...) log_print_rel( owner, LOG_CLASS_CRITICAL, msg, ##args ) #define avsys_assert_r(condition) log_assert_rel(( condition )) -#define avsys_info(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_INFO, "[%05d:%s] "msg, __LINE__, __func__, ##args ) -#define avsys_warning(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_WARNING, "[%05d:%s] "msg, __LINE__, __func__, ##args ) -#define avsys_error(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_ERR, "[%05d:%s] "msg, __LINE__, __func__, ##args ) -#define avsys_critical(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_CRITICAL, "[%05d:%s] "msg, __LINE__, __func__, ##args ) +#define avsys_info(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_INFO, msg, ##args ) +#define avsys_warning(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_WARNING, msg, ##args ) +#define avsys_error(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_ERR, msg, ##args ) +#define avsys_critical(owner, msg, args...) log_print_dbg( owner, LOG_CLASS_CRITICAL, msg, ##args ) #define avsys_assert(condition) log_assert_dbg( (condition) ) #else /* __USE_LOGMANAGER__ */ diff --git a/packaging/avsystem.service b/packaging/avsystem.service new file mode 100644 index 0000000..6660b9b --- /dev/null +++ b/packaging/avsystem.service @@ -0,0 +1,11 @@ +[Unit] +Description=Start the av system + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/sound_initializer -i +ExecStop=/usr/bin/sound_initializer -u + +[Install] +WantedBy=tizen-mobile.target diff --git a/packaging/avsystem.spec b/packaging/avsystem.spec index 8118229..35d1209 100644 --- a/packaging/avsystem.spec +++ b/packaging/avsystem.spec @@ -1,11 +1,18 @@ - Name: avsystem Summary: Audio Video System -Version: 0.3.50 -Release: 1 -Group: TO_BE/FILLED_IN -License: TO BE FILLED IN -Source0: avsystem-%{version}.tar.bz2 +Version: 0.5.4 +Release: 0 +Group: System/Libraries +License: Apache-2.0 +Source0: avsystem-%{version}.tar.gz +Source101: packaging/avsystem.service + +Requires(post): /sbin/ldconfig +Requires(post): /usr/bin/systemctl +Requires(postun): /sbin/ldconfig +Requires(postun): /usr/bin/systemctl +Requires(preun): /usr/bin/systemctl + BuildRequires: pkgconfig(alsa) BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(mm-ta) @@ -35,39 +42,55 @@ Audio Video System Development headers and libraries. %build %autogen %configure \ -%ifarch %{ix86} - --enable-slp2 --enable-aquila --enable-pasimple +%if 0%{?simulator} + --enable-audiotest --enable-sdk %else - --enable-slp2 --enable-sdk --enable-aquila --enable-pasimple + --enable-audiotest %endif make %{?jobs:-j%jobs} %install -rm -rf %{buildroot} %make_install +mkdir -m 755 -p %{buildroot}/%{_sysconfdir}/rc.d/rc3.d/ +ln -s ../init.d/snd_init %{buildroot}/%{_sysconfdir}/rc.d/rc3.d/S15snd_init +mkdir -m 755 -p %{buildroot}/%{_sysconfdir}/rc.d/rc4.d/ +ln -s ../init.d/snd_init %{buildroot}/%{_sysconfdir}/rc.d/rc4.d/S15snd_init + +mkdir -m 755 -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants +install -m 0644 %SOURCE101 %{buildroot}%{_libdir}/systemd/system/avsystem.service +ln -s ../avsystem.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/avsystem.service + +%preun +if [ $1 == 0 ]; then + systemctl stop avsystem.service +fi +%post +/sbin/ldconfig +systemctl daemon-reload +if [ $1 == 1 ]; then + systemctl restart avsystem.service +fi -%post -p /sbin/ldconfig +%postun +/sbin/ldconfig +systemctl daemon-reload %files +%manifest avsystem.manifest %defattr(-,root,root,-) -/etc/rc.d/init.d/snd_init -/usr/bin/camera_caps_generator -/usr/bin/sound_initializer -/usr/lib/libavsysaudio.so.0 -/usr/lib/libavsysaudio.so.0.0.1 -/usr/lib/libavsyscamera.so.0 -/usr/lib/libavsyscamera.so.0.0.0 +%{_sysconfdir}/rc.d/init.d/snd_init +%{_sysconfdir}/rc.d/rc3.d/S15snd_init +%{_sysconfdir}/rc.d/rc4.d/S15snd_init +%{_bindir}/* +%{_libdir}/lib*.so.* +%{_libdir}/systemd/system/avsystem.service +%{_libdir}/systemd/system/multi-user.target.wants/avsystem.service %files devel -/usr/lib/libavsysaudio.so -/usr/lib/pkgconfig/*.pc -/usr/lib/libavsyscamera.so -/usr/include/avsystem/avsys-audio.h -/usr/include/avsystem/avsys-cam-exif.h -/usr/include/avsystem/avsys-cam.h -/usr/include/avsystem/avsys-error.h -/usr/include/avsystem/avsys-types.h -/usr/include/avsystem/avsystem.h +%manifest avsystem.manifest +%{_libdir}/pkgconfig/*.pc +%{_libdir}/*.so +/usr/include/avsystem/*.h -- 2.7.4