EMIPLIB

mipaudiorecorderinput.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 MIPAUDIORECORDERINPUT_H
00030 
00031 #define MIPAUDIORECORDERINPUT_H
00032 
00033 #include "mipconfig.h"
00034 
00035 #ifdef MIPCONFIG_SUPPORT_AUDIORECORDER
00036 
00037 #include "mipcomponent.h"
00038 #include "miptime.h"
00039 #include "mipsignalwaiter.h"
00040 #include <jthread/jthread.h>
00041 #include <string>
00042 
00043 class MIPRaw16bitAudioMessage;
00044 
00045 namespace android
00046 {
00047         class AudioRecord;
00048 }
00049 
00056 class EMIPLIB_IMPORTEXPORT MIPAudioRecorderInput : public MIPComponent, public jthread::JThread
00057 {
00058 public:
00059         MIPAudioRecorderInput();
00060         ~MIPAudioRecorderInput();
00061 
00070         bool open(int sampRate, int channels, MIPTime interval = MIPTime(0.020), MIPTime arrayTime = MIPTime(10.0));
00071 
00073         bool close();
00074 
00075         bool push(const MIPComponentChain &chain, int64_t iteration, MIPMessage *pMsg);
00076         bool pull(const MIPComponentChain &chain, int64_t iteration, MIPMessage **pMsg);
00077 private:
00078         static void StaticAudioRecorderCallback(int event, void *pUser, void *pInfo);
00079         void AudioRecorderCallback(void *pInfo);
00080         void *Thread();
00081         
00082         class RecordBuffer
00083         {
00084         public:
00085                 RecordBuffer(size_t bufSize)                                            { m_pBuffer = new uint16_t[bufSize]; }
00086                 ~RecordBuffer()                                                         { delete [] m_pBuffer; }
00087                 uint16_t *getBuffer()                                                   { return m_pBuffer; }
00088                 void setOffset(size_t o)                                                { m_offset = o; }
00089                 size_t getOffset() const                                                { return m_offset; }
00090         private:
00091                 uint16_t *m_pBuffer;
00092                 size_t m_offset;
00093         };
00094         
00095         android::AudioRecord *m_pRecorder;
00096 
00097         int m_sampRate, m_channels;
00098         size_t m_blockSize, m_blockFrames;
00099         uint16_t *m_pLastInputCopy;
00100         uint16_t *m_pMsgBuffer;
00101         size_t m_bufSize;
00102         size_t m_frames;
00103         RecordBuffer **m_pRecordBuffers;
00104         int m_numBuffers;
00105         int m_curBuffer;
00106         int m_curReadBuffer;
00107         size_t m_availableFrames;
00108         MIPRaw16bitAudioMessage *m_pMsg;
00109         bool m_gotLastInput;
00110         bool m_gotMsg;
00111         bool m_stopThread;
00112         MIPSignalWaiter m_sigWait, m_sigWait2;
00113         jthread::JMutex m_frameMutex, m_blockMutex, m_stopMutex;
00114         MIPTime m_interval, m_sampleInstant;
00115 };
00116 
00117 #endif // MIPCONFIG_SUPPORT_AUDIORECORDER
00118 
00119 #endif // MIPAUDIORECORDERINPUT_H
00120