📄 aud_media.c
字号:
/*****************************************************************************
* FUNCTION
* aud_stop_unfinished_process
* DESCRIPTION
* This function is to stop unfinished media process
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void aud_stop_unfinished_process(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
switch (aud_context_p->state)
{
case AUD_MEDIA_PLAY:
{
/* Stop voice memo recording process */
aud_media_stop_and_store_info_to_temp();
/* stop volume crescendo timer */
med_stop_timer(AUD_TIMER_CRESCENDO);
/* stop the driver like led, backlight and vibrator */
aud_melody_stop_driver();
/* free file buffer */
aud_free_melody_file_buffer();
/* enter AUD_MEDIA_IDLE state */
AUD_ENTER_STATE(AUD_MEDIA_IDLE);
break;
}
case AUD_MEDIA_PLAY_PAUSED:
case AUD_MEDIA_SEEK_PAUSED:
{
/* Stop voice memo recording process */
aud_media_stop_and_store_info_to_temp();
/* free file buffer */
aud_free_melody_file_buffer();
/* enter AUD_MEDIA_IDLE state */
AUD_ENTER_STATE(AUD_MEDIA_IDLE);
break;
}
case AUD_MEDIA_PLAY_FINISH:
{
/* Stop voice memo recording process */
aud_media_stop_and_store_info_to_temp();
/* stop volume crescendo timer */
med_stop_timer(AUD_TIMER_CRESCENDO);
/* enter AUD_MEDIA_IDLE state */
AUD_ENTER_STATE(AUD_MEDIA_IDLE);
break;
}
case AUD_VM_RECORD:
case AUD_MEDIA_RECORD:
case AUD_MEDIA_RECORD_PAUSED:
{
kal_uint32 len;
kal_int32 result;
/* Stop voice memo recording process */
Media_Stop();
/* Restore input source when stop recording */
L1SP_SetInputSource(aud_context_p->input_device);
/* Write the remaining data to file */
Media_GetReadBuffer(&(aud_context_p->buf_p), (kal_uint32*) & (aud_context_p->buf_len));
ASSERT(aud_context_p->buf_p != NULL);
ASSERT(aud_context_p->buf_len <= AUD_RING_BUFFER_LEN);
result = FS_Write(
aud_context_p->current_file_handle,
aud_context_p->buf_p,
aud_context_p->buf_len * 2,
&len);
/* update offset */
aud_context_p->offset += len;
Media_ReadDataDone(len >> 1);
AUD_VALUE_TRACE(aud_context_p->offset, aud_context_p->buf_len, len >> 1);
if (result == FS_NO_ERROR)
{
/* in case that encounter ring buffer boundary */
Media_GetReadBuffer(&(aud_context_p->buf_p), (kal_uint32*) & (aud_context_p->buf_len));
if (aud_context_p->buf_len > 0)
{
ASSERT(aud_context_p->buf_p != NULL);
ASSERT(aud_context_p->buf_len <= AUD_RING_BUFFER_LEN);
result = FS_Write(
aud_context_p->current_file_handle,
aud_context_p->buf_p,
aud_context_p->buf_len * 2,
&len);
/* update offset */
aud_context_p->offset += len;
Media_ReadDataDone(len >> 1);
AUD_VALUE_TRACE(aud_context_p->offset, aud_context_p->buf_len, len >> 1);
}
}
/* close record file, add header if wav */
aud_close_record_file();
/* enter AUD_MEDIA_IDLE state */
AUD_ENTER_STATE(AUD_MEDIA_IDLE);
break;
}
default:
{
break;
}
}
}
/*****************************************************************************
* FUNCTION
* aud_media_record_callback
* DESCRIPTION
* This function is the callback function for recording audio.
* PARAMETERS
* event [IN]
* RETURNS
* void
*****************************************************************************/
void aud_media_record_callback(Media_Event event)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
aud_media_read_data_ind_struct *ind_p = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (event == MEDIA_TERMINATED)
{
return;
}
ind_p = (aud_media_read_data_ind_struct*) construct_local_para(sizeof(aud_media_read_data_ind_struct), TD_CTRL);
ind_p->event = event;
aud_send_ilm(MOD_MED, MSG_ID_AUD_MEDIA_READ_DATA_IND, ind_p, NULL);
}
/*****************************************************************************
* FUNCTION
* aud_media_record_req_hdlr
* DESCRIPTION
* This function is to handle the audio record request.
* PARAMETERS
* ilm_ptr [?]
* RETURNS
* void
*****************************************************************************/
void aud_media_record_req_hdlr(ilm_struct *ilm_ptr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
l4aud_media_record_req_struct *msg_p = NULL;
kal_uint8 result;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
AUD_FUNC_ENTRY(AUD_MEDIA_RECORD_REQ_HDLR);
aud_context_p->src_mod = ilm_ptr->src_mod_id;
msg_p = (l4aud_media_record_req_struct*) ilm_ptr->local_para_ptr;
aud_context_p->src_id = msg_p->src_id;
/* if keytone is playing, stop it */
aud_keytone_stop();
/* if tone is playing, stop it */
if (aud_context_p->tone_playing)
{
aud_tone_stop();
}
#ifdef __MED_MMA_MOD__
/* close all mma tasks */
aud_mma_close_all();
#endif /* __MED_MMA_MOD__ */
#if defined(__MED_VID_MOD__) || defined (__MED_MJPG_MOD__)
if (!vid_is_audio_channel_available())
{
/* send confirm message to L4 */
aud_set_result(MED_RES_BUSY);
AUD_SET_EVENT(AUD_EVT_RECORD);
if (aud_context_p->src_mod != MOD_MMI)
{
aud_send_media_record_cnf(MED_RES_BUSY);
}
return;
}
#endif /* defined(__MED_VID_MOD__) || defined (__MED_MJPG_MOD__) */
if (!(aud_context_p->state == AUD_MEDIA_RECORD ||
aud_context_p->state == AUD_MEDIA_RECORD_PAUSED ||
aud_context_p->state == AUD_VM_RECORD || aud_context_p->state == AUD_VM_RECORD_PAUSED))
{
aud_stop_unfinished_process();
}
switch (aud_context_p->state)
{
case AUD_MEDIA_IDLE:
{
result = aud_open_record_file((kal_wchar*) msg_p->file_name, (kal_uint8) msg_p->format);
if (result != MED_RES_OK)
{
aud_set_result(result);
AUD_SET_EVENT(AUD_EVT_RECORD);
if (aud_context_p->src_mod != MOD_MMI)
{
aud_send_media_record_cnf(result);
}
return;
}
if (aud_context_p->current_file_handle >= 0)
{
if (!msg_p->default_input)
{
L1SP_SetInputSource(custom_cfg_hw_aud_input_path(msg_p->input_source));
aud_context_p->use_default_input = KAL_FALSE;
}
else
{
aud_context_p->use_default_input = KAL_TRUE;
}
/* set buffer */
Media_SetBuffer(aud_context_p->ring_buf, AUD_RING_BUFFER_LEN);
/* start to record */
#if defined(AMRWB_ENCODE)
/* Use higher quality to record FM radio */
if((aud_context_p->current_format == MEDIA_FORMAT_AMR_WB) && (msg_p->input_source == AUDIO_DEVICE_FMRR))
{
kal_uint8 rec_param = 0x28;
result = Media_Record((Media_Format) aud_context_p->current_format, aud_media_record_callback, (void*)rec_param);
}
else
#endif
{
result = Media_Record((Media_Format) aud_context_p->current_format, aud_media_record_callback, NULL);
}
#if !defined(__MTK_TARGET__) /* MODIS */
result = MEDIA_SUCCESS;
#endif
if (result != MEDIA_SUCCESS)
{
/* Restore input source when stop recording */
L1SP_SetInputSource(aud_context_p->input_device);
aud_set_result(aud_get_res(result));
AUD_SET_EVENT(AUD_EVT_RECORD);
if (aud_context_p->src_mod != MOD_MMI)
{
aud_send_media_record_cnf(aud_get_res(result));
}
return;
}
/* reset offset */
aud_context_p->offset = 0;
aud_set_result(MED_RES_OK);
AUD_SET_EVENT(AUD_EVT_RECORD);
if (aud_context_p->src_mod != MOD_MMI)
{
aud_send_media_record_cnf(MED_RES_OK);
}
/* enter AUD_MEDIA_RECORD state */
AUD_ENTER_STATE(AUD_MEDIA_RECORD);
}
else
{
/* send confirm message to L4 */
aud_set_result(MED_RES_OPEN_FILE_FAIL);
AUD_SET_EVENT(AUD_EVT_RECORD);
if (aud_context_p->src_mod != MOD_MMI)
{
aud_send_media_record_cnf(MED_RES_OPEN_FILE_FAIL);
}
}
break;
}
default:
{
/* send confirm message to L4 */
aud_set_result(MED_RES_BUSY);
AUD_SET_EVENT(AUD_EVT_RECORD);
if (aud_context_p->src_mod != MOD_MMI)
{
aud_send_media_record_cnf(MED_RES_BUSY);
}
break;
}
}
}
/*****************************************************************************
* FUNCTION
* aud_media_play_stream_event_callback
* DESCRIPTION
* This function is ....
* PARAMETERS
* handle [?]
* event [IN]
* RETURNS
* void
*****************************************************************************/
void aud_media_play_stream_event_callback(MHdl *handle, Media_Event event)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
aud_media_play_stream_event_ind_struct *ind_p = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ind_p =
(aud_media_play_stream_event_ind_struct*) construct_local_para(
sizeof(aud_media_play_stream_event_ind_struct),
TD_CTRL);
ind_p->src_id = aud_context_p->src_id;
ind_p->event = event;
ind_p->seq_no = aud_context_p->last_seq_no;
aud_send_ilm(MOD_MED, MSG_ID_AUD_MEDIA_PLAY_STREAM_EVENT_IND, ind_p, NULL);
}
/*****************************************************************************
* FUNCTION
* aud_media_play_byte_stream
* DESCRIPTION
* This function is ....
* PARAMETERS
* data [?]
* size [IN]
* play_style [IN]
* RETURNS
* void
*****************************************************************************/
kal_uint8 aud_media_play_byte_stream(kal_uint8 *data, kal_uint32 size, kal_uint8 play_style)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
FSAL_Status eFSALRet;
kal_uint8 result;
media_open_func_ptr openFunc = NULL;
media_ctrl_func_ptr closeFunc, playFunc;
media_set_buf_func_ptr setBufFunc;
Media_VM_PCM_Param vpFormat;
void *param = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ASSERT(aud_context_p->state == AUD_MEDIA_IDLE);
#if !defined(__MTK_TARGET__) /* MODIS */
return MED_RES_OK;
#else /* !defined(__MTK_TARGET__) */
/* open file for playing */
FSAL_Direct_SetRamFileSize(¤t_file_stream, size);
if ((eFSALRet = FSAL_Open(¤t_file_stream, data, FSAL_ROMFILE)) != FSAL_OK)
{
result = MED_RES_OPEN_FILE_FAIL;
}
else
{
switch (aud_context_p->current_format)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -