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

add stream status to api.

This commit is contained in:
winlin 2015-05-08 16:45:25 +08:00
parent ac13817aae
commit 7fc1cda392
5 changed files with 35 additions and 4 deletions

2
trunk/auto/depends.sh Executable file → Normal file
View file

@ -572,7 +572,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
rm -rf research/api-server/static-dir/forward && rm -rf research/api-server/static-dir/forward &&
mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward && mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
ret=$?; if [[ $ret -ne 0 ]]; then echo "link players to cherrypy static-dir failed, ret=$ret"; exit $ret; fi ret=$?; if [[ $ret -ne 0 ]]; then echo "[warn] link players to cherrypy static-dir failed"; fi
fi fi
##################################################################################### #####################################################################################

View file

@ -2570,7 +2570,7 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost)
return SRS_CONF_DEFAULT_EDGE_MODE; return SRS_CONF_DEFAULT_EDGE_MODE;
} }
return conf->arg0() == "remote"; return "remote" == conf->arg0();
} }
SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost) SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost)

View file

@ -1917,7 +1917,8 @@ int SrsSource::on_publish()
srs_error("handle on publish failed. ret=%d", ret); srs_error("handle on publish failed. ret=%d", ret);
return ret; return ret;
} }
SrsStatistic* stat = SrsStatistic::instance();
stat->on_stream_publish(_req);
return ret; return ret;
} }
@ -1958,6 +1959,8 @@ void SrsSource::on_unpublish()
// notify the handler. // notify the handler.
srs_assert(handler); srs_assert(handler);
SrsStatistic* stat = SrsStatistic::instance();
stat->on_stream_close(_req);
handler->on_unpublish(this, _req); handler->on_unpublish(this, _req);
} }

View file

@ -58,6 +58,7 @@ SrsStatisticStream::SrsStatisticStream()
{ {
id = srs_generate_id(); id = srs_generate_id();
vhost = NULL; vhost = NULL;
status = STATISTIC_STREAM_STATUS_IDLING;
has_video = false; has_video = false;
vcodec = SrsCodecVideoReserved; vcodec = SrsCodecVideoReserved;
@ -79,10 +80,16 @@ SrsStatisticStream::~SrsStatisticStream()
srs_freep(kbps); srs_freep(kbps);
} }
void SrsStatisticStream::publish()
{
status = STATISTIC_STREAM_STATUS_PUBLISHING;
}
void SrsStatisticStream::close() void SrsStatisticStream::close()
{ {
has_video = false; has_video = false;
has_audio = false; has_audio = false;
status = STATISTIC_STREAM_STATUS_IDLING;
} }
SrsStatistic* SrsStatistic::_instance = new SrsStatistic(); SrsStatistic* SrsStatistic::_instance = new SrsStatistic();
@ -161,6 +168,14 @@ int SrsStatistic::on_audio_info(SrsRequest* req,
return ret; return ret;
} }
void SrsStatistic::on_stream_publish(SrsRequest* req)
{
SrsStatisticVhost* vhost = create_vhost(req);
SrsStatisticStream* stream = create_stream(vhost, req);
stream->publish();
}
void SrsStatistic::on_stream_close(SrsRequest* req) void SrsStatistic::on_stream_close(SrsRequest* req)
{ {
SrsStatisticVhost* vhost = create_vhost(req); SrsStatisticVhost* vhost = create_vhost(req);
@ -308,7 +323,8 @@ int SrsStatistic::dumps_streams(stringstream& ss)
<< SRS_JFIELD_ORG("clients", client_num) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("clients", client_num) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("send_bytes", stream->kbps->get_send_bytes()) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("send_bytes", stream->kbps->get_send_bytes()) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("recv_bytes", stream->kbps->get_recv_bytes()) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("recv_bytes", stream->kbps->get_recv_bytes()) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT; << SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("status", stream->status) << SRS_JFIELD_CONT;
if (!stream->has_video) { if (!stream->has_video) {
ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT; ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT;

View file

@ -35,6 +35,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_codec.hpp> #include <srs_kernel_codec.hpp>
#define STATISTIC_STREAM_STATUS_PUBLISHING "publishing"
#define STATISTIC_STREAM_STATUS_IDLING "idling"
class SrsKbps; class SrsKbps;
class SrsRequest; class SrsRequest;
class SrsConnection; class SrsConnection;
@ -62,6 +65,7 @@ public:
std::string app; std::string app;
std::string stream; std::string stream;
std::string url; std::string url;
std::string status;
public: public:
/** /**
* stream total kbps. * stream total kbps.
@ -90,6 +94,10 @@ public:
SrsStatisticStream(); SrsStatisticStream();
virtual ~SrsStatisticStream(); virtual ~SrsStatisticStream();
public: public:
/**
* publish the stream.
*/
virtual void publish();
/** /**
* close the stream. * close the stream.
*/ */
@ -137,6 +145,10 @@ public:
SrsAacObjectType aac_object SrsAacObjectType aac_object
); );
/** /**
* when publish stream.
*/
virtual void on_stream_publish(SrsRequest* req);
/**
* when close stream. * when close stream.
*/ */
virtual void on_stream_close(SrsRequest* req); virtual void on_stream_close(SrsRequest* req);