Skip to content

Commit

Permalink
add a new function for buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jason77lee committed Dec 6, 2023
1 parent 2a0e1a3 commit 340b122
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
24 changes: 24 additions & 0 deletions IsoLib/libisomediafile/src/MP4FileMappingInputStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions IsoLib/libisomediafile/src/MP4Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
{ \
Expand Down
3 changes: 2 additions & 1 deletion IsoLib/libisomediafile/src/MP4InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
24 changes: 24 additions & 0 deletions IsoLib/libisomediafile/src/MP4MemoryInputStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 340b122

Please sign in to comment.