OLD | NEW |
1 //#include <strmif.h> | 1 // #include <strmif.h> |
2 #include "EbmlBufferWriter.h" | 2 #include "EbmlBufferWriter.h" |
3 #include "EbmlWriter.h" | 3 #include "EbmlWriter.h" |
4 //#include <cassert> | 4 // #include <cassert> |
5 //#include <limits> | 5 // #include <limits> |
6 //#include <malloc.h> //_alloca | 6 // #include <malloc.h> //_alloca |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <wchar.h> | 8 #include <wchar.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 void Ebml_Write(EbmlGlobal *glob, const void *buffer_in, unsigned long len) | 11 void Ebml_Write(EbmlGlobal *glob, const void *buffer_in, unsigned long len) { |
12 { | 12 unsigned char *src = glob->buf; |
13 unsigned char *src = glob->buf; | 13 src += glob->offset; |
14 src += glob->offset; | 14 memcpy(src, buffer_in, len); |
15 memcpy(src, buffer_in, len); | 15 glob->offset += len; |
16 glob->offset += len; | |
17 } | 16 } |
18 | 17 |
19 static void _Serialize(EbmlGlobal *glob, const unsigned char *p, const unsigned
char *q) | 18 static void _Serialize(EbmlGlobal *glob, const unsigned char *p, const unsigned
char *q) { |
20 { | 19 while (q != p) { |
21 while (q != p) | 20 --q; |
22 { | |
23 --q; | |
24 | 21 |
25 unsigned long cbWritten; | 22 unsigned long cbWritten; |
26 memcpy(&(glob->buf[glob->offset]), q, 1); | 23 memcpy(&(glob->buf[glob->offset]), q, 1); |
27 glob->offset ++; | 24 glob->offset++; |
28 } | 25 } |
29 } | 26 } |
30 | 27 |
31 void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len) | 28 void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len)
{ |
32 { | 29 // assert(buf); |
33 //assert(buf); | |
34 | 30 |
35 const unsigned char *const p = (const unsigned char *)(buffer_in); | 31 const unsigned char *const p = (const unsigned char *)(buffer_in); |
36 const unsigned char *const q = p + len; | 32 const unsigned char *const q = p + len; |
37 | 33 |
38 _Serialize(glob, p, q); | 34 _Serialize(glob, p, q); |
39 } | 35 } |
40 | 36 |
41 | 37 |
42 void Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc, unsigned long clas
s_id) | 38 void Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc, unsigned long clas
s_id) { |
43 { | 39 Ebml_WriteID(glob, class_id); |
44 Ebml_WriteID(glob, class_id); | 40 ebmlLoc->offset = glob->offset; |
45 ebmlLoc->offset = glob->offset; | 41 // todo this is always taking 8 bytes, this may need later optimization |
46 //todo this is always taking 8 bytes, this may need later optimization | 42 unsigned long long unknownLen = 0x01FFFFFFFFFFFFFFLLU; |
47 unsigned long long unknownLen = 0x01FFFFFFFFFFFFFFLLU; | 43 Ebml_Serialize(glob, (void *)&unknownLen, 8); // this is a key that says lengh
t unknown |
48 Ebml_Serialize(glob, (void *)&unknownLen, 8); //this is a key that says leng
ht unknown | |
49 } | 44 } |
50 | 45 |
51 void Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc) | 46 void Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc) { |
52 { | 47 unsigned long long size = glob->offset - ebmlLoc->offset - 8; |
53 unsigned long long size = glob->offset - ebmlLoc->offset - 8; | 48 unsigned long long curOffset = glob->offset; |
54 unsigned long long curOffset = glob->offset; | 49 glob->offset = ebmlLoc->offset; |
55 glob->offset = ebmlLoc->offset; | 50 size |= 0x0100000000000000LLU; |
56 size |= 0x0100000000000000LLU; | 51 Ebml_Serialize(glob, &size, 8); |
57 Ebml_Serialize(glob, &size, 8); | 52 glob->offset = curOffset; |
58 glob->offset = curOffset; | |
59 } | 53 } |
60 | 54 |
OLD | NEW |