优化临界状态丢起始帧的问题

This commit is contained in:
xiongziliang 2020-02-27 12:31:57 +08:00
parent 38584a7478
commit e6eee321ea
2 changed files with 31 additions and 10 deletions

View File

@ -64,22 +64,34 @@ void MediaSink::resetTracks() {
void MediaSink::inputFrame(const Frame::Ptr &frame) {
lock_guard<recursive_mutex> lck(_mtx);
auto codec_id = frame->getCodecId();
auto it = _track_map.find(codec_id);
auto it = _track_map.find(frame->getCodecId());
if (it == _track_map.end()) {
return;
}
it->second->inputFrame(frame);
checkTrackIfReady(it->second);
}
if(!_allTrackReady && !_trackReadyCallback.empty() && it->second->ready()){
void MediaSink::checkTrackIfReady_l(const Track::Ptr &track){
//Track由未就绪状态转换成就绪状态我们就触发onTrackReady回调
auto it_callback = _trackReadyCallback.find(codec_id);
if(it_callback != _trackReadyCallback.end()){
auto it_callback = _trackReadyCallback.find(track->getCodecId());
if (it_callback != _trackReadyCallback.end() && track->ready()) {
it_callback->second();
_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);
}
}
}
if(!_allTrackReady){
if(_ticker.elapsedTime() > MAX_WAIT_MS_READY){
//如果超过规定时间那么不再等待并忽略未准备好的Track
@ -107,9 +119,12 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) {
}
void MediaSink::addTrackCompleted(){
{
lock_guard<recursive_mutex> lck(_mtx);
_max_track_size = _track_map.size();
}
checkTrackIfReady(nullptr);
}
void MediaSink::emitAllTrackReady() {
if (_allTrackReady) {

View File

@ -121,6 +121,12 @@ private:
* onAllTrackReady事件
*/
void emitAllTrackReady();
/**
* track是否准备完毕
*/
void checkTrackIfReady(const Track::Ptr &track);
void checkTrackIfReady_l(const Track::Ptr &track);
private:
mutable recursive_mutex _mtx;
map<int,Track::Ptr> _track_map;