AI: Add utest to cover app rtmp module.

This commit is contained in:
OSSRS-AI 2025-10-04 09:25:53 -04:00 committed by winlin
parent cdfe82357e
commit b5664747ac
14 changed files with 3071 additions and 25 deletions

View File

@ -39,12 +39,12 @@ ISrsMessagePumper::~ISrsMessagePumper()
{
}
SrsRecvThread::SrsRecvThread(ISrsMessagePumper *p, SrsRtmpServer *r, srs_utime_t tm, SrsContextId parent_cid)
SrsRecvThread::SrsRecvThread(ISrsMessagePumper *p, ISrsRtmpServer *r, srs_utime_t tm, SrsContextId parent_cid)
{
rtmp_ = r;
pumper_ = p;
timeout_ = tm;
_parent_cid = parent_cid;
parent_cid_ = parent_cid;
trd_ = new SrsDummyCoroutine();
}
@ -63,7 +63,7 @@ srs_error_t SrsRecvThread::start()
srs_error_t err = srs_success;
srs_freep(trd_);
trd_ = new SrsSTCoroutine("recv", this, _parent_cid);
trd_ = new SrsSTCoroutine("recv", this, parent_cid_);
// change stack size to 256K, fix crash when call some 3rd-part api.
((SrsSTCoroutine *)trd_)->set_stack_size(1 << 18);
@ -144,7 +144,7 @@ srs_error_t SrsRecvThread::do_cycle()
return err;
}
SrsQueueRecvThread::SrsQueueRecvThread(SrsLiveConsumer *consumer, SrsRtmpServer *rtmp_sdk, srs_utime_t tm, SrsContextId parent_cid)
SrsQueueRecvThread::SrsQueueRecvThread(SrsLiveConsumer *consumer, ISrsRtmpServer *rtmp_sdk, srs_utime_t tm, SrsContextId parent_cid)
: trd_(this, rtmp_sdk, tm, parent_cid)
{
_consumer = consumer;
@ -257,7 +257,7 @@ void SrsQueueRecvThread::on_stop()
rtmp_->set_auto_response(true);
}
SrsPublishRecvThread::SrsPublishRecvThread(SrsRtmpServer *rtmp_sdk, ISrsRequest *_req,
SrsPublishRecvThread::SrsPublishRecvThread(ISrsRtmpServer *rtmp_sdk, ISrsRequest *_req,
int mr_sock_fd, srs_utime_t tm, SrsRtmpConn *conn, SrsSharedPtr<SrsLiveSource> source, SrsContextId parent_cid)
: trd_(this, rtmp_sdk, tm, parent_cid)
{

View File

@ -26,6 +26,7 @@ class ISrsRequest;
class SrsLiveConsumer;
class SrsHttpConn;
class SrsHttpxConn;
class ISrsRtmpServer;
// The message consumer which consume a message.
class ISrsMessageConsumer
@ -66,15 +67,15 @@ class SrsRecvThread : public ISrsCoroutineHandler
protected:
ISrsCoroutine *trd_;
ISrsMessagePumper *pumper_;
SrsRtmpServer *rtmp_;
SrsContextId _parent_cid;
ISrsRtmpServer *rtmp_;
SrsContextId parent_cid_;
// The recv timeout in srs_utime_t.
srs_utime_t timeout_;
public:
// Constructor.
// @param tm The receive timeout in srs_utime_t.
SrsRecvThread(ISrsMessagePumper *p, SrsRtmpServer *r, srs_utime_t tm, SrsContextId parent_cid);
SrsRecvThread(ISrsMessagePumper *p, ISrsRtmpServer *r, srs_utime_t tm, SrsContextId parent_cid);
virtual ~SrsRecvThread();
public:
@ -101,14 +102,14 @@ class SrsQueueRecvThread : public ISrsMessagePumper
private:
std::vector<SrsRtmpCommonMessage *> queue_;
SrsRecvThread trd_;
SrsRtmpServer *rtmp_;
ISrsRtmpServer *rtmp_;
// The recv thread error code.
srs_error_t recv_error_;
SrsLiveConsumer *_consumer;
public:
// TODO: FIXME: Refine timeout in time unit.
SrsQueueRecvThread(SrsLiveConsumer *consumer, SrsRtmpServer *rtmp_sdk, srs_utime_t tm, SrsContextId parent_cid);
SrsQueueRecvThread(SrsLiveConsumer *consumer, ISrsRtmpServer *rtmp_sdk, srs_utime_t tm, SrsContextId parent_cid);
virtual ~SrsQueueRecvThread();
public:
@ -140,7 +141,7 @@ class SrsPublishRecvThread : public ISrsMessagePumper, public ISrsReloadHandler
private:
uint32_t nn_msgs_for_yield_;
SrsRecvThread trd_;
SrsRtmpServer *rtmp_;
ISrsRtmpServer *rtmp_;
ISrsRequest *req_;
// The msgs already got.
int64_t _nb_msgs;
@ -165,7 +166,7 @@ private:
SrsContextId ncid_;
public:
SrsPublishRecvThread(SrsRtmpServer *rtmp_sdk, ISrsRequest *_req,
SrsPublishRecvThread(ISrsRtmpServer *rtmp_sdk, ISrsRequest *_req,
int mr_sock_fd, srs_utime_t tm, SrsRtmpConn *conn, SrsSharedPtr<SrsLiveSource> source, SrsContextId parent_cid);
virtual ~SrsPublishRecvThread();

View File

@ -48,6 +48,14 @@ using namespace std;
// the timeout in srs_utime_t to wait encoder to republish
// if timeout, close the connection.
#define SRS_REPUBLISH_SEND_TIMEOUT (3 * SRS_UTIME_MINUTES)
ISrsRtmpTransport::ISrsRtmpTransport()
{
}
ISrsRtmpTransport::~ISrsRtmpTransport()
{
}
// if timeout, close the connection.
#define SRS_REPUBLISH_RECV_TIMEOUT (3 * SRS_UTIME_MINUTES)
@ -183,13 +191,11 @@ const char *SrsRtmpsTransport::transport_type()
return "ssl";
}
SrsRtmpConn::SrsRtmpConn(SrsServer *svr, SrsRtmpTransport *transport, string cip, int cport)
SrsRtmpConn::SrsRtmpConn(ISrsRtmpTransport *transport, string cip, int cport)
{
// Create a identify for this client.
_srs_context->set_id(_srs_context->generate_id());
server_ = svr;
transport_ = transport;
ip_ = cip;
port_ = cport;
@ -226,7 +232,9 @@ SrsRtmpConn::SrsRtmpConn(SrsServer *svr, SrsRtmpTransport *transport, string cip
hooks_ = _srs_hooks;
rtc_sources_ = _srs_rtc_sources;
srt_sources_ = _srs_srt_sources;
#ifdef SRS_RTSP
rtsp_sources_ = _srs_rtsp_sources;
#endif
}
void SrsRtmpConn::assemble()
@ -261,7 +269,9 @@ SrsRtmpConn::~SrsRtmpConn()
hooks_ = NULL;
rtc_sources_ = NULL;
srt_sources_ = NULL;
#ifdef SRS_RTSP
rtsp_sources_ = NULL;
#endif
}
std::string SrsRtmpConn::desc()
@ -635,6 +645,11 @@ srs_error_t SrsRtmpConn::playing(SrsSharedPtr<SrsLiveSource> source)
{
srs_error_t err = srs_success;
// Check whether thread is quiting.
if ((err = trd_->pull()) != srs_success) {
return srs_error_wrap(err, "thread");
}
// Check page referer of player.
ISrsRequest *req = info_->req_;
if (config_->get_refer_enabled(req->vhost_)) {
@ -846,6 +861,11 @@ srs_error_t SrsRtmpConn::publishing(SrsSharedPtr<SrsLiveSource> source)
{
srs_error_t err = srs_success;
// Check whether thread is quiting.
if ((err = trd_->pull()) != srs_success) {
return srs_error_wrap(err, "thread");
}
ISrsRequest *req = info_->req_;
if (config_->get_refer_enabled(req->vhost_)) {

View File

@ -49,6 +49,9 @@ class ISrsHttpHooks;
class ISrsRtcSourceManager;
class ISrsSrtSourceManager;
class ISrsRtspSourceManager;
class ISrsRtmpServer;
class ISrsRtmpTransport;
class ISrsSecurity;
// The simple rtmp client for SRS.
class SrsSimpleRtmpClient : public SrsBasicRtmpClient
@ -82,8 +85,26 @@ public:
virtual ~SrsClientInfo();
};
// The transport layer for RTMP connections.
class ISrsRtmpTransport
{
public:
ISrsRtmpTransport();
virtual ~ISrsRtmpTransport();
public:
virtual srs_netfd_t fd() = 0;
virtual ISrsProtocolReadWriter *io() = 0;
virtual srs_error_t handshake() = 0;
virtual const char *transport_type() = 0;
virtual srs_error_t set_socket_buffer(srs_utime_t buffer_v) = 0;
virtual srs_error_t set_tcp_nodelay(bool v) = 0;
virtual int64_t get_recv_bytes() = 0;
virtual int64_t get_send_bytes() = 0;
};
// The base transport layer for RTMP connections over plain TCP.
class SrsRtmpTransport
class SrsRtmpTransport : public ISrsRtmpTransport
{
protected:
srs_netfd_t stfd_;
@ -147,14 +168,15 @@ private:
ISrsHttpHooks *hooks_;
ISrsRtcSourceManager *rtc_sources_;
ISrsSrtSourceManager *srt_sources_;
#ifdef SRS_RTSP
ISrsRtspSourceManager *rtsp_sources_;
#endif
private:
SrsServer *server_;
SrsRtmpServer *rtmp_;
ISrsRtmpServer *rtmp_;
SrsRefer *refer_;
SrsBandwidth *bandwidth_;
SrsSecurity *security_;
ISrsSecurity *security_;
// The wakable handler, maybe NULL.
// TODO: FIXME: Should refine the state for receiving thread.
ISrsWakable *wakable_;
@ -179,7 +201,7 @@ private:
SrsClientInfo *info_;
private:
SrsRtmpTransport *transport_;
ISrsRtmpTransport *transport_;
// Each connection start a green thread,
// when thread stop, the connection will be delete by server.
ISrsCoroutine *trd_;
@ -194,7 +216,7 @@ private:
int64_t create_time_;
public:
SrsRtmpConn(SrsServer *svr, SrsRtmpTransport *transport, std::string cip, int port);
SrsRtmpConn(ISrsRtmpTransport *transport, std::string cip, int port);
void assemble();
virtual ~SrsRtmpConn();
// Interface ISrsResource.

View File

@ -11,6 +11,14 @@
using namespace std;
ISrsSecurity::ISrsSecurity()
{
}
ISrsSecurity::~ISrsSecurity()
{
}
SrsSecurity::SrsSecurity()
{
}

View File

@ -16,8 +16,19 @@
class SrsConfDirective;
// The security interface.
class ISrsSecurity
{
public:
ISrsSecurity();
virtual ~ISrsSecurity();
public:
virtual srs_error_t check(SrsRtmpConnType type, std::string ip, ISrsRequest *req) = 0;
};
// The security apply on vhost.
class SrsSecurity
class SrsSecurity : public ISrsSecurity
{
public:
SrsSecurity();

View File

@ -1507,12 +1507,12 @@ srs_error_t SrsServer::do_on_tcp_client(ISrsListener *listener, srs_netfd_t &stf
if (!resource) {
if (listener == rtmp_listener_) {
SrsRtmpTransport *transport = new SrsRtmpTransport(stfd2);
SrsRtmpConn *conn = new SrsRtmpConn(this, transport, ip, port);
SrsRtmpConn *conn = new SrsRtmpConn(transport, ip, port);
conn->assemble();
resource = conn;
} else if (listener == rtmps_listener_) {
SrsRtmpTransport *transport = new SrsRtmpsTransport(stfd2);
SrsRtmpConn *conn = new SrsRtmpConn(this, transport, ip, port);
SrsRtmpConn *conn = new SrsRtmpConn(transport, ip, port);
conn->assemble();
resource = conn;
} else if (listener == api_listener_ || listener == apis_listener_) {

View File

@ -336,6 +336,9 @@ extern SrsProcSelfStat *srs_get_self_proc_stat();
extern SrsProcSystemStat *srs_get_system_proc_stat();
// The daemon st-thread will update it.
extern void srs_update_proc_stat();
// Read process self stat from /proc/self/stat (Linux only).
// @return true on success, false on failure.
extern bool get_proc_self_stat(SrsProcSelfStat &r);
// Stat disk iops
// @see: http://stackoverflow.com/questions/4458183/how-the-util-of-iostat-is-computed
@ -443,6 +446,10 @@ public:
extern SrsDiskStat *srs_get_disk_stat();
// The daemon st-thread will update it.
extern void srs_update_disk_stat();
// Internal helper function to read disk stats from /proc/diskstats
// @param r the disk stat object to fill
// @return true on success, false on failure
extern bool srs_get_disk_diskstats_stat(SrsDiskStat &r);
// Stat system memory info
// @see: cat /proc/meminfo

View File

@ -2150,6 +2150,14 @@ srs_error_t SrsRtmpClient::fmle_publish(string stream, int &stream_id)
return err;
}
ISrsRtmpServer::ISrsRtmpServer()
{
}
ISrsRtmpServer::~ISrsRtmpServer()
{
}
SrsRtmpServer::SrsRtmpServer(ISrsProtocolReadWriter *skt)
{
io_ = skt;

View File

@ -660,10 +660,47 @@ public:
}
};
// The rtmp server interface.
class ISrsRtmpServer
{
public:
ISrsRtmpServer();
virtual ~ISrsRtmpServer();
public:
virtual void set_recv_timeout(srs_utime_t tm) = 0;
virtual void set_send_timeout(srs_utime_t tm) = 0;
virtual srs_error_t handshake() = 0;
virtual srs_error_t connect_app(ISrsRequest *req) = 0;
virtual uint32_t proxy_real_ip() = 0;
virtual srs_error_t set_window_ack_size(int ack_size) = 0;
virtual srs_error_t set_peer_bandwidth(int bandwidth, int type) = 0;
virtual srs_error_t set_chunk_size(int chunk_size) = 0;
virtual srs_error_t response_connect_app(ISrsRequest *req, const char *server_ip = NULL) = 0;
virtual srs_error_t on_bw_done() = 0;
virtual srs_error_t identify_client(int stream_id, SrsRtmpConnType &type, std::string &stream_name, srs_utime_t &duration) = 0;
virtual srs_error_t start_play(int stream_id) = 0;
virtual srs_error_t start_fmle_publish(int stream_id) = 0;
virtual srs_error_t start_haivision_publish(int stream_id) = 0;
virtual srs_error_t fmle_unpublish(int stream_id, double unpublish_tid) = 0;
virtual srs_error_t start_flash_publish(int stream_id) = 0;
virtual srs_error_t start_publishing(int stream_id) = 0;
virtual srs_error_t redirect(ISrsRequest *r, std::string url, bool &accepted) = 0;
virtual srs_error_t send_and_free_messages(SrsMediaPacket **msgs, int nb_msgs, int stream_id) = 0;
virtual srs_error_t decode_message(SrsRtmpCommonMessage *msg, SrsRtmpCommand **ppacket) = 0;
virtual srs_error_t send_and_free_packet(SrsRtmpCommand *packet, int stream_id) = 0;
virtual srs_error_t on_play_client_pause(int stream_id, bool is_pause) = 0;
virtual srs_error_t set_in_window_ack_size(int ack_size) = 0;
virtual srs_error_t recv_message(SrsRtmpCommonMessage **pmsg) = 0;
virtual void set_auto_response(bool v) = 0;
virtual void set_merge_read(bool v, IMergeReadHandler *handler) = 0;
virtual void set_recv_buffer(int buffer_size) = 0;
};
// The rtmp provices rtmp-command-protocol services,
// a high level protocol, media stream oriented services,
// such as connect to vhost/app, play stream, get audio/video data.
class SrsRtmpServer
class SrsRtmpServer : public ISrsRtmpServer
{
private:
SrsHandshakeBytes *hs_bytes_;

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,8 @@
#include <srs_app_factory.hpp>
#include <srs_app_rtc_server.hpp>
#include <srs_app_heartbeat.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_security.hpp>
// Mock config for testing SrsServer::listen()
class MockAppConfigForServerListen : public MockAppConfig
@ -293,4 +295,451 @@ public:
virtual void unsubscribe(ISrsDisposingHandler *h);
};
// Mock config for testing SrsRtmpConn constructor and assemble()
class MockAppConfigForRtmpConn : public MockAppConfig
{
public:
int subscribe_count_;
int unsubscribe_count_;
ISrsReloadHandler *last_subscribed_handler_;
SrsConfDirective *vhost_directive_;
public:
MockAppConfigForRtmpConn();
virtual ~MockAppConfigForRtmpConn();
public:
virtual void subscribe(ISrsReloadHandler *handler);
virtual void unsubscribe(ISrsReloadHandler *handler);
virtual SrsConfDirective *get_vhost(std::string vhost, bool try_default_vhost = true);
virtual bool get_vhost_is_edge(std::string vhost);
void reset();
};
// Mock ISrsRtmpServer for testing SrsRtmpConn::stream_service_cycle()
class MockRtmpServerForStreamService : public ISrsRtmpServer
{
public:
SrsRtmpConnType identify_type_;
std::string identify_stream_;
srs_utime_t identify_duration_;
int start_play_count_;
int start_fmle_publish_count_;
int start_flash_publish_count_;
int start_haivision_publish_count_;
public:
MockRtmpServerForStreamService();
virtual ~MockRtmpServerForStreamService();
public:
virtual void set_recv_timeout(srs_utime_t tm);
virtual void set_send_timeout(srs_utime_t tm);
virtual srs_error_t handshake();
virtual srs_error_t connect_app(ISrsRequest *req);
virtual uint32_t proxy_real_ip();
virtual srs_error_t set_window_ack_size(int ack_size);
virtual srs_error_t set_peer_bandwidth(int bandwidth, int type);
virtual srs_error_t set_chunk_size(int chunk_size);
virtual srs_error_t response_connect_app(ISrsRequest *req, const char *server_ip);
virtual srs_error_t on_bw_done();
virtual srs_error_t identify_client(int stream_id, SrsRtmpConnType &type, std::string &stream_name, srs_utime_t &duration);
virtual srs_error_t start_play(int stream_id);
virtual srs_error_t start_fmle_publish(int stream_id);
virtual srs_error_t start_haivision_publish(int stream_id);
virtual srs_error_t fmle_unpublish(int stream_id, double unpublish_tid);
virtual srs_error_t start_flash_publish(int stream_id);
virtual srs_error_t start_publishing(int stream_id);
virtual srs_error_t redirect(ISrsRequest *r, std::string url, bool &accepted);
virtual srs_error_t send_and_free_messages(SrsMediaPacket **msgs, int nb_msgs, int stream_id);
virtual srs_error_t decode_message(SrsRtmpCommonMessage *msg, SrsRtmpCommand **ppacket);
virtual srs_error_t send_and_free_packet(SrsRtmpCommand *packet, int stream_id);
virtual srs_error_t on_play_client_pause(int stream_id, bool is_pause);
virtual srs_error_t set_in_window_ack_size(int ack_size);
virtual srs_error_t recv_message(SrsRtmpCommonMessage **pmsg);
virtual void set_auto_response(bool v);
virtual void set_merge_read(bool v, IMergeReadHandler *handler);
virtual void set_recv_buffer(int buffer_size);
};
// Mock ISrsCoroutine for testing SrsRtmpConn::service_cycle()
class MockCoroutineForRtmpConn : public ISrsCoroutine
{
public:
srs_error_t pull_error_;
int pull_count_;
public:
MockCoroutineForRtmpConn();
virtual ~MockCoroutineForRtmpConn();
public:
virtual srs_error_t start();
virtual void stop();
virtual void interrupt();
virtual srs_error_t pull();
virtual const SrsContextId &cid();
virtual void set_cid(const SrsContextId &cid);
};
// Mock ISrsRtmpTransport for testing SrsRtmpConn::do_cycle()
class MockRtmpTransportForDoCycle : public ISrsRtmpTransport
{
public:
MockRtmpTransportForDoCycle();
virtual ~MockRtmpTransportForDoCycle();
public:
virtual srs_netfd_t fd();
virtual ISrsProtocolReadWriter *io();
virtual srs_error_t handshake();
virtual const char *transport_type();
virtual srs_error_t set_socket_buffer(srs_utime_t buffer_v);
virtual srs_error_t set_tcp_nodelay(bool v);
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
};
// Mock ISrsSecurity for testing SrsRtmpConn::stream_service_cycle()
class MockSecurityForStreamService : public ISrsSecurity
{
public:
MockSecurityForStreamService();
virtual ~MockSecurityForStreamService();
public:
virtual srs_error_t check(SrsRtmpConnType type, std::string ip, ISrsRequest *req);
};
// Mock ISrsRtmpServer for testing SrsRtmpConn::handle_publish_message()
class MockRtmpServerForHandlePublishMessage : public ISrsRtmpServer
{
public:
srs_error_t decode_message_error_;
SrsRtmpCommand* decode_message_packet_;
int decode_message_count_;
srs_error_t fmle_unpublish_error_;
int fmle_unpublish_count_;
public:
MockRtmpServerForHandlePublishMessage();
virtual ~MockRtmpServerForHandlePublishMessage();
public:
virtual void set_recv_timeout(srs_utime_t tm);
virtual void set_send_timeout(srs_utime_t tm);
virtual srs_error_t handshake();
virtual srs_error_t connect_app(ISrsRequest *req);
virtual uint32_t proxy_real_ip();
virtual srs_error_t set_window_ack_size(int ack_size);
virtual srs_error_t set_peer_bandwidth(int bandwidth, int type);
virtual srs_error_t set_chunk_size(int chunk_size);
virtual srs_error_t response_connect_app(ISrsRequest *req, const char *server_ip);
virtual srs_error_t on_bw_done();
virtual srs_error_t identify_client(int stream_id, SrsRtmpConnType &type, std::string &stream_name, srs_utime_t &duration);
virtual srs_error_t start_play(int stream_id);
virtual srs_error_t start_fmle_publish(int stream_id);
virtual srs_error_t start_haivision_publish(int stream_id);
virtual srs_error_t fmle_unpublish(int stream_id, double unpublish_tid);
virtual srs_error_t start_flash_publish(int stream_id);
virtual srs_error_t start_publishing(int stream_id);
virtual srs_error_t redirect(ISrsRequest *r, std::string url, bool &accepted);
virtual srs_error_t send_and_free_messages(SrsMediaPacket **msgs, int nb_msgs, int stream_id);
virtual srs_error_t decode_message(SrsRtmpCommonMessage *msg, SrsRtmpCommand **ppacket);
virtual srs_error_t send_and_free_packet(SrsRtmpCommand *packet, int stream_id);
virtual srs_error_t on_play_client_pause(int stream_id, bool is_pause);
virtual srs_error_t set_in_window_ack_size(int ack_size);
virtual srs_error_t recv_message(SrsRtmpCommonMessage **pmsg);
virtual void set_auto_response(bool v);
virtual void set_merge_read(bool v, IMergeReadHandler *handler);
virtual void set_recv_buffer(int buffer_size);
void reset();
};
// Mock ISrsRtmpServer for testing SrsRtmpConn::process_play_control_msg()
class MockRtmpServerForPlayControl : public ISrsRtmpServer
{
public:
SrsRtmpCommand* decode_message_packet_;
int decode_message_count_;
int send_and_free_packet_count_;
int on_play_client_pause_count_;
bool last_pause_state_;
public:
MockRtmpServerForPlayControl();
virtual ~MockRtmpServerForPlayControl();
public:
virtual void set_recv_timeout(srs_utime_t tm);
virtual void set_send_timeout(srs_utime_t tm);
virtual srs_error_t handshake();
virtual srs_error_t connect_app(ISrsRequest *req);
virtual uint32_t proxy_real_ip();
virtual srs_error_t set_window_ack_size(int ack_size);
virtual srs_error_t set_peer_bandwidth(int bandwidth, int type);
virtual srs_error_t set_chunk_size(int chunk_size);
virtual srs_error_t response_connect_app(ISrsRequest *req, const char *server_ip);
virtual srs_error_t on_bw_done();
virtual srs_error_t identify_client(int stream_id, SrsRtmpConnType &type, std::string &stream_name, srs_utime_t &duration);
virtual srs_error_t start_play(int stream_id);
virtual srs_error_t start_fmle_publish(int stream_id);
virtual srs_error_t start_haivision_publish(int stream_id);
virtual srs_error_t fmle_unpublish(int stream_id, double unpublish_tid);
virtual srs_error_t start_flash_publish(int stream_id);
virtual srs_error_t start_publishing(int stream_id);
virtual srs_error_t redirect(ISrsRequest *r, std::string url, bool &accepted);
virtual srs_error_t send_and_free_messages(SrsMediaPacket **msgs, int nb_msgs, int stream_id);
virtual srs_error_t decode_message(SrsRtmpCommonMessage *msg, SrsRtmpCommand **ppacket);
virtual srs_error_t send_and_free_packet(SrsRtmpCommand *packet, int stream_id);
virtual srs_error_t on_play_client_pause(int stream_id, bool is_pause);
virtual srs_error_t set_in_window_ack_size(int ack_size);
virtual srs_error_t recv_message(SrsRtmpCommonMessage **pmsg);
virtual void set_auto_response(bool v);
virtual void set_merge_read(bool v, IMergeReadHandler *handler);
virtual void set_recv_buffer(int buffer_size);
void reset();
};
// Mock SrsLiveConsumer for testing SrsRtmpConn::process_play_control_msg()
class MockLiveConsumerForPlayControl : public SrsLiveConsumer
{
public:
int on_play_client_pause_count_;
bool last_pause_state_;
public:
MockLiveConsumerForPlayControl(ISrsLiveSource *source);
virtual ~MockLiveConsumerForPlayControl();
public:
virtual srs_error_t on_play_client_pause(bool is_pause);
};
// Mock ISrsAppConfig for testing SrsRtmpConn::http_hooks_on_connect()
class MockAppConfigForHttpHooksOnConnect : public MockAppConfig
{
public:
bool http_hooks_enabled_;
SrsConfDirective *on_connect_directive_;
public:
MockAppConfigForHttpHooksOnConnect();
virtual ~MockAppConfigForHttpHooksOnConnect();
public:
virtual bool get_vhost_http_hooks_enabled(std::string vhost);
virtual SrsConfDirective *get_vhost_on_connect(std::string vhost);
};
// Mock ISrsHttpHooks for testing SrsRtmpConn::http_hooks_on_connect() and http_hooks_on_close()
class MockHttpHooksForOnConnect : public ISrsHttpHooks
{
public:
std::vector<std::pair<std::string, ISrsRequest *> > on_connect_calls_;
int on_connect_count_;
srs_error_t on_connect_error_;
// For on_close tracking
struct OnCloseCall {
std::string url_;
ISrsRequest *req_;
int64_t send_bytes_;
int64_t recv_bytes_;
};
std::vector<OnCloseCall> on_close_calls_;
int on_close_count_;
// For on_unpublish tracking
std::vector<std::pair<std::string, ISrsRequest *> > on_unpublish_calls_;
int on_unpublish_count_;
// For on_stop tracking
std::vector<std::pair<std::string, ISrsRequest *> > on_stop_calls_;
int on_stop_count_;
public:
MockHttpHooksForOnConnect();
virtual ~MockHttpHooksForOnConnect();
public:
virtual srs_error_t on_connect(std::string url, ISrsRequest *req);
virtual void on_close(std::string url, ISrsRequest *req, int64_t send_bytes, int64_t recv_bytes);
virtual srs_error_t on_publish(std::string url, ISrsRequest *req);
virtual void on_unpublish(std::string url, ISrsRequest *req);
virtual srs_error_t on_play(std::string url, ISrsRequest *req);
virtual void on_stop(std::string url, ISrsRequest *req);
virtual srs_error_t on_dvr(SrsContextId cid, std::string url, ISrsRequest *req, std::string file);
virtual srs_error_t on_hls(SrsContextId cid, std::string url, ISrsRequest *req, std::string file, std::string ts_url,
std::string m3u8, std::string m3u8_url, int sn, srs_utime_t duration);
virtual srs_error_t on_hls_notify(SrsContextId cid, std::string url, ISrsRequest *req, std::string ts_url, int nb_notify);
virtual srs_error_t discover_co_workers(std::string url, std::string &host, int &port);
virtual srs_error_t on_forward_backend(std::string url, ISrsRequest *req, std::vector<std::string> &rtmp_urls);
void reset();
};
// Mock ISrsAppConfig for testing SrsRtmpConn::http_hooks_on_close()
class MockAppConfigForHttpHooksOnClose : public MockAppConfig
{
public:
bool http_hooks_enabled_;
SrsConfDirective *on_close_directive_;
public:
MockAppConfigForHttpHooksOnClose();
virtual ~MockAppConfigForHttpHooksOnClose();
public:
virtual bool get_vhost_http_hooks_enabled(std::string vhost);
virtual SrsConfDirective *get_vhost_on_close(std::string vhost);
};
// Mock ISrsAppConfig for testing SrsRtmpConn::http_hooks_on_publish()
class MockAppConfigForHttpHooksOnPublish : public MockAppConfig
{
public:
bool http_hooks_enabled_;
SrsConfDirective *on_publish_directive_;
public:
MockAppConfigForHttpHooksOnPublish();
virtual ~MockAppConfigForHttpHooksOnPublish();
public:
virtual bool get_vhost_http_hooks_enabled(std::string vhost);
virtual SrsConfDirective *get_vhost_on_publish(std::string vhost);
};
// Mock ISrsHttpHooks for testing SrsRtmpConn::http_hooks_on_publish()
class MockHttpHooksForOnPublish : public ISrsHttpHooks
{
public:
std::vector<std::pair<std::string, ISrsRequest *> > on_publish_calls_;
int on_publish_count_;
srs_error_t on_publish_error_;
public:
MockHttpHooksForOnPublish();
virtual ~MockHttpHooksForOnPublish();
public:
virtual srs_error_t on_connect(std::string url, ISrsRequest *req);
virtual void on_close(std::string url, ISrsRequest *req, int64_t send_bytes, int64_t recv_bytes);
virtual srs_error_t on_publish(std::string url, ISrsRequest *req);
virtual void on_unpublish(std::string url, ISrsRequest *req);
virtual srs_error_t on_play(std::string url, ISrsRequest *req);
virtual void on_stop(std::string url, ISrsRequest *req);
virtual srs_error_t on_dvr(SrsContextId cid, std::string url, ISrsRequest *req, std::string file);
virtual srs_error_t on_hls(SrsContextId cid, std::string url, ISrsRequest *req, std::string file, std::string ts_url,
std::string m3u8, std::string m3u8_url, int sn, srs_utime_t duration);
virtual srs_error_t on_hls_notify(SrsContextId cid, std::string url, ISrsRequest *req, std::string ts_url, int nb_notify);
virtual srs_error_t discover_co_workers(std::string url, std::string &host, int &port);
virtual srs_error_t on_forward_backend(std::string url, ISrsRequest *req, std::vector<std::string> &rtmp_urls);
void reset();
};
// Mock ISrsAppConfig for testing SrsRtmpConn::http_hooks_on_unpublish()
class MockAppConfigForHttpHooksOnUnpublish : public MockAppConfig
{
public:
bool http_hooks_enabled_;
SrsConfDirective *on_unpublish_directive_;
public:
MockAppConfigForHttpHooksOnUnpublish();
virtual ~MockAppConfigForHttpHooksOnUnpublish();
public:
virtual bool get_vhost_http_hooks_enabled(std::string vhost);
virtual SrsConfDirective *get_vhost_on_unpublish(std::string vhost);
};
// Mock ISrsAppConfig for testing SrsRtmpConn::http_hooks_on_stop()
class MockAppConfigForHttpHooksOnStop : public MockAppConfig
{
public:
bool http_hooks_enabled_;
SrsConfDirective *on_stop_directive_;
public:
MockAppConfigForHttpHooksOnStop();
virtual ~MockAppConfigForHttpHooksOnStop();
public:
virtual bool get_vhost_http_hooks_enabled(std::string vhost);
virtual SrsConfDirective *get_vhost_on_stop(std::string vhost);
};
// Mock ISrsAppConfig for testing SrsRtmpConn::http_hooks_on_play()
class MockAppConfigForHttpHooksOnPlay : public MockAppConfig
{
public:
bool http_hooks_enabled_;
SrsConfDirective *on_play_directive_;
public:
MockAppConfigForHttpHooksOnPlay();
virtual ~MockAppConfigForHttpHooksOnPlay();
public:
virtual bool get_vhost_http_hooks_enabled(std::string vhost);
virtual SrsConfDirective *get_vhost_on_play(std::string vhost);
};
// Mock ISrsHttpHooks for testing SrsRtmpConn::http_hooks_on_play()
class MockHttpHooksForOnPlay : public ISrsHttpHooks
{
public:
std::vector<std::pair<std::string, ISrsRequest *> > on_play_calls_;
int on_play_count_;
srs_error_t on_play_error_;
public:
MockHttpHooksForOnPlay();
virtual ~MockHttpHooksForOnPlay();
public:
virtual srs_error_t on_connect(std::string url, ISrsRequest *req);
virtual void on_close(std::string url, ISrsRequest *req, int64_t send_bytes, int64_t recv_bytes);
virtual srs_error_t on_publish(std::string url, ISrsRequest *req);
virtual void on_unpublish(std::string url, ISrsRequest *req);
virtual srs_error_t on_play(std::string url, ISrsRequest *req);
virtual void on_stop(std::string url, ISrsRequest *req);
virtual srs_error_t on_dvr(SrsContextId cid, std::string url, ISrsRequest *req, std::string file);
virtual srs_error_t on_hls(SrsContextId cid, std::string url, ISrsRequest *req, std::string file, std::string ts_url,
std::string m3u8, std::string m3u8_url, int sn, srs_utime_t duration);
virtual srs_error_t on_hls_notify(SrsContextId cid, std::string url, ISrsRequest *req, std::string ts_url, int nb_notify);
virtual srs_error_t discover_co_workers(std::string url, std::string &host, int &port);
virtual srs_error_t on_forward_backend(std::string url, ISrsRequest *req, std::vector<std::string> &rtmp_urls);
void reset();
};
// Mock ISrsAppConfig for testing SrsRtmpConn::acquire_publish()
class MockAppConfigForAcquirePublish : public MockAppConfigForRtmpConn
{
public:
bool rtc_server_enabled_;
bool rtc_enabled_;
bool srt_enabled_;
bool rtsp_server_enabled_;
bool rtsp_enabled_;
public:
MockAppConfigForAcquirePublish();
virtual ~MockAppConfigForAcquirePublish();
public:
virtual bool get_rtc_server_enabled();
virtual bool get_rtc_enabled(std::string vhost);
virtual bool get_srt_enabled();
virtual bool get_srt_enabled(std::string vhost);
virtual bool get_rtsp_server_enabled();
virtual bool get_rtsp_enabled(std::string vhost);
};
#endif

View File

@ -4374,6 +4374,18 @@ void MockLiveSource::set_can_publish(bool can_publish)
can_publish_result_ = can_publish;
}
srs_error_t MockLiveSource::on_publish()
{
// Mock implementation - just return success
return srs_success;
}
srs_error_t MockLiveSource::on_edge_start_publish()
{
// Mock implementation - just return success
return srs_success;
}
// Mock SRT source implementation
MockSrtSource::MockSrtSource()
{

View File

@ -709,6 +709,8 @@ public:
virtual ~MockLiveSource();
virtual bool can_publish(bool is_edge);
void set_can_publish(bool can_publish);
virtual srs_error_t on_publish();
virtual srs_error_t on_edge_start_publish();
};
// Mock SRT source for testing SrsRtcPublishStream