兼容一些不规范的rtmp推流:#190

This commit is contained in:
xiongziliang 2019-12-25 10:13:59 +08:00
parent 9dc1f3a804
commit bb4e8b73b5
3 changed files with 7 additions and 24 deletions

View File

@ -57,8 +57,9 @@ public:
const string &strApp, const string &strApp,
const string &strId, const string &strId,
int ringSize = 0) : int ringSize = 0) :
MediaSource(RTMP_SCHEMA,vhost,strApp,strId), MediaSource(RTMP_SCHEMA,vhost,strApp,strId), _ringSize(ringSize) {
_ringSize(ringSize) {} _metadata = TitleMeta().getMetadata();
}
virtual ~RtmpMediaSource() {} virtual ~RtmpMediaSource() {}
@ -95,7 +96,6 @@ public:
return; return;
} }
_mapStamp[pkt->typeId] = pkt->timeStamp;
if(!_pRing){ if(!_pRing){
weak_ptr<RtmpMediaSource> weakSelf = dynamic_pointer_cast<RtmpMediaSource>(shared_from_this()); weak_ptr<RtmpMediaSource> weakSelf = dynamic_pointer_cast<RtmpMediaSource>(shared_from_this());
_pRing = std::make_shared<RingType>(_ringSize,[weakSelf](const EventPoller::Ptr &,int size,bool){ _pRing = std::make_shared<RingType>(_ringSize,[weakSelf](const EventPoller::Ptr &,int size,bool){
@ -108,12 +108,13 @@ public:
onReaderChanged(0); onReaderChanged(0);
} }
if(!_registed && _metadata && _mapCfgFrame.size() >= getTrackSize()){ //如果输入了非config帧那么说明不再可能获取config帧以及metadata,所以我们强制其为已注册
//在未注册的情况下需要获取到metadata并且获取到全部的config帧才可以注册 if(!_registed){
_registed = true; _registed = true;
regist(); regist();
} }
_mapStamp[pkt->typeId] = pkt->timeStamp;
_pRing->write(pkt,pkt->isVideoKeyFrame()); _pRing->write(pkt,pkt->isVideoKeyFrame());
checkNoneReader(); checkNoneReader();
} }
@ -149,17 +150,6 @@ private:
onNoneReader(); onNoneReader();
} }
} }
int getTrackSize(){
int ret = 0;
if(_metadata["videocodecid"]){
++ret;
}
if(_metadata["audiocodecid"]){
++ret;
}
return ret;
}
protected: protected:
AMFValue _metadata; AMFValue _metadata;
unordered_map<int, RtmpPacket::Ptr> _mapCfgFrame; unordered_map<int, RtmpPacket::Ptr> _mapCfgFrame;

View File

@ -438,7 +438,6 @@ void RtmpSession::setMetaData(AMFDecoder &dec) {
} }
auto metadata = dec.load<AMFValue>(); auto metadata = dec.load<AMFValue>();
// dumpMetadata(metadata); // dumpMetadata(metadata);
_metadata_got = true;
_pPublisherSrc->onGetMetaData(metadata); _pPublisherSrc->onGetMetaData(metadata);
} }
@ -496,11 +495,6 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) {
_stamp[chunkData.typeId % 2].revise(chunkData.timeStamp, chunkData.timeStamp, dts_out, dts_out, true); _stamp[chunkData.typeId % 2].revise(chunkData.timeStamp, chunkData.timeStamp, dts_out, dts_out, true);
chunkData.timeStamp = dts_out; chunkData.timeStamp = dts_out;
} }
if(!_metadata_got && !chunkData.isCfgFrame()){
//有些rtmp推流客户端不产生metadata我们产生一个默认的metadata目的是为了触发注册操作
_metadata_got = true;
_pPublisherSrc->onGetMetaData(TitleMeta().getMetadata());
}
_pPublisherSrc->onWrite(std::make_shared<RtmpPacket>(std::move(chunkData))); _pPublisherSrc->onWrite(std::make_shared<RtmpPacket>(std::move(chunkData)));
} }
break; break;

View File

@ -89,7 +89,6 @@ private:
string getStreamId(const string &str); string getStreamId(const string &str);
void dumpMetadata(const AMFValue &metadata); void dumpMetadata(const AMFValue &metadata);
private: private:
bool _metadata_got = false;
std::string _strTcUrl; std::string _strTcUrl;
MediaInfo _mediaInfo; MediaInfo _mediaInfo;
double _dNowReqID = 0; double _dNowReqID = 0;