This is to re-open an earlier CL
https://webrtc-codereview.appspot.com/16619005/ which is reverted due to an issue in audio conference mixer. This issue has been solved in https://webrtc-codereview.appspot.com/20779004/ BUG=webrtc:3155 R=turaj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/18819005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6736 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -162,7 +162,7 @@ int AudioDecoder::CodecSampleRateHz(NetEqDecoder codec_type) {
|
||||
#ifdef WEBRTC_CODEC_OPUS
|
||||
case kDecoderOpus:
|
||||
case kDecoderOpus_2ch: {
|
||||
return 32000;
|
||||
return 48000;
|
||||
}
|
||||
#endif
|
||||
case kDecoderCNGswb48kHz: {
|
||||
|
||||
@ -602,7 +602,7 @@ class AudioDecoderCeltStereoTest : public AudioDecoderTest {
|
||||
class AudioDecoderOpusTest : public AudioDecoderTest {
|
||||
protected:
|
||||
AudioDecoderOpusTest() : AudioDecoderTest() {
|
||||
frame_size_ = 320;
|
||||
frame_size_ = 480;
|
||||
data_length_ = 10 * frame_size_;
|
||||
decoder_ = new AudioDecoderOpus(kDecoderOpus);
|
||||
assert(decoder_);
|
||||
@ -613,75 +613,69 @@ class AudioDecoderOpusTest : public AudioDecoderTest {
|
||||
WebRtcOpus_EncoderFree(encoder_);
|
||||
}
|
||||
|
||||
virtual void SetUp() OVERRIDE {
|
||||
AudioDecoderTest::SetUp();
|
||||
// Upsample from 32 to 48 kHz.
|
||||
// Because Opus is 48 kHz codec but the input file is 32 kHz, so the data
|
||||
// read in |AudioDecoderTest::SetUp| has to be upsampled.
|
||||
// |AudioDecoderTest::SetUp| has read |data_length_| samples, which is more
|
||||
// than necessary after upsampling, so the end of audio that has been read
|
||||
// is unused and the end of the buffer is overwritten by the resampled data.
|
||||
Resampler rs;
|
||||
rs.Reset(32000, 48000, kResamplerSynchronous);
|
||||
const int before_resamp_len_samples = static_cast<int>(data_length_) * 2
|
||||
/ 3;
|
||||
int16_t* before_resamp_input = new int16_t[before_resamp_len_samples];
|
||||
memcpy(before_resamp_input, input_,
|
||||
sizeof(int16_t) * before_resamp_len_samples);
|
||||
int resamp_len_samples;
|
||||
EXPECT_EQ(0, rs.Push(before_resamp_input, before_resamp_len_samples,
|
||||
input_, static_cast<int>(data_length_),
|
||||
resamp_len_samples));
|
||||
EXPECT_EQ(static_cast<int>(data_length_), resamp_len_samples);
|
||||
delete[] before_resamp_input;
|
||||
}
|
||||
|
||||
virtual void InitEncoder() {}
|
||||
|
||||
virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
|
||||
uint8_t* output) {
|
||||
// Upsample from 32 to 48 kHz.
|
||||
Resampler rs;
|
||||
rs.Reset(32000, 48000, kResamplerSynchronous);
|
||||
const int max_resamp_len_samples = static_cast<int>(input_len_samples) *
|
||||
3 / 2;
|
||||
int16_t* resamp_input = new int16_t[max_resamp_len_samples];
|
||||
int resamp_len_samples;
|
||||
EXPECT_EQ(0, rs.Push(input, static_cast<int>(input_len_samples),
|
||||
resamp_input, max_resamp_len_samples,
|
||||
resamp_len_samples));
|
||||
EXPECT_EQ(max_resamp_len_samples, resamp_len_samples);
|
||||
int enc_len_bytes =
|
||||
WebRtcOpus_Encode(encoder_, resamp_input, resamp_len_samples,
|
||||
static_cast<int>(data_length_), output);
|
||||
uint8_t* output) OVERRIDE {
|
||||
int enc_len_bytes = WebRtcOpus_Encode(encoder_, const_cast<int16_t*>(input),
|
||||
static_cast<int16_t>(input_len_samples),
|
||||
static_cast<int16_t>(data_length_), output);
|
||||
EXPECT_GT(enc_len_bytes, 0);
|
||||
delete [] resamp_input;
|
||||
return enc_len_bytes;
|
||||
}
|
||||
|
||||
OpusEncInst* encoder_;
|
||||
};
|
||||
|
||||
class AudioDecoderOpusStereoTest : public AudioDecoderTest {
|
||||
class AudioDecoderOpusStereoTest : public AudioDecoderOpusTest {
|
||||
protected:
|
||||
AudioDecoderOpusStereoTest() : AudioDecoderTest() {
|
||||
AudioDecoderOpusStereoTest() : AudioDecoderOpusTest() {
|
||||
channels_ = 2;
|
||||
frame_size_ = 320;
|
||||
data_length_ = 10 * frame_size_;
|
||||
WebRtcOpus_EncoderFree(encoder_);
|
||||
delete decoder_;
|
||||
decoder_ = new AudioDecoderOpus(kDecoderOpus_2ch);
|
||||
assert(decoder_);
|
||||
WebRtcOpus_EncoderCreate(&encoder_, 2);
|
||||
}
|
||||
|
||||
~AudioDecoderOpusStereoTest() {
|
||||
WebRtcOpus_EncoderFree(encoder_);
|
||||
}
|
||||
|
||||
virtual void InitEncoder() {}
|
||||
|
||||
virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
|
||||
uint8_t* output) {
|
||||
uint8_t* output) OVERRIDE {
|
||||
// Create stereo by duplicating each sample in |input|.
|
||||
const int input_stereo_samples = static_cast<int>(input_len_samples) * 2;
|
||||
int16_t* input_stereo = new int16_t[input_stereo_samples];
|
||||
for (size_t i = 0; i < input_len_samples; i++)
|
||||
input_stereo[i * 2] = input_stereo[i * 2 + 1] = input[i];
|
||||
// Upsample from 32 to 48 kHz.
|
||||
Resampler rs;
|
||||
rs.Reset(32000, 48000, kResamplerSynchronousStereo);
|
||||
const int max_resamp_len_samples = input_stereo_samples * 3 / 2;
|
||||
int16_t* resamp_input = new int16_t[max_resamp_len_samples];
|
||||
int resamp_len_samples;
|
||||
EXPECT_EQ(0, rs.Push(input_stereo, input_stereo_samples, resamp_input,
|
||||
max_resamp_len_samples, resamp_len_samples));
|
||||
EXPECT_EQ(max_resamp_len_samples, resamp_len_samples);
|
||||
int enc_len_bytes =
|
||||
WebRtcOpus_Encode(encoder_, resamp_input, resamp_len_samples / 2,
|
||||
static_cast<int16_t>(data_length_), output);
|
||||
|
||||
int enc_len_bytes = WebRtcOpus_Encode(
|
||||
encoder_, input_stereo, static_cast<int16_t>(input_len_samples),
|
||||
static_cast<int16_t>(data_length_), output);
|
||||
EXPECT_GT(enc_len_bytes, 0);
|
||||
delete [] resamp_input;
|
||||
delete [] input_stereo;
|
||||
delete[] input_stereo;
|
||||
return enc_len_bytes;
|
||||
}
|
||||
|
||||
OpusEncInst* encoder_;
|
||||
};
|
||||
|
||||
TEST_F(AudioDecoderPcmUTest, EncodeDecode) {
|
||||
@ -871,11 +865,11 @@ TEST(AudioDecoder, CodecSampleRateHz) {
|
||||
EXPECT_EQ(8000, AudioDecoder::CodecSampleRateHz(kDecoderCNGnb));
|
||||
EXPECT_EQ(16000, AudioDecoder::CodecSampleRateHz(kDecoderCNGwb));
|
||||
EXPECT_EQ(32000, AudioDecoder::CodecSampleRateHz(kDecoderCNGswb32kHz));
|
||||
EXPECT_EQ(48000, AudioDecoder::CodecSampleRateHz(kDecoderOpus));
|
||||
EXPECT_EQ(48000, AudioDecoder::CodecSampleRateHz(kDecoderOpus_2ch));
|
||||
// TODO(tlegrand): Change 32000 to 48000 below once ACM has 48 kHz support.
|
||||
EXPECT_EQ(32000, AudioDecoder::CodecSampleRateHz(kDecoderCNGswb48kHz));
|
||||
EXPECT_EQ(-1, AudioDecoder::CodecSampleRateHz(kDecoderArbitrary));
|
||||
EXPECT_EQ(32000, AudioDecoder::CodecSampleRateHz(kDecoderOpus));
|
||||
EXPECT_EQ(32000, AudioDecoder::CodecSampleRateHz(kDecoderOpus_2ch));
|
||||
#ifdef WEBRTC_CODEC_CELT
|
||||
EXPECT_EQ(32000, AudioDecoder::CodecSampleRateHz(kDecoderCELT_32));
|
||||
EXPECT_EQ(32000, AudioDecoder::CodecSampleRateHz(kDecoderCELT_32_2ch));
|
||||
|
||||
@ -743,7 +743,7 @@ TEST(FecPayloadSplitter, MixedPayload) {
|
||||
// Check first packet.
|
||||
packet = packet_list.front();
|
||||
EXPECT_EQ(0, packet->header.payloadType);
|
||||
EXPECT_EQ(kBaseTimestamp - 20 * 32, packet->header.timestamp);
|
||||
EXPECT_EQ(kBaseTimestamp - 20 * 48, packet->header.timestamp);
|
||||
EXPECT_EQ(10, packet->payload_length);
|
||||
EXPECT_FALSE(packet->primary);
|
||||
delete [] packet->payload;
|
||||
|
||||
@ -21,8 +21,7 @@ namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
static const int kOpusBlockDurationMs = 20;
|
||||
static const int kOpusInputSamplingKhz = 48;
|
||||
static const int kOpusOutputSamplingKhz = 32;
|
||||
static const int kOpusSamplingKhz = 48;
|
||||
|
||||
// Define switch for input file name.
|
||||
static bool ValidateInFilename(const char* flagname, const string& value) {
|
||||
@ -128,8 +127,8 @@ class NetEqOpusFecQualityTest : public NetEqQualityTest {
|
||||
};
|
||||
|
||||
NetEqOpusFecQualityTest::NetEqOpusFecQualityTest()
|
||||
: NetEqQualityTest(kOpusBlockDurationMs, kOpusInputSamplingKhz,
|
||||
kOpusOutputSamplingKhz,
|
||||
: NetEqQualityTest(kOpusBlockDurationMs, kOpusSamplingKhz,
|
||||
kOpusSamplingKhz,
|
||||
(FLAGS_channels == 1) ? kDecoderOpus : kDecoderOpus_2ch,
|
||||
FLAGS_channels,
|
||||
FLAGS_in_filename,
|
||||
|
||||
@ -48,8 +48,6 @@ uint32_t TimestampScaler::ToInternal(uint32_t external_timestamp,
|
||||
denominator_ = 1;
|
||||
break;
|
||||
}
|
||||
case kDecoderOpus:
|
||||
case kDecoderOpus_2ch:
|
||||
case kDecoderISACfb:
|
||||
case kDecoderCNGswb48kHz: {
|
||||
// Use timestamp scaling with factor 2/3 (32 kHz sample rate, but RTP
|
||||
|
||||
@ -252,10 +252,14 @@ TEST(TimestampScaler, TestG722Reset) {
|
||||
EXPECT_CALL(db, Die()); // Called when database object is deleted.
|
||||
}
|
||||
|
||||
// TODO(minyue): This test becomes trivial since Opus does not need a timestamp
|
||||
// scaler. Therefore, this test may be removed in future. There is no harm to
|
||||
// keep it, since it can be taken as a test case for the situation of a trivial
|
||||
// timestamp scaler.
|
||||
TEST(TimestampScaler, TestOpusLargeStep) {
|
||||
MockDecoderDatabase db;
|
||||
DecoderDatabase::DecoderInfo info;
|
||||
info.codec_type = kDecoderOpus; // Uses a factor 2/3 scaling.
|
||||
info.codec_type = kDecoderOpus;
|
||||
static const uint8_t kRtpPayloadType = 17;
|
||||
EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
|
||||
.WillRepeatedly(Return(&info));
|
||||
@ -273,8 +277,7 @@ TEST(TimestampScaler, TestOpusLargeStep) {
|
||||
scaler.ToInternal(external_timestamp, kRtpPayloadType));
|
||||
// Scale back.
|
||||
EXPECT_EQ(external_timestamp, scaler.ToExternal(internal_timestamp));
|
||||
// Internal timestamp should be incremented with twice the step.
|
||||
internal_timestamp += 2 * kStep / 3;
|
||||
internal_timestamp += kStep;
|
||||
}
|
||||
|
||||
EXPECT_CALL(db, Die()); // Called when database object is deleted.
|
||||
@ -283,7 +286,7 @@ TEST(TimestampScaler, TestOpusLargeStep) {
|
||||
TEST(TimestampScaler, TestIsacFbLargeStep) {
|
||||
MockDecoderDatabase db;
|
||||
DecoderDatabase::DecoderInfo info;
|
||||
info.codec_type = kDecoderISACfb; // Uses a factor 2/3 scaling.
|
||||
info.codec_type = kDecoderISACfb;
|
||||
static const uint8_t kRtpPayloadType = 17;
|
||||
EXPECT_CALL(db, GetDecoderInfo(kRtpPayloadType))
|
||||
.WillRepeatedly(Return(&info));
|
||||
@ -301,7 +304,7 @@ TEST(TimestampScaler, TestIsacFbLargeStep) {
|
||||
scaler.ToInternal(external_timestamp, kRtpPayloadType));
|
||||
// Scale back.
|
||||
EXPECT_EQ(external_timestamp, scaler.ToExternal(internal_timestamp));
|
||||
// Internal timestamp should be incremented with twice the step.
|
||||
// Internal timestamp should be incremented with two-thirds the step.
|
||||
internal_timestamp += 2 * kStep / 3;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user