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

View File

@ -437,8 +437,7 @@ void RtmpSession::setMetaData(AMFDecoder &dec) {
throw std::runtime_error("can only set metadata");
}
auto metadata = dec.load<AMFValue>();
//dumpMetadata(metadata);
_metadata_got = true;
// dumpMetadata(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);
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)));
}
break;

View File

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