mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-12 19:24:22 +08:00
新增webrtc播放器datachannel消息广播机制和接口
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user