Commit bdc1f0cd by xiongziliang

规范SdpAttr成员变量命名

parent c5561228
......@@ -110,13 +110,13 @@ void SdpAttr::load(const string &sdp) {
for (auto &pr : _track_map) {
auto &track = *pr.second;
if (pr.first == "") {
track.type = TrackTitle;
track._type = TrackTitle;
} else if (pr.first == "video") {
track.type = TrackVideo;
track._type = TrackVideo;
} else if (pr.first == "audio") {
track.type = TrackAudio;
track._type = TrackAudio;
} else {
track.type = TrackInvalid;
track._type = TrackInvalid;
}
auto it = track._attr.find("range");
......@@ -165,7 +165,7 @@ bool SdpAttr::available() const {
SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const {
for (auto &pr : _track_map){
if(pr.second->type == type){
if(pr.second->_type == type){
return pr.second;
}
}
......
......@@ -63,13 +63,13 @@ public:
string _fmtp;
string _control;
string _control_surffix;
TrackType type;
TrackType _type;
public:
uint8_t interleaved = 0;
bool inited = false;
uint32_t ssrc = 0;
uint16_t seq = 0;
uint32_t timeStamp = 0;
uint8_t _interleaved = 0;
bool _inited = false;
uint32_t _ssrc = 0;
uint16_t _seq = 0;
uint32_t _time_stamp = 0;
};
class SdpAttr {
public:
......
......@@ -71,31 +71,45 @@ public:
}
virtual uint32_t getSsrc(TrackType trackType) {
return _mapTracks[trackType].ssrc;
auto track = _sdpAttr.getTrack(trackType);
if(!track){
return 0;
}
return track->_ssrc;
}
virtual uint16_t getSeqence(TrackType trackType) {
return _mapTracks[trackType].seq;
auto track = _sdpAttr.getTrack(trackType);
if(!track){
return 0;
}
return track->_seq;
}
virtual uint32_t getTimestamp(TrackType trackType) {
return _mapTracks[trackType].timeStamp;
auto track = _sdpAttr.getTrack(trackType);
if(!track){
return 0;
}
return track->_time_stamp;
}
virtual void onGetSDP(const string& sdp) {
//派生类设置该媒体源媒体描述信息
_strSdp = sdp;
_sdpAttr.load(sdp);
regist();
}
void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override {
auto &trackRef = _mapTracks[rtppt->type];
trackRef.seq = rtppt->sequence;
trackRef.timeStamp = rtppt->timeStamp;
trackRef.ssrc = rtppt->ssrc;
trackRef.type = rtppt->type;
auto track = _sdpAttr.getTrack(rtppt->type);
if(track){
track->_seq = rtppt->sequence;
track->_time_stamp = rtppt->timeStamp;
track->_ssrc = rtppt->ssrc;
}
_pRing->write(rtppt,keyPos);
}
protected:
unordered_map<int, SdpTrack> _mapTracks;
SdpAttr _sdpAttr;
string _strSdp; //媒体描述信息
RingType::Ptr _pRing; //rtp环形缓冲
};
......
......@@ -287,10 +287,6 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
}
CLEAR_ARR(_aui32SsrcErrorCnt)
for (auto &track : _aTrackInfo) {
track->ssrc=0;
}
sendSetup(0);
}
//发送SETUP命令
......@@ -302,7 +298,7 @@ bool RtspPlayer::sendSetup(unsigned int trackIndex) {
switch (_eType) {
case RTP_TCP: {
StrCaseMap header;
header["Transport"] = StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track->type * 2 << "-" << track->type * 2 + 1;
header["Transport"] = StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track->_type * 2 << "-" << track->_type * 2 + 1;
return sendRtspRequest("SETUP",baseUrl,header);
}
break;
......@@ -352,7 +348,7 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int uiTrackIndex)
if(_eType == RTP_TCP) {
string interleaved = FindField( FindField((strTransport + ";").c_str(), "interleaved=", ";").c_str(), NULL, "-");
_aTrackInfo[uiTrackIndex]->interleaved = atoi(interleaved.c_str());
_aTrackInfo[uiTrackIndex]->_interleaved = atoi(interleaved.c_str());
}else{
const char *strPos = (_eType == RTP_MULTICAST ? "port=" : "server_port=") ;
auto port_str = FindField((strTransport + ";").c_str(), strPos, ";");
......@@ -589,7 +585,7 @@ bool RtspPlayer::handleOneRtp(int iTrackidx, unsigned char *pucData, unsigned in
auto &track = _aTrackInfo[iTrackidx];
auto pt_ptr=_pktPool.obtain();
auto &rtppt=*pt_ptr;
rtppt.interleaved = track->interleaved;
rtppt.interleaved = track->_interleaved;
rtppt.length = uiLen + 4;
rtppt.mark = pucData[1] >> 7;
......@@ -603,15 +599,15 @@ bool RtspPlayer::handleOneRtp(int iTrackidx, unsigned char *pucData, unsigned in
//ssrc
memcpy(&rtppt.ssrc,pucData+8,4);//内存对齐
rtppt.ssrc = ntohl(rtppt.ssrc);
rtppt.type = track->type;
if (track->ssrc == 0) {
track->ssrc = rtppt.ssrc;
rtppt.type = track->_type;
if (track->_ssrc == 0) {
track->_ssrc = rtppt.ssrc;
//保存SSRC
} else if (track->ssrc != rtppt.ssrc) {
} else if (track->_ssrc != rtppt.ssrc) {
//ssrc错误
WarnL << "ssrc错误";
if (_aui32SsrcErrorCnt[iTrackidx]++ > 10) {
track->ssrc = rtppt.ssrc;
track->_ssrc = rtppt.ssrc;
WarnL << "ssrc更换!";
}
return false;
......@@ -815,7 +811,7 @@ int RtspPlayer::getTrackIndexByControlSuffix(const string &controlSuffix) const{
}
int RtspPlayer::getTrackIndexByInterleaved(int interleaved) const{
for (unsigned int i = 0; i < _aTrackInfo.size(); i++) {
if (_aTrackInfo[i]->interleaved == interleaved) {
if (_aTrackInfo[i]->_interleaved == interleaved) {
return i;
}
}
......@@ -824,7 +820,7 @@ int RtspPlayer::getTrackIndexByInterleaved(int interleaved) const{
int RtspPlayer::getTrackIndexByTrackType(TrackType trackType) const {
for (unsigned int i = 0; i < _aTrackInfo.size(); i++) {
if (_aTrackInfo[i]->type == trackType) {
if (_aTrackInfo[i]->_type == trackType) {
return i;
}
}
......
......@@ -67,7 +67,7 @@ private:
if(_pRtspMediaSrc){
_pRtspMediaSrc->onGetSDP(sdp);
}
_parser.reset(new RtspDemuxer(sdp));
_parser.reset(new RtspDemuxer(sdpAttr));
return true;
}
void onRecvRTP(const RtpPacket::Ptr &rtppt, const SdpTrack::Ptr &track) override {
......
......@@ -512,11 +512,11 @@ bool RtspSession::handleReq_Setup() {
return false;
}
SdpTrack::Ptr &trackRef = _aTrackInfo[trackIdx];
if (trackRef->inited) {
if (trackRef->_inited) {
//已经初始化过该Track
return false;
}
trackRef->inited = true; //现在初始化
trackRef->_inited = true; //现在初始化
auto strongRing = _pWeakRing.lock();
if (!strongRing) {
......@@ -562,9 +562,9 @@ bool RtspSession::handleReq_Setup() {
"x-Dynamic-Rate: 1\r\n\r\n",
_iCseq, SERVER_NAME,
RTSP_VERSION, RTSP_BUILDTIME,
dateHeader().data(), trackRef->type * 2,
trackRef->type * 2 + 1,
printSSRC(trackRef->ssrc).data(),
dateHeader().data(), trackRef->_type * 2,
trackRef->_type * 2 + 1,
printSSRC(trackRef->_ssrc).data(),
_strSession.data());
SocketHelper::send(_pcBuf, iLen);
}
......@@ -609,7 +609,7 @@ bool RtspSession::handleReq_Setup() {
RTSP_VERSION, RTSP_BUILDTIME,
dateHeader().data(), strClientPort.data(),
pSockRtp->get_local_port(), pSockRtcp->get_local_port(),
printSSRC(trackRef->ssrc).data(),
printSSRC(trackRef->_ssrc).data(),
_strSession.data());
SocketHelper::send(_pcBuf, n);
}
......@@ -630,7 +630,7 @@ bool RtspSession::handleReq_Setup() {
strongSelf->safeShutdown();
});
}
int iSrvPort = _pBrdcaster->getPort(trackRef->type);
int iSrvPort = _pBrdcaster->getPort(trackRef->_type);
//我们用trackIdx区分rtp和rtcp包
auto pSockRtcp = UDPServer::Instance().getSock(get_local_ip().data(),2*trackIdx + 1,iSrvPort + 1);
if (!pSockRtcp) {
......@@ -652,7 +652,7 @@ bool RtspSession::handleReq_Setup() {
RTSP_VERSION, RTSP_BUILDTIME,
dateHeader().data(), _pBrdcaster->getIP().data(),
get_local_ip().data(), iSrvPort, pSockRtcp->get_local_port(),
udpTTL,printSSRC(trackRef->ssrc).data(),
udpTTL,printSSRC(trackRef->_ssrc).data(),
_strSession.data());
SocketHelper::send(_pcBuf, n);
}
......@@ -733,9 +733,9 @@ bool RtspSession::handleReq_Play() {
}
for(auto &track : _aTrackInfo){
track->ssrc = pMediaSrc->getSsrc(track->type);
track->seq = pMediaSrc->getSeqence(track->type);
track->timeStamp = pMediaSrc->getTimestamp(track->type);
track->_ssrc = pMediaSrc->getSsrc(track->_type);
track->_seq = pMediaSrc->getSeqence(track->_type);
track->_time_stamp = pMediaSrc->getTimestamp(track->_type);
}
}
_bFirstPlay = false;
......@@ -749,12 +749,12 @@ bool RtspSession::handleReq_Play() {
dateHeader().data(), _strSession.data(),iStamp/1000.0);
for(auto &track : _aTrackInfo){
if (track->inited == false) {
if (track->_inited == false) {
//还有track没有setup
shutdown();
return;
}
iLen += sprintf(_pcBuf + iLen, "url=%s/%s;seq=%d;rtptime=%u,", _strUrl.data(), track->_control_surffix.data(), track->seq,track->timeStamp);
iLen += sprintf(_pcBuf + iLen, "url=%s/%s;seq=%d;rtptime=%u,", _strUrl.data(), track->_control_surffix.data(), track->_seq,track->_time_stamp);
}
iLen -= 1;
......@@ -904,9 +904,9 @@ inline bool RtspSession::findStream() {
_pMediaSrc = pMediaSrc;
for(auto &track : _aTrackInfo){
track->ssrc = pMediaSrc->getSsrc(track->type);
track->seq = pMediaSrc->getSeqence(track->type);
track->timeStamp = pMediaSrc->getTimestamp(track->type);
track->_ssrc = pMediaSrc->getSsrc(track->_type);
track->_seq = pMediaSrc->getSeqence(track->_type);
track->_time_stamp = pMediaSrc->getTimestamp(track->_type);
}
return true;
}
......
......@@ -118,7 +118,7 @@ private:
}
inline int getTrackIndexByTrackType(TrackType type) {
for (unsigned int i = 0; i < _aTrackInfo.size(); i++) {
if (type == _aTrackInfo[i]->type) {
if (type == _aTrackInfo[i]->_type) {
return i;
}
}
......
......@@ -49,8 +49,9 @@ public:
virtual ~RtspToRtmpMediaSource();
virtual void onGetSDP(const string& strSdp) override{
RtspMediaSource::onGetSDP(strSdp);
try {
_pParser.reset(new RtspDemuxer(strSdp));
_pParser.reset(new RtspDemuxer(_sdpAttr));
_pRecorder.reset(new MediaRecorder(getVhost(),getApp(),getId(),_pParser,_bEnableHls,_bEnableMp4));
//todo(xzl) 修复此处
// _pParser->setOnAudioCB( std::bind(&RtspToRtmpMediaSource::onGetAAC, this, placeholders::_1));
......@@ -59,7 +60,6 @@ public:
} catch (exception &ex) {
WarnL << ex.what();
}
RtspMediaSource::onGetSDP(strSdp);
}
virtual void onWrite(const RtpPacket::Ptr &pRtppkt, bool bKeyPos) override{
if (_pParser) {
......@@ -73,20 +73,9 @@ public:
}
void updateTimeStamp(uint32_t uiStamp) {
for (auto &pr : _mapTracks) {
switch (pr.second.type) {
case TrackAudio: {
//todo(xzl) 修复此处
// pr.second.timeStamp = uiStamp * (_pParser->getAudioSampleRate() / 1000.0);
}
break;
case TrackVideo: {
pr.second.timeStamp = uiStamp * 90;
}
break;
default:
break;
}
auto tracks = _sdpAttr.getAvailableTrack();
for (auto &track : tracks) {
track->_time_stamp = uiStamp * (track->_samplerate / 1000.0);
}
}
......
......@@ -61,7 +61,7 @@ RtspDemuxer::RtspDemuxer(const SdpAttr &attr) {
void RtspDemuxer::loadSdp(const SdpAttr &attr) {
auto tracks = attr.getAvailableTrack();
for (auto &track : tracks){
switch (track->type) {
switch (track->_type) {
case TrackVideo: {
makeVideoTrack(track);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论