mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-27 04:22:20 +08:00
Merge branch 'master' of https://github.com/ZLMediaKit/ZLMediaKit into feature/transcode2
# Conflicts: # conf/config.ini # src/Codec/Transcode.cpp # src/Common/MediaSource.h # src/Common/MultiMediaSourceMuxer.cpp # src/Common/MultiMediaSourceMuxer.h # src/Common/macros.h # webrtc/WebRtcPusher.cpp # webrtc/WebRtcTransport.cpp # webrtc/WebRtcTransport.h
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "RtcMediaSource.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -20,13 +21,18 @@ WebRtcPusher::Ptr WebRtcPusher::create(const EventPoller::Ptr &poller,
|
||||
const RtspMediaSource::Ptr &src,
|
||||
const std::shared_ptr<void> &ownership,
|
||||
const MediaInfo &info,
|
||||
const ProtocolOption &option) {
|
||||
WebRtcPusher::Ptr ret(new WebRtcPusher(poller, src, ownership, info, option), [](WebRtcPusher *ptr) {
|
||||
const ProtocolOption &option,
|
||||
WebRtcTransport::Role role,
|
||||
WebRtcTransport::SignalingProtocols signaling_protocols) {
|
||||
WebRtcPusher::Ptr pusher(new WebRtcPusher(poller, src, ownership, info, option), [](WebRtcPusher *ptr) {
|
||||
ptr->onDestory();
|
||||
delete ptr;
|
||||
});
|
||||
ret->onCreate();
|
||||
return ret;
|
||||
|
||||
pusher->setRole(role);
|
||||
pusher->setSignalingProtocols(signaling_protocols);
|
||||
pusher->onCreate();
|
||||
return pusher;
|
||||
}
|
||||
|
||||
WebRtcPusher::WebRtcPusher(const EventPoller::Ptr &poller,
|
||||
@@ -42,19 +48,10 @@ WebRtcPusher::WebRtcPusher(const EventPoller::Ptr &poller,
|
||||
}
|
||||
|
||||
bool WebRtcPusher::close(MediaSource &sender) {
|
||||
// 此回调在其他线程触发 [AUTO-TRANSLATED:c98e7686]
|
||||
// This callback is triggered in another thread
|
||||
string err = StrPrinter << "close media: " << sender.getUrl();
|
||||
weak_ptr<WebRtcPusher> weak_self = static_pointer_cast<WebRtcPusher>(shared_from_this());
|
||||
getPoller()->async([weak_self, err]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (strong_self) {
|
||||
strong_self->onShutdown(SockException(Err_shutdown, err));
|
||||
// 主动关闭推流,那么不延时注销 [AUTO-TRANSLATED:ee7cc580]
|
||||
// Actively close the stream, then do not delay the logout
|
||||
strong_self->_push_src = nullptr;
|
||||
}
|
||||
});
|
||||
onShutdown(SockException(Err_shutdown, "close media: " + sender.getUrl()));
|
||||
// 主动关闭推流,那么不延时注销 [AUTO-TRANSLATED:ee7cc580]
|
||||
// Actively close the stream, then do not delay the logout
|
||||
_push_src = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -117,7 +114,7 @@ void WebRtcPusher::onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Pt
|
||||
void WebRtcPusher::onStartWebRTC() {
|
||||
WebRtcTransportImp::onStartWebRTC();
|
||||
_simulcast = _answer_sdp->supportSimulcast();
|
||||
if (canRecvRtp()) {
|
||||
if (canRecvRtp() && _push_src) {
|
||||
_push_src->setSdp(_answer_sdp->toRtspSdp());
|
||||
}
|
||||
}
|
||||
@@ -175,4 +172,61 @@ void WebRtcPusher::onShutdown(const SockException &ex) {
|
||||
WebRtcTransportImp::onShutdown(ex);
|
||||
}
|
||||
|
||||
}// namespace mediakit
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WebRtcPlayerClient::Ptr WebRtcPlayerClient::create(const EventPoller::Ptr &poller, WebRtcTransport::Role role,
|
||||
WebRtcTransport::SignalingProtocols signaling_protocols) {
|
||||
WebRtcPlayerClient::Ptr pusher(new WebRtcPlayerClient(poller), [](WebRtcPlayerClient *ptr) {
|
||||
ptr->onDestory();
|
||||
delete ptr;
|
||||
});
|
||||
|
||||
pusher->setRole(role);
|
||||
pusher->setSignalingProtocols(signaling_protocols);
|
||||
pusher->onCreate();
|
||||
return pusher;
|
||||
}
|
||||
|
||||
WebRtcPlayerClient::WebRtcPlayerClient(const EventPoller::Ptr &poller)
|
||||
: WebRtcTransportImp(poller) {
|
||||
_demuxer = std::make_shared<RtspDemuxer>();
|
||||
}
|
||||
|
||||
void WebRtcPlayerClient::onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) {
|
||||
auto key_pos = _demuxer->inputRtp(rtp);
|
||||
if (_push_src) {
|
||||
_push_src->onWrite(rtp, key_pos);
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcPlayerClient::onStartWebRTC() {
|
||||
WebRtcTransportImp::onStartWebRTC();
|
||||
CHECK(!_answer_sdp->supportSimulcast());
|
||||
auto sdp = _answer_sdp->toRtspSdp();
|
||||
if (canRecvRtp()) {
|
||||
if (_push_src) {
|
||||
_push_src->setSdp(sdp);
|
||||
}
|
||||
_demuxer->loadSdp(sdp);
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcPlayerClient::onRtcConfigure(RtcConfigure &configure) const {
|
||||
WebRtcTransportImp::onRtcConfigure(configure);
|
||||
// 这只是推流 [AUTO-TRANSLATED:f877bf98]
|
||||
// This is just pushing the stream
|
||||
configure.audio.direction = configure.video.direction = RtpDirection::recvonly;
|
||||
}
|
||||
|
||||
vector<Track::Ptr> WebRtcPlayerClient::getTracks(bool ready) const {
|
||||
return _demuxer->getTracks(ready);
|
||||
}
|
||||
|
||||
void WebRtcPlayerClient::setMediaSource(RtspMediaSource::Ptr src) {
|
||||
_push_src = std::move(src);
|
||||
if (_push_src && canRecvRtp()) {
|
||||
_push_src->setSdp(_answer_sdp->toRtspSdp());
|
||||
}
|
||||
}
|
||||
|
||||
}// namespace mediakit
|
||||
|
||||
Reference in New Issue
Block a user