mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-28 05:29:24 +08:00
基本废弃 AsyncTaskThread的代码
This commit is contained in:
@@ -152,9 +152,10 @@ void MediaReader::startReadMP4() {
|
||||
auto strongSelf = shared_from_this();
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,sampleMS,Record::kSampleMS);
|
||||
|
||||
AsyncTaskThread::Instance().DoTaskDelay(reinterpret_cast<uint64_t>(this), sampleMS, [strongSelf](){
|
||||
_timer = std::make_shared<Timer>(sampleMS / 1000.0f,[strongSelf](){
|
||||
return strongSelf->readSample(0,false);
|
||||
});
|
||||
}, nullptr);
|
||||
|
||||
//先读sampleMS毫秒的数据用于产生MediaSouce
|
||||
readSample(sampleMS, false);
|
||||
_mediaMuxer->setListener(strongSelf);
|
||||
@@ -164,7 +165,7 @@ void MediaReader::startReadMP4() {
|
||||
return true;
|
||||
}
|
||||
bool MediaReader::close(){
|
||||
AsyncTaskThread::Instance().CancelTask(reinterpret_cast<uint64_t>(this));
|
||||
_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -292,7 +293,7 @@ void MediaReader::seek(uint32_t iSeekTime,bool bReStart){
|
||||
_mediaMuxer->setTimeStamp(_iSeekTime);
|
||||
|
||||
if(bReStart){
|
||||
AsyncTaskThread::Instance().CancelTask(reinterpret_cast<uint64_t>(this));
|
||||
_timer.reset();
|
||||
startReadMP4();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ private:
|
||||
Ticker _ticker;
|
||||
Ticker _alive;
|
||||
recursive_mutex _mtx;
|
||||
Timer::Ptr _timer;
|
||||
#endif //ENABLE_MP4V2
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "Util/mini.h"
|
||||
#include "Util/MD5.h"
|
||||
#include "Util/logger.h"
|
||||
#include "Thread/AsyncTaskThread.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
@@ -114,15 +113,13 @@ void PlayerProxy::play(const char* strUrl) {
|
||||
}
|
||||
|
||||
PlayerProxy::~PlayerProxy() {
|
||||
auto iTaskId = reinterpret_cast<uint64_t>(this);
|
||||
AsyncTaskThread::Instance().CancelTask(iTaskId);
|
||||
_timer.reset();
|
||||
}
|
||||
void PlayerProxy::rePlay(const string &strUrl,int iFailedCnt){
|
||||
auto iTaskId = reinterpret_cast<uint64_t>(this);
|
||||
auto iDelay = MAX(2 * 1000, MIN(iFailedCnt * 3000,60*1000));
|
||||
weak_ptr<PlayerProxy> weakSelf = shared_from_this();
|
||||
AsyncTaskThread::Instance().CancelTask(iTaskId);
|
||||
AsyncTaskThread::Instance().DoTaskDelay(iTaskId, iDelay, [weakSelf,strUrl,iFailedCnt]() {
|
||||
_timer = std::make_shared<Timer>(iDelay / 1000.0f,[weakSelf,strUrl,iFailedCnt]() {
|
||||
//播放失败次数越多,则延时越长
|
||||
auto strongPlayer = weakSelf.lock();
|
||||
if(!strongPlayer) {
|
||||
@@ -131,7 +128,7 @@ void PlayerProxy::rePlay(const string &strUrl,int iFailedCnt){
|
||||
WarnL << "重试播放[" << iFailedCnt << "]:" << strUrl;
|
||||
strongPlayer->MediaPlayer::play(strUrl.data());
|
||||
return false;
|
||||
});
|
||||
}, nullptr);
|
||||
}
|
||||
bool PlayerProxy::close() {
|
||||
//通知其停止推流
|
||||
|
||||
@@ -68,6 +68,7 @@ private:
|
||||
string _strVhost;
|
||||
string _strApp;
|
||||
string _strSrc;
|
||||
Timer::Ptr _timer;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
Reference in New Issue
Block a user