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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc

Issue 2686043006: WebRtcVoiceMediaChannel::AddRecvStream: Don't call SetRecPayloadType (Closed)
Patch Set: Discard packets when updating payload type map Created 3 years, 9 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
11 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" 11 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
17 #include "webrtc/base/stringutils.h" 17 #include "webrtc/base/stringutils.h"
18 #include "webrtc/common_types.h" 18 #include "webrtc/common_types.h"
19 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
19 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 20 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
20 21
21 namespace webrtc { 22 namespace webrtc {
22 23
23 namespace { 24 namespace {
24 25
25 bool PayloadIsCompatible(const RtpUtility::Payload& payload, 26 bool PayloadIsCompatible(const RtpUtility::Payload& payload,
26 const CodecInst& audio_codec) { 27 const CodecInst& audio_codec) {
27 if (!payload.audio) 28 if (!payload.audio)
28 return false; 29 return false;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 113
113 RTPPayloadRegistry::RTPPayloadRegistry() 114 RTPPayloadRegistry::RTPPayloadRegistry()
114 : incoming_payload_type_(-1), 115 : incoming_payload_type_(-1),
115 last_received_payload_type_(-1), 116 last_received_payload_type_(-1),
116 last_received_media_payload_type_(-1), 117 last_received_media_payload_type_(-1),
117 rtx_(false), 118 rtx_(false),
118 ssrc_rtx_(0) {} 119 ssrc_rtx_(0) {}
119 120
120 RTPPayloadRegistry::~RTPPayloadRegistry() = default; 121 RTPPayloadRegistry::~RTPPayloadRegistry() = default;
121 122
123 bool RTPPayloadRegistry::SetAudioReceivePayloads(
the sun 2017/03/14 20:07:01 Like with DecoderDatabase, we should be able to tr
kwiberg-webrtc 2017/03/16 10:24:12 Done.
124 std::map<int, SdpAudioFormat> codecs) {
125 for (const auto& kv : codecs) {
126 if (!IsPayloadTypeValid(kv.first)) {
127 return false;
128 }
129 }
130
131 // Make sure we have no collisions.
132 auto existing_it = payload_type_map_.cbegin();
133 auto new_it = codecs.cbegin();
134 while (existing_it != payload_type_map_.cend() && new_it != codecs.cend()) {
135 if (existing_it->second.audio) {
136 ++existing_it;
137 } else {
138 if (existing_it->first == new_it->first) {
139 return false; // Trying to overwrite a video PT with audio.
the sun 2017/03/14 20:07:01 This should never happen, since we have an RTPPayl
kwiberg-webrtc 2017/03/16 10:24:12 Acknowledged. I'll try adding DCHECKs that verify
140 }
141 if (existing_it->first < new_it->first) {
142 ++existing_it;
143 } else {
144 ++new_it;
145 }
146 }
147 }
148
149 // Remove existing audio payload types.
the sun 2017/03/14 20:07:01 This shouldn't be allowed.
kwiberg-webrtc 2017/03/16 10:24:12 In principle, yes. See other comments...
150 for (auto it = payload_type_map_.begin(); it != payload_type_map_.end();) {
151 if (it->second.audio) {
152 it = payload_type_map_.erase(it);
153 } else {
154 ++it;
155 }
156 }
157
158 // Insert the new payload types.
159 for (const auto& kv : codecs) {
160 const int& rtp_payload_type = kv.first;
161 const SdpAudioFormat& audio_format = kv.second;
the sun 2017/03/14 20:07:01 I suggest you do this conversion in voe::Channel,
kwiberg-webrtc 2017/03/16 10:24:12 Well, yes... but I'm trying to reduce the use of C
162 const CodecInst ci = SdpToCodecInst(rtp_payload_type, audio_format);
163 payload_type_map_[rtp_payload_type] = CreatePayloadType(ci);
164 }
165
166 // Clear the value of last received payload type since it might mean
167 // something else now.
168 last_received_payload_type_ = -1;
169 last_received_media_payload_type_ = -1;
170 return true;
the sun 2017/03/14 20:07:01 If you address the above I don't think we even nee
kwiberg-webrtc 2017/03/16 10:24:12 Acknowledged.
171 }
172
122 int32_t RTPPayloadRegistry::RegisterReceivePayload(const CodecInst& audio_codec, 173 int32_t RTPPayloadRegistry::RegisterReceivePayload(const CodecInst& audio_codec,
123 bool* created_new_payload) { 174 bool* created_new_payload) {
124 *created_new_payload = false; 175 *created_new_payload = false;
125 if (!IsPayloadTypeValid(audio_codec.pltype)) 176 if (!IsPayloadTypeValid(audio_codec.pltype))
126 return -1; 177 return -1;
127 178
128 rtc::CritScope cs(&crit_sect_); 179 rtc::CritScope cs(&crit_sect_);
129 180
130 auto it = payload_type_map_.find(audio_codec.pltype); 181 auto it = payload_type_map_.find(audio_codec.pltype);
131 if (it != payload_type_map_.end()) { 182 if (it != payload_type_map_.end()) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 const char* payload_name) const { 437 const char* payload_name) const {
387 rtc::CritScope cs(&crit_sect_); 438 rtc::CritScope cs(&crit_sect_);
388 for (const auto& it : payload_type_map_) { 439 for (const auto& it : payload_type_map_) {
389 if (_stricmp(it.second.name, payload_name) == 0) 440 if (_stricmp(it.second.name, payload_name) == 0)
390 return it.first; 441 return it.first;
391 } 442 }
392 return -1; 443 return -1;
393 } 444 }
394 445
395 } // namespace webrtc 446 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698