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:
henrik.lundin@webrtc.org
2014-12-11 10:47:19 +00:00
parent b3ad8cf6ca
commit 817e50dd7d
7 changed files with 99 additions and 23 deletions

View File

@ -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_;

View File

@ -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

View File

@ -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

View File

@ -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_

View File

@ -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',
],
},