Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: talk/media/webrtc/webrtcvoiceengine.cc

Issue 1454073002: Move some receive stream configuration into webrtc::AudioReceiveStream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 voe_codec.rate = (in.bitrate > 0) ? in.bitrate : -1; 1128 voe_codec.rate = (in.bitrate > 0) ? in.bitrate : -1;
1129 } 1129 }
1130 *out = voe_codec; 1130 *out = voe_codec;
1131 } 1131 }
1132 return true; 1132 return true;
1133 } 1133 }
1134 } 1134 }
1135 } 1135 }
1136 return false; 1136 return false;
1137 } 1137 }
1138
1138 const std::vector<RtpHeaderExtension>& 1139 const std::vector<RtpHeaderExtension>&
1139 WebRtcVoiceEngine::rtp_header_extensions() const { 1140 WebRtcVoiceEngine::rtp_header_extensions() const {
1140 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); 1141 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread());
1141 return rtp_header_extensions_; 1142 return rtp_header_extensions_;
1142 } 1143 }
1143 1144
1144 void WebRtcVoiceEngine::SetLogging(int min_sev, const char* filter) { 1145 void WebRtcVoiceEngine::SetLogging(int min_sev, const char* filter) {
1145 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1146 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1146 // if min_sev == -1, we keep the current log level. 1147 // if min_sev == -1, we keep the current log level.
1147 if (min_sev >= 0) { 1148 if (min_sev >= 0) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 return voe_wrapper_->base()->CreateChannel(voe_config_); 1347 return voe_wrapper_->base()->CreateChannel(voe_config_);
1347 } 1348 }
1348 1349
1349 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream 1350 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
1350 : public AudioRenderer::Sink { 1351 : public AudioRenderer::Sink {
1351 public: 1352 public:
1352 WebRtcAudioSendStream(int ch, webrtc::AudioTransport* voe_audio_transport, 1353 WebRtcAudioSendStream(int ch, webrtc::AudioTransport* voe_audio_transport,
1353 uint32_t ssrc, const std::string& c_name, 1354 uint32_t ssrc, const std::string& c_name,
1354 const std::vector<webrtc::RtpExtension>& extensions, 1355 const std::vector<webrtc::RtpExtension>& extensions,
1355 webrtc::Call* call) 1356 webrtc::Call* call)
1356 : channel_(ch), 1357 : voe_audio_transport_(voe_audio_transport),
1357 voe_audio_transport_(voe_audio_transport),
1358 call_(call), 1358 call_(call),
1359 config_(nullptr) { 1359 config_(nullptr) {
1360 RTC_DCHECK_GE(ch, 0); 1360 RTC_DCHECK_GE(ch, 0);
1361 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: 1361 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore:
1362 // RTC_DCHECK(voe_audio_transport); 1362 // RTC_DCHECK(voe_audio_transport);
1363 RTC_DCHECK(call); 1363 RTC_DCHECK(call);
1364 audio_capture_thread_checker_.DetachFromThread(); 1364 audio_capture_thread_checker_.DetachFromThread();
1365 config_.rtp.ssrc = ssrc; 1365 config_.rtp.ssrc = ssrc;
1366 config_.rtp.c_name = c_name; 1366 config_.rtp.c_name = c_name;
1367 config_.voe_channel_id = ch; 1367 config_.voe_channel_id = ch;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 // AudioRenderer::Sink implementation. 1422 // AudioRenderer::Sink implementation.
1423 // This method is called on the audio thread. 1423 // This method is called on the audio thread.
1424 void OnData(const void* audio_data, 1424 void OnData(const void* audio_data,
1425 int bits_per_sample, 1425 int bits_per_sample,
1426 int sample_rate, 1426 int sample_rate,
1427 int number_of_channels, 1427 int number_of_channels,
1428 size_t number_of_frames) override { 1428 size_t number_of_frames) override {
1429 RTC_DCHECK(!worker_thread_checker_.CalledOnValidThread()); 1429 RTC_DCHECK(!worker_thread_checker_.CalledOnValidThread());
1430 RTC_DCHECK(audio_capture_thread_checker_.CalledOnValidThread()); 1430 RTC_DCHECK(audio_capture_thread_checker_.CalledOnValidThread());
1431 RTC_DCHECK(voe_audio_transport_); 1431 RTC_DCHECK(voe_audio_transport_);
1432 voe_audio_transport_->OnData(channel_, 1432 voe_audio_transport_->OnData(config_.voe_channel_id,
1433 audio_data, 1433 audio_data,
1434 bits_per_sample, 1434 bits_per_sample,
1435 sample_rate, 1435 sample_rate,
1436 number_of_channels, 1436 number_of_channels,
1437 number_of_frames); 1437 number_of_frames);
1438 } 1438 }
1439 1439
1440 // Callback from the |renderer_| when it is going away. In case Start() has 1440 // Callback from the |renderer_| when it is going away. In case Start() has
1441 // never been called, this callback won't be triggered. 1441 // never been called, this callback won't be triggered.
1442 void OnClose() override { 1442 void OnClose() override {
1443 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1443 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1444 // Set |renderer_| to nullptr to make sure no more callback will get into 1444 // Set |renderer_| to nullptr to make sure no more callback will get into
1445 // the renderer. 1445 // the renderer.
1446 renderer_ = nullptr; 1446 renderer_ = nullptr;
1447 } 1447 }
1448 1448
1449 // Accessor to the VoE channel ID. 1449 // Accessor to the VoE channel ID.
1450 int channel() const { 1450 int channel() const {
1451 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1451 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1452 return channel_; 1452 return config_.voe_channel_id;
1453 } 1453 }
1454 1454
1455 private: 1455 private:
1456 rtc::ThreadChecker worker_thread_checker_; 1456 rtc::ThreadChecker worker_thread_checker_;
1457 rtc::ThreadChecker audio_capture_thread_checker_; 1457 rtc::ThreadChecker audio_capture_thread_checker_;
1458 const int channel_ = -1;
1459 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; 1458 webrtc::AudioTransport* const voe_audio_transport_ = nullptr;
1460 webrtc::Call* call_ = nullptr; 1459 webrtc::Call* call_ = nullptr;
1461 webrtc::AudioSendStream::Config config_; 1460 webrtc::AudioSendStream::Config config_;
1462 // The stream is owned by WebRtcAudioSendStream and may be reallocated if 1461 // The stream is owned by WebRtcAudioSendStream and may be reallocated if
1463 // configuration changes. 1462 // configuration changes.
1464 webrtc::AudioSendStream* stream_ = nullptr; 1463 webrtc::AudioSendStream* stream_ = nullptr;
1465 1464
1466 // Raw pointer to AudioRenderer owned by LocalAudioTrackHandler. 1465 // Raw pointer to AudioRenderer owned by LocalAudioTrackHandler.
1467 // PeerConnection will make sure invalidating the pointer before the object 1466 // PeerConnection will make sure invalidating the pointer before the object
1468 // goes away. 1467 // goes away.
1469 AudioRenderer* renderer_ = nullptr; 1468 AudioRenderer* renderer_ = nullptr;
1470 1469
1471 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream); 1470 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream);
1472 }; 1471 };
1473 1472
1474 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream { 1473 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream {
1475 public: 1474 public:
1476 explicit WebRtcAudioReceiveStream(int voe_channel_id) 1475 WebRtcAudioReceiveStream(int ch, uint32_t remote_ssrc, uint32_t local_ssrc,
1477 : channel_(voe_channel_id) {} 1476 bool use_combined_bwe, const std::string& sync_group,
1477 const std::vector<webrtc::RtpExtension>& extensions,
1478 webrtc::Call* call)
1479 : call_(call),
1480 config_() {
1481 RTC_DCHECK_GE(ch, 0);
1482 RTC_DCHECK(call);
1483 config_.rtp.remote_ssrc = remote_ssrc;
1484 config_.rtp.local_ssrc = local_ssrc;
1485 config_.voe_channel_id = ch;
1486 config_.sync_group = sync_group;
1487 RecreateAudioReceiveStream(use_combined_bwe, extensions);
1488 }
1478 1489
1479 int channel() { return channel_; } 1490 ~WebRtcAudioReceiveStream() {
1491 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1492 call_->DestroyAudioReceiveStream(stream_);
1493 }
1494
1495 void RecreateAudioReceiveStream(
1496 const std::vector<webrtc::RtpExtension>& extensions) {
1497 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1498 RecreateAudioReceiveStream(config_.combined_audio_video_bwe, extensions);
1499 }
1500 void RecreateAudioReceiveStream(bool use_combined_bwe) {
1501 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1502 RecreateAudioReceiveStream(use_combined_bwe, config_.rtp.extensions);
1503 }
1504
1505 webrtc::AudioReceiveStream::Stats GetStats() const {
1506 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1507 RTC_DCHECK(stream_);
1508 return stream_->GetStats();
1509 }
1510
1511 int channel() const {
1512 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1513 return config_.voe_channel_id;
1514 }
1480 1515
1481 private: 1516 private:
1482 int channel_; 1517 void RecreateAudioReceiveStream(bool use_combined_bwe,
1518 const std::vector<webrtc::RtpExtension>& extensions) {
1519 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1520 if (stream_) {
1521 call_->DestroyAudioReceiveStream(stream_);
1522 stream_ = nullptr;
1523 }
1524 config_.rtp.extensions = extensions;
1525 config_.combined_audio_video_bwe = use_combined_bwe;
1526 RTC_DCHECK(!stream_);
1527 stream_ = call_->CreateAudioReceiveStream(config_);
1528 RTC_CHECK(stream_);
1529 }
1530
1531 rtc::ThreadChecker worker_thread_checker_;
1532 webrtc::Call* call_ = nullptr;
1533 webrtc::AudioReceiveStream::Config config_;
1534 // The stream is owned by WebRtcAudioReceiveStream and may be reallocated if
1535 // configuration changes.
1536 webrtc::AudioReceiveStream* stream_ = nullptr;
1483 1537
1484 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioReceiveStream); 1538 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioReceiveStream);
1485 }; 1539 };
1486 1540
1487 // WebRtcVoiceMediaChannel
1488 WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, 1541 WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine,
1489 const AudioOptions& options, 1542 const AudioOptions& options,
1490 webrtc::Call* call) 1543 webrtc::Call* call)
1491 : engine_(engine), call_(call) { 1544 : engine_(engine), call_(call) {
1492 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel"; 1545 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel";
1493 RTC_DCHECK(call); 1546 RTC_DCHECK(call);
1494 engine->RegisterChannel(this); 1547 engine->RegisterChannel(this);
1495 SetOptions(options); 1548 SetOptions(options);
1496 } 1549 }
1497 1550
1498 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { 1551 WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() {
1499 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1552 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1500 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel"; 1553 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel";
1501
1502 // Remove any remaining send streams.
1503 while (!send_streams_.empty()) { 1554 while (!send_streams_.empty()) {
1504 RemoveSendStream(send_streams_.begin()->first); 1555 RemoveSendStream(send_streams_.begin()->first);
1505 } 1556 }
1506 1557 while (!recv_streams_.empty()) {
1507 // Remove any remaining receive streams. 1558 RemoveRecvStream(recv_streams_.begin()->first);
hlundin-webrtc 2015/11/20 12:59:21 This is slightly backwards by design. Iterate thro
the sun 2015/11/20 14:24:09 Thanks, we'll get to it, eventually... Added TODO.
1508 while (!receive_channels_.empty()) {
1509 RemoveRecvStream(receive_channels_.begin()->first);
1510 } 1559 }
1511 RTC_DCHECK(receive_streams_.empty());
1512
1513 // Unregister ourselves from the engine.
1514 engine()->UnregisterChannel(this); 1560 engine()->UnregisterChannel(this);
1515 } 1561 }
1516 1562
1517 bool WebRtcVoiceMediaChannel::SetSendParameters( 1563 bool WebRtcVoiceMediaChannel::SetSendParameters(
1518 const AudioSendParameters& params) { 1564 const AudioSendParameters& params) {
1519 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1565 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1520 // TODO(pthatcher): Refactor this to be more clean now that we have 1566 // TODO(pthatcher): Refactor this to be more clean now that we have
1521 // all the information at once. 1567 // all the information at once.
1522 1568
1523 if (!SetSendCodecs(params.codecs)) { 1569 if (!SetSendCodecs(params.codecs)) {
(...skipping 13 matching lines...) Expand all
1537 return false; 1583 return false;
1538 } 1584 }
1539 return SetOptions(params.options); 1585 return SetOptions(params.options);
1540 } 1586 }
1541 1587
1542 bool WebRtcVoiceMediaChannel::SetRecvParameters( 1588 bool WebRtcVoiceMediaChannel::SetRecvParameters(
1543 const AudioRecvParameters& params) { 1589 const AudioRecvParameters& params) {
1544 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1590 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1545 // TODO(pthatcher): Refactor this to be more clean now that we have 1591 // TODO(pthatcher): Refactor this to be more clean now that we have
1546 // all the information at once. 1592 // all the information at once.
1547 return (SetRecvCodecs(params.codecs) && 1593
1548 SetRecvRtpHeaderExtensions(params.extensions)); 1594 if (!SetRecvCodecs(params.codecs)) {
1595 return false;
1596 }
1597
1598 std::vector<webrtc::RtpExtension> recv_rtp_extensions =
1599 FindAudioRtpHeaderExtensions(params.extensions);
1600 if (recv_rtp_extensions_ != recv_rtp_extensions) {
1601 recv_rtp_extensions_.swap(recv_rtp_extensions);
1602 for (auto& it : recv_streams_) {
1603 it.second->RecreateAudioReceiveStream(recv_rtp_extensions_);
1604 }
1605 }
1606
1607 return true;
1549 } 1608 }
1550 1609
1551 bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { 1610 bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) {
1552 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1611 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1553 LOG(LS_INFO) << "Setting voice channel options: " 1612 LOG(LS_INFO) << "Setting voice channel options: "
1554 << options.ToString(); 1613 << options.ToString();
1555 1614
1556 // Check if DSCP value is changed from previous. 1615 // Check if DSCP value is changed from previous.
1557 bool dscp_option_changed = (options_.dscp != options.dscp); 1616 bool dscp_option_changed = (options_.dscp != options.dscp);
1558 1617
(...skipping 13 matching lines...) Expand all
1572 if (dscp_option_changed) { 1631 if (dscp_option_changed) {
1573 rtc::DiffServCodePoint dscp = rtc::DSCP_DEFAULT; 1632 rtc::DiffServCodePoint dscp = rtc::DSCP_DEFAULT;
1574 if (options_.dscp.value_or(false)) 1633 if (options_.dscp.value_or(false))
1575 dscp = kAudioDscpValue; 1634 dscp = kAudioDscpValue;
1576 if (MediaChannel::SetDscp(dscp) != 0) { 1635 if (MediaChannel::SetDscp(dscp) != 0) {
1577 LOG(LS_WARNING) << "Failed to set DSCP settings for audio channel"; 1636 LOG(LS_WARNING) << "Failed to set DSCP settings for audio channel";
1578 } 1637 }
1579 } 1638 }
1580 1639
1581 // TODO(solenberg): Don't recreate unless options changed. 1640 // TODO(solenberg): Don't recreate unless options changed.
1582 RecreateAudioReceiveStreams(); 1641 for (auto& it : recv_streams_) {
1642 it.second->RecreateAudioReceiveStream(
1643 options_.combined_audio_video_bwe.value_or(false));
1644 }
1583 1645
1584 LOG(LS_INFO) << "Set voice channel options. Current options: " 1646 LOG(LS_INFO) << "Set voice channel options. Current options: "
1585 << options_.ToString(); 1647 << options_.ToString();
1586 return true; 1648 return true;
1587 } 1649 }
1588 1650
1589 bool WebRtcVoiceMediaChannel::SetRecvCodecs( 1651 bool WebRtcVoiceMediaChannel::SetRecvCodecs(
1590 const std::vector<AudioCodec>& codecs) { 1652 const std::vector<AudioCodec>& codecs) {
1591 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1653 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1592 1654
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 1920
1859 // Cache the codecs in order to configure the channel created later. 1921 // Cache the codecs in order to configure the channel created later.
1860 send_codecs_ = codecs; 1922 send_codecs_ = codecs;
1861 for (const auto& ch : send_streams_) { 1923 for (const auto& ch : send_streams_) {
1862 if (!SetSendCodecs(ch.second->channel(), codecs)) { 1924 if (!SetSendCodecs(ch.second->channel(), codecs)) {
1863 return false; 1925 return false;
1864 } 1926 }
1865 } 1927 }
1866 1928
1867 // Set nack status on receive channels and update |nack_enabled_|. 1929 // Set nack status on receive channels and update |nack_enabled_|.
1868 for (const auto& ch : receive_channels_) { 1930 for (const auto& ch : recv_streams_) {
1869 SetNack(ch.second->channel(), nack_enabled_); 1931 SetNack(ch.second->channel(), nack_enabled_);
1870 } 1932 }
1871 1933
1872 return true; 1934 return true;
1873 } 1935 }
1874 1936
1875 void WebRtcVoiceMediaChannel::SetNack(int channel, bool nack_enabled) { 1937 void WebRtcVoiceMediaChannel::SetNack(int channel, bool nack_enabled) {
1876 if (nack_enabled) { 1938 if (nack_enabled) {
1877 LOG(LS_INFO) << "Enabling NACK for channel " << channel; 1939 LOG(LS_INFO) << "Enabling NACK for channel " << channel;
1878 engine()->voe()->rtp()->SetNACKStatus(channel, true, kNackMaxPackets); 1940 engine()->voe()->rtp()->SetNACKStatus(channel, true, kNackMaxPackets);
(...skipping 15 matching lines...) Expand all
1894 return true; 1956 return true;
1895 } 1957 }
1896 1958
1897 if (engine()->voe()->codec()->SetSendCodec(channel, send_codec) == -1) { 1959 if (engine()->voe()->codec()->SetSendCodec(channel, send_codec) == -1) {
1898 LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec)); 1960 LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec));
1899 return false; 1961 return false;
1900 } 1962 }
1901 return true; 1963 return true;
1902 } 1964 }
1903 1965
1904 bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions(
1905 const std::vector<RtpHeaderExtension>& extensions) {
1906 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1907 if (receive_extensions_ == extensions) {
1908 return true;
1909 }
1910
1911 for (const auto& ch : receive_channels_) {
1912 if (!SetChannelRecvRtpHeaderExtensions(ch.second->channel(), extensions)) {
1913 return false;
1914 }
1915 }
1916
1917 receive_extensions_ = extensions;
1918
1919 // Recreate AudioReceiveStream:s.
1920 recv_rtp_extensions_ = FindAudioRtpHeaderExtensions(extensions);
1921 RecreateAudioReceiveStreams();
1922
1923 return true;
1924 }
1925
1926 bool WebRtcVoiceMediaChannel::SetChannelRecvRtpHeaderExtensions(
1927 int channel_id, const std::vector<RtpHeaderExtension>& extensions) {
1928 const RtpHeaderExtension* audio_level_extension =
1929 FindHeaderExtension(extensions, kRtpAudioLevelHeaderExtension);
1930 if (!SetHeaderExtension(
1931 &webrtc::VoERTP_RTCP::SetReceiveAudioLevelIndicationStatus, channel_id,
1932 audio_level_extension)) {
1933 return false;
1934 }
1935
1936 const RtpHeaderExtension* send_time_extension =
1937 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension);
1938 if (!SetHeaderExtension(
1939 &webrtc::VoERTP_RTCP::SetReceiveAbsoluteSenderTimeStatus, channel_id,
1940 send_time_extension)) {
1941 return false;
1942 }
1943
1944 return true;
1945 }
1946
1947 bool WebRtcVoiceMediaChannel::SetPlayout(bool playout) { 1966 bool WebRtcVoiceMediaChannel::SetPlayout(bool playout) {
1948 desired_playout_ = playout; 1967 desired_playout_ = playout;
1949 return ChangePlayout(desired_playout_); 1968 return ChangePlayout(desired_playout_);
1950 } 1969 }
1951 1970
1952 bool WebRtcVoiceMediaChannel::PausePlayout() { 1971 bool WebRtcVoiceMediaChannel::PausePlayout() {
1953 return ChangePlayout(false); 1972 return ChangePlayout(false);
1954 } 1973 }
1955 1974
1956 bool WebRtcVoiceMediaChannel::ResumePlayout() { 1975 bool WebRtcVoiceMediaChannel::ResumePlayout() {
1957 return ChangePlayout(desired_playout_); 1976 return ChangePlayout(desired_playout_);
1958 } 1977 }
1959 1978
1960 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { 1979 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) {
1961 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1980 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1962 if (playout_ == playout) { 1981 if (playout_ == playout) {
1963 return true; 1982 return true;
1964 } 1983 }
1965 1984
1966 for (const auto& ch : receive_channels_) { 1985 for (const auto& ch : recv_streams_) {
1967 if (!SetPlayout(ch.second->channel(), playout)) { 1986 if (!SetPlayout(ch.second->channel(), playout)) {
1968 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " 1987 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel "
1969 << ch.second->channel() << " failed"; 1988 << ch.second->channel() << " failed";
1970 return false; 1989 return false;
1971 } 1990 }
1972 } 1991 }
1973 playout_ = playout; 1992 playout_ = playout;
1974 return true; 1993 return true;
1975 } 1994 }
1976 1995
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 return -1; 2080 return -1;
2062 } 2081 }
2063 if (engine()->voe()->network()->RegisterExternalTransport(id, *this) == -1) { 2082 if (engine()->voe()->network()->RegisterExternalTransport(id, *this) == -1) {
2064 LOG_RTCERR2(RegisterExternalTransport, id, this); 2083 LOG_RTCERR2(RegisterExternalTransport, id, this);
2065 engine()->voe()->base()->DeleteChannel(id); 2084 engine()->voe()->base()->DeleteChannel(id);
2066 return -1; 2085 return -1;
2067 } 2086 }
2068 return id; 2087 return id;
2069 } 2088 }
2070 2089
2071 bool WebRtcVoiceMediaChannel::DeleteChannel(int channel) { 2090 bool WebRtcVoiceMediaChannel::DeleteVoEChannel(int channel) {
2072 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { 2091 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) {
2073 LOG_RTCERR1(DeRegisterExternalTransport, channel); 2092 LOG_RTCERR1(DeRegisterExternalTransport, channel);
2074 } 2093 }
2075 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { 2094 if (engine()->voe()->base()->DeleteChannel(channel) == -1) {
2076 LOG_RTCERR1(DeleteChannel, channel); 2095 LOG_RTCERR1(DeleteChannel, channel);
2077 return false; 2096 return false;
2078 } 2097 }
2079 return true; 2098 return true;
2080 } 2099 }
2081 2100
(...skipping 28 matching lines...) Expand all
2110 if (!send_codecs_.empty() && !SetSendCodecs(channel, send_codecs_)) { 2129 if (!send_codecs_.empty() && !SetSendCodecs(channel, send_codecs_)) {
2111 RemoveSendStream(ssrc); 2130 RemoveSendStream(ssrc);
2112 return false; 2131 return false;
2113 } 2132 }
2114 2133
2115 // At this point the channel's local SSRC has been updated. If the channel is 2134 // At this point the channel's local SSRC has been updated. If the channel is
2116 // the first send channel make sure that all the receive channels are updated 2135 // the first send channel make sure that all the receive channels are updated
2117 // with the same SSRC in order to send receiver reports. 2136 // with the same SSRC in order to send receiver reports.
2118 if (send_streams_.size() == 1) { 2137 if (send_streams_.size() == 1) {
2119 receiver_reports_ssrc_ = ssrc; 2138 receiver_reports_ssrc_ = ssrc;
2120 for (const auto& ch : receive_channels_) { 2139 for (const auto& stream : recv_streams_) {
2121 int recv_channel = ch.second->channel(); 2140 int recv_channel = stream.second->channel();
2122 if (engine()->voe()->rtp()->SetLocalSSRC(recv_channel, ssrc) != 0) { 2141 if (engine()->voe()->rtp()->SetLocalSSRC(recv_channel, ssrc) != 0) {
2123 LOG_RTCERR2(SetLocalSSRC, ch.second->channel(), ssrc); 2142 LOG_RTCERR2(SetLocalSSRC, recv_channel, ssrc);
2124 return false; 2143 return false;
2125 } 2144 }
2126 engine()->voe()->base()->AssociateSendChannel(recv_channel, channel); 2145 engine()->voe()->base()->AssociateSendChannel(recv_channel, channel);
2127 LOG(LS_INFO) << "VoiceEngine channel #" << recv_channel 2146 LOG(LS_INFO) << "VoiceEngine channel #" << recv_channel
2128 << " is associated with channel #" << channel << "."; 2147 << " is associated with channel #" << channel << ".";
2129 } 2148 }
2130 } 2149 }
2131 2150
2132 return ChangeSend(channel, desired_send_); 2151 return ChangeSend(channel, desired_send_);
2133 } 2152 }
2134 2153
2135 bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) { 2154 bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) {
2136 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2155 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2137 LOG(LS_INFO) << "RemoveSendStream: " << ssrc; 2156 LOG(LS_INFO) << "RemoveSendStream: " << ssrc;
2138 2157
2139 auto it = send_streams_.find(ssrc); 2158 auto it = send_streams_.find(ssrc);
2140 if (it == send_streams_.end()) { 2159 if (it == send_streams_.end()) {
2141 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc 2160 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc
2142 << " which doesn't exist."; 2161 << " which doesn't exist.";
2143 return false; 2162 return false;
2144 } 2163 }
2145 2164
2146 int channel = it->second->channel(); 2165 int channel = it->second->channel();
2147 ChangeSend(channel, SEND_NOTHING); 2166 ChangeSend(channel, SEND_NOTHING);
2148 2167
2149 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, 2168 // Clean up and delete the send stream+channel.
2150 // this will disconnect the audio renderer with the send channel. 2169 LOG(LS_INFO) << "Removing audio send stream " << ssrc
2170 << " with VoiceEngine channel #" << channel << ".";
2151 delete it->second; 2171 delete it->second;
2152 send_streams_.erase(it); 2172 send_streams_.erase(it);
2153 2173 if (!DeleteVoEChannel(channel)) {
2154 // Clean up and delete the send channel.
2155 LOG(LS_INFO) << "Removing audio send stream " << ssrc
2156 << " with VoiceEngine channel #" << channel << ".";
2157 if (!DeleteChannel(channel)) {
2158 return false; 2174 return false;
2159 } 2175 }
2160 if (send_streams_.empty()) { 2176 if (send_streams_.empty()) {
2161 ChangeSend(SEND_NOTHING); 2177 ChangeSend(SEND_NOTHING);
2162 } 2178 }
2163 return true; 2179 return true;
2164 } 2180 }
2165 2181
2166 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { 2182 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) {
2167 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2183 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2168 LOG(LS_INFO) << "AddRecvStream: " << sp.ToString(); 2184 LOG(LS_INFO) << "AddRecvStream: " << sp.ToString();
2169 2185
2170 if (!ValidateStreamParams(sp)) { 2186 if (!ValidateStreamParams(sp)) {
2171 return false; 2187 return false;
2172 } 2188 }
2173 2189
2174 uint32_t ssrc = sp.first_ssrc(); 2190 uint32_t ssrc = sp.first_ssrc();
2175 if (ssrc == 0) { 2191 if (ssrc == 0) {
2176 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; 2192 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported.";
2177 return false; 2193 return false;
2178 } 2194 }
2179 2195
2180 // Remove the default receive stream if one had been created with this ssrc; 2196 // Remove the default receive stream if one had been created with this ssrc;
2181 // we'll recreate it then. 2197 // we'll recreate it then.
2182 if (IsDefaultRecvStream(ssrc)) { 2198 if (IsDefaultRecvStream(ssrc)) {
2183 RemoveRecvStream(ssrc); 2199 RemoveRecvStream(ssrc);
2184 } 2200 }
2185 2201
2186 if (receive_channels_.find(ssrc) != receive_channels_.end()) { 2202 if (GetReceiveChannelId(ssrc) != -1) {
2187 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; 2203 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc;
2188 return false; 2204 return false;
2189 } 2205 }
2190 RTC_DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end());
2191 2206
2192 // Create a new channel for receiving audio data. 2207 // Create a new channel for receiving audio data.
2193 int channel = CreateVoEChannel(); 2208 int channel = CreateVoEChannel();
2194 if (channel == -1) { 2209 if (channel == -1) {
2195 return false; 2210 return false;
2196 } 2211 }
2197 if (!ConfigureRecvChannel(channel)) {
2198 DeleteChannel(channel);
2199 return false;
2200 }
2201
2202 WebRtcAudioReceiveStream* stream = new WebRtcAudioReceiveStream(channel);
2203 receive_channels_.insert(std::make_pair(ssrc, stream));
2204 receive_stream_params_[ssrc] = sp;
2205 AddAudioReceiveStream(ssrc);
2206
2207 LOG(LS_INFO) << "New audio stream " << ssrc
2208 << " registered to VoiceEngine channel #"
2209 << channel << ".";
2210 return true;
2211 }
2212
2213 bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) {
2214 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2215
2216 int send_channel = GetSendChannelId(receiver_reports_ssrc_);
2217 if (send_channel != -1) {
2218 // Associate receive channel with first send channel (so the receive channel
2219 // can obtain RTT from the send channel)
2220 engine()->voe()->base()->AssociateSendChannel(channel, send_channel);
2221 LOG(LS_INFO) << "VoiceEngine channel #" << channel
2222 << " is associated with channel #" << send_channel << ".";
2223 }
2224 if (engine()->voe()->rtp()->SetLocalSSRC(channel,
2225 receiver_reports_ssrc_) == -1) {
2226 LOG_RTCERR1(SetLocalSSRC, channel);
2227 return false;
2228 }
2229 2212
2230 // Turn off all supported codecs. 2213 // Turn off all supported codecs.
2231 int ncodecs = engine()->voe()->codec()->NumOfCodecs(); 2214 int ncodecs = engine()->voe()->codec()->NumOfCodecs();
2232 for (int i = 0; i < ncodecs; ++i) { 2215 for (int i = 0; i < ncodecs; ++i) {
2233 webrtc::CodecInst voe_codec; 2216 webrtc::CodecInst voe_codec;
2234 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) { 2217 if (engine()->voe()->codec()->GetCodec(i, voe_codec) != -1) {
2235 voe_codec.pltype = -1; 2218 voe_codec.pltype = -1;
2236 if (engine()->voe()->codec()->SetRecPayloadType( 2219 if (engine()->voe()->codec()->SetRecPayloadType(
2237 channel, voe_codec) == -1) { 2220 channel, voe_codec) == -1) {
2238 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); 2221 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec));
2222 DeleteVoEChannel(channel);
2239 return false; 2223 return false;
2240 } 2224 }
2241 } 2225 }
2242 } 2226 }
2243 2227
2244 // Only enable those configured for this channel. 2228 // Only enable those configured for this channel.
2245 for (const auto& codec : recv_codecs_) { 2229 for (const auto& codec : recv_codecs_) {
2246 webrtc::CodecInst voe_codec; 2230 webrtc::CodecInst voe_codec;
2247 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { 2231 if (engine()->FindWebRtcCodec(codec, &voe_codec)) {
2248 voe_codec.pltype = codec.id; 2232 voe_codec.pltype = codec.id;
2249 if (engine()->voe()->codec()->SetRecPayloadType( 2233 if (engine()->voe()->codec()->SetRecPayloadType(
2250 channel, voe_codec) == -1) { 2234 channel, voe_codec) == -1) {
2251 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); 2235 LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec));
2236 DeleteVoEChannel(channel);
2252 return false; 2237 return false;
2253 } 2238 }
2254 } 2239 }
2255 } 2240 }
2256 2241
2257 SetNack(channel, nack_enabled_); 2242 int send_channel = GetSendChannelId(receiver_reports_ssrc_);
hlundin-webrtc 2015/11/20 12:59:21 const, if you are inclined towards local consts.
the sun 2015/11/20 14:24:09 I am, and I've changed it in this function, but wo
2258 2243 if (send_channel != -1) {
2259 // Set RTP header extension for the new channel. 2244 // Associate receive channel with first send channel (so the receive channel
2260 if (!SetChannelRecvRtpHeaderExtensions(channel, receive_extensions_)) { 2245 // can obtain RTT from the send channel)
2261 return false; 2246 engine()->voe()->base()->AssociateSendChannel(channel, send_channel);
2247 LOG(LS_INFO) << "VoiceEngine channel #" << channel
2248 << " is associated with channel #" << send_channel << ".";
2262 } 2249 }
2263 2250
2251 recv_streams_.insert(std::make_pair(ssrc, new WebRtcAudioReceiveStream(
2252 channel, ssrc, receiver_reports_ssrc_,
2253 options_.combined_audio_video_bwe.value_or(false), sp.sync_label,
2254 recv_rtp_extensions_, call_)));
2255
2256 SetNack(channel, nack_enabled_);
2264 SetPlayout(channel, playout_); 2257 SetPlayout(channel, playout_);
2258
2265 return true; 2259 return true;
2266 } 2260 }
2267 2261
2268 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { 2262 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) {
2269 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2263 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2270 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; 2264 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc;
2271 2265
2272 auto it = receive_channels_.find(ssrc); 2266 auto it = recv_streams_.find(ssrc);
2273 if (it == receive_channels_.end()) { 2267 if (it == recv_streams_.end()) {
2274 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc 2268 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc
2275 << " which doesn't exist."; 2269 << " which doesn't exist.";
2276 return false; 2270 return false;
2277 } 2271 }
2278 2272
2279 RemoveAudioReceiveStream(ssrc);
2280 receive_stream_params_.erase(ssrc);
2281
2282 const int channel = it->second->channel();
2283 delete it->second;
2284 receive_channels_.erase(it);
2285
2286 // Deregister default channel, if that's the one being destroyed. 2273 // Deregister default channel, if that's the one being destroyed.
2287 if (IsDefaultRecvStream(ssrc)) { 2274 if (IsDefaultRecvStream(ssrc)) {
2288 default_recv_ssrc_ = -1; 2275 default_recv_ssrc_ = -1;
2289 } 2276 }
2290 2277
2291 LOG(LS_INFO) << "Removing audio stream " << ssrc 2278 int channel = it->second->channel();
hlundin-webrtc 2015/11/20 12:59:21 const
the sun 2015/11/20 14:24:09 Done.
2279
2280 // Clean up and delete the receive stream+channel.
2281 LOG(LS_INFO) << "Removing audio receive stream " << ssrc
2292 << " with VoiceEngine channel #" << channel << "."; 2282 << " with VoiceEngine channel #" << channel << ".";
2293 return DeleteChannel(channel); 2283 delete it->second;
2284 recv_streams_.erase(it);
2285 return DeleteVoEChannel(channel);
2294 } 2286 }
2295 2287
2296 bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc, 2288 bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc,
2297 AudioRenderer* renderer) { 2289 AudioRenderer* renderer) {
2298 auto it = send_streams_.find(ssrc); 2290 auto it = send_streams_.find(ssrc);
2299 if (it == send_streams_.end()) { 2291 if (it == send_streams_.end()) {
2300 if (renderer) { 2292 if (renderer) {
2301 // Return an error if trying to set a valid renderer with an invalid ssrc. 2293 // Return an error if trying to set a valid renderer with an invalid ssrc.
2302 LOG(LS_ERROR) << "SetLocalRenderer failed with ssrc "<< ssrc; 2294 LOG(LS_ERROR) << "SetLocalRenderer failed with ssrc "<< ssrc;
2303 return false; 2295 return false;
2304 } 2296 }
2305 2297
2306 // The channel likely has gone away, do nothing. 2298 // The channel likely has gone away, do nothing.
2307 return true; 2299 return true;
2308 } 2300 }
2309 2301
2310 if (renderer) { 2302 if (renderer) {
2311 it->second->Start(renderer); 2303 it->second->Start(renderer);
2312 } else { 2304 } else {
2313 it->second->Stop(); 2305 it->second->Stop();
2314 } 2306 }
2315 2307
2316 return true; 2308 return true;
2317 } 2309 }
2318 2310
2319 bool WebRtcVoiceMediaChannel::GetActiveStreams( 2311 bool WebRtcVoiceMediaChannel::GetActiveStreams(
2320 AudioInfo::StreamList* actives) { 2312 AudioInfo::StreamList* actives) {
2321 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2313 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2322 actives->clear(); 2314 actives->clear();
2323 for (const auto& ch : receive_channels_) { 2315 for (const auto& ch : recv_streams_) {
2324 int level = GetOutputLevel(ch.second->channel()); 2316 int level = GetOutputLevel(ch.second->channel());
2325 if (level > 0) { 2317 if (level > 0) {
2326 actives->push_back(std::make_pair(ch.first, level)); 2318 actives->push_back(std::make_pair(ch.first, level));
2327 } 2319 }
2328 } 2320 }
2329 return true; 2321 return true;
2330 } 2322 }
2331 2323
2332 int WebRtcVoiceMediaChannel::GetOutputLevel() { 2324 int WebRtcVoiceMediaChannel::GetOutputLevel() {
2333 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2325 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2334 int highest = 0; 2326 int highest = 0;
2335 for (const auto& ch : receive_channels_) { 2327 for (const auto& ch : recv_streams_) {
2336 highest = std::max(GetOutputLevel(ch.second->channel()), highest); 2328 highest = std::max(GetOutputLevel(ch.second->channel()), highest);
2337 } 2329 }
2338 return highest; 2330 return highest;
2339 } 2331 }
2340 2332
2341 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() { 2333 int WebRtcVoiceMediaChannel::GetTimeSinceLastTyping() {
2342 int ret; 2334 int ret;
2343 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) { 2335 if (engine()->voe()->processing()->TimeSinceLastTyping(ret) == -1) {
2344 // In case of error, log the info and continue 2336 // In case of error, log the info and continue
2345 LOG_RTCERR0(TimeSinceLastTyping); 2337 LOG_RTCERR0(TimeSinceLastTyping);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 2430
2439 void WebRtcVoiceMediaChannel::OnPacketReceived( 2431 void WebRtcVoiceMediaChannel::OnPacketReceived(
2440 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { 2432 rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
2441 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2433 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2442 2434
2443 uint32_t ssrc = 0; 2435 uint32_t ssrc = 0;
2444 if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) { 2436 if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) {
2445 return; 2437 return;
2446 } 2438 }
2447 2439
2448 if (receive_channels_.empty()) { 2440 if (recv_streams_.empty()) {
2449 // Create new channel, which will be the default receive channel. 2441 // Create new channel, which will be the default receive channel.
2450 StreamParams sp; 2442 StreamParams sp;
2451 sp.ssrcs.push_back(ssrc); 2443 sp.ssrcs.push_back(ssrc);
2452 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; 2444 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << ".";
2453 if (!AddRecvStream(sp)) { 2445 if (!AddRecvStream(sp)) {
2454 LOG(LS_WARNING) << "Could not create default receive stream."; 2446 LOG(LS_WARNING) << "Could not create default receive stream.";
2455 return; 2447 return;
2456 } 2448 }
2457 default_recv_ssrc_ = ssrc; 2449 default_recv_ssrc_ = ssrc;
2458 SetOutputVolume(default_recv_ssrc_, default_recv_volume_); 2450 SetOutputVolume(default_recv_ssrc_, default_recv_volume_);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 sinfo.echo_delay_std_ms = stats.echo_delay_std_ms; 2625 sinfo.echo_delay_std_ms = stats.echo_delay_std_ms;
2634 sinfo.echo_return_loss = stats.echo_return_loss; 2626 sinfo.echo_return_loss = stats.echo_return_loss;
2635 sinfo.echo_return_loss_enhancement = stats.echo_return_loss_enhancement; 2627 sinfo.echo_return_loss_enhancement = stats.echo_return_loss_enhancement;
2636 sinfo.typing_noise_detected = 2628 sinfo.typing_noise_detected =
2637 (send_ == SEND_NOTHING ? false : stats.typing_noise_detected); 2629 (send_ == SEND_NOTHING ? false : stats.typing_noise_detected);
2638 info->senders.push_back(sinfo); 2630 info->senders.push_back(sinfo);
2639 } 2631 }
2640 2632
2641 // Get SSRC and stats for each receiver. 2633 // Get SSRC and stats for each receiver.
2642 RTC_DCHECK(info->receivers.size() == 0); 2634 RTC_DCHECK(info->receivers.size() == 0);
2643 for (const auto& stream : receive_streams_) { 2635 for (const auto& stream : recv_streams_) {
2644 webrtc::AudioReceiveStream::Stats stats = stream.second->GetStats(); 2636 webrtc::AudioReceiveStream::Stats stats = stream.second->GetStats();
2645 VoiceReceiverInfo rinfo; 2637 VoiceReceiverInfo rinfo;
2646 rinfo.add_ssrc(stats.remote_ssrc); 2638 rinfo.add_ssrc(stats.remote_ssrc);
2647 rinfo.bytes_rcvd = stats.bytes_rcvd; 2639 rinfo.bytes_rcvd = stats.bytes_rcvd;
2648 rinfo.packets_rcvd = stats.packets_rcvd; 2640 rinfo.packets_rcvd = stats.packets_rcvd;
2649 rinfo.packets_lost = stats.packets_lost; 2641 rinfo.packets_lost = stats.packets_lost;
2650 rinfo.fraction_lost = stats.fraction_lost; 2642 rinfo.fraction_lost = stats.fraction_lost;
2651 rinfo.codec_name = stats.codec_name; 2643 rinfo.codec_name = stats.codec_name;
2652 rinfo.ext_seqnum = stats.ext_seqnum; 2644 rinfo.ext_seqnum = stats.ext_seqnum;
2653 rinfo.jitter_ms = stats.jitter_ms; 2645 rinfo.jitter_ms = stats.jitter_ms;
(...skipping 21 matching lines...) Expand all
2675 } 2667 }
2676 2668
2677 int WebRtcVoiceMediaChannel::GetOutputLevel(int channel) { 2669 int WebRtcVoiceMediaChannel::GetOutputLevel(int channel) {
2678 unsigned int ulevel = 0; 2670 unsigned int ulevel = 0;
2679 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); 2671 int ret = engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel);
2680 return (ret == 0) ? static_cast<int>(ulevel) : -1; 2672 return (ret == 0) ? static_cast<int>(ulevel) : -1;
2681 } 2673 }
2682 2674
2683 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32_t ssrc) const { 2675 int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32_t ssrc) const {
2684 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2676 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2685 const auto it = receive_channels_.find(ssrc); 2677 const auto it = recv_streams_.find(ssrc);
2686 if (it != receive_channels_.end()) { 2678 if (it != recv_streams_.end()) {
2687 return it->second->channel(); 2679 return it->second->channel();
2688 } 2680 }
2689 return -1; 2681 return -1;
2690 } 2682 }
2691 2683
2692 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32_t ssrc) const { 2684 int WebRtcVoiceMediaChannel::GetSendChannelId(uint32_t ssrc) const {
2693 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2685 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2694 const auto it = send_streams_.find(ssrc); 2686 const auto it = send_streams_.find(ssrc);
2695 if (it != send_streams_.end()) { 2687 if (it != send_streams_.end()) {
2696 return it->second->channel(); 2688 return it->second->channel();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 LOG_RTCERR1(StartPlayout, channel); 2741 LOG_RTCERR1(StartPlayout, channel);
2750 return false; 2742 return false;
2751 } 2743 }
2752 } else { 2744 } else {
2753 LOG(LS_INFO) << "Stopping playout for channel #" << channel; 2745 LOG(LS_INFO) << "Stopping playout for channel #" << channel;
2754 engine()->voe()->base()->StopPlayout(channel); 2746 engine()->voe()->base()->StopPlayout(channel);
2755 } 2747 }
2756 return true; 2748 return true;
2757 } 2749 }
2758 2750
2759 bool WebRtcVoiceMediaChannel::SetHeaderExtension(ExtensionSetterFunction setter,
2760 int channel_id, const RtpHeaderExtension* extension) {
2761 bool enable = false;
2762 int id = 0;
2763 std::string uri;
2764 if (extension) {
2765 enable = true;
2766 id = extension->id;
2767 uri = extension->uri;
2768 }
2769 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) {
2770 LOG_RTCERR4(*setter, uri, channel_id, enable, id);
2771 return false;
2772 }
2773 return true;
2774 }
2775
2776 void WebRtcVoiceMediaChannel::RecreateAudioReceiveStreams() {
2777 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2778 for (const auto& it : receive_channels_) {
2779 RemoveAudioReceiveStream(it.first);
2780 }
2781 for (const auto& it : receive_channels_) {
2782 AddAudioReceiveStream(it.first);
2783 }
2784 }
2785
2786 void WebRtcVoiceMediaChannel::AddAudioReceiveStream(uint32_t ssrc) {
2787 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2788 WebRtcAudioReceiveStream* stream = receive_channels_[ssrc];
2789 RTC_DCHECK(stream != nullptr);
2790 RTC_DCHECK(receive_streams_.find(ssrc) == receive_streams_.end());
2791 webrtc::AudioReceiveStream::Config config;
2792 config.rtp.remote_ssrc = ssrc;
2793 // Only add RTP extensions if we support combined A/V BWE.
2794 config.rtp.extensions = recv_rtp_extensions_;
2795 config.combined_audio_video_bwe =
2796 options_.combined_audio_video_bwe.value_or(false);
2797 config.voe_channel_id = stream->channel();
2798 config.sync_group = receive_stream_params_[ssrc].sync_label;
2799 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config);
2800 receive_streams_.insert(std::make_pair(ssrc, s));
2801 }
2802
2803 void WebRtcVoiceMediaChannel::RemoveAudioReceiveStream(uint32_t ssrc) {
2804 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2805 auto stream_it = receive_streams_.find(ssrc);
2806 if (stream_it != receive_streams_.end()) {
2807 call_->DestroyAudioReceiveStream(stream_it->second);
2808 receive_streams_.erase(stream_it);
2809 }
2810 }
2811
2812 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( 2751 bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal(
2813 const std::vector<AudioCodec>& new_codecs) { 2752 const std::vector<AudioCodec>& new_codecs) {
2814 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2753 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2815 for (const AudioCodec& codec : new_codecs) { 2754 for (const AudioCodec& codec : new_codecs) {
2816 webrtc::CodecInst voe_codec; 2755 webrtc::CodecInst voe_codec;
2817 if (engine()->FindWebRtcCodec(codec, &voe_codec)) { 2756 if (engine()->FindWebRtcCodec(codec, &voe_codec)) {
2818 LOG(LS_INFO) << ToString(codec); 2757 LOG(LS_INFO) << ToString(codec);
2819 voe_codec.pltype = codec.id; 2758 voe_codec.pltype = codec.id;
2820 for (const auto& ch : receive_channels_) { 2759 for (const auto& ch : recv_streams_) {
2821 if (engine()->voe()->codec()->SetRecPayloadType( 2760 if (engine()->voe()->codec()->SetRecPayloadType(
2822 ch.second->channel(), voe_codec) == -1) { 2761 ch.second->channel(), voe_codec) == -1) {
2823 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(), 2762 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(),
2824 ToString(voe_codec)); 2763 ToString(voe_codec));
2825 return false; 2764 return false;
2826 } 2765 }
2827 } 2766 }
2828 } else { 2767 } else {
2829 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); 2768 LOG(LS_WARNING) << "Unknown codec " << ToString(codec);
2830 return false; 2769 return false;
2831 } 2770 }
2832 } 2771 }
2833 return true; 2772 return true;
2834 } 2773 }
2835
2836 } // namespace cricket 2774 } // namespace cricket
2837 2775
2838 #endif // HAVE_WEBRTC_VOICE 2776 #endif // HAVE_WEBRTC_VOICE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698