| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 RentACodec::StackParameters param; | 35 RentACodec::StackParameters param; |
| 36 param.use_cng = true; | 36 param.use_cng = true; |
| 37 param.speech_encoder = speech_encoder_; | 37 param.speech_encoder = speech_encoder_; |
| 38 encoder_ = rent_a_codec_.RentEncoderStack(¶m); | 38 encoder_ = rent_a_codec_.RentEncoderStack(¶m); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void EncodeAndVerify(size_t expected_out_length, | 41 void EncodeAndVerify(size_t expected_out_length, |
| 42 uint32_t expected_timestamp, | 42 uint32_t expected_timestamp, |
| 43 int expected_payload_type, | 43 int expected_payload_type, |
| 44 int expected_send_even_if_empty) { | 44 int expected_send_even_if_empty) { |
| 45 uint8_t out[kPacketSizeSamples]; | 45 rtc::Buffer out; |
| 46 AudioEncoder::EncodedInfo encoded_info; | 46 AudioEncoder::EncodedInfo encoded_info; |
| 47 encoded_info = | 47 encoded_info = |
| 48 encoder_->Encode(timestamp_, kZeroData, kPacketSizeSamples, out); | 48 encoder_->Encode(timestamp_, kZeroData, &out); |
| 49 timestamp_ += kDataLengthSamples; | 49 timestamp_ += kDataLengthSamples; |
| 50 EXPECT_TRUE(encoded_info.redundant.empty()); | 50 EXPECT_TRUE(encoded_info.redundant.empty()); |
| 51 EXPECT_EQ(expected_out_length, encoded_info.encoded_bytes); | 51 EXPECT_EQ(expected_out_length, encoded_info.encoded_bytes); |
| 52 EXPECT_EQ(expected_timestamp, encoded_info.encoded_timestamp); | 52 EXPECT_EQ(expected_timestamp, encoded_info.encoded_timestamp); |
| 53 if (expected_payload_type >= 0) | 53 if (expected_payload_type >= 0) |
| 54 EXPECT_EQ(expected_payload_type, encoded_info.payload_type); | 54 EXPECT_EQ(expected_payload_type, encoded_info.payload_type); |
| 55 if (expected_send_even_if_empty >= 0) | 55 if (expected_send_even_if_empty >= 0) |
| 56 EXPECT_EQ(static_cast<bool>(expected_send_even_if_empty), | 56 EXPECT_EQ(static_cast<bool>(expected_send_even_if_empty), |
| 57 encoded_info.send_even_if_empty); | 57 encoded_info.send_even_if_empty); |
| 58 } | 58 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 .WillRepeatedly(Return(kSampleRateHz)); | 108 .WillRepeatedly(Return(kSampleRateHz)); |
| 109 EXPECT_CALL(external_encoder, NumChannels()).WillRepeatedly(Return(1)); | 109 EXPECT_CALL(external_encoder, NumChannels()).WillRepeatedly(Return(1)); |
| 110 EXPECT_CALL(external_encoder, SetFec(false)).WillRepeatedly(Return(true)); | 110 EXPECT_CALL(external_encoder, SetFec(false)).WillRepeatedly(Return(true)); |
| 111 | 111 |
| 112 RentACodec rac; | 112 RentACodec rac; |
| 113 RentACodec::StackParameters param; | 113 RentACodec::StackParameters param; |
| 114 param.speech_encoder = &external_encoder; | 114 param.speech_encoder = &external_encoder; |
| 115 EXPECT_EQ(&external_encoder, rac.RentEncoderStack(¶m)); | 115 EXPECT_EQ(&external_encoder, rac.RentEncoderStack(¶m)); |
| 116 const int kPacketSizeSamples = kSampleRateHz / 100; | 116 const int kPacketSizeSamples = kSampleRateHz / 100; |
| 117 int16_t audio[kPacketSizeSamples] = {0}; | 117 int16_t audio[kPacketSizeSamples] = {0}; |
| 118 uint8_t encoded[kPacketSizeSamples]; | 118 rtc::Buffer encoded; |
| 119 AudioEncoder::EncodedInfo info; | 119 AudioEncoder::EncodedInfo info; |
| 120 | 120 |
| 121 { | 121 { |
| 122 ::testing::InSequence s; | 122 ::testing::InSequence s; |
| 123 info.encoded_timestamp = 0; | 123 info.encoded_timestamp = 0; |
| 124 EXPECT_CALL(external_encoder, | 124 EXPECT_CALL(external_encoder, |
| 125 EncodeInternal(0, rtc::ArrayView<const int16_t>(audio), | 125 EncodeInternal(0, rtc::ArrayView<const int16_t>(audio), |
| 126 arraysize(encoded), encoded)) | 126 &encoded)) |
| 127 .WillOnce(Return(info)); | 127 .WillOnce(Return(info)); |
| 128 EXPECT_CALL(external_encoder, Mark("A")); | 128 EXPECT_CALL(external_encoder, Mark("A")); |
| 129 EXPECT_CALL(external_encoder, Mark("B")); | 129 EXPECT_CALL(external_encoder, Mark("B")); |
| 130 info.encoded_timestamp = 2; | 130 info.encoded_timestamp = 2; |
| 131 EXPECT_CALL(external_encoder, | 131 EXPECT_CALL(external_encoder, |
| 132 EncodeInternal(2, rtc::ArrayView<const int16_t>(audio), | 132 EncodeInternal(2, rtc::ArrayView<const int16_t>(audio), |
| 133 arraysize(encoded), encoded)) | 133 &encoded)) |
| 134 .WillOnce(Return(info)); | 134 .WillOnce(Return(info)); |
| 135 EXPECT_CALL(external_encoder, Die()); | 135 EXPECT_CALL(external_encoder, Die()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 info = external_encoder.Encode(0, audio, arraysize(encoded), encoded); | 138 info = external_encoder.Encode(0, audio, &encoded); |
| 139 EXPECT_EQ(0u, info.encoded_timestamp); | 139 EXPECT_EQ(0u, info.encoded_timestamp); |
| 140 external_encoder.Mark("A"); | 140 external_encoder.Mark("A"); |
| 141 | 141 |
| 142 // Change to internal encoder. | 142 // Change to internal encoder. |
| 143 CodecInst codec_inst = kDefaultCodecInst; | 143 CodecInst codec_inst = kDefaultCodecInst; |
| 144 codec_inst.pacsize = kPacketSizeSamples; | 144 codec_inst.pacsize = kPacketSizeSamples; |
| 145 param.speech_encoder = rac.RentEncoder(codec_inst); | 145 param.speech_encoder = rac.RentEncoder(codec_inst); |
| 146 ASSERT_TRUE(param.speech_encoder); | 146 ASSERT_TRUE(param.speech_encoder); |
| 147 EXPECT_EQ(param.speech_encoder, rac.RentEncoderStack(¶m)); | 147 EXPECT_EQ(param.speech_encoder, rac.RentEncoderStack(¶m)); |
| 148 | 148 |
| 149 // Don't expect any more calls to the external encoder. | 149 // Don't expect any more calls to the external encoder. |
| 150 info = param.speech_encoder->Encode(1, audio, arraysize(encoded), encoded); | 150 info = param.speech_encoder->Encode(1, audio, &encoded); |
| 151 external_encoder.Mark("B"); | 151 external_encoder.Mark("B"); |
| 152 | 152 |
| 153 // Change back to external encoder again. | 153 // Change back to external encoder again. |
| 154 param.speech_encoder = &external_encoder; | 154 param.speech_encoder = &external_encoder; |
| 155 EXPECT_EQ(&external_encoder, rac.RentEncoderStack(¶m)); | 155 EXPECT_EQ(&external_encoder, rac.RentEncoderStack(¶m)); |
| 156 info = external_encoder.Encode(2, audio, arraysize(encoded), encoded); | 156 info = external_encoder.Encode(2, audio, &encoded); |
| 157 EXPECT_EQ(2u, info.encoded_timestamp); | 157 EXPECT_EQ(2u, info.encoded_timestamp); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Verify that the speech encoder's Reset method is called when CNG or RED | 160 // Verify that the speech encoder's Reset method is called when CNG or RED |
| 161 // (or both) are switched on, but not when they're switched off. | 161 // (or both) are switched on, but not when they're switched off. |
| 162 void TestCngAndRedResetSpeechEncoder(bool use_cng, bool use_red) { | 162 void TestCngAndRedResetSpeechEncoder(bool use_cng, bool use_red) { |
| 163 MockAudioEncoder speech_encoder; | 163 MockAudioEncoder speech_encoder; |
| 164 EXPECT_CALL(speech_encoder, NumChannels()).WillRepeatedly(Return(1)); | 164 EXPECT_CALL(speech_encoder, NumChannels()).WillRepeatedly(Return(1)); |
| 165 EXPECT_CALL(speech_encoder, Max10MsFramesInAPacket()) | 165 EXPECT_CALL(speech_encoder, Max10MsFramesInAPacket()) |
| 166 .WillRepeatedly(Return(2)); | 166 .WillRepeatedly(Return(2)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 213 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 214 TEST(RentACodecTest, RentEncoderStackWithoutSpeechEncoder) { | 214 TEST(RentACodecTest, RentEncoderStackWithoutSpeechEncoder) { |
| 215 RentACodec::StackParameters sp; | 215 RentACodec::StackParameters sp; |
| 216 EXPECT_EQ(nullptr, sp.speech_encoder); | 216 EXPECT_EQ(nullptr, sp.speech_encoder); |
| 217 EXPECT_DEATH(RentACodec().RentEncoderStack(&sp), ""); | 217 EXPECT_DEATH(RentACodec().RentEncoderStack(&sp), ""); |
| 218 } | 218 } |
| 219 #endif | 219 #endif |
| 220 | 220 |
| 221 } // namespace acm2 | 221 } // namespace acm2 |
| 222 } // namespace webrtc | 222 } // namespace webrtc |
| OLD | NEW |