![]() |
AlarmNotifications
PANDA Slow Control Alarm Daemon
|
Opto-acoustic alarm engine. More...
#include <beedo.h>
Signals | |
void | signalPlay () |
Signal GUI to start playing. More... | |
void | signalStop () |
Signal GUI to stop playing. More... | |
Public Member Functions | |
virtual | ~Beedo () |
Destructor. More... | |
Beedo (const Beedo &other)=delete | |
Copy constructor (deleted) More... | |
Beedo (Beedo &&other)=delete | |
Move constructor (C++11, deleted) More... | |
Beedo & | operator= (const Beedo &other)=delete |
Copy assignment (deleted) More... | |
Beedo & | operator= (Beedo &&other)=delete |
Move assignment (C++11, deleted) More... | |
void | destroy () |
Destroy all media objects. More... | |
Static Public Member Functions | |
static Beedo & | instance () |
Get singleton instance. More... | |
static void | start () noexcept |
Start video playback. More... | |
static void | stop () noexcept |
Stop video playback. More... | |
Private Slots | |
void | playAlarmVideo () |
Instruct phonon to start playing. More... | |
void | stopAlarmVideo () |
Instruct Phonon to stop playing. More... | |
void | phononStateChange (const Phonon::State newState, const Phonon::State oldState) |
React on a Phonon state change. More... | |
Private Member Functions | |
Beedo () | |
Constructor. More... | |
void | start_internal () noexcept |
Internal routine to start video/audio playback. More... | |
void | stop_internal () noexcept |
Internal routine to stop video/audio playback. More... | |
void | createMediaObjects () |
Create the Qt objects to play a media file. More... | |
void | destroyMediaObjects () |
Delete the Qt and Phonon objects. More... | |
Private Attributes | |
bool | _go |
Video/audio play flag. More... | |
QWidget * | _display |
Video window. More... | |
Phonon::AudioOutput * | _audio |
Phonon audio output encapsulation. More... | |
Phonon::MediaObject * | _media |
Phonon media file encapsulation. More... | |
Phonon::VideoWidget * | _video |
Phonon video output encapsulation. More... | |
Phonon::Path | _mediaToAudio |
Connection between _media and _audio. More... | |
Phonon::Path | _mediaToVideo |
Connection between _media and _video. More... | |
Opto-acoustic alarm engine.
In case of an alarm, this class will play a video (with sound) in the top left corner of the screen. The video window is displayed borderless and without the control buttons of the window manager, so it cannot be "clicked away". The video is compiled into the application executable via the Qt Resource beedo.qrc, which refers to the video file beedo.ogv. The video should use the Ogg Theora video and Ogg Vorbis audio codec to ensure that it is playable on as many systems as possible. To ensure that the video resource is not optimized out by the compiler, the main method must call "Q_INIT_RESOURCE(beedo);".
As there is no need to play several video overlays, this class is laid out as a singleton. To start and stop the video/audio playback, other code just needs to invoke the static methods start() and stop() respectively. In addition, the GUI elements and the signal/slot mechanism must be initialized from the main event loop, otherwise a Qt error will occur. To do this, the constructor of DesktopAlarmWidget calls Beedo::instance(). When the applications exits, the Beedo class will be destructed last because it is a global object. This is a problem because all the other Qt objects will be gone then and so the destructor of QObject will cause a segmentation fault. To avoid this, the destructor of DesktopAlarmWidget invokes the destroy() method. Trying to use this object after destroy() has been called will result in undefined behaviour or even a crash.
If the video playback is active, the file will be looped until stop() is called. Although this class is built for a smooth playback, a small interruption is unavoidable.
The Qt libraries on Scientific Linux 6 are somehow buggy: The first play-through of the file works fine, but the second time the video hangs and the sound is very scratchy. As a workaround, the preprocessor definition BEEDOOLDQTFALLBACK is set when cmake detects an older version of Qt. In this case, all objects related to the media playback are destroyed and recreated upon every new start() and new loop. Unfortunately, this increases the gap between two loops significantly. The old Phonon libraries cannot read a media file directly from a Qt resource, so it is read from the executable and stored in a QBuffer that a Phonon::MediaSource can use.
The actual video and audio handling is done by the Phonon library which was developed by KDE and is a part of Qt. The sound output of this class is grouped into the notification category of Phonon and PulseAudio.
|
private |
Constructor.
On new Qt libraries, the constructor initializes all the hardware connections by invoking createMediaObjects(). If BEEDOOLDQTFALLBACK is set, this is done every time a file is played by playAlarmVideo(). On these old libraries, the constructor puts the video file into a QBuffer as the old libs cannot read from a Qt resource.
|
virtual |
Destructor.
Calls destroy() just to be safe, but destroy() should have been called before by the user. This destructor will be one of the last destructors called because this singleton instance is a global object. As the Qt infrastructure will be gone by then, it will cause a segmentation fault.
To avoid this, the user should call destroy() at an appropriate point.
|
delete |
|
delete |
Move constructor (C++11, deleted)
This class cannot be moved.
other | Another instance of Beedo |
|
private |
Create the Qt objects to play a media file.
Encapsulates all the initialization for Phonon. On recent Qt versions this method is invoked once by the constructor. On old versions (BEEDOOLDQTFALLBACK is set), the objects have to be recreated every time by playAlarmVideo().
This method cannot throw exceptions.
void Beedo::destroy | ( | ) |
Destroy all media objects.
Stops the video/audio playback and deleted all related objects. The user has to cal this method when the application exists (as e.g. in the destructor of DesktopAlarmWidget), otherwise a segmentation fault is likely to occur when the destructor tries to remove the objects but the rest of the Qt infrastructure is already gone.
|
private |
Delete the Qt and Phonon objects.
This method deleted the objects for audio and video playback and clears all corresponding resources. On old Qt versions, playAlarmVideo() does this before recreating the objects. On all versions, this method is called by destroy().
|
static |
Get singleton instance.
This returns a reference (not a pointer) to the singleton instance. On the first invocation, the singleton instance is created. This should only be done from within the GUI thread (as in the constructor of DesktopAlarmWidget) - otherwise a Qt error will occur.
Copy assignment (deleted)
This class cannot be copied.
other | Another instance of Beedo |
Move assignment (C++11, deleted)
This class cannot be moved.
other | Another instance of Beedo |
|
privateslot |
React on a Phonon state change.
This slot is connected to the stateChanged signal on _media. It will close the video window after playback has been stopped and restart the video file after it ran out to procude a loop until stop() is called.
newState | Current state of _media |
oldState | Old state of _media before the change |
|
privateslot |
Instruct phonon to start playing.
This slot method receives the signalPlay() emitted by start_internal() and instructs Phonon to start playing. On old versions of Qt (BEEDOOLDQTFALLBACK is set), this method recreates the needed widgets first to avoid problems.
|
signal |
Signal GUI to start playing.
Emitted by start_internal() to call playAlarmVideo() in the GUI thread.
|
signal |
Signal GUI to stop playing.
Emitted by stop_internal() to call stopAlarmVideo() in the GUI thread.
|
inlinestaticnoexcept |
|
privatenoexcept |
Internal routine to start video/audio playback.
Called by the static helper method start(). Sets the _go flag and emits signalPlay() to invoke playAlarmVideo() in the GUI thread. If _go is already set this method does nothing.
|
inlinestaticnoexcept |
|
privatenoexcept |
Internal routine to stop video/audio playback.
Called by the static helper method stop(). Clears the _go flag and emits signalStop() to invoke stopAlarmVideo() in the GUI thread. If _go is already cleared this method does nothing.
This method cannot throw exceptions.
|
privateslot |
Instruct Phonon to stop playing.
This slot method receives the signalStop() emitted by stop_internal() and instructs Phonon to stop playing. The video window is not closed by this method as this may result in a video driver crash. This close is done in phononStateChange() after the status has changed to stopped.
|
private |
|
private |
|
private |
Video/audio play flag.
Set to true by start_internal() when a video is started and set to false by stop_internal() when the video is stopped.
|
private |
|
private |
|
private |
|
private |