Commit 7e06fea4 authored by Steve Lhomme's avatar Steve Lhomme

libebml2: automatically recompute the size of elements when it's needed, otherwise cache it

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@548 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent f0852dcf
......@@ -116,14 +116,15 @@ struct ebml_parser_context
struct ebml_element
{
nodetree Base;
bool_t bValueIsSet;
bool_t bDefaultIsSet;
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 ?
const ebml_context *Context;
int DefaultSize;
int8_t SizeLength;
boolmem_t bValueIsSet;
boolmem_t bDefaultIsSet;
boolmem_t bNeedDataSizeUpdate;
};
typedef struct ebml_element_vmt
......@@ -136,7 +137,8 @@ typedef struct ebml_element_vmt
#endif
bool_t (*IsDefaultValue)(const void*);
bool_t (*DefaultIsSet)(const void*);
filepos_t (*UpdateSize)(void*, bool_t bWithDefault, bool_t bForceRender);
filepos_t (*UpdateDataSize)(void*, bool_t bWithDefault, bool_t bForceRender);
bool_t (*NeedsDataSizeUpdate)(const void*, bool_t bWithDefault);
int (*Cmp)(const void*, const void*);
ebml_element *(*Copy)(const void*, const void *Cookie);
......@@ -145,13 +147,14 @@ typedef struct ebml_element_vmt
} ebml_element_vmt;
#define EBML_ElementValidateSize(p) VMT_FUNC(p,ebml_element_vmt)->ValidateSize(p)
#define EBML_ElementReadData(p,i,c,d,s,r) VMT_FUNC(p,ebml_element_vmt)->ReadData(p,i,c,d,s,r)
#define EBML_ElementRenderData(p,s,f,k,r) VMT_FUNC(p,ebml_element_vmt)->RenderData(p,s,f,k,r)
#define EBML_ElementIsDefaultValue(p) VMT_FUNC(p,ebml_element_vmt)->IsDefaultValue(p)
#define EBML_ElementUpdateSize(p,k,f) VMT_FUNC(p,ebml_element_vmt)->UpdateSize(p,k,f)
#define EBML_ElementCmp(p,e) VMT_FUNC(p,ebml_element_vmt)->Cmp(p,e)
#define EBML_ElementCopy(p,c) VMT_FUNC(p,ebml_element_vmt)->Copy(p,c)
#define EBML_ElementValidateSize(p) VMT_FUNC(p,ebml_element_vmt)->ValidateSize(p)
#define EBML_ElementReadData(p,i,c,d,s,r) VMT_FUNC(p,ebml_element_vmt)->ReadData(p,i,c,d,s,r)
#define EBML_ElementRenderData(p,s,f,k,r) VMT_FUNC(p,ebml_element_vmt)->RenderData(p,s,f,k,r)
#define EBML_ElementIsDefaultValue(p) VMT_FUNC(p,ebml_element_vmt)->IsDefaultValue(p)
#define EBML_ElementUpdateSize(p,k,f) VMT_FUNC(p,ebml_element_vmt)->UpdateDataSize(p,k,f)
#define EBML_ElementNeedsDataSizeUpdate(p,d) VMT_FUNC(p,ebml_element_vmt)->NeedsDataSizeUpdate(p,d)
#define EBML_ElementCmp(p,e) VMT_FUNC(p,ebml_element_vmt)->Cmp(p,e)
#define EBML_ElementCopy(p,c) VMT_FUNC(p,ebml_element_vmt)->Copy(p,c)
typedef struct ebml_master
{
......@@ -237,8 +240,8 @@ static INLINE filepos_t EBML_ElementPositionEnd(const ebml_element *Element)
}
#if defined(CONFIG_EBML_WRITING)
// TODO: replace the list of bools by flags
EBML_DLL err_t EBML_ElementRender(ebml_element *Element, stream *Output, bool_t bWithDefault, bool_t bKeepPosition, bool_t bForceRender, filepos_t *Rendered, bool_t UpdateSize);
// TODO: replace the list of bools by flags ?
EBML_DLL err_t EBML_ElementRender(ebml_element *Element, stream *Output, bool_t bWithDefault, bool_t bKeepPosition, bool_t bForceRender, filepos_t *Rendered);
EBML_DLL err_t EBML_ElementRenderHead(ebml_element *Element, stream *Output, bool_t bKeepPosition, filepos_t *Rendered);
#endif
......
......@@ -76,15 +76,11 @@ static bool_t IsDefaultValue(const ebml_binary *Element)
return 0; // TODO: a default binary value needs a size too (use a structure to set the value in the structure)
}
static filepos_t UpdateSize(ebml_binary *Element, bool_t bWithDefault, bool_t bForceRender)
static filepos_t UpdateDataSize(ebml_binary *Element, bool_t bWithDefault, bool_t bForceRender)
{
Element->Base.DataSize = ARRAYCOUNT(Element->Data,uint8_t);
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
return Element->Base.DataSize;
return INHERITED(Element,ebml_element_vmt,EBML_BINARY_CLASS)->UpdateDataSize(Element, bWithDefault, bForceRender);
}
static bool_t ValidateSize(const ebml_element *p)
......@@ -104,6 +100,7 @@ static ebml_binary *Copy(const ebml_binary *Element, const void *Cookie)
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
Result->Base.bNeedDataSizeUpdate = Element->Base.bNeedDataSizeUpdate;
}
return Result;
}
......@@ -115,7 +112,7 @@ META_DATA(TYPE_ARRAY,0,ebml_binary,Data)
META_VMT(TYPE_FUNC,ebml_element_vmt,ValidateSize,ValidateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateDataSize,UpdateDataSize)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
......@@ -128,6 +125,7 @@ err_t EBML_BinarySetData(ebml_binary *Element, const uint8_t *Data, size_t DataS
return ERR_OUT_OF_MEMORY;
memcpy(ARRAYBEGIN(Element->Data,void),Data,DataSize);
Element->Base.DataSize = DataSize;
Element->Base.bNeedDataSizeUpdate = 0;
Element->Base.bValueIsSet = 1;
return ERR_NONE;
}
......
......@@ -198,6 +198,7 @@ static ebml_crc *Copy(const ebml_crc *Element, const void *Cookie)
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
Result->Base.bNeedDataSizeUpdate = Element->Base.bNeedDataSizeUpdate;
}
return Result;
}
......@@ -207,15 +208,11 @@ static bool_t IsDefaultValue(const ebml_element *Element)
return 0; // CRC has no default value
}
static filepos_t UpdateSize(ebml_element *Element, bool_t bWithDefault, bool_t bForceRender)
{
Element->DataSize = 4;
return Element->DataSize;
}
static err_t Create(ebml_crc *Element)
{
Element->CRC = CRC32_NEGL;
Element->Base.bNeedDataSizeUpdate = 0;
Element->Base.DataSize = 4;
return ERR_NONE;
}
......@@ -226,7 +223,6 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,ValidateSize,ValidateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,Copy)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
......
......@@ -86,6 +86,7 @@ static void PostCreate(ebml_date *Element)
{
INHERITED(Element,ebml_element_vmt,EBML_DATE_CLASS)->PostCreate(Element);
Element->Base.DefaultSize = 8;
Element->Base.bNeedDataSizeUpdate = 0;
}
META_START(EBMLDate_Class,EBML_DATE_CLASS)
......
......@@ -39,9 +39,34 @@ static void PostCreate(ebml_element *Element)
Element->SizePosition = INVALID_FILEPOS_T;
}
static bool_t NeedsDataSizeUpdate(ebml_element *Element, bool_t bWithDefault)
{
if (!Element->bNeedDataSizeUpdate)
return 0;
if (!bWithDefault && EBML_ElementIsDefaultValue(Element))
return 0;
return 1;
}
static filepos_t UpdateDataSize(ebml_element *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (!bWithDefault && EBML_ElementIsDefaultValue(Element))
return 0;
if (Element->DefaultSize > Element->DataSize)
Element->DataSize = Element->DefaultSize;
Element->bNeedDataSizeUpdate = 0;
#if !defined(NDEBUG)
assert(!EBML_ElementNeedsDataSizeUpdate(Element, bWithDefault));
#endif
return Element->DataSize;
}
static err_t Create(ebml_element *Element)
{
Element->DataSize = INVALID_FILEPOS_T;
Element->bNeedDataSizeUpdate = 1;
return ERR_NONE;
}
......@@ -52,6 +77,8 @@ META_CLASS(FLAGS,CFLAG_ABSTRACT)
META_CLASS(CREATE,Create)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreate)
META_VMT(TYPE_FUNC,ebml_element_vmt,ValidateSize,ValidateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateDataSize,UpdateDataSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,NeedsDataSizeUpdate,NeedsDataSizeUpdate)
META_PARAM(TYPE,EBML_ELEMENT_INFINITESIZE,TYPE_BOOLEAN)
META_DYNAMIC(TYPE_BOOLEAN,EBML_ELEMENT_INFINITESIZE)
......@@ -181,7 +208,7 @@ fourcc_t EBML_BufferToID(const uint8_t *Buffer)
}
#if defined(CONFIG_EBML_WRITING)
err_t EBML_ElementRender(ebml_element *Element, stream *Output, bool_t bWithDefault, bool_t bKeepPosition, bool_t bForceRender, filepos_t *Rendered, bool_t UpdateSize)
err_t EBML_ElementRender(ebml_element *Element, stream *Output, bool_t bWithDefault, bool_t bKeepPosition, bool_t bForceRender, filepos_t *Rendered)
{
err_t Result;
filepos_t _Rendered,WrittenSize;
......@@ -203,11 +230,14 @@ err_t EBML_ElementRender(ebml_element *Element, stream *Output, bool_t bWithDefa
return ERR_INVALID_DATA;
#if !defined(NDEBUG)
SupposedSize =
if (Element->bNeedDataSizeUpdate)
SupposedSize = EBML_ElementUpdateSize(Element, bWithDefault, bForceRender);
else
SupposedSize = Element->DataSize;
#else
if (UpdateSize)
#endif
if (Element->bNeedDataSizeUpdate)
EBML_ElementUpdateSize(Element, bWithDefault, bForceRender);
#endif
Result = EBML_ElementRenderHead(Element, Output, bKeepPosition, &WrittenSize);
*Rendered += WrittenSize;
if (Result != ERR_NONE)
......
......@@ -80,7 +80,10 @@ err_t EBML_MasterAppend(ebml_master *Element, ebml_element *Append)
assert(Node_IsPartOf(Element,EBML_MASTER_CLASS));
Result = NodeTree_SetParent(Append,Element,NULL);
if (Result==ERR_NONE)
{
Element->Base.bNeedDataSizeUpdate = 1;
Element->Base.bValueIsSet = 1;
}
return Result;
}
......@@ -176,37 +179,55 @@ bool_t EBML_MasterCheckMandatory(const ebml_master *Element, bool_t bWithDefault
return 1;
}
static filepos_t UpdateSize(ebml_master *Element, bool_t bWithDefault, bool_t bForceRender)
static bool_t NeedsDataSizeUpdate(ebml_element *Element, bool_t bWithDefault)
{
ebml_element *i;
if (INHERITED(Element,ebml_element_vmt,EBML_MASTER_CLASS)->NeedsDataSizeUpdate(Element, bWithDefault))
return 1;
Element->Base.DataSize = 0;
for (i=EBML_MasterChildren(Element);i;i=EBML_MasterNext(i))
{
if (EBML_ElementNeedsDataSizeUpdate(i,bWithDefault))
return 1;
}
return 0;
}
//if (!EBML_ElementIsFiniteSize((ebml_element*)Element))
// return INVALID_FILEPOS_T;
static filepos_t UpdateDataSize(ebml_master *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (EBML_ElementNeedsDataSizeUpdate(Element, bWithDefault))
{
ebml_element *i;
if (!bForceRender) {
assert(CheckMandatory((ebml_master*)Element, bWithDefault));
}
Element->Base.DataSize = 0;
if (Element->CheckSumStatus)
Element->Base.DataSize += 6;
//if (!EBML_ElementIsFiniteSize((ebml_element*)Element))
// return INVALID_FILEPOS_T;
for (i=EBML_MasterChildren(Element);i;i=EBML_MasterNext(i))
{
if (!bWithDefault && EBML_ElementIsDefaultValue(i))
continue;
EBML_ElementUpdateSize(i,bWithDefault,bForceRender);
if (i->DataSize == INVALID_FILEPOS_T)
return INVALID_FILEPOS_T;
Element->Base.DataSize += EBML_ElementFullSize(i,bWithDefault);
}
if (!bForceRender) {
assert(CheckMandatory((ebml_master*)Element, bWithDefault));
}
if (Element->CheckSumStatus)
Element->Base.DataSize += 6;
for (i=EBML_MasterChildren(Element);i;i=EBML_MasterNext(i))
{
if (!bWithDefault && EBML_ElementIsDefaultValue(i))
continue;
EBML_ElementUpdateSize(i,bWithDefault,bForceRender);
if (i->DataSize == INVALID_FILEPOS_T)
return INVALID_FILEPOS_T;
Element->Base.DataSize += EBML_ElementFullSize(i,bWithDefault);
}
#ifdef TODO
if (bChecksumUsed) {
Element->DataSize += EBML_ElementFullSize(Element->Checksum,bWithDefault);
}
if (bChecksumUsed) {
Element->DataSize += EBML_ElementFullSize(Element->Checksum,bWithDefault);
}
#endif
return Element->Base.DataSize;
}
return INHERITED(Element,ebml_element_vmt,EBML_MASTER_CLASS)->UpdateDataSize(Element, bWithDefault, bForceRender);
}
void EBML_MasterMandatory(ebml_master *Element, bool_t SetDefault)
......@@ -368,11 +389,13 @@ bool_t EBML_MasterUseChecksum(ebml_master *Element, bool_t Use)
{
if (Use && Element->CheckSumStatus==0)
{
Element->Base.bNeedDataSizeUpdate = 1;
Element->CheckSumStatus = 1;
return 1;
}
if (!Use && Element->CheckSumStatus)
{
Element->Base.bNeedDataSizeUpdate = 1;
Element->CheckSumStatus = 0;
return 1;
}
......@@ -394,7 +417,7 @@ static err_t InternalRender(ebml_master *Element, stream *Output, bool_t bForceR
{
if (!bWithDefault && EBML_ElementIsDefaultValue(i))
continue;
Err = EBML_ElementRender(i,Output, bWithDefault, 0, bForceRender, &ItemRendered,0);
Err = EBML_ElementRender(i,Output, bWithDefault, 0, bForceRender, &ItemRendered);
if (Err!=ERR_NONE)
return Err;
*Rendered += ItemRendered;
......@@ -449,7 +472,7 @@ static err_t RenderData(ebml_master *Element, stream *Output, bool_t bForceRende
filepos_t CrcSize;
EBML_CRCAddBuffer(CrcElt, ARRAYBEGIN(TmpBuf,uint8_t), ARRAYCOUNT(TmpBuf,uint8_t));
EBML_CRCFinalize(CrcElt);
Err = EBML_ElementRender((ebml_element*)CrcElt, Output, bWithDefault, 0, bForceRender, &CrcSize, 0);
Err = EBML_ElementRender((ebml_element*)CrcElt, Output, bWithDefault, 0, bForceRender, &CrcSize);
if (Err==ERR_NONE)
{
size_t Written;
......@@ -474,7 +497,7 @@ static err_t RenderData(ebml_master *Element, stream *Output, bool_t bForceRende
EBML_CRCAddBuffer(CrcElt, Data + (VirtualPos - CrcSize), (size_t)Element->Base.DataSize-6);
EBML_CRCFinalize(CrcElt);
Stream_Seek(Output,EBML_ElementPositionData((ebml_element*)Element),SEEK_SET);
Err = EBML_ElementRender((ebml_element*)CrcElt, Output, bWithDefault, 0, bForceRender, &CrcSize, 0);
Err = EBML_ElementRender((ebml_element*)CrcElt, Output, bWithDefault, 0, bForceRender, &CrcSize);
*Rendered = *Rendered + CrcSize;
Stream_Seek(Output,EBML_ElementPositionEnd((ebml_element*)Element),SEEK_SET);
}
......@@ -502,6 +525,7 @@ static ebml_element *Copy(const ebml_master *Element, const void *Cookie)
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
Result->Base.bNeedDataSizeUpdate = Element->Base.bNeedDataSizeUpdate;
Result->CheckSumStatus = Element->CheckSumStatus;
for (i=EBML_MasterChildren(Element);i;i=EBML_MasterNext(i))
{
......@@ -521,7 +545,8 @@ META_START(EBMLMaster_Class,EBML_MASTER_CLASS)
META_CLASS(SIZE,sizeof(ebml_master))
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreate)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateDataSize,UpdateDataSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,NeedsDataSizeUpdate,NeedsDataSizeUpdate)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,Copy)
#if defined(CONFIG_EBML_WRITING)
......
......@@ -268,67 +268,52 @@ static bool_t IsDefaultValueFloat(const ebml_float *Element)
static filepos_t UpdateSizeSignedInt(ebml_integer *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (!bWithDefault && IsDefaultValueInt(Element))
return 0;
if (Element->Value <= 0x7F && Element->Value >= (-0x80)) {
Element->Base.DataSize = 1;
} else if (Element->Value <= 0x7FFF && Element->Value >= (-0x8000)) {
Element->Base.DataSize = 2;
} else if (Element->Value <= 0x7FFFFF && Element->Value >= (-0x800000)) {
Element->Base.DataSize = 3;
} else if (Element->Value <= (int64_t)(0x7FFFFFFF) && Element->Value >= (int64_t)(-0x80000000)) {
Element->Base.DataSize = 4;
} else if (Element->Value <= 0x7FFFFFFFFF && Element->Value >= (-0x8000000000)) {
Element->Base.DataSize = 5;
} else if (Element->Value <= 0x7FFFFFFFFFFF && Element->Value >= (-0x800000000000)) {
Element->Base.DataSize = 6;
} else if (Element->Value <= 0x7FFFFFFFFFFFFF && Element->Value >= (-0x80000000000000)) {
Element->Base.DataSize = 7;
} else
Element->Base.DataSize = 8;
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
if (EBML_ElementNeedsDataSizeUpdate(Element, bWithDefault))
{
if (Element->Value <= 0x7F && Element->Value >= (-0x80)) {
Element->Base.DataSize = 1;
} else if (Element->Value <= 0x7FFF && Element->Value >= (-0x8000)) {
Element->Base.DataSize = 2;
} else if (Element->Value <= 0x7FFFFF && Element->Value >= (-0x800000)) {
Element->Base.DataSize = 3;
} else if (Element->Value <= (int64_t)(0x7FFFFFFF) && Element->Value >= (int64_t)(-0x80000000)) {
Element->Base.DataSize = 4;
} else if (Element->Value <= 0x7FFFFFFFFF && Element->Value >= (-0x8000000000)) {
Element->Base.DataSize = 5;
} else if (Element->Value <= 0x7FFFFFFFFFFF && Element->Value >= (-0x800000000000)) {
Element->Base.DataSize = 6;
} else if (Element->Value <= 0x7FFFFFFFFFFFFF && Element->Value >= (-0x80000000000000)) {
Element->Base.DataSize = 7;
} else
Element->Base.DataSize = 8;
}
return Element->Base.DataSize;
return INHERITED(Element,ebml_element_vmt,EBML_SINTEGER_CLASS)->UpdateDataSize(Element, bWithDefault, bForceRender);
}
static filepos_t UpdateSizeInt(ebml_integer *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (!bWithDefault && IsDefaultValueInt(Element))
return 0;
if ((uint64_t)Element->Value <= 0xFF) {
Element->Base.DataSize = 1;
} else if ((uint64_t)Element->Value <= 0xFFFF) {
Element->Base.DataSize = 2;
} else if ((uint64_t)Element->Value <= 0xFFFFFF) {
Element->Base.DataSize = 3;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFF) {
Element->Base.DataSize = 4;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFF) {
Element->Base.DataSize = 5;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFFFF) {
Element->Base.DataSize = 6;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFFFFFF) {
Element->Base.DataSize = 7;
} else
Element->Base.DataSize = 8;
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
return Element->Base.DataSize;
}
if (EBML_ElementNeedsDataSizeUpdate(Element, bWithDefault))
{
if ((uint64_t)Element->Value <= 0xFF) {
Element->Base.DataSize = 1;
} else if ((uint64_t)Element->Value <= 0xFFFF) {
Element->Base.DataSize = 2;
} else if ((uint64_t)Element->Value <= 0xFFFFFF) {
Element->Base.DataSize = 3;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFF) {
Element->Base.DataSize = 4;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFF) {
Element->Base.DataSize = 5;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFFFF) {
Element->Base.DataSize = 6;
} else if ((uint64_t)Element->Value <= 0xFFFFFFFFFFFFFF) {
Element->Base.DataSize = 7;
} else
Element->Base.DataSize = 8;
}
static filepos_t UpdateSizeFloat(ebml_float *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (!bWithDefault && IsDefaultValueFloat(Element))
return 0;
return Element->Base.DataSize;
return INHERITED(Element,ebml_element_vmt,EBML_INTEGER_CLASS)->UpdateDataSize(Element, bWithDefault, bForceRender);
}
static void PostCreateInt(ebml_element *Element)
......@@ -370,6 +355,7 @@ static ebml_integer *CopyInt(const ebml_integer *Element, const void *Cookie)
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
Result->Base.bNeedDataSizeUpdate = Element->Base.bNeedDataSizeUpdate;
}
return Result;
}
......@@ -386,6 +372,7 @@ static ebml_float *CopyFloat(const ebml_float *Element, const void *Cookie)
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
Result->Base.bNeedDataSizeUpdate = Element->Base.bNeedDataSizeUpdate;
}
return Result;
}
......@@ -398,7 +385,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadDataInt)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderDataInt)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSizeInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateDataSize,UpdateSizeInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,CopyInt)
META_END_CONTINUE(EBML_ELEMENT_CLASS)
......@@ -411,7 +398,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadDataSignedInt)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderDataSignedInt)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSizeSignedInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateDataSize,UpdateSizeSignedInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateSignedInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,Copy,CopyInt)
META_END_CONTINUE(EBML_ELEMENT_CLASS)
......@@ -425,7 +412,6 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValueFloat)
META_VMT(TYPE_FUNC,ebml_element_vmt,ValidateSize,ValidateSizeFloat)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadDataFloat)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateFloat)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSizeFloat)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderDataFloat)
#endif
......@@ -436,5 +422,6 @@ err_t EBML_IntegerSetValue(ebml_integer *Element, int64_t Value)
{
Element->Value = Value;
Element->Base.bValueIsSet = 1;
Element->Base.bNeedDataSizeUpdate = 1;
return ERR_NONE;
}
\ No newline at end of file
......@@ -46,6 +46,7 @@ err_t EBML_StringSetValue(ebml_string *Element,const char *Value)
Element->Buffer = strdup(Value);
Element->Base.bValueIsSet = 1;
Element->Base.DataSize = strlen(Element->Buffer);
Element->Base.bNeedDataSizeUpdate = 0;
return ERR_NONE;
}
......@@ -160,18 +161,20 @@ static void Delete(ebml_string *p)
free((char*)p->Buffer);
}
static filepos_t UpdateSize(ebml_string *Element, bool_t bWithDefault, bool_t bForceRender)
static filepos_t UpdateDataSize(ebml_string *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (!bWithDefault && EBML_ElementIsDefaultValue(Element))
return 0;
if (EBML_ElementNeedsDataSizeUpdate(Element, bWithDefault))
Element->Base.DataSize = strlen(Element->Buffer);
Element->Base.DataSize = strlen(Element->Buffer);
return INHERITED(Element,ebml_element_vmt,EBML_STRING_CLASS)->UpdateDataSize(Element, bWithDefault, bForceRender);
}
if (Element->Base.DefaultSize > Element->Base.DataSize) {
Element->Base.DataSize = Element->Base.DefaultSize;
}
static filepos_t UpdateDataSizeUni(ebml_string *Element, bool_t bWithDefault, bool_t bForceRender)
{
if (EBML_ElementNeedsDataSizeUpdate(Element, bWithDefault))
Element->Base.DataSize = strlen(Element->Buffer);
return Element->Base.DataSize;
return INHERITED(Element,ebml_element_vmt,EBML_UNISTRING_CLASS)->UpdateDataSize(Element, bWithDefault, bForceRender);
}
static bool_t IsDefaultValue(const ebml_string *Element)
......@@ -211,6 +214,7 @@ static ebml_string *Copy(const ebml_string *Element, const void *Cookie)
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
Result->Base.SizePosition = Element->Base.SizePosition;
Result->Base.bNeedDataSizeUpdate = Element->Base.bNeedDataSizeUpdate;
}
return Result;
}
......@@ -220,7 +224,7 @@ META_CLASS(SIZE,sizeof(ebml_string))
META_CLASS(DELETE,Delete)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateDataSize,UpdateDataSize)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
......@@ -233,7 +237,7 @@ META_CLASS(SIZE,sizeof(ebml_string))
META_CLASS(DELETE,Delete)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateDataSize,UpdateDataSizeUni)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
......
......@@ -32,11 +32,6 @@ static bool_t IsDefaultValue(const ebml_element *Element)
return 0;
}
static filepos_t UpdateSize(ebml_element *Element, bool_t bWithDefault, bool_t bForceRender)
{
return Element->DataSize;
}
static err_t ReadData(ebml_element *Element, stream *Input, const ebml_parser_context *ParserContext, bool_t AllowDummyElt, int Scope, size_t DepthCheckCRC)
{
EBML_ElementSkipData(Element,Input,ParserContext,NULL,AllowDummyElt);
......@@ -73,13 +68,13 @@ static ebml_element *Copy(const ebml_element *Element, const void *Cookie)
Result->ElementPosition = Element->ElementPosition;
Result->SizeLength = Element->SizeLength;
Result->SizePosition = Element->SizePosition;
Result->bNeedDataSizeUpdate = Element->bNeedDataSizeUpdate;
}
return Result;
}
META_START(EBMLVoid_Class,EBML_VOID_CLASS)
META_VMT(TYPE_FUNC,ebml_element_vmt,IsDefaultValue,IsDefaultValue)
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadData)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
......@@ -93,6 +88,7 @@ void EBML_VoidSetSize(ebml_element *Void, filepos_t DataSize)
assert(Node_IsPartOf(Void,EBML_VOID_CLASS));
Void->DataSize = DataSize;
Void->bValueIsSet = 1;
Void->bNeedDataSizeUpdate = 0;
}
filepos_t EBML_VoidReplaceWith(ebml_element *Void, ebml_element *ReplacedWith, stream *Output, bool_t ComeBackAfterward, bool_t bWithDefault)
......@@ -111,7 +107,7 @@ filepos_t EBML_VoidReplaceWith(ebml_element *Void, ebml_element *ReplacedWith, s
CurrentPosition = Stream_Seek(Output,0,SEEK_CUR);
Stream_Seek(Output,Void->ElementPosition,SEEK_SET);
EBML_ElementRender(ReplacedWith,Output,bWithDefault,0,1,NULL,0);
EBML_ElementRender(ReplacedWith,Output,bWithDefault,0,1,NULL);
if (EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) > 1)
{
......
......@@ -3,7 +3,7 @@
GROUP ebml2_group
{
PROJECT_NAME "libebml2"
PROJECT_VERSION 0.11.1
PROJECT_VERSION 0.12.0
PROJECT_VENDOR "Matroska Foundation"
EXPDEFINE HAS_EBML2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment