mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 04:08:57 +08:00
优化获取播放器列表相关功能
This commit is contained in:
parent
d286ac1d73
commit
39dd886ec1
@ -1 +1 @@
|
||||
Subproject commit d7dd07ddd968ad8f927da2c655e13956be116cef
|
||||
Subproject commit 97f9b9a2ac58353f72f085830690d27833b8ad88
|
@ -795,22 +795,24 @@ void installWebApi() {
|
||||
throw ApiRetException("can not find the stream", API::NotFound);
|
||||
}
|
||||
src->getPlayerList(
|
||||
[=](const std::list<std::shared_ptr<void>> &info_list) mutable {
|
||||
[=](const std::list<toolkit::Any> &info_list) mutable {
|
||||
val["code"] = API::Success;
|
||||
auto &data = val["data"];
|
||||
data = Value(arrayValue);
|
||||
for (auto &info : info_list) {
|
||||
auto obj = static_pointer_cast<Value>(info);
|
||||
data.append(std::move(*obj));
|
||||
auto &obj = info.get<Value>();
|
||||
data.append(std::move(obj));
|
||||
}
|
||||
invoker(200, headerOut, val.toStyledString());
|
||||
},
|
||||
[](std::shared_ptr<void> &&info) -> std::shared_ptr<void> {
|
||||
[](toolkit::Any &&info) -> toolkit::Any {
|
||||
auto obj = std::make_shared<Value>();
|
||||
auto session = static_pointer_cast<Session>(info);
|
||||
fillSockInfo(*obj, session.get());
|
||||
(*obj)["typeid"] = toolkit::demangle(typeid(*session).name());
|
||||
return obj;
|
||||
auto &sock = info.get<SockInfo>();
|
||||
fillSockInfo(*obj, &sock);
|
||||
(*obj)["typeid"] = toolkit::demangle(typeid(sock).name());
|
||||
toolkit::Any ret;
|
||||
ret.set(obj);
|
||||
return ret;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -347,10 +347,10 @@ public:
|
||||
// 观看者个数,包括(hls/rtsp/rtmp)
|
||||
virtual int totalReaderCount();
|
||||
// 获取播放器列表
|
||||
virtual void getPlayerList(const std::function<void(const std::list<std::shared_ptr<void>> &info_list)> &cb,
|
||||
const std::function<std::shared_ptr<void>(std::shared_ptr<void> &&info)> &on_change) {
|
||||
virtual void getPlayerList(const std::function<void(const std::list<toolkit::Any> &info_list)> &cb,
|
||||
const std::function<toolkit::Any(toolkit::Any &&info)> &on_change) {
|
||||
assert(cb);
|
||||
cb(std::list<std::shared_ptr<void>>());
|
||||
cb(std::list<toolkit::Any>());
|
||||
}
|
||||
|
||||
// 获取媒体源类型
|
||||
|
@ -51,8 +51,8 @@ public:
|
||||
return _ring;
|
||||
}
|
||||
|
||||
void getPlayerList(const std::function<void(const std::list<std::shared_ptr<void>> &info_list)> &cb,
|
||||
const std::function<std::shared_ptr<void>(std::shared_ptr<void> &&info)> &on_change) override {
|
||||
void getPlayerList(const std::function<void(const std::list<toolkit::Any> &info_list)> &cb,
|
||||
const std::function<toolkit::Any(toolkit::Any &&info)> &on_change) override {
|
||||
_ring->getInfoList(cb, on_change);
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,11 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb) {
|
||||
weak_ptr<HttpSession> weak_self = static_pointer_cast<HttpSession>(shared_from_this());
|
||||
fmp4_src->pause(false);
|
||||
_fmp4_reader = fmp4_src->getRing()->attach(getPoller());
|
||||
_fmp4_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
|
||||
_fmp4_reader->setGetInfoCB([weak_self]() {
|
||||
Any ret;
|
||||
ret.set(static_pointer_cast<SockInfo>(weak_self.lock()));
|
||||
return ret;
|
||||
});
|
||||
_fmp4_reader->setDetachCB([weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
@ -378,7 +382,11 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb) {
|
||||
weak_ptr<HttpSession> weak_self = static_pointer_cast<HttpSession>(shared_from_this());
|
||||
ts_src->pause(false);
|
||||
_ts_reader = ts_src->getRing()->attach(getPoller());
|
||||
_ts_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
|
||||
_ts_reader->setGetInfoCB([weak_self]() {
|
||||
Any ret;
|
||||
ret.set(static_pointer_cast<SockInfo>(weak_self.lock()));
|
||||
return ret;
|
||||
});
|
||||
_ts_reader->setDetachCB([weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
@ -33,6 +33,12 @@ void HlsCookieData::addReaderCount() {
|
||||
// HlsMediaSource已经销毁
|
||||
*added = false;
|
||||
});
|
||||
auto info = _sock_info;
|
||||
_ring_reader->setGetInfoCB([info]() {
|
||||
Any ret;
|
||||
ret.set(info);
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,11 @@ public:
|
||||
|
||||
void onSegmentSize(size_t bytes) { _speed[TrackVideo] += bytes; }
|
||||
|
||||
void getPlayerList(const std::function<void(const std::list<toolkit::Any> &info_list)> &cb,
|
||||
const std::function<toolkit::Any(toolkit::Any &&info)> &on_change) override {
|
||||
_ring->getInfoList(cb, on_change);
|
||||
}
|
||||
|
||||
private:
|
||||
RingType::Ptr _ring;
|
||||
std::string _index_file;
|
||||
|
@ -46,7 +46,11 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
|
||||
std::weak_ptr<FlvMuxer> weak_self = getSharedPtr();
|
||||
media->pause(false);
|
||||
_ring_reader = media->getRing()->attach(poller);
|
||||
_ring_reader->setGetInfoCB([weak_self]() { return dynamic_pointer_cast<HttpSession>(weak_self.lock()); });
|
||||
_ring_reader->setGetInfoCB([weak_self]() {
|
||||
Any ret;
|
||||
ret.set(dynamic_pointer_cast<SockInfo>(weak_self.lock()));
|
||||
return ret;
|
||||
});
|
||||
_ring_reader->setDetachCB([weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
@ -57,8 +57,8 @@ public:
|
||||
return _ring;
|
||||
}
|
||||
|
||||
void getPlayerList(const std::function<void(const std::list<std::shared_ptr<void>> &info_list)> &cb,
|
||||
const std::function<std::shared_ptr<void>(std::shared_ptr<void> &&info)> &on_change) override {
|
||||
void getPlayerList(const std::function<void(const std::list<toolkit::Any> &info_list)> &cb,
|
||||
const std::function<toolkit::Any(toolkit::Any &&info)> &on_change) override {
|
||||
_ring->getInfoList(cb, on_change);
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,11 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
|
||||
src->pause(false);
|
||||
_ring_reader = src->getRing()->attach(getPoller());
|
||||
weak_ptr<RtmpSession> weak_self = static_pointer_cast<RtmpSession>(shared_from_this());
|
||||
_ring_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
|
||||
_ring_reader->setGetInfoCB([weak_self]() {
|
||||
Any ret;
|
||||
ret.set(static_pointer_cast<SockInfo>(weak_self.lock()));
|
||||
return ret;
|
||||
});
|
||||
_ring_reader->setReadCB([weak_self](const RtmpMediaSource::RingDataType &pkt) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
@ -53,8 +53,8 @@ public:
|
||||
return _ring;
|
||||
}
|
||||
|
||||
void getPlayerList(const std::function<void(const std::list<std::shared_ptr<void>> &info_list)> &cb,
|
||||
const std::function<std::shared_ptr<void>(std::shared_ptr<void> &&info)> &on_change) override {
|
||||
void getPlayerList(const std::function<void(const std::list<toolkit::Any> &info_list)> &cb,
|
||||
const std::function<toolkit::Any(toolkit::Any &&info)> &on_change) override {
|
||||
_ring->getInfoList(cb, on_change);
|
||||
}
|
||||
|
||||
|
@ -857,7 +857,11 @@ void RtspSession::handleReq_Play(const Parser &parser) {
|
||||
if (!_play_reader && _rtp_type != Rtsp::RTP_MULTICAST) {
|
||||
weak_ptr<RtspSession> weak_self = static_pointer_cast<RtspSession>(shared_from_this());
|
||||
_play_reader = play_src->getRing()->attach(getPoller(), use_gop);
|
||||
_play_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
|
||||
_play_reader->setGetInfoCB([weak_self]() {
|
||||
Any ret;
|
||||
ret.set(static_pointer_cast<SockInfo>(weak_self.lock()));
|
||||
return ret;
|
||||
});
|
||||
_play_reader->setDetachCB([weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
@ -50,8 +50,8 @@ public:
|
||||
return _ring;
|
||||
}
|
||||
|
||||
void getPlayerList(const std::function<void(const std::list<std::shared_ptr<void>> &info_list)> &cb,
|
||||
const std::function<std::shared_ptr<void>(std::shared_ptr<void> &&info)> &on_change) override {
|
||||
void getPlayerList(const std::function<void(const std::list<toolkit::Any> &info_list)> &cb,
|
||||
const std::function<toolkit::Any(toolkit::Any &&info)> &on_change) override {
|
||||
_ring->getInfoList(cb, on_change);
|
||||
}
|
||||
|
||||
|
@ -224,7 +224,11 @@ void SrtTransportImp::doPlay() {
|
||||
ts_src->pause(false);
|
||||
strong_self->_ts_reader = ts_src->getRing()->attach(strong_self->getPoller());
|
||||
weak_ptr<Session> weak_session = strong_self->getSession();
|
||||
strong_self->_ts_reader->setGetInfoCB([weak_session]() { return weak_session.lock(); });
|
||||
strong_self->_ts_reader->setGetInfoCB([weak_session]() {
|
||||
Any ret;
|
||||
ret.set(static_pointer_cast<SockInfo>(weak_session.lock()));
|
||||
return ret;
|
||||
});
|
||||
strong_self->_ts_reader->setDetachCB([weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
@ -48,7 +48,11 @@ void WebRtcPlayer::onStartWebRTC() {
|
||||
_reader = playSrc->getRing()->attach(getPoller(), true);
|
||||
weak_ptr<WebRtcPlayer> weak_self = static_pointer_cast<WebRtcPlayer>(shared_from_this());
|
||||
weak_ptr<Session> weak_session = static_pointer_cast<Session>(getSession());
|
||||
_reader->setGetInfoCB([weak_session]() { return weak_session.lock(); });
|
||||
_reader->setGetInfoCB([weak_session]() {
|
||||
Any ret;
|
||||
ret.set(static_pointer_cast<SockInfo>(weak_session.lock()));
|
||||
return ret;
|
||||
});
|
||||
_reader->setReadCB([weak_self](const RtspMediaSource::RingDataType &pkt) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
Loading…
Reference in New Issue
Block a user