BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
4a1b01f
Branches
Tags
master
Blinker
src
noarch
Scaler.cpp
implemented scaler module
Stefan Schuermans
commited
4a1b01f
at 2011-11-19 22:04:34
Scaler.cpp
Blame
History
Raw
/* Blinker Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <iostream> #include <stdlib.h> #include <string> #include <BlinkenLib/BlinkenFrame.h> #include "CallMgr.h" #include "Directory.h" #include "File.h" #include "Module.h" #include "Scaler.h" #include "SettingFile.h" #include "Size.h" #include "StreamMgr.h" #include "StreamRecv.h" namespace Blinker { /** * @brief constructor * @param[in] callMgr callback manager * @param[in] streamMgr stream manager * @param[in] dirBase base directory */ Scaler::Scaler(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase): Module(callMgr, streamMgr, dirBase), m_fileInStream(dirBase.getFile("instream")), m_fileSize(dirBase.getFile("size")), m_fileOutStream(dirBase.getFile("outstream")), m_pInStream(NULL), m_haveSize(false), m_pOutStream(NULL) { // set up getInStream(); getSize(); getOutStream(); } /// virtual destructor Scaler::~Scaler() { // clean up releaseInStream(); releaseOutStream(); } /// check for update of configuration void Scaler::updateConfig() { // stream name or size file was modified -> re-get stream or size if (m_fileInStream.checkModified()) { releaseInStream(); getInStream(); } if (m_fileSize.checkModified()) { getSize(); } if (m_fileOutStream.checkModified()) { releaseOutStream(); getOutStream(); } } /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame */ void Scaler::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { procFrame(pFrame); (void)stream; // unused } /** * @brief set current frame to none * @param[in] stream stream name */ void Scaler::setNoFrame(const std::string &stream) { procNoFrame(); (void)stream; // unused } /// get input stream and attach to it void Scaler::getInStream() { // get input stream m_fileInStream.getStr(m_nameInStream); m_pInStream = &m_streamMgr.refStream(m_nameInStream); // attach to input stream if (m_pInStream) m_pInStream->attach(this); } /// detach from input stream and release it void Scaler::releaseInStream() { // detach from input stream if (m_pInStream) m_pInStream->detach(this); // unreference stream m_pInStream = NULL; m_streamMgr.unrefStream(m_nameInStream); } /// (re-)get size to scale to void Scaler::getSize() { std::string strSize; // read size from size file m_haveSize = m_fileSize.getStr(strSize) && m_size.fromStr(strSize); // send current frame to output stream sendFrame(); } /// get output stream void Scaler::getOutStream() { // get output stream m_fileOutStream.getStr(m_nameOutStream); m_pOutStream = &m_streamMgr.refStream(m_nameOutStream); // send current frame to output stream sendFrame(); } /// release output stream void Scaler::releaseOutStream() { // send no frame information if (m_pOutStream) m_pOutStream->setNoFrame(); // unreference stream m_pOutStream = NULL; m_streamMgr.unrefStream(m_nameOutStream); } /// send current frame to output stream void Scaler::sendFrame() { stBlinkenFrame *pFrame; // get current frame from input stream and process it if (m_pInStream && m_pInStream->getCurFrame(pFrame)) procFrame(pFrame); else procNoFrame(); } /** * @brief process frame * @param[in] pFrame frame to process */ void Scaler::procFrame(stBlinkenFrame *pFrame) { stBlinkenFrame *pProcFrame; // no output stream -> nothing to do if (!m_pOutStream) return; // no size -> pass "no frame" if (!m_haveSize) { m_pOutStream->setNoFrame(); return; } // size matches -> pass frame directly if ((unsigned int)BlinkenFrameGetWidth(pFrame) == m_size.m_width && (unsigned int)BlinkenFrameGetHeight(pFrame) == m_size.m_height) { m_pOutStream->setFrame(pFrame); return; } // clone frame pProcFrame = BlinkenFrameClone(pFrame); if (!pProcFrame){ m_pOutStream->setNoFrame(); return; } // scale frame BlinkenFrameScale(pProcFrame, m_size.m_height, m_size.m_width); // pass process frame to output stream m_pOutStream->setFrame(pProcFrame); // free cloned frame BlinkenFrameFree(pProcFrame); } /// process "no frame" void Scaler::procNoFrame() { // pass "no frame" to output stream if (m_pOutStream) m_pOutStream->setNoFrame(); } } // namespace Blinker