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/call/rtc_event_log.h" |
22 #include "webrtc/common.h" | 23 #include "webrtc/common.h" |
23 #include "webrtc/config.h" | 24 #include "webrtc/config.h" |
24 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" | 25 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" |
25 #include "webrtc/modules/audio_device/include/audio_device.h" | 26 #include "webrtc/modules/audio_device/include/audio_device.h" |
26 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 27 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
27 #include "webrtc/modules/include/module_common_types.h" | 28 #include "webrtc/modules/include/module_common_types.h" |
28 #include "webrtc/modules/pacing/packet_router.h" | 29 #include "webrtc/modules/pacing/packet_router.h" |
29 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 30 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
30 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 31 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
31 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 32 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
(...skipping 19 matching lines...) Expand all Loading... |
51 const CodecInst& ci) { | 52 const CodecInst& ci) { |
52 const int result = (*acm)->RegisterReceiveCodec( | 53 const int result = (*acm)->RegisterReceiveCodec( |
53 ci, [&] { return rac->RentIsacDecoder(ci.plfreq); }); | 54 ci, [&] { return rac->RentIsacDecoder(ci.plfreq); }); |
54 return result == 0; | 55 return result == 0; |
55 } | 56 } |
56 | 57 |
57 } // namespace | 58 } // namespace |
58 | 59 |
59 const int kTelephoneEventAttenuationdB = 10; | 60 const int kTelephoneEventAttenuationdB = 10; |
60 | 61 |
| 62 class RtcEventLogProxy final : public webrtc::RtcEventLog { |
| 63 public: |
| 64 RtcEventLogProxy() : event_log_(nullptr) {} |
| 65 |
| 66 bool StartLogging(const std::string& file_name, |
| 67 int64_t max_size_bytes) override { |
| 68 RTC_NOTREACHED(); |
| 69 return false; |
| 70 } |
| 71 |
| 72 bool StartLogging(rtc::PlatformFile log_file, |
| 73 int64_t max_size_bytes) override { |
| 74 RTC_NOTREACHED(); |
| 75 return false; |
| 76 } |
| 77 |
| 78 void StopLogging() override { RTC_NOTREACHED(); } |
| 79 |
| 80 void LogVideoReceiveStreamConfig( |
| 81 const webrtc::VideoReceiveStream::Config& config) override { |
| 82 rtc::CritScope lock(&crit_); |
| 83 if (event_log_) { |
| 84 event_log_->LogVideoReceiveStreamConfig(config); |
| 85 } |
| 86 } |
| 87 |
| 88 void LogVideoSendStreamConfig( |
| 89 const webrtc::VideoSendStream::Config& config) override { |
| 90 rtc::CritScope lock(&crit_); |
| 91 if (event_log_) { |
| 92 event_log_->LogVideoSendStreamConfig(config); |
| 93 } |
| 94 } |
| 95 |
| 96 void LogRtpHeader(webrtc::PacketDirection direction, |
| 97 webrtc::MediaType media_type, |
| 98 const uint8_t* header, |
| 99 size_t packet_length) override { |
| 100 rtc::CritScope lock(&crit_); |
| 101 if (event_log_) { |
| 102 event_log_->LogRtpHeader(direction, media_type, header, packet_length); |
| 103 } |
| 104 } |
| 105 |
| 106 void LogRtcpPacket(webrtc::PacketDirection direction, |
| 107 webrtc::MediaType media_type, |
| 108 const uint8_t* packet, |
| 109 size_t length) override { |
| 110 rtc::CritScope lock(&crit_); |
| 111 if (event_log_) { |
| 112 event_log_->LogRtcpPacket(direction, media_type, packet, length); |
| 113 } |
| 114 } |
| 115 |
| 116 void LogAudioPlayout(uint32_t ssrc) override { |
| 117 rtc::CritScope lock(&crit_); |
| 118 if (event_log_) { |
| 119 event_log_->LogAudioPlayout(ssrc); |
| 120 } |
| 121 } |
| 122 |
| 123 void LogBwePacketLossEvent(int32_t bitrate, |
| 124 uint8_t fraction_loss, |
| 125 int32_t total_packets) override { |
| 126 rtc::CritScope lock(&crit_); |
| 127 if (event_log_) { |
| 128 event_log_->LogBwePacketLossEvent(bitrate, fraction_loss, total_packets); |
| 129 } |
| 130 } |
| 131 |
| 132 void SetEventLog(RtcEventLog* event_log) { |
| 133 rtc::CritScope lock(&crit_); |
| 134 event_log_ = event_log; |
| 135 } |
| 136 |
| 137 private: |
| 138 rtc::CriticalSection crit_; |
| 139 RtcEventLog* event_log_ GUARDED_BY(crit_); |
| 140 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogProxy); |
| 141 }; |
| 142 |
61 class TransportFeedbackProxy : public TransportFeedbackObserver { | 143 class TransportFeedbackProxy : public TransportFeedbackObserver { |
62 public: | 144 public: |
63 TransportFeedbackProxy() : feedback_observer_(nullptr) { | 145 TransportFeedbackProxy() : feedback_observer_(nullptr) { |
64 pacer_thread_.DetachFromThread(); | 146 pacer_thread_.DetachFromThread(); |
65 network_thread_.DetachFromThread(); | 147 network_thread_.DetachFromThread(); |
66 } | 148 } |
67 | 149 |
68 void SetTransportFeedbackObserver( | 150 void SetTransportFeedbackObserver( |
69 TransportFeedbackObserver* feedback_observer) { | 151 TransportFeedbackObserver* feedback_observer) { |
70 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 152 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 header.payload_type_frequency = | 555 header.payload_type_frequency = |
474 rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); | 556 rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); |
475 if (header.payload_type_frequency < 0) | 557 if (header.payload_type_frequency < 0) |
476 return false; | 558 return false; |
477 return ReceivePacket(rtp_packet, rtp_packet_length, header, false); | 559 return ReceivePacket(rtp_packet, rtp_packet_length, header, false); |
478 } | 560 } |
479 | 561 |
480 MixerParticipant::AudioFrameInfo Channel::GetAudioFrameWithMuted( | 562 MixerParticipant::AudioFrameInfo Channel::GetAudioFrameWithMuted( |
481 int32_t id, | 563 int32_t id, |
482 AudioFrame* audioFrame) { | 564 AudioFrame* audioFrame) { |
483 if (event_log_) { | 565 unsigned int ssrc; |
484 unsigned int ssrc; | 566 RTC_CHECK_EQ(GetLocalSSRC(ssrc), 0); |
485 RTC_CHECK_EQ(GetLocalSSRC(ssrc), 0); | 567 event_log_proxy_->LogAudioPlayout(ssrc); |
486 event_log_->LogAudioPlayout(ssrc); | |
487 } | |
488 // Get 10ms raw PCM data from the ACM (mixer limits output frequency) | 568 // Get 10ms raw PCM data from the ACM (mixer limits output frequency) |
489 bool muted; | 569 bool muted; |
490 if (audio_coding_->PlayoutData10Ms(audioFrame->sample_rate_hz_, audioFrame, | 570 if (audio_coding_->PlayoutData10Ms(audioFrame->sample_rate_hz_, audioFrame, |
491 &muted) == -1) { | 571 &muted) == -1) { |
492 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), | 572 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
493 "Channel::GetAudioFrame() PlayoutData10Ms() failed!"); | 573 "Channel::GetAudioFrame() PlayoutData10Ms() failed!"); |
494 // In all likelihood, the audio in this frame is garbage. We return an | 574 // In all likelihood, the audio in this frame is garbage. We return an |
495 // error so that the audio mixer module doesn't add it to the mix. As | 575 // error so that the audio mixer module doesn't add it to the mix. As |
496 // a result, it won't be played out and the actions skipped here are | 576 // a result, it won't be played out and the actions skipped here are |
497 // irrelevant. | 577 // irrelevant. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 } | 744 } |
665 } | 745 } |
666 } | 746 } |
667 | 747 |
668 return (highestNeeded); | 748 return (highestNeeded); |
669 } | 749 } |
670 | 750 |
671 int32_t Channel::CreateChannel(Channel*& channel, | 751 int32_t Channel::CreateChannel(Channel*& channel, |
672 int32_t channelId, | 752 int32_t channelId, |
673 uint32_t instanceId, | 753 uint32_t instanceId, |
674 RtcEventLog* const event_log, | |
675 const Config& config) { | 754 const Config& config) { |
676 return CreateChannel(channel, channelId, instanceId, event_log, config, | 755 return CreateChannel(channel, channelId, instanceId, config, |
677 CreateBuiltinAudioDecoderFactory()); | 756 CreateBuiltinAudioDecoderFactory()); |
678 } | 757 } |
679 | 758 |
680 int32_t Channel::CreateChannel( | 759 int32_t Channel::CreateChannel( |
681 Channel*& channel, | 760 Channel*& channel, |
682 int32_t channelId, | 761 int32_t channelId, |
683 uint32_t instanceId, | 762 uint32_t instanceId, |
684 RtcEventLog* const event_log, | |
685 const Config& config, | 763 const Config& config, |
686 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) { | 764 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) { |
687 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), | 765 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), |
688 "Channel::CreateChannel(channelId=%d, instanceId=%d)", channelId, | 766 "Channel::CreateChannel(channelId=%d, instanceId=%d)", channelId, |
689 instanceId); | 767 instanceId); |
690 | 768 |
691 channel = | 769 channel = new Channel(channelId, instanceId, config, decoder_factory); |
692 new Channel(channelId, instanceId, event_log, config, decoder_factory); | |
693 if (channel == NULL) { | 770 if (channel == NULL) { |
694 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), | 771 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), |
695 "Channel::CreateChannel() unable to allocate memory for" | 772 "Channel::CreateChannel() unable to allocate memory for" |
696 " channel"); | 773 " channel"); |
697 return -1; | 774 return -1; |
698 } | 775 } |
699 return 0; | 776 return 0; |
700 } | 777 } |
701 | 778 |
702 void Channel::PlayNotification(int32_t id, uint32_t durationMs) { | 779 void Channel::PlayNotification(int32_t id, uint32_t durationMs) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 rtc::CritScope cs(&_fileCritSect); | 818 rtc::CritScope cs(&_fileCritSect); |
742 | 819 |
743 _outputFileRecording = false; | 820 _outputFileRecording = false; |
744 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 821 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
745 "Channel::RecordFileEnded() => output file recorder module is" | 822 "Channel::RecordFileEnded() => output file recorder module is" |
746 " shutdown"); | 823 " shutdown"); |
747 } | 824 } |
748 | 825 |
749 Channel::Channel(int32_t channelId, | 826 Channel::Channel(int32_t channelId, |
750 uint32_t instanceId, | 827 uint32_t instanceId, |
751 RtcEventLog* const event_log, | |
752 const Config& config, | 828 const Config& config, |
753 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) | 829 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) |
754 : _instanceId(instanceId), | 830 : _instanceId(instanceId), |
755 _channelId(channelId), | 831 _channelId(channelId), |
756 event_log_(event_log), | 832 event_log_proxy_(new RtcEventLogProxy()), |
757 rtp_header_parser_(RtpHeaderParser::Create()), | 833 rtp_header_parser_(RtpHeaderParser::Create()), |
758 rtp_payload_registry_( | 834 rtp_payload_registry_( |
759 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), | 835 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), |
760 rtp_receive_statistics_( | 836 rtp_receive_statistics_( |
761 ReceiveStatistics::Create(Clock::GetRealTimeClock())), | 837 ReceiveStatistics::Create(Clock::GetRealTimeClock())), |
762 rtp_receiver_( | 838 rtp_receiver_( |
763 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), | 839 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), |
764 this, | 840 this, |
765 this, | 841 this, |
766 rtp_payload_registry_.get())), | 842 rtp_payload_registry_.get())), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 configuration.audio = true; | 925 configuration.audio = true; |
850 configuration.outgoing_transport = this; | 926 configuration.outgoing_transport = this; |
851 configuration.receive_statistics = rtp_receive_statistics_.get(); | 927 configuration.receive_statistics = rtp_receive_statistics_.get(); |
852 configuration.bandwidth_callback = rtcp_observer_.get(); | 928 configuration.bandwidth_callback = rtcp_observer_.get(); |
853 if (pacing_enabled_) { | 929 if (pacing_enabled_) { |
854 configuration.paced_sender = rtp_packet_sender_proxy_.get(); | 930 configuration.paced_sender = rtp_packet_sender_proxy_.get(); |
855 configuration.transport_sequence_number_allocator = | 931 configuration.transport_sequence_number_allocator = |
856 seq_num_allocator_proxy_.get(); | 932 seq_num_allocator_proxy_.get(); |
857 configuration.transport_feedback_callback = feedback_observer_proxy_.get(); | 933 configuration.transport_feedback_callback = feedback_observer_proxy_.get(); |
858 } | 934 } |
859 configuration.event_log = event_log; | 935 configuration.event_log = &(*event_log_proxy_); |
860 | 936 |
861 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); | 937 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
862 _rtpRtcpModule->SetSendingMediaStatus(false); | 938 _rtpRtcpModule->SetSendingMediaStatus(false); |
863 | 939 |
864 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); | 940 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); |
865 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( | 941 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( |
866 statistics_proxy_.get()); | 942 statistics_proxy_.get()); |
867 | 943 |
868 Config audioproc_config; | 944 Config audioproc_config; |
869 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); | 945 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
(...skipping 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3001 rtc::CritScope lock(&assoc_send_channel_lock_); | 3077 rtc::CritScope lock(&assoc_send_channel_lock_); |
3002 Channel* channel = associate_send_channel_.channel(); | 3078 Channel* channel = associate_send_channel_.channel(); |
3003 if (channel && channel->ChannelId() == channel_id) { | 3079 if (channel && channel->ChannelId() == channel_id) { |
3004 // If this channel is associated with a send channel of the specified | 3080 // If this channel is associated with a send channel of the specified |
3005 // Channel ID, disassociate with it. | 3081 // Channel ID, disassociate with it. |
3006 ChannelOwner ref(NULL); | 3082 ChannelOwner ref(NULL); |
3007 associate_send_channel_ = ref; | 3083 associate_send_channel_ = ref; |
3008 } | 3084 } |
3009 } | 3085 } |
3010 | 3086 |
| 3087 void Channel::SetRtcEventLog(RtcEventLog* event_log) { |
| 3088 event_log_proxy_->SetEventLog(event_log); |
| 3089 } |
| 3090 |
3011 int Channel::RegisterExternalMediaProcessing(ProcessingTypes type, | 3091 int Channel::RegisterExternalMediaProcessing(ProcessingTypes type, |
3012 VoEMediaProcess& processObject) { | 3092 VoEMediaProcess& processObject) { |
3013 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 3093 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
3014 "Channel::RegisterExternalMediaProcessing()"); | 3094 "Channel::RegisterExternalMediaProcessing()"); |
3015 | 3095 |
3016 rtc::CritScope cs(&_callbackCritSect); | 3096 rtc::CritScope cs(&_callbackCritSect); |
3017 | 3097 |
3018 if (kPlaybackPerChannel == type) { | 3098 if (kPlaybackPerChannel == type) { |
3019 if (_outputExternalMediaCallbackPtr) { | 3099 if (_outputExternalMediaCallbackPtr) { |
3020 _engineStatisticsPtr->SetLastError( | 3100 _engineStatisticsPtr->SetLastError( |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3482 int64_t min_rtt = 0; | 3562 int64_t min_rtt = 0; |
3483 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 3563 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
3484 0) { | 3564 0) { |
3485 return 0; | 3565 return 0; |
3486 } | 3566 } |
3487 return rtt; | 3567 return rtt; |
3488 } | 3568 } |
3489 | 3569 |
3490 } // namespace voe | 3570 } // namespace voe |
3491 } // namespace webrtc | 3571 } // namespace webrtc |
OLD | NEW |