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