📄 aud_media.c
字号:
kal_uint8 *header;
kal_uint16 size;
}
aud_file_header_struct;
aud_file_header_struct aud_file_header[2];
const kal_uint8 amr_header[] = AMR_HEADER;
const kal_uint8 awb_header[] = AWB_HEADER;
#ifdef __MED_VID_MOD__
extern STMp4Parser stMp4Parser;
extern STFSAL fsalAudioFile;
#endif /* __MED_VID_MOD__ */
#if defined (__MED_MJPG_AUDIO__)
extern med_avi_info_struct avi_data;
#endif
STFSAL current_file_stream;
/* Use Static Memory For FSAL Buffer to avoid External memory fragment */
#if defined(AUD_PROC_USE_EXT_MEM)
static kal_uint8 med_aud_fasl_buf[AUD_PROC_BUF_SIZE];
#endif
#ifdef __MED_BT_A2DP_MOD__
#if defined(__BTMTK__)
extern void aud_bt_a2dp_open_codec(void);
#elif defined(__BTVCSR_HCI_BCHS__)
extern void aud_bt_a2dp_set_output_on(kal_bool on);
extern void aud_bt_a2dp_media_output_hdlr(kal_bool on);
extern void aud_bt_a2dp_media_play_hdlr(void);
extern void aud_bt_a2dp_media_pause_hdlr(void);
extern void aud_bt_a2dp_media_resume_hdlr(void);
extern void aud_bt_a2dp_media_stop_hdlr(void);
#endif
#endif /* __MED_BT_A2DP_MOD__ */
/*========== Functions =============*/
/*****************************************************************************
* FUNCTION
* aud_media_init
* DESCRIPTION
* This function is used to init aud_media module
* PARAMETERS
* void
* RETURNS
*
*****************************************************************************/
kal_bool aud_media_init(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
aud_file_header[0].header = (kal_uint8*) amr_header;
aud_file_header[0].size = sizeof(AMR_HEADER) - 1;
aud_file_header[1].header = (kal_uint8*) awb_header;
aud_file_header[1].size = sizeof(AWB_HEADER) - 1;
aud_context_p->processing_data = KAL_FALSE;
#ifdef DEDI_AMR_REC_BUFFER
aud_context_p->amr_buffer_p = NULL;
aud_context_p->amr_buffer_size = 0;
#endif /* DEDI_AMR_REC_BUFFER */
aud_context_p->start_offset = aud_context_p->end_offset = 0;
#ifdef __RICH_AUDIO_PROFILE__
audio_input_stream_mutex = kal_create_mutex("audio_input_stream_mutex");
#endif
return KAL_TRUE;
}
/*****************************************************************************
* FUNCTION
* aud_open_record_file
* DESCRIPTION
* This function is to open file for recording
* PARAMETERS
* file_name [?] kal_uint8 format
* format [IN]
* RETURNS
* kal_uint8
*****************************************************************************/
kal_uint8 aud_open_record_file(kal_wchar *file_name, kal_uint8 format)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint32 len;
kal_uint8 res;
kal_int32 result;
kal_bool file_exist = KAL_FALSE;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if ((res = aud_check_disc_space(file_name, RECORD_MEM_MARGIN)) != MED_RES_OK)
{
return res;
}
/* set current file foramt */
aud_context_p->current_format = med_get_media_type((kal_wchar*) file_name);
/* check if the format valid */
if (aud_context_p->current_format == MED_TYPE_NONE)
{
if (format == MED_TYPE_NONE)
{
return MED_RES_INVALID_FORMAT;
}
else
{
aud_context_p->current_format = format;
}
}
else if (aud_context_p->current_format == MED_TYPE_WAV)
{
if (format == MED_TYPE_WAV)
{
aud_context_p->current_format = MED_TYPE_WAV;
}
else
{
aud_context_p->current_format = MED_TYPE_WAV_DVI_ADPCM;
}
}
else if (aud_context_p->current_format == MED_TYPE_GSM_EFR)
{
if (format == MED_TYPE_GSM_FR)
{
aud_context_p->current_format = MED_TYPE_GSM_FR;
}
}
/* open the file */
if ((aud_context_p->current_file_handle = FS_Open((kal_wchar*) file_name, FS_READ_WRITE)) >= 0)
{
file_exist = KAL_TRUE;
}
else
{
aud_context_p->current_file_handle = FS_Open((kal_wchar*) file_name, FS_CREATE | FS_READ_WRITE);
}
if (aud_context_p->current_file_handle >= 0)
{
if (file_exist)
{
FS_Seek(aud_context_p->current_file_handle, (int)0, FS_FILE_END);
}
else if (aud_context_p->current_format == MED_TYPE_AMR || aud_context_p->current_format == MED_TYPE_AMR_WB)
{
aud_file_header_struct *file_header;
file_header = &(aud_file_header[aud_context_p->current_format - MED_TYPE_AMR]);
result = FS_Write(aud_context_p->current_file_handle, file_header->header, file_header->size, &len);
if (result != FS_NO_ERROR || len != file_header->size)
{
FS_Close(aud_context_p->current_file_handle);
aud_context_p->current_file_handle = -1;
return MED_RES_OPEN_FILE_FAIL;
}
#ifdef DEDI_AMR_REC_BUFFER
if (aud_context_p->speech_on)
{
aud_context_p->amr_buffer_size = AMR515_BufferSize();
if (aud_context_p->amr_buffer_size > 0)
{
aud_context_p->amr_buffer_p = med_alloc_int_mem(aud_context_p->amr_buffer_size);
AMR515_SetBuffer(aud_context_p->amr_buffer_p, aud_context_p->amr_buffer_size);
}
}
#endif /* DEDI_AMR_REC_BUFFER */
}
kal_mem_cpy(aud_context_p->current_file_name, file_name, MAX_FILE_NAME_LEN * ENCODE_BYTE);
return MED_RES_OK;
}
else if (aud_context_p->current_file_handle == FS_WRITE_PROTECTION)
{
return MED_RES_WRITE_PROTECTION;
}
else
{
return MED_RES_OPEN_FILE_FAIL;
}
}
/*****************************************************************************
* FUNCTION
* aud_close_record_file
* DESCRIPTION
* This function is to close the recorded file.
* PARAMETERS
* void
* RETURNS
* kal_uint8
*****************************************************************************/
kal_uint8 aud_close_record_file(void)
{
#if !defined(MT6205B) && !defined(MT6208)
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint32 len;
kal_int32 result;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (aud_context_p->current_format == MED_TYPE_WAV ||
aud_context_p->current_format == MED_TYPE_WAV_ALAW ||
aud_context_p->current_format == MED_TYPE_WAV_ULAW || aud_context_p->current_format == MED_TYPE_WAV_DVI_ADPCM)
{
kal_uint8 *header_p;
kal_uint32 data_len;
Media_GetFileHeader(&header_p, &aud_context_p->buf_len);
data_len = (kal_uint32) * (header_p + 4);
data_len += (((kal_uint32) * (header_p + 5)) << 8);
data_len += (((kal_uint32) * (header_p + 6)) << 16);
data_len += (((kal_uint32) * (header_p + 7)) << 24);
/* To check the file size consistency */
result = FS_GetFileSize(aud_context_p->current_file_handle, &len);
if (result == FS_NO_ERROR && (data_len + 8 != aud_context_p->offset || aud_context_p->offset != len))
{
AUD_VALUE_TRACE(data_len + 8, aud_context_p->offset, len);
ASSERT(data_len + 8 == aud_context_p->offset);
}
if (aud_context_p->buf_len > 0)
{
FS_Seek(aud_context_p->current_file_handle, (int)0, FS_FILE_BEGIN);
result = FS_Write(aud_context_p->current_file_handle, header_p, aud_context_p->buf_len, &len);
if (result != FS_NO_ERROR || len != aud_context_p->buf_len)
{
FS_Close(aud_context_p->current_file_handle);
aud_context_p->current_file_handle = -1;
return MED_RES_FAIL;
}
}
else
{
FS_Close(aud_context_p->current_file_handle);
aud_context_p->current_file_handle = -1;
return MED_RES_FAIL;
}
}
else if (aud_context_p->current_format == MED_TYPE_AMR || aud_context_p->current_format == MED_TYPE_AMR_WB)
{
/* Append null data 0x7c if not record anything. 1 byte for 20ms, put 5 bytes here.*/
if(aud_context_p->offset == 0)
{
kal_uint8 null_data[5] = {0x7c,0x7c,0x7c,0x7c,0x7c};
result = FS_Write(aud_context_p->current_file_handle, &null_data, 5, &len);
}
#ifdef DEDI_AMR_REC_BUFFER
if (aud_context_p->amr_buffer_p)
{
med_free_int_mem((void **)&aud_context_p->amr_buffer_p);
}
#endif /* DEDI_AMR_REC_BUFFER */
}
#endif /* !defined(MT6205B) && !defined(MT6208) */
FS_Close(aud_context_p->current_file_handle);
aud_context_p->current_file_handle = -1;
return MED_RES_OK;
}
/*****************************************************************************
* FUNCTION
* aud_media_stop_and_store_info_to_temp
* DESCRIPTION
* This function is to stop media play and store play info to temp.
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void aud_media_stop_and_store_info_to_temp(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* avoid other type of stop procedures */
if (aud_context_p->source_type > AUD_STRING)
{
return;
}
switch (aud_context_p->current_format)
{
#ifdef __MED_MMA_MOD__
case MED_TYPE_SMF:
case MED_TYPE_SMF_SND:
ASSERT(aud_context_p->last_handle != NULL);
temp_last_time = JSmf_GetCurrentTime(aud_context_p->last_handle);
JSmf_Stop(aud_context_p->last_handle);
JSmf_Close(aud_context_p->last_handle);
aud_context_p->last_handle = NULL;
kal_prompt_trace(MOD_MED, "stop and store info to temp: temp_last_time = %d", temp_last_time);
#if defined(__BTVCSR_HCI_BCHS__) && defined(__MED_BT_A2DP_MOD__)
aud_bt_a2dp_media_stop_hdlr();
#endif
break;
case MED_TYPE_IMELODY:
ASSERT(aud_context_p->last_handle != NULL);
temp_last_time = JImy_GetCurrentTime(aud_context_p->last_handle);
JImy_Stop(aud_context_p->last_handle);
JImy_Close(aud_context_p->last_handle);
aud_context_p->last_handle = NULL;
kal_prompt_trace(MOD_MED, "stop and store info to temp: temp_last_time = %d", temp_last_time);
#if defined(__BTVCSR_HCI_BCHS__) && defined(__MED_BT_A2DP_MOD__)
aud_bt_a2dp_media_stop_hdlr();
#endif
break;
#ifdef MMF_DECODE
case MED_TYPE_MMF:
ASSERT(aud_context_p->last_handle != NULL);
temp_last_time = JMmf_GetCurrentTime(aud_context_p->last_handle);
JMmf_Stop(aud_context_p->last_handle);
JMmf_Close(aud_context_p->last_handle);
aud_context_p->last_handle = NULL;
kal_prompt_trace(MOD_MED, "stop and store info to temp: temp_last_time = %d", temp_last_time);
#if defined(__BTVCSR_HCI_BCHS__) && defined(__MED_BT_A2DP_MOD__)
aud_bt_a2dp_media_stop_hdlr();
#endif
break;
#endif /* MMF_DECODE */
#endif /* __MED_MMA_MOD__ */
case MED_TYPE_AMR:
case MED_TYPE_AMR_WB:
case MED_TYPE_GSM_EFR:
case MED_TYPE_VR:
case MED_TYPE_PCM_8K:
case MED_TYPE_PCM_16K:
case MED_TYPE_DVI_ADPCM:
case MED_TYPE_DAF:
case MED_TYPE_WAV:
case MED_TYPE_WAV_ALAW:
case MED_TYPE_WAV_ULAW:
case MED_TYPE_WAV_DVI_ADPCM:
case MED_TYPE_AU:
case MED_TYPE_AIFF:
case MED_TYPE_WMA:
case MED_TYPE_AAC:
case MED_TYPE_M4A:
ASSERT(aud_context_p->last_mhdl_handle != NULL);
temp_last_time = aud_context_p->last_mhdl_handle->GetCurrentTime(aud_context_p->last_mhdl_handle);
aud_context_p->last_mhdl_handle->Stop(aud_context_p->last_mhdl_handle);
aud_context_p->last_mhdl_handle->Close(aud_context_p->last_mhdl_handle);
aud_media_close_file_handle();
aud_context_p->last_mhdl_handle = NULL;
kal_prompt_trace(MOD_MED, "stop and store info to temp: temp_last_time = %d", temp_last_time);
#if defined(__BTVCSR_HCI_BCHS__) && defined(__MED_BT_A2DP_MOD__)
aud_bt_a2dp_media_stop_hdlr();
#endif
break;
default:
Media_Stop();
temp_last_offset = aud_context_p->offset - (mediaGetDataCount() << 1);
kal_prompt_trace(
MOD_MED,
"stop and store info to temp: offset = %d, temp_last_offset = %d",
aud_context_p->offset,
temp_last_offset);
break;
}
aud_context_p->last_seq_no++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -