Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 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 |
| 11 #include "webrtc/pc/mediasession.h" | 11 #include "webrtc/pc/mediasession.h" |
| 12 | 12 |
| 13 #include <algorithm> // For std::find_if, std::sort. | 13 #include <algorithm> // For std::find_if, std::sort. |
| 14 #include <functional> | 14 #include <functional> |
| 15 #include <map> | 15 #include <map> |
| 16 #include <memory> | 16 #include <memory> |
| 17 #include <set> | 17 #include <set> |
| 18 #include <unordered_map> | 18 #include <unordered_map> |
| 19 #include <utility> | 19 #include <utility> |
| 20 | 20 |
| 21 #include "webrtc/base/base64.h" | 21 #include "webrtc/base/base64.h" |
| 22 #include "webrtc/base/helpers.h" | 22 #include "webrtc/base/helpers.h" |
| 23 #include "webrtc/base/logging.h" | 23 #include "webrtc/base/logging.h" |
| 24 #include "webrtc/base/stringutils.h" | 24 #include "webrtc/base/stringutils.h" |
| 25 #include "webrtc/common_video/h264/profile_level_id.h" | |
| 25 #include "webrtc/media/base/cryptoparams.h" | 26 #include "webrtc/media/base/cryptoparams.h" |
| 26 #include "webrtc/media/base/mediaconstants.h" | 27 #include "webrtc/media/base/mediaconstants.h" |
| 27 #include "webrtc/p2p/base/p2pconstants.h" | 28 #include "webrtc/p2p/base/p2pconstants.h" |
| 28 #include "webrtc/pc/channelmanager.h" | 29 #include "webrtc/pc/channelmanager.h" |
| 29 #include "webrtc/pc/srtpfilter.h" | 30 #include "webrtc/pc/srtpfilter.h" |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 const char kInline[] = "inline:"; | 33 const char kInline[] = "inline:"; |
| 33 | 34 |
| 34 void GetSupportedCryptoSuiteNames(void (*func)(const rtc::CryptoOptions&, | 35 void GetSupportedCryptoSuiteNames(void (*func)(const rtc::CryptoOptions&, |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 if (!rtc::FromString(codec1_id_str, &codec1_id) || | 763 if (!rtc::FromString(codec1_id_str, &codec1_id) || |
| 763 !rtc::FromString(codec2_id_str, &codec2_id) || | 764 !rtc::FromString(codec2_id_str, &codec2_id) || |
| 764 !FindCodecById(codecs1, codec1_id, &codec1) || | 765 !FindCodecById(codecs1, codec1_id, &codec1) || |
| 765 !FindCodecById(codecs2, codec2_id, &codec2)) { | 766 !FindCodecById(codecs2, codec2_id, &codec2)) { |
| 766 return false; | 767 return false; |
| 767 } | 768 } |
| 768 return codec1.Matches(codec2); | 769 return codec1.Matches(codec2); |
| 769 } | 770 } |
| 770 | 771 |
| 771 template <class C> | 772 template <class C> |
| 773 static rtc::Optional<C> IntersectCodecs(const C& local, const C& remote) { | |
| 774 C intersected = local; | |
| 775 | |
| 776 if (CodecNamesEq(local.name.c_str(), kH264CodecName)) { | |
| 777 const rtc::Optional<webrtc::H264::ProfileLevelId> intersected_profile = | |
| 778 webrtc::H264::NegotiateProfileLevelId(local.params, remote.params); | |
|
hta-webrtc
2016/11/08 13:59:53
Illustrates my point about Negotiate being misname
magjed_webrtc
2016/11/08 16:18:26
Yeah, I'm not that happy with either the name inte
| |
| 779 if (!intersected_profile) | |
| 780 return rtc::Optional<C>(); | |
| 781 intersected.params["profile-level-id"] = | |
| 782 *webrtc::H264::ProfileLevelIdToString(*intersected_profile); | |
| 783 } | |
| 784 | |
| 785 intersected.IntersectFeedbackParams(remote); | |
| 786 if (IsRtxCodec(remote)) { | |
| 787 const auto apt_it = remote.params.find(kCodecParamAssociatedPayloadType); | |
| 788 RTC_DCHECK(apt_it != remote.params.end()); | |
| 789 intersected.SetParam(kCodecParamAssociatedPayloadType, apt_it->second); | |
| 790 } | |
| 791 intersected.id = remote.id; | |
| 792 intersected.name = remote.name; | |
| 793 return rtc::Optional<C>(std::move(intersected)); | |
| 794 } | |
| 795 | |
| 796 template <class C> | |
| 772 static void NegotiateCodecs(const std::vector<C>& local_codecs, | 797 static void NegotiateCodecs(const std::vector<C>& local_codecs, |
| 773 const std::vector<C>& offered_codecs, | 798 const std::vector<C>& offered_codecs, |
| 774 std::vector<C>* negotiated_codecs) { | 799 std::vector<C>* negotiated_codecs) { |
| 775 for (const C& ours : local_codecs) { | 800 for (const C& ours : local_codecs) { |
| 776 C theirs; | 801 C theirs; |
| 777 // Note that we intentionally only find one matching codec for each of our | 802 // Note that we intentionally only find one matching codec for each of our |
| 778 // local codecs, in case the remote offer contains duplicate codecs. | 803 // local codecs, in case the remote offer contains duplicate codecs. |
| 779 if (FindMatchingCodec(local_codecs, offered_codecs, ours, &theirs)) { | 804 if (FindMatchingCodec(local_codecs, offered_codecs, ours, &theirs)) { |
| 780 C negotiated = ours; | 805 rtc::Optional<C> negotiated = IntersectCodecs(ours, theirs); |
| 781 negotiated.IntersectFeedbackParams(theirs); | 806 if (negotiated) |
| 782 if (IsRtxCodec(negotiated)) { | 807 negotiated_codecs->push_back(std::move(*negotiated)); |
| 783 std::string offered_apt_value; | |
| 784 theirs.GetParam(kCodecParamAssociatedPayloadType, &offered_apt_value); | |
| 785 // FindMatchingCodec shouldn't return something with no apt value. | |
| 786 RTC_DCHECK(!offered_apt_value.empty()); | |
| 787 negotiated.SetParam(kCodecParamAssociatedPayloadType, | |
| 788 offered_apt_value); | |
| 789 } | |
| 790 negotiated.id = theirs.id; | |
| 791 negotiated.name = theirs.name; | |
| 792 negotiated_codecs->push_back(negotiated); | |
| 793 } | 808 } |
| 794 } | 809 } |
| 795 // RFC3264: Although the answerer MAY list the formats in their desired | 810 // RFC3264: Although the answerer MAY list the formats in their desired |
| 796 // order of preference, it is RECOMMENDED that unless there is a | 811 // order of preference, it is RECOMMENDED that unless there is a |
| 797 // specific reason, the answerer list formats in the same relative order | 812 // specific reason, the answerer list formats in the same relative order |
| 798 // they were present in the offer. | 813 // they were present in the offer. |
| 799 std::unordered_map<int, int> payload_type_preferences; | 814 std::unordered_map<int, int> payload_type_preferences; |
| 800 int preference = static_cast<int>(offered_codecs.size() + 1); | 815 int preference = static_cast<int>(offered_codecs.size() + 1); |
| 801 for (const C& codec : offered_codecs) { | 816 for (const C& codec : offered_codecs) { |
| 802 payload_type_preferences[codec.id] = preference--; | 817 payload_type_preferences[codec.id] = preference--; |
| (...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2161 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 2176 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
| 2162 } | 2177 } |
| 2163 | 2178 |
| 2164 DataContentDescription* GetFirstDataContentDescription( | 2179 DataContentDescription* GetFirstDataContentDescription( |
| 2165 SessionDescription* sdesc) { | 2180 SessionDescription* sdesc) { |
| 2166 return static_cast<DataContentDescription*>( | 2181 return static_cast<DataContentDescription*>( |
| 2167 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2182 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
| 2168 } | 2183 } |
| 2169 | 2184 |
| 2170 } // namespace cricket | 2185 } // namespace cricket |
| OLD | NEW |