Commit 87ffecd1 authored by Steve Lhomme's avatar Steve Lhomme

libebml2: add a EBML_ElementPosition() helper function, don't make...

libebml2: add a EBML_ElementPosition() helper function, don't make EBML_ElementPositionData() and EBML_ElementPosition() inline anymore

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@602 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent db508087
......@@ -226,24 +226,9 @@ EBML_DLL bool_t EBML_ElementInfiniteForceSize(ebml_element *Element, filepos_t N
EBML_DLL bool_t EBML_ElementIsDummy(const ebml_element *Element);
EBML_DLL fourcc_t EBML_ElementClassID(const ebml_element *Element);
static INLINE filepos_t EBML_ElementPositionData(const ebml_element *Element)
{
if (!EBML_ElementIsFiniteSize(Element))
{
if (!Element->SizeLength)
return INVALID_FILEPOS_T;
return Element->SizePosition + Element->SizeLength;
}
else
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; // the end position is unknown
else
return Element->SizePosition + EBML_CodedSizeLength(Element->DataSize,Element->SizeLength,1) + Element->DataSize;
}
EBML_DLL filepos_t EBML_ElementPosition(const ebml_element *Element);
EBML_DLL filepos_t EBML_ElementPositionData(const ebml_element *Element);
EBML_DLL filepos_t EBML_ElementPositionEnd(const ebml_element *Element);
#if defined(CONFIG_EBML_WRITING)
// TODO: replace the list of bools by flags ?
......
......@@ -137,6 +137,31 @@ fourcc_t EBML_ElementClassID(const ebml_element *Element)
return Element->Context->Id;
}
filepos_t EBML_ElementPosition(const ebml_element *Element)
{
return Element->ElementPosition;
}
filepos_t EBML_ElementPositionData(const ebml_element *Element)
{
if (!EBML_ElementIsFiniteSize(Element))
{
if (!Element->SizeLength)
return INVALID_FILEPOS_T;
return Element->SizePosition + Element->SizeLength;
}
else
return Element->SizePosition + EBML_CodedSizeLength(Element->DataSize,Element->SizeLength,1);
}
filepos_t EBML_ElementPositionEnd(const ebml_element *Element)
{
if (!EBML_ElementIsFiniteSize(Element))
return INVALID_FILEPOS_T; // the end position is unknown
else
return Element->SizePosition + EBML_CodedSizeLength(Element->DataSize,Element->SizeLength,1) + Element->DataSize;
}
bool_t EBML_ElementInfiniteForceSize(ebml_element *Element, filepos_t NewSize)
{
int OldSizeLen;
......
......@@ -99,8 +99,8 @@ void DebugMessage(const tchar_t* Msg,...)
static void EndLine(ebml_element *Element)
{
if (ShowPos && Element->ElementPosition!=INVALID_FILEPOS_T)
fprintf(stdout," at %"PRId64"\r\n",Element->ElementPosition);
if (ShowPos && EBML_ElementPosition(Element)!=INVALID_FILEPOS_T)
fprintf(stdout," at %"PRId64"\r\n",EBML_ElementPosition(Element));
else
fprintf(stdout,"\r\n");
}
......@@ -128,7 +128,7 @@ static ebml_element *OutputElement(ebml_element *Element, const ebml_parser_cont
SubContext.Context = Element->Context;
SubContext.EndPosition = EBML_ElementPositionEnd(Element);
SubElement = EBML_FindNextElement(Input, &SubContext, &UpperElement, 1);
while (SubElement != NULL && UpperElement<=0 && (!EBML_ElementIsFiniteSize(Element) || SubElement->ElementPosition <= EBML_ElementPositionEnd(Element)))
while (SubElement != NULL && UpperElement<=0 && (!EBML_ElementIsFiniteSize(Element) || EBML_ElementPosition(SubElement) <= EBML_ElementPositionEnd(Element)))
{
// a sub element == not higher level and contained inside the current element
(*Level)++;
......
......@@ -208,7 +208,7 @@ static void ReduceSize(ebml_element *Element)
{
tchar_t IdString[MAXPATH];
Node_FromStr(i,IdString,TSIZEOF(IdString),s->eClass->ElementName);
TextPrintf(StdErr,T("The %s element at %") TPRId64 T(" is missing mandatory elements, skipping\r\n"),IdString,i->ElementPosition);
TextPrintf(StdErr,T("The %s element at %") TPRId64 T(" is missing mandatory elements, skipping\r\n"),IdString,EBML_ElementPosition(i));
EBML_MasterRemove((ebml_master*)Element,i); // make sure it doesn't remain in the list
NodeDelete((node*)i);
i=EBML_MasterChildren((ebml_master*)Element);
......@@ -219,7 +219,7 @@ static void ReduceSize(ebml_element *Element)
{
tchar_t IdString[MAXPATH];
Node_FromStr(i,IdString,TSIZEOF(IdString),s->eClass->ElementName);
TextPrintf(StdErr,T("The %s element at %") TPRId64 T(" is not part of profile '%s', skipping\r\n"),IdString,i->ElementPosition,GetProfileName(DstProfile));
TextPrintf(StdErr,T("The %s element at %") TPRId64 T(" is not part of profile '%s', skipping\r\n"),IdString,EBML_ElementPosition(i),GetProfileName(DstProfile));
EBML_MasterRemove((ebml_master*)Element,i); // make sure it doesn't remain in the list
NodeDelete((node*)i);
i=EBML_MasterChildren((ebml_master*)Element);
......@@ -397,7 +397,7 @@ static void SettleClustersWithCues(array *Clusters, filepos_t ClusterStart, ebml
static void ShowProgress(const ebml_element *RCluster, const ebml_element *RSegment)
{
if (!Quiet)
TextPrintf(StdErr,T("Progress %d/%d: %3d%%\r"), CurrentPhase, TotalPhases,Scale32(100,RCluster->ElementPosition,RSegment->DataSize)+1);
TextPrintf(StdErr,T("Progress %d/%d: %3d%%\r"), CurrentPhase, TotalPhases,Scale32(100,EBML_ElementPosition(RCluster),RSegment->DataSize)+1);
}
static void EndProgress()
......
......@@ -54,7 +54,7 @@ static timecode_t MinTime = INVALID_TIMECODE_T, MaxTime = INVALID_TIMECODE_T;
static timecode_t ClusterTime = INVALID_TIMECODE_T;
// some macros for code readability
#define EL_Pos(elt) ((const ebml_element*)elt)->ElementPosition
#define EL_Pos(elt) EBML_ElementPosition((const ebml_element*)elt)
#define EL_Int(elt) EBML_IntegerValue((const ebml_integer*)elt)
#define EL_Type(elt, type) (((const ebml_element*)elt)->Context->Id == (type)->Id)
#define EL_DataSize(elt) ((const ebml_element*)elt)->DataSize
......
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