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 |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 rtc::ToString(matching_codec.id); | 925 rtc::ToString(matching_codec.id); |
926 used_pltypes->FindAndSetIdUsed(&rtx_codec); | 926 used_pltypes->FindAndSetIdUsed(&rtx_codec); |
927 offered_codecs->push_back(rtx_codec); | 927 offered_codecs->push_back(rtx_codec); |
928 } | 928 } |
929 } | 929 } |
930 } | 930 } |
931 | 931 |
932 static bool FindByUri(const RtpHeaderExtensions& extensions, | 932 static bool FindByUri(const RtpHeaderExtensions& extensions, |
933 const webrtc::RtpExtension& ext_to_match, | 933 const webrtc::RtpExtension& ext_to_match, |
934 webrtc::RtpExtension* found_extension) { | 934 webrtc::RtpExtension* found_extension) { |
935 // We assume that all URIs are given in a canonical format. | |
936 const webrtc::RtpExtension* found = | |
937 webrtc::RtpExtension::FindHeaderExtensionByUri(extensions, | |
938 ext_to_match.uri); | |
939 if (!found) { | |
940 return false; | |
941 } | |
942 if (found_extension) { | |
943 *found_extension = *found; | |
944 } | |
945 return true; | |
946 } | |
947 | |
948 static bool FindByUriWithEncryptionPreference( | |
949 const RtpHeaderExtensions& extensions, | |
950 const webrtc::RtpExtension& ext_to_match, bool encryption_preference, | |
951 webrtc::RtpExtension* found_extension) { | |
952 const webrtc::RtpExtension* regular_extension = nullptr; | |
935 for (RtpHeaderExtensions::const_iterator it = extensions.begin(); | 953 for (RtpHeaderExtensions::const_iterator it = extensions.begin(); |
936 it != extensions.end(); ++it) { | 954 it != extensions.end(); ++it) { |
937 // We assume that all URIs are given in a canonical format. | 955 // We assume that all URIs are given in a canonical format. |
938 if (it->uri == ext_to_match.uri) { | 956 if (it->uri == ext_to_match.uri) { |
939 if (found_extension != NULL) { | 957 if (!found_extension) { |
958 return true; | |
959 } | |
960 if (!encryption_preference || it->encrypt) { | |
940 *found_extension = *it; | 961 *found_extension = *it; |
962 return true; | |
941 } | 963 } |
942 return true; | 964 regular_extension = &(*it); |
943 } | 965 } |
944 } | 966 } |
967 if (regular_extension) { | |
968 *found_extension = *regular_extension; | |
969 return true; | |
970 } | |
945 return false; | 971 return false; |
946 } | 972 } |
947 | 973 |
948 // Iterates through |offered_extensions|, adding each one to |all_extensions| | 974 // Iterates through |offered_extensions|, adding each one to |all_extensions| |
949 // and |used_ids|, and resolving ID conflicts. If an offered extension has the | 975 // and |used_ids|, and resolving ID conflicts. If an offered extension has the |
950 // same URI as one in |all_extensions|, it will re-use the same ID and won't be | 976 // same URI as one in |all_extensions|, it will re-use the same ID and won't be |
951 // treated as a conflict. | 977 // treated as a conflict. |
952 static void FindAndSetRtpHdrExtUsed(RtpHeaderExtensions* offered_extensions, | 978 static void FindAndSetRtpHdrExtUsed(RtpHeaderExtensions* offered_extensions, |
953 RtpHeaderExtensions* all_extensions, | 979 RtpHeaderExtensions* all_extensions, |
954 UsedRtpHeaderExtensionIds* used_ids) { | 980 UsedRtpHeaderExtensionIds* used_ids) { |
(...skipping 22 matching lines...) Expand all Loading... | |
977 offered_extensions->push_back(existing); | 1003 offered_extensions->push_back(existing); |
978 } else { | 1004 } else { |
979 used_ids->FindAndSetIdUsed(&reference_extension); | 1005 used_ids->FindAndSetIdUsed(&reference_extension); |
980 all_extensions->push_back(reference_extension); | 1006 all_extensions->push_back(reference_extension); |
981 offered_extensions->push_back(reference_extension); | 1007 offered_extensions->push_back(reference_extension); |
982 } | 1008 } |
983 } | 1009 } |
984 } | 1010 } |
985 } | 1011 } |
986 | 1012 |
1013 static void AddEncryptedVersionsOfHdrExts(RtpHeaderExtensions* extensions, | |
1014 UsedRtpHeaderExtensionIds* used_ids) { | |
1015 RtpHeaderExtensions encrypted_extensions; | |
1016 for (const webrtc::RtpExtension& extension : *extensions) { | |
1017 if (extension.encrypt || | |
Taylor Brandstetter
2017/03/23 20:10:56
Could you leave a comment explaining why "extensio
joachim
2017/03/30 22:43:49
Done and also updated the condition.
| |
1018 !webrtc::RtpExtension::IsEncryptionSupported(extension.uri)) { | |
1019 continue; | |
1020 } | |
1021 | |
1022 webrtc::RtpExtension encrypted(extension); | |
1023 encrypted.encrypt = true; | |
1024 used_ids->FindAndSetIdUsed(&encrypted); | |
Taylor Brandstetter
2017/03/23 20:10:56
If the same encrypted extension is used for audio
joachim
2017/03/30 22:43:49
Done. Also added a test for encrypted id reuse and
| |
1025 encrypted_extensions.push_back(encrypted); | |
1026 } | |
1027 extensions->insert(extensions->end(), encrypted_extensions.begin(), | |
1028 encrypted_extensions.end()); | |
1029 } | |
1030 | |
987 static void NegotiateRtpHeaderExtensions( | 1031 static void NegotiateRtpHeaderExtensions( |
988 const RtpHeaderExtensions& local_extensions, | 1032 const RtpHeaderExtensions& local_extensions, |
989 const RtpHeaderExtensions& offered_extensions, | 1033 const RtpHeaderExtensions& offered_extensions, |
1034 bool enable_encrypted_rtp_header_extensions, | |
990 RtpHeaderExtensions* negotiated_extenstions) { | 1035 RtpHeaderExtensions* negotiated_extenstions) { |
991 RtpHeaderExtensions::const_iterator ours; | 1036 RtpHeaderExtensions::const_iterator ours; |
992 for (ours = local_extensions.begin(); | 1037 for (ours = local_extensions.begin(); |
993 ours != local_extensions.end(); ++ours) { | 1038 ours != local_extensions.end(); ++ours) { |
994 webrtc::RtpExtension theirs; | 1039 webrtc::RtpExtension theirs; |
995 if (FindByUri(offered_extensions, *ours, &theirs)) { | 1040 if (FindByUriWithEncryptionPreference(offered_extensions, *ours, |
1041 enable_encrypted_rtp_header_extensions, &theirs)) { | |
996 // We respond with their RTP header extension id. | 1042 // We respond with their RTP header extension id. |
997 negotiated_extenstions->push_back(theirs); | 1043 negotiated_extenstions->push_back(theirs); |
998 } | 1044 } |
999 } | 1045 } |
1000 } | 1046 } |
1001 | 1047 |
1002 static void StripCNCodecs(AudioCodecs* audio_codecs) { | 1048 static void StripCNCodecs(AudioCodecs* audio_codecs) { |
1003 AudioCodecs::iterator iter = audio_codecs->begin(); | 1049 AudioCodecs::iterator iter = audio_codecs->begin(); |
1004 while (iter != audio_codecs->end()) { | 1050 while (iter != audio_codecs->end()) { |
1005 if (STR_CASE_CMP(iter->name.c_str(), kComfortNoiseCodecName) == 0) { | 1051 if (STR_CASE_CMP(iter->name.c_str(), kComfortNoiseCodecName) == 0) { |
(...skipping 14 matching lines...) Expand all Loading... | |
1020 // from the incoming session-initiate. If the negotiation fails, this | 1066 // from the incoming session-initiate. If the negotiation fails, this |
1021 // method returns false. The created content is added to the offer. | 1067 // method returns false. The created content is added to the offer. |
1022 template <class C> | 1068 template <class C> |
1023 static bool CreateMediaContentAnswer( | 1069 static bool CreateMediaContentAnswer( |
1024 const MediaContentDescriptionImpl<C>* offer, | 1070 const MediaContentDescriptionImpl<C>* offer, |
1025 const MediaSessionOptions& options, | 1071 const MediaSessionOptions& options, |
1026 const std::vector<C>& local_codecs, | 1072 const std::vector<C>& local_codecs, |
1027 const SecurePolicy& sdes_policy, | 1073 const SecurePolicy& sdes_policy, |
1028 const CryptoParamsVec* current_cryptos, | 1074 const CryptoParamsVec* current_cryptos, |
1029 const RtpHeaderExtensions& local_rtp_extenstions, | 1075 const RtpHeaderExtensions& local_rtp_extenstions, |
1076 bool enable_encrypted_rtp_header_extensions, | |
1030 StreamParamsVec* current_streams, | 1077 StreamParamsVec* current_streams, |
1031 bool add_legacy_stream, | 1078 bool add_legacy_stream, |
1032 bool bundle_enabled, | 1079 bool bundle_enabled, |
1033 MediaContentDescriptionImpl<C>* answer) { | 1080 MediaContentDescriptionImpl<C>* answer) { |
1034 std::vector<C> negotiated_codecs; | 1081 std::vector<C> negotiated_codecs; |
1035 NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs); | 1082 NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs); |
1036 answer->AddCodecs(negotiated_codecs); | 1083 answer->AddCodecs(negotiated_codecs); |
1037 answer->set_protocol(offer->protocol()); | 1084 answer->set_protocol(offer->protocol()); |
1038 RtpHeaderExtensions negotiated_rtp_extensions; | 1085 RtpHeaderExtensions negotiated_rtp_extensions; |
1039 NegotiateRtpHeaderExtensions(local_rtp_extenstions, | 1086 NegotiateRtpHeaderExtensions(local_rtp_extenstions, |
1040 offer->rtp_header_extensions(), | 1087 offer->rtp_header_extensions(), |
1088 enable_encrypted_rtp_header_extensions, | |
1041 &negotiated_rtp_extensions); | 1089 &negotiated_rtp_extensions); |
1042 answer->set_rtp_header_extensions(negotiated_rtp_extensions); | 1090 answer->set_rtp_header_extensions(negotiated_rtp_extensions); |
1043 | 1091 |
1044 answer->set_rtcp_mux(options.rtcp_mux_enabled && offer->rtcp_mux()); | 1092 answer->set_rtcp_mux(options.rtcp_mux_enabled && offer->rtcp_mux()); |
1045 if (answer->type() == cricket::MEDIA_TYPE_VIDEO) { | 1093 if (answer->type() == cricket::MEDIA_TYPE_VIDEO) { |
1046 answer->set_rtcp_reduced_size(offer->rtcp_reduced_size()); | 1094 answer->set_rtcp_reduced_size(offer->rtcp_reduced_size()); |
1047 } | 1095 } |
1048 | 1096 |
1049 if (sdes_policy != SEC_DISABLED) { | 1097 if (sdes_policy != SEC_DISABLED) { |
1050 CryptoParams crypto; | 1098 CryptoParams crypto; |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1598 FindAndSetRtpHdrExtUsed(video_extensions, &all_extensions, &used_ids); | 1646 FindAndSetRtpHdrExtUsed(video_extensions, &all_extensions, &used_ids); |
1599 } | 1647 } |
1600 } | 1648 } |
1601 | 1649 |
1602 // Add our default RTP header extensions that are not in | 1650 // Add our default RTP header extensions that are not in |
1603 // |current_description|. | 1651 // |current_description|. |
1604 FindRtpHdrExtsToOffer(audio_rtp_header_extensions(), audio_extensions, | 1652 FindRtpHdrExtsToOffer(audio_rtp_header_extensions(), audio_extensions, |
1605 &all_extensions, &used_ids); | 1653 &all_extensions, &used_ids); |
1606 FindRtpHdrExtsToOffer(video_rtp_header_extensions(), video_extensions, | 1654 FindRtpHdrExtsToOffer(video_rtp_header_extensions(), video_extensions, |
1607 &all_extensions, &used_ids); | 1655 &all_extensions, &used_ids); |
1656 if (enable_encrypted_rtp_header_extensions_) { | |
1657 AddEncryptedVersionsOfHdrExts(audio_extensions, &used_ids); | |
1658 AddEncryptedVersionsOfHdrExts(video_extensions, &used_ids); | |
1659 } | |
1608 } | 1660 } |
1609 | 1661 |
1610 bool MediaSessionDescriptionFactory::AddTransportOffer( | 1662 bool MediaSessionDescriptionFactory::AddTransportOffer( |
1611 const std::string& content_name, | 1663 const std::string& content_name, |
1612 const TransportOptions& transport_options, | 1664 const TransportOptions& transport_options, |
1613 const SessionDescription* current_desc, | 1665 const SessionDescription* current_desc, |
1614 SessionDescription* offer_desc) const { | 1666 SessionDescription* offer_desc) const { |
1615 if (!transport_desc_factory_) | 1667 if (!transport_desc_factory_) |
1616 return false; | 1668 return false; |
1617 const TransportDescription* current_tdesc = | 1669 const TransportDescription* current_tdesc = |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1871 // Do not require or create SDES cryptos if DTLS is used. | 1923 // Do not require or create SDES cryptos if DTLS is used. |
1872 cricket::SecurePolicy sdes_policy = | 1924 cricket::SecurePolicy sdes_policy = |
1873 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); | 1925 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); |
1874 if (!CreateMediaContentAnswer( | 1926 if (!CreateMediaContentAnswer( |
1875 offer_audio, | 1927 offer_audio, |
1876 options, | 1928 options, |
1877 audio_codecs, | 1929 audio_codecs, |
1878 sdes_policy, | 1930 sdes_policy, |
1879 GetCryptos(GetFirstAudioContentDescription(current_description)), | 1931 GetCryptos(GetFirstAudioContentDescription(current_description)), |
1880 audio_rtp_extensions_, | 1932 audio_rtp_extensions_, |
1933 enable_encrypted_rtp_header_extensions_, | |
1881 current_streams, | 1934 current_streams, |
1882 add_legacy_, | 1935 add_legacy_, |
1883 bundle_enabled, | 1936 bundle_enabled, |
1884 audio_answer.get())) { | 1937 audio_answer.get())) { |
1885 return false; // Fails the session setup. | 1938 return false; // Fails the session setup. |
1886 } | 1939 } |
1887 | 1940 |
1888 bool secure = bundle_transport ? bundle_transport->description.secure() | 1941 bool secure = bundle_transport ? bundle_transport->description.secure() |
1889 : audio_transport->secure(); | 1942 : audio_transport->secure(); |
1890 bool rejected = !options.has_audio() || audio_content->rejected || | 1943 bool rejected = !options.has_audio() || audio_content->rejected || |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1927 bool bundle_enabled = | 1980 bool bundle_enabled = |
1928 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | 1981 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; |
1929 if (!CreateMediaContentAnswer( | 1982 if (!CreateMediaContentAnswer( |
1930 static_cast<const VideoContentDescription*>( | 1983 static_cast<const VideoContentDescription*>( |
1931 video_content->description), | 1984 video_content->description), |
1932 options, | 1985 options, |
1933 video_codecs_, | 1986 video_codecs_, |
1934 sdes_policy, | 1987 sdes_policy, |
1935 GetCryptos(GetFirstVideoContentDescription(current_description)), | 1988 GetCryptos(GetFirstVideoContentDescription(current_description)), |
1936 video_rtp_extensions_, | 1989 video_rtp_extensions_, |
1990 enable_encrypted_rtp_header_extensions_, | |
1937 current_streams, | 1991 current_streams, |
1938 add_legacy_, | 1992 add_legacy_, |
1939 bundle_enabled, | 1993 bundle_enabled, |
1940 video_answer.get())) { | 1994 video_answer.get())) { |
1941 return false; | 1995 return false; |
1942 } | 1996 } |
1943 bool secure = bundle_transport ? bundle_transport->description.secure() | 1997 bool secure = bundle_transport ? bundle_transport->description.secure() |
1944 : video_transport->secure(); | 1998 : video_transport->secure(); |
1945 bool rejected = !options.has_video() || video_content->rejected || | 1999 bool rejected = !options.has_video() || video_content->rejected || |
1946 !IsMediaProtocolSupported(MEDIA_TYPE_VIDEO, | 2000 !IsMediaProtocolSupported(MEDIA_TYPE_VIDEO, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1988 bool bundle_enabled = | 2042 bool bundle_enabled = |
1989 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | 2043 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; |
1990 if (!CreateMediaContentAnswer( | 2044 if (!CreateMediaContentAnswer( |
1991 static_cast<const DataContentDescription*>( | 2045 static_cast<const DataContentDescription*>( |
1992 data_content->description), | 2046 data_content->description), |
1993 options, | 2047 options, |
1994 data_codecs_, | 2048 data_codecs_, |
1995 sdes_policy, | 2049 sdes_policy, |
1996 GetCryptos(GetFirstDataContentDescription(current_description)), | 2050 GetCryptos(GetFirstDataContentDescription(current_description)), |
1997 RtpHeaderExtensions(), | 2051 RtpHeaderExtensions(), |
2052 enable_encrypted_rtp_header_extensions_, | |
1998 current_streams, | 2053 current_streams, |
1999 add_legacy_, | 2054 add_legacy_, |
2000 bundle_enabled, | 2055 bundle_enabled, |
2001 data_answer.get())) { | 2056 data_answer.get())) { |
2002 return false; // Fails the session setup. | 2057 return false; // Fails the session setup. |
2003 } | 2058 } |
2004 | 2059 |
2005 // Respond with sctpmap if the offer uses sctpmap. | 2060 // Respond with sctpmap if the offer uses sctpmap. |
2006 const DataContentDescription* offer_data_description = | 2061 const DataContentDescription* offer_data_description = |
2007 static_cast<const DataContentDescription*>(data_content->description); | 2062 static_cast<const DataContentDescription*>(data_content->description); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2183 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 2238 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
2184 } | 2239 } |
2185 | 2240 |
2186 DataContentDescription* GetFirstDataContentDescription( | 2241 DataContentDescription* GetFirstDataContentDescription( |
2187 SessionDescription* sdesc) { | 2242 SessionDescription* sdesc) { |
2188 return static_cast<DataContentDescription*>( | 2243 return static_cast<DataContentDescription*>( |
2189 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2244 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
2190 } | 2245 } |
2191 | 2246 |
2192 } // namespace cricket | 2247 } // namespace cricket |
OLD | NEW |