1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libmkv/source_fix.patch Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,193 @@ 1.4 +diff --git a/EbmlBufferWriter.c b/EbmlBufferWriter.c 1.5 +index 574e478..8c26e80 100644 1.6 +--- a/EbmlBufferWriter.c 1.7 ++++ b/EbmlBufferWriter.c 1.8 +@@ -8,6 +8,31 @@ 1.9 + #include <wchar.h> 1.10 + #include <string.h> 1.11 + 1.12 ++void 1.13 ++Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, int buffer_size, unsigned long len) 1.14 ++{ 1.15 ++ /* buffer_size: 1.16 ++ * 1 - int8_t; 1.17 ++ * 2 - int16_t; 1.18 ++ * 3 - int32_t; 1.19 ++ * 4 - int64_t; 1.20 ++ */ 1.21 ++ long i; 1.22 ++ for(i = len-1; i >= 0; i--) { 1.23 ++ unsigned char x; 1.24 ++ if (buffer_size == 1) { 1.25 ++ x = (char)(*(const int8_t *)buffer_in >> (i * 8)); 1.26 ++ } else if (buffer_size == 2) { 1.27 ++ x = (char)(*(const int16_t *)buffer_in >> (i * 8)); 1.28 ++ } else if (buffer_size == 4) { 1.29 ++ x = (char)(*(const int32_t *)buffer_in >> (i * 8)); 1.30 ++ } else if (buffer_size == 8) { 1.31 ++ x = (char)(*(const int64_t *)buffer_in >> (i * 8)); 1.32 ++ } 1.33 ++ Ebml_Write(glob, &x, 1); 1.34 ++ } 1.35 ++} 1.36 ++ 1.37 + void Ebml_Write(EbmlGlobal *glob, const void *buffer_in, unsigned long len) { 1.38 + unsigned char *src = glob->buf; 1.39 + src += glob->offset; 1.40 +@@ -19,12 +44,12 @@ static void _Serialize(EbmlGlobal *glob, const unsigned char *p, const unsigned 1.41 + while (q != p) { 1.42 + --q; 1.43 + 1.44 +- unsigned long cbWritten; 1.45 + memcpy(&(glob->buf[glob->offset]), q, 1); 1.46 + glob->offset++; 1.47 + } 1.48 + } 1.49 + 1.50 ++/* 1.51 + void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len) { 1.52 + // assert(buf); 1.53 + 1.54 +@@ -33,22 +58,22 @@ void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, unsigned long len) 1.55 + 1.56 + _Serialize(glob, p, q); 1.57 + } 1.58 +- 1.59 ++*/ 1.60 + 1.61 + void Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc, unsigned long class_id) { 1.62 ++ unsigned long long unknownLen = 0x01FFFFFFFFFFFFFFLL; 1.63 + Ebml_WriteID(glob, class_id); 1.64 + ebmlLoc->offset = glob->offset; 1.65 + // todo this is always taking 8 bytes, this may need later optimization 1.66 +- unsigned long long unknownLen = 0x01FFFFFFFFFFFFFFLLU; 1.67 +- Ebml_Serialize(glob, (void *)&unknownLen, 8); // this is a key that says lenght unknown 1.68 ++ Ebml_Serialize(glob, (void *)&unknownLen,sizeof(unknownLen), 8); // this is a key that says lenght unknown 1.69 + } 1.70 + 1.71 + void Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc) { 1.72 + unsigned long long size = glob->offset - ebmlLoc->offset - 8; 1.73 + unsigned long long curOffset = glob->offset; 1.74 + glob->offset = ebmlLoc->offset; 1.75 +- size |= 0x0100000000000000LLU; 1.76 +- Ebml_Serialize(glob, &size, 8); 1.77 ++ size |= 0x0100000000000000LL; 1.78 ++ Ebml_Serialize(glob, &size,sizeof(size), 8); 1.79 + glob->offset = curOffset; 1.80 + } 1.81 + 1.82 +diff --git a/EbmlBufferWriter.h b/EbmlBufferWriter.h 1.83 +index acd5c2a..c135f29 100644 1.84 +--- a/EbmlBufferWriter.h 1.85 ++++ b/EbmlBufferWriter.h 1.86 +@@ -11,9 +11,7 @@ typedef struct { 1.87 + unsigned int offset; 1.88 + } EbmlGlobal; 1.89 + 1.90 +- 1.91 + void Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc, unsigned long class_id); 1.92 + void Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc); 1.93 + 1.94 +- 1.95 + #endif 1.96 +diff --git a/EbmlWriter.c b/EbmlWriter.c 1.97 +index 27cfe86..ebefc1a 100644 1.98 +--- a/EbmlWriter.c 1.99 ++++ b/EbmlWriter.c 1.100 +@@ -74,6 +74,13 @@ void Ebml_WriteID(EbmlGlobal *glob, unsigned long class_id) { 1.101 + Ebml_Serialize(glob, (void *)&class_id, sizeof(class_id), len); 1.102 + } 1.103 + 1.104 ++void Ebml_SerializeUnsigned32(EbmlGlobal *glob, unsigned long class_id, uint32_t ui) { 1.105 ++ unsigned char sizeSerialized = 8 | 0x80; 1.106 ++ Ebml_WriteID(glob, class_id); 1.107 ++ Ebml_Serialize(glob, &sizeSerialized, sizeof(sizeSerialized), 1); 1.108 ++ Ebml_Serialize(glob, &ui, sizeof(ui), 4); 1.109 ++} 1.110 ++ 1.111 + void Ebml_SerializeUnsigned64(EbmlGlobal *glob, unsigned long class_id, uint64_t ui) { 1.112 + unsigned char sizeSerialized = 8 | 0x80; 1.113 + Ebml_WriteID(glob, class_id); 1.114 +diff --git a/EbmlWriter.h b/EbmlWriter.h 1.115 +index b94f757..a0a848b 100644 1.116 +--- a/EbmlWriter.h 1.117 ++++ b/EbmlWriter.h 1.118 +@@ -28,6 +28,7 @@ void Ebml_WriteLen(EbmlGlobal *glob, int64_t val); 1.119 + void Ebml_WriteString(EbmlGlobal *glob, const char *str); 1.120 + void Ebml_WriteUTF8(EbmlGlobal *glob, const wchar_t *wstr); 1.121 + void Ebml_WriteID(EbmlGlobal *glob, unsigned long class_id); 1.122 ++void Ebml_SerializeUnsigned32(EbmlGlobal *glob, unsigned long class_id, uint32_t ui); 1.123 + void Ebml_SerializeUnsigned64(EbmlGlobal *glob, unsigned long class_id, uint64_t ui); 1.124 + void Ebml_SerializeUnsigned(EbmlGlobal *glob, unsigned long class_id, unsigned long ui); 1.125 + void Ebml_SerializeBinary(EbmlGlobal *glob, unsigned long class_id, unsigned long ui); 1.126 +diff --git a/WebMElement.c b/WebMElement.c 1.127 +index 2f79a3c..02eefa4 100644 1.128 +--- a/WebMElement.c 1.129 ++++ b/WebMElement.c 1.130 +@@ -11,8 +11,12 @@ 1.131 + #include "EbmlIDs.h" 1.132 + #include "WebMElement.h" 1.133 + #include <stdio.h> 1.134 ++#include <stdint.h> 1.135 ++#include <stdlib.h> 1.136 ++#include <time.h> 1.137 + 1.138 + #define kVorbisPrivateMaxSize 4000 1.139 ++#define UInt64 uint64_t 1.140 + 1.141 + void writeHeader(EbmlGlobal *glob) { 1.142 + EbmlLoc start; 1.143 +@@ -30,15 +34,16 @@ void writeHeader(EbmlGlobal *glob) { 1.144 + void writeSimpleBlock(EbmlGlobal *glob, unsigned char trackNumber, short timeCode, 1.145 + int isKeyframe, unsigned char lacingFlag, int discardable, 1.146 + unsigned char *data, unsigned long dataLength) { 1.147 +- Ebml_WriteID(glob, SimpleBlock); 1.148 + unsigned long blockLength = 4 + dataLength; 1.149 ++ unsigned char flags = 0x00 | (isKeyframe ? 0x80 : 0x00) | (lacingFlag << 1) | discardable; 1.150 ++ Ebml_WriteID(glob, SimpleBlock); 1.151 + blockLength |= 0x10000000; // TODO check length < 0x0FFFFFFFF 1.152 + Ebml_Serialize(glob, &blockLength, sizeof(blockLength), 4); 1.153 + trackNumber |= 0x80; // TODO check track nubmer < 128 1.154 + Ebml_Write(glob, &trackNumber, 1); 1.155 + // Ebml_WriteSigned16(glob, timeCode,2); //this is 3 bytes 1.156 + Ebml_Serialize(glob, &timeCode, sizeof(timeCode), 2); 1.157 +- unsigned char flags = 0x00 | (isKeyframe ? 0x80 : 0x00) | (lacingFlag << 1) | discardable; 1.158 ++ flags = 0x00 | (isKeyframe ? 0x80 : 0x00) | (lacingFlag << 1) | discardable; 1.159 + Ebml_Write(glob, &flags, 1); 1.160 + Ebml_Write(glob, data, dataLength); 1.161 + } 1.162 +@@ -48,17 +53,18 @@ static UInt64 generateTrackID(unsigned int trackNumber) { 1.163 + UInt64 r = rand(); 1.164 + r = r << 32; 1.165 + r += rand(); 1.166 +- UInt64 rval = t ^ r; 1.167 +- return rval; 1.168 ++// UInt64 rval = t ^ r; 1.169 ++ return t ^ r; 1.170 + } 1.171 + 1.172 + void writeVideoTrack(EbmlGlobal *glob, unsigned int trackNumber, int flagLacing, 1.173 + char *codecId, unsigned int pixelWidth, unsigned int pixelHeight, 1.174 + double frameRate) { 1.175 + EbmlLoc start; 1.176 ++ UInt64 trackID; 1.177 + Ebml_StartSubElement(glob, &start, TrackEntry); 1.178 + Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber); 1.179 +- UInt64 trackID = generateTrackID(trackNumber); 1.180 ++ trackID = generateTrackID(trackNumber); 1.181 + Ebml_SerializeUnsigned(glob, TrackUID, trackID); 1.182 + Ebml_SerializeString(glob, CodecName, "VP8"); // TODO shouldn't be fixed 1.183 + 1.184 +@@ -78,9 +84,10 @@ void writeAudioTrack(EbmlGlobal *glob, unsigned int trackNumber, int flagLacing, 1.185 + char *codecId, double samplingFrequency, unsigned int channels, 1.186 + unsigned char *private, unsigned long privateSize) { 1.187 + EbmlLoc start; 1.188 ++ UInt64 trackID; 1.189 + Ebml_StartSubElement(glob, &start, TrackEntry); 1.190 + Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber); 1.191 +- UInt64 trackID = generateTrackID(trackNumber); 1.192 ++ trackID = generateTrackID(trackNumber); 1.193 + Ebml_SerializeUnsigned(glob, TrackUID, trackID); 1.194 + Ebml_SerializeUnsigned(glob, TrackType, 2); // audio is always 2 1.195 + // I am using defaults for thesed required fields 1.196 +