防止多个track重复驱动静音生成

This commit is contained in:
xia-chu 2023-12-09 20:58:45 +08:00
parent 336b3b1fe0
commit f100ea583e
2 changed files with 16 additions and 10 deletions

View File

@ -230,16 +230,21 @@ static uint8_t s_mute_adts[] = {0xff, 0xf1, 0x6c, 0x40, 0x2d, 0x3f, 0xfc, 0x00,
static uint8_t ADTS_CONFIG[2] = { 0x15, 0x88 }; static uint8_t ADTS_CONFIG[2] = { 0x15, 0x88 };
bool MuteAudioMaker::inputFrame(const Frame::Ptr &frame) { bool MuteAudioMaker::inputFrame(const Frame::Ptr &frame) {
if (frame->getTrackType() == TrackVideo) { if (_track_index == -1) {
// 锁定track
_track_index = frame->getIndex();
}
if (frame->getIndex() != _track_index) {
// 不是锁定的track
return false;
}
auto audio_idx = frame->dts() / MUTE_ADTS_DATA_MS; auto audio_idx = frame->dts() / MUTE_ADTS_DATA_MS;
if (_audio_idx != audio_idx) { if (_audio_idx != audio_idx) {
_audio_idx = audio_idx; _audio_idx = audio_idx;
auto aacFrame = std::make_shared<FrameToCache<FrameFromPtr>>(CodecAAC, (char *) MUTE_ADTS_DATA, sizeof(s_mute_adts), auto aacFrame = std::make_shared<FrameToCache<FrameFromPtr>>(CodecAAC, (char *)MUTE_ADTS_DATA, sizeof(s_mute_adts), _audio_idx * MUTE_ADTS_DATA_MS, 0, 7);
_audio_idx * MUTE_ADTS_DATA_MS, 0, 7);
aacFrame->setIndex(MUTE_AUDIO_INDEX); aacFrame->setIndex(MUTE_AUDIO_INDEX);
return FrameDispatcher::inputFrame(aacFrame); return FrameDispatcher::inputFrame(aacFrame);
} }
}
return false; return false;
} }

View File

@ -55,6 +55,7 @@ public:
bool inputFrame(const Frame::Ptr &frame) override; bool inputFrame(const Frame::Ptr &frame) override;
private: private:
int _track_index = -1;
uint64_t _audio_idx = 0; uint64_t _audio_idx = 0;
}; };