Stefan Schuermans commited on 2011-10-23 19:20:38
Showing 9 changed files, with 295 additions and 21 deletions.
| ... | ... |
@@ -13,6 +13,7 @@ |
| 13 | 13 |
#include "Directory.h" |
| 14 | 14 |
#include "File.h" |
| 15 | 15 |
#include "Player.h" |
| 16 |
+#include "SettingFile.h" |
|
| 16 | 17 |
#include "StreamMgr.h" |
| 17 | 18 |
#include "Time.h" |
| 18 | 19 |
#include "TimeCallee.h" |
| ... | ... |
@@ -30,14 +31,15 @@ Player::Player(CallMgr &callMgr, StreamMgr &streamMgr, |
| 30 | 31 |
m_callMgr(callMgr), |
| 31 | 32 |
m_streamMgr(streamMgr), |
| 32 | 33 |
m_dirBase(dirBase), |
| 34 |
+ m_fileOutStream(dirBase.getFile("outstream")),
|
|
| 33 | 35 |
m_dirPlaylist(dirBase.getSubdir("playlist")),
|
| 34 |
- m_streamName("TEST"), // TODO
|
|
| 35 |
- m_pStream(NULL), |
|
| 36 |
+ m_pOutStream(NULL), |
|
| 36 | 37 |
m_curEntry(m_playlist.begin()), |
| 37 | 38 |
m_curFrame(0) |
| 38 | 39 |
{
|
| 39 | 40 |
// get output stream |
| 40 |
- m_pStream = &m_streamMgr.refStream(m_streamName); |
|
| 41 |
+ m_fileOutStream.getStr(m_nameOutStream); |
|
| 42 |
+ m_pOutStream = &m_streamMgr.refStream(m_nameOutStream); |
|
| 41 | 43 |
|
| 42 | 44 |
// load playlist |
| 43 | 45 |
updatePlaylist(); |
| ... | ... |
@@ -53,8 +55,8 @@ Player::~Player() |
| 53 | 55 |
} |
| 54 | 56 |
|
| 55 | 57 |
// unreference stream |
| 56 |
- m_pStream = NULL; |
|
| 57 |
- m_streamMgr.unrefStream(m_streamName); |
|
| 58 |
+ m_pOutStream = NULL; |
|
| 59 |
+ m_streamMgr.unrefStream(m_nameOutStream); |
|
| 58 | 60 |
} |
| 59 | 61 |
|
| 60 | 62 |
/// callback when requsted time reached |
| ... | ... |
@@ -144,8 +146,8 @@ void Player::showFrame() |
| 144 | 146 |
// detect empty playlist or playlist with only empty movies |
| 145 | 147 |
if (wrapped) {
|
| 146 | 148 |
// empty playlist or playlist with only empty movies -> no frame |
| 147 |
- if (m_pStream) |
|
| 148 |
- m_pStream->setNoFrame(); |
|
| 149 |
+ if (m_pOutStream) |
|
| 150 |
+ m_pOutStream->setNoFrame(); |
|
| 149 | 151 |
return; |
| 150 | 152 |
} |
| 151 | 153 |
wrapped = true; |
| ... | ... |
@@ -161,8 +163,8 @@ void Player::showFrame() |
| 161 | 163 |
// show frame |
| 162 | 164 |
stBlinkenFrame *pFrame = |
| 163 | 165 |
BlinkenMovieGetFrame(m_curEntry->m_pMovie, m_curFrame); |
| 164 |
- if (m_pStream) |
|
| 165 |
- m_pStream->setFrame(pFrame); |
|
| 166 |
+ if (m_pOutStream) |
|
| 167 |
+ m_pOutStream->setFrame(pFrame); |
|
| 166 | 168 |
|
| 167 | 169 |
// calculate show time for next frame |
| 168 | 170 |
Time duration; |
| ... | ... |
@@ -14,6 +14,7 @@ |
| 14 | 14 |
#include "CallMgr.h" |
| 15 | 15 |
#include "Directory.h" |
| 16 | 16 |
#include "File.h" |
| 17 |
+#include "SettingFile.h" |
|
| 17 | 18 |
#include "StreamMgr.h" |
| 18 | 19 |
#include "Time.h" |
| 19 | 20 |
#include "TimeCallee.h" |
| ... | ... |
@@ -71,9 +72,10 @@ protected: |
| 71 | 72 |
CallMgr &m_callMgr; ///< callback manager |
| 72 | 73 |
StreamMgr &m_streamMgr; ///< stream manager |
| 73 | 74 |
Directory m_dirBase; ///< base directory |
| 75 |
+ SettingFile m_fileOutStream; ///< output stream name file |
|
| 74 | 76 |
Directory m_dirPlaylist; ///< playlist directory |
| 75 |
- std::string m_streamName; ///< name of output stream |
|
| 76 |
- Stream *m_pStream; ///< output stream |
|
| 77 |
+ std::string m_nameOutStream; ///< name of output stream |
|
| 78 |
+ Stream *m_pOutStream; ///< output stream |
|
| 77 | 79 |
Playlist m_playlist; ///< current playlist |
| 78 | 80 |
Playlist::const_iterator m_curEntry; ///< current playlist entry |
| 79 | 81 |
int m_curFrame; ///< current frame in movie |
| ... | ... |
@@ -0,0 +1,71 @@ |
| 1 |
+/* Blinker |
|
| 2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
| 3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
| 4 |
+ a blinkenarea.org project */ |
|
| 5 |
+ |
|
| 6 |
+#include <iostream> |
|
| 7 |
+#include <stdlib.h> |
|
| 8 |
+#include <string> |
|
| 9 |
+ |
|
| 10 |
+#include <BlinkenLib/BlinkenFrame.h> |
|
| 11 |
+ |
|
| 12 |
+#include "Directory.h" |
|
| 13 |
+#include "File.h" |
|
| 14 |
+#include "Printer.h" |
|
| 15 |
+#include "SettingFile.h" |
|
| 16 |
+#include "StreamMgr.h" |
|
| 17 |
+#include "StreamRecv.h" |
|
| 18 |
+ |
|
| 19 |
+namespace Blinker {
|
|
| 20 |
+ |
|
| 21 |
+/** |
|
| 22 |
+ * @brief constructor |
|
| 23 |
+ * @param[in] streamMgr stream manager |
|
| 24 |
+ * @param[in] dirBase base directory |
|
| 25 |
+ */ |
|
| 26 |
+Printer::Printer(StreamMgr &streamMgr, const Directory &dirBase): |
|
| 27 |
+ m_streamMgr(streamMgr), |
|
| 28 |
+ m_dirBase(dirBase), |
|
| 29 |
+ m_fileInStream(dirBase.getFile("instream")),
|
|
| 30 |
+ m_pInStream(NULL) |
|
| 31 |
+{
|
|
| 32 |
+ // get input stream |
|
| 33 |
+ m_fileInStream.getStr(m_nameInStream); |
|
| 34 |
+ m_pInStream = &m_streamMgr.refStream(m_nameInStream); |
|
| 35 |
+ |
|
| 36 |
+ // attach to input stream |
|
| 37 |
+ if (m_pInStream) |
|
| 38 |
+ m_pInStream->attach(this); |
|
| 39 |
+} |
|
| 40 |
+ |
|
| 41 |
+/// virtual destructor |
|
| 42 |
+Printer::~Printer() |
|
| 43 |
+{
|
|
| 44 |
+ // detach from input stream |
|
| 45 |
+ if (m_pInStream) |
|
| 46 |
+ m_pInStream->detach(this); |
|
| 47 |
+ |
|
| 48 |
+ // unreference stream |
|
| 49 |
+ m_pInStream = NULL; |
|
| 50 |
+ m_streamMgr.unrefStream(m_nameInStream); |
|
| 51 |
+} |
|
| 52 |
+ |
|
| 53 |
+/** |
|
| 54 |
+ * @brief set current frame |
|
| 55 |
+ * @param[in] pFrame current frame |
|
| 56 |
+ */ |
|
| 57 |
+void Printer::setFrame(stBlinkenFrame *pFrame) |
|
| 58 |
+{
|
|
| 59 |
+ char *str = BlinkenFrameToString(pFrame); |
|
| 60 |
+ std::cout << str; |
|
| 61 |
+ free(str); |
|
| 62 |
+} |
|
| 63 |
+ |
|
| 64 |
+/// set current frame to none |
|
| 65 |
+void Printer::setNoFrame() |
|
| 66 |
+{
|
|
| 67 |
+ std::cout << "no frame" << std::endl; |
|
| 68 |
+} |
|
| 69 |
+ |
|
| 70 |
+} // namespace Blinker |
|
| 71 |
+ |
| ... | ... |
@@ -0,0 +1,63 @@ |
| 1 |
+/* Blinker |
|
| 2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
| 3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
| 4 |
+ a blinkenarea.org project */ |
|
| 5 |
+ |
|
| 6 |
+#ifndef PRINTER_H |
|
| 7 |
+#define PRINTER_H |
|
| 8 |
+ |
|
| 9 |
+#include <string> |
|
| 10 |
+ |
|
| 11 |
+#include <BlinkenLib/BlinkenFrame.h> |
|
| 12 |
+ |
|
| 13 |
+#include "Directory.h" |
|
| 14 |
+#include "File.h" |
|
| 15 |
+#include "SettingFile.h" |
|
| 16 |
+#include "StreamMgr.h" |
|
| 17 |
+#include "StreamRecv.h" |
|
| 18 |
+ |
|
| 19 |
+namespace Blinker {
|
|
| 20 |
+ |
|
| 21 |
+/// a stream printer |
|
| 22 |
+class Printer: public StreamRecv |
|
| 23 |
+{
|
|
| 24 |
+public: |
|
| 25 |
+ /** |
|
| 26 |
+ * @brief constructor |
|
| 27 |
+ * @param[in] streamMgr stream manager |
|
| 28 |
+ * @param[in] dirBase base directory |
|
| 29 |
+ */ |
|
| 30 |
+ Printer(StreamMgr &streamMgr, const Directory &dirBase); |
|
| 31 |
+ |
|
| 32 |
+ /// virtual destructor |
|
| 33 |
+ virtual ~Printer(); |
|
| 34 |
+ |
|
| 35 |
+private: |
|
| 36 |
+ /// copy constructor disabled |
|
| 37 |
+ Printer(const Printer & that); |
|
| 38 |
+ |
|
| 39 |
+ /// assignment operator disabled |
|
| 40 |
+ const Printer& operator=(const Printer &that); |
|
| 41 |
+ |
|
| 42 |
+public: |
|
| 43 |
+ /** |
|
| 44 |
+ * @brief set current frame |
|
| 45 |
+ * @param[in] pFrame current frame |
|
| 46 |
+ */ |
|
| 47 |
+ virtual void setFrame(stBlinkenFrame *pFrame); |
|
| 48 |
+ |
|
| 49 |
+ /// set current frame to none |
|
| 50 |
+ virtual void setNoFrame(); |
|
| 51 |
+ |
|
| 52 |
+protected: |
|
| 53 |
+ StreamMgr &m_streamMgr; ///< stream manager |
|
| 54 |
+ Directory m_dirBase; ///< base directory |
|
| 55 |
+ SettingFile m_fileInStream; ///< input stream name file |
|
| 56 |
+ std::string m_nameInStream; ///< name of input stream |
|
| 57 |
+ Stream *m_pInStream; ///< input stream |
|
| 58 |
+}; // class Printer |
|
| 59 |
+ |
|
| 60 |
+} // namespace Blinker |
|
| 61 |
+ |
|
| 62 |
+#endif // #ifndef PRINTER_H |
|
| 63 |
+ |
| ... | ... |
@@ -0,0 +1,69 @@ |
| 1 |
+/* Blinker |
|
| 2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
| 3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
| 4 |
+ a blinkenarea.org project */ |
|
| 5 |
+ |
|
| 6 |
+#include <fstream> |
|
| 7 |
+#include <string> |
|
| 8 |
+ |
|
| 9 |
+#include "File.h" |
|
| 10 |
+#include "SettingFile.h" |
|
| 11 |
+ |
|
| 12 |
+namespace Blinker {
|
|
| 13 |
+ |
|
| 14 |
+/** |
|
| 15 |
+ * @brief constructor from path |
|
| 16 |
+ * @param[in] path path to file |
|
| 17 |
+ */ |
|
| 18 |
+SettingFile::SettingFile(const std::string &path): |
|
| 19 |
+ File(path) |
|
| 20 |
+{
|
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+/** |
|
| 24 |
+ * @brief constructor from basic file |
|
| 25 |
+ * @param[in] file basic file object |
|
| 26 |
+ */ |
|
| 27 |
+SettingFile::SettingFile(const File &file): |
|
| 28 |
+ File(file) |
|
| 29 |
+{
|
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+/** |
|
| 33 |
+ * @brief assignment operator |
|
| 34 |
+ * @param[in] file basic file object |
|
| 35 |
+ */ |
|
| 36 |
+const SettingFile & SettingFile::operator=(const File &file) |
|
| 37 |
+{
|
|
| 38 |
+ File::operator=(file); |
|
| 39 |
+ return *this; |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+/** |
|
| 43 |
+ * @brief get setting as string |
|
| 44 |
+ * @param[out] val setting read from file |
|
| 45 |
+ * @param[in] def default setting (to return on error) |
|
| 46 |
+ * @return if setting was successfully read from file |
|
| 47 |
+ */ |
|
| 48 |
+bool SettingFile::getStr(std::string &val, |
|
| 49 |
+ const std::string &def /*= ""*/) const |
|
| 50 |
+{
|
|
| 51 |
+ std::ifstream ifstrm(m_path.c_str(), std::ios::in); |
|
| 52 |
+ if (!ifstrm.is_open()) {
|
|
| 53 |
+ val = def; |
|
| 54 |
+ return false; |
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+ std::getline(ifstrm, val); |
|
| 58 |
+ if (ifstrm.fail()) {
|
|
| 59 |
+ val = def; |
|
| 60 |
+ return false; |
|
| 61 |
+ } |
|
| 62 |
+ |
|
| 63 |
+ ifstrm.close(); |
|
| 64 |
+ |
|
| 65 |
+ return true; |
|
| 66 |
+} |
|
| 67 |
+ |
|
| 68 |
+} // namespace Blinker |
|
| 69 |
+ |
| ... | ... |
@@ -0,0 +1,50 @@ |
| 1 |
+/* Blinker |
|
| 2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
| 3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
| 4 |
+ a blinkenarea.org project */ |
|
| 5 |
+ |
|
| 6 |
+#ifndef SETTINGFILE_H |
|
| 7 |
+#define SETTINGFILE_H |
|
| 8 |
+ |
|
| 9 |
+#include <string> |
|
| 10 |
+ |
|
| 11 |
+#include "File.h" |
|
| 12 |
+ |
|
| 13 |
+namespace Blinker {
|
|
| 14 |
+ |
|
| 15 |
+/// file containting a single setting |
|
| 16 |
+class SettingFile: public File |
|
| 17 |
+{
|
|
| 18 |
+public: |
|
| 19 |
+ /** |
|
| 20 |
+ * @brief constructor from path |
|
| 21 |
+ * @param[in] path path to file |
|
| 22 |
+ */ |
|
| 23 |
+ SettingFile(const std::string &path); |
|
| 24 |
+ |
|
| 25 |
+ /** |
|
| 26 |
+ * @brief constructor from basic file |
|
| 27 |
+ * @param[in] file basic file object |
|
| 28 |
+ */ |
|
| 29 |
+ SettingFile(const File &file); |
|
| 30 |
+ |
|
| 31 |
+ /** |
|
| 32 |
+ * @brief assignment operator |
|
| 33 |
+ * @param[in] file basic file object |
|
| 34 |
+ */ |
|
| 35 |
+ const SettingFile & operator=(const File &file); |
|
| 36 |
+ |
|
| 37 |
+public: |
|
| 38 |
+ /** |
|
| 39 |
+ * @brief get setting as string |
|
| 40 |
+ * @param[out] val setting read from file |
|
| 41 |
+ * @param[in] def default setting (to return on error) |
|
| 42 |
+ * @return if setting was successfully read from file |
|
| 43 |
+ */ |
|
| 44 |
+ bool getStr(std::string& val, const std::string& def = "") const; |
|
| 45 |
+}; // class SettingFile |
|
| 46 |
+ |
|
| 47 |
+} // namespace Blinker |
|
| 48 |
+ |
|
| 49 |
+#endif // #ifndef SETTINGFILE_H |
|
| 50 |
+ |
| ... | ... |
@@ -3,9 +3,7 @@ |
| 3 | 3 |
Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
| 4 | 4 |
a blinkenarea.org project */ |
| 5 | 5 |
|
| 6 |
-#include <iostream> // DEBUG |
|
| 7 | 6 |
#include <set> |
| 8 |
-#include <stdlib.h> // DEBUG |
|
| 9 | 7 |
|
| 10 | 8 |
#include <BlinkenLib/BlinkenFrame.h> |
| 11 | 9 |
|
| ... | ... |
@@ -15,13 +13,17 @@ |
| 15 | 13 |
namespace Blinker {
|
| 16 | 14 |
|
| 17 | 15 |
/// constructor |
| 18 |
-Stream::Stream() |
|
| 16 |
+Stream::Stream(): |
|
| 17 |
+ m_pFrame(NULL) |
|
| 19 | 18 |
{
|
| 20 | 19 |
} |
| 21 | 20 |
|
| 22 | 21 |
/// virtual destructor |
| 23 | 22 |
Stream::~Stream() |
| 24 | 23 |
{
|
| 24 |
+ // free current frame |
|
| 25 |
+ if (m_pFrame) |
|
| 26 |
+ BlinkenFrameFree(m_pFrame); |
|
| 25 | 27 |
} |
| 26 | 28 |
|
| 27 | 29 |
/** |
| ... | ... |
@@ -31,6 +33,12 @@ Stream::~Stream() |
| 31 | 33 |
void Stream::attach(StreamRecv *recv) |
| 32 | 34 |
{
|
| 33 | 35 |
m_recvs.insert(recv); |
| 36 |
+ |
|
| 37 |
+ // send current frame to receiver |
|
| 38 |
+ if (m_pFrame) |
|
| 39 |
+ recv->setFrame(m_pFrame); |
|
| 40 |
+ else |
|
| 41 |
+ recv->setNoFrame(); |
|
| 34 | 42 |
} |
| 35 | 43 |
|
| 36 | 44 |
/** |
| ... | ... |
@@ -48,22 +56,27 @@ void Stream::detach(StreamRecv *recv) |
| 48 | 56 |
*/ |
| 49 | 57 |
void Stream::setFrame(stBlinkenFrame *pFrame) |
| 50 | 58 |
{
|
| 51 |
- // DEBUG |
|
| 52 |
- char *str = BlinkenFrameToString(pFrame); |
|
| 53 |
- std::cout << str; |
|
| 54 |
- free(str); |
|
| 59 |
+ // update local copy of current frame |
|
| 60 |
+ if (m_pFrame) |
|
| 61 |
+ BlinkenFrameFree(m_pFrame); |
|
| 62 |
+ m_pFrame = BlinkenFrameClone(pFrame); |
|
| 63 |
+ if (!m_pFrame) |
|
| 64 |
+ return; // out of memory: do not pass NULL pointer to receivers |
|
| 55 | 65 |
|
| 56 | 66 |
// pass frame to all receivers |
| 57 | 67 |
Recvs::iterator it; |
| 58 | 68 |
for (it = m_recvs.begin(); it != m_recvs.end(); ++it) |
| 59 |
- (*it)->setFrame(pFrame); |
|
| 69 |
+ (*it)->setFrame(m_pFrame); |
|
| 60 | 70 |
} |
| 61 | 71 |
|
| 62 | 72 |
/// set current frame to none |
| 63 | 73 |
void Stream::setNoFrame() |
| 64 | 74 |
{
|
| 65 |
- // DEBUG |
|
| 66 |
- std::cout << "no frame" << std::endl; |
|
| 75 |
+ // set current frame to none |
|
| 76 |
+ if (m_pFrame) {
|
|
| 77 |
+ BlinkenFrameFree(m_pFrame); |
|
| 78 |
+ m_pFrame = NULL; |
|
| 79 |
+ } |
|
| 67 | 80 |
|
| 68 | 81 |
// pass "no frame" to all receivers |
| 69 | 82 |
Recvs::iterator it; |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
#include "CallMgr.h" |
| 2 | 2 |
#include "Directory.h" |
| 3 | 3 |
#include "Player.h" |
| 4 |
+#include "Printer.h" |
|
| 4 | 5 |
#include "StreamMgr.h" |
| 5 | 6 |
|
| 6 | 7 |
using namespace Blinker; |
| ... | ... |
@@ -11,6 +12,7 @@ int main() |
| 11 | 12 |
StreamMgr streamMgr; |
| 12 | 13 |
|
| 13 | 14 |
Player player(callMgr, streamMgr, Directory("../example.cfg/players/hdl"));
|
| 15 |
+ Printer printer(streamMgr, Directory("../example.cfg/printers/hdl"));
|
|
| 14 | 16 |
|
| 15 | 17 |
callMgr.run(); |
| 16 | 18 |
|
| 17 | 19 |