全局自动添加静音音频

This commit is contained in:
ziyue 2021-09-27 13:20:34 +08:00
parent e9008afca0
commit afec4b62b9
2 changed files with 12 additions and 12 deletions

View File

@ -31,6 +31,12 @@ 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) {
@ -39,9 +45,9 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
}
//克隆Track只拷贝其数据不拷贝其数据转发关系
auto track = track_in->clone();
auto codec_id = track->getCodecId();
_track_map[codec_id] = track;
_track_ready_callback[codec_id] = [this, track]() {
auto track_type = track->getTrackType();
_track_map[track_type] = track;
_track_ready_callback[track_type] = [this, track]() {
onTrackReady(track);
};
_ticker.resetTime();
@ -50,7 +56,7 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
if (_all_track_ready) {
return onTrackFrame(frame);
}
auto &frame_unread = _frame_unread[frame->getCodecId()];
auto &frame_unread = _frame_unread[frame->getTrackType()];
if (frame_unread.size() > kMaxUnreadyFrame) {
//未就绪的的track不能缓存太多的帧否则可能内存溢出
frame_unread.clear();
@ -75,7 +81,7 @@ void MediaSink::resetTracks() {
bool MediaSink::inputFrame(const Frame::Ptr &frame) {
lock_guard<recursive_mutex> lck(_mtx);
auto it = _track_map.find(frame->getCodecId());
auto it = _track_map.find(frame->getTrackType());
if (it == _track_map.end()) {
return false;
}
@ -90,7 +96,7 @@ bool MediaSink::inputFrame(const Frame::Ptr &frame) {
void MediaSink::checkTrackIfReady_l(const Track::Ptr &track){
//Track由未就绪状态转换成就绪状态我们就触发onTrackReady回调
auto it_callback = _track_ready_callback.find(track->getCodecId());
auto it_callback = _track_ready_callback.find(track->getTrackType());
if (it_callback != _track_ready_callback.end() && track->ready()) {
it_callback->second();
_track_ready_callback.erase(it_callback);

View File

@ -207,18 +207,12 @@ void PlayerProxy::onPlaySuccess() {
videoTrack->addDelegate(_muxer);
}
//是否添加静音音频
GET_CONFIG(bool, addMuteAudio, General::kAddMuteAudio);
auto audioTrack = getTrack(TrackAudio, false);
if (audioTrack) {
//添加音频
_muxer->addTrack(audioTrack);
//音频数据写入_mediaMuxer
audioTrack->addDelegate(_muxer);
} else if (addMuteAudio && videoTrack) {
//没有音频信息,产生一个静音音频
_muxer->addMuteAudioTrack();
}
//添加完毕所有track防止单track情况下最大等待3秒