rtc推流添加媒体事件相关接口

This commit is contained in:
xia-chu 2021-04-07 18:18:27 +08:00
parent 155c59e17e
commit 0c5fa36e4d
3 changed files with 48 additions and 1 deletions

View File

@ -1137,6 +1137,7 @@ void installWebApi() {
auto push_src = std::make_shared<RtspMediaSourceImp>(info._vhost, info._app, info._streamid); auto push_src = std::make_shared<RtspMediaSourceImp>(info._vhost, info._app, info._streamid);
push_src->setProtocolTranslation(enableHls, enableMP4); push_src->setProtocolTranslation(enableHls, enableMP4);
auto rtc = WebRtcTransportImp::create(EventPollerPool::Instance().getPoller()); auto rtc = WebRtcTransportImp::create(EventPollerPool::Instance().getPoller());
push_src->setListener(rtc);
rtc->attach(push_src, false); rtc->attach(push_src, false);
val["sdp"] = rtc->getAnswerSdp(offer_sdp); val["sdp"] = rtc->getAnswerSdp(offer_sdp);
val["type"] = "answer"; val["type"] = "answer";

View File

@ -559,3 +559,35 @@ void WebRtcTransportImp::onShutdown(const SockException &ex){
_self = nullptr; _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);
}

View File

@ -110,7 +110,7 @@ private:
class RtpReceiverImp; 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: public:
using Ptr = std::shared_ptr<WebRtcTransportImp>; using Ptr = std::shared_ptr<WebRtcTransportImp>;
~WebRtcTransportImp() override; ~WebRtcTransportImp() override;
@ -139,6 +139,20 @@ protected:
void onRtcp(const char *buf, size_t len) override; void onRtcp(const char *buf, size_t len) override;
void onShutdown(const SockException &ex) 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: private:
WebRtcTransportImp(const EventPoller::Ptr &poller); WebRtcTransportImp(const EventPoller::Ptr &poller);
void onCreate() override; void onCreate() override;