/usr/include/sipxtapi/mp/MpJitterBuffer.h is in libsipxtapi-dev 3.3.0~test17-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | //
// Copyright (C) 2006-2012 SIPez LLC.
//
// Copyright (C) 2004-2008 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////
#ifndef _MpJitterBuffer_h_
#define _MpJitterBuffer_h_
// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include "mp/MpRtpBuf.h"
#include "mp/MpAudioBuf.h"
#include "mp/MpResampler.h"
// DEFINES
// MACROS
// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STRUCTS
// TYPEDEFS
// FORWARD DECLARATIONS
class MpDecoderPayloadMap;
class MpPlcBase;
class MpVadBase;
class MpAgcBase;
class MpFlowGraphBase;
/**
* @brief 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.
*/
class MpJitterBuffer
{
/* //////////////////////////// PUBLIC //////////////////////////////////// */
public:
/* ============================ CREATORS ================================== */
///@name Creators
//@{
/// Constructor
MpJitterBuffer(MpDecoderPayloadMap *pPayloadMap = NULL);
/**<
* @param[in] pPayloadMap - set of decoders, mapped to their RTP payload
* types.
*/
/// Initialize with given sample rate and frame size.
void init(unsigned int samplesPerSec, unsigned int samplesPerFrame);
/**<
* Should be called only once upon construction of an object.
*/
/// Destructor
~MpJitterBuffer();
//@}
/* ============================ MANIPULATORS ============================== */
///@name Manipulators
//@{
/// Reset class to the initial state, preparing for handling new stream.
void reset();
/// Push packet into decoder buffer.
OsStatus pushPacket(const MpRtpBufPtr &rtpPacket,
int minBufferSamples,
int wantedBufferSamples,
int &decodedSamples,
int &adjustment,
UtlBoolean &played);
/**<
* 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.
*
* @param[in] rtpPacket - RTP packet to be decoded.
* @param[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.
* @param[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.
* @param[out] decodedSamples - number of samples, decoded from packet.
* @param[out] adjustment - how many samples were added or removed from
* stream to fulfil \p wantedBufferSamples request.
* @param[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 \p played=FALSE then number of samples
* in buffer was not increased.
*
* @note This implementation behave unpredictable if packets come reordered.
* @note Valid RTP packet MUST be passed with first call to this function.
*
* @retval OS_SUCCESS if RTP packet was successfully decoded.
* @retval OS_FAILED in case of any problems.
*/
/// Get next frame from decoder buffer.
void getFrame(MpAudioBufPtr &pFrame, int &numOriginalSamples);
/**<
* @note \p pFrame must be NULL before passing to this method!
*
* @param[out] pFrame - pointer to returned frame.
* @param[out] numOriginalSamples - number of samples in returned frame
* would be without resampling.
*/
/// Update list of available decoders.
void setCodecList(MpDecoderPayloadMap *pPayloadMap);
/// Change PLC algorithm to one provided.
void setPlc(const UtlString &plcName);
//@}
/* ============================ ACCESSORS ================================= */
///@name Accessors
//@{
/// Set the pointer to the parent flowgraph for debug purposes.
void setFlowGraph(MpFlowGraphBase* pFlowgraph);
/// Get number of samples, remaining in buffer.
inline
int getSamplesNum() const;
//@}
/* ============================ INQUIRY =================================== */
///@name Inquiry
//@{
//@}
/* //////////////////////////// PROTECTED ///////////////////////////////// */
protected:
/// Reduce or extend audio fragment.
int adjustStream(MpAudioSample *pBuffer, int bufferSize, unsigned numSamples,
int wantedAdjustment);
OsStatus sliceToFrames(int decodedSamples, int codecSampleRate,
const MpSpeechParams &speechParams);
/* //////////////////////////// PRIVATE /////////////////////////////////// */
private:
enum {
FRAMES_TO_STORE = 32, ///< Number of frames to store in buffer.
///< Should be a power of 2.
DECODED_DATA_MAX_LENGTH = 10 * 160 ///< Size of mDecodedData temporary buffer.
};
///@name Resampler variables.
//@{
int mStreamSampleRate; ///< Sample rate of incoming RTP stream.
int mOutputSampleRate; ///< Output sample rate for decoded data.
///< Samples from codecs with different
///< sample rates will be resampled to this
///< sample rate.
int mSamplesPerFrame; ///< Number of samples to put to output buffers.
MpAudioSample mDecodedData[DECODED_DATA_MAX_LENGTH]; ///< Buffer, used to
///< temporarily store decoded data.
MpResamplerBase *mpResampler; ///< Resampler instance to convert codec
///< sample rate to flowgraph sample rate.
//@}
///@name Audio buffers variables.
//@{
unsigned mCurFrameNum; ///< Internal sequence number of oldest
///< frame in mFrames[]. It is also used
///< as a base for frames index calculation.
unsigned mRemainingSamplesNum; ///< Total number of samples still residing
///< in mFrames[].
MpAudioBufPtr mFrames[FRAMES_TO_STORE]; ///< Buffer for decoded, resampled and sliced audio.
int mOriginalSamples[FRAMES_TO_STORE]; ///< Numbers of samples in frames
///< before resampling was done.
//@}
///@name Decoding related variables.
//@{
UtlBoolean mIsFirstPacket; ///< Have we received our first packet or not.
RtpSeq mStreamSeq; ///< Sequence number of last played RTP packet.
RtpTimestamp mStreamTimestamp; ///< Timestamp of last played RTP packet.
uint8_t mStreamRtpPayload; ///< Payload type of last received RTP packet.
MpDecoderPayloadMap *mpPayloadMap; ///< Map of RTP payload types to decoders.
///< Note, we do not own instance of this map,
///< we only store pointer to it.
unsigned mSamplesPerPacket; ///< Number of samples in RTP packet.
//@}
UtlString mPlcName; ///< Packet Loss Concealer algorithm name.
MpPlcBase *mpPlc; ///< Packet Loss Concealer instance.
MpVadBase *mpVad; ///< Voice Activity Detector instance.
MpAgcBase *mpAgc; ///< Automatic Gain Calculator instance.
MpFlowGraphBase* mpFlowGraph; ///< Parent flowgraph for debugging
/// Copy constructor
MpJitterBuffer(const MpJitterBuffer& rMpJitterBuffer);
/// Assignment operator
MpJitterBuffer& operator=(const MpJitterBuffer& rhs);
};
/* ============================ INLINE METHODS ============================ */
int MpJitterBuffer::getSamplesNum() const
{
return mRemainingSamplesNum;
}
#endif // _MpJitterBuffer_h_
|