From 9ef5a115794a301d9113082d6ea2dbef1b230e5a Mon Sep 17 00:00:00 2001 From: xzl <771730766@qq.com> Date: Thu, 18 May 2017 16:24:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9rtmp=20play2?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpSession.cpp | 41 +++++++++++++++++++++++----------------- src/Rtmp/RtmpSession.h | 2 ++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 4bb31fb8..886cbdd8 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -21,6 +21,7 @@ RtmpSession::RtmpSession(const std::shared_ptr &pTh, const Socket::P g_mapCmd.emplace("publish",&RtmpSession::onCmd_publish); g_mapCmd.emplace("deleteStream",&RtmpSession::onCmd_deleteStream); g_mapCmd.emplace("play",&RtmpSession::onCmd_play); + g_mapCmd.emplace("play2",&RtmpSession::onCmd_play2); g_mapCmd.emplace("seek",&RtmpSession::onCmd_seek); g_mapCmd.emplace("pause",&RtmpSession::onCmd_pause);}, []() {}); DebugL << getPeerIp(); @@ -136,13 +137,7 @@ void RtmpSession::onCmd_deleteStream(AMFDecoder &dec) { throw std::runtime_error(StrPrinter << "Stop publishing." << endl); } -void RtmpSession::onCmd_play(AMFDecoder &dec) { - dec.load();/* NULL */ - m_strId = dec.load(); - auto iPos = m_strId.find('?'); - if (iPos != string::npos) { - m_strId.erase(iPos); - } +void RtmpSession::doPlay(){ auto src = RtmpMediaSource::find(m_strApp,m_strId,true); bool ok = (src.operator bool()); ok = ok && src->ready(); @@ -150,7 +145,7 @@ void RtmpSession::onCmd_play(AMFDecoder &dec) { //stream begin sendUserControl(CONTROL_STREAM_BEGIN, STREAM_MEDIA); -// onStatus(NetStream.Play.Reset) + // onStatus(NetStream.Play.Reset) AMFValue status(AMF_OBJECT); status.set("level", ok ? "status" : "error"); status.set("code", ok ? "NetStream.Play.Reset" : "NetStream.Play.StreamNotFound"); @@ -162,7 +157,7 @@ void RtmpSession::onCmd_play(AMFDecoder &dec) { throw std::runtime_error( StrPrinter << "No such stream:" << m_strApp << " " << m_strId << endl); } -// onStatus(NetStream.Play.Start) + // onStatus(NetStream.Play.Start) status.clear(); status.set("level", "status"); status.set("code", "NetStream.Play.Start"); @@ -171,7 +166,7 @@ void RtmpSession::onCmd_play(AMFDecoder &dec) { status.set("clientid", "0"); sendReply("onStatus", nullptr, status); -// |RtmpSampleAccess(true, true) + // |RtmpSampleAccess(true, true) AMFEncoder invoke; invoke << "|RtmpSampleAccess" << true << true; sendResponse(MSG_DATA, invoke.data()); @@ -192,15 +187,15 @@ void RtmpSession::onCmd_play(AMFDecoder &dec) { status.set("clientid", "0"); sendReply("onStatus", nullptr, status); -// onMetaData + // onMetaData invoke.clear(); invoke << "onMetaData" << src->getMetaData(); sendResponse(MSG_DATA, invoke.data()); src->getConfigFrame([&](const RtmpPacket &pkt) { //DebugL<<"send initial frame"; - onSendMedia(pkt); - }); + onSendMedia(pkt); + }); m_pRingReader = src->getRing()->attach(); weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); @@ -224,10 +219,22 @@ void RtmpSession::onCmd_play(AMFDecoder &dec) { } strongSelf->safeShutdown(); }); - m_pPlayerSrc = src; - if(src->getRing()->readerCount() == 1){ - src->seekTo(0); - } + m_pPlayerSrc = src; + if(src->getRing()->readerCount() == 1){ + src->seekTo(0); + } +} +void RtmpSession::onCmd_play2(AMFDecoder &dec) { + doPlay(); +} +void RtmpSession::onCmd_play(AMFDecoder &dec) { + dec.load();/* NULL */ + m_strId = dec.load(); + auto iPos = m_strId.find('?'); + if (iPos != string::npos) { + m_strId.erase(iPos); + } + doPlay(); } void RtmpSession::onCmd_pause(AMFDecoder &dec) { diff --git a/src/Rtmp/RtmpSession.h b/src/Rtmp/RtmpSession.h index 1b984378..60f6d465 100644 --- a/src/Rtmp/RtmpSession.h +++ b/src/Rtmp/RtmpSession.h @@ -56,6 +56,8 @@ private: void onCmd_deleteStream(AMFDecoder &dec); void onCmd_play(AMFDecoder &dec); + void onCmd_play2(AMFDecoder &dec); + void doPlay(); void onCmd_seek(AMFDecoder &dec); void onCmd_pause(AMFDecoder &dec); void setMetaData(AMFDecoder &dec);