mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
implements the proxy for edge publish mode
This commit is contained in:
parent
ec96072472
commit
79c9c6dcb7
7 changed files with 187 additions and 65 deletions
|
@ -41,12 +41,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <srs_app_source.hpp>
|
#include <srs_app_source.hpp>
|
||||||
#include <srs_app_pithy_print.hpp>
|
#include <srs_app_pithy_print.hpp>
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
|
#include <srs_app_socket.hpp>
|
||||||
|
|
||||||
// when error, edge ingester sleep for a while and retry.
|
// when error, edge ingester sleep for a while and retry.
|
||||||
#define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(1*1000*1000LL)
|
#define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(1*1000*1000LL)
|
||||||
|
|
||||||
// when edge timeout, retry next.
|
// when edge timeout, retry next.
|
||||||
#define SRS_EDGE_TIMEOUT_US (int64_t)(3*1000*1000LL)
|
#define SRS_EDGE_INGESTER_TIMEOUT_US (int64_t)(3*1000*1000LL)
|
||||||
|
|
||||||
SrsEdgeIngester::SrsEdgeIngester()
|
SrsEdgeIngester::SrsEdgeIngester()
|
||||||
{
|
{
|
||||||
|
@ -146,7 +147,7 @@ int SrsEdgeIngester::ingest()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
client->set_recv_timeout(SRS_EDGE_TIMEOUT_US);
|
client->set_recv_timeout(SRS_EDGE_INGESTER_TIMEOUT_US);
|
||||||
|
|
||||||
SrsPithyPrint pithy_print(SRS_STAGE_EDGE);
|
SrsPithyPrint pithy_print(SRS_STAGE_EDGE);
|
||||||
|
|
||||||
|
@ -306,6 +307,21 @@ int SrsEdgeIngester::connect_server()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SrsEdgeProxyContext::SrsEdgeProxyContext()
|
||||||
|
{
|
||||||
|
edge_stream_id = 0;
|
||||||
|
edge_io = NULL;
|
||||||
|
edge_rtmp = NULL;
|
||||||
|
|
||||||
|
origin_stream_id = 0;
|
||||||
|
origin_io = NULL;
|
||||||
|
origin_rtmp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsEdgeProxyContext::~SrsEdgeProxyContext()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
SrsEdgeForwarder::SrsEdgeForwarder()
|
SrsEdgeForwarder::SrsEdgeForwarder()
|
||||||
{
|
{
|
||||||
io = NULL;
|
io = NULL;
|
||||||
|
@ -315,14 +331,11 @@ SrsEdgeForwarder::SrsEdgeForwarder()
|
||||||
origin_index = 0;
|
origin_index = 0;
|
||||||
stream_id = 0;
|
stream_id = 0;
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
pthread = new SrsThread(this, SRS_EDGE_INGESTER_SLEEP_US);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsEdgeForwarder::~SrsEdgeForwarder()
|
SrsEdgeForwarder::~SrsEdgeForwarder()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
srs_freep(pthread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsEdgeForwarder::initialize(SrsSource* source, SrsPublishEdge* edge, SrsRequest* req)
|
int SrsEdgeForwarder::initialize(SrsSource* source, SrsPublishEdge* edge, SrsRequest* req)
|
||||||
|
@ -337,21 +350,6 @@ int SrsEdgeForwarder::initialize(SrsSource* source, SrsPublishEdge* edge, SrsReq
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsEdgeForwarder::start()
|
int SrsEdgeForwarder::start()
|
||||||
{
|
|
||||||
return pthread->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SrsEdgeForwarder::stop()
|
|
||||||
{
|
|
||||||
pthread->stop();
|
|
||||||
|
|
||||||
close_underlayer_socket();
|
|
||||||
|
|
||||||
srs_freep(client);
|
|
||||||
srs_freep(io);
|
|
||||||
}
|
|
||||||
|
|
||||||
int SrsEdgeForwarder::cycle()
|
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -378,37 +376,36 @@ int SrsEdgeForwarder::cycle()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = client->play(req->stream, stream_id)) != ERROR_SUCCESS) {
|
if ((ret = client->publish(req->stream, stream_id)) != ERROR_SUCCESS) {
|
||||||
srs_error("connect with server failed, stream=%s, stream_id=%d. ret=%d",
|
srs_error("connect with server failed, stream=%s, stream_id=%d. ret=%d",
|
||||||
req->stream.c_str(), stream_id, ret);
|
req->stream.c_str(), stream_id, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = _source->on_publish()) != ERROR_SUCCESS) {
|
|
||||||
srs_error("edge ingester play stream then publish to edge failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ret = _edge->on_forward_publish()) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ret = forward()) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsEdgeForwarder::forward()
|
void SrsEdgeForwarder::stop()
|
||||||
|
{
|
||||||
|
close_underlayer_socket();
|
||||||
|
|
||||||
|
srs_freep(client);
|
||||||
|
srs_freep(io);
|
||||||
|
}
|
||||||
|
|
||||||
|
int SrsEdgeForwarder::proxy(SrsEdgeProxyContext* context)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
client->set_recv_timeout(SRS_EDGE_TIMEOUT_US);
|
context->origin_io = io;
|
||||||
|
context->origin_rtmp = client;
|
||||||
|
context->origin_stream_id = stream_id;
|
||||||
|
|
||||||
|
client->set_recv_timeout(SRS_PULSE_TIMEOUT_US);
|
||||||
|
|
||||||
SrsPithyPrint pithy_print(SRS_STAGE_EDGE);
|
SrsPithyPrint pithy_print(SRS_STAGE_EDGE);
|
||||||
|
|
||||||
while (pthread->can_loop()) {
|
while (true) {
|
||||||
// switch to other st-threads.
|
// switch to other st-threads.
|
||||||
st_usleep(0);
|
st_usleep(0);
|
||||||
|
|
||||||
|
@ -419,17 +416,59 @@ int SrsEdgeForwarder::forward()
|
||||||
srs_trace("<- time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
|
srs_trace("<- time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
|
||||||
pithy_print.age(), client->get_send_bytes(), client->get_recv_bytes(), client->get_send_kbps(), client->get_recv_kbps());
|
pithy_print.age(), client->get_send_bytes(), client->get_recv_bytes(), client->get_send_kbps(), client->get_recv_kbps());
|
||||||
}
|
}
|
||||||
|
|
||||||
// read from client.
|
if ((ret = proxy_message(context)) != ERROR_SUCCESS) {
|
||||||
SrsCommonMessage* msg = NULL;
|
|
||||||
if ((ret = client->recv_message(&msg)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("recv origin server message failed. ret=%d", ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("edge loop recv message. ret=%d", ret);
|
}
|
||||||
|
|
||||||
srs_assert(msg);
|
return ret;
|
||||||
SrsAutoFree(SrsCommonMessage, msg, false);
|
}
|
||||||
|
|
||||||
|
int SrsEdgeForwarder::proxy_message(SrsEdgeProxyContext* context)
|
||||||
|
{
|
||||||
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
SrsCommonMessage* msg = NULL;
|
||||||
|
|
||||||
|
// proxy origin message to client
|
||||||
|
msg = NULL;
|
||||||
|
ret = context->origin_rtmp->recv_message(&msg);
|
||||||
|
if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {
|
||||||
|
srs_error("recv origin server message failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
if (msg->size <= 0) {
|
||||||
|
srs_freep(msg);
|
||||||
|
} else {
|
||||||
|
msg->header.stream_id = context->edge_stream_id;
|
||||||
|
if ((ret = context->edge_rtmp->send_message(msg)) != ERROR_SUCCESS) {
|
||||||
|
srs_error("send origin message to client failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// proxy client message to origin
|
||||||
|
msg = NULL;
|
||||||
|
ret = context->edge_rtmp->recv_message(&msg);
|
||||||
|
if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {
|
||||||
|
srs_error("recv client message failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
if (msg->size <= 0) {
|
||||||
|
srs_freep(msg);
|
||||||
|
} else {
|
||||||
|
msg->header.stream_id = context->origin_stream_id;
|
||||||
|
if ((ret = context->origin_rtmp->send_message(msg)) != ERROR_SUCCESS) {
|
||||||
|
srs_error("send client message to origin failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -620,21 +659,33 @@ int SrsPublishEdge::on_client_publish()
|
||||||
// error state.
|
// error state.
|
||||||
if (user_state != SrsEdgeUserStateInit) {
|
if (user_state != SrsEdgeUserStateInit) {
|
||||||
ret = ERROR_RTMP_EDGE_PUBLISH_STATE;
|
ret = ERROR_RTMP_EDGE_PUBLISH_STATE;
|
||||||
srs_error("invalid state for client to play stream on edge. "
|
srs_error("invalid state for client to publish stream on edge. "
|
||||||
"state=%d, user_state=%d, ret=%d", state, user_state, ret);
|
"state=%d, user_state=%d, ret=%d", state, user_state, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start ingest when init state.
|
// error when not init state.
|
||||||
if (state == SrsEdgeStateInit) {
|
if (state != SrsEdgeStateInit) {
|
||||||
state = SrsEdgeStatePublish;
|
ret = ERROR_RTMP_EDGE_PUBLISH_STATE;
|
||||||
|
srs_error("invalid state for client to publish stream on edge. "
|
||||||
|
"state=%d, user_state=%d, ret=%d", state, user_state, ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
SrsEdgeState pstate = state;
|
||||||
|
state = SrsEdgeStatePublish;
|
||||||
|
srs_trace("edge change from %d to state %d (forward publish).", pstate, state);
|
||||||
|
|
||||||
|
return forwarder->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsPublishEdge::on_forward_publish()
|
int SrsPublishEdge::on_proxy_publish(SrsEdgeProxyContext* context)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = forwarder->proxy(context);
|
||||||
|
|
||||||
|
SrsEdgeState pstate = state;
|
||||||
|
state = SrsEdgeStateInit;
|
||||||
|
srs_trace("edge change from %d to state %d (init).", pstate, state);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <srs_app_st.hpp>
|
#include <srs_app_st.hpp>
|
||||||
#include <srs_app_thread.hpp>
|
#include <srs_app_thread.hpp>
|
||||||
|
|
||||||
|
class SrsSocket;
|
||||||
|
class SrsRtmpServer;
|
||||||
class SrsSource;
|
class SrsSource;
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
class SrsPlayEdge;
|
class SrsPlayEdge;
|
||||||
|
@ -55,8 +57,6 @@ enum SrsEdgeState
|
||||||
|
|
||||||
// for publish edge
|
// for publish edge
|
||||||
SrsEdgeStatePublish = 200,
|
SrsEdgeStatePublish = 200,
|
||||||
// publish stream to edge, forward to origin
|
|
||||||
SrsEdgeStateForwardConnected,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,10 +101,25 @@ private:
|
||||||
virtual int process_publish_message(SrsCommonMessage* msg);
|
virtual int process_publish_message(SrsCommonMessage* msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SrsEdgeProxyContext
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int edge_stream_id;
|
||||||
|
ISrsProtocolReaderWriter* edge_io;
|
||||||
|
SrsRtmpServer* edge_rtmp;
|
||||||
|
public:
|
||||||
|
int origin_stream_id;
|
||||||
|
ISrsProtocolReaderWriter* origin_io;
|
||||||
|
SrsRtmpClient* origin_rtmp;
|
||||||
|
public:
|
||||||
|
SrsEdgeProxyContext();
|
||||||
|
virtual ~SrsEdgeProxyContext();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* edge used to forward stream to origin.
|
* edge used to forward stream to origin.
|
||||||
*/
|
*/
|
||||||
class SrsEdgeForwarder : public ISrsThreadHandler
|
class SrsEdgeForwarder
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int stream_id;
|
int stream_id;
|
||||||
|
@ -112,7 +127,6 @@ private:
|
||||||
SrsSource* _source;
|
SrsSource* _source;
|
||||||
SrsPublishEdge* _edge;
|
SrsPublishEdge* _edge;
|
||||||
SrsRequest* _req;
|
SrsRequest* _req;
|
||||||
SrsThread* pthread;
|
|
||||||
st_netfd_t stfd;
|
st_netfd_t stfd;
|
||||||
ISrsProtocolReaderWriter* io;
|
ISrsProtocolReaderWriter* io;
|
||||||
SrsRtmpClient* client;
|
SrsRtmpClient* client;
|
||||||
|
@ -124,11 +138,10 @@ public:
|
||||||
virtual int initialize(SrsSource* source, SrsPublishEdge* edge, SrsRequest* req);
|
virtual int initialize(SrsSource* source, SrsPublishEdge* edge, SrsRequest* req);
|
||||||
virtual int start();
|
virtual int start();
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
// interface ISrsThreadHandler
|
|
||||||
public:
|
public:
|
||||||
virtual int cycle();
|
virtual int proxy(SrsEdgeProxyContext* context);
|
||||||
private:
|
private:
|
||||||
virtual int forward();
|
virtual int proxy_message(SrsEdgeProxyContext* context);
|
||||||
virtual void close_underlayer_socket();
|
virtual void close_underlayer_socket();
|
||||||
virtual int connect_server();
|
virtual int connect_server();
|
||||||
};
|
};
|
||||||
|
@ -182,11 +195,10 @@ public:
|
||||||
* when client publish stream on edge.
|
* when client publish stream on edge.
|
||||||
*/
|
*/
|
||||||
virtual int on_client_publish();
|
virtual int on_client_publish();
|
||||||
public:
|
|
||||||
/**
|
/**
|
||||||
* when forwarder start to publish stream.
|
* proxy publish stream to edge
|
||||||
*/
|
*/
|
||||||
virtual int on_forward_publish();
|
virtual int on_proxy_publish(SrsEdgeProxyContext* context);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,6 +42,7 @@ using namespace std;
|
||||||
#include <srs_app_bandwidth.hpp>
|
#include <srs_app_bandwidth.hpp>
|
||||||
#include <srs_app_socket.hpp>
|
#include <srs_app_socket.hpp>
|
||||||
#include <srs_app_http_hooks.hpp>
|
#include <srs_app_http_hooks.hpp>
|
||||||
|
#include <srs_app_edge.hpp>
|
||||||
|
|
||||||
// when stream is busy, for example, streaming is already
|
// when stream is busy, for example, streaming is already
|
||||||
// publishing, when a new client to request to publish,
|
// publishing, when a new client to request to publish,
|
||||||
|
@ -332,6 +333,15 @@ int SrsRtmpConn::stream_service_cycle()
|
||||||
srs_error("start to publish stream failed. ret=%d", ret);
|
srs_error("start to publish stream failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SrsEdgeProxyContext context;
|
||||||
|
context.edge_io = skt;
|
||||||
|
context.edge_stream_id = res->stream_id;
|
||||||
|
context.edge_rtmp = rtmp;
|
||||||
|
if (vhost_is_edge) {
|
||||||
|
return source->on_edge_proxy_publish(&context);
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret = on_publish()) != ERROR_SUCCESS) {
|
if ((ret = on_publish()) != ERROR_SUCCESS) {
|
||||||
srs_error("http hook on_publish failed. ret=%d", ret);
|
srs_error("http hook on_publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -345,10 +355,26 @@ int SrsRtmpConn::stream_service_cycle()
|
||||||
case SrsRtmpConnFlashPublish: {
|
case SrsRtmpConnFlashPublish: {
|
||||||
srs_verbose("flash start to publish stream %s.", req->stream.c_str());
|
srs_verbose("flash start to publish stream %s.", req->stream.c_str());
|
||||||
|
|
||||||
|
if (vhost_is_edge) {
|
||||||
|
if ((ret = source->on_edge_start_publish()) != ERROR_SUCCESS) {
|
||||||
|
srs_error("notice edge start publish stream failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret = rtmp->start_flash_publish(res->stream_id)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->start_flash_publish(res->stream_id)) != ERROR_SUCCESS) {
|
||||||
srs_error("flash start to publish stream failed. ret=%d", ret);
|
srs_error("flash start to publish stream failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SrsEdgeProxyContext context;
|
||||||
|
context.edge_io = skt;
|
||||||
|
context.edge_stream_id = res->stream_id;
|
||||||
|
context.edge_rtmp = rtmp;
|
||||||
|
if (vhost_is_edge) {
|
||||||
|
return source->on_edge_proxy_publish(&context);
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret = on_publish()) != ERROR_SUCCESS) {
|
if ((ret = on_publish()) != ERROR_SUCCESS) {
|
||||||
srs_error("http hook on_publish failed. ret=%d", ret);
|
srs_error("http hook on_publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1199,6 +1199,11 @@ int SrsSource::on_edge_start_publish()
|
||||||
return publish_edge->on_client_publish();
|
return publish_edge->on_client_publish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SrsSource::on_edge_proxy_publish(SrsEdgeProxyContext* context)
|
||||||
|
{
|
||||||
|
return publish_edge->on_proxy_publish(context);
|
||||||
|
}
|
||||||
|
|
||||||
int SrsSource::create_forwarders()
|
int SrsSource::create_forwarders()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
|
@ -45,6 +45,9 @@ class SrsOnMetaDataPacket;
|
||||||
class SrsSharedPtrMessage;
|
class SrsSharedPtrMessage;
|
||||||
class SrsForwarder;
|
class SrsForwarder;
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
|
class SrsSocket;
|
||||||
|
class SrsRtmpServer;
|
||||||
|
class SrsEdgeProxyContext;
|
||||||
#ifdef SRS_AUTO_HLS
|
#ifdef SRS_AUTO_HLS
|
||||||
class SrsHls;
|
class SrsHls;
|
||||||
#endif
|
#endif
|
||||||
|
@ -318,6 +321,8 @@ public:
|
||||||
virtual int on_edge_start_play();
|
virtual int on_edge_start_play();
|
||||||
// for edge, when publish edge stream, check the state
|
// for edge, when publish edge stream, check the state
|
||||||
virtual int on_edge_start_publish();
|
virtual int on_edge_start_publish();
|
||||||
|
// for edge, proxy the publish
|
||||||
|
virtual int on_edge_proxy_publish(SrsEdgeProxyContext* context);
|
||||||
private:
|
private:
|
||||||
virtual int create_forwarders();
|
virtual int create_forwarders();
|
||||||
virtual void destroy_forwarders();
|
virtual void destroy_forwarders();
|
||||||
|
|
|
@ -652,11 +652,17 @@ int SrsProtocol::on_send_message(ISrsMessage* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsCommonMessage* common_msg = dynamic_cast<SrsCommonMessage*>(msg);
|
SrsCommonMessage* common_msg = dynamic_cast<SrsCommonMessage*>(msg);
|
||||||
if (!msg) {
|
if (!common_msg) {
|
||||||
srs_verbose("ignore the shared ptr message.");
|
srs_verbose("ignore the shared ptr message.");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for proxy, the common msg is not decoded, ignore.
|
||||||
|
if (!common_msg->has_packet()) {
|
||||||
|
srs_verbose("ignore the proxy common message.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
srs_assert(common_msg != NULL);
|
srs_assert(common_msg != NULL);
|
||||||
|
|
||||||
switch (common_msg->header.message_type) {
|
switch (common_msg->header.message_type) {
|
||||||
|
@ -1459,6 +1465,11 @@ int SrsCommonMessage::decode_packet(SrsProtocol* protocol)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SrsCommonMessage::has_packet()
|
||||||
|
{
|
||||||
|
return packet != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SrsPacket* SrsCommonMessage::get_packet()
|
SrsPacket* SrsCommonMessage::get_packet()
|
||||||
{
|
{
|
||||||
if (!packet) {
|
if (!packet) {
|
||||||
|
@ -1501,6 +1512,14 @@ int SrsCommonMessage::encode_packet()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
// sometimes, for example, the edge proxy,
|
||||||
|
// the payload is not decoded, so directly sent out.
|
||||||
|
if (payload != NULL) {
|
||||||
|
header.payload_length = size;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// encode packet to payload and size.
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
srs_warn("packet is empty, send out empty message.");
|
srs_warn("packet is empty, send out empty message.");
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -352,6 +352,10 @@ public:
|
||||||
// TODO: use protocol to decode it.
|
// TODO: use protocol to decode it.
|
||||||
virtual int decode_packet(SrsProtocol* protocol);
|
virtual int decode_packet(SrsProtocol* protocol);
|
||||||
/**
|
/**
|
||||||
|
* whether msg has decoded packet.
|
||||||
|
*/
|
||||||
|
virtual bool has_packet();
|
||||||
|
/**
|
||||||
* get the decoded packet which decoded by decode_packet().
|
* get the decoded packet which decoded by decode_packet().
|
||||||
* @remark, user never free the pkt, the message will auto free it.
|
* @remark, user never free the pkt, the message will auto free it.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue