mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-28 21:14:03 +08:00
新增流健康度探针功能
This commit is contained in:
@@ -818,7 +818,36 @@ void MultiMediaSourceMuxer::resetTracks() {
|
||||
}
|
||||
}
|
||||
|
||||
void MultiMediaSourceMuxer::addProbe(uint32_t probe_ms, const std::function<void(const std::list<FrameInfo> &info_list)> &cb) {
|
||||
CHECK(getOwnerPoller(MediaSource::NullMediaSource())->isCurrentThread());
|
||||
auto info_list = std::make_shared<std::list<FrameInfo>>();
|
||||
Ticker ticker;
|
||||
_on_frame = [info_list, ticker](const Frame::Ptr &frame) mutable {
|
||||
FrameInfo info;
|
||||
info.codec_id = frame->getCodecId();
|
||||
info.dts = frame->dts();
|
||||
info.pts = frame->pts();
|
||||
info.recv_stamp = ticker.createdTime();
|
||||
info.frame_size = frame->size();
|
||||
info.index = frame->getIndex();
|
||||
info.key_frame = frame->keyFrame();
|
||||
info.config_frame = frame->configFrame();
|
||||
info_list->emplace_back(info);
|
||||
};
|
||||
std::weak_ptr<MultiMediaSourceMuxer> weak_self = shared_from_this();
|
||||
getOwnerPoller(MediaSource::NullMediaSource())->doDelayTask(probe_ms, [weak_self, cb, info_list]() {
|
||||
if (auto strong_self = weak_self.lock()) {
|
||||
strong_self->_on_frame = nullptr;
|
||||
}
|
||||
cb(*info_list);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
bool MultiMediaSourceMuxer::onTrackFrame(const Frame::Ptr &frame_in) {
|
||||
if (_on_frame) {
|
||||
_on_frame(frame_in);
|
||||
}
|
||||
auto frame = frame_in;
|
||||
if (_option.modify_stamp != ProtocolOption::kModifyStampOff) {
|
||||
// 时间戳不采用原始的绝对时间戳 [AUTO-TRANSLATED:8beb3bf7]
|
||||
|
||||
@@ -25,6 +25,18 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
struct FrameInfo {
|
||||
CodecId codec_id = CodecInvalid;
|
||||
int64_t dts = 0;
|
||||
int64_t pts = 0;
|
||||
int64_t recv_stamp = 0;
|
||||
size_t frame_size = 0;
|
||||
|
||||
int index = 0;
|
||||
bool key_frame = false;
|
||||
bool config_frame = false;
|
||||
};
|
||||
|
||||
class MultiMediaSourceMuxer : public MediaSourceEventInterceptor, public MediaSink, public toolkit::noncopyable, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
||||
public:
|
||||
using Ptr = std::shared_ptr<MultiMediaSourceMuxer>;
|
||||
@@ -188,6 +200,9 @@ public:
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
void forEachRtpSender(const std::function<void(const std::string &ssrc, const RtpSender &sender)> &cb) const;
|
||||
#endif // ENABLE_RTPPROXY
|
||||
|
||||
void addProbe(uint32_t probe_ms, const std::function<void(const std::list<FrameInfo> &info_list)> &cb);
|
||||
|
||||
protected:
|
||||
/////////////////////////////////MediaSink override/////////////////////////////////
|
||||
|
||||
@@ -231,6 +246,7 @@ private:
|
||||
bool _create_in_poller = false;
|
||||
bool _video_key_pos = false;
|
||||
float _dur_sec;
|
||||
std::function<void(const Frame::Ptr &frame)> _on_frame;
|
||||
std::shared_ptr<class FramePacedSender> _paced_sender;
|
||||
MediaTuple _tuple;
|
||||
ProtocolOption _option;
|
||||
|
||||
Reference in New Issue
Block a user