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