完善hls播放器个数计数

This commit is contained in:
xiongziliang 2019-12-28 16:57:35 +08:00
parent f93b32740f
commit e72fa359b6
7 changed files with 15 additions and 4 deletions

View File

@ -109,6 +109,8 @@ API_EXPORT const char* API_CALL mk_media_source_get_app(const mk_media_source ct
API_EXPORT const char* API_CALL mk_media_source_get_stream(const mk_media_source ctx); API_EXPORT const char* API_CALL mk_media_source_get_stream(const mk_media_source ctx);
//MediaSource::readerCount() //MediaSource::readerCount()
API_EXPORT int API_CALL mk_media_source_get_reader_count(const mk_media_source ctx); API_EXPORT int API_CALL mk_media_source_get_reader_count(const mk_media_source ctx);
//MediaSource::totalReaderCount()
API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_source ctx);
//MediaSource::close() //MediaSource::close()
API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force); API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force);
//MediaSource::seekTo() //MediaSource::seekTo()

View File

@ -199,6 +199,13 @@ API_EXPORT int API_CALL mk_media_source_get_reader_count(const mk_media_source c
MediaSource *src = (MediaSource *)ctx; MediaSource *src = (MediaSource *)ctx;
return src->readerCount(); return src->readerCount();
} }
API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_source ctx){
assert(ctx);
MediaSource *src = (MediaSource *)ctx;
return src->totalReaderCount();
}
API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){ API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){
assert(ctx); assert(ctx);
MediaSource *src = (MediaSource *)ctx; MediaSource *src = (MediaSource *)ctx;

View File

@ -412,6 +412,7 @@ void installWebApi() {
item["app"] = media->getApp(); item["app"] = media->getApp();
item["stream"] = media->getId(); item["stream"] = media->getId();
item["readerCount"] = media->readerCount(); item["readerCount"] = media->readerCount();
item["totalReaderCount"] = media->totalReaderCount();
for(auto &track : media->getTracks()){ for(auto &track : media->getTracks()){
Value obj; Value obj;
obj["codec_id"] = track->getCodecId(); obj["codec_id"] = track->getCodecId();
@ -441,6 +442,7 @@ void installWebApi() {
} }
val["online"] = true; val["online"] = true;
val["readerCount"] = src->readerCount(); val["readerCount"] = src->readerCount();
val["totalReaderCount"] = src->totalReaderCount();
for(auto &track : src->getTracks()){ for(auto &track : src->getTracks()){
Value obj; Value obj;
obj["codec_id"] = track->getCodecId(); obj["codec_id"] = track->getCodecId();

View File

@ -175,7 +175,7 @@ private:
void onReaderChanged(int size) { void onReaderChanged(int size) {
//我们记录最后一次活动时间 //我们记录最后一次活动时间
_reader_changed_ticker.resetTime(); _reader_changed_ticker.resetTime();
if (size != 0 || readerCount() != 0) { if (size != 0 || totalReaderCount() != 0) {
//还有消费者正在观看该流 //还有消费者正在观看该流
_async_emit_none_reader = false; _async_emit_none_reader = false;
return; return;

View File

@ -302,7 +302,7 @@ void RtmpSession::sendPlayResponse(const string &err,const RtmpMediaSource::Ptr
strongSelf->shutdown(SockException(Err_shutdown,"rtmp ring buffer detached")); strongSelf->shutdown(SockException(Err_shutdown,"rtmp ring buffer detached"));
}); });
_pPlayerSrc = src; _pPlayerSrc = src;
if (src->readerCount() == 1) { if (src->totalReaderCount() == 1) {
src->seekTo(0); src->seekTo(0);
} }
//提高服务器发送性能 //提高服务器发送性能

View File

@ -195,7 +195,7 @@ private:
void onReaderChanged(int size) { void onReaderChanged(int size) {
//我们记录最后一次活动时间 //我们记录最后一次活动时间
_reader_changed_ticker.resetTime(); _reader_changed_ticker.resetTime();
if (size != 0 || readerCount() != 0) { if (size != 0 || totalReaderCount() != 0) {
//还有消费者正在观看该流 //还有消费者正在观看该流
_async_emit_none_reader = false; _async_emit_none_reader = false;
return; return;

View File

@ -773,7 +773,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
auto iStartTime = 1000 * atof(strStart.data()); auto iStartTime = 1000 * atof(strStart.data());
InfoP(this) << "rtsp seekTo(ms):" << iStartTime; InfoP(this) << "rtsp seekTo(ms):" << iStartTime;
useBuf = !pMediaSrc->seekTo(iStartTime); useBuf = !pMediaSrc->seekTo(iStartTime);
}else if(pMediaSrc->readerCount() == 0){ }else if(pMediaSrc->totalReaderCount() == 0){
//第一个消费者 //第一个消费者
pMediaSrc->seekTo(0); pMediaSrc->seekTo(0);
} }