Commit c6e9f836 by xiongziliang

规范类命名

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