BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
f87ca98
Branches
Tags
master
Blinker
src
noarch
Scaler.cpp
merged frame processing with no frame processing
Stefan Schuermans
commited
f87ca98
at 2011-12-04 12:58:57
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 (NULL for none) */ void Scaler::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { procFrame(pFrame); (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->setFrame(NULL); // unreference stream m_pOutStream = NULL; m_streamMgr.unrefStream(m_nameOutStream); } /// send current frame to output stream void Scaler::sendFrame() { stBlinkenFrame *pFrame = NULL; // get current frame from input stream and process it if (m_pInStream) m_pInStream->getCurFrame(pFrame); procFrame(pFrame); } /** * @brief process frame * @param[in] pFrame frame to process (NULL for none) */ void Scaler::procFrame(stBlinkenFrame *pFrame) { stBlinkenFrame *pProcFrame; // no output stream -> nothing to do if (!m_pOutStream) return; // no frame or no size -> pass "no frame" if (!pFrame || !m_haveSize) { m_pOutStream->setFrame(NULL); 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->setFrame(NULL); 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); } } // namespace Blinker