EMIPLIB

mippainputoutput.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 MIPPAINPUTOUTPUT_H
00030 
00031 #define MIPPAINPUTOUTPUT_H
00032 
00033 #include "mipconfig.h"
00034 
00035 #ifdef MIPCONFIG_SUPPORT_PORTAUDIO
00036 
00037 #include "mipcomponent.h"
00038 #include "miptime.h"
00039 #include "mipsignalwaiter.h"
00040 #include <portaudio.h>
00041 #include <jthread/jthread.h>
00042 #include <string>
00043 
00044 class MIPRaw16bitAudioMessage;
00045 class MIPStreamBuffer;
00046 
00055 class EMIPLIB_IMPORTEXPORT MIPPAInputOutput : public MIPComponent
00056 {
00057 public:
00064         enum AccessMode { ReadOnly, WriteOnly, ReadWrite };
00065         
00066         MIPPAInputOutput();
00067         ~MIPPAInputOutput();
00068         
00077         bool open(int sampRate, int channels, MIPTime interval, AccessMode accessMode = WriteOnly, 
00078                   MIPTime bufferTime = MIPTime(10.0));
00079         
00081         bool close();
00082 
00086         static bool initializePortAudio(std::string &errorString);
00087         
00089         static void terminatePortAudio();
00090         
00091         bool push(const MIPComponentChain &chain, int64_t iteration, MIPMessage *pMsg);
00092         bool pull(const MIPComponentChain &chain, int64_t iteration, MIPMessage **pMsg);
00093 private:
00094         static int staticPACallback(const void *pInput, void *pOutput, unsigned long frameCount, const PaStreamCallbackTimeInfo *pTimeInfo, PaStreamCallbackFlags statusFlags, void *pUserData);
00095         int portAudioCallback(const void *pInput, void *pOutput, unsigned long frameCount, const PaStreamCallbackTimeInfo *pTimeInfo, PaStreamCallbackFlags statusFlags);
00096         
00097         PaStream *m_pStream;
00098         int m_sampRate;
00099         int m_channels;
00100         AccessMode m_accessMode;
00101         size_t m_blockFrames, m_blockBytes;
00102         MIPStreamBuffer *m_pOutputBuffer, *m_pInputBuffer;
00103 
00104         bool m_gotMsg;
00105         MIPSignalWaiter m_sigWait;
00106         MIPRaw16bitAudioMessage *m_pMsg;
00107         uint16_t *m_pMsgBuffer;
00108         bool m_gotLastInput;
00109 };
00110 
00111 #endif // MIPCONFIG_SUPPORT_PORTAUDIO
00112 
00113 #endif // MIPPAINPUTOUTPUT_H
00114