Commit bb4e8b73 by xiongziliang

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

parent 9dc1f3a8
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论