Skip to content

Commit

Permalink
fix(data_source): update CURLConnection file size
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Feb 28, 2020
1 parent 244ccae commit 747646e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions framework/data_source/curl/CURLConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions framework/data_source/curl/CURLConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions framework/data_source/curl/curl_data_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 747646e

Please sign in to comment.