Browse Source

1,添加从指定时间开始缓存 用于 seek 操作

jsonwang 3 years ago
parent
commit
84fe111477

+ 1 - 0
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -108,6 +108,7 @@ class PQStuckPointEditerController: PQBaseViewController {
                 let seekTimeRange: CMTimeRange = CMTimeRange(start: CMTime(value: CMTimeValue(Int64(newBeginSconds)), timescale: 600), end:
                     CMTime(value: CMTimeValue(Int64(endTime * 600)), timescale: 600))
                 BFLog(message: "修改的开始 \(CMTimeGetSeconds(seekTimeRange.start)) 结束  \(CMTimeGetSeconds(seekTimeRange.end))")
+                //重新设置有效缓存
                 self?.playerView.configCache(beginTime: CMTimeGetSeconds(seekTimeRange.start))
                 self?.playerView.play(pauseFirstFrame: false, playeTimeRange: seekTimeRange)
 

+ 10 - 5
BFFramework/Classes/Stuckpoint/ViewModel/PQGPUImagePlayerView.swift

@@ -131,7 +131,7 @@ public class PQGPUImagePlayerView: UIView {
             
             FilterLog(message: "设置线程为: \(Thread.current) \(OperationQueue.current?.underlyingQueue?.label as Any)")
         
-            configCache()
+            configCache(beginTime: mStickers?.first?.timelineIn ?? 0)
         }
     }
  
@@ -406,7 +406,7 @@ public class PQGPUImagePlayerView: UIView {
             guard let strongSelf = self else { return }
             //缓存已经用完,重新初始化缓存
             if(strongSelf.filters.count == 0){
-                strongSelf.configCache()
+                strongSelf.configCache(beginTime: strongSelf.mStickers?.first?.timelineIn ?? 0)
             }
             
             DispatchQueue.main.async {
@@ -421,8 +421,9 @@ public class PQGPUImagePlayerView: UIView {
         applyFilters()
     }
 
-    // 初始化缓存,默认选创建 cacheFiltersMaxCount 个缓存 filterrs
-    func configCache() {
+    /// 初始化缓存,默认选创建 cacheFiltersMaxCount 个缓存 filterrs
+    /// - Parameter beginTime: 开始缓存的开始时间,用在 seek操作时 老的缓存已经无效不能在使用了
+    func configCache(beginTime: Float64 ) {
         cacheFilters.removeAll()
         FilterLog(message: "原素材 总数:\(mStickers?.count ?? 0) ")
        
@@ -435,9 +436,13 @@ public class PQGPUImagePlayerView: UIView {
             
             for (index, currentSticker) in mStickers!.enumerated() {
                //到达最大缓存数退出
-                if index == cacheFiltersMaxCount {
+                if cacheFilters.count == cacheFiltersMaxCount {
                     break
                 }
+                //小于缓存的开始时间继续查找
+                if(currentSticker.timelineOut < beginTime){
+                    continue
+                }
                 var showFitler: PQBaseFilter?
                 if currentSticker.type == StickerType.VIDEO.rawValue {
                     showFitler = PQMovieFilter(movieSticker: currentSticker)