mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-11-30 10:32:24 +00:00
Revert "player自暂停"
This reverts commit196e42143e
. Revert "增加Pause和Resume接口" This reverts commit539db381c9
. Revert "Buffering_Start后Read增加1秒校验,减少error_again次数" This reverts commit7cb945979e
. Signed-off-by: dcss <yangzhenjun2@huawei.com>
This commit is contained in:
parent
437b93a2f3
commit
b4cba9cb8e
@ -98,8 +98,7 @@ public:
|
||||
Status DisableMediaTrack(Plugins::MediaType mediaType);
|
||||
void RegisterVideoStreamReadyCallback(const std::shared_ptr<VideoStreamReadyCallback> &callback);
|
||||
void DeregisterVideoStreamReadyCallback();
|
||||
Status ResumeDemuxerReadLoop();
|
||||
Status PauseDemuxerReadLoop();
|
||||
|
||||
protected:
|
||||
Status OnLinked(StreamType inType, const std::shared_ptr<Meta> &meta,
|
||||
const std::shared_ptr<FilterLinkCallback> &callback) override;
|
||||
|
@ -118,8 +118,6 @@ public:
|
||||
|
||||
Status GetFrameIndexByPresentationTimeUs(uint32_t trackIndex, int64_t presentationTimeUs, uint32_t &frameIndex);
|
||||
Status GetPresentationTimeUsByFrameIndex(uint32_t trackIndex, uint32_t frameIndex, int64_t &presentationTimeUs);
|
||||
Status ResumeDemuxerReadLoop();
|
||||
Status PauseDemuxerReadLoop();
|
||||
void SetCacheLimit(uint32_t limitSize);
|
||||
private:
|
||||
class AVBufferQueueProducerListener;
|
||||
@ -261,7 +259,6 @@ private:
|
||||
std::atomic<bool> shouldCheckSubtitleFramePts_ = false;
|
||||
int64_t lastSubtitlePts_ = 0;
|
||||
std::shared_ptr<VideoStreamReadyCallback> VideoStreamReadyCallback_ = nullptr;
|
||||
std::atomic<bool> isDemuxerLoopExecuting_ {false};
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -728,22 +728,6 @@ bool DemuxerFilter::IsRenderNextVideoFrameSupported()
|
||||
return demuxer_->IsRenderNextVideoFrameSupported();
|
||||
}
|
||||
|
||||
Status DemuxerFilter::ResumeDemuxerReadLoop()
|
||||
{
|
||||
MediaAVCodec::AVCodecTrace trace("DemuxerFilter::ResumeDemuxerReadLoop");
|
||||
FALSE_RETURN_V_MSG_E(demuxer_ != nullptr, Status::ERROR_INVALID_OPERATION, "ResumeDemuxerReadLoop failed.");
|
||||
MEDIA_LOG_I("ResumeDemuxerReadLoop start.");
|
||||
return demuxer_->ResumeDemuxerReadLoop();
|
||||
}
|
||||
|
||||
Status DemuxerFilter::PauseDemuxerReadLoop()
|
||||
{
|
||||
MediaAVCodec::AVCodecTrace trace("DemuxerFilter::PauseDemuxerReadLoop");
|
||||
FALSE_RETURN_V_MSG_E(demuxer_ != nullptr, Status::ERROR_INVALID_OPERATION, "PauseDemuxerReadLoop failed.");
|
||||
MEDIA_LOG_I("PauseDemuxerReadLoop start.");
|
||||
return demuxer_->PauseDemuxerReadLoop();
|
||||
}
|
||||
|
||||
bool DemuxerFilter::IsVideoEos()
|
||||
{
|
||||
FALSE_RETURN_V_MSG_E(demuxer_ != nullptr, false, "demuxer_ is nullptr");
|
||||
|
@ -1144,7 +1144,6 @@ Status MediaDemuxer::Flush()
|
||||
Status MediaDemuxer::StopAllTask()
|
||||
{
|
||||
MEDIA_LOG_I("StopAllTask enter.");
|
||||
isDemuxerLoopExecuting_ = false;
|
||||
if (streamDemuxer_ != nullptr) {
|
||||
streamDemuxer_->SetIsIgnoreParse(true);
|
||||
}
|
||||
@ -1168,7 +1167,6 @@ Status MediaDemuxer::StopAllTask()
|
||||
Status MediaDemuxer::PauseAllTask()
|
||||
{
|
||||
MEDIA_LOG_I("PauseAllTask enter.");
|
||||
isDemuxerLoopExecuting_ = false;
|
||||
// To accelerate DemuxerLoop thread to run into PAUSED state
|
||||
for (auto &iter : taskMap_) {
|
||||
if (iter.second != nullptr) {
|
||||
@ -1188,7 +1186,6 @@ Status MediaDemuxer::PauseAllTask()
|
||||
Status MediaDemuxer::ResumeAllTask()
|
||||
{
|
||||
MEDIA_LOG_I("ResumeAllTask enter.");
|
||||
isDemuxerLoopExecuting_ = true;
|
||||
streamDemuxer_->SetIsIgnoreParse(false);
|
||||
|
||||
auto it = bufferQueueMap_.begin();
|
||||
@ -1330,7 +1327,6 @@ Status MediaDemuxer::Reset()
|
||||
{
|
||||
MediaAVCodec::AVCodecTrace trace("MediaDemuxer::Reset");
|
||||
FALSE_RETURN_V_MSG_E(useBufferQueue_, Status::ERROR_WRONG_STATE, "Cannot reset track when not use buffer queue.");
|
||||
isDemuxerLoopExecuting_ = false;
|
||||
ResetInner();
|
||||
for (auto item : eosMap_) {
|
||||
eosMap_[item.first] = false;
|
||||
@ -1360,7 +1356,6 @@ Status MediaDemuxer::Start()
|
||||
}
|
||||
isThreadExit_ = false;
|
||||
isStopped_ = false;
|
||||
isDemuxerLoopExecuting_ = true;
|
||||
if (!doPrepareFrame_) {
|
||||
auto it = bufferQueueMap_.begin();
|
||||
while (it != bufferQueueMap_.end()) {
|
||||
@ -2106,28 +2101,6 @@ Status MediaDemuxer::GetPresentationTimeUsByFrameIndex(uint32_t trackIndex,
|
||||
return ret;
|
||||
}
|
||||
|
||||
Status MediaDemuxer::ResumeDemuxerReadLoop()
|
||||
{
|
||||
MEDIA_LOG_I("ResumeDemuxerReadLoop in.");
|
||||
if (isDemuxerLoopExecuting_) {
|
||||
MEDIA_LOG_I("Has already resumed");
|
||||
return Status::OK;
|
||||
}
|
||||
isDemuxerLoopExecuting_ = true;
|
||||
return ResumeAllTask();
|
||||
}
|
||||
|
||||
Status MediaDemuxer::PauseDemuxerReadLoop()
|
||||
{
|
||||
MEDIA_LOG_I("PauseDemuxerReadLoop in.");
|
||||
if (isDemuxerLoopExecuting_) {
|
||||
MEDIA_LOG_I("Has already pause");
|
||||
return Status::OK;
|
||||
}
|
||||
isDemuxerLoopExecuting_ = false;
|
||||
return PauseAllTask();
|
||||
}
|
||||
|
||||
void MediaDemuxer::SetCacheLimit(uint32_t limitSize)
|
||||
{
|
||||
MEDIA_LOG_D("SetCacheLimit");
|
||||
|
@ -55,8 +55,6 @@ constexpr int SECOND_TO_MILLIONSECOND = 1000;
|
||||
constexpr int UPDATE_CACHE_STEP = 5 * 1024;
|
||||
constexpr int SEEK_STATUS_RETRY_TIMES = 100;
|
||||
constexpr int SEEK_STATUS_SLEEP_TIME = 50;
|
||||
constexpr int32_t ONE_SECONDS = 1000;
|
||||
constexpr int32_t TEN_MILLISECONDS = 10;
|
||||
}
|
||||
|
||||
// hls manifest, m3u8 --- content get from m3u8 url, we get play list from the content
|
||||
@ -302,17 +300,44 @@ bool HlsMediaDownloader::HandleBuffering()
|
||||
if (!isBuffering_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_PERCENT);
|
||||
if (buffer_->GetSize() >= waterLineAbove_ || CheckBreakCondition()) {
|
||||
isBuffering_ = false;
|
||||
MEDIA_LOG_I("HandleBuffering begin.");
|
||||
int32_t sleepTime = 0;
|
||||
isBufferEnough_ = false;
|
||||
bool isDownloadComplete = false;
|
||||
while (!isInterrupt_) {
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_PERCENT);
|
||||
if (buffer_->GetSize() >= waterLineAbove_) {
|
||||
isBufferEnough_ = true;
|
||||
isBuffering_ = false;
|
||||
break;
|
||||
}
|
||||
if (CheckBreakCondition()) {
|
||||
isBuffering_ = false;
|
||||
isDownloadComplete = true;
|
||||
break;
|
||||
}
|
||||
OSAL::SleepFor(SLEEP_TIME::BUFFERING_SLEEP_TIME);
|
||||
sleepTime += SLEEP_TIME::BUFFERING_SLEEP_TIME;
|
||||
if (sleepTime > SLEEP_TIME::BUFFERING_TIME_OUT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isBuffering_ && isFirstFrameArrived_) {
|
||||
if (!isBufferEnough_) {
|
||||
if (isDownloadComplete) {
|
||||
MEDIA_LOG_I("CacheData onEvent BUFFERING_END");
|
||||
callback_->OnEvent({PluginEventType::BUFFERING_END, {BufferingInfoType::BUFFERING_END}, "end"});
|
||||
}
|
||||
return isBuffering_;
|
||||
}
|
||||
if (!isReadFrame_) {
|
||||
isReadFrame_ = true;
|
||||
MEDIA_LOG_I("Playing start");
|
||||
} else {
|
||||
MEDIA_LOG_I("CacheData onEvent BUFFERING_END");
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_END);
|
||||
callback_->OnEvent({PluginEventType::BUFFERING_END, {BufferingInfoType::BUFFERING_END}, "end"});
|
||||
}
|
||||
MEDIA_LOG_I("HandleBuffering end.");
|
||||
return isBuffering_;
|
||||
}
|
||||
|
||||
@ -358,7 +383,7 @@ Status HlsMediaDownloader::ReadDelegate(unsigned char* buff, ReadDataInfo& readD
|
||||
return Status::END_OF_STREAM;
|
||||
}
|
||||
|
||||
if (isBuffering_ && CheckBufferingOneSeconds()) {
|
||||
if (HandleBuffering()) {
|
||||
MEDIA_LOG_I("Read return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
@ -535,17 +560,15 @@ bool HlsMediaDownloader::SaveData(uint8_t* data, uint32_t len)
|
||||
OnWriteRingBuffer(len);
|
||||
}
|
||||
startedPlayStatus_ = true;
|
||||
bool ret = false;
|
||||
if (keyLen_ == 0) {
|
||||
ret = buffer_->WriteBuffer(data, len);
|
||||
bool res = buffer_->WriteBuffer(data, len);
|
||||
HandleCachedDuration();
|
||||
return res;
|
||||
} else {
|
||||
ret = SaveEncryptData(data, len);
|
||||
bool res = SaveEncryptData(data, len);
|
||||
HandleCachedDuration();
|
||||
return res;
|
||||
}
|
||||
MEDIA_LOG_D("SaveData ret: " PUBLIC_LOG_D32 ", bufferSize: " PUBLIC_LOG_ZU ", len: " PUBLIC_LOG_U32,
|
||||
ret, buffer_->GetSize(), len);
|
||||
HandleCachedDuration();
|
||||
HandleBuffering();
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t HlsMediaDownloader::GetDecrptyRealLen(uint8_t* writeDataPoint, uint32_t waitLen, uint32_t writeLen)
|
||||
@ -850,7 +873,6 @@ void HlsMediaDownloader::UpdateDownloadFinished(const std::string &url, const st
|
||||
auto downloadTime = (nowTime - startDownloadTime_) / 1000;
|
||||
MEDIA_LOG_D("Download done, data usage: " PUBLIC_LOG_U64 " bits in " PUBLIC_LOG_D64 "ms",
|
||||
totalBits_, downloadTime * 1000);
|
||||
HandleBuffering();
|
||||
}
|
||||
|
||||
// bitrate above 0, user is not selecting, auto seliect is not going, playlist is done, is not seeking
|
||||
@ -883,10 +905,6 @@ void HlsMediaDownloader::SetDownloadErrorState()
|
||||
{
|
||||
MEDIA_LOG_I("SetDownloadErrorState");
|
||||
downloadErrorState_ = true;
|
||||
if (callback_ != nullptr) {
|
||||
MEDIA_LOG_I("Read time out, OnEvent");
|
||||
callback_->OnEvent({PluginEventType::CLIENT_ERROR, {NetworkClientErrorCode::ERROR_TIME_OUT}, "read"});
|
||||
}
|
||||
}
|
||||
|
||||
void HlsMediaDownloader::AutoSelectBitrate(uint32_t bitRate)
|
||||
@ -1183,22 +1201,6 @@ void HlsMediaDownloader::UpdateCachedPercent(BufferingInfoType infoType)
|
||||
lastCachedSize_ = bufferSize;
|
||||
}
|
||||
}
|
||||
|
||||
bool HlsMediaDownloader::CheckBufferingOneSeconds()
|
||||
{
|
||||
MEDIA_LOG_I("CheckBufferingOneSeconds in");
|
||||
int32_t sleepTime = 0;
|
||||
// return error again 1 time 1s, avoid ffmpeg error
|
||||
while (sleepTime < ONE_SECONDS && !isInterruptNeeded_.load()) {
|
||||
if (!isBuffering_) {
|
||||
break;
|
||||
}
|
||||
OSAL::SleepFor(TEN_MILLISECONDS);
|
||||
sleepTime += TEN_MILLISECONDS;
|
||||
}
|
||||
MEDIA_LOG_I("CheckBufferingOneSeconds out");
|
||||
return isBuffering_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,6 @@ private:
|
||||
void CaculateBitRate(size_t fragmentSize, double duration);
|
||||
double CalculateCurrentDownloadSpeed();
|
||||
void UpdateCachedPercent(BufferingInfoType infoType);
|
||||
bool CheckBufferingOneSeconds();
|
||||
|
||||
private:
|
||||
std::shared_ptr<RingBuffer> buffer_;
|
||||
@ -223,6 +222,7 @@ private:
|
||||
bool isInterrupt_ {false};
|
||||
bool isBuffering_ {false};
|
||||
bool isFirstFrameArrived_ {false};
|
||||
bool isBufferEnough_ {true};
|
||||
std::atomic<bool> isSeekingFlag {false};
|
||||
Mutex switchMutex_ {};
|
||||
bool isLastDecryptWriteError_ {false};
|
||||
|
@ -41,6 +41,9 @@ constexpr int AVG_SPEED_SUM_SCALE = 10000;
|
||||
constexpr double ZERO_THRESHOLD = 1e-9;
|
||||
constexpr size_t PLAY_WATER_LINE = 5 * 1024;
|
||||
constexpr size_t DEFAULT_WATER_LINE_ABOVE = 48 * 10 * 1024;
|
||||
constexpr int BUFFERING_TIME_OUT = 1000;
|
||||
constexpr int BUFFERING_SLEEP_TIME = 10;
|
||||
constexpr int REQUEST_SLEEP_TIME = 5;
|
||||
constexpr int64_t SECOND_TO_MILLIONSECOND = 1000;
|
||||
constexpr int FIVE_MICROSECOND = 5;
|
||||
constexpr int ONE_HUNDRED_MILLIONSECOND = 100;
|
||||
@ -53,8 +56,6 @@ constexpr int32_t DEFAULT_BIT_RATE = 1638400;
|
||||
constexpr int UPDATE_CACHE_STEP = 5 * 1024;
|
||||
constexpr int32_t SAVE_DATA_LOG_FEQUENCE = 10;
|
||||
constexpr size_t MIN_WATER_LINE_ABOVE = 10 * 1024;
|
||||
constexpr int32_t ONE_SECONDS = 1000;
|
||||
constexpr int32_t TEN_MILLISECONDS = 10;
|
||||
}
|
||||
|
||||
HttpMediaDownloader::HttpMediaDownloader(std::string url)
|
||||
@ -171,7 +172,6 @@ bool HttpMediaDownloader::Open(const std::string& url, const std::map<std::strin
|
||||
static_cast<int32_t>(avgDownloadSpeed_));
|
||||
MEDIA_LOG_I("Download done, data usage: " PUBLIC_LOG_U64 " bits in " PUBLIC_LOG_D64 "ms",
|
||||
totalBits_, static_cast<int64_t>(downloadTime * SECOND_TO_MILLIONSECOND));
|
||||
HandleBuffering();
|
||||
};
|
||||
MediaSouce mediaSouce;
|
||||
mediaSouce.url = url;
|
||||
@ -242,34 +242,50 @@ bool HttpMediaDownloader::HandleBuffering()
|
||||
if (!isBuffering_ || downloadRequest_->IsChunkedVod()) {
|
||||
return false;
|
||||
}
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_PERCENT);
|
||||
MEDIA_LOG_I("HandleBuffering begin.");
|
||||
int32_t sleepTime = 0;
|
||||
isBufferEnough_ = false;
|
||||
size_t fileRemain = 0;
|
||||
size_t fileContenLen = downloadRequest_->GetFileContentLength();
|
||||
if (fileContenLen > readOffset_) {
|
||||
fileRemain = fileContenLen - readOffset_;
|
||||
waterLineAbove_ = std::min(fileRemain, waterLineAbove_);
|
||||
}
|
||||
while (!isInterruptNeeded_ && canWrite_) {
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_PERCENT);
|
||||
if (GetCurrentBufferSize() >= waterLineAbove_) {
|
||||
isBufferEnough_ = true;
|
||||
isBuffering_ = false;
|
||||
MEDIA_LOG_D("BufferEnough");
|
||||
break;
|
||||
}
|
||||
if (downloadRequest_ == nullptr) {
|
||||
OSAL::SleepFor(REQUEST_SLEEP_TIME);
|
||||
continue;
|
||||
}
|
||||
if (HandleBreak(sleepTime)) {
|
||||
MEDIA_LOG_D("HandleBreak");
|
||||
isErrorBreak_ = true;
|
||||
break;
|
||||
}
|
||||
OSAL::SleepFor(BUFFERING_SLEEP_TIME);
|
||||
}
|
||||
if (!canWrite_) {
|
||||
MEDIA_LOG_I("canWrite_ false");
|
||||
isBuffering_ = false;
|
||||
}
|
||||
if (GetCurrentBufferSize() >= waterLineAbove_) {
|
||||
MEDIA_LOG_I("Buffer is not enough");
|
||||
isBuffering_ = false;
|
||||
if (!isBufferEnough_) {
|
||||
MEDIA_LOG_D("Buffer is not enough.");
|
||||
return isBuffering_;
|
||||
}
|
||||
if (HandleBreak()) {
|
||||
MEDIA_LOG_I("HandleBreak");
|
||||
isBuffering_ = false;
|
||||
}
|
||||
|
||||
if (!isBuffering_ && isFirstFrameArrived_) {
|
||||
if (!isReadFrame_) {
|
||||
isReadFrame_ = true;
|
||||
MEDIA_LOG_I("Playing start");
|
||||
} else {
|
||||
MEDIA_LOG_I("CacheData onEvent BUFFERING_END");
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_END);
|
||||
callback_->OnEvent({PluginEventType::BUFFERING_END, {BufferingInfoType::BUFFERING_END}, "end"});
|
||||
}
|
||||
MEDIA_LOG_D("HandleBuffering bufferSize: " PUBLIC_LOG_ZU ", waterLineAbove_: " PUBLIC_LOG_ZU
|
||||
", isBuffering: " PUBLIC_LOG_D32 ", canWrite: " PUBLIC_LOG_D32,
|
||||
GetCurrentBufferSize(), waterLineAbove_, isBuffering_, canWrite_.load());
|
||||
MEDIA_LOG_I("HandleBuffering end.");
|
||||
return isBuffering_;
|
||||
}
|
||||
|
||||
@ -292,7 +308,7 @@ bool HttpMediaDownloader::StartBuffering()
|
||||
if (downloadRequest_ != nullptr) {
|
||||
isEos = downloadRequest_->IsEos();
|
||||
}
|
||||
if (isFirstFrameArrived_ && GetCurrentBufferSize() < cacheWaterLine && !isEos && !HandleBreak()) {
|
||||
if (isFirstFrameArrived_ && GetCurrentBufferSize() < cacheWaterLine && !isEos && !isErrorBreak_) {
|
||||
waterLineAbove_ = std::max(MIN_WATER_LINE_ABOVE, static_cast<size_t>(GetWaterLineAbove()));
|
||||
waterLineAbove_ = std::min(waterLineAbove_, fileRemain);
|
||||
|
||||
@ -413,9 +429,11 @@ Status HttpMediaDownloader::ReadDelegate(unsigned char* buff, ReadDataInfo& read
|
||||
FALSE_RETURN_V_MSG(buffer_ != nullptr, Status::END_OF_STREAM, "buffer_ = nullptr");
|
||||
FALSE_RETURN_V_MSG(!isInterruptNeeded_.load(), Status::END_OF_STREAM, "isInterruptNeeded");
|
||||
FALSE_RETURN_V_MSG(readDataInfo.wantReadLength_ > 0, Status::END_OF_STREAM, "wantReadLength_ <= 0");
|
||||
if (isBuffering_ && !downloadRequest_->IsChunkedVod() && CheckBufferingOneSeconds()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
if (isBuffering_) {
|
||||
if (HandleBuffering()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
}
|
||||
if (StartBuffering()) {
|
||||
return Status::ERROR_AGAIN;
|
||||
@ -425,13 +443,16 @@ Status HttpMediaDownloader::ReadDelegate(unsigned char* buff, ReadDataInfo& read
|
||||
FALSE_RETURN_V_MSG(cacheMediaBuffer_ != nullptr, Status::END_OF_STREAM, "cacheMediaBuffer_ = nullptr");
|
||||
FALSE_RETURN_V_MSG(!isInterruptNeeded_.load(), Status::END_OF_STREAM, "isInterruptNeeded");
|
||||
FALSE_RETURN_V_MSG(readDataInfo.wantReadLength_ > 0, Status::END_OF_STREAM, "wantReadLength_ <= 0");
|
||||
if (isBuffering_ && !downloadRequest_->IsChunkedVod() && canWrite_ && CheckBufferingOneSeconds()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
if (isBuffering_ && canWrite_) {
|
||||
if (HandleBuffering()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
}
|
||||
if (StartBuffering()) {
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
isErrorBreak_ = false;
|
||||
return ReadCacheBuffer(buff, readDataInfo);
|
||||
}
|
||||
}
|
||||
@ -676,18 +697,9 @@ bool HttpMediaDownloader::SaveRingBufferData(uint8_t* data, uint32_t len)
|
||||
|
||||
bool HttpMediaDownloader::SaveData(uint8_t* data, uint32_t len)
|
||||
{
|
||||
bool ret = true;
|
||||
if (isFlv_) {
|
||||
ret = SaveRingBufferData(data, len);
|
||||
} else {
|
||||
ret = SaveCacheBufferData(data, len);
|
||||
return SaveRingBufferData(data, len);
|
||||
}
|
||||
HandleBuffering();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool HttpMediaDownloader::SaveCacheBufferData(uint8_t* data, uint32_t len)
|
||||
{
|
||||
if (isNeedClean_) {
|
||||
return true;
|
||||
}
|
||||
@ -710,7 +722,6 @@ bool HttpMediaDownloader::SaveCacheBufferData(uint8_t* data, uint32_t len)
|
||||
}
|
||||
MEDIA_LOG_W("CacheMediaBuffer write fail.");
|
||||
canWrite_ = false;
|
||||
HandleBuffering();
|
||||
while (!isInterrupt_ && !isNeedClean_ && !canWrite_ && !isInterruptNeeded_.load()) {
|
||||
MEDIA_LOGI_LIMIT(SAVE_DATA_LOG_FEQUENCE, "CacheMediaBuffer can not write, drop data.");
|
||||
if (isHitSeeking_ || isNeedDropData_) {
|
||||
@ -806,7 +817,6 @@ void HttpMediaDownloader::SetDownloadErrorState()
|
||||
Close(true);
|
||||
}
|
||||
}
|
||||
OnClientErrorEvent();
|
||||
}
|
||||
|
||||
void HttpMediaDownloader::SetInterruptState(bool isInterruptNeeded)
|
||||
@ -855,7 +865,7 @@ void HttpMediaDownloader::GetDownloadInfo(DownloadInfo& downloadInfo)
|
||||
downloadInfo.isTimeOut = isTimeOut_;
|
||||
}
|
||||
|
||||
bool HttpMediaDownloader::HandleBreak()
|
||||
bool HttpMediaDownloader::HandleBreak(int32_t& sleepTime)
|
||||
{
|
||||
bool isEos = false;
|
||||
if (downloadRequest_ != nullptr) {
|
||||
@ -863,10 +873,12 @@ bool HttpMediaDownloader::HandleBreak()
|
||||
}
|
||||
if (isEos && GetCurrentBufferSize() == 0) {
|
||||
MEDIA_LOG_I("CacheData over, isEos: " PUBLIC_LOG_D32, isEos);
|
||||
isBuffering_ = false;
|
||||
return true;
|
||||
}
|
||||
if (downloadErrorState_) {
|
||||
MEDIA_LOG_I("downloadErrorState_ break");
|
||||
isBuffering_ = false;
|
||||
return true;
|
||||
}
|
||||
bool isClosed = false;
|
||||
@ -875,6 +887,12 @@ bool HttpMediaDownloader::HandleBreak()
|
||||
}
|
||||
if (isClosed && GetCurrentBufferSize() == 0) {
|
||||
MEDIA_LOG_I("isClosed break");
|
||||
isBuffering_ = false;
|
||||
return true;
|
||||
}
|
||||
sleepTime += BUFFERING_SLEEP_TIME;
|
||||
if (sleepTime > BUFFERING_TIME_OUT) {
|
||||
MEDIA_LOG_D("BUFFERING_TIME_OUT");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -965,23 +983,7 @@ void HttpMediaDownloader::UpdateCachedPercent(BufferingInfoType infoType)
|
||||
lastCachedSize_ = bufferSize;
|
||||
}
|
||||
}
|
||||
|
||||
bool HttpMediaDownloader::CheckBufferingOneSeconds()
|
||||
{
|
||||
MEDIA_LOG_I("CheckBufferingOneSeconds in");
|
||||
int32_t sleepTime = 0;
|
||||
// return error again 1 time 1s, avoid ffmpeg error
|
||||
while (sleepTime < ONE_SECONDS && !isInterruptNeeded_.load()) {
|
||||
if (!isBuffering_) {
|
||||
break;
|
||||
}
|
||||
OSAL::SleepFor(TEN_MILLISECONDS);
|
||||
sleepTime += TEN_MILLISECONDS;
|
||||
}
|
||||
MEDIA_LOG_I("CheckBufferingOneSeconds out");
|
||||
return isBuffering_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -65,9 +65,8 @@ public:
|
||||
void UpdateCachedPercent(BufferingInfoType infoType);
|
||||
private:
|
||||
bool SaveData(uint8_t* data, uint32_t len);
|
||||
bool SaveCacheBufferData(uint8_t* data, uint32_t len);
|
||||
Status ReadDelegate(unsigned char* buff, ReadDataInfo& readDataInfo);
|
||||
bool SaveRingBufferData(uint8_t* data, uint32_t len);
|
||||
Status ReadDelegate(unsigned char* buff, ReadDataInfo& readDataInfo);
|
||||
void OnClientErrorEvent();
|
||||
Status CheckIsEosRingBuffer(unsigned char* buff, ReadDataInfo& readDataInfo);
|
||||
Status CheckIsEosCacheBuffer(unsigned char* buff, ReadDataInfo& readDataInfo);
|
||||
@ -83,12 +82,11 @@ private:
|
||||
bool HandleBuffering();
|
||||
bool StartBuffering();
|
||||
size_t GetCurrentBufferSize();
|
||||
bool HandleBreak();
|
||||
bool HandleBreak(int32_t& sleepTime);
|
||||
void ChangeDownloadPos();
|
||||
int32_t GetWaterLineAbove();
|
||||
void HandleCachedDuration();
|
||||
double CalculateCurrentDownloadSpeed();
|
||||
bool CheckBufferingOneSeconds();
|
||||
|
||||
private:
|
||||
std::shared_ptr<RingBuffer> buffer_;
|
||||
@ -102,6 +100,7 @@ private:
|
||||
bool aboveWaterline_ {false};
|
||||
bool startedPlayStatus_ {false};
|
||||
uint64_t readTime_ {0};
|
||||
bool isReadFrame_ {false};
|
||||
bool isTimeOut_ {false};
|
||||
bool downloadErrorState_ {false};
|
||||
std::atomic<bool> isInterruptNeeded_{false};
|
||||
@ -133,6 +132,8 @@ private:
|
||||
bool isInterrupt_ {false};
|
||||
bool isBuffering_ {false};
|
||||
bool isFirstFrameArrived_ {false};
|
||||
bool isBufferEnough_ {false};
|
||||
bool isErrorBreak_ {false};
|
||||
|
||||
uint64_t lastReadCheckTime_ {0};
|
||||
uint64_t readTotalBits_ {0};
|
||||
|
Loading…
Reference in New Issue
Block a user