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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 voe_codec->rate = GetOpusBitrate(codec, *max_playback_rate); | 324 voe_codec->rate = GetOpusBitrate(codec, *max_playback_rate); |
325 } | 325 } |
326 | 326 |
327 // Changes RTP timestamp rate of G722. This is due to the "bug" in the RFC | 327 // Changes RTP timestamp rate of G722. This is due to the "bug" in the RFC |
328 // which says that G722 should be advertised as 8 kHz although it is a 16 kHz | 328 // which says that G722 should be advertised as 8 kHz although it is a 16 kHz |
329 // codec. | 329 // codec. |
330 static void MaybeFixupG722(webrtc::CodecInst* voe_codec, int new_plfreq) { | 330 static void MaybeFixupG722(webrtc::CodecInst* voe_codec, int new_plfreq) { |
331 if (IsCodec(*voe_codec, kG722CodecName)) { | 331 if (IsCodec(*voe_codec, kG722CodecName)) { |
332 // If the ASSERT triggers, the codec definition in WebRTC VoiceEngine | 332 // If the ASSERT triggers, the codec definition in WebRTC VoiceEngine |
333 // has changed, and this special case is no longer needed. | 333 // has changed, and this special case is no longer needed. |
334 DCHECK(voe_codec->plfreq != new_plfreq); | 334 RTC_DCHECK(voe_codec->plfreq != new_plfreq); |
335 voe_codec->plfreq = new_plfreq; | 335 voe_codec->plfreq = new_plfreq; |
336 } | 336 } |
337 } | 337 } |
338 | 338 |
339 // Gets the default set of options applied to the engine. Historically, these | 339 // Gets the default set of options applied to the engine. Historically, these |
340 // were supplied as a combination of flags from the channel manager (ec, agc, | 340 // were supplied as a combination of flags from the channel manager (ec, agc, |
341 // ns, and highpass) and the rest hardcoded in InitInternal. | 341 // ns, and highpass) and the rest hardcoded in InitInternal. |
342 static AudioOptions GetDefaultEngineOptions() { | 342 static AudioOptions GetDefaultEngineOptions() { |
343 AudioOptions options; | 343 AudioOptions options; |
344 options.echo_cancellation.Set(true); | 344 options.echo_cancellation.Set(true); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 if (voe_wrapper_->base()->DeRegisterVoiceEngineObserver() == -1) { | 486 if (voe_wrapper_->base()->DeRegisterVoiceEngineObserver() == -1) { |
487 LOG_RTCERR0(DeRegisterVoiceEngineObserver); | 487 LOG_RTCERR0(DeRegisterVoiceEngineObserver); |
488 } | 488 } |
489 if (adm_) { | 489 if (adm_) { |
490 voe_wrapper_.reset(); | 490 voe_wrapper_.reset(); |
491 adm_->Release(); | 491 adm_->Release(); |
492 adm_ = NULL; | 492 adm_ = NULL; |
493 } | 493 } |
494 | 494 |
495 // Test to see if the media processor was deregistered properly | 495 // Test to see if the media processor was deregistered properly |
496 DCHECK(SignalRxMediaFrame.is_empty()); | 496 RTC_DCHECK(SignalRxMediaFrame.is_empty()); |
497 DCHECK(SignalTxMediaFrame.is_empty()); | 497 RTC_DCHECK(SignalTxMediaFrame.is_empty()); |
498 | 498 |
499 tracing_->SetTraceCallback(NULL); | 499 tracing_->SetTraceCallback(NULL); |
500 } | 500 } |
501 | 501 |
502 bool WebRtcVoiceEngine::Init(rtc::Thread* worker_thread) { | 502 bool WebRtcVoiceEngine::Init(rtc::Thread* worker_thread) { |
503 DCHECK(worker_thread == rtc::Thread::Current()); | 503 RTC_DCHECK(worker_thread == rtc::Thread::Current()); |
504 LOG(LS_INFO) << "WebRtcVoiceEngine::Init"; | 504 LOG(LS_INFO) << "WebRtcVoiceEngine::Init"; |
505 bool res = InitInternal(); | 505 bool res = InitInternal(); |
506 if (res) { | 506 if (res) { |
507 LOG(LS_INFO) << "WebRtcVoiceEngine::Init Done!"; | 507 LOG(LS_INFO) << "WebRtcVoiceEngine::Init Done!"; |
508 } else { | 508 } else { |
509 LOG(LS_ERROR) << "WebRtcVoiceEngine::Init failed"; | 509 LOG(LS_ERROR) << "WebRtcVoiceEngine::Init failed"; |
510 Terminate(); | 510 Terminate(); |
511 } | 511 } |
512 return res; | 512 return res; |
513 } | 513 } |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 unsigned int ulevel; | 1064 unsigned int ulevel; |
1065 if (voe_wrapper_->volume()->GetSpeakerVolume(ulevel) == -1) { | 1065 if (voe_wrapper_->volume()->GetSpeakerVolume(ulevel) == -1) { |
1066 LOG_RTCERR1(GetSpeakerVolume, level); | 1066 LOG_RTCERR1(GetSpeakerVolume, level); |
1067 return false; | 1067 return false; |
1068 } | 1068 } |
1069 *level = ulevel; | 1069 *level = ulevel; |
1070 return true; | 1070 return true; |
1071 } | 1071 } |
1072 | 1072 |
1073 bool WebRtcVoiceEngine::SetOutputVolume(int level) { | 1073 bool WebRtcVoiceEngine::SetOutputVolume(int level) { |
1074 DCHECK(level >= 0 && level <= 255); | 1074 RTC_DCHECK(level >= 0 && level <= 255); |
1075 if (voe_wrapper_->volume()->SetSpeakerVolume(level) == -1) { | 1075 if (voe_wrapper_->volume()->SetSpeakerVolume(level) == -1) { |
1076 LOG_RTCERR1(SetSpeakerVolume, level); | 1076 LOG_RTCERR1(SetSpeakerVolume, level); |
1077 return false; | 1077 return false; |
1078 } | 1078 } |
1079 return true; | 1079 return true; |
1080 } | 1080 } |
1081 | 1081 |
1082 int WebRtcVoiceEngine::GetInputLevel() { | 1082 int WebRtcVoiceEngine::GetInputLevel() { |
1083 unsigned int ulevel; | 1083 unsigned int ulevel; |
1084 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? | 1084 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 } | 1297 } |
1298 } | 1298 } |
1299 | 1299 |
1300 void WebRtcVoiceEngine::CallbackOnError(int channel_num, int err_code) { | 1300 void WebRtcVoiceEngine::CallbackOnError(int channel_num, int err_code) { |
1301 rtc::CritScope lock(&channels_cs_); | 1301 rtc::CritScope lock(&channels_cs_); |
1302 WebRtcVoiceMediaChannel* channel = NULL; | 1302 WebRtcVoiceMediaChannel* channel = NULL; |
1303 uint32 ssrc = 0; | 1303 uint32 ssrc = 0; |
1304 LOG(LS_WARNING) << "VoiceEngine error " << err_code << " reported on channel " | 1304 LOG(LS_WARNING) << "VoiceEngine error " << err_code << " reported on channel " |
1305 << channel_num << "."; | 1305 << channel_num << "."; |
1306 if (FindChannelAndSsrc(channel_num, &channel, &ssrc)) { | 1306 if (FindChannelAndSsrc(channel_num, &channel, &ssrc)) { |
1307 DCHECK(channel != NULL); | 1307 RTC_DCHECK(channel != NULL); |
1308 channel->OnError(ssrc, err_code); | 1308 channel->OnError(ssrc, err_code); |
1309 } else { | 1309 } else { |
1310 LOG(LS_ERROR) << "VoiceEngine channel " << channel_num | 1310 LOG(LS_ERROR) << "VoiceEngine channel " << channel_num |
1311 << " could not be found in channel list when error reported."; | 1311 << " could not be found in channel list when error reported."; |
1312 } | 1312 } |
1313 } | 1313 } |
1314 | 1314 |
1315 bool WebRtcVoiceEngine::FindChannelAndSsrc( | 1315 bool WebRtcVoiceEngine::FindChannelAndSsrc( |
1316 int channel_num, WebRtcVoiceMediaChannel** channel, uint32* ssrc) const { | 1316 int channel_num, WebRtcVoiceMediaChannel** channel, uint32* ssrc) const { |
1317 DCHECK(channel != NULL && ssrc != NULL); | 1317 RTC_DCHECK(channel != NULL && ssrc != NULL); |
1318 | 1318 |
1319 *channel = NULL; | 1319 *channel = NULL; |
1320 *ssrc = 0; | 1320 *ssrc = 0; |
1321 // Find corresponding channel and ssrc | 1321 // Find corresponding channel and ssrc |
1322 for (WebRtcVoiceMediaChannel* ch : channels_) { | 1322 for (WebRtcVoiceMediaChannel* ch : channels_) { |
1323 DCHECK(ch != NULL); | 1323 RTC_DCHECK(ch != NULL); |
1324 if (ch->FindSsrc(channel_num, ssrc)) { | 1324 if (ch->FindSsrc(channel_num, ssrc)) { |
1325 *channel = ch; | 1325 *channel = ch; |
1326 return true; | 1326 return true; |
1327 } | 1327 } |
1328 } | 1328 } |
1329 | 1329 |
1330 return false; | 1330 return false; |
1331 } | 1331 } |
1332 | 1332 |
1333 // This method will search through the WebRtcVoiceMediaChannels and | 1333 // This method will search through the WebRtcVoiceMediaChannels and |
1334 // obtain the voice engine's channel number. | 1334 // obtain the voice engine's channel number. |
1335 bool WebRtcVoiceEngine::FindChannelNumFromSsrc( | 1335 bool WebRtcVoiceEngine::FindChannelNumFromSsrc( |
1336 uint32 ssrc, MediaProcessorDirection direction, int* channel_num) { | 1336 uint32 ssrc, MediaProcessorDirection direction, int* channel_num) { |
1337 DCHECK(channel_num != NULL); | 1337 RTC_DCHECK(channel_num != NULL); |
1338 DCHECK(direction == MPD_RX || direction == MPD_TX); | 1338 RTC_DCHECK(direction == MPD_RX || direction == MPD_TX); |
1339 | 1339 |
1340 *channel_num = -1; | 1340 *channel_num = -1; |
1341 // Find corresponding channel for ssrc. | 1341 // Find corresponding channel for ssrc. |
1342 for (const WebRtcVoiceMediaChannel* ch : channels_) { | 1342 for (const WebRtcVoiceMediaChannel* ch : channels_) { |
1343 DCHECK(ch != NULL); | 1343 RTC_DCHECK(ch != NULL); |
1344 if (direction & MPD_RX) { | 1344 if (direction & MPD_RX) { |
1345 *channel_num = ch->GetReceiveChannelNum(ssrc); | 1345 *channel_num = ch->GetReceiveChannelNum(ssrc); |
1346 } | 1346 } |
1347 if (*channel_num == -1 && (direction & MPD_TX)) { | 1347 if (*channel_num == -1 && (direction & MPD_TX)) { |
1348 *channel_num = ch->GetSendChannelNum(ssrc); | 1348 *channel_num = ch->GetSendChannelNum(ssrc); |
1349 } | 1349 } |
1350 if (*channel_num != -1) { | 1350 if (*channel_num != -1) { |
1351 return true; | 1351 return true; |
1352 } | 1352 } |
1353 } | 1353 } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 voe_audio_transport_(voe_audio_transport), | 1615 voe_audio_transport_(voe_audio_transport), |
1616 renderer_(NULL) {} | 1616 renderer_(NULL) {} |
1617 ~WebRtcVoiceChannelRenderer() override { Stop(); } | 1617 ~WebRtcVoiceChannelRenderer() override { Stop(); } |
1618 | 1618 |
1619 // Starts the rendering by setting a sink to the renderer to get data | 1619 // Starts the rendering by setting a sink to the renderer to get data |
1620 // callback. | 1620 // callback. |
1621 // This method is called on the libjingle worker thread. | 1621 // This method is called on the libjingle worker thread. |
1622 // TODO(xians): Make sure Start() is called only once. | 1622 // TODO(xians): Make sure Start() is called only once. |
1623 void Start(AudioRenderer* renderer) { | 1623 void Start(AudioRenderer* renderer) { |
1624 rtc::CritScope lock(&lock_); | 1624 rtc::CritScope lock(&lock_); |
1625 DCHECK(renderer != NULL); | 1625 RTC_DCHECK(renderer != NULL); |
1626 if (renderer_ != NULL) { | 1626 if (renderer_ != NULL) { |
1627 DCHECK(renderer_ == renderer); | 1627 RTC_DCHECK(renderer_ == renderer); |
1628 return; | 1628 return; |
1629 } | 1629 } |
1630 | 1630 |
1631 // TODO(xians): Remove AddChannel() call after Chrome turns on APM | 1631 // TODO(xians): Remove AddChannel() call after Chrome turns on APM |
1632 // in getUserMedia by default. | 1632 // in getUserMedia by default. |
1633 renderer->AddChannel(channel_); | 1633 renderer->AddChannel(channel_); |
1634 renderer->SetSink(this); | 1634 renderer->SetSink(this); |
1635 renderer_ = renderer; | 1635 renderer_ = renderer; |
1636 } | 1636 } |
1637 | 1637 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1701 nack_enabled_(false), | 1701 nack_enabled_(false), |
1702 playout_(false), | 1702 playout_(false), |
1703 typing_noise_detected_(false), | 1703 typing_noise_detected_(false), |
1704 desired_send_(SEND_NOTHING), | 1704 desired_send_(SEND_NOTHING), |
1705 send_(SEND_NOTHING), | 1705 send_(SEND_NOTHING), |
1706 call_(call), | 1706 call_(call), |
1707 default_receive_ssrc_(0) { | 1707 default_receive_ssrc_(0) { |
1708 engine->RegisterChannel(this); | 1708 engine->RegisterChannel(this); |
1709 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " | 1709 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " |
1710 << voe_channel(); | 1710 << voe_channel(); |
1711 DCHECK(nullptr != call); | 1711 RTC_DCHECK(nullptr != call); |
1712 ConfigureSendChannel(voe_channel()); | 1712 ConfigureSendChannel(voe_channel()); |
1713 } | 1713 } |
1714 | 1714 |
1715 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { | 1715 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { |
1716 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel " | 1716 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel " |
1717 << voe_channel(); | 1717 << voe_channel(); |
1718 | 1718 |
1719 // Remove any remaining send streams, the default channel will be deleted | 1719 // Remove any remaining send streams, the default channel will be deleted |
1720 // later. | 1720 // later. |
1721 while (!send_channels_.empty()) | 1721 while (!send_channels_.empty()) |
1722 RemoveSendStream(send_channels_.begin()->first); | 1722 RemoveSendStream(send_channels_.begin()->first); |
1723 | 1723 |
1724 // Unregister ourselves from the engine. | 1724 // Unregister ourselves from the engine. |
1725 engine()->UnregisterChannel(this); | 1725 engine()->UnregisterChannel(this); |
1726 // Remove any remaining streams. | 1726 // Remove any remaining streams. |
1727 while (!receive_channels_.empty()) { | 1727 while (!receive_channels_.empty()) { |
1728 RemoveRecvStream(receive_channels_.begin()->first); | 1728 RemoveRecvStream(receive_channels_.begin()->first); |
1729 } | 1729 } |
1730 DCHECK(receive_streams_.empty()); | 1730 RTC_DCHECK(receive_streams_.empty()); |
1731 | 1731 |
1732 // Delete the default channel. | 1732 // Delete the default channel. |
1733 DeleteChannel(voe_channel()); | 1733 DeleteChannel(voe_channel()); |
1734 } | 1734 } |
1735 | 1735 |
1736 bool WebRtcVoiceMediaChannel::SetSendParameters( | 1736 bool WebRtcVoiceMediaChannel::SetSendParameters( |
1737 const AudioSendParameters& params) { | 1737 const AudioSendParameters& params) { |
1738 // TODO(pthatcher): Refactor this to be more clean now that we have | 1738 // TODO(pthatcher): Refactor this to be more clean now that we have |
1739 // all the information at once. | 1739 // all the information at once. |
1740 return (SetSendCodecs(params.codecs) && | 1740 return (SetSendCodecs(params.codecs) && |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2358 if (engine()->voe()->base()->StartSend(channel) == -1) { | 2358 if (engine()->voe()->base()->StartSend(channel) == -1) { |
2359 LOG_RTCERR1(StartSend, channel); | 2359 LOG_RTCERR1(StartSend, channel); |
2360 return false; | 2360 return false; |
2361 } | 2361 } |
2362 if (engine()->voe()->file() && | 2362 if (engine()->voe()->file() && |
2363 engine()->voe()->file()->StopPlayingFileAsMicrophone(channel) == -1) { | 2363 engine()->voe()->file()->StopPlayingFileAsMicrophone(channel) == -1) { |
2364 LOG_RTCERR1(StopPlayingFileAsMicrophone, channel); | 2364 LOG_RTCERR1(StopPlayingFileAsMicrophone, channel); |
2365 return false; | 2365 return false; |
2366 } | 2366 } |
2367 } else { // SEND_NOTHING | 2367 } else { // SEND_NOTHING |
2368 DCHECK(send == SEND_NOTHING); | 2368 RTC_DCHECK(send == SEND_NOTHING); |
2369 if (engine()->voe()->base()->StopSend(channel) == -1) { | 2369 if (engine()->voe()->base()->StopSend(channel) == -1) { |
2370 LOG_RTCERR1(StopSend, channel); | 2370 LOG_RTCERR1(StopSend, channel); |
2371 return false; | 2371 return false; |
2372 } | 2372 } |
2373 } | 2373 } |
2374 | 2374 |
2375 return true; | 2375 return true; |
2376 } | 2376 } |
2377 | 2377 |
2378 bool WebRtcVoiceMediaChannel::SetAudioSend(uint32 ssrc, bool mute, | 2378 bool WebRtcVoiceMediaChannel::SetAudioSend(uint32 ssrc, bool mute, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 return false; | 2525 return false; |
2526 } | 2526 } |
2527 | 2527 |
2528 if (send_channels_.empty()) | 2528 if (send_channels_.empty()) |
2529 ChangeSend(SEND_NOTHING); | 2529 ChangeSend(SEND_NOTHING); |
2530 | 2530 |
2531 return true; | 2531 return true; |
2532 } | 2532 } |
2533 | 2533 |
2534 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { | 2534 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { |
2535 DCHECK(thread_checker_.CalledOnValidThread()); | 2535 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2536 rtc::CritScope lock(&receive_channels_cs_); | 2536 rtc::CritScope lock(&receive_channels_cs_); |
2537 | 2537 |
2538 if (!VERIFY(sp.ssrcs.size() == 1)) | 2538 if (!VERIFY(sp.ssrcs.size() == 1)) |
2539 return false; | 2539 return false; |
2540 uint32 ssrc = sp.first_ssrc(); | 2540 uint32 ssrc = sp.first_ssrc(); |
2541 | 2541 |
2542 if (ssrc == 0) { | 2542 if (ssrc == 0) { |
2543 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; | 2543 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; |
2544 return false; | 2544 return false; |
2545 } | 2545 } |
2546 | 2546 |
2547 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 2547 if (receive_channels_.find(ssrc) != receive_channels_.end()) { |
2548 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 2548 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; |
2549 return false; | 2549 return false; |
2550 } | 2550 } |
2551 | 2551 |
2552 DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); | 2552 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end()); |
2553 | 2553 |
2554 // Reuse default channel for recv stream in non-conference mode call | 2554 // Reuse default channel for recv stream in non-conference mode call |
2555 // when the default channel is not being used. | 2555 // when the default channel is not being used. |
2556 webrtc::AudioTransport* audio_transport = | 2556 webrtc::AudioTransport* audio_transport = |
2557 engine()->voe()->base()->audio_transport(); | 2557 engine()->voe()->base()->audio_transport(); |
2558 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | 2558 if (!InConferenceMode() && default_receive_ssrc_ == 0) { |
2559 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | 2559 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; |
2560 default_receive_ssrc_ = ssrc; | 2560 default_receive_ssrc_ = ssrc; |
2561 WebRtcVoiceChannelRenderer* channel_renderer = | 2561 WebRtcVoiceChannelRenderer* channel_renderer = |
2562 new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport); | 2562 new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2655 | 2655 |
2656 // Set RTP header extension for the new channel. | 2656 // Set RTP header extension for the new channel. |
2657 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { | 2657 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { |
2658 return false; | 2658 return false; |
2659 } | 2659 } |
2660 | 2660 |
2661 return SetPlayout(channel, playout_); | 2661 return SetPlayout(channel, playout_); |
2662 } | 2662 } |
2663 | 2663 |
2664 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32 ssrc) { | 2664 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32 ssrc) { |
2665 DCHECK(thread_checker_.CalledOnValidThread()); | 2665 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2666 rtc::CritScope lock(&receive_channels_cs_); | 2666 rtc::CritScope lock(&receive_channels_cs_); |
2667 ChannelMap::iterator it = receive_channels_.find(ssrc); | 2667 ChannelMap::iterator it = receive_channels_.find(ssrc); |
2668 if (it == receive_channels_.end()) { | 2668 if (it == receive_channels_.end()) { |
2669 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 2669 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc |
2670 << " which doesn't exist."; | 2670 << " which doesn't exist."; |
2671 return false; | 2671 return false; |
2672 } | 2672 } |
2673 | 2673 |
2674 RemoveAudioReceiveStream(ssrc); | 2674 RemoveAudioReceiveStream(ssrc); |
2675 receive_stream_params_.erase(ssrc); | 2675 receive_stream_params_.erase(ssrc); |
2676 | 2676 |
2677 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this | 2677 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this |
2678 // will disconnect the audio renderer with the receive channel. | 2678 // will disconnect the audio renderer with the receive channel. |
2679 // Cache the channel before the deletion. | 2679 // Cache the channel before the deletion. |
2680 const int channel = it->second->channel(); | 2680 const int channel = it->second->channel(); |
2681 delete it->second; | 2681 delete it->second; |
2682 receive_channels_.erase(it); | 2682 receive_channels_.erase(it); |
2683 | 2683 |
2684 if (ssrc == default_receive_ssrc_) { | 2684 if (ssrc == default_receive_ssrc_) { |
2685 DCHECK(IsDefaultChannel(channel)); | 2685 RTC_DCHECK(IsDefaultChannel(channel)); |
2686 // Recycle the default channel is for recv stream. | 2686 // Recycle the default channel is for recv stream. |
2687 if (playout_) | 2687 if (playout_) |
2688 SetPlayout(voe_channel(), false); | 2688 SetPlayout(voe_channel(), false); |
2689 | 2689 |
2690 default_receive_ssrc_ = 0; | 2690 default_receive_ssrc_ = 0; |
2691 return true; | 2691 return true; |
2692 } | 2692 } |
2693 | 2693 |
2694 LOG(LS_INFO) << "Removing audio stream " << ssrc | 2694 LOG(LS_INFO) << "Removing audio stream " << ssrc |
2695 << " with VoiceEngine channel #" << channel << "."; | 2695 << " with VoiceEngine channel #" << channel << "."; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2956 LOG_RTCERR2(PlayDtmfTone, event, duration); | 2956 LOG_RTCERR2(PlayDtmfTone, event, duration); |
2957 return false; | 2957 return false; |
2958 } | 2958 } |
2959 } | 2959 } |
2960 | 2960 |
2961 return true; | 2961 return true; |
2962 } | 2962 } |
2963 | 2963 |
2964 void WebRtcVoiceMediaChannel::OnPacketReceived( | 2964 void WebRtcVoiceMediaChannel::OnPacketReceived( |
2965 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 2965 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
2966 DCHECK(thread_checker_.CalledOnValidThread()); | 2966 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
2967 | 2967 |
2968 // Forward packet to Call as well. | 2968 // Forward packet to Call as well. |
2969 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2969 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2970 packet_time.not_before); | 2970 packet_time.not_before); |
2971 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2971 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2972 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2972 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
2973 webrtc_packet_time); | 2973 webrtc_packet_time); |
2974 | 2974 |
2975 // Pick which channel to send this packet to. If this packet doesn't match | 2975 // Pick which channel to send this packet to. If this packet doesn't match |
2976 // any multiplexed streams, just send it to the default channel. Otherwise, | 2976 // any multiplexed streams, just send it to the default channel. Otherwise, |
(...skipping 21 matching lines...) Expand all Loading... |
2998 } | 2998 } |
2999 | 2999 |
3000 // Pass it off to the decoder. | 3000 // Pass it off to the decoder. |
3001 engine()->voe()->network()->ReceivedRTPPacket( | 3001 engine()->voe()->network()->ReceivedRTPPacket( |
3002 which_channel, packet->data(), packet->size(), | 3002 which_channel, packet->data(), packet->size(), |
3003 webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); | 3003 webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); |
3004 } | 3004 } |
3005 | 3005 |
3006 void WebRtcVoiceMediaChannel::OnRtcpReceived( | 3006 void WebRtcVoiceMediaChannel::OnRtcpReceived( |
3007 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 3007 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { |
3008 DCHECK(thread_checker_.CalledOnValidThread()); | 3008 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3009 | 3009 |
3010 // Forward packet to Call as well. | 3010 // Forward packet to Call as well. |
3011 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 3011 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
3012 packet_time.not_before); | 3012 packet_time.not_before); |
3013 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 3013 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
3014 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 3014 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
3015 webrtc_packet_time); | 3015 webrtc_packet_time); |
3016 | 3016 |
3017 // Sending channels need all RTCP packets with feedback information. | 3017 // Sending channels need all RTCP packets with feedback information. |
3018 // Even sender reports can contain attached report blocks. | 3018 // Even sender reports can contain attached report blocks. |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3318 GetSpeechOutputLevelFullRange(ch_id, level) != -1) ? level : -1; | 3318 GetSpeechOutputLevelFullRange(ch_id, level) != -1) ? level : -1; |
3319 info->receivers.push_back(rinfo); | 3319 info->receivers.push_back(rinfo); |
3320 } | 3320 } |
3321 } | 3321 } |
3322 | 3322 |
3323 return true; | 3323 return true; |
3324 } | 3324 } |
3325 | 3325 |
3326 void WebRtcVoiceMediaChannel::GetLastMediaError( | 3326 void WebRtcVoiceMediaChannel::GetLastMediaError( |
3327 uint32* ssrc, VoiceMediaChannel::Error* error) { | 3327 uint32* ssrc, VoiceMediaChannel::Error* error) { |
3328 DCHECK(ssrc != NULL); | 3328 RTC_DCHECK(ssrc != NULL); |
3329 DCHECK(error != NULL); | 3329 RTC_DCHECK(error != NULL); |
3330 FindSsrc(voe_channel(), ssrc); | 3330 FindSsrc(voe_channel(), ssrc); |
3331 *error = WebRtcErrorToChannelError(GetLastEngineError()); | 3331 *error = WebRtcErrorToChannelError(GetLastEngineError()); |
3332 } | 3332 } |
3333 | 3333 |
3334 bool WebRtcVoiceMediaChannel::FindSsrc(int channel_num, uint32* ssrc) { | 3334 bool WebRtcVoiceMediaChannel::FindSsrc(int channel_num, uint32* ssrc) { |
3335 rtc::CritScope lock(&receive_channels_cs_); | 3335 rtc::CritScope lock(&receive_channels_cs_); |
3336 DCHECK(ssrc != NULL); | 3336 RTC_DCHECK(ssrc != NULL); |
3337 if (channel_num == -1 && send_ != SEND_NOTHING) { | 3337 if (channel_num == -1 && send_ != SEND_NOTHING) { |
3338 // Sometimes the VoiceEngine core will throw error with channel_num = -1. | 3338 // Sometimes the VoiceEngine core will throw error with channel_num = -1. |
3339 // This means the error is not limited to a specific channel. Signal the | 3339 // This means the error is not limited to a specific channel. Signal the |
3340 // message using ssrc=0. If the current channel is sending, use this | 3340 // message using ssrc=0. If the current channel is sending, use this |
3341 // channel for sending the message. | 3341 // channel for sending the message. |
3342 *ssrc = 0; | 3342 *ssrc = 0; |
3343 return true; | 3343 return true; |
3344 } else { | 3344 } else { |
3345 // Check whether this is a sending channel. | 3345 // Check whether this is a sending channel. |
3346 for (const auto& ch : send_channels_) { | 3346 for (const auto& ch : send_channels_) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3537 uri = extension->uri; | 3537 uri = extension->uri; |
3538 } | 3538 } |
3539 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { | 3539 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { |
3540 LOG_RTCERR4(*setter, uri, channel_id, enable, id); | 3540 LOG_RTCERR4(*setter, uri, channel_id, enable, id); |
3541 return false; | 3541 return false; |
3542 } | 3542 } |
3543 return true; | 3543 return true; |
3544 } | 3544 } |
3545 | 3545 |
3546 void WebRtcVoiceMediaChannel::RecreateAudioReceiveStreams() { | 3546 void WebRtcVoiceMediaChannel::RecreateAudioReceiveStreams() { |
3547 DCHECK(thread_checker_.CalledOnValidThread()); | 3547 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3548 for (const auto& it : receive_channels_) { | 3548 for (const auto& it : receive_channels_) { |
3549 RemoveAudioReceiveStream(it.first); | 3549 RemoveAudioReceiveStream(it.first); |
3550 } | 3550 } |
3551 for (const auto& it : receive_channels_) { | 3551 for (const auto& it : receive_channels_) { |
3552 AddAudioReceiveStream(it.first); | 3552 AddAudioReceiveStream(it.first); |
3553 } | 3553 } |
3554 } | 3554 } |
3555 | 3555 |
3556 void WebRtcVoiceMediaChannel::AddAudioReceiveStream(uint32 ssrc) { | 3556 void WebRtcVoiceMediaChannel::AddAudioReceiveStream(uint32 ssrc) { |
3557 DCHECK(thread_checker_.CalledOnValidThread()); | 3557 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3558 WebRtcVoiceChannelRenderer* channel = receive_channels_[ssrc]; | 3558 WebRtcVoiceChannelRenderer* channel = receive_channels_[ssrc]; |
3559 DCHECK(channel != nullptr); | 3559 RTC_DCHECK(channel != nullptr); |
3560 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); | 3560 RTC_DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); |
3561 webrtc::AudioReceiveStream::Config config; | 3561 webrtc::AudioReceiveStream::Config config; |
3562 config.rtp.remote_ssrc = ssrc; | 3562 config.rtp.remote_ssrc = ssrc; |
3563 // Only add RTP extensions if we support combined A/V BWE. | 3563 // Only add RTP extensions if we support combined A/V BWE. |
3564 config.rtp.extensions = recv_rtp_extensions_; | 3564 config.rtp.extensions = recv_rtp_extensions_; |
3565 config.combined_audio_video_bwe = | 3565 config.combined_audio_video_bwe = |
3566 options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false); | 3566 options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false); |
3567 config.voe_channel_id = channel->channel(); | 3567 config.voe_channel_id = channel->channel(); |
3568 config.sync_group = receive_stream_params_[ssrc].sync_label; | 3568 config.sync_group = receive_stream_params_[ssrc].sync_label; |
3569 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); | 3569 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); |
3570 receive_streams_.insert(std::make_pair(ssrc, s)); | 3570 receive_streams_.insert(std::make_pair(ssrc, s)); |
3571 } | 3571 } |
3572 | 3572 |
3573 void WebRtcVoiceMediaChannel::RemoveAudioReceiveStream(uint32 ssrc) { | 3573 void WebRtcVoiceMediaChannel::RemoveAudioReceiveStream(uint32 ssrc) { |
3574 DCHECK(thread_checker_.CalledOnValidThread()); | 3574 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
3575 auto stream_it = receive_streams_.find(ssrc); | 3575 auto stream_it = receive_streams_.find(ssrc); |
3576 if (stream_it != receive_streams_.end()) { | 3576 if (stream_it != receive_streams_.end()) { |
3577 call_->DestroyAudioReceiveStream(stream_it->second); | 3577 call_->DestroyAudioReceiveStream(stream_it->second); |
3578 receive_streams_.erase(stream_it); | 3578 receive_streams_.erase(stream_it); |
3579 } | 3579 } |
3580 } | 3580 } |
3581 | 3581 |
3582 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( | 3582 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( |
3583 const std::vector<AudioCodec>& new_codecs) { | 3583 const std::vector<AudioCodec>& new_codecs) { |
3584 for (const AudioCodec& codec : new_codecs) { | 3584 for (const AudioCodec& codec : new_codecs) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3625 | 3625 |
3626 int WebRtcSoundclipStream::Rewind() { | 3626 int WebRtcSoundclipStream::Rewind() { |
3627 mem_.Rewind(); | 3627 mem_.Rewind(); |
3628 // Return -1 to keep VoiceEngine from looping. | 3628 // Return -1 to keep VoiceEngine from looping. |
3629 return (loop_) ? 0 : -1; | 3629 return (loop_) ? 0 : -1; |
3630 } | 3630 } |
3631 | 3631 |
3632 } // namespace cricket | 3632 } // namespace cricket |
3633 | 3633 |
3634 #endif // HAVE_WEBRTC_VOICE | 3634 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |