mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
rtc推流添加媒体事件相关接口
This commit is contained in:
parent
155c59e17e
commit
0c5fa36e4d
@ -1137,6 +1137,7 @@ void installWebApi() {
|
||||
auto push_src = std::make_shared<RtspMediaSourceImp>(info._vhost, info._app, info._streamid);
|
||||
push_src->setProtocolTranslation(enableHls, enableMP4);
|
||||
auto rtc = WebRtcTransportImp::create(EventPollerPool::Instance().getPoller());
|
||||
push_src->setListener(rtc);
|
||||
rtc->attach(push_src, false);
|
||||
val["sdp"] = rtc->getAnswerSdp(offer_sdp);
|
||||
val["type"] = "answer";
|
||||
|
@ -559,3 +559,35 @@ void WebRtcTransportImp::onShutdown(const SockException &ex){
|
||||
_self = nullptr;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool WebRtcTransportImp::close(MediaSource &sender, bool force) {
|
||||
//此回调在其他线程触发
|
||||
if(!_push_src || (!force && _push_src->totalReaderCount())){
|
||||
return false;
|
||||
}
|
||||
string err = StrPrinter << "close media:" << sender.getSchema() << "/" << sender.getVhost() << "/" << sender.getApp() << "/" << sender.getId() << " " << force;
|
||||
onShutdown(SockException(Err_shutdown,err));
|
||||
return true;
|
||||
}
|
||||
|
||||
int WebRtcTransportImp::totalReaderCount(MediaSource &sender) {
|
||||
return _push_src ? _push_src->totalReaderCount() : sender.readerCount();
|
||||
}
|
||||
|
||||
MediaOriginType WebRtcTransportImp::getOriginType(MediaSource &sender) const {
|
||||
return MediaOriginType::rtc_push;
|
||||
}
|
||||
|
||||
string WebRtcTransportImp::getOriginUrl(MediaSource &sender) const {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::shared_ptr<SockInfo> WebRtcTransportImp::getOriginSock(MediaSource &sender) const {
|
||||
return const_cast<WebRtcTransportImp *>(this)->_socket;
|
||||
}
|
||||
|
||||
void WebRtcTransportImp::OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) {
|
||||
WebRtcTransport::OnIceServerSelectedTuple(iceServer, tuple);
|
||||
_socket->setSendPeerAddr(tuple);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ private:
|
||||
|
||||
class RtpReceiverImp;
|
||||
|
||||
class WebRtcTransportImp : public WebRtcTransport, public std::enable_shared_from_this<WebRtcTransportImp>{
|
||||
class WebRtcTransportImp : public WebRtcTransport, public MediaSourceEvent, public std::enable_shared_from_this<WebRtcTransportImp>{
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcTransportImp>;
|
||||
~WebRtcTransportImp() override;
|
||||
@ -139,6 +139,20 @@ protected:
|
||||
void onRtcp(const char *buf, size_t len) override;
|
||||
void onShutdown(const SockException &ex) override;
|
||||
|
||||
void OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) override;
|
||||
|
||||
///////MediaSourceEvent override///////
|
||||
// 关闭
|
||||
bool close(MediaSource &sender, bool force) override;
|
||||
// 播放总人数
|
||||
int totalReaderCount(MediaSource &sender) override;
|
||||
// 获取媒体源类型
|
||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||
// 获取媒体源url或者文件路径
|
||||
string getOriginUrl(MediaSource &sender) const override;
|
||||
// 获取媒体源客户端相关信息
|
||||
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
|
||||
private:
|
||||
WebRtcTransportImp(const EventPoller::Ptr &poller);
|
||||
void onCreate() override;
|
||||
|
Loading…
Reference in New Issue
Block a user