Skip to content

Commit

Permalink
for #442, add publish connection in stream.publish api
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 22, 2015
1 parent 529803e commit b37797b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ int SrsSource::on_publish()
return ret;
}
SrsStatistic* stat = SrsStatistic::instance();
stat->on_stream_publish(_req);
stat->on_stream_publish(_req, _source_id);
return ret;
}

Expand Down
21 changes: 13 additions & 8 deletions trunk/src/app/srs_app_statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ SrsStatisticStream::SrsStatisticStream()
{
id = srs_generate_id();
vhost = NULL;
status = STATISTIC_STREAM_STATUS_IDLING;
active = false;
connection_cid = -1;

has_video = false;
vcodec = SrsCodecVideoReserved;
Expand Down Expand Up @@ -124,15 +125,18 @@ int SrsStatisticStream::dumps(stringstream& ss)
<< SRS_JFIELD_STR("name", stream) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("vhost", vhost->id) << 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("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT
<< SRS_JFIELD_OBJ("kbps")
<< SRS_JFIELD_ORG("recv_30s", kbps->get_recv_kbps_30s()) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("send_30s", kbps->get_send_kbps_30s())
<< SRS_JOBJECT_END << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("status", status) << SRS_JFIELD_CONT;
<< SRS_JFIELD_OBJ("publish")
<< SRS_JFIELD_BOOL("active", active) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("cid", connection_cid)
<< SRS_JOBJECT_END << SRS_JFIELD_CONT;

if (!has_video) {
ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT;
Expand Down Expand Up @@ -161,16 +165,17 @@ int SrsStatisticStream::dumps(stringstream& ss)
return ret;
}

void SrsStatisticStream::publish()
void SrsStatisticStream::publish(int cid)
{
status = STATISTIC_STREAM_STATUS_PUBLISHING;
connection_cid = cid;
active = true;
}

void SrsStatisticStream::close()
{
has_video = false;
has_audio = false;
status = STATISTIC_STREAM_STATUS_IDLING;
active = false;
}

SrsStatisticClient::SrsStatisticClient()
Expand Down Expand Up @@ -301,12 +306,12 @@ int SrsStatistic::on_audio_info(SrsRequest* req,
return ret;
}

void SrsStatistic::on_stream_publish(SrsRequest* req)
void SrsStatistic::on_stream_publish(SrsRequest* req, int cid)
{
SrsStatisticVhost* vhost = create_vhost(req);
SrsStatisticStream* stream = create_stream(vhost, req);

stream->publish();
stream->publish(cid);
}

void SrsStatistic::on_stream_close(SrsRequest* req)
Expand Down
16 changes: 8 additions & 8 deletions trunk/src/app/srs_app_statistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <srs_kernel_codec.hpp>

#define STATISTIC_STREAM_STATUS_PUBLISHING "publishing"
#define STATISTIC_STREAM_STATUS_IDLING "idling"

class SrsKbps;
class SrsRequest;
class SrsConnection;
Expand Down Expand Up @@ -68,7 +65,8 @@ struct SrsStatisticStream
std::string app;
std::string stream;
std::string url;
std::string status;
bool active;
int connection_cid;
int nb_clients;
public:
/**
Expand Down Expand Up @@ -103,7 +101,7 @@ struct SrsStatisticStream
/**
* publish the stream.
*/
virtual void publish();
virtual void publish(int cid);
/**
* close the stream.
*/
Expand Down Expand Up @@ -169,9 +167,11 @@ class SrsStatistic
SrsAacObjectType aac_object
);
/**
* when publish stream.
*/
virtual void on_stream_publish(SrsRequest* req);
* when publish stream.
* @param req the request object of publish connection.
* @param cid the cid of publish connection.
*/
virtual void on_stream_publish(SrsRequest* req, int cid);
/**
* when close stream.
*/
Expand Down

0 comments on commit b37797b

Please sign in to comment.