From e2569d9980dad0308face2135541c9753f0ba49f Mon Sep 17 00:00:00 2001 From: sirlemonhead Date: Thu, 14 May 2020 00:32:27 +0100 Subject: [PATCH] libsmackerdec: Implement GotoFrame() function # Conflicts: # source/libsmackerdec/src/SmackerDecoder.cpp --- source/libsmackerdec/include/SmackerDecoder.h | 1 + source/libsmackerdec/src/SmackerDecoder.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/libsmackerdec/include/SmackerDecoder.h b/source/libsmackerdec/include/SmackerDecoder.h index d962b6564..f35fdc0fc 100644 --- a/source/libsmackerdec/include/SmackerDecoder.h +++ b/source/libsmackerdec/include/SmackerDecoder.h @@ -152,6 +152,7 @@ class SmackerDecoder uint32_t currentFrame; int32_t nextPos; + int32_t firstFrameFilePos; bool DecodeHeaderTrees(); int DecodeHeaderTree(SmackerCommon::BitReader &bits, std::vector &recodes, int *last, int size); diff --git a/source/libsmackerdec/src/SmackerDecoder.cpp b/source/libsmackerdec/src/SmackerDecoder.cpp index 01c954ce7..ed71052fe 100644 --- a/source/libsmackerdec/src/SmackerDecoder.cpp +++ b/source/libsmackerdec/src/SmackerDecoder.cpp @@ -406,9 +406,10 @@ bool SmackerDecoder::Open(const char *fileName) // set nextPos to where we are now, as next data is frame 1 nextPos = file.GetPosition(); + firstFrameFilePos = nextPos; // determine max buffer sizes for audio tracks - file.Seek(nextPos, SmackerCommon::FileStream::kSeekStart); +// file.Seek(nextPos, SmackerCommon::FileStream::kSeekStart); uint32_t UNUSED(frameSize) = frameSizes[0] & (~3); uint8_t frameFlag = frameFlags[0]; @@ -1111,21 +1112,20 @@ float SmackerDecoder::GetFrameRate() void SmackerDecoder::GotoFrame(uint32_t frameNum) { - if (frameNum >= nFrames) { + if (frameNum > nFrames) { Printf("SmackerDecoder::GotoFrame() - Invalid frame number\n"); return; } - - // TODO +// file.Seek(firstFrameFilePos, SmackerCommon::FileStream::kSeekStart); - // seek to the desired frame (just set currentFrame) -// currentFrame = frameNum; + currentFrame = 0; + nextPos = firstFrameFilePos; - // what else? (memset some stuff?) + for (int i = 0; i < frameNum + 1; i++) + GetNextFrame(); } - SmackerAudioInfo SmackerDecoder::GetAudioTrackDetails(uint32_t trackIndex) { SmackerAudioInfo info;