|
@@ -2,6 +2,8 @@
|
|
|
#include <stdbool.h>
|
|
|
#include <assert.h>
|
|
|
#include <string.h>
|
|
|
+#include <time.h>
|
|
|
+#include <errno.h>
|
|
|
|
|
|
#include "CPicturePlayer.h"
|
|
|
|
|
@@ -66,6 +68,20 @@ CPicturePlayer::CPicturePlayer(CPicHostApi* pHostApi)
|
|
|
m_show_width = 0;
|
|
|
m_show_height = 0;
|
|
|
m_busrstop = false;
|
|
|
+
|
|
|
+ Uint32 uRet = SDL_WasInit(SDL_INIT_VIDEO);
|
|
|
+
|
|
|
+ if (0 == uRet) {
|
|
|
+ if (SDL_Init(SDL_INIT_VIDEO))
|
|
|
+ {
|
|
|
+ m_pHostApi->PicDebug(PIC_LOG_ERROR, "Could not initialize SDL - %s", SDL_GetError());
|
|
|
+ m_pHostApi->PicDebug(PIC_LOG_ERROR, "(Did you set the DISPLAY variable?)");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ uRet = SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);
|
|
|
+ m_pHostApi->PicDebug(PIC_LOG_DEBUG, "initialize SDL success, and init ret = %d.", uRet);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
CPicturePlayer::~CPicturePlayer()
|
|
@@ -87,19 +103,21 @@ size_t CPicturePlayer::GetVideoDisplayInfo()
|
|
|
return uCount;
|
|
|
}
|
|
|
|
|
|
-int CPicturePlayer::Init(rvc_picture_player_param_t* tparam)
|
|
|
+int CPicturePlayer::InitParam(rvc_picture_player_param_t* tparam)
|
|
|
{
|
|
|
int iRet = -1;
|
|
|
if (NULL == tparam) {
|
|
|
return iRet;
|
|
|
}
|
|
|
|
|
|
- if (0 != SDL_Init(SDL_INIT_VIDEO)) {
|
|
|
- m_pHostApi->PicDebug(PIC_LOG_ERROR,"Could not initialize SDL - %s", SDL_GetError());
|
|
|
- m_pHostApi->PicDebug(PIC_LOG_ERROR, "(Did you set the DISPLAY variable?)");
|
|
|
- return iRet;
|
|
|
- }
|
|
|
+ //if (0 != SDL_Init(SDL_INIT_VIDEO)) {
|
|
|
+ // m_pHostApi->PicDebug(PIC_LOG_ERROR,"Could not initialize SDL - %s", SDL_GetError());
|
|
|
+ // m_pHostApi->PicDebug(PIC_LOG_ERROR, "(Did you set the DISPLAY variable?)");
|
|
|
+ // return iRet;
|
|
|
+ //}
|
|
|
|
|
|
+ sem_init(&m_play_exit_sem, 0, 0);
|
|
|
+ m_busrstop = false;
|
|
|
|
|
|
m_nfile_cnt = tparam->nfile_cnt;
|
|
|
m_nplay_cnt = tparam->nplay_cnt;
|
|
@@ -116,8 +134,8 @@ int CPicturePlayer::Init(rvc_picture_player_param_t* tparam)
|
|
|
|
|
|
size_t uVideoPlayNum = GetVideoDisplayInfo();
|
|
|
|
|
|
- int idispalycx = SDL_WINDOWPOS_UNDEFINED;
|
|
|
- int idispalycy = SDL_WINDOWPOS_UNDEFINED;
|
|
|
+ int idispalycx = 0;
|
|
|
+ int idispalycy = 0;
|
|
|
int idispaly_width = m_dispalymode[0].w;
|
|
|
int idispaly_height = m_dispalymode[0].h;
|
|
|
|
|
@@ -174,6 +192,7 @@ int CPicturePlayer::DeInit()
|
|
|
m_show_width = 0;
|
|
|
m_show_height = 0;
|
|
|
m_busrstop = false;
|
|
|
+ sem_destroy(&m_play_exit_sem);
|
|
|
|
|
|
|
|
|
if (NULL != m_window) {
|
|
@@ -235,7 +254,28 @@ bool CPicturePlayer::StartPicPlay()
|
|
|
|
|
|
SDL_FreeSurface(surface);
|
|
|
SDL_FreeSurface(image);
|
|
|
- SDL_Delay(m_nplay_interval);
|
|
|
+ //SDL_Delay(m_nplay_interval);
|
|
|
+
|
|
|
+ struct timespec ts;
|
|
|
+ int itimems = m_nplay_interval;
|
|
|
+ clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
+ if (itimems > 1000){
|
|
|
+ ts.tv_sec += (itimems / 1000);
|
|
|
+ itimems = m_nplay_interval % 1000;
|
|
|
+ }
|
|
|
+
|
|
|
+ long unsec = ts.tv_nsec + (1000 * 1000 * itimems);
|
|
|
+ ts.tv_sec += (unsec / 1000000000);
|
|
|
+ ts.tv_nsec = (unsec % 1000000000);
|
|
|
+
|
|
|
+ if (-1 == sem_timedwait(&m_play_exit_sem, &ts)) {
|
|
|
+ if (ETIMEDOUT == errno) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -247,7 +287,8 @@ bool CPicturePlayer::StartPicPlay()
|
|
|
m_pHostApi->PicDebug(PIC_LOG_INFO, "user stop picture playing task, exit");
|
|
|
}
|
|
|
|
|
|
- SDL_Quit();
|
|
|
+ SDL_DestroyWindow(m_window);
|
|
|
+ m_window = NULL;
|
|
|
|
|
|
bRet = true;
|
|
|
|
|
@@ -258,7 +299,7 @@ bool CPicturePlayer::StartPicPlay()
|
|
|
int CPicturePlayer::StopPicPlay()
|
|
|
{
|
|
|
int iRet = -1;
|
|
|
-
|
|
|
+ sem_post(&m_play_exit_sem);
|
|
|
m_busrstop = true;
|
|
|
m_pHostApi->PicDebug(PIC_LOG_DEBUG, "stop picture play, set user stop flag true.");
|
|
|
|