mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
优化临界状态丢起始帧的问题
This commit is contained in:
parent
38584a7478
commit
e6eee321ea
@ -64,19 +64,31 @@ void MediaSink::resetTracks() {
|
|||||||
|
|
||||||
void MediaSink::inputFrame(const Frame::Ptr &frame) {
|
void MediaSink::inputFrame(const Frame::Ptr &frame) {
|
||||||
lock_guard<recursive_mutex> lck(_mtx);
|
lock_guard<recursive_mutex> lck(_mtx);
|
||||||
auto codec_id = frame->getCodecId();
|
auto it = _track_map.find(frame->getCodecId());
|
||||||
auto it = _track_map.find(codec_id);
|
|
||||||
if (it == _track_map.end()) {
|
if (it == _track_map.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it->second->inputFrame(frame);
|
it->second->inputFrame(frame);
|
||||||
|
checkTrackIfReady(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
if(!_allTrackReady && !_trackReadyCallback.empty() && it->second->ready()){
|
void MediaSink::checkTrackIfReady_l(const Track::Ptr &track){
|
||||||
//Track由未就绪状态转换成就绪状态,我们就触发onTrackReady回调
|
//Track由未就绪状态转换成就绪状态,我们就触发onTrackReady回调
|
||||||
auto it_callback = _trackReadyCallback.find(codec_id);
|
auto it_callback = _trackReadyCallback.find(track->getCodecId());
|
||||||
if(it_callback != _trackReadyCallback.end()){
|
if (it_callback != _trackReadyCallback.end() && track->ready()) {
|
||||||
it_callback->second();
|
it_callback->second();
|
||||||
_trackReadyCallback.erase(it_callback);
|
_trackReadyCallback.erase(it_callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaSink::checkTrackIfReady(const Track::Ptr &track){
|
||||||
|
if (!_allTrackReady && !_trackReadyCallback.empty()) {
|
||||||
|
if (track) {
|
||||||
|
checkTrackIfReady_l(track);
|
||||||
|
} else {
|
||||||
|
for (auto &pr : _track_map) {
|
||||||
|
checkTrackIfReady_l(pr.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +119,11 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MediaSink::addTrackCompleted(){
|
void MediaSink::addTrackCompleted(){
|
||||||
lock_guard<recursive_mutex> lck(_mtx);
|
{
|
||||||
_max_track_size = _track_map.size();
|
lock_guard<recursive_mutex> lck(_mtx);
|
||||||
|
_max_track_size = _track_map.size();
|
||||||
|
}
|
||||||
|
checkTrackIfReady(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaSink::emitAllTrackReady() {
|
void MediaSink::emitAllTrackReady() {
|
||||||
|
@ -121,6 +121,12 @@ private:
|
|||||||
* 触发onAllTrackReady事件
|
* 触发onAllTrackReady事件
|
||||||
*/
|
*/
|
||||||
void emitAllTrackReady();
|
void emitAllTrackReady();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查track是否准备完毕
|
||||||
|
*/
|
||||||
|
void checkTrackIfReady(const Track::Ptr &track);
|
||||||
|
void checkTrackIfReady_l(const Track::Ptr &track);
|
||||||
private:
|
private:
|
||||||
mutable recursive_mutex _mtx;
|
mutable recursive_mutex _mtx;
|
||||||
map<int,Track::Ptr> _track_map;
|
map<int,Track::Ptr> _track_map;
|
||||||
|
Loading…
Reference in New Issue
Block a user