1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SOUND_TRIGGER_INTF_H 18 #define SOUND_TRIGGER_INTF_H 19 20 #include <hardware/sound_trigger.h> 21 #include "tinyalsa/asoundlib.h" 22 23 /*-------------------- Begin: AHAL-STHAL Interface ---------------------------*/ 24 /* 25 * Maintain the proprietary interface between AHAL and STHAL locally to avoid 26 * the compilation dependency of interface header file from STHAL. 27 */ 28 29 #define MAKE_HAL_VERSION(maj, min) ((((maj) & 0xff) << 8) | ((min) & 0xff)) 30 #define MAJOR_VERSION(ver) (((ver) & 0xff00) >> 8) 31 #define MINOR_VERSION(ver) ((ver) & 0x00ff) 32 33 /* Proprietary interface version used for compatibility with STHAL */ 34 #define STHAL_PROP_API_VERSION_1_0 MAKE_HAL_VERSION(1, 0) 35 #define STHAL_PROP_API_CURRENT_VERSION STHAL_PROP_API_VERSION_1_0 36 37 #define ST_EVENT_CONFIG_MAX_STR_VALUE 32 38 39 #define AUDIO_HAL_NAME_PREFIX "audio.primary" 40 #define SOUND_TRIGGER_PLATFORM "msmnile" 41 42 #ifdef __LP64__ 43 #define AUDIO_HAL_LIBRARY_PATH "/vendor/lib64/hw" 44 #else 45 #define AUDIO_HAL_LIBRARY_PATH "/vendor/lib/hw" 46 #endif 47 48 const unsigned int sthal_prop_api_version = STHAL_PROP_API_CURRENT_VERSION; 49 50 #define SOUND_TRIGGER_SAMPLING_RATE 16000 51 #define SOUND_TRIGGER_CHANNEL 1 52 #define SOUND_TRIGGER_PERIOD_COUNT 2 53 #define SOUND_TRIGGER_PERIOD_DURATION_MSEC 20 54 #define SOUND_TRIGGER_PERIOD_SIZE (SOUND_TRIGGER_SAMPLING_RATE * \ 55 SOUND_TRIGGER_CHANNEL * \ 56 SOUND_TRIGGER_PERIOD_DURATION_MSEC) / 1000 57 58 static struct pcm_config stdev_hotword_pcm_config = { 59 .channels = SOUND_TRIGGER_CHANNEL, 60 .rate = SOUND_TRIGGER_SAMPLING_RATE, 61 .period_size = SOUND_TRIGGER_PERIOD_SIZE, 62 .period_count = SOUND_TRIGGER_PERIOD_COUNT, 63 .format = PCM_FORMAT_S16_LE, 64 }; 65 66 typedef enum { 67 ST_EVENT_SESSION_REGISTER, 68 ST_EVENT_SESSION_DEREGISTER 69 } sound_trigger_event_type_t; 70 71 typedef enum { 72 AUDIO_EVENT_CAPTURE_DEVICE_INACTIVE, 73 AUDIO_EVENT_CAPTURE_DEVICE_ACTIVE, 74 AUDIO_EVENT_PLAYBACK_STREAM_INACTIVE, 75 AUDIO_EVENT_PLAYBACK_STREAM_ACTIVE, 76 AUDIO_EVENT_STOP_LAB, 77 AUDIO_EVENT_SSR, 78 AUDIO_EVENT_NUM_ST_SESSIONS, 79 AUDIO_EVENT_READ_SAMPLES, 80 AUDIO_EVENT_DEVICE_CONNECT, 81 AUDIO_EVENT_DEVICE_DISCONNECT, 82 AUDIO_EVENT_SVA_EXEC_MODE, 83 AUDIO_EVENT_SVA_EXEC_MODE_STATUS, 84 AUDIO_EVENT_CAPTURE_STREAM_INACTIVE, 85 AUDIO_EVENT_CAPTURE_STREAM_ACTIVE, 86 } audio_event_type_t; 87 88 typedef enum { 89 USECASE_TYPE_PCM_PLAYBACK, 90 USECASE_TYPE_PCM_CAPTURE, 91 USECASE_TYPE_VOICE_CALL, 92 USECASE_TYPE_VOIP_CALL, 93 } audio_stream_usecase_type_t; 94 95 enum ssr_event_status { 96 SND_CARD_STATUS_OFFLINE, 97 SND_CARD_STATUS_ONLINE, 98 CPE_STATUS_OFFLINE, 99 CPE_STATUS_ONLINE, 100 SLPI_STATUS_OFFLINE, 101 SLPI_STATUS_ONLINE 102 }; 103 104 struct sound_trigger_session_info { 105 void* p_ses; /* opaque pointer to st_session obj */ 106 int capture_handle; 107 struct pcm *pcm; 108 struct pcm_config config; 109 }; 110 111 struct audio_read_samples_info { 112 struct sound_trigger_session_info *ses_info; 113 void *buf; 114 size_t num_bytes; 115 }; 116 117 struct audio_hal_usecase { 118 audio_stream_usecase_type_t type; 119 }; 120 121 struct sound_trigger_event_info { 122 struct sound_trigger_session_info st_ses; 123 }; 124 125 struct sound_trigger_get_param_data { 126 char *param; 127 int sm_handle; 128 struct str_parms *reply; 129 }; 130 131 struct sound_trigger_device_info { 132 int device; 133 }; 134 135 struct audio_event_info { 136 union { 137 enum ssr_event_status status; 138 int value; 139 struct sound_trigger_session_info ses_info; 140 struct audio_read_samples_info aud_info; 141 char str_value[ST_EVENT_CONFIG_MAX_STR_VALUE]; 142 struct audio_hal_usecase usecase; 143 bool audio_ec_ref_enabled; 144 struct sound_trigger_get_param_data st_get_param_data; 145 } u; 146 struct sound_trigger_device_info device_info; 147 }; 148 149 /* STHAL callback which is called by AHAL */ 150 typedef int (*sound_trigger_hw_call_back_t)(audio_event_type_t, 151 struct audio_event_info*); 152 153 /* AHAL callback which is called by STHAL */ 154 typedef void (*audio_hw_call_back_t)(sound_trigger_event_type_t, 155 struct sound_trigger_event_info*); 156 157 /*---------------- End: AHAL-STHAL Interface ----------------------------------*/ 158 #endif /* SOUND_TRIGGER_INTF_H */ 159