兼容不规范的rtmp推流器 (#2417 #2715)

有些rtmp推流器在服务器返回鉴权成功前就开启推送流数据
This commit is contained in:
夏楚 2023-07-29 13:06:36 +08:00 committed by GitHub
parent 5464313b41
commit 54194fe501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -536,7 +536,14 @@ void RtmpSession::onRtmpChunk(RtmpPacket::Ptr packet) {
case MSG_AUDIO:
case MSG_VIDEO: {
if (!_push_src) {
WarnL << "Not a rtmp push!";
if (_ring_reader) {
throw std::runtime_error("Rtmp player send media packets");
}
if (packet->isConfigFrame()) {
auto id = packet->type_id;
_push_config_packets.emplace(id, std::move(packet));
}
WarnL << "Rtmp pusher send media packet before handshake completed!";
return;
}
@ -544,6 +551,12 @@ void RtmpSession::onRtmpChunk(RtmpPacket::Ptr packet) {
_set_meta_data = true;
_push_src->setMetaData(_push_metadata ? _push_metadata : TitleMeta().getMetadata());
}
if (!_push_config_packets.empty()) {
for (auto &pr : _push_config_packets) {
_push_src->onWrite(std::move(pr.second));
}
_push_config_packets.clear();
}
_push_src->onWrite(std::move(packet));
break;
}

View File

@ -97,6 +97,7 @@ private:
MediaInfo _media_info;
std::weak_ptr<RtmpMediaSource> _play_src;
AMFValue _push_metadata;
std::map<uint8_t, RtmpPacket::Ptr> _push_config_packets;
RtmpMediaSourceImp::Ptr _push_src;
std::shared_ptr<void> _push_src_ownership;
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;