Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 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 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1617 return CreateVoiceChannel(voe_wrapper_.get()); | 1617 return CreateVoiceChannel(voe_wrapper_.get()); |
| 1618 } | 1618 } |
| 1619 | 1619 |
| 1620 class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer | 1620 class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer |
| 1621 : public AudioRenderer::Sink { | 1621 : public AudioRenderer::Sink { |
| 1622 public: | 1622 public: |
| 1623 WebRtcVoiceChannelRenderer(int ch, | 1623 WebRtcVoiceChannelRenderer(int ch, |
| 1624 webrtc::AudioTransport* voe_audio_transport) | 1624 webrtc::AudioTransport* voe_audio_transport) |
| 1625 : channel_(ch), | 1625 : channel_(ch), |
| 1626 voe_audio_transport_(voe_audio_transport), | 1626 voe_audio_transport_(voe_audio_transport), |
| 1627 renderer_(NULL) { | 1627 renderer_(NULL) {} |
| 1628 } | |
| 1629 ~WebRtcVoiceChannelRenderer() override { Stop(); } | 1628 ~WebRtcVoiceChannelRenderer() override { Stop(); } |
| 1630 | 1629 |
| 1631 // Starts the rendering by setting a sink to the renderer to get data | 1630 // Starts the rendering by setting a sink to the renderer to get data |
| 1632 // callback. | 1631 // callback. |
| 1633 // This method is called on the libjingle worker thread. | 1632 // This method is called on the libjingle worker thread. |
| 1634 // TODO(xians): Make sure Start() is called only once. | 1633 // TODO(xians): Make sure Start() is called only once. |
| 1635 void Start(AudioRenderer* renderer) { | 1634 void Start(AudioRenderer* renderer) { |
| 1636 rtc::CritScope lock(&lock_); | 1635 rtc::CritScope lock(&lock_); |
| 1637 DCHECK(renderer != NULL); | 1636 DCHECK(renderer != NULL); |
| 1638 if (renderer_ != NULL) { | 1637 if (renderer_ != NULL) { |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2472 return false; | 2471 return false; |
| 2473 } | 2472 } |
| 2474 | 2473 |
| 2475 ConfigureSendChannel(channel); | 2474 ConfigureSendChannel(channel); |
| 2476 } | 2475 } |
| 2477 | 2476 |
| 2478 // Save the channel to send_channels_, so that RemoveSendStream() can still | 2477 // Save the channel to send_channels_, so that RemoveSendStream() can still |
| 2479 // delete the channel in case failure happens below. | 2478 // delete the channel in case failure happens below. |
| 2480 webrtc::AudioTransport* audio_transport = | 2479 webrtc::AudioTransport* audio_transport = |
| 2481 engine()->voe()->base()->audio_transport(); | 2480 engine()->voe()->base()->audio_transport(); |
| 2482 send_channels_.insert(std::make_pair( | 2481 send_channels_.insert( |
| 2483 sp.first_ssrc(), | 2482 std::make_pair(sp.first_ssrc(), |
| 2484 new WebRtcVoiceChannelRenderer(channel, audio_transport))); | 2483 new WebRtcVoiceChannelRenderer(channel, audio_transport))); |
| 2485 | 2484 |
| 2486 // Set the send (local) SSRC. | 2485 // Set the send (local) SSRC. |
| 2487 // If there are multiple send SSRCs, we can only set the first one here, and | 2486 // If there are multiple send SSRCs, we can only set the first one here, and |
| 2488 // the rest of the SSRC(s) need to be set after SetSendCodec has been called | 2487 // the rest of the SSRC(s) need to be set after SetSendCodec has been called |
| 2489 // (with a codec requires multiple SSRC(s)). | 2488 // (with a codec requires multiple SSRC(s)). |
| 2490 if (engine()->voe()->rtp()->SetLocalSSRC(channel, sp.first_ssrc()) == -1) { | 2489 if (engine()->voe()->rtp()->SetLocalSSRC(channel, sp.first_ssrc()) == -1) { |
| 2491 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); | 2490 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); |
| 2492 return false; | 2491 return false; |
| 2493 } | 2492 } |
| 2494 | 2493 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2567 if (ssrc == 0) { | 2566 if (ssrc == 0) { |
| 2568 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; | 2567 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; |
| 2569 return false; | 2568 return false; |
| 2570 } | 2569 } |
| 2571 | 2570 |
| 2572 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 2571 if (receive_channels_.find(ssrc) != receive_channels_.end()) { |
| 2573 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 2572 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; |
| 2574 return false; | 2573 return false; |
| 2575 } | 2574 } |
| 2576 | 2575 |
| 2577 TryAddAudioRecvStream(ssrc); | 2576 DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); |
|
stefan-webrtc
2015/06/16 15:33:39
Can someone give us a fake sdp and cause a crash h
the sun
2015/06/18 08:38:37
Notice that we look for the ssrc in receive_channe
stefan-webrtc
2015/06/22 14:19:42
Acknowledged.
pbos-webrtc
2015/06/24 09:46:09
I moved the storing of the StreamParams to prevent
| |
| 2577 receive_stream_params_[ssrc] = sp; | |
| 2578 | 2578 |
| 2579 // Reuse default channel for recv stream in non-conference mode call | 2579 // Reuse default channel for recv stream in non-conference mode call |
| 2580 // when the default channel is not being used. | 2580 // when the default channel is not being used. |
| 2581 webrtc::AudioTransport* audio_transport = | 2581 webrtc::AudioTransport* audio_transport = |
| 2582 engine()->voe()->base()->audio_transport(); | 2582 engine()->voe()->base()->audio_transport(); |
| 2583 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | 2583 if (!InConferenceMode() && default_receive_ssrc_ == 0) { |
| 2584 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | 2584 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; |
| 2585 default_receive_ssrc_ = ssrc; | 2585 default_receive_ssrc_ = ssrc; |
| 2586 receive_channels_.insert(std::make_pair( | 2586 WebRtcVoiceChannelRenderer* channel_renderer = |
| 2587 default_receive_ssrc_, | 2587 new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport); |
| 2588 new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport))); | 2588 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); |
| 2589 TryAddAudioRecvStream(ssrc); | |
| 2589 return SetPlayout(voe_channel(), playout_); | 2590 return SetPlayout(voe_channel(), playout_); |
| 2590 } | 2591 } |
| 2591 | 2592 |
| 2592 // Create a new channel for receiving audio data. | 2593 // Create a new channel for receiving audio data. |
| 2593 int channel = engine()->CreateMediaVoiceChannel(); | 2594 int channel = engine()->CreateMediaVoiceChannel(); |
| 2594 if (channel == -1) { | 2595 if (channel == -1) { |
| 2595 LOG_RTCERR0(CreateChannel); | 2596 LOG_RTCERR0(CreateChannel); |
| 2597 receive_stream_params_.erase(ssrc); | |
| 2596 return false; | 2598 return false; |
| 2597 } | 2599 } |
| 2598 | 2600 |
| 2599 if (!ConfigureRecvChannel(channel)) { | 2601 if (!ConfigureRecvChannel(channel)) { |
| 2600 DeleteChannel(channel); | 2602 DeleteChannel(channel); |
| 2603 receive_stream_params_.erase(ssrc); | |
| 2601 return false; | 2604 return false; |
| 2602 } | 2605 } |
| 2603 | 2606 |
| 2604 receive_channels_.insert( | 2607 WebRtcVoiceChannelRenderer* channel_renderer = |
| 2605 std::make_pair( | 2608 new WebRtcVoiceChannelRenderer(channel, audio_transport); |
| 2606 ssrc, new WebRtcVoiceChannelRenderer(channel, audio_transport))); | 2609 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); |
| 2610 TryAddAudioRecvStream(ssrc); | |
| 2607 | 2611 |
| 2608 LOG(LS_INFO) << "New audio stream " << ssrc | 2612 LOG(LS_INFO) << "New audio stream " << ssrc |
| 2609 << " registered to VoiceEngine channel #" | 2613 << " registered to VoiceEngine channel #" |
| 2610 << channel << "."; | 2614 << channel << "."; |
| 2611 return true; | 2615 return true; |
| 2612 } | 2616 } |
| 2613 | 2617 |
| 2614 bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { | 2618 bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { |
| 2615 // Configure to use external transport, like our default channel. | 2619 // Configure to use external transport, like our default channel. |
| 2616 if (engine()->voe()->network()->RegisterExternalTransport( | 2620 if (engine()->voe()->network()->RegisterExternalTransport( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2687 DCHECK(thread_checker_.CalledOnValidThread()); | 2691 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2688 rtc::CritScope lock(&receive_channels_cs_); | 2692 rtc::CritScope lock(&receive_channels_cs_); |
| 2689 ChannelMap::iterator it = receive_channels_.find(ssrc); | 2693 ChannelMap::iterator it = receive_channels_.find(ssrc); |
| 2690 if (it == receive_channels_.end()) { | 2694 if (it == receive_channels_.end()) { |
| 2691 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 2695 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc |
| 2692 << " which doesn't exist."; | 2696 << " which doesn't exist."; |
| 2693 return false; | 2697 return false; |
| 2694 } | 2698 } |
| 2695 | 2699 |
| 2696 TryRemoveAudioRecvStream(ssrc); | 2700 TryRemoveAudioRecvStream(ssrc); |
| 2701 receive_stream_params_.erase(ssrc); | |
| 2697 | 2702 |
| 2698 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this | 2703 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this |
| 2699 // will disconnect the audio renderer with the receive channel. | 2704 // will disconnect the audio renderer with the receive channel. |
| 2700 // Cache the channel before the deletion. | 2705 // Cache the channel before the deletion. |
| 2701 const int channel = it->second->channel(); | 2706 const int channel = it->second->channel(); |
| 2702 delete it->second; | 2707 delete it->second; |
| 2703 receive_channels_.erase(it); | 2708 receive_channels_.erase(it); |
| 2704 | 2709 |
| 2705 if (ssrc == default_receive_ssrc_) { | 2710 if (ssrc == default_receive_ssrc_) { |
| 2706 DCHECK(IsDefaultChannel(channel)); | 2711 DCHECK(IsDefaultChannel(channel)); |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3443 unsigned int ulevel; | 3448 unsigned int ulevel; |
| 3444 int ret = | 3449 int ret = |
| 3445 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); | 3450 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); |
| 3446 return (ret == 0) ? static_cast<int>(ulevel) : -1; | 3451 return (ret == 0) ? static_cast<int>(ulevel) : -1; |
| 3447 } | 3452 } |
| 3448 | 3453 |
| 3449 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) { | 3454 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) { |
| 3450 ChannelMap::iterator it = receive_channels_.find(ssrc); | 3455 ChannelMap::iterator it = receive_channels_.find(ssrc); |
| 3451 if (it != receive_channels_.end()) | 3456 if (it != receive_channels_.end()) |
| 3452 return it->second->channel(); | 3457 return it->second->channel(); |
| 3453 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; | 3458 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; |
| 3454 } | 3459 } |
| 3455 | 3460 |
| 3456 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) { | 3461 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) { |
| 3457 ChannelMap::iterator it = send_channels_.find(ssrc); | 3462 ChannelMap::iterator it = send_channels_.find(ssrc); |
| 3458 if (it != send_channels_.end()) | 3463 if (it != send_channels_.end()) |
| 3459 return it->second->channel(); | 3464 return it->second->channel(); |
| 3460 | 3465 |
| 3461 return -1; | 3466 return -1; |
| 3462 } | 3467 } |
| 3463 | 3468 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3616 } | 3621 } |
| 3617 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { | 3622 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { |
| 3618 LOG_RTCERR4(*setter, uri, channel_id, enable, id); | 3623 LOG_RTCERR4(*setter, uri, channel_id, enable, id); |
| 3619 return false; | 3624 return false; |
| 3620 } | 3625 } |
| 3621 return true; | 3626 return true; |
| 3622 } | 3627 } |
| 3623 | 3628 |
| 3624 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream(uint32 ssrc) { | 3629 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream(uint32 ssrc) { |
| 3625 DCHECK(thread_checker_.CalledOnValidThread()); | 3630 DCHECK(thread_checker_.CalledOnValidThread()); |
| 3631 WebRtcVoiceChannelRenderer* channel = receive_channels_[ssrc]; | |
| 3632 DCHECK(channel != nullptr); | |
| 3633 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); | |
| 3626 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too. | 3634 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too. |
| 3627 if (call_ && options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) { | 3635 if (!call_) { |
| 3628 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); | 3636 return; |
| 3629 webrtc::AudioReceiveStream::Config config; | 3637 } |
| 3630 config.rtp.remote_ssrc = ssrc; | 3638 webrtc::AudioReceiveStream::Config config; |
| 3639 config.rtp.remote_ssrc = ssrc; | |
| 3640 // Only add RTP extensions if we support combined AV BWE. | |
|
stefan-webrtc
2015/06/16 15:33:39
A/V BWE
pbos-webrtc
2015/06/24 09:46:09
Done.
| |
| 3641 if (options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) { | |
| 3631 config.rtp.extensions = recv_rtp_extensions_; | 3642 config.rtp.extensions = recv_rtp_extensions_; |
| 3632 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); | |
| 3633 receive_streams_.insert(std::make_pair(ssrc, s)); | |
| 3634 } | 3643 } |
| 3644 config.voe_channel_id = channel->channel(); | |
| 3645 config.sync_group = receive_stream_params_[ssrc].sync_label; | |
|
stefan-webrtc
2015/06/16 15:33:39
Does this mean A/V BWE depends on sync labels? I w
the sun
2015/06/18 08:38:37
No, we create the ARS regardless, but only set rtp
stefan-webrtc
2015/06/22 14:19:42
Yes, I have no clue how I read this code. :)
| |
| 3646 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); | |
| 3647 receive_streams_.insert(std::make_pair(ssrc, s)); | |
| 3635 } | 3648 } |
| 3636 | 3649 |
| 3637 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) { | 3650 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) { |
| 3638 DCHECK(thread_checker_.CalledOnValidThread()); | 3651 DCHECK(thread_checker_.CalledOnValidThread()); |
| 3639 // If we are hooked up to a webrtc::Call, assume there is an | 3652 // If we are hooked up to a webrtc::Call, assume there is an |
| 3640 // AudioReceiveStream to destroy too. | 3653 // AudioReceiveStream to destroy too. |
| 3641 if (call_) { | 3654 if (call_) { |
| 3642 auto stream_it = receive_streams_.find(ssrc); | 3655 auto stream_it = receive_streams_.find(ssrc); |
| 3643 if (stream_it != receive_streams_.end()) { | 3656 if (stream_it != receive_streams_.end()) { |
| 3644 call_->DestroyAudioReceiveStream(stream_it->second); | 3657 call_->DestroyAudioReceiveStream(stream_it->second); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 3655 | 3668 |
| 3656 int WebRtcSoundclipStream::Rewind() { | 3669 int WebRtcSoundclipStream::Rewind() { |
| 3657 mem_.Rewind(); | 3670 mem_.Rewind(); |
| 3658 // Return -1 to keep VoiceEngine from looping. | 3671 // Return -1 to keep VoiceEngine from looping. |
| 3659 return (loop_) ? 0 : -1; | 3672 return (loop_) ? 0 : -1; |
| 3660 } | 3673 } |
| 3661 | 3674 |
| 3662 } // namespace cricket | 3675 } // namespace cricket |
| 3663 | 3676 |
| 3664 #endif // HAVE_WEBRTC_VOICE | 3677 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |