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 using_default_recv_channel_(false), |
| 1411 default_recv_ssrc_(0) { |
1412 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1412 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1413 engine->RegisterChannel(this); | 1413 engine->RegisterChannel(this); |
1414 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " | 1414 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " |
1415 << default_send_channel_id(); | 1415 << default_send_channel_id(); |
1416 RTC_DCHECK(nullptr != call); | 1416 RTC_DCHECK(nullptr != call); |
1417 ConfigureSendChannel(default_send_channel_id()); | 1417 ConfigureSendChannel(default_send_channel_id()); |
1418 SetOptions(options); | 1418 SetOptions(options); |
1419 } | 1419 } |
1420 | 1420 |
1421 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { | 1421 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 options_.SetAll(options); | 1478 options_.SetAll(options); |
1479 | 1479 |
1480 if (send_ != SEND_NOTHING) { | 1480 if (send_ != SEND_NOTHING) { |
1481 if (!engine()->ApplyOptions(options_)) { | 1481 if (!engine()->ApplyOptions(options_)) { |
1482 LOG(LS_WARNING) << | 1482 LOG(LS_WARNING) << |
1483 "Failed to apply engine options during channel SetOptions."; | 1483 "Failed to apply engine options during channel SetOptions."; |
1484 return false; | 1484 return false; |
1485 } | 1485 } |
1486 } | 1486 } |
1487 | 1487 |
1488 if (!SetRecvOptions(default_send_channel_id(), options)) { | |
1489 return false; | |
1490 } | |
1491 for (const auto& ch : receive_channels_) { | 1488 for (const auto& ch : receive_channels_) { |
1492 if (!SetRecvOptions(ch.second->channel(), options)) { | 1489 if (!SetRecvOptions(ch.second->channel(), options)) { |
1493 return false; | 1490 return false; |
1494 } | 1491 } |
1495 } | 1492 } |
1496 if (dscp_option_changed) { | 1493 if (dscp_option_changed) { |
1497 rtc::DiffServCodePoint dscp = rtc::DSCP_DEFAULT; | 1494 rtc::DiffServCodePoint dscp = rtc::DSCP_DEFAULT; |
1498 if (options_.dscp.GetWithDefaultIfUnset(false)) | 1495 if (options_.dscp.GetWithDefaultIfUnset(false)) |
1499 dscp = kAudioDscpValue; | 1496 dscp = kAudioDscpValue; |
1500 if (MediaChannel::SetDscp(dscp) != 0) { | 1497 if (MediaChannel::SetDscp(dscp) != 0) { |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 return true; | 1892 return true; |
1896 } | 1893 } |
1897 | 1894 |
1898 bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions( | 1895 bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions( |
1899 const std::vector<RtpHeaderExtension>& extensions) { | 1896 const std::vector<RtpHeaderExtension>& extensions) { |
1900 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1897 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1901 if (receive_extensions_ == extensions) { | 1898 if (receive_extensions_ == extensions) { |
1902 return true; | 1899 return true; |
1903 } | 1900 } |
1904 | 1901 |
1905 // The default channel may or may not be in |receive_channels_|. Set the rtp | |
1906 // header extensions for default channel regardless. | |
1907 if (!SetChannelRecvRtpHeaderExtensions(default_send_channel_id(), | |
1908 extensions)) { | |
1909 return false; | |
1910 } | |
1911 | |
1912 // Loop through all receive channels and enable/disable the extensions. | |
1913 for (const auto& ch : receive_channels_) { | 1902 for (const auto& ch : receive_channels_) { |
1914 if (!SetChannelRecvRtpHeaderExtensions(ch.second->channel(), extensions)) { | 1903 if (!SetChannelRecvRtpHeaderExtensions(ch.second->channel(), extensions)) { |
1915 return false; | 1904 return false; |
1916 } | 1905 } |
1917 } | 1906 } |
1918 | 1907 |
1919 receive_extensions_ = extensions; | 1908 receive_extensions_ = extensions; |
1920 | 1909 |
1921 // Recreate AudioReceiveStream:s. | 1910 // Recreate AudioReceiveStream:s. |
1922 { | 1911 { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 } | 2015 } |
2027 | 2016 |
2028 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { | 2017 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { |
2029 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2018 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2030 if (playout_ == playout) { | 2019 if (playout_ == playout) { |
2031 return true; | 2020 return true; |
2032 } | 2021 } |
2033 | 2022 |
2034 // Change the playout of all channels to the new state. | 2023 // Change the playout of all channels to the new state. |
2035 bool result = true; | 2024 bool result = true; |
2036 if (receive_channels_.empty()) { | |
2037 // Only toggle the default channel if we don't have any other channels. | |
2038 result = SetPlayout(default_send_channel_id(), playout); | |
2039 } | |
2040 for (const auto& ch : receive_channels_) { | 2025 for (const auto& ch : receive_channels_) { |
2041 if (!SetPlayout(ch.second->channel(), playout)) { | 2026 if (!SetPlayout(ch.second->channel(), playout)) { |
2042 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " | 2027 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " |
2043 << ch.second->channel() << " failed"; | 2028 << ch.second->channel() << " failed"; |
2044 result = false; | 2029 result = false; |
2045 break; | 2030 break; |
2046 } | 2031 } |
2047 } | 2032 } |
2048 | 2033 |
2049 if (result) { | 2034 if (result) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2133 // TODO(ronghuawu): Change this method to return bool. | 2118 // TODO(ronghuawu): Change this method to return bool. |
2134 void WebRtcVoiceMediaChannel::ConfigureSendChannel(int channel) { | 2119 void WebRtcVoiceMediaChannel::ConfigureSendChannel(int channel) { |
2135 if (engine()->voe()->network()->RegisterExternalTransport( | 2120 if (engine()->voe()->network()->RegisterExternalTransport( |
2136 channel, *this) == -1) { | 2121 channel, *this) == -1) { |
2137 LOG_RTCERR2(RegisterExternalTransport, channel, this); | 2122 LOG_RTCERR2(RegisterExternalTransport, channel, this); |
2138 } | 2123 } |
2139 | 2124 |
2140 // Enable RTCP (for quality stats and feedback messages) | 2125 // Enable RTCP (for quality stats and feedback messages) |
2141 EnableRtcp(channel); | 2126 EnableRtcp(channel); |
2142 | 2127 |
2143 // Reset all recv codecs; they will be enabled via SetRecvCodecs. | |
2144 ResetRecvCodecs(channel); | |
2145 | |
2146 // Set RTP header extension for the new channel. | 2128 // Set RTP header extension for the new channel. |
2147 SetChannelSendRtpHeaderExtensions(channel, send_extensions_); | 2129 SetChannelSendRtpHeaderExtensions(channel, send_extensions_); |
2148 } | 2130 } |
2149 | 2131 |
2150 bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) { | 2132 bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) { |
2151 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { | 2133 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { |
2152 LOG_RTCERR1(DeRegisterExternalTransport, channel); | 2134 LOG_RTCERR1(DeRegisterExternalTransport, channel); |
2153 } | 2135 } |
2154 | 2136 |
2155 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { | 2137 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2206 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); | 2188 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); |
2207 return false; | 2189 return false; |
2208 } | 2190 } |
2209 | 2191 |
2210 // At this point the channel's local SSRC has been updated. If the channel is | 2192 // At this point the channel's local SSRC has been updated. If the channel is |
2211 // the default channel make sure that all the receive channels are updated as | 2193 // the default channel make sure that all the receive channels are updated as |
2212 // well. Receive channels have to have the same SSRC as the default channel in | 2194 // well. Receive channels have to have the same SSRC as the default channel in |
2213 // order to send receiver reports with this SSRC. | 2195 // order to send receiver reports with this SSRC. |
2214 if (IsDefaultChannel(channel)) { | 2196 if (IsDefaultChannel(channel)) { |
2215 for (const auto& ch : receive_channels_) { | 2197 for (const auto& ch : receive_channels_) { |
2216 // Only update the SSRC for non-default channels. | 2198 if (engine()->voe()->rtp()->SetLocalSSRC(ch.second->channel(), |
2217 if (!IsDefaultChannel(ch.second->channel())) { | 2199 sp.first_ssrc()) != 0) { |
2218 if (engine()->voe()->rtp()->SetLocalSSRC(ch.second->channel(), | 2200 LOG_RTCERR2(SetLocalSSRC, ch.second->channel(), sp.first_ssrc()); |
2219 sp.first_ssrc()) != 0) { | 2201 return false; |
2220 LOG_RTCERR2(SetLocalSSRC, ch.second->channel(), sp.first_ssrc()); | |
2221 return false; | |
2222 } | |
2223 } | 2202 } |
2224 } | 2203 } |
2225 } | 2204 } |
2226 | 2205 |
2227 if (engine()->voe()->rtp()->SetRTCP_CNAME(channel, sp.cname.c_str()) == -1) { | 2206 if (engine()->voe()->rtp()->SetRTCP_CNAME(channel, sp.cname.c_str()) == -1) { |
2228 LOG_RTCERR2(SetRTCP_CNAME, channel, sp.cname); | 2207 LOG_RTCERR2(SetRTCP_CNAME, channel, sp.cname); |
2229 return false; | 2208 return false; |
2230 } | 2209 } |
2231 | 2210 |
2232 // Set the current codecs to be used for the new channel. | 2211 // Set the current codecs to be used for the new channel. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2277 if (!ValidateStreamParams(sp)) { | 2256 if (!ValidateStreamParams(sp)) { |
2278 return false; | 2257 return false; |
2279 } | 2258 } |
2280 | 2259 |
2281 uint32 ssrc = sp.first_ssrc(); | 2260 uint32 ssrc = sp.first_ssrc(); |
2282 if (ssrc == 0) { | 2261 if (ssrc == 0) { |
2283 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; | 2262 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; |
2284 return false; | 2263 return false; |
2285 } | 2264 } |
2286 | 2265 |
2287 rtc::CritScope lock(&receive_channels_cs_); | 2266 // Remove the default receive stream if one had been created with this ssrc; |
| 2267 // we'll recreate it then. |
| 2268 if (using_default_recv_channel_ && ssrc == default_recv_ssrc_) { |
| 2269 RemoveRecvStream(ssrc); |
| 2270 } |
2288 | 2271 |
2289 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 2272 if (receive_channels_.find(ssrc) != receive_channels_.end()) { |
2290 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 2273 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; |
2291 return false; | 2274 return false; |
2292 } | 2275 } |
2293 | |
2294 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); | 2276 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); |
2295 | 2277 |
2296 // Reuse default channel for recv stream in non-conference mode call | |
2297 // when the default channel is not being used. | |
2298 webrtc::AudioTransport* audio_transport = | |
2299 engine()->voe()->base()->audio_transport(); | |
2300 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | |
2301 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | |
2302 default_receive_ssrc_ = ssrc; | |
2303 WebRtcVoiceChannelRenderer* channel_renderer = | |
2304 new WebRtcVoiceChannelRenderer(default_send_channel_id(), | |
2305 audio_transport); | |
2306 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | |
2307 receive_stream_params_[ssrc] = sp; | |
2308 AddAudioReceiveStream(ssrc); | |
2309 return SetPlayout(default_send_channel_id(), playout_); | |
2310 } | |
2311 | |
2312 // Create a new channel for receiving audio data. | 2278 // Create a new channel for receiving audio data. |
2313 int channel = engine()->CreateMediaVoiceChannel(); | 2279 int channel = engine()->CreateMediaVoiceChannel(); |
2314 if (channel == -1) { | 2280 if (channel == -1) { |
2315 LOG_RTCERR0(CreateChannel); | 2281 LOG_RTCERR0(CreateChannel); |
2316 return false; | 2282 return false; |
2317 } | 2283 } |
2318 if (!ConfigureRecvChannel(channel)) { | 2284 if (!ConfigureRecvChannel(channel)) { |
2319 DeleteChannel(channel); | 2285 DeleteChannel(channel); |
2320 return false; | 2286 return false; |
2321 } | 2287 } |
2322 | 2288 |
| 2289 webrtc::AudioTransport* audio_transport = |
| 2290 engine()->voe()->base()->audio_transport(); |
2323 WebRtcVoiceChannelRenderer* channel_renderer = | 2291 WebRtcVoiceChannelRenderer* channel_renderer = |
2324 new WebRtcVoiceChannelRenderer(channel, audio_transport); | 2292 new WebRtcVoiceChannelRenderer(channel, audio_transport); |
2325 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | 2293 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); |
2326 receive_stream_params_[ssrc] = sp; | 2294 receive_stream_params_[ssrc] = sp; |
2327 AddAudioReceiveStream(ssrc); | 2295 AddAudioReceiveStream(ssrc); |
2328 | 2296 |
2329 LOG(LS_INFO) << "New audio stream " << ssrc | 2297 LOG(LS_INFO) << "New audio stream " << ssrc |
2330 << " registered to VoiceEngine channel #" | 2298 << " registered to VoiceEngine channel #" |
2331 << channel << "."; | 2299 << channel << "."; |
2332 return true; | 2300 return true; |
(...skipping 25 matching lines...) Expand all Loading... |
2358 } | 2326 } |
2359 | 2327 |
2360 // Associate receive channel to default send channel (so the receive channel | 2328 // Associate receive channel to default send channel (so the receive channel |
2361 // can obtain RTT from the send channel). | 2329 // can obtain RTT from the send channel). |
2362 engine()->voe()->base()->AssociateSendChannel(channel, | 2330 engine()->voe()->base()->AssociateSendChannel(channel, |
2363 default_send_channel_id()); | 2331 default_send_channel_id()); |
2364 LOG(LS_INFO) << "VoiceEngine channel #" | 2332 LOG(LS_INFO) << "VoiceEngine channel #" |
2365 << channel << " is associated with channel #" | 2333 << channel << " is associated with channel #" |
2366 << default_send_channel_id() << "."; | 2334 << default_send_channel_id() << "."; |
2367 | 2335 |
2368 // Use the same recv payload types as our default channel. | 2336 // Turn off all supported codecs. |
2369 ResetRecvCodecs(channel); | 2337 int ncodecs = engine()->voe()->codec()->NumOfCodecs(); |
2370 if (!recv_codecs_.empty()) { | 2338 for (int i = 0; i < ncodecs; ++i) { |
2371 for (const auto& codec : recv_codecs_) { | 2339 webrtc::CodecInst voe_codec; |
2372 webrtc::CodecInst voe_codec; | 2340 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) { |
2373 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { | 2341 voe_codec.pltype = -1; |
2374 voe_codec.pltype = codec.id; | 2342 if (engine()->voe()->codec()->SetRecPayloadType( |
2375 voe_codec.rate = 0; // Needed to make GetRecPayloadType work for ISAC | 2343 channel, voe_codec) == -1) { |
2376 if (engine()->voe()->codec()->GetRecPayloadType( | 2344 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); |
2377 default_send_channel_id(), voe_codec) != -1) { | 2345 return false; |
2378 if (engine()->voe()->codec()->SetRecPayloadType( | |
2379 channel, voe_codec) == -1) { | |
2380 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); | |
2381 return false; | |
2382 } | |
2383 } | |
2384 } | 2346 } |
2385 } | 2347 } |
2386 } | 2348 } |
2387 | 2349 |
2388 if (InConferenceMode()) { | 2350 // Only enable those configured for this channel. |
2389 // To be in par with the video, default_send_channel_id() is not used for | 2351 for (const auto& codec : recv_codecs_) { |
2390 // receiving in a conference call. | 2352 webrtc::CodecInst voe_codec; |
2391 if (receive_channels_.empty() && default_receive_ssrc_ == 0 && playout_) { | 2353 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { |
2392 // This is the first stream in a multi user meeting. We can now | 2354 voe_codec.pltype = codec.id; |
2393 // disable playback of the default stream. This since the default | 2355 if (engine()->voe()->codec()->SetRecPayloadType( |
2394 // stream will probably have received some initial packets before | 2356 channel, voe_codec) == -1) { |
2395 // the new stream was added. This will mean that the CN state from | 2357 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); |
2396 // the default channel will be mixed in with the other streams | 2358 return false; |
2397 // throughout the whole meeting, which might be disturbing. | 2359 } |
2398 LOG(LS_INFO) << "Disabling playback on the default voice channel"; | |
2399 SetPlayout(default_send_channel_id(), false); | |
2400 } | 2360 } |
2401 } | 2361 } |
2402 | 2362 |
2403 SetNack(channel, nack_enabled_); | 2363 SetNack(channel, nack_enabled_); |
2404 | 2364 |
2405 // Set RTP header extension for the new channel. | 2365 // Set RTP header extension for the new channel. |
2406 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { | 2366 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { |
2407 return false; | 2367 return false; |
2408 } | 2368 } |
2409 | 2369 |
2410 return SetPlayout(channel, playout_); | 2370 return SetPlayout(channel, playout_); |
2411 } | 2371 } |
2412 | 2372 |
2413 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32 ssrc) { | 2373 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32 ssrc) { |
2414 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2374 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2415 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; | 2375 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; |
2416 | 2376 |
2417 rtc::CritScope lock(&receive_channels_cs_); | |
2418 ChannelMap::iterator it = receive_channels_.find(ssrc); | 2377 ChannelMap::iterator it = receive_channels_.find(ssrc); |
2419 if (it == receive_channels_.end()) { | 2378 if (it == receive_channels_.end()) { |
2420 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 2379 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc |
2421 << " which doesn't exist."; | 2380 << " which doesn't exist."; |
2422 return false; | 2381 return false; |
2423 } | 2382 } |
2424 | 2383 |
2425 RemoveAudioReceiveStream(ssrc); | 2384 RemoveAudioReceiveStream(ssrc); |
2426 receive_stream_params_.erase(ssrc); | 2385 receive_stream_params_.erase(ssrc); |
2427 | 2386 |
2428 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this | 2387 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this |
2429 // will disconnect the audio renderer with the receive channel. | 2388 // will disconnect the audio renderer with the receive channel. |
2430 // Cache the channel before the deletion. | 2389 // Cache the channel before the deletion. |
2431 const int channel = it->second->channel(); | 2390 const int channel = it->second->channel(); |
2432 delete it->second; | 2391 delete it->second; |
2433 receive_channels_.erase(it); | 2392 receive_channels_.erase(it); |
2434 | 2393 |
2435 if (ssrc == default_receive_ssrc_) { | 2394 // Deregister default channel, if that's the one being destroyed. |
2436 RTC_DCHECK(IsDefaultChannel(channel)); | 2395 if (using_default_recv_channel_ && ssrc == default_recv_ssrc_) { |
2437 // Recycle the default channel is for recv stream. | 2396 using_default_recv_channel_ = false; |
2438 if (playout_) | 2397 default_recv_ssrc_ = 0; |
2439 SetPlayout(default_send_channel_id(), false); | |
2440 | |
2441 default_receive_ssrc_ = 0; | |
2442 return true; | |
2443 } | 2398 } |
2444 | 2399 |
2445 LOG(LS_INFO) << "Removing audio stream " << ssrc | 2400 LOG(LS_INFO) << "Removing audio stream " << ssrc |
2446 << " with VoiceEngine channel #" << channel << "."; | 2401 << " with VoiceEngine channel #" << channel << "."; |
2447 if (!DeleteChannel(channel)) | 2402 return DeleteChannel(channel); |
2448 return false; | |
2449 | |
2450 bool enable_default_channel_playout = false; | |
2451 if (receive_channels_.empty()) { | |
2452 // The last stream was removed. We can now enable the default | |
2453 // channel for new channels to be played out immediately without | |
2454 // waiting for AddStream messages. | |
2455 // We do this for both conference mode and non-conference mode. | |
2456 // TODO(oja): Does the default channel still have it's CN state? | |
2457 enable_default_channel_playout = true; | |
2458 } | |
2459 if (!InConferenceMode() && receive_channels_.size() == 1 && | |
2460 default_receive_ssrc_ != 0) { | |
2461 // Only the default channel is active, enable the playout on default | |
2462 // channel. | |
2463 enable_default_channel_playout = true; | |
2464 } | |
2465 if (enable_default_channel_playout && playout_) { | |
2466 LOG(LS_INFO) << "Enabling playback on the default voice channel"; | |
2467 SetPlayout(default_send_channel_id(), true); | |
2468 } | |
2469 | |
2470 return true; | |
2471 } | 2403 } |
2472 | 2404 |
2473 bool WebRtcVoiceMediaChannel::SetRemoteRenderer(uint32 ssrc, | 2405 bool WebRtcVoiceMediaChannel::SetRemoteRenderer(uint32 ssrc, |
2474 AudioRenderer* renderer) { | 2406 AudioRenderer* renderer) { |
2475 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2407 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2476 ChannelMap::iterator it = receive_channels_.find(ssrc); | 2408 ChannelMap::iterator it = receive_channels_.find(ssrc); |
2477 if (it == receive_channels_.end()) { | 2409 if (it == receive_channels_.end()) { |
2478 if (renderer) { | 2410 if (renderer) { |
2479 // Return an error if trying to set a valid renderer with an invalid ssrc. | 2411 // Return an error if trying to set a valid renderer with an invalid ssrc. |
2480 LOG(LS_ERROR) << "SetRemoteRenderer failed with ssrc "<< ssrc; | 2412 LOG(LS_ERROR) << "SetRemoteRenderer failed with ssrc "<< ssrc; |
(...skipping 30 matching lines...) Expand all Loading... |
2511 it->second->Start(renderer); | 2443 it->second->Start(renderer); |
2512 else | 2444 else |
2513 it->second->Stop(); | 2445 it->second->Stop(); |
2514 | 2446 |
2515 return true; | 2447 return true; |
2516 } | 2448 } |
2517 | 2449 |
2518 bool WebRtcVoiceMediaChannel::GetActiveStreams( | 2450 bool WebRtcVoiceMediaChannel::GetActiveStreams( |
2519 AudioInfo::StreamList* actives) { | 2451 AudioInfo::StreamList* actives) { |
2520 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2452 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2521 // In conference mode, the default channel should not be in | |
2522 // |receive_channels_|. | |
2523 actives->clear(); | 2453 actives->clear(); |
2524 for (const auto& ch : receive_channels_) { | 2454 for (const auto& ch : receive_channels_) { |
2525 int level = GetOutputLevel(ch.second->channel()); | 2455 int level = GetOutputLevel(ch.second->channel()); |
2526 if (level > 0) { | 2456 if (level > 0) { |
2527 actives->push_back(std::make_pair(ch.first, level)); | 2457 actives->push_back(std::make_pair(ch.first, level)); |
2528 } | 2458 } |
2529 } | 2459 } |
2530 return true; | 2460 return true; |
2531 } | 2461 } |
2532 | 2462 |
2533 int WebRtcVoiceMediaChannel::GetOutputLevel() { | 2463 int WebRtcVoiceMediaChannel::GetOutputLevel() { |
2534 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2464 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2535 // return the highest output level of all streams | 2465 int highest = 0; |
2536 int highest = GetOutputLevel(default_send_channel_id()); | |
2537 for (const auto& ch : receive_channels_) { | 2466 for (const auto& ch : receive_channels_) { |
2538 highest = std::max(GetOutputLevel(ch.second->channel()), highest); | 2467 highest = std::max(GetOutputLevel(ch.second->channel()), highest); |
2539 } | 2468 } |
2540 return highest; | 2469 return highest; |
2541 } | 2470 } |
2542 | 2471 |
2543 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() { | 2472 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() { |
2544 int ret; | 2473 int ret; |
2545 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) { | 2474 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) { |
2546 // In case of error, log the info and continue | 2475 // In case of error, log the info and continue |
(...skipping 14 matching lines...) Expand all Loading... |
2561 // In case of error, log the info and continue | 2490 // In case of error, log the info and continue |
2562 LOG_RTCERR5(SetTypingDetectionParameters, time_window, | 2491 LOG_RTCERR5(SetTypingDetectionParameters, time_window, |
2563 cost_per_typing, reporting_threshold, penalty_decay, | 2492 cost_per_typing, reporting_threshold, penalty_decay, |
2564 type_event_delay); | 2493 type_event_delay); |
2565 } | 2494 } |
2566 } | 2495 } |
2567 | 2496 |
2568 bool WebRtcVoiceMediaChannel::SetOutputScaling( | 2497 bool WebRtcVoiceMediaChannel::SetOutputScaling( |
2569 uint32 ssrc, double left, double right) { | 2498 uint32 ssrc, double left, double right) { |
2570 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2499 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2571 rtc::CritScope lock(&receive_channels_cs_); | 2500 int ch_id = GetReceiveChannelId(ssrc); |
2572 // Collect the channels to scale the output volume. | 2501 if (ch_id < 0) { |
2573 std::vector<int> channels; | 2502 LOG(LS_WARNING) << "Cannot find channel for ssrc:" << ssrc; |
2574 if (0 == ssrc) { // Collect all channels, including the default one. | 2503 return true; |
2575 // Default channel is not in receive_channels_ if it is not being used for | |
2576 // playout. | |
2577 if (default_receive_ssrc_ == 0) | |
2578 channels.push_back(default_send_channel_id()); | |
2579 for (const auto& ch : receive_channels_) { | |
2580 channels.push_back(ch.second->channel()); | |
2581 } | |
2582 } else { // Collect only the channel of the specified ssrc. | |
2583 int channel = GetReceiveChannelId(ssrc); | |
2584 if (-1 == channel) { | |
2585 LOG(LS_WARNING) << "Cannot find channel for ssrc:" << ssrc; | |
2586 return false; | |
2587 } | |
2588 channels.push_back(channel); | |
2589 } | 2504 } |
2590 | 2505 |
2591 // Scale the output volume for the collected channels. We first normalize to | 2506 // Scale the output volume for the collected channels. We first normalize to |
2592 // scale the volume and then set the left and right pan. | 2507 // scale the volume and then set the left and right pan. |
2593 float scale = static_cast<float>(std::max(left, right)); | 2508 float scale = static_cast<float>(std::max(left, right)); |
2594 if (scale > 0.0001f) { | 2509 if (scale > 0.0001f) { |
2595 left /= scale; | 2510 left /= scale; |
2596 right /= scale; | 2511 right /= scale; |
2597 } | 2512 } |
2598 for (int ch_id : channels) { | 2513 if (-1 == engine()->voe()->volume()->SetChannelOutputVolumeScaling( |
2599 if (-1 == engine()->voe()->volume()->SetChannelOutputVolumeScaling( | 2514 ch_id, scale)) { |
2600 ch_id, scale)) { | 2515 LOG_RTCERR2(SetChannelOutputVolumeScaling, ch_id, scale); |
2601 LOG_RTCERR2(SetChannelOutputVolumeScaling, ch_id, scale); | 2516 return false; |
2602 return false; | |
2603 } | |
2604 if (-1 == engine()->voe()->volume()->SetOutputVolumePan( | |
2605 ch_id, static_cast<float>(left), static_cast<float>(right))) { | |
2606 LOG_RTCERR3(SetOutputVolumePan, ch_id, left, right); | |
2607 // Do not return if fails. SetOutputVolumePan is not available for all | |
2608 // pltforms. | |
2609 } | |
2610 LOG(LS_INFO) << "SetOutputScaling to left=" << left * scale | |
2611 << " right=" << right * scale | |
2612 << " for channel " << ch_id << " and ssrc " << ssrc; | |
2613 } | 2517 } |
| 2518 if (-1 == engine()->voe()->volume()->SetOutputVolumePan( |
| 2519 ch_id, static_cast<float>(left), static_cast<float>(right))) { |
| 2520 LOG_RTCERR3(SetOutputVolumePan, ch_id, left, right); |
| 2521 // Do not return if fails. SetOutputVolumePan is not available for all |
| 2522 // pltforms. |
| 2523 } |
| 2524 LOG(LS_INFO) << "SetOutputScaling to left=" << left * scale |
| 2525 << " right=" << right * scale |
| 2526 << " for channel " << ch_id << " and ssrc " << ssrc; |
2614 return true; | 2527 return true; |
2615 } | 2528 } |
2616 | 2529 |
2617 bool WebRtcVoiceMediaChannel::CanInsertDtmf() { | 2530 bool WebRtcVoiceMediaChannel::CanInsertDtmf() { |
2618 return dtmf_allowed_; | 2531 return dtmf_allowed_; |
2619 } | 2532 } |
2620 | 2533 |
2621 bool WebRtcVoiceMediaChannel::InsertDtmf(uint32 ssrc, int event, | 2534 bool WebRtcVoiceMediaChannel::InsertDtmf(uint32 ssrc, int event, |
2622 int duration, int flags) { | 2535 int duration, int flags) { |
2623 if (!dtmf_allowed_) { | 2536 if (!dtmf_allowed_) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2665 } | 2578 } |
2666 } | 2579 } |
2667 | 2580 |
2668 return true; | 2581 return true; |
2669 } | 2582 } |
2670 | 2583 |
2671 void WebRtcVoiceMediaChannel::OnPacketReceived( | 2584 void WebRtcVoiceMediaChannel::OnPacketReceived( |
2672 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 2585 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
2673 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2586 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2674 | 2587 |
2675 // Forward packet to Call as well. | 2588 uint32 ssrc = 0; |
| 2589 if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) { |
| 2590 return; |
| 2591 } |
| 2592 |
| 2593 if (receive_channels_.empty()) { |
| 2594 // Create new channel, which will be the default receive channel. |
| 2595 StreamParams sp; |
| 2596 sp.ssrcs.push_back(ssrc); |
| 2597 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; |
| 2598 if (!AddRecvStream(sp)) { |
| 2599 LOG(LS_WARNING) << "Could not create default receive stream."; |
| 2600 return; |
| 2601 } |
| 2602 using_default_recv_channel_ = true; |
| 2603 default_recv_ssrc_ = ssrc; |
| 2604 } |
| 2605 |
| 2606 // Forward packet to Call. If the SSRC is unknown we'll return after this. |
2676 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2607 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2677 packet_time.not_before); | 2608 packet_time.not_before); |
2678 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2609 webrtc::PacketReceiver::DeliveryStatus delivery_result = |
2679 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2610 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2680 webrtc_packet_time); | 2611 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
| 2612 webrtc_packet_time); |
| 2613 if (webrtc::PacketReceiver::DELIVERY_OK != delivery_result) { |
| 2614 return; |
| 2615 } |
2681 | 2616 |
2682 // Pick which channel to send this packet to. If this packet doesn't match | 2617 // Find the channel to send this packet to. It must exist since webrtc::Call |
2683 // any multiplexed streams, just send it to the default channel. Otherwise, | 2618 // was able to demux the packet. |
2684 // send it to the specific decoder instance for that stream. | 2619 int channel = GetReceiveChannelId(ssrc); |
2685 int which_channel = | 2620 RTC_DCHECK(channel != -1); |
2686 GetReceiveChannelId(ParseSsrc(packet->data(), packet->size(), false)); | |
2687 if (which_channel == -1) { | |
2688 which_channel = default_send_channel_id(); | |
2689 } | |
2690 | 2621 |
2691 // Pass it off to the decoder. | 2622 // Pass it off to the decoder. |
2692 engine()->voe()->network()->ReceivedRTPPacket( | 2623 engine()->voe()->network()->ReceivedRTPPacket( |
2693 which_channel, packet->data(), packet->size(), | 2624 channel, packet->data(), packet->size(), webrtc_packet_time); |
2694 webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); | |
2695 } | 2625 } |
2696 | 2626 |
2697 void WebRtcVoiceMediaChannel::OnRtcpReceived( | 2627 void WebRtcVoiceMediaChannel::OnRtcpReceived( |
2698 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 2628 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
2699 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2629 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2700 | 2630 |
2701 // Forward packet to Call as well. | 2631 // Forward packet to Call as well. |
2702 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2632 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2703 packet_time.not_before); | 2633 packet_time.not_before); |
2704 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2634 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2705 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2635 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
2706 webrtc_packet_time); | 2636 webrtc_packet_time); |
2707 | 2637 |
2708 // Sending channels need all RTCP packets with feedback information. | 2638 // Sending channels need all RTCP packets with feedback information. |
2709 // Even sender reports can contain attached report blocks. | 2639 // Even sender reports can contain attached report blocks. |
2710 // Receiving channels need sender reports in order to create | 2640 // Receiving channels need sender reports in order to create |
2711 // correct receiver reports. | 2641 // correct receiver reports. |
2712 int type = 0; | 2642 int type = 0; |
2713 if (!GetRtcpType(packet->data(), packet->size(), &type)) { | 2643 if (!GetRtcpType(packet->data(), packet->size(), &type)) { |
2714 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; | 2644 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; |
2715 return; | 2645 return; |
2716 } | 2646 } |
2717 | 2647 |
2718 // If it is a sender report, find the receive channel that is listening. | 2648 // If it is a sender report, find the receive channel that is listening. |
2719 bool has_sent_to_default_channel = false; | |
2720 if (type == kRtcpTypeSR) { | 2649 if (type == kRtcpTypeSR) { |
2721 uint32 ssrc = 0; | 2650 uint32 ssrc = 0; |
2722 if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) { | 2651 if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) { |
2723 return; | 2652 return; |
2724 } | 2653 } |
2725 int recv_channel_id = GetReceiveChannelId(ssrc); | 2654 int recv_channel_id = GetReceiveChannelId(ssrc); |
2726 if (recv_channel_id != -1) { | 2655 if (recv_channel_id != -1) { |
2727 engine()->voe()->network()->ReceivedRTCPPacket( | 2656 engine()->voe()->network()->ReceivedRTCPPacket( |
2728 recv_channel_id, packet->data(), packet->size()); | 2657 recv_channel_id, packet->data(), packet->size()); |
2729 | |
2730 if (IsDefaultChannel(recv_channel_id)) | |
2731 has_sent_to_default_channel = true; | |
2732 } | 2658 } |
2733 } | 2659 } |
2734 | 2660 |
2735 // SR may continue RR and any RR entry may correspond to any one of the send | 2661 // SR may continue RR and any RR entry may correspond to any one of the send |
2736 // channels. So all RTCP packets must be forwarded all send channels. VoE | 2662 // channels. So all RTCP packets must be forwarded all send channels. VoE |
2737 // will filter out RR internally. | 2663 // will filter out RR internally. |
2738 for (const auto& ch : send_channels_) { | 2664 for (const auto& ch : send_channels_) { |
2739 // Make sure not sending the same packet to default channel more than once. | |
2740 if (IsDefaultChannel(ch.second->channel()) && | |
2741 has_sent_to_default_channel) | |
2742 continue; | |
2743 | |
2744 engine()->voe()->network()->ReceivedRTCPPacket( | 2665 engine()->voe()->network()->ReceivedRTCPPacket( |
2745 ch.second->channel(), packet->data(), packet->size()); | 2666 ch.second->channel(), packet->data(), packet->size()); |
2746 } | 2667 } |
2747 } | 2668 } |
2748 | 2669 |
2749 bool WebRtcVoiceMediaChannel::MuteStream(uint32 ssrc, bool muted) { | 2670 bool WebRtcVoiceMediaChannel::MuteStream(uint32 ssrc, bool muted) { |
2750 int channel = | 2671 int channel = |
2751 (ssrc == 0) ? default_send_channel_id() : GetSendChannelId(ssrc); | 2672 (ssrc == 0) ? default_send_channel_id() : GetSendChannelId(ssrc); |
2752 if (channel == -1) { | 2673 if (channel == -1) { |
2753 LOG(LS_WARNING) << "The specified ssrc " << ssrc << " is not in use."; | 2674 LOG(LS_WARNING) << "The specified ssrc " << ssrc << " is not in use."; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2928 sinfo.echo_return_loss_enhancement = echo_return_loss_enhancement; | 2849 sinfo.echo_return_loss_enhancement = echo_return_loss_enhancement; |
2929 sinfo.echo_delay_median_ms = echo_delay_median_ms; | 2850 sinfo.echo_delay_median_ms = echo_delay_median_ms; |
2930 sinfo.echo_delay_std_ms = echo_delay_std_ms; | 2851 sinfo.echo_delay_std_ms = echo_delay_std_ms; |
2931 // TODO(ajm): Re-enable this metric once we have a reliable implementation. | 2852 // TODO(ajm): Re-enable this metric once we have a reliable implementation. |
2932 sinfo.aec_quality_min = -1; | 2853 sinfo.aec_quality_min = -1; |
2933 sinfo.typing_noise_detected = typing_noise_detected_; | 2854 sinfo.typing_noise_detected = typing_noise_detected_; |
2934 | 2855 |
2935 info->senders.push_back(sinfo); | 2856 info->senders.push_back(sinfo); |
2936 } | 2857 } |
2937 | 2858 |
2938 // Build the list of receivers, one for each receiving channel, or 1 in | 2859 // Get the SSRC and stats for each receiver. |
2939 // a 1:1 call. | |
2940 std::vector<int> channels; | |
2941 for (const auto& ch : receive_channels_) { | 2860 for (const auto& ch : receive_channels_) { |
2942 channels.push_back(ch.second->channel()); | 2861 int ch_id = ch.second->channel(); |
2943 } | |
2944 if (channels.empty()) { | |
2945 channels.push_back(default_send_channel_id()); | |
2946 } | |
2947 | |
2948 // Get the SSRC and stats for each receiver, based on our own calculations. | |
2949 for (int ch_id : channels) { | |
2950 memset(&cs, 0, sizeof(cs)); | 2862 memset(&cs, 0, sizeof(cs)); |
2951 if (engine()->voe()->rtp()->GetRemoteSSRC(ch_id, ssrc) != -1 && | 2863 if (engine()->voe()->rtp()->GetRemoteSSRC(ch_id, ssrc) != -1 && |
2952 engine()->voe()->rtp()->GetRTCPStatistics(ch_id, cs) != -1 && | 2864 engine()->voe()->rtp()->GetRTCPStatistics(ch_id, cs) != -1 && |
2953 engine()->voe()->codec()->GetRecCodec(ch_id, codec) != -1) { | 2865 engine()->voe()->codec()->GetRecCodec(ch_id, codec) != -1) { |
2954 VoiceReceiverInfo rinfo; | 2866 VoiceReceiverInfo rinfo; |
2955 rinfo.add_ssrc(ssrc); | 2867 rinfo.add_ssrc(ssrc); |
2956 rinfo.bytes_rcvd = cs.bytesReceived; | 2868 rinfo.bytes_rcvd = cs.bytesReceived; |
2957 rinfo.packets_rcvd = cs.packetsReceived; | 2869 rinfo.packets_rcvd = cs.packetsReceived; |
2958 // The next four fields are from the most recently sent RTCP report. | 2870 // The next four fields are from the most recently sent RTCP report. |
2959 // Convert Q8 to floating point. | 2871 // Convert Q8 to floating point. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3036 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); | 2948 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); |
3037 return (ret == 0) ? static_cast<int>(ulevel) : -1; | 2949 return (ret == 0) ? static_cast<int>(ulevel) : -1; |
3038 } | 2950 } |
3039 | 2951 |
3040 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32 ssrc) const { | 2952 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32 ssrc) const { |
3041 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2953 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3042 ChannelMap::const_iterator it = receive_channels_.find(ssrc); | 2954 ChannelMap::const_iterator it = receive_channels_.find(ssrc); |
3043 if (it != receive_channels_.end()) { | 2955 if (it != receive_channels_.end()) { |
3044 return it->second->channel(); | 2956 return it->second->channel(); |
3045 } | 2957 } |
3046 return (ssrc == default_receive_ssrc_) ? default_send_channel_id() : -1; | 2958 return -1; |
3047 } | 2959 } |
3048 | 2960 |
3049 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32 ssrc) const { | 2961 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32 ssrc) const { |
3050 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 2962 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3051 ChannelMap::const_iterator it = send_channels_.find(ssrc); | 2963 ChannelMap::const_iterator it = send_channels_.find(ssrc); |
3052 if (it != send_channels_.end()) { | 2964 if (it != send_channels_.end()) { |
3053 return it->second->channel(); | 2965 return it->second->channel(); |
3054 } | 2966 } |
3055 return -1; | 2967 return -1; |
3056 } | 2968 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3104 LOG_RTCERR2(SetRTCPStatus, channel, 1); | 3016 LOG_RTCERR2(SetRTCPStatus, channel, 1); |
3105 return false; | 3017 return false; |
3106 } | 3018 } |
3107 // TODO(juberti): Enable VQMon and RTCP XR reports, once we know what | 3019 // TODO(juberti): Enable VQMon and RTCP XR reports, once we know what |
3108 // what we want to do with them. | 3020 // what we want to do with them. |
3109 // engine()->voe().EnableVQMon(default_send_channel_id(), true); | 3021 // engine()->voe().EnableVQMon(default_send_channel_id(), true); |
3110 // engine()->voe().EnableRTCP_XR(default_send_channel_id(), true); | 3022 // engine()->voe().EnableRTCP_XR(default_send_channel_id(), true); |
3111 return true; | 3023 return true; |
3112 } | 3024 } |
3113 | 3025 |
3114 bool WebRtcVoiceMediaChannel::ResetRecvCodecs(int channel) { | |
3115 int ncodecs = engine()->voe()->codec()->NumOfCodecs(); | |
3116 for (int i = 0; i < ncodecs; ++i) { | |
3117 webrtc::CodecInst voe_codec; | |
3118 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) { | |
3119 voe_codec.pltype = -1; | |
3120 if (engine()->voe()->codec()->SetRecPayloadType( | |
3121 channel, voe_codec) == -1) { | |
3122 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); | |
3123 return false; | |
3124 } | |
3125 } | |
3126 } | |
3127 return true; | |
3128 } | |
3129 | |
3130 bool WebRtcVoiceMediaChannel::SetPlayout(int channel, bool playout) { | 3026 bool WebRtcVoiceMediaChannel::SetPlayout(int channel, bool playout) { |
3131 if (playout) { | 3027 if (playout) { |
3132 LOG(LS_INFO) << "Starting playout for channel #" << channel; | 3028 LOG(LS_INFO) << "Starting playout for channel #" << channel; |
3133 if (engine()->voe()->base()->StartPlayout(channel) == -1) { | 3029 if (engine()->voe()->base()->StartPlayout(channel) == -1) { |
3134 LOG_RTCERR1(StartPlayout, channel); | 3030 LOG_RTCERR1(StartPlayout, channel); |
3135 return false; | 3031 return false; |
3136 } | 3032 } |
3137 } else { | 3033 } else { |
3138 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 3034 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
3139 engine()->voe()->base()->StopPlayout(channel); | 3035 engine()->voe()->base()->StopPlayout(channel); |
3140 } | 3036 } |
3141 return true; | 3037 return true; |
3142 } | 3038 } |
3143 | 3039 |
3144 uint32 WebRtcVoiceMediaChannel::ParseSsrc(const void* data, size_t len, | |
3145 bool rtcp) { | |
3146 size_t ssrc_pos = (!rtcp) ? 8 : 4; | |
3147 uint32 ssrc = 0; | |
3148 if (len >= (ssrc_pos + sizeof(ssrc))) { | |
3149 ssrc = rtc::GetBE32(static_cast<const char*>(data) + ssrc_pos); | |
3150 } | |
3151 return ssrc; | |
3152 } | |
3153 | |
3154 // Convert VoiceEngine error code into VoiceMediaChannel::Error enum. | 3040 // Convert VoiceEngine error code into VoiceMediaChannel::Error enum. |
3155 VoiceMediaChannel::Error | 3041 VoiceMediaChannel::Error |
3156 WebRtcVoiceMediaChannel::WebRtcErrorToChannelError(int err_code) { | 3042 WebRtcVoiceMediaChannel::WebRtcErrorToChannelError(int err_code) { |
3157 switch (err_code) { | 3043 switch (err_code) { |
3158 case 0: | 3044 case 0: |
3159 return ERROR_NONE; | 3045 return ERROR_NONE; |
3160 case VE_CANNOT_START_RECORDING: | 3046 case VE_CANNOT_START_RECORDING: |
3161 case VE_MIC_VOL_ERROR: | 3047 case VE_MIC_VOL_ERROR: |
3162 case VE_GET_MIC_VOL_ERROR: | 3048 case VE_GET_MIC_VOL_ERROR: |
3163 case VE_CANNOT_ACCESS_MIC_VOL: | 3049 case VE_CANNOT_ACCESS_MIC_VOL: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3238 } | 3124 } |
3239 | 3125 |
3240 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( | 3126 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( |
3241 const std::vector<AudioCodec>& new_codecs) { | 3127 const std::vector<AudioCodec>& new_codecs) { |
3242 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 3128 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3243 for (const AudioCodec& codec : new_codecs) { | 3129 for (const AudioCodec& codec : new_codecs) { |
3244 webrtc::CodecInst voe_codec; | 3130 webrtc::CodecInst voe_codec; |
3245 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { | 3131 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { |
3246 LOG(LS_INFO) << ToString(codec); | 3132 LOG(LS_INFO) << ToString(codec); |
3247 voe_codec.pltype = codec.id; | 3133 voe_codec.pltype = codec.id; |
3248 if (default_receive_ssrc_ == 0) { | |
3249 // Set the receive codecs on the default channel explicitly if the | |
3250 // default channel is not used by |receive_channels_|, this happens in | |
3251 // conference mode or in non-conference mode when there is no playout | |
3252 // channel. | |
3253 // TODO(xians): Figure out how we use the default channel in conference | |
3254 // mode. | |
3255 if (engine()->voe()->codec()->SetRecPayloadType( | |
3256 default_send_channel_id(), voe_codec) == -1) { | |
3257 LOG_RTCERR2(SetRecPayloadType, default_send_channel_id(), | |
3258 ToString(voe_codec)); | |
3259 return false; | |
3260 } | |
3261 } | |
3262 | |
3263 // Set the receive codecs on all receiving channels. | |
3264 for (const auto& ch : receive_channels_) { | 3134 for (const auto& ch : receive_channels_) { |
3265 if (engine()->voe()->codec()->SetRecPayloadType( | 3135 if (engine()->voe()->codec()->SetRecPayloadType( |
3266 ch.second->channel(), voe_codec) == -1) { | 3136 ch.second->channel(), voe_codec) == -1) { |
3267 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(), | 3137 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(), |
3268 ToString(voe_codec)); | 3138 ToString(voe_codec)); |
3269 return false; | 3139 return false; |
3270 } | 3140 } |
3271 } | 3141 } |
3272 } else { | 3142 } else { |
3273 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); | 3143 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); |
3274 return false; | 3144 return false; |
3275 } | 3145 } |
3276 } | 3146 } |
3277 return true; | 3147 return true; |
3278 } | 3148 } |
3279 | 3149 |
3280 } // namespace cricket | 3150 } // namespace cricket |
3281 | 3151 |
3282 #endif // HAVE_WEBRTC_VOICE | 3152 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |