OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 Terminate(); | 74 Terminate(); |
75 // If srtp is initialized (done by the Channel) then we must call | 75 // If srtp is initialized (done by the Channel) then we must call |
76 // srtp_shutdown to free all crypto kernel lists. But we need to make sure | 76 // srtp_shutdown to free all crypto kernel lists. But we need to make sure |
77 // shutdown always called at the end, after channels are destroyed. | 77 // shutdown always called at the end, after channels are destroyed. |
78 // ChannelManager d'tor is always called last, it's safe place to call | 78 // ChannelManager d'tor is always called last, it's safe place to call |
79 // shutdown. | 79 // shutdown. |
80 ShutdownSrtp(); | 80 ShutdownSrtp(); |
81 } | 81 } |
82 // The media engine needs to be deleted on the worker thread for thread safe | 82 // The media engine needs to be deleted on the worker thread for thread safe |
83 // destruction, | 83 // destruction, |
84 worker_thread_->Invoke<void>(Bind( | 84 worker_thread_->Invoke<void>( |
85 &ChannelManager::DestructorDeletes_w, this)); | 85 FROM_HERE, Bind(&ChannelManager::DestructorDeletes_w, this)); |
86 } | 86 } |
87 | 87 |
88 bool ChannelManager::SetVideoRtxEnabled(bool enable) { | 88 bool ChannelManager::SetVideoRtxEnabled(bool enable) { |
89 // To be safe, this call is only allowed before initialization. Apps like | 89 // To be safe, this call is only allowed before initialization. Apps like |
90 // Flute only have a singleton ChannelManager and we don't want this flag to | 90 // Flute only have a singleton ChannelManager and we don't want this flag to |
91 // be toggled between calls or when there's concurrent calls. We expect apps | 91 // be toggled between calls or when there's concurrent calls. We expect apps |
92 // to enable this at startup and retain that setting for the lifetime of the | 92 // to enable this at startup and retain that setting for the lifetime of the |
93 // app. | 93 // app. |
94 if (!initialized_) { | 94 if (!initialized_) { |
95 enable_rtx_ = enable; | 95 enable_rtx_ = enable; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 bool ChannelManager::Init() { | 143 bool ChannelManager::Init() { |
144 ASSERT(!initialized_); | 144 ASSERT(!initialized_); |
145 if (initialized_) { | 145 if (initialized_) { |
146 return false; | 146 return false; |
147 } | 147 } |
148 RTC_DCHECK(network_thread_); | 148 RTC_DCHECK(network_thread_); |
149 RTC_DCHECK(worker_thread_); | 149 RTC_DCHECK(worker_thread_); |
150 if (!network_thread_->IsCurrent()) { | 150 if (!network_thread_->IsCurrent()) { |
151 // Do not allow invoking calls to other threads on the network thread. | 151 // Do not allow invoking calls to other threads on the network thread. |
152 network_thread_->Invoke<bool>( | 152 network_thread_->Invoke<bool>( |
| 153 FROM_HERE, |
153 rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false)); | 154 rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false)); |
154 } | 155 } |
155 | 156 |
156 initialized_ = worker_thread_->Invoke<bool>( | 157 initialized_ = worker_thread_->Invoke<bool>( |
157 Bind(&ChannelManager::InitMediaEngine_w, this)); | 158 FROM_HERE, Bind(&ChannelManager::InitMediaEngine_w, this)); |
158 ASSERT(initialized_); | 159 ASSERT(initialized_); |
159 if (!initialized_) { | 160 if (!initialized_) { |
160 return false; | 161 return false; |
161 } | 162 } |
162 | 163 |
163 // If audio_output_volume_ has been set via SetOutputVolume(), set the | 164 // If audio_output_volume_ has been set via SetOutputVolume(), set the |
164 // audio output volume of the engine. | 165 // audio output volume of the engine. |
165 if (kNotSetOutputVolume != audio_output_volume_ && | 166 if (kNotSetOutputVolume != audio_output_volume_ && |
166 !SetOutputVolume(audio_output_volume_)) { | 167 !SetOutputVolume(audio_output_volume_)) { |
167 LOG(LS_WARNING) << "Failed to SetOutputVolume to " | 168 LOG(LS_WARNING) << "Failed to SetOutputVolume to " |
168 << audio_output_volume_; | 169 << audio_output_volume_; |
169 } | 170 } |
170 | 171 |
171 return initialized_; | 172 return initialized_; |
172 } | 173 } |
173 | 174 |
174 bool ChannelManager::InitMediaEngine_w() { | 175 bool ChannelManager::InitMediaEngine_w() { |
175 ASSERT(worker_thread_ == rtc::Thread::Current()); | 176 ASSERT(worker_thread_ == rtc::Thread::Current()); |
176 return media_engine_->Init(); | 177 return media_engine_->Init(); |
177 } | 178 } |
178 | 179 |
179 void ChannelManager::Terminate() { | 180 void ChannelManager::Terminate() { |
180 ASSERT(initialized_); | 181 ASSERT(initialized_); |
181 if (!initialized_) { | 182 if (!initialized_) { |
182 return; | 183 return; |
183 } | 184 } |
184 worker_thread_->Invoke<void>(Bind(&ChannelManager::Terminate_w, this)); | 185 worker_thread_->Invoke<void>(FROM_HERE, |
| 186 Bind(&ChannelManager::Terminate_w, this)); |
185 initialized_ = false; | 187 initialized_ = false; |
186 } | 188 } |
187 | 189 |
188 void ChannelManager::DestructorDeletes_w() { | 190 void ChannelManager::DestructorDeletes_w() { |
189 ASSERT(worker_thread_ == rtc::Thread::Current()); | 191 ASSERT(worker_thread_ == rtc::Thread::Current()); |
190 media_engine_.reset(NULL); | 192 media_engine_.reset(NULL); |
191 } | 193 } |
192 | 194 |
193 void ChannelManager::Terminate_w() { | 195 void ChannelManager::Terminate_w() { |
194 ASSERT(worker_thread_ == rtc::Thread::Current()); | 196 ASSERT(worker_thread_ == rtc::Thread::Current()); |
195 // Need to destroy the voice/video channels | 197 // Need to destroy the voice/video channels |
196 while (!video_channels_.empty()) { | 198 while (!video_channels_.empty()) { |
197 DestroyVideoChannel_w(video_channels_.back()); | 199 DestroyVideoChannel_w(video_channels_.back()); |
198 } | 200 } |
199 while (!voice_channels_.empty()) { | 201 while (!voice_channels_.empty()) { |
200 DestroyVoiceChannel_w(voice_channels_.back()); | 202 DestroyVoiceChannel_w(voice_channels_.back()); |
201 } | 203 } |
202 } | 204 } |
203 | 205 |
204 VoiceChannel* ChannelManager::CreateVoiceChannel( | 206 VoiceChannel* ChannelManager::CreateVoiceChannel( |
205 webrtc::MediaControllerInterface* media_controller, | 207 webrtc::MediaControllerInterface* media_controller, |
206 TransportController* transport_controller, | 208 TransportController* transport_controller, |
207 const std::string& content_name, | 209 const std::string& content_name, |
208 bool rtcp, | 210 bool rtcp, |
209 const AudioOptions& options) { | 211 const AudioOptions& options) { |
210 return worker_thread_->Invoke<VoiceChannel*>( | 212 return worker_thread_->Invoke<VoiceChannel*>( |
| 213 FROM_HERE, |
211 Bind(&ChannelManager::CreateVoiceChannel_w, this, media_controller, | 214 Bind(&ChannelManager::CreateVoiceChannel_w, this, media_controller, |
212 transport_controller, content_name, rtcp, options)); | 215 transport_controller, content_name, rtcp, options)); |
213 } | 216 } |
214 | 217 |
215 VoiceChannel* ChannelManager::CreateVoiceChannel_w( | 218 VoiceChannel* ChannelManager::CreateVoiceChannel_w( |
216 webrtc::MediaControllerInterface* media_controller, | 219 webrtc::MediaControllerInterface* media_controller, |
217 TransportController* transport_controller, | 220 TransportController* transport_controller, |
218 const std::string& content_name, | 221 const std::string& content_name, |
219 bool rtcp, | 222 bool rtcp, |
220 const AudioOptions& options) { | 223 const AudioOptions& options) { |
(...skipping 13 matching lines...) Expand all Loading... |
234 return nullptr; | 237 return nullptr; |
235 } | 238 } |
236 voice_channels_.push_back(voice_channel); | 239 voice_channels_.push_back(voice_channel); |
237 return voice_channel; | 240 return voice_channel; |
238 } | 241 } |
239 | 242 |
240 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { | 243 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { |
241 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); | 244 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); |
242 if (voice_channel) { | 245 if (voice_channel) { |
243 worker_thread_->Invoke<void>( | 246 worker_thread_->Invoke<void>( |
| 247 FROM_HERE, |
244 Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel)); | 248 Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel)); |
245 } | 249 } |
246 } | 250 } |
247 | 251 |
248 void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) { | 252 void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) { |
249 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w"); | 253 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w"); |
250 // Destroy voice channel. | 254 // Destroy voice channel. |
251 ASSERT(initialized_); | 255 ASSERT(initialized_); |
252 ASSERT(worker_thread_ == rtc::Thread::Current()); | 256 ASSERT(worker_thread_ == rtc::Thread::Current()); |
253 VoiceChannels::iterator it = std::find(voice_channels_.begin(), | 257 VoiceChannels::iterator it = std::find(voice_channels_.begin(), |
254 voice_channels_.end(), voice_channel); | 258 voice_channels_.end(), voice_channel); |
255 ASSERT(it != voice_channels_.end()); | 259 ASSERT(it != voice_channels_.end()); |
256 if (it == voice_channels_.end()) | 260 if (it == voice_channels_.end()) |
257 return; | 261 return; |
258 voice_channels_.erase(it); | 262 voice_channels_.erase(it); |
259 delete voice_channel; | 263 delete voice_channel; |
260 } | 264 } |
261 | 265 |
262 VideoChannel* ChannelManager::CreateVideoChannel( | 266 VideoChannel* ChannelManager::CreateVideoChannel( |
263 webrtc::MediaControllerInterface* media_controller, | 267 webrtc::MediaControllerInterface* media_controller, |
264 TransportController* transport_controller, | 268 TransportController* transport_controller, |
265 const std::string& content_name, | 269 const std::string& content_name, |
266 bool rtcp, | 270 bool rtcp, |
267 const VideoOptions& options) { | 271 const VideoOptions& options) { |
268 return worker_thread_->Invoke<VideoChannel*>( | 272 return worker_thread_->Invoke<VideoChannel*>( |
| 273 FROM_HERE, |
269 Bind(&ChannelManager::CreateVideoChannel_w, this, media_controller, | 274 Bind(&ChannelManager::CreateVideoChannel_w, this, media_controller, |
270 transport_controller, content_name, rtcp, options)); | 275 transport_controller, content_name, rtcp, options)); |
271 } | 276 } |
272 | 277 |
273 VideoChannel* ChannelManager::CreateVideoChannel_w( | 278 VideoChannel* ChannelManager::CreateVideoChannel_w( |
274 webrtc::MediaControllerInterface* media_controller, | 279 webrtc::MediaControllerInterface* media_controller, |
275 TransportController* transport_controller, | 280 TransportController* transport_controller, |
276 const std::string& content_name, | 281 const std::string& content_name, |
277 bool rtcp, | 282 bool rtcp, |
278 const VideoOptions& options) { | 283 const VideoOptions& options) { |
(...skipping 14 matching lines...) Expand all Loading... |
293 return NULL; | 298 return NULL; |
294 } | 299 } |
295 video_channels_.push_back(video_channel); | 300 video_channels_.push_back(video_channel); |
296 return video_channel; | 301 return video_channel; |
297 } | 302 } |
298 | 303 |
299 void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { | 304 void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { |
300 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); | 305 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); |
301 if (video_channel) { | 306 if (video_channel) { |
302 worker_thread_->Invoke<void>( | 307 worker_thread_->Invoke<void>( |
| 308 FROM_HERE, |
303 Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel)); | 309 Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel)); |
304 } | 310 } |
305 } | 311 } |
306 | 312 |
307 void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) { | 313 void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) { |
308 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w"); | 314 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w"); |
309 // Destroy video channel. | 315 // Destroy video channel. |
310 ASSERT(initialized_); | 316 ASSERT(initialized_); |
311 ASSERT(worker_thread_ == rtc::Thread::Current()); | 317 ASSERT(worker_thread_ == rtc::Thread::Current()); |
312 VideoChannels::iterator it = std::find(video_channels_.begin(), | 318 VideoChannels::iterator it = std::find(video_channels_.begin(), |
313 video_channels_.end(), video_channel); | 319 video_channels_.end(), video_channel); |
314 ASSERT(it != video_channels_.end()); | 320 ASSERT(it != video_channels_.end()); |
315 if (it == video_channels_.end()) | 321 if (it == video_channels_.end()) |
316 return; | 322 return; |
317 | 323 |
318 video_channels_.erase(it); | 324 video_channels_.erase(it); |
319 delete video_channel; | 325 delete video_channel; |
320 } | 326 } |
321 | 327 |
322 DataChannel* ChannelManager::CreateDataChannel( | 328 DataChannel* ChannelManager::CreateDataChannel( |
323 TransportController* transport_controller, | 329 TransportController* transport_controller, |
324 const std::string& content_name, | 330 const std::string& content_name, |
325 bool rtcp, | 331 bool rtcp, |
326 DataChannelType channel_type) { | 332 DataChannelType channel_type) { |
327 return worker_thread_->Invoke<DataChannel*>( | 333 return worker_thread_->Invoke<DataChannel*>( |
328 Bind(&ChannelManager::CreateDataChannel_w, this, transport_controller, | 334 FROM_HERE, Bind(&ChannelManager::CreateDataChannel_w, this, |
329 content_name, rtcp, channel_type)); | 335 transport_controller, content_name, rtcp, channel_type)); |
330 } | 336 } |
331 | 337 |
332 DataChannel* ChannelManager::CreateDataChannel_w( | 338 DataChannel* ChannelManager::CreateDataChannel_w( |
333 TransportController* transport_controller, | 339 TransportController* transport_controller, |
334 const std::string& content_name, | 340 const std::string& content_name, |
335 bool rtcp, | 341 bool rtcp, |
336 DataChannelType data_channel_type) { | 342 DataChannelType data_channel_type) { |
337 // This is ok to alloc from a thread other than the worker thread. | 343 // This is ok to alloc from a thread other than the worker thread. |
338 ASSERT(initialized_); | 344 ASSERT(initialized_); |
339 DataMediaChannel* media_channel = data_media_engine_->CreateChannel( | 345 DataMediaChannel* media_channel = data_media_engine_->CreateChannel( |
(...skipping 13 matching lines...) Expand all Loading... |
353 return NULL; | 359 return NULL; |
354 } | 360 } |
355 data_channels_.push_back(data_channel); | 361 data_channels_.push_back(data_channel); |
356 return data_channel; | 362 return data_channel; |
357 } | 363 } |
358 | 364 |
359 void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { | 365 void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { |
360 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel"); | 366 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel"); |
361 if (data_channel) { | 367 if (data_channel) { |
362 worker_thread_->Invoke<void>( | 368 worker_thread_->Invoke<void>( |
| 369 FROM_HERE, |
363 Bind(&ChannelManager::DestroyDataChannel_w, this, data_channel)); | 370 Bind(&ChannelManager::DestroyDataChannel_w, this, data_channel)); |
364 } | 371 } |
365 } | 372 } |
366 | 373 |
367 void ChannelManager::DestroyDataChannel_w(DataChannel* data_channel) { | 374 void ChannelManager::DestroyDataChannel_w(DataChannel* data_channel) { |
368 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel_w"); | 375 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel_w"); |
369 // Destroy data channel. | 376 // Destroy data channel. |
370 ASSERT(initialized_); | 377 ASSERT(initialized_); |
371 DataChannels::iterator it = std::find(data_channels_.begin(), | 378 DataChannels::iterator it = std::find(data_channels_.begin(), |
372 data_channels_.end(), data_channel); | 379 data_channels_.end(), data_channel); |
373 ASSERT(it != data_channels_.end()); | 380 ASSERT(it != data_channels_.end()); |
374 if (it == data_channels_.end()) | 381 if (it == data_channels_.end()) |
375 return; | 382 return; |
376 | 383 |
377 data_channels_.erase(it); | 384 data_channels_.erase(it); |
378 delete data_channel; | 385 delete data_channel; |
379 } | 386 } |
380 | 387 |
381 bool ChannelManager::GetOutputVolume(int* level) { | 388 bool ChannelManager::GetOutputVolume(int* level) { |
382 if (!initialized_) { | 389 if (!initialized_) { |
383 return false; | 390 return false; |
384 } | 391 } |
385 return worker_thread_->Invoke<bool>( | 392 return worker_thread_->Invoke<bool>( |
| 393 FROM_HERE, |
386 Bind(&MediaEngineInterface::GetOutputVolume, media_engine_.get(), level)); | 394 Bind(&MediaEngineInterface::GetOutputVolume, media_engine_.get(), level)); |
387 } | 395 } |
388 | 396 |
389 bool ChannelManager::SetOutputVolume(int level) { | 397 bool ChannelManager::SetOutputVolume(int level) { |
390 bool ret = level >= 0 && level <= 255; | 398 bool ret = level >= 0 && level <= 255; |
391 if (initialized_) { | 399 if (initialized_) { |
392 ret &= worker_thread_->Invoke<bool>( | 400 ret &= worker_thread_->Invoke<bool>( |
393 Bind(&MediaEngineInterface::SetOutputVolume, | 401 FROM_HERE, Bind(&MediaEngineInterface::SetOutputVolume, |
394 media_engine_.get(), level)); | 402 media_engine_.get(), level)); |
395 } | 403 } |
396 | 404 |
397 if (ret) { | 405 if (ret) { |
398 audio_output_volume_ = level; | 406 audio_output_volume_ = level; |
399 } | 407 } |
400 | 408 |
401 return ret; | 409 return ret; |
402 } | 410 } |
403 | 411 |
404 | 412 |
405 bool ChannelManager::StartAecDump(rtc::PlatformFile file, | 413 bool ChannelManager::StartAecDump(rtc::PlatformFile file, |
406 int64_t max_size_bytes) { | 414 int64_t max_size_bytes) { |
407 return worker_thread_->Invoke<bool>(Bind(&MediaEngineInterface::StartAecDump, | 415 return worker_thread_->Invoke<bool>( |
408 media_engine_.get(), file, | 416 FROM_HERE, Bind(&MediaEngineInterface::StartAecDump, media_engine_.get(), |
409 max_size_bytes)); | 417 file, max_size_bytes)); |
410 } | 418 } |
411 | 419 |
412 void ChannelManager::StopAecDump() { | 420 void ChannelManager::StopAecDump() { |
413 worker_thread_->Invoke<void>( | 421 worker_thread_->Invoke<void>( |
414 Bind(&MediaEngineInterface::StopAecDump, media_engine_.get())); | 422 FROM_HERE, Bind(&MediaEngineInterface::StopAecDump, media_engine_.get())); |
415 } | 423 } |
416 | 424 |
417 bool ChannelManager::StartRtcEventLog(rtc::PlatformFile file) { | 425 bool ChannelManager::StartRtcEventLog(rtc::PlatformFile file) { |
418 return worker_thread_->Invoke<bool>( | 426 return worker_thread_->Invoke<bool>( |
| 427 FROM_HERE, |
419 Bind(&MediaEngineInterface::StartRtcEventLog, media_engine_.get(), file)); | 428 Bind(&MediaEngineInterface::StartRtcEventLog, media_engine_.get(), file)); |
420 } | 429 } |
421 | 430 |
422 void ChannelManager::StopRtcEventLog() { | 431 void ChannelManager::StopRtcEventLog() { |
423 worker_thread_->Invoke<void>( | 432 worker_thread_->Invoke<void>( |
| 433 FROM_HERE, |
424 Bind(&MediaEngineInterface::StopRtcEventLog, media_engine_.get())); | 434 Bind(&MediaEngineInterface::StopRtcEventLog, media_engine_.get())); |
425 } | 435 } |
426 | 436 |
427 } // namespace cricket | 437 } // namespace cricket |
OLD | NEW |