MediaSink: 静音音频确保最后添加

This commit is contained in:
ziyue 2021-11-10 10:41:03 +08:00
parent dad0c5e3cc
commit ded5d83e04
2 changed files with 12 additions and 12 deletions

View File

@ -31,12 +31,6 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
//音频被全局忽略
return false;
}
} else {
//是否添加静音音频
GET_CONFIG(bool, addMuteAudio, General::kAddMuteAudio);
if (addMuteAudio && track_in->getTrackType() == TrackVideo) {
addMuteAudioTrack();
}
}
lock_guard<recursive_mutex> lck(_mtx);
if (_all_track_ready) {
@ -46,10 +40,6 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
//克隆Track只拷贝其数据不拷贝其数据转发关系
auto track = track_in->clone();
auto track_type = track->getTrackType();
if (track_type == TrackAudio) {
//确保添加非静音音频track时取消之前的静音音频track
_mute_audio_maker = nullptr;
}
_track_map[track_type] = track;
_track_ready_callback[track_type] = [this, track]() {
onTrackReady(track);
@ -172,8 +162,7 @@ void MediaSink::emitAllTrackReady() {
if (!_track_map.empty()) {
//最少有一个有效的Track
_all_track_ready = true;
onAllTrackReady();
onAllTrackReady_l();
//全部Track就绪我们一次性把之前的帧输出
for(auto &pr : _frame_unread){
@ -189,6 +178,16 @@ void MediaSink::emitAllTrackReady() {
}
}
void MediaSink::onAllTrackReady_l() {
//是否添加静音音频
GET_CONFIG(bool, addMuteAudio, General::kAddMuteAudio);
if (addMuteAudio && !_track_map[TrackAudio]) {
addMuteAudioTrack();
}
onAllTrackReady();
_all_track_ready = true;
}
vector<Track::Ptr> MediaSink::getTracks(bool trackReady) const{
vector<Track::Ptr> ret;
lock_guard<recursive_mutex> lck(_mtx);

View File

@ -143,6 +143,7 @@ private:
*/
void checkTrackIfReady(const Track::Ptr &track);
void checkTrackIfReady_l(const Track::Ptr &track);
void onAllTrackReady_l();
private:
bool _all_track_ready = false;