sipxmedialib
Version 3.3
|
Class for decoding of incoming RTP, resampling it to target sample rate and slicing to frames of target size. More...
#include <MpJitterBuffer.h>
Public Member Functions | |
Creators | |
MpJitterBuffer (MpDecoderPayloadMap *pPayloadMap=NULL, const UtlString &resourceName="unknown") | |
Constructor. More... | |
void | init (unsigned int samplesPerSec, unsigned int samplesPerFrame) |
Initialize with given sample rate and frame size. More... | |
~MpJitterBuffer () | |
Destructor. More... | |
Manipulators | |
void | reset () |
Reset class to the initial state, preparing for handling new stream. More... | |
OsStatus | pushPacket (const MpRtpBufPtr &rtpPacket, int minBufferSamples, int wantedBufferSamples, int &decodedSamples, int &adjustment, UtlBoolean &played) |
Push packet into decoder buffer. More... | |
void | getFrame (MpAudioBufPtr &pFrame, int &numOriginalSamples) |
Get next frame from decoder buffer. More... | |
void | setCodecList (MpDecoderPayloadMap *pPayloadMap) |
Update list of available decoders. More... | |
void | setPlc (const UtlString &plcName) |
Change PLC algorithm to one provided. More... | |
Accessors | |
void | setFlowGraph (MpFlowGraphBase *pFlowgraph) |
Set the pointer to the parent flowgraph for debug purposes. More... | |
int | getSamplesNum () const |
Get number of samples, remaining in buffer. More... | |
OsStatus | setVadParam (const UtlString &name, int value) |
Set parameter on the VAD component. More... | |
Protected Member Functions | |
int | adjustStream (MpAudioSample *pBuffer, int bufferSize, unsigned numSamples, int wantedAdjustment) |
Reduce or extend audio fragment. More... | |
OsStatus | sliceToFrames (int decodedSamples, int codecSampleRate, const MpSpeechParams &speechParams) |
Private Types | |
enum | { FRAMES_TO_STORE = 32, DECODED_DATA_MAX_LENGTH = 10 * 160 } |
Private Member Functions | |
MpJitterBuffer (const MpJitterBuffer &rMpJitterBuffer) | |
Copy constructor. More... | |
MpJitterBuffer & | operator= (const MpJitterBuffer &rhs) |
Assignment operator. More... | |
Private Attributes | |
UtlString | mPlcName |
Packet Loss Concealer algorithm name. More... | |
MpPlcBase * | mpPlc |
Packet Loss Concealer instance. More... | |
MpVadBase * | mpVad |
Voice Activity Detector instance. More... | |
MpAgcBase * | mpAgc |
Automatic Gain Calculator instance. More... | |
MpFlowGraphBase * | mpFlowGraph |
Parent flowgraph for debugging. More... | |
Resampler variables. | |
int | mStreamSampleRate |
Sample rate of incoming RTP stream. More... | |
int | mOutputSampleRate |
int | mSamplesPerFrame |
Number of samples to put to output buffers. More... | |
MpAudioSample | mDecodedData [DECODED_DATA_MAX_LENGTH] |
temporarily store decoded data. More... | |
MpResamplerBase * | mpResampler |
Audio buffers variables. | |
unsigned | mCurFrameNum |
unsigned | mRemainingSamplesNum |
MpAudioBufPtr | mFrames [FRAMES_TO_STORE] |
Buffer for decoded, resampled and sliced audio. More... | |
int | mOriginalSamples [FRAMES_TO_STORE] |
before resampling was done. More... | |
Decoding related variables. | |
UtlBoolean | mIsFirstPacket |
Have we received our first packet or not. More... | |
RtpSeq | mStreamSeq |
Sequence number of last played RTP packet. More... | |
RtpTimestamp | mStreamTimestamp |
Timestamp of last played RTP packet. More... | |
uint8_t | mStreamRtpPayload |
Payload type of last received RTP packet. More... | |
MpDecoderPayloadMap * | mpPayloadMap |
unsigned | mSamplesPerPacket |
Number of samples in RTP packet. More... | |
Class for decoding of incoming RTP, resampling it to target sample rate and slicing to frames of target size.
This class is not thread-safe. For thread-safety it relies on external synchronization mechanisms in MprDecode.
|
private |
MpJitterBuffer | ( | MpDecoderPayloadMap * | pPayloadMap = NULL , |
const UtlString & | resourceName = "unknown" |
||
) |
Constructor.
[in] | pPayloadMap | - set of decoders, mapped to their RTP payload types. |
[in] | resourceName | - name of the resource that this is part of. Used for debugging and logging purposes. |
~MpJitterBuffer | ( | ) |
Destructor.
|
private |
Copy constructor.
void init | ( | unsigned int | samplesPerSec, |
unsigned int | samplesPerFrame | ||
) |
Initialize with given sample rate and frame size.
Should be called only once upon construction of an object.
void reset | ( | ) |
Reset class to the initial state, preparing for handling new stream.
OsStatus pushPacket | ( | const MpRtpBufPtr & | rtpPacket, |
int | minBufferSamples, | ||
int | wantedBufferSamples, | ||
int & | decodedSamples, | ||
int & | adjustment, | ||
UtlBoolean & | played | ||
) |
Push packet into decoder buffer.
Packet will be decoded and decoded data will be copied to internal buffer. If no decoder is available for this packet's payload type packet will be ignored.
[in] | rtpPacket | - RTP packet to be decoded. |
[in] | minBufferSamples | - minimum number of samples to remain in buffer after decoding and applying adjustment. This is useful, when we do not want to decode more packets at this moment, but need a frame of audio for processing. |
[in] | wantedBufferSamples | - number of samples we want to have in buffer after decoding packet. Note, this value may be negative - this means we want to shorten our buffer as much as possible. |
[out] | decodedSamples | - number of samples, decoded from packet. |
[out] | adjustment | - how many samples were added or removed from stream to fulfil wantedBufferSamples request. |
[out] | played | - was passed RTP packet decoded and added to decoder buffer, or it was dropped or used just to update PLC history. I.e. if played=FALSE then number of samples in buffer was not increased. |
OS_SUCCESS | if RTP packet was successfully decoded. |
OS_FAILED | in case of any problems. |
void getFrame | ( | MpAudioBufPtr & | pFrame, |
int & | numOriginalSamples | ||
) |
Get next frame from decoder buffer.
pFrame
must be NULL before passing to this method![out] | pFrame | - pointer to returned frame. |
[out] | numOriginalSamples | - number of samples in returned frame would be without resampling. |
void setCodecList | ( | MpDecoderPayloadMap * | pPayloadMap | ) |
Update list of available decoders.
void setPlc | ( | const UtlString & | plcName | ) |
Change PLC algorithm to one provided.
void setFlowGraph | ( | MpFlowGraphBase * | pFlowgraph | ) |
Set the pointer to the parent flowgraph for debug purposes.
|
inline |
Get number of samples, remaining in buffer.
OsStatus setVadParam | ( | const UtlString & | name, |
int | value | ||
) |
Set parameter on the VAD component.
|
protected |
Reduce or extend audio fragment.
|
protected |
|
private |
Assignment operator.
|
private |
Sample rate of incoming RTP stream.
|
private |
Output sample rate for decoded data. Samples from codecs with different sample rates will be resampled to this sample rate.
|
private |
Number of samples to put to output buffers.
|
private |
temporarily store decoded data.
Buffer, used to
|
private |
Resampler instance to convert codec sample rate to flowgraph sample rate.
|
private |
Internal sequence number of oldest frame in mFrames[]. It is also used as a base for frames index calculation.
|
private |
Total number of samples still residing in mFrames[].
|
private |
Buffer for decoded, resampled and sliced audio.
|
private |
before resampling was done.
Numbers of samples in frames
|
private |
Have we received our first packet or not.
|
private |
Sequence number of last played RTP packet.
|
private |
Timestamp of last played RTP packet.
|
private |
Payload type of last received RTP packet.
|
private |
Map of RTP payload types to decoders. Note, we do not own instance of this map, we only store pointer to it.
|
private |
Number of samples in RTP packet.
|
private |
Packet Loss Concealer algorithm name.
|
private |
Packet Loss Concealer instance.
|
private |
Voice Activity Detector instance.
|
private |
Automatic Gain Calculator instance.
|
private |
Parent flowgraph for debugging.