diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp index e1d3c508..62eeb89d 100644 --- a/src/Device/Device.cpp +++ b/src/Device/Device.cpp @@ -270,7 +270,6 @@ inline void DevChannel::makeSDP_AAC(unsigned char *fixedHeader) { void DevChannel::makeSDP(const string& strSdp) { onGetSDP(strSdp); - regist(); } void DevChannel::initVideo(const VideoInfo& info) { diff --git a/src/Player/PlayerBase.h b/src/Player/PlayerBase.h index 79faa718..454c8789 100644 --- a/src/Player/PlayerBase.h +++ b/src/Player/PlayerBase.h @@ -34,9 +34,11 @@ #include "Player.h" #include "Network/Socket.h" #include "Util/mini.h" +#include "Common/MediaSource.h" using namespace std; using namespace ZL::Util; +using namespace ZL::Media; using namespace ZL::Network; namespace ZL { @@ -92,6 +94,7 @@ public: virtual float getDuration() const { return 0;}; virtual float getProgress() const { return 0;}; virtual void seekTo(float fProgress) {}; + virtual void setMediaSouce(const MediaSource::Ptr & src) {}; protected: virtual void onShutdown(const SockException &ex) {}; virtual void onPlayResult(const SockException &ex) {}; @@ -226,6 +229,14 @@ public: } return PlayerBase::seekTo(fProgress); }; + + void setMediaSouce(const MediaSource::Ptr & src) override { + if (m_parser) { + return m_parser->setMediaSouce(src); + } + m_pMediaSrc = src; + }; + protected: void onShutdown(const SockException &ex) override { if (m_shutdownCB) { @@ -238,11 +249,13 @@ protected: m_playResultCB = nullptr; } } +protected: function m_shutdownCB; function m_playResultCB; std::shared_ptr m_parser; function m_onGetVideoCB; function m_onGetAudioCB; + MediaSource::Ptr m_pMediaSrc; }; } /* namespace Player */ diff --git a/src/Rtmp/RtmpPlayerImp.h b/src/Rtmp/RtmpPlayerImp.h index ebe86ea5..12b0c46c 100644 --- a/src/Rtmp/RtmpPlayerImp.h +++ b/src/Rtmp/RtmpPlayerImp.h @@ -32,6 +32,7 @@ #include "Common/config.h" #include "RtmpPlayer.h" #include "RtmpParser.h" +#include "RtmpMediaSource.h" #include "Poller/Timer.h" #include "Util/TimeTicker.h" @@ -62,6 +63,10 @@ public: private: //派生类回调函数 bool onCheckMeta(AMFValue &val) override { + m_pRtmpMediaSrc = dynamic_pointer_cast(m_pMediaSrc); + if(m_pRtmpMediaSrc){ + m_pRtmpMediaSrc->onGetMetaData(val); + } try { m_parser.reset(new RtmpParser(val)); m_parser->setOnVideoCB(m_onGetVideoCB); @@ -69,14 +74,20 @@ private: return true; } catch (std::exception &ex) { WarnL << ex.what(); - return false; + return m_pRtmpMediaSrc ? true : false; } } void onMediaData(const RtmpPacket::Ptr &chunkData) override { if(m_parser){ m_parser->inputRtmp(chunkData); } + if(m_pRtmpMediaSrc){ + m_pRtmpMediaSrc->onGetMedia(chunkData); + } } + +private: + RtmpMediaSource::Ptr m_pRtmpMediaSrc; }; diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index 1c43379d..283d18fe 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -58,6 +58,7 @@ int parserSDP(const string& sdp, RtspTrack Track[2]) { pos_end = sdp.size(); } auto sdp_mid = sdp.substr(pos_head, pos_end - pos_head); + pos_head = pos_end; Track[track_cnt].trackSdp = sdp_mid; Track[track_cnt].inited = false; Track[track_cnt].PT = atoi(FindField(sdp_mid.c_str(), "a=rtpmap:", " ").c_str()); @@ -72,9 +73,8 @@ int parserSDP(const string& sdp, RtspTrack Track[2]) { Track[track_cnt].type = TrackAudio; } else { //不识别的track - return track_cnt; + continue; } - pos_head = pos_end; track_cnt++; } return track_cnt; diff --git a/src/Rtsp/RtspPlayerImp.h b/src/Rtsp/RtspPlayerImp.h index 12870d1c..467f7595 100644 --- a/src/Rtsp/RtspPlayerImp.h +++ b/src/Rtsp/RtspPlayerImp.h @@ -65,6 +65,10 @@ public: private: //派生类回调函数 bool onCheckSDP(const string &sdp, const RtspTrack *track, int trackCnt) override { + m_pRtspMediaSrc = dynamic_pointer_cast(m_pMediaSrc); + if(m_pRtspMediaSrc){ + m_pRtspMediaSrc->onGetSDP(sdp); + } try { m_parser.reset(new RtpParser(sdp)); m_parser->setOnVideoCB(m_onGetVideoCB); @@ -72,12 +76,21 @@ private: return true; } catch (std::exception &ex) { WarnL << ex.what(); - return false; + return m_pRtspMediaSrc ? true : false; } } void onRecvRTP(const RtpPacket::Ptr &rtppt, const RtspTrack &track) override { - m_parser->inputRtp(*rtppt); + if(m_parser){ + m_parser->inputRtp(*rtppt); + } + + if(m_pRtspMediaSrc){ + m_pRtspMediaSrc->onGetRTP(rtppt,true); + } } + +private: + RtspMediaSource::Ptr m_pRtspMediaSrc; };