Commit 1ffff59a authored by Steve Lhomme's avatar Steve Lhomme

fix the EOL style of C/C++/header files

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@125 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent 784c28b9
/*
* $Id: ebmlbinary.c 1319 2008-09-19 16:08:57Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
static err_t ReadData(ebml_binary *Element, stream *Input, const ebml_parser_context *ParserContext, bool_t AllowDummyElt, int Scope)
{
err_t Result;
Element->Base.bValueIsSet = 0;
if (Scope == SCOPE_NO_DATA)
return ERR_NONE;
if (Stream_Seek(Input,EBML_ElementPositionData((ebml_element*)Element),SEEK_SET)==INVALID_FILEPOS_T)
{
Result = ERR_READ;
goto failed;
}
if (!ArrayResize(&Element->Data,(size_t)Element->Base.Size,0))
{
Result = ERR_OUT_OF_MEMORY;
goto failed;
}
Result = Stream_Read(Input,ARRAYBEGIN(Element->Data,void),(size_t)Element->Base.Size,NULL);
if (Result == ERR_NONE)
Element->Base.bValueIsSet = 1;
failed:
return Result;
}
#if defined(CONFIG_EBML_WRITING)
static err_t RenderData(ebml_binary *Element, stream *Output, bool_t bForceRender, bool_t bWithDefault, filepos_t *Rendered)
{
size_t Written;
err_t Err = Stream_Write(Output,ARRAYBEGIN(Element->Data,uint8_t),ARRAYCOUNT(Element->Data,uint8_t),&Written);
if (Rendered)
*Rendered = Written;
return Err;
}
#endif
err_t EBML_BinarySetData(ebml_binary *Element, const uint8_t *Data, size_t DataSize)
{
if (!ArrayResize(&Element->Data,DataSize,0))
return ERR_OUT_OF_MEMORY;
memcpy(ARRAYBEGIN(Element->Data,void),Data,DataSize);
Element->Base.bValueIsSet = 1;
return ERR_NONE;
}
static void Delete(ebml_binary *Element)
{
ArrayClear(&Element->Data);
}
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)
{
Element->Base.Size = ARRAYCOUNT(Element->Data,uint8_t);
if (Element->Base.DefaultSize > Element->Base.Size) {
Element->Base.Size = Element->Base.DefaultSize;
}
return Element->Base.Size;
}
META_START(EBMLBinary_Class,EBML_BINARY_CLASS)
META_CLASS(SIZE,sizeof(ebml_binary))
META_CLASS(DELETE,Delete)
META_DATA(TYPE_ARRAY,0,ebml_binary,Data)
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)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_END(EBML_ELEMENT_CLASS)
/*
* $Id: ebmlbinary.c 1319 2008-09-19 16:08:57Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
static err_t ReadData(ebml_binary *Element, stream *Input, const ebml_parser_context *ParserContext, bool_t AllowDummyElt, int Scope)
{
err_t Result;
Element->Base.bValueIsSet = 0;
if (Scope == SCOPE_NO_DATA)
return ERR_NONE;
if (Stream_Seek(Input,EBML_ElementPositionData((ebml_element*)Element),SEEK_SET)==INVALID_FILEPOS_T)
{
Result = ERR_READ;
goto failed;
}
if (!ArrayResize(&Element->Data,(size_t)Element->Base.Size,0))
{
Result = ERR_OUT_OF_MEMORY;
goto failed;
}
Result = Stream_Read(Input,ARRAYBEGIN(Element->Data,void),(size_t)Element->Base.Size,NULL);
if (Result == ERR_NONE)
Element->Base.bValueIsSet = 1;
failed:
return Result;
}
#if defined(CONFIG_EBML_WRITING)
static err_t RenderData(ebml_binary *Element, stream *Output, bool_t bForceRender, bool_t bWithDefault, filepos_t *Rendered)
{
size_t Written;
err_t Err = Stream_Write(Output,ARRAYBEGIN(Element->Data,uint8_t),ARRAYCOUNT(Element->Data,uint8_t),&Written);
if (Rendered)
*Rendered = Written;
return Err;
}
#endif
err_t EBML_BinarySetData(ebml_binary *Element, const uint8_t *Data, size_t DataSize)
{
if (!ArrayResize(&Element->Data,DataSize,0))
return ERR_OUT_OF_MEMORY;
memcpy(ARRAYBEGIN(Element->Data,void),Data,DataSize);
Element->Base.bValueIsSet = 1;
return ERR_NONE;
}
static void Delete(ebml_binary *Element)
{
ArrayClear(&Element->Data);
}
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)
{
Element->Base.Size = ARRAYCOUNT(Element->Data,uint8_t);
if (Element->Base.DefaultSize > Element->Base.Size) {
Element->Base.Size = Element->Base.DefaultSize;
}
return Element->Base.Size;
}
META_START(EBMLBinary_Class,EBML_BINARY_CLASS)
META_CLASS(SIZE,sizeof(ebml_binary))
META_CLASS(DELETE,Delete)
META_DATA(TYPE_ARRAY,0,ebml_binary,Data)
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)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_END(EBML_ELEMENT_CLASS)
/*
* $Id: ebmlcrc.c 1311 2008-08-24 08:45:24Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
static bool_t ValidateSize(ebml_element *p)
{
return (p->Size == 4);
}
META_START(EBMLCRC_Class,EBML_CRC_CLASS)
META_VMT(TYPE_FUNC,ebml_element_vmt,ValidateSize,ValidateSize)
META_END(EBML_ELEMENT_CLASS)
/*
* $Id: ebmlcrc.c 1311 2008-08-24 08:45:24Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
static bool_t ValidateSize(ebml_element *p)
{
return (p->Size == 4);
}
META_START(EBMLCRC_Class,EBML_CRC_CLASS)
META_VMT(TYPE_FUNC,ebml_element_vmt,ValidateSize,ValidateSize)
META_END(EBML_ELEMENT_CLASS)
/*
* $Id: ebmldate.c 1319 2008-09-19 16:08:57Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
datetime_t EBML_DateTime(const ebml_date *Element)
{
assert(Node_IsPartOf(Element,EBML_DATE_CLASS));
if (!Element->Base.bValueIsSet)
return 0;
return (datetime_t)Scale32(Element->Value,1,1000000000); // nanoseconds to seconds
}
err_t EBML_DateSetDateTime(ebml_date *Element, datetime_t Date)
{
if (Date == INVALID_DATETIME_T)
return ERR_INVALID_PARAM;
Element->Value = Scale64(Date,1000000000,1); // seconds to nanoseconds
Element->Base.bValueIsSet = 1;
return ERR_NONE;
}
static bool_t ValidateSize(ebml_element *p)
{
return (p->Size == 8 || p->Size == 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;
uint8_t Value[8];
Element->Base.bValueIsSet = 0;
if (Scope == SCOPE_NO_DATA)
return ERR_NONE;
if (Stream_Seek(Input,EBML_ElementPositionData((ebml_element*)Element),SEEK_SET)==INVALID_FILEPOS_T)
{
Result = ERR_READ;
goto failed;
}
assert(Element->Base.Size<=8);
Result = Stream_Read(Input,Value,(size_t)Element->Base.Size,NULL);
if (Result != ERR_NONE)
goto failed;
#ifdef IS_BIG_ENDIAN
memcpy(&Element->Value,Value,Element->Base.Size);
#else
Element->Value = 0;
for (Size=0;Size<Element->Base.Size;++Size)
((uint8_t*)&Element->Value)[Size] = Value[Element->Base.Size-Size-1];
#endif
Element->Base.bValueIsSet = 1;
failed:
return Result;
}
static void PostCreate(ebml_date *Element)
{
INHERITED(Element,ebml_element_vmt,EBML_DATE_CLASS)->PostCreate(Element);
Element->Base.DefaultSize = 8;
}
META_START(EBMLDate_Class,EBML_DATE_CLASS)
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,ReadData,ReadData)
META_END(EBML_SINTEGER_CLASS)
/*
* $Id: ebmldate.c 1319 2008-09-19 16:08:57Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
datetime_t EBML_DateTime(const ebml_date *Element)
{
assert(Node_IsPartOf(Element,EBML_DATE_CLASS));
if (!Element->Base.bValueIsSet)
return 0;
return (datetime_t)Scale32(Element->Value,1,1000000000); // nanoseconds to seconds
}
err_t EBML_DateSetDateTime(ebml_date *Element, datetime_t Date)
{
if (Date == INVALID_DATETIME_T)
return ERR_INVALID_PARAM;
Element->Value = Scale64(Date,1000000000,1); // seconds to nanoseconds
Element->Base.bValueIsSet = 1;
return ERR_NONE;
}
static bool_t ValidateSize(ebml_element *p)
{
return (p->Size == 8 || p->Size == 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;
uint8_t Value[8];
Element->Base.bValueIsSet = 0;
if (Scope == SCOPE_NO_DATA)
return ERR_NONE;
if (Stream_Seek(Input,EBML_ElementPositionData((ebml_element*)Element),SEEK_SET)==INVALID_FILEPOS_T)
{
Result = ERR_READ;
goto failed;
}
assert(Element->Base.Size<=8);
Result = Stream_Read(Input,Value,(size_t)Element->Base.Size,NULL);
if (Result != ERR_NONE)
goto failed;
#ifdef IS_BIG_ENDIAN
memcpy(&Element->Value,Value,Element->Base.Size);
#else
Element->Value = 0;
for (Size=0;Size<Element->Base.Size;++Size)
((uint8_t*)&Element->Value)[Size] = Value[Element->Base.Size-Size-1];
#endif
Element->Base.bValueIsSet = 1;
failed:
return Result;
}
static void PostCreate(ebml_date *Element)
{
INHERITED(Element,ebml_element_vmt,EBML_DATE_CLASS)->PostCreate(Element);
Element->Base.DefaultSize = 8;
}
META_START(EBMLDate_Class,EBML_DATE_CLASS)
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,ReadData,ReadData)
META_END(EBML_SINTEGER_CLASS)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* $Id: ebmlcrc.c 1311 2008-08-24 08:45:24Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
static err_t Create(ebml_element *p)
{
return ERR_NONE;
}
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->Size;
}
#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;
err_t Err = ERR_NONE;
uint8_t Buf[2*1024]; // write 2 KB chunks at a time
memset(Buf,0,sizeof(Buf));
while (Err==ERR_NONE && Left)
{
Err = Stream_Write(Output,Buf,min(Left,sizeof(Buf)),&Written);
if (Err == ERR_NONE)
Left -= min(Left,sizeof(Buf));
}
if (Rendered)
*Rendered = Element->Size - Left;
return Err;
}
#endif
META_START(EBMLVoid_Class,EBML_VOID_CLASS)
META_CLASS(CREATE,Create)
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
META_END(EBML_ELEMENT_CLASS)
void EBML_VoidSetSize(ebml_element *Void, filepos_t Size)
{
assert(Node_IsPartOf(Void,EBML_VOID_CLASS));
Void->Size = Size;
Void->bValueIsSet = 1;
}
filepos_t EBML_VoidReplaceWith(ebml_element *Void, ebml_element *ReplacedWith, stream *Output, bool_t ComeBackAfterward, bool_t bWithDefault)
{
filepos_t CurrentPosition;
assert(Node_IsPartOf(Void,EBML_VOID_CLASS));
EBML_ElementUpdateSize(ReplacedWith,bWithDefault,0);
if (EBML_ElementFullSize(Void,1) < EBML_ElementFullSize(ReplacedWith,1))
// the element can't be written here !
return INVALID_FILEPOS_T;
if (EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) == 1)
// there is not enough space to put a filling element
return INVALID_FILEPOS_T;
CurrentPosition = Stream_Seek(Output,0,SEEK_CUR);
Stream_Seek(Output,Void->ElementPosition,SEEK_SET);
EBML_ElementRender(ReplacedWith,Output,bWithDefault,0,1,NULL);
if (EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) > 1)
{
// fill the rest with another void element
ebml_element *aTmp = EBML_ElementCreate(Void,Void->Context,0,NULL);
if (aTmp)
{
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;
if (HeadBefore != HeadAfter)
aTmp->SizeLength = (int8_t)(EBML_CodedSizeLength(aTmp->Size, aTmp->SizeLength, EBML_ElementIsFiniteSize(aTmp)) - (HeadAfter - HeadBefore));
EBML_ElementRenderHead(aTmp,Output,0,NULL);
NodeDelete((node*)aTmp);
}
}
if (ComeBackAfterward)
Stream_Seek(Output,CurrentPosition,SEEK_SET);
return EBML_ElementFullSize(Void,1);
}
/*
* $Id: ebmlcrc.c 1311 2008-08-24 08:45:24Z robux4 $
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Matroska Foundation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY The Matroska Foundation ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ebml/ebml.h"
static err_t Create(ebml_element *p)
{
return ERR_NONE;
}
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->Size;
}
#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;
err_t Err = ERR_NONE;
uint8_t Buf[2*1024]; // write 2 KB chunks at a time
memset(Buf,0,sizeof(Buf));
while (Err==ERR_NONE && Left)
{
Err = Stream_Write(Output,Buf,min(Left,sizeof(Buf)),&Written);
if (Err == ERR_NONE)
Left -= min(Left,sizeof(Buf));
}
if (Rendered)
*Rendered = Element->Size - Left;
return Err;
}
#endif
META_START(EBMLVoid_Class,EBML_VOID_CLASS)
META_CLASS(CREATE,Create)
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
META_END(EBML_ELEMENT_CLASS)
void EBML_VoidSetSize(ebml_element *Void, filepos_t Size)
{
assert(Node_IsPartOf(Void,EBML_VOID_CLASS));
Void->Size = Size;
Void->bValueIsSet = 1;
}
filepos_t EBML_VoidReplaceWith(ebml_element *Void, ebml_element *ReplacedWith, stream *Output, bool_t ComeBackAfterward, bool_t bWithDefault)
{
filepos_t CurrentPosition;
assert(Node_IsPartOf(Void,EBML_VOID_CLASS));
EBML_ElementUpdateSize(ReplacedWith,bWithDefault,0);
if (EBML_ElementFullSize(Void,1) < EBML_ElementFullSize(ReplacedWith,1))
// the element can't be written here !
return INVALID_FILEPOS_T;
if (EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) == 1)
// there is not enough space to put a filling element
return INVALID_FILEPOS_T;
CurrentPosition = Stream_Seek(Output,0,SEEK_CUR);
Stream_Seek(Output,Void->ElementPosition,SEEK_SET);
EBML_ElementRender(ReplacedWith,Output,bWithDefault,0,1,NULL);
if (EBML_ElementFullSize(Void,1) - EBML_ElementFullSize(ReplacedWith,1) > 1)