rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2012 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Filename: |
| 38 | * --------- |
| 39 | * med_utility.c |
| 40 | * |
| 41 | * Project: |
| 42 | * -------- |
| 43 | * Maui |
| 44 | * |
| 45 | * Description: |
| 46 | * ------------ |
| 47 | * This file includes common used functions of media task. |
| 48 | * |
| 49 | * Author: |
| 50 | * ------- |
| 51 | * ------- |
| 52 | * |
| 53 | *============================================================================== |
| 54 | * HISTORY |
| 55 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 56 | *------------------------------------------------------------------------------ |
| 57 | * removed! |
| 58 | * |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * removed! |
| 62 | * |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * removed! |
| 66 | * |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * removed! |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * |
| 87 | * removed! |
| 88 | * removed! |
| 89 | * removed! |
| 90 | * |
| 91 | *------------------------------------------------------------------------------ |
| 92 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 93 | *============================================================================== |
| 94 | *******************************************************************************/ |
| 95 | |
| 96 | /*==== INCLUDES =========*/ |
| 97 | #include "kal_public_defs.h" |
| 98 | #include "kal_public_api.h" |
| 99 | #include "kal_general_types.h" |
| 100 | #include "kal_trace.h" |
| 101 | |
| 102 | /* global includes */ |
| 103 | #include "l1audio.h" |
| 104 | |
| 105 | /* local includes */ |
| 106 | #include "med_main.h" |
| 107 | #include "med_global.h" |
| 108 | #include "med_mem.h" |
| 109 | #include "med_struct.h" |
| 110 | #include "med_context.h" |
| 111 | #include "med_smalloc.h" |
| 112 | #include "med_utility.h" |
| 113 | #include "med_trc.h" |
| 114 | #include "aud_main.h" |
| 115 | |
| 116 | kal_mutexid med_mem_mutex; |
| 117 | |
| 118 | /***************************************************************************** |
| 119 | * FUNCTION |
| 120 | * med_alloc_ext_mem |
| 121 | * DESCRIPTION |
| 122 | * |
| 123 | * PARAMETERS |
| 124 | * size [IN] |
| 125 | * RETURNS |
| 126 | * void |
| 127 | *****************************************************************************/ |
| 128 | void *med_alloc_ext_mem_ext(kal_int32 size, kal_uint8 location, char* file_p, long line_p) |
| 129 | { |
| 130 | /*----------------------------------------------------------------*/ |
| 131 | /* Local Variables */ |
| 132 | /*----------------------------------------------------------------*/ |
| 133 | void *p = NULL; |
| 134 | |
| 135 | /*----------------------------------------------------------------*/ |
| 136 | /* Code Body */ |
| 137 | /*----------------------------------------------------------------*/ |
| 138 | kal_take_mutex(med_mem_mutex); |
| 139 | p = (void*)med_ext_smalloc_ext((size_type) size, location, file_p, line_p); |
| 140 | kal_give_mutex(med_mem_mutex); |
| 141 | |
| 142 | return p; |
| 143 | } |
| 144 | |
| 145 | /***************************************************************************** |
| 146 | * FUNCTION |
| 147 | * med_free_aud_mem_ext |
| 148 | * DESCRIPTION |
| 149 | * |
| 150 | * PARAMETERS |
| 151 | * pointer [IN] |
| 152 | * RETURNS |
| 153 | * void |
| 154 | *****************************************************************************/ |
| 155 | void med_free_aud_mem_ext(void **pointer,char* file_p, long line_p) |
| 156 | { |
| 157 | /*----------------------------------------------------------------*/ |
| 158 | /* Local Variables */ |
| 159 | /*----------------------------------------------------------------*/ |
| 160 | |
| 161 | /*----------------------------------------------------------------*/ |
| 162 | /* Code Body */ |
| 163 | /*----------------------------------------------------------------*/ |
| 164 | kal_take_mutex(med_mem_mutex); |
| 165 | med_aud_sfree((address_t) * pointer); |
| 166 | kal_give_mutex(med_mem_mutex); |
| 167 | *pointer = NULL; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | /***************************************************************************** |
| 172 | * FUNCTION |
| 173 | * med_util_alloc_aud_mem |
| 174 | * DESCRIPTION |
| 175 | * This function is to allocate memory from audio memory pool. |
| 176 | * PARAMETERS |
| 177 | * size [IN] Memory size to be allocated. |
| 178 | * file_p [IN] File name. |
| 179 | * line [IN] Line number in the file. |
| 180 | * RETURNS |
| 181 | * Allocated memory address |
| 182 | *****************************************************************************/ |
| 183 | static void* med_util_alloc_aud_mem(kal_uint32 size, char* file_p, long line) |
| 184 | { |
| 185 | /*----------------------------------------------------------------*/ |
| 186 | /* Local Variables */ |
| 187 | /*----------------------------------------------------------------*/ |
| 188 | |
| 189 | /*----------------------------------------------------------------*/ |
| 190 | /* Code Body */ |
| 191 | /*----------------------------------------------------------------*/ |
| 192 | return med_alloc_ext_mem_ext(size, MED_EXT_MEMORY_TYPE_AUDIO_NONCACHEABLE, file_p, line); |
| 193 | } |
| 194 | |
| 195 | /***************************************************************************** |
| 196 | * FUNCTION |
| 197 | * med_util_alloc_aud_cacheable_mem |
| 198 | * DESCRIPTION |
| 199 | * This function is to allocate cacheable memory from audio memory pool. |
| 200 | * PARAMETERS |
| 201 | * void |
| 202 | * RETURNS |
| 203 | * Allocated memory address |
| 204 | *****************************************************************************/ |
| 205 | static void* med_util_alloc_aud_cacheable_mem(kal_uint32 size, char* file_p, long line) |
| 206 | { |
| 207 | /*----------------------------------------------------------------*/ |
| 208 | /* Local Variables */ |
| 209 | /*----------------------------------------------------------------*/ |
| 210 | |
| 211 | /*----------------------------------------------------------------*/ |
| 212 | /* Code Body */ |
| 213 | /*----------------------------------------------------------------*/ |
| 214 | return med_alloc_ext_mem_ext(size, MED_EXT_MEMORY_TYPE_AUDIO_CACHEABLE, file_p, line); |
| 215 | } |
| 216 | |
| 217 | /***************************************************************************** |
| 218 | * FUNCTION |
| 219 | * med_util_free_aud_mem |
| 220 | * DESCRIPTION |
| 221 | * This function is to free audio memory. |
| 222 | * PARAMETERS |
| 223 | * void |
| 224 | * RETURNS |
| 225 | * Allocated memory address |
| 226 | *****************************************************************************/ |
| 227 | static void med_util_free_aud_mem(void** mem_p, char* file_p, long line) |
| 228 | { |
| 229 | /*----------------------------------------------------------------*/ |
| 230 | /* Local Variables */ |
| 231 | /*----------------------------------------------------------------*/ |
| 232 | |
| 233 | /*----------------------------------------------------------------*/ |
| 234 | /* Code Body */ |
| 235 | /*----------------------------------------------------------------*/ |
| 236 | med_free_aud_mem_ext(mem_p, file_p, line); |
| 237 | } |
| 238 | |
| 239 | /***************************************************************************** |
| 240 | * FUNCTION |
| 241 | * med_utility_init |
| 242 | * DESCRIPTION |
| 243 | * |
| 244 | * PARAMETERS |
| 245 | * void |
| 246 | * RETURNS |
| 247 | * |
| 248 | *****************************************************************************/ |
| 249 | kal_bool med_utility_init(void) |
| 250 | { |
| 251 | |
| 252 | /*----------------------------------------------------------------*/ |
| 253 | /* Local Variables */ |
| 254 | /*----------------------------------------------------------------*/ |
| 255 | Media_Func_Reg_Type media_func; |
| 256 | |
| 257 | /*----------------------------------------------------------------*/ |
| 258 | /* Code Body */ |
| 259 | /*----------------------------------------------------------------*/ |
| 260 | |
| 261 | med_mem_mutex = kal_create_mutex("MED MEM"); |
| 262 | |
| 263 | /* Register callback functions to L1audio */ |
| 264 | media_func.alloc_mem = med_util_alloc_aud_mem; |
| 265 | media_func.alloc_mem_cacheable = med_util_alloc_aud_cacheable_mem; |
| 266 | media_func.free_mem = med_util_free_aud_mem; |
| 267 | media_func.set_path_volume = NULL; |
| 268 | media_func.get_active_mode = NULL; |
| 269 | #if defined(__VOLTE_SUPPORT__) |
| 270 | media_func.send_proc_call = aud_send_in_proc_call_req; // is only used in VoLTE DTMF MCU destroy functions |
| 271 | #else |
| 272 | media_func.send_proc_call = NULL; |
| 273 | #endif |
| 274 | media_func.send_proc_call2 = NULL; |
| 275 | media_func.get_meta_file = NULL; |
| 276 | media_func.get_meta_array = NULL; |
| 277 | |
| 278 | #if !defined(L1_NOT_PRESENT) |
| 279 | Audio_MedFuncReg(&media_func); |
| 280 | #endif |
| 281 | |
| 282 | /* init audio memory */ |
| 283 | med_set_aud_memory_pool((unsigned char*)med_context_p->aud_mem_p, MED_AUD_MEM_SIZE); |
| 284 | |
| 285 | return KAL_TRUE; |
| 286 | } |
| 287 | |
| 288 | |