/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLIO/src/ICLIO/GenericImageOutput.cpp ** ** Module : ICLIO ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include #include #ifdef ICL_HAVE_QT #include #endif #ifdef ICL_HAVE_ZMQ #include #endif #ifdef ICL_HAVE_OPENCV #include #endif #ifdef ICL_HAVE_LIBAV #include #endif #if defined(ICL_HAVE_RSB) && defined(ICL_HAVE_PROTOBUF) #include #endif #ifdef ICL_HAVE_VIDEODEV #include #endif #include #include #include using namespace icl::utils; using namespace icl::core; namespace icl{ namespace io{ GenericImageOutput::GenericImageOutput(const std::string &type, const std::string &description){ init(type,description); } GenericImageOutput::GenericImageOutput(const ProgArg &pa){ init(pa); } void GenericImageOutput::init(const ProgArg &pa){ init(*pa,utils::pa(pa.getID(),1)); } void GenericImageOutput::release(){ impl = SmartPtr(); } void GenericImageOutput::init(const std::string &type, const std::string &description){ impl = SmartPtr(); this->type = type; this->description = description; ImageOutput *o = 0; std::string d = description; if(d.substr(0,type.length()+1) == type+"=") d = d.substr(type.length()+1); if(type == "null"){ struct NullOutput : public ImageOutput{ virtual void send(const ImgBase *) {} }; o = new NullOutput; } std::vector plugins; #ifdef ICL_HAVE_LIBAV plugins.push_back("video~Video File~libav based video file writer"); if(type == "video"){ try{ std::vector t = tok(d,","); if(!t.size()) throw ICLException("unable to create LibAVVideoWriter with empty destination filename"); std::string fourcc = t.size() > 1 ? t[1] : str("DIV3"); Size size = t.size() > 2 ? parse(t[2]) : Size::VGA; double fps = t.size() > 3 ? parse(t[3]) : 24; std::cout<<"t.size():"< t = tok(d,","); if(!t.size()) throw ICLException("unable to create OpenCVVideoWriter with empty destination filename"); std::string fourcc = t.size() > 1 ? t[1] : str("DIV3"); Size size = t.size() > 2 ? parse(t[2]) : Size::VGA; double fps = t.size() > 3 ? parse(t[3]) : 24; o = new OpenCVVideoWriter(t[0], fourcc, fps, size); }catch(const std::exception &e){ ERROR_LOG("Unable to create OpenCVVideoWriter with this parameters: " << d << "(error: " << e.what() << ")"); } } #endif #endif #ifdef ICL_HAVE_VIDEODEV plugins.push_back("v4l~device name or ID~V4L2-loopback device based image transfer"); if(type == "v4l"){ o = new V4L2LoopBackOutput(d); } #endif #ifdef ICL_HAVE_ZMQ plugins.push_back("zmq~port~ZMQ-based network transfer"); if(type == "zmq"){ o = new ZmqImageOutput(parse(d)); } #endif #ifdef ICL_HAVE_QT plugins.push_back("sm~Shared Memory Segment ID~Qt based shared memory writer"); if(type == "sm"){ o = new SharedMemoryPublisher(d); } #endif #if defined(ICL_HAVE_RSB) && defined(ICL_HAVE_PROTOBUF) plugins.push_back("rsb~[transport:]/scope~Network output stream"); if(type == "rsb"){ try{ std::vector ts = tok(d,":"); if(!ts.size()) throw ICLException("unable to create RSBImageOutput without scope-definition"); if(ts.size() == 1){ o = new RSBImageOutput(ts[0],""); }else if(ts.size() == 2){ o = new RSBImageOutput(ts[1],ts[0]); }else{ throw ICLException("invalid definition string (exptected: [transport-list:]scope"); } }catch(std::exception &e){ ERROR_LOG("Unable to create RSBImageOutput with this parameters: " << d << "(error: " < ts = tok(plugins[i],"~"); t(1,i+1) = ts[0]; t(2,i+1) = ts[1]; t(3,i+1) = ts[2]; } std::cout << "Supported Image Output Devices: "<< std::endl << std::endl << t << std::endl; std::terminate(); } if(!o){ ERROR_LOG("unable to instantiate GenericImageOutput with type \"" << type << "\" and params \"" << d << "\""); } else{ impl = SmartPtr(o); } } } // namespace io }