CODEC_API int PLG_DECODE_V1(sipxPcma)(void* handle, const void* pCodedData, unsigned cbCodedPacketSize, void* pAudioBuffer, unsigned cbBufferSize, unsigned *pcbCodedSize, const struct RtpHeader* pRtpHeader) { int samples; if (handle != DECODER_HANDLE) return RPLG_BAD_HANDLE; // Assert that available buffer size is enough for the packet. if (cbCodedPacketSize > cbBufferSize) { return RPLG_INVALID_ARGUMENT; } if (cbBufferSize == 0) return RPLG_INVALID_ARGUMENT; samples = min(cbCodedPacketSize, cbBufferSize); #ifdef USE_BUGGY_G711 // [ G711A_Decoder(samples, (uint8_t*)pCodedData, (MpAudioSample *)pAudioBuffer); #else // USE_BUGGY_G711 ][ { int16_t *pSamples = (int16_t*)pAudioBuffer; uint8_t *pEncoded = (uint8_t*)pCodedData; int i; for (i=0; i<samples; i++) { pSamples[i] = alaw_to_linear(pEncoded[i]); } } #endif // USE_BUGGY_G711 ] *pcbCodedSize = samples; return RPLG_SUCCESS; }
int MpJitterBuffer::ReceivePacket(JB_uchar* RTPpacket, JB_size RTPlength, JB_ulong TS) { int numSamples = 0; unsigned char* pRtpData = NULL; struct rtpHeader* pHdr = (struct rtpHeader*) RTPpacket; int cc; int payloadType; int overhead; payloadType = (pHdr->mpt) & 0x7f; cc = (pHdr->vpxcc) & 0x0f; overhead = sizeof(struct rtpHeader) + (cc*sizeof(int)); switch (payloadType) { case 0: // G.711 u-Law case 8: // G.711 a-Law numSamples = RTPlength - overhead;; pRtpData = RTPpacket + overhead; break; default: break; } if (0 == numSamples) { return 0; } if (numSamples != 160) { if (debugCount++ < 10) { printf("RTPlength=%d, cc=%d, payloadType=%d\n", RTPlength, cc, payloadType); } } if (JbQWait > 0) { JbQWait--; } if (JbQueueSize == JbQCount) { // discard some data... JbQOut = JbQIn + numSamples; JbQCount -= numSamples; } switch (payloadType) { case 0: // G.711 u-Law G711U_Decoder(numSamples, pRtpData, JbQ+JbQIn); break; case 8: // G.711 a-Law G711A_Decoder(numSamples, pRtpData, JbQ+JbQIn); break; default: break; } JbQCount += numSamples; JbQIn += numSamples; if (JbQIn >= JbQueueSize) { JbQIn -= JbQueueSize; } return 0; }