mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-13 11:41:44 +08:00
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user