mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
优化单Track情况下等待3秒的情况
This commit is contained in:
parent
f76109c629
commit
d60101b93c
@ -59,6 +59,7 @@ void MediaSink::resetTracks() {
|
||||
_track_map.clear();
|
||||
_trackReadyCallback.clear();
|
||||
_ticker.resetTime();
|
||||
_max_track_size = 2;
|
||||
}
|
||||
|
||||
void MediaSink::inputFrame(const Frame::Ptr &frame) {
|
||||
@ -82,7 +83,7 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) {
|
||||
if(!_allTrackReady){
|
||||
if(_ticker.elapsedTime() > MAX_WAIT_MS_READY){
|
||||
//如果超过规定时间,那么不再等待并忽略未准备好的Track
|
||||
addTrackCompleted();
|
||||
emitAllTrackReady();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,21 +92,26 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(_track_map.size() == 2){
|
||||
if(_track_map.size() == _max_track_size){
|
||||
//如果已经添加了音视频Track,并且不存在未准备好的Track,那么说明所有Track都准备好了
|
||||
addTrackCompleted();
|
||||
emitAllTrackReady();
|
||||
return;
|
||||
}
|
||||
|
||||
if(_track_map.size() == 1 && _ticker.elapsedTime() > MAX_WAIT_MS_ADD_TRACK){
|
||||
//如果只有一个Track,那么在该Track添加后,我们最多还等待若干时间(可能后面还会添加Track)
|
||||
addTrackCompleted();
|
||||
emitAllTrackReady();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MediaSink::addTrackCompleted() {
|
||||
void MediaSink::addTrackCompleted(){
|
||||
lock_guard<recursive_mutex> lck(_mtx);
|
||||
_max_track_size = _track_map.size();
|
||||
}
|
||||
|
||||
void MediaSink::emitAllTrackReady() {
|
||||
if (_allTrackReady) {
|
||||
return;
|
||||
}
|
||||
|
@ -116,12 +116,18 @@ protected:
|
||||
* @param frame
|
||||
*/
|
||||
virtual void onTrackFrame(const Frame::Ptr &frame) {};
|
||||
private:
|
||||
/**
|
||||
* 触发onAllTrackReady事件
|
||||
*/
|
||||
void emitAllTrackReady();
|
||||
private:
|
||||
mutable recursive_mutex _mtx;
|
||||
map<int,Track::Ptr> _track_map;
|
||||
map<int,function<void()> > _trackReadyCallback;
|
||||
bool _allTrackReady = false;
|
||||
Ticker _ticker;
|
||||
int _max_track_size = 2;
|
||||
};
|
||||
|
||||
|
||||
|
@ -291,6 +291,9 @@ void PlayerProxy::onPlaySuccess() {
|
||||
audioMaker->addDelegate(_mediaMuxer);
|
||||
}
|
||||
|
||||
//添加完毕所有track,防止单track情况下最大等待3秒
|
||||
_mediaMuxer->addTrackCompleted();
|
||||
|
||||
if(_pMediaSrc){
|
||||
_pMediaSrc->setTrackSource(_mediaMuxer);
|
||||
}
|
||||
|
@ -151,6 +151,9 @@ MP4Reader::MP4Reader(const string &strVhost,const string &strApp, const string &
|
||||
H264Track::Ptr track = std::make_shared<H264Track>(_strSps,_strPps);
|
||||
_mediaMuxer->addTrack(track);
|
||||
}
|
||||
|
||||
//添加完毕所有track,防止单track情况下最大等待3秒
|
||||
_mediaMuxer->addTrackCompleted();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user