sipxmedialib  Version 3.3
MpJitterBuffer.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 
14 #ifndef _MpJitterBuffer_h_
15 #define _MpJitterBuffer_h_
16 
17 // SYSTEM INCLUDES
18 
19 // APPLICATION INCLUDES
20 #include "mp/MpRtpBuf.h"
21 #include "mp/MpAudioBuf.h"
22 #include "mp/MpResampler.h"
23 
24 // DEFINES
25 // MACROS
26 // EXTERNAL FUNCTIONS
27 // EXTERNAL VARIABLES
28 // CONSTANTS
29 // STRUCTS
30 // TYPEDEFS
31 // FORWARD DECLARATIONS
33 class MpPlcBase;
34 class MpVadBase;
35 class MpAgcBase;
36 class MpFlowGraphBase;
37 
46 {
47 /* //////////////////////////// PUBLIC //////////////////////////////////// */
48 public:
49 
50 /* ============================ CREATORS ================================== */
52 
53 
55  MpJitterBuffer(MpDecoderPayloadMap *pPayloadMap = NULL,
56  const UtlString& resourceName = "unknown");
64  void init(unsigned int samplesPerSec, unsigned int samplesPerFrame);
72 
74 
75 /* ============================ MANIPULATORS ============================== */
77 
78 
80  void reset();
81 
83  OsStatus pushPacket(const MpRtpBufPtr &rtpPacket,
84  int minBufferSamples,
85  int wantedBufferSamples,
86  int &decodedSamples,
87  int &adjustment,
88  UtlBoolean &played);
118  void getFrame(MpAudioBufPtr &pFrame, int &numOriginalSamples);
128  void setCodecList(MpDecoderPayloadMap *pPayloadMap);
130 
132  void setPlc(const UtlString &plcName);
133 
134 
136 
137 /* ============================ ACCESSORS ================================= */
139 
140 
142  void setFlowGraph(MpFlowGraphBase* pFlowgraph);
143 
145  inline
146  int getSamplesNum() const;
147 
149  OsStatus setVadParam(const UtlString& name, int value);
150 
152 
153 /* ============================ INQUIRY =================================== */
155 
156 
158 
159 /* //////////////////////////// PROTECTED ///////////////////////////////// */
160 protected:
161 
163  int adjustStream(MpAudioSample *pBuffer, int bufferSize, unsigned numSamples,
164  int wantedAdjustment);
165 
166  OsStatus sliceToFrames(int decodedSamples, int codecSampleRate,
167  const MpSpeechParams &speechParams);
168 
169 /* //////////////////////////// PRIVATE /////////////////////////////////// */
170 private:
171 
172  enum {
174  DECODED_DATA_MAX_LENGTH = 10 * 160
176  };
177 
179 
182  int mSamplesPerFrame;
189 
191 
193 
194  unsigned mCurFrameNum;
195  unsigned mRemainingSamplesNum;
201 
203 
205 
206  UtlBoolean mIsFirstPacket;
211  unsigned mSamplesPerPacket;
214 
215 
216  UtlString mPlcName;
221 
223  MpJitterBuffer(const MpJitterBuffer& rMpJitterBuffer);
224 
227 };
228 
229 /* ============================ INLINE METHODS ============================ */
230 
232 {
233  return mRemainingSamplesNum;
234 }
235 
236 #endif // _MpJitterBuffer_h_
void init(unsigned int samplesPerSec, unsigned int samplesPerFrame)
Initialize with given sample rate and frame size.
Definition: MpJitterBuffer.cpp:95
UtlBoolean mIsFirstPacket
Have we received our first packet or not.
Definition: MpJitterBuffer.h:206
MpDecoderPayloadMap * mpPayloadMap
Definition: MpJitterBuffer.h:210
Definition: MpPlcBase.h:40
int getSamplesNum() const
Get number of samples, remaining in buffer.
Definition: MpJitterBuffer.h:231
int samplesPerFrame
Definition: MpVadBase.h:40
Definition: MpTypes.h:74
MpJitterBuffer & operator=(const MpJitterBuffer &rhs)
Assignment operator.
Generic audio resampler.
Definition: MpResampler.h:34
MpAudioSample mDecodedData[DECODED_DATA_MAX_LENGTH]
temporarily store decoded data.
Definition: MpJitterBuffer.h:186
uint8_t mStreamRtpPayload
Payload type of last received RTP packet.
Definition: MpJitterBuffer.h:209
int adjustStream(MpAudioSample *pBuffer, int bufferSize, unsigned numSamples, int wantedAdjustment)
Reduce or extend audio fragment.
Definition: MpJitterBuffer.cpp:594
~MpJitterBuffer()
Destructor.
Definition: MpJitterBuffer.cpp:105
OsStatus setVadParam(const UtlString &name, int value)
Set parameter on the VAD component.
Definition: MpJitterBuffer.cpp:515
UtlString mPlcName
Packet Loss Concealer algorithm name.
Definition: MpJitterBuffer.h:216
MpAudioBufPtr mFrames[FRAMES_TO_STORE]
Buffer for decoded, resampled and sliced audio.
Definition: MpJitterBuffer.h:199
Base class for AGC algorithm.
Definition: MpAgcBase.h:35
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
RtpTimestamp mStreamTimestamp
Timestamp of last played RTP packet.
Definition: MpJitterBuffer.h:208
Definition: MpJitterBuffer.h:173
Smart pointer to MpRtpBuf.
Definition: MpRtpBuf.h:348
MpAgcBase * mpAgc
Automatic Gain Calculator instance.
Definition: MpJitterBuffer.h:219
int mOutputSampleRate
Definition: MpJitterBuffer.h:181
int16_t MpAudioSample
Definition: MpTypes.h:44
OsStatus pushPacket(const MpRtpBufPtr &rtpPacket, int minBufferSamples, int wantedBufferSamples, int &decodedSamples, int &adjustment, UtlBoolean &played)
Push packet into decoder buffer.
Definition: MpJitterBuffer.cpp:150
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
MpFlowGraphBase * mpFlowGraph
Parent flowgraph for debugging.
Definition: MpJitterBuffer.h:220
Smart pointer to MpAudioBuf.
Definition: MpAudioBuf.h:168
Size of mDecodedData temporary buffer.
Definition: MpJitterBuffer.h:175
OsStatus sliceToFrames(int decodedSamples, int codecSampleRate, const MpSpeechParams &speechParams)
Definition: MpJitterBuffer.cpp:676
int mStreamSampleRate
Sample rate of incoming RTP stream.
Definition: MpJitterBuffer.h:180
int mSamplesPerFrame
Number of samples to put to output buffers.
Definition: MpJitterBuffer.h:185
MpJitterBuffer(MpDecoderPayloadMap *pPayloadMap=NULL, const UtlString &resourceName="unknown")
Constructor.
Definition: MpJitterBuffer.cpp:73
uint16_t RtpSeq
RTP sequence number.
Definition: MpTypes.h:59
unsigned mRemainingSamplesNum
Definition: MpJitterBuffer.h:197
MpPlcBase * mpPlc
Packet Loss Concealer instance.
Definition: MpJitterBuffer.h:217
Helper class for MprDecode - it maps payload types to decoder instances.
Definition: MpDecoderPayloadMap.h:27
void setFlowGraph(MpFlowGraphBase *pFlowgraph)
Set the pointer to the parent flowgraph for debug purposes.
Definition: MpJitterBuffer.cpp:509
int mOriginalSamples[FRAMES_TO_STORE]
before resampling was done.
Definition: MpJitterBuffer.h:200
unsigned mSamplesPerPacket
Number of samples in RTP packet.
Definition: MpJitterBuffer.h:213
unsigned mCurFrameNum
Definition: MpJitterBuffer.h:194
MpVadBase * mpVad
Voice Activity Detector instance.
Definition: MpJitterBuffer.h:218
void setCodecList(MpDecoderPayloadMap *pPayloadMap)
Update list of available decoders.
Definition: MpJitterBuffer.cpp:477
RtpSeq mStreamSeq
Sequence number of last played RTP packet.
Definition: MpJitterBuffer.h:207
void getFrame(MpAudioBufPtr &pFrame, int &numOriginalSamples)
Get next frame from decoder buffer.
Definition: MpJitterBuffer.cpp:450
MpResamplerBase * mpResampler
Definition: MpJitterBuffer.h:188
void reset()
Reset class to the initial state, preparing for handling new stream.
Definition: MpJitterBuffer.cpp:115
void setPlc(const UtlString &plcName)
Change PLC algorithm to one provided.
Definition: MpJitterBuffer.cpp:490