Fix Connectiojn Limit Bug

This commit is contained in:
Exil Productions
2025-12-26 23:37:04 +01:00
parent ea52870ca5
commit fad6425f44
5 changed files with 21 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
#include "../include/rtmp_capi.h"
#include "../include/rtmp_capi.hpp"
#include <stdio.h>
#include <unistd.h>
@@ -27,10 +27,12 @@ int main()
rtmp_server_set_on_publish(server, on_publish_cb, NULL);
rtmp_server_set_on_audio_data(server, on_audio_cb, NULL);
rtmp_server_enable_gop_cache(server, true);
if (rtmp_server_start(server))
bool isRunning = false;
if (rtmp_server_start(server, &isRunning))
{
printf("RTMP Server started on port 1935. Press Ctrl+C to stop.\n");
sleep(300); // 5 min
while (isRunning) {
sleep(1); // Block main Thread
}
}
else
{

View File

@@ -48,7 +48,7 @@ typedef bool (*RtmpAuthCallback)(const char *app, const char *stream_key,
// Create and destroy
RtmpServerHandle rtmp_server_create(int port);
void rtmp_server_destroy(RtmpServerHandle handle);
bool rtmp_server_start(RtmpServerHandle handle);
bool rtmp_server_start(RtmpServerHandle handle, bool* isRunning);
void rtmp_server_stop(RtmpServerHandle handle);
bool rtmp_server_is_running(RtmpServerHandle handle);

View File

@@ -340,7 +340,7 @@ public:
RTMPServer(int port = 1935);
~RTMPServer();
bool start();
bool start(bool& isRunning);
void stop();
bool isRunning() const { return running; }

View File

@@ -1,5 +1,5 @@
#include "../include/rtmp_capi.h"
#include "../include/rtmp_server.h"
#include "../include/rtmp_capi.hpp"
#include "../include/rtmp_server.hpp"
#include <string>
#include <vector>
@@ -109,12 +109,15 @@ void rtmp_server_destroy(RtmpServerHandle handle) {
delete impl->server;
delete impl;
}
bool rtmp_server_start(RtmpServerHandle handle) {
if (!handle)
bool rtmp_server_start(RtmpServerHandle handle, bool *isRunning) {
if (!handle || !isRunning)
return false;
Impl *impl = static_cast<Impl *>(handle);
return impl->server->start();
bool result = impl->server->start(*isRunning);
return result;
}
void rtmp_server_stop(RtmpServerHandle handle) {
if (!handle)
return;

View File

@@ -1,4 +1,4 @@
#include "../include/rtmp_server.h"
#include "../include/rtmp_server.hpp"
#include <algorithm>
#include <cstring>
#include <ctime>
@@ -1007,7 +1007,7 @@ RTMPServer::RTMPServer(int port) : port(port), server_fd(-1), running(false) {}
RTMPServer::~RTMPServer() { stop(); }
bool RTMPServer::start() {
bool RTMPServer::start(bool& isRunning) {
server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd < 0) {
LOG_ERROR("Failed to create socket");
@@ -1040,6 +1040,7 @@ bool RTMPServer::start() {
}
timeout_thread = std::thread(&RTMPServer::timeoutCheckRoutine, this);
LOG_INFO("RTMP Server started on port " + std::to_string(port));
isRunning = true;
return true;
}
@@ -1436,10 +1437,10 @@ bool RTMPServer::checkConnectionLimits(const std::string &app,
bool is_publisher) const {
if (is_publisher) {
int current = countPublishers(app, stream_key);
return current < max_publishers_per_stream;
return current >= max_publishers_per_stream;
} else {
int current = countPlayers(app, stream_key);
return current < max_players_per_stream;
return current >= max_players_per_stream;
}
}