Fix Connectiojn Limit Bug
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#include "../include/rtmp_capi.h"
|
#include "../include/rtmp_capi.hpp"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -27,10 +27,12 @@ int main()
|
|||||||
rtmp_server_set_on_publish(server, on_publish_cb, NULL);
|
rtmp_server_set_on_publish(server, on_publish_cb, NULL);
|
||||||
rtmp_server_set_on_audio_data(server, on_audio_cb, NULL);
|
rtmp_server_set_on_audio_data(server, on_audio_cb, NULL);
|
||||||
rtmp_server_enable_gop_cache(server, true);
|
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");
|
while (isRunning) {
|
||||||
sleep(300); // 5 min
|
sleep(1); // Block main Thread
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ typedef bool (*RtmpAuthCallback)(const char *app, const char *stream_key,
|
|||||||
// Create and destroy
|
// Create and destroy
|
||||||
RtmpServerHandle rtmp_server_create(int port);
|
RtmpServerHandle rtmp_server_create(int port);
|
||||||
void rtmp_server_destroy(RtmpServerHandle handle);
|
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);
|
void rtmp_server_stop(RtmpServerHandle handle);
|
||||||
bool rtmp_server_is_running(RtmpServerHandle handle);
|
bool rtmp_server_is_running(RtmpServerHandle handle);
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ public:
|
|||||||
RTMPServer(int port = 1935);
|
RTMPServer(int port = 1935);
|
||||||
~RTMPServer();
|
~RTMPServer();
|
||||||
|
|
||||||
bool start();
|
bool start(bool& isRunning);
|
||||||
void stop();
|
void stop();
|
||||||
bool isRunning() const { return running; }
|
bool isRunning() const { return running; }
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "../include/rtmp_capi.h"
|
#include "../include/rtmp_capi.hpp"
|
||||||
#include "../include/rtmp_server.h"
|
#include "../include/rtmp_server.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -109,12 +109,15 @@ void rtmp_server_destroy(RtmpServerHandle handle) {
|
|||||||
delete impl->server;
|
delete impl->server;
|
||||||
delete impl;
|
delete impl;
|
||||||
}
|
}
|
||||||
bool rtmp_server_start(RtmpServerHandle handle) {
|
bool rtmp_server_start(RtmpServerHandle handle, bool *isRunning) {
|
||||||
if (!handle)
|
if (!handle || !isRunning)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Impl *impl = static_cast<Impl *>(handle);
|
Impl *impl = static_cast<Impl *>(handle);
|
||||||
return impl->server->start();
|
bool result = impl->server->start(*isRunning);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtmp_server_stop(RtmpServerHandle handle) {
|
void rtmp_server_stop(RtmpServerHandle handle) {
|
||||||
if (!handle)
|
if (!handle)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../include/rtmp_server.h"
|
#include "../include/rtmp_server.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
@@ -1007,7 +1007,7 @@ RTMPServer::RTMPServer(int port) : port(port), server_fd(-1), running(false) {}
|
|||||||
|
|
||||||
RTMPServer::~RTMPServer() { stop(); }
|
RTMPServer::~RTMPServer() { stop(); }
|
||||||
|
|
||||||
bool RTMPServer::start() {
|
bool RTMPServer::start(bool& isRunning) {
|
||||||
server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (server_fd < 0) {
|
if (server_fd < 0) {
|
||||||
LOG_ERROR("Failed to create socket");
|
LOG_ERROR("Failed to create socket");
|
||||||
@@ -1040,6 +1040,7 @@ bool RTMPServer::start() {
|
|||||||
}
|
}
|
||||||
timeout_thread = std::thread(&RTMPServer::timeoutCheckRoutine, this);
|
timeout_thread = std::thread(&RTMPServer::timeoutCheckRoutine, this);
|
||||||
LOG_INFO("RTMP Server started on port " + std::to_string(port));
|
LOG_INFO("RTMP Server started on port " + std::to_string(port));
|
||||||
|
isRunning = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1436,10 +1437,10 @@ bool RTMPServer::checkConnectionLimits(const std::string &app,
|
|||||||
bool is_publisher) const {
|
bool is_publisher) const {
|
||||||
if (is_publisher) {
|
if (is_publisher) {
|
||||||
int current = countPublishers(app, stream_key);
|
int current = countPublishers(app, stream_key);
|
||||||
return current < max_publishers_per_stream;
|
return current >= max_publishers_per_stream;
|
||||||
} else {
|
} else {
|
||||||
int current = countPlayers(app, stream_key);
|
int current = countPlayers(app, stream_key);
|
||||||
return current < max_players_per_stream;
|
return current >= max_players_per_stream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user