From 5f4f8bc8908a53e003cef7bda29df33491863f5d Mon Sep 17 00:00:00 2001 From: hexleo Date: Tue, 27 Jul 2021 19:37:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bug:=20=E4=BF=AE=E5=A4=8D=E8=9E=8D=E5=90=88?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E5=BE=AA=E7=8E=AF=E6=92=AD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=9F=AD=E6=9A=82=E6=B6=88=E5=A4=B1=E9=97=AE=E9=A2=98=E3=80=82?= =?UTF-8?q?=20=E5=8E=9F=E5=9B=A0=E6=98=AFplugin=E7=BC=BA=E5=B0=91=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E6=92=AD=E6=94=BE=E7=9A=84=E9=80=9A=E7=9F=A5=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E9=80=9A=E8=BF=87=E5=AE=B9=E9=94=99=E6=84=9F?= =?UTF-8?q?=E7=9F=A5=E5=BE=AA=E7=8E=AF=E6=92=AD=E6=94=BE=20close=20#118?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tencent/qgame/animplayer/HardDecoder.kt | 7 +++++-- .../qgame/animplayer/plugin/AnimPluginManager.kt | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/HardDecoder.kt b/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/HardDecoder.kt index d8915fff..cce9081a 100644 --- a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/HardDecoder.kt +++ b/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) diff --git a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/plugin/AnimPluginManager.kt b/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/plugin/AnimPluginManager.kt index d8ce6aa4..bf717c98 100644 --- a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/plugin/AnimPluginManager.kt +++ b/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") From 22e9bafee97035fbec11a469ffc558d914be61ca Mon Sep 17 00:00:00 2001 From: hexleo Date: Tue, 27 Jul 2021 19:37:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?style:=20=E8=A1=A5=E5=85=85=E5=BC=80?= =?UTF-8?q?=E6=BA=90=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qgame/animplayer/file/StreamContainer.kt | 15 +++++++++++++++ .../animplayer/file/StreamMediaDataSource.kt | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamContainer.kt b/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamContainer.kt index 0e6bffb9..d41ab730 100644 --- a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamContainer.kt +++ b/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 diff --git a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamMediaDataSource.kt b/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamMediaDataSource.kt index 23362a6a..1fba6404 100644 --- a/Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/file/StreamMediaDataSource.kt +++ b/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