Commit 13bbb7b0 by xiongziliang

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

parent 84129aef
...@@ -36,7 +36,6 @@ MediaPlayer::MediaPlayer() { ...@@ -36,7 +36,6 @@ MediaPlayer::MediaPlayer() {
} }
MediaPlayer::~MediaPlayer() { MediaPlayer::~MediaPlayer() {
teardown();
} }
void MediaPlayer::play(const char* strUrl) { void MediaPlayer::play(const char* strUrl) {
string strPrefix = FindField(strUrl, NULL, "://"); string strPrefix = FindField(strUrl, NULL, "://");
......
...@@ -41,14 +41,20 @@ const char PlayerBase::kRtspPwdIsMD5[] = "rtsp_pwd_md5"; ...@@ -41,14 +41,20 @@ const char PlayerBase::kRtspPwdIsMD5[] = "rtsp_pwd_md5";
PlayerBase::Ptr PlayerBase::createPlayer(const char* strUrl) { PlayerBase::Ptr PlayerBase::createPlayer(const char* strUrl) {
static auto releasePlayer = [](PlayerBase *ptr){
onceToken token(nullptr,[&](){
delete ptr;
});
ptr->teardown();
};
string prefix = FindField(strUrl, NULL, "://"); string prefix = FindField(strUrl, NULL, "://");
if (strcasecmp("rtsp",prefix.data()) == 0) { if (strcasecmp("rtsp",prefix.data()) == 0) {
return PlayerBase::Ptr(new RtspPlayerImp()); return PlayerBase::Ptr(new RtspPlayerImp(),releasePlayer);
} }
if (strcasecmp("rtmp",prefix.data()) == 0) { 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////////////////////////////// ///////////////////////////Demuxer//////////////////////////////
......
...@@ -46,7 +46,6 @@ RtmpPlayer::RtmpPlayer() { ...@@ -46,7 +46,6 @@ RtmpPlayer::RtmpPlayer() {
} }
RtmpPlayer::~RtmpPlayer() { RtmpPlayer::~RtmpPlayer() {
teardown();
DebugL << endl; DebugL << endl;
} }
void RtmpPlayer::teardown() { void RtmpPlayer::teardown() {
......
...@@ -45,7 +45,6 @@ public: ...@@ -45,7 +45,6 @@ public:
RtmpPlayerImp(){}; RtmpPlayerImp(){};
virtual ~RtmpPlayerImp(){ virtual ~RtmpPlayerImp(){
DebugL<<endl; DebugL<<endl;
teardown();
}; };
float getProgress() const override{ float getProgress() const override{
if(getDuration() > 0){ if(getDuration() > 0){
......
...@@ -55,7 +55,6 @@ RtspPlayer::RtspPlayer(void){ ...@@ -55,7 +55,6 @@ RtspPlayer::RtspPlayer(void){
_pktPool.setSize(64); _pktPool.setSize(64);
} }
RtspPlayer::~RtspPlayer(void) { RtspPlayer::~RtspPlayer(void) {
RtspPlayer::teardown();
DebugL<<endl; DebugL<<endl;
} }
void RtspPlayer::teardown(){ void RtspPlayer::teardown(){
......
...@@ -47,7 +47,6 @@ public: ...@@ -47,7 +47,6 @@ public:
RtspPlayerImp(){}; RtspPlayerImp(){};
virtual ~RtspPlayerImp(){ virtual ~RtspPlayerImp(){
DebugL<<endl; DebugL<<endl;
teardown();
}; };
float getProgress() const override{ float getProgress() const override{
if(getDuration() > 0){ if(getDuration() > 0){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论