FreeCalypso > hg > tcs211-l1-reconst
comparison chipsetsw/services/Audio/audio_driver.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /****************************************************************************/ | |
2 /* */ | |
3 /* File Name: audio_driver.c */ | |
4 /* */ | |
5 /* Purpose: This file contains all the functions used to manage the */ | |
6 /* driver. */ | |
7 /* */ | |
8 /* Version 0.1 */ | |
9 /* */ | |
10 /* Date Modification */ | |
11 /* ------------------------------------ */ | |
12 /* 09 December 2002 Create */ | |
13 /* */ | |
14 /* Author Frederic Turgis */ | |
15 /* */ | |
16 /* (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved*/ | |
17 /****************************************************************************/ | |
18 | |
19 #include "rv/rv_defined_swe.h" | |
20 #ifdef RVM_AUDIO_MAIN_SWE | |
21 #ifndef _WINDOWS | |
22 #include "config/swconfig.cfg" | |
23 #include "config/sys.cfg" | |
24 #include "config/chipset.cfg" | |
25 #endif | |
26 | |
27 #include "l1_confg.h" | |
28 #include "rvf/rvf_api.h" | |
29 #include "rv/rv_general.h" | |
30 #include "rvm/rvm_gen.h" | |
31 #include "audio/audio_features_i.h" | |
32 #include "audio/audio_api.h" | |
33 #include "audio/audio_env_i.h" | |
34 #include "audio/audio_ffs_i.h" | |
35 #include "audio/audio_structs_i.h" | |
36 #include "audio/audio_macro_i.h" | |
37 #include "rvf/rvf_target.h" | |
38 #include "audio/audio_const_i.h" | |
39 #include "audio/audio_var_i.h" | |
40 #include "audio/audio_error_hdlr_i.h" | |
41 #include "audio/audio_messages_i.h" | |
42 | |
43 #ifndef _WINDOWS | |
44 // include the usefull L1 header | |
45 #define BOOL_FLAG | |
46 #define CHAR_FLAG | |
47 #include "l1_types.h" | |
48 #include "cust_os.h" | |
49 #include "l1audio_cust.h" | |
50 #include "l1audio_msgty.h" | |
51 #include "l1audio_signa.h" | |
52 #include "l1_signa.h" | |
53 #else | |
54 // include the usefull L1 header | |
55 #define BOOL_FLAG | |
56 #define CHAR_FLAG | |
57 #include "l1_types.h" | |
58 #include "l1audio_const.h" | |
59 #include "l1audio_cust.h" | |
60 #include "l1audio_defty.h" | |
61 #include "l1audio_msgty.h" | |
62 #include "l1audio_signa.h" | |
63 #include "l1_const.h" | |
64 #include "l1_defty.h" | |
65 #include "l1_msgty.h" | |
66 #include "l1_signa.h" | |
67 #include "l1_varex.h" | |
68 #include "audio/tests/audio_test.h" | |
69 #endif | |
70 | |
71 #if (L1_AUDIO_DRIVER) | |
72 #if (L1_VOICE_MEMO_AMR) | |
73 extern T_AUDIO_RET audio_driver_vm_amr_play_manager (T_RV_HDR *p_message, T_AUDIO_DRIVER_SESSION *p_session); | |
74 extern T_AUDIO_RET audio_driver_vm_amr_record_manager (T_RV_HDR *p_message, T_AUDIO_DRIVER_SESSION *p_session); | |
75 extern T_AUDIO_RET audio_driver_midi_manager (T_RV_HDR *p_message, T_AUDIO_DRIVER_SESSION *p_session); | |
76 #endif | |
77 | |
78 UINT8 audio_driver_message_switch(T_RV_HDR *p_message); | |
79 void audio_driver_send_status (T_AUDIO_RET status, | |
80 UINT8 status_type, | |
81 UINT8 channel_id, | |
82 T_RV_RETURN return_path); | |
83 void audio_driver_init_send_status (T_AUDIO_RET status, | |
84 UINT8 session_id, | |
85 UINT8 channel_id, | |
86 T_RV_RETURN return_path); | |
87 void audio_driver_manager(T_RV_HDR *p_message); | |
88 T_AUDIO_RET audio_driver_get_play_buffer(UINT8 channel_id, UINT8 **pp_buffer); | |
89 T_AUDIO_RET audio_driver_play_buffer(UINT8 channel_id, UINT8 *p_buffer); | |
90 | |
91 UINT8 audio_driver_message_switch(T_RV_HDR *p_message) | |
92 { | |
93 switch (p_message->msg_id) | |
94 { | |
95 case AUDIO_DRIVER_START_SESSION: | |
96 case AUDIO_DRIVER_STOP_SESSION: | |
97 case AUDIO_DRIVER_FREE_SESSION: | |
98 return(AUDIO_DRIVER_SWITCH); | |
99 break; | |
100 #if (L1_VOICE_MEMO_AMR) | |
101 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
102 case MMI_VM_AMR_RECORD_START_CON: | |
103 case MMI_VM_AMR_RECORD_STOP_CON: | |
104 return(AUDIO_DRIVER_VM_AMR_RECORD_SESSION_SWITCH); | |
105 break; | |
106 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
107 case MMI_VM_AMR_PLAY_START_CON: | |
108 case MMI_VM_AMR_PLAY_STOP_CON: | |
109 return(AUDIO_DRIVER_VM_AMR_PLAY_SESSION_SWITCH); | |
110 break; | |
111 #endif | |
112 #if (L1_MIDI == 1) | |
113 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
114 case MMI_MIDI_START_CON: | |
115 case MMI_MIDI_STOP_CON: | |
116 return(AUDIO_DRIVER_MIDI_SESSION_SWITCH); | |
117 break; | |
118 #endif | |
119 default: | |
120 return(AUDIO_DRIVER_NONE); | |
121 break; | |
122 } // switch | |
123 } | |
124 | |
125 void audio_driver_send_status (T_AUDIO_RET status, | |
126 UINT8 status_type, | |
127 UINT8 channel_id, | |
128 T_RV_RETURN return_path) | |
129 { | |
130 T_AUDIO_DRIVER_STATUS *p_send_message; | |
131 T_RVF_MB_STATUS mb_status = RVF_RED; | |
132 | |
133 while (mb_status == RVF_RED) | |
134 { | |
135 // allocate the message buffer | |
136 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external, | |
137 sizeof (T_AUDIO_DRIVER_STATUS), | |
138 (T_RVF_BUFFER **) (&p_send_message)); | |
139 | |
140 // If insufficient resources, then report a memory error and abort. | |
141 // and wait until more ressource is given | |
142 if (mb_status == RVF_RED) | |
143 { | |
144 audio_driver_error_trace(AUDIO_ENTITY_NO_MEMORY); | |
145 rvf_delay(RVF_MS_TO_TICKS(1000)); | |
146 } | |
147 } | |
148 | |
149 // fill the header of the message + parameters | |
150 p_send_message->os_hdr.msg_id = AUDIO_DRIVER_STATUS_MSG; | |
151 p_send_message->status = status; | |
152 p_send_message->status_type = status_type; | |
153 p_send_message->channel_id = channel_id; | |
154 | |
155 // send message or call callback | |
156 if (return_path.callback_func == NULL) | |
157 rvf_send_msg (return_path.addr_id, p_send_message); | |
158 else | |
159 { | |
160 (*return_path.callback_func)((void *)(p_send_message)); | |
161 rvf_free_buf((T_RVF_BUFFER *)p_send_message); | |
162 } | |
163 } | |
164 | |
165 void audio_driver_init_send_status (T_AUDIO_RET status, | |
166 UINT8 session_id, | |
167 UINT8 channel_id, | |
168 T_RV_RETURN return_path) | |
169 { | |
170 T_AUDIO_DRIVER_INIT_STATUS *p_send_message; | |
171 T_RVF_MB_STATUS mb_status = RVF_RED; | |
172 | |
173 while (mb_status == RVF_RED) | |
174 { | |
175 // allocate the message buffer | |
176 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external, | |
177 sizeof (T_AUDIO_DRIVER_INIT_STATUS), | |
178 (T_RVF_BUFFER **) (&p_send_message)); | |
179 | |
180 // If insufficient resources, then report a memory error and abort. | |
181 // and wait until more ressource is given | |
182 if (mb_status == RVF_RED) | |
183 { | |
184 audio_driver_error_trace(AUDIO_ENTITY_NO_MEMORY); | |
185 rvf_delay(RVF_MS_TO_TICKS(1000)); | |
186 } | |
187 } | |
188 | |
189 // fill the header of the message | |
190 p_send_message->os_hdr.msg_id = AUDIO_DRIVER_INIT_STATUS_MSG; | |
191 | |
192 // fill the status parameters | |
193 p_send_message->status = status; | |
194 p_send_message->session_id = session_id; | |
195 p_send_message->channel_id = channel_id; | |
196 | |
197 // send message or call callback | |
198 if (return_path.callback_func == NULL) | |
199 rvf_send_msg (return_path.addr_id, p_send_message); | |
200 else | |
201 { | |
202 (*return_path.callback_func)((void *)(p_send_message)); | |
203 rvf_free_buf((T_RVF_BUFFER *)p_send_message); | |
204 } | |
205 } | |
206 | |
207 void audio_driver_manager(T_RV_HDR *p_message) | |
208 { | |
209 T_AUDIO_DRIVER_SESSION *p_session; | |
210 T_AUDIO_DRIVER_PARAMETER *driver_parameter; | |
211 T_RV_RETURN return_path; | |
212 T_RVF_MB_STATUS mb_status; | |
213 UINT8 session_id, channel_id, state, j; | |
214 | |
215 // initialize return_path to default values | |
216 return_path.callback_func=NULL; | |
217 return_path.addr_id=0; | |
218 | |
219 // find state + extract information:channel_id or session_id + driver_parameter | |
220 switch (p_message->msg_id) | |
221 { | |
222 // start/stop session messages have channel_id so we know the driver_session | |
223 case AUDIO_DRIVER_START_SESSION: | |
224 case AUDIO_DRIVER_STOP_SESSION: | |
225 case AUDIO_DRIVER_FREE_SESSION: | |
226 channel_id = ((T_AUDIO_DRIVER_HANDLE_SESSION *)p_message)->channel_id; | |
227 p_session = &(p_audio_gbl_var->audio_driver_session[channel_id]); | |
228 state = p_session->session_info.state; | |
229 if (p_message->msg_id != AUDIO_DRIVER_STOP_SESSION) | |
230 return_path = ((T_AUDIO_DRIVER_HANDLE_SESSION *)p_message)->return_path; | |
231 else | |
232 return_path = p_session->session_req.return_path; | |
233 break; | |
234 // messages which contain only session_id, must look for it in ACTIVE driver_session | |
235 default: | |
236 { | |
237 switch (p_message->msg_id) | |
238 { | |
239 #if (L1_VOICE_MEMO_AMR) | |
240 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
241 session_id = AUDIO_VM_AMR_RECORD_SESSION_ID; | |
242 driver_parameter = &(((T_AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION *)p_message)->driver_parameter); | |
243 return_path = ((T_AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION *)p_message)->return_path; | |
244 break; | |
245 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
246 session_id = AUDIO_VM_AMR_PLAY_SESSION_ID; | |
247 driver_parameter = & (((T_AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION *)p_message)->driver_parameter); | |
248 return_path = ((T_AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION *)p_message)->return_path; | |
249 break; | |
250 case MMI_VM_AMR_RECORD_START_CON: | |
251 case MMI_VM_AMR_RECORD_STOP_CON: | |
252 session_id = AUDIO_VM_AMR_RECORD_SESSION_ID; | |
253 break; | |
254 case MMI_VM_AMR_PLAY_START_CON: | |
255 case MMI_VM_AMR_PLAY_STOP_CON: | |
256 session_id = AUDIO_VM_AMR_PLAY_SESSION_ID; | |
257 break; | |
258 #endif | |
259 #if (L1_MIDI == 1) | |
260 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
261 session_id = AUDIO_MIDI_SESSION_ID; | |
262 driver_parameter = &(((T_AUDIO_DRIVER_INIT_MIDI_SESSION *)p_message)->driver_parameter); | |
263 return_path = ((T_AUDIO_DRIVER_INIT_MIDI_SESSION *)p_message)->return_path; | |
264 break; | |
265 case MMI_MIDI_START_CON: | |
266 case MMI_MIDI_STOP_CON: | |
267 session_id = AUDIO_MIDI_SESSION_ID; | |
268 break; | |
269 #endif | |
270 } | |
271 | |
272 // initialize channel_id to browse all driver channels | |
273 channel_id = 0; | |
274 state = AUDIO_DRIVER_CHANNEL_WAIT_INIT; | |
275 | |
276 // look for an active session, which session_id matches the one from the message | |
277 while ( (channel_id < AUDIO_DRIVER_MAX_CHANNEL)&& | |
278 ((p_audio_gbl_var->audio_driver_session[channel_id].session_info.state == AUDIO_DRIVER_CHANNEL_WAIT_INIT)|| | |
279 (p_audio_gbl_var->audio_driver_session[channel_id].session_req.session_id != session_id)) ) | |
280 { | |
281 channel_id++; | |
282 } | |
283 // if channel_id < MAX_CHANNEL, we found an active channel so we can derive channel_id + state | |
284 if (channel_id < AUDIO_DRIVER_MAX_CHANNEL) | |
285 { | |
286 p_session = &(p_audio_gbl_var->audio_driver_session[channel_id]); | |
287 state = p_session->session_info.state; | |
288 return_path = p_session->session_req.return_path; | |
289 } | |
290 } | |
291 break; // default | |
292 } | |
293 | |
294 switch (state) | |
295 { | |
296 case AUDIO_DRIVER_CHANNEL_WAIT_INIT: | |
297 { | |
298 switch (p_message->msg_id) | |
299 { | |
300 #if (L1_VOICE_MEMO_AMR) | |
301 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
302 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
303 #endif | |
304 #if (L1_MIDI == 1) | |
305 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
306 #endif | |
307 { | |
308 T_AUDIO_RET result; | |
309 | |
310 // Find a free channel | |
311 channel_id = 0; | |
312 while ( (p_audio_gbl_var->audio_driver_session[channel_id].session_info.state != AUDIO_DRIVER_CHANNEL_WAIT_INIT) && | |
313 (channel_id < AUDIO_DRIVER_MAX_CHANNEL) ) | |
314 channel_id++; | |
315 | |
316 if (channel_id == AUDIO_DRIVER_MAX_CHANNEL) | |
317 { | |
318 AUDIO_SEND_TRACE("no driver channel available", RV_TRACE_LEVEL_DEBUG_LOW); | |
319 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
320 return; | |
321 } | |
322 | |
323 AUDIO_SEND_TRACE_PARAM("AUDIO DRIVER: open channel", channel_id, RV_TRACE_LEVEL_DEBUG_LOW); | |
324 | |
325 // get session descriptor and fill REQ parameters | |
326 p_session = &(p_audio_gbl_var->audio_driver_session[channel_id]); | |
327 p_session->session_req.session_id = session_id; | |
328 p_session->session_req.size = driver_parameter->buffer_size << 1;// we request 16-bit words buffers | |
329 p_session->session_req.nb_buffer = driver_parameter->nb_buffer; | |
330 // fill return_path parameters, may be used if next message is STOP_SESSION | |
331 p_session->session_req.return_path.callback_func = return_path.callback_func; | |
332 p_session->session_req.return_path.addr_id = return_path.addr_id; | |
333 | |
334 /************************************************************/ | |
335 /* the driver must allocate the RAM buffers pointer */ | |
336 /************************************************************/ | |
337 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal, | |
338 sizeof(T_AUDIO_DRIVER_BUFFER_INFO)*p_session->session_req.nb_buffer, | |
339 (T_RVF_BUFFER **) (&p_session->session_info.buffer)); | |
340 | |
341 // If insufficient resources, then report a memory error and abort. | |
342 if (mb_status == RVF_RED) | |
343 { | |
344 audio_driver_error_trace(AUDIO_ENTITY_NO_MEMORY); | |
345 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
346 return; | |
347 } | |
348 | |
349 /************************************************************/ | |
350 /* the driver must allocate the RAM buffers */ | |
351 /************************************************************/ | |
352 for (j = 0; j < p_session->session_req.nb_buffer; j++) | |
353 { | |
354 mb_status = rvf_get_buf (p_audio_gbl_var->mb_audio_ffs, | |
355 p_session->session_req.size, | |
356 (T_RVF_BUFFER **) (&p_session->session_info.buffer[j].p_start_pointer)); | |
357 | |
358 // If insufficient resources, then report a memory error and abort. | |
359 if (mb_status == RVF_RED) | |
360 { | |
361 UINT8 i; | |
362 // free already allocated buffers + buffer pointer | |
363 if (j > 0) | |
364 { | |
365 for (i = j - 1; i >= 0; i--) | |
366 rvf_free_buf((T_RVF_BUFFER *)p_session->session_info.buffer[i].p_start_pointer); | |
367 } | |
368 rvf_free_buf((T_RVF_BUFFER *)p_session->session_info.buffer); | |
369 audio_driver_error_trace(AUDIO_ENTITY_NO_MEMORY); | |
370 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
371 return; | |
372 } | |
373 | |
374 // initialize parameters | |
375 p_session->session_info.buffer[j].size = p_session->session_req.size; | |
376 | |
377 AUDIO_SEND_TRACE_PARAM("AUDIO DRIVER: allocate buffer", | |
378 p_session->session_info.buffer[j].p_start_pointer, RV_TRACE_LEVEL_DEBUG_LOW); | |
379 } | |
380 | |
381 // info parameters (state must be changed before driver specific functions call | |
382 p_session->session_info.index_l1 = 0; | |
383 p_session->session_info.index_appli = 0; | |
384 p_session->session_info.stop_request = 0; | |
385 | |
386 // conversion of parameters + prepare l1 start message | |
387 switch(p_message->msg_id) | |
388 { | |
389 #if (L1_VOICE_MEMO_AMR) | |
390 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
391 result=audio_driver_vm_amr_record_manager(p_message,p_session); | |
392 break; | |
393 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
394 result=audio_driver_vm_amr_play_manager(p_message,p_session); | |
395 break; | |
396 #endif | |
397 #if (L1_MIDI == 1) | |
398 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
399 result=audio_driver_midi_manager(p_message,p_session); | |
400 break; | |
401 #endif | |
402 } | |
403 | |
404 // check L1 msg allocation was successfull | |
405 if (result != AUDIO_OK) | |
406 { | |
407 AUDIO_SEND_TRACE("AUDIO DRIVER MANAGER: L1 msg allocation failed", RV_TRACE_LEVEL_DEBUG_LOW); | |
408 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
409 return; | |
410 } | |
411 | |
412 // state (must be changed after driver specific functions calls) | |
413 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_START; | |
414 | |
415 audio_driver_init_send_status(AUDIO_OK, session_id, channel_id, return_path); | |
416 } //case AUDIO_DRIVER_INIT_..._SESSION: | |
417 break; | |
418 case AUDIO_DRIVER_START_SESSION: | |
419 audio_driver_error_trace(AUDIO_ERROR_START_EVENT); | |
420 audio_driver_send_status(AUDIO_ERROR, AUDIO_START_STATUS, channel_id, return_path); | |
421 break; | |
422 case AUDIO_DRIVER_STOP_SESSION: | |
423 audio_driver_error_trace(AUDIO_ERROR_STOP_EVENT); | |
424 audio_driver_send_status(AUDIO_ERROR, AUDIO_STOP_STATUS, channel_id, return_path); | |
425 break; | |
426 case AUDIO_DRIVER_FREE_SESSION: | |
427 audio_driver_error_trace(AUDIO_ERROR_FREE_EVENT); | |
428 audio_driver_send_status(AUDIO_ERROR, AUDIO_FREE_STATUS, channel_id, return_path); | |
429 break; | |
430 } // switch (p_message->msg_id) | |
431 } //case AUDIO_DRIVER_CHANNEL_WAIT_INIT: | |
432 break; | |
433 case AUDIO_DRIVER_CHANNEL_WAIT_START: | |
434 { | |
435 switch (p_message->msg_id) | |
436 { | |
437 case AUDIO_DRIVER_START_SESSION: | |
438 { | |
439 T_AUDIO_RET result; | |
440 | |
441 // fill notification parameters | |
442 p_session->session_req.return_path.callback_func = return_path.callback_func; | |
443 p_session->session_req.return_path.addr_id = return_path.addr_id; | |
444 | |
445 // send l1 message | |
446 switch(p_session->session_req.session_id) | |
447 { | |
448 #if (L1_VOICE_MEMO_AMR) | |
449 case AUDIO_VM_AMR_RECORD_SESSION_ID: | |
450 result=audio_driver_vm_amr_record_manager(p_message,p_session); | |
451 break; | |
452 case AUDIO_VM_AMR_PLAY_SESSION_ID: | |
453 result=audio_driver_vm_amr_play_manager(p_message,p_session); | |
454 break; | |
455 #endif | |
456 #if (L1_MIDI == 1) | |
457 case AUDIO_MIDI_SESSION_ID: | |
458 result=audio_driver_midi_manager(p_message,p_session); | |
459 break; | |
460 #endif | |
461 } | |
462 | |
463 if (result != AUDIO_OK) | |
464 { | |
465 audio_driver_error_trace(AUDIO_ERROR_L1_START_EVENT); | |
466 audio_driver_send_status(AUDIO_ERROR, AUDIO_START_STATUS, channel_id, return_path); | |
467 return; | |
468 } | |
469 | |
470 // change state | |
471 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_START_CON; | |
472 } | |
473 break; | |
474 case AUDIO_DRIVER_STOP_SESSION: | |
475 { | |
476 // deallocate buffers | |
477 for(j=0; j<p_session->session_req.nb_buffer; j++) | |
478 { | |
479 mb_status=rvf_free_buf((T_RVF_BUFFER *)(p_session->session_info.buffer[j].p_start_pointer)); | |
480 | |
481 AUDIO_SEND_TRACE_PARAM("AUDIO DRIVER MANAGER: deallocate buffer", | |
482 j, RV_TRACE_LEVEL_DEBUG_LOW); | |
483 | |
484 if (mb_status != RVF_GREEN) | |
485 AUDIO_SEND_TRACE_PARAM("can't deallocate buffer", j, RV_TRACE_LEVEL_ERROR); | |
486 } | |
487 | |
488 // Deallocate buffers pointer | |
489 rvf_free_buf((T_RVF_BUFFER *)p_session->session_info.buffer); | |
490 | |
491 // deallocate l1 message | |
492 audio_deallocate_l1_message(p_session->session_req.p_l1_send_message); | |
493 | |
494 // send status OK | |
495 audio_driver_send_status(AUDIO_OK,AUDIO_STOP_STATUS,channel_id,return_path); | |
496 | |
497 // change state | |
498 p_session->session_info.state=AUDIO_DRIVER_CHANNEL_WAIT_INIT; | |
499 } | |
500 break; | |
501 #if (L1_VOICE_MEMO_AMR) | |
502 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
503 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
504 #endif | |
505 #if (L1_MIDI == 1) | |
506 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
507 #endif | |
508 audio_driver_error_trace(AUDIO_ERROR_INIT_EVENT); | |
509 audio_driver_init_send_status(AUDIO_ERROR, session_id, 0, return_path); | |
510 break; | |
511 case AUDIO_DRIVER_FREE_SESSION: | |
512 audio_driver_error_trace(AUDIO_ERROR_FREE_EVENT); | |
513 audio_driver_send_status(AUDIO_ERROR, AUDIO_FREE_STATUS, channel_id, return_path); | |
514 break; | |
515 } // switch | |
516 } //case AUDIO_DRIVER_CHANNEL_WAIT_START: | |
517 break; | |
518 case AUDIO_DRIVER_CHANNEL_WAIT_START_CON: | |
519 { | |
520 switch (p_message->msg_id) | |
521 { | |
522 #if (L1_VOICE_MEMO_AMR) | |
523 case MMI_VM_AMR_RECORD_START_CON: | |
524 case MMI_VM_AMR_PLAY_START_CON: | |
525 #endif | |
526 #if (L1_MIDI == 1) | |
527 case MMI_MIDI_START_CON: | |
528 #endif | |
529 // change state | |
530 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_STOP; | |
531 break; | |
532 case AUDIO_DRIVER_STOP_SESSION: | |
533 // change state | |
534 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_START_CON_TO_STOP; | |
535 break; | |
536 #if (L1_VOICE_MEMO_AMR) | |
537 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
538 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
539 #endif | |
540 #if (L1_MIDI == 1) | |
541 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
542 #endif | |
543 audio_driver_error_trace(AUDIO_ERROR_INIT_EVENT); | |
544 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
545 break; | |
546 case AUDIO_DRIVER_START_SESSION: | |
547 audio_driver_error_trace(AUDIO_ERROR_START_EVENT); | |
548 audio_driver_send_status(AUDIO_ERROR, AUDIO_START_STATUS, channel_id, return_path); | |
549 break; | |
550 case AUDIO_DRIVER_FREE_SESSION: | |
551 audio_driver_error_trace(AUDIO_ERROR_FREE_EVENT); | |
552 audio_driver_send_status(AUDIO_ERROR, AUDIO_FREE_STATUS, channel_id, return_path); | |
553 break; | |
554 } // switch | |
555 } //case AUDIO_DRIVER_CHANNEL_WAIT_START_CON: | |
556 break; | |
557 case AUDIO_DRIVER_CHANNEL_WAIT_STOP: | |
558 { | |
559 switch (p_message->msg_id) | |
560 { | |
561 case AUDIO_DRIVER_STOP_SESSION: | |
562 { | |
563 // 1st stop request | |
564 if (p_session->session_info.stop_request == 0) | |
565 { | |
566 T_AUDIO_RET result; | |
567 | |
568 // send l1 message STOP_REQ | |
569 switch(p_session->session_req.session_id) | |
570 { | |
571 #if (L1_VOICE_MEMO_AMR) | |
572 case AUDIO_VM_AMR_RECORD_SESSION_ID: | |
573 result=audio_driver_vm_amr_record_manager(p_message,p_session); | |
574 break; | |
575 case AUDIO_VM_AMR_PLAY_SESSION_ID: | |
576 result=audio_driver_vm_amr_play_manager(p_message,p_session); | |
577 break; | |
578 #endif | |
579 #if (L1_MIDI == 1) | |
580 case AUDIO_MIDI_SESSION_ID: | |
581 result=audio_driver_midi_manager(p_message,p_session); | |
582 break; | |
583 #endif | |
584 } | |
585 | |
586 // allocate or send L1 msg went wrong | |
587 if (result != AUDIO_OK) | |
588 { | |
589 audio_driver_error_trace(AUDIO_ERROR_L1_STOP_EVENT); | |
590 audio_driver_send_status(AUDIO_ERROR, AUDIO_STOP_STATUS, channel_id, return_path); | |
591 return; | |
592 } | |
593 | |
594 // STOP has been requested, no longer accept it | |
595 p_session->session_info.stop_request = 1; | |
596 } | |
597 else | |
598 { | |
599 audio_driver_error_trace(AUDIO_ERROR_STOP_EVENT); | |
600 audio_driver_send_status(AUDIO_ERROR, AUDIO_STOP_STATUS, channel_id, return_path); | |
601 } | |
602 } | |
603 break; | |
604 #if (L1_VOICE_MEMO_AMR) | |
605 case MMI_VM_AMR_RECORD_STOP_CON: | |
606 { | |
607 // send last notification | |
608 T_AUDIO_DRIVER_LAST_NOTIFICATION *p_status_message; | |
609 | |
610 // Allocate the Riviera buffer | |
611 mb_status = RVF_RED; | |
612 while (mb_status == RVF_RED) | |
613 { | |
614 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal, | |
615 sizeof (T_AUDIO_DRIVER_LAST_NOTIFICATION), | |
616 (T_RVF_BUFFER **) (&p_status_message)); | |
617 // If insufficient resources, then report a memory error and abort. | |
618 if (mb_status == RVF_RED) | |
619 { | |
620 // the memory is insufficient to continue the non regression test | |
621 audio_driver_error_trace(AUDIO_ENTITY_NO_MEMORY); | |
622 rvf_delay(RVF_MS_TO_TICKS(1000)); | |
623 } | |
624 } | |
625 | |
626 // Fill the message ID | |
627 p_status_message->header.msg_id = AUDIO_DRIVER_LAST_NOTIFICATION_MSG; | |
628 | |
629 // fill parameters | |
630 p_status_message->channel_id = channel_id; | |
631 p_status_message->recorded_size = ((T_MMI_VM_AMR_RECORD_CON *)p_message)->recorded_size - SC_VM_AMR_END_MASK_SIZE; | |
632 p_status_message->p_buffer = | |
633 (UINT16 *)p_session->session_info.buffer[p_session->session_info.index_l1].p_start_pointer; | |
634 | |
635 if (return_path.callback_func == NULL) | |
636 rvf_send_msg (return_path.addr_id, p_status_message); | |
637 else | |
638 { | |
639 // call the callback function | |
640 (*(return_path.callback_func))((void *)(p_status_message)); | |
641 rvf_free_buf((T_RVF_BUFFER *)p_status_message); | |
642 } | |
643 | |
644 // change state | |
645 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_FREE; | |
646 } | |
647 break; | |
648 #endif // #if (L1_VOICE_MEMO_AMR) | |
649 #if (L1_VOICE_MEMO_AMR) | |
650 case MMI_VM_AMR_PLAY_STOP_CON: | |
651 #endif | |
652 #if (L1_MIDI == 1) | |
653 case MMI_MIDI_STOP_CON: | |
654 #endif | |
655 { | |
656 // deallocate buffers | |
657 for (j = 0; j < p_session->session_req.nb_buffer; j++) | |
658 { | |
659 mb_status = rvf_free_buf ((T_RVF_BUFFER *) (p_session->session_info.buffer[j].p_start_pointer)); | |
660 | |
661 AUDIO_SEND_TRACE_PARAM("AUDIO DRIVER MANAGER: deallocate buffer", j, RV_TRACE_LEVEL_DEBUG_LOW); | |
662 | |
663 if (mb_status != RVF_GREEN) | |
664 AUDIO_SEND_TRACE_PARAM("can't deallocate buffer", j, RV_TRACE_LEVEL_ERROR); | |
665 } | |
666 // Deallocate buffers pointer | |
667 rvf_free_buf((T_RVF_BUFFER *)p_session->session_info.buffer); | |
668 | |
669 audio_driver_send_status (AUDIO_OK, AUDIO_STOP_STATUS, channel_id, | |
670 return_path); | |
671 // change state | |
672 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_INIT; | |
673 } | |
674 break; | |
675 #if (L1_VOICE_MEMO_AMR) | |
676 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
677 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
678 #endif | |
679 #if (L1_MIDI == 1) | |
680 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
681 #endif | |
682 audio_driver_error_trace(AUDIO_ERROR_INIT_EVENT); | |
683 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
684 break; | |
685 case AUDIO_DRIVER_START_SESSION: | |
686 audio_driver_error_trace(AUDIO_ERROR_START_EVENT); | |
687 audio_driver_send_status(AUDIO_ERROR, AUDIO_START_STATUS, channel_id, return_path); | |
688 break; | |
689 case AUDIO_DRIVER_FREE_SESSION: | |
690 audio_driver_error_trace(AUDIO_ERROR_FREE_EVENT); | |
691 audio_driver_send_status(AUDIO_ERROR, AUDIO_FREE_STATUS, channel_id, return_path); | |
692 break; | |
693 } //switch | |
694 } //case AUDIO_DRIVER_CHANNEL_WAIT_STOP: | |
695 break; | |
696 case AUDIO_DRIVER_CHANNEL_WAIT_START_CON_TO_STOP: | |
697 { | |
698 T_AUDIO_RET result = AUDIO_OK; | |
699 switch (p_message->msg_id) | |
700 { | |
701 #if (L1_VOICE_MEMO_AMR) | |
702 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
703 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
704 #endif | |
705 #if (L1_MIDI == 1) | |
706 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
707 #endif | |
708 audio_driver_error_trace(AUDIO_ERROR_INIT_EVENT); | |
709 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
710 return; | |
711 break; | |
712 case AUDIO_DRIVER_START_SESSION: | |
713 audio_driver_error_trace(AUDIO_ERROR_START_EVENT); | |
714 audio_driver_send_status(AUDIO_ERROR, AUDIO_START_STATUS, channel_id, return_path); | |
715 return; | |
716 break; | |
717 case AUDIO_DRIVER_STOP_SESSION: | |
718 audio_driver_error_trace(AUDIO_ERROR_STOP_EVENT); | |
719 audio_driver_send_status(AUDIO_ERROR, AUDIO_STOP_STATUS, channel_id, return_path); | |
720 return; | |
721 break; | |
722 case AUDIO_DRIVER_FREE_SESSION: | |
723 audio_driver_error_trace(AUDIO_ERROR_FREE_EVENT); | |
724 audio_driver_send_status(AUDIO_ERROR, AUDIO_FREE_STATUS, channel_id, return_path); | |
725 return; | |
726 break; | |
727 #if (L1_VOICE_MEMO_AMR) | |
728 case MMI_VM_AMR_RECORD_START_CON: | |
729 // send L1 stop msg | |
730 result=audio_driver_vm_amr_record_manager(p_message, p_session); | |
731 break; | |
732 case MMI_VM_AMR_PLAY_START_CON: | |
733 // send L1 stop msg | |
734 result=audio_driver_vm_amr_play_manager(p_message, p_session); | |
735 break; | |
736 #endif | |
737 #if (L1_MIDI == 1) | |
738 case MMI_MIDI_START_CON: | |
739 // send L1 stop msg | |
740 result=audio_driver_midi_manager(p_message,p_session); | |
741 break; | |
742 #endif | |
743 } | |
744 | |
745 if (result != AUDIO_OK) | |
746 { | |
747 audio_driver_send_status(AUDIO_ERROR, AUDIO_STOP_STATUS, channel_id, return_path); | |
748 return; | |
749 } | |
750 else | |
751 { | |
752 // next state should be WAIT_STOP_CON, which is WAIT_STOP + stop_request == 1 | |
753 p_session->session_info.stop_request = 1; | |
754 // change state | |
755 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_STOP; | |
756 } | |
757 } | |
758 break; | |
759 case AUDIO_DRIVER_CHANNEL_WAIT_FREE: | |
760 { | |
761 switch (p_message->msg_id) | |
762 { | |
763 case AUDIO_DRIVER_FREE_SESSION: | |
764 { | |
765 // deallocate buffers | |
766 for (j = 0; j < p_session->session_req.nb_buffer; j++) | |
767 { | |
768 mb_status = rvf_free_buf ((T_RVF_BUFFER *) (p_session->session_info.buffer[j].p_start_pointer)); | |
769 | |
770 AUDIO_SEND_TRACE_PARAM("AUDIO DRIVER MANAGER: deallocate buffer", j, RV_TRACE_LEVEL_DEBUG_LOW); | |
771 | |
772 if (mb_status != RVF_GREEN) | |
773 AUDIO_SEND_TRACE_PARAM("can't deallocate buffer", j, RV_TRACE_LEVEL_ERROR); | |
774 } | |
775 // Deallocate buffers pointer | |
776 rvf_free_buf((T_RVF_BUFFER *)p_session->session_info.buffer); | |
777 | |
778 audio_driver_send_status (AUDIO_OK, AUDIO_FREE_STATUS, channel_id, | |
779 return_path); | |
780 | |
781 // change state | |
782 p_session->session_info.state = AUDIO_DRIVER_CHANNEL_WAIT_INIT; | |
783 } | |
784 break; | |
785 #if (L1_VOICE_MEMO_AMR) | |
786 case AUDIO_DRIVER_INIT_VM_AMR_RECORD_SESSION: | |
787 case AUDIO_DRIVER_INIT_VM_AMR_PLAY_SESSION: | |
788 #endif | |
789 #if (L1_MIDI == 1) | |
790 case AUDIO_DRIVER_INIT_MIDI_SESSION: | |
791 #endif | |
792 audio_driver_error_trace(AUDIO_ERROR_INIT_EVENT); | |
793 audio_driver_init_send_status(AUDIO_ERROR, session_id, channel_id, return_path); | |
794 break; | |
795 case AUDIO_DRIVER_START_SESSION: | |
796 audio_driver_error_trace(AUDIO_ERROR_START_EVENT); | |
797 audio_driver_send_status(AUDIO_ERROR, AUDIO_START_STATUS, channel_id, return_path); | |
798 break; | |
799 case AUDIO_DRIVER_STOP_SESSION: | |
800 audio_driver_error_trace(AUDIO_ERROR_STOP_EVENT); | |
801 audio_driver_send_status(AUDIO_ERROR, AUDIO_STOP_STATUS, channel_id, return_path); | |
802 break; | |
803 } // switch | |
804 } | |
805 break; | |
806 } | |
807 } | |
808 #endif // (L1_AUDIO_DRIVER) | |
809 | |
810 #endif // #ifdef RVM_AUDIO_MAIN_SWE |