OLD | NEW |
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 Loading... |
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 rtc::RefCountedObject<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 Loading... |
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 Loading... |
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_refptr<FakeAudioSink> fake_sink = new FakeAudioSink(); |
| 3122 |
| 3123 // This should do nothing, since there's no recv stream yet. |
| 3124 channel_->SetRawAudioSink(kSsrc1, fake_sink); |
| 3125 // Ensure the ref count wasn't incremented. |
| 3126 EXPECT_TRUE(fake_sink->HasOneRef()); |
| 3127 |
| 3128 EXPECT_TRUE( |
| 3129 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 3130 // Now, the channel should latch on to the sink. |
| 3131 channel_->SetRawAudioSink(kSsrc1, fake_sink); |
| 3132 EXPECT_FALSE(fake_sink->HasOneRef()); |
| 3133 EXPECT_EQ(fake_sink, GetRecvStream(kSsrc1).sink()); |
| 3134 |
| 3135 // Setting a nullptr should release the reference. |
| 3136 channel_->SetRawAudioSink(kSsrc1, nullptr); |
| 3137 EXPECT_TRUE(fake_sink->HasOneRef()); |
| 3138 } |
| 3139 |
| 3140 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) { |
| 3141 EXPECT_TRUE(SetupEngine()); |
| 3142 rtc::scoped_refptr<FakeAudioSink> fake_sink_1 = new FakeAudioSink(); |
| 3143 rtc::scoped_refptr<FakeAudioSink> fake_sink_2 = new FakeAudioSink(); |
| 3144 |
| 3145 // Should be able to set a default sink even when no stream exists. |
| 3146 channel_->SetRawAudioSink(0, fake_sink_1); |
| 3147 EXPECT_FALSE(fake_sink_1->HasOneRef()); |
| 3148 |
| 3149 // Create default channel. |
| 3150 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 3151 EXPECT_EQ(fake_sink_1, GetRecvStream(0x01).sink()); |
| 3152 |
| 3153 // Should be able to set the default sink after a stream exists. |
| 3154 channel_->SetRawAudioSink(0, fake_sink_2); |
| 3155 EXPECT_TRUE(fake_sink_1->HasOneRef()); |
| 3156 EXPECT_FALSE(fake_sink_2->HasOneRef()); |
| 3157 EXPECT_EQ(fake_sink_2, 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_FALSE(fake_sink_2->HasOneRef()); |
| 3163 EXPECT_EQ(fake_sink_2, GetRecvStream(0x01).sink()); |
| 3164 |
| 3165 // Finally, try resetting the default sink. |
| 3166 channel_->SetRawAudioSink(0, nullptr); |
| 3167 EXPECT_TRUE(fake_sink_2->HasOneRef()); |
| 3168 } |
| 3169 |
3108 // Tests that the library initializes and shuts down properly. | 3170 // Tests that the library initializes and shuts down properly. |
3109 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | 3171 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
3110 cricket::WebRtcVoiceEngine engine; | 3172 cricket::WebRtcVoiceEngine engine; |
3111 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3173 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
3112 rtc::scoped_ptr<webrtc::Call> call( | 3174 rtc::scoped_ptr<webrtc::Call> call( |
3113 webrtc::Call::Create(webrtc::Call::Config())); | 3175 webrtc::Call::Create(webrtc::Call::Config())); |
3114 cricket::VoiceMediaChannel* channel = | 3176 cricket::VoiceMediaChannel* channel = |
3115 engine.CreateChannel(call.get(), cricket::AudioOptions()); | 3177 engine.CreateChannel(call.get(), cricket::AudioOptions()); |
3116 EXPECT_TRUE(channel != nullptr); | 3178 EXPECT_TRUE(channel != nullptr); |
3117 delete channel; | 3179 delete channel; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3238 cricket::WebRtcVoiceEngine engine; | 3300 cricket::WebRtcVoiceEngine engine; |
3239 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3301 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
3240 rtc::scoped_ptr<webrtc::Call> call( | 3302 rtc::scoped_ptr<webrtc::Call> call( |
3241 webrtc::Call::Create(webrtc::Call::Config())); | 3303 webrtc::Call::Create(webrtc::Call::Config())); |
3242 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), | 3304 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), |
3243 call.get()); | 3305 call.get()); |
3244 cricket::AudioRecvParameters parameters; | 3306 cricket::AudioRecvParameters parameters; |
3245 parameters.codecs = engine.codecs(); | 3307 parameters.codecs = engine.codecs(); |
3246 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3308 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3247 } | 3309 } |
OLD | NEW |