sipxmedialib  Version 3.3
MprDecode.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2014 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2008 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 
13 #ifndef _MprDecode_h_ /* [ */
14 #define _MprDecode_h_
15 
16 // SYSTEM INCLUDES
17 // APPLICATION INCLUDES
18 #include "mp/MpMisc.h"
19 #include "mp/MpRtpBuf.h"
20 #include "mp/MpAudioResource.h"
21 #include "mp/MpFlowGraphMsg.h"
22 #include "mp/MpResourceMsg.h"
23 #include "mp/MpDecoderPayloadMap.h"
25 #include "sdp/SdpCodec.h"
26 #include "os/OsBSem.h"
27 
28 // DEFINES
29 // MACROS
30 // EXTERNAL FUNCTIONS
31 // EXTERNAL VARIABLES
32 // CONSTANTS
33 // STRUCTS
34 // TYPEDEFS
35 
36 // FORWARD DECLARATIONS
37 class UtlSerialized;
38 class MpDecoderBase;
39 class MprRecorder;
40 class MpJitterBuffer;
41 class MprDejitter;
42 class MpPlcBase;
43 
45 class MprDecode : public MpAudioResource
46 {
47 /* //////////////////////////// PUBLIC //////////////////////////////////// */
48 public:
49 
50  typedef enum
51  {
57 
58  static const UtlContainableType TYPE;
59 
60 /* ============================ CREATORS ================================== */
62 
63 
65  MprDecode(const UtlString &rName,
66  const UtlString &plcName = "");
67 
69  virtual
70  ~MprDecode();
71 
73 
74 /* ============================ MANIPULATORS ============================== */
76 
77 
79  static OsStatus reset(const UtlString& namedResource, OsMsgQ& fgQ);
80 
82  virtual void reset();
83 
85  static OsStatus selectCodecs(const UtlString& namedResource,
86  OsMsgQ& fgQ,
87  SdpCodec* codecs[],
88  int numCodecs);
89 
91  static OsStatus deselectCodecs(const UtlString& namedResource,
92  OsMsgQ& fgQ);
93 
95  static OsStatus setPlc(const UtlString& namedResource,
96  OsMsgQ& fgQ,
97  const UtlString& plcName = "");
112  void setMyDejitter(MprDejitter* newDJ, UtlBoolean ownDj);
119  virtual OsStatus pushBuffer(int inputPort, MpBufPtr& inputBuffer);
121 
123  OsStatus pushPacket(MpRtpBufPtr &pRtp);
133  void setConnectionId(MpConnectionID connectionId);
135 
137  void setStreamId(int connectionId);
138 
140 
141 /* ============================ ACCESSORS ================================= */
143 
144 
146  UtlContainableType getContainableType() const;
147 
149  virtual OsStatus getCurrentLatency(int &latency, int input=0, int output=0) const;
150 
152 
153 /* ============================ INQUIRY =================================== */
155 
156 
158 
159 /* //////////////////////////// PROTECTED ///////////////////////////////// */
160 protected:
161 
162 /* //////////////////////////// PRIVATE /////////////////////////////////// */
163 private:
164 
166  UtlBoolean mIsJBInitialized;
167 
169  UtlBoolean mOwnDJ;
170  UtlBoolean mIsStreamInitialized;
171  struct StreamState
172  {
173  unsigned sampleRate;
174  UtlBoolean isFirstRtpPulled;
177  int32_t rtpStreamHint;
179  unsigned playbackFrameSize;
180  uint8_t rtpPayloadType;
181  uint32_t dejitterLength;
182  } mStreamState;
184 
186 
188 
190 
196  UtlBoolean mEnableG722Hack;
202 
206 
210 
212 
213  virtual UtlBoolean doProcessFrame(MpBufPtr inBufs[],
214  MpBufPtr outBufs[],
215  int inBufsSize,
216  int outBufsSize,
217  UtlBoolean isEnabled,
218  int samplesPerFrame,
219  int samplesPerSecond);
220 
222  UtlBoolean tryDecodeAsSignalling(const MpRtpBufPtr &rtp);
228  OsStatus setFlowGraph(MpFlowGraphBase* pFlowGraph);
230 
232  virtual UtlBoolean handleMessage(MpResourceMsg& rMsg);
233 
235  UtlBoolean handleSelectCodecs(SdpCodec* pCodecs[], int numCodecs);
240  UtlBoolean handleDeselectCodecs(UtlBoolean shouldLock = TRUE);
243 
245  UtlBoolean handleDeselectCodec(MpDecoderBase* pDecoder);
250  UtlBoolean handleSetPlc(const UtlString &plcName);
252 
254  UtlBoolean handleReset();
255 
257  UtlBoolean handleDisable();
258 
260  UtlBoolean handleSetVadParam(UtlSerialized& serialData);
261 
263  void deletePriorCodecs();
264 
266  MprDecode(const MprDecode& rMprDecode);
267 
269  MprDecode& operator=(const MprDecode& rhs);
270 
271 };
272 
273 /* ============================ INLINE METHODS ============================ */
274 
275 #endif /* _MprDecode_h_ ] */
RtpSeq mLastPulledSeq
Sequence number of last pulled packet.
Definition: MprDecode.h:185
UtlBoolean handleDisable()
perform the disable operation on the resource
Definition: MprDecode.cpp:1011
Message object used to communicate with the media processing task.
Definition: MpResourceMsg.h:30
int32_t rtpStreamHint
Recommended playback position (in RTP timestamp units).
Definition: MprDecode.h:177
virtual OsStatus pushBuffer(int inputPort, MpBufPtr &inputBuffer)
MpResource::pushBuffer
Definition: MprDecode.cpp:231
RtpTimestamp rtpStreamPosition
Current pulling JB position (in RTP timestamp units).
Definition: MprDecode.h:176
Definition: MpPlcBase.h:40
MpDecoderBase ** mpPrevCodecs
Similar list of all codecs that have ever been listed on mpCurrentCodecs.
Definition: MprDecode.h:208
MpJitterBufferEstimation * mpJbEstimationState
State of JB delay estimation.
Definition: MprDecode.h:187
unsigned sampleRate
Sample rate of this stream.
Definition: MprDecode.h:173
int samplesPerFrame
UtlBoolean handleReset()
Handle MPRM_RESET message.
Definition: MprDecode.cpp:985
RtpSeq rtpStreamSeq
Current sequence number of RTP stream.
Definition: MprDecode.h:175
Definition: MpResourceMsg.h:56
Base class for all media processing decoders.
Definition: MpDecoderBase.h:37
virtual ~MprDecode()
Destructor.
Definition: MprDecode.cpp:109
UtlBoolean mIsStreamInitialized
Have we received at least one packet?
Definition: MprDecode.h:170
Definition: MprDecode.h:54
UtlBoolean handleSelectCodecs(SdpCodec *pCodecs[], int numCodecs)
Replace mpCurrentCodecs with pCodecs.
Definition: MprDecode.cpp:746
UtlBoolean mOwnDJ
Is dejitter owned by this decoder?
Definition: MprDecode.h:169
int mG722HackPayloadType
Definition: MprDecode.h:201
UtlBoolean handleDeselectCodecs(UtlBoolean shouldLock=TRUE)
Remove all codecs from mpCurrentCodecs, transferring them to mpPrevCodecs.
Definition: MprDecode.cpp:910
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
virtual OsStatus getCurrentLatency(int &latency, int input=0, int output=0) const
Get current input to output latency (in samples)
Definition: MprDecode.cpp:372
MpDecoderBase ** mpCurrentCodecs
List of the codecs to be used to decode media.
Definition: MprDecode.h:194
void setConnectionId(MpConnectionID connectionId)
Set the ID of a connection this resource belongs to.
Definition: MprDecode.cpp:347
Smart pointer to MpRtpBuf.
Definition: MpRtpBuf.h:348
static const UtlContainableType TYPE
Class name, used for run-time checks.
Definition: MprDecode.h:58
int samplesPerSecond
static OsStatus deselectCodecs(const UtlString &namedResource, OsMsgQ &fgQ)
Clear set of codecs this resource is able to decode.
Definition: MprDecode.cpp:205
unsigned playbackFrameSize
Stream frame size of this stream (in RTP timestamp units).
Definition: MprDecode.h:179
uint32_t dejitterLength
Definition: MprDecode.h:181
MpDecoderPayloadMap mDecoderMap
Mapping of payload types to decoder instances.
Definition: MprDecode.h:211
virtual UtlBoolean handleMessage(MpResourceMsg &rMsg)
Handle new style messages for this resource.
Definition: MprDecode.cpp:705
UtlContainableType getContainableType() const
Definition: MprDecode.cpp:367
uint8_t rtpPayloadType
Current RTP payload type.
Definition: MprDecode.h:180
AddlResMsgTypes
Definition: MprDecode.h:50
UtlBoolean handleDeselectCodec(MpDecoderBase *pDecoder)
Remove one codec from mpConnection's payload type decoder table.
Definition: MprDecode.cpp:893
uint32_t RtpTimestamp
RTP timestamp.
Definition: MpTypes.h:60
Class for decoding of incoming RTP, resampling it to target sample rate and slicing to frames of targ...
Definition: MpJitterBuffer.h:45
uint32_t playbackStreamPosition
Current playback position (in RTP timestamp units).
Definition: MprDecode.h:178
MprDejitter * mpMyDJ
Dejitter instance, used by this decoder.
Definition: MprDecode.h:168
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: MprDecode.cpp:404
int mNumCurrentCodecs
Length of mpCurrentCodecs array.
Definition: MprDecode.h:195
virtual void reset()
Reset decoder to the initial state to be able process new stream.
Definition: MprDecode.cpp:191
int mNumPrevCodecs
Length of mpPrevCodecs array.
Definition: MprDecode.h:209
void deletePriorCodecs()
Delete the array of previously used codecs.
Definition: MprDecode.cpp:161
Abstract base class for all audio processing objects.
Definition: MpAudioResource.h:38
UtlBoolean mEnableG722Hack
Definition: MprDecode.h:196
void setMyDejitter(MprDejitter *newDJ, UtlBoolean ownDj)
Pair this decode resource with the dejitter resource.
Definition: MprDecode.cpp:221
The "Recorder" media processing resource.
Definition: MprRecorder.h:53
The "Decode" media processing resource.
Definition: MprDecode.h:45
uint16_t RtpSeq
RTP sequence number.
Definition: MpTypes.h:59
UtlBoolean mIsJBInitialized
Is JB initialized or not?
Definition: MprDecode.h:166
UtlBoolean handleSetPlc(const UtlString &plcName)
Change PLC algorithm to one provided.
Definition: MprDecode.cpp:904
Helper class for MprDecode - it maps payload types to decoder instances.
Definition: MpDecoderPayloadMap.h:27
static OsStatus setPlc(const UtlString &namedResource, OsMsgQ &fgQ, const UtlString &plcName="")
Change PLC algorithm to one with given name. THIS METHOD DOES NOT WORK!
Definition: MprDecode.cpp:212
struct MprDecode::StreamState mStreamState
static OsStatus selectCodecs(const UtlString &namedResource, OsMsgQ &fgQ, SdpCodec *codecs[], int numCodecs)
Provide set of codecs this decode resource will be able to decode.
Definition: MprDecode.cpp:196
Smart pointer to MpBuf.
Definition: MpBuf.h:160
OsStatus setFlowGraph(MpFlowGraphBase *pFlowGraph)
Associates this resource with the indicated flow graph.
Definition: MprDecode.cpp:682
void setStreamId(int connectionId)
Set the ID of a stream inside of the connection this resource belongs to.
Definition: MprDecode.cpp:356
UtlBoolean tryDecodeAsSignalling(const MpRtpBufPtr &rtp)
Decode RTP packet if it belongs to signaling codec.
Definition: MprDecode.cpp:634
MprDecode & operator=(const MprDecode &rhs)
Assignment operator (not implemented for this class)
Definition: MprDecode.h:53
int MpConnectionID
Flowgraph connection ID.
Definition: MpTypes.h:56
UtlBoolean handleSetVadParam(UtlSerialized &serialData)
Handle message to set VAD parameter.
Definition: MprDecode.cpp:1021
Definition: MprDecode.h:55
UtlBoolean isFirstRtpPulled
Have we got first packet from JB queue?
Definition: MprDecode.h:174
Abstract base class for Jitter Buffer Estimation (JBE) algorithms.
Definition: MpJitterBufferEstimation.h:35
OsStatus pushPacket(MpRtpBufPtr &pRtp)
Add incoming RTP packet to the decoding queue.
Definition: MprDecode.cpp:247
The "Dejitter" utility class.
Definition: MprDejitter.h:39
MprDecode(const UtlString &rName, const UtlString &plcName="")
Constructor.
Definition: MprDecode.cpp:88
#define TRUE
Definition: PlgDefsV1.h:41
Definition: MprDecode.h:52
UtlBoolean isEnabled() const
Returns TRUE is this resource is currently enabled, FALSE otherwise.
Definition: MpResource.cpp:440
MpJitterBuffer * mpJB
Pointer to JitterBuffer instance.
Definition: MprDecode.h:165
Definition: MprDecode.h:171