2 #include "EbmlBufferWriter.h"
3 #include "EbmlWriter.h"
6 //#include <malloc.h> //_alloca
11 void Ebml_Write(EbmlGlobal
*glob
, const void *buffer_in
, unsigned long len
)
13 unsigned char *src
= glob
->buf
;
15 memcpy(src
, buffer_in
, len
);
19 static void _Serialize(EbmlGlobal
*glob
, const unsigned char *p
, const unsigned char *q
)
25 unsigned long cbWritten
;
26 memcpy(&(glob
->buf
[glob
->offset
]), q
, 1);
31 void Ebml_Serialize(EbmlGlobal
*glob
, const void *buffer_in
, unsigned long len
)
35 const unsigned char *const p
= (const unsigned char *)(buffer_in
);
36 const unsigned char *const q
= p
+ len
;
38 _Serialize(glob
, p
, q
);
42 void Ebml_StartSubElement(EbmlGlobal
*glob
, EbmlLoc
*ebmlLoc
, unsigned long class_id
)
44 Ebml_WriteID(glob
, class_id
);
45 ebmlLoc
->offset
= glob
->offset
;
46 //todo this is always taking 8 bytes, this may need later optimization
47 unsigned long long unknownLen
= 0x01FFFFFFFFFFFFFFLLU
;
48 Ebml_Serialize(glob
, (void *)&unknownLen
, 8); //this is a key that says lenght unknown
51 void Ebml_EndSubElement(EbmlGlobal
*glob
, EbmlLoc
*ebmlLoc
)
53 unsigned long long size
= glob
->offset
- ebmlLoc
->offset
- 8;
54 unsigned long long curOffset
= glob
->offset
;
55 glob
->offset
= ebmlLoc
->offset
;
56 size
|= 0x0100000000000000LLU
;
57 Ebml_Serialize(glob
, &size
, 8);
58 glob
->offset
= curOffset
;