mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
优化代码
This commit is contained in:
parent
83df74561c
commit
bb03af0f7f
@ -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) {
|
||||
|
@ -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<void(const SockException &ex)> m_shutdownCB;
|
||||
function<void(const SockException &ex)> m_playResultCB;
|
||||
std::shared_ptr<Parser> m_parser;
|
||||
function<void(const H264Frame &frame)> m_onGetVideoCB;
|
||||
function<void(const AdtsFrame &frame)> m_onGetAudioCB;
|
||||
MediaSource::Ptr m_pMediaSrc;
|
||||
|
||||
};
|
||||
} /* namespace Player */
|
||||
|
@ -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<RtmpMediaSource>(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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -65,6 +65,10 @@ public:
|
||||
private:
|
||||
//派生类回调函数
|
||||
bool onCheckSDP(const string &sdp, const RtspTrack *track, int trackCnt) override {
|
||||
m_pRtspMediaSrc = dynamic_pointer_cast<RtspMediaSource>(m_pMediaSrc);
|
||||
if(m_pRtspMediaSrc){
|
||||
m_pRtspMediaSrc->onGetSDP(sdp);
|
||||
}
|
||||
try {
|
||||
m_parser.reset(new RtpParser(sdp));
|
||||
m_parser->setOnVideoCB(m_onGetVideoCB);
|
||||
@ -72,13 +76,22 @@ 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 {
|
||||
if(m_parser){
|
||||
m_parser->inputRtp(*rtppt);
|
||||
}
|
||||
|
||||
if(m_pRtspMediaSrc){
|
||||
m_pRtspMediaSrc->onGetRTP(rtppt,true);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
RtspMediaSource::Ptr m_pRtspMediaSrc;
|
||||
|
||||
};
|
||||
|
||||
} /* namespace Rtsp */
|
||||
|
Loading…
Reference in New Issue
Block a user