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

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

Issue 2516993002: Pass SdpAudioFormat through Channel, without converting to CodecInst (Closed)
Patch Set: . Created 4 years 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 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 bool use_nack, 1460 bool use_nack,
1461 const std::string& sync_group, 1461 const std::string& sync_group,
1462 const std::vector<webrtc::RtpExtension>& extensions, 1462 const std::vector<webrtc::RtpExtension>& extensions,
1463 webrtc::Call* call, 1463 webrtc::Call* call,
1464 webrtc::Transport* rtcp_send_transport, 1464 webrtc::Transport* rtcp_send_transport,
1465 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory) 1465 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory)
1466 : call_(call), config_() { 1466 : call_(call), config_() {
1467 RTC_DCHECK_GE(ch, 0); 1467 RTC_DCHECK_GE(ch, 0);
1468 RTC_DCHECK(call); 1468 RTC_DCHECK(call);
1469 config_.rtp.remote_ssrc = remote_ssrc; 1469 config_.rtp.remote_ssrc = remote_ssrc;
1470 config_.rtp.local_ssrc = local_ssrc;
1471 config_.rtp.transport_cc = use_transport_cc;
1472 config_.rtp.nack.rtp_history_ms = use_nack ? kNackRtpHistoryMs : 0;
1473 config_.rtp.extensions = extensions;
1470 config_.rtcp_send_transport = rtcp_send_transport; 1474 config_.rtcp_send_transport = rtcp_send_transport;
1471 config_.voe_channel_id = ch; 1475 config_.voe_channel_id = ch;
1472 config_.sync_group = sync_group; 1476 config_.sync_group = sync_group;
1473 config_.decoder_factory = decoder_factory; 1477 config_.decoder_factory = decoder_factory;
1474 RecreateAudioReceiveStream(local_ssrc, 1478 RecreateAudioReceiveStream();
1475 use_transport_cc,
1476 use_nack,
1477 extensions);
1478 } 1479 }
1479 1480
1480 ~WebRtcAudioReceiveStream() { 1481 ~WebRtcAudioReceiveStream() {
1481 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1482 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1482 call_->DestroyAudioReceiveStream(stream_); 1483 call_->DestroyAudioReceiveStream(stream_);
1483 } 1484 }
1484 1485
1485 void RecreateAudioReceiveStream(uint32_t local_ssrc) { 1486 void RecreateAudioReceiveStream(uint32_t local_ssrc) {
1486 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1487 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1487 RecreateAudioReceiveStream(local_ssrc, 1488 config_.rtp.local_ssrc = local_ssrc;
1488 config_.rtp.transport_cc, 1489 RecreateAudioReceiveStream();
1489 config_.rtp.nack.rtp_history_ms != 0,
1490 config_.rtp.extensions);
1491 } 1490 }
1492 1491
1493 void RecreateAudioReceiveStream(bool use_transport_cc, bool use_nack) { 1492 void RecreateAudioReceiveStream(bool use_transport_cc, bool use_nack) {
1494 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1493 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1495 RecreateAudioReceiveStream(config_.rtp.local_ssrc, 1494 config_.rtp.transport_cc = use_transport_cc;
1496 use_transport_cc, 1495 config_.rtp.nack.rtp_history_ms = use_nack ? kNackRtpHistoryMs : 0;
1497 use_nack, 1496 RecreateAudioReceiveStream();
1498 config_.rtp.extensions);
1499 } 1497 }
1500 1498
1501 void RecreateAudioReceiveStream( 1499 void RecreateAudioReceiveStream(
1502 const std::vector<webrtc::RtpExtension>& extensions) { 1500 std::vector<webrtc::RtpExtension>&& extensions) {
1503 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1501 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1504 RecreateAudioReceiveStream(config_.rtp.local_ssrc, 1502 config_.rtp.extensions = std::move(extensions);
1505 config_.rtp.transport_cc, 1503 RecreateAudioReceiveStream();
1506 config_.rtp.nack.rtp_history_ms != 0, 1504 }
1507 extensions); 1505
1506 // Set a new payload type -> decoder map. The new map must be a superset of
1507 // the old one.
1508 bool RecreateAudioReceiveStream(
1509 std::map<int, webrtc::SdpAudioFormat>&& decoder_map) {
1510 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1511 for (const auto& item : config_.decoder_map) {
the sun 2016/12/08 10:53:52 This is a good check, but it has (or *should* have
kwiberg-webrtc 2016/12/09 02:39:01 Done. Also changed return type to void.
1512 auto it = decoder_map.find(item.first);
1513 if (it == decoder_map.end() || *it != item) {
1514 return false; // The old map isn't a subset of the new map.
1515 }
1516 }
1517 config_.decoder_map = std::move(decoder_map);
1518 RecreateAudioReceiveStream();
1519 return true;
1508 } 1520 }
1509 1521
1510 webrtc::AudioReceiveStream::Stats GetStats() const { 1522 webrtc::AudioReceiveStream::Stats GetStats() const {
1511 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1523 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1512 RTC_DCHECK(stream_); 1524 RTC_DCHECK(stream_);
1513 return stream_->GetStats(); 1525 return stream_->GetStats();
1514 } 1526 }
1515 1527
1516 int channel() const { 1528 int channel() const {
1517 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1529 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
(...skipping 17 matching lines...) Expand all
1535 LOG(LS_INFO) << "Starting playout for channel #" << channel(); 1547 LOG(LS_INFO) << "Starting playout for channel #" << channel();
1536 stream_->Start(); 1548 stream_->Start();
1537 } else { 1549 } else {
1538 LOG(LS_INFO) << "Stopping playout for channel #" << channel(); 1550 LOG(LS_INFO) << "Stopping playout for channel #" << channel();
1539 stream_->Stop(); 1551 stream_->Stop();
1540 } 1552 }
1541 playout_ = playout; 1553 playout_ = playout;
1542 } 1554 }
1543 1555
1544 private: 1556 private:
1545 void RecreateAudioReceiveStream( 1557 void RecreateAudioReceiveStream() {
1546 uint32_t local_ssrc,
1547 bool use_transport_cc,
1548 bool use_nack,
1549 const std::vector<webrtc::RtpExtension>& extensions) {
1550 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1558 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1551 if (stream_) { 1559 if (stream_) {
1552 call_->DestroyAudioReceiveStream(stream_); 1560 call_->DestroyAudioReceiveStream(stream_);
1553 stream_ = nullptr;
1554 } 1561 }
1555 config_.rtp.local_ssrc = local_ssrc;
1556 config_.rtp.transport_cc = use_transport_cc;
1557 config_.rtp.nack.rtp_history_ms = use_nack ? kNackRtpHistoryMs : 0;
1558 config_.rtp.extensions = extensions;
1559 RTC_DCHECK(!stream_);
1560 stream_ = call_->CreateAudioReceiveStream(config_); 1562 stream_ = call_->CreateAudioReceiveStream(config_);
1561 RTC_CHECK(stream_); 1563 RTC_CHECK(stream_);
1562 SetPlayout(playout_); 1564 SetPlayout(playout_);
1563 } 1565 }
1564 1566
1565 rtc::ThreadChecker worker_thread_checker_; 1567 rtc::ThreadChecker worker_thread_checker_;
1566 webrtc::Call* call_ = nullptr; 1568 webrtc::Call* call_ = nullptr;
1567 webrtc::AudioReceiveStream::Config config_; 1569 webrtc::AudioReceiveStream::Config config_;
1568 // The stream is owned by WebRtcAudioReceiveStream and may be reallocated if 1570 // The stream is owned by WebRtcAudioReceiveStream and may be reallocated if
1569 // configuration changes. 1571 // configuration changes.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 1660
1659 if (!ValidateRtpExtensions(params.extensions)) { 1661 if (!ValidateRtpExtensions(params.extensions)) {
1660 return false; 1662 return false;
1661 } 1663 }
1662 std::vector<webrtc::RtpExtension> filtered_extensions = 1664 std::vector<webrtc::RtpExtension> filtered_extensions =
1663 FilterRtpExtensions(params.extensions, 1665 FilterRtpExtensions(params.extensions,
1664 webrtc::RtpExtension::IsSupportedForAudio, false); 1666 webrtc::RtpExtension::IsSupportedForAudio, false);
1665 if (recv_rtp_extensions_ != filtered_extensions) { 1667 if (recv_rtp_extensions_ != filtered_extensions) {
1666 recv_rtp_extensions_.swap(filtered_extensions); 1668 recv_rtp_extensions_.swap(filtered_extensions);
1667 for (auto& it : recv_streams_) { 1669 for (auto& it : recv_streams_) {
1668 it.second->RecreateAudioReceiveStream(recv_rtp_extensions_); 1670 auto ext = recv_rtp_extensions_; // Make a copy.
the sun 2016/12/08 10:53:52 To me, the fact that you need to write a comment i
kwiberg-webrtc 2016/12/09 02:39:01 I declared RecreateAudioReceiveStreamn to take an
the sun 2016/12/09 12:29:49 I think it's a little unnecessary. Sometimes we ne
ossu 2016/12/09 13:23:39 I think I agree with solenberg here. This map isn'
kwiberg-webrtc 2016/12/11 11:24:55 Not sure. We may be, but I guess it doesn't matter
1671 it.second->RecreateAudioReceiveStream(std::move(ext));
1669 } 1672 }
1670 } 1673 }
1671 return true; 1674 return true;
1672 } 1675 }
1673 1676
1674 webrtc::RtpParameters WebRtcVoiceMediaChannel::GetRtpSendParameters( 1677 webrtc::RtpParameters WebRtcVoiceMediaChannel::GetRtpSendParameters(
1675 uint32_t ssrc) const { 1678 uint32_t ssrc) const {
1676 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1679 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1677 auto it = send_streams_.find(ssrc); 1680 auto it = send_streams_.find(ssrc);
1678 if (it == send_streams_.end()) { 1681 if (it == send_streams_.end()) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 // never removed. 1843 // never removed.
1841 return true; 1844 return true;
1842 } 1845 }
1843 1846
1844 if (playout_) { 1847 if (playout_) {
1845 // Receive codecs can not be changed while playing. So we temporarily 1848 // Receive codecs can not be changed while playing. So we temporarily
1846 // pause playout. 1849 // pause playout.
1847 ChangePlayout(false); 1850 ChangePlayout(false);
1848 } 1851 }
1849 1852
1853 std::map<int, webrtc::SdpAudioFormat> decoder_map;
1854 for (const AudioCodec& codec : codecs) {
1855 LOG(LS_INFO) << ToString(codec);
1856 decoder_map.insert({codec.id, AudioCodecToSdp(codec)});
1857 }
1850 bool result = true; 1858 bool result = true;
1851 for (const AudioCodec& codec : new_codecs) { 1859 for (auto& it : recv_streams_) {
the sun 2016/12/08 10:53:52 nit: it -> kv
kwiberg-webrtc 2016/12/09 02:39:01 Done.
1852 webrtc::CodecInst voe_codec = {0}; 1860 auto dm = decoder_map; // Make a copy.
the sun 2016/12/08 10:53:52 Same comment as on line 1670
1853 if (WebRtcVoiceEngine::ToCodecInst(codec, &voe_codec)) { 1861 result = it.second->RecreateAudioReceiveStream(std::move(dm)) && result;
1854 LOG(LS_INFO) << ToString(codec);
1855 voe_codec.pltype = codec.id;
1856 for (const auto& ch : recv_streams_) {
1857 if (engine()->voe()->codec()->SetRecPayloadType(
1858 ch.second->channel(), voe_codec) == -1) {
1859 LOG_RTCERR2(SetRecPayloadType, ch.second->channel(),
1860 ToString(voe_codec));
1861 result = false;
1862 }
1863 }
1864 } else {
1865 LOG(LS_WARNING) << "Unknown codec " << ToString(codec);
1866 result = false;
1867 break;
1868 }
1869 } 1862 }
1870 if (result) { 1863 recv_codecs_ = codecs;
1871 recv_codecs_ = codecs;
1872 }
1873 1864
1874 if (desired_playout_ && !playout_) { 1865 if (desired_playout_ && !playout_) {
1875 ChangePlayout(desired_playout_); 1866 ChangePlayout(desired_playout_);
1876 } 1867 }
1877 return result; 1868 return result;
1878 } 1869 }
1879 1870
1880 // Utility function called from SetSendParameters() to extract current send 1871 // Utility function called from SetSendParameters() to extract current send
1881 // codec settings from the given list of codecs (originally from SDP). Both send 1872 // codec settings from the given list of codecs (originally from SDP). Both send
1882 // and receive streams may be reconfigured based on the new settings. 1873 // and receive streams may be reconfigured based on the new settings.
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
2651 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2642 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2652 const auto it = send_streams_.find(ssrc); 2643 const auto it = send_streams_.find(ssrc);
2653 if (it != send_streams_.end()) { 2644 if (it != send_streams_.end()) {
2654 return it->second->channel(); 2645 return it->second->channel();
2655 } 2646 }
2656 return -1; 2647 return -1;
2657 } 2648 }
2658 } // namespace cricket 2649 } // namespace cricket
2659 2650
2660 #endif // HAVE_WEBRTC_VOICE 2651 #endif // HAVE_WEBRTC_VOICE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698