2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-04-12 11:02:38 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "acm_common_defs.h"
|
|
|
|
|
#include "acm_neteq.h"
|
|
|
|
|
#include "acm_pcmu.h"
|
|
|
|
|
#include "trace.h"
|
|
|
|
|
#include "webrtc_neteq.h"
|
|
|
|
|
#include "webrtc_neteq_help_macros.h"
|
|
|
|
|
|
|
|
|
|
// Codec interface
|
|
|
|
|
#include "g711_interface.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ACMPCMU::ACMPCMU(WebRtc_Word16 codecID)
|
|
|
|
|
{
|
|
|
|
|
_codecID = codecID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ACMPCMU::~ACMPCMU()
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word16
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::InternalEncode(
|
|
|
|
|
WebRtc_UWord8* bitStream,
|
|
|
|
|
WebRtc_Word16* bitStreamLenByte)
|
|
|
|
|
{
|
|
|
|
|
*bitStreamLenByte = WebRtcG711_EncodeU(NULL, &_inAudio[_inAudioIxRead],
|
|
|
|
|
_frameLenSmpl*_noChannels, (WebRtc_Word16*)bitStream);
|
2011-11-03 17:20:10 +00:00
|
|
|
// increment the read index this tell the caller that how far
|
2011-07-07 08:21:25 +00:00
|
|
|
// we have gone forward in reading the audio buffer
|
|
|
|
|
_inAudioIxRead += _frameLenSmpl*_noChannels;
|
|
|
|
|
return *bitStreamLenByte;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word16
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::DecodeSafe(
|
|
|
|
|
WebRtc_UWord8* /* bitStream */,
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word16 /* bitStreamLenByte */,
|
2011-07-07 08:21:25 +00:00
|
|
|
WebRtc_Word16* /* audio */,
|
|
|
|
|
WebRtc_Word16* /* audioSamples */,
|
|
|
|
|
WebRtc_Word8* /* speechType */)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word16
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::InternalInitEncoder(
|
|
|
|
|
WebRtcACMCodecParams* /* codecParams */)
|
|
|
|
|
{
|
|
|
|
|
// This codec does not need initialization,
|
|
|
|
|
// PCM has no instance
|
2011-11-03 17:20:10 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word16
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::InternalInitDecoder(
|
|
|
|
|
WebRtcACMCodecParams* /* codecParams */)
|
|
|
|
|
{
|
|
|
|
|
// This codec does not need initialization,
|
|
|
|
|
// PCM has no instance
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word32
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::CodecDef(
|
|
|
|
|
WebRtcNetEQ_CodecDef& codecDef,
|
|
|
|
|
const CodecInst& codecInst)
|
|
|
|
|
{
|
2011-11-03 17:20:10 +00:00
|
|
|
// Fill up the structure by calling
|
2011-07-07 08:21:25 +00:00
|
|
|
// "SET_CODEC_PAR" & "SET_PCMU_FUNCTION."
|
|
|
|
|
// Then call NetEQ to add the codec to it's
|
|
|
|
|
// database.
|
|
|
|
|
SET_CODEC_PAR((codecDef), kDecoderPCMu, codecInst.pltype, NULL, 8000);
|
|
|
|
|
SET_PCMU_FUNCTIONS((codecDef));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ACMGenericCodec*
|
|
|
|
|
ACMPCMU::CreateInstance(void)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word16
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::InternalCreateEncoder()
|
|
|
|
|
{
|
|
|
|
|
// PCM has no instance
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
WebRtc_Word16
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::InternalCreateDecoder()
|
|
|
|
|
{
|
|
|
|
|
// PCM has no instance
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
void
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::InternalDestructEncoderInst(
|
|
|
|
|
void* /* ptrInst */)
|
|
|
|
|
{
|
|
|
|
|
// PCM has no instance
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-03 17:20:10 +00:00
|
|
|
void
|
2011-07-07 08:21:25 +00:00
|
|
|
ACMPCMU::DestructEncoderSafe()
|
|
|
|
|
{
|
|
|
|
|
// PCM has no instance
|
|
|
|
|
_encoderExist = false;
|
|
|
|
|
_encoderInitialized = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ACMPCMU::DestructDecoderSafe()
|
|
|
|
|
{
|
|
|
|
|
// PCM has no instance
|
|
|
|
|
_decoderInitialized = false;
|
|
|
|
|
_decoderExist = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-12 11:02:38 +00:00
|
|
|
// Split the stereo packet and place left and right channel after each other
|
|
|
|
|
// in the payload vector.
|
|
|
|
|
void ACMPCMU::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
|
|
|
|
|
uint8_t right_byte;
|
|
|
|
|
|
|
|
|
|
// Check for valid inputs.
|
|
|
|
|
assert(payload != NULL);
|
|
|
|
|
assert(*payload_length > 0);
|
|
|
|
|
|
|
|
|
|
// Move one bytes representing right channel each loop, and place it at the
|
|
|
|
|
// end of the bytestream vector. After looping the data is reordered to:
|
|
|
|
|
// l1 l2 l3 l4 ... l(N-1) lN r1 r2 r3 r4 ... r(N-1) r(N),
|
|
|
|
|
// where N is the total number of samples.
|
|
|
|
|
for (int i = 0; i < *payload_length / 2; i ++) {
|
|
|
|
|
right_byte = payload[i + 1];
|
|
|
|
|
memmove(&payload[i + 1], &payload[i + 2], *payload_length - i - 2);
|
|
|
|
|
payload[*payload_length - 1] = right_byte;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|