mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 02:34:26 +08:00
新增webrtc播放器datachannel消息广播机制和接口
This commit is contained in:
parent
39dd886ec1
commit
e3e7495c90
@ -1 +1 @@
|
||||
Subproject commit 97f9b9a2ac58353f72f085830690d27833b8ad88
|
||||
Subproject commit 5d74e09b8c84cccc46036ed2ef1a62f670c423d4
|
@ -816,6 +816,19 @@ void installWebApi() {
|
||||
});
|
||||
});
|
||||
|
||||
api_regist("/index/api/broadcastMessage", [](API_ARGS_MAP) {
|
||||
CHECK_SECRET();
|
||||
CHECK_ARGS("schema", "vhost", "app", "stream", "msg");
|
||||
auto src = MediaSource::find(allArgs["schema"], allArgs["vhost"], allArgs["app"], allArgs["stream"]);
|
||||
if (!src) {
|
||||
throw ApiRetException("can not find the stream", API::NotFound);
|
||||
}
|
||||
Any any;
|
||||
Buffer::Ptr buffer = std::make_shared<BufferLikeString>(allArgs["msg"]);
|
||||
any.set(std::move(buffer));
|
||||
src->broadcastMessage(any);
|
||||
});
|
||||
|
||||
//测试url http://127.0.0.1/index/api/getMediaInfo?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs
|
||||
api_regist("/index/api/getMediaInfo",[](API_ARGS_MAP_ASYNC){
|
||||
CHECK_SECRET();
|
||||
|
@ -353,6 +353,8 @@ public:
|
||||
cb(std::list<toolkit::Any>());
|
||||
}
|
||||
|
||||
virtual bool broadcastMessage(const toolkit::Any &data) { return false; }
|
||||
|
||||
// 获取媒体源类型
|
||||
MediaOriginType getOriginType() const;
|
||||
// 获取媒体源url或者文件路径
|
||||
|
@ -55,9 +55,16 @@ public:
|
||||
|
||||
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 {
|
||||
assert(_ring);
|
||||
_ring->getInfoList(cb, on_change);
|
||||
}
|
||||
|
||||
bool broadcastMessage(const toolkit::Any &data) override {
|
||||
assert(_ring);
|
||||
_ring->sendMessage(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取播放器个数
|
||||
*/
|
||||
|
@ -71,6 +71,21 @@ void WebRtcPlayer::onStartWebRTC() {
|
||||
}
|
||||
strong_self->onShutdown(SockException(Err_shutdown, "rtsp ring buffer detached"));
|
||||
});
|
||||
|
||||
_reader->setMessageCB([weak_self] (const toolkit::Any &data) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return;
|
||||
}
|
||||
if (data.is<Buffer>()) {
|
||||
auto &buffer = data.get<Buffer>();
|
||||
// PPID 51: 文本string
|
||||
// PPID 53: 二进制
|
||||
strong_self->sendDatachannel(0, 51, buffer.data(), buffer.size());
|
||||
} else {
|
||||
WarnL << "Send unknown message type to webrtc player: " << data.type_name();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
void WebRtcPlayer::onDestory() {
|
||||
|
@ -229,6 +229,19 @@ void WebRtcTransport::OnSctpAssociationMessageReceived(
|
||||
_sctp->SendSctpMessage(params, ppid, msg, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
void WebRtcTransport::sendDatachannel(uint16_t streamId, uint32_t ppid, const char *msg, size_t len) {
|
||||
#ifdef ENABLE_SCTP
|
||||
if (_sctp) {
|
||||
RTC::SctpStreamParameters params;
|
||||
params.streamId = streamId;
|
||||
_sctp->SendSctpMessage(params, ppid, (uint8_t *)msg, len);
|
||||
}
|
||||
#else
|
||||
WarnL << "WebRTC datachannel disabled!";
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void WebRtcTransport::sendSockData(const char *buf, size_t len, RTC::TransportTuple *tuple) {
|
||||
|
@ -112,6 +112,7 @@ public:
|
||||
*/
|
||||
void sendRtpPacket(const char *buf, int len, bool flush, void *ctx = nullptr);
|
||||
void sendRtcpPacket(const char *buf, int len, bool flush, void *ctx = nullptr);
|
||||
void sendDatachannel(uint16_t streamId, uint32_t ppid, const char *msg, size_t len);
|
||||
|
||||
const EventPoller::Ptr& getPoller() const;
|
||||
Session::Ptr getSession() const;
|
||||
|
Loading…
Reference in New Issue
Block a user