| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
| 11 #include "webrtc/voice_engine/channel.h" | 11 #include "webrtc/voice_engine/channel.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
| 18 #include "webrtc/base/format_macros.h" | 18 #include "webrtc/base/format_macros.h" |
| 19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 20 #include "webrtc/base/thread_checker.h" | 20 #include "webrtc/base/thread_checker.h" |
| 21 #include "webrtc/base/timeutils.h" | 21 #include "webrtc/base/timeutils.h" |
| 22 #include "webrtc/common.h" | 22 #include "webrtc/common.h" |
| 23 #include "webrtc/config.h" | 23 #include "webrtc/config.h" |
| 24 #include "webrtc/call/rtc_event_log.h" |
| 24 #include "webrtc/modules/audio_device/include/audio_device.h" | 25 #include "webrtc/modules/audio_device/include/audio_device.h" |
| 25 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 26 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 26 #include "webrtc/modules/include/module_common_types.h" | 27 #include "webrtc/modules/include/module_common_types.h" |
| 27 #include "webrtc/modules/pacing/packet_router.h" | 28 #include "webrtc/modules/pacing/packet_router.h" |
| 28 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 29 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
| 29 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 30 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 30 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 31 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
| 31 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" | 32 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" |
| 32 #include "webrtc/modules/utility/include/audio_frame_operations.h" | 33 #include "webrtc/modules/utility/include/audio_frame_operations.h" |
| 33 #include "webrtc/modules/utility/include/process_thread.h" | 34 #include "webrtc/modules/utility/include/process_thread.h" |
| 34 #include "webrtc/system_wrappers/include/trace.h" | 35 #include "webrtc/system_wrappers/include/trace.h" |
| 35 #include "webrtc/voice_engine/include/voe_base.h" | 36 #include "webrtc/voice_engine/include/voe_base.h" |
| 36 #include "webrtc/voice_engine/include/voe_external_media.h" | 37 #include "webrtc/voice_engine/include/voe_external_media.h" |
| 37 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 38 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
| 38 #include "webrtc/voice_engine/output_mixer.h" | 39 #include "webrtc/voice_engine/output_mixer.h" |
| 39 #include "webrtc/voice_engine/statistics.h" | 40 #include "webrtc/voice_engine/statistics.h" |
| 40 #include "webrtc/voice_engine/transmit_mixer.h" | 41 #include "webrtc/voice_engine/transmit_mixer.h" |
| 41 #include "webrtc/voice_engine/utility.h" | 42 #include "webrtc/voice_engine/utility.h" |
| 42 | 43 |
| 43 namespace webrtc { | 44 namespace webrtc { |
| 44 namespace voe { | 45 namespace voe { |
| 45 | 46 |
| 46 const int kTelephoneEventAttenuationdB = 10; | 47 const int kTelephoneEventAttenuationdB = 10; |
| 47 | 48 |
| 49 class RtcEventLogProxy final : public webrtc::RtcEventLog { |
| 50 public: |
| 51 RtcEventLogProxy() : event_log_(nullptr) {} |
| 52 |
| 53 void SetBufferDuration(int64_t buffer_duration_us) override { |
| 54 RTC_NOTREACHED(); |
| 55 } |
| 56 |
| 57 void StartLogging(const std::string& file_name, int duration_ms) override { |
| 58 RTC_NOTREACHED(); |
| 59 } |
| 60 |
| 61 bool StartLogging(rtc::PlatformFile log_file, |
| 62 int64_t max_size_bytes) override { |
| 63 RTC_NOTREACHED(); |
| 64 } |
| 65 |
| 66 void StopLogging() override { RTC_NOTREACHED(); } |
| 67 |
| 68 void LogVideoReceiveStreamConfig( |
| 69 const webrtc::VideoReceiveStream::Config& config) override { |
| 70 rtc::CritScope lock(&crit_); |
| 71 if (event_log_) { |
| 72 event_log_->LogVideoReceiveStreamConfig(config); |
| 73 } |
| 74 } |
| 75 |
| 76 void LogVideoSendStreamConfig( |
| 77 const webrtc::VideoSendStream::Config& config) override { |
| 78 rtc::CritScope lock(&crit_); |
| 79 if (event_log_) { |
| 80 event_log_->LogVideoSendStreamConfig(config); |
| 81 } |
| 82 } |
| 83 |
| 84 void LogRtpHeader(webrtc::PacketDirection direction, |
| 85 webrtc::MediaType media_type, |
| 86 const uint8_t* header, |
| 87 size_t packet_length) override { |
| 88 rtc::CritScope lock(&crit_); |
| 89 if (event_log_) { |
| 90 event_log_->LogRtpHeader(direction, media_type, header, packet_length); |
| 91 } |
| 92 } |
| 93 |
| 94 void LogRtcpPacket(webrtc::PacketDirection direction, |
| 95 webrtc::MediaType media_type, |
| 96 const uint8_t* packet, |
| 97 size_t length) override { |
| 98 rtc::CritScope lock(&crit_); |
| 99 if (event_log_) { |
| 100 event_log_->LogRtcpPacket(direction, media_type, packet, length); |
| 101 } |
| 102 } |
| 103 |
| 104 void LogAudioPlayout(uint32_t ssrc) override { |
| 105 rtc::CritScope lock(&crit_); |
| 106 if (event_log_) { |
| 107 event_log_->LogAudioPlayout(ssrc); |
| 108 } |
| 109 } |
| 110 |
| 111 void LogBwePacketLossEvent(int32_t bitrate, |
| 112 uint8_t fraction_loss, |
| 113 int32_t total_packets) override { |
| 114 rtc::CritScope lock(&crit_); |
| 115 if (event_log_) { |
| 116 event_log_->LogBwePacketLossEvent(bitrate, fraction_loss, total_packets); |
| 117 } |
| 118 } |
| 119 |
| 120 void SetEventLog(RtcEventLog* event_log) { |
| 121 rtc::CritScope lock(&crit_); |
| 122 event_log_ = event_log; |
| 123 } |
| 124 |
| 125 private: |
| 126 rtc::CriticalSection crit_; |
| 127 RtcEventLog* event_log_ GUARDED_BY(crit_); |
| 128 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogProxy); |
| 129 }; |
| 130 |
| 48 class TransportFeedbackProxy : public TransportFeedbackObserver { | 131 class TransportFeedbackProxy : public TransportFeedbackObserver { |
| 49 public: | 132 public: |
| 50 TransportFeedbackProxy() : feedback_observer_(nullptr) { | 133 TransportFeedbackProxy() : feedback_observer_(nullptr) { |
| 51 pacer_thread_.DetachFromThread(); | 134 pacer_thread_.DetachFromThread(); |
| 52 network_thread_.DetachFromThread(); | 135 network_thread_.DetachFromThread(); |
| 53 } | 136 } |
| 54 | 137 |
| 55 void SetTransportFeedbackObserver( | 138 void SetTransportFeedbackObserver( |
| 56 TransportFeedbackObserver* feedback_observer) { | 139 TransportFeedbackObserver* feedback_observer) { |
| 57 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 140 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return false; | 541 return false; |
| 459 } | 542 } |
| 460 header.payload_type_frequency = | 543 header.payload_type_frequency = |
| 461 rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); | 544 rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); |
| 462 if (header.payload_type_frequency < 0) | 545 if (header.payload_type_frequency < 0) |
| 463 return false; | 546 return false; |
| 464 return ReceivePacket(rtp_packet, rtp_packet_length, header, false); | 547 return ReceivePacket(rtp_packet, rtp_packet_length, header, false); |
| 465 } | 548 } |
| 466 | 549 |
| 467 int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) { | 550 int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) { |
| 468 if (event_log_) { | 551 unsigned int ssrc; |
| 469 unsigned int ssrc; | 552 RTC_CHECK_EQ(GetLocalSSRC(ssrc), 0); |
| 470 RTC_CHECK_EQ(GetLocalSSRC(ssrc), 0); | 553 event_log_proxy_->LogAudioPlayout(ssrc); |
| 471 event_log_->LogAudioPlayout(ssrc); | |
| 472 } | |
| 473 // Get 10ms raw PCM data from the ACM (mixer limits output frequency) | 554 // Get 10ms raw PCM data from the ACM (mixer limits output frequency) |
| 474 if (audio_coding_->PlayoutData10Ms(audioFrame->sample_rate_hz_, audioFrame) == | 555 if (audio_coding_->PlayoutData10Ms(audioFrame->sample_rate_hz_, audioFrame) == |
| 475 -1) { | 556 -1) { |
| 476 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), | 557 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 477 "Channel::GetAudioFrame() PlayoutData10Ms() failed!"); | 558 "Channel::GetAudioFrame() PlayoutData10Ms() failed!"); |
| 478 // In all likelihood, the audio in this frame is garbage. We return an | 559 // In all likelihood, the audio in this frame is garbage. We return an |
| 479 // error so that the audio mixer module doesn't add it to the mix. As | 560 // error so that the audio mixer module doesn't add it to the mix. As |
| 480 // a result, it won't be played out and the actions skipped here are | 561 // a result, it won't be played out and the actions skipped here are |
| 481 // irrelevant. | 562 // irrelevant. |
| 482 return -1; | 563 return -1; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 719 } |
| 639 } | 720 } |
| 640 } | 721 } |
| 641 | 722 |
| 642 return (highestNeeded); | 723 return (highestNeeded); |
| 643 } | 724 } |
| 644 | 725 |
| 645 int32_t Channel::CreateChannel(Channel*& channel, | 726 int32_t Channel::CreateChannel(Channel*& channel, |
| 646 int32_t channelId, | 727 int32_t channelId, |
| 647 uint32_t instanceId, | 728 uint32_t instanceId, |
| 648 RtcEventLog* const event_log, | |
| 649 const Config& config) { | 729 const Config& config) { |
| 650 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), | 730 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), |
| 651 "Channel::CreateChannel(channelId=%d, instanceId=%d)", channelId, | 731 "Channel::CreateChannel(channelId=%d, instanceId=%d)", channelId, |
| 652 instanceId); | 732 instanceId); |
| 653 | 733 |
| 654 channel = new Channel(channelId, instanceId, event_log, config); | 734 channel = new Channel(channelId, instanceId, config); |
| 655 if (channel == NULL) { | 735 if (channel == NULL) { |
| 656 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), | 736 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), |
| 657 "Channel::CreateChannel() unable to allocate memory for" | 737 "Channel::CreateChannel() unable to allocate memory for" |
| 658 " channel"); | 738 " channel"); |
| 659 return -1; | 739 return -1; |
| 660 } | 740 } |
| 661 return 0; | 741 return 0; |
| 662 } | 742 } |
| 663 | 743 |
| 664 void Channel::PlayNotification(int32_t id, uint32_t durationMs) { | 744 void Channel::PlayNotification(int32_t id, uint32_t durationMs) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 assert(id == _outputFileRecorderId); | 781 assert(id == _outputFileRecorderId); |
| 702 | 782 |
| 703 rtc::CritScope cs(&_fileCritSect); | 783 rtc::CritScope cs(&_fileCritSect); |
| 704 | 784 |
| 705 _outputFileRecording = false; | 785 _outputFileRecording = false; |
| 706 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 786 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 707 "Channel::RecordFileEnded() => output file recorder module is" | 787 "Channel::RecordFileEnded() => output file recorder module is" |
| 708 " shutdown"); | 788 " shutdown"); |
| 709 } | 789 } |
| 710 | 790 |
| 711 Channel::Channel(int32_t channelId, | 791 Channel::Channel(int32_t channelId, uint32_t instanceId, const Config& config) |
| 712 uint32_t instanceId, | |
| 713 RtcEventLog* const event_log, | |
| 714 const Config& config) | |
| 715 : _instanceId(instanceId), | 792 : _instanceId(instanceId), |
| 716 _channelId(channelId), | 793 _channelId(channelId), |
| 717 event_log_(event_log), | 794 event_log_proxy_(new RtcEventLogProxy()), |
| 718 rtp_header_parser_(RtpHeaderParser::Create()), | 795 rtp_header_parser_(RtpHeaderParser::Create()), |
| 719 rtp_payload_registry_( | 796 rtp_payload_registry_( |
| 720 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), | 797 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), |
| 721 rtp_receive_statistics_( | 798 rtp_receive_statistics_( |
| 722 ReceiveStatistics::Create(Clock::GetRealTimeClock())), | 799 ReceiveStatistics::Create(Clock::GetRealTimeClock())), |
| 723 rtp_receiver_( | 800 rtp_receiver_( |
| 724 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), | 801 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), |
| 725 this, | 802 this, |
| 726 this, | 803 this, |
| 727 rtp_payload_registry_.get())), | 804 rtp_payload_registry_.get())), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 configuration.audio = true; | 885 configuration.audio = true; |
| 809 configuration.outgoing_transport = this; | 886 configuration.outgoing_transport = this; |
| 810 configuration.receive_statistics = rtp_receive_statistics_.get(); | 887 configuration.receive_statistics = rtp_receive_statistics_.get(); |
| 811 configuration.bandwidth_callback = rtcp_observer_.get(); | 888 configuration.bandwidth_callback = rtcp_observer_.get(); |
| 812 if (pacing_enabled_) { | 889 if (pacing_enabled_) { |
| 813 configuration.paced_sender = rtp_packet_sender_proxy_.get(); | 890 configuration.paced_sender = rtp_packet_sender_proxy_.get(); |
| 814 configuration.transport_sequence_number_allocator = | 891 configuration.transport_sequence_number_allocator = |
| 815 seq_num_allocator_proxy_.get(); | 892 seq_num_allocator_proxy_.get(); |
| 816 configuration.transport_feedback_callback = feedback_observer_proxy_.get(); | 893 configuration.transport_feedback_callback = feedback_observer_proxy_.get(); |
| 817 } | 894 } |
| 818 configuration.event_log = event_log; | 895 configuration.event_log = &(*event_log_proxy_); |
| 819 | 896 |
| 820 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); | 897 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
| 821 _rtpRtcpModule->SetSendingMediaStatus(false); | 898 _rtpRtcpModule->SetSendingMediaStatus(false); |
| 822 | 899 |
| 823 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); | 900 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); |
| 824 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( | 901 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( |
| 825 statistics_proxy_.get()); | 902 statistics_proxy_.get()); |
| 826 | 903 |
| 827 Config audioproc_config; | 904 Config audioproc_config; |
| 828 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); | 905 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
| (...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3015 rtc::CritScope lock(&assoc_send_channel_lock_); | 3092 rtc::CritScope lock(&assoc_send_channel_lock_); |
| 3016 Channel* channel = associate_send_channel_.channel(); | 3093 Channel* channel = associate_send_channel_.channel(); |
| 3017 if (channel && channel->ChannelId() == channel_id) { | 3094 if (channel && channel->ChannelId() == channel_id) { |
| 3018 // If this channel is associated with a send channel of the specified | 3095 // If this channel is associated with a send channel of the specified |
| 3019 // Channel ID, disassociate with it. | 3096 // Channel ID, disassociate with it. |
| 3020 ChannelOwner ref(NULL); | 3097 ChannelOwner ref(NULL); |
| 3021 associate_send_channel_ = ref; | 3098 associate_send_channel_ = ref; |
| 3022 } | 3099 } |
| 3023 } | 3100 } |
| 3024 | 3101 |
| 3102 void Channel::SetRtcEventLog(RtcEventLog* event_log) { |
| 3103 event_log_proxy_->SetEventLog(event_log); |
| 3104 } |
| 3105 |
| 3025 int Channel::RegisterExternalMediaProcessing(ProcessingTypes type, | 3106 int Channel::RegisterExternalMediaProcessing(ProcessingTypes type, |
| 3026 VoEMediaProcess& processObject) { | 3107 VoEMediaProcess& processObject) { |
| 3027 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 3108 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3028 "Channel::RegisterExternalMediaProcessing()"); | 3109 "Channel::RegisterExternalMediaProcessing()"); |
| 3029 | 3110 |
| 3030 rtc::CritScope cs(&_callbackCritSect); | 3111 rtc::CritScope cs(&_callbackCritSect); |
| 3031 | 3112 |
| 3032 if (kPlaybackPerChannel == type) { | 3113 if (kPlaybackPerChannel == type) { |
| 3033 if (_outputExternalMediaCallbackPtr) { | 3114 if (_outputExternalMediaCallbackPtr) { |
| 3034 _engineStatisticsPtr->SetLastError( | 3115 _engineStatisticsPtr->SetLastError( |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3528 int64_t min_rtt = 0; | 3609 int64_t min_rtt = 0; |
| 3529 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 3610 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
| 3530 0) { | 3611 0) { |
| 3531 return 0; | 3612 return 0; |
| 3532 } | 3613 } |
| 3533 return rtt; | 3614 return rtt; |
| 3534 } | 3615 } |
| 3535 | 3616 |
| 3536 } // namespace voe | 3617 } // namespace voe |
| 3537 } // namespace webrtc | 3618 } // namespace webrtc |
| OLD | NEW |