/******************************************************************************
* function : Create the thread to get stream from file and send to adec
******************************************************************************/
HI_S32 SAMPLE_COMM_AUDIO_Playing_Timer(void *argv)
{
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_sta = 1;
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_close_sta = 0;
int timer;
int tmp_time,now_time;
int ret;
timer = get_current_time_second() + AUDIO_PLAY_MAX_TIME;
do
{
if(joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_sta == 0)
{
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_close_sta = 1;
return 0;
}
now_time = get_current_time_second();
tmp_time = now_time;
if(tmp_time >= timer)
{
pthread_cancel(joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_pthread_id);
printf("\nIT'S THE TIME\n\n");
ret = HI_MPI_ADEC_ClearChnBuf(0);
if(ret != 0)
{
printf("%s: HI_MPI_ADEC_ClearChnBuf failed with %#x!\n",__FUNCTION__, ret);
}
ret = HI_MPI_AO_ClearChnBuf(0 , 0);
if(ret != 0)
{
printf("%s: HI_MPI_AO_ClearChnBuf failed with %#x!\n", __FUNCTION__, ret);
}
SAMPLE_ADEC_S * pstAdec = &gs_stSampleAdec[0];
pstAdec->bStart = HI_FALSE;
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_sta = 0;
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_close_sta = 1;
return -1;
}
}while(1);
}
/******************************************************************************
* function : get stream from file, and send it to Adec
******************************************************************************/
void *SAMPLE_COMM_AUDIO_AdecProc(void *parg)
{
HI_S32 s32Ret;
AUDIO_STREAM_S stAudioStream;
HI_S32 s32AdecChn;
HI_S32 myseek = 0;
SAMPLE_ADEC_S *pstAdecCtl = (SAMPLE_ADEC_S *)parg;
s32AdecChn = pstAdecCtl->AdChn;
int ret;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_pthread_id = pthread_self();
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_sta = 1;
printf("BEGIN PLAY\n\n");
while (HI_TRUE == pstAdecCtl->bStart)
{
if(joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_grabs_sta == 1)
{
printf("TO BE GRABS\n");
ret = HI_MPI_ADEC_ClearChnBuf(0);
if(ret != 0)
{
printf("%s: HI_MPI_ADEC_ClearChnBuf(%d) failed with %#x!\n",\
__FUNCTION__, s32AdecChn, ret);
}
ret = HI_MPI_AO_ClearChnBuf(0 , 0);
if(ret != 0)
{
printf("%s: HI_MPI_AO_ClearChnBuf(%d) failed with %#x!\n",\
__FUNCTION__, s32AdecChn, ret);
}
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_grabs_sta = 0;
break;
}
/* here only demo adec streaming sending mode, but pack sending mode is commended */
stAudioStream.pStream =(void *)(pstAdecCtl->AudioNode->audio_buf_pointer) + myseek;
stAudioStream.u32Len = ((pstAdecCtl->AudioNode->audio_data_len - myseek) > 640) ? 640 : (pstAdecCtl->AudioNode->audio_data_len - myseek);
myseek += stAudioStream.u32Len;
if(stAudioStream.u32Len <= 0)
{
ret = HI_MPI_ADEC_ClearChnBuf(0);
if(ret != 0)
{
printf("%s: HI_MPI_ADEC_ClearChnBuf(%d) failed with %#x!\n",\
__FUNCTION__, s32AdecChn, ret);
}
ret = HI_MPI_AO_ClearChnBuf(0 , 0);
if(ret != 0)
{
printf("%s: HI_MPI_AO_ClearChnBuf(%d) failed with %#x!\n",\
__FUNCTION__, s32AdecChn, ret);
}
break;
}
s32Ret = HI_MPI_ADEC_SendStream(s32AdecChn, &stAudioStream, HI_TRUE);
if (s32Ret != 0)
{
printf("%s: HI_MPI_ADEC_SendStream(%d) failed with %#x!\n",\
__FUNCTION__, s32AdecChn, s32Ret);
break;
}
}
if(joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_sta == 0)
{
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_close_sta = 1;
}
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_timer_sta = 0;
joseph_ipnc_param.joseph_ipnc_audio_attr.joseph_ipnc_a_playing_sta = 0;
pstAdecCtl->bStart = HI_FALSE;
return NULL;
}