From 340b1226cae228252861fd78796b0e628fe6c454 Mon Sep 17 00:00:00 2001 From: Jinwon Lee Date: Wed, 6 Dec 2023 12:52:45 +0900 Subject: [PATCH] add a new function for buffer --- .../src/MP4FileMappingInputStream.c | 24 +++++++++++++++++++ IsoLib/libisomediafile/src/MP4Impl.h | 5 ++++ IsoLib/libisomediafile/src/MP4InputStream.h | 3 ++- .../src/MP4MemoryInputStream.c | 24 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/IsoLib/libisomediafile/src/MP4FileMappingInputStream.c b/IsoLib/libisomediafile/src/MP4FileMappingInputStream.c index 14f6ea9..225a7cd 100644 --- a/IsoLib/libisomediafile/src/MP4FileMappingInputStream.c +++ b/IsoLib/libisomediafile/src/MP4FileMappingInputStream.c @@ -158,6 +158,29 @@ static MP4Err skipData(struct MP4InputStreamRecord *s, u64 bytes, char *msg) return err; } +static MP4Err rewindData(struct MP4InputStreamRecord *s, u64 bytes, char *msg) +{ + MP4Err err; + MP4FileMappingInputStreamPtr self = (MP4FileMappingInputStreamPtr)s; + + err = MP4NoErr; + + CHECK_AVAIL(bytes) + self->available += bytes; + self->current_offset -= bytes; + + if(msg && self->debugging) + { + doIndent(s); + fprintf(stdout, "%s = [%lld bytes of data rewinded]\n", msg, bytes); + } + +bail: + TEST_RETURN(err); + + return err; +} + static MP4Err readData(struct MP4InputStreamRecord *s, u64 bytes, char *outData, char *msg) { MP4Err err; @@ -223,6 +246,7 @@ MP4Err MP4CreateFileMappingInputStream(struct FileMappingObjectRecord *mapping, is->read32 = read32; is->readData = readData; is->skipData = skipData; + is->rewindData = rewindData; is->getStreamOffset = getStreamOffset; is->getFileMappingObject = getFileMappingObject; is->mapping = mapping; diff --git a/IsoLib/libisomediafile/src/MP4Impl.h b/IsoLib/libisomediafile/src/MP4Impl.h index 3af025f..98a7cb0 100644 --- a/IsoLib/libisomediafile/src/MP4Impl.h +++ b/IsoLib/libisomediafile/src/MP4Impl.h @@ -236,6 +236,11 @@ derivative works. Copyright (c) 1999. } \ } +#define REWIND_DATA(length, var) \ + err = inputStream->rewindData(inputStream, length, var); \ + if(err) goto bail; \ + self->bytesRead -= length; + #define PUTBYTES(src, len) \ if((self->bytesWritten + len) > self->size) \ { \ diff --git a/IsoLib/libisomediafile/src/MP4InputStream.h b/IsoLib/libisomediafile/src/MP4InputStream.h index b4e5f77..4a01b28 100644 --- a/IsoLib/libisomediafile/src/MP4InputStream.h +++ b/IsoLib/libisomediafile/src/MP4InputStream.h @@ -41,7 +41,8 @@ derivative works. Copyright (c) 1999. MP4Err (*read32)(struct MP4InputStreamRecord * self, u32 * outVal, char *msg); \ MP4Err (*readData)(struct MP4InputStreamRecord * self, u64 bytes, char *outData, char *msg); \ u64 (*getStreamOffset)(struct MP4InputStreamRecord * self); \ - MP4Err (*skipData)(struct MP4InputStreamRecord * self, u64 bytes, char *msg); + MP4Err (*skipData)(struct MP4InputStreamRecord * self, u64 bytes, char *msg); \ + MP4Err (*rewindData)(struct MP4InputStreamRecord * self, u64 bytes, char *msg); typedef struct MP4InputStreamRecord { diff --git a/IsoLib/libisomediafile/src/MP4MemoryInputStream.c b/IsoLib/libisomediafile/src/MP4MemoryInputStream.c index d345df1..2e9cc35 100644 --- a/IsoLib/libisomediafile/src/MP4MemoryInputStream.c +++ b/IsoLib/libisomediafile/src/MP4MemoryInputStream.c @@ -168,6 +168,29 @@ static MP4Err skipData(struct MP4InputStreamRecord *s, u64 bytes, char *msg) return err; } +static MP4Err rewindData(struct MP4InputStreamRecord *s, u64 bytes, char *msg) +{ + MP4Err err; + MP4FileMappingInputStreamPtr self = (MP4FileMappingInputStreamPtr)s; + + err = MP4NoErr; + + CHECK_AVAIL(bytes) + self->available += bytes; + self->current_offset -= bytes; + + if(msg && self->debugging) + { + doIndent(s); + fprintf(stdout, "%s = [%lld bytes of data rewinded]\n", msg, bytes); + } + +bail: + TEST_RETURN(err); + + return err; +} + static MP4Err readData(struct MP4InputStreamRecord *s, u64 bytes, char *outData, char *msg) { MP4Err err; @@ -221,6 +244,7 @@ MP4Err MP4CreateMemoryInputStream(char *base, u32 size, MP4InputStreamPtr *outSt is->read32 = read32; is->readData = readData; is->skipData = skipData; + is->rewindData = rewindData; is->getStreamOffset = getStreamOffset; is->msg = msg; is->getFileMappingObject = getFileMappingObject;