diff --git a/src/MediaFile/Mp4Maker.cpp b/src/MediaFile/MP4Recorder.cpp similarity index 93% rename from src/MediaFile/Mp4Maker.cpp rename to src/MediaFile/MP4Recorder.cpp index 3cf2a7ec..658243c9 100644 --- a/src/MediaFile/Mp4Maker.cpp +++ b/src/MediaFile/MP4Recorder.cpp @@ -28,7 +28,7 @@ #include #include #include "Common/config.h" -#include "Mp4Maker.h" +#include "MP4Recorder.h" #include "Util/util.h" #include "Util/NoticeCenter.h" #include "Thread/WorkThreadPool.h" @@ -53,7 +53,7 @@ string timeStr(const char *fmt) { return buffer; } -Mp4Maker::Mp4Maker(const string& strPath, +MP4Recorder::MP4Recorder(const string& strPath, const string &strVhost, const string &strApp, const string &strStreamId) { @@ -64,11 +64,11 @@ Mp4Maker::Mp4Maker(const string& strPath, _info.strVhost = strVhost; _info.strFolder = strPath; } -Mp4Maker::~Mp4Maker() { +MP4Recorder::~MP4Recorder() { closeFile(); } -void Mp4Maker::createFile() { +void MP4Recorder::createFile() { closeFile(); auto strDate = timeStr("%Y-%m-%d"); auto strTime = timeStr("%H-%M-%S"); @@ -100,7 +100,7 @@ void Mp4Maker::createFile() { } } -void Mp4Maker::asyncClose() { +void MP4Recorder::asyncClose() { auto muxer = _muxer; auto strFileTmp = _strFileTmp; auto strFile = _strFile; @@ -121,14 +121,14 @@ void Mp4Maker::asyncClose() { }); } -void Mp4Maker::closeFile() { +void MP4Recorder::closeFile() { if (_muxer) { asyncClose(); _muxer = nullptr; } } -void Mp4Maker::onTrackFrame(const Frame::Ptr &frame) { +void MP4Recorder::onTrackFrame(const Frame::Ptr &frame) { GET_CONFIG(uint32_t,recordSec,Record::kFileSecond); if(!_muxer || ((_createFileTicker.elapsedTime() > recordSec * 1000) && (!_haveVideo || (_haveVideo && frame->keyFrame()))) ){ @@ -145,7 +145,7 @@ void Mp4Maker::onTrackFrame(const Frame::Ptr &frame) { } } -void Mp4Maker::onTrackReady(const Track::Ptr & track){ +void MP4Recorder::onTrackReady(const Track::Ptr & track){ //保存所有的track,为创建MP4MuxerFile做准备 _tracks.emplace_back(track); if(track->getTrackType() == TrackVideo){ diff --git a/src/MediaFile/Mp4Maker.h b/src/MediaFile/MP4Recorder.h similarity index 95% rename from src/MediaFile/Mp4Maker.h rename to src/MediaFile/MP4Recorder.h index cef69701..ca97cb3f 100644 --- a/src/MediaFile/Mp4Maker.h +++ b/src/MediaFile/MP4Recorder.h @@ -55,14 +55,14 @@ public: string strStreamId;//流ID string strVhost;//vhost }; -class Mp4Maker : public MediaSink{ +class MP4Recorder : public MediaSink{ public: - typedef std::shared_ptr Ptr; - Mp4Maker(const string &strPath, + typedef std::shared_ptr Ptr; + MP4Recorder(const string &strPath, const string &strVhost , const string &strApp, const string &strStreamId); - virtual ~Mp4Maker(); + virtual ~MP4Recorder(); private: /** * 某Track输出frame,在onAllTrackReady触发后才会调用此方法 diff --git a/src/MediaFile/MediaRecorder.cpp b/src/MediaFile/MediaRecorder.cpp index 71eac5e4..ee205623 100644 --- a/src/MediaFile/MediaRecorder.cpp +++ b/src/MediaFile/MediaRecorder.cpp @@ -58,10 +58,10 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, string m3u8FilePath; if(enableVhost){ m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8"; - _hlsMaker.reset(new HlsRecorder(m3u8FilePath,string(VHOST_KEY) + "=" + strVhost ,hlsBufSize, hlsDuration, hlsNum)); + _hlsRecorder.reset(new HlsRecorder(m3u8FilePath,string(VHOST_KEY) + "=" + strVhost ,hlsBufSize, hlsDuration, hlsNum)); }else{ m3u8FilePath = hlsPath + "/" + strApp + "/" + strId + "/hls.m3u8"; - _hlsMaker.reset(new HlsRecorder(m3u8FilePath,"",hlsBufSize, hlsDuration, hlsNum)); + _hlsRecorder.reset(new HlsRecorder(m3u8FilePath,"",hlsBufSize, hlsDuration, hlsNum)); } } #endif //defined(ENABLE_HLS) @@ -77,7 +77,7 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, } else { mp4FilePath = recordPath + "/" + recordAppName + "/" + strApp + "/" + strId + "/"; } - _mp4Maker.reset(new Mp4Maker(mp4FilePath,strVhost,strApp,strId)); + _mp4Recorder.reset(new MP4Recorder(mp4FilePath,strVhost,strApp,strId)); } #endif //defined(ENABLE_MP4V2) } @@ -87,28 +87,28 @@ MediaRecorder::~MediaRecorder() { void MediaRecorder::inputFrame(const Frame::Ptr &frame) { #if defined(ENABLE_HLS) - if (_hlsMaker) { - _hlsMaker->inputFrame(frame); + if (_hlsRecorder) { + _hlsRecorder->inputFrame(frame); } #endif //defined(ENABLE_HLS) #if defined(ENABLE_MP4V2) - if (_mp4Maker) { - _mp4Maker->inputFrame(frame); + if (_mp4Recorder) { + _mp4Recorder->inputFrame(frame); } #endif //defined(ENABLE_MP4V2) } void MediaRecorder::addTrack(const Track::Ptr &track) { #if defined(ENABLE_HLS) - if (_hlsMaker) { - _hlsMaker->addTrack(track); + if (_hlsRecorder) { + _hlsRecorder->addTrack(track); } #endif //defined(ENABLE_HLS) #if defined(ENABLE_MP4RECORD) - if (_mp4Maker) { - _mp4Maker->addTrack(track); + if (_mp4Recorder) { + _mp4Recorder->addTrack(track); } #endif //defined(ENABLE_MP4RECORD) } diff --git a/src/MediaFile/MediaRecorder.h b/src/MediaFile/MediaRecorder.h index da06885e..70ff0093 100644 --- a/src/MediaFile/MediaRecorder.h +++ b/src/MediaFile/MediaRecorder.h @@ -30,7 +30,7 @@ #include #include "Player/PlayerBase.h" #include "Common/MediaSink.h" -#include "Mp4Maker.h" +#include "MP4Recorder.h" #include "HlsRecorder.h" using namespace toolkit; @@ -61,11 +61,11 @@ public: void addTrack(const Track::Ptr & track) override; private: #if defined(ENABLE_HLS) - std::shared_ptr _hlsMaker; + std::shared_ptr _hlsRecorder; #endif //defined(ENABLE_HLS) #if defined(ENABLE_MP4RECORD) - std::shared_ptr _mp4Maker; + std::shared_ptr _mp4Recorder; #endif //defined(ENABLE_MP4RECORD) }; diff --git a/src/Rtsp/RtpBroadCaster.cpp b/src/Rtsp/RtpMultiCaster.cpp similarity index 90% rename from src/Rtsp/RtpBroadCaster.cpp rename to src/Rtsp/RtpMultiCaster.cpp index b5e4b7dd..1de5bcfe 100644 --- a/src/Rtsp/RtpBroadCaster.cpp +++ b/src/Rtsp/RtpMultiCaster.cpp @@ -26,7 +26,7 @@ #include #include -#include "RtpBroadCaster.h" +#include "RtpMultiCaster.h" #include "Util/util.h" #include "Network/sockutil.h" #include "RtspSession.h" @@ -81,10 +81,10 @@ void MultiCastAddressMaker::release(uint32_t iAddr){ } -recursive_mutex RtpBroadCaster::g_mtx; -unordered_map > RtpBroadCaster::g_mapBroadCaster; +recursive_mutex RtpMultiCaster::g_mtx; +unordered_map > RtpMultiCaster::g_mapBroadCaster; -void RtpBroadCaster::setDetachCB(void* listener, const onDetach& cb) { +void RtpMultiCaster::setDetachCB(void* listener, const onDetach& cb) { lock_guard lck(_mtx); if(cb){ _mapDetach.emplace(listener,cb); @@ -92,12 +92,12 @@ void RtpBroadCaster::setDetachCB(void* listener, const onDetach& cb) { _mapDetach.erase(listener); } } -RtpBroadCaster::~RtpBroadCaster() { +RtpMultiCaster::~RtpMultiCaster() { _pReader->setReadCB(nullptr); _pReader->setDetachCB(nullptr); DebugL; } -RtpBroadCaster::RtpBroadCaster(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream) { +RtpMultiCaster::RtpMultiCaster(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream) { auto src = dynamic_pointer_cast(MediaSource::find(RTSP_SCHEMA,strVhost,strApp, strStream)); if(!src){ auto strErr = StrPrinter << "未找到媒体源:" << strVhost << " " << strApp << " " << strStream << endl; @@ -148,22 +148,22 @@ RtpBroadCaster::RtpBroadCaster(const EventPoller::Ptr &poller,const string &strL << strVhost << " " << strApp << " " << strStream; } -uint16_t RtpBroadCaster::getPort(TrackType trackType){ +uint16_t RtpMultiCaster::getPort(TrackType trackType){ return _apUdpSock[trackType]->get_local_port(); } -string RtpBroadCaster::getIP(){ +string RtpMultiCaster::getIP(){ return inet_ntoa(_aPeerUdpAddr[0].sin_addr); } -RtpBroadCaster::Ptr RtpBroadCaster::make(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream){ +RtpMultiCaster::Ptr RtpMultiCaster::make(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream){ try{ - auto ret = Ptr(new RtpBroadCaster(poller,strLocalIp,strVhost,strApp,strStream),[poller](RtpBroadCaster *ptr){ + auto ret = Ptr(new RtpMultiCaster(poller,strLocalIp,strVhost,strApp,strStream),[poller](RtpMultiCaster *ptr){ poller->async([ptr]() { delete ptr; }); }); lock_guard lck(g_mtx); string strKey = StrPrinter << strLocalIp << " " << strVhost << " " << strApp << " " << strStream << endl; - weak_ptr weakPtr = ret; + weak_ptr weakPtr = ret; g_mapBroadCaster.emplace(strKey,weakPtr); return ret; }catch (std::exception &ex) { @@ -172,7 +172,7 @@ RtpBroadCaster::Ptr RtpBroadCaster::make(const EventPoller::Ptr &poller,const st } } -RtpBroadCaster::Ptr RtpBroadCaster::get(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream) { +RtpMultiCaster::Ptr RtpMultiCaster::get(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream) { string strKey = StrPrinter << strLocalIp << " " << strVhost << " " << strApp << " " << strStream << endl; lock_guard lck(g_mtx); auto it = g_mapBroadCaster.find(strKey); diff --git a/src/Rtsp/RtpBroadCaster.h b/src/Rtsp/RtpMultiCaster.h similarity index 93% rename from src/Rtsp/RtpBroadCaster.h rename to src/Rtsp/RtpMultiCaster.h index 10a5bb48..e95802b1 100644 --- a/src/Rtsp/RtpBroadCaster.h +++ b/src/Rtsp/RtpMultiCaster.h @@ -65,18 +65,18 @@ private: recursive_mutex _mtx; unordered_set _setBadAddr; }; -class RtpBroadCaster { +class RtpMultiCaster { public: - typedef std::shared_ptr Ptr; + typedef std::shared_ptr Ptr; typedef function onDetach; - virtual ~RtpBroadCaster(); + virtual ~RtpMultiCaster(); static Ptr get(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream); void setDetachCB(void *listener,const onDetach &cb); uint16_t getPort(TrackType trackType); string getIP(); private: static recursive_mutex g_mtx; - static unordered_map > g_mapBroadCaster; + static unordered_map > g_mapBroadCaster; static Ptr make(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream); std::shared_ptr _multiAddr; @@ -86,7 +86,7 @@ private: Socket::Ptr _apUdpSock[2]; struct sockaddr_in _aPeerUdpAddr[2]; - RtpBroadCaster(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream); + RtpMultiCaster(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream); }; diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index af01f5a7..47c8b120 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -673,14 +673,14 @@ void RtspSession::handleReq_Setup(const Parser &parser) { } break; case Rtsp::RTP_MULTICAST: { - if(!_pBrdcaster){ - _pBrdcaster = RtpBroadCaster::get(getPoller(),get_local_ip(),_mediaInfo._vhost, _mediaInfo._app, _mediaInfo._streamid); - if (!_pBrdcaster) { + if(!_multicaster){ + _multicaster = RtpMultiCaster::get(getPoller(),get_local_ip(),_mediaInfo._vhost, _mediaInfo._app, _mediaInfo._streamid); + if (!_multicaster) { send_NotAcceptable(); throw SockException(Err_shutdown, "can not get a available udp multicast socket"); } weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); - _pBrdcaster->setDetachCB(this, [weakSelf]() { + _multicaster->setDetachCB(this, [weakSelf]() { auto strongSelf = weakSelf.lock(); if(!strongSelf) { return; @@ -688,7 +688,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) { strongSelf->safeShutdown(SockException(Err_shutdown,"ring buffer detached")); }); } - int iSrvPort = _pBrdcaster->getPort(trackRef->_type); + int iSrvPort = _multicaster->getPort(trackRef->_type); //我们用trackIdx区分rtp和rtcp包 //由于组播udp端口是共享的,而rtcp端口为组播udp端口+1,所以rtcp端口需要改成共享端口 auto pSockRtcp = UDPServer::Instance().getSock(getPoller(),get_local_ip().data(),2*trackIdx + 1,iSrvPort + 1); @@ -702,7 +702,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) { sendRtspResponse("200 OK", {"Transport",StrPrinter << "RTP/AVP;multicast;" - << "destination=" << _pBrdcaster->getIP() << ";" + << "destination=" << _multicaster->getIP() << ";" << "source=" << get_local_ip() << ";" << "port=" << iSrvPort << "-" << pSockRtcp->get_local_port() << ";" << "ttl=" << udpTTL << ";" diff --git a/src/Rtsp/RtspSession.h b/src/Rtsp/RtspSession.h index a6ca4b00..90ebc94f 100644 --- a/src/Rtsp/RtspSession.h +++ b/src/Rtsp/RtspSession.h @@ -36,7 +36,7 @@ #include "Common/config.h" #include "Network/TcpSession.h" #include "Player/PlayerBase.h" -#include "RtpBroadCaster.h" +#include "RtpMultiCaster.h" #include "RtspMediaSource.h" #include "RtspSplitter.h" #include "RtpReceiver.h" @@ -213,7 +213,7 @@ private: unordered_set _udpSockConnected; ////////RTP over udp_multicast//////// //共享的rtp组播对象 - RtpBroadCaster::Ptr _pBrdcaster; + RtpMultiCaster::Ptr _multicaster; //登录认证 string _strNonce;