Make an AudioEncoder subclass for PCM16B
The implementation depends on AudioEncoderPcm to reduce code duplication. BUG=3926 R=kjellander@webrtc.org, kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/33589004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7872 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -612,10 +612,16 @@ config("pcm16b_config") {
|
||||
|
||||
source_set("pcm16b") {
|
||||
sources = [
|
||||
"codecs/pcm16b/include/audio_encoder_pcm16b.h",
|
||||
"codecs/pcm16b/include/pcm16b.h",
|
||||
"codecs/pcm16b/audio_encoder_pcm16b.cc",
|
||||
"codecs/pcm16b/pcm16b.c",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":g711",
|
||||
]
|
||||
|
||||
configs += [ "../..:common_config" ]
|
||||
|
||||
public_configs = [
|
||||
|
@@ -27,14 +27,16 @@ int16_t NumSamplesPerFrame(int num_channels,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AudioEncoderPcm::AudioEncoderPcm(const Config& config)
|
||||
: num_channels_(config.num_channels),
|
||||
AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz)
|
||||
: sample_rate_hz_(sample_rate_hz),
|
||||
num_channels_(config.num_channels),
|
||||
payload_type_(config.payload_type),
|
||||
num_10ms_frames_per_packet_(config.frame_size_ms / 10),
|
||||
full_frame_samples_(NumSamplesPerFrame(num_channels_,
|
||||
full_frame_samples_(NumSamplesPerFrame(config.num_channels,
|
||||
config.frame_size_ms,
|
||||
kSampleRateHz)),
|
||||
sample_rate_hz_)),
|
||||
first_timestamp_in_buffer_(0) {
|
||||
CHECK_GT(sample_rate_hz, 0) << "Sample rate must be larger than 0 Hz";
|
||||
CHECK_EQ(config.frame_size_ms % 10, 0)
|
||||
<< "Frame size must be an integer multiple of 10 ms.";
|
||||
speech_buffer_.reserve(full_frame_samples_);
|
||||
@@ -44,7 +46,7 @@ AudioEncoderPcm::~AudioEncoderPcm() {
|
||||
}
|
||||
|
||||
int AudioEncoderPcm::sample_rate_hz() const {
|
||||
return kSampleRateHz;
|
||||
return sample_rate_hz_;
|
||||
}
|
||||
int AudioEncoderPcm::num_channels() const {
|
||||
return num_channels_;
|
||||
|
@@ -30,8 +30,6 @@ class AudioEncoderPcm : public AudioEncoder {
|
||||
: frame_size_ms(20), num_channels(1), payload_type(pt) {}
|
||||
};
|
||||
|
||||
explicit AudioEncoderPcm(const Config& config);
|
||||
|
||||
virtual ~AudioEncoderPcm();
|
||||
|
||||
virtual int sample_rate_hz() const OVERRIDE;
|
||||
@@ -40,6 +38,8 @@ class AudioEncoderPcm : public AudioEncoder {
|
||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||
|
||||
protected:
|
||||
AudioEncoderPcm(const Config& config, int sample_rate_hz);
|
||||
|
||||
virtual bool EncodeInternal(uint32_t timestamp,
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
@@ -52,7 +52,7 @@ class AudioEncoderPcm : public AudioEncoder {
|
||||
uint8_t* encoded) = 0;
|
||||
|
||||
private:
|
||||
static const int kSampleRateHz = 8000;
|
||||
const int sample_rate_hz_;
|
||||
const int num_channels_;
|
||||
const int payload_type_;
|
||||
const int num_10ms_frames_per_packet_;
|
||||
@@ -67,12 +67,16 @@ class AudioEncoderPcmA : public AudioEncoderPcm {
|
||||
Config() : AudioEncoderPcm::Config(8) {}
|
||||
};
|
||||
|
||||
explicit AudioEncoderPcmA(const Config& config) : AudioEncoderPcm(config) {}
|
||||
explicit AudioEncoderPcmA(const Config& config)
|
||||
: AudioEncoderPcm(config, kSampleRateHz) {}
|
||||
|
||||
protected:
|
||||
virtual int16_t EncodeCall(const int16_t* audio,
|
||||
size_t input_len,
|
||||
uint8_t* encoded) OVERRIDE;
|
||||
|
||||
private:
|
||||
static const int kSampleRateHz = 8000;
|
||||
};
|
||||
|
||||
class AudioEncoderPcmU : public AudioEncoderPcm {
|
||||
@@ -81,12 +85,16 @@ class AudioEncoderPcmU : public AudioEncoderPcm {
|
||||
Config() : AudioEncoderPcm::Config(0) {}
|
||||
};
|
||||
|
||||
explicit AudioEncoderPcmU(const Config& config) : AudioEncoderPcm(config) {}
|
||||
explicit AudioEncoderPcmU(const Config& config)
|
||||
: AudioEncoderPcm(config, kSampleRateHz) {}
|
||||
|
||||
protected:
|
||||
virtual int16_t EncodeCall(const int16_t* audio,
|
||||
size_t input_len,
|
||||
uint8_t* encoded) OVERRIDE;
|
||||
|
||||
private:
|
||||
static const int kSampleRateHz = 8000;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* 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 "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
int16_t AudioEncoderPcm16B::EncodeCall(const int16_t* audio,
|
||||
size_t input_len,
|
||||
uint8_t* encoded) {
|
||||
return WebRtcPcm16b_Encode(audio, static_cast<int16_t>(input_len), encoded);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_PCM16B_INCLUDE_AUDIO_ENCODER_PCM16B_H_
|
||||
#define WEBRTC_MODULES_AUDIO_CODING_CODECS_PCM16B_INCLUDE_AUDIO_ENCODER_PCM16B_H_
|
||||
|
||||
#include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class AudioEncoderPcm16B : public AudioEncoderPcm {
|
||||
public:
|
||||
struct Config : public AudioEncoderPcm::Config {
|
||||
public:
|
||||
Config() : AudioEncoderPcm::Config(107), sample_rate_hz(8000) {}
|
||||
|
||||
int sample_rate_hz;
|
||||
};
|
||||
|
||||
explicit AudioEncoderPcm16B(const Config& config)
|
||||
: AudioEncoderPcm(config, config.sample_rate_hz) {}
|
||||
|
||||
protected:
|
||||
virtual int16_t EncodeCall(const int16_t* audio,
|
||||
size_t input_len,
|
||||
uint8_t* encoded) OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_PCM16B_INCLUDE_AUDIO_ENCODER_PCM16B_H_
|
@@ -11,6 +11,9 @@
|
||||
{
|
||||
'target_name': 'PCM16B',
|
||||
'type': 'static_library',
|
||||
'dependencies': [
|
||||
'G711',
|
||||
],
|
||||
'include_dirs': [
|
||||
'include',
|
||||
'<(webrtc_root)',
|
||||
@@ -22,7 +25,9 @@
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
'include/audio_encoder_pcm16b.h',
|
||||
'include/pcm16b.h',
|
||||
'audio_encoder_pcm16b.cc',
|
||||
'pcm16b.c',
|
||||
],
|
||||
},
|
||||
|
@@ -17,14 +17,13 @@
|
||||
#include <vector>
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/g711/include/g711_interface.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_isac.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
|
||||
#include "webrtc/system_wrappers/interface/data_log.h"
|
||||
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
||||
@@ -300,20 +299,17 @@ class AudioDecoderPcmATest : public AudioDecoderTest {
|
||||
class AudioDecoderPcm16BTest : public AudioDecoderTest {
|
||||
protected:
|
||||
AudioDecoderPcm16BTest() : AudioDecoderTest() {
|
||||
codec_input_rate_hz_ = 8000;
|
||||
frame_size_ = 160;
|
||||
codec_input_rate_hz_ = 16000;
|
||||
frame_size_ = 20 * codec_input_rate_hz_ / 1000;
|
||||
data_length_ = 10 * frame_size_;
|
||||
decoder_ = new AudioDecoderPcm16B;
|
||||
assert(decoder_);
|
||||
}
|
||||
|
||||
virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
|
||||
uint8_t* output) {
|
||||
int enc_len_bytes = WebRtcPcm16b_EncodeW16(
|
||||
const_cast<int16_t*>(input), static_cast<int>(input_len_samples),
|
||||
reinterpret_cast<int16_t*>(output));
|
||||
EXPECT_EQ(2 * input_len_samples, static_cast<size_t>(enc_len_bytes));
|
||||
return enc_len_bytes;
|
||||
AudioEncoderPcm16B::Config config;
|
||||
config.sample_rate_hz = codec_input_rate_hz_;
|
||||
config.frame_size_ms =
|
||||
static_cast<int>(frame_size_ / (config.sample_rate_hz / 1000));
|
||||
config.payload_type = payload_type_;
|
||||
audio_encoder_.reset(new AudioEncoderPcm16B(config));
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user