添加rtsp推流器

整理代码
This commit is contained in:
xiongziliang
2019-03-27 18:41:52 +08:00
parent e3ab51b337
commit b1a2de3853
35 changed files with 1210 additions and 273 deletions

View File

@@ -37,7 +37,7 @@ MediaPlayer::MediaPlayer() {
MediaPlayer::~MediaPlayer() {
}
void MediaPlayer::play(const char* strUrl) {
void MediaPlayer::play(const string &strUrl) {
_parser = PlayerBase::createPlayer(strUrl);
_parser->setOnShutdown(_shutdownCB);
_parser->setOnPlayResult(_playResultCB);

View File

@@ -43,7 +43,7 @@ public:
MediaPlayer();
virtual ~MediaPlayer();
void play(const char* strUrl) override;
void play(const string &strUrl) override;
void pause(bool bPause) override;
void teardown() override;
EventPoller::Ptr getPoller();

View File

@@ -45,14 +45,14 @@ const char PlayerBase::kBeatIntervalMS[] = "beat_interval_ms";
const char PlayerBase::kMaxAnalysisMS[] = "max_analysis_ms";
PlayerBase::Ptr PlayerBase::createPlayer(const char* strUrl) {
PlayerBase::Ptr PlayerBase::createPlayer(const string &strUrl) {
static auto releasePlayer = [](PlayerBase *ptr){
onceToken token(nullptr,[&](){
delete ptr;
});
ptr->teardown();
};
string prefix = FindField(strUrl, NULL, "://");
string prefix = FindField(strUrl.data(), NULL, "://");
if (strcasecmp("rtsp",prefix.data()) == 0) {
return PlayerBase::Ptr(new RtspPlayerImp(),releasePlayer);
}

View File

@@ -86,13 +86,7 @@ public:
class PlayerBase : public DemuxerBase, public mINI{
public:
typedef std::shared_ptr<PlayerBase> Ptr;
typedef enum {
RTP_Invalid = -1,
RTP_TCP = 0,
RTP_UDP = 1,
RTP_MULTICAST = 2,
} eRtpType;
static Ptr createPlayer(const char* strUrl);
static Ptr createPlayer(const string &strUrl);
//指定网卡ip
static const char kNetAdapter[];
@@ -122,7 +116,7 @@ public:
* 开始播放
* @param strUrl 视频url支持rtsp/rtmp
*/
virtual void play(const char* strUrl) {}
virtual void play(const string &strUrl) {}
/**
* 暂停或恢复

View File

@@ -61,9 +61,9 @@ static uint8_t s_mute_adts[] = {0xff, 0xf1, 0x6c, 0x40, 0x2d, 0x3f, 0xfc, 0x00,
#define MUTE_ADTS_DATA_LEN sizeof(s_mute_adts)
#define MUTE_ADTS_DATA_MS 130
PlayerProxy::PlayerProxy(const char *strVhost,
const char *strApp,
const char *strSrc,
PlayerProxy::PlayerProxy(const string &strVhost,
const string &strApp,
const string &strSrc,
bool bEnableHls,
bool bEnableMp4,
int iRetryCount){
@@ -74,10 +74,9 @@ PlayerProxy::PlayerProxy(const char *strVhost,
_bEnableMp4 = bEnableMp4;
_iRetryCount = iRetryCount;
}
void PlayerProxy::play(const char* strUrl) {
void PlayerProxy::play(const string &strUrlTmp) {
weak_ptr<PlayerProxy> weakSelf = shared_from_this();
std::shared_ptr<int> piFailedCnt(new int(0)); //连续播放失败次数
string strUrlTmp(strUrl);
setOnPlayResult([weakSelf,strUrlTmp,piFailedCnt](const SockException &err) {
auto strongSelf = weakSelf.lock();
if(!strongSelf) {
@@ -109,7 +108,7 @@ void PlayerProxy::play(const char* strUrl) {
strongSelf->rePlay(strUrlTmp,(*piFailedCnt)++);
}
});
MediaPlayer::play(strUrl);
MediaPlayer::play(strUrlTmp);
}
PlayerProxy::~PlayerProxy() {
@@ -126,7 +125,7 @@ void PlayerProxy::rePlay(const string &strUrl,int iFailedCnt){
return false;
}
WarnL << "重试播放[" << iFailedCnt << "]:" << strUrl;
strongPlayer->MediaPlayer::play(strUrl.data());
strongPlayer->MediaPlayer::play(strUrl);
return false;
}, nullptr);
}
@@ -170,7 +169,7 @@ private:
};
void PlayerProxy::onPlaySuccess() {
_mediaMuxer.reset(new MultiMediaSourceMuxer(_strVhost.data(),_strApp.data(),_strSrc.data(),getDuration(),_bEnableHls,_bEnableMp4));
_mediaMuxer.reset(new MultiMediaSourceMuxer(_strVhost,_strApp,_strSrc,getDuration(),_bEnableHls,_bEnableMp4));
_mediaMuxer->setListener(shared_from_this());
auto videoTrack = getTrack(TrackVideo,false);

View File

@@ -46,16 +46,16 @@ public:
//如果iRetryCount<0,则一直重试播放否则重试iRetryCount次数
//默认一直重试
PlayerProxy(const char *strVhost,
const char *strApp,
const char *strSrc,
PlayerProxy(const string &strVhost,
const string &strApp,
const string &strSrc,
bool bEnableHls = true,
bool bEnableMp4 = false,
int iRetryCount = -1);
virtual ~PlayerProxy();
void play(const char* strUrl) override;
void play(const string &strUrl) override;
bool close() override;
private:
void rePlay(const string &strUrl,int iFailedCnt);