sipxmedialib  Version 3.3
MprEncode.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2008 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2008 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 
15 #ifndef _MprEncode_h_
16 #define _MprEncode_h_
17 
18 // SYSTEM INCLUDES
19 // APPLICATION INCLUDES
20 #include "mp/MpAudioResource.h"
21 #include "sdp/SdpCodec.h"
22 #include "mp/MpFlowGraphMsg.h"
23 #include "mp/MpResourceMsg.h"
24 #include "mp/MprToNet.h"
25 #include "mp/MpMisc.h"
26 #include "mp/MpResampler.h"
27 
28 // DEFINES
29 // MACROS
30 // EXTERNAL FUNCTIONS
31 // EXTERNAL VARIABLES
32 // CONSTANTS
33 // STRUCTS
34 // TYPEDEFS
35 // FORWARD DECLARATIONS
36 class MpEncoderBase;
37 
41 class MprEncode : public MpAudioResource
42 {
43 /* //////////////////////////// PUBLIC //////////////////////////////////// */
44 public:
45 
46  static const UtlContainableType TYPE;
47 
48 /* ============================ CREATORS ================================== */
50 
51 
52  // Constructor
53  MprEncode(const UtlString& rName);
54 
55  // Destructor
56  virtual
57  ~MprEncode();
58 
60 
61 /* ============================ MANIPULATORS ============================== */
63 
64 
66  static OsStatus selectCodecs(const UtlString& namedResource,
67  OsMsgQ& fgQ,
68  SdpCodec* pPrimaryCodec,
69  SdpCodec* pDtmfCodec);
70 
72  static OsStatus deselectCodecs(const UtlString& namedResource,
73  OsMsgQ& fgQ);
74 
76  void setMyToNet(MprToNet* myToNet);
82  static OsStatus startTone(const UtlString& namedResource,
84  OsMsgQ& fgQ,
85  int toneId);
86 
88  static OsStatus stopTone(const UtlString& namedResource,
89  OsMsgQ& fgQ);
90 
92  static OsStatus enableDtx(const UtlString& namedResource,
93  OsMsgQ& fgQ,
94  UtlBoolean dtx);
99  static OsStatus setMaxPacketTime(const UtlString& namedResource,
101  OsMsgQ& fgQ,
102  unsigned int maxPacketTime);
103 
105 
106 /* ============================ ACCESSORS ================================= */
108 
109 
111  UtlContainableType getContainableType() const;
112 
114 
115 /* ============================ INQUIRY =================================== */
117 
118 
120 
121 /* //////////////////////////// PROTECTED ///////////////////////////////// */
122 protected:
123 
124  virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[],
125  MpBufPtr outBufs[],
126  int inBufsSize,
127  int outBufsSize,
128  UtlBoolean isEnabled,
129  int samplesPerFrame,
130  int samplesPerSecond);
131 
132 /* //////////////////////////// PRIVATE /////////////////////////////////// */
133 private:
134 
135  typedef enum
136  {
143  } AddlResMsgTypes;
144 
145 
146  enum {
149  };
150 
152 
154 
156  unsigned char* mpPacket1Payload;
160  unsigned int mSamplesPacked;
162  unsigned int mStartTimestamp1;
164  UtlBoolean mActiveAudio1;
165  UtlBoolean mMarkNext1;
169  UtlBoolean mDoesVad1;
170  UtlBoolean mDisableDTX;
171  UtlBoolean mEnableG722Hack;
172  UtlBoolean mDoG722Hack;
177 
180 
182 
183  UtlBoolean mNeedResample;
185  unsigned int mResampleBufLen;
188 
190 
192 
194  unsigned char* mpPacket2Payload;
196  unsigned int mStartTimestamp2;
202  UtlBoolean mNewTone;
203 
204 
205 
207 
208  unsigned int mCurrentTimestamp;
209  unsigned int mMaxPacketTime;
210 
212 
214 
216  virtual UtlBoolean handleMessage(MpResourceMsg& rMsg);
217 
219  OsStatus allocPacketBuffer(const MpEncoderBase& rEncoder,
220  unsigned char*& rpPacketPayload,
221  int& rPacketPayloadBytes);
222 
223  void handleSelectCodecs(int newCodecsCount, SdpCodec** newCodecs);
224 
225  void handleDeselectCodecs(void);
226 
228  int lookupTone(int toneId);
229 
231  void handleStartTone(int toneId);
232 
234  void handleEnableDTX(UtlBoolean dtx);
235 
237  void handleSetMaxPacketTime(unsigned maxPacketTime);
238 
240  void handleStopTone(void);
241 
243  void doPrimaryCodec(MpAudioBufPtr in);
244 
247 
249  void notifyStartTx();
250 
252  void notifyStopTx();
253 
255  MprEncode(const MprEncode& rMprEncode);
256 
258  MprEncode& operator=(const MprEncode& rhs);
259 
260 };
261 
262 /* ============================ INLINE METHODS ============================ */
263 
264 #endif // _MprEncode_h_
static OsStatus stopTone(const UtlString &namedResource, OsMsgQ &fgQ)
Send "stop tone" DTMF RTP packet.
Definition: MprEncode.cpp:152
MpEncoderBase * mpPrimaryCodec
Definition: MprEncode.h:155
Message object used to communicate with the media processing task.
Definition: MpResourceMsg.h:30
unsigned int mLastDtmfSendTimestamp
Definition: MprEncode.h:197
MprToNet * mpToNet
Definition: MprEncode.h:211
unsigned char * mpPacket1Payload
Packet buffer for primary RTP stream.
Definition: MprEncode.h:156
MpResamplerBase * mpResampler
Definition: MprEncode.h:184
int samplesPerFrame
int mConsecutiveUnsentFrames1
Definition: MprEncode.h:168
void notifyStartTx()
Send notification about TX start.
Definition: MprEncode.cpp:814
UtlBoolean mNewTone
set when tone starts
Definition: MprEncode.h:202
MpAudioSample * mpResampleBuf
Definition: MprEncode.h:187
Generic audio resampler.
Definition: MpResampler.h:34
int mConsecutiveInactive1
Number of RTP packets with active voice data.
Definition: MprEncode.h:166
Definition: MpResourceMsg.h:56
MUST BE > 0.
Definition: MprEncode.h:147
unsigned int mCurrentTimestamp
Definition: MprEncode.h:208
void handleDeselectCodecs(void)
Definition: MprEncode.cpp:219
Definition: MprEncode.h:142
void handleStartTone(int toneId)
Handle message to send "begin tone" DTMF RTP packet.
Definition: MprEncode.cpp:364
int lookupTone(int toneId)
Translate our tone ID into RFC2833 values.
Definition: MprEncode.cpp:451
Base class for all media processing encoders.
Definition: MpEncoderBase.h:35
void handleStopTone(void)
Handle message to send "stop tone" DTMF RTP packet.
Definition: MprEncode.cpp:375
int mPayloadBytesUsed
Definition: MprEncode.h:159
static OsStatus deselectCodecs(const UtlString &namedResource, OsMsgQ &fgQ)
Free selected codecs.
Definition: MprEncode.cpp:133
static OsStatus enableDtx(const UtlString &namedResource, OsMsgQ &fgQ, UtlBoolean dtx)
Enable or disable internal DTX.
Definition: MprEncode.cpp:158
int samplesPerSecond
void notifyStopTx()
Send notification about TX stop.
Definition: MprEncode.cpp:829
void doDtmfCodec(int samplesPerFrame, int samplesPerSecond)
Encode and send DTMF tone.
Definition: MprEncode.cpp:692
unsigned int mResampleBufLen
Length of mpResampleBuf.
Definition: MprEncode.h:186
static const UtlContainableType TYPE
Class name, used for run-time checks.
Definition: MprEncode.h:46
MprEncode & operator=(const MprEncode &rhs)
Assignment operator (not implemented for this class)
UtlBoolean mNeedResample
Is resampling needed?
Definition: MprEncode.h:183
int16_t MpAudioSample
Definition: MpTypes.h:44
MprEncode(const UtlString &rName)
Definition: MprEncode.cpp:72
virtual UtlBoolean handleMessage(MpResourceMsg &rMsg)
Handle resource messages for this resource.
Definition: MprEncode.cpp:392
UtlContainableType getContainableType() const
Definition: MprEncode.cpp:178
AddlResMsgTypes
Definition: MprEncode.h:135
int mConsecutiveActive1
Definition: MprEncode.h:167
int mTotalTime
samples tone was active, set when tone stops
Definition: MprEncode.h:201
UtlBoolean mMarkNext1
Set Mark bit on next RTP packet.
Definition: MprEncode.h:165
int mNumToneStops
set to # of end packets to send when tone stops
Definition: MprEncode.h:200
Definition: MprEncode.h:137
int mDtmfSampleInterval
samples between AVT packets
Definition: MprEncode.h:198
UtlBoolean mEnableG722Hack
Definition: MprEncode.h:171
virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[], MpBufPtr outBufs[], int inBufsSize, int outBufsSize, UtlBoolean isEnabled, int samplesPerFrame, int samplesPerSecond)
This method does the real work for the media processing resource and must be defined in each class de...
Definition: MprEncode.cpp:777
Smart pointer to MpAudioBuf.
Definition: MpAudioBuf.h:168
Abstract base class for all audio processing objects.
Definition: MpAudioResource.h:38
void doPrimaryCodec(MpAudioBufPtr in)
Encode audio buffer and send it.
Definition: MprEncode.cpp:496
virtual ~MprEncode()
Definition: MprEncode.cpp:111
static OsStatus setMaxPacketTime(const UtlString &namedResource, OsMsgQ &fgQ, unsigned int maxPacketTime)
Set maximum duration of one packet in milliseconds.
Definition: MprEncode.cpp:168
int mMaxPacketSamples
Maximum number of samples in RTP packet.
Definition: MprEncode.h:157
Definition: MprEncode.h:141
Definition: MprEncode.h:140
unsigned int mSamplesPacked
Definition: MprEncode.h:161
UtlBoolean mActiveAudio1
Does current RTP packet contain active voice?
Definition: MprEncode.h:164
int mPacket2PayloadBytes
4
Definition: MprEncode.h:195
At 20 ms each, 500 ms.
Definition: MprEncode.h:148
int mPacket1PayloadBytes
Size of mpPacket1Payload buffer.
Definition: MprEncode.h:158
MpEncoderBase * mpDtmfCodec
Definition: MprEncode.h:193
Definition: MprEncode.h:138
The "Encode" media processing resource.
Definition: MprEncode.h:41
void handleEnableDTX(UtlBoolean dtx)
Handle message to enable or disable internal DTX.
Definition: MprEncode.cpp:382
UtlBoolean mDoesVad1
Does codec its own VAD?
Definition: MprEncode.h:169
Smart pointer to MpBuf.
Definition: MpBuf.h:160
The RTP writer.
Definition: MprToNet.h:48
void setMyToNet(MprToNet *myToNet)
Set ToNet resource which will send generated RTP packets.
Definition: MprEncode.cpp:139
int mCurrentTone
AVT event code for current tone.
Definition: MprEncode.h:199
unsigned int mMaxPacketTime
Maximum duration of one packet in milliseconds.
Definition: MprEncode.h:209
static OsStatus startTone(const UtlString &namedResource, OsMsgQ &fgQ, int toneId)
Send "begin tone" DTMF RTP packet.
Definition: MprEncode.cpp:144
static OsStatus selectCodecs(const UtlString &namedResource, OsMsgQ &fgQ, SdpCodec *pPrimaryCodec, SdpCodec *pDtmfCodec)
Tell encoder which codecs to use.
Definition: MprEncode.cpp:123
UtlBoolean mDisableDTX
Disable internal DTX.
Definition: MprEncode.h:170
void handleSelectCodecs(int newCodecsCount, SdpCodec **newCodecs)
Definition: MprEncode.cpp:256
unsigned char * mpPacket2Payload
packet buffer for DTMF event RTP stream
Definition: MprEncode.h:194
OsStatus allocPacketBuffer(const MpEncoderBase &rEncoder, unsigned char *&rpPacketPayload, int &rPacketPayloadBytes)
Allocate memory for RTP packet.
Definition: MprEncode.cpp:191
void handleSetMaxPacketTime(unsigned maxPacketTime)
Handle message to set maximum duration of one packet.
Definition: MprEncode.cpp:387
Definition: MprEncode.h:139
UtlBoolean mDoG722Hack
Definition: MprEncode.h:176
unsigned int mStartTimestamp1
Timestamp of packets being encoded.
Definition: MprEncode.h:163
static const int RTP_KEEP_ALIVE_FRAME_INTERVAL
Definition: MprEncode.h:151
UtlBoolean isEnabled() const
Returns TRUE is this resource is currently enabled, FALSE otherwise.
Definition: MpResource.cpp:440
unsigned int mStartTimestamp2
sample time when tone starts
Definition: MprEncode.h:196