mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
全局自动添加静音音频
This commit is contained in:
parent
e9008afca0
commit
afec4b62b9
@ -31,6 +31,12 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
|
|||||||
//音频被全局忽略
|
//音频被全局忽略
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
//是否添加静音音频
|
||||||
|
GET_CONFIG(bool, addMuteAudio, General::kAddMuteAudio);
|
||||||
|
if (addMuteAudio && track_in->getTrackType() == TrackVideo) {
|
||||||
|
addMuteAudioTrack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lock_guard<recursive_mutex> lck(_mtx);
|
lock_guard<recursive_mutex> lck(_mtx);
|
||||||
if (_all_track_ready) {
|
if (_all_track_ready) {
|
||||||
@ -39,9 +45,9 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
|
|||||||
}
|
}
|
||||||
//克隆Track,只拷贝其数据,不拷贝其数据转发关系
|
//克隆Track,只拷贝其数据,不拷贝其数据转发关系
|
||||||
auto track = track_in->clone();
|
auto track = track_in->clone();
|
||||||
auto codec_id = track->getCodecId();
|
auto track_type = track->getTrackType();
|
||||||
_track_map[codec_id] = track;
|
_track_map[track_type] = track;
|
||||||
_track_ready_callback[codec_id] = [this, track]() {
|
_track_ready_callback[track_type] = [this, track]() {
|
||||||
onTrackReady(track);
|
onTrackReady(track);
|
||||||
};
|
};
|
||||||
_ticker.resetTime();
|
_ticker.resetTime();
|
||||||
@ -50,7 +56,7 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
|
|||||||
if (_all_track_ready) {
|
if (_all_track_ready) {
|
||||||
return onTrackFrame(frame);
|
return onTrackFrame(frame);
|
||||||
}
|
}
|
||||||
auto &frame_unread = _frame_unread[frame->getCodecId()];
|
auto &frame_unread = _frame_unread[frame->getTrackType()];
|
||||||
if (frame_unread.size() > kMaxUnreadyFrame) {
|
if (frame_unread.size() > kMaxUnreadyFrame) {
|
||||||
//未就绪的的track,不能缓存太多的帧,否则可能内存溢出
|
//未就绪的的track,不能缓存太多的帧,否则可能内存溢出
|
||||||
frame_unread.clear();
|
frame_unread.clear();
|
||||||
@ -75,7 +81,7 @@ void MediaSink::resetTracks() {
|
|||||||
|
|
||||||
bool MediaSink::inputFrame(const Frame::Ptr &frame) {
|
bool MediaSink::inputFrame(const Frame::Ptr &frame) {
|
||||||
lock_guard<recursive_mutex> lck(_mtx);
|
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()) {
|
if (it == _track_map.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -90,7 +96,7 @@ bool MediaSink::inputFrame(const Frame::Ptr &frame) {
|
|||||||
|
|
||||||
void MediaSink::checkTrackIfReady_l(const Track::Ptr &track){
|
void MediaSink::checkTrackIfReady_l(const Track::Ptr &track){
|
||||||
//Track由未就绪状态转换成就绪状态,我们就触发onTrackReady回调
|
//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()) {
|
if (it_callback != _track_ready_callback.end() && track->ready()) {
|
||||||
it_callback->second();
|
it_callback->second();
|
||||||
_track_ready_callback.erase(it_callback);
|
_track_ready_callback.erase(it_callback);
|
||||||
|
@ -207,18 +207,12 @@ void PlayerProxy::onPlaySuccess() {
|
|||||||
videoTrack->addDelegate(_muxer);
|
videoTrack->addDelegate(_muxer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//是否添加静音音频
|
|
||||||
GET_CONFIG(bool, addMuteAudio, General::kAddMuteAudio);
|
|
||||||
|
|
||||||
auto audioTrack = getTrack(TrackAudio, false);
|
auto audioTrack = getTrack(TrackAudio, false);
|
||||||
if (audioTrack) {
|
if (audioTrack) {
|
||||||
//添加音频
|
//添加音频
|
||||||
_muxer->addTrack(audioTrack);
|
_muxer->addTrack(audioTrack);
|
||||||
//音频数据写入_mediaMuxer
|
//音频数据写入_mediaMuxer
|
||||||
audioTrack->addDelegate(_muxer);
|
audioTrack->addDelegate(_muxer);
|
||||||
} else if (addMuteAudio && videoTrack) {
|
|
||||||
//没有音频信息,产生一个静音音频
|
|
||||||
_muxer->addMuteAudioTrack();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加完毕所有track,防止单track情况下最大等待3秒
|
//添加完毕所有track,防止单track情况下最大等待3秒
|
||||||
|
Loading…
Reference in New Issue
Block a user