Commit 611d806a authored by Steve Lhomme's avatar Steve Lhomme

v2/mkclean: fix support for large files (>4GB)

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@171 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent 21665dd9
2010-05-05
version 0.1.3:
- By default build with support for large files (>4GB)
2010-05-04
version 0.1.2:
- Fix the wrong EBML header in release builds (doh!)
......
......@@ -6,4 +6,5 @@
#define USE_PRECOMPILED_HEADERS
#define CONFIG_DEBUGCHECKS
#define CONFIG_STDIO
#define CONFIG_FILEPOS_64
//#define CONFIG_DEBUG_LEAKS
......@@ -116,7 +116,7 @@ struct ebml_element
nodetree Base;
bool_t bValueIsSet;
bool_t bDefaultIsSet;
filepos_t Size; // size of the data inside the element
filepos_t DataSize; // size of the data inside the element
int8_t SizeLength;
filepos_t ElementPosition;
filepos_t SizePosition; // TODO: is this needed since we have the ElementPosition and SizeLength ?
......@@ -197,8 +197,8 @@ EBML_DLL int EBML_CodedSizeLength(filepos_t Length, uint8_t SizeLength, bool_t b
EBML_DLL int EBML_CodedSizeLengthSigned(filepos_t Length, uint8_t SizeLength); // TODO: turn into a macro ?
EBML_DLL int EBML_CodedValueLength(filepos_t Length, size_t CodedSize, uint8_t *OutBuffer); // TODO: turn into a macro ?
EBML_DLL int EBML_CodedValueLengthSigned(filepos_t Length, size_t CodedSize, uint8_t * OutBuffer); // TODO: turn into a macro ?
EBML_DLL size_t EBML_ReadCodedSizeValue(const uint8_t *InBuffer, size_t *BufferSize, size_t *SizeUnknown);
EBML_DLL int64_t EBML_ReadCodedSizeSignedValue(const uint8_t *InBuffer, size_t *BufferSize, size_t *SizeUnknown);
EBML_DLL filepos_t EBML_ReadCodedSizeValue(const uint8_t *InBuffer, size_t *BufferSize, filepos_t *SizeUnknown);
EBML_DLL filepos_t EBML_ReadCodedSizeSignedValue(const uint8_t *InBuffer, size_t *BufferSize, filepos_t *SizeUnknown);
EBML_DLL filepos_t EBML_ElementFullSize(const ebml_element *Element, bool_t bWithDefault);
EBML_DLL ebml_element *EBML_ElementSkipData(ebml_element *Element, stream *Input, const ebml_parser_context *Context, ebml_element *TestReadElt, bool_t AllowDummy);
......@@ -211,14 +211,14 @@ static INLINE filepos_t EBML_ElementPositionData(const ebml_element *Element)
if (!EBML_ElementIsFiniteSize(Element))
return INVALID_FILEPOS_T;
else
return Element->SizePosition + EBML_CodedSizeLength(Element->Size,Element->SizeLength,1);
return Element->SizePosition + EBML_CodedSizeLength(Element->DataSize,Element->SizeLength,1);
}
static INLINE filepos_t EBML_ElementPositionEnd(const ebml_element *Element)
{
if (!EBML_ElementIsFiniteSize(Element))
return INVALID_FILEPOS_T;
else
return Element->SizePosition + EBML_CodedSizeLength(Element->Size,Element->SizeLength,1) + Element->Size;
return Element->SizePosition + EBML_CodedSizeLength(Element->DataSize,Element->SizeLength,1) + Element->DataSize;
}
#if defined(CONFIG_EBML_WRITING)
......
......@@ -42,13 +42,13 @@ static err_t ReadData(ebml_binary *Element, stream *Input, const ebml_parser_con
goto failed;
}
if (!ArrayResize(&Element->Data,(size_t)Element->Base.Size,0))
if (!ArrayResize(&Element->Data,(size_t)Element->Base.DataSize,0))
{
Result = ERR_OUT_OF_MEMORY;
goto failed;
}
Result = Stream_Read(Input,ARRAYBEGIN(Element->Data,void),(size_t)Element->Base.Size,NULL);
Result = Stream_Read(Input,ARRAYBEGIN(Element->Data,void),(size_t)Element->Base.DataSize,NULL);
if (Result == ERR_NONE)
Element->Base.bValueIsSet = 1;
failed:
......@@ -78,13 +78,13 @@ static bool_t IsDefaultValue(const ebml_binary *Element)
static filepos_t UpdateSize(ebml_binary *Element, bool_t bWithDefault, bool_t bForceRender)
{
Element->Base.Size = ARRAYCOUNT(Element->Data,uint8_t);
Element->Base.DataSize = ARRAYCOUNT(Element->Data,uint8_t);
if (Element->Base.DefaultSize > Element->Base.Size) {
Element->Base.Size = Element->Base.DefaultSize;
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
return Element->Base.Size;
return Element->Base.DataSize;
}
META_START(EBMLBinary_Class,EBML_BINARY_CLASS)
......
......@@ -29,7 +29,7 @@
static bool_t ValidateSize(ebml_element *p)
{
return (p->Size == 4);
return (p->DataSize == 4);
}
META_START(EBMLCRC_Class,EBML_CRC_CLASS)
......
......@@ -46,13 +46,13 @@ err_t EBML_DateSetDateTime(ebml_date *Element, datetime_t Date)
static bool_t ValidateSize(ebml_element *p)
{
return (p->Size == 8 || p->Size == 0);
return (p->DataSize == 8 || p->DataSize == 0);
}
static err_t ReadData(ebml_date *Element, stream *Input, const ebml_parser_context *ParserContext, bool_t AllowDummyElt, int Scope)
{
err_t Result;
int Size;
int DataSize;
uint8_t Value[8];
Element->Base.bValueIsSet = 0;
......@@ -66,17 +66,17 @@ static err_t ReadData(ebml_date *Element, stream *Input, const ebml_parser_conte
goto failed;
}
assert(Element->Base.Size<=8);
Result = Stream_Read(Input,Value,(size_t)Element->Base.Size,NULL);
assert(Element->Base.DataSize<=8);
Result = Stream_Read(Input,Value,(size_t)Element->Base.DataSize,NULL);
if (Result != ERR_NONE)
goto failed;
#ifdef IS_BIG_ENDIAN
memcpy(&Element->Value,Value,Element->Base.Size);
memcpy(&Element->Value,Value,Element->Base.DataSize);
#else
Element->Value = 0;
for (Size=0;Size<Element->Base.Size;++Size)
((uint8_t*)&Element->Value)[Size] = Value[Element->Base.Size-Size-1];
for (DataSize=0;DataSize<Element->Base.DataSize;++DataSize)
((uint8_t*)&Element->Value)[DataSize] = Value[Element->Base.DataSize-DataSize-1];
#endif
Element->Base.bValueIsSet = 1;
failed:
......
......@@ -41,7 +41,7 @@ static void PostCreate(ebml_element *Element)
static err_t Create(ebml_element *Element)
{
Element->Size = INVALID_FILEPOS_T;
Element->DataSize = INVALID_FILEPOS_T;
return ERR_NONE;
}
......@@ -87,7 +87,7 @@ ebml_element *EBML_ElementSkipData(ebml_element *p, stream *Input, const ebml_pa
if (EBML_ElementIsFiniteSize(p)) {
assert(TestReadElt == NULL);
assert(p->ElementPosition < p->SizePosition);
Stream_Seek(Input, p->SizePosition + EBML_CodedSizeLength(p->Size, p->SizeLength, 1) + p->Size, SEEK_SET);
Stream_Seek(Input, p->SizePosition + EBML_CodedSizeLength(p->DataSize, p->SizeLength, 1) + p->DataSize, SEEK_SET);
} else {
// read elements until an upper element is found
bool_t bEndFound = 0;
......@@ -103,7 +103,7 @@ ebml_element *EBML_ElementSkipData(ebml_element *p, stream *Input, const ebml_pa
#ifdef TODO
unsigned int EltIndex;
// data known in this Master's context
for (EltIndex = 0; EltIndex < Context.Size; EltIndex++) {
for (EltIndex = 0; EltIndex < Context.DataSize; EltIndex++) {
if (EbmlId(*Result) == Context.MyTable[EltIndex].GetCallbacks.GlobalId) {
// skip the data with its own context
Result = Result->SkipData(DataStream, Context.MyTable[EltIndex].GetCallbacks.Context, NULL);
......@@ -111,7 +111,7 @@ ebml_element *EBML_ElementSkipData(ebml_element *p, stream *Input, const ebml_pa
}
}
if (EltIndex >= Context.Size) {
if (EltIndex >= Context.DataSize) {
if (Context.UpTable != NULL) {
Result = SkipData(DataStream, *Context.UpTable, Result);
} else {
......@@ -147,7 +147,7 @@ filepos_t EBML_ElementFullSize(const ebml_element *Element, bool_t bWithDefault)
{
if (!bWithDefault && EBML_ElementIsDefaultValue(Element))
return INVALID_FILEPOS_T; // won't be saved
return Element->Size + GetIdLength(Element->Context->Id) + EBML_CodedSizeLength(Element->Size, Element->SizeLength, EBML_ElementIsFiniteSize(Element));
return Element->DataSize + GetIdLength(Element->Context->Id) + EBML_CodedSizeLength(Element->DataSize, Element->SizeLength, EBML_ElementIsFiniteSize(Element));
}
bool_t EBML_ElementInfiniteForceSize(ebml_element *Element, filepos_t NewSize)
......@@ -159,16 +159,16 @@ bool_t EBML_ElementInfiniteForceSize(ebml_element *Element, filepos_t NewSize)
if (EBML_ElementIsFiniteSize(Element))
return 0;
OldSizeLen = EBML_CodedSizeLength(Element->Size, Element->SizeLength, EBML_ElementIsFiniteSize(Element));
OldSize = Element->Size;
Element->Size = NewSize;
OldSizeLen = EBML_CodedSizeLength(Element->DataSize, Element->SizeLength, EBML_ElementIsFiniteSize(Element));
OldSize = Element->DataSize;
Element->DataSize = NewSize;
if (EBML_CodedSizeLength(Element->Size, Element->SizeLength, EBML_ElementIsFiniteSize(Element)) == OldSizeLen)
if (EBML_CodedSizeLength(Element->DataSize, Element->SizeLength, EBML_ElementIsFiniteSize(Element)) == OldSizeLen)
{
EBML_ElementSetInfiniteSize(Element,1);
return 1;
}
Element->Size = OldSize;
Element->DataSize = OldSize;
return 0;
}
......@@ -235,8 +235,8 @@ err_t EBML_ElementRenderHead(ebml_element *Element, stream *Output, bool_t bKeep
FinalHeadSize = EBML_FillBufferID(FinalHead,sizeof(FinalHead),Element->Context->Id);
CodedSize = EBML_CodedSizeLength(Element->Size, Element->SizeLength, EBML_ElementIsFiniteSize(Element));
EBML_CodedValueLength(Element->Size, CodedSize, &FinalHead[FinalHeadSize]);
CodedSize = EBML_CodedSizeLength(Element->DataSize, Element->SizeLength, EBML_ElementIsFiniteSize(Element));
EBML_CodedValueLength(Element->DataSize, CodedSize, &FinalHead[FinalHeadSize]);
FinalHeadSize += CodedSize;
Err = Stream_Write(Output, FinalHead, FinalHeadSize, &i);
......
......@@ -118,10 +118,10 @@ const ebml_semantic EBML_SemanticGlobals[] = {
static const ebml_context EBML_ContextGlobals = {0, 0, 0, 0, "GlobalContext", EBML_SemanticGlobals, EBML_SemanticGlobals};
size_t EBML_ReadCodedSizeValue(const uint8_t *InBuffer, size_t *BufferSize, size_t *SizeUnknown)
filepos_t EBML_ReadCodedSizeValue(const uint8_t *InBuffer, size_t *BufferSize, filepos_t *SizeUnknown)
{
uint8_t SizeBitMask = 1 << 7;
size_t Result = 0x7F;
filepos_t Result = 0x7F;
unsigned int SizeIdx, PossibleSizeLength = 0;
uint8_t PossibleSize[8];
unsigned int i;
......@@ -159,9 +159,9 @@ size_t EBML_ReadCodedSizeValue(const uint8_t *InBuffer, size_t *BufferSize, size
return 0;
}
int64_t EBML_ReadCodedSizeSignedValue(const uint8_t *InBuffer, size_t *BufferSize, size_t *SizeUnknown)
filepos_t EBML_ReadCodedSizeSignedValue(const uint8_t *InBuffer, size_t *BufferSize, filepos_t *SizeUnknown)
{
int64_t Result = EBML_ReadCodedSizeValue(InBuffer, BufferSize, SizeUnknown);
filepos_t Result = EBML_ReadCodedSizeValue(InBuffer, BufferSize, SizeUnknown);
if (*BufferSize != 0)
{
......@@ -320,7 +320,7 @@ static ebml_element *EBML_ElementCreateUsingContext(void *AnyNode, const uint8_t
ebml_element *EBML_FindNextId(stream *Input, const ebml_context *Context, size_t MaxDataSize)
{
filepos_t aElementPosition, aSizePosition;
size_t SizeFound=0, SizeUnknown;
filepos_t SizeFound=0, SizeUnknown;
int ReadSize;
uint8_t BitMask;
uint8_t PossibleId[4];
......@@ -382,8 +382,8 @@ else if (PossibleID_Length==1)
printf("Elt: size %d id %d %02X\n",SizeFound,PossibleID_Length,PossibleId[0]);
#endif
Result->SizeLength = PossibleSizeLength;
Result->Size = SizeFound;
if (!EBML_ElementValidateSize(Result) || (SizeFound != SizeUnknown && MaxDataSize < (size_t)Result->Size))
Result->DataSize = SizeFound;
if (!EBML_ElementValidateSize(Result) || (SizeFound != SizeUnknown && MaxDataSize < (size_t)Result->DataSize))
{
NodeDelete((node*)Result);
return NULL;
......@@ -498,10 +498,10 @@ ebml_element *EBML_FindNextElement(stream *Input, const ebml_parser_context *Con
uint8_t PossibleID_Length = 0;
uint8_t PossibleIdNSize[16];
int PossibleSizeLength;
size_t SizeUnknown;
filepos_t SizeUnknown;
int8_t SizeIdx,ReadIndex = 0; // trick for the algo, start index at 0
uint32_t ReadSize = 0;
size_t SizeFound;
filepos_t SizeFound;
bool_t bFound;
int UpperLevel_original = *UpperLevels;
filepos_t CurrentPos;
......@@ -605,7 +605,7 @@ ebml_element *EBML_FindNextElement(stream *Input, const ebml_parser_context *Con
assert(_SizeLength <= 8);
Result->SizeLength = (int8_t)_SizeLength;
Result->Size = SizeFound;
Result->DataSize = SizeFound;
// LevelChange values
// -1 : global element
// 0 : child
......
......@@ -151,7 +151,7 @@ filepos_t UpdateSize(ebml_element *Element, bool_t bWithDefault, bool_t bForceRe
{
ebml_element *i;
Element->Size = 0;
Element->DataSize = 0;
if (!EBML_ElementIsFiniteSize(Element))
return INVALID_FILEPOS_T;
......@@ -165,16 +165,16 @@ filepos_t UpdateSize(ebml_element *Element, bool_t bWithDefault, bool_t bForceRe
if (!bWithDefault && EBML_ElementIsDefaultValue(i))
continue;
EBML_ElementUpdateSize(i,bWithDefault,bForceRender);
if (i->Size == INVALID_FILEPOS_T)
if (i->DataSize == INVALID_FILEPOS_T)
return INVALID_FILEPOS_T;
Element->Size += EBML_ElementFullSize(i,bWithDefault);
Element->DataSize += EBML_ElementFullSize(i,bWithDefault);
}
#ifdef TODO
if (bChecksumUsed) {
Element->Size += EBML_ElementFullSize(Element->Checksum,bWithDefault);
Element->DataSize += EBML_ElementFullSize(Element->Checksum,bWithDefault);
}
#endif
return Element->Size;
return Element->DataSize;
}
static void PostCreate(ebml_element *Element)
......@@ -195,7 +195,7 @@ static err_t ReadData(ebml_element *Element, stream *Input, const ebml_parser_co
Element->bValueIsSet = 0;
// read blocks and discard the ones we don't care about
if (Element->Size > 0) {
if (Element->DataSize > 0) {
ebml_element *SubElement;
ebml_parser_context Context;
int UpperEltFound = 0;
......@@ -204,7 +204,7 @@ static err_t ReadData(ebml_element *Element, stream *Input, const ebml_parser_co
if (Stream_Seek(Input,EBML_ElementPositionData(Element),SEEK_SET)==INVALID_FILEPOS_T)
return ERR_END_OF_FILE;
MaxSizeToRead = Element->Size;
MaxSizeToRead = Element->DataSize;
Context.UpContext = ParserContext;
Context.Context = Element->Context;
Context.EndPosition = EBML_ElementPositionEnd(Element);
......@@ -290,7 +290,7 @@ static err_t RenderData(ebml_element *Element, stream *Output, bool_t bForceRend
}
#ifdef TODO
} else { // new school: render in memory and compute the CRC
MemIOCallback TmpBuf(Size - 6);
MemIOCallback TmpBuf(DataSize - 6);
for (Index = 0; Index < ElementList.size(); Index++) {
if (!bWithDefault && (ElementList[Index])->IsDefaultValue())
continue;
......
......@@ -33,7 +33,7 @@ static err_t ReadDataInt(ebml_integer *Element, stream *Input, const ebml_parser
char Buffer[8];
int i;
assert(Element->Base.Size <= 8);
assert(Element->Base.DataSize <= 8);
Element->Base.bValueIsSet = 0;
......@@ -46,12 +46,12 @@ static err_t ReadDataInt(ebml_integer *Element, stream *Input, const ebml_parser
goto failed;
}
Result = Stream_Read(Input,Buffer,(size_t)Element->Base.Size,NULL);
Result = Stream_Read(Input,Buffer,(size_t)Element->Base.DataSize,NULL);
if (Result != ERR_NONE)
return Result;
Element->Value = 0;
for (i=0; i<(int)Element->Base.Size; i++)
for (i=0; i<(int)Element->Base.DataSize; i++)
{
Element->Value <<= 8;
Element->Value |= (uint8_t)Buffer[i];
......@@ -67,7 +67,7 @@ static err_t ReadDataSignedInt(ebml_integer *Element, stream *Input, const ebml_
char Buffer[8];
int i;
assert(Element->Base.Size <= 8);
assert(Element->Base.DataSize <= 8);
Element->Base.bValueIsSet = 0;
......@@ -80,7 +80,7 @@ static err_t ReadDataSignedInt(ebml_integer *Element, stream *Input, const ebml_
goto failed;
}
Result = Stream_Read(Input,Buffer,(size_t)Element->Base.Size,NULL);
Result = Stream_Read(Input,Buffer,(size_t)Element->Base.DataSize,NULL);
if (Result != ERR_NONE)
goto failed;
......@@ -88,7 +88,7 @@ static err_t ReadDataSignedInt(ebml_integer *Element, stream *Input, const ebml_
Element->Value = -1;
else
Element->Value = 0;
for (i=0; i<(int)Element->Base.Size; i++)
for (i=0; i<(int)Element->Base.DataSize; i++)
{
Element->Value <<= 8;
Element->Value |= Buffer[i];
......@@ -109,27 +109,27 @@ static err_t RenderDataSignedInt(ebml_integer *Element, stream *Output, bool_t b
if (Element->Base.SizeLength > 8)
return 0; // integers larger than 64 bits are not supported
if (Element->Base.Size == 0)
if (Element->Base.DataSize == 0)
return 0; // nothing to write
TempValue = Element->Value;
if (Element->Base.DefaultSize > Element->Base.Size)
if (Element->Base.DefaultSize > Element->Base.DataSize)
{
for (i=Element->Base.DefaultSize - Element->Base.Size - 1;i;--i)
for (i=Element->Base.DefaultSize - (int)Element->Base.DataSize - 1;i;--i)
FinalData[i-1] = 0;
i = Element->Base.DefaultSize - Element->Base.Size;
i = Element->Base.DefaultSize - (int)Element->Base.DataSize;
}
else
i=(size_t)Element->Base.Size;
i=(size_t)Element->Base.DataSize;
for (;i;--i) {
FinalData[i-1] = (uint8_t)(TempValue & 0xFF);
TempValue >>= 8;
}
if (Element->Base.DefaultSize > Element->Base.Size)
if (Element->Base.DefaultSize > Element->Base.DataSize)
Err = Stream_Write(Output,FinalData,(size_t)Element->Base.DefaultSize,&i);
else
Err = Stream_Write(Output,FinalData,(size_t)Element->Base.Size,&i);
Err = Stream_Write(Output,FinalData,(size_t)Element->Base.DataSize,&i);
if (Rendered)
*Rendered = i;
return Err;
......@@ -145,27 +145,27 @@ static err_t RenderDataInt(ebml_integer *Element, stream *Output, bool_t bForceR
if (Element->Base.SizeLength > 8)
return 0; // integers larger than 64 bits are not supported
if (Element->Base.Size == 0)
if (Element->Base.DataSize == 0)
return 0; // nothing to write
TempValue = Element->Value;
if (Element->Base.DefaultSize > Element->Base.Size)
if (Element->Base.DefaultSize > Element->Base.DataSize)
{
for (i=Element->Base.DefaultSize - Element->Base.Size - 1;i;--i)
for (i=Element->Base.DefaultSize - (int)Element->Base.DataSize - 1;i;--i)
FinalData[i-1] = 0;
i = Element->Base.DefaultSize - Element->Base.Size;
i = Element->Base.DefaultSize - (int)Element->Base.DataSize;
}
else
i=(size_t)Element->Base.Size;
i=(size_t)Element->Base.DataSize;
for (;i;--i) {
FinalData[i-1] = (uint8_t)(TempValue & 0xFF);
TempValue >>= 8;
}
if (Element->Base.DefaultSize > Element->Base.Size)
if (Element->Base.DefaultSize > Element->Base.DataSize)
Err = Stream_Write(Output,FinalData,(size_t)Element->Base.DefaultSize,&i);
else
Err = Stream_Write(Output,FinalData,(size_t)Element->Base.Size,&i);
Err = Stream_Write(Output,FinalData,(size_t)Element->Base.DataSize,&i);
if (Rendered)
*Rendered = i;
return Err;
......@@ -175,7 +175,7 @@ static err_t RenderDataFloat(ebml_float *Element, stream *Output, bool_t bForceR
{
err_t Err;
size_t i = 0;
if (Element->Base.Size == 8)
if (Element->Base.DataSize == 8)
{
uint64_t Buf = LOAD64BE(&Element->Value);
Err = Stream_Write(Output,&Buf,8,&i);
......@@ -194,12 +194,12 @@ static err_t RenderDataFloat(ebml_float *Element, stream *Output, bool_t bForceR
static bool_t ValidateSizeInt(ebml_element *p)
{
return (p->Size <= 8);
return (p->DataSize <= 8);
}
static bool_t ValidateSizeFloat(ebml_element *p)
{
return (p->Size == 8 || p->Size == 4);
return (p->DataSize == 8 || p->DataSize == 4);
}
static err_t ReadDataFloat(ebml_float *Element, stream *Input, const ebml_parser_context *ParserContext, bool_t AllowDummyElt, int Scope)
......@@ -207,7 +207,7 @@ static err_t ReadDataFloat(ebml_float *Element, stream *Input, const ebml_parser
uint8_t Value[8];
err_t Result;
assert(Element->Base.Size == 8 || Element->Base.Size == 4);
assert(Element->Base.DataSize == 8 || Element->Base.DataSize == 4);
Element->Base.bValueIsSet = 0;
......@@ -220,11 +220,11 @@ static err_t ReadDataFloat(ebml_float *Element, stream *Input, const ebml_parser
goto failed;
}
Result = Stream_Read(Input,Value,min((size_t)Element->Base.Size,sizeof(Value)),NULL); // min is for code safety
Result = Stream_Read(Input,Value,min((size_t)Element->Base.DataSize,sizeof(Value)),NULL); // min is for code safety
if (Result != ERR_NONE)
goto failed;
if (Element->Base.Size == 4) {
if (Element->Base.DataSize == 4) {
float Val;
#ifdef IS_BIG_ENDIAN
memcpy(&Val,Value,4);
......@@ -236,7 +236,7 @@ static err_t ReadDataFloat(ebml_float *Element, stream *Input, const ebml_parser
#endif
Element->Value = Val;
Element->Base.bValueIsSet = 1;
} else if (Element->Base.Size == 8) {
} else if (Element->Base.DataSize == 8) {
#ifdef IS_BIG_ENDIAN
memcpy(&Element->Value,Value,8);
#else
......@@ -272,27 +272,27 @@ static filepos_t UpdateSizeSignedInt(ebml_integer *Element, bool_t bWithDefault,
return 0;
if (Element->Value <= 0x7F && Element->Value >= (-0x80)) {
Element->Base.Size = 1;
Element->Base.DataSize = 1;
} else if (Element->Value <= 0x7FFF && Element->Value >= (-0x8000)) {
Element->Base.Size = 2;
Element->Base.DataSize = 2;
} else if (Element->Value <= 0x7FFFFF && Element->Value >= (-0x800000)) {
Element->Base.Size = 3;
Element->Base.DataSize = 3;
} else if (Element->Value <= (int64_t)(0x7FFFFFFF) && Element->Value >= (int64_t)(-0x80000000)) {
Element->Base.Size = 4;
Element->Base.DataSize = 4;
} else if (Element->Value <= 0x7FFFFFFFFF && Element->Value >= (-0x8000000000)) {
Element->Base.Size = 5;
Element->Base.DataSize = 5;
} else if (Element->Value <= 0x7FFFFFFFFFFF && Element->Value >= (-0x800000000000)) {
Element->Base.Size = 6;
Element->Base.DataSize = 6;
} else if (Element->Value <= 0x7FFFFFFFFFFFFF && Element->Value >= (-0x80000000000000)) {
Element->Base.Size = 7;
Element->Base.DataSize = 7;
} else
Element->Base.Size = 8;
Element->Base.DataSize = 8;
if (Element->Base.DefaultSize > Element->Base.Size) {
Element->Base.Size = Element->Base.DefaultSize;
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
return Element->Base.Size;
return Element->Base.DataSize;
}
static filepos_t UpdateSizeInt(ebml_integer *Element, bool_t bWithDefault, bool_t bForceRender)
......@@ -301,34 +301,34 @@ static filepos_t UpdateSizeInt(ebml_integer *Element, bool_t bWithDefault, bool_
return 0;
if ((uint64_t)Element->Value <= 0xFF) {
Element->Base.Size = 1;
Element->Base.DataSize = 1;
} else if ((uint64_t)Element->Value <= 0xFFFF) {
Element->Base.Size = 2;
Element->Base.DataSize = 2;
} else if ((uint64_t)Element->Value <= 0xFFFFFF) {
Element->Base.Size = 3;
Element->Base.DataSize = 3;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFF) {
Element->Base.Size = 4;
Element->Base.DataSize = 4;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFF) {
Element->Base.Size = 5;
Element->Base.DataSize = 5;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFFFF) {
Element->Base.Size = 6;
Element->Base.DataSize = 6;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFFFFFF) {
Element->Base.Size = 7;
Element->Base.DataSize = 7;
} else
Element->Base.Size = 8;
Element->Base.DataSize = 8;
if (Element->Base.DefaultSize > Element->Base.Size) {
Element->Base.Size = Element->Base.DefaultSize;
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
return Element->Base.Size;
return Element->Base.DataSize;
}
static filepos_t UpdateSizeFloat(ebml_float *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (!bWithDefault && IsDefaultValueFloat(Element))
return 0;
return Element->Base.Size;
return Element->Base.DataSize;
}
static void PostCreateInt(ebml_element *Element)
......
......@@ -45,7 +45,7 @@ err_t EBML_StringSetValue(ebml_string *Element,const char *Value)
free((char*)Element->Buffer);
Element->Buffer = strdup(Value);
Element->Base.bValueIsSet = 1;
Element->Base.Size = strlen(Element->Buffer);
Element->Base.DataSize = strlen(Element->Buffer);
return ERR_NONE;
}
......@@ -65,15 +65,15 @@ static err_t ReadData(ebml_string *Element, stream *Input, const ebml_parser_con
goto failed;
}
Buffer = malloc((size_t)Element->Base.Size+1);
Buffer = malloc((size_t)Element->Base.DataSize+1);
if (!Buffer)
return ERR_OUT_OF_MEMORY;
Result = Stream_Read(Input,Buffer,(size_t)Element->Base.Size,NULL);
Result = Stream_Read(Input,Buffer,(size_t)Element->Base.DataSize,NULL);
if (Result != ERR_NONE)
goto failed;
Buffer[Element->Base.Size] = 0;
Buffer[Element->Base.DataSize] = 0;
Element->Buffer = Buffer;
Element->Base.bValueIsSet = 1;
return ERR_NONE;
......@@ -88,16 +88,16 @@ failed:
static err_t RenderData(ebml_string *Element, stream *Output, bool_t bForceRender, bool_t bWithDefault, filepos_t *Rendered)
{
size_t Written;
err_t Err = Stream_Write(Output,Element->Buffer,(size_t)Element->Base.Size,&Written);
err_t Err = Stream_Write(Output,Element->Buffer,(size_t)Element->Base.DataSize,&Written);
if (Rendered)
*Rendered = Written;
if ((Err == ERR_NONE) && (Element->Base.DefaultSize > (int)Element->Base.Size))
if ((Err == ERR_NONE) && (Element->Base.DefaultSize > (int)Element->Base.DataSize))
{
char *Padding = malloc(Element->Base.DefaultSize - (int)Element->Base.Size);
char *Padding = malloc(Element->Base.DefaultSize - (int)Element->Base.DataSize);
if (!Padding)
return ERR_OUT_OF_MEMORY;
memset(Padding,0,Element->Base.DefaultSize - (int)Element->Base.Size);
Err = Stream_Write(Output,Padding,Element->Base.DefaultSize - (int)Element->Base.Size,&Written);
memset(Padding,0,Element->Base.DefaultSize - (int)Element->Base.DataSize);
Err = Stream_Write(Output,Padding,Element->Base.DefaultSize - (int)Element->Base.DataSize,&Written);
if (Rendered)
*Rendered += Written;
free(Padding);
......@@ -147,13 +147,13 @@ static filepos_t UpdateSize(ebml_string *Element, bool_t bWithDefault, bool_t bF
if (!bWithDefault && EBML_ElementIsDefaultValue(Element))
return 0;
Element->Base.Size = strlen(Element->Buffer);
Element->Base.DataSize = strlen(Element->Buffer);
if (Element->Base.DefaultSize > Element->Base.Size) {
Element->Base.Size = Element->Base.DefaultSize;
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
return Element->Base.Size;
return Element->Base.DataSize;
}
static bool_t IsDefaultValue(const ebml_string *Element)
......
......@@ -39,13 +39,13 @@ static bool_t IsDefaultValue(const ebml_element *Element)
static filepos_t UpdateSize(ebml_element *Element, bool_t bWithDefault, bool_t bForceRender)
{
return Element->Size;
return Element->DataSize;
}
#if defined(CONFIG_EBML_WRITING)
static err_t RenderData(ebml_element *Element, stream *Output, bool_t bForceRender, bool_t bWithDefault, filepos_t *Rendered)
{
size_t Written, Left = Element->Size;
size_t Written, Left = (size_t)Element->DataSize;
err_t Err = ERR_NONE;
uint8_t Buf[2*1024]; // write 2 KB chunks at a time
memset(Buf,0,sizeof(Buf));
......@@ -56,7 +56,7 @@ static err_t RenderData(ebml_element *Element, stream *Output, bool_t bForceRend
Left -= min(Left,sizeof(Buf));
}
if (Rendered)
*Rendered = Element->Size - Left;
*Rendered = Element->DataSize - Left;
return Err;
}
#endif
......@@ -70,10 +70,10 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_END(EBML_ELEMENT_CLASS)
void EBML_VoidSetSize(ebml_element *Void, filepos_t Size)
void EBML_VoidSetSize(ebml_element *Void, filepos_t DataSize)
{
assert(Node_IsPartOf(Void,EBML_VOID_CLASS));
Void->Size = Size;
Void->DataSize = DataSize;
Void->bValueIsSet = 1;
}
......@@ -103,11 +103,11 @@ filepos_t EBML_VoidReplaceWith(ebml_element *Void, ebml_element *ReplacedWith, s
{
filepos_t HeadBefore,HeadAfter;
EBML_VoidSetSize(aTmp, EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) - 1); // 1 is the length of the Void ID
HeadBefore = EBML_ElementFullSize(aTmp,1) - aTmp->Size;
aTmp->Size = aTmp->Size - EBML_CodedSizeLength(aTmp->Size, aTmp->SizeLength, EBML_ElementIsFiniteSize(aTmp));
HeadAfter = EBML_ElementFullSize(aTmp,1) - aTmp->Size;
HeadBefore = EBML_ElementFullSize(aTmp,1) - aTmp->DataSize;
aTmp->DataSize = aTmp->DataSize -