版权声明:本文仅为本人转载学习保存使用,并未用作其他任何之处。 https://blog.csdn.net/qq_14997637/article/details/83902545
#include "Stdafw.h"
#include "aud_app.h"
#include "aud_timer.h"
#define TIME_OUT_100MS 100 //10s
extern struct t_pcm_file g_pcm_file;
extern E_AUD_STATUS g_audio_status;
extern E_RECORD_STATUS g_recocder_status;
extern struct t_aud_frame* ptr_cur_aud_frame;
extern E_PROTOCOL_TYPE* g_protocol_type;
/*超时定时器*/
static void tran_time_out(void);
static struct t_time_out _timeout_timer =
{
FALSE,
TIME_OUT_100MS,
0,
FALSE,
tran_time_out,
};
void req_timeout_timer(void)
{
if (_timeout_timer.m_en == TRUE && _timeout_timer.m_timeout_sta == FALSE)
{
_timeout_timer.m_cur_sec++;
#if _AUD_DEBUG
printf("cur_sec = %u Sec., time_out = %u Sec.\r\n", _timeout_timer.m_cur_sec, _timeout_timer.m_limit_sec);
#endif
if (_timeout_timer.m_cur_sec >= _timeout_timer.m_limit_sec)
{
_timeout_timer.m_hander();
_timeout_timer.m_timeout_sta = TRUE;
#if _AUD_DEBUG
printf("time_out_process.\r\n");
#endif
}
}
else
{
_timeout_timer.m_cur_sec = 0;
}
}
/*超时处理函数*/
static void tran_time_out(void)
{
struct t_rsp_code _rsp_code;
/*当前为请求帧超时,丢弃当前请求*/
//释放当前帧申请内存
if (ptr_cur_aud_frame->m_Data)
{
free(ptr_cur_aud_frame->m_Data);
ptr_cur_aud_frame->m_Data = NULL;
}
//当前协议帧重新复位
memset(ptr_cur_aud_frame, 0, sizeof(struct t_aud_frame));
*g_protocol_type = PROTOCOL_HEAD;
/*当前为传输帧超时,丢弃当前media文件*/
if (g_audio_status == PLAY_STATUS || g_audio_status == TRANS_STATUS)
{
/*释放资源*/
g_audio_status = STOP_STATUS;
if (g_pcm_file.m_fp)
fclose(g_pcm_file.m_fp);
if (g_pcm_file.m_filename)
remove(g_pcm_file.m_filename);
memset(&g_pcm_file, 0, sizeof(struct t_pcm_file));
/*回馈接收media文件超时*/
_rsp_code.m_PlayResult = ERR_TIMEOUT;
_rsp_code.m_ContextId = g_pcm_file.m_MediaId;
protocol_send_frame(AUDIO_DATA_OVER_RSP, &_rsp_code, AUD_TYPE_RSP);
}
}
/*使能超时处理*/
void timeout_tim(BOOL vp_en)
{
_timeout_timer.m_en = vp_en;
}
/*跳过命令定时器*/
static struct t_skip_cmd_req skip_cmd_req;
void skip_req_timer(void)
{
if (skip_cmd_req.m_skip_req_sta == TRUE && skip_cmd_req.m_keep_time >= 0)
{
/*阻塞模式*/
if (skip_cmd_req.m_keep_time == AUD_PLAYBLOCK)
{
if (g_audio_status == STOP_STATUS)
{
skip_cmd_req.m_skip_req_sta = FALSE;
skip_cmd_req.m_cur_time = 0;
skip_cmd_req.m_cmd = 0;
}
}
else {
/*定时模式*/
skip_cmd_req.m_cur_time++;
if (skip_cmd_req.m_cur_time >= skip_cmd_req.m_keep_time)
{
skip_cmd_req.m_skip_req_sta = FALSE;
skip_cmd_req.m_cur_time = 0;
skip_cmd_req.m_cmd = 0;
}
}
}
else
{
skip_cmd_req.m_cur_time = 0;
skip_cmd_req.m_cmd = 0;
}
}
/*添加跳过指令项*/
void skip_cmd_addItem(BOOL en, u32 keep_time_100ms, u8 CmdId)
{
skip_cmd_req.m_skip_req_sta = en;
skip_cmd_req.m_keep_time = keep_time_100ms;
skip_cmd_req.m_cmd = CmdId;
}
/*检查当前是否跳出*/
BOOL check_skip_cmd(u8 cmd)
{
struct t_rsp_code rsp_code;
if (skip_cmd_req.m_skip_req_sta == TRUE)
{
if (cmd == skip_cmd_req.m_cmd)
{
#if _AUD_DEBUG
printf("==================skip cmd[%u] %u Sec.=================\r\n", cmd, skip_cmd_req.m_keep_time);
#endif
switch (cmd)
{
case STOP_PLAY_AUDIO_REQ:
rsp_code.m_PlayResult = ERR_BUSY; //此处直接返回ERR_BUSY
rsp_code.m_ContextId = g_pcm_file.m_MediaId;
protocol_send_frame(STOP_PLAY_AUDIO_RSP, &rsp_code, AUD_TYPE_RSP);
break;
default:
break;
}
return TRUE;
}
}
return FALSE;
}
void sci_aud_timer(void)
{
req_timeout_timer();
skip_req_timer();
}
void sci_timer_flash(void)
{
_timeout_timer.m_cur_sec = 0;
_timeout_timer.m_timeout_sta = FALSE;
}