From 6eae93258acf9b76cbca0a29944726726fe0caa5 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 1 Jan 2018 19:39:57 +0800 Subject: [PATCH] For #913, APP support complex error. --- trunk/src/app/srs_app_bandwidth.cpp | 199 ++++++------- trunk/src/app/srs_app_bandwidth.hpp | 18 +- trunk/src/app/srs_app_caster_flv.hpp | 10 +- trunk/src/app/srs_app_config.cpp | 268 ++++++++---------- trunk/src/app/srs_app_config.hpp | 384 +++++++++++++------------- trunk/src/app/srs_app_dash.hpp | 26 +- trunk/src/app/srs_app_edge.cpp | 99 +++---- trunk/src/app/srs_app_edge.hpp | 16 +- trunk/src/app/srs_app_encoder.cpp | 112 +++----- trunk/src/app/srs_app_encoder.hpp | 8 +- trunk/src/app/srs_app_ffmpeg.cpp | 91 ++---- trunk/src/app/srs_app_ffmpeg.hpp | 10 +- trunk/src/app/srs_app_forward.cpp | 29 +- trunk/src/app/srs_app_hds.hpp | 12 +- trunk/src/app/srs_app_heartbeat.cpp | 35 ++- trunk/src/app/srs_app_heartbeat.hpp | 2 + trunk/src/app/srs_app_hls.cpp | 32 +-- trunk/src/app/srs_app_hourglass.hpp | 6 +- trunk/src/app/srs_app_http_api.cpp | 349 +++++++++++------------ trunk/src/app/srs_app_http_conn.cpp | 19 +- trunk/src/app/srs_app_http_conn.hpp | 2 +- trunk/src/app/srs_app_http_hooks.cpp | 25 +- trunk/src/app/srs_app_http_hooks.hpp | 3 +- trunk/src/app/srs_app_http_static.cpp | 64 ++--- trunk/src/app/srs_app_http_static.hpp | 2 +- trunk/src/app/srs_app_http_stream.cpp | 20 +- trunk/src/app/srs_app_ingest.cpp | 142 ++++------ trunk/src/app/srs_app_ingest.hpp | 14 +- trunk/src/app/srs_app_kafka.hpp | 12 +- trunk/src/app/srs_app_mpegts_udp.hpp | 18 +- trunk/src/app/srs_app_ng_exec.hpp | 4 +- trunk/src/app/srs_app_process.hpp | 6 +- trunk/src/app/srs_app_recv_thread.cpp | 65 +++-- trunk/src/app/srs_app_recv_thread.hpp | 22 +- trunk/src/app/srs_app_refer.cpp | 35 +-- trunk/src/app/srs_app_refer.hpp | 4 +- trunk/src/app/srs_app_rtmp_conn.cpp | 148 +++++----- trunk/src/app/srs_app_rtmp_conn.hpp | 2 +- trunk/src/app/srs_app_rtsp.hpp | 22 +- trunk/src/app/srs_app_security.hpp | 6 +- trunk/src/app/srs_app_server.cpp | 5 +- trunk/src/app/srs_app_server.hpp | 4 +- trunk/src/app/srs_app_source.cpp | 138 ++++----- trunk/src/app/srs_app_source.hpp | 2 - trunk/src/app/srs_app_statistic.hpp | 22 +- trunk/src/app/srs_app_utility.cpp | 16 +- trunk/src/app/srs_app_utility.hpp | 2 +- 47 files changed, 1098 insertions(+), 1432 deletions(-) diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index 529e85e183..e3b12409cb 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -91,26 +91,25 @@ bool _bandwidth_is_stopped_publish(SrsBandwidthPacket* pkt) { return pkt->is_stopped_publish(); } -int _srs_expect_bandwidth_packet(SrsRtmpServer* rtmp, _CheckPacketType pfn) +srs_error_t _srs_expect_bandwidth_packet(SrsRtmpServer* rtmp, _CheckPacketType pfn) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; while (true) { SrsCommonMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = rtmp->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { - return ret; + if ((err = rtmp->expect_message(&msg, &pkt)) != srs_success) { + return srs_error_wrap(err, "expect message"); } SrsAutoFree(SrsCommonMessage, msg); SrsAutoFree(SrsBandwidthPacket, pkt); - srs_info("get bwtc message success."); if (pfn(pkt)) { - return ret; + return err; } } - return ret; + return err; } SrsBandwidth::SrsBandwidth() @@ -123,24 +122,22 @@ SrsBandwidth::~SrsBandwidth() { } -int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io_stat, SrsRequest* req, string local_ip) +srs_error_t SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io_stat, SrsRequest* req, string local_ip) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; _rtmp = rtmp; _req = req; if (!_srs_config->get_bw_check_enabled(_req->vhost)) { - return ret; + return err; } // validate the bandwidth check key std::string key = "key=" + _srs_config->get_bw_check_key(_req->vhost); if (_req->tcUrl.find(key) == std::string::npos) { - ret = ERROR_SYSTEM_BANDWIDTH_KEY; - srs_error("check the vhost=%s %s failed, tcUrl=%s, ret=%d", - _req->vhost.c_str(), key.c_str(), _req->tcUrl.c_str(), ret); - return ret; + return srs_error_new(ERROR_SYSTEM_BANDWIDTH_KEY, "check the vhost=%s %s failed, tcUrl=%s", + _req->vhost.c_str(), key.c_str(), _req->tcUrl.c_str()); } // shared global last check time, @@ -154,21 +151,15 @@ int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io int64_t time_now = srs_get_system_time_ms(); // reject the connection in the interval window. if (last_check_time > 0 && time_now - last_check_time < interval_ms) { - ret = ERROR_SYSTEM_BANDWIDTH_DENIED; - srs_trace("reject, " - "last_check=%" PRId64 ", now=%" PRId64 ", interval=%d", - last_check_time, time_now, interval_ms); - _rtmp->response_connect_reject(_req, "bandcheck rejected"); - return ret; + return srs_error_new(ERROR_SYSTEM_BANDWIDTH_DENIED, "reject, last_check=%" PRId64 ", now=%" PRId64 ", interval=%d", last_check_time, time_now, interval_ms); } // accept and do bandwidth check. last_check_time = time_now; - if ((ret = _rtmp->response_connect_app(_req, local_ip.c_str())) != ERROR_SUCCESS) { - srs_error("response connect app failed. ret=%d", ret); - return ret; + if ((err = _rtmp->response_connect_app(_req, local_ip.c_str())) != srs_success) { + return srs_error_wrap(err, "response connect app"); } // create a limit object. @@ -181,9 +172,9 @@ int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io return do_bandwidth_check(&limit); } -int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) +srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsBandwidthSample play_sample; SrsBandwidthSample publish_sample; @@ -197,41 +188,27 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) int64_t start_time = srs_get_system_time_ms(); // sample play - srs_info("start play test."); - - if ((ret = play_start(&play_sample, limit)) != ERROR_SUCCESS) { - srs_error("bandwidth play check failed. ret=%d", ret); - return ret; + if ((err = play_start(&play_sample, limit)) != srs_success) { + return srs_error_wrap(err, "play start"); } - if ((ret = play_checking(&play_sample, limit)) != ERROR_SUCCESS) { - srs_error("bandwidth play check failed. ret=%d", ret); - return ret; + if ((err = play_checking(&play_sample, limit)) != srs_success) { + return srs_error_wrap(err, "play check"); } - if ((ret = play_stop(&play_sample, limit)) != ERROR_SUCCESS) { - srs_error("bandwidth play check failed. ret=%d", ret); - return ret; + if ((err = play_stop(&play_sample, limit)) != srs_success) { + return srs_error_wrap(err, "play stop"); } - srs_info("stop play test. kbps=%d", play_sample.kbps); - // sample publish - srs_info("start publish test."); - - if ((ret = publish_start(&publish_sample, limit)) != ERROR_SUCCESS) { - srs_error("bandwidth publish check failed. ret=%d", ret); - return ret; + if ((err = publish_start(&publish_sample, limit)) != srs_success) { + return srs_error_wrap(err, "publish start"); } - if ((ret = publish_checking(&publish_sample, limit)) != ERROR_SUCCESS) { - srs_error("bandwidth publish check failed. ret=%d", ret); - return ret; + if ((err = publish_checking(&publish_sample, limit)) != srs_success) { + return srs_error_wrap(err, "publish check"); } - if ((ret = publish_stop(&publish_sample, limit)) != ERROR_SUCCESS) { - srs_error("bandwidth publish check failed. ret=%d", ret); - return ret; + if ((err = publish_stop(&publish_sample, limit)) != srs_success) { + return srs_error_wrap(err, "publish stop"); } - srs_info("stop publish test. kbps=%d", publish_sample.kbps); - // stop test. srs_update_system_time_ms(); int64_t end_time = srs_get_system_time_ms(); @@ -241,19 +218,18 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) publish_sample.actual_duration_ms, play_sample.kbps, publish_sample.kbps); - if ((ret = finial(play_sample, publish_sample, start_time, end_time)) != ERROR_SUCCESS) { - return ret; + if ((err = do_final(play_sample, publish_sample, start_time, end_time)) != srs_success) { + return srs_error_wrap(err, "final"); } srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT_MS * 1000); - srs_info("BW check finished."); - return ret; + return err; } -int SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) +srs_error_t SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (true) { // send start play command to client @@ -263,24 +239,21 @@ int SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms)); pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); - if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { - srs_error("send bandwidth check start play message failed. ret=%d", ret); - return ret; + if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) { + return srs_error_wrap(err, "send packet"); } } - srs_info("BW check play begin."); - if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_play)) != ERROR_SUCCESS) { - return ret; + if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_play)) != srs_success) { + return srs_error_wrap(err, "expect bandwidth"); } - srs_info("BW check recv play begin response."); - return ret; + return err; } -int SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit) +srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; // send play data to client int size = 1024; // TODO: FIXME: magic number @@ -305,23 +278,21 @@ int SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit) } data_count += 2; - if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { - srs_error("send bandwidth check play messages failed. ret=%d", ret); - return ret; + if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) { + return srs_error_wrap(err, "send packet"); } limit->send_limit(); } srs_update_system_time_ms(); - sample->calc_kbps(_rtmp->get_send_bytes(), srs_get_system_time_ms() - starttime); - srs_info("BW check send play bytes over."); + sample->calc_kbps((int)_rtmp->get_send_bytes(), (int)(srs_get_system_time_ms() - starttime)); - return ret; + return err; } -int SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit*/) +srs_error_t SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit*/) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (true) { // notify client to stop play @@ -332,24 +303,21 @@ int SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit*/) pkt->data->set("duration_delta", SrsAmf0Any::number(sample->actual_duration_ms)); pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes)); - if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { - srs_error("send bandwidth check stop play message failed. ret=%d", ret); - return ret; + if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) { + return srs_error_wrap(err, "send packet"); } } - srs_info("BW check stop play bytes."); - if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_play)) != ERROR_SUCCESS) { - return ret; + if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_play)) != srs_success) { + return srs_error_wrap(err, "expect bandwidth"); } - srs_info("BW check recv stop play response."); - return ret; + return err; } -int SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) +srs_error_t SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (true) { // notify client to start publish @@ -359,24 +327,21 @@ int SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms)); pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); - if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { - srs_error("send bandwidth check start publish message failed. ret=%d", ret); - return ret; + if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) { + return srs_error_wrap(err, "send packet"); } } - srs_info("BW check publish begin."); - if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_publish)) != ERROR_SUCCESS) { - return ret; + if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_publish)) != srs_success) { + return srs_error_wrap(err, "expect packet"); } - srs_info("BW check recv publish begin response."); - return ret; + return err; } -int SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit) +srs_error_t SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; // recv publish msgs until @duration_ms ms srs_update_system_time_ms(); @@ -384,8 +349,8 @@ int SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* lim while ((srs_get_system_time_ms() - starttime) < sample->duration_ms) { SrsCommonMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = _rtmp->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { - return ret; + if ((err = _rtmp->expect_message(&msg, &pkt)) != srs_success) { + return srs_error_wrap(err, "expect message"); } SrsAutoFree(SrsCommonMessage, msg); SrsAutoFree(SrsBandwidthPacket, pkt); @@ -399,15 +364,14 @@ int SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* lim limit->recv_limit(); } srs_update_system_time_ms(); - sample->calc_kbps(_rtmp->get_recv_bytes(), srs_get_system_time_ms() - starttime); - srs_info("BW check recv publish data over."); + sample->calc_kbps((int)_rtmp->get_recv_bytes(), (int)(srs_get_system_time_ms() - starttime)); - return ret; + return err; } -int SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit*/) +srs_error_t SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit*/) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (true) { // notify client to stop publish @@ -417,12 +381,10 @@ int SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit pkt->data->set("duration_delta", SrsAmf0Any::number(sample->actual_duration_ms)); pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes)); - if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { - srs_error("send bandwidth check stop publish message failed. ret=%d", ret); - return ret; + if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) { + return srs_error_wrap(err, "send packet"); } } - srs_info("BW check stop publish bytes."); // expect client to stop publish // if flash client, we never expect the client stop publish bytes, @@ -431,18 +393,17 @@ int SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit // we just ignore the packet and send the bandwidth test data. bool is_flash = (_req->swfUrl != ""); if (!is_flash) { - if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_publish)) != ERROR_SUCCESS) { - return ret; + if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_publish)) != srs_success) { + return srs_error_wrap(err, "expect bandwidth"); } - srs_info("BW check recv stop publish response."); } - return ret; + return err; } -int SrsBandwidth::finial(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time) +srs_error_t SrsBandwidth::do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; // send finished msg, // flash client will close connection when got this packet, @@ -457,24 +418,20 @@ int SrsBandwidth::finial(SrsBandwidthSample& play_sample, SrsBandwidthSample& pu pkt->data->set("play_time", SrsAmf0Any::number(play_sample.actual_duration_ms)); pkt->data->set("publish_time", SrsAmf0Any::number(publish_sample.actual_duration_ms)); - if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { - srs_error("send bandwidth check finish message failed. ret=%d", ret); - return ret; + if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) { + return srs_error_wrap(err, "send packet"); } - srs_info("send finish packet."); // we notice the result, and expect a final packet if not flash. // if flash client, client will disconnect when got finish packet. bool is_flash = (_req->swfUrl != ""); if (!is_flash) { // ignore any error. - _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_final); - srs_info("BW check recv flash final response."); + err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_final); + srs_error_reset(err); } - srs_info("BW check finished."); - - return ret; + return err; } SrsKbpsLimit::SrsKbpsLimit(SrsKbps* kbps, int limit_kbps) diff --git a/trunk/src/app/srs_app_bandwidth.hpp b/trunk/src/app/srs_app_bandwidth.hpp index 0128ee54bd..e2986aa593 100644 --- a/trunk/src/app/srs_app_bandwidth.hpp +++ b/trunk/src/app/srs_app_bandwidth.hpp @@ -131,13 +131,13 @@ class SrsBandwidth * @param req, client request object, specifies the request info from client. * @param local_ip, the ip of server which client connected at */ - virtual int bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io_stat, SrsRequest* req, std::string local_ip); + virtual srs_error_t bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io_stat, SrsRequest* req, std::string local_ip); private: /** * used to process band width check from client. * @param limit, the bandwidth limit object, to slowdown if exceed the kbps. */ - virtual int do_bandwidth_check(SrsKbpsLimit* limit); + virtual srs_error_t do_bandwidth_check(SrsKbpsLimit* limit); // play check/test, downloading bandwidth kbps. private: /** @@ -145,19 +145,19 @@ class SrsBandwidth * send start-play command to client, client must response starting-play * to start the test. */ - virtual int play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); + virtual srs_error_t play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); /** * do play/download bandwidth check/test, * server send call messages to client in specified time, * calc the time and bytes sent, then we got the kbps. */ - virtual int play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); + virtual srs_error_t play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); /** * stop play/download bandwidth check/test, * send stop-play command to client, client must response stopped-play * to stop the test. */ - virtual int play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); + virtual srs_error_t play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); // publish check/test, publishing bandwidth kbps. private: /** @@ -165,7 +165,7 @@ class SrsBandwidth * send start-publish command to client, client must response starting-publish * to start the test. */ - virtual int publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); + virtual srs_error_t publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); /** * do publish/upload bandwidth check/test, * client send call messages to client in specified time, @@ -176,7 +176,7 @@ class SrsBandwidth * the send queue is fullfill with call messages, so we should never expect the * response message in the publish-stop stage. */ - virtual int publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); + virtual srs_error_t publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); /** * stop publish/upload bandwidth check/test, * send stop-publish command to client, @@ -184,7 +184,7 @@ class SrsBandwidth * for flash client, the sent queue is fullfill with publishing call messages, * so server never expect the stopped-publish from it. */ - virtual int publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); + virtual srs_error_t publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); private: /** * report and final packet @@ -193,7 +193,7 @@ class SrsBandwidth * for flash client, the sent queue is fullfill with publishing call messages, * so server never expect the final packet from it. */ - virtual int finial(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time); + virtual srs_error_t do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time); }; /** diff --git a/trunk/src/app/srs_app_caster_flv.hpp b/trunk/src/app/srs_app_caster_flv.hpp index 28eb189202..c43c8393e2 100644 --- a/trunk/src/app/srs_app_caster_flv.hpp +++ b/trunk/src/app/srs_app_caster_flv.hpp @@ -90,9 +90,9 @@ class SrsDynamicHttpConn : public SrsHttpConn public: virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg); public: - virtual int proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string o); + virtual srs_error_t proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string o); private: - virtual int do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec); + virtual srs_error_t do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec); }; /** @@ -110,7 +110,7 @@ class SrsHttpFileReader : public SrsFileReader /** * open file reader, can open then close then open... */ - virtual int open(std::string file); + virtual srs_error_t open(std::string file); virtual void close(); public: // TODO: FIXME: extract interface. @@ -120,8 +120,8 @@ class SrsHttpFileReader : public SrsFileReader virtual int64_t seek2(int64_t offset); virtual int64_t filesize(); public: - virtual int read(void* buf, size_t count, ssize_t* pnread); - virtual int lseek(off_t offset, int whence, off_t* seeked); + virtual srs_error_t read(void* buf, size_t count, ssize_t* pnread); + virtual srs_error_t lseek(off_t offset, int whence, off_t* seeked); }; #endif diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index bdb53891be..199903694e 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -78,7 +78,7 @@ const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER; * @param dir the transcode or ingest config directive. * @param engine the amf0 object to dumps to. */ -int srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine); +srs_error_t srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine); /** * whether the two vector actual equals, for instance, @@ -135,14 +135,13 @@ namespace _srs_internal srs_error_t SrsConfigBuffer::fullfill(const char* filename) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsFileReader reader; // open file reader. - if ((ret = reader.open(filename)) != ERROR_SUCCESS) { - return srs_error_new(ret, "open file=%s", filename); + if ((err = reader.open(filename)) != srs_success) { + return srs_error_wrap(err, "open file=%s", filename); } // read all. @@ -155,8 +154,8 @@ namespace _srs_internal // read total content from file. ssize_t nread = 0; - if ((ret = reader.read(start, filesize, &nread)) != ERROR_SUCCESS) { - return srs_error_new(ret, "read %d only %d bytes", filesize, nread); + if ((err = reader.read(start, filesize, &nread)) != srs_success) { + return srs_error_wrap(err, "read %d only %d bytes", filesize, nread); } return err; @@ -527,9 +526,9 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root) return err; } -int srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine) +srs_error_t srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsConfDirective* conf = NULL; @@ -626,7 +625,7 @@ int srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine) engine->set("output", conf->dumps_arg0_to_str()); } - return ret; + return err; } SrsConfDirective::SrsConfDirective() @@ -803,7 +802,6 @@ srs_error_t SrsConfDirective::parse(SrsConfigBuffer* buffer) srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; static char SPACE = SRS_CONSTS_SP; @@ -817,34 +815,34 @@ srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level) if (level > 0) { // indent by (level - 1) * 4 space. for (int i = 0; i < level - 1; i++) { - if ((ret = writer->write((char*)INDENT, 4, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write indent"); + if ((err = writer->write((char*)INDENT, 4, NULL)) != srs_success) { + return srs_error_wrap(err, "write indent"); } } // directive name. - if ((ret = writer->write((char*)name.c_str(), (int)name.length(), NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write name"); + if ((err = writer->write((char*)name.c_str(), (int)name.length(), NULL)) != srs_success) { + return srs_error_wrap(err, "write name"); } - if (!args.empty() && (ret = writer->write((char*)&SPACE, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write name space"); + if (!args.empty() && (err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write name space"); } // directive args. for (int i = 0; i < (int)args.size(); i++) { std::string& arg = args.at(i); - if ((ret = writer->write((char*)arg.c_str(), (int)arg.length(), NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write arg"); + if ((err = writer->write((char*)arg.c_str(), (int)arg.length(), NULL)) != srs_success) { + return srs_error_wrap(err, "write arg"); } - if (i < (int)args.size() - 1 && (ret = writer->write((char*)&SPACE, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write arg space"); + if (i < (int)args.size() - 1 && (err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write arg space"); } } // native directive, without sub directives. if (directives.empty()) { - if ((ret = writer->write((char*)&SEMICOLON, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write arg semicolon"); + if ((err = writer->write((char*)&SEMICOLON, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write arg semicolon"); } } } @@ -852,16 +850,16 @@ srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level) // persistence all sub directives. if (level > 0) { if (!directives.empty()) { - if ((ret = writer->write((char*)&SPACE, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write sub-dir space"); + if ((err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write sub-dir space"); } - if ((ret = writer->write((char*)&LB, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write sub-dir left-brace"); + if ((err = writer->write((char*)&LB, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write sub-dir left-brace"); } } - if ((ret = writer->write((char*)&LF, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write sub-dir linefeed"); + if ((err = writer->write((char*)&LF, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write sub-dir linefeed"); } } @@ -875,17 +873,17 @@ srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level) if (level > 0 && !directives.empty()) { // indent by (level - 1) * 4 space. for (int i = 0; i < level - 1; i++) { - if ((ret = writer->write((char*)INDENT, 4, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write sub-dir indent"); + if ((err = writer->write((char*)INDENT, 4, NULL)) != srs_success) { + return srs_error_wrap(err, "write sub-dir indent"); } } - if ((ret = writer->write((char*)&RB, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write sub-dir right-brace"); + if ((err = writer->write((char*)&RB, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write sub-dir right-brace"); } - if ((ret = writer->write((char*)&LF, 1, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write sub-dir linefeed"); + if ((err = writer->write((char*)&LF, 1, NULL)) != srs_success) { + return srs_error_wrap(err, "write sub-dir linefeed"); } } @@ -1983,7 +1981,6 @@ srs_error_t SrsConfig::initialize_cwd() srs_error_t SrsConfig::persistence() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // write to a tmp file, then mv to the config. @@ -1991,8 +1988,8 @@ srs_error_t SrsConfig::persistence() // open the tmp file for persistence SrsFileWriter fw; - if ((ret = fw.open(path)) != ERROR_SUCCESS) { - return srs_error_new(ret, "open file"); + if ((err = fw.open(path)) != srs_success) { + return srs_error_wrap(err, "open file"); } // do persistence to writer. @@ -2004,8 +2001,7 @@ srs_error_t SrsConfig::persistence() // rename the config file. if (::rename(path.c_str(), config_file.c_str()) < 0) { ::unlink(path.c_str()); - return srs_error_new(ERROR_SYSTEM_CONFIG_PERSISTENCE, "rename %s=>%s", - path.c_str(), config_file.c_str()); + return srs_error_new(ERROR_SYSTEM_CONFIG_PERSISTENCE, "rename %s=>%s", path.c_str(), config_file.c_str()); } return err; @@ -2023,9 +2019,9 @@ srs_error_t SrsConfig::do_persistence(SrsFileWriter* fw) return err; } -int SrsConfig::minimal_to_json(SrsJsonObject* obj) +srs_error_t SrsConfig::minimal_to_json(SrsJsonObject* obj) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; for (int i = 0; i < (int)root->directives.size(); i++) { SrsConfDirective* dir = root->directives.at(i); @@ -2038,12 +2034,12 @@ int SrsConfig::minimal_to_json(SrsJsonObject* obj) } } - return ret; + return err; } -int SrsConfig::global_to_json(SrsJsonObject* obj) +srs_error_t SrsConfig::global_to_json(SrsJsonObject* obj) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; for (int i = 0; i < (int)root->directives.size(); i++) { SrsConfDirective* dir = root->directives.at(i); @@ -2307,12 +2303,12 @@ int SrsConfig::global_to_json(SrsJsonObject* obj) obj->set("nb_vhosts", SrsJsonAny::integer(nb_vhosts)); obj->set("vhosts", sobjs); - return ret; + return err; } -int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj) +srs_error_t SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsConfDirective* dir = NULL; @@ -2716,8 +2712,8 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj) SrsJsonObject* engine = SrsJsonAny::object(); ingest->set("engine", engine); - if ((ret = srs_config_dumps_engine(sdir, engine)) != ERROR_SUCCESS) { - return ret; + if ((err = srs_config_dumps_engine(sdir, engine)) != srs_success) { + return srs_error_wrap(err, "dump engine"); } } } @@ -2754,19 +2750,19 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj) SrsJsonObject* engine = SrsJsonAny::object(); engines->append(engine); - if ((ret = srs_config_dumps_engine(sdir, engine)) != ERROR_SUCCESS) { - return ret; + if ((err = srs_config_dumps_engine(sdir, engine)) != srs_success) { + return srs_error_wrap(err, "dump engine"); } } } } - return ret; + return err; } -int SrsConfig::raw_to_json(SrsJsonObject* obj) +srs_error_t SrsConfig::raw_to_json(SrsJsonObject* obj) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsJsonObject* sobj = SrsJsonAny::object(); obj->set("http_api", sobj); @@ -2783,12 +2779,11 @@ int SrsConfig::raw_to_json(SrsJsonObject* obj) ssobj->set("allow_query", SrsJsonAny::boolean(get_raw_api_allow_query())); ssobj->set("allow_update", SrsJsonAny::boolean(get_raw_api_allow_update())); - return ret; + return err; } -int SrsConfig::raw_set_listen(const vector& eps, bool& applied) +srs_error_t SrsConfig::raw_set_listen(const vector& eps, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -2797,27 +2792,23 @@ int SrsConfig::raw_set_listen(const vector& eps, bool& applied) // nothing changed, ignore. if (srs_vector_actual_equals(conf->args, eps)) { - return ret; + return err; } // changed, apply and reload. conf->args = eps; if ((err = do_reload_listen()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload listen"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_set_pid(string pid, bool& applied) +srs_error_t SrsConfig::raw_set_pid(string pid, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -2825,34 +2816,31 @@ int SrsConfig::raw_set_pid(string pid, bool& applied) SrsConfDirective* conf = root->get_or_create("pid"); if (conf->arg0() == pid) { - return ret; + return err; } conf->args.clear(); conf->args.push_back(pid); if ((err = do_reload_pid()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload pid"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied) +srs_error_t SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; applied = false; SrsConfDirective* conf = root->get_or_create("chunk_size"); if (conf->arg0() == chunk_size) { - return ret; + return err; } conf->args.clear(); @@ -2862,19 +2850,19 @@ int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied) applied = true; - return ret; + return err; } -int SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied) +srs_error_t SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; applied = false; SrsConfDirective* conf = root->get_or_create("ff_log_dir"); if (conf->arg0() == ff_log_dir) { - return ret; + return err; } conf->args.clear(); @@ -2884,12 +2872,11 @@ int SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied) applied = true; - return ret; + return err; } -int SrsConfig::raw_set_srs_log_tank(string srs_log_tank, bool& applied) +srs_error_t SrsConfig::raw_set_srs_log_tank(string srs_log_tank, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -2897,27 +2884,23 @@ int SrsConfig::raw_set_srs_log_tank(string srs_log_tank, bool& applied) SrsConfDirective* conf = root->get_or_create("srs_log_tank"); if (conf->arg0() == srs_log_tank) { - return ret; + return err; } conf->args.clear(); conf->args.push_back(srs_log_tank); if ((err = do_reload_srs_log_tank()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload log tank"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_set_srs_log_level(string srs_log_level, bool& applied) +srs_error_t SrsConfig::raw_set_srs_log_level(string srs_log_level, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -2925,27 +2908,23 @@ int SrsConfig::raw_set_srs_log_level(string srs_log_level, bool& applied) SrsConfDirective* conf = root->get_or_create("srs_log_level"); if (conf->arg0() == srs_log_level) { - return ret; + return err; } conf->args.clear(); conf->args.push_back(srs_log_level); if ((err = do_reload_srs_log_level()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload log level"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_set_srs_log_file(string srs_log_file, bool& applied) +srs_error_t SrsConfig::raw_set_srs_log_file(string srs_log_file, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -2953,27 +2932,23 @@ int SrsConfig::raw_set_srs_log_file(string srs_log_file, bool& applied) SrsConfDirective* conf = root->get_or_create("srs_log_file"); if (conf->arg0() == srs_log_file) { - return ret; + return err; } conf->args.clear(); conf->args.push_back(srs_log_file); if ((err = do_reload_srs_log_file()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload log file"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_set_max_connections(string max_connections, bool& applied) +srs_error_t SrsConfig::raw_set_max_connections(string max_connections, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -2981,22 +2956,19 @@ int SrsConfig::raw_set_max_connections(string max_connections, bool& applied) SrsConfDirective* conf = root->get_or_create("max_connections"); if (conf->arg0() == max_connections) { - return ret; + return err; } conf->args.clear(); conf->args.push_back(max_connections); if ((err = do_reload_max_connections()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload max connection"); } applied = true; - return ret; + return err; } srs_error_t SrsConfig::raw_set_utc_time(string utc_time, bool& applied) @@ -3023,9 +2995,8 @@ srs_error_t SrsConfig::raw_set_utc_time(string utc_time, bool& applied) return err; } -int SrsConfig::raw_set_pithy_print_ms(string pithy_print_ms, bool& applied) +srs_error_t SrsConfig::raw_set_pithy_print_ms(string pithy_print_ms, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -3033,27 +3004,23 @@ int SrsConfig::raw_set_pithy_print_ms(string pithy_print_ms, bool& applied) SrsConfDirective* conf = root->get_or_create("pithy_print_ms"); if (conf->arg0() == pithy_print_ms) { - return ret; + return err; } conf->args.clear(); conf->args.push_back(pithy_print_ms); if ((err = do_reload_pithy_print_ms()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload pithy print"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_create_vhost(string vhost, bool& applied) +srs_error_t SrsConfig::raw_create_vhost(string vhost, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -3062,20 +3029,17 @@ int SrsConfig::raw_create_vhost(string vhost, bool& applied) conf->get_or_create("enabled")->set_arg0("on"); if ((err = do_reload_vhost_added(vhost)) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload vhost"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_update_vhost(string vhost, string name, bool& applied) +srs_error_t SrsConfig::raw_update_vhost(string vhost, string name, bool& applied) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; applied = false; @@ -3085,12 +3049,12 @@ int SrsConfig::raw_update_vhost(string vhost, string name, bool& applied) applied = true; - return ret; + return err; } -int SrsConfig::raw_delete_vhost(string vhost, bool& applied) +srs_error_t SrsConfig::raw_delete_vhost(string vhost, bool& applied) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; applied = false; @@ -3104,12 +3068,11 @@ int SrsConfig::raw_delete_vhost(string vhost, bool& applied) applied = true; - return ret; + return err; } -int SrsConfig::raw_disable_vhost(string vhost, bool& applied) +srs_error_t SrsConfig::raw_disable_vhost(string vhost, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -3118,20 +3081,16 @@ int SrsConfig::raw_disable_vhost(string vhost, bool& applied) conf->get_or_create("enabled")->set_arg0("off"); if ((err = do_reload_vhost_removed(vhost)) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload vhost removed"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_enable_vhost(string vhost, bool& applied) +srs_error_t SrsConfig::raw_enable_vhost(string vhost, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -3140,20 +3099,16 @@ int SrsConfig::raw_enable_vhost(string vhost, bool& applied) conf->get_or_create("enabled")->set_arg0("on"); if ((err = do_reload_vhost_added(vhost)) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload vhost added"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_enable_dvr(string vhost, string stream, bool& applied) +srs_error_t SrsConfig::raw_enable_dvr(string vhost, string stream, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -3170,20 +3125,16 @@ int SrsConfig::raw_enable_dvr(string vhost, string stream, bool& applied) } if ((err = do_reload_vhost_dvr_apply(vhost)) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload vhost dvr"); } applied = true; - return ret; + return err; } -int SrsConfig::raw_disable_dvr(string vhost, string stream, bool& applied) +srs_error_t SrsConfig::raw_disable_dvr(string vhost, string stream, bool& applied) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; applied = false; @@ -3202,15 +3153,12 @@ int SrsConfig::raw_disable_dvr(string vhost, string stream, bool& applied) } if ((err = do_reload_vhost_dvr_apply(vhost)) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - return ret; + return srs_error_wrap(err, "reload vhost dvr"); } applied = true; - return ret; + return err; } srs_error_t SrsConfig::do_reload_listen() diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 1249818320..ec2d868aae 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -428,51 +428,51 @@ class SrsConfig /** * dumps the global sections to json. */ - virtual int global_to_json(SrsJsonObject* obj); + virtual srs_error_t global_to_json(SrsJsonObject* obj); /** * dumps the minimal sections to json. */ - virtual int minimal_to_json(SrsJsonObject* obj); + virtual srs_error_t minimal_to_json(SrsJsonObject* obj); /** * dumps the vhost section to json. */ - virtual int vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj); + virtual srs_error_t vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj); /** * dumps the http_api sections to json for raw api info. */ - virtual int raw_to_json(SrsJsonObject* obj); + virtual srs_error_t raw_to_json(SrsJsonObject* obj); /** * raw set the global listen. */ - virtual int raw_set_listen(const std::vector& eps, bool& applied); + virtual srs_error_t raw_set_listen(const std::vector& eps, bool& applied); /** * raw set the global pid. */ - virtual int raw_set_pid(std::string pid, bool& applied); + virtual srs_error_t raw_set_pid(std::string pid, bool& applied); /** * raw set the global chunk size. */ - virtual int raw_set_chunk_size(std::string chunk_size, bool& applied); + virtual srs_error_t raw_set_chunk_size(std::string chunk_size, bool& applied); /** * raw set the global ffmpeg log dir. */ - virtual int raw_set_ff_log_dir(std::string ff_log_dir, bool& applied); + virtual srs_error_t raw_set_ff_log_dir(std::string ff_log_dir, bool& applied); /** * raw set the global log tank. */ - virtual int raw_set_srs_log_tank(std::string srs_log_tank, bool& applied); + virtual srs_error_t raw_set_srs_log_tank(std::string srs_log_tank, bool& applied); /** * raw set the global log level. */ - virtual int raw_set_srs_log_level(std::string srs_log_level, bool& applied); + virtual srs_error_t raw_set_srs_log_level(std::string srs_log_level, bool& applied); /** * raw set the global log file path for file tank. */ - virtual int raw_set_srs_log_file(std::string srs_log_file, bool& applied); + virtual srs_error_t raw_set_srs_log_file(std::string srs_log_file, bool& applied); /** * raw set the global max connections of srs. */ - virtual int raw_set_max_connections(std::string max_connections, bool& applied); + virtual srs_error_t raw_set_max_connections(std::string max_connections, bool& applied); /** * raw set the global whether use utc time. */ @@ -480,35 +480,35 @@ class SrsConfig /** * raw set the global pithy print interval in ms. */ - virtual int raw_set_pithy_print_ms(std::string pithy_print_ms, bool& applied); + virtual srs_error_t raw_set_pithy_print_ms(std::string pithy_print_ms, bool& applied); /** * raw create the new vhost. */ - virtual int raw_create_vhost(std::string vhost, bool& applied); + virtual srs_error_t raw_create_vhost(std::string vhost, bool& applied); /** * raw update the disabled vhost name. */ - virtual int raw_update_vhost(std::string vhost, std::string name, bool& applied); + virtual srs_error_t raw_update_vhost(std::string vhost, std::string name, bool& applied); /** * raw delete the disabled vhost. */ - virtual int raw_delete_vhost(std::string vhost, bool& applied); + virtual srs_error_t raw_delete_vhost(std::string vhost, bool& applied); /** * raw disable the enabled vhost. */ - virtual int raw_disable_vhost(std::string vhost, bool& applied); + virtual srs_error_t raw_disable_vhost(std::string vhost, bool& applied); /** * raw enable the disabled vhost. */ - virtual int raw_enable_vhost(std::string vhost, bool& applied); + virtual srs_error_t raw_enable_vhost(std::string vhost, bool& applied); /** * raw enable the dvr of stream of vhost. */ - virtual int raw_enable_dvr(std::string vhost, std::string stream, bool& applied); + virtual srs_error_t raw_enable_dvr(std::string vhost, std::string stream, bool& applied); /** * raw disable the dvr of stream of vhost. */ - virtual int raw_disable_dvr(std::string vhost, std::string stream, bool& applied); + virtual srs_error_t raw_disable_dvr(std::string vhost, std::string stream, bool& applied); private: virtual srs_error_t do_reload_listen(); virtual srs_error_t do_reload_pid(); @@ -559,11 +559,11 @@ class SrsConfig /** * get the current work directory. */ - virtual std::string cwd(); + virtual std::string cwd(); /** * get the cli, the main(argc,argv), program start command. */ - virtual std::string argv(); + virtual std::string argv(); // global section public: /** @@ -571,13 +571,13 @@ class SrsConfig * the root directive, no name and args, contains directives. * all directive parsed can retrieve from root. */ - virtual SrsConfDirective* get_root(); + virtual SrsConfDirective* get_root(); /** * get the deamon config. * if true, SRS will run in deamon mode, fork and fork to reap the * grand-child process to init process. */ - virtual bool get_deamon(); + virtual bool get_deamon(); /** * get the max connections limit of system. * if exceed the max connection, SRS will disconnect the connection. @@ -586,13 +586,13 @@ class SrsConfig * user must use "ulimit -HSn 10000" and config the max connections * of SRS. */ - virtual int get_max_connections(); + virtual int get_max_connections(); /** * get the listen port of SRS. * user can specifies multiple listen ports, * each args of directive is a listen port. */ - virtual std::vector get_listens(); + virtual std::vector get_listens(); /** * get the pid file path. * the pid file is used to save the pid of SRS, @@ -601,68 +601,68 @@ class SrsConfig * for example, to start multiple SRS for multiple CPUs, * user can use different pid file for each process. */ - virtual std::string get_pid_file(); + virtual std::string get_pid_file(); /** * get pithy print pulse ms, * for example, all rtmp connections only print one message * every this interval in ms. */ - virtual int get_pithy_print_ms(); + virtual int get_pithy_print_ms(); /** * whether use utc-time to format the time. */ - virtual bool get_utc_time(); + virtual bool get_utc_time(); /** * get the configed work dir. * ignore if empty string. */ - virtual std::string get_work_dir(); + virtual std::string get_work_dir(); // whether use asprocess mode. - virtual bool get_asprocess(); + virtual bool get_asprocess(); // stream_caster section public: /** * get all stream_caster in config file. */ - virtual std::vector get_stream_casters(); + virtual std::vector get_stream_casters(); /** * get whether the specified stream_caster is enabled. */ - virtual bool get_stream_caster_enabled(SrsConfDirective* conf); + virtual bool get_stream_caster_enabled(SrsConfDirective* conf); /** * get the engine of stream_caster, the caster config. */ - virtual std::string get_stream_caster_engine(SrsConfDirective* conf); + virtual std::string get_stream_caster_engine(SrsConfDirective* conf); /** * get the output rtmp url of stream_caster, the output config. */ - virtual std::string get_stream_caster_output(SrsConfDirective* conf); + virtual std::string get_stream_caster_output(SrsConfDirective* conf); /** * get the listen port of stream caster. */ - virtual int get_stream_caster_listen(SrsConfDirective* conf); + virtual int get_stream_caster_listen(SrsConfDirective* conf); /** * get the min udp port for rtp of stream caster rtsp. */ - virtual int get_stream_caster_rtp_port_min(SrsConfDirective* conf); + virtual int get_stream_caster_rtp_port_min(SrsConfDirective* conf); /** * get the max udp port for rtp of stream caster rtsp. */ - virtual int get_stream_caster_rtp_port_max(SrsConfDirective* conf); + virtual int get_stream_caster_rtp_port_max(SrsConfDirective* conf); // kafka section. public: /** * whether the kafka enabled. */ - virtual bool get_kafka_enabled(); + virtual bool get_kafka_enabled(); /** * get the broker list, each is format in . */ - virtual SrsConfDirective* get_kafka_brokers(); + virtual SrsConfDirective* get_kafka_brokers(); /** * get the kafka topic to use for srs. */ - virtual std::string get_kafka_topic(); + virtual std::string get_kafka_topic(); // vhost specified section public: /** @@ -670,7 +670,7 @@ class SrsConfig * @param vhost, the name of vhost to get. * @param try_default_vhost whether try default when get specified vhost failed. */ - virtual SrsConfDirective* get_vhost(std::string vhost, bool try_default_vhost = true); + virtual SrsConfDirective* get_vhost(std::string vhost, bool try_default_vhost = true); /** * get all vhosts in config file. */ @@ -680,20 +680,20 @@ class SrsConfig * @param vhost, the vhost name. * @return true when vhost is ok; otherwise, false. */ - virtual bool get_vhost_enabled(std::string vhost); + virtual bool get_vhost_enabled(std::string vhost); /** * whether vhost is enabled * @param vhost, the vhost directive. * @return true when vhost is ok; otherwise, false. */ - virtual bool get_vhost_enabled(SrsConfDirective* conf); + virtual bool get_vhost_enabled(SrsConfDirective* conf); /** * whether gop_cache is enabled of vhost. * gop_cache used to cache last gop, for client to fast startup. * @return true when gop_cache is ok; otherwise, false. * @remark, default true. */ - virtual bool get_gop_cache(std::string vhost); + virtual bool get_gop_cache(std::string vhost); /** * whether debug_srs_upnode is enabled of vhost. * debug_srs_upnode is very important feature for tracable log, @@ -702,187 +702,187 @@ class SrsConfig * @return true when debug_srs_upnode is ok; otherwise, false. * @remark, default true. */ - virtual bool get_debug_srs_upnode(std::string vhost); + virtual bool get_debug_srs_upnode(std::string vhost); /** * whether atc is enabled of vhost. * atc always use encoder timestamp, SRS never adjust the time. * @return true when atc is ok; otherwise, false. * @remark, default false. */ - virtual bool get_atc(std::string vhost); + virtual bool get_atc(std::string vhost); /** * whether atc_auto is enabled of vhost. * atc_auto used to auto enable atc, when metadata specified the bravo_atc. * @return true when atc_auto is ok; otherwise, false. * @remark, default true. */ - virtual bool get_atc_auto(std::string vhost); + virtual bool get_atc_auto(std::string vhost); /** * get the time_jitter algorithm. * @return the time_jitter algorithm, defined in SrsRtmpJitterAlgorithm. * @remark, default full. */ - virtual int get_time_jitter(std::string vhost); + virtual int get_time_jitter(std::string vhost); /** * whether use mix correct algorithm to ensure the timestamp * monotonically increase. */ - virtual bool get_mix_correct(std::string vhost); + virtual bool get_mix_correct(std::string vhost); /** * get the cache queue length, in seconds. * when exceed the queue length, drop packet util I frame. * @remark, default 10. */ - virtual double get_queue_length(std::string vhost); + virtual double get_queue_length(std::string vhost); /** * whether the refer hotlink-denial enabled. */ - virtual bool get_refer_enabled(std::string vhost); + virtual bool get_refer_enabled(std::string vhost); /** * get the refer hotlink-denial for all type. * @return the refer, NULL for not configed. */ - virtual SrsConfDirective* get_refer_all(std::string vhost); + virtual SrsConfDirective* get_refer_all(std::string vhost); /** * get the refer hotlink-denial for play. * @return the refer, NULL for not configed. */ - virtual SrsConfDirective* get_refer_play(std::string vhost); + virtual SrsConfDirective* get_refer_play(std::string vhost); /** * get the refer hotlink-denial for publish. * @return the refer, NULL for not configed. */ - virtual SrsConfDirective* get_refer_publish(std::string vhost); + virtual SrsConfDirective* get_refer_publish(std::string vhost); // Get the input default ack size, which is generally set by message from peer. - virtual int get_in_ack_size(std::string vhost); + virtual int get_in_ack_size(std::string vhost); // Get the output default ack size, to notify the peer to send acknowledge to server. - virtual int get_out_ack_size(std::string vhost); + virtual int get_out_ack_size(std::string vhost); /** * get the chunk size of vhost. * @param vhost, the vhost to get the chunk size. use global if not specified. * empty string to get the global. * @remark, default 60000. */ - virtual int get_chunk_size(std::string vhost); + virtual int get_chunk_size(std::string vhost); /** * whether parse the sps when publish stream to SRS. */ - virtual bool get_parse_sps(std::string vhost); + virtual bool get_parse_sps(std::string vhost); /** * whether mr is enabled for vhost. * @param vhost, the vhost to get the mr. */ - virtual bool get_mr_enabled(std::string vhost); + virtual bool get_mr_enabled(std::string vhost); /** * get the mr sleep time in ms for vhost. * @param vhost, the vhost to get the mr sleep time. */ // TODO: FIXME: add utest for mr config. - virtual int get_mr_sleep_ms(std::string vhost); + virtual int get_mr_sleep_ms(std::string vhost); /** * get the mw sleep time in ms for vhost. * @param vhost, the vhost to get the mw sleep time. */ // TODO: FIXME: add utest for mw config. - virtual int get_mw_sleep_ms(std::string vhost); + virtual int get_mw_sleep_ms(std::string vhost); /** * whether min latency mode enabled. * @param vhost, the vhost to get the min_latency. */ // TODO: FIXME: add utest for min_latency. - virtual bool get_realtime_enabled(std::string vhost); + virtual bool get_realtime_enabled(std::string vhost); /** * whether enable tcp nodelay for all clients of vhost. */ - virtual bool get_tcp_nodelay(std::string vhost); + virtual bool get_tcp_nodelay(std::string vhost); /** * the minimal send interval in ms. */ - virtual double get_send_min_interval(std::string vhost); + virtual double get_send_min_interval(std::string vhost); /** * whether reduce the sequence header. */ - virtual bool get_reduce_sequence_header(std::string vhost); + virtual bool get_reduce_sequence_header(std::string vhost); /** * the 1st packet timeout in ms for encoder. */ - virtual int get_publish_1stpkt_timeout(std::string vhost); + virtual int get_publish_1stpkt_timeout(std::string vhost); /** * the normal packet timeout in ms for encoder. */ - virtual int get_publish_normal_timeout(std::string vhost); + virtual int get_publish_normal_timeout(std::string vhost); private: /** * get the global chunk size. */ - virtual int get_global_chunk_size(); + virtual int get_global_chunk_size(); // forward section public: /** * whether the forwarder enabled. */ - virtual bool get_forward_enabled(std::string vhost); + virtual bool get_forward_enabled(std::string vhost); /** * get the forward directive of vhost. */ - virtual SrsConfDirective* get_forwards(std::string vhost); + virtual SrsConfDirective* get_forwards(std::string vhost); // http_hooks section private: /** * get the http_hooks directive of vhost. */ - virtual SrsConfDirective* get_vhost_http_hooks(std::string vhost); + virtual SrsConfDirective* get_vhost_http_hooks(std::string vhost); public: /** * whether vhost http-hooks enabled. * @remark, if not enabled, donot callback all http hooks. */ - virtual bool get_vhost_http_hooks_enabled(std::string vhost); + virtual bool get_vhost_http_hooks_enabled(std::string vhost); /** * get the on_connect callbacks of vhost. * @return the on_connect callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_connect(std::string vhost); + virtual SrsConfDirective* get_vhost_on_connect(std::string vhost); /** * get the on_close callbacks of vhost. * @return the on_close callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_close(std::string vhost); + virtual SrsConfDirective* get_vhost_on_close(std::string vhost); /** * get the on_publish callbacks of vhost. * @return the on_publish callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_publish(std::string vhost); + virtual SrsConfDirective* get_vhost_on_publish(std::string vhost); /** * get the on_unpublish callbacks of vhost. * @return the on_unpublish callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); + virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); /** * get the on_play callbacks of vhost. * @return the on_play callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_play(std::string vhost); + virtual SrsConfDirective* get_vhost_on_play(std::string vhost); /** * get the on_stop callbacks of vhost. * @return the on_stop callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); + virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); /** * get the on_dvr callbacks of vhost. * @return the on_dvr callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_dvr(std::string vhost); + virtual SrsConfDirective* get_vhost_on_dvr(std::string vhost); /** * get the on_hls callbacks of vhost. * @return the on_hls callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_hls(std::string vhost); + virtual SrsConfDirective* get_vhost_on_hls(std::string vhost); /** * get the on_hls_notify callbacks of vhost. * @return the on_hls_notify callback directive, the args is the url to callback. */ - virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost); + virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost); // bwct(bandwidth check tool) section public: /** @@ -890,24 +890,24 @@ class SrsConfig * if enabled, serve all clients with bandwidth check services. * oterwise, serve all cleints with stream. */ - virtual bool get_bw_check_enabled(std::string vhost); + virtual bool get_bw_check_enabled(std::string vhost); /** * the key of server, if client key mot match, reject. */ - virtual std::string get_bw_check_key(std::string vhost); + virtual std::string get_bw_check_key(std::string vhost); /** * the check interval, in ms. * if the client request check in very short time(in the interval), * SRS will reject client. * @remark this is used to prevent the bandwidth check attack. */ - virtual int get_bw_check_interval_ms(std::string vhost); + virtual int get_bw_check_interval_ms(std::string vhost); /** * the max kbps that user can test, * if exceed the kbps, server will slowdown the send-recv. * @remark this is used to protect the service bandwidth. */ - virtual int get_bw_check_limit_kbps(std::string vhost); + virtual int get_bw_check_limit_kbps(std::string vhost); // vhost cluster section public: /** @@ -915,40 +915,40 @@ class SrsConfig * for edge, publish client will be proxyed to upnode, * for edge, play client will share a connection to get stream from upnode. */ - virtual bool get_vhost_is_edge(std::string vhost); + virtual bool get_vhost_is_edge(std::string vhost); /** * whether vhost is edge mode. * for edge, publish client will be proxyed to upnode, * for edge, play client will share a connection to get stream from upnode. */ - virtual bool get_vhost_is_edge(SrsConfDirective* conf); + virtual bool get_vhost_is_edge(SrsConfDirective* conf); /** * get the origin config of edge, * specifies the origin ip address, port. */ - virtual SrsConfDirective* get_vhost_edge_origin(std::string vhost); + virtual SrsConfDirective* get_vhost_edge_origin(std::string vhost); /** * whether edge token tranverse is enabled, * if true, edge will send connect origin to verfy the token of client. * for example, we verify all clients on the origin FMS by server-side as, * all clients connected to edge must be tranverse to origin to verify. */ - virtual bool get_vhost_edge_token_traverse(std::string vhost); + virtual bool get_vhost_edge_token_traverse(std::string vhost); /** * get the transformed vhost for edge, * @see https://github.com/ossrs/srs/issues/372 */ - virtual std::string get_vhost_edge_transform_vhost(std::string vhost); + virtual std::string get_vhost_edge_transform_vhost(std::string vhost); // vhost security section public: /** * whether the secrity of vhost enabled. */ - virtual bool get_security_enabled(std::string vhost); + virtual bool get_security_enabled(std::string vhost); /** * get the security rules. */ - virtual SrsConfDirective* get_security_rules(std::string vhost); + virtual SrsConfDirective* get_security_rules(std::string vhost); // vhost transcode section public: /** @@ -962,23 +962,23 @@ class SrsConfig * @remark, please see the samples of full.conf, the app.transcode.srs.com * and stream.transcode.srs.com. */ - virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); + virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); /** * whether the transcode directive is enabled. */ - virtual bool get_transcode_enabled(SrsConfDirective* conf); + virtual bool get_transcode_enabled(SrsConfDirective* conf); /** * get the ffmpeg tool path of transcode. */ - virtual std::string get_transcode_ffmpeg(SrsConfDirective* conf); + virtual std::string get_transcode_ffmpeg(SrsConfDirective* conf); /** * get the engines of transcode. */ - virtual std::vector get_transcode_engines(SrsConfDirective* conf); + virtual std::vector get_transcode_engines(SrsConfDirective* conf); /** * whether the engine is enabled. */ - virtual bool get_engine_enabled(SrsConfDirective* conf); + virtual bool get_engine_enabled(SrsConfDirective* conf); /** * get the perfile of engine */ @@ -986,7 +986,7 @@ class SrsConfig /** * get the iformat of engine */ - virtual std::string get_engine_iformat(SrsConfDirective* conf); + virtual std::string get_engine_iformat(SrsConfDirective* conf); /** * get the vfilter of engine, * the video filter set before the vcodec of FFMPEG. @@ -996,42 +996,42 @@ class SrsConfig * get the vcodec of engine, * the codec of video, can be vn, copy or libx264 */ - virtual std::string get_engine_vcodec(SrsConfDirective* conf); + virtual std::string get_engine_vcodec(SrsConfDirective* conf); /** * get the vbitrate of engine, * the bitrate in kbps of video, for example, 800kbps */ - virtual int get_engine_vbitrate(SrsConfDirective* conf); + virtual int get_engine_vbitrate(SrsConfDirective* conf); /** * get the vfps of engine. * the video fps, for example, 25fps */ - virtual double get_engine_vfps(SrsConfDirective* conf); + virtual double get_engine_vfps(SrsConfDirective* conf); /** * get the vwidth of engine, * the video width, for example, 1024 */ - virtual int get_engine_vwidth(SrsConfDirective* conf); + virtual int get_engine_vwidth(SrsConfDirective* conf); /** * get the vheight of engine, * the video height, for example, 576 */ - virtual int get_engine_vheight(SrsConfDirective* conf); + virtual int get_engine_vheight(SrsConfDirective* conf); /** * get the vthreads of engine, * the video transcode libx264 threads, for instance, 8 */ - virtual int get_engine_vthreads(SrsConfDirective* conf); + virtual int get_engine_vthreads(SrsConfDirective* conf); /** * get the vprofile of engine, * the libx264 profile, can be high,main,baseline */ - virtual std::string get_engine_vprofile(SrsConfDirective* conf); + virtual std::string get_engine_vprofile(SrsConfDirective* conf); /** * get the vpreset of engine, * the libx264 preset, can be ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo */ - virtual std::string get_engine_vpreset(SrsConfDirective* conf); + virtual std::string get_engine_vpreset(SrsConfDirective* conf); /** * get the additional video params. */ @@ -1040,22 +1040,22 @@ class SrsConfig * get the acodec of engine, * the audio codec can be an, copy or libfdk_aac */ - virtual std::string get_engine_acodec(SrsConfDirective* conf); + virtual std::string get_engine_acodec(SrsConfDirective* conf); /** * get the abitrate of engine, * the audio bitrate in kbps, for instance, 64kbps. */ - virtual int get_engine_abitrate(SrsConfDirective* conf); + virtual int get_engine_abitrate(SrsConfDirective* conf); /** * get the asample_rate of engine, * the audio sample_rate, for instance, 44100HZ */ - virtual int get_engine_asample_rate(SrsConfDirective* conf); + virtual int get_engine_asample_rate(SrsConfDirective* conf); /** * get the achannels of engine, * the audio channel, for instance, 1 for mono, 2 for stereo. */ - virtual int get_engine_achannels(SrsConfDirective* conf); + virtual int get_engine_achannels(SrsConfDirective* conf); /** * get the aparams of engine, * the audio additional params. @@ -1064,27 +1064,27 @@ class SrsConfig /** * get the oformat of engine */ - virtual std::string get_engine_oformat(SrsConfDirective* conf); + virtual std::string get_engine_oformat(SrsConfDirective* conf); /** * get the output of engine, for example, rtmp://localhost/live/livestream, * @remark, we will use some variable, for instance, [vhost] to substitude with vhost. */ - virtual std::string get_engine_output(SrsConfDirective* conf); + virtual std::string get_engine_output(SrsConfDirective* conf); // vhost exec secion private: /** * get the exec directive of vhost. */ - virtual SrsConfDirective* get_exec(std::string vhost); + virtual SrsConfDirective* get_exec(std::string vhost); public: /** * whether the exec is enabled of vhost. */ - virtual bool get_exec_enabled(std::string vhost); + virtual bool get_exec_enabled(std::string vhost); /** * get all exec publish directives of vhost. */ - virtual std::vector get_exec_publishs(std::string vhost); + virtual std::vector get_exec_publishs(std::string vhost); // vhost ingest section public: /** @@ -1094,339 +1094,339 @@ class SrsConfig /** * get specified ingest. */ - virtual SrsConfDirective* get_ingest_by_id(std::string vhost, std::string ingest_id); + virtual SrsConfDirective* get_ingest_by_id(std::string vhost, std::string ingest_id); /** * whether ingest is enalbed. */ - virtual bool get_ingest_enabled(SrsConfDirective* conf); + virtual bool get_ingest_enabled(SrsConfDirective* conf); /** * get the ingest ffmpeg tool */ - virtual std::string get_ingest_ffmpeg(SrsConfDirective* conf); + virtual std::string get_ingest_ffmpeg(SrsConfDirective* conf); /** * get the ingest input type, file or stream. */ - virtual std::string get_ingest_input_type(SrsConfDirective* conf); + virtual std::string get_ingest_input_type(SrsConfDirective* conf); /** * get the ingest input url. */ - virtual std::string get_ingest_input_url(SrsConfDirective* conf); + virtual std::string get_ingest_input_url(SrsConfDirective* conf); // log section public: /** * whether log to file. */ - virtual bool get_log_tank_file(); + virtual bool get_log_tank_file(); /** * get the log level. */ - virtual std::string get_log_level(); + virtual std::string get_log_level(); /** * get the log file path. */ - virtual std::string get_log_file(); + virtual std::string get_log_file(); /** * whether ffmpeg log enabled */ - virtual bool get_ffmpeg_log_enabled(); + virtual bool get_ffmpeg_log_enabled(); /** * the ffmpeg log dir. * @remark, /dev/null to disable it. */ - virtual std::string get_ffmpeg_log_dir(); + virtual std::string get_ffmpeg_log_dir(); // The MPEG-DASH section. private: - virtual SrsConfDirective* get_dash(std::string vhost); + virtual SrsConfDirective* get_dash(std::string vhost); public: // Whether DASH is enabled. - virtual bool get_dash_enabled(std::string vhost); + virtual bool get_dash_enabled(std::string vhost); // Get the duration of segment in milliseconds. - virtual int get_dash_fragment(std::string vhost); + virtual int get_dash_fragment(std::string vhost); // Get the period to update MPD in milliseconds. - virtual int get_dash_update_period(std::string vhost); + virtual int get_dash_update_period(std::string vhost); // Get the depth of timeshift buffer in milliseconds. - virtual int get_dash_timeshift(std::string vhost); + virtual int get_dash_timeshift(std::string vhost); // Get the base/home dir/path for dash, into which write files. - virtual std::string get_dash_path(std::string vhost); + virtual std::string get_dash_path(std::string vhost); // Get the path for DASH MPD, to generate the MPD file. - virtual std::string get_dash_mpd_file(std::string vhost); + virtual std::string get_dash_mpd_file(std::string vhost); // hls section private: /** * get the hls directive of vhost. */ - virtual SrsConfDirective* get_hls(std::string vhost); + virtual SrsConfDirective* get_hls(std::string vhost); public: /** * whether HLS is enabled. */ - virtual bool get_hls_enabled(std::string vhost); + virtual bool get_hls_enabled(std::string vhost); /** * get the HLS m3u8 list ts segment entry prefix info. */ - virtual std::string get_hls_entry_prefix(std::string vhost); + virtual std::string get_hls_entry_prefix(std::string vhost); /** * get the HLS ts/m3u8 file store path. */ - virtual std::string get_hls_path(std::string vhost); + virtual std::string get_hls_path(std::string vhost); /** * get the HLS m3u8 file path template. */ - virtual std::string get_hls_m3u8_file(std::string vhost); + virtual std::string get_hls_m3u8_file(std::string vhost); /** * get the HLS ts file path template. */ - virtual std::string get_hls_ts_file(std::string vhost); + virtual std::string get_hls_ts_file(std::string vhost); /** * whether enable the floor(timestamp/hls_fragment) for variable timestamp. */ - virtual bool get_hls_ts_floor(std::string vhost); + virtual bool get_hls_ts_floor(std::string vhost); /** * get the hls fragment time, in seconds. */ - virtual double get_hls_fragment(std::string vhost); + virtual double get_hls_fragment(std::string vhost); /** * get the hls td(target duration) ratio. */ - virtual double get_hls_td_ratio(std::string vhost); + virtual double get_hls_td_ratio(std::string vhost); /** * get the hls aof(audio overflow) ratio. */ - virtual double get_hls_aof_ratio(std::string vhost); + virtual double get_hls_aof_ratio(std::string vhost); /** * get the hls window time, in seconds. * a window is a set of ts, the ts collection in m3u8. * @remark SRS will delete the ts exceed the window. */ - virtual double get_hls_window(std::string vhost); + virtual double get_hls_window(std::string vhost); /** * get the hls hls_on_error config. * the ignore will ignore error and disable hls. * the disconnect will disconnect publish connection. * @see https://github.com/ossrs/srs/issues/264 */ - virtual std::string get_hls_on_error(std::string vhost); + virtual std::string get_hls_on_error(std::string vhost); /** * get the HLS default audio codec. */ - virtual std::string get_hls_acodec(std::string vhost); + virtual std::string get_hls_acodec(std::string vhost); /** * get the HLS default video codec. */ - virtual std::string get_hls_vcodec(std::string vhost); + virtual std::string get_hls_vcodec(std::string vhost); /** * whether cleanup the old ts files. */ - virtual bool get_hls_cleanup(std::string vhost); + virtual bool get_hls_cleanup(std::string vhost); /** * the timeout to dispose the hls. */ - virtual int get_hls_dispose(std::string vhost); + virtual int get_hls_dispose(std::string vhost); /** * whether reap the ts when got keyframe. */ - virtual bool get_hls_wait_keyframe(std::string vhost); + virtual bool get_hls_wait_keyframe(std::string vhost); /** * get the size of bytes to read from cdn network, for the on_hls_notify callback, * that is, to read max bytes of the bytes from the callback, or timeout or error. */ - virtual int get_vhost_hls_nb_notify(std::string vhost); + virtual int get_vhost_hls_nb_notify(std::string vhost); // hds section private: /** * get the hds directive of vhost. */ - virtual SrsConfDirective* get_hds(const std::string &vhost); + virtual SrsConfDirective* get_hds(const std::string &vhost); public: /** * whether HDS is enabled. */ - virtual bool get_hds_enabled(const std::string &vhost); + virtual bool get_hds_enabled(const std::string &vhost); /** * get the HDS file store path. */ - virtual std::string get_hds_path(const std::string &vhost); + virtual std::string get_hds_path(const std::string &vhost); /** * get the hds fragment time, in seconds. */ - virtual double get_hds_fragment(const std::string &vhost); + virtual double get_hds_fragment(const std::string &vhost); /** * get the hds window time, in seconds. * a window is a set of hds fragments. */ - virtual double get_hds_window(const std::string &vhost); + virtual double get_hds_window(const std::string &vhost); // dvr section private: /** * get the dvr directive. */ - virtual SrsConfDirective* get_dvr(std::string vhost); + virtual SrsConfDirective* get_dvr(std::string vhost); public: /** * whether dvr is enabled. */ - virtual bool get_dvr_enabled(std::string vhost); + virtual bool get_dvr_enabled(std::string vhost); /** * get the filter of dvr to apply to. * @remark user can use srs_config_apply_filter(conf, req):bool to check it. */ - virtual SrsConfDirective* get_dvr_apply(std::string vhost); + virtual SrsConfDirective* get_dvr_apply(std::string vhost); /** * get the dvr path, the flv file to save in. */ - virtual std::string get_dvr_path(std::string vhost); + virtual std::string get_dvr_path(std::string vhost); /** * get the plan of dvr, how to reap the flv file. */ - virtual std::string get_dvr_plan(std::string vhost); + virtual std::string get_dvr_plan(std::string vhost); /** * get the duration of dvr flv. */ - virtual int get_dvr_duration(std::string vhost); + virtual int get_dvr_duration(std::string vhost); /** * whether wait keyframe to reap segment. */ - virtual bool get_dvr_wait_keyframe(std::string vhost); + virtual bool get_dvr_wait_keyframe(std::string vhost); /** * get the time_jitter algorithm for dvr. */ - virtual int get_dvr_time_jitter(std::string vhost); + virtual int get_dvr_time_jitter(std::string vhost); // http api section private: /** * whether http api enabled */ - virtual bool get_http_api_enabled(SrsConfDirective* conf); + virtual bool get_http_api_enabled(SrsConfDirective* conf); public: /** * whether http api enabled. */ - virtual bool get_http_api_enabled(); + virtual bool get_http_api_enabled(); /** * get the http api listen port. */ - virtual std::string get_http_api_listen(); + virtual std::string get_http_api_listen(); /** * whether enable crossdomain for http api. */ - virtual bool get_http_api_crossdomain(); + virtual bool get_http_api_crossdomain(); /** * whether enable the HTTP RAW API. */ - virtual bool get_raw_api(); + virtual bool get_raw_api(); /** * whether allow rpc reload. */ - virtual bool get_raw_api_allow_reload(); + virtual bool get_raw_api_allow_reload(); /** * whether allow rpc query. */ - virtual bool get_raw_api_allow_query(); + virtual bool get_raw_api_allow_query(); /** * whether allow rpc update. */ - virtual bool get_raw_api_allow_update(); + virtual bool get_raw_api_allow_update(); // http stream section private: /** * whether http stream enabled. */ - virtual bool get_http_stream_enabled(SrsConfDirective* conf); + virtual bool get_http_stream_enabled(SrsConfDirective* conf); public: /** * whether http stream enabled. */ // TODO: FIXME: rename to http_static. - virtual bool get_http_stream_enabled(); + virtual bool get_http_stream_enabled(); /** * get the http stream listen port. */ - virtual std::string get_http_stream_listen(); + virtual std::string get_http_stream_listen(); /** * get the http stream root dir. */ - virtual std::string get_http_stream_dir(); + virtual std::string get_http_stream_dir(); /** * whether enable crossdomain for http static and stream server. */ - virtual bool get_http_stream_crossdomain(); + virtual bool get_http_stream_crossdomain(); public: /** * get whether vhost enabled http stream */ - virtual bool get_vhost_http_enabled(std::string vhost); + virtual bool get_vhost_http_enabled(std::string vhost); /** * get the http mount point for vhost. * for example, http://vhost/live/livestream */ - virtual std::string get_vhost_http_mount(std::string vhost); + virtual std::string get_vhost_http_mount(std::string vhost); /** * get the http dir for vhost. * the path on disk for mount root of http vhost. */ - virtual std::string get_vhost_http_dir(std::string vhost); + virtual std::string get_vhost_http_dir(std::string vhost); // flv live streaming section public: /** * get whether vhost enabled http flv live stream */ - virtual bool get_vhost_http_remux_enabled(std::string vhost); + virtual bool get_vhost_http_remux_enabled(std::string vhost); /** * get the fast cache duration for http audio live stream. */ - virtual double get_vhost_http_remux_fast_cache(std::string vhost); + virtual double get_vhost_http_remux_fast_cache(std::string vhost); /** * get the http flv live stream mount point for vhost. * used to generate the flv stream mount path. */ - virtual std::string get_vhost_http_remux_mount(std::string vhost); + virtual std::string get_vhost_http_remux_mount(std::string vhost); // http heartbeart section private: /** * get the heartbeat directive. */ - virtual SrsConfDirective* get_heartbeart(); + virtual SrsConfDirective* get_heartbeart(); public: /** * whether heartbeat enabled. */ - virtual bool get_heartbeat_enabled(); + virtual bool get_heartbeat_enabled(); /** * get the heartbeat interval, in ms. */ - virtual int64_t get_heartbeat_interval(); + virtual int64_t get_heartbeat_interval(); /** * get the heartbeat report url. */ - virtual std::string get_heartbeat_url(); + virtual std::string get_heartbeat_url(); /** * get the device id of heartbeat, to report to server. */ - virtual std::string get_heartbeat_device_id(); + virtual std::string get_heartbeat_device_id(); /** * whether report with summaries of http api: /api/v1/summaries. */ - virtual bool get_heartbeat_summaries(); + virtual bool get_heartbeat_summaries(); // stats section private: /** * get the stats directive. */ - virtual SrsConfDirective* get_stats(); + virtual SrsConfDirective* get_stats(); public: /** * get the network device index, used to retrieve the ip of device, * for heartbeat to report to server, or to get the local ip. * for example, 0 means the eth0 maybe. */ - virtual int get_stats_network(); + virtual int get_stats_network(); /** * get the disk stat device name list. * the device name configed in args of directive. * @return the disk device name to stat. NULL if not configed. */ - virtual SrsConfDirective* get_stats_disk_device(); + virtual SrsConfDirective* get_stats_disk_device(); }; #endif diff --git a/trunk/src/app/srs_app_dash.hpp b/trunk/src/app/srs_app_dash.hpp index f70f82ad22..cf379ecbfa 100644 --- a/trunk/src/app/srs_app_dash.hpp +++ b/trunk/src/app/srs_app_dash.hpp @@ -53,7 +53,7 @@ class SrsInitMp4 : public SrsFragment virtual ~SrsInitMp4(); public: // Write the init mp4 file, with the tid(track id). - virtual int write(SrsFormat* format, bool video, int tid); + virtual srs_error_t write(SrsFormat* format, bool video, int tid); }; /** @@ -69,11 +69,11 @@ class SrsFragmentedMp4 : public SrsFragment virtual ~SrsFragmentedMp4(); public: // Initialize the fragment, create the home dir, open the file. - virtual int initialize(SrsRequest* r, bool video, SrsMpdWriter* mpd, uint32_t tid); + virtual srs_error_t initialize(SrsRequest* r, bool video, SrsMpdWriter* mpd, uint32_t tid); // Write media message to fragment. - virtual int write(SrsSharedPtrMessage* shared_msg, SrsFormat* format); + virtual srs_error_t write(SrsSharedPtrMessage* shared_msg, SrsFormat* format); // Reap the fragment, close the fd and rename tmp to official file. - virtual int reap(uint64_t& dts); + virtual srs_error_t reap(uint64_t& dts); }; /** @@ -104,11 +104,11 @@ class SrsMpdWriter public: virtual srs_error_t initialize(SrsRequest* r); // Write MPD according to parsed format of stream. - virtual int write(SrsFormat* format); + virtual srs_error_t write(SrsFormat* format); public: // Get the fragment relative home and filename. // The basetime is the absolute time in ms, while the sn(sequence number) is basetime/fragment. - virtual int get_fragment(bool video, std::string& home, std::string& filename, int64_t& sn, uint64_t& basetime); + virtual srs_error_t get_fragment(bool video, std::string& home, std::string& filename, int64_t& sn, uint64_t& basetime); }; /** @@ -138,11 +138,11 @@ class SrsDashController virtual ~SrsDashController(); public: 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); + virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format); + virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format); private: - virtual int refresh_mpd(SrsFormat* format); - virtual int refresh_init_mp4(SrsSharedPtrMessage* msg, SrsFormat* format); + virtual srs_error_t refresh_mpd(SrsFormat* format); + virtual srs_error_t refresh_init_mp4(SrsSharedPtrMessage* msg, SrsFormat* format); }; /** @@ -163,11 +163,11 @@ class SrsDash // Initalize the encoder. virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r); // When stream start publishing. - virtual int on_publish(); + virtual srs_error_t on_publish(); // When got an shared audio message. - virtual int on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format); + virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format); // When got an shared video message. - virtual int on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format); + virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format); // When stream stop publishing. virtual void on_unpublish(); }; diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 541c10a3ff..3c6f1bf312 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -72,9 +72,9 @@ SrsEdgeRtmpUpstream::~SrsEdgeRtmpUpstream() close(); } -int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb) +srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsRequest* req = r; @@ -86,9 +86,7 @@ int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb) // when origin is error, for instance, server is shutdown, // then user remove the vhost then reload, the conf is empty. if (!conf) { - ret = ERROR_EDGE_VHOST_REMOVED; - srs_warn("vhost %s removed. ret=%d", req->vhost.c_str(), ret); - return ret; + return srs_error_new(ERROR_EDGE_VHOST_REMOVED, "vhost %s removed", req->vhost.c_str()); } // select the origin. @@ -120,25 +118,23 @@ int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb) int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; sdk = new SrsSimpleRtmpClient(url, cto, sto); - if ((ret = sdk->connect()) != ERROR_SUCCESS) { - srs_error("edge pull %s failed, cto=%" PRId64 ", sto=%" PRId64 ". ret=%d", url.c_str(), cto, sto, ret); - return ret; + if ((err = sdk->connect()) != srs_success) { + return srs_error_wrap(err, "edge pull %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto); } - if ((ret = sdk->play()) != ERROR_SUCCESS) { - srs_error("edge pull %s stream failed. ret=%d", url.c_str(), ret); - return ret; + if ((err = sdk->play()) != srs_success) { + return srs_error_wrap(err, "edge pull %s stream failed", url.c_str()); } - return ret; + return err; } -int SrsEdgeRtmpUpstream::recv_message(SrsCommonMessage** pmsg) +srs_error_t SrsEdgeRtmpUpstream::recv_message(SrsCommonMessage** pmsg) { return sdk->recv_message(pmsg); } -int SrsEdgeRtmpUpstream::decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) +srs_error_t SrsEdgeRtmpUpstream::decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) { return sdk->decode_message(msg, ppacket); } @@ -246,7 +242,6 @@ srs_error_t SrsEdgeIngester::cycle() srs_error_t SrsEdgeIngester::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; while (true) { @@ -265,12 +260,12 @@ srs_error_t SrsEdgeIngester::do_cycle() return srs_error_wrap(err, "on source id changed"); } - if ((ret = upstream->connect(req, lb)) != ERROR_SUCCESS) { - return srs_error_new(ret, "connect upstream"); + if ((err = upstream->connect(req, lb)) != srs_success) { + return srs_error_wrap(err, "connect upstream"); } - if ((ret = edge->on_ingest_play()) != ERROR_SUCCESS) { - return srs_error_new(ret, "notify edge play"); + if ((err = edge->on_ingest_play()) != srs_success) { + return srs_error_wrap(err, "notify edge play"); } err = ingest(); @@ -288,12 +283,11 @@ srs_error_t SrsEdgeIngester::do_cycle() break; } - return srs_error_new(ret, "cycle"); + return err; } srs_error_t SrsEdgeIngester::ingest() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsPithyPrint* pprint = SrsPithyPrint::create_edge(); @@ -317,8 +311,8 @@ srs_error_t SrsEdgeIngester::ingest() // read from client. SrsCommonMessage* msg = NULL; - if ((ret = upstream->recv_message(&msg)) != ERROR_SUCCESS) { - return srs_error_new(ret, "recv message"); + if ((err = upstream->recv_message(&msg)) != srs_success) { + return srs_error_wrap(err, "recv message"); } srs_assert(msg); @@ -334,7 +328,6 @@ srs_error_t SrsEdgeIngester::ingest() srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // process audio packet @@ -362,8 +355,8 @@ srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg) // process onMetaData if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) { SrsPacket* pkt = NULL; - if ((ret = upstream->decode_message(msg, &pkt)) != ERROR_SUCCESS) { - return srs_error_new(ret, "decode message"); + if ((err = upstream->decode_message(msg, &pkt)) != srs_success) { + return srs_error_wrap(err, "decode message"); } SrsAutoFree(SrsPacket, pkt); @@ -381,8 +374,8 @@ srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg) // call messages, for example, reject, redirect. if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) { SrsPacket* pkt = NULL; - if ((ret = upstream->decode_message(msg, &pkt)) != ERROR_SUCCESS) { - return srs_error_new(ret, "decode message"); + if ((err = upstream->decode_message(msg, &pkt)) != srs_success) { + return srs_error_wrap(err, "decode message"); } SrsAutoFree(SrsPacket, pkt); @@ -456,7 +449,6 @@ srs_error_t SrsEdgeForwarder::initialize(SrsSource* s, SrsPublishEdge* e, SrsReq srs_error_t SrsEdgeForwarder::start() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // reset the error code. @@ -486,12 +478,12 @@ srs_error_t SrsEdgeForwarder::start() int64_t sto = SRS_CONSTS_RTMP_TMMS; sdk = new SrsSimpleRtmpClient(url, cto, sto); - if ((ret = sdk->connect()) != ERROR_SUCCESS) { - return srs_error_new(ret, "sdk connect %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto); + if ((err = sdk->connect()) != srs_success) { + return srs_error_wrap(err, "sdk connect %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto); } - if ((ret = sdk->publish()) != ERROR_SUCCESS) { - return srs_error_new(ret, "sdk publish"); + if ((err = sdk->publish()) != srs_success) { + return srs_error_wrap(err, "sdk publish"); } srs_freep(trd); @@ -537,7 +529,6 @@ srs_error_t SrsEdgeForwarder::cycle() srs_error_t SrsEdgeForwarder::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS); @@ -560,15 +551,17 @@ srs_error_t SrsEdgeForwarder::do_cycle() // read from client. if (true) { SrsCommonMessage* msg = NULL; - ret = sdk->recv_message(&msg); + err = sdk->recv_message(&msg); srs_verbose("edge loop recv message. ret=%d", ret); - if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) { - srs_error("edge push get server control message failed. ret=%d", ret); - send_error_code = ret; + if (err != srs_success && srs_error_code(err) != ERROR_SOCKET_TIMEOUT) { + srs_error("edge push get server control message failed. err=%s", srs_error_desc(err).c_str()); + send_error_code = srs_error_code(err); + srs_error_reset(err); continue; } + srs_error_reset(err); srs_freep(msg); } @@ -593,8 +586,8 @@ srs_error_t SrsEdgeForwarder::do_cycle() } // sendout messages, all messages are freed by send_and_free_messages(). - if ((ret = sdk->send_and_free_messages(msgs.msgs, count)) != ERROR_SUCCESS) { - return srs_error_new(ret, "send messages"); + if ((err = sdk->send_and_free_messages(msgs.msgs, count)) != srs_success) { + return srs_error_wrap(err, "send messages"); } } @@ -603,11 +596,10 @@ srs_error_t SrsEdgeForwarder::do_cycle() srs_error_t SrsEdgeForwarder::proxy(SrsCommonMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; - if ((ret = send_error_code) != ERROR_SUCCESS) { - return srs_error_new(ret, "edge forwarder"); + if (send_error_code != ERROR_SUCCESS) { + return srs_error_new(send_error_code, "edge forwarder"); } // the msg is auto free by source, @@ -620,8 +612,8 @@ srs_error_t SrsEdgeForwarder::proxy(SrsCommonMessage* msg) } SrsSharedPtrMessage copy; - if ((ret = copy.create(msg)) != ERROR_SUCCESS) { - return srs_error_new(ret, "create message"); + if ((err = copy.create(msg)) != srs_success) { + return srs_error_wrap(err, "create message"); } copy.stream_id = sdk->sid(); @@ -654,22 +646,17 @@ srs_error_t SrsPlayEdge::initialize(SrsSource* source, SrsRequest* req) return err; } -int SrsPlayEdge::on_client_play() +srs_error_t SrsPlayEdge::on_client_play() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // start ingest when init state. if (state == SrsEdgeStateInit) { state = SrsEdgeStatePlay; err = ingester->start(); - - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); } - return ret; + return err; } void SrsPlayEdge::on_all_client_stop() @@ -692,13 +679,13 @@ string SrsPlayEdge::get_curr_origin() return ingester->get_curr_origin(); } -int SrsPlayEdge::on_ingest_play() +srs_error_t SrsPlayEdge::on_ingest_play() { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; // when already connected(for instance, reconnect for error), ignore. if (state == SrsEdgeStateIngestConnected) { - return ret; + return err; } srs_assert(state == SrsEdgeStatePlay); @@ -707,7 +694,7 @@ int SrsPlayEdge::on_ingest_play() state = SrsEdgeStateIngestConnected; srs_trace("edge change from %d to state %d (pull).", pstate, state); - return ret; + return err; } SrsPublishEdge::SrsPublishEdge() diff --git a/trunk/src/app/srs_app_edge.hpp b/trunk/src/app/srs_app_edge.hpp index 99c6b55f8b..7ea75a0265 100644 --- a/trunk/src/app/srs_app_edge.hpp +++ b/trunk/src/app/srs_app_edge.hpp @@ -81,9 +81,9 @@ class SrsEdgeUpstream SrsEdgeUpstream(); virtual ~SrsEdgeUpstream(); public: - virtual int connect(SrsRequest* r, SrsLbRoundRobin* lb) = 0; - virtual int recv_message(SrsCommonMessage** pmsg) = 0; - virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0; + virtual srs_error_t connect(SrsRequest* r, SrsLbRoundRobin* lb) = 0; + virtual srs_error_t recv_message(SrsCommonMessage** pmsg) = 0; + virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0; virtual void close() = 0; public: virtual void set_recv_timeout(int64_t tm) = 0; @@ -102,9 +102,9 @@ class SrsEdgeRtmpUpstream : public SrsEdgeUpstream SrsEdgeRtmpUpstream(std::string r); virtual ~SrsEdgeRtmpUpstream(); public: - virtual int connect(SrsRequest* r, SrsLbRoundRobin* lb); - virtual int recv_message(SrsCommonMessage** pmsg); - virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); + virtual srs_error_t connect(SrsRequest* r, SrsLbRoundRobin* lb); + virtual srs_error_t recv_message(SrsCommonMessage** pmsg); + virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); virtual void close(); public: virtual void set_recv_timeout(int64_t tm); @@ -206,7 +206,7 @@ class SrsPlayEdge /** * when client play stream on edge. */ - virtual int on_client_play(); + virtual srs_error_t on_client_play(); /** * when all client stopped play, disconnect to origin. */ @@ -216,7 +216,7 @@ class SrsPlayEdge /** * when ingester start to play stream. */ - virtual int on_ingest_play(); + virtual srs_error_t on_ingest_play(); }; /** diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index 506f3c640c..46ba7f7fce 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -53,38 +53,33 @@ SrsEncoder::~SrsEncoder() srs_freep(pprint); } -int SrsEncoder::on_publish(SrsRequest* req) +srs_error_t SrsEncoder::on_publish(SrsRequest* req) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // parse the transcode engines for vhost and app and stream. - ret = parse_scope_engines(req); + err = parse_scope_engines(req); // ignore the loop encoder // if got a loop, donot transcode the whole stream. - if (ret == ERROR_ENCODER_LOOP) { + if (srs_error_code(err) == ERROR_ENCODER_LOOP) { clear_engines(); - ret = ERROR_SUCCESS; + srs_error_reset(err); } // return for error or no engine. - if (ret != ERROR_SUCCESS || ffmpegs.empty()) { - return ret; + if (err != srs_success || ffmpegs.empty()) { + return err; } // start thread to run all encoding engines. srs_freep(trd); trd = new SrsSTCoroutine("encoder", this, _srs_context->get_id()); if ((err = trd->start()) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - - return ret; + return srs_error_wrap(err, "start encoder"); } - return ret; + return err; } void SrsEncoder::on_unpublish() @@ -103,11 +98,12 @@ srs_error_t SrsEncoder::cycle() while (true) { if ((err = do_cycle()) != srs_success) { srs_warn("Encoder: Ignore error, %s", srs_error_desc(err).c_str()); - srs_freep(err); + srs_error_reset(err); } if ((err = trd->pull()) != srs_success) { - return srs_error_wrap(err, "encoder"); + err = srs_error_wrap(err, "encoder"); + break; } srs_usleep(SRS_RTMP_ENCODER_CIMS * 1000); @@ -126,7 +122,6 @@ srs_error_t SrsEncoder::cycle() srs_error_t SrsEncoder::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; std::vector::iterator it; @@ -134,13 +129,13 @@ srs_error_t SrsEncoder::do_cycle() SrsFFMPEG* ffmpeg = *it; // start all ffmpegs. - if ((ret = ffmpeg->start()) != ERROR_SUCCESS) { - return srs_error_new(ret, "ffmpeg start"); + if ((err = ffmpeg->start()) != srs_success) { + return srs_error_wrap(err, "ffmpeg start"); } // check ffmpeg status. - if ((ret = ffmpeg->cycle()) != ERROR_SUCCESS) { - return srs_error_new(ret, "ffmpeg cycle"); + if ((err = ffmpeg->cycle()) != srs_success) { + return srs_error_wrap(err, "ffmpeg cycle"); } } @@ -176,9 +171,9 @@ SrsFFMPEG* SrsEncoder::at(int index) return ffmpegs[index]; } -int SrsEncoder::parse_scope_engines(SrsRequest* req) +srs_error_t SrsEncoder::parse_scope_engines(SrsRequest* req) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; // parse all transcode engines. SrsConfDirective* conf = NULL; @@ -186,96 +181,78 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) // parse vhost scope engines std::string scope = ""; if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { - if ((ret = parse_ffmpeg(req, conf)) != ERROR_SUCCESS) { - if (ret != ERROR_ENCODER_LOOP) { - srs_error("parse vhost scope=%s transcode engines failed. " - "ret=%d", scope.c_str(), ret); - } - return ret; + if ((err = parse_ffmpeg(req, conf)) != srs_success) { + return srs_error_wrap(err, "parse ffmpeg"); } } // parse app scope engines scope = req->app; if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { - if ((ret = parse_ffmpeg(req, conf)) != ERROR_SUCCESS) { - if (ret != ERROR_ENCODER_LOOP) { - srs_error("parse app scope=%s transcode engines failed. " - "ret=%d", scope.c_str(), ret); - } - return ret; + if ((err = parse_ffmpeg(req, conf)) != srs_success) { + return srs_error_wrap(err, "parse ffmpeg"); } } // parse stream scope engines scope += "/"; scope += req->stream; if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { - if ((ret = parse_ffmpeg(req, conf)) != ERROR_SUCCESS) { - if (ret != ERROR_ENCODER_LOOP) { - srs_error("parse stream scope=%s transcode engines failed. " - "ret=%d", scope.c_str(), ret); - } - return ret; + if ((err = parse_ffmpeg(req, conf)) != srs_success) { + return srs_error_wrap(err, "parse ffmpeg"); } } - return ret; + return err; } -int SrsEncoder::parse_ffmpeg(SrsRequest* req, SrsConfDirective* conf) +srs_error_t SrsEncoder::parse_ffmpeg(SrsRequest* req, SrsConfDirective* conf) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; srs_assert(conf); // enabled if (!_srs_config->get_transcode_enabled(conf)) { srs_trace("ignore the disabled transcode: %s", conf->arg0().c_str()); - return ret; + return err; } // ffmpeg std::string ffmpeg_bin = _srs_config->get_transcode_ffmpeg(conf); if (ffmpeg_bin.empty()) { - srs_trace("ignore the empty ffmpeg transcode: %s", - conf->arg0().c_str()); - return ret; + srs_trace("ignore the empty ffmpeg transcode: %s", conf->arg0().c_str()); + return err; } // get all engines. std::vector engines = _srs_config->get_transcode_engines(conf); if (engines.empty()) { - srs_trace("ignore the empty transcode engine: %s", - conf->arg0().c_str()); - return ret; + srs_trace("ignore the empty transcode engine: %s", conf->arg0().c_str()); + return err; } // create engine for (int i = 0; i < (int)engines.size(); i++) { SrsConfDirective* engine = engines[i]; if (!_srs_config->get_engine_enabled(engine)) { - srs_trace("ignore the diabled transcode engine: %s %s", - conf->arg0().c_str(), engine->arg0().c_str()); + srs_trace("ignore the diabled transcode engine: %s %s", conf->arg0().c_str(), engine->arg0().c_str()); continue; } SrsFFMPEG* ffmpeg = new SrsFFMPEG(ffmpeg_bin); - if ((ret = initialize_ffmpeg(ffmpeg, req, engine)) != ERROR_SUCCESS) { + if ((err = initialize_ffmpeg(ffmpeg, req, engine)) != srs_success) { srs_freep(ffmpeg); - if (ret != ERROR_ENCODER_LOOP) { - srs_error("invalid transcode engine: %s %s", conf->arg0().c_str(), engine->arg0().c_str()); - } - return ret; + return srs_error_wrap(err, "init ffmpeg"); } ffmpegs.push_back(ffmpeg); } - return ret; + return err; } -int SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDirective* engine) +srs_error_t SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDirective* engine) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; std::string input; // input stream, from local. @@ -330,21 +307,18 @@ int SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDir std::vector::iterator it; it = std::find(_transcoded_url.begin(), _transcoded_url.end(), input); if (it != _transcoded_url.end()) { - ret = ERROR_ENCODER_LOOP; - srs_trace("detect a loop cycle, input=%s, output=%s, ignore it. ret=%d", - input.c_str(), output.c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_LOOP, "detect a loop cycle, input=%s, output=%s", input.c_str(), output.c_str()); } _transcoded_url.push_back(output); - if ((ret = ffmpeg->initialize(input, output, log_file)) != ERROR_SUCCESS) { - return ret; + if ((err = ffmpeg->initialize(input, output, log_file)) != srs_success) { + return srs_error_wrap(err, "init ffmpeg"); } - if ((ret = ffmpeg->initialize_transcode(engine)) != ERROR_SUCCESS) { - return ret; + if ((err = ffmpeg->initialize_transcode(engine)) != srs_success) { + return srs_error_wrap(err, "init transcode"); } - return ret; + return err; } void SrsEncoder::show_encode_log_message() diff --git a/trunk/src/app/srs_app_encoder.hpp b/trunk/src/app/srs_app_encoder.hpp index f92c2f89f4..589babe756 100644 --- a/trunk/src/app/srs_app_encoder.hpp +++ b/trunk/src/app/srs_app_encoder.hpp @@ -54,7 +54,7 @@ class SrsEncoder : public ISrsCoroutineHandler SrsEncoder(); virtual ~SrsEncoder(); public: - virtual int on_publish(SrsRequest* req); + virtual srs_error_t on_publish(SrsRequest* req); virtual void on_unpublish(); // interface ISrsReusableThreadHandler. public: @@ -64,9 +64,9 @@ class SrsEncoder : public ISrsCoroutineHandler private: virtual void clear_engines(); virtual SrsFFMPEG* at(int index); - virtual int parse_scope_engines(SrsRequest* req); - virtual int parse_ffmpeg(SrsRequest* req, SrsConfDirective* conf); - virtual int initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDirective* engine); + virtual srs_error_t parse_scope_engines(SrsRequest* req); + virtual srs_error_t parse_ffmpeg(SrsRequest* req, SrsConfDirective* conf); + virtual srs_error_t initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDirective* engine); virtual void show_encode_log_message(); }; diff --git a/trunk/src/app/srs_app_ffmpeg.cpp b/trunk/src/app/srs_app_ffmpeg.cpp index e16358dc1a..60bf711e85 100644 --- a/trunk/src/app/srs_app_ffmpeg.cpp +++ b/trunk/src/app/srs_app_ffmpeg.cpp @@ -97,20 +97,20 @@ string SrsFFMPEG::output() return _output; } -int SrsFFMPEG::initialize(string in, string out, string log) +srs_error_t SrsFFMPEG::initialize(string in, string out, string log) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; input = in; _output = out; log_file = log; - return ret; + return err; } -int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) +srs_error_t SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; perfile = _srs_config->get_engine_perfile(engine); iformat = _srs_config->get_engine_iformat(engine); @@ -136,85 +136,56 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) vheight -= vheight % 2; if (vcodec == SRS_RTMP_ENCODER_NO_VIDEO && acodec == SRS_RTMP_ENCODER_NO_AUDIO) { - ret = ERROR_ENCODER_VCODEC; - srs_warn("video and audio disabled. ret=%d", ret); - return ret; + return srs_error_new(ERROR_ENCODER_VCODEC, "video and audio disabled"); } if (vcodec != SRS_RTMP_ENCODER_COPY && vcodec != SRS_RTMP_ENCODER_NO_VIDEO && vcodec != SRS_RTMP_ENCODER_VCODEC_PNG) { if (vcodec != SRS_RTMP_ENCODER_VCODEC_LIBX264) { - ret = ERROR_ENCODER_VCODEC; - srs_error("invalid vcodec, must be %s, actual %s, ret=%d", - SRS_RTMP_ENCODER_VCODEC_LIBX264, vcodec.c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_VCODEC, "invalid vcodec, must be %s, actual %s", SRS_RTMP_ENCODER_VCODEC_LIBX264, vcodec.c_str()); } if (vbitrate < 0) { - ret = ERROR_ENCODER_VBITRATE; - srs_error("invalid vbitrate: %d, ret=%d", vbitrate, ret); - return ret; + return srs_error_new(ERROR_ENCODER_VBITRATE, "invalid vbitrate: %d", vbitrate); } if (vfps < 0) { - ret = ERROR_ENCODER_VFPS; - srs_error("invalid vfps: %.2f, ret=%d", vfps, ret); - return ret; + return srs_error_new(ERROR_ENCODER_VFPS, "invalid vfps: %.2f", vfps); } if (vwidth < 0) { - ret = ERROR_ENCODER_VWIDTH; - srs_error("invalid vwidth: %d, ret=%d", vwidth, ret); - return ret; + return srs_error_new(ERROR_ENCODER_VWIDTH, "invalid vwidth: %d", vwidth); } if (vheight < 0) { - ret = ERROR_ENCODER_VHEIGHT; - srs_error("invalid vheight: %d, ret=%d", vheight, ret); - return ret; + return srs_error_new(ERROR_ENCODER_VHEIGHT, "invalid vheight: %d", vheight); } if (vthreads < 0) { - ret = ERROR_ENCODER_VTHREADS; - srs_error("invalid vthreads: %d, ret=%d", vthreads, ret); - return ret; + return srs_error_new(ERROR_ENCODER_VTHREADS, "invalid vthreads: %d", vthreads); } if (vprofile.empty()) { - ret = ERROR_ENCODER_VPROFILE; - srs_error("invalid vprofile: %s, ret=%d", vprofile.c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_VPROFILE, "invalid vprofile: %s", vprofile.c_str()); } if (vpreset.empty()) { - ret = ERROR_ENCODER_VPRESET; - srs_error("invalid vpreset: %s, ret=%d", vpreset.c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_VPRESET, "invalid vpreset: %s", vpreset.c_str()); } } // @see, https://github.com/ossrs/srs/issues/145 if (acodec == SRS_RTMP_ENCODER_LIBAACPLUS && acodec != SRS_RTMP_ENCODER_LIBFDKAAC) { if (abitrate != 0 && (abitrate < 16 || abitrate > 72)) { - ret = ERROR_ENCODER_ABITRATE; - srs_error("invalid abitrate for aac: %d, must in [16, 72], ret=%d", abitrate, ret); - return ret; + return srs_error_new(ERROR_ENCODER_ABITRATE, "invalid abitrate for aac: %d, must in [16, 72]", abitrate); } } if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) { if (abitrate < 0) { - ret = ERROR_ENCODER_ABITRATE; - srs_error("invalid abitrate: %d, ret=%d", abitrate, ret); - return ret; + return srs_error_new(ERROR_ENCODER_ABITRATE, "invalid abitrate: %d", abitrate); } if (asample_rate < 0) { - ret = ERROR_ENCODER_ASAMPLE_RATE; - srs_error("invalid sample rate: %d, ret=%d", asample_rate, ret); - return ret; + return srs_error_new(ERROR_ENCODER_ASAMPLE_RATE, "invalid sample rate: %d", asample_rate); } if (achannels != 0 && achannels != 1 && achannels != 2) { - ret = ERROR_ENCODER_ACHANNELS; - srs_error("invalid achannels, must be 1 or 2, actual %d, ret=%d", achannels, ret); - return ret; + return srs_error_new(ERROR_ENCODER_ACHANNELS, "invalid achannels, must be 1 or 2, actual %d", achannels); } } if (_output.empty()) { - ret = ERROR_ENCODER_OUTPUT; - srs_error("invalid empty output, ret=%d", ret); - return ret; + return srs_error_new(ERROR_ENCODER_OUTPUT, "invalid empty output"); } // for not rtmp input, donot append the iformat, @@ -224,31 +195,29 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) iformat = ""; } - return ret; + return err; } -int SrsFFMPEG::initialize_copy() +srs_error_t SrsFFMPEG::initialize_copy() { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; vcodec = SRS_RTMP_ENCODER_COPY; acodec = SRS_RTMP_ENCODER_COPY; if (_output.empty()) { - ret = ERROR_ENCODER_OUTPUT; - srs_error("invalid empty output, ret=%d", ret); - return ret; + return srs_error_new(ERROR_ENCODER_OUTPUT, "invalid empty output"); } - return ret; + return err; } -int SrsFFMPEG::start() +srs_error_t SrsFFMPEG::start() { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (process->started()) { - return ret; + return err; } // the argv for process. @@ -427,14 +396,14 @@ int SrsFFMPEG::start() } // initialize the process. - if ((ret = process->initialize(ffmpeg, params)) != ERROR_SUCCESS) { - return ret; + if ((err = process->initialize(ffmpeg, params)) != srs_success) { + return srs_error_wrap(err, "init process"); } return process->start(); } -int SrsFFMPEG::cycle() +srs_error_t SrsFFMPEG::cycle() { return process->cycle(); } diff --git a/trunk/src/app/srs_app_ffmpeg.hpp b/trunk/src/app/srs_app_ffmpeg.hpp index 5cf82e5437..b47a098b0e 100644 --- a/trunk/src/app/srs_app_ffmpeg.hpp +++ b/trunk/src/app/srs_app_ffmpeg.hpp @@ -77,12 +77,12 @@ class SrsFFMPEG virtual void set_oformat(std::string format); virtual std::string output(); public: - virtual int initialize(std::string in, std::string out, std::string log); - virtual int initialize_transcode(SrsConfDirective* engine); - virtual int initialize_copy(); + virtual srs_error_t initialize(std::string in, std::string out, std::string log); + virtual srs_error_t initialize_transcode(SrsConfDirective* engine); + virtual srs_error_t initialize_copy(); public: - virtual int start(); - virtual int cycle(); + virtual srs_error_t start(); + virtual srs_error_t cycle(); virtual void stop(); public: virtual void fast_stop(); diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index c932af7127..ce50c1747c 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -234,7 +234,6 @@ srs_error_t SrsForwarder::cycle() srs_error_t SrsForwarder::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; std::string url; @@ -254,12 +253,12 @@ srs_error_t SrsForwarder::do_cycle() int64_t sto = SRS_CONSTS_RTMP_TMMS; sdk = new SrsSimpleRtmpClient(url, cto, sto); - if ((ret = sdk->connect()) != ERROR_SUCCESS) { - return srs_error_new(ret, "sdk connect url=%s, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto); + if ((err = sdk->connect()) != srs_success) { + return srs_error_wrap(err, "sdk connect url=%s, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto); } - if ((ret = sdk->publish()) != ERROR_SUCCESS) { - return srs_error_new(ret, "sdk publish"); + if ((err = sdk->publish()) != srs_success) { + return srs_error_wrap(err, "sdk publish"); } if ((err = hub->on_forwarder_start(this)) != srs_success) { @@ -276,7 +275,6 @@ srs_error_t SrsForwarder::do_cycle() #define SYS_MAX_FORWARD_SEND_MSGS 128 srs_error_t SrsForwarder::forward() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS); @@ -289,13 +287,13 @@ srs_error_t SrsForwarder::forward() // update sequence header // TODO: FIXME: maybe need to zero the sequence header timestamp. if (sh_video) { - if ((ret = sdk->send_and_free_message(sh_video->copy())) != ERROR_SUCCESS) { - return srs_error_new(ret, "send video sh"); + if ((err = sdk->send_and_free_message(sh_video->copy())) != srs_success) { + return srs_error_wrap(err, "send video sh"); } } if (sh_audio) { - if ((ret = sdk->send_and_free_message(sh_audio->copy())) != ERROR_SUCCESS) { - return srs_error_new(ret, "send audio sh"); + if ((err = sdk->send_and_free_message(sh_audio->copy())) != srs_success) { + return srs_error_wrap(err, "send audio sh"); } } @@ -309,11 +307,12 @@ srs_error_t SrsForwarder::forward() // read from client. if (true) { SrsCommonMessage* msg = NULL; - ret = sdk->recv_message(&msg); + err = sdk->recv_message(&msg); - if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) { - return srs_error_new(ret, "receive control message"); + if (err != srs_success && srs_error_code(err) != ERROR_SOCKET_TIMEOUT) { + return srs_error_wrap(err, "receive control message"); } + srs_error_reset(err); srs_freep(msg); } @@ -336,8 +335,8 @@ srs_error_t SrsForwarder::forward() } // sendout messages, all messages are freed by send_and_free_messages(). - if ((ret = sdk->send_and_free_messages(msgs.msgs, count)) != ERROR_SUCCESS) { - return srs_error_new(ret, "send messages"); + if ((err = sdk->send_and_free_messages(msgs.msgs, count)) != srs_success) { + return srs_error_wrap(err, "send messages"); } } diff --git a/trunk/src/app/srs_app_hds.hpp b/trunk/src/app/srs_app_hds.hpp index c2127411da..d5f97e235a 100644 --- a/trunk/src/app/srs_app_hds.hpp +++ b/trunk/src/app/srs_app_hds.hpp @@ -41,15 +41,15 @@ class SrsHds SrsHds(); virtual ~SrsHds(); - int on_publish(SrsRequest* req); - int on_unpublish(); + srs_error_t on_publish(SrsRequest* req); + srs_error_t on_unpublish(); - int on_video(SrsSharedPtrMessage* msg); - int on_audio(SrsSharedPtrMessage* msg); + srs_error_t on_video(SrsSharedPtrMessage* msg); + srs_error_t on_audio(SrsSharedPtrMessage* msg); private: - int flush_mainfest(); - int flush_bootstrap(); + srs_error_t flush_mainfest(); + srs_error_t flush_bootstrap(); void adjust_windows(); private: diff --git a/trunk/src/app/srs_app_heartbeat.cpp b/trunk/src/app/srs_app_heartbeat.cpp index 4b024f6ea2..4cc1258506 100644 --- a/trunk/src/app/srs_app_heartbeat.cpp +++ b/trunk/src/app/srs_app_heartbeat.cpp @@ -46,15 +46,23 @@ SrsHttpHeartbeat::~SrsHttpHeartbeat() void SrsHttpHeartbeat::heartbeat() { - int ret = ERROR_SUCCESS; + srs_error_t err = do_heartbeat(); + if (err != srs_success) { + srs_warn("heartbeat err=%s", srs_error_desc(err).c_str()); + } + srs_freep(err); + return; +} + +srs_error_t SrsHttpHeartbeat::do_heartbeat() +{ srs_error_t err = srs_success; std::string url = _srs_config->get_heartbeat_url(); SrsHttpUri uri; - if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { - srs_error("http uri parse hartbeart url failed. url=%s, ret=%d", url.c_str(), ret); - return; + if ((err = uri.initialize(url)) != srs_success) { + return srs_error_wrap(err, "http uri parse hartbeart url failed. url=%s", url.c_str()); } std::string ip = ""; @@ -80,30 +88,21 @@ void SrsHttpHeartbeat::heartbeat() SrsHttpClient http; if ((err = http.initialize(uri.get_host(), uri.get_port())) != srs_success) { - srs_freep(err); - return; + return srs_error_wrap(err, "init uri=%s", uri.get_url().c_str()); } std::string req = obj->dumps(); ISrsHttpMessage* msg = NULL; if ((err = http.post(uri.get_path(), req, &msg)) != srs_success) { - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); - srs_info("http post hartbeart uri failed. url=%s, request=%s, ret=%d", - url.c_str(), req.c_str(), ret); - return; + return srs_error_wrap(err, "http post hartbeart uri failed. url=%s, request=%s", url.c_str(), req.c_str()); } SrsAutoFree(ISrsHttpMessage, msg); std::string res; - if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) { - return; + if ((err = msg->body_read_all(res)) != srs_success) { + return srs_error_wrap(err, "read body"); } - srs_info("http hook hartbeart success. url=%s, request=%s, response=%s, ret=%d", - url.c_str(), req.c_str(), res.c_str(), ret); - - return; + return err; } diff --git a/trunk/src/app/srs_app_heartbeat.hpp b/trunk/src/app/srs_app_heartbeat.hpp index 22f577b81e..230728dba2 100644 --- a/trunk/src/app/srs_app_heartbeat.hpp +++ b/trunk/src/app/srs_app_heartbeat.hpp @@ -37,6 +37,8 @@ class SrsHttpHeartbeat virtual ~SrsHttpHeartbeat(); public: virtual void heartbeat(); +private: + virtual srs_error_t do_heartbeat(); }; #endif diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index df17572fc8..d707cd4243 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -107,7 +107,6 @@ srs_error_t SrsDvrAsyncCallOnHls::call() SrsConfDirective* conf = _srs_config->get_vhost_on_hls(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_hls"); return err; } @@ -158,7 +157,6 @@ srs_error_t SrsDvrAsyncCallOnHlsNotify::call() SrsConfDirective* conf = _srs_config->get_vhost_on_hls_notify(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_hls_notify"); return err; } @@ -299,7 +297,6 @@ srs_error_t SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, if ((err = srs_create_dir_recursively(m3u8_dir)) != srs_success) { return srs_error_wrap(err, "create dir"); } - srs_info("create m3u8 dir %s ok", m3u8_dir.c_str()); return err; } @@ -322,13 +319,10 @@ srs_error_t SrsHlsMuxer::segment_open() std::string default_acodec_str = _srs_config->get_hls_acodec(req->vhost); if (default_acodec_str == "mp3") { default_acodec = SrsAudioCodecIdMP3; - srs_info("hls: use default mp3 acodec"); } else if (default_acodec_str == "aac") { default_acodec = SrsAudioCodecIdAAC; - srs_info("hls: use default aac acodec"); } else if (default_acodec_str == "an") { default_acodec = SrsAudioCodecIdDisabled; - srs_info("hls: use default an acodec for pure video"); } else { srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str()); } @@ -340,10 +334,8 @@ srs_error_t SrsHlsMuxer::segment_open() std::string default_vcodec_str = _srs_config->get_hls_vcodec(req->vhost); if (default_vcodec_str == "h264") { default_vcodec = SrsVideoCodecIdAVC; - srs_info("hls: use default h264 vcodec"); } else if (default_vcodec_str == "vn") { default_vcodec = SrsVideoCodecIdDisabled; - srs_info("hls: use default vn vcodec for pure audio"); } else { srs_warn("hls: use h264 for other codec=%s", default_vcodec_str.c_str()); } @@ -397,7 +389,6 @@ srs_error_t SrsHlsMuxer::segment_open() ts_file = srs_string_replace(ts_file, "[seq]", ss.str()); } current->set_path(hls_path + "/" + ts_file); - srs_info("hls: generate ts path %s, tmpl=%s, floor=%d", ts_file.c_str(), hls_ts_file.c_str(), hls_ts_floor); // the ts url, relative or absolute url. // TODO: FIXME: Use url and path manager. @@ -430,7 +421,6 @@ srs_error_t SrsHlsMuxer::segment_open() if ((err = current->tscw->open(tmp_file.c_str())) != srs_success) { return srs_error_wrap(err, "open hls muxer"); } - srs_info("open HLS muxer success. path=%s, tmp=%s", current->fullpath().c_str(), tmp_file.c_str()); return err; } @@ -459,8 +449,6 @@ bool SrsHlsMuxer::is_segment_overflow() // use N% deviation, to smoother. double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0.0; - srs_info("hls: dur=%" PRId64 "ms, tar=%.2f, dev=%.2fms/%dp, frag=%.2f", - current->duration(), hls_fragment + deviation, deviation, deviation_ts, hls_fragment); return current->duration() >= (hls_fragment + deviation) * 1000; } @@ -482,8 +470,6 @@ bool SrsHlsMuxer::is_segment_absolutely_overflow() // use N% deviation, to smoother. double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0.0; - srs_info("hls: dur=%" PRId64 "ms, tar=%.2f, dev=%.2fms/%dp, frag=%.2f", - current->duration(), hls_fragment + deviation, deviation, deviation_ts, hls_fragment); return current->duration() >= (hls_aof_ratio * hls_fragment + deviation) * 1000; } @@ -576,7 +562,6 @@ srs_error_t SrsHlsMuxer::segment_close() if ((err = async->execute(new SrsDvrAsyncCallOnHlsNotify(_srs_context->get_id(), req, current->uri))) != srs_success) { return srs_error_wrap(err, "segment close"); } - srs_info("Reap ts segment, sequence_no=%d, uri=%s, duration=%" PRId64 "ms", current->sequence_no, current->uri.c_str(), current->duration()); // close the muxer of finished segment. srs_freep(current->tscw); @@ -646,7 +631,6 @@ srs_error_t SrsHlsMuxer::refresh_m3u8() srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // no segments, return. @@ -655,10 +639,9 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file) } SrsFileWriter writer; - if ((ret = writer.open(m3u8_file)) != ERROR_SUCCESS) { - return srs_error_new(ret, "hls: open m3u8 file %s", m3u8_file.c_str()); + if ((err = writer.open(m3u8_file)) != srs_success) { + return srs_error_wrap(err, "hls: open m3u8 file %s", m3u8_file.c_str()); } - srs_info("open m3u8 file %s success.", m3u8_file.c_str()); // #EXTM3U\n // #EXT-X-VERSION:3\n @@ -667,12 +650,10 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file) ss << "#EXTM3U" << SRS_CONSTS_LF << "#EXT-X-VERSION:3" << SRS_CONSTS_LF << "#EXT-X-ALLOW-CACHE:YES" << SRS_CONSTS_LF; - srs_verbose("write m3u8 header success."); // #EXT-X-MEDIA-SEQUENCE:4294967295\n SrsHlsSegment* first = dynamic_cast(segments->first()); ss << "#EXT-X-MEDIA-SEQUENCE:" << first->sequence_no << SRS_CONSTS_LF; - srs_verbose("write m3u8 sequence success."); // iterator shared for td generation and segemnts wrote. std::vector::iterator it; @@ -691,7 +672,6 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file) target_duration = srs_max(target_duration, max_td); ss << "#EXT-X-TARGETDURATION:" << target_duration << SRS_CONSTS_LF; - srs_verbose("write m3u8 duration success."); // write all segments for (int i = 0; i < segments->size(); i++) { @@ -700,26 +680,22 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file) if (segment->is_sequence_header()) { // #EXT-X-DISCONTINUITY\n ss << "#EXT-X-DISCONTINUITY" << SRS_CONSTS_LF; - srs_verbose("write m3u8 segment discontinuity success."); } // "#EXTINF:4294967295.208,\n" ss.precision(3); ss.setf(std::ios::fixed, std::ios::floatfield); ss << "#EXTINF:" << segment->duration() / 1000.0 << ", no desc" << SRS_CONSTS_LF; - srs_verbose("write m3u8 segment info success."); // {file name}\n ss << segment->uri << SRS_CONSTS_LF; - srs_verbose("write m3u8 segment uri success."); } // write m3u8 to writer. std::string m3u8 = ss.str(); - if ((ret = writer.write((char*)m3u8.c_str(), (int)m3u8.length(), NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "hls: write m3u8"); + if ((err = writer.write((char*)m3u8.c_str(), (int)m3u8.length(), NULL)) != srs_success) { + return srs_error_wrap(err, "hls: write m3u8"); } - srs_info("write m3u8 %s success.", m3u8_file.c_str()); return err; } diff --git a/trunk/src/app/srs_app_hourglass.hpp b/trunk/src/app/srs_app_hourglass.hpp index e38d08b5c6..94c5e1f4c8 100644 --- a/trunk/src/app/srs_app_hourglass.hpp +++ b/trunk/src/app/srs_app_hourglass.hpp @@ -40,7 +40,7 @@ class ISrsHourGlass /** * notify the handler, the type and tick. */ - virtual int notify(int type, int interval, int64_t tick) = 0; + virtual srs_error_t notify(int type, int interval, int64_t tick) = 0; }; /** @@ -87,11 +87,11 @@ class SrsHourGlass // add a pair of tick(type, interval). // @param type the type of tick. // @param interval the interval in ms of tick. - virtual int tick(int type, int interval); + virtual srs_error_t tick(int type, int interval); public: // cycle the hourglass, which will sleep resolution every time. // and call handler when ticked. - virtual int cycle(); + virtual srs_error_t cycle(); }; #endif diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 4c9c1e31b1..088f5cf523 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -48,7 +48,6 @@ using namespace std; srs_error_t srs_api_response_jsonp(ISrsHttpResponseWriter* w, string callback, string data) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsHttpHeader* h = w->header(); @@ -56,21 +55,21 @@ srs_error_t srs_api_response_jsonp(ISrsHttpResponseWriter* w, string callback, s h->set_content_length(data.length() + callback.length() + 2); h->set_content_type("text/javascript"); - if (!callback.empty() && (ret = w->write((char*)callback.data(), (int)callback.length())) != ERROR_SUCCESS) { - return srs_error_new(ret, "write jsonp callback"); + if (!callback.empty() && (err = w->write((char*)callback.data(), (int)callback.length())) != srs_success) { + return srs_error_wrap(err, "write jsonp callback"); } static char* c0 = (char*)"("; - if ((ret = w->write(c0, 1)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write jsonp left token"); + if ((err = w->write(c0, 1)) != srs_success) { + return srs_error_wrap(err, "write jsonp left token"); } - if ((ret = w->write((char*)data.data(), (int)data.length())) != ERROR_SUCCESS) { - return srs_error_new(ret, "write jsonp data"); + if ((err = w->write((char*)data.data(), (int)data.length())) != srs_success) { + return srs_error_wrap(err, "write jsonp data"); } static char* c1 = (char*)")"; - if ((ret = w->write(c1, 1)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write jsonp right token"); + if ((err = w->write(c1, 1)) != srs_success) { + return srs_error_wrap(err, "write jsonp right token"); } return err; @@ -98,7 +97,6 @@ srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callba srs_error_t srs_api_response_json(ISrsHttpResponseWriter* w, string data) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsHttpHeader* h = w->header(); @@ -106,8 +104,8 @@ srs_error_t srs_api_response_json(ISrsHttpResponseWriter* w, string data) h->set_content_length(data.length()); h->set_content_type("application/json"); - if ((ret = w->write((char*)data.data(), (int)data.length())) != ERROR_SUCCESS) { - return srs_error_new(ret, "write json"); + if ((err = w->write((char*)data.data(), (int)data.length())) != srs_success) { + return srs_error_wrap(err, "write json"); } return err; @@ -716,7 +714,7 @@ SrsGoApiVhosts::~SrsGoApiVhosts() srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsStatistic* stat = SrsStatistic::instance(); @@ -726,9 +724,7 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag SrsStatisticVhost* vhost = NULL; if (vid > 0 && (vhost = stat->find_vhost(vid)) == NULL) { - ret = ERROR_RTMP_VHOST_NOT_FOUND; - srs_error("vhost id=%d not found. ret=%d", vid, ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_RTMP_VHOST_NOT_FOUND); } SrsJsonObject* obj = SrsJsonAny::object(); @@ -742,15 +738,19 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag SrsJsonArray* data = SrsJsonAny::array(); obj->set("vhosts", data); - if ((ret = stat->dumps_vhosts(data)) != ERROR_SUCCESS) { - return srs_api_response_code(w, r, ret); + if ((err = stat->dumps_vhosts(data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else { SrsJsonObject* data = SrsJsonAny::object(); obj->set("vhost", data);; - if ((ret = vhost->dumps(data)) != ERROR_SUCCESS) { - return srs_api_response_code(w, r, ret); + if ((err = vhost->dumps(data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } } else { @@ -770,7 +770,7 @@ SrsGoApiStreams::~SrsGoApiStreams() srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsStatistic* stat = SrsStatistic::instance(); @@ -780,9 +780,7 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa SrsStatisticStream* stream = NULL; if (sid >= 0 && (stream = stat->find_stream(sid)) == NULL) { - ret = ERROR_RTMP_STREAM_NOT_FOUND; - srs_error("stream id=%d not found. ret=%d", sid, ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_RTMP_STREAM_NOT_FOUND); } SrsJsonObject* obj = SrsJsonAny::object(); @@ -796,15 +794,19 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa SrsJsonArray* data = SrsJsonAny::array(); obj->set("streams", data); - if ((ret = stat->dumps_streams(data)) != ERROR_SUCCESS) { - return srs_api_response_code(w, r, ret); + if ((err = stat->dumps_streams(data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else { SrsJsonObject* data = SrsJsonAny::object(); obj->set("stream", data);; - if ((ret = stream->dumps(data)) != ERROR_SUCCESS) { - return srs_api_response_code(w, r, ret); + if ((err = stream->dumps(data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } } else { @@ -824,7 +826,7 @@ SrsGoApiClients::~SrsGoApiClients() srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; SrsStatistic* stat = SrsStatistic::instance(); @@ -834,9 +836,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa SrsStatisticClient* client = NULL; if (cid >= 0 && (client = stat->find_client(cid)) == NULL) { - ret = ERROR_RTMP_CLIENT_NOT_FOUND; - srs_error("client id=%d not found. ret=%d", cid, ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND); } SrsJsonObject* obj = SrsJsonAny::object(); @@ -854,22 +854,24 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa std::string rcount = r->query_get("count"); int start = srs_max(0, atoi(rstart.c_str())); int count = srs_max(10, atoi(rcount.c_str())); - if ((ret = stat->dumps_clients(data, start, count)) != ERROR_SUCCESS) { - return srs_api_response_code(w, r, ret); + if ((err = stat->dumps_clients(data, start, count)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else { SrsJsonObject* data = SrsJsonAny::object(); obj->set("client", data);; - if ((ret = client->dumps(data)) != ERROR_SUCCESS) { - return srs_api_response_code(w, r, ret); + if ((err = client->dumps(data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } } else if (r->is_http_delete()) { if (!client) { - ret = ERROR_RTMP_CLIENT_NOT_FOUND; - srs_error("client id=%d not found. ret=%d", cid, ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND); } client->conn->expire(); @@ -900,7 +902,6 @@ SrsGoApiRaw::~SrsGoApiRaw() srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; std::string rpc = r->query_get("rpc"); @@ -913,9 +914,10 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* // for rpc=raw, to query the raw api config for http api. if (rpc == "raw") { // query global scope. - if ((ret = _srs_config->raw_to_json(obj)) != ERROR_SUCCESS) { - srs_error("raw api rpc raw failed. ret=%d", ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_to_json(obj)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } return srs_api_response(w, r, obj->dumps()); @@ -923,31 +925,24 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* // whether enabled the HTTP RAW API. if (!raw_api) { - ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; - srs_warn("raw api disabled. ret=%d", ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED); } ////////////////////////////////////////////////////////////////////////// // the rpc is required. // the allowd rpc method check. if (rpc.empty() || (rpc != "reload" && rpc != "query" && rpc != "raw" && rpc != "update")) { - ret = ERROR_SYSTEM_CONFIG_RAW; - srs_error("raw api invalid rpc=%s. ret=%d", rpc.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW); } // for rpc=reload, trigger the server to reload the config. if (rpc == "reload") { if (!allow_reload) { - ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; - srs_error("raw api reload disabled rpc=%s. ret=%d", rpc.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED); } - srs_trace("raw api trigger reload. ret=%d", ret); server->on_signal(SRS_SIGNAL_RELOAD); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SUCCESS); } // for rpc=query, to get the configs of server. @@ -959,58 +954,53 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* // for the default vhost, must be __defaultVhost__ if (rpc == "query") { if (!allow_query) { - ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; - srs_error("raw api allow_query disabled rpc=%s. ret=%d", rpc.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED); } std::string scope = r->query_get("scope"); std::string vhost = r->query_get("vhost"); if (scope.empty() || (scope != "global" && scope != "vhost" && scope != "minimal")) { - ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; - srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); } if (scope == "vhost") { // query vhost scope. if (vhost.empty()) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api query vhost invalid vhost=%s. ret=%d", vhost.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } SrsConfDirective* root = _srs_config->get_root(); SrsConfDirective* conf = root->get("vhost", vhost); if (!conf) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api query vhost invalid vhost=%s. ret=%d", vhost.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } SrsJsonObject* data = SrsJsonAny::object(); obj->set("vhost", data); - if ((ret = _srs_config->vhost_to_json(conf, data)) != ERROR_SUCCESS) { - srs_error("raw api query vhost failed. ret=%d", ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->vhost_to_json(conf, data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "minimal") { SrsJsonObject* data = SrsJsonAny::object(); obj->set("minimal", data); // query minimal scope. - if ((ret = _srs_config->minimal_to_json(data)) != ERROR_SUCCESS) { - srs_error("raw api query global failed. ret=%d", ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->minimal_to_json(data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else { SrsJsonObject* data = SrsJsonAny::object(); obj->set("global", data); // query global scope. - if ((ret = _srs_config->global_to_json(data)) != ERROR_SUCCESS) { - srs_error("raw api query global failed. ret=%d", ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->global_to_json(data)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } @@ -1044,26 +1034,20 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* // dvr ossrs.net disable live/livestream disable the dvr of stream if (rpc == "update") { if (!allow_update) { - ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; - srs_error("raw api allow_update disabled rpc=%s. ret=%d", rpc.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED); } std::string scope = r->query_get("scope"); std::string value = r->query_get("value"); if (scope.empty()) { - ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; - srs_error("raw api query invalid empty scope. ret=%d", ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); } if (scope != "listen" && scope != "pid" && scope != "chunk_size" && scope != "ff_log_dir" && scope != "srs_log_tank" && scope != "srs_log_level" && scope != "srs_log_file" && scope != "max_connections" && scope != "utc_time" && scope != "pithy_print_ms" && scope != "vhost" && scope != "dvr" ) { - ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; - srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); } bool applied = false; @@ -1081,99 +1065,89 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* } } if (invalid) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check listen=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_listen(eps, applied)) != ERROR_SUCCESS) { - srs_error("raw api update listen=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_listen(eps, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "pid") { if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".pid")) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check pid=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_pid(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update pid=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_pid(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "chunk_size") { int csv = ::atoi(value.c_str()); if (csv < 128 || csv > 65535 || !srs_is_digit_number(value)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_chunk_size(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_chunk_size(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "ff_log_dir") { if (value.empty() || (value != "/dev/null" && !srs_string_starts_with(value, "./", "/tmp/", "/var/"))) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check ff_log_dir=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_ff_log_dir(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update ff_log_dir=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_ff_log_dir(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "srs_log_tank") { if (value.empty() || (value != "file" && value != "console")) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check srs_log_tank=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_srs_log_tank(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update srs_log_tank=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_srs_log_tank(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "srs_log_level") { if (value != "verbose" && value != "info" && value != "trace" && value != "warn" && value != "error") { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check srs_log_level=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_srs_log_level(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update srs_log_level=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_srs_log_level(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "srs_log_file") { if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".log")) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check srs_log_file=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_srs_log_file(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update srs_log_file=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_srs_log_file(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "max_connections") { int mcv = ::atoi(value.c_str()); if (mcv < 10 || mcv > 65535 || !srs_is_digit_number(value)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check max_connections=%s/%d failed. ret=%d", value.c_str(), mcv, ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_max_connections(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update max_connections=%s/%d failed. ret=%d", value.c_str(), mcv, ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_max_connections(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "utc_time") { if (!srs_is_boolean(value)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check utc_time=%s failed. ret=%d", value.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } if ((err = _srs_config->raw_set_utc_time(srs_config_bool2switch(value), applied)) != srs_success) { @@ -1182,36 +1156,32 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* } else if (scope == "pithy_print_ms") { int ppmv = ::atoi(value.c_str()); if (ppmv < 100 || ppmv > 300000 || !srs_is_digit_number(value)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check pithy_print_ms=%s/%d failed. ret=%d", value.c_str(), ppmv, ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_set_pithy_print_ms(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update pithy_print_ms=%s/%d failed. ret=%d", value.c_str(), ppmv, ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_set_pithy_print_ms(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (scope == "vhost") { std::string param = r->query_get("param"); std::string data = r->query_get("data"); if (param != "create" && param != "update" && param != "delete" && param != "disable" && param != "enable") { - ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; - srs_error("raw api query invalid scope=%s, param=%s. ret=%d", scope.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); } extra += " " + param; if (param == "create") { // when create, the vhost must not exists. if (param.empty() || _srs_config->get_vhost(value, false)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_create_vhost(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_create_vhost(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (param == "update") { extra += " to " + data; @@ -1219,53 +1189,49 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* // when update, the vhost must exists and disabled. SrsConfDirective* vhost = _srs_config->get_vhost(value, false); if (data.empty() || data == value || param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check vhost=%s, param=%s, data=%s failed. ret=%d", value.c_str(), param.c_str(), data.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_update_vhost(value, data, applied)) != ERROR_SUCCESS) { - srs_error("raw api update vhost=%s, param=%s, data=%s failed. ret=%d", value.c_str(), param.c_str(), data.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_update_vhost(value, data, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (param == "delete") { // when delete, the vhost must exists and disabled. SrsConfDirective* vhost = _srs_config->get_vhost(value, false); if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_delete_vhost(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_delete_vhost(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (param == "disable") { // when disable, the vhost must exists and enabled. SrsConfDirective* vhost = _srs_config->get_vhost(value, false); if (param.empty() || !vhost || !_srs_config->get_vhost_enabled(vhost)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_disable_vhost(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_disable_vhost(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else if (param == "enable") { // when enable, the vhost must exists and disabled. SrsConfDirective* vhost = _srs_config->get_vhost(value, false); if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { - ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; - srs_error("raw api update check vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); } - if ((ret = _srs_config->raw_enable_vhost(value, applied)) != ERROR_SUCCESS) { - srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_enable_vhost(value, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else { // TODO: support other param. @@ -1276,26 +1242,24 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* extra += "/" + stream + " to " + action; if (action != "enable" && action != "disable") { - ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; - srs_error("raw api query invalid scope=%s, param=%s. ret=%d", scope.c_str(), action.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); } if (!_srs_config->get_dvr_enabled(value)) { - ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; - srs_error("raw api query invalid scope=%s, value=%s, param=%s. ret=%d", scope.c_str(), value.c_str(), action.c_str(), ret); - return srs_api_response_code(w, r, ret); + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); } if (action == "enable") { - if ((ret = _srs_config->raw_enable_dvr(value, stream, applied)) != ERROR_SUCCESS) { - srs_error("raw api update dvr=%s/%s, param=%s failed. ret=%d", value.c_str(), stream.c_str(), action.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_enable_dvr(value, stream, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } else { - if ((ret = _srs_config->raw_disable_dvr(value, stream, applied)) != ERROR_SUCCESS) { - srs_error("raw api update dvr=%s/%s, param=%s failed. ret=%d", value.c_str(), stream.c_str(), action.c_str(), ret); - return srs_api_response_code(w, r, ret); + if ((err = _srs_config->raw_disable_dvr(value, stream, applied)) != srs_success) { + int code = srs_error_code(err); + srs_error_reset(err); + return srs_api_response_code(w, r, code); } } } else { @@ -1381,14 +1345,13 @@ void SrsHttpApi::cleanup() srs_error_t SrsHttpApi::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; srs_trace("api get peer ip success. ip=%s", ip.c_str()); // initialize parser - if ((ret = parser->initialize(HTTP_REQUEST, true)) != ERROR_SUCCESS) { - return srs_error_new(ret, "init parser"); + if ((err = parser->initialize(HTTP_REQUEST, true)) != srs_success) { + return srs_error_wrap(err, "init parser"); } // set the recv timeout, for some clients never disconnect the connection. @@ -1406,8 +1369,8 @@ srs_error_t SrsHttpApi::do_cycle() ISrsHttpMessage* req = NULL; // get a http message - if ((ret = parser->parse_message(skt, this, &req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "parse message"); + if ((err = parser->parse_message(skt, this, &req)) != srs_success) { + return srs_error_wrap(err, "parse message"); } // if SUCCESS, always NOT-NULL. @@ -1426,8 +1389,8 @@ srs_error_t SrsHttpApi::do_cycle() char buf[SRS_HTTP_READ_CACHE_BYTES]; ISrsHttpResponseReader* br = req->body_reader(); while (!br->eof()) { - if ((ret = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "read response"); + if ((err = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != srs_success) { + return srs_error_wrap(err, "read response"); } } diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 483bb0d95b..da42458e1a 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -97,14 +97,13 @@ void SrsHttpConn::cleanup() srs_error_t SrsHttpConn::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; srs_trace("HTTP client ip=%s", ip.c_str()); // initialize parser - if ((ret = parser->initialize(HTTP_REQUEST, false)) != ERROR_SUCCESS) { - return srs_error_new(ret, "init parser"); + if ((err = parser->initialize(HTTP_REQUEST, false)) != srs_success) { + return srs_error_wrap(err, "init parser"); } // set the recv timeout, for some clients never disconnect the connection. @@ -125,7 +124,7 @@ srs_error_t SrsHttpConn::do_cycle() ISrsHttpMessage* req = NULL; // get a http message - if ((ret = parser->parse_message(skt, this, &req)) != ERROR_SUCCESS) { + if ((err = parser->parse_message(skt, this, &req)) != srs_success) { break; } @@ -212,7 +211,6 @@ SrsResponseOnlyHttpConn::~SrsResponseOnlyHttpConn() srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsStSocket skt; @@ -221,8 +219,8 @@ srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq) return srs_error_wrap(err, "init socket"); } - if ((ret = parser->parse_message(&skt, this, preq)) != ERROR_SUCCESS) { - return srs_error_new(ret, "parse message"); + if ((err = parser->parse_message(&skt, this, preq)) != srs_success) { + return srs_error_wrap(err, "parse message"); } return err; @@ -230,7 +228,6 @@ srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq) srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; ISrsHttpResponseReader* br = msg->body_reader(); @@ -243,8 +240,8 @@ srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg) // drop all request body. while (!br->eof()) { char body[4096]; - if ((ret = br->read(body, 4096, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "read response"); + if ((err = br->read(body, 4096, NULL)) != srs_success) { + return srs_error_wrap(err, "read response"); } } @@ -300,7 +297,7 @@ srs_error_t SrsHttpServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage return http_static->mux.serve_http(w, r); } -int SrsHttpServer::http_mount(SrsSource* s, SrsRequest* r) +srs_error_t SrsHttpServer::http_mount(SrsSource* s, SrsRequest* r) { return http_stream->http_mount(s, r); } diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index 8ae4161ddf..354a81e3f7 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -131,7 +131,7 @@ class SrsHttpServer : public ISrsHttpServeMux virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); // http flv/ts/mp3/aac stream public: - virtual int http_mount(SrsSource* s, SrsRequest* r); + virtual srs_error_t http_mount(SrsSource* s, SrsRequest* r); virtual void http_unmount(SrsSource* s, SrsRequest* r); }; diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 741177bf38..d2081f1ea9 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -343,7 +343,6 @@ srs_error_t SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string fi srs_error_t SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; int client_id = cid; @@ -360,8 +359,8 @@ srs_error_t SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* re int64_t starttime = srs_update_system_time_ms(); SrsHttpUri uri; - if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { - return srs_error_new(ret, "http: init url=%s", url.c_str()); + if ((err = uri.initialize(url)) != srs_success) { + return srs_error_wrap(err, "http: init url=%s", url.c_str()); } SrsHttpClient http; @@ -393,30 +392,28 @@ srs_error_t SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* re ISrsHttpResponseReader* br = msg->body_reader(); while (nb_read < nb_notify && !br->eof()) { int nb_bytes = 0; - if ((ret = br->read(buf, nb_buf, &nb_bytes)) != ERROR_SUCCESS) { + if ((err = br->read(buf, nb_buf, &nb_bytes)) != srs_success) { break; } nb_read += nb_bytes; } int spenttime = (int)(srs_update_system_time_ms() - starttime); - srs_trace("http hook on_hls_notify success. client_id=%d, url=%s, code=%d, spent=%dms, read=%dB, ret=%d", - client_id, url.c_str(), msg->status_code(), spenttime, nb_read, ret); + srs_trace("http hook on_hls_notify success. client_id=%d, url=%s, code=%d, spent=%dms, read=%dB, err=%s", + client_id, url.c_str(), msg->status_code(), spenttime, nb_read, srs_error_desc(err).c_str()); // ignore any error for on_hls_notify. - ret = ERROR_SUCCESS; - - return err; + srs_error_reset(err); + return srs_success; } srs_error_t SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::string req, int& code, string& res) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsHttpUri uri; - if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { - return srs_error_new(ret, "http: post failed. url=%s", url.c_str()); + if ((err = uri.initialize(url)) != srs_success) { + return srs_error_wrap(err, "http: post failed. url=%s", url.c_str()); } if ((err = hc->initialize(uri.get_host(), uri.get_port())) != srs_success) { @@ -430,8 +427,8 @@ srs_error_t SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::strin SrsAutoFree(ISrsHttpMessage, msg); code = msg->status_code(); - if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) { - return srs_error_new(ret, "http: body read"); + if ((err = msg->body_read_all(res)) != srs_success) { + return srs_error_wrap(err, "http: body read"); } // ensure the http status is ok. diff --git a/trunk/src/app/srs_app_http_hooks.hpp b/trunk/src/app/srs_app_http_hooks.hpp index 586aaaac8f..7d73bdfc0d 100644 --- a/trunk/src/app/srs_app_http_hooks.hpp +++ b/trunk/src/app/srs_app_http_hooks.hpp @@ -102,7 +102,8 @@ class SrsHttpHooks * @param duration the segment duration in seconds. * @param cid the source connection cid, for the on_dvr is async call. */ - static srs_error_t on_hls(int cid, std::string url, SrsRequest* req, std::string file, std::string ts_url, std::string m3u8, std::string m3u8_url, int sn, double duration); + static srs_error_t on_hls(int cid, std::string url, SrsRequest* req, std::string file, std::string ts_url, + std::string m3u8, std::string m3u8_url, int sn, double duration); /** * when hls reap segment, callback. * @param url the api server url, to process the event. diff --git a/trunk/src/app/srs_app_http_static.cpp b/trunk/src/app/srs_app_http_static.cpp index 34ec28f2b6..faceaef5e5 100644 --- a/trunk/src/app/srs_app_http_static.cpp +++ b/trunk/src/app/srs_app_http_static.cpp @@ -62,14 +62,13 @@ SrsVodStream::~SrsVodStream() srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, string fullpath, int offset) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsFileReader fs; // open flv file - if ((ret = fs.open(fullpath)) != ERROR_SUCCESS) { - return srs_error_new(ret, "open file"); + if ((err = fs.open(fullpath)) != srs_success) { + return srs_error_wrap(err, "open file"); } if (offset > fs.filesize()) { @@ -80,16 +79,16 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe SrsFlvVodStreamDecoder ffd; // open fast decoder - if ((ret = ffd.initialize(&fs)) != ERROR_SUCCESS) { - return srs_error_new(ret, "init ffd"); + if ((err = ffd.initialize(&fs)) != srs_success) { + return srs_error_wrap(err, "init ffd"); } // save header, send later. char flv_header[13]; // send flv header - if ((ret = ffd.read_header_ext(flv_header)) != ERROR_SUCCESS) { - return srs_error_new(ret, "ffd read header"); + if ((err = ffd.read_header_ext(flv_header)) != srs_success) { + return srs_error_wrap(err, "ffd read header"); } // save sequence header, send later @@ -99,8 +98,8 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe if (true) { // send sequence header int64_t start = 0; - if ((ret = ffd.read_sequence_header_summary(&start, &sh_size)) != ERROR_SUCCESS) { - return srs_error_new(ret, "ffd read sps"); + if ((err = ffd.read_sequence_header_summary(&start, &sh_size)) != srs_success) { + return srs_error_wrap(err, "ffd read sps"); } if (sh_size <= 0) { return srs_error_new(ERROR_HTTP_REMUX_SEQUENCE_HEADER, "no sequence, size=%d", sh_size); @@ -108,8 +107,8 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe } sh_data = new char[sh_size]; SrsAutoFreeA(char, sh_data); - if ((ret = fs.read(sh_data, sh_size, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "fs read"); + if ((err = fs.read(sh_data, sh_size, NULL)) != srs_success) { + return srs_error_wrap(err, "fs read"); } // seek to data offset @@ -120,16 +119,16 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe w->header()->set_content_type("video/x-flv"); // write flv header and sequence header. - if ((ret = w->write(flv_header, sizeof(flv_header))) != ERROR_SUCCESS) { - return srs_error_new(ret, "write flv header"); + if ((err = w->write(flv_header, sizeof(flv_header))) != srs_success) { + return srs_error_wrap(err, "write flv header"); } - if (sh_size > 0 && (ret = w->write(sh_data, sh_size)) != ERROR_SUCCESS) { - return srs_error_new(ret, "write sequence"); + if (sh_size > 0 && (err = w->write(sh_data, sh_size)) != srs_success) { + return srs_error_wrap(err, "write sequence"); } // write body. - if ((ret = ffd.seek2(offset)) != ERROR_SUCCESS) { - return srs_error_new(ret, "ffd seek"); + if ((err = ffd.seek2(offset)) != srs_success) { + return srs_error_wrap(err, "ffd seek"); } // send data @@ -142,7 +141,6 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe srs_error_t SrsVodStream::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, string fullpath, int start, int end) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; srs_assert(start >= 0); @@ -151,8 +149,8 @@ srs_error_t SrsVodStream::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMe SrsFileReader fs; // open flv file - if ((ret = fs.open(fullpath)) != ERROR_SUCCESS) { - return srs_error_new(ret, "fs open"); + if ((err = fs.open(fullpath)) != srs_success) { + return srs_error_wrap(err, "fs open"); } // parse -1 to whole file. @@ -204,7 +202,6 @@ SrsHttpStaticServer::~SrsHttpStaticServer() srs_error_t SrsHttpStaticServer::initialize() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; bool default_root_exists = false; @@ -220,8 +217,8 @@ srs_error_t SrsHttpStaticServer::initialize() string pmount; string vhost = conf->arg0(); - if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) { - return srs_error_new(ret, "mount vhost"); + if ((err = mount_vhost(vhost, pmount)) != srs_success) { + return srs_error_wrap(err, "mount vhost"); } if (pmount == "/") { @@ -243,19 +240,18 @@ srs_error_t SrsHttpStaticServer::initialize() return err; } -int SrsHttpStaticServer::mount_vhost(string vhost, string& pmount) +srs_error_t SrsHttpStaticServer::mount_vhost(string vhost, string& pmount) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // when vhost disabled, ignore. if (!_srs_config->get_vhost_enabled(vhost)) { - return ret; + return err; } // when vhost http_static disabled, ignore. if (!_srs_config->get_vhost_http_enabled(vhost)) { - return ret; + return err; } std::string mount = _srs_config->get_vhost_http_mount(vhost); @@ -275,28 +271,22 @@ int SrsHttpStaticServer::mount_vhost(string vhost, string& pmount) // mount the http of vhost. if ((err = mux.handle(mount, new SrsVodStream(dir))) != srs_success) { - // TODO: FIXME: Use error. - ret = srs_error_code(err); - srs_freep(err); - - srs_error("http: mount dir=%s for vhost=%s failed. ret=%d", dir.c_str(), vhost.c_str(), ret); - return ret; + return srs_error_wrap(err, "mux handle"); } srs_trace("http: vhost=%s mount to %s at %s", vhost.c_str(), mount.c_str(), dir.c_str()); pmount = mount; - return ret; + return err; } srs_error_t SrsHttpStaticServer::on_reload_vhost_added(string vhost) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; string pmount; - if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) { - return srs_error_new(ret, "mount vhost"); + if ((err = mount_vhost(vhost, pmount)) != srs_success) { + return srs_error_wrap(err, "mount vhost"); } return err; diff --git a/trunk/src/app/srs_app_http_static.hpp b/trunk/src/app/srs_app_http_static.hpp index c9257e9721..3e5e8dc1db 100644 --- a/trunk/src/app/srs_app_http_static.hpp +++ b/trunk/src/app/srs_app_http_static.hpp @@ -60,7 +60,7 @@ class SrsHttpStaticServer : virtual public ISrsReloadHandler public: virtual srs_error_t initialize(); private: - virtual int mount_vhost(std::string vhost, std::string& pmount); + virtual srs_error_t mount_vhost(std::string vhost, std::string& pmount); // interface ISrsReloadHandler. public: virtual srs_error_t on_reload_vhost_added(std::string vhost); diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 4548c5bff4..58aa2d1121 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -615,27 +615,27 @@ srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage return err; } -int SrsLiveStream::streaming_send_messages(ISrsBufferEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs) +srs_error_t SrsLiveStream::streaming_send_messages(ISrsBufferEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; for (int i = 0; i < nb_msgs; i++) { SrsSharedPtrMessage* msg = msgs[i]; if (msg->is_audio()) { - ret = enc->write_audio(msg->timestamp, msg->payload, msg->size); + err = enc->write_audio(msg->timestamp, msg->payload, msg->size); } else if (msg->is_video()) { - ret = enc->write_video(msg->timestamp, msg->payload, msg->size); + err = enc->write_video(msg->timestamp, msg->payload, msg->size); } else { - ret = enc->write_metadata(msg->timestamp, msg->payload, msg->size); + err = enc->write_metadata(msg->timestamp, msg->payload, msg->size); } - if (ret != ERROR_SUCCESS) { - return ret; + if (err != srs_success) { + return srs_error_wrap(err, "send messages"); } } - return ret; + return err; } SrsLiveEntry::SrsLiveEntry(std::string m) @@ -731,8 +731,7 @@ srs_error_t SrsHttpStreamServer::http_mount(SrsSource* s, SrsRequest* r) // create stream from template when not found. if (sflvs.find(sid) == sflvs.end()) { if (tflvs.find(r->vhost) == tflvs.end()) { - srs_info("ignore mount flv stream for disabled"); - return ret; + return err; } SrsLiveEntry* tmpl = tflvs[r->vhost]; @@ -797,7 +796,6 @@ void SrsHttpStreamServer::http_unmount(SrsSource* s, SrsRequest* r) std::string sid = r->get_stream_url(); if (sflvs.find(sid) == sflvs.end()) { - srs_info("ignore unmount flv stream for disabled"); return; } diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index c06f731c86..34a69d00ff 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -47,16 +47,16 @@ SrsIngesterFFMPEG::~SrsIngesterFFMPEG() srs_freep(ffmpeg); } -int SrsIngesterFFMPEG::initialize(SrsFFMPEG* ff, string v, string i) +srs_error_t SrsIngesterFFMPEG::initialize(SrsFFMPEG* ff, string v, string i) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; ffmpeg = ff; vhost = v; id = i; starttime = srs_get_system_time_ms(); - return ret; + return err; } string SrsIngesterFFMPEG::uri() @@ -79,7 +79,7 @@ bool SrsIngesterFFMPEG::equals(string v, string i) return vhost == v && id == i; } -int SrsIngesterFFMPEG::start() +srs_error_t SrsIngesterFFMPEG::start() { return ffmpeg->start(); } @@ -89,7 +89,7 @@ void SrsIngesterFFMPEG::stop() ffmpeg->stop(); } -int SrsIngesterFFMPEG::cycle() +srs_error_t SrsIngesterFFMPEG::cycle() { return ffmpeg->cycle(); } @@ -128,12 +128,11 @@ void SrsIngester::dispose() srs_error_t SrsIngester::start() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; - if ((ret = parse()) != ERROR_SUCCESS) { + if ((err = parse()) != srs_success) { clear_engines(); - return srs_error_new(ret, "parse"); + return srs_error_wrap(err, "parse"); } // even no ingesters, we must also start it, @@ -195,7 +194,6 @@ srs_error_t SrsIngester::cycle() srs_error_t SrsIngester::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // when expired, restart all ingesters. @@ -207,8 +205,8 @@ srs_error_t SrsIngester::do_cycle() clear_engines(); // re-prase the ingesters. - if ((ret = parse()) != ERROR_SUCCESS) { - return srs_error_new(ret, "parse"); + if ((err = parse()) != srs_success) { + return srs_error_wrap(err, "parse"); } } @@ -218,13 +216,13 @@ srs_error_t SrsIngester::do_cycle() SrsIngesterFFMPEG* ingester = *it; // start all ffmpegs. - if ((ret = ingester->start()) != ERROR_SUCCESS) { - return srs_error_new(ret, "ingester start"); + if ((err = ingester->start()) != srs_success) { + return srs_error_wrap(err, "ingester start"); } // check ffmpeg status. - if ((ret = ingester->cycle()) != ERROR_SUCCESS) { - return srs_error_new(ret, "ingester cycle"); + if ((err = ingester->cycle()) != srs_success) { + return srs_error_wrap(err, "ingester cycle"); } } @@ -246,9 +244,9 @@ void SrsIngester::clear_engines() ingesters.clear(); } -int SrsIngester::parse() +srs_error_t SrsIngester::parse() { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; // parse ingesters std::vector vhosts; @@ -256,21 +254,21 @@ int SrsIngester::parse() for (int i = 0; i < (int)vhosts.size(); i++) { SrsConfDirective* vhost = vhosts[i]; - if ((ret = parse_ingesters(vhost)) != ERROR_SUCCESS) { - return ret; + if ((err = parse_ingesters(vhost)) != srs_success) { + return srs_error_wrap(err, "parse ingesters"); } } - return ret; + return err; } -int SrsIngester::parse_ingesters(SrsConfDirective* vhost) +srs_error_t SrsIngester::parse_ingesters(SrsConfDirective* vhost) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; // when vhost disabled, ignore any ingesters. if (!_srs_config->get_vhost_enabled(vhost)) { - return ret; + return err; } std::vector ingesters = _srs_config->get_ingesters(vhost->arg0()); @@ -278,27 +276,25 @@ int SrsIngester::parse_ingesters(SrsConfDirective* vhost) // create engine for (int i = 0; i < (int)ingesters.size(); i++) { SrsConfDirective* ingest = ingesters[i]; - if ((ret = parse_engines(vhost, ingest)) != ERROR_SUCCESS) { - return ret; + if ((err = parse_engines(vhost, ingest)) != srs_success) { + return srs_error_wrap(err, "parse engines"); } } - return ret; + return err; } -int SrsIngester::parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest) +srs_error_t SrsIngester::parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (!_srs_config->get_ingest_enabled(ingest)) { - return ret; + return err; } std::string ffmpeg_bin = _srs_config->get_ingest_ffmpeg(ingest); if (ffmpeg_bin.empty()) { - ret = ERROR_ENCODER_PARSE; - srs_trace("empty ffmpeg ret=%d", ret); - return ret; + return srs_error_new(ERROR_ENCODER_PARSE, "parse ffmpeg"); } // get all engines. @@ -307,52 +303,45 @@ int SrsIngester::parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest // create ingesters without engines. if (engines.empty()) { SrsFFMPEG* ffmpeg = new SrsFFMPEG(ffmpeg_bin); - if ((ret = initialize_ffmpeg(ffmpeg, vhost, ingest, NULL)) != ERROR_SUCCESS) { + if ((err = initialize_ffmpeg(ffmpeg, vhost, ingest, NULL)) != srs_success) { srs_freep(ffmpeg); - if (ret != ERROR_ENCODER_LOOP) { - srs_error("invalid ingest engine. ret=%d", ret); - } - return ret; + return srs_error_wrap(err, "init ffmpeg"); } SrsIngesterFFMPEG* ingester = new SrsIngesterFFMPEG(); - if ((ret = ingester->initialize(ffmpeg, vhost->arg0(), ingest->arg0())) != ERROR_SUCCESS) { + if ((err = ingester->initialize(ffmpeg, vhost->arg0(), ingest->arg0())) != srs_success) { srs_freep(ingester); - return ret; + return srs_error_wrap(err, "init ingester"); } ingesters.push_back(ingester); - return ret; + return err; } // create ingesters with engine for (int i = 0; i < (int)engines.size(); i++) { SrsConfDirective* engine = engines[i]; SrsFFMPEG* ffmpeg = new SrsFFMPEG(ffmpeg_bin); - if ((ret = initialize_ffmpeg(ffmpeg, vhost, ingest, engine)) != ERROR_SUCCESS) { + if ((err = initialize_ffmpeg(ffmpeg, vhost, ingest, engine)) != srs_success) { srs_freep(ffmpeg); - if (ret != ERROR_ENCODER_LOOP) { - srs_error("invalid ingest engine: %s %s, ret=%d", - ingest->arg0().c_str(), engine->arg0().c_str(), ret); - } - return ret; + return srs_error_wrap(err, "init ffmpeg"); } SrsIngesterFFMPEG* ingester = new SrsIngesterFFMPEG(); - if ((ret = ingester->initialize(ffmpeg, vhost->arg0(), ingest->arg0())) != ERROR_SUCCESS) { + if ((err = ingester->initialize(ffmpeg, vhost->arg0(), ingest->arg0())) != srs_success) { srs_freep(ingester); - return ret; + return srs_error_wrap(err, "init ingester"); } ingesters.push_back(ingester); } - return ret; + return err; } -int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, SrsConfDirective* ingest, SrsConfDirective* engine) +srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, SrsConfDirective* ingest, SrsConfDirective* engine) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; int port; if (true) { @@ -370,9 +359,7 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S output = srs_string_replace(output, "[vhost]", vhost->arg0()); output = srs_string_replace(output, "[port]", srs_int2str(port)); if (output.empty()) { - ret = ERROR_ENCODER_NO_OUTPUT; - srs_trace("empty output url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_NO_OUTPUT, "empty output url, ingest=%s", ingest->arg0().c_str()); } // find the app and stream in rtmp url @@ -402,43 +389,35 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S // input std::string input_type = _srs_config->get_ingest_input_type(ingest); if (input_type.empty()) { - ret = ERROR_ENCODER_NO_INPUT; - srs_trace("empty intput type, ingest=%s. ret=%d", ingest->arg0().c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_NO_INPUT, "empty intput type, ingest=%s", ingest->arg0().c_str()); } if (srs_config_ingest_is_file(input_type)) { std::string input_url = _srs_config->get_ingest_input_url(ingest); if (input_url.empty()) { - ret = ERROR_ENCODER_NO_INPUT; - srs_trace("empty intput url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_NO_INPUT, "empty intput url, ingest=%s", ingest->arg0().c_str()); } // for file, set re. ffmpeg->set_iparams("-re"); - if ((ret = ffmpeg->initialize(input_url, output, log_file)) != ERROR_SUCCESS) { - return ret; + if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) { + return srs_error_wrap(err, "init ffmpeg"); } } else if (srs_config_ingest_is_stream(input_type)) { std::string input_url = _srs_config->get_ingest_input_url(ingest); if (input_url.empty()) { - ret = ERROR_ENCODER_NO_INPUT; - srs_trace("empty intput url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret); - return ret; + return srs_error_new(ERROR_ENCODER_NO_INPUT, "empty intput url, ingest=%s", ingest->arg0().c_str()); } // for stream, no re. ffmpeg->set_iparams(""); - if ((ret = ffmpeg->initialize(input_url, output, log_file)) != ERROR_SUCCESS) { - return ret; + if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) { + return srs_error_wrap(err, "init ffmpeg"); } } else { - ret = ERROR_ENCODER_INPUT_TYPE; - srs_error("invalid ingest=%s type=%s, ret=%d", - ingest->arg0().c_str(), input_type.c_str(), ret); + return srs_error_new(ERROR_ENCODER_INPUT_TYPE, "invalid ingest=%s type=%s", ingest->arg0().c_str(), input_type.c_str()); } // set output format to flv for RTMP @@ -449,19 +428,18 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S // whatever the engine config, use copy as default. bool engine_disabled = !engine || !_srs_config->get_engine_enabled(engine); if (engine_disabled || vcodec.empty() || acodec.empty()) { - if ((ret = ffmpeg->initialize_copy()) != ERROR_SUCCESS) { - return ret; + if ((err = ffmpeg->initialize_copy()) != srs_success) { + return srs_error_wrap(err, "init ffmpeg"); } } else { - if ((ret = ffmpeg->initialize_transcode(engine)) != ERROR_SUCCESS) { - return ret; + if ((err = ffmpeg->initialize_transcode(engine)) != srs_success) { + return srs_error_wrap(err, "init ffmpeg"); } } - srs_trace("parse success, ingest=%s, vhost=%s", - ingest->arg0().c_str(), vhost->arg0().c_str()); + srs_trace("parse success, ingest=%s, vhost=%s", ingest->arg0().c_str(), vhost->arg0().c_str()); - return ret; + return err; } void SrsIngester::show_ingest_log_message() @@ -513,12 +491,11 @@ srs_error_t SrsIngester::on_reload_vhost_removed(string vhost) srs_error_t SrsIngester::on_reload_vhost_added(string vhost) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsConfDirective* _vhost = _srs_config->get_vhost(vhost); - if ((ret = parse_ingesters(_vhost)) != ERROR_SUCCESS) { - return srs_error_new(ret, "parse ingesters"); + if ((err = parse_ingesters(_vhost)) != srs_success) { + return srs_error_wrap(err, "parse ingesters"); } srs_trace("reload add vhost ingesters, vhost=%s", vhost.c_str()); @@ -556,14 +533,13 @@ srs_error_t SrsIngester::on_reload_ingest_removed(string vhost, string ingest_id srs_error_t SrsIngester::on_reload_ingest_added(string vhost, string ingest_id) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsConfDirective* _vhost = _srs_config->get_vhost(vhost); SrsConfDirective* _ingester = _srs_config->get_ingest_by_id(vhost, ingest_id); - if ((ret = parse_engines(_vhost, _ingester)) != ERROR_SUCCESS) { - return srs_error_new(ret, "parse engines"); + if ((err = parse_engines(_vhost, _ingester)) != srs_success) { + return srs_error_wrap(err, "parse engines"); } srs_trace("reload add ingester, vhost=%s, id=%s", vhost.c_str(), ingest_id.c_str()); diff --git a/trunk/src/app/srs_app_ingest.hpp b/trunk/src/app/srs_app_ingest.hpp index 9fdec2efb5..0845b85796 100644 --- a/trunk/src/app/srs_app_ingest.hpp +++ b/trunk/src/app/srs_app_ingest.hpp @@ -51,7 +51,7 @@ class SrsIngesterFFMPEG SrsIngesterFFMPEG(); virtual ~SrsIngesterFFMPEG(); public: - virtual int initialize(SrsFFMPEG* ff, std::string v, std::string i); + virtual srs_error_t initialize(SrsFFMPEG* ff, std::string v, std::string i); // the ingest uri, [vhost]/[ingest id] virtual std::string uri(); // the alive in ms. @@ -59,9 +59,9 @@ class SrsIngesterFFMPEG virtual bool equals(std::string v, std::string i); virtual bool equals(std::string v); public: - virtual int start(); + virtual srs_error_t start(); virtual void stop(); - virtual int cycle(); + virtual srs_error_t cycle(); // @see SrsFFMPEG.fast_stop(). virtual void fast_stop(); }; @@ -99,10 +99,10 @@ class SrsIngester : public ISrsCoroutineHandler, public ISrsReloadHandler virtual srs_error_t do_cycle(); private: virtual void clear_engines(); - virtual int parse(); - virtual int parse_ingesters(SrsConfDirective* vhost); - virtual int parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest); - virtual int initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, SrsConfDirective* ingest, SrsConfDirective* engine); + virtual srs_error_t parse(); + virtual srs_error_t parse_ingesters(SrsConfDirective* vhost); + virtual srs_error_t parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest); + virtual srs_error_t initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, SrsConfDirective* ingest, SrsConfDirective* engine); virtual void show_ingest_log_message(); // interface ISrsReloadHandler. public: diff --git a/trunk/src/app/srs_app_kafka.hpp b/trunk/src/app/srs_app_kafka.hpp index 20ad4b3280..e2f2593cd8 100644 --- a/trunk/src/app/srs_app_kafka.hpp +++ b/trunk/src/app/srs_app_kafka.hpp @@ -69,8 +69,8 @@ struct SrsKafkaPartition virtual ~SrsKafkaPartition(); public: virtual std::string hostport(); - virtual int connect(); - virtual int flush(SrsKafkaPartitionCache* pc); + virtual srs_error_t connect(); + virtual srs_error_t flush(SrsKafkaPartitionCache* pc); private: virtual void disconnect(); }; @@ -123,7 +123,7 @@ class SrsKafkaCache /** * flush the specified partition cache. */ - virtual int flush(SrsKafkaPartition* partition, int key, SrsKafkaPartitionCache* pc); + virtual srs_error_t flush(SrsKafkaPartition* partition, int key, SrsKafkaPartitionCache* pc); }; /** @@ -189,7 +189,7 @@ class SrsKafkaProducer : virtual public ISrsCoroutineHandler, virtual public ISr * @param key the key to map to the partition, user can use cid or hash. * @param obj the json object; user must never free it again. */ - virtual int send(int key, SrsJsonObject* obj); + virtual srs_error_t send(int key, SrsJsonObject* obj); // interface ISrsKafkaCluster public: virtual srs_error_t on_client(int key, SrsListenerType type, std::string ip); @@ -200,10 +200,10 @@ class SrsKafkaProducer : virtual public ISrsCoroutineHandler, virtual public ISr private: virtual void clear_metadata(); virtual srs_error_t do_cycle(); - virtual int request_metadata(); + virtual srs_error_t request_metadata(); // set the metadata to invalid and refresh it. virtual void refresh_metadata(); - virtual int flush(); + virtual srs_error_t flush(); }; #endif diff --git a/trunk/src/app/srs_app_mpegts_udp.hpp b/trunk/src/app/srs_app_mpegts_udp.hpp index b891c939c1..77901163f3 100644 --- a/trunk/src/app/srs_app_mpegts_udp.hpp +++ b/trunk/src/app/srs_app_mpegts_udp.hpp @@ -66,7 +66,7 @@ class SrsMpegtsQueue SrsMpegtsQueue(); virtual ~SrsMpegtsQueue(); public: - virtual int push(SrsSharedPtrMessage* msg); + virtual srs_error_t push(SrsSharedPtrMessage* msg); virtual SrsSharedPtrMessage* dequeue(); }; @@ -103,21 +103,21 @@ class SrsMpegtsOverUdp : virtual public ISrsTsHandler public: virtual srs_error_t on_udp_packet(sockaddr_in* from, char* buf, int nb_buf); private: - virtual int on_udp_bytes(std::string host, int port, char* buf, int nb_buf); + virtual srs_error_t on_udp_bytes(std::string host, int port, char* buf, int nb_buf); // interface ISrsTsHandler public: virtual srs_error_t on_ts_message(SrsTsMessage* msg); private: - virtual int on_ts_video(SrsTsMessage* msg, SrsBuffer* avs); - virtual int write_h264_sps_pps(uint32_t dts, uint32_t pts); - virtual int write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts, uint32_t pts); - virtual int on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs); - virtual int write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts); + virtual srs_error_t on_ts_video(SrsTsMessage* msg, SrsBuffer* avs); + virtual srs_error_t write_h264_sps_pps(uint32_t dts, uint32_t pts); + virtual srs_error_t write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts, uint32_t pts); + virtual srs_error_t on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs); + virtual srs_error_t write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts); private: - virtual int rtmp_write_packet(char type, uint32_t timestamp, char* data, int size); + virtual srs_error_t rtmp_write_packet(char type, uint32_t timestamp, char* data, int size); private: // Connect to RTMP server. - virtual int connect(); + virtual srs_error_t connect(); // Close the connection to RTMP server. virtual void close(); }; diff --git a/trunk/src/app/srs_app_ng_exec.hpp b/trunk/src/app/srs_app_ng_exec.hpp index 23893cc091..efa1da9f92 100644 --- a/trunk/src/app/srs_app_ng_exec.hpp +++ b/trunk/src/app/srs_app_ng_exec.hpp @@ -51,7 +51,7 @@ class SrsNgExec : public ISrsCoroutineHandler SrsNgExec(); virtual ~SrsNgExec(); public: - virtual int on_publish(SrsRequest* req); + virtual srs_error_t on_publish(SrsRequest* req); virtual void on_unpublish(); // interface ISrsReusableThreadHandler. public: @@ -59,7 +59,7 @@ class SrsNgExec : public ISrsCoroutineHandler private: virtual srs_error_t do_cycle(); private: - virtual int parse_exec_publish(SrsRequest* req); + virtual srs_error_t parse_exec_publish(SrsRequest* req); virtual void clear_exec_publish(); virtual void show_exec_log_message(); virtual std::string parse(SrsRequest* req, std::string tmpl); diff --git a/trunk/src/app/srs_app_process.hpp b/trunk/src/app/srs_app_process.hpp index bbe18b91c6..2f2f0d2f1d 100644 --- a/trunk/src/app/srs_app_process.hpp +++ b/trunk/src/app/srs_app_process.hpp @@ -77,17 +77,17 @@ class SrsProcess * @param argv the argv for binary path, the argv[0] generally is the binary. * @remark the argv[0] must be the binary. */ - virtual int initialize(std::string binary, std::vector argv); + virtual srs_error_t initialize(std::string binary, std::vector argv); public: /** * start the process, ignore when already started. */ - virtual int start(); + virtual srs_error_t start(); /** * cycle check the process, update the state of process. * @remark when process terminated(not started), user can restart it again by start(). */ - virtual int cycle(); + virtual srs_error_t cycle(); /** * send SIGTERM then SIGKILL to ensure the process stopped. * the stop will wait [0, SRS_PROCESS_QUIT_TIMEOUT_MS] depends on the diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 3592be47a9..d2146a8c9b 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -125,7 +125,6 @@ srs_error_t SrsRecvThread::cycle() srs_error_t SrsRecvThread::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; while (true) { @@ -142,24 +141,19 @@ srs_error_t SrsRecvThread::do_cycle() SrsCommonMessage* msg = NULL; // Process the received message. - if ((ret = rtmp->recv_message(&msg)) == ERROR_SUCCESS) { - ret = pumper->consume(msg); + if ((err = rtmp->recv_message(&msg)) == srs_success) { + err = pumper->consume(msg); } - if (ret != ERROR_SUCCESS) { - if (!srs_is_client_gracefully_close(ret) && !srs_is_system_control_error(ret)) { - srs_error("recv thread error. ret=%d", ret); - } - + if (err != srs_success) { // Interrupt the receive thread for any error. trd->interrupt(); // Notify the pumper to quit for error. - pumper->interrupt(ret); + pumper->interrupt(err); - return srs_error_new(ret, "recv thread"); + return srs_error_wrap(err, "recv thread"); } - srs_verbose("thread loop recv message. ret=%d", ret); } return err; @@ -170,7 +164,7 @@ SrsQueueRecvThread::SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtm { _consumer = consumer; rtmp = rtmp_sdk; - recv_error_code = ERROR_SUCCESS; + recv_error = srs_success; } SrsQueueRecvThread::~SrsQueueRecvThread() @@ -184,6 +178,8 @@ SrsQueueRecvThread::~SrsQueueRecvThread() srs_freep(msg); } queue.clear(); + + srs_freep(recv_error); } srs_error_t SrsQueueRecvThread::start() @@ -223,12 +219,12 @@ SrsCommonMessage* SrsQueueRecvThread::pump() return msg; } -int SrsQueueRecvThread::error_code() +srs_error_t SrsQueueRecvThread::error_code() { - return recv_error_code; + return srs_error_copy(recv_error); } -int SrsQueueRecvThread::consume(SrsCommonMessage* msg) +srs_error_t SrsQueueRecvThread::consume(SrsCommonMessage* msg) { // put into queue, the send thread will get and process it, // @see SrsRtmpConn::process_play_control_msg @@ -238,7 +234,7 @@ int SrsQueueRecvThread::consume(SrsCommonMessage* msg) _consumer->wakeup(); } #endif - return ERROR_SUCCESS; + return srs_success; } bool SrsQueueRecvThread::interrupted() @@ -250,9 +246,10 @@ bool SrsQueueRecvThread::interrupted() return !empty(); } -void SrsQueueRecvThread::interrupt(int ret) +void SrsQueueRecvThread::interrupt(srs_error_t err) { - recv_error_code = ret; + srs_freep(recv_error); + recv_error = srs_error_copy(err); #ifdef SRS_PERF_QUEUE_COND_WAIT if (_consumer) { @@ -283,7 +280,7 @@ SrsPublishRecvThread::SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, SrsRequest* _conn = conn; _source = source; - recv_error_code = ERROR_SUCCESS; + recv_error = srs_success; _nb_msgs = 0; video_frames = 0; error = srs_cond_new(); @@ -308,18 +305,19 @@ SrsPublishRecvThread::~SrsPublishRecvThread() trd.stop(); srs_cond_destroy(error); + srs_freep(recv_error); } -int SrsPublishRecvThread::wait(uint64_t timeout_ms) +srs_error_t SrsPublishRecvThread::wait(uint64_t timeout_ms) { - if (recv_error_code != ERROR_SUCCESS) { - return recv_error_code; + if (recv_error != srs_success) { + return srs_error_copy(recv_error); } // ignore any return of cond wait. srs_cond_timedwait(error, timeout_ms * 1000); - return ERROR_SUCCESS; + return srs_success; } int64_t SrsPublishRecvThread::nb_msgs() @@ -332,9 +330,9 @@ uint64_t SrsPublishRecvThread::nb_video_frames() return video_frames; } -int SrsPublishRecvThread::error_code() +srs_error_t SrsPublishRecvThread::error_code() { - return recv_error_code; + return srs_error_copy(recv_error); } void SrsPublishRecvThread::set_cid(int v) @@ -365,9 +363,8 @@ void SrsPublishRecvThread::stop() trd.stop(); } -int SrsPublishRecvThread::consume(SrsCommonMessage* msg) +srs_error_t SrsPublishRecvThread::consume(SrsCommonMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // when cid changed, change it. @@ -388,15 +385,16 @@ int SrsPublishRecvThread::consume(SrsCommonMessage* msg) // the rtmp connection will handle this message err = _conn->handle_publish_message(_source, msg); - // TODO: FIXME: Use error - ret = srs_error_code(err); - srs_freep(err); // must always free it, // the source will copy it if need to use. srs_freep(msg); - return ret; + if (err != srs_success) { + return srs_error_wrap(err, "handle publish message"); + } + + return err; } bool SrsPublishRecvThread::interrupted() @@ -405,9 +403,10 @@ bool SrsPublishRecvThread::interrupted() return false; } -void SrsPublishRecvThread::interrupt(int ret) +void SrsPublishRecvThread::interrupt(srs_error_t err) { - recv_error_code = ret; + srs_freep(recv_error); + recv_error = srs_error_copy(err); // when recv thread error, signal the conn thread to process it. // @see https://github.com/ossrs/srs/issues/244 diff --git a/trunk/src/app/srs_app_recv_thread.hpp b/trunk/src/app/srs_app_recv_thread.hpp index 9c1e198ab2..720ca71de9 100644 --- a/trunk/src/app/srs_app_recv_thread.hpp +++ b/trunk/src/app/srs_app_recv_thread.hpp @@ -55,7 +55,7 @@ class ISrsMessageConsumer * Consume the received message. * @remark user must free this message. */ - virtual int consume(SrsCommonMessage* msg) = 0; + virtual srs_error_t consume(SrsCommonMessage* msg) = 0; }; /** @@ -76,7 +76,7 @@ class ISrsMessagePumper : public ISrsMessageConsumer /** * Interrupt the pumper for a error. */ - virtual void interrupt(int error) = 0; + virtual void interrupt(srs_error_t error) = 0; /** * When start the pumper. */ @@ -129,7 +129,7 @@ class SrsQueueRecvThread : public ISrsMessagePumper SrsRecvThread trd; SrsRtmpServer* rtmp; // the recv thread error code. - int recv_error_code; + srs_error_t recv_error; SrsConsumer* _consumer; public: SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtmp_sdk, int timeout_ms); @@ -141,12 +141,12 @@ class SrsQueueRecvThread : public ISrsMessagePumper virtual bool empty(); virtual int size(); virtual SrsCommonMessage* pump(); - virtual int error_code(); + virtual srs_error_t error_code(); // interface ISrsMessagePumper public: - virtual int consume(SrsCommonMessage* msg); + virtual srs_error_t consume(SrsCommonMessage* msg); virtual bool interrupted(); - virtual void interrupt(int ret); + virtual void interrupt(srs_error_t err); virtual void on_start(); virtual void on_stop(); }; @@ -177,7 +177,7 @@ class SrsPublishRecvThread : virtual public ISrsMessagePumper, virtual public IS // @see https://github.com/ossrs/srs/issues/257 bool realtime; // the recv thread error code. - int recv_error_code; + srs_error_t recv_error; SrsRtmpConn* _conn; // the params for conn callback. SrsSource* _source; @@ -194,10 +194,10 @@ class SrsPublishRecvThread : virtual public ISrsMessagePumper, virtual public IS /** * wait for error for some timeout. */ - virtual int wait(uint64_t timeout_ms); + virtual srs_error_t wait(uint64_t timeout_ms); virtual int64_t nb_msgs(); virtual uint64_t nb_video_frames(); - virtual int error_code(); + virtual srs_error_t error_code(); virtual void set_cid(int v); virtual int get_cid(); public: @@ -205,9 +205,9 @@ class SrsPublishRecvThread : virtual public ISrsMessagePumper, virtual public IS virtual void stop(); // interface ISrsMessagePumper public: - virtual int consume(SrsCommonMessage* msg); + virtual srs_error_t consume(SrsCommonMessage* msg); virtual bool interrupted(); - virtual void interrupt(int ret); + virtual void interrupt(srs_error_t err); virtual void on_start(); virtual void on_stop(); // interface IMergeReadHandler diff --git a/trunk/src/app/srs_app_refer.cpp b/trunk/src/app/srs_app_refer.cpp index 2cb7350c65..84ee5c7d42 100644 --- a/trunk/src/app/srs_app_refer.cpp +++ b/trunk/src/app/srs_app_refer.cpp @@ -35,32 +35,28 @@ SrsRefer::~SrsRefer() { } -int SrsRefer::check(std::string page_url, SrsConfDirective* refer) +srs_error_t SrsRefer::check(std::string page_url, SrsConfDirective* refer) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (!refer) { - srs_verbose("ignore refer check for page_url=%s", page_url.c_str()); - return ret; + return err; } for (int i = 0; i < (int)refer->args.size(); i++) { - if ((ret = check_single_refer(page_url, refer->args.at(i))) == ERROR_SUCCESS) { - srs_verbose("check refer success. page_url=%s, refer=%s", - page_url.c_str(), refer->args.at(i).c_str()); - return ret; + if ((err = check_single_refer(page_url, refer->args.at(i))) == srs_success) { + return srs_success; } + + srs_error_reset(err); } - ret = ERROR_RTMP_ACCESS_DENIED; - srs_error("check refer failed. ret=%d", ret); - - return ret; + return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied"); } -int SrsRefer::check_single_refer(std::string page_url, std::string refer) +srs_error_t SrsRefer::check_single_refer(std::string page_url, std::string refer) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; size_t pos = std::string::npos; @@ -79,19 +75,14 @@ int SrsRefer::check_single_refer(std::string page_url, std::string refer) pos = domain_name.find(refer); if (pos == std::string::npos) { - ret = ERROR_RTMP_ACCESS_DENIED; + return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied"); } // match primary domain. if (pos != domain_name.length() - refer.length()) { - ret = ERROR_RTMP_ACCESS_DENIED; - } - - if (ret != ERROR_SUCCESS) { - srs_verbose("access denied, page_url=%s, domain_name=%s, refer=%s, ret=%d", - page_url.c_str(), domain_name.c_str(), refer.c_str(), ret); + return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied"); } - return ret; + return err; } diff --git a/trunk/src/app/srs_app_refer.hpp b/trunk/src/app/srs_app_refer.hpp index d6ec02d21c..468a1ded64 100644 --- a/trunk/src/app/srs_app_refer.hpp +++ b/trunk/src/app/srs_app_refer.hpp @@ -41,9 +41,9 @@ class SrsRefer * @param page_url the client page url. * @param refer the refer in config. */ - virtual int check(std::string page_url, SrsConfDirective* refer); + virtual srs_error_t check(std::string page_url, SrsConfDirective* refer); private: - virtual int check_single_refer(std::string page_url, std::string refer); + virtual srs_error_t check_single_refer(std::string page_url, std::string refer); }; #endif diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index e66a4ee6f3..98b1ecda67 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -85,7 +85,7 @@ SrsSimpleRtmpClient::~SrsSimpleRtmpClient() { } -int SrsSimpleRtmpClient::connect_app() +srs_error_t SrsSimpleRtmpClient::connect_app() { std::vector ips = srs_get_local_ipv4_ips(); assert(_srs_config->get_stats_network() < (int)ips.size()); @@ -159,7 +159,6 @@ void SrsRtmpConn::dispose() // TODO: return detail message when error for client. srs_error_t SrsRtmpConn::do_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; srs_trace("RTMP client ip=%s, fd=%d", ip.c_str(), srs_netfd_fileno(stfd)); @@ -174,13 +173,13 @@ srs_error_t SrsRtmpConn::do_cycle() rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TMMS); rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS); - if ((ret = rtmp->handshake()) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp handshake"); + if ((err = rtmp->handshake()) != srs_success) { + return srs_error_wrap(err, "rtmp handshake"); } SrsRequest* req = info->req; - if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp connect tcUrl"); + if ((err = rtmp->connect_app(req)) != srs_success) { + return srs_error_wrap(err, "rtmp connect tcUrl"); } // set client ip to request. @@ -192,9 +191,6 @@ srs_error_t SrsRtmpConn::do_cycle() req->vhost = parsed_vhost->arg0(); } - srs_info("discovery app success. schema=%s, vhost=%s, port=%d, app=%s", - req->schema.c_str(), req->vhost.c_str(), req->port, req->app.c_str()); - if (req->schema.empty() || req->vhost.empty() || req->port == 0 || req->app.empty()) { return srs_error_new(ERROR_RTMP_REQ_TCURL, "discovery tcUrl failed, tcUrl=%s, schema=%s, vhost=%s, port=%d, app=%s", req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port, req->app.c_str()); @@ -231,8 +227,6 @@ srs_error_t SrsRtmpConn::do_cycle() srs_id = (int)prop->to_number(); } - srs_info("edge-srs ip=%s, version=%s, pid=%d, id=%d", - srs_server_ip.c_str(), srs_version.c_str(), srs_pid, srs_id); if (srs_pid > 0) { srs_trace("edge-srs ip=%s, version=%s, pid=%d, id=%d", srs_server_ip.c_str(), srs_version.c_str(), srs_pid, srs_id); @@ -377,23 +371,22 @@ void SrsRtmpConn::cleanup() srs_error_t SrsRtmpConn::service_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsRequest* req = info->req; int out_ack_size = _srs_config->get_out_ack_size(req->vhost); - if (out_ack_size && (ret = rtmp->set_window_ack_size(out_ack_size)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: set out window ack size"); + if (out_ack_size && (err = rtmp->set_window_ack_size(out_ack_size)) != srs_success) { + return srs_error_wrap(err, "rtmp: set out window ack size"); } int in_ack_size = _srs_config->get_in_ack_size(req->vhost); - if (in_ack_size && (ret = rtmp->set_in_window_ack_size(in_ack_size)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: set in window ack size"); + if (in_ack_size && (err = rtmp->set_in_window_ack_size(in_ack_size)) != srs_success) { + return srs_error_wrap(err, "rtmp: set in window ack size"); } - if ((ret = rtmp->set_peer_bandwidth((int)(2.5 * 1000 * 1000), 2)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: set peer bandwidth"); + if ((err = rtmp->set_peer_bandwidth((int)(2.5 * 1000 * 1000), 2)) != srs_success) { + return srs_error_wrap(err, "rtmp: set peer bandwidth"); } // get the ip which client connected. @@ -401,8 +394,8 @@ srs_error_t SrsRtmpConn::service_cycle() // do bandwidth test if connect to the vhost which is for bandwidth check. if (_srs_config->get_bw_check_enabled(req->vhost)) { - if ((ret = bandwidth->bandwidth_check(rtmp, skt, req, local_ip)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: bandwidth check"); + if ((err = bandwidth->bandwidth_check(rtmp, skt, req, local_ip)) != srs_success) { + return srs_error_wrap(err, "rtmp: bandwidth check"); } return err; } @@ -423,17 +416,17 @@ srs_error_t SrsRtmpConn::service_cycle() // set the chunk size before any larger response greater than 128, // to make OBS happy, @see https://github.com/ossrs/srs/issues/454 int chunk_size = _srs_config->get_chunk_size(req->vhost); - if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: set chunk size %d", chunk_size); + if ((err = rtmp->set_chunk_size(chunk_size)) != srs_success) { + return srs_error_wrap(err, "rtmp: set chunk size %d", chunk_size); } // response the client connect ok. - if ((ret = rtmp->response_connect_app(req, local_ip.c_str())) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: response connect app"); + if ((err = rtmp->response_connect_app(req, local_ip.c_str())) != srs_success) { + return srs_error_wrap(err, "rtmp: response connect app"); } - if ((ret = rtmp->on_bw_done()) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: on bw down"); + if ((err = rtmp->on_bw_done()) != srs_success) { + return srs_error_wrap(err, "rtmp: on bw down"); } while (true) { @@ -490,21 +483,20 @@ srs_error_t SrsRtmpConn::service_cycle() srs_error_t SrsRtmpConn::stream_service_cycle() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsRequest* req = info->req; - if ((ret = rtmp->identify_client(info->res->stream_id, info->type, req->stream, req->duration)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: identify client"); + if ((err = rtmp->identify_client(info->res->stream_id, info->type, req->stream, req->duration)) != srs_success) { + return srs_error_wrap(err, "rtmp: identify client"); } req->strip(); srs_trace("client identified, type=%s, stream_name=%s, duration=%.2f", srs_client_type_string(info->type).c_str(), req->stream.c_str(), req->duration); // security check - if ((ret = security->check(info->type, ip, req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: security check"); + if ((err = security->check(info->type, ip, req)) != srs_success) { + return srs_error_wrap(err, "rtmp: security check"); } // Never allow the empty stream name, for HLS may write to a file with empty name. @@ -526,8 +518,8 @@ srs_error_t SrsRtmpConn::stream_service_cycle() // update the statistic when source disconveried. SrsStatistic* stat = SrsStatistic::instance(); - if ((ret = stat->on_client(_srs_context->get_id(), req, this, info->type)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: stat client"); + if ((err = stat->on_client(_srs_context->get_id(), req, this, info->type)) != srs_success) { + return srs_error_wrap(err, "rtmp: stat client"); } bool enabled_cache = _srs_config->get_gop_cache(req->vhost); @@ -538,8 +530,8 @@ srs_error_t SrsRtmpConn::stream_service_cycle() switch (info->type) { case SrsRtmpConnPlay: { // response connection start play - if ((ret = rtmp->start_play(info->res->stream_id)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: start play"); + if ((err = rtmp->start_play(info->res->stream_id)) != srs_success) { + return srs_error_wrap(err, "rtmp: start play"); } if ((err = http_hooks_on_play()) != srs_success) { return srs_error_wrap(err, "rtmp: callback on play"); @@ -551,22 +543,22 @@ srs_error_t SrsRtmpConn::stream_service_cycle() return err; } case SrsRtmpConnFMLEPublish: { - if ((ret = rtmp->start_fmle_publish(info->res->stream_id)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: start FMLE publish"); + if ((err = rtmp->start_fmle_publish(info->res->stream_id)) != srs_success) { + return srs_error_wrap(err, "rtmp: start FMLE publish"); } return publishing(source); } case SrsRtmpConnHaivisionPublish: { - if ((ret = rtmp->start_haivision_publish(info->res->stream_id)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: start HAIVISION publish"); + if ((err = rtmp->start_haivision_publish(info->res->stream_id)) != srs_success) { + return srs_error_wrap(err, "rtmp: start HAIVISION publish"); } return publishing(source); } case SrsRtmpConnFlashPublish: { - if ((ret = rtmp->start_flash_publish(info->res->stream_id)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: start FLASH publish"); + if ((err = rtmp->start_flash_publish(info->res->stream_id)) != srs_success) { + return srs_error_wrap(err, "rtmp: start FLASH publish"); } return publishing(source); @@ -581,7 +573,6 @@ srs_error_t SrsRtmpConn::stream_service_cycle() srs_error_t SrsRtmpConn::check_vhost(bool try_default_vhost) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsRequest* req = info->req; @@ -602,8 +593,8 @@ srs_error_t SrsRtmpConn::check_vhost(bool try_default_vhost) } if (_srs_config->get_refer_enabled(req->vhost)) { - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_all(req->vhost))) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: referer check"); + if ((err = refer->check(req->pageUrl, _srs_config->get_refer_all(req->vhost))) != srs_success) { + return srs_error_wrap(err, "rtmp: referer check"); } } @@ -652,15 +643,14 @@ srs_error_t SrsRtmpConn::playing(SrsSource* source) srs_error_t SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRecvThread* rtrd) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; srs_assert(consumer != NULL); SrsRequest* req = info->req; if (_srs_config->get_refer_enabled(req->vhost)) { - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: referer check"); + if ((err = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != srs_success) { + return srs_error_wrap(err, "rtmp: referer check"); } } @@ -707,8 +697,8 @@ srs_error_t SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, Sr } // quit when recv thread error. - if ((ret = rtrd->error_code()) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: recv thread"); + if ((err = rtrd->error_code()) != srs_success) { + return srs_error_wrap(err, "rtmp: recv thread"); } #ifdef SRS_PERF_QUEUE_COND_WAIT @@ -766,8 +756,8 @@ srs_error_t SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, Sr // sendout messages, all messages are freed by send_and_free_messages(). // no need to assert msg, for the rtmp will assert it. - if (count > 0 && (ret = rtmp->send_and_free_messages(msgs.msgs, count, info->res->stream_id)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: send %d messages", count); + if (count > 0 && (err = rtmp->send_and_free_messages(msgs.msgs, count, info->res->stream_id)) != srs_success) { + return srs_error_wrap(err, "rtmp: send %d messages", count); } // if duration specified, and exceed it, stop play live. @@ -789,14 +779,13 @@ srs_error_t SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, Sr srs_error_t SrsRtmpConn::publishing(SrsSource* source) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsRequest* req = info->req; if (_srs_config->get_refer_enabled(req->vhost)) { - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: referer check"); + if ((err = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != srs_success) { + return srs_error_wrap(err, "rtmp: referer check"); } } @@ -828,7 +817,6 @@ srs_error_t SrsRtmpConn::publishing(SrsSource* source) srs_error_t SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* rtrd) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsRequest* req = info->req; @@ -878,8 +866,8 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* } // check the thread error code. - if ((ret = rtrd->error_code()) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: receive thread"); + if ((err = rtrd->error_code()) != srs_success) { + return srs_error_wrap(err, "rtmp: receive thread"); } // when not got any messages, timeout. @@ -892,8 +880,8 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* // Update the stat for video fps. // @remark https://github.com/ossrs/srs/issues/851 SrsStatistic* stat = SrsStatistic::instance(); - if ((ret = stat->on_video_frames(req, (int)(rtrd->nb_video_frames() - nb_frames))) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: stat video frames"); + if ((err = stat->on_video_frames(req, (int)(rtrd->nb_video_frames() - nb_frames))) != srs_success) { + return srs_error_wrap(err, "rtmp: stat video frames"); } nb_frames = rtrd->nb_video_frames(); @@ -948,14 +936,13 @@ void SrsRtmpConn::release_publish(SrsSource* source) srs_error_t SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // process publish event. if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) { SrsPacket* pkt = NULL; - if ((ret = rtmp->decode_message(msg, &pkt)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: decode message"); + if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) { + return srs_error_wrap(err, "rtmp: decode message"); } SrsAutoFree(SrsPacket, pkt); @@ -970,8 +957,8 @@ srs_error_t SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMess // for fmle, drop others except the fmle start packet. if (dynamic_cast(pkt)) { SrsFMLEStartPacket* unpublish = dynamic_cast(pkt); - if ((ret = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: republish"); + if ((err = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != srs_success) { + return srs_error_wrap(err, "rtmp: republish"); } return srs_error_new(ERROR_CONTROL_REPUBLISH, "rtmp: republish"); } @@ -990,7 +977,6 @@ srs_error_t SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMess srs_error_t SrsRtmpConn::process_publish_message(SrsSource* source, SrsCommonMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // for edge, directly proxy message to origin. @@ -1027,8 +1013,8 @@ srs_error_t SrsRtmpConn::process_publish_message(SrsSource* source, SrsCommonMes // process onMetaData if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) { SrsPacket* pkt = NULL; - if ((ret = rtmp->decode_message(msg, &pkt)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: decode message"); + if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) { + return srs_error_wrap(err, "rtmp: decode message"); } SrsAutoFree(SrsPacket, pkt); @@ -1047,7 +1033,6 @@ srs_error_t SrsRtmpConn::process_publish_message(SrsSource* source, SrsCommonMes srs_error_t SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; if (!msg) { @@ -1060,8 +1045,8 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsComm } SrsPacket* pkt = NULL; - if ((ret = rtmp->decode_message(msg, &pkt)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: decode message"); + if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) { + return srs_error_wrap(err, "rtmp: decode message"); } SrsAutoFree(SrsPacket, pkt); @@ -1084,8 +1069,8 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsComm SrsCallResPacket* res = new SrsCallResPacket(call->transaction_id); res->command_object = SrsAmf0Any::null(); res->response = SrsAmf0Any::null(); - if ((ret = rtmp->send_and_free_packet(res, 0)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: send packets"); + if ((err = rtmp->send_and_free_packet(res, 0)) != srs_success) { + return srs_error_wrap(err, "rtmp: send packets"); } } return err; @@ -1094,8 +1079,8 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsComm // pause SrsPausePacket* pause = dynamic_cast(pkt); if (pause) { - if ((ret = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: pause"); + if ((err = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != srs_success) { + return srs_error_wrap(err, "rtmp: pause"); } if ((err = consumer->on_play_client_pause(pause->is_pause)) != srs_success) { return srs_error_wrap(err, "rtmp: pause"); @@ -1226,7 +1211,6 @@ srs_error_t SrsRtmpConn::check_edge_token_traverse_auth() srs_error_t SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsRequest* req = info->req; @@ -1235,13 +1219,13 @@ srs_error_t SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client) client->set_recv_timeout(SRS_CONSTS_RTMP_TMMS); client->set_send_timeout(SRS_CONSTS_RTMP_TMMS); - if ((ret = client->handshake()) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: handshake"); + if ((err = client->handshake()) != srs_success) { + return srs_error_wrap(err, "rtmp: handshake"); } // for token tranverse, always take the debug info(which carries token). - if ((ret = client->connect_app(req->app, req->tcUrl, req, true, NULL)) != ERROR_SUCCESS) { - return srs_error_new(ret, "rtmp: connect tcUrl"); + if ((err = client->connect_app(req->app, req->tcUrl, req, true, NULL)) != srs_success) { + return srs_error_wrap(err, "rtmp: connect tcUrl"); } srs_trace("edge token auth ok, tcUrl=%s", req->tcUrl.c_str()); @@ -1284,7 +1268,6 @@ srs_error_t SrsRtmpConn::http_hooks_on_connect() SrsConfDirective* conf = _srs_config->get_vhost_on_connect(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_connect"); return err; } @@ -1318,7 +1301,6 @@ void SrsRtmpConn::http_hooks_on_close() SrsConfDirective* conf = _srs_config->get_vhost_on_close(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_close"); return; } @@ -1350,7 +1332,6 @@ srs_error_t SrsRtmpConn::http_hooks_on_publish() SrsConfDirective* conf = _srs_config->get_vhost_on_publish(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_publish"); return err; } @@ -1384,7 +1365,6 @@ void SrsRtmpConn::http_hooks_on_unpublish() SrsConfDirective* conf = _srs_config->get_vhost_on_unpublish(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_unpublish"); return; } @@ -1416,7 +1396,6 @@ srs_error_t SrsRtmpConn::http_hooks_on_play() SrsConfDirective* conf = _srs_config->get_vhost_on_play(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_play"); return err; } @@ -1450,7 +1429,6 @@ void SrsRtmpConn::http_hooks_on_stop() SrsConfDirective* conf = _srs_config->get_vhost_on_stop(req->vhost); if (!conf) { - srs_info("ignore the empty http callback: on_stop"); return; } diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index 686448a05b..c4b0df63e8 100644 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -67,7 +67,7 @@ class SrsSimpleRtmpClient : public SrsBasicRtmpClient SrsSimpleRtmpClient(std::string u, int64_t ctm, int64_t stm); virtual ~SrsSimpleRtmpClient(); protected: - virtual int connect_app(); + virtual srs_error_t connect_app(); }; /** diff --git a/trunk/src/app/srs_app_rtsp.hpp b/trunk/src/app/srs_app_rtsp.hpp index 516df163ba..5c123dda3e 100644 --- a/trunk/src/app/srs_app_rtsp.hpp +++ b/trunk/src/app/srs_app_rtsp.hpp @@ -104,7 +104,7 @@ class SrsRtspJitter virtual ~SrsRtspJitter(); public: virtual int64_t timestamp(); - virtual int correct(int64_t& ts); + virtual srs_error_t correct(int64_t& ts); }; /** @@ -162,18 +162,18 @@ class SrsRtspConn : public ISrsCoroutineHandler public: virtual srs_error_t cycle(); private: - virtual int on_rtp_video(SrsRtpPacket* pkt, int64_t dts, int64_t pts); - virtual int on_rtp_audio(SrsRtpPacket* pkt, int64_t dts); - virtual int kickoff_audio_cache(SrsRtpPacket* pkt, int64_t dts); + virtual srs_error_t on_rtp_video(SrsRtpPacket* pkt, int64_t dts, int64_t pts); + virtual srs_error_t on_rtp_audio(SrsRtpPacket* pkt, int64_t dts); + virtual srs_error_t kickoff_audio_cache(SrsRtpPacket* pkt, int64_t dts); private: - virtual int write_sequence_header(); - virtual int write_h264_sps_pps(uint32_t dts, uint32_t pts); - virtual int write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts, uint32_t pts); - virtual int write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts); - virtual int rtmp_write_packet(char type, uint32_t timestamp, char* data, int size); + virtual srs_error_t write_sequence_header(); + virtual srs_error_t write_h264_sps_pps(uint32_t dts, uint32_t pts); + virtual srs_error_t write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts, uint32_t pts); + virtual srs_error_t write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts); + virtual srs_error_t rtmp_write_packet(char type, uint32_t timestamp, char* data, int size); private: // Connect to RTMP server. - virtual int connect(); + virtual srs_error_t connect(); // Close the connection to RTMP server. virtual void close(); }; @@ -199,7 +199,7 @@ class SrsRtspCaster : public ISrsTcpHandler * alloc a rtp port from local ports pool. * @param pport output the rtp port. */ - virtual int alloc_port(int* pport); + virtual srs_error_t alloc_port(int* pport); /** * free the alloced rtp port. */ diff --git a/trunk/src/app/srs_app_security.hpp b/trunk/src/app/srs_app_security.hpp index b6beff7492..249f87e421 100644 --- a/trunk/src/app/srs_app_security.hpp +++ b/trunk/src/app/srs_app_security.hpp @@ -48,18 +48,18 @@ class SrsSecurity * @param ip the ip address of client. * @param req the request object of client. */ - virtual int check(SrsRtmpConnType type, std::string ip, SrsRequest* req); + virtual srs_error_t check(SrsRtmpConnType type, std::string ip, SrsRequest* req); private: /** * security check the allow, * @return, if allowed, ERROR_SYSTEM_SECURITY_ALLOW. */ - virtual int allow_check(SrsConfDirective* rules, SrsRtmpConnType type, std::string ip); + virtual srs_error_t allow_check(SrsConfDirective* rules, SrsRtmpConnType type, std::string ip); /** * security check the deny, * @return, if denied, ERROR_SYSTEM_SECURITY_DENY. */ - virtual int deny_check(SrsConfDirective* rules, SrsRtmpConnType type, std::string ip); + virtual srs_error_t deny_check(SrsConfDirective* rules, SrsRtmpConnType type, std::string ip); }; #endif diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index a5716573b1..6416dd7511 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -1391,11 +1391,10 @@ srs_error_t SrsServer::on_reload_http_stream_updated() srs_error_t SrsServer::on_publish(SrsSource* s, SrsRequest* r) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; - if ((ret = http_server->http_mount(s, r)) != ERROR_SUCCESS) { - return srs_error_new(ret, "http mount"); + if ((err = http_server->http_mount(s, r)) != srs_success) { + return srs_error_wrap(err, "http mount"); } return err; diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index b9d97c61f6..022b62cb92 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -295,7 +295,7 @@ class SrsServer : virtual public ISrsReloadHandler * to stop all ingesters, cleanup HLS and dvr. */ virtual void dispose(); - // server startup workflow, @see run_master() +// server startup workflow, @see run_master() public: /** * initialize server with callback handler ch. @@ -310,7 +310,7 @@ class SrsServer : virtual public ISrsReloadHandler virtual srs_error_t http_handle(); virtual srs_error_t ingest(); virtual srs_error_t cycle(); - // server utilities. +// server utilities. public: /** * callback for signal manager got a signal. diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 0458df59a7..268af754eb 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -135,12 +135,6 @@ srs_error_t SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, SrsRtmpJitterAlgori // use default 10ms to notice the problem of stream. // @see https://github.com/ossrs/srs/issues/425 delta = DEFAULT_FRAME_TIME_MS; - - srs_info("jitter detected, last_pts=%" PRId64 ", pts=%" PRId64 ", diff=%" PRId64 ", last_time=%" PRId64 ", time=%" PRId64 ", diff=%" PRId64 "", - last_pkt_time, time, time - last_pkt_time, last_pkt_correct_time, last_pkt_correct_time + delta, delta); - } else { - srs_verbose("timestamp no jitter. time=%" PRId64 ", last_pkt=%" PRId64 ", correct_to=%" PRId64 "", - time, last_pkt_time, last_pkt_correct_time + delta); } last_pkt_correct_time = srs_max(0, last_pkt_correct_time + delta); @@ -389,10 +383,7 @@ void SrsMessageQueue::shrink() msgs.push_back(audio_sh); } - if (_ignore_shrink) { - srs_info("shrink the cache queue, size=%d, removed=%d, max=%.2f", - (int)msgs.size(), msgs_size - (int)msgs.size(), queue_size_ms / 1000.0); - } else { + if (!_ignore_shrink) { srs_trace("shrink the cache queue, size=%d, removed=%d, max=%.2f", (int)msgs.size(), msgs_size - (int)msgs.size(), queue_size_ms / 1000.0); } @@ -484,9 +475,6 @@ srs_error_t SrsConsumer::enqueue(SrsSharedPtrMessage* shared_msg, bool atc, SrsR } #ifdef SRS_PERF_QUEUE_COND_WAIT - srs_verbose("enqueue msg, time=%" PRId64 ", size=%d, duration=%d, waiting=%d, min_msg=%d", - msg->timestamp, msg->size, queue->duration(), mw_waiting, mw_min_msgs); - // fire the mw when msgs is enough. if (mw_waiting) { int duration_ms = queue->duration(); @@ -614,12 +602,9 @@ void SrsGopCache::set(bool v) enable_gop_cache = v; if (!v) { - srs_info("disable gop cache, clear %d packets.", (int)gop_cache.size()); clear(); return; } - - srs_info("enable gop cache"); } bool SrsGopCache::enabled() @@ -951,7 +936,6 @@ srs_error_t SrsOriginHub::on_meta_data(SrsSharedPtrMessage* shared_metadata, Srs srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsSharedPtrMessage* msg = shared_audio; @@ -971,8 +955,8 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio) // when got audio stream info. SrsStatistic* stat = SrsStatistic::instance(); - if ((ret = stat->on_audio_info(req, SrsAudioCodecIdAAC, c->sound_rate, c->sound_type, c->aac_object)) != ERROR_SUCCESS) { - return srs_error_new(ret, "stat audio"); + if ((err = stat->on_audio_info(req, SrsAudioCodecIdAAC, c->sound_rate, c->sound_type, c->aac_object)) != srs_success) { + return srs_error_wrap(err, "stat audio"); } srs_trace("%dB audio sh, codec(%d, profile=%s, %dchannels, %dkbps, %dHZ), flv(%dbits, %dchannels, %dHZ)", @@ -1001,23 +985,23 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio) } } - if ((ret = dash->on_audio(msg, format)) != ERROR_SUCCESS) { - srs_warn("dash: ignore audio error ret=%d", ret); - dash->on_unpublish(); + if ((err = dash->on_audio(msg, format)) != srs_success) { + srs_warn("dash: ignore audio error %s", srs_error_desc(err).c_str()); srs_error_reset(err); + dash->on_unpublish(); } if ((err = dvr->on_audio(msg, format)) != srs_success) { srs_warn("dvr: ignore audio error %s", srs_error_desc(err).c_str()); - dvr->on_unpublish(); srs_error_reset(err); + dvr->on_unpublish(); } #ifdef SRS_AUTO_HDS - if ((ret = hds->on_audio(msg)) != ERROR_SUCCESS) { - srs_warn("hds: ignore audio error ret=%d", ret); - hds->on_unpublish(); + if ((err = hds->on_audio(msg)) != srs_success) { + srs_warn("hds: ignore audio error %s", srs_error_desc(err).c_str()); srs_error_reset(err); + hds->on_unpublish(); } #endif @@ -1037,7 +1021,6 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio) srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_sequence_header) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsSharedPtrMessage* msg = shared_video; @@ -1060,8 +1043,8 @@ srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_se // when got video stream info. SrsStatistic* stat = SrsStatistic::instance(); - if ((ret = stat->on_video_info(req, SrsVideoCodecIdAVC, c->avc_profile, c->avc_level, c->width, c->height)) != ERROR_SUCCESS) { - return srs_error_new(ret, "stat video"); + if ((err = stat->on_video_info(req, SrsVideoCodecIdAVC, c->avc_profile, c->avc_level, c->width, c->height)) != srs_success) { + return srs_error_wrap(err, "stat video"); } srs_trace("%dB video sh, codec(%d, profile=%s, level=%s, %dx%d, %dkbps, %.1ffps, %.1fs)", @@ -1079,7 +1062,7 @@ srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_se hls->on_unpublish(); srs_error_reset(err); } else if (srs_config_hls_is_on_error_continue(hls_error_strategy)) { - if (srs_hls_can_continue(ret, source->meta->vsh(), msg)) { + if (srs_hls_can_continue(srs_error_code(err), source->meta->vsh(), msg)) { srs_error_reset(err); } else { return srs_error_wrap(err, "hls: video"); @@ -1089,23 +1072,23 @@ srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_se } } - if ((ret = dash->on_video(msg, format)) != ERROR_SUCCESS) { - srs_warn("dash: ignore video error ret=%d", ret); - dash->on_unpublish(); + if ((err = dash->on_video(msg, format)) != srs_success) { + srs_warn("dash: ignore video error %s", srs_error_desc(err).c_str()); srs_error_reset(err); + dash->on_unpublish(); } if ((err = dvr->on_video(msg, format)) != srs_success) { srs_warn("dvr: ignore video error %s", srs_error_desc(err).c_str()); - dvr->on_unpublish(); srs_error_reset(err); + dvr->on_unpublish(); } #ifdef SRS_AUTO_HDS - if ((ret = hds->on_video(msg)) != ERROR_SUCCESS) { - srs_warn("hds: ignore video error ret=%d", ret); - hds->on_unpublish(); + if ((err = hds->on_video(msg)) != srs_success) { + srs_warn("hds: ignore video error %s", srs_error_desc(err).c_str()); srs_error_reset(err); + hds->on_unpublish(); } #endif @@ -1125,7 +1108,6 @@ srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_se srs_error_t SrsOriginHub::on_publish() { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // create forwarders @@ -1135,8 +1117,8 @@ srs_error_t SrsOriginHub::on_publish() // TODO: FIXME: use initialize to set req. #ifdef SRS_AUTO_TRANSCODE - if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "encoder publish"); + if ((err = encoder->on_publish(req)) != srs_success) { + return srs_error_wrap(err, "encoder publish"); } #endif @@ -1144,8 +1126,8 @@ srs_error_t SrsOriginHub::on_publish() return srs_error_wrap(err, "hls publish"); } - if ((ret = dash->on_publish()) != ERROR_SUCCESS) { - return srs_error_new(ret, "dash publish"); + if ((err = dash->on_publish()) != srs_success) { + return srs_error_wrap(err, "dash publish"); } if ((err = dvr->on_publish()) != srs_success) { @@ -1154,14 +1136,14 @@ srs_error_t SrsOriginHub::on_publish() // TODO: FIXME: use initialize to set req. #ifdef SRS_AUTO_HDS - if ((ret = hds->on_publish(req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "hds publish"); + if ((err = hds->on_publish(req)) != srs_success) { + return srs_error_wrap(err, "hds publish"); } #endif // TODO: FIXME: use initialize to set req. - if ((ret = ng_exec->on_publish(req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "exec publish"); + if ((err = ng_exec->on_publish(req)) != srs_success) { + return srs_error_wrap(err, "exec publish"); } is_active = true; @@ -1273,7 +1255,6 @@ srs_error_t SrsOriginHub::on_reload_vhost_forward(string vhost) srs_error_t SrsOriginHub::on_reload_vhost_dash(string vhost) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; if (req->vhost != vhost) { @@ -1287,8 +1268,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_dash(string vhost) return err; } - if ((ret = dash->on_publish()) != ERROR_SUCCESS) { - return srs_error_new(ret, "dash start publish"); + if ((err = dash->on_publish()) != srs_success) { + return srs_error_wrap(err, "dash start publish"); } SrsSharedPtrMessage* cache_sh_video = source->meta->vsh(); @@ -1296,8 +1277,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_dash(string vhost) if ((err = format->on_video(cache_sh_video)) != srs_success) { return srs_error_wrap(err, "format on_video"); } - if ((ret = dash->on_video(cache_sh_video, format)) != ERROR_SUCCESS) { - return srs_error_new(ret, "dash on_video"); + if ((err = dash->on_video(cache_sh_video, format)) != srs_success) { + return srs_error_wrap(err, "dash on_video"); } } @@ -1306,8 +1287,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_dash(string vhost) if ((err = format->on_audio(cache_sh_audio)) != srs_success) { return srs_error_wrap(err, "format on_audio"); } - if ((ret = dash->on_audio(cache_sh_audio, format)) != ERROR_SUCCESS) { - return srs_error_new(ret, "dash on_audio"); + if ((err = dash->on_audio(cache_sh_audio, format)) != srs_success) { + return srs_error_wrap(err, "dash on_audio"); } } @@ -1366,7 +1347,6 @@ srs_error_t SrsOriginHub::on_reload_vhost_hls(string vhost) srs_error_t SrsOriginHub::on_reload_vhost_hds(string vhost) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; if (req->vhost != vhost) { @@ -1383,8 +1363,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_hds(string vhost) return err; } - if ((ret = hds->on_publish(req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "hds publish failed"); + if ((err = hds->on_publish(req)) != srs_success) { + return srs_error_wrap(err, "hds publish failed"); } srs_trace("vhost %s hds reload success", vhost.c_str()); #endif @@ -1431,7 +1411,6 @@ srs_error_t SrsOriginHub::on_reload_vhost_dvr(string vhost) srs_error_t SrsOriginHub::on_reload_vhost_transcode(string vhost) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; if (req->vhost != vhost) { @@ -1448,8 +1427,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_transcode(string vhost) return err; } - if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "start encoder failed"); + if ((err = encoder->on_publish(req)) != srs_success) { + return srs_error_wrap(err, "start encoder failed"); } srs_trace("vhost %s transcode reload success", vhost.c_str()); #endif @@ -1459,7 +1438,6 @@ srs_error_t SrsOriginHub::on_reload_vhost_transcode(string vhost) srs_error_t SrsOriginHub::on_reload_vhost_exec(string vhost) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; if (req->vhost != vhost) { @@ -1475,8 +1453,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_exec(string vhost) return err; } - if ((ret = ng_exec->on_publish(req)) != ERROR_SUCCESS) { - return srs_error_new(ret, "start exec failed"); + if ((err = ng_exec->on_publish(req)) != srs_success) { + return srs_error_wrap(err, "start exec failed"); } srs_trace("vhost %s exec reload success", vhost.c_str()); @@ -1598,7 +1576,6 @@ srs_error_t SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPac { updated = false; - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; SrsAmf0Any* prop = NULL; @@ -1636,8 +1613,8 @@ srs_error_t SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPac // encode the metadata to payload int size = 0; char* payload = NULL; - if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) { - return srs_error_new(ret, "encode metadata"); + if ((err = metadata->encode(size, payload)) != srs_success) { + return srs_error_wrap(err, "encode metadata"); } if (size <= 0) { @@ -1652,8 +1629,8 @@ srs_error_t SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPac // dump message to shared ptr message. // the payload/size managed by cache_metadata, user should not free it. - if ((ret = meta->create(header, payload, size)) != ERROR_SUCCESS) { - return srs_error_new(ret, "create metadata"); + if ((err = meta->create(header, payload, size)) != srs_success) { + return srs_error_wrap(err, "create metadata"); } return err; @@ -1697,7 +1674,6 @@ srs_error_t SrsSource::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, SrsS } pool[stream_url] = source; - srs_info("create new source for url=%s, vhost=%s", stream_url.c_str(), vhost.c_str()); *pps = source; @@ -1807,7 +1783,6 @@ SrsSource::SrsSource() play_edge = new SrsPlayEdge(); publish_edge = new SrsPublishEdge(); gop_cache = new SrsGopCache(); - aggregate_stream = new SrsBuffer(); hub = new SrsOriginHub(); meta = new SrsMetaCache(); @@ -1833,7 +1808,6 @@ SrsSource::~SrsSource() srs_freep(play_edge); srs_freep(publish_edge); srs_freep(gop_cache); - srs_freep(aggregate_stream); srs_freep(req); } @@ -2087,7 +2061,6 @@ srs_error_t SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* srs_error_t SrsSource::on_audio(SrsCommonMessage* shared_audio) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // monotically increase detect. @@ -2102,8 +2075,8 @@ srs_error_t SrsSource::on_audio(SrsCommonMessage* shared_audio) // convert shared_audio to msg, user should not use shared_audio again. // the payload is transfer to msg, and set to NULL in shared_audio. SrsSharedPtrMessage msg; - if ((ret = msg.create(shared_audio)) != ERROR_SUCCESS) { - return srs_error_new(ret, "create message"); + if ((err = msg.create(shared_audio)) != srs_success) { + return srs_error_wrap(err, "create message"); } // directly process the audio message. @@ -2196,7 +2169,6 @@ srs_error_t SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) srs_error_t SrsSource::on_video(SrsCommonMessage* shared_video) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; // monotically increase detect. @@ -2223,8 +2195,8 @@ srs_error_t SrsSource::on_video(SrsCommonMessage* shared_video) // convert shared_video to msg, user should not use shared_video again. // the payload is transfer to msg, and set to NULL in shared_video. SrsSharedPtrMessage msg; - if ((ret = msg.create(shared_video)) != ERROR_SUCCESS) { - return srs_error_new(ret, "create message"); + if ((err = msg.create(shared_video)) != srs_success) { + return srs_error_wrap(err, "create message"); } // directly process the audio message. @@ -2313,13 +2285,10 @@ srs_error_t SrsSource::on_video_imp(SrsSharedPtrMessage* msg) srs_error_t SrsSource::on_aggregate(SrsCommonMessage* msg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; - SrsBuffer* stream = aggregate_stream; - if ((ret = stream->initialize(msg->payload, msg->size)) != ERROR_SUCCESS) { - return srs_error_new(ret, "init stream"); - } + SrsBuffer* stream = new SrsBuffer(msg->payload, msg->size); + SrsAutoFree(SrsBuffer, stream); // the aggregate message always use abs time. int delta = -1; @@ -2457,7 +2426,6 @@ void SrsSource::on_unpublish() // when drop dup sequence header, drop the metadata also. gop_cache->clear(); - srs_info("clear cache/metadata when unpublish."); srs_trace("cleanup when unpublish"); _can_publish = true; @@ -2477,7 +2445,6 @@ void SrsSource::on_unpublish() srs_error_t SrsSource::create_consumer(SrsConnection* conn, SrsConsumer*& consumer, bool ds, bool dm, bool dg) { - int ret = ERROR_SUCCESS; srs_error_t err = srs_success; consumer = new SrsConsumer(this, conn); @@ -2519,8 +2486,8 @@ srs_error_t SrsSource::create_consumer(SrsConnection* conn, SrsConsumer*& consum // for edge, when play edge stream, check the state if (_srs_config->get_vhost_is_edge(req->vhost)) { // notice edge to start for the first client. - if ((ret = play_edge->on_client_play()) != ERROR_SUCCESS) { - return srs_error_new(ret, "play edge"); + if ((err = play_edge->on_client_play()) != srs_success) { + return srs_error_wrap(err, "play edge"); } } @@ -2534,7 +2501,6 @@ void SrsSource::on_consumer_destroy(SrsConsumer* consumer) if (it != consumers.end()) { consumers.erase(it); } - srs_info("handle consumer destroy success."); if (consumers.empty()) { play_edge->on_all_client_stop(); diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 3f1c18d3aa..7f09c68d9d 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -594,8 +594,6 @@ class SrsSource : public ISrsReloadHandler bool is_monotonically_increase; // the time of the packet we just got. int64_t last_packet_time; - // for aggregate message - SrsBuffer* aggregate_stream; // the event handler. ISrsSourceHandler* handler; // edge control service diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 9a41ef0369..73c2df80e5 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -55,7 +55,7 @@ struct SrsStatisticVhost SrsStatisticVhost(); virtual ~SrsStatisticVhost(); public: - virtual int dumps(SrsJsonObject* obj); + virtual srs_error_t dumps(SrsJsonObject* obj); }; struct SrsStatisticStream @@ -101,7 +101,7 @@ struct SrsStatisticStream SrsStatisticStream(); virtual ~SrsStatisticStream(); public: - virtual int dumps(SrsJsonObject* obj); + virtual srs_error_t dumps(SrsJsonObject* obj); public: /** * publish the stream. @@ -126,7 +126,7 @@ struct SrsStatisticClient SrsStatisticClient(); virtual ~SrsStatisticClient(); public: - virtual int dumps(SrsJsonObject* obj); + virtual srs_error_t dumps(SrsJsonObject* obj); }; class SrsStatistic @@ -166,16 +166,18 @@ class SrsStatistic /** * when got video info for stream. */ - virtual int on_video_info(SrsRequest* req, SrsVideoCodecId vcodec, SrsAvcProfile avc_profile, SrsAvcLevel avc_level, int width, int height); + virtual srs_error_t on_video_info(SrsRequest* req, SrsVideoCodecId vcodec, SrsAvcProfile avc_profile, + SrsAvcLevel avc_level, int width, int height); /** * when got audio info for stream. */ - virtual int on_audio_info(SrsRequest* req, SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioChannels asound_type, SrsAacObjectType aac_object); + virtual srs_error_t on_audio_info(SrsRequest* req, SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, + SrsAudioChannels asound_type, SrsAacObjectType aac_object); /** * When got videos, update the frames. * We only stat the total number of video frames. */ - virtual int on_video_frames(SrsRequest* req, int nb_frames); + virtual srs_error_t on_video_frames(SrsRequest* req, int nb_frames); /** * when publish stream. * @param req the request object of publish connection. @@ -194,7 +196,7 @@ class SrsStatistic * @param conn, the physical absract connection object. * @param type, the type of connection. */ - virtual int on_client(int id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type); + virtual srs_error_t on_client(int id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type); /** * client disconnect * @remark the on_disconnect always call, while the on_client is call when @@ -222,17 +224,17 @@ class SrsStatistic /** * dumps the vhosts to amf0 array. */ - virtual int dumps_vhosts(SrsJsonArray* arr); + virtual srs_error_t dumps_vhosts(SrsJsonArray* arr); /** * dumps the streams to amf0 array. */ - virtual int dumps_streams(SrsJsonArray* arr); + virtual srs_error_t dumps_streams(SrsJsonArray* arr); /** * dumps the clients to amf0 array * @param start the start index, from 0. * @param count the max count of clients to dump. */ - virtual int dumps_clients(SrsJsonArray* arr, int start, int count); + virtual srs_error_t dumps_clients(SrsJsonArray* arr, int start, int count); private: virtual SrsStatisticVhost* create_vhost(SrsRequest* req); virtual SrsStatisticStream* create_stream(SrsStatisticVhost* vhost, SrsRequest* req); diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index b4da46fda6..cc23cff02a 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -155,17 +155,17 @@ string srs_path_build_timestamp(string template_path) return path; } -int srs_kill_forced(int& pid) +srs_error_t srs_kill_forced(int& pid) { - int ret = ERROR_SUCCESS; + srs_error_t err = srs_success; if (pid <= 0) { - return ret; + return err; } // first, try kill by SIGTERM. if (kill(pid, SIGTERM) < 0) { - return ERROR_SYSTEM_KILL; + return srs_error_new(ERROR_SYSTEM_KILL, "kill"); } // wait to quit. @@ -174,7 +174,7 @@ int srs_kill_forced(int& pid) int status = 0; pid_t qpid = -1; if ((qpid = waitpid(pid, &status, WNOHANG)) < 0) { - return ERROR_SYSTEM_KILL; + return srs_error_new(ERROR_SYSTEM_KILL, "kill"); } // 0 is not quit yet. @@ -187,12 +187,12 @@ int srs_kill_forced(int& pid) srs_trace("SIGTERM stop process pid=%d ok.", pid); pid = -1; - return ret; + return err; } // then, try kill by SIGKILL. if (kill(pid, SIGKILL) < 0) { - return ERROR_SYSTEM_KILL; + return srs_error_new(ERROR_SYSTEM_KILL, "kill"); } // wait for the process to quit. @@ -211,7 +211,7 @@ int srs_kill_forced(int& pid) srs_trace("SIGKILL stop process pid=%d ok.", pid); pid = -1; - return ret; + return err; } static SrsRusage _srs_system_rusage; diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 02a73df130..611be7a8c3 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -76,7 +76,7 @@ extern std::string srs_path_build_timestamp(std::string template_path); * @param pid the pid to kill. ignore for -1. set to -1 when killed. * @return an int error code. */ -extern int srs_kill_forced(int& pid); +extern srs_error_t srs_kill_forced(int& pid); // current process resouce usage. // @see: man getrusage