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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1401 send_bitrate_bps_(0), | 1400 send_bitrate_bps_(0), |
1402 options_(), | 1401 options_(), |
1403 dtmf_allowed_(false), | 1402 dtmf_allowed_(false), |
1404 desired_playout_(false), | 1403 desired_playout_(false), |
1405 nack_enabled_(false), | 1404 nack_enabled_(false), |
1406 playout_(false), | 1405 playout_(false), |
1407 typing_noise_detected_(false), | 1406 typing_noise_detected_(false), |
1408 desired_send_(SEND_NOTHING), | 1407 desired_send_(SEND_NOTHING), |
1409 send_(SEND_NOTHING), | 1408 send_(SEND_NOTHING), |
1410 call_(call), | 1409 call_(call), |
1411 default_receive_ssrc_(0) { | 1410 default_recv_ssrc_(-1) { |
1412 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1411 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1413 engine->RegisterChannel(this); | 1412 engine->RegisterChannel(this); |
1414 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " | 1413 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " |
1415 << default_send_channel_id(); | 1414 << default_send_channel_id(); |
1416 RTC_DCHECK(nullptr != call); | 1415 RTC_DCHECK(nullptr != call); |
1417 ConfigureSendChannel(default_send_channel_id()); | 1416 ConfigureSendChannel(default_send_channel_id()); |
1418 SetOptions(options); | 1417 SetOptions(options); |
1419 } | 1418 } |
1420 | 1419 |
1421 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { | 1420 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1830 return true; | 1829 return true; |
1831 } | 1830 } |
1832 | 1831 |
1833 bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions( | 1832 bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions( |
1834 const std::vector<RtpHeaderExtension>& extensions) { | 1833 const std::vector<RtpHeaderExtension>& extensions) { |
1835 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1834 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1836 if (receive_extensions_ == extensions) { | 1835 if (receive_extensions_ == extensions) { |
1837 return true; | 1836 return true; |
1838 } | 1837 } |
1839 | 1838 |
1840 // The default channel may or may not be in |receive_channels_|. Set the rtp | |
1841 // header extensions for default channel regardless. | |
1842 if (!SetChannelRecvRtpHeaderExtensions(default_send_channel_id(), | |
1843 extensions)) { | |
1844 return false; | |
1845 } | |
1846 | |
1847 // Loop through all receive channels and enable/disable the extensions. | |
1848 for (const auto& ch : receive_channels_) { | 1839 for (const auto& ch : receive_channels_) { |
1849 if (!SetChannelRecvRtpHeaderExtensions(ch.second->channel(), extensions)) { | 1840 if (!SetChannelRecvRtpHeaderExtensions(ch.second->channel(), extensions)) { |
1850 return false; | 1841 return false; |
1851 } | 1842 } |
1852 } | 1843 } |
1853 | 1844 |
1854 receive_extensions_ = extensions; | 1845 receive_extensions_ = extensions; |
1855 | 1846 |
1856 // Recreate AudioReceiveStream:s. | 1847 // Recreate AudioReceiveStream:s. |
1857 { | 1848 { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1961 } | 1952 } |
1962 | 1953 |
1963 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { | 1954 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { |
1964 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1955 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1965 if (playout_ == playout) { | 1956 if (playout_ == playout) { |
1966 return true; | 1957 return true; |
1967 } | 1958 } |
1968 | 1959 |
1969 // Change the playout of all channels to the new state. | 1960 // Change the playout of all channels to the new state. |
1970 bool result = true; | 1961 bool result = true; |
1962 // TODO(solenberg): Remove!!!!!! | |
pthatcher1
2015/10/08 18:55:40
Do you plan to do that in this CL or a future one?
the sun
2015/10/12 15:03:01
Done.
| |
1971 if (receive_channels_.empty()) { | 1963 if (receive_channels_.empty()) { |
1972 // Only toggle the default channel if we don't have any other channels. | 1964 // Only toggle the default channel if we don't have any other channels. |
1973 result = SetPlayout(default_send_channel_id(), playout); | 1965 result = SetPlayout(default_send_channel_id(), playout); |
1974 } | 1966 } |
1975 for (const auto& ch : receive_channels_) { | 1967 for (const auto& ch : receive_channels_) { |
1976 if (!SetPlayout(ch.second->channel(), playout)) { | 1968 if (!SetPlayout(ch.second->channel(), playout)) { |
1977 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " | 1969 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " |
1978 << ch.second->channel() << " failed"; | 1970 << ch.second->channel() << " failed"; |
1979 result = false; | 1971 result = false; |
1980 break; | 1972 break; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2069 // TODO(ronghuawu): Change this method to return bool. | 2061 // TODO(ronghuawu): Change this method to return bool. |
2070 void WebRtcVoiceMediaChannel::ConfigureSendChannel(int channel) { | 2062 void WebRtcVoiceMediaChannel::ConfigureSendChannel(int channel) { |
2071 if (engine()->voe()->network()->RegisterExternalTransport( | 2063 if (engine()->voe()->network()->RegisterExternalTransport( |
2072 channel, *this) == -1) { | 2064 channel, *this) == -1) { |
2073 LOG_RTCERR2(RegisterExternalTransport, channel, this); | 2065 LOG_RTCERR2(RegisterExternalTransport, channel, this); |
2074 } | 2066 } |
2075 | 2067 |
2076 // Enable RTCP (for quality stats and feedback messages) | 2068 // Enable RTCP (for quality stats and feedback messages) |
2077 EnableRtcp(channel); | 2069 EnableRtcp(channel); |
2078 | 2070 |
2079 // Reset all recv codecs; they will be enabled via SetRecvCodecs. | |
2080 ResetRecvCodecs(channel); | |
2081 | |
2082 // Set RTP header extension for the new channel. | 2071 // Set RTP header extension for the new channel. |
2083 SetChannelSendRtpHeaderExtensions(channel, send_extensions_); | 2072 SetChannelSendRtpHeaderExtensions(channel, send_extensions_); |
2084 } | 2073 } |
2085 | 2074 |
2086 bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) { | 2075 bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) { |
2087 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { | 2076 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { |
2088 LOG_RTCERR1(DeRegisterExternalTransport, channel); | 2077 LOG_RTCERR1(DeRegisterExternalTransport, channel); |
2089 } | 2078 } |
2090 | 2079 |
2091 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { | 2080 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2142 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); | 2131 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); |
2143 return false; | 2132 return false; |
2144 } | 2133 } |
2145 | 2134 |
2146 // At this point the channel's local SSRC has been updated. If the channel is | 2135 // At this point the channel's local SSRC has been updated. If the channel is |
2147 // the default channel make sure that all the receive channels are updated as | 2136 // the default channel make sure that all the receive channels are updated as |
2148 // well. Receive channels have to have the same SSRC as the default channel in | 2137 // well. Receive channels have to have the same SSRC as the default channel in |
2149 // order to send receiver reports with this SSRC. | 2138 // order to send receiver reports with this SSRC. |
2150 if (IsDefaultChannel(channel)) { | 2139 if (IsDefaultChannel(channel)) { |
2151 for (const auto& ch : receive_channels_) { | 2140 for (const auto& ch : receive_channels_) { |
2152 // Only update the SSRC for non-default channels. | 2141 if (engine()->voe()->rtp()->SetLocalSSRC(ch.second->channel(), |
2153 if (!IsDefaultChannel(ch.second->channel())) { | 2142 sp.first_ssrc()) != 0) { |
2154 if (engine()->voe()->rtp()->SetLocalSSRC(ch.second->channel(), | 2143 LOG_RTCERR2(SetLocalSSRC, ch.second->channel(), sp.first_ssrc()); |
2155 sp.first_ssrc()) != 0) { | 2144 return false; |
2156 LOG_RTCERR2(SetLocalSSRC, ch.second->channel(), sp.first_ssrc()); | |
2157 return false; | |
2158 } | |
2159 } | 2145 } |
2160 } | 2146 } |
2161 } | 2147 } |
2162 | 2148 |
2163 if (engine()->voe()->rtp()->SetRTCP_CNAME(channel, sp.cname.c_str()) == -1) { | 2149 if (engine()->voe()->rtp()->SetRTCP_CNAME(channel, sp.cname.c_str()) == -1) { |
2164 LOG_RTCERR2(SetRTCP_CNAME, channel, sp.cname); | 2150 LOG_RTCERR2(SetRTCP_CNAME, channel, sp.cname); |
2165 return false; | 2151 return false; |
2166 } | 2152 } |
2167 | 2153 |
2168 // Set the current codecs to be used for the new channel. | 2154 // Set the current codecs to be used for the new channel. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2213 if (!ValidateStreamParams(sp)) { | 2199 if (!ValidateStreamParams(sp)) { |
2214 return false; | 2200 return false; |
2215 } | 2201 } |
2216 | 2202 |
2217 uint32_t ssrc = sp.first_ssrc(); | 2203 uint32_t ssrc = sp.first_ssrc(); |
2218 if (ssrc == 0) { | 2204 if (ssrc == 0) { |
2219 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; | 2205 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; |
2220 return false; | 2206 return false; |
2221 } | 2207 } |
2222 | 2208 |
2223 rtc::CritScope lock(&receive_channels_cs_); | 2209 // Remove the default receive stream if one had been created with this ssrc; |
2210 // we'll recreate it then. | |
2211 if (default_recv_ssrc_ == static_cast<int64_t>(ssrc)) { | |
pthatcher1
2015/10/08 18:55:40
A simple IsDefaultRecvStream(ssrc) might be nice,
the sun
2015/10/12 15:03:01
Done.
| |
2212 RemoveRecvStream(ssrc); | |
2213 } | |
2224 | 2214 |
2225 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 2215 if (receive_channels_.find(ssrc) != receive_channels_.end()) { |
2226 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 2216 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; |
2227 return false; | 2217 return false; |
2228 } | 2218 } |
2229 | |
2230 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); | 2219 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); |
2231 | 2220 |
2232 // Reuse default channel for recv stream in non-conference mode call | |
2233 // when the default channel is not being used. | |
2234 webrtc::AudioTransport* audio_transport = | |
2235 engine()->voe()->base()->audio_transport(); | |
2236 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | |
2237 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | |
2238 default_receive_ssrc_ = ssrc; | |
2239 WebRtcVoiceChannelRenderer* channel_renderer = | |
2240 new WebRtcVoiceChannelRenderer(default_send_channel_id(), | |
2241 audio_transport); | |
2242 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | |
2243 receive_stream_params_[ssrc] = sp; | |
2244 AddAudioReceiveStream(ssrc); | |
2245 return SetPlayout(default_send_channel_id(), playout_); | |
2246 } | |
2247 | |
2248 // Create a new channel for receiving audio data. | 2221 // Create a new channel for receiving audio data. |
2249 int channel = engine()->CreateMediaVoiceChannel(); | 2222 int channel = engine()->CreateMediaVoiceChannel(); |
2250 if (channel == -1) { | 2223 if (channel == -1) { |
2251 LOG_RTCERR0(CreateChannel); | 2224 LOG_RTCERR0(CreateChannel); |
2252 return false; | 2225 return false; |
2253 } | 2226 } |
2254 if (!ConfigureRecvChannel(channel)) { | 2227 if (!ConfigureRecvChannel(channel)) { |
2255 DeleteChannel(channel); | 2228 DeleteChannel(channel); |
2256 return false; | 2229 return false; |
2257 } | 2230 } |
2258 | 2231 |
2232 webrtc::AudioTransport* audio_transport = | |
2233 engine()->voe()->base()->audio_transport(); | |
2259 WebRtcVoiceChannelRenderer* channel_renderer = | 2234 WebRtcVoiceChannelRenderer* channel_renderer = |
2260 new WebRtcVoiceChannelRenderer(channel, audio_transport); | 2235 new WebRtcVoiceChannelRenderer(channel, audio_transport); |
2261 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | 2236 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); |
2262 receive_stream_params_[ssrc] = sp; | 2237 receive_stream_params_[ssrc] = sp; |
2263 AddAudioReceiveStream(ssrc); | 2238 AddAudioReceiveStream(ssrc); |
2264 | 2239 |
2265 LOG(LS_INFO) << "New audio stream " << ssrc | 2240 LOG(LS_INFO) << "New audio stream " << ssrc |
2266 << " registered to VoiceEngine channel #" | 2241 << " registered to VoiceEngine channel #" |
2267 << channel << "."; | 2242 << channel << "."; |
2268 return true; | 2243 return true; |
(...skipping 22 matching lines...) Expand all Loading... | |
2291 } | 2266 } |
2292 | 2267 |
2293 // Associate receive channel to default send channel (so the receive channel | 2268 // Associate receive channel to default send channel (so the receive channel |
2294 // can obtain RTT from the send channel). | 2269 // can obtain RTT from the send channel). |
2295 engine()->voe()->base()->AssociateSendChannel(channel, | 2270 engine()->voe()->base()->AssociateSendChannel(channel, |
2296 default_send_channel_id()); | 2271 default_send_channel_id()); |
2297 LOG(LS_INFO) << "VoiceEngine channel #" | 2272 LOG(LS_INFO) << "VoiceEngine channel #" |
2298 << channel << " is associated with channel #" | 2273 << channel << " is associated with channel #" |
2299 << default_send_channel_id() << "."; | 2274 << default_send_channel_id() << "."; |
2300 | 2275 |
2301 // Use the same recv payload types as our default channel. | 2276 // Turn off all supported codecs. |
2302 ResetRecvCodecs(channel); | 2277 int ncodecs = engine()->voe()->codec()->NumOfCodecs(); |
2303 if (!recv_codecs_.empty()) { | 2278 for (int i = 0; i < ncodecs; ++i) { |
2304 for (const auto& codec : recv_codecs_) { | 2279 webrtc::CodecInst voe_codec; |
2305 webrtc::CodecInst voe_codec; | 2280 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) { |
2306 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { | 2281 voe_codec.pltype = -1; |
2307 voe_codec.pltype = codec.id; | 2282 if (engine()->voe()->codec()->SetRecPayloadType( |
2308 voe_codec.rate = 0; // Needed to make GetRecPayloadType work for ISAC | 2283 channel, voe_codec) == -1) { |
2309 if (engine()->voe()->codec()->GetRecPayloadType( | 2284 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); |
2310 default_send_channel_id(), voe_codec) != -1) { | 2285 return false; |
2311 if (engine()->voe()->codec()->SetRecPayloadType( | |
2312 channel, voe_codec) == -1) { | |
2313 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); | |
2314 return false; | |
2315 } | |
2316 } | |
2317 } | 2286 } |
2318 } | 2287 } |
2319 } | 2288 } |
2320 | 2289 |
2321 if (InConferenceMode()) { | 2290 // Only enable those configured for this channel. |
2322 // To be in par with the video, default_send_channel_id() is not used for | 2291 for (const auto& codec : recv_codecs_) { |
2323 // receiving in a conference call. | 2292 webrtc::CodecInst voe_codec; |
2324 if (receive_channels_.empty() && default_receive_ssrc_ == 0 && playout_) { | 2293 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { |
2325 // This is the first stream in a multi user meeting. We can now | 2294 voe_codec.pltype = codec.id; |
2326 // disable playback of the default stream. This since the default | 2295 if (engine()->voe()->codec()->SetRecPayloadType( |
2327 // stream will probably have received some initial packets before | 2296 channel, voe_codec) == -1) { |
2328 // the new stream was added. This will mean that the CN state from | 2297 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); |
2329 // the default channel will be mixed in with the other streams | 2298 return false; |
2330 // throughout the whole meeting, which might be disturbing. | 2299 } |
2331 LOG(LS_INFO) << "Disabling playback on the default voice channel"; | |
2332 SetPlayout(default_send_channel_id(), false); | |
2333 } | 2300 } |
2334 } | 2301 } |
2335 | 2302 |
2336 SetNack(channel, nack_enabled_); | 2303 SetNack(channel, nack_enabled_); |
2337 | 2304 |
2338 // Set RTP header extension for the new channel. | 2305 // Set RTP header extension for the new channel. |
2339 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { | 2306 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { |
2340 return false; | 2307 return false; |
2341 } | 2308 } |
2342 | 2309 |
2343 return SetPlayout(channel, playout_); | 2310 return SetPlayout(channel, playout_); |
2344 } | 2311 } |
2345 | 2312 |
2346 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { | 2313 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { |
2347 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2314 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2348 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; | 2315 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; |
2349 | 2316 |
2350 rtc::CritScope lock(&receive_channels_cs_); | |
2351 ChannelMap::iterator it = receive_channels_.find(ssrc); | 2317 ChannelMap::iterator it = receive_channels_.find(ssrc); |
2352 if (it == receive_channels_.end()) { | 2318 if (it == receive_channels_.end()) { |
2353 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 2319 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc |
2354 << " which doesn't exist."; | 2320 << " which doesn't exist."; |
2355 return false; | 2321 return false; |
2356 } | 2322 } |
2357 | 2323 |
2358 RemoveAudioReceiveStream(ssrc); | 2324 RemoveAudioReceiveStream(ssrc); |
2359 receive_stream_params_.erase(ssrc); | 2325 receive_stream_params_.erase(ssrc); |
2360 | 2326 |
2361 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this | 2327 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this |
2362 // will disconnect the audio renderer with the receive channel. | 2328 // will disconnect the audio renderer with the receive channel. |
2363 // Cache the channel before the deletion. | 2329 // Cache the channel before the deletion. |
2364 const int channel = it->second->channel(); | 2330 const int channel = it->second->channel(); |
2365 delete it->second; | 2331 delete it->second; |
2366 receive_channels_.erase(it); | 2332 receive_channels_.erase(it); |
2367 | 2333 |
2368 if (ssrc == default_receive_ssrc_) { | 2334 // Deregister default channel, if that's the one being destroyed. |
2369 RTC_DCHECK(IsDefaultChannel(channel)); | 2335 if (default_recv_ssrc_ == static_cast<int64_t>(ssrc)) { |
2370 // Recycle the default channel is for recv stream. | 2336 default_recv_ssrc_ = -1; |
2371 if (playout_) | |
2372 SetPlayout(default_send_channel_id(), false); | |
2373 | |
2374 default_receive_ssrc_ = 0; | |
2375 return true; | |
2376 } | 2337 } |
2377 | 2338 |
2378 LOG(LS_INFO) << "Removing audio stream " << ssrc | 2339 LOG(LS_INFO) << "Removing audio stream " << ssrc |
2379 << " with VoiceEngine channel #" << channel << "."; | 2340 << " with VoiceEngine channel #" << channel << "."; |
2380 if (!DeleteChannel(channel)) | 2341 return DeleteChannel(channel); |
2381 return false; | |
2382 | |
2383 bool enable_default_channel_playout = false; | |
2384 if (receive_channels_.empty()) { | |
2385 // The last stream was removed. We can now enable the default | |
2386 // channel for new channels to be played out immediately without | |
2387 // waiting for AddStream messages. | |
2388 // We do this for both conference mode and non-conference mode. | |
2389 // TODO(oja): Does the default channel still have it's CN state? | |
2390 enable_default_channel_playout = true; | |
2391 } | |
2392 if (!InConferenceMode() && receive_channels_.size() == 1 && | |
2393 default_receive_ssrc_ != 0) { | |
2394 // Only the default channel is active, enable the playout on default | |
2395 // channel. | |
2396 enable_default_channel_playout = true; | |
2397 } | |
2398 if (enable_default_channel_playout && playout_) { | |
2399 LOG(LS_INFO) << "Enabling playback on the default voice channel"; | |
2400 SetPlayout(default_send_channel_id(), true); | |
2401 } | |
2402 | |
2403 return true; | |
2404 } | 2342 } |
2405 | 2343 |
2406 bool WebRtcVoiceMediaChannel::SetRemoteRenderer(uint32_t ssrc, | 2344 bool WebRtcVoiceMediaChannel::SetRemoteRenderer(uint32_t ssrc, |
2407 AudioRenderer* renderer) { | 2345 AudioRenderer* renderer) { |
2408 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2346 RTC_DCHECK(renderer == nullptr); |
2409 ChannelMap::iterator it = receive_channels_.find(ssrc); | |
2410 if (it == receive_channels_.end()) { | |
2411 if (renderer) { | |
2412 // Return an error if trying to set a valid renderer with an invalid ssrc. | |
2413 LOG(LS_ERROR) << "SetRemoteRenderer failed with ssrc "<< ssrc; | |
2414 return false; | |
2415 } | |
2416 | |
2417 // The channel likely has gone away, do nothing. | |
2418 return true; | |
2419 } | |
2420 | |
2421 if (renderer) | |
2422 it->second->Start(renderer); | |
2423 else | |
2424 it->second->Stop(); | |
2425 | |
2426 return true; | 2347 return true; |
2427 } | 2348 } |
2428 | 2349 |
2429 bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc, | 2350 bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc, |
2430 AudioRenderer* renderer) { | 2351 AudioRenderer* renderer) { |
2431 ChannelMap::iterator it = send_channels_.find(ssrc); | 2352 ChannelMap::iterator it = send_channels_.find(ssrc); |
2432 if (it == send_channels_.end()) { | 2353 if (it == send_channels_.end()) { |
2433 if (renderer) { | 2354 if (renderer) { |
2434 // Return an error if trying to set a valid renderer with an invalid ssrc. | 2355 // Return an error if trying to set a valid renderer with an invalid ssrc. |
2435 LOG(LS_ERROR) << "SetLocalRenderer failed with ssrc "<< ssrc; | 2356 LOG(LS_ERROR) << "SetLocalRenderer failed with ssrc "<< ssrc; |
2436 return false; | 2357 return false; |
2437 } | 2358 } |
2438 | 2359 |
2439 // The channel likely has gone away, do nothing. | 2360 // The channel likely has gone away, do nothing. |
2440 return true; | 2361 return true; |
2441 } | 2362 } |
2442 | 2363 |
2443 if (renderer) | 2364 if (renderer) { |
2444 it->second->Start(renderer); | 2365 it->second->Start(renderer); |
2445 else | 2366 } else { |
2446 it->second->Stop(); | 2367 it->second->Stop(); |
2368 } | |
2447 | 2369 |
2448 return true; | 2370 return true; |
2449 } | 2371 } |
2450 | 2372 |
2451 bool WebRtcVoiceMediaChannel::GetActiveStreams( | 2373 bool WebRtcVoiceMediaChannel::GetActiveStreams( |
2452 AudioInfo::StreamList* actives) { | 2374 AudioInfo::StreamList* actives) { |
2453 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2375 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2454 // In conference mode, the default channel should not be in | |
2455 // |receive_channels_|. | |
2456 actives->clear(); | 2376 actives->clear(); |
2457 for (const auto& ch : receive_channels_) { | 2377 for (const auto& ch : receive_channels_) { |
2458 int level = GetOutputLevel(ch.second->channel()); | 2378 int level = GetOutputLevel(ch.second->channel()); |
2459 if (level > 0) { | 2379 if (level > 0) { |
2460 actives->push_back(std::make_pair(ch.first, level)); | 2380 actives->push_back(std::make_pair(ch.first, level)); |
2461 } | 2381 } |
2462 } | 2382 } |
2463 return true; | 2383 return true; |
2464 } | 2384 } |
2465 | 2385 |
2466 int WebRtcVoiceMediaChannel::GetOutputLevel() { | 2386 int WebRtcVoiceMediaChannel::GetOutputLevel() { |
2467 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2387 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2468 // return the highest output level of all streams | 2388 int highest = 0; |
2469 int highest = GetOutputLevel(default_send_channel_id()); | |
2470 for (const auto& ch : receive_channels_) { | 2389 for (const auto& ch : receive_channels_) { |
2471 highest = std::max(GetOutputLevel(ch.second->channel()), highest); | 2390 highest = std::max(GetOutputLevel(ch.second->channel()), highest); |
2472 } | 2391 } |
2473 return highest; | 2392 return highest; |
2474 } | 2393 } |
2475 | 2394 |
2476 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() { | 2395 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() { |
2477 int ret; | 2396 int ret; |
2478 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) { | 2397 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) { |
2479 // In case of error, log the info and continue | 2398 // In case of error, log the info and continue |
(...skipping 15 matching lines...) Expand all Loading... | |
2495 LOG_RTCERR5(SetTypingDetectionParameters, time_window, | 2414 LOG_RTCERR5(SetTypingDetectionParameters, time_window, |
2496 cost_per_typing, reporting_threshold, penalty_decay, | 2415 cost_per_typing, reporting_threshold, penalty_decay, |
2497 type_event_delay); | 2416 type_event_delay); |
2498 } | 2417 } |
2499 } | 2418 } |
2500 | 2419 |
2501 bool WebRtcVoiceMediaChannel::SetOutputScaling(uint32_t ssrc, | 2420 bool WebRtcVoiceMediaChannel::SetOutputScaling(uint32_t ssrc, |
2502 double left, | 2421 double left, |
2503 double right) { | 2422 double right) { |
2504 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2423 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2505 rtc::CritScope lock(&receive_channels_cs_); | 2424 int ch_id = GetReceiveChannelId(ssrc); |
2506 // Collect the channels to scale the output volume. | 2425 if (ch_id < 0) { |
2507 std::vector<int> channels; | 2426 LOG(LS_WARNING) << "Cannot find channel for ssrc:" << ssrc; |
2508 if (0 == ssrc) { // Collect all channels, including the default one. | 2427 // TODO(solenberg): !!!!!! |
pthatcher1
2015/10/08 18:55:40
I assume this means you'll do the logic for "if ss
the sun
2015/10/12 15:03:01
Done.
| |
2509 // Default channel is not in receive_channels_ if it is not being used for | 2428 return true; |
2510 // playout. | |
2511 if (default_receive_ssrc_ == 0) | |
2512 channels.push_back(default_send_channel_id()); | |
2513 for (const auto& ch : receive_channels_) { | |
2514 channels.push_back(ch.second->channel()); | |
2515 } | |
2516 } else { // Collect only the channel of the specified ssrc. | |
2517 int channel = GetReceiveChannelId(ssrc); | |
2518 if (-1 == channel) { | |
2519 LOG(LS_WARNING) << "Cannot find channel for ssrc:" << ssrc; | |
2520 return false; | |
2521 } | |
2522 channels.push_back(channel); | |
2523 } | 2429 } |
2524 | 2430 |
2525 // Scale the output volume for the collected channels. We first normalize to | 2431 // Scale the output volume for the collected channels. We first normalize to |
2526 // scale the volume and then set the left and right pan. | 2432 // scale the volume and then set the left and right pan. |
2527 float scale = static_cast<float>(std::max(left, right)); | 2433 float scale = static_cast<float>(std::max(left, right)); |
2528 if (scale > 0.0001f) { | 2434 if (scale > 0.0001f) { |
2529 left /= scale; | 2435 left /= scale; |
2530 right /= scale; | 2436 right /= scale; |
2531 } | 2437 } |
2532 for (int ch_id : channels) { | 2438 if (-1 == engine()->voe()->volume()->SetChannelOutputVolumeScaling( |
2533 if (-1 == engine()->voe()->volume()->SetChannelOutputVolumeScaling( | 2439 ch_id, scale)) { |
2534 ch_id, scale)) { | 2440 LOG_RTCERR2(SetChannelOutputVolumeScaling, ch_id, scale); |
2535 LOG_RTCERR2(SetChannelOutputVolumeScaling, ch_id, scale); | 2441 return false; |
2536 return false; | |
2537 } | |
2538 if (-1 == engine()->voe()->volume()->SetOutputVolumePan( | |
2539 ch_id, static_cast<float>(left), static_cast<float>(right))) { | |
2540 LOG_RTCERR3(SetOutputVolumePan, ch_id, left, right); | |
2541 // Do not return if fails. SetOutputVolumePan is not available for all | |
2542 // pltforms. | |
2543 } | |
2544 LOG(LS_INFO) << "SetOutputScaling to left=" << left * scale | |
2545 << " right=" << right * scale | |
2546 << " for channel " << ch_id << " and ssrc " << ssrc; | |
2547 } | 2442 } |
2443 if (-1 == engine()->voe()->volume()->SetOutputVolumePan( | |
2444 ch_id, static_cast<float>(left), static_cast<float>(right))) { | |
2445 LOG_RTCERR3(SetOutputVolumePan, ch_id, left, right); | |
2446 // Do not return if fails. SetOutputVolumePan is not available for all | |
2447 // pltforms. | |
2448 } | |
2449 LOG(LS_INFO) << "SetOutputScaling to left=" << left * scale | |
2450 << " right=" << right * scale | |
2451 << " for channel " << ch_id << " and ssrc " << ssrc; | |
2548 return true; | 2452 return true; |
2549 } | 2453 } |
2550 | 2454 |
2551 bool WebRtcVoiceMediaChannel::CanInsertDtmf() { | 2455 bool WebRtcVoiceMediaChannel::CanInsertDtmf() { |
2552 return dtmf_allowed_; | 2456 return dtmf_allowed_; |
2553 } | 2457 } |
2554 | 2458 |
2555 bool WebRtcVoiceMediaChannel::InsertDtmf(uint32_t ssrc, | 2459 bool WebRtcVoiceMediaChannel::InsertDtmf(uint32_t ssrc, |
2556 int event, | 2460 int event, |
2557 int duration, | 2461 int duration, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2601 } | 2505 } |
2602 } | 2506 } |
2603 | 2507 |
2604 return true; | 2508 return true; |
2605 } | 2509 } |
2606 | 2510 |
2607 void WebRtcVoiceMediaChannel::OnPacketReceived( | 2511 void WebRtcVoiceMediaChannel::OnPacketReceived( |
2608 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 2512 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
2609 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2513 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2610 | 2514 |
2611 // Forward packet to Call as well. | 2515 uint32_t ssrc = 0; |
2516 if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) { | |
2517 return; | |
2518 } | |
2519 | |
2520 if (receive_channels_.empty()) { | |
2521 // Create new channel, which will be the default receive channel. | |
2522 StreamParams sp; | |
2523 sp.ssrcs.push_back(ssrc); | |
2524 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; | |
2525 if (!AddRecvStream(sp)) { | |
2526 LOG(LS_WARNING) << "Could not create default receive stream."; | |
2527 return; | |
2528 } | |
2529 default_recv_ssrc_ = ssrc; | |
2530 } | |
2531 | |
2532 // Forward packet to Call. If the SSRC is unknown we'll return after this. | |
2612 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2533 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2613 packet_time.not_before); | 2534 packet_time.not_before); |
2614 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2535 webrtc::PacketReceiver::DeliveryStatus delivery_result = |
2615 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2536 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2616 webrtc_packet_time); | 2537 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
2538 webrtc_packet_time); | |
2539 if (webrtc::PacketReceiver::DELIVERY_OK != delivery_result) { | |
2540 return; | |
2541 } | |
2617 | 2542 |
2618 // Pick which channel to send this packet to. If this packet doesn't match | 2543 // Find the channel to send this packet to. It must exist since webrtc::Call |
2619 // any multiplexed streams, just send it to the default channel. Otherwise, | 2544 // was able to demux the packet. |
2620 // send it to the specific decoder instance for that stream. | 2545 int channel = GetReceiveChannelId(ssrc); |
2621 int which_channel = | 2546 RTC_DCHECK(channel != -1); |
2622 GetReceiveChannelId(ParseSsrc(packet->data(), packet->size(), false)); | |
2623 if (which_channel == -1) { | |
2624 which_channel = default_send_channel_id(); | |
2625 } | |
2626 | 2547 |
2627 // Pass it off to the decoder. | 2548 // Pass it off to the decoder. |
2628 engine()->voe()->network()->ReceivedRTPPacket( | 2549 engine()->voe()->network()->ReceivedRTPPacket( |
2629 which_channel, packet->data(), packet->size(), | 2550 channel, packet->data(), packet->size(), webrtc_packet_time); |
2630 webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); | |
2631 } | 2551 } |
2632 | 2552 |
2633 void WebRtcVoiceMediaChannel::OnRtcpReceived( | 2553 void WebRtcVoiceMediaChannel::OnRtcpReceived( |
2634 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 2554 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
2635 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2555 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2636 | 2556 |
2637 // Forward packet to Call as well. | 2557 // Forward packet to Call as well. |
2638 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2558 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2639 packet_time.not_before); | 2559 packet_time.not_before); |
2640 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2560 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2641 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2561 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
2642 webrtc_packet_time); | 2562 webrtc_packet_time); |
2643 | 2563 |
2644 // Sending channels need all RTCP packets with feedback information. | 2564 // Sending channels need all RTCP packets with feedback information. |
2645 // Even sender reports can contain attached report blocks. | 2565 // Even sender reports can contain attached report blocks. |
2646 // Receiving channels need sender reports in order to create | 2566 // Receiving channels need sender reports in order to create |
2647 // correct receiver reports. | 2567 // correct receiver reports. |
2648 int type = 0; | 2568 int type = 0; |
2649 if (!GetRtcpType(packet->data(), packet->size(), &type)) { | 2569 if (!GetRtcpType(packet->data(), packet->size(), &type)) { |
2650 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; | 2570 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; |
2651 return; | 2571 return; |
2652 } | 2572 } |
2653 | 2573 |
2654 // If it is a sender report, find the receive channel that is listening. | 2574 // If it is a sender report, find the receive channel that is listening. |
2655 bool has_sent_to_default_channel = false; | |
2656 if (type == kRtcpTypeSR) { | 2575 if (type == kRtcpTypeSR) { |
2657 uint32_t ssrc = 0; | 2576 uint32_t ssrc = 0; |
2658 if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) { | 2577 if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) { |
2659 return; | 2578 return; |
2660 } | 2579 } |
2661 int recv_channel_id = GetReceiveChannelId(ssrc); | 2580 int recv_channel_id = GetReceiveChannelId(ssrc); |
2662 if (recv_channel_id != -1) { | 2581 if (recv_channel_id != -1) { |
2663 engine()->voe()->network()->ReceivedRTCPPacket( | 2582 engine()->voe()->network()->ReceivedRTCPPacket( |
2664 recv_channel_id, packet->data(), packet->size()); | 2583 recv_channel_id, packet->data(), packet->size()); |
2665 | |
2666 if (IsDefaultChannel(recv_channel_id)) | |
2667 has_sent_to_default_channel = true; | |
2668 } | 2584 } |
2669 } | 2585 } |
2670 | 2586 |
2671 // SR may continue RR and any RR entry may correspond to any one of the send | 2587 // SR may continue RR and any RR entry may correspond to any one of the send |
2672 // channels. So all RTCP packets must be forwarded all send channels. VoE | 2588 // channels. So all RTCP packets must be forwarded all send channels. VoE |
2673 // will filter out RR internally. | 2589 // will filter out RR internally. |
2674 for (const auto& ch : send_channels_) { | 2590 for (const auto& ch : send_channels_) { |
2675 // Make sure not sending the same packet to default channel more than once. | |
2676 if (IsDefaultChannel(ch.second->channel()) && | |
2677 has_sent_to_default_channel) | |
2678 continue; | |
2679 | |
2680 engine()->voe()->network()->ReceivedRTCPPacket( | 2591 engine()->voe()->network()->ReceivedRTCPPacket( |
2681 ch.second->channel(), packet->data(), packet->size()); | 2592 ch.second->channel(), packet->data(), packet->size()); |
2682 } | 2593 } |
2683 } | 2594 } |
2684 | 2595 |
2685 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { | 2596 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { |
2686 int channel = | 2597 int channel = |
2687 (ssrc == 0) ? default_send_channel_id() : GetSendChannelId(ssrc); | 2598 (ssrc == 0) ? default_send_channel_id() : GetSendChannelId(ssrc); |
2688 if (channel == -1) { | 2599 if (channel == -1) { |
2689 LOG(LS_WARNING) << "The specified ssrc " << ssrc << " is not in use."; | 2600 LOG(LS_WARNING) << "The specified ssrc " << ssrc << " is not in use."; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2864 sinfo.echo_return_loss_enhancement = echo_return_loss_enhancement; | 2775 sinfo.echo_return_loss_enhancement = echo_return_loss_enhancement; |
2865 sinfo.echo_delay_median_ms = echo_delay_median_ms; | 2776 sinfo.echo_delay_median_ms = echo_delay_median_ms; |
2866 sinfo.echo_delay_std_ms = echo_delay_std_ms; | 2777 sinfo.echo_delay_std_ms = echo_delay_std_ms; |
2867 // TODO(ajm): Re-enable this metric once we have a reliable implementation. | 2778 // TODO(ajm): Re-enable this metric once we have a reliable implementation. |
2868 sinfo.aec_quality_min = -1; | 2779 sinfo.aec_quality_min = -1; |
2869 sinfo.typing_noise_detected = typing_noise_detected_; | 2780 sinfo.typing_noise_detected = typing_noise_detected_; |
2870 | 2781 |
2871 info->senders.push_back(sinfo); | 2782 info->senders.push_back(sinfo); |
2872 } | 2783 } |
2873 | 2784 |
2874 // Build the list of receivers, one for each receiving channel, or 1 in | 2785 // Get the SSRC and stats for each receiver. |
2875 // a 1:1 call. | |
2876 std::vector<int> channels; | |
2877 for (const auto& ch : receive_channels_) { | 2786 for (const auto& ch : receive_channels_) { |
2878 channels.push_back(ch.second->channel()); | 2787 int ch_id = ch.second->channel(); |
2879 } | |
2880 if (channels.empty()) { | |
2881 channels.push_back(default_send_channel_id()); | |
2882 } | |
2883 | |
2884 // Get the SSRC and stats for each receiver, based on our own calculations. | |
2885 for (int ch_id : channels) { | |
2886 memset(&cs, 0, sizeof(cs)); | 2788 memset(&cs, 0, sizeof(cs)); |
2887 if (engine()->voe()->rtp()->GetRemoteSSRC(ch_id, ssrc) != -1 && | 2789 if (engine()->voe()->rtp()->GetRemoteSSRC(ch_id, ssrc) != -1 && |
2888 engine()->voe()->rtp()->GetRTCPStatistics(ch_id, cs) != -1 && | 2790 engine()->voe()->rtp()->GetRTCPStatistics(ch_id, cs) != -1 && |
2889 engine()->voe()->codec()->GetRecCodec(ch_id, codec) != -1) { | 2791 engine()->voe()->codec()->GetRecCodec(ch_id, codec) != -1) { |
2890 VoiceReceiverInfo rinfo; | 2792 VoiceReceiverInfo rinfo; |
2891 rinfo.add_ssrc(ssrc); | 2793 rinfo.add_ssrc(ssrc); |
2892 rinfo.bytes_rcvd = cs.bytesReceived; | 2794 rinfo.bytes_rcvd = cs.bytesReceived; |
2893 rinfo.packets_rcvd = cs.packetsReceived; | 2795 rinfo.packets_rcvd = cs.packetsReceived; |
2894 // The next four fields are from the most recently sent RTCP report. | 2796 // The next four fields are from the most recently sent RTCP report. |
2895 // Convert Q8 to floating point. | 2797 // Convert Q8 to floating point. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2972 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); | 2874 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); |
2973 return (ret == 0) ? static_cast<int>(ulevel) : -1; | 2875 return (ret == 0) ? static_cast<int>(ulevel) : -1; |
2974 } | 2876 } |
2975 | 2877 |
2976 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32_t ssrc) const { | 2878 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32_t ssrc) const { |
2977 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2879 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2978 ChannelMap::const_iterator it = receive_channels_.find(ssrc); | 2880 ChannelMap::const_iterator it = receive_channels_.find(ssrc); |
2979 if (it != receive_channels_.end()) { | 2881 if (it != receive_channels_.end()) { |
2980 return it->second->channel(); | 2882 return it->second->channel(); |
2981 } | 2883 } |
2982 return (ssrc == default_receive_ssrc_) ? default_send_channel_id() : -1; | 2884 return -1; |
2983 } | 2885 } |
2984 | 2886 |
2985 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32_t ssrc) const { | 2887 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32_t ssrc) const { |
2986 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2888 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2987 ChannelMap::const_iterator it = send_channels_.find(ssrc); | 2889 ChannelMap::const_iterator it = send_channels_.find(ssrc); |
2988 if (it != send_channels_.end()) { | 2890 if (it != send_channels_.end()) { |
2989 return it->second->channel(); | 2891 return it->second->channel(); |
2990 } | 2892 } |
2991 return -1; | 2893 return -1; |
2992 } | 2894 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3040 LOG_RTCERR2(SetRTCPStatus, channel, 1); | 2942 LOG_RTCERR2(SetRTCPStatus, channel, 1); |
3041 return false; | 2943 return false; |
3042 } | 2944 } |
3043 // TODO(juberti): Enable VQMon and RTCP XR reports, once we know what | 2945 // TODO(juberti): Enable VQMon and RTCP XR reports, once we know what |
3044 // what we want to do with them. | 2946 // what we want to do with them. |
3045 // engine()->voe().EnableVQMon(default_send_channel_id(), true); | 2947 // engine()->voe().EnableVQMon(default_send_channel_id(), true); |
3046 // engine()->voe().EnableRTCP_XR(default_send_channel_id(), true); | 2948 // engine()->voe().EnableRTCP_XR(default_send_channel_id(), true); |
3047 return true; | 2949 return true; |
3048 } | 2950 } |
3049 | 2951 |
3050 bool WebRtcVoiceMediaChannel::ResetRecvCodecs(int channel) { | |
3051 int ncodecs = engine()->voe()->codec()->NumOfCodecs(); | |
3052 for (int i = 0; i < ncodecs; ++i) { | |
3053 webrtc::CodecInst voe_codec; | |
3054 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) { | |
3055 voe_codec.pltype = -1; | |
3056 if (engine()->voe()->codec()->SetRecPayloadType( | |
3057 channel, voe_codec) == -1) { | |
3058 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); | |
3059 return false; | |
3060 } | |
3061 } | |
3062 } | |
3063 return true; | |
3064 } | |
3065 | |
3066 bool WebRtcVoiceMediaChannel::SetPlayout(int channel, bool playout) { | 2952 bool WebRtcVoiceMediaChannel::SetPlayout(int channel, bool playout) { |
3067 if (playout) { | 2953 if (playout) { |
3068 LOG(LS_INFO) << "Starting playout for channel #" << channel; | 2954 LOG(LS_INFO) << "Starting playout for channel #" << channel; |
3069 if (engine()->voe()->base()->StartPlayout(channel) == -1) { | 2955 if (engine()->voe()->base()->StartPlayout(channel) == -1) { |
3070 LOG_RTCERR1(StartPlayout, channel); | 2956 LOG_RTCERR1(StartPlayout, channel); |
3071 return false; | 2957 return false; |
3072 } | 2958 } |
3073 } else { | 2959 } else { |
3074 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2960 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
3075 engine()->voe()->base()->StopPlayout(channel); | 2961 engine()->voe()->base()->StopPlayout(channel); |
3076 } | 2962 } |
3077 return true; | 2963 return true; |
3078 } | 2964 } |
3079 | 2965 |
3080 uint32_t WebRtcVoiceMediaChannel::ParseSsrc(const void* data, | |
3081 size_t len, | |
3082 bool rtcp) { | |
3083 size_t ssrc_pos = (!rtcp) ? 8 : 4; | |
3084 uint32_t ssrc = 0; | |
3085 if (len >= (ssrc_pos + sizeof(ssrc))) { | |
3086 ssrc = rtc::GetBE32(static_cast<const char*>(data) + ssrc_pos); | |
3087 } | |
3088 return ssrc; | |
3089 } | |
3090 | |
3091 // Convert VoiceEngine error code into VoiceMediaChannel::Error enum. | 2966 // Convert VoiceEngine error code into VoiceMediaChannel::Error enum. |
3092 VoiceMediaChannel::Error | 2967 VoiceMediaChannel::Error |
3093 WebRtcVoiceMediaChannel::WebRtcErrorToChannelError(int err_code) { | 2968 WebRtcVoiceMediaChannel::WebRtcErrorToChannelError(int err_code) { |
3094 switch (err_code) { | 2969 switch (err_code) { |
3095 case 0: | 2970 case 0: |
3096 return ERROR_NONE; | 2971 return ERROR_NONE; |
3097 case VE_CANNOT_START_RECORDING: | 2972 case VE_CANNOT_START_RECORDING: |
3098 case VE_MIC_VOL_ERROR: | 2973 case VE_MIC_VOL_ERROR: |
3099 case VE_GET_MIC_VOL_ERROR: | 2974 case VE_GET_MIC_VOL_ERROR: |
3100 case VE_CANNOT_ACCESS_MIC_VOL: | 2975 case VE_CANNOT_ACCESS_MIC_VOL: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3175 } | 3050 } |
3176 | 3051 |
3177 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( | 3052 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( |
3178 const std::vector<AudioCodec>& new_codecs) { | 3053 const std::vector<AudioCodec>& new_codecs) { |
3179 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 3054 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3180 for (const AudioCodec& codec : new_codecs) { | 3055 for (const AudioCodec& codec : new_codecs) { |
3181 webrtc::CodecInst voe_codec; | 3056 webrtc::CodecInst voe_codec; |
3182 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { | 3057 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { |
3183 LOG(LS_INFO) << ToString(codec); | 3058 LOG(LS_INFO) << ToString(codec); |
3184 voe_codec.pltype = codec.id; | 3059 voe_codec.pltype = codec.id; |
3185 if (default_receive_ssrc_ == 0) { | |
3186 // Set the receive codecs on the default channel explicitly if the | |
3187 // default channel is not used by |receive_channels_|, this happens in | |
3188 // conference mode or in non-conference mode when there is no playout | |
3189 // channel. | |
3190 // TODO(xians): Figure out how we use the default channel in conference | |
3191 // mode. | |
3192 if (engine()->voe()->codec()->SetRecPayloadType( | |
3193 default_send_channel_id(), voe_codec) == -1) { | |
3194 LOG_RTCERR2(SetRecPayloadType, default_send_channel_id(), | |
3195 ToString(voe_codec)); | |
3196 return false; | |
3197 } | |
3198 } | |
3199 | |
3200 // Set the receive codecs on all receiving channels. | |
3201 for (const auto& ch : receive_channels_) { | 3060 for (const auto& ch : receive_channels_) { |
3202 if (engine()->voe()->codec()->SetRecPayloadType( | 3061 if (engine()->voe()->codec()->SetRecPayloadType( |
3203 ch.second->channel(), voe_codec) == -1) { | 3062 ch.second->channel(), voe_codec) == -1) { |
3204 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(), | 3063 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(), |
3205 ToString(voe_codec)); | 3064 ToString(voe_codec)); |
3206 return false; | 3065 return false; |
3207 } | 3066 } |
3208 } | 3067 } |
3209 } else { | 3068 } else { |
3210 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); | 3069 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); |
3211 return false; | 3070 return false; |
3212 } | 3071 } |
3213 } | 3072 } |
3214 return true; | 3073 return true; |
3215 } | 3074 } |
3216 | 3075 |
3217 } // namespace cricket | 3076 } // namespace cricket |
3218 | 3077 |
3219 #endif // HAVE_WEBRTC_VOICE | 3078 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |