| /****************************************************************************** |
| * |
| * (C)Copyright 2022 ASRMicro. All Rights Reserved. |
| * |
| * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ASRMicro. |
| * The copyright notice above does not evidence any actual or intended |
| * publication of such source code. |
| * This Module contains Proprietary Information of ASRMicro and should be |
| * treated as Confidential. |
| * The information in this file is provided for the exclusive use of the |
| * licensees of ASRMicro. |
| * Such users have the right to use, modify, and incorporate this code into |
| * products for purposes authorized by the license agreement provided they |
| * include this notice and the associated copyright notice with any such |
| * product. |
| * The information in this file is provided "AS IS" without warranty. |
| * |
| ******************************************************************************/ |
| |
| |
| /****************************************************************************** |
| * Include files |
| ******************************************************************************/ |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <fcntl.h> |
| #include <unistd.h> |
| #include <sys/ioctl.h> |
| #include <cutils/log.h> |
| #include "audio_pa.h" |
| |
| |
| /****************************************************************************** |
| * Macro definitions |
| ******************************************************************************/ |
| #define AUDIO_PA_MAGIC 'y' |
| #define PA_ENABLE _IO(AUDIO_PA_MAGIC, 'a') |
| #define PA_DISABLE _IO(AUDIO_PA_MAGIC, 'b') |
| |
| |
| /****************************************************************************** |
| * Local variable definitions |
| ******************************************************************************/ |
| static int audio_pa_fd = -1; |
| static int is_in_voice = 0; |
| static int is_in_media = 0; |
| |
| |
| /****************************************************************************** |
| * function definitions |
| ******************************************************************************/ |
| int audio_pa_init(void) |
| { |
| if (audio_pa_fd <= 0) { |
| audio_pa_fd = open("/dev/audio_pa", O_RDWR); |
| if (audio_pa_fd <= 0) { |
| LOGI(audio_pa_init, "audio_pa %s:%s:%d, open device fail, fd=%d\n", __FILE__, __FUNCTION__, __LINE__, audio_pa_fd); |
| return -1; |
| } |
| |
| LOGI(aaudio_pa_init, "audio_pa %s:%s:%d, open device success, fd=%d\n", __FILE__, __FUNCTION__, __LINE__, audio_pa_fd); |
| return 0; |
| } |
| |
| LOGI(audio_pa_init, "audio_pa %s:%s:%d, device already open\n", __FILE__, __FUNCTION__, __LINE__); |
| return -2; |
| } |
| |
| int audio_pa_enable(AUDIO_PA_TYPE type) |
| { |
| if (type < AUDIO_PA_VOICE || type > AUDIO_PA_MEDIA) { |
| LOGI(audio_pa_enable, "audio_pa %s:%s:%d, type=%d is incorrect\n", __FILE__, __FUNCTION__, __LINE__); |
| ioctl(audio_pa_fd, PA_DISABLE); |
| return -1; |
| } |
| |
| if (audio_pa_fd > 0) { |
| LOGI(audio_pa_enable, "audio_pa %s:%s:%d, in_voice=%s, in_media=%s, type=%s\n", |
| __FILE__, __FUNCTION__, __LINE__, is_in_voice?"yes":"no", is_in_media?"yes":"no", type == 1?"voice":"media"); |
| |
| if (!is_in_voice && !is_in_media) { |
| ioctl(audio_pa_fd, PA_ENABLE); |
| } |
| |
| if (AUDIO_PA_VOICE == type && !is_in_voice) { |
| is_in_voice = 1; |
| } |
| else if (AUDIO_PA_MEDIA == type && !is_in_media) { |
| is_in_media = 1; |
| } |
| |
| return 0; |
| } |
| |
| LOGI(audio_pa_enable, "audio_pa %s:%s:%d, device not ready, fd=%d\n", __FILE__, __FUNCTION__, __LINE__, audio_pa_fd); |
| return -2; |
| } |
| |
| int audio_pa_disable(AUDIO_PA_TYPE type) |
| { |
| if (type < AUDIO_PA_VOICE || type > AUDIO_PA_MEDIA) { |
| LOGI(audio_pa_disable, "audio_pa %s:%s:%d, type=%d is incorrect\n", __FILE__, __FUNCTION__, __LINE__); |
| ioctl(audio_pa_fd, PA_DISABLE); |
| return -1; |
| } |
| |
| if (audio_pa_fd > 0) { |
| LOGI(audio_pa_disable, "audio_pa %s:%s:%d, in_voice=%s, in_media=%s, type=%s\n", |
| __FILE__, __FUNCTION__, __LINE__, is_in_voice?"yes":"no", is_in_media?"yes":"no", type == 1?"voice":"media"); |
| |
| if (AUDIO_PA_VOICE == type && is_in_voice) { |
| is_in_voice = 0; |
| } |
| else if (AUDIO_PA_MEDIA == type && is_in_media) { |
| is_in_media = 0; |
| } |
| else { |
| return -2; |
| } |
| |
| if (!is_in_voice && !is_in_media) { |
| ioctl(audio_pa_fd, PA_DISABLE); |
| } |
| return 0; |
| } |
| |
| LOGI(audio_pa_disable, "audio_pa %s:%s:%d, device not ready, fd=%d\n", __FILE__, __FUNCTION__, __LINE__, audio_pa_fd); |
| return -3; |
| } |
| |
| void audio_pa_exit(void) |
| { |
| LOGI(audio_pa_exit, "audio_pa %s:%s:%d, fd=%d\n", __FILE__, __FUNCTION__, __LINE__, audio_pa_fd); |
| |
| if (audio_pa_fd > 0) { |
| close(audio_pa_fd); |
| } |
| |
| audio_pa_fd = -1; |
| } |