|
@@ -189,22 +189,21 @@ static int audio_play_finished_callback(void* userdata)
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int mediaplay_thread(void* arg)
|
|
|
+static int mediaplay_thread_func(void* arg)
|
|
|
{
|
|
|
int iret = -1;
|
|
|
|
|
|
+ int icount = 0;
|
|
|
+
|
|
|
CMediaPlayer* pPlayer = (CMediaPlayer*)arg;
|
|
|
|
|
|
pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_DEBUG, "************* enter mediaplay_thread func ************");
|
|
|
|
|
|
- SDL_LockMutex(pPlayer->GetMeidaPlayStartWaitMutex());
|
|
|
if (0 == open_demux(pPlayer->GetPlayerStat())) {
|
|
|
pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_DEBUG, "open_demux function call success.");
|
|
|
}
|
|
|
else {
|
|
|
pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_ERROR, "open_demux function call failed.");
|
|
|
- pPlayer->StartMediaPlayFailed();
|
|
|
- SDL_UnlockMutex(pPlayer->GetMeidaPlayStartWaitMutex());
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
@@ -213,21 +212,41 @@ static int mediaplay_thread(void* arg)
|
|
|
if (0 != iret) {
|
|
|
pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_ERROR, "open video failed.");
|
|
|
pPlayer->StartMediaPlayFailed();
|
|
|
- SDL_UnlockMutex(pPlayer->GetMeidaPlayStartWaitMutex());
|
|
|
return iret;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
iret = open_audio(pPlayer->GetPlayerStat());
|
|
|
|
|
|
- SDL_UnlockMutex(pPlayer->GetMeidaPlayStartWaitMutex());
|
|
|
-
|
|
|
if (0 == iret) {
|
|
|
- pPlayer->SetMediaPlayStartedFlag(true);
|
|
|
+ bool baudioplay_thread_exit = false;
|
|
|
+ do {
|
|
|
+ if (NULL != pPlayer->GetPlayerStat()->m_audio_play_wait_sem) {
|
|
|
+ int iWait = SDL_SemWaitTimeout(pPlayer->GetPlayerStat()->m_audio_play_wait_sem, 5);
|
|
|
+ if (0 != iWait) {
|
|
|
+ if (SDL_MUTEX_TIMEDOUT == iWait) {
|
|
|
+ if (false == pPlayer->GetMediaPlayStartedFlag()) {
|
|
|
+ pPlayer->SetMediaPlayStartedFlag(true);
|
|
|
+ }
|
|
|
+ if (++icount % 20 == 0) {
|
|
|
+ pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_INFO, "audio playing ...........");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_ERROR, "SDL_SemWaitTimeout error.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_INFO, "---------------stop audio playing thread---------------");
|
|
|
+ baudioplay_thread_exit = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ pPlayer->GetMediaHostApi()->Debug(MEDIA_LOG_ERROR, "invalid m_audio_play_wait_sem");
|
|
|
+ baudioplay_thread_exit = true;
|
|
|
+ }
|
|
|
+ } while (!baudioplay_thread_exit);
|
|
|
|
|
|
- SDL_LockMutex(pPlayer->GetPlayerStat()->m_audio_play_wait_mutex);
|
|
|
- SDL_CondWait(pPlayer->GetPlayerStat()->m_audio_play_cond, pPlayer->GetPlayerStat()->m_audio_play_wait_mutex);
|
|
|
- SDL_UnlockMutex(pPlayer->GetPlayerStat()->m_audio_play_wait_mutex);
|
|
|
SDL_CloseAudioDevice(pPlayer->GetPlayerStat()->m_audio_dev);
|
|
|
}
|
|
|
else {
|
|
@@ -386,8 +405,9 @@ int CMediaPlayer::UnInitialize_Player_Stat()
|
|
|
}
|
|
|
|
|
|
SDL_DestroyCond(m_player_stat->m_continue_read_thread);
|
|
|
- SDL_DestroyCond(m_player_stat->m_audio_play_cond);
|
|
|
- SDL_DestroyMutex(m_player_stat->m_audio_play_wait_mutex);
|
|
|
+ m_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_DestroySemaphore m_audio_play_wait_sem.");
|
|
|
+ SDL_DestroySemaphore(m_player_stat->m_audio_play_wait_sem);
|
|
|
+ m_player_stat->m_audio_play_wait_sem = NULL;
|
|
|
|
|
|
if (m_player_stat->m_eMType == eVideo_Type) {
|
|
|
for (int index = 0; index < m_player_stat->m_uFilesCount; index++) {
|
|
@@ -510,13 +530,13 @@ int CMediaPlayer::InitParam(rvc_media_player_param_t* pMedia_Player)
|
|
|
packet_queue_put(&m_player_stat->video_pkt_queue, &flush_pkt, m_hostapi);
|
|
|
packet_queue_put(&m_player_stat->audio_pkt_queue, &flush_pkt, m_hostapi);
|
|
|
|
|
|
- if (!(m_player_stat->m_continue_read_thread = SDL_CreateCond()) || !(m_player_stat->m_audio_play_cond = SDL_CreateCond())){
|
|
|
+ if (!(m_player_stat->m_continue_read_thread = SDL_CreateCond())){
|
|
|
m_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_CreateCond(): %s.", SDL_GetError());
|
|
|
UnInitialize_Player_Stat();
|
|
|
return iRet;
|
|
|
}
|
|
|
|
|
|
- m_player_stat->m_audio_play_wait_mutex = SDL_CreateMutex();
|
|
|
+ m_player_stat->m_audio_play_wait_sem = SDL_CreateSemaphore(0);
|
|
|
|
|
|
init_clock(&m_player_stat->video_clk, &m_player_stat->video_pkt_queue.serial);
|
|
|
init_clock(&m_player_stat->audio_clk, &m_player_stat->audio_pkt_queue.serial);
|
|
@@ -560,12 +580,15 @@ int CMediaPlayer::StartMediaPlay()
|
|
|
int iRet = -1;
|
|
|
|
|
|
m_bplaying = true;
|
|
|
+ SDL_LockMutex(m_meida_play_start_wait_mutex);
|
|
|
+
|
|
|
m_bmediaplay_started_flag = false;
|
|
|
m_bmediaplay_start_failed = false;
|
|
|
|
|
|
m_mediaplay_started_sem = SDL_CreateSemaphore(0);
|
|
|
- m_mediaplay_tid = SDL_CreateThread(mediaplay_thread, "mediaplay_thread", this);
|
|
|
+ m_mediaplay_tid = SDL_CreateThread(mediaplay_thread_func, "mediaplay_thread", this);
|
|
|
if (NULL == m_mediaplay_tid) {
|
|
|
+ SDL_UnlockMutex(m_meida_play_start_wait_mutex);
|
|
|
m_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_CreateThread() failed: %s.", SDL_GetError());
|
|
|
return iRet;
|
|
|
}
|
|
@@ -599,6 +622,8 @@ int CMediaPlayer::StartMediaPlay()
|
|
|
SDL_DestroySemaphore(m_mediaplay_started_sem);
|
|
|
m_mediaplay_started_sem = NULL;
|
|
|
|
|
|
+ SDL_UnlockMutex(m_meida_play_start_wait_mutex);
|
|
|
+
|
|
|
m_hostapi->Debug(MEDIA_LOG_DEBUG, "wait media play thread.");
|
|
|
SDL_WaitThread(m_mediaplay_tid, NULL);
|
|
|
m_mediaplay_tid = NULL;
|
|
@@ -647,19 +672,23 @@ int CMediaPlayer::StopMediaPlay()
|
|
|
|
|
|
m_hostapi->Debug(MEDIA_LOG_DEBUG, "StopMediaPlay called.");
|
|
|
|
|
|
+ if (NULL == m_player_stat) {
|
|
|
+ return iRet;
|
|
|
+ }
|
|
|
+
|
|
|
if (NULL != m_mediaplay_started_sem) {
|
|
|
SDL_SemPost(m_mediaplay_started_sem);
|
|
|
}
|
|
|
|
|
|
- if (NULL == m_player_stat) {
|
|
|
- return iRet;
|
|
|
- }
|
|
|
+ m_player_stat->buser_stop = true;
|
|
|
|
|
|
SDL_LockMutex(m_meida_play_start_wait_mutex);
|
|
|
|
|
|
- SDL_LockMutex(m_player_stat->m_audio_play_wait_mutex);
|
|
|
- SDL_CondSignal(m_player_stat->m_audio_play_cond);
|
|
|
- SDL_UnlockMutex(m_player_stat->m_audio_play_wait_mutex);
|
|
|
+ if (NULL != m_player_stat->m_audio_play_wait_sem) {
|
|
|
+ m_hostapi->Debug(MEDIA_LOG_INFO, "SDL_SemPost m_audio_play_wait_sem.");
|
|
|
+ SDL_SemPost(m_player_stat->m_audio_play_wait_sem);
|
|
|
+ }
|
|
|
+
|
|
|
packet_queue_abort(&m_player_stat->video_pkt_queue, m_hostapi);
|
|
|
packet_queue_abort(&m_player_stat->audio_pkt_queue, m_hostapi);
|
|
|
|
|
@@ -670,8 +699,6 @@ int CMediaPlayer::StopMediaPlay()
|
|
|
|
|
|
SDL_UnlockMutex(m_meida_play_start_wait_mutex);
|
|
|
|
|
|
- m_player_stat->buser_stop = true;
|
|
|
-
|
|
|
iRet = 0;
|
|
|
|
|
|
m_hostapi->Debug(MEDIA_LOG_DEBUG, "StopMediaPlay exit.");
|