for #442, add publish connection in stream.publish api

pull/499/head
winlin 10 years ago
parent 529803ed04
commit b37797b13a

@ -2066,7 +2066,7 @@ int SrsSource::on_publish()
return ret; return ret;
} }
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
stat->on_stream_publish(_req); stat->on_stream_publish(_req, _source_id);
return ret; return ret;
} }

@ -91,7 +91,8 @@ SrsStatisticStream::SrsStatisticStream()
{ {
id = srs_generate_id(); id = srs_generate_id();
vhost = NULL; vhost = NULL;
status = STATISTIC_STREAM_STATUS_IDLING; active = false;
connection_cid = -1;
has_video = false; has_video = false;
vcodec = SrsCodecVideoReserved; vcodec = SrsCodecVideoReserved;
@ -124,6 +125,7 @@ int SrsStatisticStream::dumps(stringstream& ss)
<< SRS_JFIELD_STR("name", stream) << SRS_JFIELD_CONT << SRS_JFIELD_STR("name", stream) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("vhost", vhost->id) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("vhost", vhost->id) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("app", app) << SRS_JFIELD_CONT << SRS_JFIELD_STR("app", app) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT
@ -131,8 +133,10 @@ int SrsStatisticStream::dumps(stringstream& ss)
<< SRS_JFIELD_ORG("recv_30s", kbps->get_recv_kbps_30s()) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("recv_30s", kbps->get_recv_kbps_30s()) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("send_30s", kbps->get_send_kbps_30s()) << SRS_JFIELD_ORG("send_30s", kbps->get_send_kbps_30s())
<< SRS_JOBJECT_END << SRS_JFIELD_CONT << SRS_JOBJECT_END << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT << SRS_JFIELD_OBJ("publish")
<< SRS_JFIELD_STR("status", status) << SRS_JFIELD_CONT; << SRS_JFIELD_BOOL("active", active) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("cid", connection_cid)
<< SRS_JOBJECT_END << SRS_JFIELD_CONT;
if (!has_video) { if (!has_video) {
ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT; ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT;
@ -161,16 +165,17 @@ int SrsStatisticStream::dumps(stringstream& ss)
return ret; return ret;
} }
void SrsStatisticStream::publish() void SrsStatisticStream::publish(int cid)
{ {
status = STATISTIC_STREAM_STATUS_PUBLISHING; connection_cid = cid;
active = true;
} }
void SrsStatisticStream::close() void SrsStatisticStream::close()
{ {
has_video = false; has_video = false;
has_audio = false; has_audio = false;
status = STATISTIC_STREAM_STATUS_IDLING; active = false;
} }
SrsStatisticClient::SrsStatisticClient() SrsStatisticClient::SrsStatisticClient()
@ -301,12 +306,12 @@ int SrsStatistic::on_audio_info(SrsRequest* req,
return ret; return ret;
} }
void SrsStatistic::on_stream_publish(SrsRequest* req) void SrsStatistic::on_stream_publish(SrsRequest* req, int cid)
{ {
SrsStatisticVhost* vhost = create_vhost(req); SrsStatisticVhost* vhost = create_vhost(req);
SrsStatisticStream* stream = create_stream(vhost, req); SrsStatisticStream* stream = create_stream(vhost, req);
stream->publish(); stream->publish(cid);
} }
void SrsStatistic::on_stream_close(SrsRequest* req) void SrsStatistic::on_stream_close(SrsRequest* req)

@ -35,9 +35,6 @@ 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;
@ -68,7 +65,8 @@ public:
std::string app; std::string app;
std::string stream; std::string stream;
std::string url; std::string url;
std::string status; bool active;
int connection_cid;
int nb_clients; int nb_clients;
public: public:
/** /**
@ -103,7 +101,7 @@ public:
/** /**
* publish the stream. * publish the stream.
*/ */
virtual void publish(); virtual void publish(int cid);
/** /**
* close the stream. * close the stream.
*/ */
@ -169,9 +167,11 @@ public:
SrsAacObjectType aac_object SrsAacObjectType aac_object
); );
/** /**
* when publish stream. * when publish stream.
*/ * @param req the request object of publish connection.
virtual void on_stream_publish(SrsRequest* req); * @param cid the cid of publish connection.
*/
virtual void on_stream_publish(SrsRequest* req, int cid);
/** /**
* when close stream. * when close stream.
*/ */

Loading…
Cancel
Save