From 1ca8d974e2c90f59fe061dedfb72a8279ae9550d Mon Sep 17 00:00:00 2001 From: liyang Date: Fri, 23 Feb 2024 18:09:33 +0800 Subject: [PATCH] fixed e03fd59 from https://gitee.com/acefighteryuan/multimedia_av_codec/pulls/1292 fix hls download duration error Signed-off-by: liyang --- .../http_source/hls/hls_media_downloader.cpp | 17 ++++++++--------- .../http_source/hls/hls_playlist_downloader.cpp | 4 +--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/services/media_engine/plugins/source/http_source/hls/hls_media_downloader.cpp b/services/media_engine/plugins/source/http_source/hls/hls_media_downloader.cpp index bc458786f..e0e439644 100644 --- a/services/media_engine/plugins/source/http_source/hls/hls_media_downloader.cpp +++ b/services/media_engine/plugins/source/http_source/hls/hls_media_downloader.cpp @@ -307,14 +307,13 @@ bool HlsMediaDownloader::SelectBitRate(uint32_t bitRate) void HlsMediaDownloader::SeekToTs(int64_t seekTime) { havePlayedTsNum_ = 0; - int64_t totalDuration = 0; + double totalDuration = 0; isDownloadStarted_ = false; playList_->Clear(); for (const auto &item : backPlayList_) { - int64_t hstTime; - Sec2HstTime(item.duration_, hstTime); - totalDuration += HstTime2Ns(hstTime); - if (seekTime >= totalDuration) { + double hstTime = item.duration_ * HST_SECOND; + totalDuration += hstTime / HST_NSECOND; + if (seekTime >= (int64_t)totalDuration) { havePlayedTsNum_++; continue; } @@ -322,10 +321,10 @@ void HlsMediaDownloader::SeekToTs(int64_t seekTime) playInfo.url_ = item.url_; playInfo.duration_ = item.duration_; int64_t startTimePos = 0; - int64_t lastTotalDuration = totalDuration - hstTime; - if (lastTotalDuration < seekTime) { - startTimePos = seekTime - lastTotalDuration; - if (startTimePos > hstTime / 2 && (&item != &backPlayList_.back())) { // 2 + double lastTotalDuration = totalDuration - hstTime; + if ((int64_t)lastTotalDuration < seekTime) { + startTimePos = seekTime - (int64_t)lastTotalDuration; + if (startTimePos > (int64_t)hstTime / 2 && (&item != &backPlayList_.back())) { // 2 havePlayedTsNum_++; continue; } diff --git a/services/media_engine/plugins/source/http_source/hls/hls_playlist_downloader.cpp b/services/media_engine/plugins/source/http_source/hls/hls_playlist_downloader.cpp index fd3dc7289..12b712759 100644 --- a/services/media_engine/plugins/source/http_source/hls/hls_playlist_downloader.cpp +++ b/services/media_engine/plugins/source/http_source/hls/hls_playlist_downloader.cpp @@ -59,9 +59,7 @@ int64_t HlsPlayListDownloader::GetDuration() const if (!master_) { return 0; } - int64_t hstTime; - Sec2HstTime(master_->duration_, hstTime); - return master_->bLive_ ? -1.0 : (HstTime2Ns(hstTime)); // -1.0 + return master_->bLive_ ? -1 : ((int64_t)master_->duration_ * HST_SECOND / HST_NSECOND); // -1 } Seekable HlsPlayListDownloader::GetSeekable() const -- Gitee