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/audio/utility/audio_frame_operations.h" | 16 #include "webrtc/audio/utility/audio_frame_operations.h" |
17 #include "webrtc/base/array_view.h" | 17 #include "webrtc/base/array_view.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
20 #include "webrtc/base/format_macros.h" | 20 #include "webrtc/base/format_macros.h" |
21 #include "webrtc/base/location.h" | 21 #include "webrtc/base/location.h" |
22 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
23 #include "webrtc/base/rate_limiter.h" | 23 #include "webrtc/base/rate_limiter.h" |
24 #include "webrtc/base/thread_checker.h" | |
25 #include "webrtc/base/timeutils.h" | 24 #include "webrtc/base/timeutils.h" |
26 #include "webrtc/config.h" | 25 #include "webrtc/config.h" |
27 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 26 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
28 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" | 27 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" |
29 #include "webrtc/modules/audio_device/include/audio_device.h" | 28 #include "webrtc/modules/audio_device/include/audio_device.h" |
30 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 29 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
31 #include "webrtc/modules/include/module_common_types.h" | 30 #include "webrtc/modules/include/module_common_types.h" |
32 #include "webrtc/modules/pacing/packet_router.h" | 31 #include "webrtc/modules/pacing/packet_router.h" |
33 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 32 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
34 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 33 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 configuration.event_log = &(*event_log_proxy_); | 927 configuration.event_log = &(*event_log_proxy_); |
929 configuration.rtt_stats = &(*rtcp_rtt_stats_proxy_); | 928 configuration.rtt_stats = &(*rtcp_rtt_stats_proxy_); |
930 configuration.retransmission_rate_limiter = | 929 configuration.retransmission_rate_limiter = |
931 retransmission_rate_limiter_.get(); | 930 retransmission_rate_limiter_.get(); |
932 | 931 |
933 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); | 932 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
934 _rtpRtcpModule->SetSendingMediaStatus(false); | 933 _rtpRtcpModule->SetSendingMediaStatus(false); |
935 } | 934 } |
936 | 935 |
937 Channel::~Channel() { | 936 Channel::~Channel() { |
938 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL); | 937 RTC_DCHECK(!channel_state_.Get().sending); |
939 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), | 938 RTC_DCHECK(!channel_state_.Get().playing); |
940 "Channel::~Channel() - dtor"); | |
941 | |
942 StopSend(); | |
943 StopPlayout(); | |
944 | |
945 { | |
946 rtc::CritScope cs(&_fileCritSect); | |
947 if (input_file_player_) { | |
948 input_file_player_->RegisterModuleFileCallback(NULL); | |
949 input_file_player_->StopPlayingFile(); | |
950 } | |
951 if (output_file_player_) { | |
952 output_file_player_->RegisterModuleFileCallback(NULL); | |
953 output_file_player_->StopPlayingFile(); | |
954 } | |
955 if (output_file_recorder_) { | |
956 output_file_recorder_->RegisterModuleFileCallback(NULL); | |
957 output_file_recorder_->StopRecording(); | |
958 } | |
959 } | |
960 | |
961 // The order to safely shutdown modules in a channel is: | |
962 // 1. De-register callbacks in modules | |
963 // 2. De-register modules in process thread | |
964 // 3. Destroy modules | |
965 if (audio_coding_->RegisterTransportCallback(NULL) == -1) { | |
966 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), | |
967 "~Channel() failed to de-register transport callback" | |
968 " (Audio coding module)"); | |
969 } | |
970 if (audio_coding_->RegisterVADCallback(NULL) == -1) { | |
971 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), | |
972 "~Channel() failed to de-register VAD callback" | |
973 " (Audio coding module)"); | |
974 } | |
975 // De-register modules in process thread | |
976 _moduleProcessThreadPtr->DeRegisterModule(_rtpRtcpModule.get()); | |
977 | |
978 // End of modules shutdown | |
979 } | 939 } |
980 | 940 |
981 int32_t Channel::Init() { | 941 int32_t Channel::Init() { |
942 RTC_DCHECK(construction_thread_.CalledOnValidThread()); | |
982 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 943 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
983 "Channel::Init()"); | 944 "Channel::Init()"); |
984 | 945 |
985 channel_state_.Reset(); | 946 channel_state_.Reset(); |
986 | 947 |
987 // --- Initial sanity | 948 // --- Initial sanity |
988 | 949 |
989 if ((_engineStatisticsPtr == NULL) || (_moduleProcessThreadPtr == NULL)) { | 950 if ((_engineStatisticsPtr == NULL) || (_moduleProcessThreadPtr == NULL)) { |
990 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), | 951 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
991 "Channel::Init() must call SetEngineInformation() first"); | 952 "Channel::Init() must call SetEngineInformation() first"); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 "Channel::Init() failed to register CN (%d/%d) " | 1035 "Channel::Init() failed to register CN (%d/%d) " |
1075 "correctly - 1", | 1036 "correctly - 1", |
1076 codec.pltype, codec.plfreq); | 1037 codec.pltype, codec.plfreq); |
1077 } | 1038 } |
1078 } | 1039 } |
1079 } | 1040 } |
1080 | 1041 |
1081 return 0; | 1042 return 0; |
1082 } | 1043 } |
1083 | 1044 |
1045 void Channel::Terminate() { | |
1046 RTC_DCHECK(construction_thread_.CalledOnValidThread()); | |
1047 // Must be called on the same thread as Init(). | |
1048 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), | |
1049 "Channel::Terminate"); | |
1050 | |
1051 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL); | |
1052 | |
1053 StopSend(); | |
the sun
2017/03/20 19:11:12
StopSend() looks like it has races. I'm thinking o
tommi
2017/03/21 09:07:45
I can look into whether we can put thread checks t
| |
1054 StopPlayout(); | |
1055 | |
1056 { | |
1057 rtc::CritScope cs(&_fileCritSect); | |
1058 if (input_file_player_) { | |
1059 input_file_player_->RegisterModuleFileCallback(NULL); | |
1060 input_file_player_->StopPlayingFile(); | |
1061 } | |
1062 if (output_file_player_) { | |
1063 output_file_player_->RegisterModuleFileCallback(NULL); | |
1064 output_file_player_->StopPlayingFile(); | |
1065 } | |
1066 if (output_file_recorder_) { | |
1067 output_file_recorder_->RegisterModuleFileCallback(NULL); | |
1068 output_file_recorder_->StopRecording(); | |
1069 } | |
1070 } | |
1071 | |
1072 // The order to safely shutdown modules in a channel is: | |
1073 // 1. De-register callbacks in modules | |
1074 // 2. De-register modules in process thread | |
1075 // 3. Destroy modules | |
1076 if (audio_coding_->RegisterTransportCallback(NULL) == -1) { | |
1077 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), | |
1078 "Terminate() failed to de-register transport callback" | |
1079 " (Audio coding module)"); | |
1080 } | |
1081 | |
1082 if (audio_coding_->RegisterVADCallback(NULL) == -1) { | |
1083 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), | |
1084 "Terminate() failed to de-register VAD callback" | |
1085 " (Audio coding module)"); | |
1086 } | |
1087 | |
1088 // De-register modules in process thread | |
1089 if (_moduleProcessThreadPtr) | |
1090 _moduleProcessThreadPtr->DeRegisterModule(_rtpRtcpModule.get()); | |
1091 | |
1092 // End of modules shutdown | |
1093 } | |
1094 | |
1084 int32_t Channel::SetEngineInformation(Statistics& engineStatistics, | 1095 int32_t Channel::SetEngineInformation(Statistics& engineStatistics, |
1085 OutputMixer& outputMixer, | 1096 OutputMixer& outputMixer, |
1086 ProcessThread& moduleProcessThread, | 1097 ProcessThread& moduleProcessThread, |
1087 AudioDeviceModule& audioDeviceModule, | 1098 AudioDeviceModule& audioDeviceModule, |
1088 VoiceEngineObserver* voiceEngineObserver, | 1099 VoiceEngineObserver* voiceEngineObserver, |
1089 rtc::CriticalSection* callbackCritSect) { | 1100 rtc::CriticalSection* callbackCritSect) { |
1090 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 1101 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
1091 "Channel::SetEngineInformation()"); | 1102 "Channel::SetEngineInformation()"); |
1092 _engineStatisticsPtr = &engineStatistics; | 1103 _engineStatisticsPtr = &engineStatistics; |
1093 _outputMixerPtr = &outputMixer; | 1104 _outputMixerPtr = &outputMixer; |
(...skipping 1898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2992 int64_t min_rtt = 0; | 3003 int64_t min_rtt = 0; |
2993 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 3004 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
2994 0) { | 3005 0) { |
2995 return 0; | 3006 return 0; |
2996 } | 3007 } |
2997 return rtt; | 3008 return rtt; |
2998 } | 3009 } |
2999 | 3010 |
3000 } // namespace voe | 3011 } // namespace voe |
3001 } // namespace webrtc | 3012 } // namespace webrtc |
OLD | NEW |