Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1231)

Side by Side Diff: webrtc/voice_engine/channel.cc

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

Powered by Google App Engine
This is Rietveld 408576698