mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine source, rename req to _req
This commit is contained in:
parent
a2f317a113
commit
b0951d36d3
5 changed files with 51 additions and 35 deletions
|
@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <srs_app_edge.hpp>
|
#include <srs_app_edge.hpp>
|
||||||
|
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
|
#include <srs_protocol_rtmp.hpp>
|
||||||
|
|
||||||
SrsEdge::SrsEdge()
|
SrsEdge::SrsEdge()
|
||||||
{
|
{
|
||||||
|
@ -34,6 +35,15 @@ SrsEdge::~SrsEdge()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SrsEdge::initialize(SrsRequest* req)
|
||||||
|
{
|
||||||
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
_req = req;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int SrsEdge::on_client_play()
|
int SrsEdge::on_client_play()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
|
@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
|
class SrsRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the state of edge
|
* the state of edge
|
||||||
*/
|
*/
|
||||||
|
@ -49,11 +51,13 @@ enum SrsEdgeState
|
||||||
class SrsEdge
|
class SrsEdge
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
SrsRequest* _req;
|
||||||
SrsEdgeState state;
|
SrsEdgeState state;
|
||||||
public:
|
public:
|
||||||
SrsEdge();
|
SrsEdge();
|
||||||
virtual ~SrsEdge();
|
virtual ~SrsEdge();
|
||||||
public:
|
public:
|
||||||
|
virtual int initialize(SrsRequest* req);
|
||||||
/**
|
/**
|
||||||
* when client play stream on edge.
|
* when client play stream on edge.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -515,7 +515,7 @@ int SrsRtmpConn::fmle_publish(SrsSource* source)
|
||||||
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
|
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
|
||||||
|
|
||||||
// notify the hls to prepare when publish start.
|
// notify the hls to prepare when publish start.
|
||||||
if ((ret = source->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = source->on_publish()) != ERROR_SUCCESS) {
|
||||||
srs_error("fmle hls on_publish failed. ret=%d", ret);
|
srs_error("fmle hls on_publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -584,7 +584,7 @@ int SrsRtmpConn::flash_publish(SrsSource* source)
|
||||||
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
|
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
|
||||||
|
|
||||||
// notify the hls to prepare when publish start.
|
// notify the hls to prepare when publish start.
|
||||||
if ((ret = source->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = source->on_publish()) != ERROR_SUCCESS) {
|
||||||
srs_error("flash hls on_publish failed. ret=%d", ret);
|
srs_error("flash hls on_publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,9 +437,9 @@ int SrsSource::find(SrsRequest* req, SrsSource** ppsource)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSource::SrsSource(SrsRequest* _req)
|
SrsSource::SrsSource(SrsRequest* req)
|
||||||
{
|
{
|
||||||
req = _req->copy();
|
_req = req->copy();
|
||||||
|
|
||||||
#ifdef SRS_AUTO_HLS
|
#ifdef SRS_AUTO_HLS
|
||||||
hls = new SrsHls(this);
|
hls = new SrsHls(this);
|
||||||
|
@ -460,7 +460,7 @@ SrsSource::SrsSource(SrsRequest* _req)
|
||||||
gop_cache = new SrsGopCache();
|
gop_cache = new SrsGopCache();
|
||||||
|
|
||||||
_srs_config->subscribe(this);
|
_srs_config->subscribe(this);
|
||||||
atc = _srs_config->get_atc(req->vhost);
|
atc = _srs_config->get_atc(_req->vhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSource::~SrsSource()
|
SrsSource::~SrsSource()
|
||||||
|
@ -502,7 +502,7 @@ SrsSource::~SrsSource()
|
||||||
srs_freep(encoder);
|
srs_freep(encoder);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
srs_freep(req);
|
srs_freep(_req);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSource::initialize()
|
int SrsSource::initialize()
|
||||||
|
@ -510,11 +510,15 @@ int SrsSource::initialize()
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
#ifdef SRS_AUTO_DVR
|
#ifdef SRS_AUTO_DVR
|
||||||
if ((ret = dvr->initialize(req)) != ERROR_SUCCESS) {
|
if ((ret = dvr->initialize(_req)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if ((ret = edge->initialize(_req)) != ERROR_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +526,7 @@ int SrsSource::on_reload_vhost_atc(string vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
if (_req->vhost != vhost) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +545,7 @@ int SrsSource::on_reload_vhost_gop_cache(string vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
if (_req->vhost != vhost) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,7 +553,7 @@ int SrsSource::on_reload_vhost_gop_cache(string vhost)
|
||||||
bool enabled_cache = _srs_config->get_gop_cache(vhost);
|
bool enabled_cache = _srs_config->get_gop_cache(vhost);
|
||||||
|
|
||||||
srs_trace("vhost %s gop_cache changed to %d, source url=%s",
|
srs_trace("vhost %s gop_cache changed to %d, source url=%s",
|
||||||
vhost.c_str(), enabled_cache, req->get_stream_url().c_str());
|
vhost.c_str(), enabled_cache, _req->get_stream_url().c_str());
|
||||||
|
|
||||||
set_cache(enabled_cache);
|
set_cache(enabled_cache);
|
||||||
|
|
||||||
|
@ -560,11 +564,11 @@ int SrsSource::on_reload_vhost_queue_length(string vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
if (_req->vhost != vhost) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
double queue_size = _srs_config->get_queue_length(req->vhost);
|
double queue_size = _srs_config->get_queue_length(_req->vhost);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
std::vector<SrsConsumer*>::iterator it;
|
std::vector<SrsConsumer*>::iterator it;
|
||||||
|
@ -595,7 +599,7 @@ int SrsSource::on_reload_vhost_forward(string vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
if (_req->vhost != vhost) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,13 +619,13 @@ int SrsSource::on_reload_vhost_hls(string vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
if (_req->vhost != vhost) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SRS_AUTO_HLS
|
#ifdef SRS_AUTO_HLS
|
||||||
hls->on_unpublish();
|
hls->on_unpublish();
|
||||||
if ((ret = hls->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) {
|
||||||
srs_error("hls publish failed. ret=%d", ret);
|
srs_error("hls publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -635,7 +639,7 @@ int SrsSource::on_reload_vhost_dvr(string vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
if (_req->vhost != vhost) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,12 +648,12 @@ int SrsSource::on_reload_vhost_dvr(string vhost)
|
||||||
dvr->on_unpublish();
|
dvr->on_unpublish();
|
||||||
|
|
||||||
// reinitialize the dvr, update plan.
|
// reinitialize the dvr, update plan.
|
||||||
if ((ret = dvr->initialize(req)) != ERROR_SUCCESS) {
|
if ((ret = dvr->initialize(_req)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start to publish by new plan.
|
// start to publish by new plan.
|
||||||
if ((ret = dvr->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = dvr->on_publish(_req)) != ERROR_SUCCESS) {
|
||||||
srs_error("dvr publish failed. ret=%d", ret);
|
srs_error("dvr publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -664,13 +668,13 @@ int SrsSource::on_reload_vhost_transcode(string vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
if (_req->vhost != vhost) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SRS_AUTO_TRANSCODE
|
#ifdef SRS_AUTO_TRANSCODE
|
||||||
encoder->on_unpublish();
|
encoder->on_unpublish();
|
||||||
if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = encoder->on_publish(_req)) != ERROR_SUCCESS) {
|
||||||
srs_error("start encoder failed. ret=%d", ret);
|
srs_error("start encoder failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1038,14 +1042,12 @@ int SrsSource::on_video(SrsCommonMessage* video)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSource::on_publish(SrsRequest* _req)
|
int SrsSource::on_publish()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
// update the request object.
|
// update the request object.
|
||||||
srs_freep(req);
|
srs_assert(_req);
|
||||||
req = _req->copy();
|
|
||||||
srs_assert(req);
|
|
||||||
|
|
||||||
_can_publish = false;
|
_can_publish = false;
|
||||||
|
|
||||||
|
@ -1056,21 +1058,21 @@ int SrsSource::on_publish(SrsRequest* _req)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SRS_AUTO_TRANSCODE
|
#ifdef SRS_AUTO_TRANSCODE
|
||||||
if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = encoder->on_publish(_req)) != ERROR_SUCCESS) {
|
||||||
srs_error("start encoder failed. ret=%d", ret);
|
srs_error("start encoder failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SRS_AUTO_HLS
|
#ifdef SRS_AUTO_HLS
|
||||||
if ((ret = hls->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) {
|
||||||
srs_error("start hls failed. ret=%d", ret);
|
srs_error("start hls failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SRS_AUTO_DVR
|
#ifdef SRS_AUTO_DVR
|
||||||
if ((ret = dvr->on_publish(req)) != ERROR_SUCCESS) {
|
if ((ret = dvr->on_publish(_req)) != ERROR_SUCCESS) {
|
||||||
srs_error("start dvr failed. ret=%d", ret);
|
srs_error("start dvr failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1116,7 +1118,7 @@ void SrsSource::on_unpublish()
|
||||||
consumer = new SrsConsumer(this);
|
consumer = new SrsConsumer(this);
|
||||||
consumers.push_back(consumer);
|
consumers.push_back(consumer);
|
||||||
|
|
||||||
double queue_size = _srs_config->get_queue_length(req->vhost);
|
double queue_size = _srs_config->get_queue_length(_req->vhost);
|
||||||
consumer->set_queue_size(queue_size);
|
consumer->set_queue_size(queue_size);
|
||||||
|
|
||||||
if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), sample_rate, frame_rate)) != ERROR_SUCCESS) {
|
if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), sample_rate, frame_rate)) != ERROR_SUCCESS) {
|
||||||
|
@ -1187,20 +1189,20 @@ int SrsSource::create_forwarders()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
SrsConfDirective* conf = _srs_config->get_forward(req->vhost);
|
SrsConfDirective* conf = _srs_config->get_forward(_req->vhost);
|
||||||
for (int i = 0; conf && i < (int)conf->args.size(); i++) {
|
for (int i = 0; conf && i < (int)conf->args.size(); i++) {
|
||||||
std::string forward_server = conf->args.at(i);
|
std::string forward_server = conf->args.at(i);
|
||||||
|
|
||||||
SrsForwarder* forwarder = new SrsForwarder(this);
|
SrsForwarder* forwarder = new SrsForwarder(this);
|
||||||
forwarders.push_back(forwarder);
|
forwarders.push_back(forwarder);
|
||||||
|
|
||||||
double queue_size = _srs_config->get_queue_length(req->vhost);
|
double queue_size = _srs_config->get_queue_length(_req->vhost);
|
||||||
forwarder->set_queue_size(queue_size);
|
forwarder->set_queue_size(queue_size);
|
||||||
|
|
||||||
if ((ret = forwarder->on_publish(req, forward_server)) != ERROR_SUCCESS) {
|
if ((ret = forwarder->on_publish(_req, forward_server)) != ERROR_SUCCESS) {
|
||||||
srs_error("start forwarder failed. "
|
srs_error("start forwarder failed. "
|
||||||
"vhost=%s, app=%s, stream=%s, forward-to=%s",
|
"vhost=%s, app=%s, stream=%s, forward-to=%s",
|
||||||
req->vhost.c_str(), req->app.c_str(), req->stream.c_str(),
|
_req->vhost.c_str(), _req->app.c_str(), _req->stream.c_str(),
|
||||||
forward_server.c_str());
|
forward_server.c_str());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,7 @@ public:
|
||||||
static int find(SrsRequest* req, SrsSource** ppsource);
|
static int find(SrsRequest* req, SrsSource** ppsource);
|
||||||
private:
|
private:
|
||||||
// deep copy of client request.
|
// deep copy of client request.
|
||||||
SrsRequest* req;
|
SrsRequest* _req;
|
||||||
// to delivery stream to clients.
|
// to delivery stream to clients.
|
||||||
std::vector<SrsConsumer*> consumers;
|
std::vector<SrsConsumer*> consumers;
|
||||||
// hls handler.
|
// hls handler.
|
||||||
|
@ -272,7 +272,7 @@ public:
|
||||||
* @param _req the client request object,
|
* @param _req the client request object,
|
||||||
* this object will deep copy it for reload.
|
* this object will deep copy it for reload.
|
||||||
*/
|
*/
|
||||||
SrsSource(SrsRequest* _req);
|
SrsSource(SrsRequest* req);
|
||||||
virtual ~SrsSource();
|
virtual ~SrsSource();
|
||||||
public:
|
public:
|
||||||
virtual int initialize();
|
virtual int initialize();
|
||||||
|
@ -302,7 +302,7 @@ public:
|
||||||
* @param _req the request from client, the source will deep copy it,
|
* @param _req the request from client, the source will deep copy it,
|
||||||
* for when reload the request of client maybe invalid.
|
* for when reload the request of client maybe invalid.
|
||||||
*/
|
*/
|
||||||
virtual int on_publish(SrsRequest* _req);
|
virtual int on_publish();
|
||||||
virtual void on_unpublish();
|
virtual void on_unpublish();
|
||||||
public:
|
public:
|
||||||
virtual int create_consumer(SrsConsumer*& consumer);
|
virtual int create_consumer(SrsConsumer*& consumer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue