完成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) {
_info = info;
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
if(src){
src->modifyCount(true);
addReaderCount();
}
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() {
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
if(src){
src->modifyCount(false);
if(_added){
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
if(src){
src->modifyReaderCount(false);
}
}
}
void HlsCookieData::addByteUsage(uint64_t bytes) {
addReaderCount();
_bytes += bytes;
}

View File

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