OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 } | 1162 } |
1163 return webrtc::GetTrackIdBySsrc(remote_desc_->description(), ssrc, track_id); | 1163 return webrtc::GetTrackIdBySsrc(remote_desc_->description(), ssrc, track_id); |
1164 } | 1164 } |
1165 | 1165 |
1166 std::string WebRtcSession::BadStateErrMsg(State state) { | 1166 std::string WebRtcSession::BadStateErrMsg(State state) { |
1167 std::ostringstream desc; | 1167 std::ostringstream desc; |
1168 desc << "Called in wrong state: " << GetStateString(state); | 1168 desc << "Called in wrong state: " << GetStateString(state); |
1169 return desc.str(); | 1169 return desc.str(); |
1170 } | 1170 } |
1171 | 1171 |
| 1172 void WebRtcSession::SetAudioPlayout(uint32_t ssrc, bool enable) { |
| 1173 ASSERT(signaling_thread()->IsCurrent()); |
| 1174 if (!voice_channel_) { |
| 1175 LOG(LS_ERROR) << "SetAudioPlayout: No audio channel exists."; |
| 1176 return; |
| 1177 } |
| 1178 if (!voice_channel_->SetOutputVolume(ssrc, enable ? 1 : 0)) { |
| 1179 // Allow that SetOutputVolume fail if |enable| is false but assert |
| 1180 // otherwise. This in the normal case when the underlying media channel has |
| 1181 // already been deleted. |
| 1182 ASSERT(enable == false); |
| 1183 } |
| 1184 } |
| 1185 |
| 1186 void WebRtcSession::SetAudioSend(uint32_t ssrc, |
| 1187 bool enable, |
| 1188 const cricket::AudioOptions& options, |
| 1189 cricket::AudioSource* source) { |
| 1190 ASSERT(signaling_thread()->IsCurrent()); |
| 1191 if (!voice_channel_) { |
| 1192 LOG(LS_ERROR) << "SetAudioSend: No audio channel exists."; |
| 1193 return; |
| 1194 } |
| 1195 if (!voice_channel_->SetAudioSend(ssrc, enable, &options, source)) { |
| 1196 LOG(LS_ERROR) << "SetAudioSend: ssrc is incorrect: " << ssrc; |
| 1197 } |
| 1198 } |
| 1199 |
| 1200 void WebRtcSession::SetAudioPlayoutVolume(uint32_t ssrc, double volume) { |
| 1201 ASSERT(signaling_thread()->IsCurrent()); |
| 1202 ASSERT(volume >= 0 && volume <= 10); |
| 1203 if (!voice_channel_) { |
| 1204 LOG(LS_ERROR) << "SetAudioPlayoutVolume: No audio channel exists."; |
| 1205 return; |
| 1206 } |
| 1207 |
| 1208 if (!voice_channel_->SetOutputVolume(ssrc, volume)) { |
| 1209 ASSERT(false); |
| 1210 } |
| 1211 } |
| 1212 |
| 1213 void WebRtcSession::SetRawAudioSink(uint32_t ssrc, |
| 1214 std::unique_ptr<AudioSinkInterface> sink) { |
| 1215 ASSERT(signaling_thread()->IsCurrent()); |
| 1216 if (!voice_channel_) |
| 1217 return; |
| 1218 |
| 1219 voice_channel_->SetRawAudioSink(ssrc, std::move(sink)); |
| 1220 } |
| 1221 |
| 1222 RtpParameters WebRtcSession::GetAudioRtpSendParameters(uint32_t ssrc) const { |
| 1223 ASSERT(signaling_thread()->IsCurrent()); |
| 1224 if (voice_channel_) { |
| 1225 return voice_channel_->GetRtpSendParameters(ssrc); |
| 1226 } |
| 1227 return RtpParameters(); |
| 1228 } |
| 1229 |
| 1230 bool WebRtcSession::SetAudioRtpSendParameters(uint32_t ssrc, |
| 1231 const RtpParameters& parameters) { |
| 1232 ASSERT(signaling_thread()->IsCurrent()); |
| 1233 if (!voice_channel_) { |
| 1234 return false; |
| 1235 } |
| 1236 return voice_channel_->SetRtpSendParameters(ssrc, parameters); |
| 1237 } |
| 1238 |
| 1239 RtpParameters WebRtcSession::GetAudioRtpReceiveParameters(uint32_t ssrc) const { |
| 1240 ASSERT(signaling_thread()->IsCurrent()); |
| 1241 if (voice_channel_) { |
| 1242 return voice_channel_->GetRtpReceiveParameters(ssrc); |
| 1243 } |
| 1244 return RtpParameters(); |
| 1245 } |
| 1246 |
| 1247 bool WebRtcSession::SetAudioRtpReceiveParameters( |
| 1248 uint32_t ssrc, |
| 1249 const RtpParameters& parameters) { |
| 1250 ASSERT(signaling_thread()->IsCurrent()); |
| 1251 if (!voice_channel_) { |
| 1252 return false; |
| 1253 } |
| 1254 return voice_channel_->SetRtpReceiveParameters(ssrc, parameters); |
| 1255 } |
| 1256 |
| 1257 void WebRtcSession::SetVideoPlayout( |
| 1258 uint32_t ssrc, |
| 1259 bool enable, |
| 1260 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) { |
| 1261 ASSERT(signaling_thread()->IsCurrent()); |
| 1262 if (!video_channel_) { |
| 1263 LOG(LS_WARNING) << "SetVideoPlayout: No video channel exists."; |
| 1264 return; |
| 1265 } |
| 1266 if (!video_channel_->SetSink(ssrc, enable ? sink : NULL)) { |
| 1267 // Allow that SetSink fail if |sink| is NULL but assert otherwise. |
| 1268 // This in the normal case when the underlying media channel has already |
| 1269 // been deleted. |
| 1270 ASSERT(sink == NULL); |
| 1271 } |
| 1272 } |
| 1273 |
| 1274 void WebRtcSession::SetVideoSend( |
| 1275 uint32_t ssrc, |
| 1276 bool enable, |
| 1277 const cricket::VideoOptions* options, |
| 1278 rtc::VideoSourceInterface<cricket::VideoFrame>* source) { |
| 1279 ASSERT(signaling_thread()->IsCurrent()); |
| 1280 if (!video_channel_) { |
| 1281 LOG(LS_WARNING) << "SetVideoSend: No video channel exists."; |
| 1282 return; |
| 1283 } |
| 1284 if (!video_channel_->SetVideoSend(ssrc, enable, options, source)) { |
| 1285 // Allow that MuteStream fail if |enable| is false and |source| is NULL but |
| 1286 // assert otherwise. This in the normal case when the underlying media |
| 1287 // channel has already been deleted. |
| 1288 ASSERT(enable == false && source == nullptr); |
| 1289 } |
| 1290 } |
| 1291 |
| 1292 RtpParameters WebRtcSession::GetVideoRtpSendParameters(uint32_t ssrc) const { |
| 1293 ASSERT(signaling_thread()->IsCurrent()); |
| 1294 if (video_channel_) { |
| 1295 return video_channel_->GetRtpSendParameters(ssrc); |
| 1296 } |
| 1297 return RtpParameters(); |
| 1298 } |
| 1299 |
| 1300 bool WebRtcSession::SetVideoRtpSendParameters(uint32_t ssrc, |
| 1301 const RtpParameters& parameters) { |
| 1302 ASSERT(signaling_thread()->IsCurrent()); |
| 1303 if (!video_channel_) { |
| 1304 return false; |
| 1305 } |
| 1306 return video_channel_->SetRtpSendParameters(ssrc, parameters); |
| 1307 } |
| 1308 |
| 1309 RtpParameters WebRtcSession::GetVideoRtpReceiveParameters(uint32_t ssrc) const { |
| 1310 ASSERT(signaling_thread()->IsCurrent()); |
| 1311 if (video_channel_) { |
| 1312 return video_channel_->GetRtpReceiveParameters(ssrc); |
| 1313 } |
| 1314 return RtpParameters(); |
| 1315 } |
| 1316 |
| 1317 bool WebRtcSession::SetVideoRtpReceiveParameters( |
| 1318 uint32_t ssrc, |
| 1319 const RtpParameters& parameters) { |
| 1320 ASSERT(signaling_thread()->IsCurrent()); |
| 1321 if (!video_channel_) { |
| 1322 return false; |
| 1323 } |
| 1324 return video_channel_->SetRtpReceiveParameters(ssrc, parameters); |
| 1325 } |
| 1326 |
1172 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { | 1327 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { |
1173 ASSERT(signaling_thread()->IsCurrent()); | 1328 ASSERT(signaling_thread()->IsCurrent()); |
1174 if (!voice_channel_) { | 1329 if (!voice_channel_) { |
1175 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; | 1330 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; |
1176 return false; | 1331 return false; |
1177 } | 1332 } |
1178 uint32_t send_ssrc = 0; | 1333 uint32_t send_ssrc = 0; |
1179 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc | 1334 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc |
1180 // exists. | 1335 // exists. |
1181 if (!local_desc_ || | 1336 if (!local_desc_ || |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 bundle_transport, create_rtcp_transport_channel, audio_options_)); | 1760 bundle_transport, create_rtcp_transport_channel, audio_options_)); |
1606 if (!voice_channel_) { | 1761 if (!voice_channel_) { |
1607 return false; | 1762 return false; |
1608 } | 1763 } |
1609 if (require_rtcp_mux) { | 1764 if (require_rtcp_mux) { |
1610 voice_channel_->ActivateRtcpMux(); | 1765 voice_channel_->ActivateRtcpMux(); |
1611 } | 1766 } |
1612 | 1767 |
1613 voice_channel_->SignalDtlsSetupFailure.connect( | 1768 voice_channel_->SignalDtlsSetupFailure.connect( |
1614 this, &WebRtcSession::OnDtlsSetupFailure); | 1769 this, &WebRtcSession::OnDtlsSetupFailure); |
| 1770 voice_channel_->SignalFirstPacketReceived.connect( |
| 1771 this, &WebRtcSession::OnChannelFirstPacketReceived); |
1615 | 1772 |
1616 SignalVoiceChannelCreated(); | 1773 SignalVoiceChannelCreated(); |
1617 voice_channel_->SignalSentPacket.connect(this, | 1774 voice_channel_->SignalSentPacket.connect(this, |
1618 &WebRtcSession::OnSentPacket_w); | 1775 &WebRtcSession::OnSentPacket_w); |
1619 return true; | 1776 return true; |
1620 } | 1777 } |
1621 | 1778 |
1622 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content, | 1779 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content, |
1623 const std::string* bundle_transport) { | 1780 const std::string* bundle_transport) { |
1624 bool require_rtcp_mux = | 1781 bool require_rtcp_mux = |
1625 rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; | 1782 rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; |
1626 bool create_rtcp_transport_channel = !require_rtcp_mux; | 1783 bool create_rtcp_transport_channel = !require_rtcp_mux; |
1627 video_channel_.reset(channel_manager_->CreateVideoChannel( | 1784 video_channel_.reset(channel_manager_->CreateVideoChannel( |
1628 media_controller_, transport_controller_.get(), content->name, | 1785 media_controller_, transport_controller_.get(), content->name, |
1629 bundle_transport, create_rtcp_transport_channel, video_options_)); | 1786 bundle_transport, create_rtcp_transport_channel, video_options_)); |
1630 if (!video_channel_) { | 1787 if (!video_channel_) { |
1631 return false; | 1788 return false; |
1632 } | 1789 } |
1633 if (require_rtcp_mux) { | 1790 if (require_rtcp_mux) { |
1634 video_channel_->ActivateRtcpMux(); | 1791 video_channel_->ActivateRtcpMux(); |
1635 } | 1792 } |
1636 video_channel_->SignalDtlsSetupFailure.connect( | 1793 video_channel_->SignalDtlsSetupFailure.connect( |
1637 this, &WebRtcSession::OnDtlsSetupFailure); | 1794 this, &WebRtcSession::OnDtlsSetupFailure); |
| 1795 video_channel_->SignalFirstPacketReceived.connect( |
| 1796 this, &WebRtcSession::OnChannelFirstPacketReceived); |
1638 | 1797 |
1639 SignalVideoChannelCreated(); | 1798 SignalVideoChannelCreated(); |
1640 video_channel_->SignalSentPacket.connect(this, | 1799 video_channel_->SignalSentPacket.connect(this, |
1641 &WebRtcSession::OnSentPacket_w); | 1800 &WebRtcSession::OnSentPacket_w); |
1642 return true; | 1801 return true; |
1643 } | 1802 } |
1644 | 1803 |
1645 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content, | 1804 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content, |
1646 const std::string* bundle_transport) { | 1805 const std::string* bundle_transport) { |
1647 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); | 1806 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); |
(...skipping 21 matching lines...) Expand all Loading... |
1669 SignalDataChannelCreated(); | 1828 SignalDataChannelCreated(); |
1670 data_channel_->SignalSentPacket.connect(this, &WebRtcSession::OnSentPacket_w); | 1829 data_channel_->SignalSentPacket.connect(this, &WebRtcSession::OnSentPacket_w); |
1671 return true; | 1830 return true; |
1672 } | 1831 } |
1673 | 1832 |
1674 void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) { | 1833 void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) { |
1675 SetError(ERROR_TRANSPORT, | 1834 SetError(ERROR_TRANSPORT, |
1676 rtcp ? kDtlsSetupFailureRtcp : kDtlsSetupFailureRtp); | 1835 rtcp ? kDtlsSetupFailureRtcp : kDtlsSetupFailureRtp); |
1677 } | 1836 } |
1678 | 1837 |
| 1838 void WebRtcSession::OnChannelFirstPacketReceived( |
| 1839 cricket::BaseChannel* channel) { |
| 1840 ASSERT(signaling_thread()->IsCurrent()); |
| 1841 |
| 1842 if (!received_first_audio_packet_ && |
| 1843 channel->media_type() == cricket::MEDIA_TYPE_AUDIO) { |
| 1844 received_first_audio_packet_ = true; |
| 1845 SignalFirstAudioPacketReceived(); |
| 1846 } else if (!received_first_video_packet_ && |
| 1847 channel->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1848 received_first_video_packet_ = true; |
| 1849 SignalFirstVideoPacketReceived(); |
| 1850 } |
| 1851 } |
| 1852 |
1679 void WebRtcSession::OnDataChannelMessageReceived( | 1853 void WebRtcSession::OnDataChannelMessageReceived( |
1680 cricket::DataChannel* channel, | 1854 cricket::DataChannel* channel, |
1681 const cricket::ReceiveDataParams& params, | 1855 const cricket::ReceiveDataParams& params, |
1682 const rtc::CopyOnWriteBuffer& payload) { | 1856 const rtc::CopyOnWriteBuffer& payload) { |
1683 RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); | 1857 RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); |
1684 if (params.type == cricket::DMT_CONTROL && IsOpenMessage(payload)) { | 1858 if (params.type == cricket::DMT_CONTROL && IsOpenMessage(payload)) { |
1685 // Received OPEN message; parse and signal that a new data channel should | 1859 // Received OPEN message; parse and signal that a new data channel should |
1686 // be created. | 1860 // be created. |
1687 std::string label; | 1861 std::string label; |
1688 InternalDataChannelInit config; | 1862 InternalDataChannelInit config; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 ssl_cipher_suite); | 2161 ssl_cipher_suite); |
1988 } | 2162 } |
1989 } | 2163 } |
1990 | 2164 |
1991 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { | 2165 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { |
1992 RTC_DCHECK(worker_thread()->IsCurrent()); | 2166 RTC_DCHECK(worker_thread()->IsCurrent()); |
1993 media_controller_->call_w()->OnSentPacket(sent_packet); | 2167 media_controller_->call_w()->OnSentPacket(sent_packet); |
1994 } | 2168 } |
1995 | 2169 |
1996 } // namespace webrtc | 2170 } // namespace webrtc |
OLD | NEW |