Skip to content

Commit 0082e2f

Browse files
committed
RTSPServer: cleanup redundant code
1 parent 1e6a6a4 commit 0082e2f

File tree

1 file changed

+3
-49
lines changed

1 file changed

+3
-49
lines changed

src/AudioTools/Communication/RTSP/RTSPServer.h

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -80,58 +80,12 @@ class RTSPServer : public RTSPServerBase<Platform> {
8080
}
8181

8282
void sessionThreadLoop() {
83-
typename Platform::TcpClientType* s = &this->client;
84-
unsigned long lastCheck = millis();
8583
LOGD("RTSP Task running");
86-
RtspSession<Platform>* rtsp = createSession(s);
87-
unsigned long lastRequestTime = millis();
88-
processSessionLoop(rtsp, lastCheck, lastRequestTime);
89-
cleanupSession(rtsp);
90-
}
91-
92-
RtspSession<Platform>* createSession(typename Platform::TcpClientType* s) {
93-
RtspSession<Platform>* rtsp = new RtspSession<Platform>(*s, *this->streamer);
94-
if (this->onSessionPathCb) {
95-
rtsp->setOnSessionPath(this->onSessionPathCb, this->onSessionPathRef);
96-
}
97-
assert(rtsp != nullptr);
98-
LOGI("Session ready");
99-
return rtsp;
100-
}
101-
102-
void processSessionLoop(RtspSession<Platform>* rtsp, unsigned long lastCheck, unsigned long lastRequestTime) {
103-
while (rtsp->isSessionOpen()) {
104-
uint32_t timeout = 30;
105-
bool gotRequest = rtsp->handleRequests(timeout);
106-
if (gotRequest) {
107-
lastRequestTime = millis();
108-
LOGD("Request handling successful");
109-
} else {
110-
if (rtsp->isStreaming()) {
111-
LOGI("Request handling timed out or no data yet");
112-
}
113-
}
114-
if (this->sessionTimeoutMs > 0 && rtsp->isStreaming()) {
115-
if ((millis() - lastRequestTime) > this->sessionTimeoutMs) {
116-
LOGW("Session timeout: no client request received for 20 seconds, closing session");
117-
break;
118-
}
119-
}
120-
int time = timeout - (millis() - lastCheck);
121-
if (time < 0) time = 0;
122-
delay(time);
123-
}
124-
LOGI("Session loop exited - session no longer open");
125-
LOGI("sessionThread stopped, cleaning up");
126-
}
127-
128-
void cleanupSession(RtspSession<Platform>* rtsp) {
129-
delete rtsp;
130-
if (this->client.connected()) {
131-
Platform::closeSocket(&this->client);
84+
while (this->rtspSession && this->rtspSession->isSessionOpen()) {
85+
this->handleSession();
86+
delay(30);
13287
}
13388
delay(500);
134-
this->client_count--;
13589
LOGI("Session cleaned up: (numClients: %d)", this->client_count);
13690
sessionTask.end();
13791
}

0 commit comments

Comments
 (0)