AudioEncoder: Rename virtual accessors to CamelCase
Although sample_rate_hz(), num_channels(), and rtp_timestamp_rate_hz() are simple accessors for almost all implementations of AudioEncoder, they are virtual and not guaranteed to be just simple accessors. Thus, it makes more sense to use the normal CamelCase naming scheme. BUG=4235 R=henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/34239004 Cr-Commit-Position: refs/heads/master@{#8407} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8407 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
cc483b7379
commit
0521127779
@ -26,15 +26,15 @@ bool AudioEncoder::Encode(uint32_t rtp_timestamp,
|
|||||||
uint8_t* encoded,
|
uint8_t* encoded,
|
||||||
EncodedInfo* info) {
|
EncodedInfo* info) {
|
||||||
CHECK_EQ(num_samples_per_channel,
|
CHECK_EQ(num_samples_per_channel,
|
||||||
static_cast<size_t>(sample_rate_hz() / 100));
|
static_cast<size_t>(SampleRateHz() / 100));
|
||||||
bool ret =
|
bool ret =
|
||||||
EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded, info);
|
EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded, info);
|
||||||
CHECK_LE(info->encoded_bytes, max_encoded_bytes);
|
CHECK_LE(info->encoded_bytes, max_encoded_bytes);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoder::rtp_timestamp_rate_hz() const {
|
int AudioEncoder::RtpTimestampRateHz() const {
|
||||||
return sample_rate_hz();
|
return SampleRateHz();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -70,12 +70,12 @@ class AudioEncoder {
|
|||||||
|
|
||||||
// Return the input sample rate in Hz and the number of input channels.
|
// Return the input sample rate in Hz and the number of input channels.
|
||||||
// These are constants set at instantiation time.
|
// These are constants set at instantiation time.
|
||||||
virtual int sample_rate_hz() const = 0;
|
virtual int SampleRateHz() const = 0;
|
||||||
virtual int num_channels() const = 0;
|
virtual int NumChannels() const = 0;
|
||||||
|
|
||||||
// Returns the rate with which the RTP timestamps are updated. By default,
|
// Returns the rate with which the RTP timestamps are updated. By default,
|
||||||
// this is the same as sample_rate_hz().
|
// this is the same as sample_rate_hz().
|
||||||
virtual int rtp_timestamp_rate_hz() const;
|
virtual int RtpTimestampRateHz() const;
|
||||||
|
|
||||||
// Returns the number of 10 ms frames the encoder will put in the next
|
// Returns the number of 10 ms frames the encoder will put in the next
|
||||||
// packet. This value may only change when Encode() outputs a packet; i.e.,
|
// packet. This value may only change when Encode() outputs a packet; i.e.,
|
||||||
|
@ -29,7 +29,7 @@ bool AudioEncoderCng::Config::IsOk() const {
|
|||||||
return false;
|
return false;
|
||||||
if (!speech_encoder)
|
if (!speech_encoder)
|
||||||
return false;
|
return false;
|
||||||
if (num_channels != speech_encoder->num_channels())
|
if (num_channels != speech_encoder->NumChannels())
|
||||||
return false;
|
return false;
|
||||||
if (sid_frame_interval_ms < speech_encoder->Max10MsFramesInAPacket() * 10)
|
if (sid_frame_interval_ms < speech_encoder->Max10MsFramesInAPacket() * 10)
|
||||||
return false;
|
return false;
|
||||||
@ -55,7 +55,7 @@ AudioEncoderCng::AudioEncoderCng(const Config& config)
|
|||||||
CNG_enc_inst* cng_inst;
|
CNG_enc_inst* cng_inst;
|
||||||
CHECK_EQ(WebRtcCng_CreateEnc(&cng_inst), 0) << "WebRtcCng_CreateEnc failed.";
|
CHECK_EQ(WebRtcCng_CreateEnc(&cng_inst), 0) << "WebRtcCng_CreateEnc failed.";
|
||||||
cng_inst_.reset(cng_inst); // Transfer ownership to scoped_ptr.
|
cng_inst_.reset(cng_inst); // Transfer ownership to scoped_ptr.
|
||||||
CHECK_EQ(WebRtcCng_InitEnc(cng_inst_.get(), sample_rate_hz(),
|
CHECK_EQ(WebRtcCng_InitEnc(cng_inst_.get(), SampleRateHz(),
|
||||||
config.sid_frame_interval_ms,
|
config.sid_frame_interval_ms,
|
||||||
config.num_cng_coefficients),
|
config.num_cng_coefficients),
|
||||||
0)
|
0)
|
||||||
@ -65,15 +65,15 @@ AudioEncoderCng::AudioEncoderCng(const Config& config)
|
|||||||
AudioEncoderCng::~AudioEncoderCng() {
|
AudioEncoderCng::~AudioEncoderCng() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderCng::sample_rate_hz() const {
|
int AudioEncoderCng::SampleRateHz() const {
|
||||||
return speech_encoder_->sample_rate_hz();
|
return speech_encoder_->SampleRateHz();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderCng::rtp_timestamp_rate_hz() const {
|
int AudioEncoderCng::RtpTimestampRateHz() const {
|
||||||
return speech_encoder_->rtp_timestamp_rate_hz();
|
return speech_encoder_->RtpTimestampRateHz();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderCng::num_channels() const {
|
int AudioEncoderCng::NumChannels() const {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ bool AudioEncoderCng::EncodeInternal(uint32_t rtp_timestamp,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
info->encoded_bytes = 0;
|
info->encoded_bytes = 0;
|
||||||
const int num_samples = sample_rate_hz() / 100 * num_channels();
|
const int num_samples = SampleRateHz() / 100 * NumChannels();
|
||||||
if (speech_buffer_.empty()) {
|
if (speech_buffer_.empty()) {
|
||||||
CHECK_EQ(frames_in_buffer_, 0);
|
CHECK_EQ(frames_in_buffer_, 0);
|
||||||
first_timestamp_in_buffer_ = rtp_timestamp;
|
first_timestamp_in_buffer_ = rtp_timestamp;
|
||||||
@ -119,7 +119,7 @@ bool AudioEncoderCng::EncodeInternal(uint32_t rtp_timestamp,
|
|||||||
}
|
}
|
||||||
CHECK_LE(frames_in_buffer_, 6)
|
CHECK_LE(frames_in_buffer_, 6)
|
||||||
<< "Frame size cannot be larger than 60 ms when using VAD/CNG.";
|
<< "Frame size cannot be larger than 60 ms when using VAD/CNG.";
|
||||||
const size_t samples_per_10ms_frame = 10 * sample_rate_hz() / 1000;
|
const size_t samples_per_10ms_frame = 10 * SampleRateHz() / 1000;
|
||||||
CHECK_EQ(speech_buffer_.size(),
|
CHECK_EQ(speech_buffer_.size(),
|
||||||
static_cast<size_t>(frames_in_buffer_) * samples_per_10ms_frame);
|
static_cast<size_t>(frames_in_buffer_) * samples_per_10ms_frame);
|
||||||
|
|
||||||
@ -139,12 +139,12 @@ bool AudioEncoderCng::EncodeInternal(uint32_t rtp_timestamp,
|
|||||||
// block.
|
// block.
|
||||||
Vad::Activity activity = vad_->VoiceActivity(
|
Vad::Activity activity = vad_->VoiceActivity(
|
||||||
&speech_buffer_[0], samples_per_10ms_frame * blocks_in_first_vad_call,
|
&speech_buffer_[0], samples_per_10ms_frame * blocks_in_first_vad_call,
|
||||||
sample_rate_hz());
|
SampleRateHz());
|
||||||
if (activity == Vad::kPassive && blocks_in_second_vad_call > 0) {
|
if (activity == Vad::kPassive && blocks_in_second_vad_call > 0) {
|
||||||
// Only check the second block if the first was passive.
|
// Only check the second block if the first was passive.
|
||||||
activity = vad_->VoiceActivity(
|
activity = vad_->VoiceActivity(
|
||||||
&speech_buffer_[samples_per_10ms_frame * blocks_in_first_vad_call],
|
&speech_buffer_[samples_per_10ms_frame * blocks_in_first_vad_call],
|
||||||
samples_per_10ms_frame * blocks_in_second_vad_call, sample_rate_hz());
|
samples_per_10ms_frame * blocks_in_second_vad_call, SampleRateHz());
|
||||||
}
|
}
|
||||||
DCHECK_NE(activity, Vad::kError);
|
DCHECK_NE(activity, Vad::kError);
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ bool AudioEncoderCng::EncodeInternal(uint32_t rtp_timestamp,
|
|||||||
bool AudioEncoderCng::EncodePassive(uint8_t* encoded, size_t* encoded_bytes) {
|
bool AudioEncoderCng::EncodePassive(uint8_t* encoded, size_t* encoded_bytes) {
|
||||||
bool force_sid = last_frame_active_;
|
bool force_sid = last_frame_active_;
|
||||||
bool output_produced = false;
|
bool output_produced = false;
|
||||||
const size_t samples_per_10ms_frame = 10 * sample_rate_hz() / 1000;
|
const size_t samples_per_10ms_frame = 10 * SampleRateHz() / 1000;
|
||||||
for (int i = 0; i < frames_in_buffer_; ++i) {
|
for (int i = 0; i < frames_in_buffer_; ++i) {
|
||||||
int16_t encoded_bytes_tmp = 0;
|
int16_t encoded_bytes_tmp = 0;
|
||||||
if (WebRtcCng_Encode(cng_inst_.get(),
|
if (WebRtcCng_Encode(cng_inst_.get(),
|
||||||
@ -198,7 +198,7 @@ bool AudioEncoderCng::EncodePassive(uint8_t* encoded, size_t* encoded_bytes) {
|
|||||||
bool AudioEncoderCng::EncodeActive(size_t max_encoded_bytes,
|
bool AudioEncoderCng::EncodeActive(size_t max_encoded_bytes,
|
||||||
uint8_t* encoded,
|
uint8_t* encoded,
|
||||||
EncodedInfo* info) {
|
EncodedInfo* info) {
|
||||||
const size_t samples_per_10ms_frame = 10 * sample_rate_hz() / 1000;
|
const size_t samples_per_10ms_frame = 10 * SampleRateHz() / 1000;
|
||||||
for (int i = 0; i < frames_in_buffer_; ++i) {
|
for (int i = 0; i < frames_in_buffer_; ++i) {
|
||||||
if (!speech_encoder_->Encode(first_timestamp_in_buffer_,
|
if (!speech_encoder_->Encode(first_timestamp_in_buffer_,
|
||||||
&speech_buffer_[i * samples_per_10ms_frame],
|
&speech_buffer_[i * samples_per_10ms_frame],
|
||||||
|
@ -39,7 +39,7 @@ class AudioEncoderCngTest : public ::testing::Test {
|
|||||||
memset(encoded_, 0, kMaxEncodedBytes);
|
memset(encoded_, 0, kMaxEncodedBytes);
|
||||||
memset(audio_, 0, kMaxNumSamples * 2);
|
memset(audio_, 0, kMaxNumSamples * 2);
|
||||||
config_.speech_encoder = &mock_encoder_;
|
config_.speech_encoder = &mock_encoder_;
|
||||||
EXPECT_CALL(mock_encoder_, num_channels()).WillRepeatedly(Return(1));
|
EXPECT_CALL(mock_encoder_, NumChannels()).WillRepeatedly(Return(1));
|
||||||
// Let the AudioEncoderCng object use a MockVad instead of its internally
|
// Let the AudioEncoderCng object use a MockVad instead of its internally
|
||||||
// created Vad object.
|
// created Vad object.
|
||||||
config_.vad = mock_vad_;
|
config_.vad = mock_vad_;
|
||||||
@ -60,7 +60,7 @@ class AudioEncoderCngTest : public ::testing::Test {
|
|||||||
// is called, thus we cannot use the values until now.
|
// is called, thus we cannot use the values until now.
|
||||||
num_audio_samples_10ms_ = 10 * sample_rate_hz_ / 1000;
|
num_audio_samples_10ms_ = 10 * sample_rate_hz_ / 1000;
|
||||||
ASSERT_LE(num_audio_samples_10ms_, kMaxNumSamples);
|
ASSERT_LE(num_audio_samples_10ms_, kMaxNumSamples);
|
||||||
EXPECT_CALL(mock_encoder_, sample_rate_hz())
|
EXPECT_CALL(mock_encoder_, SampleRateHz())
|
||||||
.WillRepeatedly(Return(sample_rate_hz_));
|
.WillRepeatedly(Return(sample_rate_hz_));
|
||||||
// Max10MsFramesInAPacket() is just used to verify that the SID frame period
|
// Max10MsFramesInAPacket() is just used to verify that the SID frame period
|
||||||
// is not too small. The return value does not matter that much, as long as
|
// is not too small. The return value does not matter that much, as long as
|
||||||
@ -443,7 +443,7 @@ TEST_F(AudioEncoderCngDeathTest, NullSpeechEncoder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AudioEncoderCngDeathTest, Stereo) {
|
TEST_F(AudioEncoderCngDeathTest, Stereo) {
|
||||||
EXPECT_CALL(mock_encoder_, num_channels()).WillRepeatedly(Return(2));
|
EXPECT_CALL(mock_encoder_, NumChannels()).WillRepeatedly(Return(2));
|
||||||
EXPECT_DEATH(CreateCng(), "Invalid configuration");
|
EXPECT_DEATH(CreateCng(), "Invalid configuration");
|
||||||
config_.num_channels = 2;
|
config_.num_channels = 2;
|
||||||
EXPECT_DEATH(CreateCng(), "Invalid configuration");
|
EXPECT_DEATH(CreateCng(), "Invalid configuration");
|
||||||
|
@ -46,9 +46,9 @@ class AudioEncoderCng final : public AudioEncoder {
|
|||||||
|
|
||||||
virtual ~AudioEncoderCng();
|
virtual ~AudioEncoderCng();
|
||||||
|
|
||||||
virtual int sample_rate_hz() const OVERRIDE;
|
virtual int SampleRateHz() const OVERRIDE;
|
||||||
virtual int num_channels() const OVERRIDE;
|
virtual int NumChannels() const OVERRIDE;
|
||||||
int rtp_timestamp_rate_hz() const override;
|
int RtpTimestampRateHz() const override;
|
||||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||||
void SetTargetBitrate(int bits_per_second) override;
|
void SetTargetBitrate(int bits_per_second) override;
|
||||||
|
@ -46,10 +46,10 @@ AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz)
|
|||||||
AudioEncoderPcm::~AudioEncoderPcm() {
|
AudioEncoderPcm::~AudioEncoderPcm() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderPcm::sample_rate_hz() const {
|
int AudioEncoderPcm::SampleRateHz() const {
|
||||||
return sample_rate_hz_;
|
return sample_rate_hz_;
|
||||||
}
|
}
|
||||||
int AudioEncoderPcm::num_channels() const {
|
int AudioEncoderPcm::NumChannels() const {
|
||||||
return num_channels_;
|
return num_channels_;
|
||||||
}
|
}
|
||||||
int AudioEncoderPcm::Num10MsFramesInNextPacket() const {
|
int AudioEncoderPcm::Num10MsFramesInNextPacket() const {
|
||||||
@ -65,7 +65,7 @@ bool AudioEncoderPcm::EncodeInternal(uint32_t rtp_timestamp,
|
|||||||
size_t max_encoded_bytes,
|
size_t max_encoded_bytes,
|
||||||
uint8_t* encoded,
|
uint8_t* encoded,
|
||||||
EncodedInfo* info) {
|
EncodedInfo* info) {
|
||||||
const int num_samples = sample_rate_hz() / 100 * num_channels();
|
const int num_samples = SampleRateHz() / 100 * NumChannels();
|
||||||
if (speech_buffer_.empty()) {
|
if (speech_buffer_.empty()) {
|
||||||
first_timestamp_in_buffer_ = rtp_timestamp;
|
first_timestamp_in_buffer_ = rtp_timestamp;
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ class AudioEncoderPcm : public AudioEncoder {
|
|||||||
|
|
||||||
virtual ~AudioEncoderPcm();
|
virtual ~AudioEncoderPcm();
|
||||||
|
|
||||||
virtual int sample_rate_hz() const OVERRIDE;
|
virtual int SampleRateHz() const OVERRIDE;
|
||||||
virtual int num_channels() const OVERRIDE;
|
virtual int NumChannels() const OVERRIDE;
|
||||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||||
|
|
||||||
|
@ -51,15 +51,15 @@ AudioEncoderG722::AudioEncoderG722(const Config& config)
|
|||||||
|
|
||||||
AudioEncoderG722::~AudioEncoderG722() {}
|
AudioEncoderG722::~AudioEncoderG722() {}
|
||||||
|
|
||||||
int AudioEncoderG722::sample_rate_hz() const {
|
int AudioEncoderG722::SampleRateHz() const {
|
||||||
return kSampleRateHz;
|
return kSampleRateHz;
|
||||||
}
|
}
|
||||||
int AudioEncoderG722::rtp_timestamp_rate_hz() const {
|
int AudioEncoderG722::RtpTimestampRateHz() const {
|
||||||
// The RTP timestamp rate for G.722 is 8000 Hz, even though it is a 16 kHz
|
// The RTP timestamp rate for G.722 is 8000 Hz, even though it is a 16 kHz
|
||||||
// codec.
|
// codec.
|
||||||
return kSampleRateHz / 2;
|
return kSampleRateHz / 2;
|
||||||
}
|
}
|
||||||
int AudioEncoderG722::num_channels() const {
|
int AudioEncoderG722::NumChannels() const {
|
||||||
return num_channels_;
|
return num_channels_;
|
||||||
}
|
}
|
||||||
int AudioEncoderG722::Num10MsFramesInNextPacket() const {
|
int AudioEncoderG722::Num10MsFramesInNextPacket() const {
|
||||||
|
@ -30,9 +30,9 @@ class AudioEncoderG722 : public AudioEncoder {
|
|||||||
explicit AudioEncoderG722(const Config& config);
|
explicit AudioEncoderG722(const Config& config);
|
||||||
virtual ~AudioEncoderG722();
|
virtual ~AudioEncoderG722();
|
||||||
|
|
||||||
virtual int sample_rate_hz() const OVERRIDE;
|
virtual int SampleRateHz() const OVERRIDE;
|
||||||
int rtp_timestamp_rate_hz() const override;
|
int RtpTimestampRateHz() const override;
|
||||||
virtual int num_channels() const OVERRIDE;
|
virtual int NumChannels() const OVERRIDE;
|
||||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||||
|
|
||||||
|
@ -43,10 +43,10 @@ AudioEncoderIlbc::~AudioEncoderIlbc() {
|
|||||||
CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
|
CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderIlbc::sample_rate_hz() const {
|
int AudioEncoderIlbc::SampleRateHz() const {
|
||||||
return kSampleRateHz;
|
return kSampleRateHz;
|
||||||
}
|
}
|
||||||
int AudioEncoderIlbc::num_channels() const {
|
int AudioEncoderIlbc::NumChannels() const {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int AudioEncoderIlbc::Num10MsFramesInNextPacket() const {
|
int AudioEncoderIlbc::Num10MsFramesInNextPacket() const {
|
||||||
|
@ -31,8 +31,8 @@ class AudioEncoderIlbc : public AudioEncoder {
|
|||||||
explicit AudioEncoderIlbc(const Config& config);
|
explicit AudioEncoderIlbc(const Config& config);
|
||||||
virtual ~AudioEncoderIlbc();
|
virtual ~AudioEncoderIlbc();
|
||||||
|
|
||||||
virtual int sample_rate_hz() const OVERRIDE;
|
virtual int SampleRateHz() const OVERRIDE;
|
||||||
virtual int num_channels() const OVERRIDE;
|
virtual int NumChannels() const OVERRIDE;
|
||||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ class AudioEncoderDecoderIsacT : public AudioEncoder, public AudioDecoder {
|
|||||||
void UpdateDecoderSampleRate(int sample_rate_hz);
|
void UpdateDecoderSampleRate(int sample_rate_hz);
|
||||||
|
|
||||||
// AudioEncoder public methods.
|
// AudioEncoder public methods.
|
||||||
virtual int sample_rate_hz() const OVERRIDE;
|
virtual int SampleRateHz() const OVERRIDE;
|
||||||
virtual int num_channels() const OVERRIDE;
|
virtual int NumChannels() const OVERRIDE;
|
||||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||||
|
|
||||||
|
@ -166,13 +166,13 @@ void AudioEncoderDecoderIsacT<T>::UpdateDecoderSampleRate(int sample_rate_hz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int AudioEncoderDecoderIsacT<T>::sample_rate_hz() const {
|
int AudioEncoderDecoderIsacT<T>::SampleRateHz() const {
|
||||||
CriticalSectionScoped cs(state_lock_.get());
|
CriticalSectionScoped cs(state_lock_.get());
|
||||||
return T::EncSampRate(isac_state_);
|
return T::EncSampRate(isac_state_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int AudioEncoderDecoderIsacT<T>::num_channels() const {
|
int AudioEncoderDecoderIsacT<T>::NumChannels() const {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ int AudioEncoderDecoderIsacT<T>::Num10MsFramesInNextPacket() const {
|
|||||||
CriticalSectionScoped cs(state_lock_.get());
|
CriticalSectionScoped cs(state_lock_.get());
|
||||||
const int samples_in_next_packet = T::GetNewFrameLen(isac_state_);
|
const int samples_in_next_packet = T::GetNewFrameLen(isac_state_);
|
||||||
return rtc::CheckedDivExact(samples_in_next_packet,
|
return rtc::CheckedDivExact(samples_in_next_packet,
|
||||||
rtc::CheckedDivExact(sample_rate_hz(), 100));
|
rtc::CheckedDivExact(SampleRateHz(), 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -21,8 +21,8 @@ class MockAudioEncoder : public AudioEncoder {
|
|||||||
public:
|
public:
|
||||||
virtual ~MockAudioEncoder() { Die(); }
|
virtual ~MockAudioEncoder() { Die(); }
|
||||||
MOCK_METHOD0(Die, void());
|
MOCK_METHOD0(Die, void());
|
||||||
MOCK_CONST_METHOD0(sample_rate_hz, int());
|
MOCK_CONST_METHOD0(SampleRateHz, int());
|
||||||
MOCK_CONST_METHOD0(num_channels, int());
|
MOCK_CONST_METHOD0(NumChannels, int());
|
||||||
MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, int());
|
MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, int());
|
||||||
MOCK_CONST_METHOD0(Max10MsFramesInAPacket, int());
|
MOCK_CONST_METHOD0(Max10MsFramesInAPacket, int());
|
||||||
MOCK_METHOD1(SetTargetBitrate, void(int));
|
MOCK_METHOD1(SetTargetBitrate, void(int));
|
||||||
|
@ -96,11 +96,11 @@ AudioEncoderOpus::~AudioEncoderOpus() {
|
|||||||
CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderOpus::sample_rate_hz() const {
|
int AudioEncoderOpus::SampleRateHz() const {
|
||||||
return kSampleRateHz;
|
return kSampleRateHz;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderOpus::num_channels() const {
|
int AudioEncoderOpus::NumChannels() const {
|
||||||
return num_channels_;
|
return num_channels_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ class AudioEncoderOpus final : public AudioEncoder {
|
|||||||
explicit AudioEncoderOpus(const Config& config);
|
explicit AudioEncoderOpus(const Config& config);
|
||||||
virtual ~AudioEncoderOpus() OVERRIDE;
|
virtual ~AudioEncoderOpus() OVERRIDE;
|
||||||
|
|
||||||
virtual int sample_rate_hz() const OVERRIDE;
|
virtual int SampleRateHz() const OVERRIDE;
|
||||||
virtual int num_channels() const OVERRIDE;
|
virtual int NumChannels() const OVERRIDE;
|
||||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||||
void SetTargetBitrate(int bits_per_second) override;
|
void SetTargetBitrate(int bits_per_second) override;
|
||||||
|
@ -26,16 +26,16 @@ AudioEncoderCopyRed::AudioEncoderCopyRed(const Config& config)
|
|||||||
AudioEncoderCopyRed::~AudioEncoderCopyRed() {
|
AudioEncoderCopyRed::~AudioEncoderCopyRed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderCopyRed::sample_rate_hz() const {
|
int AudioEncoderCopyRed::SampleRateHz() const {
|
||||||
return speech_encoder_->sample_rate_hz();
|
return speech_encoder_->SampleRateHz();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderCopyRed::rtp_timestamp_rate_hz() const {
|
int AudioEncoderCopyRed::RtpTimestampRateHz() const {
|
||||||
return speech_encoder_->rtp_timestamp_rate_hz();
|
return speech_encoder_->RtpTimestampRateHz();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderCopyRed::num_channels() const {
|
int AudioEncoderCopyRed::NumChannels() const {
|
||||||
return speech_encoder_->num_channels();
|
return speech_encoder_->NumChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEncoderCopyRed::Num10MsFramesInNextPacket() const {
|
int AudioEncoderCopyRed::Num10MsFramesInNextPacket() const {
|
||||||
@ -62,7 +62,7 @@ bool AudioEncoderCopyRed::EncodeInternal(uint32_t rtp_timestamp,
|
|||||||
uint8_t* encoded,
|
uint8_t* encoded,
|
||||||
EncodedInfo* info) {
|
EncodedInfo* info) {
|
||||||
if (!speech_encoder_->Encode(rtp_timestamp, audio,
|
if (!speech_encoder_->Encode(rtp_timestamp, audio,
|
||||||
static_cast<size_t>(sample_rate_hz() / 100),
|
static_cast<size_t>(SampleRateHz() / 100),
|
||||||
max_encoded_bytes, encoded, info))
|
max_encoded_bytes, encoded, info))
|
||||||
return false;
|
return false;
|
||||||
if (max_encoded_bytes < info->encoded_bytes + secondary_info_.encoded_bytes)
|
if (max_encoded_bytes < info->encoded_bytes + secondary_info_.encoded_bytes)
|
||||||
|
@ -35,9 +35,9 @@ class AudioEncoderCopyRed : public AudioEncoder {
|
|||||||
|
|
||||||
virtual ~AudioEncoderCopyRed();
|
virtual ~AudioEncoderCopyRed();
|
||||||
|
|
||||||
virtual int sample_rate_hz() const OVERRIDE;
|
virtual int SampleRateHz() const OVERRIDE;
|
||||||
int rtp_timestamp_rate_hz() const override;
|
int RtpTimestampRateHz() const override;
|
||||||
virtual int num_channels() const OVERRIDE;
|
virtual int NumChannels() const OVERRIDE;
|
||||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||||
void SetTargetBitrate(int bits_per_second) override;
|
void SetTargetBitrate(int bits_per_second) override;
|
||||||
|
@ -41,8 +41,8 @@ class AudioEncoderCopyRedTest : public ::testing::Test {
|
|||||||
red_.reset(new AudioEncoderCopyRed(config));
|
red_.reset(new AudioEncoderCopyRed(config));
|
||||||
memset(encoded_, 0, sizeof(encoded_));
|
memset(encoded_, 0, sizeof(encoded_));
|
||||||
memset(audio_, 0, sizeof(audio_));
|
memset(audio_, 0, sizeof(audio_));
|
||||||
EXPECT_CALL(mock_encoder_, num_channels()).WillRepeatedly(Return(1));
|
EXPECT_CALL(mock_encoder_, NumChannels()).WillRepeatedly(Return(1));
|
||||||
EXPECT_CALL(mock_encoder_, sample_rate_hz())
|
EXPECT_CALL(mock_encoder_, SampleRateHz())
|
||||||
.WillRepeatedly(Return(sample_rate_hz_));
|
.WillRepeatedly(Return(sample_rate_hz_));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,13 +103,13 @@ TEST_F(AudioEncoderCopyRedTest, CreateAndDestroy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AudioEncoderCopyRedTest, CheckSampleRatePropagation) {
|
TEST_F(AudioEncoderCopyRedTest, CheckSampleRatePropagation) {
|
||||||
EXPECT_CALL(mock_encoder_, sample_rate_hz()).WillOnce(Return(17));
|
EXPECT_CALL(mock_encoder_, SampleRateHz()).WillOnce(Return(17));
|
||||||
EXPECT_EQ(17, red_->sample_rate_hz());
|
EXPECT_EQ(17, red_->SampleRateHz());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AudioEncoderCopyRedTest, CheckNumChannelsPropagation) {
|
TEST_F(AudioEncoderCopyRedTest, CheckNumChannelsPropagation) {
|
||||||
EXPECT_CALL(mock_encoder_, num_channels()).WillOnce(Return(17));
|
EXPECT_CALL(mock_encoder_, NumChannels()).WillOnce(Return(17));
|
||||||
EXPECT_EQ(17, red_->num_channels());
|
EXPECT_EQ(17, red_->NumChannels());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AudioEncoderCopyRedTest, CheckFrameSizePropagation) {
|
TEST_F(AudioEncoderCopyRedTest, CheckFrameSizePropagation) {
|
||||||
|
@ -1220,7 +1220,7 @@ int16_t ACMGenericCodecWrapper::Encode(
|
|||||||
WriteLockScoped wl(codec_wrapper_lock_);
|
WriteLockScoped wl(codec_wrapper_lock_);
|
||||||
CHECK(!input_.empty());
|
CHECK(!input_.empty());
|
||||||
CHECK(encoder_->Encode(rtp_timestamp_, &input_[0],
|
CHECK(encoder_->Encode(rtp_timestamp_, &input_[0],
|
||||||
input_.size() / encoder_->num_channels(),
|
input_.size() / encoder_->NumChannels(),
|
||||||
2 * MAX_PAYLOAD_SIZE_BYTE, bitstream, encoded_info));
|
2 * MAX_PAYLOAD_SIZE_BYTE, bitstream, encoded_info));
|
||||||
input_.clear();
|
input_.clear();
|
||||||
*bitstream_len_byte = static_cast<int16_t>(encoded_info->encoded_bytes);
|
*bitstream_len_byte = static_cast<int16_t>(encoded_info->encoded_bytes);
|
||||||
@ -1433,7 +1433,7 @@ void ACMGenericCodecWrapper::ResetAudioEncoder() {
|
|||||||
// Attach CNG if needed.
|
// Attach CNG if needed.
|
||||||
// Reverse-lookup from sample rate to complete key-value pair.
|
// Reverse-lookup from sample rate to complete key-value pair.
|
||||||
auto pt_iter =
|
auto pt_iter =
|
||||||
FindSampleRateInMap(&cng_pt_, audio_encoder_->sample_rate_hz());
|
FindSampleRateInMap(&cng_pt_, audio_encoder_->SampleRateHz());
|
||||||
if (acm_codec_params_.enable_dtx && pt_iter != cng_pt_.end()) {
|
if (acm_codec_params_.enable_dtx && pt_iter != cng_pt_.end()) {
|
||||||
AudioEncoderCng::Config config;
|
AudioEncoderCng::Config config;
|
||||||
config.num_channels = acm_codec_params_.codec_inst.channels;
|
config.num_channels = acm_codec_params_.codec_inst.channels;
|
||||||
@ -1475,8 +1475,8 @@ int32_t ACMGenericCodecWrapper::Add10MsData(const uint32_t timestamp,
|
|||||||
const uint8_t audio_channel) {
|
const uint8_t audio_channel) {
|
||||||
WriteLockScoped wl(codec_wrapper_lock_);
|
WriteLockScoped wl(codec_wrapper_lock_);
|
||||||
CHECK(input_.empty());
|
CHECK(input_.empty());
|
||||||
CHECK_EQ(length_per_channel, encoder_->sample_rate_hz() / 100);
|
CHECK_EQ(length_per_channel, encoder_->SampleRateHz() / 100);
|
||||||
for (int i = 0; i < length_per_channel * encoder_->num_channels(); ++i) {
|
for (int i = 0; i < length_per_channel * encoder_->NumChannels(); ++i) {
|
||||||
input_.push_back(data[i]);
|
input_.push_back(data[i]);
|
||||||
}
|
}
|
||||||
rtp_timestamp_ = first_frame_
|
rtp_timestamp_ = first_frame_
|
||||||
@ -1485,13 +1485,13 @@ int32_t ACMGenericCodecWrapper::Add10MsData(const uint32_t timestamp,
|
|||||||
rtc::CheckedDivExact(
|
rtc::CheckedDivExact(
|
||||||
timestamp - last_timestamp_,
|
timestamp - last_timestamp_,
|
||||||
static_cast<uint32_t>(rtc::CheckedDivExact(
|
static_cast<uint32_t>(rtc::CheckedDivExact(
|
||||||
audio_encoder_->sample_rate_hz(),
|
audio_encoder_->SampleRateHz(),
|
||||||
audio_encoder_->rtp_timestamp_rate_hz())));
|
audio_encoder_->RtpTimestampRateHz())));
|
||||||
last_timestamp_ = timestamp;
|
last_timestamp_ = timestamp;
|
||||||
last_rtp_timestamp_ = rtp_timestamp_;
|
last_rtp_timestamp_ = rtp_timestamp_;
|
||||||
first_frame_ = false;
|
first_frame_ = false;
|
||||||
|
|
||||||
CHECK_EQ(audio_channel, encoder_->num_channels());
|
CHECK_EQ(audio_channel, encoder_->NumChannels());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class AudioDecoderTest : public ::testing::Test {
|
|||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
if (audio_encoder_)
|
if (audio_encoder_)
|
||||||
codec_input_rate_hz_ = audio_encoder_->sample_rate_hz();
|
codec_input_rate_hz_ = audio_encoder_->SampleRateHz();
|
||||||
// Create arrays.
|
// Create arrays.
|
||||||
ASSERT_GT(data_length_, 0u) << "The test must set data_length_ > 0";
|
ASSERT_GT(data_length_, 0u) << "The test must set data_length_ > 0";
|
||||||
// Longest encoded data is produced by PCM16b with 2 bytes per sample.
|
// Longest encoded data is produced by PCM16b with 2 bytes per sample.
|
||||||
@ -136,7 +136,7 @@ class AudioDecoderTest : public ::testing::Test {
|
|||||||
size_t input_len_samples,
|
size_t input_len_samples,
|
||||||
uint8_t* output) {
|
uint8_t* output) {
|
||||||
encoded_info_.encoded_bytes = 0;
|
encoded_info_.encoded_bytes = 0;
|
||||||
const size_t samples_per_10ms = audio_encoder_->sample_rate_hz() / 100;
|
const size_t samples_per_10ms = audio_encoder_->SampleRateHz() / 100;
|
||||||
CHECK_EQ(samples_per_10ms * audio_encoder_->Num10MsFramesInNextPacket(),
|
CHECK_EQ(samples_per_10ms * audio_encoder_->Num10MsFramesInNextPacket(),
|
||||||
input_len_samples);
|
input_len_samples);
|
||||||
scoped_ptr<int16_t[]> interleaved_input(
|
scoped_ptr<int16_t[]> interleaved_input(
|
||||||
@ -151,7 +151,7 @@ class AudioDecoderTest : public ::testing::Test {
|
|||||||
interleaved_input.get());
|
interleaved_input.get());
|
||||||
|
|
||||||
EXPECT_TRUE(audio_encoder_->Encode(
|
EXPECT_TRUE(audio_encoder_->Encode(
|
||||||
0, interleaved_input.get(), audio_encoder_->sample_rate_hz() / 100,
|
0, interleaved_input.get(), audio_encoder_->SampleRateHz() / 100,
|
||||||
data_length_ * 2, output, &encoded_info_));
|
data_length_ * 2, output, &encoded_info_));
|
||||||
}
|
}
|
||||||
EXPECT_EQ(payload_type_, encoded_info_.payload_type);
|
EXPECT_EQ(payload_type_, encoded_info_.payload_type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user