AI automatically translates all comments in the code into English (#3917)

This commit is contained in:
alex
2024-09-19 14:53:50 +08:00
committed by GitHub
parent 046de691cb
commit 4152dcd409
279 changed files with 10602 additions and 3038 deletions

View File

@@ -31,7 +31,8 @@ static string getUserName(const char *buf, size_t len) {
packet->GetMethod() != RTC::StunPacket::Method::BINDING) {
return "";
}
//收到binding request请求
// 收到binding request请求 [AUTO-TRANSLATED:eff4d773]
// Received binding request
auto vec = split(packet->GetUsername(), ":");
return vec[0];
}
@@ -57,16 +58,19 @@ void WebRtcSession::attachServer(const Server &server) {
void WebRtcSession::onRecv_l(const char *data, size_t len) {
if (_find_transport) {
// 只允许寻找一次transport
// 只允许寻找一次transport [AUTO-TRANSLATED:446fae53]
// Only allow searching for transport once
_find_transport = false;
auto user_name = getUserName(data, len);
auto transport = WebRtcTransportManager::Instance().getItem(user_name);
CHECK(transport);
//WebRtcTransport在其他poller线程上需要切换poller线程并重新创建WebRtcSession对象
// WebRtcTransport在其他poller线程上需要切换poller线程并重新创建WebRtcSession对象 [AUTO-TRANSLATED:7e5534cf]
// WebRtcTransport is on another poller thread, need to switch poller thread and recreate WebRtcSession object
if (!transport->getPoller()->isCurrentThread()) {
auto sock = Socket::createSocket(transport->getPoller(), false);
//1、克隆socket(fd不变)切换poller线程到WebRtcTransport所在线程
// 1、克隆socket(fd不变)切换poller线程到WebRtcTransport所在线程 [AUTO-TRANSLATED:f930bfab]
// 1. Clone socket (fd remains unchanged), switch poller thread to the thread where WebRtcTransport is located
sock->cloneSocket(*(getSock()));
auto server = _server;
std::string str(data, len);
@@ -74,11 +78,13 @@ void WebRtcSession::onRecv_l(const char *data, size_t len) {
auto strong_server = server.lock();
if (strong_server) {
auto session = static_pointer_cast<WebRtcSession>(strong_server->createSession(sock));
//2、创建新的WebRtcSession对象(绑定到WebRtcTransport所在线程)重新处理一遍ice binding request命令
// 2、创建新的WebRtcSession对象(绑定到WebRtcTransport所在线程)重新处理一遍ice binding request命令 [AUTO-TRANSLATED:c75203bb]
// 2. Create a new WebRtcSession object (bound to the thread where WebRtcTransport is located), reprocess the ice binding request command
session->onRecv_l(str.data(), str.size());
}
});
//3、销毁原先的socket和WebRtcSession(原先的对象跟WebRtcTransport不在同一条线程)
// 3、销毁原先的socket和WebRtcSession(原先的对象跟WebRtcTransport不在同一条线程) [AUTO-TRANSLATED:a6d6d63f]
// 3. Destroy the original socket and WebRtcSession (the original object is not on the same thread as WebRtcTransport)
throw std::runtime_error("webrtc over tcp change poller: " + getPoller()->getThreadName() + " -> " + sock->getPoller()->getThreadName());
}
_transport = std::move(transport);
@@ -98,9 +104,12 @@ void WebRtcSession::onRecv(const Buffer::Ptr &buffer) {
}
void WebRtcSession::onError(const SockException &err) {
//udp链接超时但是rtc链接不一定超时因为可能存在链接迁移的情况
//在udp链接迁移时新的WebRtcSession对象将接管WebRtcTransport对象的生命周期
//WebRtcSession对象将在超时后自动销毁
// udp链接超时但是rtc链接不一定超时因为可能存在链接迁移的情况 [AUTO-TRANSLATED:aaa9672f]
// UDP connection timeout, but RTC connection may not timeout, because there may be connection migration
// 在udp链接迁移时新的WebRtcSession对象将接管WebRtcTransport对象的生命周期 [AUTO-TRANSLATED:7e7d19df]
// When UDP connection migrates, the new WebRtcSession object will take over the life cycle of the WebRtcTransport object
// 本WebRtcSession对象将在超时后自动销毁 [AUTO-TRANSLATED:bc903a06]
// This WebRtcSession object will be automatically destroyed after timeout
WarnP(this) << err;
if (!_transport) {
@@ -109,9 +118,11 @@ void WebRtcSession::onError(const SockException &err) {
auto self = static_pointer_cast<WebRtcSession>(shared_from_this());
auto transport = std::move(_transport);
getPoller()->async([transport, self]() mutable {
//延时减引用防止使用transport对象时销毁对象
// 延时减引用防止使用transport对象时销毁对象 [AUTO-TRANSLATED:09dd6609]
// Delay decrementing the reference count to prevent the object from being destroyed when using the transport object
transport->removeTuple(self.get());
//确保transport在Session对象前销毁防止WebRtcTransport::onDestory()时获取不到Session对象
// 确保transport在Session对象前销毁防止WebRtcTransport::onDestory()时获取不到Session对象 [AUTO-TRANSLATED:acd8bd77]
// Ensure that the transport is destroyed before the Session object to prevent WebRtcTransport::onDestory() from not being able to get the Session object
transport = nullptr;
}, false);
}
@@ -135,15 +146,18 @@ ssize_t WebRtcSession::onRecvHeader(const char *data, size_t len) {
const char *WebRtcSession::onSearchPacketTail(const char *data, size_t len) {
if (len < 2) {
// 数据不够
// 数据不够 [AUTO-TRANSLATED:830a2785]
// Not enough data
return nullptr;
}
uint16_t length = (((uint8_t *)data)[0] << 8) | ((uint8_t *)data)[1];
if (len < (size_t)(length + 2)) {
// 数据不够
// 数据不够 [AUTO-TRANSLATED:830a2785]
// Not enough data
return nullptr;
}
// 返回rtp包末尾
// 返回rtp包末尾 [AUTO-TRANSLATED:5134cf6f]
// Return the end of the RTP packet
return data + 2 + length;
}