完成HLS按需生成流

This commit is contained in:
xiongziliang 2019-12-29 12:10:31 +08:00
parent 4b4c4e0cec
commit 236dc46b82
2 changed files with 21 additions and 7 deletions

View File

@ -30,20 +30,31 @@ namespace mediakit{
HlsCookieData::HlsCookieData(const MediaInfo &info) { HlsCookieData::HlsCookieData(const MediaInfo &info) {
_info = info; _info = info;
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid)); addReaderCount();
if(src){ }
src->modifyCount(true);
void HlsCookieData::addReaderCount(){
if(!_added){
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
if(src){
src->modifyReaderCount(true);
_added = true;
}
} }
} }
HlsCookieData::~HlsCookieData() { HlsCookieData::~HlsCookieData() {
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid)); if(_added){
if(src){ auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
src->modifyCount(false); if(src){
src->modifyReaderCount(false);
}
} }
} }
void HlsCookieData::addByteUsage(uint64_t bytes) { void HlsCookieData::addByteUsage(uint64_t bytes) {
addReaderCount();
_bytes += bytes; _bytes += bytes;
} }

View File

@ -35,9 +35,12 @@ public:
HlsCookieData(const MediaInfo &info); HlsCookieData(const MediaInfo &info);
~HlsCookieData(); ~HlsCookieData();
void addByteUsage(uint64_t bytes); void addByteUsage(uint64_t bytes);
private:
void addReaderCount();
private: private:
uint64_t _bytes = 0; uint64_t _bytes = 0;
MediaInfo _info; MediaInfo _info;
bool _added = false;
}; };
class HlsMediaSource : public MediaSource { class HlsMediaSource : public MediaSource {
@ -73,7 +76,7 @@ private:
* *
* @param add * @param add
*/ */
void modifyCount(bool add) { void modifyReaderCount(bool add) {
if (add) { if (add) {
++_readerCount; ++_readerCount;
return; return;