Commit c5e61824 authored by Steve Lhomme's avatar Steve Lhomme

v2: fix the EBML dummy ID

fix writing signed integers
export the buffer->ID function
export the EBML versions supported (in case it changes)

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@153 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent dd4faff2
This diff is collapsed.
/*
* $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
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)
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;
}
const uint8_t *EBML_BinaryGetData(ebml_binary *Element)
{
if (!ARRAYCOUNT(Element->Data,uint8_t))
return NULL;
return ARRAYBEGIN(Element->Data,uint8_t);
}
/*
* $Id$
* 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
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)
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;
}
const uint8_t *EBML_BinaryGetData(ebml_binary *Element)
{
if (!ARRAYCOUNT(Element->Data,uint8_t))
return NULL;
return ARRAYBEGIN(Element->Data,uint8_t);
}
/*
* $Id: ebmlcrc.c 1311 2008-08-24 08:45:24Z robux4 $
* $Id$
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
......
/*
* $Id: ebmldate.c 1319 2008-09-19 16:08:57Z robux4 $
* $Id$
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
......
/*
* $Id: ebmlelement.c 1323 2008-10-05 12:07:46Z robux4 $
* $Id$
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
......@@ -208,6 +208,20 @@ err_t EBML_ElementRender(ebml_element *Element, stream *Output, bool_t bWithDefa
return Result;
}
size_t EBML_FillBufferID(uint8_t *Buffer, size_t BufSize, fourcc_t Id)
{
size_t i,FinalHeadSize = GetIdLength(Id);
if (BufSize < FinalHeadSize)
return 0;
#if defined(IS_BIG_ENDIAN)
memcpy(Buffer,&Id,FinalHeadSize);
#else
for (i=0;i<FinalHeadSize;++i)
Buffer[FinalHeadSize-i-1] = (uint8_t)(Id >> (i<<3));
#endif
return FinalHeadSize;
}
err_t EBML_ElementRenderHead(ebml_element *Element, stream *Output, bool_t bKeepPosition, filepos_t *Rendered)
{
err_t Err;
......@@ -216,13 +230,7 @@ err_t EBML_ElementRenderHead(ebml_element *Element, stream *Output, bool_t bKeep
int CodedSize;
filepos_t PosAfter,PosBefore = Stream_Seek(Output,0,SEEK_CUR);
FinalHeadSize = GetIdLength(Element->Context->Id);
#if defined(IS_BIG_ENDIAN)
memcpy(FinalHead,&Element->Context->Id,FinalHeadSize);
#else
for (i=0;i<FinalHeadSize;++i)
FinalHead[FinalHeadSize-i-1] = (uint8_t)(Element->Context->Id >> (i<<3));
#endif
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]);
......
This diff is collapsed.
/*
* $Id: ebmlmaster.c 1323 2008-10-05 12:07:46Z robux4 $
* $Id$
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
......
This diff is collapsed.
/*
* $Id: ebmlstring.c 1320 2008-10-04 15:03:47Z robux4 $
* $Id$
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
......
/*
* $Id: ebmlcrc.c 1311 2008-08-24 08:45:24Z robux4 $
* $Id$
* Copyright (c) 2008, Matroska Foundation
* All rights reserved.
*
......
#include "*/*.proj"
GROUP ebml2_group
{
PROJECT_VERSION 1.0.0
PROJECT_VENDOR "Matroska Foundation"
INCLUDE .
USE ebml2_project
USE node
USE file
USE date
IF COREMAKE_UNICODE
USE parser
DEFINE CONFIG_EBML_UNICODE
EXPDEFINE CONFIG_EBML_UNICODE
ENDIF
HEADER ebml/ebml.h
SOURCE ebmlmain.c
SOURCE ebmlelement.c {class EBMLElement_Class}
SOURCE ebmlmaster.c {class EBMLMaster_Class}
SOURCE ebmlbinary.c {class EBMLBinary_Class}
SOURCE ebmlstring.c {class EBMLString_Class}
SOURCE ebmlnumber.c {class EBMLInteger_Class}
SOURCE ebmlcrc.c {class EBMLCRC_Class}
SOURCE ebmldate.c {class EBMLDate_Class}
SOURCE ebmlvoid.c {class EBMLVoid_Class}
}
DLL ebml2
{
USE ebml2_group
EXPINCLUDE .
}
#include "*/*.proj"
GROUP ebml2_group
{
PROJECT_VERSION 1.0.0
PROJECT_VENDOR "Matroska Foundation"
INCLUDE .
EXPINCLUDE .
USE ebml2_project
USE node
USE file
USE date
IF COREMAKE_UNICODE
USE parser
DEFINE CONFIG_EBML_UNICODE
EXPDEFINE CONFIG_EBML_UNICODE
ENDIF
HEADER ebml/ebml.h
SOURCE ebmlmain.c
SOURCE ebmlelement.c {class EBMLElement_Class}
SOURCE ebmlmaster.c {class EBMLMaster_Class}
SOURCE ebmlbinary.c {class EBMLBinary_Class}
SOURCE ebmlstring.c {class EBMLString_Class}
SOURCE ebmlnumber.c {class EBMLInteger_Class}
SOURCE ebmlcrc.c {class EBMLCRC_Class}
SOURCE ebmldate.c {class EBMLDate_Class}
SOURCE ebmlvoid.c {class EBMLVoid_Class}
}
DLL ebml2
{
USE ebml2_group
EXPINCLUDE .
}
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