AlarmNotifications
PANDA Slow Control Alarm Daemon
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Signals | Public Member Functions | Static Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
AlarmNotifications::Beedo Class Reference

Opto-acoustic alarm engine. More...

#include <beedo.h>

Inheritance diagram for AlarmNotifications::Beedo:
Inheritance graph
[legend]
Collaboration diagram for AlarmNotifications::Beedo:
Collaboration graph
[legend]

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...
 
Beedooperator= (const Beedo &other)=delete
 Copy assignment (deleted) More...
 
Beedooperator= (Beedo &&other)=delete
 Move assignment (C++11, deleted) More...
 
void destroy ()
 Destroy all media objects. More...
 

Static Public Member Functions

static Beedoinstance ()
 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...
 

Detailed Description

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.

Definition at line 71 of file beedo.h.

Constructor & Destructor Documentation

Beedo::Beedo ( )
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.

Definition at line 60 of file beedo.cpp.

Beedo::~Beedo ( )
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.

Definition at line 82 of file beedo.cpp.

AlarmNotifications::Beedo::Beedo ( const Beedo other)
delete

Copy constructor (deleted)

This class cannot be copied.

Parameters
otherAnother instance of Beedo
AlarmNotifications::Beedo::Beedo ( Beedo &&  other)
delete

Move constructor (C++11, deleted)

This class cannot be moved.

Parameters
otherAnother instance of Beedo

Member Function Documentation

void Beedo::createMediaObjects ( )
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.

Returns
Nothing

Definition at line 88 of file beedo.cpp.

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.

Returns
Nothing

Definition at line 132 of file beedo.cpp.

void Beedo::destroyMediaObjects ( )
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().

Returns
Nothing

Definition at line 114 of file beedo.cpp.

Beedo & Beedo::instance ( )
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.

Returns
Reference to singleton instance

Definition at line 53 of file beedo.cpp.

Beedo& AlarmNotifications::Beedo::operator= ( const Beedo other)
delete

Copy assignment (deleted)

This class cannot be copied.

Parameters
otherAnother instance of Beedo
Returns
Nothing (deleted)
Beedo& AlarmNotifications::Beedo::operator= ( Beedo &&  other)
delete

Move assignment (C++11, deleted)

This class cannot be moved.

Parameters
otherAnother instance of Beedo
Returns
Nothing (deleted)
void Beedo::phononStateChange ( const Phonon::State  newState,
const Phonon::State  oldState 
)
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.

Parameters
newStateCurrent state of _media
oldStateOld state of _media before the change
Returns
Nothing

Definition at line 208 of file beedo.cpp.

void Beedo::playAlarmVideo ( )
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.

Returns
Nothing

Definition at line 176 of file beedo.cpp.

void AlarmNotifications::Beedo::signalPlay ( )
signal

Signal GUI to start playing.

Emitted by start_internal() to call playAlarmVideo() in the GUI thread.

Returns
Nothing
void AlarmNotifications::Beedo::signalStop ( )
signal

Signal GUI to stop playing.

Emitted by stop_internal() to call stopAlarmVideo() in the GUI thread.

Returns
Nothing
static void AlarmNotifications::Beedo::start ( )
inlinestaticnoexcept

Start video playback.

This will activate the Beedo engine and play the compiled-in video/audio in an endless loop until stop() is called. If the playback is already running, this method does nothing.

This method cannot throw exceptions.

Returns
Nothing

Definition at line 199 of file beedo.h.

void Beedo::start_internal ( )
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.

Returns
Nothing

Definition at line 138 of file beedo.cpp.

static void AlarmNotifications::Beedo::stop ( )
inlinestaticnoexcept

Stop video playback.

This will disable the Beedo engine, stop the video/audio playback and close the borderless window. It is already stopped, this method does nothing.

This method cannot throw exceptions.

Returns
Nothing

Definition at line 211 of file beedo.h.

void Beedo::stop_internal ( )
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.

Returns
Nothing

Definition at line 157 of file beedo.cpp.

void Beedo::stopAlarmVideo ( )
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.

Returns
Nothing

Definition at line 203 of file beedo.cpp.

Member Data Documentation

Phonon::AudioOutput* AlarmNotifications::Beedo::_audio
private

Phonon audio output encapsulation.

Phonon object that connects to the audio hardware.

Definition at line 92 of file beedo.h.

QWidget* AlarmNotifications::Beedo::_display
private

Video window.

Borderless window where the Phonon::VideoWidget is placed on.

Definition at line 86 of file beedo.h.

bool AlarmNotifications::Beedo::_go
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.

Definition at line 80 of file beedo.h.

Phonon::MediaObject* AlarmNotifications::Beedo::_media
private

Phonon media file encapsulation.

Does all the work regarding finding the codecs, reading the media file/stream etc.

Definition at line 98 of file beedo.h.

Phonon::Path AlarmNotifications::Beedo::_mediaToAudio
private

Connection between _media and _audio.

Passes the audio data from the media object as source to the audio object as sink.

Definition at line 110 of file beedo.h.

Phonon::Path AlarmNotifications::Beedo::_mediaToVideo
private

Connection between _media and _video.

Passes the audio data from the media object as source to the video object as sink.

Definition at line 116 of file beedo.h.

Phonon::VideoWidget* AlarmNotifications::Beedo::_video
private

Phonon video output encapsulation.

Phonon object that connects to the graphics server and video hardware.

Definition at line 104 of file beedo.h.


The documentation for this class was generated from the following files: