Commit f49c6848 authored by Steve Lhomme's avatar Steve Lhomme

libebml2: better handling of default values

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@618 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent 464a29ac
......@@ -117,7 +117,7 @@ typedef struct ebml_element_vmt
ebml_element *(*Copy)(const void*, const void *Cookie);
// internal call only
void (*PostCreate)(void*);
void (*PostCreate)(void*, bool_t SetDefault);
} ebml_element_vmt;
......
......@@ -72,7 +72,6 @@ struct ebml_element
int DefaultSize;
int8_t SizeLength;
boolmem_t bValueIsSet;
boolmem_t bDefaultIsSet;
boolmem_t bNeedDataSizeUpdate;
};
......
......@@ -96,7 +96,6 @@ static ebml_binary *Copy(const ebml_binary *Element, const void *Cookie)
{
ArrayCopy(&Result->Data,&Element->Data);
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
......
......@@ -194,7 +194,6 @@ static ebml_crc *Copy(const ebml_crc *Element, const void *Cookie)
{
Result->CRC = Element->CRC;
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
......
......@@ -83,9 +83,9 @@ failed:
return Result;
}
static void PostCreate(ebml_date *Element)
static void PostCreate(ebml_date *Element, bool_t SetDefault)
{
INHERITED(Element,ebml_element_vmt,EBML_DATE_CLASS)->PostCreate(Element);
INHERITED(Element,ebml_element_vmt,EBML_DATE_CLASS)->PostCreate(Element, SetDefault);
Element->Base.DefaultSize = 8;
Element->Base.bNeedDataSizeUpdate = 0;
}
......
......@@ -33,7 +33,7 @@ static bool_t ValidateSize(const ebml_element *p)
return 1;
}
static void PostCreate(ebml_element *Element)
static void PostCreate(ebml_element *Element, bool_t SetDefault)
{
Element->DefaultSize = -1;
Element->ElementPosition = INVALID_FILEPOS_T;
......@@ -282,10 +282,10 @@ err_t EBML_ElementRender(ebml_element *Element, stream *Output, bool_t bWithDefa
Rendered = &_Rendered;
*Rendered = 0;
assert(Element->bValueIsSet || (bWithDefault && Element->bDefaultIsSet)); // an element is been rendered without a value set !!!
assert(Element->bValueIsSet || (bWithDefault && EBML_ElementIsDefaultValue(Element))); // an element is been rendered without a value set !!!
// it may be a mandatory element without a default value
if (!(Element->bValueIsSet || (bWithDefault && Element->bDefaultIsSet)))
if (!(Element->bValueIsSet || (bWithDefault && EBML_ElementIsDefaultValue(Element))))
return ERR_INVALID_DATA;
if (!bWithDefault && EBML_ElementIsDefaultValue(Element))
......
......@@ -216,13 +216,12 @@ ebml_element *EBML_ElementCreate(anynode *Any, const ebml_context *Context, bool
if (Result!=NULL)
{
Result->Context = Context;
Result->bDefaultIsSet = (SetDefault && Context->HasDefault);
#if defined(EBML_LEGACY_API)
assert(Context->PostCreate); // for projects with legacy access
#endif
if (Context->PostCreate)
Context->PostCreate(Result,Cookie);
VMT_FUNC(Result,ebml_element_vmt)->PostCreate(Result);
VMT_FUNC(Result,ebml_element_vmt)->PostCreate(Result, SetDefault);
}
return Result;
}
......
......@@ -241,10 +241,14 @@ void EBML_MasterAddMandatory(ebml_master *Element, bool_t SetDefault)
}
}
static void PostCreate(ebml_master *Element)
static void PostCreate(ebml_master *Element, bool_t SetDefault)
{
INHERITED(Element,ebml_element_vmt,EBML_MASTER_CLASS)->PostCreate(Element);
EBML_MasterAddMandatory(Element,1); // TODO: should it force the default value ?
INHERITED(Element,ebml_element_vmt,EBML_MASTER_CLASS)->PostCreate(Element, SetDefault);
if (SetDefault)
{
EBML_MasterAddMandatory(Element, SetDefault);
Element->Base.bValueIsSet = 1;
}
}
static err_t ReadData(ebml_master *Element, stream *Input, const ebml_parser_context *ParserContext, bool_t AllowDummyElt, int Scope, size_t DepthCheckCRC)
......@@ -522,7 +526,6 @@ static ebml_element *Copy(const ebml_master *Element, const void *Cookie)
{
EBML_MasterErase(Result); // delete the children elements created by default
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
......
......@@ -318,31 +318,28 @@ static filepos_t UpdateSizeInt(ebml_integer *Element, bool_t bWithDefault, bool_
return INHERITED(Element,ebml_element_vmt,EBML_INTEGER_CLASS)->UpdateDataSize(Element, bWithDefault, bForceRender);
}
static void PostCreateInt(ebml_element *Element)
static void PostCreateInt(ebml_element *Element, bool_t SetDefault)
{
INHERITED(Element,ebml_element_vmt,EBML_INTEGER_CLASS)->PostCreate(Element);
INHERITED(Element,ebml_element_vmt,EBML_INTEGER_CLASS)->PostCreate(Element, SetDefault);
Element->DefaultSize = 1;
if (Element->bDefaultIsSet)
if (SetDefault && Element->Context->HasDefault)
EBML_IntegerSetValue((ebml_integer*)Element, Element->Context->DefaultValue);
}
static void PostCreateSignedInt(ebml_element *Element)
static void PostCreateSignedInt(ebml_element *Element, bool_t SetDefault)
{
INHERITED(Element,ebml_element_vmt,EBML_SINTEGER_CLASS)->PostCreate(Element);
INHERITED(Element,ebml_element_vmt,EBML_SINTEGER_CLASS)->PostCreate(Element, SetDefault);
Element->DefaultSize = 1;
if (Element->bDefaultIsSet)
if (SetDefault && Element->Context->HasDefault)
EBML_IntegerSetValue((ebml_integer*)Element, Element->Context->DefaultValue);
}
static void PostCreateFloat(ebml_element *Element)
static void PostCreateFloat(ebml_element *Element, bool_t SetDefault)
{
INHERITED(Element,ebml_element_vmt,EBML_FLOAT_CLASS)->PostCreate(Element);
INHERITED(Element,ebml_element_vmt,EBML_FLOAT_CLASS)->PostCreate(Element, SetDefault);
Element->DefaultSize = 4;
if (Element->bDefaultIsSet)
{
Element->bValueIsSet = 1;
((ebml_float*)Element)->Value = Element->Context->DefaultValue;
}
if (SetDefault && Element->Context->HasDefault)
EBML_FloatSetValue((ebml_float*)Element, Element->Context->DefaultValue);
}
static ebml_integer *CopyInt(const ebml_integer *Element, const void *Cookie)
......@@ -352,7 +349,6 @@ static ebml_integer *CopyInt(const ebml_integer *Element, const void *Cookie)
{
Result->Value = Element->Value;
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
......@@ -369,7 +365,6 @@ static ebml_float *CopyFloat(const ebml_float *Element, const void *Cookie)
{
Result->Value = Element->Value;
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
......
......@@ -183,24 +183,18 @@ static bool_t IsDefaultValue(const ebml_string *Element)
return Element->Base.Context->HasDefault && (!Element->Base.bValueIsSet || strcmp(Element->Buffer,(const char*)Element->Base.Context->DefaultValue)==0);
}
static void PostCreateString(ebml_element *Element)
static void PostCreateString(ebml_element *Element, bool_t SetDefault)
{
INHERITED(Element,ebml_element_vmt,EBML_STRING_CLASS)->PostCreate(Element);
if (Element->bDefaultIsSet)
{
Element->bValueIsSet = 1;
((ebml_string*)Element)->Buffer = strdup((const char *)Element->Context->DefaultValue);
}
INHERITED(Element,ebml_element_vmt,EBML_STRING_CLASS)->PostCreate(Element, SetDefault);
if (SetDefault && Element->Context->HasDefault)
EBML_StringSetValue((ebml_string*)Element, (const char *)Element->Context->DefaultValue);
}
static void PostCreateUniString(ebml_element *Element)
static void PostCreateUniString(ebml_element *Element, bool_t SetDefault)
{
INHERITED(Element,ebml_element_vmt,EBML_UNISTRING_CLASS)->PostCreate(Element);
if (Element->bDefaultIsSet)
{
Element->bValueIsSet = 1;
((ebml_string*)Element)->Buffer = strdup((const char *)Element->Context->DefaultValue);
}
INHERITED(Element,ebml_element_vmt,EBML_UNISTRING_CLASS)->PostCreate(Element, SetDefault);
if (SetDefault && Element->Context->HasDefault)
EBML_StringSetValue((ebml_string*)Element, (const char *)Element->Context->DefaultValue);
}
static ebml_string *Copy(const ebml_string *Element, const void *Cookie)
......@@ -210,7 +204,6 @@ static ebml_string *Copy(const ebml_string *Element, const void *Cookie)
{
Result->Buffer = strdup(Element->Buffer);
Result->Base.bValueIsSet = Element->Base.bValueIsSet;
Result->Base.bDefaultIsSet = Element->Base.bDefaultIsSet;
Result->Base.DataSize = Element->Base.DataSize;
Result->Base.ElementPosition = Element->Base.ElementPosition;
Result->Base.SizeLength = Element->Base.SizeLength;
......
......@@ -64,7 +64,6 @@ static ebml_element *Copy(const ebml_element *Element, const void *Cookie)
if (Result)
{
Result->bValueIsSet = Element->bValueIsSet;
Result->bDefaultIsSet = Element->bDefaultIsSet;
Result->DataSize = Element->DataSize;
Result->ElementPosition = Element->ElementPosition;
Result->SizeLength = Element->SizeLength;
......
......@@ -3,6 +3,7 @@ version 0.7.0:
- fix an incorrect element size computing when invalid data was read
- allow StereoMode for WebM
- adjust the timecodescale automatically if it's too small
- better handling of default values
- internal code shuffling
- make the regression test tool compile under UNIX
......
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