MCPcopy Create free account
hub / github.com/alibaba/CicadaPlayer / start

Method start

framework/cacheModule/CacheModule.cpp:103–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103CacheRet CacheModule::start()
104{
105 {
106 unique_lock<mutex> lock(mStatusMutex);
107
108 if (mStatus == Status::Stopped) {
109 AF_LOGE("---> start() , mStatus == Status::Stopped return ");
110 return CACHE_ERROR_STATUS;
111 }
112 }
113 AF_LOGD("---> start()");
114 const CacheRet &canCheck = checkCanCache();
115
116 if (canCheck.mCode != CACHE_SUCCESS.mCode) {
117 AF_LOGE("---> start() , checkCanCache fail.. return ");
118 return canCheck;
119 }
120
121 {
122 std::unique_lock<mutex> remuxerLock(mReumxerMutex);
123
124 if (mCacheFileRemuxer != nullptr) {
125 mCacheFileRemuxer->interrupt();
126 mCacheFileRemuxer->stop();
127 delete mCacheFileRemuxer;
128 mCacheFileRemuxer = nullptr;
129 }
130
131 string cacheTmpPath = mCachePath.getCachePath() + TMP_SUFFIX;
132 mCacheFileRemuxer = new CacheFileRemuxer(cacheTmpPath, mDescription);
133 mCacheFileRemuxer->setStreamMeta(&mStreamMetas);
134 mCacheFileRemuxer->setErrorCallback([this](int code, string msg) -> void {
135 if (mErrorCallback != nullptr) {
136 mErrorCallback(code, msg);
137 }
138 });
139 mCacheFileRemuxer->setResultCallback([this](bool success) -> void {
140 const string &cachePath = mCachePath.getCachePath();
141 string cacheTmpFilePath = cachePath + TMP_SUFFIX;
142 if (success) {
143 bool ret = FileUtils::Rename(cacheTmpFilePath.c_str(), cachePath.c_str());
144
145 if (ret) {
146 mCacheRet = CacheStatus::success;
147 } else {
148 FileUtils::rmrf(cacheTmpFilePath.c_str());
149 mCacheRet = CacheStatus::fail;
150 }
151 } else {
152 // not completion , need delete cached file
153 FileUtils::rmrf(cacheTmpFilePath.c_str());
154 mCacheRet = CacheStatus::fail;
155 }
156
157 if (mResultCallback != nullptr) {
158 mResultCallback(success);
159 }
160 });

Callers

nothing calls this directly

Calls 8

stopMethod · 0.65
prepareMethod · 0.65
startMethod · 0.65
interruptMethod · 0.45
getCachePathMethod · 0.45
setStreamMetaMethod · 0.45
setErrorCallbackMethod · 0.45
setResultCallbackMethod · 0.45

Tested by

no test coverage detected