From 5a8735d009260d56f3c4eb49b42ca05ae1938af4 Mon Sep 17 00:00:00 2001 From: kaienfr Date: Sat, 12 Apr 2014 11:53:20 +0200 Subject: [PATCH] minor changes to improve latency in aac playing base on https://github.com/kaienfr/ppsspp_cn/commit/3a12cf2ad76bcdfc2e424e366067cda3a046359e. Test on Fortix even better than before. --- Core/HLE/sceMp4.cpp | 11 +++++++---- native | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceMp4.cpp b/Core/HLE/sceMp4.cpp index be306ef41b..a17b86bc16 100644 --- a/Core/HLE/sceMp4.cpp +++ b/Core/HLE/sceMp4.cpp @@ -322,14 +322,13 @@ u32 sceAacDecode(u32 id, u32 pcmAddr) auto inbuff = Memory::GetPointer(ctx->AACBuf); auto outbuf = Memory::GetPointer(ctx->PCMBuf); - memset(outbuf, 0, ctx->PCMBufSize); u32 outpcmbufsize = 0; // move inbuff to writePos of buffer inbuff += ctx->writePos; - // decode frames in aacBuf and output into PCMBuf if it is not exceed - while (ctx->aacBufAvailable > 0 && outpcmbufsize < ctx->PCMBufSize){ + // decode one frame in aacBuf and output into PCMBuf. Don't use while here, it could lead to latency in playing. + if (ctx->aacBufAvailable > 0){ int pcmframesize; // decode ctx->decoder->Decode(inbuff, ctx->aacBufAvailable, outbuf, &pcmframesize); @@ -340,7 +339,6 @@ u32 sceAacDecode(u32 id, u32 pcmAddr) ctx->readPos -= ctx->aacBufAvailable; } ctx->aacBufAvailable = 0; - break; } // count total output pcm size outpcmbufsize += pcmframesize; @@ -359,6 +357,11 @@ u32 sceAacDecode(u32 id, u32 pcmAddr) Memory::Write_U32(ctx->PCMBuf, pcmAddr); + // if we have no output but readPos is not the end of audio stream, we will clear pcm outbuf and return nonzero value to continue. + if (outpcmbufsize == 0 && ctx->readPos < ctx->endPos){ + memset(outbuf, 0, ctx->PCMBufSize); + return FF_INPUT_BUFFER_PADDING_SIZE; + } return outpcmbufsize; } diff --git a/native b/native index 3139ac497f..dc1e691ea8 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 3139ac497f434f9daebb3db8b4cb062d6a739296 +Subproject commit dc1e691ea8e70778d6559366d3e6372b31fe0bf5