Browse Source

Merge pull request #119 from Tencent/bugfix/android_vapx_loop

Bugfix/android vapx loop
hexleo 4 years ago
parent
commit
1c88841581

+ 5 - 2
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/HardDecoder.kt

@@ -188,6 +188,7 @@ class HardDecoder(player: AnimPlayer) : Decoder(player), SurfaceTexture.OnFrameA
         var outputDone = false
         var inputDone = false
         var frameIndex = 0
+        var isLoop = false
 
         val decoderInputBuffers = decoder.inputBuffers
 
@@ -256,7 +257,7 @@ class HardDecoder(player: AnimPlayer) : Decoder(player), SurfaceTexture.OnFrameA
                         // release & render
                         decoder.releaseOutputBuffer(decoderStatus, doRender && !needYUV)
 
-                        if (frameIndex == 0) {
+                        if (frameIndex == 0 && !isLoop) {
                             onVideoStart()
                         }
                         player.pluginManager.onDecoding(frameIndex)
@@ -266,11 +267,13 @@ class HardDecoder(player: AnimPlayer) : Decoder(player), SurfaceTexture.OnFrameA
                         ALog.d(TAG, "decode frameIndex=$frameIndex")
                         if (loop > 0) {
                             ALog.d(TAG, "Reached EOD, looping")
+                            player.pluginManager.onLoopStart()
                             extractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC)
                             inputDone = false
                             decoder.flush()
                             speedControlUtil.reset()
-                            frameIndex = 1
+                            frameIndex = 0
+                            isLoop = true
                         }
                         if (outputDone) {
                             release(decoder, extractor)

+ 15 - 0
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamContainer.kt

@@ -1,3 +1,18 @@
+/*
+ * Tencent is pleased to support the open source community by making vap available.
+ *
+ * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
+ *
+ * Licensed under the MIT License (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://opensource.org/licenses/MIT
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.tencent.qgame.animplayer.file
 
 import android.annotation.TargetApi

+ 15 - 0
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamMediaDataSource.kt

@@ -1,3 +1,18 @@
+/*
+ * Tencent is pleased to support the open source community by making vap available.
+ *
+ * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
+ *
+ * Licensed under the MIT License (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://opensource.org/licenses/MIT
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.tencent.qgame.animplayer.file
 
 import android.annotation.TargetApi

+ 9 - 1
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/plugin/AnimPluginManager.kt

@@ -40,7 +40,7 @@ class AnimPluginManager(val player: AnimPlayer) {
     // 当前渲染的帧
     private var frameIndex = 0
     // 当前解码的帧
-    private var decodeIndex = 1
+    private var decodeIndex = 0
     // 帧不相同的次数, 连续多次不同则直接使用decodeIndex
     private var frameDiffTimes = 0
 
@@ -66,6 +66,7 @@ class AnimPluginManager(val player: AnimPlayer) {
     fun onRenderCreate() {
         ALog.i(TAG, "onRenderCreate")
         frameIndex = 0
+        decodeIndex = 0
         plugins.forEach {
             it.onRenderCreate()
         }
@@ -79,6 +80,13 @@ class AnimPluginManager(val player: AnimPlayer) {
         }
     }
 
+    // 开始循环调用
+    fun onLoopStart() {
+        ALog.i(TAG, "onLoopStart")
+        frameIndex = 0
+        decodeIndex = 0
+    }
+
     fun onRendering() {
         if (decodeIndex > frameIndex + 1 || frameDiffTimes >= DIFF_TIMES) {
             ALog.i(TAG, "jump frameIndex= $frameIndex,decodeIndex=$decodeIndex,frameDiffTimes=$frameDiffTimes")