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 bc458786f521648b47a808d55c034277d8a39e77..e0e439644ea2db1596610ddd9441c78beb1a6ae9 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 fd3dc72890fbcce19bbad06972fef5a8fa87f7a6..12b7127596de71a1021ad5d97c7c919d19f11af6 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