Index: webrtc/pc/mediasession.cc |
diff --git a/webrtc/pc/mediasession.cc b/webrtc/pc/mediasession.cc |
index a9d1b95c22aee6aae9299315a9ecc05586242336..a6abb650080d7d5e2c152cab5a3a43352ac868a8 100644 |
--- a/webrtc/pc/mediasession.cc |
+++ b/webrtc/pc/mediasession.cc |
@@ -749,7 +749,6 @@ static bool CreateMediaContentOffer( |
StreamParamsVec* current_streams, |
MediaContentDescriptionImpl<C>* offer) { |
offer->AddCodecs(codecs); |
- offer->SortCodecs(); |
if (secure_policy == SEC_REQUIRED) { |
offer->set_crypto_required(CT_SDES); |
@@ -810,6 +809,8 @@ static void NegotiateCodecs(const std::vector<C>& local_codecs, |
std::vector<C>* negotiated_codecs) { |
for (const C& ours : local_codecs) { |
C theirs; |
+ // Note that we intentionally only find one matching codec for each of our |
+ // local codecs, in case the remote offer contains duplicate codecs. |
if (FindMatchingCodec(local_codecs, offered_codecs, ours, &theirs)) { |
C negotiated = ours; |
negotiated.IntersectFeedbackParams(theirs); |
@@ -822,14 +823,24 @@ static void NegotiateCodecs(const std::vector<C>& local_codecs, |
offered_apt_value); |
} |
negotiated.id = theirs.id; |
- // RFC3264: Although the answerer MAY list the formats in their desired |
- // order of preference, it is RECOMMENDED that unless there is a |
- // specific reason, the answerer list formats in the same relative order |
- // they were present in the offer. |
- negotiated.preference = theirs.preference; |
negotiated_codecs->push_back(negotiated); |
} |
} |
+ // RFC3264: Although the answerer MAY list the formats in their desired |
+ // order of preference, it is RECOMMENDED that unless there is a |
+ // specific reason, the answerer list formats in the same relative order |
+ // they were present in the offer. |
+ std::vector<int> offer_payload_types; |
+ for (const C& codec : offered_codecs) { |
+ offer_payload_types.push_back(codec.id); |
+ } |
+ std::sort(negotiated_codecs->begin(), negotiated_codecs->end(), |
+ [offer_payload_types](const C& a, const C& b) { |
+ return std::find(offer_payload_types.begin(), |
+ offer_payload_types.end(), a.id) < |
+ std::find(offer_payload_types.begin(), |
+ offer_payload_types.end(), b.id); |
+ }); |
pthatcher1
2016/04/12 00:35:19
If you're going to fix the sort in one place, you
Taylor Brandstetter
2016/04/12 01:23:29
Done.
|
} |
// Finds a codec in |codecs2| that matches |codec_to_match|, which is |
@@ -1042,7 +1053,6 @@ static bool CreateMediaContentAnswer( |
std::vector<C> negotiated_codecs; |
NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs); |
answer->AddCodecs(negotiated_codecs); |
- answer->SortCodecs(); |
answer->set_protocol(offer->protocol()); |
RtpHeaderExtensions negotiated_rtp_extensions; |
NegotiateRtpHeaderExtensions(local_rtp_extenstions, |
@@ -1365,8 +1375,8 @@ SessionDescription* MediaSessionDescriptionFactory::CreateAnswer( |
const SessionDescription* offer, const MediaSessionOptions& options, |
const SessionDescription* current_description) const { |
// The answer contains the intersection of the codecs in the offer with the |
- // codecs we support, ordered by our local preference. As indicated by |
- // XEP-0167, we retain the same payload ids from the offer in the answer. |
+ // codecs we support. As indicated by XEP-0167, we retain the same payload ids |
+ // from the offer in the answer. |
std::unique_ptr<SessionDescription> answer(new SessionDescription()); |
StreamParamsVec current_streams; |