diff --git a/framework/data_source/curl/CURLConnection.cpp b/framework/data_source/curl/CURLConnection.cpp index b28bb03fc..55f7f8d4e 100644 --- a/framework/data_source/curl/CURLConnection.cpp +++ b/framework/data_source/curl/CURLConnection.cpp @@ -705,3 +705,9 @@ int CURLConnection::readBuffer(void *buf, size_t size) return 0; } + +void CURLConnection::updateSource(const string &location) +{ + curl_easy_setopt(mHttp_handle, CURLOPT_URL, location.c_str()); + mFileSize = -1; +} diff --git a/framework/data_source/curl/CURLConnection.h b/framework/data_source/curl/CURLConnection.h index 7f9e2a209..037a994b9 100644 --- a/framework/data_source/curl/CURLConnection.h +++ b/framework/data_source/curl/CURLConnection.h @@ -22,6 +22,8 @@ namespace Cicada { void setSource(const std::string &location, struct curl_slist *headerList); + void updateSource(const std::string &location); + void setInterrupt(std::atomic_bool *inter); void SetResume(int64_t pos); diff --git a/framework/data_source/curl/curl_data_source.cpp b/framework/data_source/curl/curl_data_source.cpp index 08fe18758..be7145fe5 100644 --- a/framework/data_source/curl/curl_data_source.cpp +++ b/framework/data_source/curl/curl_data_source.cpp @@ -78,7 +78,7 @@ int CurlDataSource::curl_connect(CURLConnection *pConnection, int64_t filePos) if (length > 0.0) { mFileSize = pConnection->tell() + (int64_t) length; - // AF_LOGE(TAG,"file size is %lld\n",curlContext.fileSize); + //AF_LOGE("file size is %lld\n",mFileSize); } // if (curlContext.fileSize == 0) @@ -215,7 +215,7 @@ int CurlDataSource::Open(const string &url) bool isRTMP = url.compare(0, 7, "rtmp://") == 0; mLocation = (isRTMP ? (url + " live=1").c_str() : url.c_str()); // only change url, don,t change share and resolve - curl_easy_setopt(mPConnection->getCurlHandle(), CURLOPT_URL, mLocation.c_str()); + mPConnection->updateSource(mLocation); int ret = curl_connect(mPConnection, rangeStart != INT64_MIN ? rangeStart : 0); mOpenTimeMS = af_gettime_relative() / 1000 - mOpenTimeMS; @@ -376,13 +376,12 @@ int CurlDataSource::Read(void *buf, size_t size) } /* only request 1 byte, for truncated reads (only if not eof) */ - if ((mFileSize <= 0 || mPConnection->tell() < mFileSize) && - (ret = mPConnection->FillBuffer(1)) < 0) { + if (mFileSize <= 0 || mPConnection->tell() < mFileSize) { + ret = mPConnection->FillBuffer(1); + if (ret < 0) { return ret; } - - return 0; } return mPConnection->readBuffer(buf, size);