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

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine_unittest.cc

Issue 1728503002: Replace scoped_ptr with unique_ptr in webrtc/media/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@up1
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | webrtc/media/sctp/sctpdataengine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2008 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
11 #include <memory>
12
11 #include "webrtc/pc/channel.h" 13 #include "webrtc/pc/channel.h"
12 #include "webrtc/base/arraysize.h" 14 #include "webrtc/base/arraysize.h"
13 #include "webrtc/base/byteorder.h" 15 #include "webrtc/base/byteorder.h"
14 #include "webrtc/base/gunit.h" 16 #include "webrtc/base/gunit.h"
15 #include "webrtc/call.h" 17 #include "webrtc/call.h"
16 #include "webrtc/p2p/base/faketransportcontroller.h" 18 #include "webrtc/p2p/base/faketransportcontroller.h"
17 #include "webrtc/test/field_trial.h" 19 #include "webrtc/test/field_trial.h"
18 #include "webrtc/media/base/constants.h" 20 #include "webrtc/media/base/constants.h"
19 #include "webrtc/media/base/fakemediaengine.h" 21 #include "webrtc/media/base/fakemediaengine.h"
20 #include "webrtc/media/base/fakenetworkinterface.h" 22 #include "webrtc/media/base/fakenetworkinterface.h"
(...skipping 2754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2775 webrtc::AgcConfig config = {0}; 2777 webrtc::AgcConfig config = {0};
2776 EXPECT_EQ(0, voe_.GetAgcConfig(config)); 2778 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2777 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv); 2779 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2778 EXPECT_EQ(set_config.digitalCompressionGaindB, 2780 EXPECT_EQ(set_config.digitalCompressionGaindB,
2779 config.digitalCompressionGaindB); 2781 config.digitalCompressionGaindB);
2780 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable); 2782 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2781 } 2783 }
2782 2784
2783 TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { 2785 TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2784 EXPECT_TRUE(SetupEngineWithSendStream()); 2786 EXPECT_TRUE(SetupEngineWithSendStream());
2785 rtc::scoped_ptr<cricket::WebRtcVoiceMediaChannel> channel1( 2787 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel1(
2786 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel( 2788 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel(
2787 &call_, cricket::MediaConfig(), cricket::AudioOptions()))); 2789 &call_, cricket::MediaConfig(), cricket::AudioOptions())));
2788 rtc::scoped_ptr<cricket::WebRtcVoiceMediaChannel> channel2( 2790 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel2(
2789 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel( 2791 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel(
2790 &call_, cricket::MediaConfig(), cricket::AudioOptions()))); 2792 &call_, cricket::MediaConfig(), cricket::AudioOptions())));
2791 2793
2792 // Have to add a stream to make SetSend work. 2794 // Have to add a stream to make SetSend work.
2793 cricket::StreamParams stream1; 2795 cricket::StreamParams stream1;
2794 stream1.ssrcs.push_back(1); 2796 stream1.ssrcs.push_back(1);
2795 channel1->AddSendStream(stream1); 2797 channel1->AddSendStream(stream1);
2796 cricket::StreamParams stream2; 2798 cricket::StreamParams stream2;
2797 stream2.ssrcs.push_back(2); 2799 stream2.ssrcs.push_back(2);
2798 channel2->AddSendStream(stream2); 2800 channel2->AddSendStream(stream2);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 EXPECT_TRUE(ec_enabled); 2880 EXPECT_TRUE(ec_enabled);
2879 EXPECT_FALSE(agc_enabled); 2881 EXPECT_FALSE(agc_enabled);
2880 EXPECT_FALSE(ns_enabled); 2882 EXPECT_FALSE(ns_enabled);
2881 } 2883 }
2882 2884
2883 // This test verifies DSCP settings are properly applied on voice media channel. 2885 // This test verifies DSCP settings are properly applied on voice media channel.
2884 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) { 2886 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
2885 EXPECT_TRUE(SetupEngineWithSendStream()); 2887 EXPECT_TRUE(SetupEngineWithSendStream());
2886 cricket::FakeNetworkInterface network_interface; 2888 cricket::FakeNetworkInterface network_interface;
2887 cricket::MediaConfig config; 2889 cricket::MediaConfig config;
2888 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel; 2890 std::unique_ptr<cricket::VoiceMediaChannel> channel;
2889 2891
2890 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions())); 2892 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions()));
2891 channel->SetInterface(&network_interface); 2893 channel->SetInterface(&network_interface);
2892 // Default value when DSCP is disabled should be DSCP_DEFAULT. 2894 // Default value when DSCP is disabled should be DSCP_DEFAULT.
2893 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp()); 2895 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp());
2894 2896
2895 config.enable_dscp = true; 2897 config.enable_dscp = true;
2896 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions())); 2898 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions()));
2897 channel->SetInterface(&network_interface); 2899 channel->SetInterface(&network_interface);
2898 EXPECT_EQ(rtc::DSCP_EF, network_interface.dscp()); 2900 EXPECT_EQ(rtc::DSCP_EF, network_interface.dscp());
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
3106 // So we force the |recv_ch| to associate with a non-default channel. 3108 // So we force the |recv_ch| to associate with a non-default channel.
3107 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch)); 3109 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch));
3108 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch); 3110 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch);
3109 3111
3110 EXPECT_TRUE(channel_->RemoveSendStream(2)); 3112 EXPECT_TRUE(channel_->RemoveSendStream(2));
3111 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1); 3113 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1);
3112 } 3114 }
3113 3115
3114 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSink) { 3116 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSink) {
3115 EXPECT_TRUE(SetupEngine()); 3117 EXPECT_TRUE(SetupEngine());
3116 rtc::scoped_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink()); 3118 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink());
3117 rtc::scoped_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink()); 3119 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink());
3118 3120
3119 // Setting the sink before a recv stream exists should do nothing. 3121 // Setting the sink before a recv stream exists should do nothing.
3120 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_1)); 3122 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_1));
3121 EXPECT_TRUE( 3123 EXPECT_TRUE(
3122 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1))); 3124 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1)));
3123 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); 3125 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink());
3124 3126
3125 // Now try actually setting the sink. 3127 // Now try actually setting the sink.
3126 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_2)); 3128 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_2));
3127 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink()); 3129 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink());
3128 3130
3129 // Now try resetting it. 3131 // Now try resetting it.
3130 channel_->SetRawAudioSink(kSsrc1, nullptr); 3132 channel_->SetRawAudioSink(kSsrc1, nullptr);
3131 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); 3133 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink());
3132 } 3134 }
3133 3135
3134 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) { 3136 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) {
3135 EXPECT_TRUE(SetupEngine()); 3137 EXPECT_TRUE(SetupEngine());
3136 rtc::scoped_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink()); 3138 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink());
3137 rtc::scoped_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink()); 3139 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink());
3138 3140
3139 // Should be able to set a default sink even when no stream exists. 3141 // Should be able to set a default sink even when no stream exists.
3140 channel_->SetRawAudioSink(0, std::move(fake_sink_1)); 3142 channel_->SetRawAudioSink(0, std::move(fake_sink_1));
3141 3143
3142 // Create default channel and ensure it's assigned the default sink. 3144 // Create default channel and ensure it's assigned the default sink.
3143 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3145 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3144 EXPECT_NE(nullptr, GetRecvStream(0x01).sink()); 3146 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3145 3147
3146 // Try resetting the default sink. 3148 // Try resetting the default sink.
3147 channel_->SetRawAudioSink(0, nullptr); 3149 channel_->SetRawAudioSink(0, nullptr);
3148 EXPECT_EQ(nullptr, GetRecvStream(0x01).sink()); 3150 EXPECT_EQ(nullptr, GetRecvStream(0x01).sink());
3149 3151
3150 // Try setting the default sink while the default stream exists. 3152 // Try setting the default sink while the default stream exists.
3151 channel_->SetRawAudioSink(0, std::move(fake_sink_2)); 3153 channel_->SetRawAudioSink(0, std::move(fake_sink_2));
3152 EXPECT_NE(nullptr, GetRecvStream(0x01).sink()); 3154 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3153 3155
3154 // If we remove and add a default stream, it should get the same sink. 3156 // If we remove and add a default stream, it should get the same sink.
3155 EXPECT_TRUE(channel_->RemoveRecvStream(0x01)); 3157 EXPECT_TRUE(channel_->RemoveRecvStream(0x01));
3156 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3158 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3157 EXPECT_NE(nullptr, GetRecvStream(0x01).sink()); 3159 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3158 } 3160 }
3159 3161
3160 // Tests that the library initializes and shuts down properly. 3162 // Tests that the library initializes and shuts down properly.
3161 TEST(WebRtcVoiceEngineTest, StartupShutdown) { 3163 TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3162 cricket::WebRtcVoiceEngine engine; 3164 cricket::WebRtcVoiceEngine engine;
3163 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3165 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3164 rtc::scoped_ptr<webrtc::Call> call( 3166 std::unique_ptr<webrtc::Call> call(
3165 webrtc::Call::Create(webrtc::Call::Config())); 3167 webrtc::Call::Create(webrtc::Call::Config()));
3166 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3168 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3167 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3169 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3168 EXPECT_TRUE(channel != nullptr); 3170 EXPECT_TRUE(channel != nullptr);
3169 delete channel; 3171 delete channel;
3170 engine.Terminate(); 3172 engine.Terminate();
3171 3173
3172 // Reinit to catch regression where VoiceEngineObserver reference is lost 3174 // Reinit to catch regression where VoiceEngineObserver reference is lost
3173 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3175 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3174 engine.Terminate(); 3176 engine.Terminate();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3256 EXPECT_EQ("1", it->params.find("useinbandfec")->second); 3258 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
3257 } 3259 }
3258 } 3260 }
3259 engine.Terminate(); 3261 engine.Terminate();
3260 } 3262 }
3261 3263
3262 // Tests that VoE supports at least 32 channels 3264 // Tests that VoE supports at least 32 channels
3263 TEST(WebRtcVoiceEngineTest, Has32Channels) { 3265 TEST(WebRtcVoiceEngineTest, Has32Channels) {
3264 cricket::WebRtcVoiceEngine engine; 3266 cricket::WebRtcVoiceEngine engine;
3265 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3267 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3266 rtc::scoped_ptr<webrtc::Call> call( 3268 std::unique_ptr<webrtc::Call> call(
3267 webrtc::Call::Create(webrtc::Call::Config())); 3269 webrtc::Call::Create(webrtc::Call::Config()));
3268 3270
3269 cricket::VoiceMediaChannel* channels[32]; 3271 cricket::VoiceMediaChannel* channels[32];
3270 int num_channels = 0; 3272 int num_channels = 0;
3271 while (num_channels < arraysize(channels)) { 3273 while (num_channels < arraysize(channels)) {
3272 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3274 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3273 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3275 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3274 if (!channel) 3276 if (!channel)
3275 break; 3277 break;
3276 channels[num_channels++] = channel; 3278 channels[num_channels++] = channel;
3277 } 3279 }
3278 3280
3279 int expected = arraysize(channels); 3281 int expected = arraysize(channels);
3280 EXPECT_EQ(expected, num_channels); 3282 EXPECT_EQ(expected, num_channels);
3281 3283
3282 while (num_channels > 0) { 3284 while (num_channels > 0) {
3283 delete channels[--num_channels]; 3285 delete channels[--num_channels];
3284 } 3286 }
3285 engine.Terminate(); 3287 engine.Terminate();
3286 } 3288 }
3287 3289
3288 // Test that we set our preferred codecs properly. 3290 // Test that we set our preferred codecs properly.
3289 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3291 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3290 cricket::WebRtcVoiceEngine engine; 3292 cricket::WebRtcVoiceEngine engine;
3291 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3293 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3292 rtc::scoped_ptr<webrtc::Call> call( 3294 std::unique_ptr<webrtc::Call> call(
3293 webrtc::Call::Create(webrtc::Call::Config())); 3295 webrtc::Call::Create(webrtc::Call::Config()));
3294 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3296 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3295 cricket::AudioOptions(), call.get()); 3297 cricket::AudioOptions(), call.get());
3296 cricket::AudioRecvParameters parameters; 3298 cricket::AudioRecvParameters parameters;
3297 parameters.codecs = engine.codecs(); 3299 parameters.codecs = engine.codecs();
3298 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3300 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3299 } 3301 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | webrtc/media/sctp/sctpdataengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698