mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-11-27 17:10:46 +00:00
恢复player自暂停
This reverts commit b4cba9cb8e
.
Signed-off-by: dcss <yangzhenjun2@huawei.com>
This commit is contained in:
parent
067dece4b1
commit
961a277166
@ -98,7 +98,8 @@ 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,6 +118,8 @@ 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;
|
||||
@ -259,6 +261,7 @@ 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,6 +728,22 @@ 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,6 +1144,7 @@ Status MediaDemuxer::Flush()
|
||||
Status MediaDemuxer::StopAllTask()
|
||||
{
|
||||
MEDIA_LOG_I("StopAllTask enter.");
|
||||
isDemuxerLoopExecuting_ = false;
|
||||
if (streamDemuxer_ != nullptr) {
|
||||
streamDemuxer_->SetIsIgnoreParse(true);
|
||||
}
|
||||
@ -1167,6 +1168,7 @@ 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) {
|
||||
@ -1186,6 +1188,7 @@ Status MediaDemuxer::PauseAllTask()
|
||||
Status MediaDemuxer::ResumeAllTask()
|
||||
{
|
||||
MEDIA_LOG_I("ResumeAllTask enter.");
|
||||
isDemuxerLoopExecuting_ = true;
|
||||
streamDemuxer_->SetIsIgnoreParse(false);
|
||||
|
||||
auto it = bufferQueueMap_.begin();
|
||||
@ -1327,6 +1330,7 @@ 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;
|
||||
@ -1356,6 +1360,7 @@ Status MediaDemuxer::Start()
|
||||
}
|
||||
isThreadExit_ = false;
|
||||
isStopped_ = false;
|
||||
isDemuxerLoopExecuting_ = true;
|
||||
if (!doPrepareFrame_) {
|
||||
auto it = bufferQueueMap_.begin();
|
||||
while (it != bufferQueueMap_.end()) {
|
||||
@ -2101,6 +2106,28 @@ 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,6 +55,8 @@ 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
|
||||
@ -300,44 +302,17 @@ bool HlsMediaDownloader::HandleBuffering()
|
||||
if (!isBuffering_) {
|
||||
return 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;
|
||||
}
|
||||
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_PERCENT);
|
||||
if (buffer_->GetSize() >= waterLineAbove_ || CheckBreakCondition()) {
|
||||
isBuffering_ = false;
|
||||
}
|
||||
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 {
|
||||
|
||||
if (!isBuffering_ && isFirstFrameArrived_) {
|
||||
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_;
|
||||
}
|
||||
|
||||
@ -383,7 +358,7 @@ Status HlsMediaDownloader::ReadDelegate(unsigned char* buff, ReadDataInfo& readD
|
||||
return Status::END_OF_STREAM;
|
||||
}
|
||||
|
||||
if (HandleBuffering()) {
|
||||
if (isBuffering_ && CheckBufferingOneSeconds()) {
|
||||
MEDIA_LOG_I("Read return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
@ -560,15 +535,17 @@ bool HlsMediaDownloader::SaveData(uint8_t* data, uint32_t len)
|
||||
OnWriteRingBuffer(len);
|
||||
}
|
||||
startedPlayStatus_ = true;
|
||||
bool ret = false;
|
||||
if (keyLen_ == 0) {
|
||||
bool res = buffer_->WriteBuffer(data, len);
|
||||
HandleCachedDuration();
|
||||
return res;
|
||||
ret = buffer_->WriteBuffer(data, len);
|
||||
} else {
|
||||
bool res = SaveEncryptData(data, len);
|
||||
HandleCachedDuration();
|
||||
return res;
|
||||
ret = SaveEncryptData(data, len);
|
||||
}
|
||||
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)
|
||||
@ -873,6 +850,7 @@ 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
|
||||
@ -905,6 +883,10 @@ 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)
|
||||
@ -1201,6 +1183,22 @@ 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,6 +119,7 @@ private:
|
||||
void CaculateBitRate(size_t fragmentSize, double duration);
|
||||
double CalculateCurrentDownloadSpeed();
|
||||
void UpdateCachedPercent(BufferingInfoType infoType);
|
||||
bool CheckBufferingOneSeconds();
|
||||
|
||||
private:
|
||||
std::shared_ptr<RingBuffer> buffer_;
|
||||
@ -222,7 +223,6 @@ private:
|
||||
bool isInterrupt_ {false};
|
||||
bool isBuffering_ {false};
|
||||
bool isFirstFrameArrived_ {false};
|
||||
bool isBufferEnough_ {true};
|
||||
std::atomic<bool> isSeekingFlag {false};
|
||||
Mutex switchMutex_ {};
|
||||
bool isLastDecryptWriteError_ {false};
|
||||
|
@ -41,9 +41,6 @@ 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;
|
||||
@ -56,6 +53,8 @@ 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)
|
||||
@ -172,6 +171,7 @@ 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,50 +242,34 @@ bool HttpMediaDownloader::HandleBuffering()
|
||||
if (!isBuffering_ || downloadRequest_->IsChunkedVod()) {
|
||||
return false;
|
||||
}
|
||||
MEDIA_LOG_I("HandleBuffering begin.");
|
||||
int32_t sleepTime = 0;
|
||||
isBufferEnough_ = false;
|
||||
UpdateCachedPercent(BufferingInfoType::BUFFERING_PERCENT);
|
||||
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 (!isBufferEnough_) {
|
||||
MEDIA_LOG_D("Buffer is not enough.");
|
||||
return isBuffering_;
|
||||
if (GetCurrentBufferSize() >= waterLineAbove_) {
|
||||
MEDIA_LOG_I("Buffer is not enough");
|
||||
isBuffering_ = false;
|
||||
}
|
||||
if (!isReadFrame_) {
|
||||
isReadFrame_ = true;
|
||||
MEDIA_LOG_I("Playing start");
|
||||
} else {
|
||||
if (HandleBreak()) {
|
||||
MEDIA_LOG_I("HandleBreak");
|
||||
isBuffering_ = false;
|
||||
}
|
||||
|
||||
if (!isBuffering_ && isFirstFrameArrived_) {
|
||||
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.");
|
||||
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());
|
||||
return isBuffering_;
|
||||
}
|
||||
|
||||
@ -308,7 +292,7 @@ bool HttpMediaDownloader::StartBuffering()
|
||||
if (downloadRequest_ != nullptr) {
|
||||
isEos = downloadRequest_->IsEos();
|
||||
}
|
||||
if (isFirstFrameArrived_ && GetCurrentBufferSize() < cacheWaterLine && !isEos && !isErrorBreak_) {
|
||||
if (isFirstFrameArrived_ && GetCurrentBufferSize() < cacheWaterLine && !isEos && !HandleBreak()) {
|
||||
waterLineAbove_ = std::max(MIN_WATER_LINE_ABOVE, static_cast<size_t>(GetWaterLineAbove()));
|
||||
waterLineAbove_ = std::min(waterLineAbove_, fileRemain);
|
||||
|
||||
@ -429,11 +413,9 @@ 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_) {
|
||||
if (HandleBuffering()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
if (isBuffering_ && !downloadRequest_->IsChunkedVod() && CheckBufferingOneSeconds()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
if (StartBuffering()) {
|
||||
return Status::ERROR_AGAIN;
|
||||
@ -443,16 +425,13 @@ 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_ && canWrite_) {
|
||||
if (HandleBuffering()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
if (isBuffering_ && !downloadRequest_->IsChunkedVod() && canWrite_ && CheckBufferingOneSeconds()) {
|
||||
MEDIA_LOG_I("Return error again.");
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
if (StartBuffering()) {
|
||||
return Status::ERROR_AGAIN;
|
||||
}
|
||||
isErrorBreak_ = false;
|
||||
return ReadCacheBuffer(buff, readDataInfo);
|
||||
}
|
||||
}
|
||||
@ -697,9 +676,18 @@ bool HttpMediaDownloader::SaveRingBufferData(uint8_t* data, uint32_t len)
|
||||
|
||||
bool HttpMediaDownloader::SaveData(uint8_t* data, uint32_t len)
|
||||
{
|
||||
bool ret = true;
|
||||
if (isFlv_) {
|
||||
return SaveRingBufferData(data, len);
|
||||
ret = SaveRingBufferData(data, len);
|
||||
} else {
|
||||
ret = SaveCacheBufferData(data, len);
|
||||
}
|
||||
HandleBuffering();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool HttpMediaDownloader::SaveCacheBufferData(uint8_t* data, uint32_t len)
|
||||
{
|
||||
if (isNeedClean_) {
|
||||
return true;
|
||||
}
|
||||
@ -722,6 +710,7 @@ bool HttpMediaDownloader::SaveData(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_) {
|
||||
@ -817,6 +806,7 @@ void HttpMediaDownloader::SetDownloadErrorState()
|
||||
Close(true);
|
||||
}
|
||||
}
|
||||
OnClientErrorEvent();
|
||||
}
|
||||
|
||||
void HttpMediaDownloader::SetInterruptState(bool isInterruptNeeded)
|
||||
@ -865,7 +855,7 @@ void HttpMediaDownloader::GetDownloadInfo(DownloadInfo& downloadInfo)
|
||||
downloadInfo.isTimeOut = isTimeOut_;
|
||||
}
|
||||
|
||||
bool HttpMediaDownloader::HandleBreak(int32_t& sleepTime)
|
||||
bool HttpMediaDownloader::HandleBreak()
|
||||
{
|
||||
bool isEos = false;
|
||||
if (downloadRequest_ != nullptr) {
|
||||
@ -873,12 +863,10 @@ bool HttpMediaDownloader::HandleBreak(int32_t& sleepTime)
|
||||
}
|
||||
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;
|
||||
@ -887,12 +875,6 @@ bool HttpMediaDownloader::HandleBreak(int32_t& sleepTime)
|
||||
}
|
||||
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;
|
||||
@ -983,7 +965,23 @@ 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,8 +65,9 @@ public:
|
||||
void UpdateCachedPercent(BufferingInfoType infoType);
|
||||
private:
|
||||
bool SaveData(uint8_t* data, uint32_t len);
|
||||
bool SaveRingBufferData(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);
|
||||
void OnClientErrorEvent();
|
||||
Status CheckIsEosRingBuffer(unsigned char* buff, ReadDataInfo& readDataInfo);
|
||||
Status CheckIsEosCacheBuffer(unsigned char* buff, ReadDataInfo& readDataInfo);
|
||||
@ -82,11 +83,12 @@ private:
|
||||
bool HandleBuffering();
|
||||
bool StartBuffering();
|
||||
size_t GetCurrentBufferSize();
|
||||
bool HandleBreak(int32_t& sleepTime);
|
||||
bool HandleBreak();
|
||||
void ChangeDownloadPos();
|
||||
int32_t GetWaterLineAbove();
|
||||
void HandleCachedDuration();
|
||||
double CalculateCurrentDownloadSpeed();
|
||||
bool CheckBufferingOneSeconds();
|
||||
|
||||
private:
|
||||
std::shared_ptr<RingBuffer> buffer_;
|
||||
@ -100,7 +102,6 @@ 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};
|
||||
@ -132,8 +133,6 @@ private:
|
||||
bool isInterrupt_ {false};
|
||||
bool isBuffering_ {false};
|
||||
bool isFirstFrameArrived_ {false};
|
||||
bool isBufferEnough_ {false};
|
||||
bool isErrorBreak_ {false};
|
||||
|
||||
uint64_t lastReadCheckTime_ {0};
|
||||
uint64_t readTotalBits_ {0};
|
||||
|
@ -1048,6 +1048,25 @@ HWTEST_F(MediaDemuxerUnitTest, MediaDemuxer_IsBufferDroppable_001,
|
||||
EXPECT_EQ(false, demuxer->IsBufferDroppable(demuxer->bufferMap_[vTrackId], vTrackId));
|
||||
}
|
||||
|
||||
HWTEST_F(MediaDemuxerUnitTest, MediaDemuxer_DemuxerReadLoop_001, TestSize.Level1)
|
||||
{
|
||||
string srtPath = "http://127.0.0.1:46666/test_dash/segment_base/index.mpd";
|
||||
std::shared_ptr<MediaDemuxer> demuxer = std::make_shared<MediaDemuxer>();
|
||||
EXPECT_EQ(demuxer->SetDataSource(std::make_shared<MediaSource>(srtPath)), Status::OK);
|
||||
std::shared_ptr<AVBufferQueue> inputBufferQueue =
|
||||
AVBufferQueue::Create(8, MemoryType::SHARED_MEMORY, "testInputBufferQueue");
|
||||
sptr<AVBufferQueueProducer> inputBufferQueueProducer = inputBufferQueue->GetProducer();
|
||||
EXPECT_EQ(demuxer->SetOutputBufferQueue(0, inputBufferQueueProducer), Status::OK);
|
||||
|
||||
EXPECT_EQ(Status::OK, demuxer->Start());
|
||||
|
||||
EXPECT_EQ(Status::OK, demuxer->PauseDemuxerReadLoop());
|
||||
EXPECT_EQ(Status::OK, demuxer->PauseDemuxerReadLoop());
|
||||
EXPECT_EQ(Status::OK, demuxer->ResumeDemuxerReadLoop());
|
||||
EXPECT_EQ(Status::OK, demuxer->ResumeDemuxerReadLoop());
|
||||
EXPECT_EQ(Status::OK, demuxer->StopAllTask());
|
||||
}
|
||||
|
||||
HWTEST_F(MediaDemuxerUnitTest, MediaDemuxer_GetPresentation_001, TestSize.Level1)
|
||||
{
|
||||
string srtPath = "http://127.0.0.1:46666/test_dash/segment_base/index.mpd";
|
||||
|
Loading…
Reference in New Issue
Block a user