| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * libjingle | 2  * libjingle | 
| 3  * Copyright 2012 Google Inc. | 3  * Copyright 2012 Google Inc. | 
| 4  * | 4  * | 
| 5  * Redistribution and use in source and binary forms, with or without | 5  * Redistribution and use in source and binary forms, with or without | 
| 6  * modification, are permitted provided that the following conditions are met: | 6  * modification, are permitted provided that the following conditions are met: | 
| 7  * | 7  * | 
| 8  *  1. Redistributions of source code must retain the above copyright notice, | 8  *  1. Redistributions of source code must retain the above copyright notice, | 
| 9  *     this list of conditions and the following disclaimer. | 9  *     this list of conditions and the following disclaimer. | 
| 10  *  2. Redistributions in binary form must reproduce the above copyright notice, | 10  *  2. Redistributions in binary form must reproduce the above copyright notice, | 
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 258     if (cricket::IsMediaContent(&*iter)) { | 258     if (cricket::IsMediaContent(&*iter)) { | 
| 259       MediaContentDescription* mdesc = | 259       MediaContentDescription* mdesc = | 
| 260           static_cast<MediaContentDescription*> (iter->description); | 260           static_cast<MediaContentDescription*> (iter->description); | 
| 261       if (mdesc) { | 261       if (mdesc) { | 
| 262         mdesc->set_crypto_required(type); | 262         mdesc->set_crypto_required(type); | 
| 263       } | 263       } | 
| 264     } | 264     } | 
| 265   } | 265   } | 
| 266 } | 266 } | 
| 267 | 267 | 
| 268 static bool GetAudioSsrcByTrackId( | 268 static bool GetAudioSsrcByTrackId(const SessionDescription* session_description, | 
| 269     const SessionDescription* session_description, | 269                                   const std::string& track_id, | 
| 270     const std::string& track_id, uint32 *ssrc) { | 270                                   uint32_t* ssrc) { | 
| 271   const cricket::ContentInfo* audio_info = | 271   const cricket::ContentInfo* audio_info = | 
| 272       cricket::GetFirstAudioContent(session_description); | 272       cricket::GetFirstAudioContent(session_description); | 
| 273   if (!audio_info) { | 273   if (!audio_info) { | 
| 274     LOG(LS_ERROR) << "Audio not used in this call"; | 274     LOG(LS_ERROR) << "Audio not used in this call"; | 
| 275     return false; | 275     return false; | 
| 276   } | 276   } | 
| 277 | 277 | 
| 278   const cricket::MediaContentDescription* audio_content = | 278   const cricket::MediaContentDescription* audio_content = | 
| 279       static_cast<const cricket::MediaContentDescription*>( | 279       static_cast<const cricket::MediaContentDescription*>( | 
| 280           audio_info->description); | 280           audio_info->description); | 
| 281   const cricket::StreamParams* stream = | 281   const cricket::StreamParams* stream = | 
| 282       cricket::GetStreamByIds(audio_content->streams(), "", track_id); | 282       cricket::GetStreamByIds(audio_content->streams(), "", track_id); | 
| 283   if (!stream) { | 283   if (!stream) { | 
| 284     return false; | 284     return false; | 
| 285   } | 285   } | 
| 286 | 286 | 
| 287   *ssrc = stream->first_ssrc(); | 287   *ssrc = stream->first_ssrc(); | 
| 288   return true; | 288   return true; | 
| 289 } | 289 } | 
| 290 | 290 | 
| 291 static bool GetTrackIdBySsrc(const SessionDescription* session_description, | 291 static bool GetTrackIdBySsrc(const SessionDescription* session_description, | 
| 292                              uint32 ssrc, std::string* track_id) { | 292                              uint32_t ssrc, | 
|  | 293                              std::string* track_id) { | 
| 293   ASSERT(track_id != NULL); | 294   ASSERT(track_id != NULL); | 
| 294 | 295 | 
| 295   const cricket::ContentInfo* audio_info = | 296   const cricket::ContentInfo* audio_info = | 
| 296       cricket::GetFirstAudioContent(session_description); | 297       cricket::GetFirstAudioContent(session_description); | 
| 297   if (audio_info) { | 298   if (audio_info) { | 
| 298     const cricket::MediaContentDescription* audio_content = | 299     const cricket::MediaContentDescription* audio_content = | 
| 299         static_cast<const cricket::MediaContentDescription*>( | 300         static_cast<const cricket::MediaContentDescription*>( | 
| 300             audio_info->description); | 301             audio_info->description); | 
| 301 | 302 | 
| 302     const auto* found = | 303     const auto* found = | 
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 454   } | 455   } | 
| 455   std::string string_value; | 456   std::string string_value; | 
| 456   T value; | 457   T value; | 
| 457   if (constraints->GetOptional().FindFirst(key, &string_value)) { | 458   if (constraints->GetOptional().FindFirst(key, &string_value)) { | 
| 458     if (rtc::FromString(string_value, &value)) { | 459     if (rtc::FromString(string_value, &value)) { | 
| 459       option->Set(value); | 460       option->Set(value); | 
| 460     } | 461     } | 
| 461   } | 462   } | 
| 462 } | 463 } | 
| 463 | 464 | 
| 464 uint32 ConvertIceTransportTypeToCandidateFilter( | 465 uint32_t ConvertIceTransportTypeToCandidateFilter( | 
| 465     PeerConnectionInterface::IceTransportsType type) { | 466     PeerConnectionInterface::IceTransportsType type) { | 
| 466   switch (type) { | 467   switch (type) { | 
| 467     case PeerConnectionInterface::kNone: | 468     case PeerConnectionInterface::kNone: | 
| 468         return cricket::CF_NONE; | 469         return cricket::CF_NONE; | 
| 469     case PeerConnectionInterface::kRelay: | 470     case PeerConnectionInterface::kRelay: | 
| 470         return cricket::CF_RELAY; | 471         return cricket::CF_RELAY; | 
| 471     case PeerConnectionInterface::kNoHost: | 472     case PeerConnectionInterface::kNoHost: | 
| 472         return (cricket::CF_ALL & ~cricket::CF_HOST); | 473         return (cricket::CF_ALL & ~cricket::CF_HOST); | 
| 473     case PeerConnectionInterface::kAll: | 474     case PeerConnectionInterface::kAll: | 
| 474         return cricket::CF_ALL; | 475         return cricket::CF_ALL; | 
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1205 | 1206 | 
| 1206   return UseCandidate(candidate); | 1207   return UseCandidate(candidate); | 
| 1207 } | 1208 } | 
| 1208 | 1209 | 
| 1209 bool WebRtcSession::SetIceTransports( | 1210 bool WebRtcSession::SetIceTransports( | 
| 1210     PeerConnectionInterface::IceTransportsType type) { | 1211     PeerConnectionInterface::IceTransportsType type) { | 
| 1211   return port_allocator()->set_candidate_filter( | 1212   return port_allocator()->set_candidate_filter( | 
| 1212         ConvertIceTransportTypeToCandidateFilter(type)); | 1213         ConvertIceTransportTypeToCandidateFilter(type)); | 
| 1213 } | 1214 } | 
| 1214 | 1215 | 
| 1215 bool WebRtcSession::GetLocalTrackIdBySsrc(uint32 ssrc, std::string* track_id) { | 1216 bool WebRtcSession::GetLocalTrackIdBySsrc(uint32_t ssrc, | 
|  | 1217                                           std::string* track_id) { | 
| 1216   if (!base_local_description()) | 1218   if (!base_local_description()) | 
| 1217     return false; | 1219     return false; | 
| 1218   return webrtc::GetTrackIdBySsrc(base_local_description(), ssrc, track_id); | 1220   return webrtc::GetTrackIdBySsrc(base_local_description(), ssrc, track_id); | 
| 1219 } | 1221 } | 
| 1220 | 1222 | 
| 1221 bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32 ssrc, std::string* track_id) { | 1223 bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32_t ssrc, | 
|  | 1224                                            std::string* track_id) { | 
| 1222   if (!base_remote_description()) | 1225   if (!base_remote_description()) | 
| 1223     return false; | 1226     return false; | 
| 1224   return webrtc::GetTrackIdBySsrc(base_remote_description(), ssrc, track_id); | 1227   return webrtc::GetTrackIdBySsrc(base_remote_description(), ssrc, track_id); | 
| 1225 } | 1228 } | 
| 1226 | 1229 | 
| 1227 std::string WebRtcSession::BadStateErrMsg(State state) { | 1230 std::string WebRtcSession::BadStateErrMsg(State state) { | 
| 1228   std::ostringstream desc; | 1231   std::ostringstream desc; | 
| 1229   desc << "Called in wrong state: " << GetStateString(state); | 1232   desc << "Called in wrong state: " << GetStateString(state); | 
| 1230   return desc.str(); | 1233   return desc.str(); | 
| 1231 } | 1234 } | 
| 1232 | 1235 | 
| 1233 void WebRtcSession::SetAudioPlayout(uint32 ssrc, bool enable, | 1236 void WebRtcSession::SetAudioPlayout(uint32_t ssrc, | 
|  | 1237                                     bool enable, | 
| 1234                                     cricket::AudioRenderer* renderer) { | 1238                                     cricket::AudioRenderer* renderer) { | 
| 1235   ASSERT(signaling_thread()->IsCurrent()); | 1239   ASSERT(signaling_thread()->IsCurrent()); | 
| 1236   if (!voice_channel_) { | 1240   if (!voice_channel_) { | 
| 1237     LOG(LS_ERROR) << "SetAudioPlayout: No audio channel exists."; | 1241     LOG(LS_ERROR) << "SetAudioPlayout: No audio channel exists."; | 
| 1238     return; | 1242     return; | 
| 1239   } | 1243   } | 
| 1240   if (!voice_channel_->SetRemoteRenderer(ssrc, renderer)) { | 1244   if (!voice_channel_->SetRemoteRenderer(ssrc, renderer)) { | 
| 1241     // SetRenderer() can fail if the ssrc does not match any playout channel. | 1245     // SetRenderer() can fail if the ssrc does not match any playout channel. | 
| 1242     LOG(LS_ERROR) << "SetAudioPlayout: ssrc is incorrect: " << ssrc; | 1246     LOG(LS_ERROR) << "SetAudioPlayout: ssrc is incorrect: " << ssrc; | 
| 1243     return; | 1247     return; | 
| 1244   } | 1248   } | 
| 1245   if (!voice_channel_->SetOutputScaling(ssrc, enable ? 1 : 0, enable ? 1 : 0)) { | 1249   if (!voice_channel_->SetOutputScaling(ssrc, enable ? 1 : 0, enable ? 1 : 0)) { | 
| 1246     // Allow that SetOutputScaling fail if |enable| is false but assert | 1250     // Allow that SetOutputScaling fail if |enable| is false but assert | 
| 1247     // otherwise. This in the normal case when the underlying media channel has | 1251     // otherwise. This in the normal case when the underlying media channel has | 
| 1248     // already been deleted. | 1252     // already been deleted. | 
| 1249     ASSERT(enable == false); | 1253     ASSERT(enable == false); | 
| 1250   } | 1254   } | 
| 1251 } | 1255 } | 
| 1252 | 1256 | 
| 1253 void WebRtcSession::SetAudioSend(uint32 ssrc, bool enable, | 1257 void WebRtcSession::SetAudioSend(uint32_t ssrc, | 
|  | 1258                                  bool enable, | 
| 1254                                  const cricket::AudioOptions& options, | 1259                                  const cricket::AudioOptions& options, | 
| 1255                                  cricket::AudioRenderer* renderer) { | 1260                                  cricket::AudioRenderer* renderer) { | 
| 1256   ASSERT(signaling_thread()->IsCurrent()); | 1261   ASSERT(signaling_thread()->IsCurrent()); | 
| 1257   if (!voice_channel_) { | 1262   if (!voice_channel_) { | 
| 1258     LOG(LS_ERROR) << "SetAudioSend: No audio channel exists."; | 1263     LOG(LS_ERROR) << "SetAudioSend: No audio channel exists."; | 
| 1259     return; | 1264     return; | 
| 1260   } | 1265   } | 
| 1261   if (!voice_channel_->SetAudioSend(ssrc, enable, &options, renderer)) { | 1266   if (!voice_channel_->SetAudioSend(ssrc, enable, &options, renderer)) { | 
| 1262     LOG(LS_ERROR) << "SetAudioSend: ssrc is incorrect: " << ssrc; | 1267     LOG(LS_ERROR) << "SetAudioSend: ssrc is incorrect: " << ssrc; | 
| 1263   } | 1268   } | 
| 1264 } | 1269 } | 
| 1265 | 1270 | 
| 1266 void WebRtcSession::SetAudioPlayoutVolume(uint32 ssrc, double volume) { | 1271 void WebRtcSession::SetAudioPlayoutVolume(uint32_t ssrc, double volume) { | 
| 1267   ASSERT(signaling_thread()->IsCurrent()); | 1272   ASSERT(signaling_thread()->IsCurrent()); | 
| 1268   ASSERT(volume >= 0 && volume <= 10); | 1273   ASSERT(volume >= 0 && volume <= 10); | 
| 1269   if (!voice_channel_) { | 1274   if (!voice_channel_) { | 
| 1270     LOG(LS_ERROR) << "SetAudioPlayoutVolume: No audio channel exists."; | 1275     LOG(LS_ERROR) << "SetAudioPlayoutVolume: No audio channel exists."; | 
| 1271     return; | 1276     return; | 
| 1272   } | 1277   } | 
| 1273 | 1278 | 
| 1274   if (!voice_channel_->SetOutputScaling(ssrc, volume, volume)) { | 1279   if (!voice_channel_->SetOutputScaling(ssrc, volume, volume)) { | 
| 1275     ASSERT(false); | 1280     ASSERT(false); | 
| 1276   } | 1281   } | 
| 1277 } | 1282 } | 
| 1278 | 1283 | 
| 1279 bool WebRtcSession::SetCaptureDevice(uint32 ssrc, | 1284 bool WebRtcSession::SetCaptureDevice(uint32_t ssrc, | 
| 1280                                      cricket::VideoCapturer* camera) { | 1285                                      cricket::VideoCapturer* camera) { | 
| 1281   ASSERT(signaling_thread()->IsCurrent()); | 1286   ASSERT(signaling_thread()->IsCurrent()); | 
| 1282 | 1287 | 
| 1283   if (!video_channel_) { | 1288   if (!video_channel_) { | 
| 1284     // |video_channel_| doesnt't exist. Probably because the remote end doesnt't | 1289     // |video_channel_| doesnt't exist. Probably because the remote end doesnt't | 
| 1285     // support video. | 1290     // support video. | 
| 1286     LOG(LS_WARNING) << "Video not used in this call."; | 1291     LOG(LS_WARNING) << "Video not used in this call."; | 
| 1287     return false; | 1292     return false; | 
| 1288   } | 1293   } | 
| 1289   if (!video_channel_->SetCapturer(ssrc, camera)) { | 1294   if (!video_channel_->SetCapturer(ssrc, camera)) { | 
| 1290     // Allow that SetCapturer fail if |camera| is NULL but assert otherwise. | 1295     // Allow that SetCapturer fail if |camera| is NULL but assert otherwise. | 
| 1291     // This in the normal case when the underlying media channel has already | 1296     // This in the normal case when the underlying media channel has already | 
| 1292     // been deleted. | 1297     // been deleted. | 
| 1293     ASSERT(camera == NULL); | 1298     ASSERT(camera == NULL); | 
| 1294     return false; | 1299     return false; | 
| 1295   } | 1300   } | 
| 1296   return true; | 1301   return true; | 
| 1297 } | 1302 } | 
| 1298 | 1303 | 
| 1299 void WebRtcSession::SetVideoPlayout(uint32 ssrc, | 1304 void WebRtcSession::SetVideoPlayout(uint32_t ssrc, | 
| 1300                                     bool enable, | 1305                                     bool enable, | 
| 1301                                     cricket::VideoRenderer* renderer) { | 1306                                     cricket::VideoRenderer* renderer) { | 
| 1302   ASSERT(signaling_thread()->IsCurrent()); | 1307   ASSERT(signaling_thread()->IsCurrent()); | 
| 1303   if (!video_channel_) { | 1308   if (!video_channel_) { | 
| 1304     LOG(LS_WARNING) << "SetVideoPlayout: No video channel exists."; | 1309     LOG(LS_WARNING) << "SetVideoPlayout: No video channel exists."; | 
| 1305     return; | 1310     return; | 
| 1306   } | 1311   } | 
| 1307   if (!video_channel_->SetRenderer(ssrc, enable ? renderer : NULL)) { | 1312   if (!video_channel_->SetRenderer(ssrc, enable ? renderer : NULL)) { | 
| 1308     // Allow that SetRenderer fail if |renderer| is NULL but assert otherwise. | 1313     // Allow that SetRenderer fail if |renderer| is NULL but assert otherwise. | 
| 1309     // This in the normal case when the underlying media channel has already | 1314     // This in the normal case when the underlying media channel has already | 
| 1310     // been deleted. | 1315     // been deleted. | 
| 1311     ASSERT(renderer == NULL); | 1316     ASSERT(renderer == NULL); | 
| 1312   } | 1317   } | 
| 1313 } | 1318 } | 
| 1314 | 1319 | 
| 1315 void WebRtcSession::SetVideoSend(uint32 ssrc, bool enable, | 1320 void WebRtcSession::SetVideoSend(uint32_t ssrc, | 
|  | 1321                                  bool enable, | 
| 1316                                  const cricket::VideoOptions* options) { | 1322                                  const cricket::VideoOptions* options) { | 
| 1317   ASSERT(signaling_thread()->IsCurrent()); | 1323   ASSERT(signaling_thread()->IsCurrent()); | 
| 1318   if (!video_channel_) { | 1324   if (!video_channel_) { | 
| 1319     LOG(LS_WARNING) << "SetVideoSend: No video channel exists."; | 1325     LOG(LS_WARNING) << "SetVideoSend: No video channel exists."; | 
| 1320     return; | 1326     return; | 
| 1321   } | 1327   } | 
| 1322   if (!video_channel_->SetVideoSend(ssrc, enable, options)) { | 1328   if (!video_channel_->SetVideoSend(ssrc, enable, options)) { | 
| 1323     // Allow that MuteStream fail if |enable| is false but assert otherwise. | 1329     // Allow that MuteStream fail if |enable| is false but assert otherwise. | 
| 1324     // This in the normal case when the underlying media channel has already | 1330     // This in the normal case when the underlying media channel has already | 
| 1325     // been deleted. | 1331     // been deleted. | 
| 1326     ASSERT(enable == false); | 1332     ASSERT(enable == false); | 
| 1327   } | 1333   } | 
| 1328 } | 1334 } | 
| 1329 | 1335 | 
| 1330 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { | 1336 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { | 
| 1331   ASSERT(signaling_thread()->IsCurrent()); | 1337   ASSERT(signaling_thread()->IsCurrent()); | 
| 1332   if (!voice_channel_) { | 1338   if (!voice_channel_) { | 
| 1333     LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; | 1339     LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; | 
| 1334     return false; | 1340     return false; | 
| 1335   } | 1341   } | 
| 1336   uint32 send_ssrc = 0; | 1342   uint32_t send_ssrc = 0; | 
| 1337   // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc | 1343   // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc | 
| 1338   // exists. | 1344   // exists. | 
| 1339   if (!GetAudioSsrcByTrackId(base_local_description(), track_id, | 1345   if (!GetAudioSsrcByTrackId(base_local_description(), track_id, | 
| 1340                              &send_ssrc)) { | 1346                              &send_ssrc)) { | 
| 1341     LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id; | 1347     LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id; | 
| 1342     return false; | 1348     return false; | 
| 1343   } | 1349   } | 
| 1344   return voice_channel_->CanInsertDtmf(); | 1350   return voice_channel_->CanInsertDtmf(); | 
| 1345 } | 1351 } | 
| 1346 | 1352 | 
| 1347 bool WebRtcSession::InsertDtmf(const std::string& track_id, | 1353 bool WebRtcSession::InsertDtmf(const std::string& track_id, | 
| 1348                                int code, int duration) { | 1354                                int code, int duration) { | 
| 1349   ASSERT(signaling_thread()->IsCurrent()); | 1355   ASSERT(signaling_thread()->IsCurrent()); | 
| 1350   if (!voice_channel_) { | 1356   if (!voice_channel_) { | 
| 1351     LOG(LS_ERROR) << "InsertDtmf: No audio channel exists."; | 1357     LOG(LS_ERROR) << "InsertDtmf: No audio channel exists."; | 
| 1352     return false; | 1358     return false; | 
| 1353   } | 1359   } | 
| 1354   uint32 send_ssrc = 0; | 1360   uint32_t send_ssrc = 0; | 
| 1355   if (!VERIFY(GetAudioSsrcByTrackId(base_local_description(), | 1361   if (!VERIFY(GetAudioSsrcByTrackId(base_local_description(), | 
| 1356                                     track_id, &send_ssrc))) { | 1362                                     track_id, &send_ssrc))) { | 
| 1357     LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id; | 1363     LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id; | 
| 1358     return false; | 1364     return false; | 
| 1359   } | 1365   } | 
| 1360   if (!voice_channel_->InsertDtmf(send_ssrc, code, duration, | 1366   if (!voice_channel_->InsertDtmf(send_ssrc, code, duration, | 
| 1361                                   cricket::DF_SEND)) { | 1367                                   cricket::DF_SEND)) { | 
| 1362     LOG(LS_ERROR) << "Failed to insert DTMF to channel."; | 1368     LOG(LS_ERROR) << "Failed to insert DTMF to channel."; | 
| 1363     return false; | 1369     return false; | 
| 1364   } | 1370   } | 
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2173   if (!srtp_cipher.empty()) { | 2179   if (!srtp_cipher.empty()) { | 
| 2174     metrics_observer_->IncrementSparseEnumCounter( | 2180     metrics_observer_->IncrementSparseEnumCounter( | 
| 2175         srtp_counter_type, rtc::GetSrtpCryptoSuiteFromName(srtp_cipher)); | 2181         srtp_counter_type, rtc::GetSrtpCryptoSuiteFromName(srtp_cipher)); | 
| 2176   } | 2182   } | 
| 2177   if (ssl_cipher) { | 2183   if (ssl_cipher) { | 
| 2178     metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, ssl_cipher); | 2184     metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, ssl_cipher); | 
| 2179   } | 2185   } | 
| 2180 } | 2186 } | 
| 2181 | 2187 | 
| 2182 }  // namespace webrtc | 2188 }  // namespace webrtc | 
| OLD | NEW | 
|---|