修复播放器析构时调用虚函数的bug

This commit is contained in:
xiongziliang 2018-11-19 11:49:17 +08:00
parent 84129aefdf
commit 13bbb7b057
6 changed files with 9 additions and 8 deletions

View File

@ -36,7 +36,6 @@ MediaPlayer::MediaPlayer() {
}
MediaPlayer::~MediaPlayer() {
teardown();
}
void MediaPlayer::play(const char* strUrl) {
string strPrefix = FindField(strUrl, NULL, "://");

View File

@ -41,14 +41,20 @@ const char PlayerBase::kRtspPwdIsMD5[] = "rtsp_pwd_md5";
PlayerBase::Ptr PlayerBase::createPlayer(const char* strUrl) {
static auto releasePlayer = [](PlayerBase *ptr){
onceToken token(nullptr,[&](){
delete ptr;
});
ptr->teardown();
};
string prefix = FindField(strUrl, NULL, "://");
if (strcasecmp("rtsp",prefix.data()) == 0) {
return PlayerBase::Ptr(new RtspPlayerImp());
return PlayerBase::Ptr(new RtspPlayerImp(),releasePlayer);
}
if (strcasecmp("rtmp",prefix.data()) == 0) {
return PlayerBase::Ptr(new RtmpPlayerImp());
return PlayerBase::Ptr(new RtmpPlayerImp(),releasePlayer);
}
return PlayerBase::Ptr(new RtspPlayerImp());
return PlayerBase::Ptr(new RtspPlayerImp(),releasePlayer);
}
///////////////////////////Demuxer//////////////////////////////

View File

@ -46,7 +46,6 @@ RtmpPlayer::RtmpPlayer() {
}
RtmpPlayer::~RtmpPlayer() {
teardown();
DebugL << endl;
}
void RtmpPlayer::teardown() {

View File

@ -45,7 +45,6 @@ public:
RtmpPlayerImp(){};
virtual ~RtmpPlayerImp(){
DebugL<<endl;
teardown();
};
float getProgress() const override{
if(getDuration() > 0){

View File

@ -55,7 +55,6 @@ RtspPlayer::RtspPlayer(void){
_pktPool.setSize(64);
}
RtspPlayer::~RtspPlayer(void) {
RtspPlayer::teardown();
DebugL<<endl;
}
void RtspPlayer::teardown(){

View File

@ -47,7 +47,6 @@ public:
RtspPlayerImp(){};
virtual ~RtspPlayerImp(){
DebugL<<endl;
teardown();
};
float getProgress() const override{
if(getDuration() > 0){