| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 AudioOptions GetDefaultEngineOptions() { | 367 AudioOptions GetDefaultEngineOptions() { |
| 368 AudioOptions options; | 368 AudioOptions options; |
| 369 options.echo_cancellation.Set(true); | 369 options.echo_cancellation.Set(true); |
| 370 options.auto_gain_control.Set(true); | 370 options.auto_gain_control.Set(true); |
| 371 options.noise_suppression.Set(true); | 371 options.noise_suppression.Set(true); |
| 372 options.highpass_filter.Set(true); | 372 options.highpass_filter.Set(true); |
| 373 options.stereo_swapping.Set(false); | 373 options.stereo_swapping.Set(false); |
| 374 options.audio_jitter_buffer_max_packets.Set(50); | 374 options.audio_jitter_buffer_max_packets.Set(50); |
| 375 options.audio_jitter_buffer_fast_accelerate.Set(false); | 375 options.audio_jitter_buffer_fast_accelerate.Set(false); |
| 376 options.typing_detection.Set(true); | 376 options.typing_detection.Set(true); |
| 377 options.conference_mode.Set(false); | |
| 378 options.adjust_agc_delta.Set(0); | 377 options.adjust_agc_delta.Set(0); |
| 379 options.experimental_agc.Set(false); | 378 options.experimental_agc.Set(false); |
| 380 options.extended_filter_aec.Set(false); | 379 options.extended_filter_aec.Set(false); |
| 381 options.delay_agnostic_aec.Set(false); | 380 options.delay_agnostic_aec.Set(false); |
| 382 options.experimental_ns.Set(false); | 381 options.experimental_ns.Set(false); |
| 383 options.aec_dump.Set(false); | 382 options.aec_dump.Set(false); |
| 384 return options; | 383 return options; |
| 385 } | 384 } |
| 386 | 385 |
| 387 std::string GetEnableString(bool enable) { | 386 std::string GetEnableString(bool enable) { |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 send_bitrate_setting_(false), | 1393 send_bitrate_setting_(false), |
| 1395 send_bitrate_bps_(0), | 1394 send_bitrate_bps_(0), |
| 1396 options_(), | 1395 options_(), |
| 1397 dtmf_allowed_(false), | 1396 dtmf_allowed_(false), |
| 1398 desired_playout_(false), | 1397 desired_playout_(false), |
| 1399 nack_enabled_(false), | 1398 nack_enabled_(false), |
| 1400 playout_(false), | 1399 playout_(false), |
| 1401 typing_noise_detected_(false), | 1400 typing_noise_detected_(false), |
| 1402 desired_send_(SEND_NOTHING), | 1401 desired_send_(SEND_NOTHING), |
| 1403 send_(SEND_NOTHING), | 1402 send_(SEND_NOTHING), |
| 1404 call_(call), | 1403 call_(call) { |
| 1405 default_receive_ssrc_(0) { | |
| 1406 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1404 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1407 engine->RegisterChannel(this); | 1405 engine->RegisterChannel(this); |
| 1408 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " | 1406 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " |
| 1409 << default_send_channel_id(); | 1407 << default_send_channel_id(); |
| 1410 RTC_DCHECK(nullptr != call); | 1408 RTC_DCHECK(nullptr != call); |
| 1411 ConfigureSendChannel(default_send_channel_id()); | 1409 ConfigureSendChannel(default_send_channel_id()); |
| 1412 SetOptions(options); | 1410 SetOptions(options); |
| 1413 } | 1411 } |
| 1414 | 1412 |
| 1415 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { | 1413 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 return true; | 1822 return true; |
| 1825 } | 1823 } |
| 1826 | 1824 |
| 1827 bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions( | 1825 bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions( |
| 1828 const std::vector<RtpHeaderExtension>& extensions) { | 1826 const std::vector<RtpHeaderExtension>& extensions) { |
| 1829 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1827 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1830 if (receive_extensions_ == extensions) { | 1828 if (receive_extensions_ == extensions) { |
| 1831 return true; | 1829 return true; |
| 1832 } | 1830 } |
| 1833 | 1831 |
| 1834 // The default channel may or may not be in |receive_channels_|. Set the rtp | |
| 1835 // header extensions for default channel regardless. | |
| 1836 if (!SetChannelRecvRtpHeaderExtensions(default_send_channel_id(), | |
| 1837 extensions)) { | |
| 1838 return false; | |
| 1839 } | |
| 1840 | |
| 1841 // Loop through all receive channels and enable/disable the extensions. | |
| 1842 for (const auto& ch : receive_channels_) { | 1832 for (const auto& ch : receive_channels_) { |
| 1843 if (!SetChannelRecvRtpHeaderExtensions(ch.second->channel(), extensions)) { | 1833 if (!SetChannelRecvRtpHeaderExtensions(ch.second->channel(), extensions)) { |
| 1844 return false; | 1834 return false; |
| 1845 } | 1835 } |
| 1846 } | 1836 } |
| 1847 | 1837 |
| 1848 receive_extensions_ = extensions; | 1838 receive_extensions_ = extensions; |
| 1849 | 1839 |
| 1850 // Recreate AudioReceiveStream:s. | 1840 // Recreate AudioReceiveStream:s. |
| 1851 { | 1841 { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 bool WebRtcVoiceMediaChannel::ResumePlayout() { | 1943 bool WebRtcVoiceMediaChannel::ResumePlayout() { |
| 1954 return ChangePlayout(desired_playout_); | 1944 return ChangePlayout(desired_playout_); |
| 1955 } | 1945 } |
| 1956 | 1946 |
| 1957 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { | 1947 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { |
| 1958 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1948 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 1959 if (playout_ == playout) { | 1949 if (playout_ == playout) { |
| 1960 return true; | 1950 return true; |
| 1961 } | 1951 } |
| 1962 | 1952 |
| 1963 // Change the playout of all channels to the new state. | |
| 1964 bool result = true; | |
| 1965 if (receive_channels_.empty()) { | |
| 1966 // Only toggle the default channel if we don't have any other channels. | |
| 1967 result = SetPlayout(default_send_channel_id(), playout); | |
| 1968 } | |
| 1969 for (const auto& ch : receive_channels_) { | 1953 for (const auto& ch : receive_channels_) { |
| 1970 if (!SetPlayout(ch.second->channel(), playout)) { | 1954 if (!SetPlayout(ch.second->channel(), playout)) { |
| 1971 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " | 1955 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " |
| 1972 << ch.second->channel() << " failed"; | 1956 << ch.second->channel() << " failed"; |
| 1973 result = false; | 1957 return false; |
| 1974 break; | |
| 1975 } | 1958 } |
| 1976 } | 1959 } |
| 1977 | 1960 playout_ = playout; |
| 1978 if (result) { | 1961 return true; |
| 1979 playout_ = playout; | |
| 1980 } | |
| 1981 return result; | |
| 1982 } | 1962 } |
| 1983 | 1963 |
| 1984 bool WebRtcVoiceMediaChannel::SetSend(SendFlags send) { | 1964 bool WebRtcVoiceMediaChannel::SetSend(SendFlags send) { |
| 1985 desired_send_ = send; | 1965 desired_send_ = send; |
| 1986 if (!send_channels_.empty()) | 1966 if (!send_channels_.empty()) |
| 1987 return ChangeSend(desired_send_); | 1967 return ChangeSend(desired_send_); |
| 1988 return true; | 1968 return true; |
| 1989 } | 1969 } |
| 1990 | 1970 |
| 1991 bool WebRtcVoiceMediaChannel::PauseSend() { | 1971 bool WebRtcVoiceMediaChannel::PauseSend() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2063 // TODO(ronghuawu): Change this method to return bool. | 2043 // TODO(ronghuawu): Change this method to return bool. |
| 2064 void WebRtcVoiceMediaChannel::ConfigureSendChannel(int channel) { | 2044 void WebRtcVoiceMediaChannel::ConfigureSendChannel(int channel) { |
| 2065 if (engine()->voe()->network()->RegisterExternalTransport( | 2045 if (engine()->voe()->network()->RegisterExternalTransport( |
| 2066 channel, *this) == -1) { | 2046 channel, *this) == -1) { |
| 2067 LOG_RTCERR2(RegisterExternalTransport, channel, this); | 2047 LOG_RTCERR2(RegisterExternalTransport, channel, this); |
| 2068 } | 2048 } |
| 2069 | 2049 |
| 2070 // Enable RTCP (for quality stats and feedback messages) | 2050 // Enable RTCP (for quality stats and feedback messages) |
| 2071 EnableRtcp(channel); | 2051 EnableRtcp(channel); |
| 2072 | 2052 |
| 2073 // Reset all recv codecs; they will be enabled via SetRecvCodecs. | |
| 2074 ResetRecvCodecs(channel); | |
| 2075 | |
| 2076 // Set RTP header extension for the new channel. | 2053 // Set RTP header extension for the new channel. |
| 2077 SetChannelSendRtpHeaderExtensions(channel, send_extensions_); | 2054 SetChannelSendRtpHeaderExtensions(channel, send_extensions_); |
| 2078 } | 2055 } |
| 2079 | 2056 |
| 2080 bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) { | 2057 bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) { |
| 2081 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { | 2058 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { |
| 2082 LOG_RTCERR1(DeRegisterExternalTransport, channel); | 2059 LOG_RTCERR1(DeRegisterExternalTransport, channel); |
| 2083 } | 2060 } |
| 2084 | 2061 |
| 2085 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { | 2062 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); | 2113 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); |
| 2137 return false; | 2114 return false; |
| 2138 } | 2115 } |
| 2139 | 2116 |
| 2140 // At this point the channel's local SSRC has been updated. If the channel is | 2117 // At this point the channel's local SSRC has been updated. If the channel is |
| 2141 // the default channel make sure that all the receive channels are updated as | 2118 // the default channel make sure that all the receive channels are updated as |
| 2142 // well. Receive channels have to have the same SSRC as the default channel in | 2119 // well. Receive channels have to have the same SSRC as the default channel in |
| 2143 // order to send receiver reports with this SSRC. | 2120 // order to send receiver reports with this SSRC. |
| 2144 if (IsDefaultChannel(channel)) { | 2121 if (IsDefaultChannel(channel)) { |
| 2145 for (const auto& ch : receive_channels_) { | 2122 for (const auto& ch : receive_channels_) { |
| 2146 // Only update the SSRC for non-default channels. | 2123 if (engine()->voe()->rtp()->SetLocalSSRC(ch.second->channel(), |
| 2147 if (!IsDefaultChannel(ch.second->channel())) { | 2124 sp.first_ssrc()) != 0) { |
| 2148 if (engine()->voe()->rtp()->SetLocalSSRC(ch.second->channel(), | 2125 LOG_RTCERR2(SetLocalSSRC, ch.second->channel(), sp.first_ssrc()); |
| 2149 sp.first_ssrc()) != 0) { | 2126 return false; |
| 2150 LOG_RTCERR2(SetLocalSSRC, ch.second->channel(), sp.first_ssrc()); | |
| 2151 return false; | |
| 2152 } | |
| 2153 } | 2127 } |
| 2154 } | 2128 } |
| 2155 } | 2129 } |
| 2156 | 2130 |
| 2157 if (engine()->voe()->rtp()->SetRTCP_CNAME(channel, sp.cname.c_str()) == -1) { | 2131 if (engine()->voe()->rtp()->SetRTCP_CNAME(channel, sp.cname.c_str()) == -1) { |
| 2158 LOG_RTCERR2(SetRTCP_CNAME, channel, sp.cname); | 2132 LOG_RTCERR2(SetRTCP_CNAME, channel, sp.cname); |
| 2159 return false; | 2133 return false; |
| 2160 } | 2134 } |
| 2161 | 2135 |
| 2162 // Set the current codecs to be used for the new channel. | 2136 // Set the current codecs to be used for the new channel. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 if (!ValidateStreamParams(sp)) { | 2181 if (!ValidateStreamParams(sp)) { |
| 2208 return false; | 2182 return false; |
| 2209 } | 2183 } |
| 2210 | 2184 |
| 2211 uint32_t ssrc = sp.first_ssrc(); | 2185 uint32_t ssrc = sp.first_ssrc(); |
| 2212 if (ssrc == 0) { | 2186 if (ssrc == 0) { |
| 2213 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; | 2187 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; |
| 2214 return false; | 2188 return false; |
| 2215 } | 2189 } |
| 2216 | 2190 |
| 2217 rtc::CritScope lock(&receive_channels_cs_); | 2191 // Remove the default receive stream if one had been created with this ssrc; |
| 2192 // we'll recreate it then. |
| 2193 if (IsDefaultRecvStream(ssrc)) { |
| 2194 RemoveRecvStream(ssrc); |
| 2195 } |
| 2218 | 2196 |
| 2219 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 2197 if (receive_channels_.find(ssrc) != receive_channels_.end()) { |
| 2220 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 2198 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; |
| 2221 return false; | 2199 return false; |
| 2222 } | 2200 } |
| 2223 | |
| 2224 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); | 2201 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); |
| 2225 | 2202 |
| 2226 // Reuse default channel for recv stream in non-conference mode call | |
| 2227 // when the default channel is not being used. | |
| 2228 webrtc::AudioTransport* audio_transport = | |
| 2229 engine()->voe()->base()->audio_transport(); | |
| 2230 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | |
| 2231 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | |
| 2232 default_receive_ssrc_ = ssrc; | |
| 2233 WebRtcVoiceChannelRenderer* channel_renderer = | |
| 2234 new WebRtcVoiceChannelRenderer(default_send_channel_id(), | |
| 2235 audio_transport); | |
| 2236 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | |
| 2237 receive_stream_params_[ssrc] = sp; | |
| 2238 AddAudioReceiveStream(ssrc); | |
| 2239 return SetPlayout(default_send_channel_id(), playout_); | |
| 2240 } | |
| 2241 | |
| 2242 // Create a new channel for receiving audio data. | 2203 // Create a new channel for receiving audio data. |
| 2243 int channel = engine()->CreateMediaVoiceChannel(); | 2204 int channel = engine()->CreateMediaVoiceChannel(); |
| 2244 if (channel == -1) { | 2205 if (channel == -1) { |
| 2245 LOG_RTCERR0(CreateChannel); | 2206 LOG_RTCERR0(CreateChannel); |
| 2246 return false; | 2207 return false; |
| 2247 } | 2208 } |
| 2248 if (!ConfigureRecvChannel(channel)) { | 2209 if (!ConfigureRecvChannel(channel)) { |
| 2249 DeleteChannel(channel); | 2210 DeleteChannel(channel); |
| 2250 return false; | 2211 return false; |
| 2251 } | 2212 } |
| 2252 | 2213 |
| 2214 webrtc::AudioTransport* audio_transport = |
| 2215 engine()->voe()->base()->audio_transport(); |
| 2253 WebRtcVoiceChannelRenderer* channel_renderer = | 2216 WebRtcVoiceChannelRenderer* channel_renderer = |
| 2254 new WebRtcVoiceChannelRenderer(channel, audio_transport); | 2217 new WebRtcVoiceChannelRenderer(channel, audio_transport); |
| 2255 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | 2218 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); |
| 2256 receive_stream_params_[ssrc] = sp; | 2219 receive_stream_params_[ssrc] = sp; |
| 2257 AddAudioReceiveStream(ssrc); | 2220 AddAudioReceiveStream(ssrc); |
| 2258 | 2221 |
| 2259 LOG(LS_INFO) << "New audio stream " << ssrc | 2222 LOG(LS_INFO) << "New audio stream " << ssrc |
| 2260 << " registered to VoiceEngine channel #" | 2223 << " registered to VoiceEngine channel #" |
| 2261 << channel << "."; | 2224 << channel << "."; |
| 2262 return true; | 2225 return true; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2285 } | 2248 } |
| 2286 | 2249 |
| 2287 // Associate receive channel to default send channel (so the receive channel | 2250 // Associate receive channel to default send channel (so the receive channel |
| 2288 // can obtain RTT from the send channel). | 2251 // can obtain RTT from the send channel). |
| 2289 engine()->voe()->base()->AssociateSendChannel(channel, | 2252 engine()->voe()->base()->AssociateSendChannel(channel, |
| 2290 default_send_channel_id()); | 2253 default_send_channel_id()); |
| 2291 LOG(LS_INFO) << "VoiceEngine channel #" | 2254 LOG(LS_INFO) << "VoiceEngine channel #" |
| 2292 << channel << " is associated with channel #" | 2255 << channel << " is associated with channel #" |
| 2293 << default_send_channel_id() << "."; | 2256 << default_send_channel_id() << "."; |
| 2294 | 2257 |
| 2295 // Use the same recv payload types as our default channel. | 2258 // Turn off all supported codecs. |
| 2296 ResetRecvCodecs(channel); | 2259 int ncodecs = engine()->voe()->codec()->NumOfCodecs(); |
| 2297 if (!recv_codecs_.empty()) { | 2260 for (int i = 0; i < ncodecs; ++i) { |
| 2298 for (const auto& codec : recv_codecs_) { | 2261 webrtc::CodecInst voe_codec; |
| 2299 webrtc::CodecInst voe_codec; | 2262 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) { |
| 2300 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { | 2263 voe_codec.pltype = -1; |
| 2301 voe_codec.pltype = codec.id; | 2264 if (engine()->voe()->codec()->SetRecPayloadType( |
| 2302 voe_codec.rate = 0; // Needed to make GetRecPayloadType work for ISAC | 2265 channel, voe_codec) == -1) { |
| 2303 if (engine()->voe()->codec()->GetRecPayloadType( | 2266 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); |
| 2304 default_send_channel_id(), voe_codec) != -1) { | 2267 return false; |
| 2305 if (engine()->voe()->codec()->SetRecPayloadType( | |
| 2306 channel, voe_codec) == -1) { | |
| 2307 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); | |
| 2308 return false; | |
| 2309 } | |
| 2310 } | |
| 2311 } | 2268 } |
| 2312 } | 2269 } |
| 2313 } | 2270 } |
| 2314 | 2271 |
| 2315 if (InConferenceMode()) { | 2272 // Only enable those configured for this channel. |
| 2316 // To be in par with the video, default_send_channel_id() is not used for | 2273 for (const auto& codec : recv_codecs_) { |
| 2317 // receiving in a conference call. | 2274 webrtc::CodecInst voe_codec; |
| 2318 if (receive_channels_.empty() && default_receive_ssrc_ == 0 && playout_) { | 2275 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { |
| 2319 // This is the first stream in a multi user meeting. We can now | 2276 voe_codec.pltype = codec.id; |
| 2320 // disable playback of the default stream. This since the default | 2277 if (engine()->voe()->codec()->SetRecPayloadType( |
| 2321 // stream will probably have received some initial packets before | 2278 channel, voe_codec) == -1) { |
| 2322 // the new stream was added. This will mean that the CN state from | 2279 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); |
| 2323 // the default channel will be mixed in with the other streams | 2280 return false; |
| 2324 // throughout the whole meeting, which might be disturbing. | 2281 } |
| 2325 LOG(LS_INFO) << "Disabling playback on the default voice channel"; | |
| 2326 SetPlayout(default_send_channel_id(), false); | |
| 2327 } | 2282 } |
| 2328 } | 2283 } |
| 2329 | 2284 |
| 2330 SetNack(channel, nack_enabled_); | 2285 SetNack(channel, nack_enabled_); |
| 2331 | 2286 |
| 2332 // Set RTP header extension for the new channel. | 2287 // Set RTP header extension for the new channel. |
| 2333 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { | 2288 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { |
| 2334 return false; | 2289 return false; |
| 2335 } | 2290 } |
| 2336 | 2291 |
| 2337 return SetPlayout(channel, playout_); | 2292 SetPlayout(channel, playout_); |
| 2293 return true; |
| 2338 } | 2294 } |
| 2339 | 2295 |
| 2340 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { | 2296 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { |
| 2341 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2297 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2342 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; | 2298 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; |
| 2343 | 2299 |
| 2344 rtc::CritScope lock(&receive_channels_cs_); | |
| 2345 ChannelMap::iterator it = receive_channels_.find(ssrc); | 2300 ChannelMap::iterator it = receive_channels_.find(ssrc); |
| 2346 if (it == receive_channels_.end()) { | 2301 if (it == receive_channels_.end()) { |
| 2347 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 2302 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc |
| 2348 << " which doesn't exist."; | 2303 << " which doesn't exist."; |
| 2349 return false; | 2304 return false; |
| 2350 } | 2305 } |
| 2351 | 2306 |
| 2352 RemoveAudioReceiveStream(ssrc); | 2307 RemoveAudioReceiveStream(ssrc); |
| 2353 receive_stream_params_.erase(ssrc); | 2308 receive_stream_params_.erase(ssrc); |
| 2354 | 2309 |
| 2355 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this | 2310 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this |
| 2356 // will disconnect the audio renderer with the receive channel. | 2311 // will disconnect the audio renderer with the receive channel. |
| 2357 // Cache the channel before the deletion. | 2312 // Cache the channel before the deletion. |
| 2358 const int channel = it->second->channel(); | 2313 const int channel = it->second->channel(); |
| 2359 delete it->second; | 2314 delete it->second; |
| 2360 receive_channels_.erase(it); | 2315 receive_channels_.erase(it); |
| 2361 | 2316 |
| 2362 if (ssrc == default_receive_ssrc_) { | 2317 // Deregister default channel, if that's the one being destroyed. |
| 2363 RTC_DCHECK(IsDefaultChannel(channel)); | 2318 if (IsDefaultRecvStream(ssrc)) { |
| 2364 // Recycle the default channel is for recv stream. | 2319 default_recv_ssrc_ = -1; |
| 2365 if (playout_) | |
| 2366 SetPlayout(default_send_channel_id(), false); | |
| 2367 | |
| 2368 default_receive_ssrc_ = 0; | |
| 2369 return true; | |
| 2370 } | 2320 } |
| 2371 | 2321 |
| 2372 LOG(LS_INFO) << "Removing audio stream " << ssrc | 2322 LOG(LS_INFO) << "Removing audio stream " << ssrc |
| 2373 << " with VoiceEngine channel #" << channel << "."; | 2323 << " with VoiceEngine channel #" << channel << "."; |
| 2374 if (!DeleteChannel(channel)) | 2324 return DeleteChannel(channel); |
| 2375 return false; | |
| 2376 | |
| 2377 bool enable_default_channel_playout = false; | |
| 2378 if (receive_channels_.empty()) { | |
| 2379 // The last stream was removed. We can now enable the default | |
| 2380 // channel for new channels to be played out immediately without | |
| 2381 // waiting for AddStream messages. | |
| 2382 // We do this for both conference mode and non-conference mode. | |
| 2383 // TODO(oja): Does the default channel still have it's CN state? | |
| 2384 enable_default_channel_playout = true; | |
| 2385 } | |
| 2386 if (!InConferenceMode() && receive_channels_.size() == 1 && | |
| 2387 default_receive_ssrc_ != 0) { | |
| 2388 // Only the default channel is active, enable the playout on default | |
| 2389 // channel. | |
| 2390 enable_default_channel_playout = true; | |
| 2391 } | |
| 2392 if (enable_default_channel_playout && playout_) { | |
| 2393 LOG(LS_INFO) << "Enabling playback on the default voice channel"; | |
| 2394 SetPlayout(default_send_channel_id(), true); | |
| 2395 } | |
| 2396 | |
| 2397 return true; | |
| 2398 } | 2325 } |
| 2399 | 2326 |
| 2400 bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc, | 2327 bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc, |
| 2401 AudioRenderer* renderer) { | 2328 AudioRenderer* renderer) { |
| 2402 ChannelMap::iterator it = send_channels_.find(ssrc); | 2329 ChannelMap::iterator it = send_channels_.find(ssrc); |
| 2403 if (it == send_channels_.end()) { | 2330 if (it == send_channels_.end()) { |
| 2404 if (renderer) { | 2331 if (renderer) { |
| 2405 // Return an error if trying to set a valid renderer with an invalid ssrc. | 2332 // Return an error if trying to set a valid renderer with an invalid ssrc. |
| 2406 LOG(LS_ERROR) << "SetLocalRenderer failed with ssrc "<< ssrc; | 2333 LOG(LS_ERROR) << "SetLocalRenderer failed with ssrc "<< ssrc; |
| 2407 return false; | 2334 return false; |
| 2408 } | 2335 } |
| 2409 | 2336 |
| 2410 // The channel likely has gone away, do nothing. | 2337 // The channel likely has gone away, do nothing. |
| 2411 return true; | 2338 return true; |
| 2412 } | 2339 } |
| 2413 | 2340 |
| 2414 if (renderer) | 2341 if (renderer) { |
| 2415 it->second->Start(renderer); | 2342 it->second->Start(renderer); |
| 2416 else | 2343 } else { |
| 2417 it->second->Stop(); | 2344 it->second->Stop(); |
| 2345 } |
| 2418 | 2346 |
| 2419 return true; | 2347 return true; |
| 2420 } | 2348 } |
| 2421 | 2349 |
| 2422 bool WebRtcVoiceMediaChannel::GetActiveStreams( | 2350 bool WebRtcVoiceMediaChannel::GetActiveStreams( |
| 2423 AudioInfo::StreamList* actives) { | 2351 AudioInfo::StreamList* actives) { |
| 2424 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2352 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2425 // In conference mode, the default channel should not be in | |
| 2426 // |receive_channels_|. | |
| 2427 actives->clear(); | 2353 actives->clear(); |
| 2428 for (const auto& ch : receive_channels_) { | 2354 for (const auto& ch : receive_channels_) { |
| 2429 int level = GetOutputLevel(ch.second->channel()); | 2355 int level = GetOutputLevel(ch.second->channel()); |
| 2430 if (level > 0) { | 2356 if (level > 0) { |
| 2431 actives->push_back(std::make_pair(ch.first, level)); | 2357 actives->push_back(std::make_pair(ch.first, level)); |
| 2432 } | 2358 } |
| 2433 } | 2359 } |
| 2434 return true; | 2360 return true; |
| 2435 } | 2361 } |
| 2436 | 2362 |
| 2437 int WebRtcVoiceMediaChannel::GetOutputLevel() { | 2363 int WebRtcVoiceMediaChannel::GetOutputLevel() { |
| 2438 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2364 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2439 // return the highest output level of all streams | 2365 int highest = 0; |
| 2440 int highest = GetOutputLevel(default_send_channel_id()); | |
| 2441 for (const auto& ch : receive_channels_) { | 2366 for (const auto& ch : receive_channels_) { |
| 2442 highest = std::max(GetOutputLevel(ch.second->channel()), highest); | 2367 highest = std::max(GetOutputLevel(ch.second->channel()), highest); |
| 2443 } | 2368 } |
| 2444 return highest; | 2369 return highest; |
| 2445 } | 2370 } |
| 2446 | 2371 |
| 2447 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() { | 2372 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() { |
| 2448 int ret; | 2373 int ret; |
| 2449 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) { | 2374 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) { |
| 2450 // In case of error, log the info and continue | 2375 // In case of error, log the info and continue |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2464 reporting_threshold, penalty_decay, type_event_delay) == -1) { | 2389 reporting_threshold, penalty_decay, type_event_delay) == -1) { |
| 2465 // In case of error, log the info and continue | 2390 // In case of error, log the info and continue |
| 2466 LOG_RTCERR5(SetTypingDetectionParameters, time_window, | 2391 LOG_RTCERR5(SetTypingDetectionParameters, time_window, |
| 2467 cost_per_typing, reporting_threshold, penalty_decay, | 2392 cost_per_typing, reporting_threshold, penalty_decay, |
| 2468 type_event_delay); | 2393 type_event_delay); |
| 2469 } | 2394 } |
| 2470 } | 2395 } |
| 2471 | 2396 |
| 2472 bool WebRtcVoiceMediaChannel::SetOutputVolume(uint32_t ssrc, double volume) { | 2397 bool WebRtcVoiceMediaChannel::SetOutputVolume(uint32_t ssrc, double volume) { |
| 2473 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2398 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2474 rtc::CritScope lock(&receive_channels_cs_); | 2399 if (ssrc == 0) { |
| 2475 // Collect the channels to scale the output volume. | 2400 default_recv_volume_ = volume; |
| 2476 std::vector<int> channels; | 2401 if (default_recv_ssrc_ == -1) { |
| 2477 if (0 == ssrc) { // Collect all channels, including the default one. | 2402 return true; |
| 2478 // Default channel is not in receive_channels_ if it is not being used for | |
| 2479 // playout. | |
| 2480 if (default_receive_ssrc_ == 0) | |
| 2481 channels.push_back(default_send_channel_id()); | |
| 2482 for (const auto& ch : receive_channels_) { | |
| 2483 channels.push_back(ch.second->channel()); | |
| 2484 } | 2403 } |
| 2485 } else { // Collect only the channel of the specified ssrc. | 2404 ssrc = static_cast<uint32_t>(default_recv_ssrc_); |
| 2486 int channel = GetReceiveChannelId(ssrc); | 2405 } |
| 2487 if (-1 == channel) { | 2406 int ch_id = GetReceiveChannelId(ssrc); |
| 2488 LOG(LS_WARNING) << "Cannot find channel for ssrc:" << ssrc; | 2407 if (ch_id < 0) { |
| 2489 return false; | 2408 LOG(LS_WARNING) << "Cannot find channel for ssrc:" << ssrc; |
| 2490 } | 2409 return false; |
| 2491 channels.push_back(channel); | |
| 2492 } | 2410 } |
| 2493 | 2411 |
| 2494 for (int ch_id : channels) { | 2412 if (-1 == engine()->voe()->volume()->SetChannelOutputVolumeScaling(ch_id, |
| 2495 if (-1 == engine()->voe()->volume()->SetChannelOutputVolumeScaling( | 2413 volume)) { |
| 2496 ch_id, volume)) { | 2414 LOG_RTCERR2(SetChannelOutputVolumeScaling, ch_id, volume); |
| 2497 LOG_RTCERR2(SetChannelOutputVolumeScaling, ch_id, volume); | 2415 return false; |
| 2498 return false; | |
| 2499 } | |
| 2500 LOG(LS_INFO) << "SetOutputVolume to " << volume | |
| 2501 << " for channel " << ch_id << " and ssrc " << ssrc; | |
| 2502 } | 2416 } |
| 2417 LOG(LS_INFO) << "SetOutputVolume to " << volume |
| 2418 << " for channel " << ch_id << " and ssrc " << ssrc; |
| 2503 return true; | 2419 return true; |
| 2504 } | 2420 } |
| 2505 | 2421 |
| 2506 bool WebRtcVoiceMediaChannel::CanInsertDtmf() { | 2422 bool WebRtcVoiceMediaChannel::CanInsertDtmf() { |
| 2507 return dtmf_allowed_; | 2423 return dtmf_allowed_; |
| 2508 } | 2424 } |
| 2509 | 2425 |
| 2510 bool WebRtcVoiceMediaChannel::InsertDtmf(uint32_t ssrc, | 2426 bool WebRtcVoiceMediaChannel::InsertDtmf(uint32_t ssrc, |
| 2511 int event, | 2427 int event, |
| 2512 int duration, | 2428 int duration, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2556 } | 2472 } |
| 2557 } | 2473 } |
| 2558 | 2474 |
| 2559 return true; | 2475 return true; |
| 2560 } | 2476 } |
| 2561 | 2477 |
| 2562 void WebRtcVoiceMediaChannel::OnPacketReceived( | 2478 void WebRtcVoiceMediaChannel::OnPacketReceived( |
| 2563 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 2479 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
| 2564 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2480 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2565 | 2481 |
| 2566 // Forward packet to Call as well. | 2482 uint32_t ssrc = 0; |
| 2483 if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) { |
| 2484 return; |
| 2485 } |
| 2486 |
| 2487 if (receive_channels_.empty()) { |
| 2488 // Create new channel, which will be the default receive channel. |
| 2489 StreamParams sp; |
| 2490 sp.ssrcs.push_back(ssrc); |
| 2491 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; |
| 2492 if (!AddRecvStream(sp)) { |
| 2493 LOG(LS_WARNING) << "Could not create default receive stream."; |
| 2494 return; |
| 2495 } |
| 2496 default_recv_ssrc_ = ssrc; |
| 2497 SetOutputVolume(default_recv_ssrc_, default_recv_volume_); |
| 2498 } |
| 2499 |
| 2500 // Forward packet to Call. If the SSRC is unknown we'll return after this. |
| 2567 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2501 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
| 2568 packet_time.not_before); | 2502 packet_time.not_before); |
| 2569 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2503 webrtc::PacketReceiver::DeliveryStatus delivery_result = |
| 2570 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2504 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
| 2571 webrtc_packet_time); | 2505 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
| 2506 webrtc_packet_time); |
| 2507 if (webrtc::PacketReceiver::DELIVERY_OK != delivery_result) { |
| 2508 return; |
| 2509 } |
| 2572 | 2510 |
| 2573 // Pick which channel to send this packet to. If this packet doesn't match | 2511 // Find the channel to send this packet to. It must exist since webrtc::Call |
| 2574 // any multiplexed streams, just send it to the default channel. Otherwise, | 2512 // was able to demux the packet. |
| 2575 // send it to the specific decoder instance for that stream. | 2513 int channel = GetReceiveChannelId(ssrc); |
| 2576 int which_channel = | 2514 RTC_DCHECK(channel != -1); |
| 2577 GetReceiveChannelId(ParseSsrc(packet->data(), packet->size(), false)); | |
| 2578 if (which_channel == -1) { | |
| 2579 which_channel = default_send_channel_id(); | |
| 2580 } | |
| 2581 | 2515 |
| 2582 // Pass it off to the decoder. | 2516 // Pass it off to the decoder. |
| 2583 engine()->voe()->network()->ReceivedRTPPacket( | 2517 engine()->voe()->network()->ReceivedRTPPacket( |
| 2584 which_channel, packet->data(), packet->size(), | 2518 channel, packet->data(), packet->size(), webrtc_packet_time); |
| 2585 webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); | |
| 2586 } | 2519 } |
| 2587 | 2520 |
| 2588 void WebRtcVoiceMediaChannel::OnRtcpReceived( | 2521 void WebRtcVoiceMediaChannel::OnRtcpReceived( |
| 2589 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 2522 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
| 2590 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2523 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2591 | 2524 |
| 2592 // Forward packet to Call as well. | 2525 // Forward packet to Call as well. |
| 2593 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2526 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
| 2594 packet_time.not_before); | 2527 packet_time.not_before); |
| 2595 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2528 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
| 2596 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2529 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
| 2597 webrtc_packet_time); | 2530 webrtc_packet_time); |
| 2598 | 2531 |
| 2599 // Sending channels need all RTCP packets with feedback information. | 2532 // Sending channels need all RTCP packets with feedback information. |
| 2600 // Even sender reports can contain attached report blocks. | 2533 // Even sender reports can contain attached report blocks. |
| 2601 // Receiving channels need sender reports in order to create | 2534 // Receiving channels need sender reports in order to create |
| 2602 // correct receiver reports. | 2535 // correct receiver reports. |
| 2603 int type = 0; | 2536 int type = 0; |
| 2604 if (!GetRtcpType(packet->data(), packet->size(), &type)) { | 2537 if (!GetRtcpType(packet->data(), packet->size(), &type)) { |
| 2605 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; | 2538 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; |
| 2606 return; | 2539 return; |
| 2607 } | 2540 } |
| 2608 | 2541 |
| 2609 // If it is a sender report, find the receive channel that is listening. | 2542 // If it is a sender report, find the receive channel that is listening. |
| 2610 bool has_sent_to_default_channel = false; | |
| 2611 if (type == kRtcpTypeSR) { | 2543 if (type == kRtcpTypeSR) { |
| 2612 uint32_t ssrc = 0; | 2544 uint32_t ssrc = 0; |
| 2613 if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) { | 2545 if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) { |
| 2614 return; | 2546 return; |
| 2615 } | 2547 } |
| 2616 int recv_channel_id = GetReceiveChannelId(ssrc); | 2548 int recv_channel_id = GetReceiveChannelId(ssrc); |
| 2617 if (recv_channel_id != -1) { | 2549 if (recv_channel_id != -1) { |
| 2618 engine()->voe()->network()->ReceivedRTCPPacket( | 2550 engine()->voe()->network()->ReceivedRTCPPacket( |
| 2619 recv_channel_id, packet->data(), packet->size()); | 2551 recv_channel_id, packet->data(), packet->size()); |
| 2620 | |
| 2621 if (IsDefaultChannel(recv_channel_id)) | |
| 2622 has_sent_to_default_channel = true; | |
| 2623 } | 2552 } |
| 2624 } | 2553 } |
| 2625 | 2554 |
| 2626 // SR may continue RR and any RR entry may correspond to any one of the send | 2555 // SR may continue RR and any RR entry may correspond to any one of the send |
| 2627 // channels. So all RTCP packets must be forwarded all send channels. VoE | 2556 // channels. So all RTCP packets must be forwarded all send channels. VoE |
| 2628 // will filter out RR internally. | 2557 // will filter out RR internally. |
| 2629 for (const auto& ch : send_channels_) { | 2558 for (const auto& ch : send_channels_) { |
| 2630 // Make sure not sending the same packet to default channel more than once. | |
| 2631 if (IsDefaultChannel(ch.second->channel()) && | |
| 2632 has_sent_to_default_channel) | |
| 2633 continue; | |
| 2634 | |
| 2635 engine()->voe()->network()->ReceivedRTCPPacket( | 2559 engine()->voe()->network()->ReceivedRTCPPacket( |
| 2636 ch.second->channel(), packet->data(), packet->size()); | 2560 ch.second->channel(), packet->data(), packet->size()); |
| 2637 } | 2561 } |
| 2638 } | 2562 } |
| 2639 | 2563 |
| 2640 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { | 2564 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { |
| 2641 int channel = | 2565 int channel = |
| 2642 (ssrc == 0) ? default_send_channel_id() : GetSendChannelId(ssrc); | 2566 (ssrc == 0) ? default_send_channel_id() : GetSendChannelId(ssrc); |
| 2643 if (channel == -1) { | 2567 if (channel == -1) { |
| 2644 LOG(LS_WARNING) << "The specified ssrc " << ssrc << " is not in use."; | 2568 LOG(LS_WARNING) << "The specified ssrc " << ssrc << " is not in use."; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2819 sinfo.echo_return_loss_enhancement = echo_return_loss_enhancement; | 2743 sinfo.echo_return_loss_enhancement = echo_return_loss_enhancement; |
| 2820 sinfo.echo_delay_median_ms = echo_delay_median_ms; | 2744 sinfo.echo_delay_median_ms = echo_delay_median_ms; |
| 2821 sinfo.echo_delay_std_ms = echo_delay_std_ms; | 2745 sinfo.echo_delay_std_ms = echo_delay_std_ms; |
| 2822 // TODO(ajm): Re-enable this metric once we have a reliable implementation. | 2746 // TODO(ajm): Re-enable this metric once we have a reliable implementation. |
| 2823 sinfo.aec_quality_min = -1; | 2747 sinfo.aec_quality_min = -1; |
| 2824 sinfo.typing_noise_detected = typing_noise_detected_; | 2748 sinfo.typing_noise_detected = typing_noise_detected_; |
| 2825 | 2749 |
| 2826 info->senders.push_back(sinfo); | 2750 info->senders.push_back(sinfo); |
| 2827 } | 2751 } |
| 2828 | 2752 |
| 2829 // Build the list of receivers, one for each receiving channel, or 1 in | 2753 // Get the SSRC and stats for each receiver. |
| 2830 // a 1:1 call. | |
| 2831 std::vector<int> channels; | |
| 2832 for (const auto& ch : receive_channels_) { | 2754 for (const auto& ch : receive_channels_) { |
| 2833 channels.push_back(ch.second->channel()); | 2755 int ch_id = ch.second->channel(); |
| 2834 } | |
| 2835 if (channels.empty()) { | |
| 2836 channels.push_back(default_send_channel_id()); | |
| 2837 } | |
| 2838 | |
| 2839 // Get the SSRC and stats for each receiver, based on our own calculations. | |
| 2840 for (int ch_id : channels) { | |
| 2841 memset(&cs, 0, sizeof(cs)); | 2756 memset(&cs, 0, sizeof(cs)); |
| 2842 if (engine()->voe()->rtp()->GetRemoteSSRC(ch_id, ssrc) != -1 && | 2757 if (engine()->voe()->rtp()->GetRemoteSSRC(ch_id, ssrc) != -1 && |
| 2843 engine()->voe()->rtp()->GetRTCPStatistics(ch_id, cs) != -1 && | 2758 engine()->voe()->rtp()->GetRTCPStatistics(ch_id, cs) != -1 && |
| 2844 engine()->voe()->codec()->GetRecCodec(ch_id, codec) != -1) { | 2759 engine()->voe()->codec()->GetRecCodec(ch_id, codec) != -1) { |
| 2845 VoiceReceiverInfo rinfo; | 2760 VoiceReceiverInfo rinfo; |
| 2846 rinfo.add_ssrc(ssrc); | 2761 rinfo.add_ssrc(ssrc); |
| 2847 rinfo.bytes_rcvd = cs.bytesReceived; | 2762 rinfo.bytes_rcvd = cs.bytesReceived; |
| 2848 rinfo.packets_rcvd = cs.packetsReceived; | 2763 rinfo.packets_rcvd = cs.packetsReceived; |
| 2849 // The next four fields are from the most recently sent RTCP report. | 2764 // The next four fields are from the most recently sent RTCP report. |
| 2850 // Convert Q8 to floating point. | 2765 // Convert Q8 to floating point. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2927 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); | 2842 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); |
| 2928 return (ret == 0) ? static_cast<int>(ulevel) : -1; | 2843 return (ret == 0) ? static_cast<int>(ulevel) : -1; |
| 2929 } | 2844 } |
| 2930 | 2845 |
| 2931 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32_t ssrc) const { | 2846 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32_t ssrc) const { |
| 2932 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2847 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2933 ChannelMap::const_iterator it = receive_channels_.find(ssrc); | 2848 ChannelMap::const_iterator it = receive_channels_.find(ssrc); |
| 2934 if (it != receive_channels_.end()) { | 2849 if (it != receive_channels_.end()) { |
| 2935 return it->second->channel(); | 2850 return it->second->channel(); |
| 2936 } | 2851 } |
| 2937 return (ssrc == default_receive_ssrc_) ? default_send_channel_id() : -1; | 2852 return -1; |
| 2938 } | 2853 } |
| 2939 | 2854 |
| 2940 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32_t ssrc) const { | 2855 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32_t ssrc) const { |
| 2941 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2856 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 2942 ChannelMap::const_iterator it = send_channels_.find(ssrc); | 2857 ChannelMap::const_iterator it = send_channels_.find(ssrc); |
| 2943 if (it != send_channels_.end()) { | 2858 if (it != send_channels_.end()) { |
| 2944 return it->second->channel(); | 2859 return it->second->channel(); |
| 2945 } | 2860 } |
| 2946 return -1; | 2861 return -1; |
| 2947 } | 2862 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2995 LOG_RTCERR2(SetRTCPStatus, channel, 1); | 2910 LOG_RTCERR2(SetRTCPStatus, channel, 1); |
| 2996 return false; | 2911 return false; |
| 2997 } | 2912 } |
| 2998 // TODO(juberti): Enable VQMon and RTCP XR reports, once we know what | 2913 // TODO(juberti): Enable VQMon and RTCP XR reports, once we know what |
| 2999 // what we want to do with them. | 2914 // what we want to do with them. |
| 3000 // engine()->voe().EnableVQMon(default_send_channel_id(), true); | 2915 // engine()->voe().EnableVQMon(default_send_channel_id(), true); |
| 3001 // engine()->voe().EnableRTCP_XR(default_send_channel_id(), true); | 2916 // engine()->voe().EnableRTCP_XR(default_send_channel_id(), true); |
| 3002 return true; | 2917 return true; |
| 3003 } | 2918 } |
| 3004 | 2919 |
| 3005 bool WebRtcVoiceMediaChannel::ResetRecvCodecs(int channel) { | |
| 3006 int ncodecs = engine()->voe()->codec()->NumOfCodecs(); | |
| 3007 for (int i = 0; i < ncodecs; ++i) { | |
| 3008 webrtc::CodecInst voe_codec; | |
| 3009 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) { | |
| 3010 voe_codec.pltype = -1; | |
| 3011 if (engine()->voe()->codec()->SetRecPayloadType( | |
| 3012 channel, voe_codec) == -1) { | |
| 3013 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); | |
| 3014 return false; | |
| 3015 } | |
| 3016 } | |
| 3017 } | |
| 3018 return true; | |
| 3019 } | |
| 3020 | |
| 3021 bool WebRtcVoiceMediaChannel::SetPlayout(int channel, bool playout) { | 2920 bool WebRtcVoiceMediaChannel::SetPlayout(int channel, bool playout) { |
| 3022 if (playout) { | 2921 if (playout) { |
| 3023 LOG(LS_INFO) << "Starting playout for channel #" << channel; | 2922 LOG(LS_INFO) << "Starting playout for channel #" << channel; |
| 3024 if (engine()->voe()->base()->StartPlayout(channel) == -1) { | 2923 if (engine()->voe()->base()->StartPlayout(channel) == -1) { |
| 3025 LOG_RTCERR1(StartPlayout, channel); | 2924 LOG_RTCERR1(StartPlayout, channel); |
| 3026 return false; | 2925 return false; |
| 3027 } | 2926 } |
| 3028 } else { | 2927 } else { |
| 3029 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2928 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
| 3030 engine()->voe()->base()->StopPlayout(channel); | 2929 engine()->voe()->base()->StopPlayout(channel); |
| 3031 } | 2930 } |
| 3032 return true; | 2931 return true; |
| 3033 } | 2932 } |
| 3034 | 2933 |
| 3035 uint32_t WebRtcVoiceMediaChannel::ParseSsrc(const void* data, | |
| 3036 size_t len, | |
| 3037 bool rtcp) { | |
| 3038 size_t ssrc_pos = (!rtcp) ? 8 : 4; | |
| 3039 uint32_t ssrc = 0; | |
| 3040 if (len >= (ssrc_pos + sizeof(ssrc))) { | |
| 3041 ssrc = rtc::GetBE32(static_cast<const char*>(data) + ssrc_pos); | |
| 3042 } | |
| 3043 return ssrc; | |
| 3044 } | |
| 3045 | |
| 3046 // Convert VoiceEngine error code into VoiceMediaChannel::Error enum. | 2934 // Convert VoiceEngine error code into VoiceMediaChannel::Error enum. |
| 3047 VoiceMediaChannel::Error | 2935 VoiceMediaChannel::Error |
| 3048 WebRtcVoiceMediaChannel::WebRtcErrorToChannelError(int err_code) { | 2936 WebRtcVoiceMediaChannel::WebRtcErrorToChannelError(int err_code) { |
| 3049 switch (err_code) { | 2937 switch (err_code) { |
| 3050 case 0: | 2938 case 0: |
| 3051 return ERROR_NONE; | 2939 return ERROR_NONE; |
| 3052 case VE_CANNOT_START_RECORDING: | 2940 case VE_CANNOT_START_RECORDING: |
| 3053 case VE_MIC_VOL_ERROR: | 2941 case VE_MIC_VOL_ERROR: |
| 3054 case VE_GET_MIC_VOL_ERROR: | 2942 case VE_GET_MIC_VOL_ERROR: |
| 3055 case VE_CANNOT_ACCESS_MIC_VOL: | 2943 case VE_CANNOT_ACCESS_MIC_VOL: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3130 } | 3018 } |
| 3131 | 3019 |
| 3132 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( | 3020 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( |
| 3133 const std::vector<AudioCodec>& new_codecs) { | 3021 const std::vector<AudioCodec>& new_codecs) { |
| 3134 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 3022 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 3135 for (const AudioCodec& codec : new_codecs) { | 3023 for (const AudioCodec& codec : new_codecs) { |
| 3136 webrtc::CodecInst voe_codec; | 3024 webrtc::CodecInst voe_codec; |
| 3137 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { | 3025 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { |
| 3138 LOG(LS_INFO) << ToString(codec); | 3026 LOG(LS_INFO) << ToString(codec); |
| 3139 voe_codec.pltype = codec.id; | 3027 voe_codec.pltype = codec.id; |
| 3140 if (default_receive_ssrc_ == 0) { | |
| 3141 // Set the receive codecs on the default channel explicitly if the | |
| 3142 // default channel is not used by |receive_channels_|, this happens in | |
| 3143 // conference mode or in non-conference mode when there is no playout | |
| 3144 // channel. | |
| 3145 // TODO(xians): Figure out how we use the default channel in conference | |
| 3146 // mode. | |
| 3147 if (engine()->voe()->codec()->SetRecPayloadType( | |
| 3148 default_send_channel_id(), voe_codec) == -1) { | |
| 3149 LOG_RTCERR2(SetRecPayloadType, default_send_channel_id(), | |
| 3150 ToString(voe_codec)); | |
| 3151 return false; | |
| 3152 } | |
| 3153 } | |
| 3154 | |
| 3155 // Set the receive codecs on all receiving channels. | |
| 3156 for (const auto& ch : receive_channels_) { | 3028 for (const auto& ch : receive_channels_) { |
| 3157 if (engine()->voe()->codec()->SetRecPayloadType( | 3029 if (engine()->voe()->codec()->SetRecPayloadType( |
| 3158 ch.second->channel(), voe_codec) == -1) { | 3030 ch.second->channel(), voe_codec) == -1) { |
| 3159 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(), | 3031 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(), |
| 3160 ToString(voe_codec)); | 3032 ToString(voe_codec)); |
| 3161 return false; | 3033 return false; |
| 3162 } | 3034 } |
| 3163 } | 3035 } |
| 3164 } else { | 3036 } else { |
| 3165 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); | 3037 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); |
| 3166 return false; | 3038 return false; |
| 3167 } | 3039 } |
| 3168 } | 3040 } |
| 3169 return true; | 3041 return true; |
| 3170 } | 3042 } |
| 3171 | 3043 |
| 3172 } // namespace cricket | 3044 } // namespace cricket |
| 3173 | 3045 |
| 3174 #endif // HAVE_WEBRTC_VOICE | 3046 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |