Skip to content

Commit

Permalink
Merge pull request #119 from Tencent/bugfix/android_vapx_loop
Browse files Browse the repository at this point in the history
Bugfix/android vapx loop
  • Loading branch information
hexleo authored Jul 28, 2021
2 parents 553d237 + 22e9baf commit 1c88841
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -66,6 +66,7 @@ class AnimPluginManager(val player: AnimPlayer) {
fun onRenderCreate() {
ALog.i(TAG, "onRenderCreate")
frameIndex = 0
decodeIndex = 0
plugins.forEach {
it.onRenderCreate()
}
Expand All @@ -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")
Expand Down

0 comments on commit 1c88841

Please sign in to comment.