1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 03:41:55 +00:00

For #913, APP support complex error.

This commit is contained in:
winlin 2018-01-01 19:39:57 +08:00
parent aebbbadf42
commit 6eae93258a
47 changed files with 1098 additions and 1432 deletions

View file

@ -91,26 +91,25 @@ bool _bandwidth_is_stopped_publish(SrsBandwidthPacket* pkt)
{ {
return pkt->is_stopped_publish(); 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) { while (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) { if ((err = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != srs_success) {
return ret; return srs_error_wrap(err, "expect message");
} }
SrsAutoFree(SrsCommonMessage, msg); SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsBandwidthPacket, pkt); SrsAutoFree(SrsBandwidthPacket, pkt);
srs_info("get bwtc message success.");
if (pfn(pkt)) { if (pfn(pkt)) {
return ret; return err;
} }
} }
return ret; return err;
} }
SrsBandwidth::SrsBandwidth() 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; _rtmp = rtmp;
_req = req; _req = req;
if (!_srs_config->get_bw_check_enabled(_req->vhost)) { if (!_srs_config->get_bw_check_enabled(_req->vhost)) {
return ret; return err;
} }
// validate the bandwidth check key // validate the bandwidth check key
std::string key = "key=" + _srs_config->get_bw_check_key(_req->vhost); std::string key = "key=" + _srs_config->get_bw_check_key(_req->vhost);
if (_req->tcUrl.find(key) == std::string::npos) { if (_req->tcUrl.find(key) == std::string::npos) {
ret = ERROR_SYSTEM_BANDWIDTH_KEY; return srs_error_new(ERROR_SYSTEM_BANDWIDTH_KEY, "check the vhost=%s %s failed, tcUrl=%s",
srs_error("check the vhost=%s %s failed, tcUrl=%s, ret=%d", _req->vhost.c_str(), key.c_str(), _req->tcUrl.c_str());
_req->vhost.c_str(), key.c_str(), _req->tcUrl.c_str(), ret);
return ret;
} }
// shared global last check time, // 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(); int64_t time_now = srs_get_system_time_ms();
// reject the connection in the interval window. // reject the connection in the interval window.
if (last_check_time > 0 && time_now - last_check_time < interval_ms) { 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"); _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. // accept and do bandwidth check.
last_check_time = time_now; last_check_time = time_now;
if ((ret = _rtmp->response_connect_app(_req, local_ip.c_str())) != ERROR_SUCCESS) { if ((err = _rtmp->response_connect_app(_req, local_ip.c_str())) != srs_success) {
srs_error("response connect app failed. ret=%d", ret); return srs_error_wrap(err, "response connect app");
return ret;
} }
// create a limit object. // create a limit object.
@ -181,9 +172,9 @@ int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io
return do_bandwidth_check(&limit); 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 play_sample;
SrsBandwidthSample publish_sample; SrsBandwidthSample publish_sample;
@ -197,41 +188,27 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
int64_t start_time = srs_get_system_time_ms(); int64_t start_time = srs_get_system_time_ms();
// sample play // sample play
srs_info("start play test."); if ((err = play_start(&play_sample, limit)) != srs_success) {
return srs_error_wrap(err, "play start");
if ((ret = play_start(&play_sample, limit)) != ERROR_SUCCESS) {
srs_error("bandwidth play check failed. ret=%d", ret);
return ret;
} }
if ((ret = play_checking(&play_sample, limit)) != ERROR_SUCCESS) { if ((err = play_checking(&play_sample, limit)) != srs_success) {
srs_error("bandwidth play check failed. ret=%d", ret); return srs_error_wrap(err, "play check");
return ret;
} }
if ((ret = play_stop(&play_sample, limit)) != ERROR_SUCCESS) { if ((err = play_stop(&play_sample, limit)) != srs_success) {
srs_error("bandwidth play check failed. ret=%d", ret); return srs_error_wrap(err, "play stop");
return ret;
} }
srs_info("stop play test. kbps=%d", play_sample.kbps);
// sample publish // sample publish
srs_info("start publish test."); if ((err = publish_start(&publish_sample, limit)) != srs_success) {
return srs_error_wrap(err, "publish start");
if ((ret = publish_start(&publish_sample, limit)) != ERROR_SUCCESS) {
srs_error("bandwidth publish check failed. ret=%d", ret);
return ret;
} }
if ((ret = publish_checking(&publish_sample, limit)) != ERROR_SUCCESS) { if ((err = publish_checking(&publish_sample, limit)) != srs_success) {
srs_error("bandwidth publish check failed. ret=%d", ret); return srs_error_wrap(err, "publish check");
return ret;
} }
if ((ret = publish_stop(&publish_sample, limit)) != ERROR_SUCCESS) { if ((err = publish_stop(&publish_sample, limit)) != srs_success) {
srs_error("bandwidth publish check failed. ret=%d", ret); return srs_error_wrap(err, "publish stop");
return ret;
} }
srs_info("stop publish test. kbps=%d", publish_sample.kbps);
// stop test. // stop test.
srs_update_system_time_ms(); srs_update_system_time_ms();
int64_t end_time = srs_get_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.actual_duration_ms, play_sample.kbps,
publish_sample.kbps); publish_sample.kbps);
if ((ret = finial(play_sample, publish_sample, start_time, end_time)) != ERROR_SUCCESS) { if ((err = do_final(play_sample, publish_sample, start_time, end_time)) != srs_success) {
return ret; return srs_error_wrap(err, "final");
} }
srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT_MS * 1000); 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) { if (true) {
// send start play command to client // 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("duration_ms", SrsAmf0Any::number(sample->duration_ms));
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
srs_error("send bandwidth check start play message failed. ret=%d", ret); return srs_error_wrap(err, "send packet");
return ret;
} }
} }
srs_info("BW check play begin.");
if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_play)) != ERROR_SUCCESS) { if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_play)) != srs_success) {
return ret; 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 // send play data to client
int size = 1024; // TODO: FIXME: magic number int size = 1024; // TODO: FIXME: magic number
@ -305,23 +278,21 @@ int SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
} }
data_count += 2; data_count += 2;
if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
srs_error("send bandwidth check play messages failed. ret=%d", ret); return srs_error_wrap(err, "send packet");
return ret;
} }
limit->send_limit(); limit->send_limit();
} }
srs_update_system_time_ms(); srs_update_system_time_ms();
sample->calc_kbps(_rtmp->get_send_bytes(), srs_get_system_time_ms() - starttime); sample->calc_kbps((int)_rtmp->get_send_bytes(), (int)(srs_get_system_time_ms() - starttime));
srs_info("BW check send play bytes over.");
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) { if (true) {
// notify client to stop play // 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("duration_delta", SrsAmf0Any::number(sample->actual_duration_ms));
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes)); pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
srs_error("send bandwidth check stop play message failed. ret=%d", ret); return srs_error_wrap(err, "send packet");
return ret;
} }
} }
srs_info("BW check stop play bytes.");
if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_play)) != ERROR_SUCCESS) { if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_play)) != srs_success) {
return ret; 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) { if (true) {
// notify client to start publish // 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("duration_ms", SrsAmf0Any::number(sample->duration_ms));
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
srs_error("send bandwidth check start publish message failed. ret=%d", ret); return srs_error_wrap(err, "send packet");
return ret;
} }
} }
srs_info("BW check publish begin.");
if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_publish)) != ERROR_SUCCESS) { if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_publish)) != srs_success) {
return ret; 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 // recv publish msgs until @duration_ms ms
srs_update_system_time_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) { while ((srs_get_system_time_ms() - starttime) < sample->duration_ms) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = _rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) { if ((err = _rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != srs_success) {
return ret; return srs_error_wrap(err, "expect message");
} }
SrsAutoFree(SrsCommonMessage, msg); SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsBandwidthPacket, pkt); SrsAutoFree(SrsBandwidthPacket, pkt);
@ -399,15 +364,14 @@ int SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* lim
limit->recv_limit(); limit->recv_limit();
} }
srs_update_system_time_ms(); srs_update_system_time_ms();
sample->calc_kbps(_rtmp->get_recv_bytes(), srs_get_system_time_ms() - starttime); sample->calc_kbps((int)_rtmp->get_recv_bytes(), (int)(srs_get_system_time_ms() - starttime));
srs_info("BW check recv publish data over.");
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) { if (true) {
// notify client to stop publish // 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("duration_delta", SrsAmf0Any::number(sample->actual_duration_ms));
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes)); pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
srs_error("send bandwidth check stop publish message failed. ret=%d", ret); return srs_error_wrap(err, "send packet");
return ret;
} }
} }
srs_info("BW check stop publish bytes.");
// expect client to stop publish // expect client to stop publish
// if flash client, we never expect the client stop publish bytes, // 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. // we just ignore the packet and send the bandwidth test data.
bool is_flash = (_req->swfUrl != ""); bool is_flash = (_req->swfUrl != "");
if (!is_flash) { if (!is_flash) {
if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_publish)) != ERROR_SUCCESS) { if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_publish)) != srs_success) {
return ret; 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, // send finished msg,
// flash client will close connection when got this packet, // 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("play_time", SrsAmf0Any::number(play_sample.actual_duration_ms));
pkt->data->set("publish_time", SrsAmf0Any::number(publish_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) { if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
srs_error("send bandwidth check finish message failed. ret=%d", ret); return srs_error_wrap(err, "send packet");
return ret;
} }
srs_info("send finish packet.");
// we notice the result, and expect a final packet if not flash. // we notice the result, and expect a final packet if not flash.
// if flash client, client will disconnect when got finish packet. // if flash client, client will disconnect when got finish packet.
bool is_flash = (_req->swfUrl != ""); bool is_flash = (_req->swfUrl != "");
if (!is_flash) { if (!is_flash) {
// ignore any error. // ignore any error.
_srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_final); err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_final);
srs_info("BW check recv flash final response."); srs_error_reset(err);
} }
srs_info("BW check finished."); return err;
return ret;
} }
SrsKbpsLimit::SrsKbpsLimit(SrsKbps* kbps, int limit_kbps) SrsKbpsLimit::SrsKbpsLimit(SrsKbps* kbps, int limit_kbps)

View file

@ -131,13 +131,13 @@ public:
* @param req, client request object, specifies the request info from client. * @param req, client request object, specifies the request info from client.
* @param local_ip, the ip of server which client connected at * @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: private:
/** /**
* used to process band width check from client. * used to process band width check from client.
* @param limit, the bandwidth limit object, to slowdown if exceed the kbps. * @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. // play check/test, downloading bandwidth kbps.
private: private:
/** /**
@ -145,19 +145,19 @@ private:
* send start-play command to client, client must response starting-play * send start-play command to client, client must response starting-play
* to start the test. * 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, * do play/download bandwidth check/test,
* server send call messages to client in specified time, * server send call messages to client in specified time,
* calc the time and bytes sent, then we got the kbps. * 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, * stop play/download bandwidth check/test,
* send stop-play command to client, client must response stopped-play * send stop-play command to client, client must response stopped-play
* to stop the test. * 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. // publish check/test, publishing bandwidth kbps.
private: private:
/** /**
@ -165,7 +165,7 @@ private:
* send start-publish command to client, client must response starting-publish * send start-publish command to client, client must response starting-publish
* to start the test. * 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, * do publish/upload bandwidth check/test,
* client send call messages to client in specified time, * client send call messages to client in specified time,
@ -176,7 +176,7 @@ private:
* the send queue is fullfill with call messages, so we should never expect the * the send queue is fullfill with call messages, so we should never expect the
* response message in the publish-stop stage. * 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, * stop publish/upload bandwidth check/test,
* send stop-publish command to client, * send stop-publish command to client,
@ -184,7 +184,7 @@ private:
* for flash client, the sent queue is fullfill with publishing call messages, * for flash client, the sent queue is fullfill with publishing call messages,
* so server never expect the stopped-publish from it. * 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: private:
/** /**
* report and final packet * report and final packet
@ -193,7 +193,7 @@ private:
* for flash client, the sent queue is fullfill with publishing call messages, * for flash client, the sent queue is fullfill with publishing call messages,
* so server never expect the final packet from it. * 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);
}; };
/** /**

View file

@ -90,9 +90,9 @@ public:
public: public:
virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg); virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg);
public: public:
virtual int proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string o); virtual srs_error_t proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string o);
private: private:
virtual int do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec); virtual srs_error_t do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec);
}; };
/** /**
@ -110,7 +110,7 @@ public:
/** /**
* open file reader, can open then close then open... * 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(); virtual void close();
public: public:
// TODO: FIXME: extract interface. // TODO: FIXME: extract interface.
@ -120,8 +120,8 @@ public:
virtual int64_t seek2(int64_t offset); virtual int64_t seek2(int64_t offset);
virtual int64_t filesize(); virtual int64_t filesize();
public: public:
virtual int read(void* buf, size_t count, ssize_t* pnread); virtual srs_error_t read(void* buf, size_t count, ssize_t* pnread);
virtual int lseek(off_t offset, int whence, off_t* seeked); virtual srs_error_t lseek(off_t offset, int whence, off_t* seeked);
}; };
#endif #endif

View file

@ -78,7 +78,7 @@ const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER;
* @param dir the transcode or ingest config directive. * @param dir the transcode or ingest config directive.
* @param engine the amf0 object to dumps to. * @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, * whether the two vector actual equals, for instance,
@ -135,14 +135,13 @@ namespace _srs_internal
srs_error_t SrsConfigBuffer::fullfill(const char* filename) srs_error_t SrsConfigBuffer::fullfill(const char* filename)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsFileReader reader; SrsFileReader reader;
// open file reader. // open file reader.
if ((ret = reader.open(filename)) != ERROR_SUCCESS) { if ((err = reader.open(filename)) != srs_success) {
return srs_error_new(ret, "open file=%s", filename); return srs_error_wrap(err, "open file=%s", filename);
} }
// read all. // read all.
@ -155,8 +154,8 @@ namespace _srs_internal
// read total content from file. // read total content from file.
ssize_t nread = 0; ssize_t nread = 0;
if ((ret = reader.read(start, filesize, &nread)) != ERROR_SUCCESS) { if ((err = reader.read(start, filesize, &nread)) != srs_success) {
return srs_error_new(ret, "read %d only %d bytes", filesize, nread); return srs_error_wrap(err, "read %d only %d bytes", filesize, nread);
} }
return err; return err;
@ -527,9 +526,9 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root)
return err; 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; SrsConfDirective* conf = NULL;
@ -626,7 +625,7 @@ int srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine)
engine->set("output", conf->dumps_arg0_to_str()); engine->set("output", conf->dumps_arg0_to_str());
} }
return ret; return err;
} }
SrsConfDirective::SrsConfDirective() SrsConfDirective::SrsConfDirective()
@ -803,7 +802,6 @@ srs_error_t SrsConfDirective::parse(SrsConfigBuffer* buffer)
srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level) srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
static char SPACE = SRS_CONSTS_SP; static char SPACE = SRS_CONSTS_SP;
@ -817,34 +815,34 @@ srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level)
if (level > 0) { if (level > 0) {
// indent by (level - 1) * 4 space. // indent by (level - 1) * 4 space.
for (int i = 0; i < level - 1; i++) { for (int i = 0; i < level - 1; i++) {
if ((ret = writer->write((char*)INDENT, 4, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)INDENT, 4, NULL)) != srs_success) {
return srs_error_new(ret, "write indent"); return srs_error_wrap(err, "write indent");
} }
} }
// directive name. // directive name.
if ((ret = writer->write((char*)name.c_str(), (int)name.length(), NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)name.c_str(), (int)name.length(), NULL)) != srs_success) {
return srs_error_new(ret, "write name"); return srs_error_wrap(err, "write name");
} }
if (!args.empty() && (ret = writer->write((char*)&SPACE, 1, NULL)) != ERROR_SUCCESS) { if (!args.empty() && (err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write name space"); return srs_error_wrap(err, "write name space");
} }
// directive args. // directive args.
for (int i = 0; i < (int)args.size(); i++) { for (int i = 0; i < (int)args.size(); i++) {
std::string& arg = args.at(i); std::string& arg = args.at(i);
if ((ret = writer->write((char*)arg.c_str(), (int)arg.length(), NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)arg.c_str(), (int)arg.length(), NULL)) != srs_success) {
return srs_error_new(ret, "write arg"); return srs_error_wrap(err, "write arg");
} }
if (i < (int)args.size() - 1 && (ret = writer->write((char*)&SPACE, 1, NULL)) != ERROR_SUCCESS) { if (i < (int)args.size() - 1 && (err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write arg space"); return srs_error_wrap(err, "write arg space");
} }
} }
// native directive, without sub directives. // native directive, without sub directives.
if (directives.empty()) { if (directives.empty()) {
if ((ret = writer->write((char*)&SEMICOLON, 1, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)&SEMICOLON, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write arg semicolon"); 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. // persistence all sub directives.
if (level > 0) { if (level > 0) {
if (!directives.empty()) { if (!directives.empty()) {
if ((ret = writer->write((char*)&SPACE, 1, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write sub-dir space"); return srs_error_wrap(err, "write sub-dir space");
} }
if ((ret = writer->write((char*)&LB, 1, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)&LB, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write sub-dir left-brace"); return srs_error_wrap(err, "write sub-dir left-brace");
} }
} }
if ((ret = writer->write((char*)&LF, 1, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)&LF, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write sub-dir linefeed"); 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()) { if (level > 0 && !directives.empty()) {
// indent by (level - 1) * 4 space. // indent by (level - 1) * 4 space.
for (int i = 0; i < level - 1; i++) { for (int i = 0; i < level - 1; i++) {
if ((ret = writer->write((char*)INDENT, 4, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)INDENT, 4, NULL)) != srs_success) {
return srs_error_new(ret, "write sub-dir indent"); return srs_error_wrap(err, "write sub-dir indent");
} }
} }
if ((ret = writer->write((char*)&RB, 1, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)&RB, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write sub-dir right-brace"); return srs_error_wrap(err, "write sub-dir right-brace");
} }
if ((ret = writer->write((char*)&LF, 1, NULL)) != ERROR_SUCCESS) { if ((err = writer->write((char*)&LF, 1, NULL)) != srs_success) {
return srs_error_new(ret, "write sub-dir linefeed"); return srs_error_wrap(err, "write sub-dir linefeed");
} }
} }
@ -1983,7 +1981,6 @@ srs_error_t SrsConfig::initialize_cwd()
srs_error_t SrsConfig::persistence() srs_error_t SrsConfig::persistence()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// write to a tmp file, then mv to the config. // 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 // open the tmp file for persistence
SrsFileWriter fw; SrsFileWriter fw;
if ((ret = fw.open(path)) != ERROR_SUCCESS) { if ((err = fw.open(path)) != srs_success) {
return srs_error_new(ret, "open file"); return srs_error_wrap(err, "open file");
} }
// do persistence to writer. // do persistence to writer.
@ -2004,8 +2001,7 @@ srs_error_t SrsConfig::persistence()
// rename the config file. // rename the config file.
if (::rename(path.c_str(), config_file.c_str()) < 0) { if (::rename(path.c_str(), config_file.c_str()) < 0) {
::unlink(path.c_str()); ::unlink(path.c_str());
return srs_error_new(ERROR_SYSTEM_CONFIG_PERSISTENCE, "rename %s=>%s", return srs_error_new(ERROR_SYSTEM_CONFIG_PERSISTENCE, "rename %s=>%s", path.c_str(), config_file.c_str());
path.c_str(), config_file.c_str());
} }
return err; return err;
@ -2023,9 +2019,9 @@ srs_error_t SrsConfig::do_persistence(SrsFileWriter* fw)
return err; 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++) { for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* dir = root->directives.at(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++) { for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* dir = root->directives.at(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("nb_vhosts", SrsJsonAny::integer(nb_vhosts));
obj->set("vhosts", sobjs); 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; SrsConfDirective* dir = NULL;
@ -2716,8 +2712,8 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj)
SrsJsonObject* engine = SrsJsonAny::object(); SrsJsonObject* engine = SrsJsonAny::object();
ingest->set("engine", engine); ingest->set("engine", engine);
if ((ret = srs_config_dumps_engine(sdir, engine)) != ERROR_SUCCESS) { if ((err = srs_config_dumps_engine(sdir, engine)) != srs_success) {
return ret; return srs_error_wrap(err, "dump engine");
} }
} }
} }
@ -2754,19 +2750,19 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj)
SrsJsonObject* engine = SrsJsonAny::object(); SrsJsonObject* engine = SrsJsonAny::object();
engines->append(engine); engines->append(engine);
if ((ret = srs_config_dumps_engine(sdir, engine)) != ERROR_SUCCESS) { if ((err = srs_config_dumps_engine(sdir, engine)) != srs_success) {
return ret; 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(); SrsJsonObject* sobj = SrsJsonAny::object();
obj->set("http_api", sobj); 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_query", SrsJsonAny::boolean(get_raw_api_allow_query()));
ssobj->set("allow_update", SrsJsonAny::boolean(get_raw_api_allow_update())); ssobj->set("allow_update", SrsJsonAny::boolean(get_raw_api_allow_update()));
return ret; return err;
} }
int SrsConfig::raw_set_listen(const vector<string>& eps, bool& applied) srs_error_t SrsConfig::raw_set_listen(const vector<string>& eps, bool& applied)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
applied = false; applied = false;
@ -2797,27 +2792,23 @@ int SrsConfig::raw_set_listen(const vector<string>& eps, bool& applied)
// nothing changed, ignore. // nothing changed, ignore.
if (srs_vector_actual_equals(conf->args, eps)) { if (srs_vector_actual_equals(conf->args, eps)) {
return ret; return err;
} }
// changed, apply and reload. // changed, apply and reload.
conf->args = eps; conf->args = eps;
if ((err = do_reload_listen()) != srs_success) { if ((err = do_reload_listen()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload listen");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; applied = false;
@ -2825,34 +2816,31 @@ int SrsConfig::raw_set_pid(string pid, bool& applied)
SrsConfDirective* conf = root->get_or_create("pid"); SrsConfDirective* conf = root->get_or_create("pid");
if (conf->arg0() == pid) { if (conf->arg0() == pid) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
conf->args.push_back(pid); conf->args.push_back(pid);
if ((err = do_reload_pid()) != srs_success) { if ((err = do_reload_pid()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload pid");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; applied = false;
SrsConfDirective* conf = root->get_or_create("chunk_size"); SrsConfDirective* conf = root->get_or_create("chunk_size");
if (conf->arg0() == chunk_size) { if (conf->arg0() == chunk_size) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
@ -2862,19 +2850,19 @@ int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied)
applied = true; 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; applied = false;
SrsConfDirective* conf = root->get_or_create("ff_log_dir"); SrsConfDirective* conf = root->get_or_create("ff_log_dir");
if (conf->arg0() == ff_log_dir) { if (conf->arg0() == ff_log_dir) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
@ -2884,12 +2872,11 @@ int SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied)
applied = true; 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; srs_error_t err = srs_success;
applied = false; 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"); SrsConfDirective* conf = root->get_or_create("srs_log_tank");
if (conf->arg0() == srs_log_tank) { if (conf->arg0() == srs_log_tank) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
conf->args.push_back(srs_log_tank); conf->args.push_back(srs_log_tank);
if ((err = do_reload_srs_log_tank()) != srs_success) { if ((err = do_reload_srs_log_tank()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload log tank");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; 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"); SrsConfDirective* conf = root->get_or_create("srs_log_level");
if (conf->arg0() == srs_log_level) { if (conf->arg0() == srs_log_level) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
conf->args.push_back(srs_log_level); conf->args.push_back(srs_log_level);
if ((err = do_reload_srs_log_level()) != srs_success) { if ((err = do_reload_srs_log_level()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload log level");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; 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"); SrsConfDirective* conf = root->get_or_create("srs_log_file");
if (conf->arg0() == srs_log_file) { if (conf->arg0() == srs_log_file) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
conf->args.push_back(srs_log_file); conf->args.push_back(srs_log_file);
if ((err = do_reload_srs_log_file()) != srs_success) { if ((err = do_reload_srs_log_file()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload log file");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; 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"); SrsConfDirective* conf = root->get_or_create("max_connections");
if (conf->arg0() == max_connections) { if (conf->arg0() == max_connections) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
conf->args.push_back(max_connections); conf->args.push_back(max_connections);
if ((err = do_reload_max_connections()) != srs_success) { if ((err = do_reload_max_connections()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload max connection");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; applied = true;
return ret; return err;
} }
srs_error_t SrsConfig::raw_set_utc_time(string utc_time, bool& applied) 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; 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; srs_error_t err = srs_success;
applied = false; 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"); SrsConfDirective* conf = root->get_or_create("pithy_print_ms");
if (conf->arg0() == pithy_print_ms) { if (conf->arg0() == pithy_print_ms) {
return ret; return err;
} }
conf->args.clear(); conf->args.clear();
conf->args.push_back(pithy_print_ms); conf->args.push_back(pithy_print_ms);
if ((err = do_reload_pithy_print_ms()) != srs_success) { if ((err = do_reload_pithy_print_ms()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload pithy print");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; applied = false;
@ -3062,20 +3029,17 @@ int SrsConfig::raw_create_vhost(string vhost, bool& applied)
conf->get_or_create("enabled")->set_arg0("on"); conf->get_or_create("enabled")->set_arg0("on");
if ((err = do_reload_vhost_added(vhost)) != srs_success) { if ((err = do_reload_vhost_added(vhost)) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload vhost");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; applied = false;
@ -3085,12 +3049,12 @@ int SrsConfig::raw_update_vhost(string vhost, string name, bool& applied)
applied = true; 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; applied = false;
@ -3104,12 +3068,11 @@ int SrsConfig::raw_delete_vhost(string vhost, bool& applied)
applied = true; 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; srs_error_t err = srs_success;
applied = false; applied = false;
@ -3118,20 +3081,16 @@ int SrsConfig::raw_disable_vhost(string vhost, bool& applied)
conf->get_or_create("enabled")->set_arg0("off"); conf->get_or_create("enabled")->set_arg0("off");
if ((err = do_reload_vhost_removed(vhost)) != srs_success) { if ((err = do_reload_vhost_removed(vhost)) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload vhost removed");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; applied = false;
@ -3140,20 +3099,16 @@ int SrsConfig::raw_enable_vhost(string vhost, bool& applied)
conf->get_or_create("enabled")->set_arg0("on"); conf->get_or_create("enabled")->set_arg0("on");
if ((err = do_reload_vhost_added(vhost)) != srs_success) { if ((err = do_reload_vhost_added(vhost)) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload vhost added");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; 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) { if ((err = do_reload_vhost_dvr_apply(vhost)) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload vhost dvr");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; 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; srs_error_t err = srs_success;
applied = false; 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) { if ((err = do_reload_vhost_dvr_apply(vhost)) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "reload vhost dvr");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
applied = true; applied = true;
return ret; return err;
} }
srs_error_t SrsConfig::do_reload_listen() srs_error_t SrsConfig::do_reload_listen()

File diff suppressed because it is too large Load diff

View file

@ -53,7 +53,7 @@ public:
virtual ~SrsInitMp4(); virtual ~SrsInitMp4();
public: public:
// Write the init mp4 file, with the tid(track id). // 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 @@ public:
virtual ~SrsFragmentedMp4(); virtual ~SrsFragmentedMp4();
public: public:
// Initialize the fragment, create the home dir, open the file. // 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. // 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. // 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 @@ public:
public: public:
virtual srs_error_t initialize(SrsRequest* r); virtual srs_error_t initialize(SrsRequest* r);
// Write MPD according to parsed format of stream. // Write MPD according to parsed format of stream.
virtual int write(SrsFormat* format); virtual srs_error_t write(SrsFormat* format);
public: public:
// Get the fragment relative home and filename. // Get the fragment relative home and filename.
// The basetime is the absolute time in ms, while the sn(sequence number) is basetime/fragment. // 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 @@ public:
virtual ~SrsDashController(); virtual ~SrsDashController();
public: public:
virtual srs_error_t initialize(SrsRequest* r); virtual srs_error_t initialize(SrsRequest* r);
virtual int on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format); virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format);
virtual int on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format); virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format);
private: private:
virtual int refresh_mpd(SrsFormat* format); virtual srs_error_t refresh_mpd(SrsFormat* format);
virtual int refresh_init_mp4(SrsSharedPtrMessage* msg, SrsFormat* format); virtual srs_error_t refresh_init_mp4(SrsSharedPtrMessage* msg, SrsFormat* format);
}; };
/** /**
@ -163,11 +163,11 @@ public:
// Initalize the encoder. // Initalize the encoder.
virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r); virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r);
// When stream start publishing. // When stream start publishing.
virtual int on_publish(); virtual srs_error_t on_publish();
// When got an shared audio message. // 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. // 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. // When stream stop publishing.
virtual void on_unpublish(); virtual void on_unpublish();
}; };

View file

@ -72,9 +72,9 @@ SrsEdgeRtmpUpstream::~SrsEdgeRtmpUpstream()
close(); 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; SrsRequest* req = r;
@ -86,9 +86,7 @@ int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
// when origin is error, for instance, server is shutdown, // when origin is error, for instance, server is shutdown,
// then user remove the vhost then reload, the conf is empty. // then user remove the vhost then reload, the conf is empty.
if (!conf) { if (!conf) {
ret = ERROR_EDGE_VHOST_REMOVED; return srs_error_new(ERROR_EDGE_VHOST_REMOVED, "vhost %s removed", req->vhost.c_str());
srs_warn("vhost %s removed. ret=%d", req->vhost.c_str(), ret);
return ret;
} }
// select the origin. // select the origin.
@ -120,25 +118,23 @@ int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto); sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) { if ((err = sdk->connect()) != srs_success) {
srs_error("edge pull %s failed, cto=%" PRId64 ", sto=%" PRId64 ". ret=%d", url.c_str(), cto, sto, ret); return srs_error_wrap(err, "edge pull %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
return ret;
} }
if ((ret = sdk->play()) != ERROR_SUCCESS) { if ((err = sdk->play()) != srs_success) {
srs_error("edge pull %s stream failed. ret=%d", url.c_str(), ret); return srs_error_wrap(err, "edge pull %s stream failed", url.c_str());
return ret;
} }
return ret; return err;
} }
int SrsEdgeRtmpUpstream::recv_message(SrsCommonMessage** pmsg) srs_error_t SrsEdgeRtmpUpstream::recv_message(SrsCommonMessage** pmsg)
{ {
return sdk->recv_message(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); return sdk->decode_message(msg, ppacket);
} }
@ -246,7 +242,6 @@ srs_error_t SrsEdgeIngester::cycle()
srs_error_t SrsEdgeIngester::do_cycle() srs_error_t SrsEdgeIngester::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
while (true) { while (true) {
@ -265,12 +260,12 @@ srs_error_t SrsEdgeIngester::do_cycle()
return srs_error_wrap(err, "on source id changed"); return srs_error_wrap(err, "on source id changed");
} }
if ((ret = upstream->connect(req, lb)) != ERROR_SUCCESS) { if ((err = upstream->connect(req, lb)) != srs_success) {
return srs_error_new(ret, "connect upstream"); return srs_error_wrap(err, "connect upstream");
} }
if ((ret = edge->on_ingest_play()) != ERROR_SUCCESS) { if ((err = edge->on_ingest_play()) != srs_success) {
return srs_error_new(ret, "notify edge play"); return srs_error_wrap(err, "notify edge play");
} }
err = ingest(); err = ingest();
@ -288,12 +283,11 @@ srs_error_t SrsEdgeIngester::do_cycle()
break; break;
} }
return srs_error_new(ret, "cycle"); return err;
} }
srs_error_t SrsEdgeIngester::ingest() srs_error_t SrsEdgeIngester::ingest()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsPithyPrint* pprint = SrsPithyPrint::create_edge(); SrsPithyPrint* pprint = SrsPithyPrint::create_edge();
@ -317,8 +311,8 @@ srs_error_t SrsEdgeIngester::ingest()
// read from client. // read from client.
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL;
if ((ret = upstream->recv_message(&msg)) != ERROR_SUCCESS) { if ((err = upstream->recv_message(&msg)) != srs_success) {
return srs_error_new(ret, "recv message"); return srs_error_wrap(err, "recv message");
} }
srs_assert(msg); srs_assert(msg);
@ -334,7 +328,6 @@ srs_error_t SrsEdgeIngester::ingest()
srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg) srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// process audio packet // process audio packet
@ -362,8 +355,8 @@ srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg)
// process onMetaData // process onMetaData
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) { if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL;
if ((ret = upstream->decode_message(msg, &pkt)) != ERROR_SUCCESS) { if ((err = upstream->decode_message(msg, &pkt)) != srs_success) {
return srs_error_new(ret, "decode message"); return srs_error_wrap(err, "decode message");
} }
SrsAutoFree(SrsPacket, pkt); SrsAutoFree(SrsPacket, pkt);
@ -381,8 +374,8 @@ srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg)
// call messages, for example, reject, redirect. // call messages, for example, reject, redirect.
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) { if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL;
if ((ret = upstream->decode_message(msg, &pkt)) != ERROR_SUCCESS) { if ((err = upstream->decode_message(msg, &pkt)) != srs_success) {
return srs_error_new(ret, "decode message"); return srs_error_wrap(err, "decode message");
} }
SrsAutoFree(SrsPacket, pkt); SrsAutoFree(SrsPacket, pkt);
@ -456,7 +449,6 @@ srs_error_t SrsEdgeForwarder::initialize(SrsSource* s, SrsPublishEdge* e, SrsReq
srs_error_t SrsEdgeForwarder::start() srs_error_t SrsEdgeForwarder::start()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// reset the error code. // reset the error code.
@ -486,12 +478,12 @@ srs_error_t SrsEdgeForwarder::start()
int64_t sto = SRS_CONSTS_RTMP_TMMS; int64_t sto = SRS_CONSTS_RTMP_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto); sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) { if ((err = sdk->connect()) != srs_success) {
return srs_error_new(ret, "sdk connect %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto); return srs_error_wrap(err, "sdk connect %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
} }
if ((ret = sdk->publish()) != ERROR_SUCCESS) { if ((err = sdk->publish()) != srs_success) {
return srs_error_new(ret, "sdk publish"); return srs_error_wrap(err, "sdk publish");
} }
srs_freep(trd); srs_freep(trd);
@ -537,7 +529,6 @@ srs_error_t SrsEdgeForwarder::cycle()
srs_error_t SrsEdgeForwarder::do_cycle() srs_error_t SrsEdgeForwarder::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS); sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS);
@ -560,15 +551,17 @@ srs_error_t SrsEdgeForwarder::do_cycle()
// read from client. // read from client.
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL;
ret = sdk->recv_message(&msg); err = sdk->recv_message(&msg);
srs_verbose("edge loop recv message. ret=%d", ret); srs_verbose("edge loop recv message. ret=%d", ret);
if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) { if (err != srs_success && srs_error_code(err) != ERROR_SOCKET_TIMEOUT) {
srs_error("edge push get server control message failed. ret=%d", ret); srs_error("edge push get server control message failed. err=%s", srs_error_desc(err).c_str());
send_error_code = ret; send_error_code = srs_error_code(err);
srs_error_reset(err);
continue; continue;
} }
srs_error_reset(err);
srs_freep(msg); srs_freep(msg);
} }
@ -593,8 +586,8 @@ srs_error_t SrsEdgeForwarder::do_cycle()
} }
// sendout messages, all messages are freed by send_and_free_messages(). // sendout messages, all messages are freed by send_and_free_messages().
if ((ret = sdk->send_and_free_messages(msgs.msgs, count)) != ERROR_SUCCESS) { if ((err = sdk->send_and_free_messages(msgs.msgs, count)) != srs_success) {
return srs_error_new(ret, "send messages"); return srs_error_wrap(err, "send messages");
} }
} }
@ -603,11 +596,10 @@ srs_error_t SrsEdgeForwarder::do_cycle()
srs_error_t SrsEdgeForwarder::proxy(SrsCommonMessage* msg) srs_error_t SrsEdgeForwarder::proxy(SrsCommonMessage* msg)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if ((ret = send_error_code) != ERROR_SUCCESS) { if (send_error_code != ERROR_SUCCESS) {
return srs_error_new(ret, "edge forwarder"); return srs_error_new(send_error_code, "edge forwarder");
} }
// the msg is auto free by source, // the msg is auto free by source,
@ -620,8 +612,8 @@ srs_error_t SrsEdgeForwarder::proxy(SrsCommonMessage* msg)
} }
SrsSharedPtrMessage copy; SrsSharedPtrMessage copy;
if ((ret = copy.create(msg)) != ERROR_SUCCESS) { if ((err = copy.create(msg)) != srs_success) {
return srs_error_new(ret, "create message"); return srs_error_wrap(err, "create message");
} }
copy.stream_id = sdk->sid(); copy.stream_id = sdk->sid();
@ -654,22 +646,17 @@ srs_error_t SrsPlayEdge::initialize(SrsSource* source, SrsRequest* req)
return err; return err;
} }
int SrsPlayEdge::on_client_play() srs_error_t SrsPlayEdge::on_client_play()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// start ingest when init state. // start ingest when init state.
if (state == SrsEdgeStateInit) { if (state == SrsEdgeStateInit) {
state = SrsEdgeStatePlay; state = SrsEdgeStatePlay;
err = ingester->start(); 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() void SrsPlayEdge::on_all_client_stop()
@ -692,13 +679,13 @@ string SrsPlayEdge::get_curr_origin()
return ingester->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. // when already connected(for instance, reconnect for error), ignore.
if (state == SrsEdgeStateIngestConnected) { if (state == SrsEdgeStateIngestConnected) {
return ret; return err;
} }
srs_assert(state == SrsEdgeStatePlay); srs_assert(state == SrsEdgeStatePlay);
@ -707,7 +694,7 @@ int SrsPlayEdge::on_ingest_play()
state = SrsEdgeStateIngestConnected; state = SrsEdgeStateIngestConnected;
srs_trace("edge change from %d to state %d (pull).", pstate, state); srs_trace("edge change from %d to state %d (pull).", pstate, state);
return ret; return err;
} }
SrsPublishEdge::SrsPublishEdge() SrsPublishEdge::SrsPublishEdge()

View file

@ -81,9 +81,9 @@ public:
SrsEdgeUpstream(); SrsEdgeUpstream();
virtual ~SrsEdgeUpstream(); virtual ~SrsEdgeUpstream();
public: public:
virtual int connect(SrsRequest* r, SrsLbRoundRobin* lb) = 0; virtual srs_error_t connect(SrsRequest* r, SrsLbRoundRobin* lb) = 0;
virtual int recv_message(SrsCommonMessage** pmsg) = 0; virtual srs_error_t recv_message(SrsCommonMessage** pmsg) = 0;
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0; virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0;
virtual void close() = 0; virtual void close() = 0;
public: public:
virtual void set_recv_timeout(int64_t tm) = 0; virtual void set_recv_timeout(int64_t tm) = 0;
@ -102,9 +102,9 @@ public:
SrsEdgeRtmpUpstream(std::string r); SrsEdgeRtmpUpstream(std::string r);
virtual ~SrsEdgeRtmpUpstream(); virtual ~SrsEdgeRtmpUpstream();
public: public:
virtual int connect(SrsRequest* r, SrsLbRoundRobin* lb); virtual srs_error_t connect(SrsRequest* r, SrsLbRoundRobin* lb);
virtual int recv_message(SrsCommonMessage** pmsg); virtual srs_error_t recv_message(SrsCommonMessage** pmsg);
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
virtual void close(); virtual void close();
public: public:
virtual void set_recv_timeout(int64_t tm); virtual void set_recv_timeout(int64_t tm);
@ -206,7 +206,7 @@ public:
/** /**
* when client play stream on edge. * 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. * when all client stopped play, disconnect to origin.
*/ */
@ -216,7 +216,7 @@ public:
/** /**
* when ingester start to play stream. * when ingester start to play stream.
*/ */
virtual int on_ingest_play(); virtual srs_error_t on_ingest_play();
}; };
/** /**

View file

@ -53,38 +53,33 @@ SrsEncoder::~SrsEncoder()
srs_freep(pprint); 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; srs_error_t err = srs_success;
// parse the transcode engines for vhost and app and stream. // parse the transcode engines for vhost and app and stream.
ret = parse_scope_engines(req); err = parse_scope_engines(req);
// ignore the loop encoder // ignore the loop encoder
// if got a loop, donot transcode the whole stream. // if got a loop, donot transcode the whole stream.
if (ret == ERROR_ENCODER_LOOP) { if (srs_error_code(err) == ERROR_ENCODER_LOOP) {
clear_engines(); clear_engines();
ret = ERROR_SUCCESS; srs_error_reset(err);
} }
// return for error or no engine. // return for error or no engine.
if (ret != ERROR_SUCCESS || ffmpegs.empty()) { if (err != srs_success || ffmpegs.empty()) {
return ret; return err;
} }
// start thread to run all encoding engines. // start thread to run all encoding engines.
srs_freep(trd); srs_freep(trd);
trd = new SrsSTCoroutine("encoder", this, _srs_context->get_id()); trd = new SrsSTCoroutine("encoder", this, _srs_context->get_id());
if ((err = trd->start()) != srs_success) { if ((err = trd->start()) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "start encoder");
ret = srs_error_code(err);
srs_freep(err);
return ret;
} }
return ret; return err;
} }
void SrsEncoder::on_unpublish() void SrsEncoder::on_unpublish()
@ -103,11 +98,12 @@ srs_error_t SrsEncoder::cycle()
while (true) { while (true) {
if ((err = do_cycle()) != srs_success) { if ((err = do_cycle()) != srs_success) {
srs_warn("Encoder: Ignore error, %s", srs_error_desc(err).c_str()); 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) { 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); srs_usleep(SRS_RTMP_ENCODER_CIMS * 1000);
@ -126,7 +122,6 @@ srs_error_t SrsEncoder::cycle()
srs_error_t SrsEncoder::do_cycle() srs_error_t SrsEncoder::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
std::vector<SrsFFMPEG*>::iterator it; std::vector<SrsFFMPEG*>::iterator it;
@ -134,13 +129,13 @@ srs_error_t SrsEncoder::do_cycle()
SrsFFMPEG* ffmpeg = *it; SrsFFMPEG* ffmpeg = *it;
// start all ffmpegs. // start all ffmpegs.
if ((ret = ffmpeg->start()) != ERROR_SUCCESS) { if ((err = ffmpeg->start()) != srs_success) {
return srs_error_new(ret, "ffmpeg start"); return srs_error_wrap(err, "ffmpeg start");
} }
// check ffmpeg status. // check ffmpeg status.
if ((ret = ffmpeg->cycle()) != ERROR_SUCCESS) { if ((err = ffmpeg->cycle()) != srs_success) {
return srs_error_new(ret, "ffmpeg cycle"); return srs_error_wrap(err, "ffmpeg cycle");
} }
} }
@ -176,9 +171,9 @@ SrsFFMPEG* SrsEncoder::at(int index)
return ffmpegs[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. // parse all transcode engines.
SrsConfDirective* conf = NULL; SrsConfDirective* conf = NULL;
@ -186,96 +181,78 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req)
// parse vhost scope engines // parse vhost scope engines
std::string scope = ""; std::string scope = "";
if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) {
if ((ret = parse_ffmpeg(req, conf)) != ERROR_SUCCESS) { if ((err = parse_ffmpeg(req, conf)) != srs_success) {
if (ret != ERROR_ENCODER_LOOP) { return srs_error_wrap(err, "parse ffmpeg");
srs_error("parse vhost scope=%s transcode engines failed. "
"ret=%d", scope.c_str(), ret);
}
return ret;
} }
} }
// parse app scope engines // parse app scope engines
scope = req->app; scope = req->app;
if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) {
if ((ret = parse_ffmpeg(req, conf)) != ERROR_SUCCESS) { if ((err = parse_ffmpeg(req, conf)) != srs_success) {
if (ret != ERROR_ENCODER_LOOP) { return srs_error_wrap(err, "parse ffmpeg");
srs_error("parse app scope=%s transcode engines failed. "
"ret=%d", scope.c_str(), ret);
}
return ret;
} }
} }
// parse stream scope engines // parse stream scope engines
scope += "/"; scope += "/";
scope += req->stream; scope += req->stream;
if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) {
if ((ret = parse_ffmpeg(req, conf)) != ERROR_SUCCESS) { if ((err = parse_ffmpeg(req, conf)) != srs_success) {
if (ret != ERROR_ENCODER_LOOP) { return srs_error_wrap(err, "parse ffmpeg");
srs_error("parse stream scope=%s transcode engines failed. "
"ret=%d", scope.c_str(), ret);
}
return ret;
} }
} }
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); srs_assert(conf);
// enabled // enabled
if (!_srs_config->get_transcode_enabled(conf)) { if (!_srs_config->get_transcode_enabled(conf)) {
srs_trace("ignore the disabled transcode: %s", conf->arg0().c_str()); srs_trace("ignore the disabled transcode: %s", conf->arg0().c_str());
return ret; return err;
} }
// ffmpeg // ffmpeg
std::string ffmpeg_bin = _srs_config->get_transcode_ffmpeg(conf); std::string ffmpeg_bin = _srs_config->get_transcode_ffmpeg(conf);
if (ffmpeg_bin.empty()) { if (ffmpeg_bin.empty()) {
srs_trace("ignore the empty ffmpeg transcode: %s", srs_trace("ignore the empty ffmpeg transcode: %s", conf->arg0().c_str());
conf->arg0().c_str()); return err;
return ret;
} }
// get all engines. // get all engines.
std::vector<SrsConfDirective*> engines = _srs_config->get_transcode_engines(conf); std::vector<SrsConfDirective*> engines = _srs_config->get_transcode_engines(conf);
if (engines.empty()) { if (engines.empty()) {
srs_trace("ignore the empty transcode engine: %s", srs_trace("ignore the empty transcode engine: %s", conf->arg0().c_str());
conf->arg0().c_str()); return err;
return ret;
} }
// create engine // create engine
for (int i = 0; i < (int)engines.size(); i++) { for (int i = 0; i < (int)engines.size(); i++) {
SrsConfDirective* engine = engines[i]; SrsConfDirective* engine = engines[i];
if (!_srs_config->get_engine_enabled(engine)) { if (!_srs_config->get_engine_enabled(engine)) {
srs_trace("ignore the diabled transcode engine: %s %s", srs_trace("ignore the diabled transcode engine: %s %s", conf->arg0().c_str(), engine->arg0().c_str());
conf->arg0().c_str(), engine->arg0().c_str());
continue; continue;
} }
SrsFFMPEG* ffmpeg = new SrsFFMPEG(ffmpeg_bin); 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); srs_freep(ffmpeg);
if (ret != ERROR_ENCODER_LOOP) { return srs_error_wrap(err, "init ffmpeg");
srs_error("invalid transcode engine: %s %s", conf->arg0().c_str(), engine->arg0().c_str());
}
return ret;
} }
ffmpegs.push_back(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; std::string input;
// input stream, from local. // input stream, from local.
@ -330,21 +307,18 @@ int SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDir
std::vector<std::string>::iterator it; std::vector<std::string>::iterator it;
it = std::find(_transcoded_url.begin(), _transcoded_url.end(), input); it = std::find(_transcoded_url.begin(), _transcoded_url.end(), input);
if (it != _transcoded_url.end()) { if (it != _transcoded_url.end()) {
ret = ERROR_ENCODER_LOOP; return srs_error_new(ERROR_ENCODER_LOOP, "detect a loop cycle, input=%s, output=%s", input.c_str(), output.c_str());
srs_trace("detect a loop cycle, input=%s, output=%s, ignore it. ret=%d",
input.c_str(), output.c_str(), ret);
return ret;
} }
_transcoded_url.push_back(output); _transcoded_url.push_back(output);
if ((ret = ffmpeg->initialize(input, output, log_file)) != ERROR_SUCCESS) { if ((err = ffmpeg->initialize(input, output, log_file)) != srs_success) {
return ret; return srs_error_wrap(err, "init ffmpeg");
} }
if ((ret = ffmpeg->initialize_transcode(engine)) != ERROR_SUCCESS) { if ((err = ffmpeg->initialize_transcode(engine)) != srs_success) {
return ret; return srs_error_wrap(err, "init transcode");
} }
return ret; return err;
} }
void SrsEncoder::show_encode_log_message() void SrsEncoder::show_encode_log_message()

View file

@ -54,7 +54,7 @@ public:
SrsEncoder(); SrsEncoder();
virtual ~SrsEncoder(); virtual ~SrsEncoder();
public: public:
virtual int on_publish(SrsRequest* req); virtual srs_error_t on_publish(SrsRequest* req);
virtual void on_unpublish(); virtual void on_unpublish();
// interface ISrsReusableThreadHandler. // interface ISrsReusableThreadHandler.
public: public:
@ -64,9 +64,9 @@ private:
private: private:
virtual void clear_engines(); virtual void clear_engines();
virtual SrsFFMPEG* at(int index); virtual SrsFFMPEG* at(int index);
virtual int parse_scope_engines(SrsRequest* req); virtual srs_error_t parse_scope_engines(SrsRequest* req);
virtual int parse_ffmpeg(SrsRequest* req, SrsConfDirective* conf); virtual srs_error_t parse_ffmpeg(SrsRequest* req, SrsConfDirective* conf);
virtual int initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDirective* engine); virtual srs_error_t initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDirective* engine);
virtual void show_encode_log_message(); virtual void show_encode_log_message();
}; };

View file

@ -97,20 +97,20 @@ string SrsFFMPEG::output()
return _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; input = in;
_output = out; _output = out;
log_file = log; 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); perfile = _srs_config->get_engine_perfile(engine);
iformat = _srs_config->get_engine_iformat(engine); iformat = _srs_config->get_engine_iformat(engine);
@ -136,85 +136,56 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
vheight -= vheight % 2; vheight -= vheight % 2;
if (vcodec == SRS_RTMP_ENCODER_NO_VIDEO && acodec == SRS_RTMP_ENCODER_NO_AUDIO) { if (vcodec == SRS_RTMP_ENCODER_NO_VIDEO && acodec == SRS_RTMP_ENCODER_NO_AUDIO) {
ret = ERROR_ENCODER_VCODEC; return srs_error_new(ERROR_ENCODER_VCODEC, "video and audio disabled");
srs_warn("video and audio disabled. ret=%d", ret);
return ret;
} }
if (vcodec != SRS_RTMP_ENCODER_COPY && vcodec != SRS_RTMP_ENCODER_NO_VIDEO && vcodec != SRS_RTMP_ENCODER_VCODEC_PNG) { 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) { if (vcodec != SRS_RTMP_ENCODER_VCODEC_LIBX264) {
ret = ERROR_ENCODER_VCODEC; return srs_error_new(ERROR_ENCODER_VCODEC, "invalid vcodec, must be %s, actual %s", SRS_RTMP_ENCODER_VCODEC_LIBX264, vcodec.c_str());
srs_error("invalid vcodec, must be %s, actual %s, ret=%d",
SRS_RTMP_ENCODER_VCODEC_LIBX264, vcodec.c_str(), ret);
return ret;
} }
if (vbitrate < 0) { if (vbitrate < 0) {
ret = ERROR_ENCODER_VBITRATE; return srs_error_new(ERROR_ENCODER_VBITRATE, "invalid vbitrate: %d", vbitrate);
srs_error("invalid vbitrate: %d, ret=%d", vbitrate, ret);
return ret;
} }
if (vfps < 0) { if (vfps < 0) {
ret = ERROR_ENCODER_VFPS; return srs_error_new(ERROR_ENCODER_VFPS, "invalid vfps: %.2f", vfps);
srs_error("invalid vfps: %.2f, ret=%d", vfps, ret);
return ret;
} }
if (vwidth < 0) { if (vwidth < 0) {
ret = ERROR_ENCODER_VWIDTH; return srs_error_new(ERROR_ENCODER_VWIDTH, "invalid vwidth: %d", vwidth);
srs_error("invalid vwidth: %d, ret=%d", vwidth, ret);
return ret;
} }
if (vheight < 0) { if (vheight < 0) {
ret = ERROR_ENCODER_VHEIGHT; return srs_error_new(ERROR_ENCODER_VHEIGHT, "invalid vheight: %d", vheight);
srs_error("invalid vheight: %d, ret=%d", vheight, ret);
return ret;
} }
if (vthreads < 0) { if (vthreads < 0) {
ret = ERROR_ENCODER_VTHREADS; return srs_error_new(ERROR_ENCODER_VTHREADS, "invalid vthreads: %d", vthreads);
srs_error("invalid vthreads: %d, ret=%d", vthreads, ret);
return ret;
} }
if (vprofile.empty()) { if (vprofile.empty()) {
ret = ERROR_ENCODER_VPROFILE; return srs_error_new(ERROR_ENCODER_VPROFILE, "invalid vprofile: %s", vprofile.c_str());
srs_error("invalid vprofile: %s, ret=%d", vprofile.c_str(), ret);
return ret;
} }
if (vpreset.empty()) { if (vpreset.empty()) {
ret = ERROR_ENCODER_VPRESET; return srs_error_new(ERROR_ENCODER_VPRESET, "invalid vpreset: %s", vpreset.c_str());
srs_error("invalid vpreset: %s, ret=%d", vpreset.c_str(), ret);
return ret;
} }
} }
// @see, https://github.com/ossrs/srs/issues/145 // @see, https://github.com/ossrs/srs/issues/145
if (acodec == SRS_RTMP_ENCODER_LIBAACPLUS && acodec != SRS_RTMP_ENCODER_LIBFDKAAC) { if (acodec == SRS_RTMP_ENCODER_LIBAACPLUS && acodec != SRS_RTMP_ENCODER_LIBFDKAAC) {
if (abitrate != 0 && (abitrate < 16 || abitrate > 72)) { if (abitrate != 0 && (abitrate < 16 || abitrate > 72)) {
ret = ERROR_ENCODER_ABITRATE; return srs_error_new(ERROR_ENCODER_ABITRATE, "invalid abitrate for aac: %d, must in [16, 72]", abitrate);
srs_error("invalid abitrate for aac: %d, must in [16, 72], ret=%d", abitrate, ret);
return ret;
} }
} }
if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) { if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) {
if (abitrate < 0) { if (abitrate < 0) {
ret = ERROR_ENCODER_ABITRATE; return srs_error_new(ERROR_ENCODER_ABITRATE, "invalid abitrate: %d", abitrate);
srs_error("invalid abitrate: %d, ret=%d", abitrate, ret);
return ret;
} }
if (asample_rate < 0) { if (asample_rate < 0) {
ret = ERROR_ENCODER_ASAMPLE_RATE; return srs_error_new(ERROR_ENCODER_ASAMPLE_RATE, "invalid sample rate: %d", asample_rate);
srs_error("invalid sample rate: %d, ret=%d", asample_rate, ret);
return ret;
} }
if (achannels != 0 && achannels != 1 && achannels != 2) { if (achannels != 0 && achannels != 1 && achannels != 2) {
ret = ERROR_ENCODER_ACHANNELS; return srs_error_new(ERROR_ENCODER_ACHANNELS, "invalid achannels, must be 1 or 2, actual %d", achannels);
srs_error("invalid achannels, must be 1 or 2, actual %d, ret=%d", achannels, ret);
return ret;
} }
} }
if (_output.empty()) { if (_output.empty()) {
ret = ERROR_ENCODER_OUTPUT; return srs_error_new(ERROR_ENCODER_OUTPUT, "invalid empty output");
srs_error("invalid empty output, ret=%d", ret);
return ret;
} }
// for not rtmp input, donot append the iformat, // for not rtmp input, donot append the iformat,
@ -224,31 +195,29 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
iformat = ""; 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; vcodec = SRS_RTMP_ENCODER_COPY;
acodec = SRS_RTMP_ENCODER_COPY; acodec = SRS_RTMP_ENCODER_COPY;
if (_output.empty()) { if (_output.empty()) {
ret = ERROR_ENCODER_OUTPUT; return srs_error_new(ERROR_ENCODER_OUTPUT, "invalid empty output");
srs_error("invalid empty output, ret=%d", ret);
return ret;
} }
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()) { if (process->started()) {
return ret; return err;
} }
// the argv for process. // the argv for process.
@ -427,14 +396,14 @@ int SrsFFMPEG::start()
} }
// initialize the process. // initialize the process.
if ((ret = process->initialize(ffmpeg, params)) != ERROR_SUCCESS) { if ((err = process->initialize(ffmpeg, params)) != srs_success) {
return ret; return srs_error_wrap(err, "init process");
} }
return process->start(); return process->start();
} }
int SrsFFMPEG::cycle() srs_error_t SrsFFMPEG::cycle()
{ {
return process->cycle(); return process->cycle();
} }

View file

@ -77,12 +77,12 @@ public:
virtual void set_oformat(std::string format); virtual void set_oformat(std::string format);
virtual std::string output(); virtual std::string output();
public: public:
virtual int initialize(std::string in, std::string out, std::string log); virtual srs_error_t initialize(std::string in, std::string out, std::string log);
virtual int initialize_transcode(SrsConfDirective* engine); virtual srs_error_t initialize_transcode(SrsConfDirective* engine);
virtual int initialize_copy(); virtual srs_error_t initialize_copy();
public: public:
virtual int start(); virtual srs_error_t start();
virtual int cycle(); virtual srs_error_t cycle();
virtual void stop(); virtual void stop();
public: public:
virtual void fast_stop(); virtual void fast_stop();

View file

@ -234,7 +234,6 @@ srs_error_t SrsForwarder::cycle()
srs_error_t SrsForwarder::do_cycle() srs_error_t SrsForwarder::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
std::string url; std::string url;
@ -254,12 +253,12 @@ srs_error_t SrsForwarder::do_cycle()
int64_t sto = SRS_CONSTS_RTMP_TMMS; int64_t sto = SRS_CONSTS_RTMP_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto); sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) { if ((err = sdk->connect()) != srs_success) {
return srs_error_new(ret, "sdk connect url=%s, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto); return srs_error_wrap(err, "sdk connect url=%s, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
} }
if ((ret = sdk->publish()) != ERROR_SUCCESS) { if ((err = sdk->publish()) != srs_success) {
return srs_error_new(ret, "sdk publish"); return srs_error_wrap(err, "sdk publish");
} }
if ((err = hub->on_forwarder_start(this)) != srs_success) { 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 #define SYS_MAX_FORWARD_SEND_MSGS 128
srs_error_t SrsForwarder::forward() srs_error_t SrsForwarder::forward()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS); sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS);
@ -289,13 +287,13 @@ srs_error_t SrsForwarder::forward()
// update sequence header // update sequence header
// TODO: FIXME: maybe need to zero the sequence header timestamp. // TODO: FIXME: maybe need to zero the sequence header timestamp.
if (sh_video) { if (sh_video) {
if ((ret = sdk->send_and_free_message(sh_video->copy())) != ERROR_SUCCESS) { if ((err = sdk->send_and_free_message(sh_video->copy())) != srs_success) {
return srs_error_new(ret, "send video sh"); return srs_error_wrap(err, "send video sh");
} }
} }
if (sh_audio) { if (sh_audio) {
if ((ret = sdk->send_and_free_message(sh_audio->copy())) != ERROR_SUCCESS) { if ((err = sdk->send_and_free_message(sh_audio->copy())) != srs_success) {
return srs_error_new(ret, "send audio sh"); return srs_error_wrap(err, "send audio sh");
} }
} }
@ -309,11 +307,12 @@ srs_error_t SrsForwarder::forward()
// read from client. // read from client.
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL;
ret = sdk->recv_message(&msg); err = sdk->recv_message(&msg);
if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) { if (err != srs_success && srs_error_code(err) != ERROR_SOCKET_TIMEOUT) {
return srs_error_new(ret, "receive control message"); return srs_error_wrap(err, "receive control message");
} }
srs_error_reset(err);
srs_freep(msg); srs_freep(msg);
} }
@ -336,8 +335,8 @@ srs_error_t SrsForwarder::forward()
} }
// sendout messages, all messages are freed by send_and_free_messages(). // sendout messages, all messages are freed by send_and_free_messages().
if ((ret = sdk->send_and_free_messages(msgs.msgs, count)) != ERROR_SUCCESS) { if ((err = sdk->send_and_free_messages(msgs.msgs, count)) != srs_success) {
return srs_error_new(ret, "send messages"); return srs_error_wrap(err, "send messages");
} }
} }

View file

@ -41,15 +41,15 @@ public:
SrsHds(); SrsHds();
virtual ~SrsHds(); virtual ~SrsHds();
int on_publish(SrsRequest* req); srs_error_t on_publish(SrsRequest* req);
int on_unpublish(); srs_error_t on_unpublish();
int on_video(SrsSharedPtrMessage* msg); srs_error_t on_video(SrsSharedPtrMessage* msg);
int on_audio(SrsSharedPtrMessage* msg); srs_error_t on_audio(SrsSharedPtrMessage* msg);
private: private:
int flush_mainfest(); srs_error_t flush_mainfest();
int flush_bootstrap(); srs_error_t flush_bootstrap();
void adjust_windows(); void adjust_windows();
private: private:

View file

@ -46,15 +46,23 @@ SrsHttpHeartbeat::~SrsHttpHeartbeat()
void SrsHttpHeartbeat::heartbeat() 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; srs_error_t err = srs_success;
std::string url = _srs_config->get_heartbeat_url(); std::string url = _srs_config->get_heartbeat_url();
SrsHttpUri uri; SrsHttpUri uri;
if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { if ((err = uri.initialize(url)) != srs_success) {
srs_error("http uri parse hartbeart url failed. url=%s, ret=%d", url.c_str(), ret); return srs_error_wrap(err, "http uri parse hartbeart url failed. url=%s", url.c_str());
return;
} }
std::string ip = ""; std::string ip = "";
@ -80,30 +88,21 @@ void SrsHttpHeartbeat::heartbeat()
SrsHttpClient http; SrsHttpClient http;
if ((err = http.initialize(uri.get_host(), uri.get_port())) != srs_success) { if ((err = http.initialize(uri.get_host(), uri.get_port())) != srs_success) {
srs_freep(err); return srs_error_wrap(err, "init uri=%s", uri.get_url().c_str());
return;
} }
std::string req = obj->dumps(); std::string req = obj->dumps();
ISrsHttpMessage* msg = NULL; ISrsHttpMessage* msg = NULL;
if ((err = http.post(uri.get_path(), req, &msg)) != srs_success) { if ((err = http.post(uri.get_path(), req, &msg)) != srs_success) {
// TODO: FIXME: Use error return srs_error_wrap(err, "http post hartbeart uri failed. url=%s, request=%s", url.c_str(), req.c_str());
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;
} }
SrsAutoFree(ISrsHttpMessage, msg); SrsAutoFree(ISrsHttpMessage, msg);
std::string res; std::string res;
if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) { if ((err = msg->body_read_all(res)) != srs_success) {
return; return srs_error_wrap(err, "read body");
} }
srs_info("http hook hartbeart success. url=%s, request=%s, response=%s, ret=%d", return err;
url.c_str(), req.c_str(), res.c_str(), ret);
return;
} }

View file

@ -37,6 +37,8 @@ public:
virtual ~SrsHttpHeartbeat(); virtual ~SrsHttpHeartbeat();
public: public:
virtual void heartbeat(); virtual void heartbeat();
private:
virtual srs_error_t do_heartbeat();
}; };
#endif #endif

View file

@ -107,7 +107,6 @@ srs_error_t SrsDvrAsyncCallOnHls::call()
SrsConfDirective* conf = _srs_config->get_vhost_on_hls(req->vhost); SrsConfDirective* conf = _srs_config->get_vhost_on_hls(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_hls");
return err; return err;
} }
@ -158,7 +157,6 @@ srs_error_t SrsDvrAsyncCallOnHlsNotify::call()
SrsConfDirective* conf = _srs_config->get_vhost_on_hls_notify(req->vhost); SrsConfDirective* conf = _srs_config->get_vhost_on_hls_notify(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_hls_notify");
return err; 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) { if ((err = srs_create_dir_recursively(m3u8_dir)) != srs_success) {
return srs_error_wrap(err, "create dir"); return srs_error_wrap(err, "create dir");
} }
srs_info("create m3u8 dir %s ok", m3u8_dir.c_str());
return err; return err;
} }
@ -322,13 +319,10 @@ srs_error_t SrsHlsMuxer::segment_open()
std::string default_acodec_str = _srs_config->get_hls_acodec(req->vhost); std::string default_acodec_str = _srs_config->get_hls_acodec(req->vhost);
if (default_acodec_str == "mp3") { if (default_acodec_str == "mp3") {
default_acodec = SrsAudioCodecIdMP3; default_acodec = SrsAudioCodecIdMP3;
srs_info("hls: use default mp3 acodec");
} else if (default_acodec_str == "aac") { } else if (default_acodec_str == "aac") {
default_acodec = SrsAudioCodecIdAAC; default_acodec = SrsAudioCodecIdAAC;
srs_info("hls: use default aac acodec");
} else if (default_acodec_str == "an") { } else if (default_acodec_str == "an") {
default_acodec = SrsAudioCodecIdDisabled; default_acodec = SrsAudioCodecIdDisabled;
srs_info("hls: use default an acodec for pure video");
} else { } else {
srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str()); 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); std::string default_vcodec_str = _srs_config->get_hls_vcodec(req->vhost);
if (default_vcodec_str == "h264") { if (default_vcodec_str == "h264") {
default_vcodec = SrsVideoCodecIdAVC; default_vcodec = SrsVideoCodecIdAVC;
srs_info("hls: use default h264 vcodec");
} else if (default_vcodec_str == "vn") { } else if (default_vcodec_str == "vn") {
default_vcodec = SrsVideoCodecIdDisabled; default_vcodec = SrsVideoCodecIdDisabled;
srs_info("hls: use default vn vcodec for pure audio");
} else { } else {
srs_warn("hls: use h264 for other codec=%s", default_vcodec_str.c_str()); 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()); ts_file = srs_string_replace(ts_file, "[seq]", ss.str());
} }
current->set_path(hls_path + "/" + ts_file); 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. // the ts url, relative or absolute url.
// TODO: FIXME: Use url and path manager. // 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) { if ((err = current->tscw->open(tmp_file.c_str())) != srs_success) {
return srs_error_wrap(err, "open hls muxer"); 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; return err;
} }
@ -459,8 +449,6 @@ bool SrsHlsMuxer::is_segment_overflow()
// use N% deviation, to smoother. // use N% deviation, to smoother.
double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0.0; 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; return current->duration() >= (hls_fragment + deviation) * 1000;
} }
@ -482,8 +470,6 @@ bool SrsHlsMuxer::is_segment_absolutely_overflow()
// use N% deviation, to smoother. // use N% deviation, to smoother.
double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0.0; 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; 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) { if ((err = async->execute(new SrsDvrAsyncCallOnHlsNotify(_srs_context->get_id(), req, current->uri))) != srs_success) {
return srs_error_wrap(err, "segment close"); 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. // close the muxer of finished segment.
srs_freep(current->tscw); srs_freep(current->tscw);
@ -646,7 +631,6 @@ srs_error_t SrsHlsMuxer::refresh_m3u8()
srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file) srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// no segments, return. // no segments, return.
@ -655,10 +639,9 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
} }
SrsFileWriter writer; SrsFileWriter writer;
if ((ret = writer.open(m3u8_file)) != ERROR_SUCCESS) { if ((err = writer.open(m3u8_file)) != srs_success) {
return srs_error_new(ret, "hls: open m3u8 file %s", m3u8_file.c_str()); 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 // #EXTM3U\n
// #EXT-X-VERSION:3\n // #EXT-X-VERSION:3\n
@ -667,12 +650,10 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
ss << "#EXTM3U" << SRS_CONSTS_LF ss << "#EXTM3U" << SRS_CONSTS_LF
<< "#EXT-X-VERSION:3" << SRS_CONSTS_LF << "#EXT-X-VERSION:3" << SRS_CONSTS_LF
<< "#EXT-X-ALLOW-CACHE:YES" << SRS_CONSTS_LF; << "#EXT-X-ALLOW-CACHE:YES" << SRS_CONSTS_LF;
srs_verbose("write m3u8 header success.");
// #EXT-X-MEDIA-SEQUENCE:4294967295\n // #EXT-X-MEDIA-SEQUENCE:4294967295\n
SrsHlsSegment* first = dynamic_cast<SrsHlsSegment*>(segments->first()); SrsHlsSegment* first = dynamic_cast<SrsHlsSegment*>(segments->first());
ss << "#EXT-X-MEDIA-SEQUENCE:" << first->sequence_no << SRS_CONSTS_LF; 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. // iterator shared for td generation and segemnts wrote.
std::vector<SrsHlsSegment*>::iterator it; std::vector<SrsHlsSegment*>::iterator it;
@ -691,7 +672,6 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
target_duration = srs_max(target_duration, max_td); target_duration = srs_max(target_duration, max_td);
ss << "#EXT-X-TARGETDURATION:" << target_duration << SRS_CONSTS_LF; ss << "#EXT-X-TARGETDURATION:" << target_duration << SRS_CONSTS_LF;
srs_verbose("write m3u8 duration success.");
// write all segments // write all segments
for (int i = 0; i < segments->size(); i++) { 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()) { if (segment->is_sequence_header()) {
// #EXT-X-DISCONTINUITY\n // #EXT-X-DISCONTINUITY\n
ss << "#EXT-X-DISCONTINUITY" << SRS_CONSTS_LF; ss << "#EXT-X-DISCONTINUITY" << SRS_CONSTS_LF;
srs_verbose("write m3u8 segment discontinuity success.");
} }
// "#EXTINF:4294967295.208,\n" // "#EXTINF:4294967295.208,\n"
ss.precision(3); ss.precision(3);
ss.setf(std::ios::fixed, std::ios::floatfield); ss.setf(std::ios::fixed, std::ios::floatfield);
ss << "#EXTINF:" << segment->duration() / 1000.0 << ", no desc" << SRS_CONSTS_LF; ss << "#EXTINF:" << segment->duration() / 1000.0 << ", no desc" << SRS_CONSTS_LF;
srs_verbose("write m3u8 segment info success.");
// {file name}\n // {file name}\n
ss << segment->uri << SRS_CONSTS_LF; ss << segment->uri << SRS_CONSTS_LF;
srs_verbose("write m3u8 segment uri success.");
} }
// write m3u8 to writer. // write m3u8 to writer.
std::string m3u8 = ss.str(); std::string m3u8 = ss.str();
if ((ret = writer.write((char*)m3u8.c_str(), (int)m3u8.length(), NULL)) != ERROR_SUCCESS) { if ((err = writer.write((char*)m3u8.c_str(), (int)m3u8.length(), NULL)) != srs_success) {
return srs_error_new(ret, "hls: write m3u8"); return srs_error_wrap(err, "hls: write m3u8");
} }
srs_info("write m3u8 %s success.", m3u8_file.c_str());
return err; return err;
} }

View file

@ -40,7 +40,7 @@ public:
/** /**
* notify the handler, the type and tick. * 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 @@ public:
// add a pair of tick(type, interval). // add a pair of tick(type, interval).
// @param type the type of tick. // @param type the type of tick.
// @param interval the interval in ms 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: public:
// cycle the hourglass, which will sleep resolution every time. // cycle the hourglass, which will sleep resolution every time.
// and call handler when ticked. // and call handler when ticked.
virtual int cycle(); virtual srs_error_t cycle();
}; };
#endif #endif

View file

@ -48,7 +48,6 @@ using namespace std;
srs_error_t srs_api_response_jsonp(ISrsHttpResponseWriter* w, string callback, string data) srs_error_t srs_api_response_jsonp(ISrsHttpResponseWriter* w, string callback, string data)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsHttpHeader* h = w->header(); 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_length(data.length() + callback.length() + 2);
h->set_content_type("text/javascript"); h->set_content_type("text/javascript");
if (!callback.empty() && (ret = w->write((char*)callback.data(), (int)callback.length())) != ERROR_SUCCESS) { if (!callback.empty() && (err = w->write((char*)callback.data(), (int)callback.length())) != srs_success) {
return srs_error_new(ret, "write jsonp callback"); return srs_error_wrap(err, "write jsonp callback");
} }
static char* c0 = (char*)"("; static char* c0 = (char*)"(";
if ((ret = w->write(c0, 1)) != ERROR_SUCCESS) { if ((err = w->write(c0, 1)) != srs_success) {
return srs_error_new(ret, "write jsonp left token"); return srs_error_wrap(err, "write jsonp left token");
} }
if ((ret = w->write((char*)data.data(), (int)data.length())) != ERROR_SUCCESS) { if ((err = w->write((char*)data.data(), (int)data.length())) != srs_success) {
return srs_error_new(ret, "write jsonp data"); return srs_error_wrap(err, "write jsonp data");
} }
static char* c1 = (char*)")"; static char* c1 = (char*)")";
if ((ret = w->write(c1, 1)) != ERROR_SUCCESS) { if ((err = w->write(c1, 1)) != srs_success) {
return srs_error_new(ret, "write jsonp right token"); return srs_error_wrap(err, "write jsonp right token");
} }
return err; 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) srs_error_t srs_api_response_json(ISrsHttpResponseWriter* w, string data)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsHttpHeader* h = w->header(); 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_length(data.length());
h->set_content_type("application/json"); h->set_content_type("application/json");
if ((ret = w->write((char*)data.data(), (int)data.length())) != ERROR_SUCCESS) { if ((err = w->write((char*)data.data(), (int)data.length())) != srs_success) {
return srs_error_new(ret, "write json"); return srs_error_wrap(err, "write json");
} }
return err; return err;
@ -716,7 +714,7 @@ SrsGoApiVhosts::~SrsGoApiVhosts()
srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{ {
int ret = ERROR_SUCCESS; srs_error_t err = srs_success;
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
@ -726,9 +724,7 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
SrsStatisticVhost* vhost = NULL; SrsStatisticVhost* vhost = NULL;
if (vid > 0 && (vhost = stat->find_vhost(vid)) == NULL) { if (vid > 0 && (vhost = stat->find_vhost(vid)) == NULL) {
ret = ERROR_RTMP_VHOST_NOT_FOUND; return srs_api_response_code(w, r, ERROR_RTMP_VHOST_NOT_FOUND);
srs_error("vhost id=%d not found. ret=%d", vid, ret);
return srs_api_response_code(w, r, ret);
} }
SrsJsonObject* obj = SrsJsonAny::object(); SrsJsonObject* obj = SrsJsonAny::object();
@ -742,15 +738,19 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
SrsJsonArray* data = SrsJsonAny::array(); SrsJsonArray* data = SrsJsonAny::array();
obj->set("vhosts", data); obj->set("vhosts", data);
if ((ret = stat->dumps_vhosts(data)) != ERROR_SUCCESS) { if ((err = stat->dumps_vhosts(data)) != srs_success) {
return srs_api_response_code(w, r, ret); int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else { } else {
SrsJsonObject* data = SrsJsonAny::object(); SrsJsonObject* data = SrsJsonAny::object();
obj->set("vhost", data);; obj->set("vhost", data);;
if ((ret = vhost->dumps(data)) != ERROR_SUCCESS) { if ((err = vhost->dumps(data)) != srs_success) {
return srs_api_response_code(w, r, ret); int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} }
} else { } else {
@ -770,7 +770,7 @@ SrsGoApiStreams::~SrsGoApiStreams()
srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{ {
int ret = ERROR_SUCCESS; srs_error_t err = srs_success;
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
@ -780,9 +780,7 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsStatisticStream* stream = NULL; SrsStatisticStream* stream = NULL;
if (sid >= 0 && (stream = stat->find_stream(sid)) == NULL) { if (sid >= 0 && (stream = stat->find_stream(sid)) == NULL) {
ret = ERROR_RTMP_STREAM_NOT_FOUND; return srs_api_response_code(w, r, ERROR_RTMP_STREAM_NOT_FOUND);
srs_error("stream id=%d not found. ret=%d", sid, ret);
return srs_api_response_code(w, r, ret);
} }
SrsJsonObject* obj = SrsJsonAny::object(); SrsJsonObject* obj = SrsJsonAny::object();
@ -796,15 +794,19 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsJsonArray* data = SrsJsonAny::array(); SrsJsonArray* data = SrsJsonAny::array();
obj->set("streams", data); obj->set("streams", data);
if ((ret = stat->dumps_streams(data)) != ERROR_SUCCESS) { if ((err = stat->dumps_streams(data)) != srs_success) {
return srs_api_response_code(w, r, ret); int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else { } else {
SrsJsonObject* data = SrsJsonAny::object(); SrsJsonObject* data = SrsJsonAny::object();
obj->set("stream", data);; obj->set("stream", data);;
if ((ret = stream->dumps(data)) != ERROR_SUCCESS) { if ((err = stream->dumps(data)) != srs_success) {
return srs_api_response_code(w, r, ret); int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} }
} else { } else {
@ -824,7 +826,7 @@ SrsGoApiClients::~SrsGoApiClients()
srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{ {
int ret = ERROR_SUCCESS; srs_error_t err = srs_success;
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
@ -834,9 +836,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsStatisticClient* client = NULL; SrsStatisticClient* client = NULL;
if (cid >= 0 && (client = stat->find_client(cid)) == NULL) { if (cid >= 0 && (client = stat->find_client(cid)) == NULL) {
ret = ERROR_RTMP_CLIENT_NOT_FOUND; return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
srs_error("client id=%d not found. ret=%d", cid, ret);
return srs_api_response_code(w, r, ret);
} }
SrsJsonObject* obj = SrsJsonAny::object(); SrsJsonObject* obj = SrsJsonAny::object();
@ -854,22 +854,24 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
std::string rcount = r->query_get("count"); std::string rcount = r->query_get("count");
int start = srs_max(0, atoi(rstart.c_str())); int start = srs_max(0, atoi(rstart.c_str()));
int count = srs_max(10, atoi(rcount.c_str())); int count = srs_max(10, atoi(rcount.c_str()));
if ((ret = stat->dumps_clients(data, start, count)) != ERROR_SUCCESS) { if ((err = stat->dumps_clients(data, start, count)) != srs_success) {
return srs_api_response_code(w, r, ret); int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else { } else {
SrsJsonObject* data = SrsJsonAny::object(); SrsJsonObject* data = SrsJsonAny::object();
obj->set("client", data);; obj->set("client", data);;
if ((ret = client->dumps(data)) != ERROR_SUCCESS) { if ((err = client->dumps(data)) != srs_success) {
return srs_api_response_code(w, r, ret); int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} }
} else if (r->is_http_delete()) { } else if (r->is_http_delete()) {
if (!client) { if (!client) {
ret = ERROR_RTMP_CLIENT_NOT_FOUND; return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
srs_error("client id=%d not found. ret=%d", cid, ret);
return srs_api_response_code(w, r, ret);
} }
client->conn->expire(); client->conn->expire();
@ -900,7 +902,6 @@ SrsGoApiRaw::~SrsGoApiRaw()
srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
std::string rpc = r->query_get("rpc"); 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. // for rpc=raw, to query the raw api config for http api.
if (rpc == "raw") { if (rpc == "raw") {
// query global scope. // query global scope.
if ((ret = _srs_config->raw_to_json(obj)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_to_json(obj)) != srs_success) {
srs_error("raw api rpc raw failed. ret=%d", ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
return srs_api_response(w, r, obj->dumps()); 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. // whether enabled the HTTP RAW API.
if (!raw_api) { if (!raw_api) {
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED);
srs_warn("raw api disabled. ret=%d", ret);
return srs_api_response_code(w, r, ret);
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// the rpc is required. // the rpc is required.
// the allowd rpc method check. // the allowd rpc method check.
if (rpc.empty() || (rpc != "reload" && rpc != "query" && rpc != "raw" && rpc != "update")) { if (rpc.empty() || (rpc != "reload" && rpc != "query" && rpc != "raw" && rpc != "update")) {
ret = ERROR_SYSTEM_CONFIG_RAW; return srs_api_response_code(w, r, 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);
} }
// for rpc=reload, trigger the server to reload the config. // for rpc=reload, trigger the server to reload the config.
if (rpc == "reload") { if (rpc == "reload") {
if (!allow_reload) { if (!allow_reload) {
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; return srs_api_response_code(w, r, 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);
} }
srs_trace("raw api trigger reload. ret=%d", ret);
server->on_signal(SRS_SIGNAL_RELOAD); 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. // 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__ // for the default vhost, must be __defaultVhost__
if (rpc == "query") { if (rpc == "query") {
if (!allow_query) { if (!allow_query) {
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; return srs_api_response_code(w, r, 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);
} }
std::string scope = r->query_get("scope"); std::string scope = r->query_get("scope");
std::string vhost = r->query_get("vhost"); std::string vhost = r->query_get("vhost");
if (scope.empty() || (scope != "global" && scope != "vhost" && scope != "minimal")) { if (scope.empty() || (scope != "global" && scope != "vhost" && scope != "minimal")) {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; return srs_api_response_code(w, r, 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);
} }
if (scope == "vhost") { if (scope == "vhost") {
// query vhost scope. // query vhost scope.
if (vhost.empty()) { if (vhost.empty()) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
SrsConfDirective* root = _srs_config->get_root(); SrsConfDirective* root = _srs_config->get_root();
SrsConfDirective* conf = root->get("vhost", vhost); SrsConfDirective* conf = root->get("vhost", vhost);
if (!conf) { if (!conf) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
SrsJsonObject* data = SrsJsonAny::object(); SrsJsonObject* data = SrsJsonAny::object();
obj->set("vhost", data); obj->set("vhost", data);
if ((ret = _srs_config->vhost_to_json(conf, data)) != ERROR_SUCCESS) { if ((err = _srs_config->vhost_to_json(conf, data)) != srs_success) {
srs_error("raw api query vhost failed. ret=%d", ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "minimal") { } else if (scope == "minimal") {
SrsJsonObject* data = SrsJsonAny::object(); SrsJsonObject* data = SrsJsonAny::object();
obj->set("minimal", data); obj->set("minimal", data);
// query minimal scope. // query minimal scope.
if ((ret = _srs_config->minimal_to_json(data)) != ERROR_SUCCESS) { if ((err = _srs_config->minimal_to_json(data)) != srs_success) {
srs_error("raw api query global failed. ret=%d", ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else { } else {
SrsJsonObject* data = SrsJsonAny::object(); SrsJsonObject* data = SrsJsonAny::object();
obj->set("global", data); obj->set("global", data);
// query global scope. // query global scope.
if ((ret = _srs_config->global_to_json(data)) != ERROR_SUCCESS) { if ((err = _srs_config->global_to_json(data)) != srs_success) {
srs_error("raw api query global failed. ret=%d", ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); 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 // dvr ossrs.net disable live/livestream disable the dvr of stream
if (rpc == "update") { if (rpc == "update") {
if (!allow_update) { if (!allow_update) {
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; return srs_api_response_code(w, r, 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);
} }
std::string scope = r->query_get("scope"); std::string scope = r->query_get("scope");
std::string value = r->query_get("value"); std::string value = r->query_get("value");
if (scope.empty()) { if (scope.empty()) {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; return srs_api_response_code(w, r, 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);
} }
if (scope != "listen" && scope != "pid" && scope != "chunk_size" if (scope != "listen" && scope != "pid" && scope != "chunk_size"
&& scope != "ff_log_dir" && scope != "srs_log_tank" && scope != "srs_log_level" && scope != "ff_log_dir" && scope != "srs_log_tank" && scope != "srs_log_level"
&& scope != "srs_log_file" && scope != "max_connections" && scope != "utc_time" && scope != "srs_log_file" && scope != "max_connections" && scope != "utc_time"
&& scope != "pithy_print_ms" && scope != "vhost" && scope != "dvr" && scope != "pithy_print_ms" && scope != "vhost" && scope != "dvr"
) { ) {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; return srs_api_response_code(w, r, 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);
} }
bool applied = false; bool applied = false;
@ -1081,99 +1065,89 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
} }
} }
if (invalid) { if (invalid) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_listen(eps, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_listen(eps, applied)) != srs_success) {
srs_error("raw api update listen=%s failed. ret=%d", value.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "pid") { } else if (scope == "pid") {
if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".pid")) { if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".pid")) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_pid(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_pid(value, applied)) != srs_success) {
srs_error("raw api update pid=%s failed. ret=%d", value.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "chunk_size") { } else if (scope == "chunk_size") {
int csv = ::atoi(value.c_str()); int csv = ::atoi(value.c_str());
if (csv < 128 || csv > 65535 || !srs_is_digit_number(value)) { if (csv < 128 || csv > 65535 || !srs_is_digit_number(value)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_chunk_size(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_chunk_size(value, applied)) != srs_success) {
srs_error("raw api update chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "ff_log_dir") { } else if (scope == "ff_log_dir") {
if (value.empty() || (value != "/dev/null" && !srs_string_starts_with(value, "./", "/tmp/", "/var/"))) { if (value.empty() || (value != "/dev/null" && !srs_string_starts_with(value, "./", "/tmp/", "/var/"))) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_ff_log_dir(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_ff_log_dir(value, applied)) != srs_success) {
srs_error("raw api update ff_log_dir=%s failed. ret=%d", value.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "srs_log_tank") { } else if (scope == "srs_log_tank") {
if (value.empty() || (value != "file" && value != "console")) { if (value.empty() || (value != "file" && value != "console")) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_srs_log_tank(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_srs_log_tank(value, applied)) != srs_success) {
srs_error("raw api update srs_log_tank=%s failed. ret=%d", value.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "srs_log_level") { } else if (scope == "srs_log_level") {
if (value != "verbose" && value != "info" && value != "trace" && value != "warn" && value != "error") { if (value != "verbose" && value != "info" && value != "trace" && value != "warn" && value != "error") {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_srs_log_level(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_srs_log_level(value, applied)) != srs_success) {
srs_error("raw api update srs_log_level=%s failed. ret=%d", value.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "srs_log_file") { } else if (scope == "srs_log_file") {
if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".log")) { if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".log")) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_srs_log_file(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_srs_log_file(value, applied)) != srs_success) {
srs_error("raw api update srs_log_file=%s failed. ret=%d", value.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "max_connections") { } else if (scope == "max_connections") {
int mcv = ::atoi(value.c_str()); int mcv = ::atoi(value.c_str());
if (mcv < 10 || mcv > 65535 || !srs_is_digit_number(value)) { if (mcv < 10 || mcv > 65535 || !srs_is_digit_number(value)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_max_connections(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_max_connections(value, applied)) != srs_success) {
srs_error("raw api update max_connections=%s/%d failed. ret=%d", value.c_str(), mcv, ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "utc_time") { } else if (scope == "utc_time") {
if (!srs_is_boolean(value)) { if (!srs_is_boolean(value)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((err = _srs_config->raw_set_utc_time(srs_config_bool2switch(value), applied)) != srs_success) { 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") { } else if (scope == "pithy_print_ms") {
int ppmv = ::atoi(value.c_str()); int ppmv = ::atoi(value.c_str());
if (ppmv < 100 || ppmv > 300000 || !srs_is_digit_number(value)) { if (ppmv < 100 || ppmv > 300000 || !srs_is_digit_number(value)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_set_pithy_print_ms(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_set_pithy_print_ms(value, applied)) != srs_success) {
srs_error("raw api update pithy_print_ms=%s/%d failed. ret=%d", value.c_str(), ppmv, ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (scope == "vhost") { } else if (scope == "vhost") {
std::string param = r->query_get("param"); std::string param = r->query_get("param");
std::string data = r->query_get("data"); std::string data = r->query_get("data");
if (param != "create" && param != "update" && param != "delete" && param != "disable" && param != "enable") { if (param != "create" && param != "update" && param != "delete" && param != "disable" && param != "enable") {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; return srs_api_response_code(w, r, 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);
} }
extra += " " + param; extra += " " + param;
if (param == "create") { if (param == "create") {
// when create, the vhost must not exists. // when create, the vhost must not exists.
if (param.empty() || _srs_config->get_vhost(value, false)) { if (param.empty() || _srs_config->get_vhost(value, false)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_create_vhost(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_create_vhost(value, applied)) != srs_success) {
srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (param == "update") { } else if (param == "update") {
extra += " to " + data; extra += " to " + data;
@ -1219,53 +1189,49 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
// when update, the vhost must exists and disabled. // when update, the vhost must exists and disabled.
SrsConfDirective* vhost = _srs_config->get_vhost(value, false); SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
if (data.empty() || data == value || param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { if (data.empty() || data == value || param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_update_vhost(value, data, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_update_vhost(value, data, applied)) != srs_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); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (param == "delete") { } else if (param == "delete") {
// when delete, the vhost must exists and disabled. // when delete, the vhost must exists and disabled.
SrsConfDirective* vhost = _srs_config->get_vhost(value, false); SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_delete_vhost(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_delete_vhost(value, applied)) != srs_success) {
srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (param == "disable") { } else if (param == "disable") {
// when disable, the vhost must exists and enabled. // when disable, the vhost must exists and enabled.
SrsConfDirective* vhost = _srs_config->get_vhost(value, false); SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
if (param.empty() || !vhost || !_srs_config->get_vhost_enabled(vhost)) { if (param.empty() || !vhost || !_srs_config->get_vhost_enabled(vhost)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_disable_vhost(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_disable_vhost(value, applied)) != srs_success) {
srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else if (param == "enable") { } else if (param == "enable") {
// when enable, the vhost must exists and disabled. // when enable, the vhost must exists and disabled.
SrsConfDirective* vhost = _srs_config->get_vhost(value, false); SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) { if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; return srs_api_response_code(w, r, 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);
} }
if ((ret = _srs_config->raw_enable_vhost(value, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_enable_vhost(value, applied)) != srs_success) {
srs_error("raw api update vhost=%s, param=%s failed. ret=%d", value.c_str(), param.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else { } else {
// TODO: support other param. // TODO: support other param.
@ -1276,26 +1242,24 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
extra += "/" + stream + " to " + action; extra += "/" + stream + " to " + action;
if (action != "enable" && action != "disable") { if (action != "enable" && action != "disable") {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; return srs_api_response_code(w, r, 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);
} }
if (!_srs_config->get_dvr_enabled(value)) { if (!_srs_config->get_dvr_enabled(value)) {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; return srs_api_response_code(w, r, 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);
} }
if (action == "enable") { if (action == "enable") {
if ((ret = _srs_config->raw_enable_dvr(value, stream, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_enable_dvr(value, stream, applied)) != srs_success) {
srs_error("raw api update dvr=%s/%s, param=%s failed. ret=%d", value.c_str(), stream.c_str(), action.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} else { } else {
if ((ret = _srs_config->raw_disable_dvr(value, stream, applied)) != ERROR_SUCCESS) { if ((err = _srs_config->raw_disable_dvr(value, stream, applied)) != srs_success) {
srs_error("raw api update dvr=%s/%s, param=%s failed. ret=%d", value.c_str(), stream.c_str(), action.c_str(), ret); int code = srs_error_code(err);
return srs_api_response_code(w, r, ret); srs_error_reset(err);
return srs_api_response_code(w, r, code);
} }
} }
} else { } else {
@ -1381,14 +1345,13 @@ void SrsHttpApi::cleanup()
srs_error_t SrsHttpApi::do_cycle() srs_error_t SrsHttpApi::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_trace("api get peer ip success. ip=%s", ip.c_str()); srs_trace("api get peer ip success. ip=%s", ip.c_str());
// initialize parser // initialize parser
if ((ret = parser->initialize(HTTP_REQUEST, true)) != ERROR_SUCCESS) { if ((err = parser->initialize(HTTP_REQUEST, true)) != srs_success) {
return srs_error_new(ret, "init parser"); return srs_error_wrap(err, "init parser");
} }
// set the recv timeout, for some clients never disconnect the connection. // set the recv timeout, for some clients never disconnect the connection.
@ -1406,8 +1369,8 @@ srs_error_t SrsHttpApi::do_cycle()
ISrsHttpMessage* req = NULL; ISrsHttpMessage* req = NULL;
// get a http message // get a http message
if ((ret = parser->parse_message(skt, this, &req)) != ERROR_SUCCESS) { if ((err = parser->parse_message(skt, this, &req)) != srs_success) {
return srs_error_new(ret, "parse message"); return srs_error_wrap(err, "parse message");
} }
// if SUCCESS, always NOT-NULL. // if SUCCESS, always NOT-NULL.
@ -1426,8 +1389,8 @@ srs_error_t SrsHttpApi::do_cycle()
char buf[SRS_HTTP_READ_CACHE_BYTES]; char buf[SRS_HTTP_READ_CACHE_BYTES];
ISrsHttpResponseReader* br = req->body_reader(); ISrsHttpResponseReader* br = req->body_reader();
while (!br->eof()) { while (!br->eof()) {
if ((ret = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != ERROR_SUCCESS) { if ((err = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != srs_success) {
return srs_error_new(ret, "read response"); return srs_error_wrap(err, "read response");
} }
} }

View file

@ -97,14 +97,13 @@ void SrsHttpConn::cleanup()
srs_error_t SrsHttpConn::do_cycle() srs_error_t SrsHttpConn::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_trace("HTTP client ip=%s", ip.c_str()); srs_trace("HTTP client ip=%s", ip.c_str());
// initialize parser // initialize parser
if ((ret = parser->initialize(HTTP_REQUEST, false)) != ERROR_SUCCESS) { if ((err = parser->initialize(HTTP_REQUEST, false)) != srs_success) {
return srs_error_new(ret, "init parser"); return srs_error_wrap(err, "init parser");
} }
// set the recv timeout, for some clients never disconnect the connection. // set the recv timeout, for some clients never disconnect the connection.
@ -125,7 +124,7 @@ srs_error_t SrsHttpConn::do_cycle()
ISrsHttpMessage* req = NULL; ISrsHttpMessage* req = NULL;
// get a http message // 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; break;
} }
@ -212,7 +211,6 @@ SrsResponseOnlyHttpConn::~SrsResponseOnlyHttpConn()
srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq) srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsStSocket skt; SrsStSocket skt;
@ -221,8 +219,8 @@ srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq)
return srs_error_wrap(err, "init socket"); return srs_error_wrap(err, "init socket");
} }
if ((ret = parser->parse_message(&skt, this, preq)) != ERROR_SUCCESS) { if ((err = parser->parse_message(&skt, this, preq)) != srs_success) {
return srs_error_new(ret, "parse message"); return srs_error_wrap(err, "parse message");
} }
return err; return err;
@ -230,7 +228,6 @@ srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq)
srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg) srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
ISrsHttpResponseReader* br = msg->body_reader(); ISrsHttpResponseReader* br = msg->body_reader();
@ -243,8 +240,8 @@ srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg)
// drop all request body. // drop all request body.
while (!br->eof()) { while (!br->eof()) {
char body[4096]; char body[4096];
if ((ret = br->read(body, 4096, NULL)) != ERROR_SUCCESS) { if ((err = br->read(body, 4096, NULL)) != srs_success) {
return srs_error_new(ret, "read response"); 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); 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); return http_stream->http_mount(s, r);
} }

View file

@ -131,7 +131,7 @@ public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
// http flv/ts/mp3/aac stream // http flv/ts/mp3/aac stream
public: 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); virtual void http_unmount(SrsSource* s, SrsRequest* r);
}; };

View file

@ -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) 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; srs_error_t err = srs_success;
int client_id = cid; 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(); int64_t starttime = srs_update_system_time_ms();
SrsHttpUri uri; SrsHttpUri uri;
if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { if ((err = uri.initialize(url)) != srs_success) {
return srs_error_new(ret, "http: init url=%s", url.c_str()); return srs_error_wrap(err, "http: init url=%s", url.c_str());
} }
SrsHttpClient http; 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(); ISrsHttpResponseReader* br = msg->body_reader();
while (nb_read < nb_notify && !br->eof()) { while (nb_read < nb_notify && !br->eof()) {
int nb_bytes = 0; 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; break;
} }
nb_read += nb_bytes; nb_read += nb_bytes;
} }
int spenttime = (int)(srs_update_system_time_ms() - starttime); 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", 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, ret); client_id, url.c_str(), msg->status_code(), spenttime, nb_read, srs_error_desc(err).c_str());
// ignore any error for on_hls_notify. // ignore any error for on_hls_notify.
ret = ERROR_SUCCESS; srs_error_reset(err);
return srs_success;
return err;
} }
srs_error_t SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::string req, int& code, string& res) 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; srs_error_t err = srs_success;
SrsHttpUri uri; SrsHttpUri uri;
if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { if ((err = uri.initialize(url)) != srs_success) {
return srs_error_new(ret, "http: post failed. url=%s", url.c_str()); 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) { 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); SrsAutoFree(ISrsHttpMessage, msg);
code = msg->status_code(); code = msg->status_code();
if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) { if ((err = msg->body_read_all(res)) != srs_success) {
return srs_error_new(ret, "http: body read"); return srs_error_wrap(err, "http: body read");
} }
// ensure the http status is ok. // ensure the http status is ok.

View file

@ -102,7 +102,8 @@ public:
* @param duration the segment duration in seconds. * @param duration the segment duration in seconds.
* @param cid the source connection cid, for the on_dvr is async call. * @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. * when hls reap segment, callback.
* @param url the api server url, to process the event. * @param url the api server url, to process the event.

View file

@ -62,14 +62,13 @@ SrsVodStream::~SrsVodStream()
srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, string fullpath, int offset) 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; srs_error_t err = srs_success;
SrsFileReader fs; SrsFileReader fs;
// open flv file // open flv file
if ((ret = fs.open(fullpath)) != ERROR_SUCCESS) { if ((err = fs.open(fullpath)) != srs_success) {
return srs_error_new(ret, "open file"); return srs_error_wrap(err, "open file");
} }
if (offset > fs.filesize()) { if (offset > fs.filesize()) {
@ -80,16 +79,16 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
SrsFlvVodStreamDecoder ffd; SrsFlvVodStreamDecoder ffd;
// open fast decoder // open fast decoder
if ((ret = ffd.initialize(&fs)) != ERROR_SUCCESS) { if ((err = ffd.initialize(&fs)) != srs_success) {
return srs_error_new(ret, "init ffd"); return srs_error_wrap(err, "init ffd");
} }
// save header, send later. // save header, send later.
char flv_header[13]; char flv_header[13];
// send flv header // send flv header
if ((ret = ffd.read_header_ext(flv_header)) != ERROR_SUCCESS) { if ((err = ffd.read_header_ext(flv_header)) != srs_success) {
return srs_error_new(ret, "ffd read header"); return srs_error_wrap(err, "ffd read header");
} }
// save sequence header, send later // save sequence header, send later
@ -99,8 +98,8 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
if (true) { if (true) {
// send sequence header // send sequence header
int64_t start = 0; int64_t start = 0;
if ((ret = ffd.read_sequence_header_summary(&start, &sh_size)) != ERROR_SUCCESS) { if ((err = ffd.read_sequence_header_summary(&start, &sh_size)) != srs_success) {
return srs_error_new(ret, "ffd read sps"); return srs_error_wrap(err, "ffd read sps");
} }
if (sh_size <= 0) { if (sh_size <= 0) {
return srs_error_new(ERROR_HTTP_REMUX_SEQUENCE_HEADER, "no sequence, size=%d", sh_size); 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]; sh_data = new char[sh_size];
SrsAutoFreeA(char, sh_data); SrsAutoFreeA(char, sh_data);
if ((ret = fs.read(sh_data, sh_size, NULL)) != ERROR_SUCCESS) { if ((err = fs.read(sh_data, sh_size, NULL)) != srs_success) {
return srs_error_new(ret, "fs read"); return srs_error_wrap(err, "fs read");
} }
// seek to data offset // 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"); w->header()->set_content_type("video/x-flv");
// write flv header and sequence header. // write flv header and sequence header.
if ((ret = w->write(flv_header, sizeof(flv_header))) != ERROR_SUCCESS) { if ((err = w->write(flv_header, sizeof(flv_header))) != srs_success) {
return srs_error_new(ret, "write flv header"); return srs_error_wrap(err, "write flv header");
} }
if (sh_size > 0 && (ret = w->write(sh_data, sh_size)) != ERROR_SUCCESS) { if (sh_size > 0 && (err = w->write(sh_data, sh_size)) != srs_success) {
return srs_error_new(ret, "write sequence"); return srs_error_wrap(err, "write sequence");
} }
// write body. // write body.
if ((ret = ffd.seek2(offset)) != ERROR_SUCCESS) { if ((err = ffd.seek2(offset)) != srs_success) {
return srs_error_new(ret, "ffd seek"); return srs_error_wrap(err, "ffd seek");
} }
// send data // 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) 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_error_t err = srs_success;
srs_assert(start >= 0); srs_assert(start >= 0);
@ -151,8 +149,8 @@ srs_error_t SrsVodStream::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
SrsFileReader fs; SrsFileReader fs;
// open flv file // open flv file
if ((ret = fs.open(fullpath)) != ERROR_SUCCESS) { if ((err = fs.open(fullpath)) != srs_success) {
return srs_error_new(ret, "fs open"); return srs_error_wrap(err, "fs open");
} }
// parse -1 to whole file. // parse -1 to whole file.
@ -204,7 +202,6 @@ SrsHttpStaticServer::~SrsHttpStaticServer()
srs_error_t SrsHttpStaticServer::initialize() srs_error_t SrsHttpStaticServer::initialize()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
bool default_root_exists = false; bool default_root_exists = false;
@ -220,8 +217,8 @@ srs_error_t SrsHttpStaticServer::initialize()
string pmount; string pmount;
string vhost = conf->arg0(); string vhost = conf->arg0();
if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) { if ((err = mount_vhost(vhost, pmount)) != srs_success) {
return srs_error_new(ret, "mount vhost"); return srs_error_wrap(err, "mount vhost");
} }
if (pmount == "/") { if (pmount == "/") {
@ -243,19 +240,18 @@ srs_error_t SrsHttpStaticServer::initialize()
return err; 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; srs_error_t err = srs_success;
// when vhost disabled, ignore. // when vhost disabled, ignore.
if (!_srs_config->get_vhost_enabled(vhost)) { if (!_srs_config->get_vhost_enabled(vhost)) {
return ret; return err;
} }
// when vhost http_static disabled, ignore. // when vhost http_static disabled, ignore.
if (!_srs_config->get_vhost_http_enabled(vhost)) { if (!_srs_config->get_vhost_http_enabled(vhost)) {
return ret; return err;
} }
std::string mount = _srs_config->get_vhost_http_mount(vhost); 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. // mount the http of vhost.
if ((err = mux.handle(mount, new SrsVodStream(dir))) != srs_success) { if ((err = mux.handle(mount, new SrsVodStream(dir))) != srs_success) {
// TODO: FIXME: Use error. return srs_error_wrap(err, "mux handle");
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;
} }
srs_trace("http: vhost=%s mount to %s at %s", vhost.c_str(), mount.c_str(), dir.c_str()); srs_trace("http: vhost=%s mount to %s at %s", vhost.c_str(), mount.c_str(), dir.c_str());
pmount = mount; pmount = mount;
return ret; return err;
} }
srs_error_t SrsHttpStaticServer::on_reload_vhost_added(string vhost) srs_error_t SrsHttpStaticServer::on_reload_vhost_added(string vhost)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
string pmount; string pmount;
if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) { if ((err = mount_vhost(vhost, pmount)) != srs_success) {
return srs_error_new(ret, "mount vhost"); return srs_error_wrap(err, "mount vhost");
} }
return err; return err;

View file

@ -60,7 +60,7 @@ public:
public: public:
virtual srs_error_t initialize(); virtual srs_error_t initialize();
private: 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. // interface ISrsReloadHandler.
public: public:
virtual srs_error_t on_reload_vhost_added(std::string vhost); virtual srs_error_t on_reload_vhost_added(std::string vhost);

View file

@ -615,27 +615,27 @@ srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage
return err; 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++) { for (int i = 0; i < nb_msgs; i++) {
SrsSharedPtrMessage* msg = msgs[i]; SrsSharedPtrMessage* msg = msgs[i];
if (msg->is_audio()) { 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()) { } 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 { } 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) { if (err != srs_success) {
return ret; return srs_error_wrap(err, "send messages");
} }
} }
return ret; return err;
} }
SrsLiveEntry::SrsLiveEntry(std::string m) 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. // create stream from template when not found.
if (sflvs.find(sid) == sflvs.end()) { if (sflvs.find(sid) == sflvs.end()) {
if (tflvs.find(r->vhost) == tflvs.end()) { if (tflvs.find(r->vhost) == tflvs.end()) {
srs_info("ignore mount flv stream for disabled"); return err;
return ret;
} }
SrsLiveEntry* tmpl = tflvs[r->vhost]; SrsLiveEntry* tmpl = tflvs[r->vhost];
@ -797,7 +796,6 @@ void SrsHttpStreamServer::http_unmount(SrsSource* s, SrsRequest* r)
std::string sid = r->get_stream_url(); std::string sid = r->get_stream_url();
if (sflvs.find(sid) == sflvs.end()) { if (sflvs.find(sid) == sflvs.end()) {
srs_info("ignore unmount flv stream for disabled");
return; return;
} }

View file

@ -47,16 +47,16 @@ SrsIngesterFFMPEG::~SrsIngesterFFMPEG()
srs_freep(ffmpeg); 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; ffmpeg = ff;
vhost = v; vhost = v;
id = i; id = i;
starttime = srs_get_system_time_ms(); starttime = srs_get_system_time_ms();
return ret; return err;
} }
string SrsIngesterFFMPEG::uri() string SrsIngesterFFMPEG::uri()
@ -79,7 +79,7 @@ bool SrsIngesterFFMPEG::equals(string v, string i)
return vhost == v && id == i; return vhost == v && id == i;
} }
int SrsIngesterFFMPEG::start() srs_error_t SrsIngesterFFMPEG::start()
{ {
return ffmpeg->start(); return ffmpeg->start();
} }
@ -89,7 +89,7 @@ void SrsIngesterFFMPEG::stop()
ffmpeg->stop(); ffmpeg->stop();
} }
int SrsIngesterFFMPEG::cycle() srs_error_t SrsIngesterFFMPEG::cycle()
{ {
return ffmpeg->cycle(); return ffmpeg->cycle();
} }
@ -128,12 +128,11 @@ void SrsIngester::dispose()
srs_error_t SrsIngester::start() srs_error_t SrsIngester::start()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if ((ret = parse()) != ERROR_SUCCESS) { if ((err = parse()) != srs_success) {
clear_engines(); clear_engines();
return srs_error_new(ret, "parse"); return srs_error_wrap(err, "parse");
} }
// even no ingesters, we must also start it, // even no ingesters, we must also start it,
@ -195,7 +194,6 @@ srs_error_t SrsIngester::cycle()
srs_error_t SrsIngester::do_cycle() srs_error_t SrsIngester::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// when expired, restart all ingesters. // when expired, restart all ingesters.
@ -207,8 +205,8 @@ srs_error_t SrsIngester::do_cycle()
clear_engines(); clear_engines();
// re-prase the ingesters. // re-prase the ingesters.
if ((ret = parse()) != ERROR_SUCCESS) { if ((err = parse()) != srs_success) {
return srs_error_new(ret, "parse"); return srs_error_wrap(err, "parse");
} }
} }
@ -218,13 +216,13 @@ srs_error_t SrsIngester::do_cycle()
SrsIngesterFFMPEG* ingester = *it; SrsIngesterFFMPEG* ingester = *it;
// start all ffmpegs. // start all ffmpegs.
if ((ret = ingester->start()) != ERROR_SUCCESS) { if ((err = ingester->start()) != srs_success) {
return srs_error_new(ret, "ingester start"); return srs_error_wrap(err, "ingester start");
} }
// check ffmpeg status. // check ffmpeg status.
if ((ret = ingester->cycle()) != ERROR_SUCCESS) { if ((err = ingester->cycle()) != srs_success) {
return srs_error_new(ret, "ingester cycle"); return srs_error_wrap(err, "ingester cycle");
} }
} }
@ -246,9 +244,9 @@ void SrsIngester::clear_engines()
ingesters.clear(); ingesters.clear();
} }
int SrsIngester::parse() srs_error_t SrsIngester::parse()
{ {
int ret = ERROR_SUCCESS; srs_error_t err = srs_success;
// parse ingesters // parse ingesters
std::vector<SrsConfDirective*> vhosts; std::vector<SrsConfDirective*> vhosts;
@ -256,21 +254,21 @@ int SrsIngester::parse()
for (int i = 0; i < (int)vhosts.size(); i++) { for (int i = 0; i < (int)vhosts.size(); i++) {
SrsConfDirective* vhost = vhosts[i]; SrsConfDirective* vhost = vhosts[i];
if ((ret = parse_ingesters(vhost)) != ERROR_SUCCESS) { if ((err = parse_ingesters(vhost)) != srs_success) {
return ret; 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. // when vhost disabled, ignore any ingesters.
if (!_srs_config->get_vhost_enabled(vhost)) { if (!_srs_config->get_vhost_enabled(vhost)) {
return ret; return err;
} }
std::vector<SrsConfDirective*> ingesters = _srs_config->get_ingesters(vhost->arg0()); std::vector<SrsConfDirective*> ingesters = _srs_config->get_ingesters(vhost->arg0());
@ -278,27 +276,25 @@ int SrsIngester::parse_ingesters(SrsConfDirective* vhost)
// create engine // create engine
for (int i = 0; i < (int)ingesters.size(); i++) { for (int i = 0; i < (int)ingesters.size(); i++) {
SrsConfDirective* ingest = ingesters[i]; SrsConfDirective* ingest = ingesters[i];
if ((ret = parse_engines(vhost, ingest)) != ERROR_SUCCESS) { if ((err = parse_engines(vhost, ingest)) != srs_success) {
return ret; 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)) { if (!_srs_config->get_ingest_enabled(ingest)) {
return ret; return err;
} }
std::string ffmpeg_bin = _srs_config->get_ingest_ffmpeg(ingest); std::string ffmpeg_bin = _srs_config->get_ingest_ffmpeg(ingest);
if (ffmpeg_bin.empty()) { if (ffmpeg_bin.empty()) {
ret = ERROR_ENCODER_PARSE; return srs_error_new(ERROR_ENCODER_PARSE, "parse ffmpeg");
srs_trace("empty ffmpeg ret=%d", ret);
return ret;
} }
// get all engines. // get all engines.
@ -307,52 +303,45 @@ int SrsIngester::parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest
// create ingesters without engines. // create ingesters without engines.
if (engines.empty()) { if (engines.empty()) {
SrsFFMPEG* ffmpeg = new SrsFFMPEG(ffmpeg_bin); 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); srs_freep(ffmpeg);
if (ret != ERROR_ENCODER_LOOP) { return srs_error_wrap(err, "init ffmpeg");
srs_error("invalid ingest engine. ret=%d", ret);
}
return ret;
} }
SrsIngesterFFMPEG* ingester = new SrsIngesterFFMPEG(); 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); srs_freep(ingester);
return ret; return srs_error_wrap(err, "init ingester");
} }
ingesters.push_back(ingester); ingesters.push_back(ingester);
return ret; return err;
} }
// create ingesters with engine // create ingesters with engine
for (int i = 0; i < (int)engines.size(); i++) { for (int i = 0; i < (int)engines.size(); i++) {
SrsConfDirective* engine = engines[i]; SrsConfDirective* engine = engines[i];
SrsFFMPEG* ffmpeg = new SrsFFMPEG(ffmpeg_bin); 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); srs_freep(ffmpeg);
if (ret != ERROR_ENCODER_LOOP) { return srs_error_wrap(err, "init ffmpeg");
srs_error("invalid ingest engine: %s %s, ret=%d",
ingest->arg0().c_str(), engine->arg0().c_str(), ret);
}
return ret;
} }
SrsIngesterFFMPEG* ingester = new SrsIngesterFFMPEG(); 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); srs_freep(ingester);
return ret; return srs_error_wrap(err, "init ingester");
} }
ingesters.push_back(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; int port;
if (true) { 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, "[vhost]", vhost->arg0());
output = srs_string_replace(output, "[port]", srs_int2str(port)); output = srs_string_replace(output, "[port]", srs_int2str(port));
if (output.empty()) { if (output.empty()) {
ret = ERROR_ENCODER_NO_OUTPUT; return srs_error_new(ERROR_ENCODER_NO_OUTPUT, "empty output url, ingest=%s", ingest->arg0().c_str());
srs_trace("empty output url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret);
return ret;
} }
// find the app and stream in rtmp url // find the app and stream in rtmp url
@ -402,43 +389,35 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S
// input // input
std::string input_type = _srs_config->get_ingest_input_type(ingest); std::string input_type = _srs_config->get_ingest_input_type(ingest);
if (input_type.empty()) { if (input_type.empty()) {
ret = ERROR_ENCODER_NO_INPUT; return srs_error_new(ERROR_ENCODER_NO_INPUT, "empty intput type, ingest=%s", ingest->arg0().c_str());
srs_trace("empty intput type, ingest=%s. ret=%d", ingest->arg0().c_str(), ret);
return ret;
} }
if (srs_config_ingest_is_file(input_type)) { if (srs_config_ingest_is_file(input_type)) {
std::string input_url = _srs_config->get_ingest_input_url(ingest); std::string input_url = _srs_config->get_ingest_input_url(ingest);
if (input_url.empty()) { if (input_url.empty()) {
ret = ERROR_ENCODER_NO_INPUT; return srs_error_new(ERROR_ENCODER_NO_INPUT, "empty intput url, ingest=%s", ingest->arg0().c_str());
srs_trace("empty intput url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret);
return ret;
} }
// for file, set re. // for file, set re.
ffmpeg->set_iparams("-re"); ffmpeg->set_iparams("-re");
if ((ret = ffmpeg->initialize(input_url, output, log_file)) != ERROR_SUCCESS) { if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return ret; return srs_error_wrap(err, "init ffmpeg");
} }
} else if (srs_config_ingest_is_stream(input_type)) { } else if (srs_config_ingest_is_stream(input_type)) {
std::string input_url = _srs_config->get_ingest_input_url(ingest); std::string input_url = _srs_config->get_ingest_input_url(ingest);
if (input_url.empty()) { if (input_url.empty()) {
ret = ERROR_ENCODER_NO_INPUT; return srs_error_new(ERROR_ENCODER_NO_INPUT, "empty intput url, ingest=%s", ingest->arg0().c_str());
srs_trace("empty intput url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret);
return ret;
} }
// for stream, no re. // for stream, no re.
ffmpeg->set_iparams(""); ffmpeg->set_iparams("");
if ((ret = ffmpeg->initialize(input_url, output, log_file)) != ERROR_SUCCESS) { if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return ret; return srs_error_wrap(err, "init ffmpeg");
} }
} else { } else {
ret = ERROR_ENCODER_INPUT_TYPE; return srs_error_new(ERROR_ENCODER_INPUT_TYPE, "invalid ingest=%s type=%s", ingest->arg0().c_str(), input_type.c_str());
srs_error("invalid ingest=%s type=%s, ret=%d",
ingest->arg0().c_str(), input_type.c_str(), ret);
} }
// set output format to flv for RTMP // 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. // whatever the engine config, use copy as default.
bool engine_disabled = !engine || !_srs_config->get_engine_enabled(engine); bool engine_disabled = !engine || !_srs_config->get_engine_enabled(engine);
if (engine_disabled || vcodec.empty() || acodec.empty()) { if (engine_disabled || vcodec.empty() || acodec.empty()) {
if ((ret = ffmpeg->initialize_copy()) != ERROR_SUCCESS) { if ((err = ffmpeg->initialize_copy()) != srs_success) {
return ret; return srs_error_wrap(err, "init ffmpeg");
} }
} else { } else {
if ((ret = ffmpeg->initialize_transcode(engine)) != ERROR_SUCCESS) { if ((err = ffmpeg->initialize_transcode(engine)) != srs_success) {
return ret; return srs_error_wrap(err, "init ffmpeg");
} }
} }
srs_trace("parse success, ingest=%s, vhost=%s", srs_trace("parse success, ingest=%s, vhost=%s", ingest->arg0().c_str(), vhost->arg0().c_str());
ingest->arg0().c_str(), vhost->arg0().c_str());
return ret; return err;
} }
void SrsIngester::show_ingest_log_message() 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) srs_error_t SrsIngester::on_reload_vhost_added(string vhost)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsConfDirective* _vhost = _srs_config->get_vhost(vhost); SrsConfDirective* _vhost = _srs_config->get_vhost(vhost);
if ((ret = parse_ingesters(_vhost)) != ERROR_SUCCESS) { if ((err = parse_ingesters(_vhost)) != srs_success) {
return srs_error_new(ret, "parse ingesters"); return srs_error_wrap(err, "parse ingesters");
} }
srs_trace("reload add vhost ingesters, vhost=%s", vhost.c_str()); 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) srs_error_t SrsIngester::on_reload_ingest_added(string vhost, string ingest_id)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsConfDirective* _vhost = _srs_config->get_vhost(vhost); SrsConfDirective* _vhost = _srs_config->get_vhost(vhost);
SrsConfDirective* _ingester = _srs_config->get_ingest_by_id(vhost, ingest_id); SrsConfDirective* _ingester = _srs_config->get_ingest_by_id(vhost, ingest_id);
if ((ret = parse_engines(_vhost, _ingester)) != ERROR_SUCCESS) { if ((err = parse_engines(_vhost, _ingester)) != srs_success) {
return srs_error_new(ret, "parse engines"); return srs_error_wrap(err, "parse engines");
} }
srs_trace("reload add ingester, vhost=%s, id=%s", vhost.c_str(), ingest_id.c_str()); srs_trace("reload add ingester, vhost=%s, id=%s", vhost.c_str(), ingest_id.c_str());

View file

@ -51,7 +51,7 @@ public:
SrsIngesterFFMPEG(); SrsIngesterFFMPEG();
virtual ~SrsIngesterFFMPEG(); virtual ~SrsIngesterFFMPEG();
public: 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] // the ingest uri, [vhost]/[ingest id]
virtual std::string uri(); virtual std::string uri();
// the alive in ms. // the alive in ms.
@ -59,9 +59,9 @@ public:
virtual bool equals(std::string v, std::string i); virtual bool equals(std::string v, std::string i);
virtual bool equals(std::string v); virtual bool equals(std::string v);
public: public:
virtual int start(); virtual srs_error_t start();
virtual void stop(); virtual void stop();
virtual int cycle(); virtual srs_error_t cycle();
// @see SrsFFMPEG.fast_stop(). // @see SrsFFMPEG.fast_stop().
virtual void fast_stop(); virtual void fast_stop();
}; };
@ -99,10 +99,10 @@ private:
virtual srs_error_t do_cycle(); virtual srs_error_t do_cycle();
private: private:
virtual void clear_engines(); virtual void clear_engines();
virtual int parse(); virtual srs_error_t parse();
virtual int parse_ingesters(SrsConfDirective* vhost); virtual srs_error_t parse_ingesters(SrsConfDirective* vhost);
virtual int parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest); virtual srs_error_t parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest);
virtual int initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, SrsConfDirective* ingest, SrsConfDirective* engine); virtual srs_error_t initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, SrsConfDirective* ingest, SrsConfDirective* engine);
virtual void show_ingest_log_message(); virtual void show_ingest_log_message();
// interface ISrsReloadHandler. // interface ISrsReloadHandler.
public: public:

View file

@ -69,8 +69,8 @@ public:
virtual ~SrsKafkaPartition(); virtual ~SrsKafkaPartition();
public: public:
virtual std::string hostport(); virtual std::string hostport();
virtual int connect(); virtual srs_error_t connect();
virtual int flush(SrsKafkaPartitionCache* pc); virtual srs_error_t flush(SrsKafkaPartitionCache* pc);
private: private:
virtual void disconnect(); virtual void disconnect();
}; };
@ -123,7 +123,7 @@ public:
/** /**
* flush the specified partition cache. * 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 @@ public:
* @param key the key to map to the partition, user can use cid or hash. * @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. * @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 // interface ISrsKafkaCluster
public: public:
virtual srs_error_t on_client(int key, SrsListenerType type, std::string ip); virtual srs_error_t on_client(int key, SrsListenerType type, std::string ip);
@ -200,10 +200,10 @@ public:
private: private:
virtual void clear_metadata(); virtual void clear_metadata();
virtual srs_error_t do_cycle(); virtual srs_error_t do_cycle();
virtual int request_metadata(); virtual srs_error_t request_metadata();
// set the metadata to invalid and refresh it. // set the metadata to invalid and refresh it.
virtual void refresh_metadata(); virtual void refresh_metadata();
virtual int flush(); virtual srs_error_t flush();
}; };
#endif #endif

View file

@ -66,7 +66,7 @@ public:
SrsMpegtsQueue(); SrsMpegtsQueue();
virtual ~SrsMpegtsQueue(); virtual ~SrsMpegtsQueue();
public: public:
virtual int push(SrsSharedPtrMessage* msg); virtual srs_error_t push(SrsSharedPtrMessage* msg);
virtual SrsSharedPtrMessage* dequeue(); virtual SrsSharedPtrMessage* dequeue();
}; };
@ -103,21 +103,21 @@ public:
public: public:
virtual srs_error_t on_udp_packet(sockaddr_in* from, char* buf, int nb_buf); virtual srs_error_t on_udp_packet(sockaddr_in* from, char* buf, int nb_buf);
private: 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 // interface ISrsTsHandler
public: public:
virtual srs_error_t on_ts_message(SrsTsMessage* msg); virtual srs_error_t on_ts_message(SrsTsMessage* msg);
private: private:
virtual int on_ts_video(SrsTsMessage* msg, SrsBuffer* avs); virtual srs_error_t on_ts_video(SrsTsMessage* msg, SrsBuffer* avs);
virtual int write_h264_sps_pps(uint32_t dts, uint32_t pts); virtual srs_error_t 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 srs_error_t 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 srs_error_t 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 write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts);
private: 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: private:
// Connect to RTMP server. // Connect to RTMP server.
virtual int connect(); virtual srs_error_t connect();
// Close the connection to RTMP server. // Close the connection to RTMP server.
virtual void close(); virtual void close();
}; };

View file

@ -51,7 +51,7 @@ public:
SrsNgExec(); SrsNgExec();
virtual ~SrsNgExec(); virtual ~SrsNgExec();
public: public:
virtual int on_publish(SrsRequest* req); virtual srs_error_t on_publish(SrsRequest* req);
virtual void on_unpublish(); virtual void on_unpublish();
// interface ISrsReusableThreadHandler. // interface ISrsReusableThreadHandler.
public: public:
@ -59,7 +59,7 @@ public:
private: private:
virtual srs_error_t do_cycle(); virtual srs_error_t do_cycle();
private: private:
virtual int parse_exec_publish(SrsRequest* req); virtual srs_error_t parse_exec_publish(SrsRequest* req);
virtual void clear_exec_publish(); virtual void clear_exec_publish();
virtual void show_exec_log_message(); virtual void show_exec_log_message();
virtual std::string parse(SrsRequest* req, std::string tmpl); virtual std::string parse(SrsRequest* req, std::string tmpl);

View file

@ -77,17 +77,17 @@ public:
* @param argv the argv for binary path, the argv[0] generally is the binary. * @param argv the argv for binary path, the argv[0] generally is the binary.
* @remark the argv[0] must be the binary. * @remark the argv[0] must be the binary.
*/ */
virtual int initialize(std::string binary, std::vector<std::string> argv); virtual srs_error_t initialize(std::string binary, std::vector<std::string> argv);
public: public:
/** /**
* start the process, ignore when already started. * start the process, ignore when already started.
*/ */
virtual int start(); virtual srs_error_t start();
/** /**
* cycle check the process, update the state of process. * cycle check the process, update the state of process.
* @remark when process terminated(not started), user can restart it again by start(). * @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. * send SIGTERM then SIGKILL to ensure the process stopped.
* the stop will wait [0, SRS_PROCESS_QUIT_TIMEOUT_MS] depends on the * the stop will wait [0, SRS_PROCESS_QUIT_TIMEOUT_MS] depends on the

View file

@ -125,7 +125,6 @@ srs_error_t SrsRecvThread::cycle()
srs_error_t SrsRecvThread::do_cycle() srs_error_t SrsRecvThread::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
while (true) { while (true) {
@ -142,24 +141,19 @@ srs_error_t SrsRecvThread::do_cycle()
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL;
// Process the received message. // Process the received message.
if ((ret = rtmp->recv_message(&msg)) == ERROR_SUCCESS) { if ((err = rtmp->recv_message(&msg)) == srs_success) {
ret = pumper->consume(msg); err = pumper->consume(msg);
} }
if (ret != ERROR_SUCCESS) { if (err != srs_success) {
if (!srs_is_client_gracefully_close(ret) && !srs_is_system_control_error(ret)) {
srs_error("recv thread error. ret=%d", ret);
}
// Interrupt the receive thread for any error. // Interrupt the receive thread for any error.
trd->interrupt(); trd->interrupt();
// Notify the pumper to quit for error. // 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; return err;
@ -170,7 +164,7 @@ SrsQueueRecvThread::SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtm
{ {
_consumer = consumer; _consumer = consumer;
rtmp = rtmp_sdk; rtmp = rtmp_sdk;
recv_error_code = ERROR_SUCCESS; recv_error = srs_success;
} }
SrsQueueRecvThread::~SrsQueueRecvThread() SrsQueueRecvThread::~SrsQueueRecvThread()
@ -184,6 +178,8 @@ SrsQueueRecvThread::~SrsQueueRecvThread()
srs_freep(msg); srs_freep(msg);
} }
queue.clear(); queue.clear();
srs_freep(recv_error);
} }
srs_error_t SrsQueueRecvThread::start() srs_error_t SrsQueueRecvThread::start()
@ -223,12 +219,12 @@ SrsCommonMessage* SrsQueueRecvThread::pump()
return msg; 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, // put into queue, the send thread will get and process it,
// @see SrsRtmpConn::process_play_control_msg // @see SrsRtmpConn::process_play_control_msg
@ -238,7 +234,7 @@ int SrsQueueRecvThread::consume(SrsCommonMessage* msg)
_consumer->wakeup(); _consumer->wakeup();
} }
#endif #endif
return ERROR_SUCCESS; return srs_success;
} }
bool SrsQueueRecvThread::interrupted() bool SrsQueueRecvThread::interrupted()
@ -250,9 +246,10 @@ bool SrsQueueRecvThread::interrupted()
return !empty(); 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 #ifdef SRS_PERF_QUEUE_COND_WAIT
if (_consumer) { if (_consumer) {
@ -283,7 +280,7 @@ SrsPublishRecvThread::SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, SrsRequest*
_conn = conn; _conn = conn;
_source = source; _source = source;
recv_error_code = ERROR_SUCCESS; recv_error = srs_success;
_nb_msgs = 0; _nb_msgs = 0;
video_frames = 0; video_frames = 0;
error = srs_cond_new(); error = srs_cond_new();
@ -308,18 +305,19 @@ SrsPublishRecvThread::~SrsPublishRecvThread()
trd.stop(); trd.stop();
srs_cond_destroy(error); 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) { if (recv_error != srs_success) {
return recv_error_code; return srs_error_copy(recv_error);
} }
// ignore any return of cond wait. // ignore any return of cond wait.
srs_cond_timedwait(error, timeout_ms * 1000); srs_cond_timedwait(error, timeout_ms * 1000);
return ERROR_SUCCESS; return srs_success;
} }
int64_t SrsPublishRecvThread::nb_msgs() int64_t SrsPublishRecvThread::nb_msgs()
@ -332,9 +330,9 @@ uint64_t SrsPublishRecvThread::nb_video_frames()
return 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) void SrsPublishRecvThread::set_cid(int v)
@ -365,9 +363,8 @@ void SrsPublishRecvThread::stop()
trd.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; srs_error_t err = srs_success;
// when cid changed, change it. // when cid changed, change it.
@ -388,15 +385,16 @@ int SrsPublishRecvThread::consume(SrsCommonMessage* msg)
// the rtmp connection will handle this message // the rtmp connection will handle this message
err = _conn->handle_publish_message(_source, msg); err = _conn->handle_publish_message(_source, msg);
// TODO: FIXME: Use error
ret = srs_error_code(err);
srs_freep(err);
// must always free it, // must always free it,
// the source will copy it if need to use. // the source will copy it if need to use.
srs_freep(msg); srs_freep(msg);
return ret; if (err != srs_success) {
return srs_error_wrap(err, "handle publish message");
}
return err;
} }
bool SrsPublishRecvThread::interrupted() bool SrsPublishRecvThread::interrupted()
@ -405,9 +403,10 @@ bool SrsPublishRecvThread::interrupted()
return false; 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. // when recv thread error, signal the conn thread to process it.
// @see https://github.com/ossrs/srs/issues/244 // @see https://github.com/ossrs/srs/issues/244

View file

@ -55,7 +55,7 @@ public:
* Consume the received message. * Consume the received message.
* @remark user must free this 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 @@ public:
/** /**
* Interrupt the pumper for a error. * Interrupt the pumper for a error.
*/ */
virtual void interrupt(int error) = 0; virtual void interrupt(srs_error_t error) = 0;
/** /**
* When start the pumper. * When start the pumper.
*/ */
@ -129,7 +129,7 @@ private:
SrsRecvThread trd; SrsRecvThread trd;
SrsRtmpServer* rtmp; SrsRtmpServer* rtmp;
// the recv thread error code. // the recv thread error code.
int recv_error_code; srs_error_t recv_error;
SrsConsumer* _consumer; SrsConsumer* _consumer;
public: public:
SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtmp_sdk, int timeout_ms); SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtmp_sdk, int timeout_ms);
@ -141,12 +141,12 @@ public:
virtual bool empty(); virtual bool empty();
virtual int size(); virtual int size();
virtual SrsCommonMessage* pump(); virtual SrsCommonMessage* pump();
virtual int error_code(); virtual srs_error_t error_code();
// interface ISrsMessagePumper // interface ISrsMessagePumper
public: public:
virtual int consume(SrsCommonMessage* msg); virtual srs_error_t consume(SrsCommonMessage* msg);
virtual bool interrupted(); virtual bool interrupted();
virtual void interrupt(int ret); virtual void interrupt(srs_error_t err);
virtual void on_start(); virtual void on_start();
virtual void on_stop(); virtual void on_stop();
}; };
@ -177,7 +177,7 @@ private:
// @see https://github.com/ossrs/srs/issues/257 // @see https://github.com/ossrs/srs/issues/257
bool realtime; bool realtime;
// the recv thread error code. // the recv thread error code.
int recv_error_code; srs_error_t recv_error;
SrsRtmpConn* _conn; SrsRtmpConn* _conn;
// the params for conn callback. // the params for conn callback.
SrsSource* _source; SrsSource* _source;
@ -194,10 +194,10 @@ public:
/** /**
* wait for error for some timeout. * 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 int64_t nb_msgs();
virtual uint64_t nb_video_frames(); virtual uint64_t nb_video_frames();
virtual int error_code(); virtual srs_error_t error_code();
virtual void set_cid(int v); virtual void set_cid(int v);
virtual int get_cid(); virtual int get_cid();
public: public:
@ -205,9 +205,9 @@ public:
virtual void stop(); virtual void stop();
// interface ISrsMessagePumper // interface ISrsMessagePumper
public: public:
virtual int consume(SrsCommonMessage* msg); virtual srs_error_t consume(SrsCommonMessage* msg);
virtual bool interrupted(); virtual bool interrupted();
virtual void interrupt(int ret); virtual void interrupt(srs_error_t err);
virtual void on_start(); virtual void on_start();
virtual void on_stop(); virtual void on_stop();
// interface IMergeReadHandler // interface IMergeReadHandler

View file

@ -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) { if (!refer) {
srs_verbose("ignore refer check for page_url=%s", page_url.c_str()); return err;
return ret;
} }
for (int i = 0; i < (int)refer->args.size(); i++) { for (int i = 0; i < (int)refer->args.size(); i++) {
if ((ret = check_single_refer(page_url, refer->args.at(i))) == ERROR_SUCCESS) { if ((err = check_single_refer(page_url, refer->args.at(i))) == srs_success) {
srs_verbose("check refer success. page_url=%s, refer=%s", return srs_success;
page_url.c_str(), refer->args.at(i).c_str());
return ret;
} }
srs_error_reset(err);
} }
ret = ERROR_RTMP_ACCESS_DENIED; return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied");
srs_error("check refer failed. ret=%d", ret);
return ret;
} }
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; 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); pos = domain_name.find(refer);
if (pos == std::string::npos) { if (pos == std::string::npos) {
ret = ERROR_RTMP_ACCESS_DENIED; return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied");
} }
// match primary domain. // match primary domain.
if (pos != domain_name.length() - refer.length()) { if (pos != domain_name.length() - refer.length()) {
ret = ERROR_RTMP_ACCESS_DENIED; return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied");
} }
if (ret != ERROR_SUCCESS) { return err;
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 ret;
} }

View file

@ -41,9 +41,9 @@ public:
* @param page_url the client page url. * @param page_url the client page url.
* @param refer the refer in config. * @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: 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 #endif

View file

@ -85,7 +85,7 @@ SrsSimpleRtmpClient::~SrsSimpleRtmpClient()
{ {
} }
int SrsSimpleRtmpClient::connect_app() srs_error_t SrsSimpleRtmpClient::connect_app()
{ {
std::vector<std::string> ips = srs_get_local_ipv4_ips(); std::vector<std::string> ips = srs_get_local_ipv4_ips();
assert(_srs_config->get_stats_network() < (int)ips.size()); assert(_srs_config->get_stats_network() < (int)ips.size());
@ -159,7 +159,6 @@ void SrsRtmpConn::dispose()
// TODO: return detail message when error for client. // TODO: return detail message when error for client.
srs_error_t SrsRtmpConn::do_cycle() srs_error_t SrsRtmpConn::do_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_trace("RTMP client ip=%s, fd=%d", ip.c_str(), srs_netfd_fileno(stfd)); 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_recv_timeout(SRS_CONSTS_RTMP_TMMS);
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS); rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
if ((ret = rtmp->handshake()) != ERROR_SUCCESS) { if ((err = rtmp->handshake()) != srs_success) {
return srs_error_new(ret, "rtmp handshake"); return srs_error_wrap(err, "rtmp handshake");
} }
SrsRequest* req = info->req; SrsRequest* req = info->req;
if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) { if ((err = rtmp->connect_app(req)) != srs_success) {
return srs_error_new(ret, "rtmp connect tcUrl"); return srs_error_wrap(err, "rtmp connect tcUrl");
} }
// set client ip to request. // set client ip to request.
@ -192,9 +191,6 @@ srs_error_t SrsRtmpConn::do_cycle()
req->vhost = parsed_vhost->arg0(); 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()) { 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", 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()); 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_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) { if (srs_pid > 0) {
srs_trace("edge-srs ip=%s, version=%s, pid=%d, id=%d", 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); 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() srs_error_t SrsRtmpConn::service_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsRequest* req = info->req; SrsRequest* req = info->req;
int out_ack_size = _srs_config->get_out_ack_size(req->vhost); 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) { if (out_ack_size && (err = rtmp->set_window_ack_size(out_ack_size)) != srs_success) {
return srs_error_new(ret, "rtmp: set out window ack size"); return srs_error_wrap(err, "rtmp: set out window ack size");
} }
int in_ack_size = _srs_config->get_in_ack_size(req->vhost); 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) { if (in_ack_size && (err = rtmp->set_in_window_ack_size(in_ack_size)) != srs_success) {
return srs_error_new(ret, "rtmp: set in window ack size"); 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) { if ((err = rtmp->set_peer_bandwidth((int)(2.5 * 1000 * 1000), 2)) != srs_success) {
return srs_error_new(ret, "rtmp: set peer bandwidth"); return srs_error_wrap(err, "rtmp: set peer bandwidth");
} }
// get the ip which client connected. // 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. // do bandwidth test if connect to the vhost which is for bandwidth check.
if (_srs_config->get_bw_check_enabled(req->vhost)) { if (_srs_config->get_bw_check_enabled(req->vhost)) {
if ((ret = bandwidth->bandwidth_check(rtmp, skt, req, local_ip)) != ERROR_SUCCESS) { if ((err = bandwidth->bandwidth_check(rtmp, skt, req, local_ip)) != srs_success) {
return srs_error_new(ret, "rtmp: bandwidth check"); return srs_error_wrap(err, "rtmp: bandwidth check");
} }
return err; return err;
} }
@ -423,17 +416,17 @@ srs_error_t SrsRtmpConn::service_cycle()
// set the chunk size before any larger response greater than 128, // set the chunk size before any larger response greater than 128,
// to make OBS happy, @see https://github.com/ossrs/srs/issues/454 // to make OBS happy, @see https://github.com/ossrs/srs/issues/454
int chunk_size = _srs_config->get_chunk_size(req->vhost); int chunk_size = _srs_config->get_chunk_size(req->vhost);
if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { if ((err = rtmp->set_chunk_size(chunk_size)) != srs_success) {
return srs_error_new(ret, "rtmp: set chunk size %d", chunk_size); return srs_error_wrap(err, "rtmp: set chunk size %d", chunk_size);
} }
// response the client connect ok. // response the client connect ok.
if ((ret = rtmp->response_connect_app(req, local_ip.c_str())) != ERROR_SUCCESS) { if ((err = rtmp->response_connect_app(req, local_ip.c_str())) != srs_success) {
return srs_error_new(ret, "rtmp: response connect app"); return srs_error_wrap(err, "rtmp: response connect app");
} }
if ((ret = rtmp->on_bw_done()) != ERROR_SUCCESS) { if ((err = rtmp->on_bw_done()) != srs_success) {
return srs_error_new(ret, "rtmp: on bw down"); return srs_error_wrap(err, "rtmp: on bw down");
} }
while (true) { while (true) {
@ -490,21 +483,20 @@ srs_error_t SrsRtmpConn::service_cycle()
srs_error_t SrsRtmpConn::stream_service_cycle() srs_error_t SrsRtmpConn::stream_service_cycle()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsRequest* req = info->req; SrsRequest* req = info->req;
if ((ret = rtmp->identify_client(info->res->stream_id, info->type, req->stream, req->duration)) != ERROR_SUCCESS) { if ((err = rtmp->identify_client(info->res->stream_id, info->type, req->stream, req->duration)) != srs_success) {
return srs_error_new(ret, "rtmp: identify client"); return srs_error_wrap(err, "rtmp: identify client");
} }
req->strip(); req->strip();
srs_trace("client identified, type=%s, stream_name=%s, duration=%.2f", 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); srs_client_type_string(info->type).c_str(), req->stream.c_str(), req->duration);
// security check // security check
if ((ret = security->check(info->type, ip, req)) != ERROR_SUCCESS) { if ((err = security->check(info->type, ip, req)) != srs_success) {
return srs_error_new(ret, "rtmp: security check"); return srs_error_wrap(err, "rtmp: security check");
} }
// Never allow the empty stream name, for HLS may write to a file with empty name. // 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. // update the statistic when source disconveried.
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
if ((ret = stat->on_client(_srs_context->get_id(), req, this, info->type)) != ERROR_SUCCESS) { if ((err = stat->on_client(_srs_context->get_id(), req, this, info->type)) != srs_success) {
return srs_error_new(ret, "rtmp: stat client"); return srs_error_wrap(err, "rtmp: stat client");
} }
bool enabled_cache = _srs_config->get_gop_cache(req->vhost); bool enabled_cache = _srs_config->get_gop_cache(req->vhost);
@ -538,8 +530,8 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
switch (info->type) { switch (info->type) {
case SrsRtmpConnPlay: { case SrsRtmpConnPlay: {
// response connection start play // response connection start play
if ((ret = rtmp->start_play(info->res->stream_id)) != ERROR_SUCCESS) { if ((err = rtmp->start_play(info->res->stream_id)) != srs_success) {
return srs_error_new(ret, "rtmp: start play"); return srs_error_wrap(err, "rtmp: start play");
} }
if ((err = http_hooks_on_play()) != srs_success) { if ((err = http_hooks_on_play()) != srs_success) {
return srs_error_wrap(err, "rtmp: callback on play"); return srs_error_wrap(err, "rtmp: callback on play");
@ -551,22 +543,22 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
return err; return err;
} }
case SrsRtmpConnFMLEPublish: { case SrsRtmpConnFMLEPublish: {
if ((ret = rtmp->start_fmle_publish(info->res->stream_id)) != ERROR_SUCCESS) { if ((err = rtmp->start_fmle_publish(info->res->stream_id)) != srs_success) {
return srs_error_new(ret, "rtmp: start FMLE publish"); return srs_error_wrap(err, "rtmp: start FMLE publish");
} }
return publishing(source); return publishing(source);
} }
case SrsRtmpConnHaivisionPublish: { case SrsRtmpConnHaivisionPublish: {
if ((ret = rtmp->start_haivision_publish(info->res->stream_id)) != ERROR_SUCCESS) { if ((err = rtmp->start_haivision_publish(info->res->stream_id)) != srs_success) {
return srs_error_new(ret, "rtmp: start HAIVISION publish"); return srs_error_wrap(err, "rtmp: start HAIVISION publish");
} }
return publishing(source); return publishing(source);
} }
case SrsRtmpConnFlashPublish: { case SrsRtmpConnFlashPublish: {
if ((ret = rtmp->start_flash_publish(info->res->stream_id)) != ERROR_SUCCESS) { if ((err = rtmp->start_flash_publish(info->res->stream_id)) != srs_success) {
return srs_error_new(ret, "rtmp: start FLASH publish"); return srs_error_wrap(err, "rtmp: start FLASH publish");
} }
return publishing(source); return publishing(source);
@ -581,7 +573,6 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
srs_error_t SrsRtmpConn::check_vhost(bool try_default_vhost) srs_error_t SrsRtmpConn::check_vhost(bool try_default_vhost)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsRequest* req = info->req; 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 (_srs_config->get_refer_enabled(req->vhost)) {
if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_all(req->vhost))) != ERROR_SUCCESS) { if ((err = refer->check(req->pageUrl, _srs_config->get_refer_all(req->vhost))) != srs_success) {
return srs_error_new(ret, "rtmp: referer check"); 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) srs_error_t SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRecvThread* rtrd)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_assert(consumer != NULL); srs_assert(consumer != NULL);
SrsRequest* req = info->req; SrsRequest* req = info->req;
if (_srs_config->get_refer_enabled(req->vhost)) { if (_srs_config->get_refer_enabled(req->vhost)) {
if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { if ((err = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != srs_success) {
return srs_error_new(ret, "rtmp: referer check"); 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. // quit when recv thread error.
if ((ret = rtrd->error_code()) != ERROR_SUCCESS) { if ((err = rtrd->error_code()) != srs_success) {
return srs_error_new(ret, "rtmp: recv thread"); return srs_error_wrap(err, "rtmp: recv thread");
} }
#ifdef SRS_PERF_QUEUE_COND_WAIT #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(). // sendout messages, all messages are freed by send_and_free_messages().
// no need to assert msg, for the rtmp will assert it. // 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) { if (count > 0 && (err = rtmp->send_and_free_messages(msgs.msgs, count, info->res->stream_id)) != srs_success) {
return srs_error_new(ret, "rtmp: send %d messages", count); return srs_error_wrap(err, "rtmp: send %d messages", count);
} }
// if duration specified, and exceed it, stop play live. // 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) srs_error_t SrsRtmpConn::publishing(SrsSource* source)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsRequest* req = info->req; SrsRequest* req = info->req;
if (_srs_config->get_refer_enabled(req->vhost)) { if (_srs_config->get_refer_enabled(req->vhost)) {
if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { if ((err = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != srs_success) {
return srs_error_new(ret, "rtmp: referer check"); 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) srs_error_t SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* rtrd)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsRequest* req = info->req; SrsRequest* req = info->req;
@ -878,8 +866,8 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread*
} }
// check the thread error code. // check the thread error code.
if ((ret = rtrd->error_code()) != ERROR_SUCCESS) { if ((err = rtrd->error_code()) != srs_success) {
return srs_error_new(ret, "rtmp: receive thread"); return srs_error_wrap(err, "rtmp: receive thread");
} }
// when not got any messages, timeout. // 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. // Update the stat for video fps.
// @remark https://github.com/ossrs/srs/issues/851 // @remark https://github.com/ossrs/srs/issues/851
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
if ((ret = stat->on_video_frames(req, (int)(rtrd->nb_video_frames() - nb_frames))) != ERROR_SUCCESS) { if ((err = stat->on_video_frames(req, (int)(rtrd->nb_video_frames() - nb_frames))) != srs_success) {
return srs_error_new(ret, "rtmp: stat video frames"); return srs_error_wrap(err, "rtmp: stat video frames");
} }
nb_frames = rtrd->nb_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) srs_error_t SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// process publish event. // process publish event.
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) { if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL;
if ((ret = rtmp->decode_message(msg, &pkt)) != ERROR_SUCCESS) { if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) {
return srs_error_new(ret, "rtmp: decode message"); return srs_error_wrap(err, "rtmp: decode message");
} }
SrsAutoFree(SrsPacket, pkt); 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. // for fmle, drop others except the fmle start packet.
if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) { if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt); SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt);
if ((ret = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != ERROR_SUCCESS) { if ((err = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != srs_success) {
return srs_error_new(ret, "rtmp: republish"); return srs_error_wrap(err, "rtmp: republish");
} }
return srs_error_new(ERROR_CONTROL_REPUBLISH, "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) srs_error_t SrsRtmpConn::process_publish_message(SrsSource* source, SrsCommonMessage* msg)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// for edge, directly proxy message to origin. // for edge, directly proxy message to origin.
@ -1027,8 +1013,8 @@ srs_error_t SrsRtmpConn::process_publish_message(SrsSource* source, SrsCommonMes
// process onMetaData // process onMetaData
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) { if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL;
if ((ret = rtmp->decode_message(msg, &pkt)) != ERROR_SUCCESS) { if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) {
return srs_error_new(ret, "rtmp: decode message"); return srs_error_wrap(err, "rtmp: decode message");
} }
SrsAutoFree(SrsPacket, pkt); 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) srs_error_t SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!msg) { if (!msg) {
@ -1060,8 +1045,8 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsComm
} }
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL;
if ((ret = rtmp->decode_message(msg, &pkt)) != ERROR_SUCCESS) { if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) {
return srs_error_new(ret, "rtmp: decode message"); return srs_error_wrap(err, "rtmp: decode message");
} }
SrsAutoFree(SrsPacket, pkt); 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); SrsCallResPacket* res = new SrsCallResPacket(call->transaction_id);
res->command_object = SrsAmf0Any::null(); res->command_object = SrsAmf0Any::null();
res->response = SrsAmf0Any::null(); res->response = SrsAmf0Any::null();
if ((ret = rtmp->send_and_free_packet(res, 0)) != ERROR_SUCCESS) { if ((err = rtmp->send_and_free_packet(res, 0)) != srs_success) {
return srs_error_new(ret, "rtmp: send packets"); return srs_error_wrap(err, "rtmp: send packets");
} }
} }
return err; return err;
@ -1094,8 +1079,8 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsComm
// pause // pause
SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(pkt); SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(pkt);
if (pause) { if (pause) {
if ((ret = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != ERROR_SUCCESS) { if ((err = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != srs_success) {
return srs_error_new(ret, "rtmp: pause"); return srs_error_wrap(err, "rtmp: pause");
} }
if ((err = consumer->on_play_client_pause(pause->is_pause)) != srs_success) { if ((err = consumer->on_play_client_pause(pause->is_pause)) != srs_success) {
return srs_error_wrap(err, "rtmp: pause"); 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) srs_error_t SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsRequest* req = info->req; 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_recv_timeout(SRS_CONSTS_RTMP_TMMS);
client->set_send_timeout(SRS_CONSTS_RTMP_TMMS); client->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
if ((ret = client->handshake()) != ERROR_SUCCESS) { if ((err = client->handshake()) != srs_success) {
return srs_error_new(ret, "rtmp: handshake"); return srs_error_wrap(err, "rtmp: handshake");
} }
// for token tranverse, always take the debug info(which carries token). // 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) { if ((err = client->connect_app(req->app, req->tcUrl, req, true, NULL)) != srs_success) {
return srs_error_new(ret, "rtmp: connect tcUrl"); return srs_error_wrap(err, "rtmp: connect tcUrl");
} }
srs_trace("edge token auth ok, tcUrl=%s", req->tcUrl.c_str()); 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); SrsConfDirective* conf = _srs_config->get_vhost_on_connect(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_connect");
return err; return err;
} }
@ -1318,7 +1301,6 @@ void SrsRtmpConn::http_hooks_on_close()
SrsConfDirective* conf = _srs_config->get_vhost_on_close(req->vhost); SrsConfDirective* conf = _srs_config->get_vhost_on_close(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_close");
return; return;
} }
@ -1350,7 +1332,6 @@ srs_error_t SrsRtmpConn::http_hooks_on_publish()
SrsConfDirective* conf = _srs_config->get_vhost_on_publish(req->vhost); SrsConfDirective* conf = _srs_config->get_vhost_on_publish(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_publish");
return err; return err;
} }
@ -1384,7 +1365,6 @@ void SrsRtmpConn::http_hooks_on_unpublish()
SrsConfDirective* conf = _srs_config->get_vhost_on_unpublish(req->vhost); SrsConfDirective* conf = _srs_config->get_vhost_on_unpublish(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_unpublish");
return; return;
} }
@ -1416,7 +1396,6 @@ srs_error_t SrsRtmpConn::http_hooks_on_play()
SrsConfDirective* conf = _srs_config->get_vhost_on_play(req->vhost); SrsConfDirective* conf = _srs_config->get_vhost_on_play(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_play");
return err; return err;
} }
@ -1450,7 +1429,6 @@ void SrsRtmpConn::http_hooks_on_stop()
SrsConfDirective* conf = _srs_config->get_vhost_on_stop(req->vhost); SrsConfDirective* conf = _srs_config->get_vhost_on_stop(req->vhost);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_stop");
return; return;
} }

View file

@ -67,7 +67,7 @@ public:
SrsSimpleRtmpClient(std::string u, int64_t ctm, int64_t stm); SrsSimpleRtmpClient(std::string u, int64_t ctm, int64_t stm);
virtual ~SrsSimpleRtmpClient(); virtual ~SrsSimpleRtmpClient();
protected: protected:
virtual int connect_app(); virtual srs_error_t connect_app();
}; };
/** /**

View file

@ -104,7 +104,7 @@ public:
virtual ~SrsRtspJitter(); virtual ~SrsRtspJitter();
public: public:
virtual int64_t timestamp(); virtual int64_t timestamp();
virtual int correct(int64_t& ts); virtual srs_error_t correct(int64_t& ts);
}; };
/** /**
@ -162,18 +162,18 @@ public:
public: public:
virtual srs_error_t cycle(); virtual srs_error_t cycle();
private: private:
virtual int on_rtp_video(SrsRtpPacket* pkt, int64_t dts, int64_t pts); virtual srs_error_t on_rtp_video(SrsRtpPacket* pkt, int64_t dts, int64_t pts);
virtual int on_rtp_audio(SrsRtpPacket* pkt, int64_t dts); virtual srs_error_t on_rtp_audio(SrsRtpPacket* pkt, int64_t dts);
virtual int kickoff_audio_cache(SrsRtpPacket* pkt, int64_t dts); virtual srs_error_t kickoff_audio_cache(SrsRtpPacket* pkt, int64_t dts);
private: private:
virtual int write_sequence_header(); virtual srs_error_t write_sequence_header();
virtual int write_h264_sps_pps(uint32_t dts, uint32_t pts); virtual srs_error_t 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 srs_error_t 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 srs_error_t 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 rtmp_write_packet(char type, uint32_t timestamp, char* data, int size);
private: private:
// Connect to RTMP server. // Connect to RTMP server.
virtual int connect(); virtual srs_error_t connect();
// Close the connection to RTMP server. // Close the connection to RTMP server.
virtual void close(); virtual void close();
}; };
@ -199,7 +199,7 @@ public:
* alloc a rtp port from local ports pool. * alloc a rtp port from local ports pool.
* @param pport output the rtp port. * @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. * free the alloced rtp port.
*/ */

View file

@ -48,18 +48,18 @@ public:
* @param ip the ip address of client. * @param ip the ip address of client.
* @param req the request object 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: private:
/** /**
* security check the allow, * security check the allow,
* @return, if allowed, ERROR_SYSTEM_SECURITY_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, * security check the deny,
* @return, if denied, ERROR_SYSTEM_SECURITY_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 #endif

View file

@ -1391,11 +1391,10 @@ srs_error_t SrsServer::on_reload_http_stream_updated()
srs_error_t SrsServer::on_publish(SrsSource* s, SrsRequest* r) srs_error_t SrsServer::on_publish(SrsSource* s, SrsRequest* r)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if ((ret = http_server->http_mount(s, r)) != ERROR_SUCCESS) { if ((err = http_server->http_mount(s, r)) != srs_success) {
return srs_error_new(ret, "http mount"); return srs_error_wrap(err, "http mount");
} }
return err; return err;

View file

@ -295,7 +295,7 @@ private:
* to stop all ingesters, cleanup HLS and dvr. * to stop all ingesters, cleanup HLS and dvr.
*/ */
virtual void dispose(); virtual void dispose();
// server startup workflow, @see run_master() // server startup workflow, @see run_master()
public: public:
/** /**
* initialize server with callback handler ch. * initialize server with callback handler ch.
@ -310,7 +310,7 @@ public:
virtual srs_error_t http_handle(); virtual srs_error_t http_handle();
virtual srs_error_t ingest(); virtual srs_error_t ingest();
virtual srs_error_t cycle(); virtual srs_error_t cycle();
// server utilities. // server utilities.
public: public:
/** /**
* callback for signal manager got a signal. * callback for signal manager got a signal.

View file

@ -135,12 +135,6 @@ srs_error_t SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, SrsRtmpJitterAlgori
// use default 10ms to notice the problem of stream. // use default 10ms to notice the problem of stream.
// @see https://github.com/ossrs/srs/issues/425 // @see https://github.com/ossrs/srs/issues/425
delta = DEFAULT_FRAME_TIME_MS; 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); last_pkt_correct_time = srs_max(0, last_pkt_correct_time + delta);
@ -389,10 +383,7 @@ void SrsMessageQueue::shrink()
msgs.push_back(audio_sh); msgs.push_back(audio_sh);
} }
if (_ignore_shrink) { 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 {
srs_trace("shrink the cache queue, size=%d, removed=%d, max=%.2f", 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); (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 #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. // fire the mw when msgs is enough.
if (mw_waiting) { if (mw_waiting) {
int duration_ms = queue->duration(); int duration_ms = queue->duration();
@ -614,12 +602,9 @@ void SrsGopCache::set(bool v)
enable_gop_cache = v; enable_gop_cache = v;
if (!v) { if (!v) {
srs_info("disable gop cache, clear %d packets.", (int)gop_cache.size());
clear(); clear();
return; return;
} }
srs_info("enable gop cache");
} }
bool SrsGopCache::enabled() 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) srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsSharedPtrMessage* msg = shared_audio; SrsSharedPtrMessage* msg = shared_audio;
@ -971,8 +955,8 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio)
// when got audio stream info. // when got audio stream info.
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
if ((ret = stat->on_audio_info(req, SrsAudioCodecIdAAC, c->sound_rate, c->sound_type, c->aac_object)) != ERROR_SUCCESS) { if ((err = stat->on_audio_info(req, SrsAudioCodecIdAAC, c->sound_rate, c->sound_type, c->aac_object)) != srs_success) {
return srs_error_new(ret, "stat audio"); return srs_error_wrap(err, "stat audio");
} }
srs_trace("%dB audio sh, codec(%d, profile=%s, %dchannels, %dkbps, %dHZ), flv(%dbits, %dchannels, %dHZ)", 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) { if ((err = dash->on_audio(msg, format)) != srs_success) {
srs_warn("dash: ignore audio error ret=%d", ret); srs_warn("dash: ignore audio error %s", srs_error_desc(err).c_str());
dash->on_unpublish();
srs_error_reset(err); srs_error_reset(err);
dash->on_unpublish();
} }
if ((err = dvr->on_audio(msg, format)) != srs_success) { if ((err = dvr->on_audio(msg, format)) != srs_success) {
srs_warn("dvr: ignore audio error %s", srs_error_desc(err).c_str()); srs_warn("dvr: ignore audio error %s", srs_error_desc(err).c_str());
dvr->on_unpublish();
srs_error_reset(err); srs_error_reset(err);
dvr->on_unpublish();
} }
#ifdef SRS_AUTO_HDS #ifdef SRS_AUTO_HDS
if ((ret = hds->on_audio(msg)) != ERROR_SUCCESS) { if ((err = hds->on_audio(msg)) != srs_success) {
srs_warn("hds: ignore audio error ret=%d", ret); srs_warn("hds: ignore audio error %s", srs_error_desc(err).c_str());
hds->on_unpublish();
srs_error_reset(err); srs_error_reset(err);
hds->on_unpublish();
} }
#endif #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) srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_sequence_header)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsSharedPtrMessage* msg = shared_video; 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. // when got video stream info.
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
if ((ret = stat->on_video_info(req, SrsVideoCodecIdAVC, c->avc_profile, c->avc_level, c->width, c->height)) != ERROR_SUCCESS) { if ((err = stat->on_video_info(req, SrsVideoCodecIdAVC, c->avc_profile, c->avc_level, c->width, c->height)) != srs_success) {
return srs_error_new(ret, "stat video"); return srs_error_wrap(err, "stat video");
} }
srs_trace("%dB video sh, codec(%d, profile=%s, level=%s, %dx%d, %dkbps, %.1ffps, %.1fs)", 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(); hls->on_unpublish();
srs_error_reset(err); srs_error_reset(err);
} else if (srs_config_hls_is_on_error_continue(hls_error_strategy)) { } 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); srs_error_reset(err);
} else { } else {
return srs_error_wrap(err, "hls: video"); 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) { if ((err = dash->on_video(msg, format)) != srs_success) {
srs_warn("dash: ignore video error ret=%d", ret); srs_warn("dash: ignore video error %s", srs_error_desc(err).c_str());
dash->on_unpublish();
srs_error_reset(err); srs_error_reset(err);
dash->on_unpublish();
} }
if ((err = dvr->on_video(msg, format)) != srs_success) { if ((err = dvr->on_video(msg, format)) != srs_success) {
srs_warn("dvr: ignore video error %s", srs_error_desc(err).c_str()); srs_warn("dvr: ignore video error %s", srs_error_desc(err).c_str());
dvr->on_unpublish();
srs_error_reset(err); srs_error_reset(err);
dvr->on_unpublish();
} }
#ifdef SRS_AUTO_HDS #ifdef SRS_AUTO_HDS
if ((ret = hds->on_video(msg)) != ERROR_SUCCESS) { if ((err = hds->on_video(msg)) != srs_success) {
srs_warn("hds: ignore video error ret=%d", ret); srs_warn("hds: ignore video error %s", srs_error_desc(err).c_str());
hds->on_unpublish();
srs_error_reset(err); srs_error_reset(err);
hds->on_unpublish();
} }
#endif #endif
@ -1125,7 +1108,6 @@ srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_se
srs_error_t SrsOriginHub::on_publish() srs_error_t SrsOriginHub::on_publish()
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// create forwarders // create forwarders
@ -1135,8 +1117,8 @@ srs_error_t SrsOriginHub::on_publish()
// TODO: FIXME: use initialize to set req. // TODO: FIXME: use initialize to set req.
#ifdef SRS_AUTO_TRANSCODE #ifdef SRS_AUTO_TRANSCODE
if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) { if ((err = encoder->on_publish(req)) != srs_success) {
return srs_error_new(ret, "encoder publish"); return srs_error_wrap(err, "encoder publish");
} }
#endif #endif
@ -1144,8 +1126,8 @@ srs_error_t SrsOriginHub::on_publish()
return srs_error_wrap(err, "hls publish"); return srs_error_wrap(err, "hls publish");
} }
if ((ret = dash->on_publish()) != ERROR_SUCCESS) { if ((err = dash->on_publish()) != srs_success) {
return srs_error_new(ret, "dash publish"); return srs_error_wrap(err, "dash publish");
} }
if ((err = dvr->on_publish()) != srs_success) { if ((err = dvr->on_publish()) != srs_success) {
@ -1154,14 +1136,14 @@ srs_error_t SrsOriginHub::on_publish()
// TODO: FIXME: use initialize to set req. // TODO: FIXME: use initialize to set req.
#ifdef SRS_AUTO_HDS #ifdef SRS_AUTO_HDS
if ((ret = hds->on_publish(req)) != ERROR_SUCCESS) { if ((err = hds->on_publish(req)) != srs_success) {
return srs_error_new(ret, "hds publish"); return srs_error_wrap(err, "hds publish");
} }
#endif #endif
// TODO: FIXME: use initialize to set req. // TODO: FIXME: use initialize to set req.
if ((ret = ng_exec->on_publish(req)) != ERROR_SUCCESS) { if ((err = ng_exec->on_publish(req)) != srs_success) {
return srs_error_new(ret, "exec publish"); return srs_error_wrap(err, "exec publish");
} }
is_active = true; 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) srs_error_t SrsOriginHub::on_reload_vhost_dash(string vhost)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (req->vhost != vhost) { if (req->vhost != vhost) {
@ -1287,8 +1268,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_dash(string vhost)
return err; return err;
} }
if ((ret = dash->on_publish()) != ERROR_SUCCESS) { if ((err = dash->on_publish()) != srs_success) {
return srs_error_new(ret, "dash start publish"); return srs_error_wrap(err, "dash start publish");
} }
SrsSharedPtrMessage* cache_sh_video = source->meta->vsh(); 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) { if ((err = format->on_video(cache_sh_video)) != srs_success) {
return srs_error_wrap(err, "format on_video"); return srs_error_wrap(err, "format on_video");
} }
if ((ret = dash->on_video(cache_sh_video, format)) != ERROR_SUCCESS) { if ((err = dash->on_video(cache_sh_video, format)) != srs_success) {
return srs_error_new(ret, "dash on_video"); 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) { if ((err = format->on_audio(cache_sh_audio)) != srs_success) {
return srs_error_wrap(err, "format on_audio"); return srs_error_wrap(err, "format on_audio");
} }
if ((ret = dash->on_audio(cache_sh_audio, format)) != ERROR_SUCCESS) { if ((err = dash->on_audio(cache_sh_audio, format)) != srs_success) {
return srs_error_new(ret, "dash on_audio"); 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) srs_error_t SrsOriginHub::on_reload_vhost_hds(string vhost)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (req->vhost != vhost) { if (req->vhost != vhost) {
@ -1383,8 +1363,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_hds(string vhost)
return err; return err;
} }
if ((ret = hds->on_publish(req)) != ERROR_SUCCESS) { if ((err = hds->on_publish(req)) != srs_success) {
return srs_error_new(ret, "hds publish failed"); return srs_error_wrap(err, "hds publish failed");
} }
srs_trace("vhost %s hds reload success", vhost.c_str()); srs_trace("vhost %s hds reload success", vhost.c_str());
#endif #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) srs_error_t SrsOriginHub::on_reload_vhost_transcode(string vhost)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (req->vhost != vhost) { if (req->vhost != vhost) {
@ -1448,8 +1427,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_transcode(string vhost)
return err; return err;
} }
if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) { if ((err = encoder->on_publish(req)) != srs_success) {
return srs_error_new(ret, "start encoder failed"); return srs_error_wrap(err, "start encoder failed");
} }
srs_trace("vhost %s transcode reload success", vhost.c_str()); srs_trace("vhost %s transcode reload success", vhost.c_str());
#endif #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) srs_error_t SrsOriginHub::on_reload_vhost_exec(string vhost)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (req->vhost != vhost) { if (req->vhost != vhost) {
@ -1475,8 +1453,8 @@ srs_error_t SrsOriginHub::on_reload_vhost_exec(string vhost)
return err; return err;
} }
if ((ret = ng_exec->on_publish(req)) != ERROR_SUCCESS) { if ((err = ng_exec->on_publish(req)) != srs_success) {
return srs_error_new(ret, "start exec failed"); return srs_error_wrap(err, "start exec failed");
} }
srs_trace("vhost %s exec reload success", vhost.c_str()); 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; updated = false;
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsAmf0Any* prop = NULL; SrsAmf0Any* prop = NULL;
@ -1636,8 +1613,8 @@ srs_error_t SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPac
// encode the metadata to payload // encode the metadata to payload
int size = 0; int size = 0;
char* payload = NULL; char* payload = NULL;
if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) { if ((err = metadata->encode(size, payload)) != srs_success) {
return srs_error_new(ret, "encode metadata"); return srs_error_wrap(err, "encode metadata");
} }
if (size <= 0) { if (size <= 0) {
@ -1652,8 +1629,8 @@ srs_error_t SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPac
// dump message to shared ptr message. // dump message to shared ptr message.
// the payload/size managed by cache_metadata, user should not free it. // the payload/size managed by cache_metadata, user should not free it.
if ((ret = meta->create(header, payload, size)) != ERROR_SUCCESS) { if ((err = meta->create(header, payload, size)) != srs_success) {
return srs_error_new(ret, "create metadata"); return srs_error_wrap(err, "create metadata");
} }
return err; return err;
@ -1697,7 +1674,6 @@ srs_error_t SrsSource::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, SrsS
} }
pool[stream_url] = source; pool[stream_url] = source;
srs_info("create new source for url=%s, vhost=%s", stream_url.c_str(), vhost.c_str());
*pps = source; *pps = source;
@ -1807,7 +1783,6 @@ SrsSource::SrsSource()
play_edge = new SrsPlayEdge(); play_edge = new SrsPlayEdge();
publish_edge = new SrsPublishEdge(); publish_edge = new SrsPublishEdge();
gop_cache = new SrsGopCache(); gop_cache = new SrsGopCache();
aggregate_stream = new SrsBuffer();
hub = new SrsOriginHub(); hub = new SrsOriginHub();
meta = new SrsMetaCache(); meta = new SrsMetaCache();
@ -1833,7 +1808,6 @@ SrsSource::~SrsSource()
srs_freep(play_edge); srs_freep(play_edge);
srs_freep(publish_edge); srs_freep(publish_edge);
srs_freep(gop_cache); srs_freep(gop_cache);
srs_freep(aggregate_stream);
srs_freep(req); 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) srs_error_t SrsSource::on_audio(SrsCommonMessage* shared_audio)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// monotically increase detect. // 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. // 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. // the payload is transfer to msg, and set to NULL in shared_audio.
SrsSharedPtrMessage msg; SrsSharedPtrMessage msg;
if ((ret = msg.create(shared_audio)) != ERROR_SUCCESS) { if ((err = msg.create(shared_audio)) != srs_success) {
return srs_error_new(ret, "create message"); return srs_error_wrap(err, "create message");
} }
// directly process the audio 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) srs_error_t SrsSource::on_video(SrsCommonMessage* shared_video)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// monotically increase detect. // 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. // 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. // the payload is transfer to msg, and set to NULL in shared_video.
SrsSharedPtrMessage msg; SrsSharedPtrMessage msg;
if ((ret = msg.create(shared_video)) != ERROR_SUCCESS) { if ((err = msg.create(shared_video)) != srs_success) {
return srs_error_new(ret, "create message"); return srs_error_wrap(err, "create message");
} }
// directly process the audio 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) srs_error_t SrsSource::on_aggregate(SrsCommonMessage* msg)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsBuffer* stream = aggregate_stream; SrsBuffer* stream = new SrsBuffer(msg->payload, msg->size);
if ((ret = stream->initialize(msg->payload, msg->size)) != ERROR_SUCCESS) { SrsAutoFree(SrsBuffer, stream);
return srs_error_new(ret, "init stream");
}
// the aggregate message always use abs time. // the aggregate message always use abs time.
int delta = -1; int delta = -1;
@ -2457,7 +2426,6 @@ void SrsSource::on_unpublish()
// when drop dup sequence header, drop the metadata also. // when drop dup sequence header, drop the metadata also.
gop_cache->clear(); gop_cache->clear();
srs_info("clear cache/metadata when unpublish.");
srs_trace("cleanup when unpublish"); srs_trace("cleanup when unpublish");
_can_publish = true; _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) 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; srs_error_t err = srs_success;
consumer = new SrsConsumer(this, conn); 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 // for edge, when play edge stream, check the state
if (_srs_config->get_vhost_is_edge(req->vhost)) { if (_srs_config->get_vhost_is_edge(req->vhost)) {
// notice edge to start for the first client. // notice edge to start for the first client.
if ((ret = play_edge->on_client_play()) != ERROR_SUCCESS) { if ((err = play_edge->on_client_play()) != srs_success) {
return srs_error_new(ret, "play edge"); return srs_error_wrap(err, "play edge");
} }
} }
@ -2534,7 +2501,6 @@ void SrsSource::on_consumer_destroy(SrsConsumer* consumer)
if (it != consumers.end()) { if (it != consumers.end()) {
consumers.erase(it); consumers.erase(it);
} }
srs_info("handle consumer destroy success.");
if (consumers.empty()) { if (consumers.empty()) {
play_edge->on_all_client_stop(); play_edge->on_all_client_stop();

View file

@ -594,8 +594,6 @@ private:
bool is_monotonically_increase; bool is_monotonically_increase;
// the time of the packet we just got. // the time of the packet we just got.
int64_t last_packet_time; int64_t last_packet_time;
// for aggregate message
SrsBuffer* aggregate_stream;
// the event handler. // the event handler.
ISrsSourceHandler* handler; ISrsSourceHandler* handler;
// edge control service // edge control service

View file

@ -55,7 +55,7 @@ public:
SrsStatisticVhost(); SrsStatisticVhost();
virtual ~SrsStatisticVhost(); virtual ~SrsStatisticVhost();
public: public:
virtual int dumps(SrsJsonObject* obj); virtual srs_error_t dumps(SrsJsonObject* obj);
}; };
struct SrsStatisticStream struct SrsStatisticStream
@ -101,7 +101,7 @@ public:
SrsStatisticStream(); SrsStatisticStream();
virtual ~SrsStatisticStream(); virtual ~SrsStatisticStream();
public: public:
virtual int dumps(SrsJsonObject* obj); virtual srs_error_t dumps(SrsJsonObject* obj);
public: public:
/** /**
* publish the stream. * publish the stream.
@ -126,7 +126,7 @@ public:
SrsStatisticClient(); SrsStatisticClient();
virtual ~SrsStatisticClient(); virtual ~SrsStatisticClient();
public: public:
virtual int dumps(SrsJsonObject* obj); virtual srs_error_t dumps(SrsJsonObject* obj);
}; };
class SrsStatistic class SrsStatistic
@ -166,16 +166,18 @@ public:
/** /**
* when got video info for stream. * 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. * 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. * When got videos, update the frames.
* We only stat the total number of video 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. * when publish stream.
* @param req the request object of publish connection. * @param req the request object of publish connection.
@ -194,7 +196,7 @@ public:
* @param conn, the physical absract connection object. * @param conn, the physical absract connection object.
* @param type, the type of connection. * @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 * client disconnect
* @remark the on_disconnect always call, while the on_client is call when * @remark the on_disconnect always call, while the on_client is call when
@ -222,17 +224,17 @@ public:
/** /**
* dumps the vhosts to amf0 array. * 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. * 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 * dumps the clients to amf0 array
* @param start the start index, from 0. * @param start the start index, from 0.
* @param count the max count of clients to dump. * @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: private:
virtual SrsStatisticVhost* create_vhost(SrsRequest* req); virtual SrsStatisticVhost* create_vhost(SrsRequest* req);
virtual SrsStatisticStream* create_stream(SrsStatisticVhost* vhost, SrsRequest* req); virtual SrsStatisticStream* create_stream(SrsStatisticVhost* vhost, SrsRequest* req);

View file

@ -155,17 +155,17 @@ string srs_path_build_timestamp(string template_path)
return 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) { if (pid <= 0) {
return ret; return err;
} }
// first, try kill by SIGTERM. // first, try kill by SIGTERM.
if (kill(pid, SIGTERM) < 0) { if (kill(pid, SIGTERM) < 0) {
return ERROR_SYSTEM_KILL; return srs_error_new(ERROR_SYSTEM_KILL, "kill");
} }
// wait to quit. // wait to quit.
@ -174,7 +174,7 @@ int srs_kill_forced(int& pid)
int status = 0; int status = 0;
pid_t qpid = -1; pid_t qpid = -1;
if ((qpid = waitpid(pid, &status, WNOHANG)) < 0) { if ((qpid = waitpid(pid, &status, WNOHANG)) < 0) {
return ERROR_SYSTEM_KILL; return srs_error_new(ERROR_SYSTEM_KILL, "kill");
} }
// 0 is not quit yet. // 0 is not quit yet.
@ -187,12 +187,12 @@ int srs_kill_forced(int& pid)
srs_trace("SIGTERM stop process pid=%d ok.", pid); srs_trace("SIGTERM stop process pid=%d ok.", pid);
pid = -1; pid = -1;
return ret; return err;
} }
// then, try kill by SIGKILL. // then, try kill by SIGKILL.
if (kill(pid, SIGKILL) < 0) { if (kill(pid, SIGKILL) < 0) {
return ERROR_SYSTEM_KILL; return srs_error_new(ERROR_SYSTEM_KILL, "kill");
} }
// wait for the process to quit. // 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); srs_trace("SIGKILL stop process pid=%d ok.", pid);
pid = -1; pid = -1;
return ret; return err;
} }
static SrsRusage _srs_system_rusage; static SrsRusage _srs_system_rusage;

View file

@ -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. * @param pid the pid to kill. ignore for -1. set to -1 when killed.
* @return an int error code. * @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. // current process resouce usage.
// @see: man getrusage // @see: man getrusage