1/* 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#include "testing/gtest/include/gtest/gtest.h" 12#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" 13#include "webrtc/modules/audio_coding/acm2/codec_manager.h" 14#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" 15 16namespace webrtc { 17namespace acm2 { 18 19using ::testing::Return; 20 21namespace { 22 23// Create a MockAudioEncoder with some reasonable default behavior. 24rtc::scoped_ptr<MockAudioEncoder> CreateMockEncoder() { 25 auto enc = rtc_make_scoped_ptr(new MockAudioEncoder); 26 EXPECT_CALL(*enc, SampleRateHz()).WillRepeatedly(Return(8000)); 27 EXPECT_CALL(*enc, NumChannels()).WillRepeatedly(Return(1)); 28 EXPECT_CALL(*enc, Max10MsFramesInAPacket()).WillRepeatedly(Return(1)); 29 EXPECT_CALL(*enc, Die()); 30 return enc; 31} 32 33} // namespace 34 35TEST(CodecManagerTest, ExternalEncoderFec) { 36 auto enc0 = CreateMockEncoder(); 37 auto enc1 = CreateMockEncoder(); 38 { 39 ::testing::InSequence s; 40 EXPECT_CALL(*enc0, SetFec(false)).WillOnce(Return(true)); 41 EXPECT_CALL(*enc0, Mark("A")); 42 EXPECT_CALL(*enc0, SetFec(true)).WillOnce(Return(true)); 43 EXPECT_CALL(*enc1, SetFec(true)).WillOnce(Return(true)); 44 EXPECT_CALL(*enc1, SetFec(false)).WillOnce(Return(true)); 45 EXPECT_CALL(*enc0, Mark("B")); 46 EXPECT_CALL(*enc0, SetFec(false)).WillOnce(Return(true)); 47 } 48 49 CodecManager cm; 50 RentACodec rac; 51 EXPECT_FALSE(cm.GetStackParams()->use_codec_fec); 52 cm.GetStackParams()->speech_encoder = enc0.get(); 53 EXPECT_TRUE(rac.RentEncoderStack(cm.GetStackParams())); 54 EXPECT_FALSE(cm.GetStackParams()->use_codec_fec); 55 enc0->Mark("A"); 56 EXPECT_EQ(true, cm.SetCodecFEC(true)); 57 EXPECT_TRUE(rac.RentEncoderStack(cm.GetStackParams())); 58 EXPECT_TRUE(cm.GetStackParams()->use_codec_fec); 59 cm.GetStackParams()->speech_encoder = enc1.get(); 60 EXPECT_TRUE(rac.RentEncoderStack(cm.GetStackParams())); 61 EXPECT_TRUE(cm.GetStackParams()->use_codec_fec); 62 63 EXPECT_EQ(true, cm.SetCodecFEC(false)); 64 EXPECT_TRUE(rac.RentEncoderStack(cm.GetStackParams())); 65 enc0->Mark("B"); 66 EXPECT_FALSE(cm.GetStackParams()->use_codec_fec); 67 cm.GetStackParams()->speech_encoder = enc0.get(); 68 EXPECT_TRUE(rac.RentEncoderStack(cm.GetStackParams())); 69 EXPECT_FALSE(cm.GetStackParams()->use_codec_fec); 70} 71 72} // namespace acm2 73} // namespace webrtc 74