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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 func(&crypto_suites); | 43 func(&crypto_suites); |
44 for (const auto crypto : crypto_suites) { | 44 for (const auto crypto : crypto_suites) { |
45 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); | 45 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); |
46 } | 46 } |
47 #endif | 47 #endif |
48 } | 48 } |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 namespace cricket { | 51 namespace cricket { |
52 | 52 |
53 namespace { | |
54 std::vector<AudioCodec> MergeAudioCodecLists( | |
55 const std::vector<AudioCodec>& send_codecs, | |
56 const std::vector<AudioCodec>& recv_codecs); | |
57 } | |
53 | 58 |
54 // RTP Profile names | 59 // RTP Profile names |
55 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml | 60 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml |
56 // RFC4585 | 61 // RFC4585 |
57 const char kMediaProtocolAvpf[] = "RTP/AVPF"; | 62 const char kMediaProtocolAvpf[] = "RTP/AVPF"; |
58 // RFC5124 | 63 // RFC5124 |
59 const char kMediaProtocolDtlsSavpf[] = "UDP/TLS/RTP/SAVPF"; | 64 const char kMediaProtocolDtlsSavpf[] = "UDP/TLS/RTP/SAVPF"; |
60 | 65 |
61 // We always generate offers with "UDP/TLS/RTP/SAVPF" when using DTLS-SRTP, | 66 // We always generate offers with "UDP/TLS/RTP/SAVPF" when using DTLS-SRTP, |
62 // but we tolerate "RTP/SAVPF" in offers we receive, for compatibility. | 67 // but we tolerate "RTP/SAVPF" in offers we receive, for compatibility. |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 add_legacy_(true), | 1250 add_legacy_(true), |
1246 transport_desc_factory_(transport_desc_factory) { | 1251 transport_desc_factory_(transport_desc_factory) { |
1247 } | 1252 } |
1248 | 1253 |
1249 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( | 1254 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
1250 ChannelManager* channel_manager, | 1255 ChannelManager* channel_manager, |
1251 const TransportDescriptionFactory* transport_desc_factory) | 1256 const TransportDescriptionFactory* transport_desc_factory) |
1252 : secure_(SEC_DISABLED), | 1257 : secure_(SEC_DISABLED), |
1253 add_legacy_(true), | 1258 add_legacy_(true), |
1254 transport_desc_factory_(transport_desc_factory) { | 1259 transport_desc_factory_(transport_desc_factory) { |
1255 channel_manager->GetSupportedAudioCodecs(&audio_sendrecv_codecs_); | 1260 channel_manager->GetSupportedAudioSendCodecs(&audio_send_codecs_); |
1261 channel_manager->GetSupportedAudioReceiveCodecs(&audio_recv_codecs_); | |
1262 channel_manager->GetSupportedAudioSendCodecs(&audio_send_codecs_); | |
1256 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); | 1263 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); |
1257 channel_manager->GetSupportedVideoCodecs(&video_codecs_); | 1264 channel_manager->GetSupportedVideoCodecs(&video_codecs_); |
1258 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); | 1265 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); |
1259 channel_manager->GetSupportedDataCodecs(&data_codecs_); | 1266 channel_manager->GetSupportedDataCodecs(&data_codecs_); |
1260 audio_send_codecs_ = audio_sendrecv_codecs_; | 1267 audio_sendrecv_codecs_ = |
1261 audio_recv_codecs_ = audio_sendrecv_codecs_; | 1268 MergeAudioCodecLists(audio_send_codecs_, audio_recv_codecs_); |
1262 } | 1269 } |
1263 | 1270 |
1264 const AudioCodecs& MediaSessionDescriptionFactory::audio_codecs() const { | 1271 const AudioCodecs& MediaSessionDescriptionFactory::audio_codecs() const { |
pthatcher1
2016/05/31 18:26:48
I don't think this is called by anything except on
ossu
2016/06/01 08:34:12
Good call! Will do that.
| |
1265 return audio_sendrecv_codecs_; | 1272 return audio_sendrecv_codecs_; |
1266 } | 1273 } |
1267 | 1274 |
1268 const AudioCodecs& MediaSessionDescriptionFactory::audio_send_codecs() const { | 1275 const AudioCodecs& MediaSessionDescriptionFactory::audio_send_codecs() const { |
1269 return audio_send_codecs_; | 1276 return audio_send_codecs_; |
1270 } | 1277 } |
1271 | 1278 |
1272 const AudioCodecs& MediaSessionDescriptionFactory::audio_recv_codecs() const { | 1279 const AudioCodecs& MediaSessionDescriptionFactory::audio_recv_codecs() const { |
1273 return audio_recv_codecs_; | 1280 return audio_recv_codecs_; |
1274 } | 1281 } |
1275 | 1282 |
1276 void MediaSessionDescriptionFactory::set_audio_codecs( | 1283 void MediaSessionDescriptionFactory::set_audio_codecs( |
1277 const AudioCodecs& send_and_recv_codecs) { | 1284 const AudioCodecs& send_and_recv_codecs) { |
1278 audio_send_codecs_ = send_and_recv_codecs; | 1285 audio_send_codecs_ = send_and_recv_codecs; |
1279 audio_recv_codecs_ = send_and_recv_codecs; | 1286 audio_recv_codecs_ = send_and_recv_codecs; |
1280 audio_sendrecv_codecs_ = send_and_recv_codecs; | 1287 audio_sendrecv_codecs_ = send_and_recv_codecs; |
1281 } | 1288 } |
1282 | 1289 |
1283 void MediaSessionDescriptionFactory::set_audio_codecs( | 1290 void MediaSessionDescriptionFactory::set_audio_codecs( |
1284 const AudioCodecs& send_codecs, const AudioCodecs& recv_codecs) { | 1291 const AudioCodecs& send_codecs, const AudioCodecs& recv_codecs) { |
1285 audio_send_codecs_ = send_codecs; | 1292 audio_send_codecs_ = send_codecs; |
1286 audio_recv_codecs_ = recv_codecs; | 1293 audio_recv_codecs_ = recv_codecs; |
1287 audio_sendrecv_codecs_.clear(); | 1294 audio_sendrecv_codecs_ = |
1288 | 1295 MergeAudioCodecLists(audio_send_codecs_, audio_recv_codecs_); |
1289 // Intersect the two lists of codecs, preserving the order of the send codecs. | |
1290 // If there's any difference in priorities, chances are encoding is more | |
1291 // expensive than decoding, and high-priority send codecs are likely handled | |
1292 // better (e.g. through hardware encoder support) than low-priority ones. | |
1293 // TODO(ossu): This is O(n^2). However, each list should generally be small | |
1294 // enough for this to not be a problem. They are also nicely local in memory | |
1295 // like this. | |
1296 for (const auto& sc : audio_send_codecs_) { | |
1297 for (const auto& rc : audio_recv_codecs_) { | |
1298 const size_t send_channels = (sc.channels == 0) ? 1 : sc.channels; | |
1299 const size_t recv_channels = (rc.channels == 0) ? 1 : rc.channels; | |
1300 if (sc.clockrate == rc.clockrate && | |
1301 sc.bitrate == rc.bitrate && | |
1302 send_channels == recv_channels && | |
1303 (_stricmp(sc.name.c_str(), rc.name.c_str()) == 0) && | |
1304 sc.params == rc.params && | |
1305 sc.feedback_params == rc.feedback_params) { | |
1306 AudioCodec out_codec = sc; | |
1307 out_codec.channels = send_channels; | |
1308 audio_sendrecv_codecs_.push_back(out_codec); | |
1309 break; | |
1310 } | |
1311 } | |
1312 } | |
1313 } | 1296 } |
1314 | 1297 |
1315 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( | 1298 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( |
1316 const MediaSessionOptions& options, | 1299 const MediaSessionOptions& options, |
1317 const SessionDescription* current_description) const { | 1300 const SessionDescription* current_description) const { |
1318 std::unique_ptr<SessionDescription> offer(new SessionDescription()); | 1301 std::unique_ptr<SessionDescription> offer(new SessionDescription()); |
1319 | 1302 |
1320 StreamParamsVec current_streams; | 1303 StreamParamsVec current_streams; |
1321 GetCurrentStreamParams(current_description, ¤t_streams); | 1304 GetCurrentStreamParams(current_description, ¤t_streams); |
1322 | 1305 |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2108 return static_cast<const VideoContentDescription*>( | 2091 return static_cast<const VideoContentDescription*>( |
2109 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 2092 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
2110 } | 2093 } |
2111 | 2094 |
2112 const DataContentDescription* GetFirstDataContentDescription( | 2095 const DataContentDescription* GetFirstDataContentDescription( |
2113 const SessionDescription* sdesc) { | 2096 const SessionDescription* sdesc) { |
2114 return static_cast<const DataContentDescription*>( | 2097 return static_cast<const DataContentDescription*>( |
2115 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2098 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
2116 } | 2099 } |
2117 | 2100 |
2101 namespace { | |
2102 std::vector<AudioCodec> MergeAudioCodecLists( | |
pthatcher1
2016/05/31 18:26:48
Can you call this MergeSendRecvCodecs?
ossu
2016/06/01 08:34:12
Sure thing!
| |
2103 const std::vector<AudioCodec>& send_codecs, | |
2104 const std::vector<AudioCodec>& recv_codecs) { | |
2105 std::vector<AudioCodec> merged; | |
2106 // Intersect the two lists of codecs, preserving the order of the send codecs. | |
2107 // If there's any difference in priorities, chances are encoding is more | |
2108 // expensive than decoding, and high-priority send codecs are likely handled | |
2109 // better (e.g. through hardware encoder support) than low-priority ones. | |
2110 // TODO(ossu): This is O(n^2). However, each list should generally be small | |
2111 // enough for this to not be a problem. They are also nicely local in memory | |
2112 // like this. | |
2113 for (const auto& sc : send_codecs) { | |
2114 for (const auto& rc : recv_codecs) { | |
2115 const size_t send_channels = (sc.channels == 0) ? 1 : sc.channels; | |
2116 const size_t recv_channels = (rc.channels == 0) ? 1 : rc.channels; | |
2117 if (sc.clockrate == rc.clockrate && sc.bitrate == rc.bitrate && | |
ossu
2016/05/26 14:18:50
This got clang-formatted. I'll put it back to one
| |
2118 send_channels == recv_channels && | |
2119 (_stricmp(sc.name.c_str(), rc.name.c_str()) == 0) && | |
2120 sc.params == rc.params && sc.feedback_params == rc.feedback_params) { | |
2121 AudioCodec out_codec = sc; | |
2122 out_codec.channels = send_channels; | |
2123 merged.push_back(out_codec); | |
2124 break; | |
2125 } | |
2126 } | |
2127 } | |
2128 | |
2129 return merged; | |
2130 } | |
2131 } | |
2132 | |
2118 } // namespace cricket | 2133 } // namespace cricket |
OLD | NEW |