EMIPLIB
|
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 MIPJACKINPUT_H 00030 00031 #define MIPJACKINPUT_H 00032 00033 #include "mipconfig.h" 00034 00035 #ifdef MIPCONFIG_SUPPORT_JACK 00036 00037 #include "mipcomponent.h" 00038 #include "miptime.h" 00039 #include "mipsignalwaiter.h" 00040 #include <jthread/jthread.h> 00041 #include <string> 00042 #include <jack/jack.h> 00043 00044 class MIPRawFloatAudioMessage; 00045 00055 class EMIPLIB_IMPORTEXPORT MIPJackInput : public MIPComponent, public jthread::JThread 00056 { 00057 public: 00058 MIPJackInput(); 00059 ~MIPJackInput(); 00060 00068 bool open(MIPTime interval = MIPTime(0.020), const std::string &serverName = std::string(""), MIPTime arrayTime = MIPTime(10.0)); 00069 00071 int getSamplingRate() const { if (m_pClient == 0) return 0; return m_sampRate; } 00072 00074 bool close(); 00075 00076 bool push(const MIPComponentChain &chain, int64_t iteration, MIPMessage *pMsg); 00077 bool pull(const MIPComponentChain &chain, int64_t iteration, MIPMessage **pMsg); 00078 private: 00079 static int StaticJackCallback(jack_nframes_t nframes, void *arg); 00080 int JackCallback(jack_nframes_t nframes); 00081 void *Thread(); 00082 00083 class RecordBuffer 00084 { 00085 public: 00086 RecordBuffer(size_t bufSize) { m_pLeftBuffer = new jack_default_audio_sample_t [bufSize]; m_pRightBuffer = new jack_default_audio_sample_t [bufSize]; } 00087 ~RecordBuffer() { delete [] m_pLeftBuffer; delete [] m_pRightBuffer; } 00088 jack_default_audio_sample_t *getLeftBuffer() { return m_pLeftBuffer; } 00089 jack_default_audio_sample_t *getRightBuffer() { return m_pRightBuffer; } 00090 void setOffset(size_t o) { m_offset = o; } 00091 size_t getOffset() const { return m_offset; } 00092 private: 00093 jack_default_audio_sample_t *m_pLeftBuffer, *m_pRightBuffer; 00094 size_t m_offset; 00095 }; 00096 00097 jack_client_t *m_pClient; 00098 jack_port_t *m_pLeftInput; 00099 jack_port_t *m_pRightInput; 00100 00101 int m_sampRate; 00102 size_t m_blockSize; 00103 float *m_pLastInputCopy; 00104 float *m_pMsgBuffer; 00105 size_t m_bufSize; 00106 size_t m_frames; 00107 RecordBuffer **m_pRecordBuffers; 00108 int m_numBuffers; 00109 int m_curBuffer; 00110 int m_curReadBuffer; 00111 size_t m_availableFrames; 00112 MIPRawFloatAudioMessage *m_pMsg; 00113 bool m_gotLastInput; 00114 bool m_gotMsg; 00115 bool m_stopThread; 00116 MIPSignalWaiter m_sigWait, m_sigWait2; 00117 jthread::JMutex m_frameMutex, m_blockMutex, m_stopMutex; 00118 MIPTime m_interval, m_sampleInstant; 00119 }; 00120 00121 #endif // MIPCONFIG_SUPPORT_JACK 00122 00123 #endif // MIPJACKINPUT_H 00124