Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc

Issue 1725143003: Changed AudioEncoder::Encode to take an rtc::Buffer* instead of uint8_t* and a maximum size. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Reverted unnecessary change to buffer_unittest.cc Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc
diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc
index a194fb98aa427f4806d5a7d2c570f92b99fbc014..ba62d171dcf394a2f92de3e1c68a6cdd7bf04c92 100644
--- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc
+++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc
@@ -47,7 +47,6 @@ class AudioEncoderCopyRedTest : public ::testing::Test {
.WillRepeatedly(Return(sample_rate_hz_));
EXPECT_CALL(mock_encoder_, MaxEncodedBytes())
.WillRepeatedly(Return(kMockMaxEncodedBytes));
- encoded_.resize(red_->MaxEncodedBytes(), 0);
}
void TearDown() override {
@@ -60,10 +59,11 @@ class AudioEncoderCopyRedTest : public ::testing::Test {
void Encode() {
ASSERT_TRUE(red_.get() != NULL);
+ encoded_.Clear();
encoded_info_ = red_->Encode(
timestamp_,
rtc::ArrayView<const int16_t>(audio_, num_audio_samples_10ms),
- encoded_.size(), &encoded_[0]);
+ &encoded_);
timestamp_ += num_audio_samples_10ms;
}
@@ -73,34 +73,11 @@ class AudioEncoderCopyRedTest : public ::testing::Test {
int16_t audio_[kMaxNumSamples];
const int sample_rate_hz_;
size_t num_audio_samples_10ms;
- std::vector<uint8_t> encoded_;
+ rtc::Buffer encoded_;
AudioEncoder::EncodedInfo encoded_info_;
const int red_payload_type_;
};
-class MockEncodeHelper {
- public:
- MockEncodeHelper() : write_payload_(false), payload_(NULL) {
- memset(&info_, 0, sizeof(info_));
- }
-
- AudioEncoder::EncodedInfo Encode(uint32_t timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded) {
- if (write_payload_) {
- RTC_CHECK(encoded);
- RTC_CHECK_LE(info_.encoded_bytes, max_encoded_bytes);
- memcpy(encoded, payload_, info_.encoded_bytes);
- }
- return info_;
- }
-
- AudioEncoder::EncodedInfo info_;
- bool write_payload_;
- uint8_t* payload_;
-};
-
TEST_F(AudioEncoderCopyRedTest, CreateAndDestroy) {
}
@@ -143,7 +120,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckImmediateEncode) {
InSequence s;
MockFunction<void(int check_point_id)> check;
for (int i = 1; i <= 6; ++i) {
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
+ EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _))
.WillRepeatedly(Return(AudioEncoder::EncodedInfo()));
EXPECT_CALL(check, Call(i));
Encode();
@@ -156,10 +133,10 @@ TEST_F(AudioEncoderCopyRedTest, CheckImmediateEncode) {
TEST_F(AudioEncoderCopyRedTest, CheckNoOutput) {
// Start with one Encode() call that will produce output.
static const size_t kEncodedSize = 17;
- AudioEncoder::EncodedInfo info;
- info.encoded_bytes = kEncodedSize;
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
- .WillOnce(Return(info));
+ MockAudioEncoderHelper helper;
+ helper.info_.encoded_bytes = kEncodedSize;
+ EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _))
+ .WillRepeatedly(Invoke(&helper, &MockAudioEncoderHelper::Encode));
Encode();
// First call is a special case, since it does not include a secondary
// payload.
@@ -167,16 +144,12 @@ TEST_F(AudioEncoderCopyRedTest, CheckNoOutput) {
EXPECT_EQ(kEncodedSize, encoded_info_.encoded_bytes);
// Next call to the speech encoder will not produce any output.
- info.encoded_bytes = 0;
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
- .WillOnce(Return(info));
+ helper.info_.encoded_bytes = 0;
Encode();
EXPECT_EQ(0u, encoded_info_.encoded_bytes);
// Final call to the speech encoder will produce output.
- info.encoded_bytes = kEncodedSize;
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
- .WillOnce(Return(info));
+ helper.info_.encoded_bytes = kEncodedSize;
Encode();
EXPECT_EQ(2 * kEncodedSize, encoded_info_.encoded_bytes);
ASSERT_EQ(2u, encoded_info_.redundant.size());
@@ -189,11 +162,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes) {
// of calls.
static const int kNumPackets = 10;
InSequence s;
+ MockAudioEncoderHelper helpers[kNumPackets];
+
for (int encode_size = 1; encode_size <= kNumPackets; ++encode_size) {
- AudioEncoder::EncodedInfo info;
- info.encoded_bytes = encode_size;
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
- .WillOnce(Return(info));
+ helpers[encode_size - 1].info_.encoded_bytes = encode_size;
+ EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _))
+ .WillOnce(Invoke(&helpers[encode_size - 1],
+ &MockAudioEncoderHelper::Encode));
}
// First call is a special case, since it does not include a secondary
@@ -213,13 +188,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes) {
// Checks that the correct timestamps are returned.
TEST_F(AudioEncoderCopyRedTest, CheckTimestamps) {
- MockEncodeHelper helper;
+ MockAudioEncoderHelper helper;
helper.info_.encoded_bytes = 17;
helper.info_.encoded_timestamp = timestamp_;
uint32_t primary_timestamp = timestamp_;
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
- .WillRepeatedly(Invoke(&helper, &MockEncodeHelper::Encode));
+ EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _))
+ .WillRepeatedly(Invoke(&helper, &MockAudioEncoderHelper::Encode));
// First call is a special case, since it does not include a secondary
// payload.
@@ -240,7 +215,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckTimestamps) {
TEST_F(AudioEncoderCopyRedTest, CheckPayloads) {
// Let the mock encoder write payloads with increasing values. The first
// payload will have values 0, 1, 2, ..., kPayloadLenBytes - 1.
- MockEncodeHelper helper;
+ MockAudioEncoderHelper helper;
static const size_t kPayloadLenBytes = 5;
helper.info_.encoded_bytes = kPayloadLenBytes;
helper.write_payload_ = true;
@@ -249,21 +224,21 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloads) {
payload[i] = i;
}
helper.payload_ = payload;
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
- .WillRepeatedly(Invoke(&helper, &MockEncodeHelper::Encode));
+ EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _))
+ .WillRepeatedly(Invoke(&helper, &MockAudioEncoderHelper::Encode));
// First call is a special case, since it does not include a secondary
// payload.
Encode();
EXPECT_EQ(kPayloadLenBytes, encoded_info_.encoded_bytes);
for (size_t i = 0; i < kPayloadLenBytes; ++i) {
- EXPECT_EQ(i, encoded_[i]);
+ EXPECT_EQ(i, encoded_.data()[i]);
}
for (int j = 0; j < 5; ++j) {
// Increment all values of the payload by 10.
for (size_t i = 0; i < kPayloadLenBytes; ++i)
- helper.payload_[i] += 10;
+ payload[i] += 10;
Encode();
ASSERT_EQ(2u, encoded_info_.redundant.size());
@@ -271,9 +246,9 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloads) {
EXPECT_EQ(kPayloadLenBytes, encoded_info_.redundant[1].encoded_bytes);
for (size_t i = 0; i < kPayloadLenBytes; ++i) {
// Check primary payload.
- EXPECT_EQ((j + 1) * 10 + i, encoded_[i]);
+ EXPECT_EQ((j + 1) * 10 + i, encoded_.data()[i]);
// Check secondary payload.
- EXPECT_EQ(j * 10 + i, encoded_[i + kPayloadLenBytes]);
+ EXPECT_EQ(j * 10 + i, encoded_.data()[i + kPayloadLenBytes]);
}
}
}
@@ -281,13 +256,13 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloads) {
// Checks correct propagation of payload type.
// Checks that the correct timestamps are returned.
TEST_F(AudioEncoderCopyRedTest, CheckPayloadType) {
- MockEncodeHelper helper;
+ MockAudioEncoderHelper helper;
helper.info_.encoded_bytes = 17;
const int primary_payload_type = red_payload_type_ + 1;
helper.info_.payload_type = primary_payload_type;
- EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _))
- .WillRepeatedly(Invoke(&helper, &MockEncodeHelper::Encode));
+ EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _))
+ .WillRepeatedly(Invoke(&helper, &MockAudioEncoderHelper::Encode));
// First call is a special case, since it does not include a secondary
// payload.

Powered by Google App Engine
This is Rietveld 408576698