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

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

Issue 2831333002: Allow a received audio codec's payload type to change. (Closed)
Patch Set: Created 3 years, 8 months 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 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 RecreateAudioReceiveStream(); 1508 RecreateAudioReceiveStream();
1509 } 1509 }
1510 1510
1511 void RecreateAudioReceiveStream( 1511 void RecreateAudioReceiveStream(
1512 const std::vector<webrtc::RtpExtension>& extensions) { 1512 const std::vector<webrtc::RtpExtension>& extensions) {
1513 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1513 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1514 config_.rtp.extensions = extensions; 1514 config_.rtp.extensions = extensions;
1515 RecreateAudioReceiveStream(); 1515 RecreateAudioReceiveStream();
1516 } 1516 }
1517 1517
1518 // Set a new payload type -> decoder map. The new map must be a superset of 1518 // Set a new payload type -> decoder map.
1519 // the old one.
1520 void RecreateAudioReceiveStream( 1519 void RecreateAudioReceiveStream(
1521 const std::map<int, webrtc::SdpAudioFormat>& decoder_map) { 1520 const std::map<int, webrtc::SdpAudioFormat>& decoder_map) {
1522 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1521 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1523 RTC_DCHECK([&] {
1524 for (const auto& item : config_.decoder_map) {
1525 auto it = decoder_map.find(item.first);
1526 if (it == decoder_map.end() || *it != item) {
1527 return false; // The old map isn't a subset of the new map.
1528 }
1529 }
1530 return true;
1531 }());
kwiberg-webrtc 2017/04/21 12:49:00 Why are you removing this check? I thought we were
Taylor Brandstetter 2017/04/21 13:02:06 I'm removing this check because the assertion is n
kwiberg-webrtc 2017/04/21 13:18:57 But isn't the error that higher layers (or this on
Taylor Brandstetter 2017/04/21 14:20:23 No; apps should be able to set a new local descrip
1532 config_.decoder_map = decoder_map; 1522 config_.decoder_map = decoder_map;
1533 RecreateAudioReceiveStream(); 1523 RecreateAudioReceiveStream();
1534 } 1524 }
1535 1525
1536 void MaybeRecreateAudioReceiveStream(const std::string& sync_group) { 1526 void MaybeRecreateAudioReceiveStream(const std::string& sync_group) {
1537 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1527 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1538 if (config_.sync_group != sync_group) { 1528 if (config_.sync_group != sync_group) {
1539 config_.sync_group = sync_group; 1529 config_.sync_group = sync_group;
1540 RecreateAudioReceiveStream(); 1530 RecreateAudioReceiveStream();
1541 } 1531 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 LOG(LS_ERROR) << "Codec payload types overlap."; 1840 LOG(LS_ERROR) << "Codec payload types overlap.";
1851 return false; 1841 return false;
1852 } 1842 }
1853 1843
1854 std::vector<AudioCodec> new_codecs; 1844 std::vector<AudioCodec> new_codecs;
1855 // Find all new codecs. We allow adding new codecs but don't allow changing 1845 // Find all new codecs. We allow adding new codecs but don't allow changing
1856 // the payload type of codecs that is already configured since we might 1846 // the payload type of codecs that is already configured since we might
1857 // already be receiving packets with that payload type. 1847 // already be receiving packets with that payload type.
1858 for (const AudioCodec& codec : codecs) { 1848 for (const AudioCodec& codec : codecs) {
1859 AudioCodec old_codec; 1849 AudioCodec old_codec;
1860 // TODO(solenberg): This isn't strictly correct. It should be possible to
1861 // add an additional payload type for a codec. That would result in a new
1862 // decoder object being allocated. What shouldn't work is to remove a PT
1863 // mapping that was previously configured.
1864 if (FindCodec(recv_codecs_, codec, &old_codec)) { 1850 if (FindCodec(recv_codecs_, codec, &old_codec)) {
1865 if (old_codec.id != codec.id) { 1851 if (old_codec.id != codec.id) {
1866 LOG(LS_ERROR) << codec.name << " payload type changed."; 1852 LOG(LS_WARNING) << codec.name << " payload type changed.";
1867 return false; 1853 new_codecs.push_back(codec);
1868 } 1854 }
1869 } else { 1855 } else {
1870 new_codecs.push_back(codec); 1856 new_codecs.push_back(codec);
1871 } 1857 }
1872 } 1858 }
1873 if (new_codecs.empty()) { 1859 if (new_codecs.empty()) {
1874 // There are no new codecs to configure. Already configured codecs are 1860 // There are no new codecs to configure. Already configured codecs are
1875 // never removed. 1861 // never removed.
1876 return true; 1862 return true;
1877 } 1863 }
1878 1864
1879 // Create a payload type -> SdpAudioFormat map with all the decoders. Fail 1865 // Create a payload type -> SdpAudioFormat map with all the decoders. Fail
1880 // unless the factory claims to support all decoders. 1866 // unless the factory claims to support all decoders.
1881 std::map<int, webrtc::SdpAudioFormat> decoder_map; 1867 std::map<int, webrtc::SdpAudioFormat> decoder_map;
1882 for (const AudioCodec& codec : codecs) { 1868 for (const AudioCodec& codec : codecs) {
1883 auto format = AudioCodecToSdpAudioFormat(codec); 1869 auto format = AudioCodecToSdpAudioFormat(codec);
1884 if (!IsCodec(codec, "cn") && !IsCodec(codec, "telephone-event") && 1870 if (!IsCodec(codec, "cn") && !IsCodec(codec, "telephone-event") &&
1885 !engine()->decoder_factory_->IsSupportedDecoder(format)) { 1871 !engine()->decoder_factory_->IsSupportedDecoder(format)) {
1886 LOG(LS_ERROR) << "Unsupported codec: " << format; 1872 LOG(LS_ERROR) << "Unsupported codec: " << format;
1887 return false; 1873 return false;
1888 } 1874 }
1875 // If a payload type is already mapped to a codec, it's illegal to map it
1876 // to a new codec.
1877 auto existing = decoder_map_.find(codec.id);
1878 if (existing != decoder_map_.end() && !existing->second.Matches(format)) {
1879 LOG(LS_ERROR) << "Attempting to use payload type " << codec.id << " for "
1880 << codec.name << ", but it is already used for "
1881 << existing->second.name;
1882 return false;
1883 }
kwiberg-webrtc 2017/04/21 12:49:00 Hmm... here you disallow changing (but not removin
Taylor Brandstetter 2017/04/21 13:02:06 True. We should probably store a permanent history
kwiberg-webrtc 2017/04/21 13:18:58 Storing a permanent history of mappings sounds muc
1889 decoder_map.insert({codec.id, std::move(format)}); 1884 decoder_map.insert({codec.id, std::move(format)});
1890 } 1885 }
1891 1886
1892 if (playout_) { 1887 if (playout_) {
1893 // Receive codecs can not be changed while playing. So we temporarily 1888 // Receive codecs can not be changed while playing. So we temporarily
1894 // pause playout. 1889 // pause playout.
1895 ChangePlayout(false); 1890 ChangePlayout(false);
1896 } 1891 }
1897 1892
1898 decoder_map_ = std::move(decoder_map); 1893 decoder_map_ = std::move(decoder_map);
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 ssrc); 2659 ssrc);
2665 if (it != unsignaled_recv_ssrcs_.end()) { 2660 if (it != unsignaled_recv_ssrcs_.end()) {
2666 unsignaled_recv_ssrcs_.erase(it); 2661 unsignaled_recv_ssrcs_.erase(it);
2667 return true; 2662 return true;
2668 } 2663 }
2669 return false; 2664 return false;
2670 } 2665 }
2671 } // namespace cricket 2666 } // namespace cricket
2672 2667
2673 #endif // HAVE_WEBRTC_VOICE 2668 #endif // HAVE_WEBRTC_VOICE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698