- screensaver: formatting code using astyle

Conflicts:
	src/gui/screensaver.cpp

Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
svenhoefer
2021-10-24 21:47:44 +02:00
committed by Thilo Graf
parent 73778cfb34
commit d16f52922c
2 changed files with 104 additions and 66 deletions

View File

@@ -35,7 +35,7 @@
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <pthread.h> #include <pthread.h>
#include <algorithm> // sort #include <algorithm> // sort
#include "audiomute.h" #include "audiomute.h"
#include "screensaver.h" #include "screensaver.h"
#include <driver/radiotext.h> #include <driver/radiotext.h>
@@ -43,12 +43,14 @@
#include <system/debug.h> #include <system/debug.h>
#include <gui/color_custom.h> #include <gui/color_custom.h>
#include <gui/infoclock.h> #include <gui/infoclock.h>
// #include <gui/infoicons.h>
#include <gui/infoviewer.h>
#include <zapit/zapit.h> #include <zapit/zapit.h>
#include <driver/pictureviewer/pictureviewer.h> #include <driver/pictureviewer/pictureviewer.h>
#include <system/set_threadname.h> #include <system/set_threadname.h>
#include <hardware/video.h> #include <hardware/video.h>
extern cVideo * videoDecoder; extern cVideo *videoDecoder;
static CComponentsFrmClock *scr_clock = NULL; static CComponentsFrmClock *scr_clock = NULL;
@@ -62,6 +64,7 @@ CScreenSaver::CScreenSaver()
index = 0; index = 0;
status_mute = CAudioMute::getInstance()->getStatus(); status_mute = CAudioMute::getInstance()->getStatus();
// status_icons = CInfoIcons::getInstance()->getStatus();
clr.i_color = COL_DARK_GRAY; clr.i_color = COL_DARK_GRAY;
for (unsigned int i = 0; i < 3; i++) for (unsigned int i = 0; i < 3; i++)
@@ -79,16 +82,19 @@ CScreenSaver::~CScreenSaver()
{ {
thrExit(); thrExit();
if (scr_clock){ // delete m_viewer;
if (scr_clock)
{
delete scr_clock; delete scr_clock;
scr_clock = NULL; scr_clock = NULL;
} }
} }
CScreenSaver* CScreenSaver::getInstance() CScreenSaver *CScreenSaver::getInstance()
{ {
static CScreenSaver * screenSaver = NULL; static CScreenSaver *screenSaver = NULL;
if (!screenSaver) if (!screenSaver)
screenSaver = new CScreenSaver(); screenSaver = new CScreenSaver();
@@ -97,14 +103,14 @@ CScreenSaver* CScreenSaver::getInstance()
void CScreenSaver::thrExit() void CScreenSaver::thrExit()
{ {
if(thrScreenSaver) if (thrScreenSaver)
{ {
dprintf(DEBUG_NORMAL,"[%s] %s: exit screensaver thread\n", __file__, __func__); dprintf(DEBUG_NORMAL, "[%s] %s: exit screensaver thread\n", __file__, __func__);
thr_exit = true; thr_exit = true;
thrScreenSaver->join(); thrScreenSaver->join();
delete thrScreenSaver; delete thrScreenSaver;
thrScreenSaver = NULL; thrScreenSaver = NULL;
dprintf(DEBUG_NORMAL,"\033[32m[CScreenSaver] [%s - %d] screensaver thread stopped\033[0m\n", __func__, __LINE__); dprintf(DEBUG_NORMAL, "\033[32m[CScreenSaver] [%s - %d] screensaver thread stopped\033[0m\n", __func__, __LINE__);
} }
} }
@@ -117,9 +123,12 @@ void CScreenSaver::Start()
status_mute = CAudioMute::getInstance()->getStatus(); status_mute = CAudioMute::getInstance()->getStatus();
CAudioMute::getInstance()->enableMuteIcon(false); CAudioMute::getInstance()->enableMuteIcon(false);
if(!CInfoClock::getInstance()->isBlocked()) if (!CInfoClock::getInstance()->isBlocked())
CInfoClock::getInstance()->block(); CInfoClock::getInstance()->block();
#if 0
status_icons = CInfoIcons::getInstance()->getStatus();
CInfoIcons::getInstance()->enableInfoIcons(false);
#endif
if (g_RadiotextWin) if (g_RadiotextWin)
g_Radiotext->OnAfterDecodeLine.block(); g_Radiotext->OnAfterDecodeLine.block();
@@ -128,17 +137,34 @@ void CScreenSaver::Start()
if (pip_channel_id[0]) if (pip_channel_id[0])
g_Zapit->stopPip(); g_Zapit->stopPip();
#endif #endif
#if 0
m_viewer->SetScaling((CPictureViewer::ScalingMode)g_settings.picviewer_scaling);
m_viewer->SetVisible(g_settings.screen_StartX, g_settings.screen_EndX, g_settings.screen_StartY, g_settings.screen_EndY);
if (g_settings.video_Format == 3)
m_viewer->SetAspectRatio(float(16.0 / 9));
else
m_viewer->SetAspectRatio(float(4.0 / 3));
m_viewer->Cleanup();
#if HAVE_ARM_HARDWARE
/*
Hack to get sure we have a blank screen.
stopFrame()-function seems not work correctly on ARM_HARDWARE
*/
m_frameBuffer->showFrame("blackscreen.jpg");
#endif
#endif
m_frameBuffer->stopFrame(); m_frameBuffer->stopFrame();
if(!thrScreenSaver) if (!thrScreenSaver)
{ {
dprintf(DEBUG_NORMAL,"[%s] %s: starting thread\n", __file__, __func__); dprintf(DEBUG_NORMAL, "[%s] %s: starting thread\n", __file__, __func__);
thr_exit = false; thr_exit = false;
thrScreenSaver = new std::thread (ScreenSaverPrg, this); thrScreenSaver = new std::thread(ScreenSaverPrg, this);
std::string tn = "screen_saver"; std::string tn = "screen_saver";
set_threadname(tn.c_str()); set_threadname(tn.c_str());
dprintf(DEBUG_NORMAL,"\033[32m[CScreenSaver] [%s - %d] thread [%p] [%s] started\033[0m\n", __func__, __LINE__, thrScreenSaver, tn.c_str()); dprintf(DEBUG_NORMAL, "\033[32m[CScreenSaver] [%s - %d] thread [%p] [%s] started\033[0m\n", __func__, __LINE__, thrScreenSaver, tn.c_str());
} }
if (!OnAfterStart.empty()) if (!OnAfterStart.empty())
@@ -152,7 +178,8 @@ void CScreenSaver::Stop()
resetIdleTime(); resetIdleTime();
if (scr_clock){ if (scr_clock)
{
std::lock_guard<std::mutex> g(scr_mutex); std::lock_guard<std::mutex> g(scr_mutex);
scr_clock->Stop(); scr_clock->Stop();
delete scr_clock; delete scr_clock;
@@ -160,19 +187,22 @@ void CScreenSaver::Stop()
} }
#if ENABLE_PIP #if ENABLE_PIP
if(pip_channel_id[0]) { if (pip_channel_id[0])
{
CNeutrinoApp::getInstance()->StartPip(pip_channel_id[0]); CNeutrinoApp::getInstance()->StartPip(pip_channel_id[0]);
pip_channel_id[0] = 0; pip_channel_id[0] = 0;
} }
#endif #endif
m_frameBuffer->paintBackground(); //clear entire screen m_frameBuffer->paintBackground(); // clear entire screen
CAudioMute::getInstance()->enableMuteIcon(status_mute); CAudioMute::getInstance()->enableMuteIcon(status_mute);
CInfoClock::getInstance()->ClearDisplay(); //provokes reinit CInfoClock::getInstance()->ClearDisplay(); // provokes reinit
CInfoClock::getInstance()->enableInfoClock(); CInfoClock::getInstance()->enableInfoClock();
#if 0
CInfoIcons::getInstance()->enableInfoIcons(status_icons);
#endif
if (g_RadiotextWin) if (g_RadiotextWin)
g_Radiotext->OnAfterDecodeLine.unblock(); g_Radiotext->OnAfterDecodeLine.unblock();
@@ -186,7 +216,7 @@ void CScreenSaver::ScreenSaverPrg(CScreenSaver *scr)
if (g_settings.screensaver_timeout) if (g_settings.screensaver_timeout)
{ {
while(!scr->thr_exit) while (!scr->thr_exit)
{ {
if (g_settings.screensaver_mode == SCR_MODE_IMAGE) if (g_settings.screensaver_mode == SCR_MODE_IMAGE)
scr->ReadDir(); scr->ReadDir();
@@ -194,17 +224,18 @@ void CScreenSaver::ScreenSaverPrg(CScreenSaver *scr)
scr->paint(); scr->paint();
int corr = 1; int corr = 1;
#if HAVE_CST_HARDWARE //time offset #if HAVE_CST_HARDWARE
// time offset
corr = 10; corr = 10;
#endif #endif
int t = 1000/corr * g_settings.screensaver_timeout; //sleep and exit handle int t = 1000 / corr * g_settings.screensaver_timeout; // sleep and exit handle
while (t > 0) while (t > 0)
{ {
if (!scr->thr_exit) if (!scr->thr_exit)
this_thread::sleep_for(std::chrono::milliseconds(1)); this_thread::sleep_for(std::chrono::milliseconds(1));
t--; t--;
if (scr->force_refresh) //NOTE: Do we really need this ? if (scr->force_refresh) // NOTE: Do we really need this ?
{ {
scr->force_refresh = false; scr->force_refresh = false;
break; break;
@@ -226,10 +257,11 @@ bool CScreenSaver::ReadDir()
{ {
struct dirent **coverlist; struct dirent **coverlist;
int n = scandir(COVERDIR_TMP, &coverlist, 0, alphasort); int n = scandir(COVERDIR_TMP, &coverlist, 0, alphasort);
if (n > 2){ // we always have the "." and ".." entrys if (n > 2) // we always have the "." and ".." entrys
{
show_audiocover = true; show_audiocover = true;
} }
if(n > -1) if (n > -1)
{ {
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
@@ -247,7 +279,7 @@ bool CScreenSaver::ReadDir()
d = g_settings.screensaver_dir; d = g_settings.screensaver_dir;
if (d.length() > 1) if (d.length() > 1)
{ {
//remove trailing slash // remove trailing slash
string::iterator it = d.end() - 1; string::iterator it = d.end() - 1;
if (*it == '/') if (*it == '/')
d.erase(it); d.erase(it);
@@ -261,24 +293,25 @@ bool CScreenSaver::ReadDir()
v_bg_files.clear(); v_bg_files.clear();
/* open dir */ // open dir
if((dir=opendir(dir_name)) == NULL) { if ((dir = opendir(dir_name)) == NULL)
fprintf(stderr,"[CScreenSaver] %s - %d : error open dir...\n", __func__, __LINE__); {
fprintf(stderr, "[CScreenSaver] %s - %d : error open dir...\n", __func__, __LINE__);
return ret; return ret;
} }
/* read complete dir */ // read complete dir
while((dirpointer=readdir(dir)) != NULL) // TODO: use threadsave readdir_r instead readdir while ((dirpointer = readdir(dir)) != NULL) // TODO: use threadsave readdir_r instead readdir
{ {
int curr_lenght = strlen((*dirpointer).d_name); int curr_lenght = strlen((*dirpointer).d_name);
string str = dir_name; string str = dir_name;
//printf("%d\n",curr_lenght); //printf("%d\n",curr_lenght);
if(curr_lenght > 4) if (curr_lenght > 4)
{ {
strncpy(curr_ext,(*dirpointer).d_name+(curr_lenght-4),sizeof(curr_ext)-1); strncpy(curr_ext, (*dirpointer).d_name + (curr_lenght - 4), sizeof(curr_ext) - 1);
//printf("%s\n",curr_ext); //printf("%s\n",curr_ext);
if (strcasecmp(".jpg",curr_ext) && strcasecmp(".png",curr_ext)) if (strcasecmp(".jpg", curr_ext) && strcasecmp(".png", curr_ext))
continue; continue;
str += "/"; str += "/";
@@ -301,15 +334,15 @@ bool CScreenSaver::ReadDir()
sort(v_bg_files.begin(), v_bg_files.end()); sort(v_bg_files.begin(), v_bg_files.end());
/* close pointer */ // close pointer
if(closedir(dir) == -1) if (closedir(dir) == -1)
dprintf(DEBUG_NORMAL, "[CScreenSaver] %s - %d : Error no closed %s\n", __func__, __LINE__, dir_name); dprintf(DEBUG_NORMAL, "[CScreenSaver] %s - %d : Error no closed %s\n", __func__, __LINE__, dir_name);
if(!v_bg_files.empty()) if (!v_bg_files.empty())
ret = true; ret = true;
#if 0 #if 0
else else
dprintf(DEBUG_NORMAL, "[CScreenSaver] %s - %d : no picture found\n", __func__, __LINE__); dprintf(DEBUG_NORMAL, "[CScreenSaver] %s - %d : no picture found\n", __func__, __LINE__);
#endif #endif
return ret; return ret;
@@ -339,14 +372,14 @@ void CScreenSaver::paint()
if (g_settings.screensaver_mode == SCR_MODE_IMAGE && !v_bg_files.empty()) if (g_settings.screensaver_mode == SCR_MODE_IMAGE && !v_bg_files.empty())
{ {
if( (index >= v_bg_files.size()) || (access(v_bg_files.at(index).c_str(), F_OK))) if ((index >= v_bg_files.size()) || (access(v_bg_files.at(index).c_str(), F_OK)))
{ {
ReadDir(); ReadDir();
index = 0; index = 0;
return; return;
} }
dprintf(DEBUG_INFO, "[CScreenSaver] %s - %d : %s\n", __func__, __LINE__, v_bg_files.at(index).c_str()); dprintf(DEBUG_INFO, "[CScreenSaver] %s - %d : %s\n", __func__, __LINE__, v_bg_files.at(index).c_str());
m_frameBuffer->showFrame(v_bg_files.at(index), CFrameBuffer::SHOW_FRAME_FALLBACK_MODE_IMAGE_UNSCALED); m_frameBuffer->showFrame(v_bg_files.at(index), CFrameBuffer::SHOW_FRAME_FALLBACK_MODE_IMAGE_UNSCALED);
@@ -357,7 +390,7 @@ void CScreenSaver::paint()
else else
index = rand_r(&seed[0]) % v_bg_files.size(); index = rand_r(&seed[0]) % v_bg_files.size();
if(index == v_bg_files.size()) if (index == v_bg_files.size())
index = 0; index = 0;
} }
else else
@@ -375,7 +408,8 @@ void CScreenSaver::paint()
#endif #endif
} }
#if !HAVE_CST_HARDWARE #if !HAVE_CST_HARDWARE
#if 0 //example for callback #if 0
// example for callback
m_frameBuffer->OnFallbackShowFrame.connect(sigc::bind(sigc::mem_fun(CFrameBuffer::getInstance(), m_frameBuffer->OnFallbackShowFrame.connect(sigc::bind(sigc::mem_fun(CFrameBuffer::getInstance(),
&CFrameBuffer::paintBoxRel), &CFrameBuffer::paintBoxRel),
scr_clock->getXPos(), scr_clock->getYPos(), scr_clock->getXPos(), scr_clock->getYPos(),
@@ -383,7 +417,7 @@ void CScreenSaver::paint()
COL_BLACK, COL_BLACK,
0, 0,
CORNER_ALL) CORNER_ALL)
); );
#endif #endif
m_frameBuffer->showFrame("blackscreen.jpg", CFrameBuffer::SHOW_FRAME_FALLBACK_MODE_CALLBACK | CFrameBuffer::SHOW_FRAME_FALLBACK_MODE_BLACKSCREEN); m_frameBuffer->showFrame("blackscreen.jpg", CFrameBuffer::SHOW_FRAME_FALLBACK_MODE_CALLBACK | CFrameBuffer::SHOW_FRAME_FALLBACK_MODE_BLACKSCREEN);
#endif #endif
@@ -393,11 +427,11 @@ void CScreenSaver::paint()
if (scr_clock) if (scr_clock)
{ {
scr_clock->setTextColor(clr.i_color); scr_clock->setTextColor(clr.i_color);
//check position and size use only possible available screen size // check position and size use only possible available screen size
int x_cl, y_cl, w_cl, h_cl; int x_cl, y_cl, w_cl, h_cl;
scr_clock->getDimensions(&x_cl, &y_cl, &w_cl, &h_cl); scr_clock->getDimensions(&x_cl, &y_cl, &w_cl, &h_cl);
int x_random = rand_r(&seed[1]) % ((g_settings.screen_EndX - w_cl - g_settings.screen_StartX) + 1) + g_settings.screen_StartX; int x_random = rand_r(&seed[1]) % ((g_settings.screen_EndX - w_cl - g_settings.screen_StartX) + 1) + g_settings.screen_StartX;
int y_random = rand_r(&seed[2]) % ((g_settings.screen_EndY - h_cl - g_settings.screen_StartY) + 1) + g_settings.screen_StartY; int y_random = rand_r(&seed[2]) % ((g_settings.screen_EndY - h_cl - g_settings.screen_StartY) + 1) + g_settings.screen_StartY;
if (g_RadiotextWin) if (g_RadiotextWin)
{ {
@@ -423,16 +457,17 @@ void CScreenSaver::paint()
if (g_settings.screensaver_mode == SCR_MODE_CLOCK_COLOR) if (g_settings.screensaver_mode == SCR_MODE_CLOCK_COLOR)
{ {
srand (time(NULL)); srand(time(NULL));
uint32_t brightness; uint32_t brightness;
// sorcery, no darkness // sorcery, no darkness
do { do
{
clr.i_color = rand_r(&seed[3]); clr.i_color = rand_r(&seed[3]);
brightness = (unsigned int)clr.uc_color.r * 19595 + (unsigned int)clr.uc_color.g * 38469 + (unsigned int)clr.uc_color.b * 7471; brightness = (unsigned int)clr.uc_color.r * 19595 + (unsigned int)clr.uc_color.g * 38469 + (unsigned int)clr.uc_color.b * 7471;
//printf("[%s] %s: brightness: %d\n", __file__, __FUNCTION__, brightness>> 16); //printf("[%s] %s: brightness: %d\n", __file__, __FUNCTION__, brightness>> 16);
} }
while(brightness >> 16 < 80); while (brightness >> 16 < 80);
clr.i_color &= 0x00FFFFFF; clr.i_color &= 0x00FFFFFF;
//printf("[%s] %s: clr.i_color: r %02x g %02x b %02x a %02x\n", __file__, __FUNCTION__, clr.uc_color.r, clr.uc_color.g, clr.uc_color.b, clr.uc_color.a); //printf("[%s] %s: clr.i_color: r %02x g %02x b %02x a %02x\n", __file__, __FUNCTION__, clr.uc_color.r, clr.uc_color.g, clr.uc_color.b, clr.uc_color.a);
@@ -450,9 +485,9 @@ void CScreenSaver::handleRadioText(bool enable_paint)
g_RadiotextWin->clearSavedScreen(); g_RadiotextWin->clearSavedScreen();
if (g_settings.screensaver_mode != SCR_MODE_IMAGE) if (g_settings.screensaver_mode != SCR_MODE_IMAGE)
g_RadiotextWin->kill(/*COL_BLACK*/); //ensure black paintBackground before repaint g_RadiotextWin->kill(/*COL_BLACK*/); // ensure black paintBackground before repaint
//check position and size, use only possible available screen size // check position and size, use only possible available screen size
int x_rt, y_rt, w_rt, h_rt; int x_rt, y_rt, w_rt, h_rt;
g_RadiotextWin->getDimensions(&x_rt, &y_rt, &w_rt, &h_rt); g_RadiotextWin->getDimensions(&x_rt, &y_rt, &w_rt, &h_rt);
int rt_x_random = rand_r(&seed[4]) % ((g_settings.screen_EndX - w_rt - g_settings.screen_StartX - OFFSET_SHADOW) + 1) + g_settings.screen_StartX; int rt_x_random = rand_r(&seed[4]) % ((g_settings.screen_EndX - w_rt - g_settings.screen_StartX - OFFSET_SHADOW) + 1) + g_settings.screen_StartX;
@@ -480,34 +515,34 @@ void CScreenSaver::hideRadioText()
return; return;
g_RadiotextWin->sl_after_decode_line.block(); g_RadiotextWin->sl_after_decode_line.block();
if (scr_clock) if (scr_clock)
scr_clock->cl_sl_show.block(); scr_clock->cl_sl_show.block();
g_RadiotextWin->kill(); g_RadiotextWin->kill();
g_RadiotextWin->hide(); g_RadiotextWin->hide();
if (scr_clock) if (scr_clock)
scr_clock->cl_sl_show.unblock(); scr_clock->cl_sl_show.unblock();
} }
bool CScreenSaver::canStart() bool CScreenSaver::canStart()
{ {
if (g_settings.screensaver_delay && (time(NULL) - idletime > g_settings.screensaver_delay*60)) if (g_settings.screensaver_delay && (time(NULL) - idletime > g_settings.screensaver_delay * 60))
return true; return true;
return false; return false;
} }
bool CScreenSaver::isActive() bool CScreenSaver::isActive()
{ {
if(thrScreenSaver) if (thrScreenSaver)
return true; return true;
return false; return false;
} }
bool CScreenSaver::ignoredMsg(neutrino_msg_t msg) bool CScreenSaver::ignoredMsg(neutrino_msg_t msg)
{ {
/* screensaver will ignore these msgs */ // screensaver will ignore these msgs
if ( if (
msg == NeutrinoMessages::EVT_CURRENTEPG msg == NeutrinoMessages::EVT_CURRENTEPG
|| msg == NeutrinoMessages::EVT_NEXTEPG || msg == NeutrinoMessages::EVT_NEXTEPG
@@ -520,13 +555,14 @@ bool CScreenSaver::ignoredMsg(neutrino_msg_t msg)
|| msg == NeutrinoMessages::EVT_ZAP_GOTPIDS || msg == NeutrinoMessages::EVT_ZAP_GOTPIDS
|| msg == NeutrinoMessages::EVT_EIT_COMPLETE || msg == NeutrinoMessages::EVT_EIT_COMPLETE
|| msg == NeutrinoMessages::EVT_BACK_ZAP_COMPLETE || msg == NeutrinoMessages::EVT_BACK_ZAP_COMPLETE
|| msg == CSectionsdClient::EVT_GOT_CN_EPG
) )
return true; return true;
return false; return false;
} }
CComponentsFrmClock* CScreenSaver::getClockObject() CComponentsFrmClock *CScreenSaver::getClockObject()
{ {
return scr_clock; return scr_clock;
} }

View File

@@ -59,8 +59,10 @@ class CScreenSaver : public sigc::trackable
time_t idletime; time_t idletime;
union u_color { union u_color
struct s_color { {
struct s_color
{
uint8_t b, g, r, a; uint8_t b, g, r, a;
} uc_color; } uc_color;
unsigned int i_color; unsigned int i_color;
@@ -76,18 +78,18 @@ class CScreenSaver : public sigc::trackable
SCR_MODE_IMAGE, SCR_MODE_IMAGE,
SCR_MODE_CLOCK, SCR_MODE_CLOCK,
SCR_MODE_CLOCK_COLOR SCR_MODE_CLOCK_COLOR
}SCR_MODE_T; } SCR_MODE_T;
typedef enum typedef enum
{ {
SCR_MODE_TEXT_OFF, SCR_MODE_TEXT_OFF,
SCR_MODE_TEXT_ON SCR_MODE_TEXT_ON
}SCR_MODE_TEXT_T; } SCR_MODE_TEXT_T;
CScreenSaver(); CScreenSaver();
~CScreenSaver(); ~CScreenSaver();
static CScreenSaver* getInstance(); static CScreenSaver *getInstance();
bool canStart(); bool canStart();
bool isActive(); bool isActive();
void Start(); void Start();
@@ -100,7 +102,7 @@ class CScreenSaver : public sigc::trackable
void resetIdleTime() { idletime = time(NULL); } void resetIdleTime() { idletime = time(NULL); }
time_t getIdleTime() { return idletime; } time_t getIdleTime() { return idletime; }
void forceRefresh() { force_refresh = true; } void forceRefresh() { force_refresh = true; }
static CComponentsFrmClock* getClockObject(); static CComponentsFrmClock *getClockObject();
}; };
#endif // __CSCREENSAVER_H__ #endif // __CSCREENSAVER_H__