Add new methods to AudioEncoder interface
The following three methods are added: rtp_timestamp_rate_hz() SetTargetBitrate() SetProjectedPacketLossRate() Default implementations are provided, and a few overrides are implemented. AudioEncoderCopyRed and AudioEncoderCng propagate the new methods to the underlying speech codec. BUG=3926 COAUTHOR:kwiberg@webrtc.org R=tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/34049004 Cr-Commit-Position: refs/heads/master@{#8171} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8171 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -74,6 +74,10 @@ int AudioEncoderCng::sample_rate_hz() const {
|
||||
return sample_rate_hz_;
|
||||
}
|
||||
|
||||
int AudioEncoderCng::rtp_timestamp_rate_hz() const {
|
||||
return speech_encoder_->rtp_timestamp_rate_hz();
|
||||
}
|
||||
|
||||
int AudioEncoderCng::num_channels() const {
|
||||
return num_channels_;
|
||||
}
|
||||
@ -86,7 +90,17 @@ int AudioEncoderCng::Max10MsFramesInAPacket() const {
|
||||
return speech_encoder_->Max10MsFramesInAPacket();
|
||||
}
|
||||
|
||||
bool AudioEncoderCng::EncodeInternal(uint32_t timestamp,
|
||||
void AudioEncoderCng::SetTargetBitrate(int bits_per_second) {
|
||||
speech_encoder_->SetTargetBitrate(bits_per_second);
|
||||
}
|
||||
|
||||
void AudioEncoderCng::SetProjectedPacketLossRate(double fraction) {
|
||||
DCHECK_GE(fraction, 0.0);
|
||||
DCHECK_LE(fraction, 1.0);
|
||||
speech_encoder_->SetProjectedPacketLossRate(fraction);
|
||||
}
|
||||
|
||||
bool AudioEncoderCng::EncodeInternal(uint32_t rtp_timestamp,
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded,
|
||||
@ -99,7 +113,7 @@ bool AudioEncoderCng::EncodeInternal(uint32_t timestamp,
|
||||
const int num_samples = sample_rate_hz() / 100 * num_channels();
|
||||
if (speech_buffer_.empty()) {
|
||||
CHECK_EQ(frames_in_buffer_, 0);
|
||||
first_timestamp_in_buffer_ = timestamp;
|
||||
first_timestamp_in_buffer_ = rtp_timestamp;
|
||||
}
|
||||
for (int i = 0; i < num_samples; ++i) {
|
||||
speech_buffer_.push_back(audio[i]);
|
||||
|
||||
@ -196,6 +196,18 @@ TEST_F(AudioEncoderCngTest, CheckFrameSizePropagation) {
|
||||
EXPECT_EQ(17, cng_->Num10MsFramesInNextPacket());
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCngTest, CheckChangeBitratePropagation) {
|
||||
CreateCng();
|
||||
EXPECT_CALL(mock_encoder_, SetTargetBitrate(4711));
|
||||
cng_->SetTargetBitrate(4711);
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCngTest, CheckProjectedPacketLossRatePropagation) {
|
||||
CreateCng();
|
||||
EXPECT_CALL(mock_encoder_, SetProjectedPacketLossRate(0.5));
|
||||
cng_->SetProjectedPacketLossRate(0.5);
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCngTest, EncodeCallsVad) {
|
||||
EXPECT_CALL(mock_encoder_, Num10MsFramesInNextPacket())
|
||||
.WillRepeatedly(Return(1));
|
||||
|
||||
@ -49,11 +49,14 @@ class AudioEncoderCng : public AudioEncoder {
|
||||
|
||||
virtual int sample_rate_hz() const OVERRIDE;
|
||||
virtual int num_channels() const OVERRIDE;
|
||||
int rtp_timestamp_rate_hz() const override;
|
||||
virtual int Num10MsFramesInNextPacket() const OVERRIDE;
|
||||
virtual int Max10MsFramesInAPacket() const OVERRIDE;
|
||||
void SetTargetBitrate(int bits_per_second) override;
|
||||
void SetProjectedPacketLossRate(double fraction) override;
|
||||
|
||||
protected:
|
||||
virtual bool EncodeInternal(uint32_t timestamp,
|
||||
virtual bool EncodeInternal(uint32_t rtp_timestamp,
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded,
|
||||
|
||||
Reference in New Issue
Block a user