Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, | 1271 VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, |
| 1272 "StartSend() RTP/RTCP failed to stop sending"); | 1272 "StartSend() RTP/RTCP failed to stop sending"); |
| 1273 } | 1273 } |
| 1274 _rtpRtcpModule->SetSendingMediaStatus(false); | 1274 _rtpRtcpModule->SetSendingMediaStatus(false); |
| 1275 } | 1275 } |
| 1276 | 1276 |
| 1277 bool Channel::SetEncoder(int payload_type, | 1277 bool Channel::SetEncoder(int payload_type, |
| 1278 std::unique_ptr<AudioEncoder> encoder) { | 1278 std::unique_ptr<AudioEncoder> encoder) { |
| 1279 RTC_DCHECK_GE(payload_type, 0); | 1279 RTC_DCHECK_GE(payload_type, 0); |
| 1280 RTC_DCHECK_LE(payload_type, 127); | 1280 RTC_DCHECK_LE(payload_type, 127); |
| 1281 // TODO(ossu): Make a CodecInst up for now. It seems like very little of this | 1281 // TODO(ossu): Make CodecInsts up, for now: one for the RTP/RTCP module and |
| 1282 // information is actually used, possibly only payload type and clock rate. | 1282 // one for for us to keep track of sample rate and number of channels, etc. |
| 1283 CodecInst lies; | 1283 |
| 1284 lies.pltype = payload_type; | 1284 // The RTP/RTCP module needs to know the RTP timestamp rate (i.e. clockrate) |
| 1285 strncpy(lies.plname, "audio", sizeof(lies.plname)); | 1285 // as well as some other things, so we collect this info and send it along. |
| 1286 lies.plname[sizeof(lies.plname) - 1] = 0; | 1286 CodecInst rtp_codec; |
| 1287 rtp_codec.pltype = payload_type; | |
| 1288 strncpy(rtp_codec.plname, "audio", sizeof(rtp_codec.plname)); | |
| 1289 rtp_codec.plname[sizeof(rtp_codec.plname) - 1] = 0; | |
| 1287 // Seems unclear if it should be clock rate or sample rate. CodecInst | 1290 // Seems unclear if it should be clock rate or sample rate. CodecInst |
| 1288 // supposedly carries the sample rate, but only clock rate seems sensible to | 1291 // supposedly carries the sample rate, but only clock rate seems sensible to |
| 1289 // send to the RTP/RTCP module. | 1292 // send to the RTP/RTCP module. |
| 1290 lies.plfreq = encoder->RtpTimestampRateHz(); | 1293 rtp_codec.plfreq = encoder->RtpTimestampRateHz(); |
| 1291 lies.pacsize = 0; | 1294 rtp_codec.pacsize = rtc::CheckedDivExact( |
| 1292 lies.channels = encoder->NumChannels(); | 1295 static_cast<int>(encoder->Max10MsFramesInAPacket() * rtp_codec.plfreq), |
| 1293 lies.rate = 0; | 1296 100); |
| 1297 rtp_codec.channels = encoder->NumChannels(); | |
| 1298 rtp_codec.rate = 0; | |
| 1294 | 1299 |
| 1295 if (_rtpRtcpModule->RegisterSendPayload(lies) != 0) { | 1300 // For audio encoding we need, instead, the actual sample rate of the codec. |
| 1301 // The rest of the information should be the same. | |
| 1302 CodecInst send_codec = rtp_codec; | |
| 1303 send_codec.plfreq = encoder->SampleRateHz(); | |
| 1304 cached_send_codec_.emplace(send_codec); | |
|
the sun
2017/06/13 09:25:07
Though this may work in practice - won't the TSAN
ossu
2017/06/13 09:39:15
I was a bit worried about that as well, but having
| |
| 1305 | |
| 1306 if (_rtpRtcpModule->RegisterSendPayload(rtp_codec) != 0) { | |
| 1296 _rtpRtcpModule->DeRegisterSendPayload(payload_type); | 1307 _rtpRtcpModule->DeRegisterSendPayload(payload_type); |
| 1297 if (_rtpRtcpModule->RegisterSendPayload(lies) != 0) { | 1308 if (_rtpRtcpModule->RegisterSendPayload(rtp_codec) != 0) { |
| 1298 WEBRTC_TRACE( | 1309 WEBRTC_TRACE( |
| 1299 kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), | 1310 kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1300 "SetEncoder() failed to register codec to RTP/RTCP module"); | 1311 "SetEncoder() failed to register codec to RTP/RTCP module"); |
| 1301 return false; | 1312 return false; |
| 1302 } | 1313 } |
| 1303 } | 1314 } |
| 1304 | 1315 |
| 1305 audio_coding_->SetEncoder(std::move(encoder)); | 1316 audio_coding_->SetEncoder(std::move(encoder)); |
| 1306 codec_manager_.UnsetCodecInst(); | 1317 codec_manager_.UnsetCodecInst(); |
| 1307 return true; | 1318 return true; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1336 _engineStatisticsPtr->SetLastError( | 1347 _engineStatisticsPtr->SetLastError( |
| 1337 VE_INVALID_OPERATION, kTraceWarning, | 1348 VE_INVALID_OPERATION, kTraceWarning, |
| 1338 "DeRegisterVoiceEngineObserver() observer already disabled"); | 1349 "DeRegisterVoiceEngineObserver() observer already disabled"); |
| 1339 return 0; | 1350 return 0; |
| 1340 } | 1351 } |
| 1341 _voiceEngineObserverPtr = NULL; | 1352 _voiceEngineObserverPtr = NULL; |
| 1342 return 0; | 1353 return 0; |
| 1343 } | 1354 } |
| 1344 | 1355 |
| 1345 int32_t Channel::GetSendCodec(CodecInst& codec) { | 1356 int32_t Channel::GetSendCodec(CodecInst& codec) { |
| 1346 { | 1357 if (cached_send_codec_) { |
| 1358 codec = *cached_send_codec_; | |
| 1359 return 0; | |
| 1360 } else { | |
| 1347 const CodecInst* send_codec = codec_manager_.GetCodecInst(); | 1361 const CodecInst* send_codec = codec_manager_.GetCodecInst(); |
| 1348 if (send_codec) { | 1362 if (send_codec) { |
| 1349 codec = *send_codec; | 1363 codec = *send_codec; |
| 1350 return 0; | 1364 return 0; |
| 1351 } | 1365 } |
| 1352 } | 1366 } |
| 1353 rtc::Optional<CodecInst> acm_send_codec = audio_coding_->SendCodec(); | |
| 1354 if (acm_send_codec) { | |
| 1355 codec = *acm_send_codec; | |
| 1356 return 0; | |
| 1357 } | |
| 1358 return -1; | 1367 return -1; |
| 1359 } | 1368 } |
| 1360 | 1369 |
| 1361 int32_t Channel::GetRecCodec(CodecInst& codec) { | 1370 int32_t Channel::GetRecCodec(CodecInst& codec) { |
| 1362 return (audio_coding_->ReceiveCodec(&codec)); | 1371 return (audio_coding_->ReceiveCodec(&codec)); |
| 1363 } | 1372 } |
| 1364 | 1373 |
| 1365 int32_t Channel::SetSendCodec(const CodecInst& codec) { | 1374 int32_t Channel::SetSendCodec(const CodecInst& codec) { |
| 1366 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 1375 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1367 "Channel::SetSendCodec()"); | 1376 "Channel::SetSendCodec()"); |
| 1368 | 1377 |
| 1369 if (!codec_manager_.RegisterEncoder(codec) || | 1378 if (!codec_manager_.RegisterEncoder(codec) || |
| 1370 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { | 1379 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { |
| 1371 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), | 1380 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1372 "SetSendCodec() failed to register codec to ACM"); | 1381 "SetSendCodec() failed to register codec to ACM"); |
| 1373 return -1; | 1382 return -1; |
| 1374 } | 1383 } |
| 1375 | 1384 |
| 1376 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { | 1385 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 1377 _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); | 1386 _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); |
| 1378 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { | 1387 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 1379 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), | 1388 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1380 "SetSendCodec() failed to register codec to" | 1389 "SetSendCodec() failed to register codec to" |
| 1381 " RTP/RTCP module"); | 1390 " RTP/RTCP module"); |
| 1382 return -1; | 1391 return -1; |
| 1383 } | 1392 } |
| 1384 } | 1393 } |
| 1385 | 1394 |
| 1395 cached_send_codec_.reset(); | |
| 1396 | |
| 1386 return 0; | 1397 return 0; |
| 1387 } | 1398 } |
| 1388 | 1399 |
| 1389 void Channel::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) { | 1400 void Channel::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) { |
| 1390 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 1401 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1391 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); | 1402 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); |
| 1392 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | 1403 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
| 1393 if (*encoder) { | 1404 if (*encoder) { |
| 1394 (*encoder)->OnReceivedUplinkBandwidth( | 1405 (*encoder)->OnReceivedUplinkBandwidth( |
| 1395 bitrate_bps, rtc::Optional<int64_t>(probing_interval_ms)); | 1406 bitrate_bps, rtc::Optional<int64_t>(probing_interval_ms)); |
| (...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3129 int64_t min_rtt = 0; | 3140 int64_t min_rtt = 0; |
| 3130 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 3141 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
| 3131 0) { | 3142 0) { |
| 3132 return 0; | 3143 return 0; |
| 3133 } | 3144 } |
| 3134 return rtt; | 3145 return rtt; |
| 3135 } | 3146 } |
| 3136 | 3147 |
| 3137 } // namespace voe | 3148 } // namespace voe |
| 3138 } // namespace webrtc | 3149 } // namespace webrtc |
| OLD | NEW |