From df14924a99f012ae8b04af6ec4fc227a8cff2190 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 15 Nov 2022 20:53:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96rtmp=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E5=85=BC=E5=AE=B9=E6=80=A7:=20#2078?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpProtocol.h | 4 ++-- src/Rtmp/RtmpSession.cpp | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Rtmp/RtmpProtocol.h b/src/Rtmp/RtmpProtocol.h index c94a6c36..ee05cd33 100644 --- a/src/Rtmp/RtmpProtocol.h +++ b/src/Rtmp/RtmpProtocol.h @@ -84,12 +84,12 @@ private: protected: int _send_req_id = 0; + int _now_stream_index = 0; uint32_t _stream_index = STREAM_CONTROL; private: - int _now_stream_index = 0; - int _now_chunk_id = 0; bool _data_started = false; + int _now_chunk_id = 0; ////////////ChunkSize//////////// size_t _chunk_size_in = DEFAULT_CHUNK_LEN; size_t _chunk_size_out = DEFAULT_CHUNK_LEN; diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index b2d9bbcf..1bda933b 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -122,9 +122,9 @@ void RtmpSession::onCmd_createStream(AMFDecoder &dec) { void RtmpSession::onCmd_publish(AMFDecoder &dec) { std::shared_ptr ticker(new Ticker); weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); - std::shared_ptr pToken(new onceToken(nullptr,[ticker,weak_self](){ + std::shared_ptr token(new onceToken(nullptr, [ticker, weak_self]() { auto strong_self = weak_self.lock(); - if(strong_self){ + if (strong_self) { DebugP(strong_self.get()) << "publish 回复时间:" << ticker->elapsedTime() << "ms"; } })); @@ -132,7 +132,9 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { _media_info.parse(_tc_url + "/" + getStreamId(dec.load())); _media_info._schema = RTMP_SCHEMA; - auto on_res = [this, pToken](const string &err, const ProtocolOption &option) { + auto now_stream_index = _now_stream_index; + auto on_res = [this, token, now_stream_index](const string &err, const ProtocolOption &option) { + _now_stream_index = now_stream_index; if (!err.empty()) { sendStatus({ "level", "error", "code", "NetStream.Publish.BadAuth", @@ -196,12 +198,12 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { return; } - Broadcast::PublishAuthInvoker invoker = [weak_self, on_res, pToken](const string &err, const ProtocolOption &option) { + Broadcast::PublishAuthInvoker invoker = [weak_self, on_res, token](const string &err, const ProtocolOption &option) { auto strong_self = weak_self.lock(); if (!strong_self) { return; } - strong_self->async([weak_self, on_res, err, pToken, option]() { + strong_self->async([weak_self, on_res, err, token, option]() { auto strong_self = weak_self.lock(); if (!strong_self) { return; @@ -361,24 +363,26 @@ void RtmpSession::doPlay(AMFDecoder &dec){ DebugP(strong_self.get()) << "play 回复时间:" << ticker->elapsedTime() << "ms"; } })); - Broadcast::AuthInvoker invoker = [weak_self,token](const string &err){ + auto now_stream_index = _now_stream_index; + Broadcast::AuthInvoker invoker = [weak_self, token, now_stream_index](const string &err) { auto strong_self = weak_self.lock(); if (!strong_self) { return; } - strong_self->async([weak_self, err, token]() { + strong_self->async([weak_self, err, token, now_stream_index]() { auto strong_self = weak_self.lock(); if (!strong_self) { return; } + strong_self->_now_stream_index = now_stream_index; strong_self->doPlayResponse(err, [token](bool) {}); }); }; auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _media_info, invoker, static_cast(*this)); - if(!flag){ - //该事件无人监听,默认不鉴权 - doPlayResponse("",[token](bool){}); + if (!flag) { + // 该事件无人监听,默认不鉴权 + doPlayResponse("", [token](bool) {}); } }