sipxmedialib  Version 3.3
MpOss.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2007 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // $$
10 
11 // Author: Sergey Kostanbaev <Sergey DOT Kostanbaev AT sipez DOT com>
12 
13 #ifndef _MpOss_h_
14 #define _MpOss_h_
15 
16 // SYSTEM INCLUDES
17 #include <pthread.h>
18 #include <semaphore.h>
19 
20 #include <sys/types.h>
21 #include <sys/soundcard.h>
22 
23 // APPLICATION INCLUDES
24 #include "mp/MpInputDeviceDriver.h"
26 #include "mp/MpOssContainer.h"
27 #include "utl/UtlVoidPtr.h"
28 
29 class MpidOss;
30 class MpodOss;
31 
35 class MpOss : public UtlVoidPtr
36 {
37  friend class MpidOss;
38  friend class MpodOss;
39  /* //////////////////////////// PUBLIC //////////////////////////////////// */
40 public:
41 
42  /* ============================ CREATORS ================================== */
44 
45 
47  MpOss();
48 
50  ~MpOss();
51 
53 
54  /* ============================ MANIPULATORS ============================== */
56 
57 
59  OsStatus setInputDevice(MpidOss* pIDD);
61  OsStatus setOutputDevice(MpodOss* pODD);
62 
64  OsStatus freeInputDevice();
66  OsStatus freeOutputDevice();
67 
69  OsStatus attachReader();
71  OsStatus attachWriter();
72 
74  OsStatus detachReader();
76  OsStatus detachWriter();
77 
79 
80  /* ============================ ACCESSORS ================================= */
82 
83 
84 
86 
87  /* ============================ INQUIRY =================================== */
89 
90 
92  inline UtlBoolean isDeviceValid();
93 
95  inline UtlBoolean isReaderAttached();
96 
98  inline UtlBoolean isWriterAttached();
99  inline UtlBoolean isDevCapBatch();
100  inline UtlBoolean isDevCapDuplex();
101  inline UtlBoolean isDevCapMmap();
102  inline UtlBoolean isDevCapTrigger();
103 
105  inline UtlBoolean isNotUsed();
106 
108 
109  /* //////////////////////////// PROTECTED ///////////////////////////////// */
110 protected:
111  int mfdDevice;
112  UtlBoolean mbReadCap;
113  UtlBoolean mbWriteCap;
114 
117 
119 
120  volatile UtlBoolean mStReader;
121  volatile UtlBoolean mStWriter;
122  volatile UtlBoolean mStShutdown;
123  volatile UtlBoolean mModeChanged;
124 
127 
129  UtlBoolean mStereoOps;
130 
131  pthread_t mIoThread;
132  sem_t mSleepSem;
133  sem_t mSignalSem;
134 
136  OsStatus initDevice(const char* devname);
138  OsStatus initDeviceFinal(unsigned samplesPerSec, unsigned samplerPerFrame);
140  OsStatus freeDevice();
141 
144  OsStatus setSampleRate(unsigned samplesPerSec, unsigned samplerPerFrame);
145 
147  OsStatus doInput(char* buffer, int size);
149  OsStatus doOutput(const char* buffer, int size);
150 
152  OsStatus doInputRs(MpAudioSample* buffer, unsigned size);
154  OsStatus doOutputRs(const MpAudioSample* buffer, unsigned size);
155 
157  void noMoreNeeded();
158 
160  void soundIoThread();
161 
162  /* //////////////////////////// PRIVATE /////////////////////////////////// */
163 private:
164 
165  void threadIoStatusChanged();
166  void threadWakeUp();
167  void threadKill();
168 
169  UtlBoolean ossSetTrigger(bool turnOn);
170  UtlBoolean ossReset();
171 
173  static void* soundCardIoWrapper(void* arg);
174 };
175 
176 /* ============================ INLINE METHODS ============================ */
177 
179 {
180  return (mfdDevice != -1);
181 }
182 
184 {
185  return (mReader != NULL);
186 }
187 
189 {
190  return (mWriter != NULL);
191 }
192 
194 {
195  return (mDeviceCap & DSP_CAP_BATCH);
196 }
197 
199 {
200  return (mDeviceCap & DSP_CAP_DUPLEX);
201 }
202 
204 {
205  return (mDeviceCap & DSP_CAP_MMAP);
206 }
207 
209 {
210  return (mDeviceCap & DSP_CAP_TRIGGER);
211 }
212 
213 UtlBoolean MpOss::isNotUsed()
214 {
215  return ((mReader == NULL) && (mWriter == NULL));
216 }
217 
218 
219 #endif // _MpOss_h_
220 
~MpOss()
Destructor.
OsStatus setInputDevice(MpidOss *pIDD)
Connect MpidOss class driver.
volatile UtlBoolean mStWriter
Output device is enabled.
Definition: MpOss.h:121
OsStatus attachReader()
Enable input device.
UtlBoolean isWriterAttached()
Inquire if the output device is connected.
Definition: MpOss.h:188
UtlBoolean ossSetTrigger(bool turnOn)
OsStatus freeDevice()
Free OSS device.
void noMoreNeeded()
Deinitialization and freeing sequences.
OsStatus initDeviceFinal(unsigned samplesPerSec, unsigned samplerPerFrame)
Final initializations for OSS device.
sem_t mSleepSem
Control IO thread sleeping.
Definition: MpOss.h:132
Container for device specific input OSS driver.
Definition: MpidOss.h:38
UtlBoolean isDevCapMmap()
Definition: MpOss.h:203
OsStatus detachReader()
Disable input device.
sem_t mSignalSem
Use for parameters synchronization.
Definition: MpOss.h:133
int mfdDevice
The fd of the POSIX device (e.g. /dev/dsp)
Definition: MpOss.h:111
Container for device specific input OSS driver.
Definition: MpodOss.h:41
int mDeviceCap
Device capabilities.
Definition: MpOss.h:118
OsStatus detachWriter()
Disable output device.
MpodOss * mWriter
Output driver.
Definition: MpOss.h:116
OsStatus setOutputDevice(MpodOss *pODD)
Connect MpodOss class driver.
OsStatus doOutput(const char *buffer, int size)
Perform output operation of OSS device.
int16_t MpAudioSample
Definition: MpTypes.h:44
UtlBoolean mbWriteCap
Device is able to capture audio.
Definition: MpOss.h:113
UtlBoolean isDevCapTrigger()
Definition: MpOss.h:208
unsigned mUsedSamplesPerSec
Used samples rate either for IO.
Definition: MpOss.h:125
void soundIoThread()
Thread subroutine.
OsStatus freeInputDevice()
Disconnect Input driver.
OsStatus freeOutputDevice()
Disconnect Output driver.
OsStatus doOutputRs(const MpAudioSample *buffer, unsigned size)
Perform output operation of OSS device with siutable resampler.
UtlBoolean isDevCapBatch()
Definition: MpOss.h:193
OsStatus setSampleRate(unsigned samplesPerSec, unsigned samplerPerFrame)
Because OSS device works in duplex mode we must ensure that input and output driver use one sample ra...
UtlBoolean isDevCapDuplex()
Definition: MpOss.h:198
MpAudioSample * mResamplerBuffer
Buffer for conversions.
Definition: MpOss.h:128
UtlBoolean isNotUsed()
Inquire if OSS device is free, i.e. neither input nor output is connected.
Definition: MpOss.h:213
pthread_t mIoThread
Internal IO thread.
Definition: MpOss.h:131
UtlBoolean isReaderAttached()
Inquire if the input device is connected.
Definition: MpOss.h:183
UtlBoolean isDeviceValid()
Inquire if the device is valid.
Definition: MpOss.h:178
MpidOss * mReader
Input driver.
Definition: MpOss.h:115
unsigned mUsedSamplesPerFrame
Used frame size for IO.
Definition: MpOss.h:126
void threadIoStatusChanged()
UtlBoolean mbReadCap
Device is able to play audio.
Definition: MpOss.h:112
OsStatus doInput(char *buffer, int size)
Perform input operation of OSS device.
UtlBoolean mStereoOps
Use stereo output.
Definition: MpOss.h:129
volatile UtlBoolean mStShutdown
Thread exit flag.
Definition: MpOss.h:122
OsStatus attachWriter()
Enable output device.
UtlBoolean ossReset()
volatile UtlBoolean mModeChanged
IO settings has changed.
Definition: MpOss.h:123
volatile UtlBoolean mStReader
Input device is enabled.
Definition: MpOss.h:120
OsStatus doInputRs(MpAudioSample *buffer, unsigned size)
Perform input operation of OSS device with siutable resampler.
OsStatus initDevice(const char *devname)
Pre initializations for OSS device.
static void * soundCardIoWrapper(void *arg)
Thread subroutine.
Wrapper for OSS device that use file descriptor to communicate.
Definition: MpOss.h:35
void threadKill()
void threadWakeUp()
MpOss()
Constructor.