EMIPLIB

mipv4linput.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of EMIPLIB, the EDM Media over IP Library.
00004   
00005   Copyright (C) 2006-2011  Hasselt University - Expertise Centre for
00006                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00021   USA
00022 
00023 */
00024 
00029 #ifndef MIPV4LINPUT_H
00030 
00031 #define MIPV4LINPUT_H
00032 
00033 #include "mipconfig.h"
00034 
00035 #ifdef MIPCONFIG_SUPPORT_VIDEO4LINUX
00036 
00037 #include "mipcomponent.h"
00038 #include "mipsignalwaiter.h"
00039 #include "miptime.h"
00040 #include <jthread/jthread.h>
00041 
00042 class MIPRawYUV420PVideoMessage;
00043 
00045 class EMIPLIB_IMPORTEXPORT MIPV4LInputParameters
00046 {
00047 public:
00048         MIPV4LInputParameters()                                                                 { }
00049         virtual ~MIPV4LInputParameters()                                                        { }
00050 };
00051 
00058 class EMIPLIB_IMPORTEXPORT MIPV4LInput : public MIPComponent, private jthread::JThread
00059 {
00060 public:
00061         MIPV4LInput();
00062 protected:
00064         MIPV4LInput(const std::string &compName);
00065 public:
00066         ~MIPV4LInput();
00067 
00074         bool open(const std::string &device = std::string("/dev/video0"), const MIPV4LInputParameters *pParams = 0);
00075 
00077         bool close();
00078 
00080         int getWidth() const                                                                    { if (m_device != -1) return m_width; return -1; }
00081 
00083         int getHeight() const                                                                   { if (m_device != -1) return m_height; return -1; }
00084 
00086         void setSourceID(uint64_t srcID)                                                        { m_sourceID = srcID; }
00087 
00089         uint64_t getSourceID() const                                                            { return m_sourceID; }
00090         
00091         bool push(const MIPComponentChain &chain, int64_t iteration, MIPMessage *pMsg);
00092         bool pull(const MIPComponentChain &chain, int64_t iteration, MIPMessage **pMsg);
00093 protected:
00103         virtual bool subInit(int device, const MIPV4LInputParameters *pParams)                  { return true; }
00104 private:
00105         void *Thread();
00106 
00107         int m_device;
00108         int m_width, m_height;
00109         uint8_t *m_pCurFrame;
00110         uint8_t *m_pFullFrame;
00111         uint8_t *m_pMsgFrame;
00112         size_t m_frameSize;
00113         MIPRawYUV420PVideoMessage *m_pVideoMsg;
00114         jthread::JMutex m_frameMutex;
00115         jthread::JMutex m_stopMutex;
00116         MIPSignalWaiter m_sigWait;
00117         bool m_gotMsg, m_stopLoop;
00118         bool m_gotFrame;
00119         MIPTime m_captureTime;
00120         uint64_t m_sourceID;
00121 };
00122 
00123 #endif // MIPCONFIG_SUPPORT_VIDEO4LINUX
00124 
00125 #endif // MIPV4LINPUT_H
00126