mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
新增webrtc echo test双向会话示例
This commit is contained in:
parent
f0e896a5e2
commit
34365a2f8f
@ -40,6 +40,7 @@
|
|||||||
#ifdef ENABLE_WEBRTC
|
#ifdef ENABLE_WEBRTC
|
||||||
#include "../webrtc/WebRtcPlayer.h"
|
#include "../webrtc/WebRtcPlayer.h"
|
||||||
#include "../webrtc/WebRtcPusher.h"
|
#include "../webrtc/WebRtcPusher.h"
|
||||||
|
#include "../webrtc/WebRtcEchoTest.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
@ -1271,6 +1272,14 @@ void installWebApi() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcasecmp(type.data(), "echo")) {
|
||||||
|
auto rtc = WebRtcEchoTest::create(EventPollerPool::Instance().getPoller());
|
||||||
|
val["sdp"] = rtc->getAnswerSdp(offer_sdp);
|
||||||
|
val["type"] = "answer";
|
||||||
|
invoker(200, headerOut, val.toStyledString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
throw ApiRetException("不支持该类型", API::InvalidArgs);
|
throw ApiRetException("不支持该类型", API::InvalidArgs);
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
38
webrtc/WebRtcEchoTest.cpp
Normal file
38
webrtc/WebRtcEchoTest.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by MIT license that can be found in the
|
||||||
|
* LICENSE file in the root of the source tree. All contributing project authors
|
||||||
|
* may be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "WebRtcEchoTest.h"
|
||||||
|
|
||||||
|
|
||||||
|
WebRtcEchoTest::Ptr WebRtcEchoTest::create(const EventPoller::Ptr &poller) {
|
||||||
|
WebRtcEchoTest::Ptr ret(new WebRtcEchoTest(poller), [](WebRtcEchoTest *ptr) {
|
||||||
|
ptr->onDestory();
|
||||||
|
delete ptr;
|
||||||
|
});
|
||||||
|
ret->onCreate();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebRtcEchoTest::WebRtcEchoTest(const EventPoller::Ptr &poller) : WebRtcTransportImp(poller) {}
|
||||||
|
|
||||||
|
void WebRtcEchoTest::onRtcConfigure(RtcConfigure &configure) const {
|
||||||
|
WebRtcTransportImp::onRtcConfigure(configure);
|
||||||
|
configure.audio.direction = configure.video.direction = RtpDirection::sendrecv;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebRtcEchoTest::onRtp(const char *buf, size_t len, uint64_t stamp_ms) {
|
||||||
|
updateTicker();
|
||||||
|
sendRtpPacket(buf, len, true, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebRtcEchoTest::onRtcp(const char *buf, size_t len) {
|
||||||
|
sendRtcpPacket(buf, len, true, nullptr);
|
||||||
|
}
|
||||||
|
|
38
webrtc/WebRtcEchoTest.h
Normal file
38
webrtc/WebRtcEchoTest.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by MIT license that can be found in the
|
||||||
|
* LICENSE file in the root of the source tree. All contributing project authors
|
||||||
|
* may be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZLMEDIAKIT_WEBRTCECHOTEST_H
|
||||||
|
#define ZLMEDIAKIT_WEBRTCECHOTEST_H
|
||||||
|
|
||||||
|
#include "WebRtcTransport.h"
|
||||||
|
|
||||||
|
class WebRtcEchoTest : public WebRtcTransportImp {
|
||||||
|
public:
|
||||||
|
using Ptr = std::shared_ptr<WebRtcEchoTest>;
|
||||||
|
~WebRtcEchoTest() override = default;
|
||||||
|
static Ptr create(const EventPoller::Ptr &poller);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
///////WebRtcTransportImp override///////
|
||||||
|
void onRtcConfigure(RtcConfigure &configure) const override;
|
||||||
|
void onRtp(const char *buf, size_t len, uint64_t stamp_ms) override;
|
||||||
|
void onRtcp(const char *buf, size_t len) override;
|
||||||
|
|
||||||
|
void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) override {};
|
||||||
|
void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) override {};
|
||||||
|
void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) override {};
|
||||||
|
|
||||||
|
private:
|
||||||
|
WebRtcEchoTest(const EventPoller::Ptr &poller);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //ZLMEDIAKIT_WEBRTCECHOTEST_H
|
@ -24,7 +24,7 @@ protected:
|
|||||||
void onStartWebRTC() override;
|
void onStartWebRTC() override;
|
||||||
void onDestory() override;
|
void onDestory() override;
|
||||||
void onRtcConfigure(RtcConfigure &configure) const override;
|
void onRtcConfigure(RtcConfigure &configure) const override;
|
||||||
void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) {};
|
void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) override {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info);
|
WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info);
|
||||||
|
@ -435,6 +435,10 @@ void WebRtcTransportImp::onCheckAnswer(RtcSession &sdp) {
|
|||||||
if (m.type == TrackApplication) {
|
if (m.type == TrackApplication) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!m.rtp_rtx_ssrc.empty()) {
|
||||||
|
//已经生成了ssrc
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//添加answer sdp的ssrc信息
|
//添加answer sdp的ssrc信息
|
||||||
m.rtp_rtx_ssrc.emplace_back();
|
m.rtp_rtx_ssrc.emplace_back();
|
||||||
auto &ssrc = m.rtp_rtx_ssrc.back();
|
auto &ssrc = m.rtp_rtx_ssrc.back();
|
||||||
@ -668,6 +672,10 @@ void WebRtcTransportImp::createRtpChannel(const string &rid, uint32_t ssrc, Medi
|
|||||||
InfoL << "create rtp receiver of ssrc:" << ssrc << ", rid:" << rid << ", codec:" << track.plan_rtp->codec;
|
InfoL << "create rtp receiver of ssrc:" << ssrc << ", rid:" << rid << ", codec:" << track.plan_rtp->codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebRtcTransportImp::updateTicker() {
|
||||||
|
_alive_ticker.resetTime();
|
||||||
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::onRtp(const char *buf, size_t len, uint64_t stamp_ms) {
|
void WebRtcTransportImp::onRtp(const char *buf, size_t len, uint64_t stamp_ms) {
|
||||||
_bytes_usage += len;
|
_bytes_usage += len;
|
||||||
_alive_ticker.resetTime();
|
_alive_ticker.resetTime();
|
||||||
|
@ -189,6 +189,7 @@ protected:
|
|||||||
void onDestory() override;
|
void onDestory() override;
|
||||||
void onShutdown(const SockException &ex) override;
|
void onShutdown(const SockException &ex) override;
|
||||||
virtual void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) = 0;
|
virtual void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) = 0;
|
||||||
|
void updateTicker();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SdpAttrCandidate::Ptr getIceCandidate() const;
|
SdpAttrCandidate::Ptr getIceCandidate() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user