EMIPLIB

mipwinmminput.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 MIPWINMMINPUT_H
00030 
00031 #define MIPWINMMINPUT_H
00032 
00033 #include "mipconfig.h"
00034 
00035 #ifdef MIPCONFIG_SUPPORT_WINMM
00036 
00037 #include "mipcomponent.h"
00038 #include "miptime.h"
00039 #include "mipsignalwaiter.h"
00040 #include <jthread/jthread.h>
00041 #include <windows.h>
00042 #include <string>
00043 #ifndef _WIN32_WCE
00044         #include <mmsystem.h>
00045 #endif // _WIN32_WCE
00046 
00047 class MIPRaw16bitAudioMessage;
00048 
00056 class EMIPLIB_IMPORTEXPORT MIPWinMMInput : public MIPComponent, private jthread::JThread
00057 {
00058 public:
00059         MIPWinMMInput();
00060         ~MIPWinMMInput();
00061 
00075         bool open(int sampRate, int channels, MIPTime interval = MIPTime(0.020), 
00076                   MIPTime bufferTime = MIPTime(10.0), bool highPriority = false,
00077                   UINT deviceID = WAVE_MAPPER);
00078 
00082         bool close();
00083         bool push(const MIPComponentChain &chain, int64_t iteration, MIPMessage *pMsg);
00084         bool pull(const MIPComponentChain &chain, int64_t iteration, MIPMessage **pMsg);
00085 private:
00086         void *Thread();
00087         static void CALLBACK inputCallback(HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2);
00088 
00089         bool m_init;
00090         HWAVEIN m_device;
00091         int m_sampRate;
00092         int m_channels;
00093         uint16_t *m_pLastInputCopy;
00094         uint16_t *m_pMsgBuffer;
00095         MIPRaw16bitAudioMessage *m_pMsg;
00096         size_t m_bufSize,m_frames;
00097         bool m_gotLastInput;
00098         bool m_gotMsg;
00099         bool m_stopThread;
00100         WAVEHDR *m_inputBuffers;
00101         int m_numBuffers;
00102         MIPSignalWaiter m_sigWait,m_threadSigWait;
00103         jthread::JMutex m_frameMutex,m_stopMutex;
00104         MIPTime m_interval, m_sampleInstant;
00105         bool m_threadPrioritySet;
00106 
00107         std::string m_threadError;
00108 };
00109 
00110 #endif // MIPCONFIG_SUPPORT_WINMM
00111 
00112 #endif // MIPWINMMINPUT_H
00113