From aeba6cb5554186478d15cbfc7a9ac580d3c52c72 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 16 Apr 2015 22:49:58 -0400 Subject: Fix the session chimes (and possible stability issue) by removing the special audio thread and using the QMediaPlayer within the main thread (no stuttering/delays in my initial tests so far). Add a PC-BSD specific routine for setting brightness so that hardware brightness controls are attempted (through pc-sysconfig) before the software brightness is modified (using xbrightness) --- libLumina/LuminaOS-FreeBSD.cpp | 19 ++++++++++++++----- lumina-desktop/LSession.cpp | 26 ++++++++++++++------------ lumina-desktop/LSession.h | 2 +- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/libLumina/LuminaOS-FreeBSD.cpp b/libLumina/LuminaOS-FreeBSD.cpp index fc4135f0..73637048 100644 --- a/libLumina/LuminaOS-FreeBSD.cpp +++ b/libLumina/LuminaOS-FreeBSD.cpp @@ -72,12 +72,21 @@ void LOS::setScreenBrightness(int percent){ if(percent<0){percent=0;} else if(percent>100){ percent=100; } float pf = percent/100.0; //convert to a decimel - //Run the command - QString cmd = "xbrightness %1"; - cmd = cmd.arg( QString::number( int(65535*pf) ) ); - int ret = LUtils::runCmd(cmd); + //Run the command(s) + bool success = false; + // - try hardware setting first (PC-BSD only) + if(QFile::exists("/usr/local/bin/pc-sysconfig")){ + QString ret = LUtils::getCmdOutput("pc-sysconfig \"setscreenbrightness "+QString::number(percent)+"\"").join(""); + success = (ret.simplified() == "[SUCCESS]"); + } + // - if hardware brightness does not work, use software brightness + if(!success){ + QString cmd = "xbrightness %1"; + cmd = cmd.arg( QString::number( int(65535*pf) ) ); + success = (0 == LUtils::runCmd(cmd) ); + } //Save the result for later - if(ret!=0){ screenbrightness = -1; } + if(!success){ screenbrightness = -1; } else{ screenbrightness = percent; } LUtils::writeFile(QDir::homePath()+"/.lumina/.currentxbrightness", QStringList() << QString::number(screenbrightness), true); } diff --git a/lumina-desktop/LSession.cpp b/lumina-desktop/LSession.cpp index 8f6da9ff..e076210f 100644 --- a/lumina-desktop/LSession.cpp +++ b/lumina-desktop/LSession.cpp @@ -24,7 +24,7 @@ #include #ifndef DEBUG -#define DEBUG 0 +#define DEBUG 1 #endif XCBEventFilter *evFilter = 0; @@ -54,8 +54,7 @@ LSession::LSession(int &argc, char ** argv) : QApplication(argc, argv){ settingsmenu = 0; currTranslator=0; mediaObj=0; - //audioOut=0; - audioThread=0; + //audioThread=0; sessionsettings=0; //Setup the event filter for Qt5 evFilter = new XCBEventFilter(this); @@ -72,7 +71,6 @@ LSession::~LSession(){ delete appmenu; delete currTranslator; if(mediaObj!=0){delete mediaObj;} - //if(audioOut!=0){delete audioOut; } } void LSession::setupSession(){ @@ -176,13 +174,17 @@ void LSession::CleanupSession(){ if(playaudio){ //wait a max of 3 seconds for audio to finish bool waitmore = true; - for(int i=0; i<6 && waitmore; i++){ - waitmore = !audioThread->wait(500); + for(int i=0; i<60 && waitmore; i++){ + usleep(50000); //50ms = 50000 us + waitmore = (mediaObj->state()==QMediaPlayer::PlayingState); + //waitmore = !audioThread->wait(500); LSession::processEvents(); } + if(waitmore){ mediaObj->stop(); } //timed out }else{ - for(int i=0; i<20; i++){ LSession::processEvents(); usleep(25); } //1/2 second pause + for(int i=0; i<20; i++){ LSession::processEvents(); usleep(25000); } //1/2 second pause } + //if(audioThread!=0){ audioThread->exit(0); } } int LSession::VersionStringToNumber(QString version){ @@ -469,19 +471,19 @@ void LSession::playAudioFile(QString filepath){ //Setup the audio output systems for the desktop bool init = false; if(DEBUG){ qDebug() << "Play Audio File"; } - if(audioThread==0){ qDebug() << " - Initialize audio systems"; audioThread = new QThread(); init = true; } + //if(audioThread==0){ qDebug() << " - Initialize audio systems"; audioThread = new QThread(); init = true; } if(mediaObj==0){ qDebug() << " - Initialize media player"; mediaObj = new QMediaPlayer(); init = true;} - if(mediaObj && init){ //in case it errors for some reason + /*if(mediaObj && init){ //in case it errors for some reason qDebug() << " -- Move audio objects to separate thread"; mediaObj->moveToThread(audioThread); audioThread->start(); - } + }*/ if(mediaObj !=0 ){ if(DEBUG){ qDebug() << " - starting playback:" << filepath; } - mediaObj->setMedia(QUrl::fromLocalFile(filepath)); mediaObj->setVolume(100); + mediaObj->setMedia(QUrl::fromLocalFile(filepath)); mediaObj->play(); - if(!audioThread->isRunning()){ audioThread->start(); } + //if(!audioThread->isRunning()){ audioThread->start(); } LSession::processEvents(); } if(DEBUG){ qDebug() << " - Done with Audio File"; } diff --git a/lumina-desktop/LSession.h b/lumina-desktop/LSession.h index 4c9ea15e..5baf72c4 100644 --- a/lumina-desktop/LSession.h +++ b/lumina-desktop/LSession.h @@ -97,7 +97,7 @@ private: SettingsMenu *settingsmenu; QTranslator *currTranslator; QMediaPlayer *mediaObj; - QThread *audioThread; + //QThread *audioThread; QSettings *sessionsettings; bool cleansession; -- cgit