mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-27 21:02:23 +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();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
@@ -219,6 +220,9 @@ public:
|
||||
// 流id
|
||||
const string& getId() const;
|
||||
|
||||
//获取对象所有权
|
||||
std::shared_ptr<void> getOwnership();
|
||||
|
||||
// 获取所有Track
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||
|
||||
@@ -301,6 +305,7 @@ protected:
|
||||
BytesSpeed _speed[TrackMax];
|
||||
|
||||
private:
|
||||
atomic_flag _owned { false };
|
||||
time_t _create_stamp;
|
||||
Ticker _ticker;
|
||||
string _schema;
|
||||
|
||||
@@ -78,6 +78,7 @@ const string kEnableAudio = GENERAL_FIELD"enable_audio";
|
||||
const string kWaitTrackReadyMS = GENERAL_FIELD"wait_track_ready_ms";
|
||||
const string kWaitAddTrackMS = GENERAL_FIELD"wait_add_track_ms";
|
||||
const string kUnreadyFrameCache = GENERAL_FIELD"unready_frame_cache";
|
||||
const string kContinuePushMS = GENERAL_FIELD"continue_push_ms";
|
||||
|
||||
onceToken token([](){
|
||||
mINI::Instance()[kFlowThreshold] = 1024;
|
||||
@@ -100,6 +101,7 @@ onceToken token([](){
|
||||
mINI::Instance()[kWaitTrackReadyMS] = 10000;
|
||||
mINI::Instance()[kWaitAddTrackMS] = 3000;
|
||||
mINI::Instance()[kUnreadyFrameCache] = 100;
|
||||
mINI::Instance()[kContinuePushMS] = 15 * 1000;
|
||||
},nullptr);
|
||||
|
||||
}//namespace General
|
||||
|
||||
@@ -193,6 +193,9 @@ extern const string kWaitTrackReadyMS;
|
||||
extern const string kWaitAddTrackMS;
|
||||
//如果track未就绪,我们先缓存帧数据,但是有最大个数限制(100帧时大约4秒),防止内存溢出
|
||||
extern const string kUnreadyFrameCache;
|
||||
//推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
|
||||
//置0关闭此特性(推流断开会导致立即断开播放器)
|
||||
extern const string kContinuePushMS;
|
||||
}//namespace General
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user