Skip to content

Commit

Permalink
For #913, source cycle error
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 11, 2017
1 parent 7275fd5 commit 7cac35a
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 152 deletions.
33 changes: 14 additions & 19 deletions trunk/src/app/srs_app_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ SrsMpdWriter::~SrsMpdWriter()
{
}

int SrsMpdWriter::initialize(SrsRequest* r)
srs_error_t SrsMpdWriter::initialize(SrsRequest* r)
{
int ret = ERROR_SUCCESS;

req = r;
fragment = _srs_config->get_dash_fragment(r->vhost);
update_period = _srs_config->get_dash_update_period(r->vhost);
Expand All @@ -187,8 +185,7 @@ int SrsMpdWriter::initialize(SrsRequest* r)
fragment_home = srs_path_dirname(mpd_path) + "/" + req->stream;

srs_trace("DASH: Config fragment=%d, period=%d", fragment, update_period);

return ret;
return srs_success;
}

int SrsMpdWriter::write(SrsFormat* format)
Expand Down Expand Up @@ -309,35 +306,34 @@ SrsDashController::~SrsDashController()
srs_freep(afragments);
}

int SrsDashController::initialize(SrsRequest* r)
srs_error_t SrsDashController::initialize(SrsRequest* r)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

req = r;
fragment = _srs_config->get_dash_fragment(r->vhost);
home = _srs_config->get_dash_path(r->vhost);

if ((ret = mpd->initialize(r)) != ERROR_SUCCESS) {
return ret;
if ((err = mpd->initialize(r)) != srs_success) {
return srs_error_wrap(err, "mpd");
}

string home, path;

srs_freep(vcurrent);
vcurrent = new SrsFragmentedMp4();
if ((ret = vcurrent->initialize(req, true, mpd, video_tack_id)) != ERROR_SUCCESS) {
srs_error("DASH: Initialize the video fragment failed, ret=%d", ret);
return ret;
return srs_error_new(ret, "video fragment");
}

srs_freep(acurrent);
acurrent = new SrsFragmentedMp4();
if ((ret = acurrent->initialize(req, false, mpd, audio_track_id)) != ERROR_SUCCESS) {
srs_error("DASH: Initialize the audio fragment failed, ret=%d", ret);
return ret;
return srs_error_new(ret, "audio fragment");
}

return ret;
return err;
}

int SrsDashController::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
Expand Down Expand Up @@ -484,19 +480,18 @@ SrsDash::~SrsDash()
srs_freep(controller);
}

int SrsDash::initialize(SrsOriginHub* h, SrsRequest* r)
srs_error_t SrsDash::initialize(SrsOriginHub* h, SrsRequest* r)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

hub = h;
req = r;

if ((ret = controller->initialize(req)) != ERROR_SUCCESS) {
srs_error("DASH: Initialize controller failed. ret=%d", ret);
return ret;
if ((err = controller->initialize(req)) != srs_success) {
return srs_error_wrap(err, "controller");
}

return ret;
return err;
}

int SrsDash::on_publish()
Expand Down
6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_dash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class SrsMpdWriter
SrsMpdWriter();
virtual ~SrsMpdWriter();
public:
virtual int initialize(SrsRequest* r);
virtual srs_error_t initialize(SrsRequest* r);
// Write MPD according to parsed format of stream.
virtual int write(SrsFormat* format);
public:
Expand Down Expand Up @@ -137,7 +137,7 @@ class SrsDashController
SrsDashController();
virtual ~SrsDashController();
public:
virtual int initialize(SrsRequest* r);
virtual srs_error_t initialize(SrsRequest* r);
virtual int on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format);
virtual int on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format);
private:
Expand All @@ -161,7 +161,7 @@ class SrsDash
virtual ~SrsDash();
public:
// Initalize the encoder.
virtual int initialize(SrsOriginHub* h, SrsRequest* r);
virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r);
// When stream start publishing.
virtual int on_publish();
// When got an shared audio message.
Expand Down
52 changes: 24 additions & 28 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ SrsDvrSegmenter::~SrsDvrSegmenter()
srs_freep(fs);
}

int SrsDvrSegmenter::initialize(SrsDvrPlan* p, SrsRequest* r)
srs_error_t SrsDvrSegmenter::initialize(SrsDvrPlan* p, SrsRequest* r)
{
int ret = ERROR_SUCCESS;

req = r;
plan = p;

jitter_algorithm = (SrsRtmpJitterAlgorithm)_srs_config->get_dvr_time_jitter(req->vhost);
wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost);

return ret;
return srs_success;
}

SrsFragment* SrsDvrSegmenter::current()
Expand Down Expand Up @@ -612,23 +610,24 @@ SrsDvrPlan::~SrsDvrPlan()
srs_freep(async);
}

int SrsDvrPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r)
srs_error_t SrsDvrPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

hub = h;
req = r;
segment = s;

if ((ret = segment->initialize(this, r)) != ERROR_SUCCESS) {
return ret;
if ((err = segment->initialize(this, r)) != srs_success) {
return srs_error_wrap(err, "segmenter");
}

if ((ret = async->start()) != ERROR_SUCCESS) {
return ret;
return srs_error_new(ret, "async");
}

return ret;
return err;
}

int SrsDvrPlan::on_meta_data(SrsSharedPtrMessage* shared_metadata)
Expand Down Expand Up @@ -688,22 +687,19 @@ int SrsDvrPlan::on_reap_segment()
return ret;
}

int SrsDvrPlan::create_plan(string vhost, SrsDvrPlan** pplan)
srs_error_t SrsDvrPlan::create_plan(string vhost, SrsDvrPlan** pplan)
{
int ret = ERROR_SUCCESS;

std::string plan = _srs_config->get_dvr_plan(vhost);
if (srs_config_dvr_is_plan_segment(plan)) {
*pplan = new SrsDvrSegmentPlan();
} else if (srs_config_dvr_is_plan_session(plan)) {
*pplan = new SrsDvrSessionPlan();
} else {
ret = ERROR_DVR_ILLEGAL_PLAN;
srs_error("DVR illegal plan=%s, vhost=%s. ret=%d", plan.c_str(), vhost.c_str(), ret);
return ret;
return srs_error_new(ERROR_DVR_ILLEGAL_PLAN, "illegal plan=%s, vhost=%s",
plan.c_str(), vhost.c_str());
}

return ret;
return srs_success;
}

SrsDvrSessionPlan::SrsDvrSessionPlan()
Expand Down Expand Up @@ -766,12 +762,12 @@ SrsDvrSegmentPlan::~SrsDvrSegmentPlan()
{
}

int SrsDvrSegmentPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r)
srs_error_t SrsDvrSegmentPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

if ((ret = SrsDvrPlan::initialize(h, s, r)) != ERROR_SUCCESS) {
return ret;
if ((err = SrsDvrPlan::initialize(h, s, r)) != srs_success) {
return srs_error_wrap(err, "segment plan");
}

wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost);
Expand All @@ -780,7 +776,7 @@ int SrsDvrSegmentPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsReques
// to ms
cduration *= 1000;

return ret;
return srs_success;
}

int SrsDvrSegmentPlan::on_publish()
Expand Down Expand Up @@ -924,9 +920,9 @@ SrsDvr::~SrsDvr()
srs_freep(plan);
}

int SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r)
srs_error_t SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

req = r;
hub = h;
Expand All @@ -935,8 +931,8 @@ int SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r)
actived = srs_config_apply_filter(conf, r);

srs_freep(plan);
if ((ret = SrsDvrPlan::create_plan(r->vhost, &plan)) != ERROR_SUCCESS) {
return ret;
if ((err = SrsDvrPlan::create_plan(r->vhost, &plan)) != srs_success) {
return srs_error_wrap(err, "create plan");
}

std::string path = _srs_config->get_dvr_path(r->vhost);
Expand All @@ -947,11 +943,11 @@ int SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r)
segmenter = new SrsDvrFlvSegmenter();
}

if ((ret = plan->initialize(hub, segmenter, r)) != ERROR_SUCCESS) {
return ret;
if ((err = plan->initialize(hub, segmenter, r)) != srs_success) {
return srs_error_wrap(err, "plan initialize");
}

return ret;
return err;
}

int SrsDvr::on_publish()
Expand Down
10 changes: 5 additions & 5 deletions trunk/src/app/srs_app_dvr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SrsDvrSegmenter : public ISrsReloadHandler
virtual ~SrsDvrSegmenter();
public:
// Initialize the segment.
virtual int initialize(SrsDvrPlan* p, SrsRequest* r);
virtual srs_error_t initialize(SrsDvrPlan* p, SrsRequest* r);
// Get the current framgnet.
virtual SrsFragment* current();
// Open new segment file.
Expand Down Expand Up @@ -194,7 +194,7 @@ class SrsDvrPlan : public ISrsReloadHandler
SrsDvrPlan();
virtual ~SrsDvrPlan();
public:
virtual int initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r);
virtual srs_error_t initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r);
virtual int on_publish() = 0;
virtual void on_unpublish() = 0;
virtual int on_meta_data(SrsSharedPtrMessage* shared_metadata);
Expand All @@ -205,7 +205,7 @@ class SrsDvrPlan : public ISrsReloadHandler
// When segmenter close a segment.
virtual int on_reap_segment();
public:
static int create_plan(std::string vhost, SrsDvrPlan** pplan);
static srs_error_t create_plan(std::string vhost, SrsDvrPlan** pplan);
};

/**
Expand Down Expand Up @@ -234,7 +234,7 @@ class SrsDvrSegmentPlan : public SrsDvrPlan
SrsDvrSegmentPlan();
virtual ~SrsDvrSegmentPlan();
public:
virtual int initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r);
virtual srs_error_t initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r);
virtual int on_publish();
virtual void on_unpublish();
virtual int on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format);
Expand Down Expand Up @@ -269,7 +269,7 @@ class SrsDvr : public ISrsReloadHandler
* when system initialize(encoder publish at first time, or reload),
* initialize the dvr will reinitialize the plan, the whole dvr framework.
*/
virtual int initialize(SrsOriginHub* h, SrsRequest* r);
virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r);
/**
* publish stream event,
* when encoder start to publish RTMP stream.
Expand Down
32 changes: 14 additions & 18 deletions trunk/src/app/srs_app_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,13 @@ SrsEdgeIngester::~SrsEdgeIngester()
srs_freep(trd);
}

int SrsEdgeIngester::initialize(SrsSource* s, SrsPlayEdge* e, SrsRequest* r)
srs_error_t SrsEdgeIngester::initialize(SrsSource* s, SrsPlayEdge* e, SrsRequest* r)
{
int ret = ERROR_SUCCESS;

source = s;
edge = e;
req = r;

return ret;
return srs_success;
}

int SrsEdgeIngester::start()
Expand Down Expand Up @@ -441,15 +439,13 @@ void SrsEdgeForwarder::set_queue_size(double queue_size)
return queue->set_queue_size(queue_size);
}

int SrsEdgeForwarder::initialize(SrsSource* s, SrsPublishEdge* e, SrsRequest* r)
srs_error_t SrsEdgeForwarder::initialize(SrsSource* s, SrsPublishEdge* e, SrsRequest* r)
{
int ret = ERROR_SUCCESS;

source = s;
edge = e;
req = r;

return ret;
return srs_success;
}

int SrsEdgeForwarder::start()
Expand Down Expand Up @@ -634,15 +630,15 @@ SrsPlayEdge::~SrsPlayEdge()
srs_freep(ingester);
}

int SrsPlayEdge::initialize(SrsSource* source, SrsRequest* req)
srs_error_t SrsPlayEdge::initialize(SrsSource* source, SrsRequest* req)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

if ((ret = ingester->initialize(source, this, req)) != ERROR_SUCCESS) {
return ret;
if ((err = ingester->initialize(source, this, req)) != srs_success) {
return srs_error_wrap(err, "ingester(pull)");
}

return ret;
return err;
}

int SrsPlayEdge::on_client_play()
Expand Down Expand Up @@ -712,15 +708,15 @@ void SrsPublishEdge::set_queue_size(double queue_size)
return forwarder->set_queue_size(queue_size);
}

int SrsPublishEdge::initialize(SrsSource* source, SrsRequest* req)
srs_error_t SrsPublishEdge::initialize(SrsSource* source, SrsRequest* req)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

if ((ret = forwarder->initialize(source, this, req)) != ERROR_SUCCESS) {
return ret;
if ((err = forwarder->initialize(source, this, req)) != srs_success) {
return srs_error_wrap(err, "forwarder(push)");
}

return ret;
return err;
}

bool SrsPublishEdge::can_publish()
Expand Down
Loading

0 comments on commit 7cac35a

Please sign in to comment.