From 54194fe501b73dc66928023191278e6b751ffc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 29 Jul 2023 13:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=8D=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E7=9A=84rtmp=E6=8E=A8=E6=B5=81=E5=99=A8=20(#2417=20#2715)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有些rtmp推流器在服务器返回鉴权成功前就开启推送流数据 --- src/Rtmp/RtmpSession.cpp | 15 ++++++++++++++- src/Rtmp/RtmpSession.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index ebdfb74e..2ebf2f41 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -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; } diff --git a/src/Rtmp/RtmpSession.h b/src/Rtmp/RtmpSession.h index f9c2bf2a..f51b567e 100644 --- a/src/Rtmp/RtmpSession.h +++ b/src/Rtmp/RtmpSession.h @@ -97,6 +97,7 @@ private: MediaInfo _media_info; std::weak_ptr _play_src; AMFValue _push_metadata; + std::map _push_config_packets; RtmpMediaSourceImp::Ptr _push_src; std::shared_ptr _push_src_ownership; RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;