rtsp/rtmp推流支持断连续推: #1240, #1300

This commit is contained in:
ziyue
2022-01-10 16:37:50 +08:00
parent 262af8dfeb
commit f5efd232a9
10 changed files with 240 additions and 130 deletions

View File

@@ -85,6 +85,20 @@ const string& MediaSource::getId() const {
return _stream_id;
}
std::shared_ptr<void> MediaSource::getOwnership() {
if (_owned.test_and_set()) {
//已经被所有
return nullptr;
}
weak_ptr<MediaSource> weak_self = shared_from_this();
return std::shared_ptr<void>(this, [weak_self](void *ptr) {
auto strong_self = weak_self.lock();
if (strong_self) {
strong_self->_owned.clear();
}
});
}
int MediaSource::getBytesSpeed(TrackType type){
if(type == TrackInvalid){
return _speed[TrackVideo].getSpeed() + _speed[TrackAudio].getSpeed();
@@ -419,8 +433,12 @@ void MediaSource::regist() {
//减小互斥锁临界区
lock_guard<recursive_mutex> lock(s_media_source_mtx);
auto &ref = s_media_source_map[_schema][_vhost][_app][_stream_id];
// 增加判断, 防止当前流已注册时再次注册
if (ref.lock() && ref.lock().get() != this) {
auto src = ref.lock();
if (src) {
if (src.get() == this) {
return;
}
//增加判断, 防止当前流已注册时再次注册
throw std::invalid_argument("media source already existed:" + _schema + "/" + _vhost + "/" + _app + "/" + _stream_id);
}
ref = shared_from_this();