BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
f87ca98
Branches
Tags
master
Blinker
src
noarch
Resizer.cpp
merged frame processing with no frame processing
Stefan Schuermans
commited
f87ca98
at 2011-12-04 12:58:57
Resizer.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 "Format.h" #include "Module.h" #include "Resizer.h" #include "SettingFile.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 */ Resizer::Resizer(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase): Module(callMgr, streamMgr, dirBase), m_fileInStream(dirBase.getFile("instream")), m_fileFormat(dirBase.getFile("format")), m_fileOutStream(dirBase.getFile("outstream")), m_pInStream(NULL), m_haveFormat(false), m_pOutStream(NULL) { // set up getInStream(); getFormat(); getOutStream(); } /// virtual destructor Resizer::~Resizer() { // clean up releaseInStream(); releaseOutStream(); } /// check for update of configuration void Resizer::updateConfig() { // stream name or format file was modified -> re-get stream or format if (m_fileInStream.checkModified()) { releaseInStream(); getInStream(); } if (m_fileFormat.checkModified()) { getFormat(); } if (m_fileOutStream.checkModified()) { releaseOutStream(); getOutStream(); } } /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame (NULL for none) */ void Resizer::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { procFrame(pFrame); (void)stream; // unused } /// get input stream and attach to it void Resizer::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 Resizer::releaseInStream() { // detach from input stream if (m_pInStream) m_pInStream->detach(this); // unreference stream m_pInStream = NULL; m_streamMgr.unrefStream(m_nameInStream); } /// (re-)get format to resize to void Resizer::getFormat() { std::string strFormat; // read format from format file m_haveFormat = m_fileFormat.getStr(strFormat) && m_format.fromStr(strFormat); // send current frame to output stream sendFrame(); } /// get output stream void Resizer::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 Resizer::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 Resizer::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 Resizer::procFrame(stBlinkenFrame *pFrame) { stBlinkenFrame *pProcFrame; // no output stream -> nothing to do if (!m_pOutStream) return; // no frame or no format -> pass "no frame" if (!pFrame || !m_haveFormat) { m_pOutStream->setFrame(NULL); return; } // format matches -> pass frame directly if ((unsigned int)BlinkenFrameGetWidth(pFrame) == m_format.m_width && (unsigned int)BlinkenFrameGetHeight(pFrame) == m_format.m_height && (unsigned int)BlinkenFrameGetChannels(pFrame) == m_format.m_channels && (unsigned int)BlinkenFrameGetMaxval(pFrame) == m_format.m_maxval) { m_pOutStream->setFrame(pFrame); return; } // clone frame pProcFrame = BlinkenFrameClone(pFrame); if (!pProcFrame){ m_pOutStream->setFrame(NULL); return; } // resize frame BlinkenFrameResize(pProcFrame, m_format.m_height, m_format.m_width, m_format.m_channels, m_format.m_maxval); // pass process frame to output stream m_pOutStream->setFrame(pProcFrame); // free cloned frame BlinkenFrameFree(pProcFrame); } } // namespace Blinker