| 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 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 } | 1614 } |
| 1615 | 1615 |
| 1616 int WebRtcVoiceEngine::CreateMediaVoiceChannel() { | 1616 int WebRtcVoiceEngine::CreateMediaVoiceChannel() { |
| 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 const std::string& sync_label, |
| 1624 webrtc::AudioTransport* voe_audio_transport) | 1625 webrtc::AudioTransport* voe_audio_transport) |
| 1625 : channel_(ch), | 1626 : channel_(ch), |
| 1627 sync_label_(sync_label), |
| 1626 voe_audio_transport_(voe_audio_transport), | 1628 voe_audio_transport_(voe_audio_transport), |
| 1627 renderer_(NULL) { | 1629 renderer_(NULL) {} |
| 1628 } | |
| 1629 ~WebRtcVoiceChannelRenderer() override { Stop(); } | 1630 ~WebRtcVoiceChannelRenderer() override { Stop(); } |
| 1630 | 1631 |
| 1631 // Starts the rendering by setting a sink to the renderer to get data | 1632 // Starts the rendering by setting a sink to the renderer to get data |
| 1632 // callback. | 1633 // callback. |
| 1633 // This method is called on the libjingle worker thread. | 1634 // This method is called on the libjingle worker thread. |
| 1634 // TODO(xians): Make sure Start() is called only once. | 1635 // TODO(xians): Make sure Start() is called only once. |
| 1635 void Start(AudioRenderer* renderer) { | 1636 void Start(AudioRenderer* renderer) { |
| 1636 rtc::CritScope lock(&lock_); | 1637 rtc::CritScope lock(&lock_); |
| 1637 DCHECK(renderer != NULL); | 1638 DCHECK(renderer != NULL); |
| 1638 if (renderer_ != NULL) { | 1639 if (renderer_ != NULL) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1679 // never been called, this callback won't be triggered. | 1680 // never been called, this callback won't be triggered. |
| 1680 void OnClose() override { | 1681 void OnClose() override { |
| 1681 rtc::CritScope lock(&lock_); | 1682 rtc::CritScope lock(&lock_); |
| 1682 // Set |renderer_| to NULL to make sure no more callback will get into | 1683 // Set |renderer_| to NULL to make sure no more callback will get into |
| 1683 // the renderer. | 1684 // the renderer. |
| 1684 renderer_ = NULL; | 1685 renderer_ = NULL; |
| 1685 } | 1686 } |
| 1686 | 1687 |
| 1687 // Accessor to the VoE channel ID. | 1688 // Accessor to the VoE channel ID. |
| 1688 int channel() const { return channel_; } | 1689 int channel() const { return channel_; } |
| 1690 const std::string& sync_label() const { return sync_label_; } |
| 1689 | 1691 |
| 1690 private: | 1692 private: |
| 1691 const int channel_; | 1693 const int channel_; |
| 1694 const std::string sync_label_; |
| 1692 webrtc::AudioTransport* const voe_audio_transport_; | 1695 webrtc::AudioTransport* const voe_audio_transport_; |
| 1693 | 1696 |
| 1694 // Raw pointer to AudioRenderer owned by LocalAudioTrackHandler. | 1697 // Raw pointer to AudioRenderer owned by LocalAudioTrackHandler. |
| 1695 // PeerConnection will make sure invalidating the pointer before the object | 1698 // PeerConnection will make sure invalidating the pointer before the object |
| 1696 // goes away. | 1699 // goes away. |
| 1697 AudioRenderer* renderer_; | 1700 AudioRenderer* renderer_; |
| 1698 | 1701 |
| 1699 // Protects |renderer_| in Start(), Stop() and OnClose(). | 1702 // Protects |renderer_| in Start(), Stop() and OnClose(). |
| 1700 rtc::CriticalSection lock_; | 1703 rtc::CriticalSection lock_; |
| 1701 }; | 1704 }; |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 | 2477 |
| 2475 ConfigureSendChannel(channel); | 2478 ConfigureSendChannel(channel); |
| 2476 } | 2479 } |
| 2477 | 2480 |
| 2478 // Save the channel to send_channels_, so that RemoveSendStream() can still | 2481 // Save the channel to send_channels_, so that RemoveSendStream() can still |
| 2479 // delete the channel in case failure happens below. | 2482 // delete the channel in case failure happens below. |
| 2480 webrtc::AudioTransport* audio_transport = | 2483 webrtc::AudioTransport* audio_transport = |
| 2481 engine()->voe()->base()->audio_transport(); | 2484 engine()->voe()->base()->audio_transport(); |
| 2482 send_channels_.insert(std::make_pair( | 2485 send_channels_.insert(std::make_pair( |
| 2483 sp.first_ssrc(), | 2486 sp.first_ssrc(), |
| 2484 new WebRtcVoiceChannelRenderer(channel, audio_transport))); | 2487 new WebRtcVoiceChannelRenderer(channel, sp.sync_label, audio_transport))); |
| 2485 | 2488 |
| 2486 // Set the send (local) SSRC. | 2489 // Set the send (local) SSRC. |
| 2487 // If there are multiple send SSRCs, we can only set the first one here, and | 2490 // 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 | 2491 // the rest of the SSRC(s) need to be set after SetSendCodec has been called |
| 2489 // (with a codec requires multiple SSRC(s)). | 2492 // (with a codec requires multiple SSRC(s)). |
| 2490 if (engine()->voe()->rtp()->SetLocalSSRC(channel, sp.first_ssrc()) == -1) { | 2493 if (engine()->voe()->rtp()->SetLocalSSRC(channel, sp.first_ssrc()) == -1) { |
| 2491 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); | 2494 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); |
| 2492 return false; | 2495 return false; |
| 2493 } | 2496 } |
| 2494 | 2497 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2567 if (ssrc == 0) { | 2570 if (ssrc == 0) { |
| 2568 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; | 2571 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; |
| 2569 return false; | 2572 return false; |
| 2570 } | 2573 } |
| 2571 | 2574 |
| 2572 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 2575 if (receive_channels_.find(ssrc) != receive_channels_.end()) { |
| 2573 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 2576 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; |
| 2574 return false; | 2577 return false; |
| 2575 } | 2578 } |
| 2576 | 2579 |
| 2577 TryAddAudioRecvStream(ssrc); | |
| 2578 | |
| 2579 // Reuse default channel for recv stream in non-conference mode call | 2580 // Reuse default channel for recv stream in non-conference mode call |
| 2580 // when the default channel is not being used. | 2581 // when the default channel is not being used. |
| 2581 webrtc::AudioTransport* audio_transport = | 2582 webrtc::AudioTransport* audio_transport = |
| 2582 engine()->voe()->base()->audio_transport(); | 2583 engine()->voe()->base()->audio_transport(); |
| 2583 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | 2584 if (!InConferenceMode() && default_receive_ssrc_ == 0) { |
| 2584 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | 2585 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; |
| 2585 default_receive_ssrc_ = ssrc; | 2586 default_receive_ssrc_ = ssrc; |
| 2586 receive_channels_.insert(std::make_pair( | 2587 WebRtcVoiceChannelRenderer* channel_renderer = |
| 2587 default_receive_ssrc_, | 2588 new WebRtcVoiceChannelRenderer(voe_channel(), sp.sync_label, |
| 2588 new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport))); | 2589 audio_transport); |
| 2590 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); |
| 2591 TryAddAudioRecvStream(ssrc, channel_renderer); |
| 2589 return SetPlayout(voe_channel(), playout_); | 2592 return SetPlayout(voe_channel(), playout_); |
| 2590 } | 2593 } |
| 2591 | 2594 |
| 2592 // Create a new channel for receiving audio data. | 2595 // Create a new channel for receiving audio data. |
| 2593 int channel = engine()->CreateMediaVoiceChannel(); | 2596 int channel = engine()->CreateMediaVoiceChannel(); |
| 2594 if (channel == -1) { | 2597 if (channel == -1) { |
| 2595 LOG_RTCERR0(CreateChannel); | 2598 LOG_RTCERR0(CreateChannel); |
| 2596 return false; | 2599 return false; |
| 2597 } | 2600 } |
| 2598 | 2601 |
| 2599 if (!ConfigureRecvChannel(channel)) { | 2602 if (!ConfigureRecvChannel(channel)) { |
| 2600 DeleteChannel(channel); | 2603 DeleteChannel(channel); |
| 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, sp.sync_label, audio_transport); |
| 2606 ssrc, new WebRtcVoiceChannelRenderer(channel, audio_transport))); | 2609 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); |
| 2610 TryAddAudioRecvStream(ssrc, channel_renderer); |
| 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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3443 unsigned int ulevel; | 3447 unsigned int ulevel; |
| 3444 int ret = | 3448 int ret = |
| 3445 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); | 3449 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); |
| 3446 return (ret == 0) ? static_cast<int>(ulevel) : -1; | 3450 return (ret == 0) ? static_cast<int>(ulevel) : -1; |
| 3447 } | 3451 } |
| 3448 | 3452 |
| 3449 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) { | 3453 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) { |
| 3450 ChannelMap::iterator it = receive_channels_.find(ssrc); | 3454 ChannelMap::iterator it = receive_channels_.find(ssrc); |
| 3451 if (it != receive_channels_.end()) | 3455 if (it != receive_channels_.end()) |
| 3452 return it->second->channel(); | 3456 return it->second->channel(); |
| 3453 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; | 3457 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; |
| 3454 } | 3458 } |
| 3455 | 3459 |
| 3456 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) { | 3460 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) { |
| 3457 ChannelMap::iterator it = send_channels_.find(ssrc); | 3461 ChannelMap::iterator it = send_channels_.find(ssrc); |
| 3458 if (it != send_channels_.end()) | 3462 if (it != send_channels_.end()) |
| 3459 return it->second->channel(); | 3463 return it->second->channel(); |
| 3460 | 3464 |
| 3461 return -1; | 3465 return -1; |
| 3462 } | 3466 } |
| 3463 | 3467 |
| 3464 void WebRtcVoiceMediaChannel::SetCall(webrtc::Call* call) { | 3468 void WebRtcVoiceMediaChannel::SetCall(webrtc::Call* call) { |
| 3465 DCHECK(thread_checker_.CalledOnValidThread()); | 3469 DCHECK(thread_checker_.CalledOnValidThread()); |
| 3466 for (const auto& it : receive_channels_) { | 3470 for (const auto& it : receive_channels_) { |
| 3467 TryRemoveAudioRecvStream(it.first); | 3471 TryRemoveAudioRecvStream(it.first); |
| 3468 } | 3472 } |
| 3469 call_ = call; | 3473 call_ = call; |
| 3470 for (const auto& it : receive_channels_) { | 3474 for (const auto& it : receive_channels_) { |
| 3471 TryAddAudioRecvStream(it.first); | 3475 TryAddAudioRecvStream(it.first, it.second); |
| 3472 } | 3476 } |
| 3473 } | 3477 } |
| 3474 | 3478 |
| 3475 bool WebRtcVoiceMediaChannel::GetRedSendCodec(const AudioCodec& red_codec, | 3479 bool WebRtcVoiceMediaChannel::GetRedSendCodec(const AudioCodec& red_codec, |
| 3476 const std::vector<AudioCodec>& all_codecs, webrtc::CodecInst* send_codec) { | 3480 const std::vector<AudioCodec>& all_codecs, webrtc::CodecInst* send_codec) { |
| 3477 // Get the RED encodings from the parameter with no name. This may | 3481 // Get the RED encodings from the parameter with no name. This may |
| 3478 // change based on what is discussed on the Jingle list. | 3482 // change based on what is discussed on the Jingle list. |
| 3479 // The encoding parameter is of the form "a/b"; we only support where | 3483 // The encoding parameter is of the form "a/b"; we only support where |
| 3480 // a == b. Verify this and parse out the value into red_pt. | 3484 // a == b. Verify this and parse out the value into red_pt. |
| 3481 // If the parameter value is absent (as it will be until we wire up the | 3485 // If the parameter value is absent (as it will be until we wire up the |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3614 id = extension->id; | 3618 id = extension->id; |
| 3615 uri = extension->uri; | 3619 uri = extension->uri; |
| 3616 } | 3620 } |
| 3617 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { | 3621 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { |
| 3618 LOG_RTCERR4(*setter, uri, channel_id, enable, id); | 3622 LOG_RTCERR4(*setter, uri, channel_id, enable, id); |
| 3619 return false; | 3623 return false; |
| 3620 } | 3624 } |
| 3621 return true; | 3625 return true; |
| 3622 } | 3626 } |
| 3623 | 3627 |
| 3624 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream(uint32 ssrc) { | 3628 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream( |
| 3629 uint32 ssrc, |
| 3630 WebRtcVoiceChannelRenderer* channel) { |
| 3625 DCHECK(thread_checker_.CalledOnValidThread()); | 3631 DCHECK(thread_checker_.CalledOnValidThread()); |
| 3632 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); |
| 3626 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too. | 3633 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too. |
| 3627 if (call_ && options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) { | 3634 if (!call_) |
| 3628 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); | 3635 return; |
| 3629 webrtc::AudioReceiveStream::Config config; | 3636 webrtc::AudioReceiveStream::Config config; |
| 3630 config.rtp.remote_ssrc = ssrc; | 3637 config.rtp.remote_ssrc = ssrc; |
| 3638 // Only add RTP extensions if we support combined AV BWE. |
| 3639 if (options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) |
| 3631 config.rtp.extensions = recv_rtp_extensions_; | 3640 config.rtp.extensions = recv_rtp_extensions_; |
| 3632 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); | 3641 config.channel_id = channel->channel(); |
| 3633 receive_streams_.insert(std::make_pair(ssrc, s)); | 3642 config.sync_group = channel->sync_label(); |
| 3634 } | 3643 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); |
| 3644 receive_streams_.insert(std::make_pair(ssrc, s)); |
| 3635 } | 3645 } |
| 3636 | 3646 |
| 3637 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) { | 3647 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) { |
| 3638 DCHECK(thread_checker_.CalledOnValidThread()); | 3648 DCHECK(thread_checker_.CalledOnValidThread()); |
| 3639 // If we are hooked up to a webrtc::Call, assume there is an | 3649 // If we are hooked up to a webrtc::Call, assume there is an |
| 3640 // AudioReceiveStream to destroy too. | 3650 // AudioReceiveStream to destroy too. |
| 3641 if (call_) { | 3651 if (call_) { |
| 3642 auto stream_it = receive_streams_.find(ssrc); | 3652 auto stream_it = receive_streams_.find(ssrc); |
| 3643 if (stream_it != receive_streams_.end()) { | 3653 if (stream_it != receive_streams_.end()) { |
| 3644 call_->DestroyAudioReceiveStream(stream_it->second); | 3654 call_->DestroyAudioReceiveStream(stream_it->second); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3655 | 3665 |
| 3656 int WebRtcSoundclipStream::Rewind() { | 3666 int WebRtcSoundclipStream::Rewind() { |
| 3657 mem_.Rewind(); | 3667 mem_.Rewind(); |
| 3658 // Return -1 to keep VoiceEngine from looping. | 3668 // Return -1 to keep VoiceEngine from looping. |
| 3659 return (loop_) ? 0 : -1; | 3669 return (loop_) ? 0 : -1; |
| 3660 } | 3670 } |
| 3661 | 3671 |
| 3662 } // namespace cricket | 3672 } // namespace cricket |
| 3663 | 3673 |
| 3664 #endif // HAVE_WEBRTC_VOICE | 3674 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |