优化接口

This commit is contained in:
xiongziliang 2018-10-25 16:55:48 +08:00
parent 0839ddb681
commit 3d83a236b6
10 changed files with 20 additions and 26 deletions

View File

@ -104,7 +104,7 @@ void DevChannel::inputH264(const char* pcData, int iDataLen, uint32_t uiStamp) {
uint32_t ui32Ssrc;
memcpy(&ui32Ssrc, makeRandStr(4, false).data(), 4);
auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) {
onGetRTP(pkt,bKeyPos);
onWrite(pkt,bKeyPos);
};
GET_CONFIG_AND_REGISTER(uint32_t,videoMtu,Rtp::kVideoMtuSize);
_pRtpMaker_h264.reset(new RtpMaker_H264(lam, ui32Ssrc,videoMtu));
@ -136,7 +136,7 @@ void DevChannel::inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t u
uint32_t ssrc;
memcpy(&ssrc, makeRandStr(8, false).data() + 4, 4);
auto lam = [this](const RtpPacket::Ptr &pkt, bool keyPos) {
onGetRTP(pkt,keyPos);
onWrite(pkt,keyPos);
};
GET_CONFIG_AND_REGISTER(uint32_t,audioMtu,Rtp::kAudioMtuSize);
_pRtpMaker_aac.reset(new RtpMaker_AAC(lam, ssrc, audioMtu,_audio->iSampleRate));

View File

@ -76,6 +76,7 @@ public:
}
}
virtual void onGetMetaData(const AMFValue &metadata) {
lock_guard<recursive_mutex> lock(_mtxMap);
_metadata = metadata;
@ -88,7 +89,8 @@ public:
_bAsyncRegist = true;
}
}
virtual void onGetMedia(const RtmpPacket::Ptr &pkt) {
void onWrite(const RtmpPacket::Ptr &pkt,bool isKey = true) override {
lock_guard<recursive_mutex> lock(_mtxMap);
if (pkt->isCfgFrame()) {
_mapCfgFrame.emplace(pkt->typeId, pkt);
@ -107,10 +109,6 @@ private:
lock_guard<recursive_mutex> lock(_mtxMap);
return _iCfgFrameSize != -1 && _iCfgFrameSize == _mapCfgFrame.size();
}
void onWrite(const RtmpPacket::Ptr &pkt,bool isKey = true) override {
onGetMedia(pkt);
}
protected:
AMFValue _metadata;
unordered_map<int, RtmpPacket::Ptr> _mapCfgFrame;

View File

@ -80,7 +80,7 @@ private:
_parser->inputRtmp(chunkData);
}
if(_pRtmpMediaSrc){
_pRtmpMediaSrc->onGetMedia(chunkData);
_pRtmpMediaSrc->onWrite(chunkData);
}
}

View File

@ -509,7 +509,7 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) {
if(rtmp_modify_stamp){
chunkData.timeStamp = _stampTicker[chunkData.typeId % 2].elapsedTime();
}
_pPublisherSrc->onGetMedia(std::make_shared<RtmpPacket>(chunkData));
_pPublisherSrc->onWrite(std::make_shared<RtmpPacket>(chunkData));
}
break;
default:

View File

@ -83,7 +83,7 @@ void RtmpToRtspMediaSource::makeSDP() {
// uint32_t ssrc0;
// memcpy(&ssrc0, makeRandStr(4, false).data(), 4);
// auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) {
// _pRtspSrc->onGetRTP(pkt,bKeyPos);
// _pRtspSrc->onWrite(pkt,bKeyPos);
// };
//
// GET_CONFIG_AND_REGISTER(uint32_t,videoMtu,Rtp::kVideoMtuSize);
@ -126,7 +126,7 @@ void RtmpToRtspMediaSource::makeSDP() {
// uint32_t ssrc1;
// memcpy(&ssrc1, makeRandStr(8, false).data() + 4, 4);
// auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) {
// _pRtspSrc->onGetRTP(pkt,bKeyPos);
// _pRtspSrc->onWrite(pkt,bKeyPos);
// };
// GET_CONFIG_AND_REGISTER(uint32_t,audioMtu,Rtp::kAudioMtuSize);
// _pRtpMaker_aac.reset(new RtpMaker_AAC(lam, ssrc1, audioMtu,_pParser->getAudioSampleRate()));

View File

@ -72,14 +72,14 @@ public:
RtmpMediaSource::onGetMetaData(_metadata);
}
void onGetMedia(const RtmpPacket::Ptr &pkt) override {
void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos) override {
if (_pParser) {
if (!_pRtspSrc && _pParser->isInited()) {
makeSDP();
}
_pParser->inputRtmp(pkt);
}
RtmpMediaSource::onGetMedia(pkt);
RtmpMediaSource::onWrite(pkt,key_pos);
}
private:

View File

@ -85,7 +85,8 @@ public:
_strSdp = sdp;
regist();
}
virtual void onGetRTP(const RtpPacket::Ptr &rtppt, bool keyPos) {
void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override {
auto &trackRef = _mapTracks[rtppt->type];
trackRef.seq = rtppt->sequence;
trackRef.timeStamp = rtppt->timeStamp;
@ -93,11 +94,6 @@ public:
trackRef.type = rtppt->type;
_pRing->write(rtppt,keyPos);
}
private:
void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override {
onGetRTP(rtppt,keyPos);
}
protected:
unordered_map<int, RtspTrack> _mapTracks;
string _strSdp; //媒体描述信息

View File

@ -84,7 +84,7 @@ private:
}
if(_pRtspMediaSrc){
_pRtspMediaSrc->onGetRTP(rtppt,true);
_pRtspMediaSrc->onWrite(rtppt,true);
}
}

View File

@ -86,7 +86,7 @@ void RtspToRtmpMediaSource::makeVideoConfigPkt() {
rtmpPkt->streamId = STREAM_MEDIA;
rtmpPkt->timeStamp = 0;
rtmpPkt->typeId = MSG_VIDEO;
_pRtmpSrc->onGetMedia(rtmpPkt);
_pRtmpSrc->onWrite(rtmpPkt);
}
void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) {
if(_pRecorder){
@ -120,7 +120,7 @@ void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) {
rtmpPkt->streamId = STREAM_MEDIA;
rtmpPkt->timeStamp = frame.timeStamp;
rtmpPkt->typeId = MSG_VIDEO;
_pRtmpSrc->onGetMedia(rtmpPkt);
_pRtmpSrc->onWrite(rtmpPkt);
}
void RtspToRtmpMediaSource::onGetAAC(const AACFrame& frame) {
if(_pRecorder){
@ -139,7 +139,7 @@ void RtspToRtmpMediaSource::onGetAAC(const AACFrame& frame) {
rtmpPkt->streamId = STREAM_MEDIA;
rtmpPkt->timeStamp = frame.timeStamp;
rtmpPkt->typeId = MSG_AUDIO;
_pRtmpSrc->onGetMedia(rtmpPkt);
_pRtmpSrc->onWrite(rtmpPkt);
}
void RtspToRtmpMediaSource::makeAudioConfigPkt() {
@ -181,7 +181,7 @@ void RtspToRtmpMediaSource::makeAudioConfigPkt() {
rtmpPkt->streamId = STREAM_MEDIA;
rtmpPkt->timeStamp = 0;
rtmpPkt->typeId = MSG_AUDIO;
_pRtmpSrc->onGetMedia(rtmpPkt);
_pRtmpSrc->onWrite(rtmpPkt);
#endif
}

View File

@ -61,11 +61,11 @@ public:
}
RtspMediaSource::onGetSDP(strSdp);
}
virtual void onGetRTP(const RtpPacket::Ptr &pRtppkt, bool bKeyPos) override{
virtual void onWrite(const RtpPacket::Ptr &pRtppkt, bool bKeyPos) override{
if (_pParser) {
bKeyPos = _pParser->inputRtp(pRtppkt);
}
RtspMediaSource::onGetRTP(pRtppkt, bKeyPos);
RtspMediaSource::onWrite(pRtppkt, bKeyPos);
}
int readerCount(){