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

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

Issue 1551813002: Storing raw audio sink for default audio track. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removing obsolete "RefCountedObject" and adding an RTC_DCHECK. Created 4 years, 11 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 | « talk/media/webrtc/webrtcvoiceengine.cc ('k') | webrtc/audio_receive_stream.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 * libjingle 2 * libjingle
3 * Copyright 2008 Google Inc. 3 * Copyright 2008 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 engine, // base 65 engine, // base
66 engine, // codec 66 engine, // codec
67 engine, // hw 67 engine, // hw
68 engine, // network 68 engine, // network
69 engine, // rtp 69 engine, // rtp
70 engine) { // volume 70 engine) { // volume
71 } 71 }
72 }; 72 };
73 } // namespace 73 } // namespace
74 74
75 class FakeAudioSink : public webrtc::AudioSinkInterface {
76 public:
77 void OnData(const Data& audio) override {}
78 };
79
75 class WebRtcVoiceEngineTestFake : public testing::Test { 80 class WebRtcVoiceEngineTestFake : public testing::Test {
76 public: 81 public:
77 WebRtcVoiceEngineTestFake() 82 WebRtcVoiceEngineTestFake()
78 : call_(webrtc::Call::Config()), 83 : call_(webrtc::Call::Config()),
79 engine_(new FakeVoEWrapper(&voe_)), 84 engine_(new FakeVoEWrapper(&voe_)),
80 channel_(nullptr) { 85 channel_(nullptr) {
81 send_parameters_.codecs.push_back(kPcmuCodec); 86 send_parameters_.codecs.push_back(kPcmuCodec);
82 recv_parameters_.codecs.push_back(kPcmuCodec); 87 recv_parameters_.codecs.push_back(kPcmuCodec);
83 } 88 }
84 bool SetupEngine() { 89 bool SetupEngine() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 delete channel_; 123 delete channel_;
119 engine_.Terminate(); 124 engine_.Terminate();
120 } 125 }
121 126
122 const cricket::FakeAudioSendStream& GetSendStream(uint32_t ssrc) { 127 const cricket::FakeAudioSendStream& GetSendStream(uint32_t ssrc) {
123 const auto* send_stream = call_.GetAudioSendStream(ssrc); 128 const auto* send_stream = call_.GetAudioSendStream(ssrc);
124 EXPECT_TRUE(send_stream); 129 EXPECT_TRUE(send_stream);
125 return *send_stream; 130 return *send_stream;
126 } 131 }
127 132
133 const cricket::FakeAudioReceiveStream& GetRecvStream(uint32_t ssrc) {
134 const auto* recv_stream = call_.GetAudioReceiveStream(ssrc);
135 EXPECT_TRUE(recv_stream);
136 return *recv_stream;
137 }
138
128 const webrtc::AudioSendStream::Config& GetSendStreamConfig(uint32_t ssrc) { 139 const webrtc::AudioSendStream::Config& GetSendStreamConfig(uint32_t ssrc) {
129 const auto* send_stream = call_.GetAudioSendStream(ssrc); 140 const auto* send_stream = call_.GetAudioSendStream(ssrc);
130 EXPECT_TRUE(send_stream); 141 EXPECT_TRUE(send_stream);
131 return send_stream->GetConfig(); 142 return send_stream->GetConfig();
132 } 143 }
133 144
134 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) { 145 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) {
135 const auto* recv_stream = call_.GetAudioReceiveStream(ssrc); 146 const auto* recv_stream = call_.GetAudioReceiveStream(ssrc);
136 EXPECT_TRUE(recv_stream); 147 EXPECT_TRUE(recv_stream);
137 return recv_stream->GetConfig(); 148 return recv_stream->GetConfig();
(...skipping 2960 matching lines...) Expand 10 before | Expand all | Expand 10 after
3098 // channel of |recv_ch|.This is not a common case, since, normally, only the 3109 // channel of |recv_ch|.This is not a common case, since, normally, only the
3099 // default channel can be associated. However, the default is not deletable. 3110 // default channel can be associated. However, the default is not deletable.
3100 // So we force the |recv_ch| to associate with a non-default channel. 3111 // So we force the |recv_ch| to associate with a non-default channel.
3101 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch)); 3112 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch));
3102 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch); 3113 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch);
3103 3114
3104 EXPECT_TRUE(channel_->RemoveSendStream(2)); 3115 EXPECT_TRUE(channel_->RemoveSendStream(2));
3105 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1); 3116 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1);
3106 } 3117 }
3107 3118
3119 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSink) {
3120 EXPECT_TRUE(SetupEngine());
3121 rtc::scoped_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink());
3122 rtc::scoped_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink());
3123
3124 // Setting the sink before a recv stream exists should do nothing.
3125 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_1));
3126 EXPECT_TRUE(
3127 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1)));
3128 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink());
3129
3130 // Now try actually setting the sink.
3131 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_2));
3132 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink());
3133
3134 // Now try resetting it.
3135 channel_->SetRawAudioSink(kSsrc1, nullptr);
3136 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink());
3137 }
3138
3139 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) {
3140 EXPECT_TRUE(SetupEngine());
3141 rtc::scoped_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink());
3142 rtc::scoped_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink());
3143
3144 // Should be able to set a default sink even when no stream exists.
3145 channel_->SetRawAudioSink(0, std::move(fake_sink_1));
3146
3147 // Create default channel and ensure it's assigned the default sink.
3148 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3149 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3150
3151 // Try resetting the default sink.
3152 channel_->SetRawAudioSink(0, nullptr);
3153 EXPECT_EQ(nullptr, GetRecvStream(0x01).sink());
3154
3155 // Try setting the default sink while the default stream exists.
3156 channel_->SetRawAudioSink(0, std::move(fake_sink_2));
3157 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3158
3159 // If we remove and add a default stream, it should get the same sink.
3160 EXPECT_TRUE(channel_->RemoveRecvStream(0x01));
3161 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3162 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3163 }
3164
3108 // Tests that the library initializes and shuts down properly. 3165 // Tests that the library initializes and shuts down properly.
3109 TEST(WebRtcVoiceEngineTest, StartupShutdown) { 3166 TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3110 cricket::WebRtcVoiceEngine engine; 3167 cricket::WebRtcVoiceEngine engine;
3111 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3168 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3112 rtc::scoped_ptr<webrtc::Call> call( 3169 rtc::scoped_ptr<webrtc::Call> call(
3113 webrtc::Call::Create(webrtc::Call::Config())); 3170 webrtc::Call::Create(webrtc::Call::Config()));
3114 cricket::VoiceMediaChannel* channel = 3171 cricket::VoiceMediaChannel* channel =
3115 engine.CreateChannel(call.get(), cricket::AudioOptions()); 3172 engine.CreateChannel(call.get(), cricket::AudioOptions());
3116 EXPECT_TRUE(channel != nullptr); 3173 EXPECT_TRUE(channel != nullptr);
3117 delete channel; 3174 delete channel;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3238 cricket::WebRtcVoiceEngine engine; 3295 cricket::WebRtcVoiceEngine engine;
3239 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3296 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3240 rtc::scoped_ptr<webrtc::Call> call( 3297 rtc::scoped_ptr<webrtc::Call> call(
3241 webrtc::Call::Create(webrtc::Call::Config())); 3298 webrtc::Call::Create(webrtc::Call::Config()));
3242 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), 3299 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(),
3243 call.get()); 3300 call.get());
3244 cricket::AudioRecvParameters parameters; 3301 cricket::AudioRecvParameters parameters;
3245 parameters.codecs = engine.codecs(); 3302 parameters.codecs = engine.codecs();
3246 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3303 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3247 } 3304 }
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvoiceengine.cc ('k') | webrtc/audio_receive_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698