/****************************************************************************** * function : get stream from Aenc, send it to Adec & save it to file ******************************************************************************/ void *SAMPLE_COMM_AUDIO_AencProc(void *parg) { HI_S32 s32Ret; HI_S32 AencFd; SAMPLE_AENC_S *pstAencCtl = (SAMPLE_AENC_S *) parg; AUDIO_STREAM_S stStream; fd_set read_fds; struct timeval TimeoutVal; FD_ZERO(&read_fds); AencFd = HI_MPI_AENC_GetFd(pstAencCtl->AeChn); FD_SET(AencFd, &read_fds); while (pstAencCtl->bStart) { TimeoutVal.tv_sec = 1; TimeoutVal.tv_usec = 0; FD_ZERO(&read_fds); FD_SET(AencFd, &read_fds); s32Ret = select(AencFd + 1, &read_fds, NULL, NULL, &TimeoutVal); if (s32Ret < 0) { break; } else if (0 == s32Ret) { printf("%s: get aenc stream select time out\n", __FUNCTION__); break; } if (FD_ISSET(AencFd, &read_fds)) { /* get stream from aenc chn */ s32Ret = HI_MPI_AENC_GetStream(pstAencCtl->AeChn, &stStream, HI_FALSE); if (HI_SUCCESS != s32Ret) { printf("%s: HI_MPI_AENC_GetStream(%d), failed with %#x!\n", __FUNCTION__, pstAencCtl->AeChn, s32Ret); pstAencCtl->bStart = HI_FALSE; return NULL; } /* send stream to decoder and play for testing */ if (HI_TRUE == pstAencCtl->bSendAdChn) { HI_MPI_ADEC_SendStream(pstAencCtl->AdChn, &stStream, HI_TRUE); } /* save audio stream to file */ fwrite(stStream.pStream, 1, stStream.u32Len, pstAencCtl->pfd); /* finally you must release the stream */ HI_MPI_AENC_ReleaseStream(pstAencCtl->AeChn, &stStream); } } fclose(pstAencCtl->pfd); pstAencCtl->bStart = HI_FALSE; return NULL; }
LiveAudioStreamSource ::LiveAudioStreamSource(UsageEnvironment& env, StreamChannel chn) : FramedSource(env), fChannelNo(chn) { TaskScheduler &scheduler = envir().taskScheduler(); aencFd = HI_MPI_AENC_GetFd(fChannelNo); ClearAudioStreamBuffer(fChannelNo); scheduler.setBackgroundHandling(aencFd, SOCKET_READABLE, (TaskScheduler::BackgroundHandlerProc*)deliverFrame0, this); }
static HI_VOID * audio_thread(void * pParam) { prctl(PR_SET_NAME, __FUNCTION__); HI_S32 s32Ret = HI_FAILURE; HI_S32 AencFd = -1; AUDIO_STREAM_S stStream; memset(&stStream, 0, sizeof(stStream)); fd_set read_fds; FD_ZERO(&read_fds); struct timeval TimeoutVal = {0, 0}; AENC_CHN AeChn = 0; AencFd = HI_MPI_AENC_GetFd(AeChn); CHECK(AencFd > 0, NULL, "Error with %#x.\n", s32Ret); int header_size = HIS_AUDIO_FRAME_HEADER_LEN; if (PT_LPCM == get_payload_type()) { header_size = 0; } while (g_audio_args->running) { int pass_time = util_time_pass(&g_audio_args->last_aw8733a_time); if (pass_time > 30*1000) { if (g_audio_args->last_aw8733a_stat > 0) { g_audio_args->last_aw8733a_stat = 0; s32Ret = audio_aw8733a(g_audio_args->last_aw8733a_stat); CHECK(s32Ret == HI_SUCCESS, NULL, "Error with %#x.\n", s32Ret); } } TimeoutVal.tv_sec = 0; TimeoutVal.tv_usec = 100*1000; FD_ZERO(&read_fds); FD_SET(AencFd, &read_fds); memset(&stStream, 0, sizeof(stStream)); s32Ret = select(AencFd + 1, &read_fds, NULL, NULL, &TimeoutVal); if (s32Ret < 0) { ERR("select error: %s\n", strerror(errno)); break; } else if (0 == s32Ret) { WRN("select time out...\n"); continue; } if (FD_ISSET(AencFd, &read_fds)) { /* get stream from aenc chn */ int timeout = 0; // 非阻塞 s32Ret = HI_MPI_AENC_GetStream(AeChn, &stStream, timeout); CHECK(s32Ret == HI_SUCCESS, NULL, "Error with %#x.\n", s32Ret); if (stStream.u32Len > header_size) { s32Ret = aenc_write_cb((HI_CHAR *)stStream.pStream+header_size, stStream.u32Len-header_size, stStream.u64TimeStamp); CHECK(s32Ret == HI_SUCCESS, NULL, "Error with %#x.\n", s32Ret); } s32Ret = HI_MPI_AENC_ReleaseStream(AeChn, &stStream); CHECK(s32Ret == HI_SUCCESS, NULL, "Error with %#x.\n", s32Ret); } } return NULL; }