[asterisk-scf-commits] asterisk-scf/integration/matroska.git branch "initial_matroska2_upstream" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Nov 8 08:26:32 CST 2011


branch "initial_matroska2_upstream" has been created
        at  86b7b9325f86ec72f1d62b1d3d498f5366f15fd2 (commit)

- Log -----------------------------------------------------------------
commit 86b7b9325f86ec72f1d62b1d3d498f5366f15fd2
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Nov 8 10:55:05 2011 -0330

    Adding corec, ebml2 and matroska2 library code.

diff --git a/config.h b/config.h
new file mode 100644
index 0000000..92a20f0
--- /dev/null
+++ b/config.h
@@ -0,0 +1,11 @@
+#define COREMAKE_STATIC
+#define COREMAKE_UNICODE
+#define CONFIG_EBML_WRITING
+#define HAVE_EBML2
+#define CONFIG_MATROSKA2
+#define USE_PRECOMPILED_HEADERS
+#define CONFIG_DEBUGCHECKS
+#define CONFIG_STDIO
+#define CONFIG_FILEPOS_64
+#define COREMAKE_CONFIG_HELPER
+//#define CONFIG_DEBUG_LEAKS
diff --git a/corec/corec.proj b/corec/corec.proj
new file mode 100644
index 0000000..d607791
--- /dev/null
+++ b/corec/corec.proj
@@ -0,0 +1,4 @@
+CONFIG_FILE config.h
+PLATFORM_FILES tools/coremake
+
+#include "*/*.proj"
diff --git a/corec/corec/array/array.c b/corec/corec/array/array.c
new file mode 100644
index 0000000..201c2ba
--- /dev/null
+++ b/corec/corec/array/array.c
@@ -0,0 +1,625 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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 "array.h"
+
+typedef struct datahead
+{
+    size_t Size;
+
+} datahead;
+
+#define Data_Head(Name)         ((datahead*)(Name)-1)
+#define Data_HeapHead(Name)     ((dataheaphead*)(Name)-1)
+#define Data_IsHeap(Name)       (Data_Head(Name)->Size & DATA_FLAG_HEAP)
+#define Data_IsMemHeap(Name)    (Data_Head(Name)->Size & DATA_FLAG_MEMHEAP)
+#define Data_GetSize(Name)      (Data_Head(Name)->Size & ~(DATA_FLAG_HEAP|DATA_FLAG_MEMHEAP))
+
+size_t Data_Size(const uint8_t* a)
+{
+    if (!a) return 0;
+    return Data_GetSize(a);
+}
+
+NOINLINE bool_t Data_ReAlloc(uint8_t** a,size_t n)
+{
+    uint8_t* p = *a;
+    size_t oldsize;
+
+    if (p)
+    {
+        if (!Data_Head(p)->Size) // const?
+            return 0;
+        oldsize = Data_GetSize(p);
+    }
+    else
+        oldsize = 0;
+
+    if (oldsize<n)
+    {
+        if (p && Data_IsMemHeap(p))
+        {
+            const cc_memheap* Heap = Data_HeapHead(p)->Heap;
+            dataheaphead* Head;
+            if (!oldsize)
+                Head = MemHeap_Alloc(Heap,n+sizeof(dataheaphead),0);
+            else
+                Head = MemHeap_ReAlloc(Heap,Data_HeapHead(p),oldsize+sizeof(dataheaphead),n+sizeof(dataheaphead));
+            if (!Head)
+                return 0;
+
+            Head->Heap = Heap;
+            Head->Size = n|DATA_FLAG_HEAP|DATA_FLAG_MEMHEAP;
+            *a = (uint8_t*)(Head+1);
+        }
+        else
+        {
+            datahead* Head;
+            if (!p || !Data_IsHeap(p))
+            {
+                uint8_t* old = p;
+                Head = malloc(n+sizeof(datahead));
+                if (Head && old)
+                    memcpy(Head+1,old,oldsize);
+            }
+            else
+                Head = realloc(Data_Head(p),n+sizeof(datahead));
+
+            if (!Head)
+                return 0;
+
+            Head->Size = n|DATA_FLAG_HEAP;
+            *a = (uint8_t*)(Head+1);
+        }
+    }
+    return 1;
+}
+
+NOINLINE void Data_Release(uint8_t** a)
+{
+    uint8_t* p = *a;
+    if (p)
+    {
+        *a = NULL;
+        if (Data_IsHeap(p))
+        {
+            if (Data_IsMemHeap(p))
+            {
+                if (Data_GetSize(p))
+                    MemHeap_Free(Data_HeapHead(p)->Heap,Data_HeapHead(p),Data_GetSize(p)+sizeof(dataheaphead));
+            }
+            else
+                free(Data_Head(p));
+        }
+    }
+}
+
+NOINLINE void Data_Clear(uint8_t** a)
+{
+    uint8_t* p = *a;
+    if (p && Data_IsMemHeap(p))
+    {
+        p = MemHeap_Null(Data_HeapHead(p)->Heap);
+        Data_Release(a);
+        *a = p;
+    }
+    else
+        Data_Release(a);
+}
+
+bool_t Data_Set(uint8_t** a,const uint8_t* b,size_t pos,size_t len)
+{
+    if (!Data_ReAlloc(a,pos+len))
+        return 0;
+
+    memcpy(*a+pos,b,len);
+    return 1;
+}
+
+size_t ArraySize(const array*p)
+{
+    return p->_End-p->_Begin;
+}
+
+void ArrayInitEx(array* p,const cc_memheap* Heap)
+{
+    p->_Begin = p->_End = Heap ? MemHeap_Null(Heap):NULL;
+}
+
+NOINLINE void ArrayClear(array* p)
+{
+	Data_Clear(&p->_Begin);
+	p->_End = p->_Begin;
+}
+
+void ArrayDrop(array* p)
+{
+	p->_End = p->_Begin;
+}
+
+static size_t SizeAlign(size_t Total, size_t Align)
+{
+    if (!Align)
+    {
+        for (Align=16;Align<16384;Align<<=1)
+            if (Align*8 > Total)
+                break;
+    }
+    --Align;
+	return (Total + Align) & ~Align;
+}
+
+bool_t ArrayAlloc(array* p,size_t Total,size_t Align)
+{
+    size_t Size = ArraySize(p);
+    if (!Data_ReAlloc(&p->_Begin,SizeAlign(Total,Align)))
+        return 0;
+	p->_End = p->_Begin + Size;
+	return 1;
+}
+
+void ArrayShrink(array* p, size_t Length)
+{
+    p->_End -= Length;
+    if (p->_End < p->_Begin)
+        p->_End = p->_Begin;
+}
+
+bool_t ArrayInsert(array* p, size_t Ofs, const void* Ptr, size_t Width, size_t Align)
+{
+	if (!ArrayAppend(p,NULL,Width,Align))
+		return 0;
+	memmove(p->_Begin+Ofs+Width,p->_Begin+Ofs,(p->_End-p->_Begin)-Width-Ofs);
+    if (Ptr)
+        memcpy(p->_Begin+Ofs,Ptr,Width);
+    return 1;
+}
+
+void ArrayDelete(array* p, size_t Ofs, size_t Width)
+{
+	memmove(p->_Begin+Ofs,p->_Begin+Ofs+Width,(p->_End-p->_Begin)-Width-Ofs);
+	p->_End -= Width;
+}
+
+bool_t ArrayAppendStr(array* p, const tchar_t* Ptr, bool_t Merge, size_t Align)
+{
+    if (Ptr && (Ptr[0] || !Merge))
+    {
+        if (Merge && !ARRAYEMPTY(*p) && ARRAYEND(*p,tchar_t)[-1]==0)
+            ArrayShrink(p,sizeof(tchar_t));
+
+        return ArrayAppend(p,Ptr,(tcslen(Ptr)+1)*sizeof(tchar_t),Align);
+    }
+    return 1;
+}
+
+bool_t ArrayAppend(array* p, const void* Ptr, size_t Length, size_t Align)
+{
+	size_t Total = p->_End - p->_Begin + Length;
+	if (Total > Data_Size(p->_Begin) && !ArrayAlloc(p,Total,Align))
+		return 0;
+	if (Ptr)
+		memcpy(p->_End,Ptr,Length);
+	p->_End += Length;
+	return 1;
+}
+
+bool_t ArrayEq(const array* a, const array* b)
+{
+    size_t an = a ? ArraySize(a):0;
+    size_t bn = b ? ArraySize(b):0;
+    return an == bn && (!an || memcmp(ARRAYBEGIN(*a,uint8_t),ARRAYBEGIN(*b,uint8_t),an)==0);
+}
+
+bool_t ArrayCopy(array* p, const array* q)
+{
+    size_t Size = ArraySize(q);
+    if (!ArrayResize(p,Size,0))
+        return 0;
+    memcpy(ARRAYBEGIN(*p,uint8_t),ARRAYBEGIN(*q,uint8_t),Size);
+    return 1;
+}
+
+bool_t ArrayResize(array* p,size_t Total, size_t Align)
+{
+    if (Total > Data_Size(p->_Begin) && !ArrayAlloc(p,Total,Align))
+        return 0;
+    p->_End = p->_Begin + Total;
+    return 1;
+}
+
+void ArrayZero(array* p)
+{
+    memset(p->_Begin,0,p->_End-p->_Begin);
+}
+
+#define QSORTMINLEN 16
+
+static INLINE void InQSortSwap(uint_fast32_t* a, uint_fast32_t* b)
+{
+    uint_fast32_t t = *a;
+    *a = *b;
+    *b = t;
+}
+
+static NOINLINE void InQSort(uint_fast32_t* First, uint_fast32_t* Last, arraycmp Cmp, const void* CmpParam)
+{
+	while (Last > First + QSORTMINLEN)
+	{	
+        uint_fast32_t* Mid = First + ((Last - First)>>1);
+        uint_fast32_t* Ref = First;
+        uint_fast32_t* Left;
+        uint_fast32_t* Right;
+
+		if (Cmp(CmpParam,First,Last) < 0) 
+		{
+			if (Cmp(CmpParam,Last,Mid) < 0)
+				Ref = Last;
+			else 
+			if (Cmp(CmpParam,First,Mid) < 0)
+				Ref = Mid;
+		}
+		else 
+		if (Cmp(CmpParam,First,Mid) >= 0) 
+		{
+			if (Cmp(CmpParam,Last,Mid) < 0)
+				Ref = Mid;
+			else
+				Ref = Last;
+		}
+
+		if (Ref != First)
+            InQSortSwap(First,Ref);
+
+		Left = First;
+		Right = Last+1;
+
+		for (;;)
+		{ 
+			while (++Left < Last && Cmp(CmpParam,First,Left) > 0) {}
+
+			while (Cmp(CmpParam,First,--Right) < 0) {}
+
+			if (Left >= Right)
+				break;
+
+			InQSortSwap(Left,Right);
+		}
+
+		if (Right == First)
+        {
+			++First;
+        }
+		else 
+		{
+			InQSortSwap(First,Right);
+
+			--Right;
+
+			if (Right - First < Last - Left) 
+			{
+				if (Right > QSORTMINLEN + First)
+					InQSort(First,Right,Cmp,CmpParam);
+				First = Left;
+			}
+			else 
+            {
+				if (Last > QSORTMINLEN + Left)
+					InQSort(Left,Last,Cmp,CmpParam);
+				Last = Right;
+			}
+		}
+	}
+}
+
+void ArraySortEx(array* p, size_t Count, size_t Width, arraycmp Cmp, const void* CmpParam, bool_t Unique)
+{
+    if (Count == ARRAY_AUTO_COUNT)
+        Count = ArraySize(p)/Width;
+
+    if (Count>1)
+    {
+        if (Width == sizeof(uint_fast32_t))
+        {
+            uint_fast32_t* End = ARRAYBEGIN(*p,uint_fast32_t)+Count;
+            uint_fast32_t* i;
+            uint_fast32_t* j;
+
+		    InQSort(ARRAYBEGIN(*p,uint_fast32_t), End-1, Cmp, CmpParam);
+
+            j = ARRAYBEGIN(*p,uint_fast32_t);
+		    for (i=j+1; i!=End; ++i)
+		    {
+                if (Cmp(CmpParam,i,j) < 0)
+                {
+                    uint_fast32_t Tmp = *i;
+                    do
+                    {
+                        j[1] = j[0];
+                        if (j-- == ARRAYBEGIN(*p,uint_fast32_t))
+                            break;
+                    }
+                    while (Cmp(CmpParam,&Tmp,j) < 0);
+                    j[1] = Tmp;
+                }
+                j = i;
+		    }
+
+            if (Unique)
+            {
+		        j = ARRAYBEGIN(*p,uint_fast32_t);
+		        for (i=j+1; i!=End; ++i)
+		        {
+			        if (Cmp(CmpParam,i,j) != 0)
+                        *(++j) = *i;
+		        }
+		        p->_End = (uint8_t*)(j+1);
+	        }
+        }
+        else
+        {
+            // dummy fallback...
+
+            uint8_t* Tmp = (uint8_t*)alloca(Width);
+            uint8_t* End = p->_Begin + Count*Width;
+            uint8_t* i;
+            uint8_t* j;
+
+            j = p->_Begin;
+		    for (i=j+Width; i!=End; i+=Width)
+		    {
+                if (Cmp(CmpParam,i,j) < 0)
+                {
+                    memcpy(Tmp,i,Width);
+                    do
+                    {
+                        memcpy(j+Width,j,Width);
+                        if (j == p->_Begin)
+                        {
+                            j -= Width;
+                            break;
+                        }
+                        j -= Width;
+                    }
+                    while (Cmp(CmpParam,Tmp,j) < 0);
+                    memcpy(j+Width,Tmp,Width);
+                }
+                j = i;
+		    }
+
+            if (Unique)
+            {
+		        j = p->_Begin;
+		        for (i=j+Width; i!=End; i+=Width)
+		        {
+			        if (Cmp(CmpParam,i,j) != 0)
+                    {
+                        j += Width;
+                        memcpy(j,i,Width);
+                    }
+		        }
+		        p->_End = j+Width;
+	        }
+        }
+
+	}
+}
+
+intptr_t ArrayFindEx(const array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, const void* CmpParam, bool_t* Found)
+{
+    if (ARRAYEMPTY(*p))
+    {
+        *Found = 0;
+        return 0;
+    }
+
+    if (Count == ARRAY_AUTO_COUNT)
+    {
+        Count = ArraySize(p)/Width;
+        assert(Count*Width == ArraySize(p));
+    }
+
+	if (Cmp)
+	{
+		int i;
+		intptr_t Mid = 0;
+		intptr_t Lower = 0;
+		intptr_t Upper = Count-1;
+
+		while (Upper >= Lower) 
+		{
+			Mid = (Upper + Lower) >> 1;
+
+			i = Cmp(CmpParam,p->_Begin+Width*Mid,Data);
+			if (i>0)
+				Upper = Mid-1;	
+			else if (i<0)  		
+				Lower = Mid+1;	
+			else 
+			{			        
+				*Found = 1;
+				return Mid;
+			}
+		}
+
+		*Found = 0;
+
+		if (Upper == Mid - 1)
+			return Mid;		
+		else                 
+			return Lower;    
+	}
+	else
+	{
+		intptr_t No = 0;
+		const uint8_t* i;
+		for (i=p->_Begin;Count--;i+=Width,++No)
+			if (memcmp(i,Data,Width)==0)
+			{
+				*Found = 1;
+				return No;
+			}
+
+		*Found = 0;
+		return No;
+	}
+}
+
+intptr_t ArrayAddEx(array* p,size_t Count, size_t Width, const void* Data, arraycmp Cmp, const void* CmpParam, size_t Align)
+{
+	intptr_t Pos;
+	bool_t Found;
+
+	Pos = ArrayFindEx(p,Count,Width,Data,Cmp,CmpParam,&Found);
+	if (!Found)
+    {
+        if (!ArrayInsert(p,Width*Pos,Data,Width,Align))
+            return -1;
+    }
+    else
+    	memcpy(p->_Begin+Width*Pos,Data,Width);
+
+	return Pos;
+}
+
+bool_t ArrayRemoveEx(array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, const void* CmpParam)
+{
+	bool_t Found;
+	size_t Pos = ArrayFindEx(p,Count,Width,Data,Cmp,CmpParam,&Found);
+	if (Found)
+        ArrayDelete(p,Pos*Width,Width);
+	return Found;
+}
+
+static INLINE uint32_t Rand(uint32_t RndSeed)
+{ 
+	return RndSeed*0x8088405U + 0x251001U;
+}
+
+void ArrayRandomize(array* Array,size_t Width,uint32_t RndSeed)
+{
+    size_t i,j,Count = ArraySize(Array)/Width;
+    uint8_t *Buf=alloca(Width);
+    for (i=0;i<Count;++i)
+    {
+        RndSeed = Rand(RndSeed);
+        j = RndSeed % Count;
+        memcpy(Buf,ARRAYBEGIN(*Array,uint8_t)+i*Width,Width);
+        memcpy(ARRAYBEGIN(*Array,uint8_t)+i*Width,ARRAYBEGIN(*Array,uint8_t)+j*Width,Width);
+        memcpy(ARRAYBEGIN(*Array,uint8_t)+j*Width,Buf,Width);
+    }
+}
+
+
+#ifdef TARGET_PALMOS
+
+// TODO: move this to base/mem and depend on "mem" platform dependently(?)
+#include "common.h"
+// end TODO
+
+void ArrayBlockClear(arrayblock* p)
+{
+	if (p->Block.Ptr)
+    {
+		FreeBlock(NULL,&p->Block);
+        p->Array._Begin = NULL;
+        p->Array._End = NULL;
+    }
+    else
+        ArrayClear(&p->Array);
+}
+
+void ArrayBlockLock(arrayblock* p)
+{
+	if (!p->Block.Ptr && p->Array._End != p->Array._Begin)
+	{
+		size_t n = p->Array._End-p->Array._Begin;
+		if (AllocBlock(NULL,n,&p->Block,1,HEAP_STORAGE))
+		{
+			WriteBlock(&p->Block,0,p->Array._Begin,n);
+			ArrayClear(&p->Array);
+			p->Array._Begin = (uint8_t*)p->Block.Ptr;
+			p->Array._End = p->Array._Begin + n;
+		}
+	}
+}
+
+#endif
+
+void Fifo_Clear(cc_fifo* p)
+{
+	ArrayClear(&p->_Base);
+    p->_Read = NULL;
+}
+
+bool_t Fifo_Alloc(cc_fifo* p, size_t Total, size_t Align)
+{
+    size_t n = p->_Read - p->_Base._Begin;
+    if (!ArrayAlloc(&p->_Base,Total,Align))
+        return 0;
+    p->_Read = p->_Base._Begin+n;
+    return 1;
+}
+
+void Fifo_Drop(cc_fifo* p)
+{
+	ArrayDrop(&p->_Base);
+	p->_Read = p->_Base._Begin;
+}
+
+uint8_t* Fifo_Write(cc_fifo* p, const void* Ptr, size_t Length, size_t Align)
+{
+    size_t Total = Data_Size(p->_Base._Begin);
+    size_t Read = p->_Read - p->_Base._Begin;
+    size_t End = p->_Base._End - p->_Base._Begin + Length + SAFETAIL;
+    uint8_t* Result;
+
+    if (End>Total && Read>0)
+    {
+        memmove(p->_Base._Begin,p->_Read,FIFO_SIZE(*p));
+        p->_Read = p->_Base._Begin;
+        p->_Base._End -= Read;
+        End -= Read;
+        Read = 0;
+    }
+
+    if (End>Total)
+    {
+        if (!ArrayAlloc(&p->_Base,End,Align))
+            return NULL;
+        p->_Read = p->_Base._Begin+Read;
+    }
+
+    Result = p->_Base._End;
+    p->_Base._End += Length;
+
+    if (Ptr)
+        memcpy(Result,Ptr,Length);
+    return Result;
+}
diff --git a/corec/corec/array/array.h b/corec/corec/array/array.h
new file mode 100644
index 0000000..33a88b9
--- /dev/null
+++ b/corec/corec/array/array.h
@@ -0,0 +1,167 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARRAY_H
+#define __ARRAY_H
+
+#include "corec/corec.h"
+#include "corec/memheap.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(ARRAY_EXPORTS)
+#define ARRAY_DLL DLLEXPORT
+#elif defined(ARRAY_IMPORTS)
+#define ARRAY_DLL DLLIMPORT
+#else
+#define ARRAY_DLL
+#endif
+
+#define Data_Var(type,name,len)  struct { size_t n; type p[len]; } __##name; type* name = (__##name.n = sizeof(__##name.p),__##name.p)
+ARRAY_DLL bool_t Data_ReAlloc(uint8_t** a,size_t n);
+ARRAY_DLL size_t Data_Size(const uint8_t* a);
+ARRAY_DLL void Data_Release(uint8_t** a);
+ARRAY_DLL void Data_Clear(uint8_t** a); // release memory, but keep heap reference
+ARRAY_DLL bool_t Data_Set(uint8_t** a,const uint8_t* b,size_t pos,size_t len);
+
+typedef struct array
+{
+	// these are private members, use ARRAY macros to access them
+	uint8_t* _Begin;
+	uint8_t* _End;
+
+} array;
+
+typedef	int (*arraycmp)(const void* Param, const void* a,const void* b);
+
+#define ARRAY_AUTO_COUNT    ((size_t)-1)
+
+static INLINE void ArrayInit(array* p) { p->_Begin = NULL; p->_End = NULL; }
+ARRAY_DLL void ArrayInitEx(array*,const cc_memheap*);
+ARRAY_DLL void ArrayClear(array*);
+ARRAY_DLL void ArrayDrop(array*);
+ARRAY_DLL size_t ArraySize(const array*);
+ARRAY_DLL bool_t ArrayEq(const array* a, const array* b);
+ARRAY_DLL bool_t ArrayCopy(array*,const array* In);
+ARRAY_DLL bool_t ArrayResize(array*,size_t Size,size_t Align);
+ARRAY_DLL void ArrayZero(array*);
+ARRAY_DLL intptr_t ArrayFindEx(const array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, const void* CmpParam, bool_t* Found);
+ARRAY_DLL bool_t ArrayAlloc(array* p,size_t Total,size_t Align);
+ARRAY_DLL bool_t ArrayAppend(array* p, const void* Ptr, size_t Length, size_t Align);
+ARRAY_DLL bool_t ArrayAppendStr(array* p, const tchar_t* Ptr, bool_t Merge, size_t Align);
+ARRAY_DLL void ArrayShrink(array* p, size_t Length);
+ARRAY_DLL intptr_t ArrayAddEx(array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, const void* CmpParam, size_t Align);
+ARRAY_DLL bool_t ArrayRemoveEx(array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, const void* CmpParam);
+ARRAY_DLL void ArraySortEx(array* p, size_t Count, size_t Width, arraycmp Cmp, const void* CmpParam, bool_t Unique);
+ARRAY_DLL bool_t ArrayInsert(array* p, size_t Ofs, const void* Ptr, size_t Length, size_t Align);
+ARRAY_DLL void ArrayDelete(array* p, size_t Ofs,  size_t Length);
+ARRAY_DLL void ArrayRandomize(array* Array,size_t Width,uint32_t RndSeed);
+
+#define ArrayAdd(p,type,Data,Cmp,CmpParam,Align)  ArrayAddEx(p,ARRAYCOUNT(*p,type),sizeof(type),Data,Cmp,CmpParam,Align)
+#define ArrayRemove(p,type,Data,Cmp,CmpParam)     ArrayRemoveEx(p,ARRAYCOUNT(*p,type),sizeof(type),Data,Cmp,CmpParam)
+#define ArrayFind(p,type,Data,Cmp,CmpParam,Found) ArrayFindEx(p,ARRAYCOUNT(*p,type),sizeof(type),Data,Cmp,CmpParam,Found)
+#define ArraySort(p,type,Cmp,CmpParam,Unique)     ArraySortEx(p,ARRAYCOUNT(*p,type),sizeof(type),Cmp,CmpParam,Unique)
+
+#ifdef CONFIG_DEBUGCHECKS
+#define ARRAYBEGIN(Array,Type)		(assert(&(Array)!=NULL),(Type*)((Array)._Begin))
+#define ARRAYEND(Array,Type)		(assert(&(Array)!=NULL),(Type*)((Array)._End))
+#define ARRAYEMPTY(Array)			(assert(&(Array)!=NULL),(Array)._Begin==(Array)._End)
+#else
+#define ARRAYBEGIN(Array,Type)		((Type*)((Array)._Begin))
+#define ARRAYEND(Array,Type)		((Type*)((Array)._End))
+#define ARRAYEMPTY(Array)			((Array)._Begin==(Array)._End)
+#endif
+#define ARRAYCOUNT(Array,Type)		((size_t)(ARRAYEND(Array,Type)-ARRAYBEGIN(Array,Type)))
+
+// TODO: move this to base/mem and depend on "mem" platform dependently(?)
+typedef struct block
+{
+	const uint8_t* Ptr;
+	uintptr_t Id;
+
+} block;
+//end TODO
+
+#ifdef TARGET_PALMOS
+
+typedef struct arrayblock
+{
+	array Array;
+	block Block;
+
+} arrayblock;
+
+ARRAY_DLL void ArrayBlockClear(arrayblock*);
+ARRAY_DLL void ArrayBlockLock(arrayblock*);
+
+#else
+
+typedef struct arrayblock
+{
+	array Array;
+
+} arrayblock;
+
+#define ArrayBlockClear(a) ArrayClear(&(a)->Array)
+#define ArrayBlockLock(a) {}
+
+#endif
+
+#define SAFETAIL	256
+
+typedef struct cc_fifo
+{
+	// private members
+	array _Base;
+	uint8_t* _Read;
+
+} cc_fifo;
+
+static INLINE void Fifo_Init(cc_fifo* p) { ArrayInit(&p->_Base); p->_Read = NULL; }
+ARRAY_DLL void Fifo_Clear(cc_fifo*);
+ARRAY_DLL void Fifo_Drop(cc_fifo*);
+ARRAY_DLL bool_t Fifo_Alloc(cc_fifo* p, size_t Size, size_t Align);
+ARRAY_DLL uint8_t* Fifo_Write(cc_fifo*, const void* Ptr, size_t Length, size_t Align);
+
+static INLINE void Fifo_Readed(cc_fifo* p, size_t Length) 
+{ 
+    p->_Read += Length; 
+}
+
+#define FIFO_SIZE(p)  (ARRAYEND((p)._Base,uint8_t)-(p)._Read)
+#define FIFO_BEGIN(p) ((p)._Read)
+#define FIFO_END(p)   ARRAYEND((p)._Base,uint8_t)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/corec/corec/array/array.proj b/corec/corec/array/array.proj
new file mode 100644
index 0000000..86b6b43
--- /dev/null
+++ b/corec/corec/array/array.proj
@@ -0,0 +1,6 @@
+GROUP array
+{
+  USE corec
+  SOURCE array.c
+  HEADER array.h
+}
diff --git a/corec/corec/banned.h b/corec/corec/banned.h
new file mode 100644
index 0000000..6061a86
--- /dev/null
+++ b/corec/corec/banned.h
@@ -0,0 +1,61 @@
+/***
+* banned.h - list of Microsoft Security Development Lifecycle banned APIs
+*
+* Purpose:
+*       This include file contains a list of banned API which should not be used in new code and 
+*       removed from legacy code over time
+* History
+* 01-Jan-2006 - mikehow - Initial Version
+* 22-Apr-2008 - mikehow	- Updated to SDL 4.1, commented out recommendations and added memcpy
+*
+***/
+
+#ifndef _INC_BANNED
+#	define _INC_BANNED
+#endif
+
+#ifdef _MSC_VER
+// Some of these functions are Windows specific
+#	pragma once
+#	pragma deprecated (strcpy, strcpyA, strcpyW, wcscpy, _tcscpy, _mbscpy, StrCpy, StrCpyA, StrCpyW, lstrcpy, lstrcpyA, lstrcpyW, _tccpy, _mbccpy)
+#	pragma deprecated (strcat, strcatA, strcatW, wcscat, _tcscat, _mbscat, StrCat, StrCatA, StrCatW, lstrcat, lstrcatA, lstrcatW, StrCatBuff, StrCatBuffA, StrCatBuffW, StrCatChainW, _tccat, _mbccat)
+#	pragma deprecated (wnsprintf, wnsprintfA, wnsprintfW, sprintfW, sprintfA, wsprintf, wsprintfW, wsprintfA, sprintf, swprintf, _stprintf, _snwprintf, _snprintf, _sntprintf)
+#	pragma deprecated (wvsprintf, wvsprintfA, wvsprintfW, vsprintf, _vstprintf, vswprintf)
+#	pragma deprecated (_vsnprintf, _vsnwprintf, _vsntprintf, wvnsprintf, wvnsprintfA, wvnsprintfW)
+#	pragma deprecated (strncpy, wcsncpy, _tcsncpy, _mbsncpy, _mbsnbcpy, StrCpyN, StrCpyNA, StrCpyNW, StrNCpy, strcpynA, StrNCpyA, StrNCpyW, lstrcpyn, lstrcpynA, lstrcpynW)
+#	pragma deprecated (strncat, wcsncat, _tcsncat, _mbsncat, _mbsnbcat, StrCatN, StrCatNA, StrCatNW, StrNCat, StrNCatA, StrNCatW, lstrncat, lstrcatnA, lstrcatnW, lstrcatn)
+#	pragma deprecated (strtok, _tcstok, wcstok, _mbstok)
+#	pragma deprecated (makepath, _tmakepath,  _makepath, _wmakepath)
+#	pragma deprecated (_splitpath, _tsplitpath, _wsplitpath)
+#	pragma deprecated (scanf, wscanf, _tscanf, sscanf, swscanf, _stscanf, snscanf, snwscanf, _sntscanf)
+//#	pragma deprecated (_itoa, _itow, _i64toa, _i64tow, _ui64toa, _ui64tot, _ui64tow, _ultoa, _ultot, _ultow)
+#	pragma deprecated (gets, _getts, _gettws)
+#	pragma deprecated (IsBadWritePtr, IsBadHugeWritePtr, IsBadReadPtr, IsBadHugeReadPtr, IsBadCodePtr, IsBadStringPtr)
+#	pragma deprecated (CharToOem, CharToOemA, CharToOemW, OemToChar, OemToCharA, OemToCharW, CharToOemBuffA, CharToOemBuffW)
+//#	pragma deprecated (alloca, _alloca)
+#	pragma deprecated (strlen, wcslen, _mbslen, _mbstrlen, StrLen, lstrlen)
+#	pragma deprecated (memcpy, RtlCopyMemory, CopyMemory)
+#else 
+#ifdef __GNUC__
+// Some of these functions are Windows specific, so you may want to add *nix specific banned function calls
+#	pragma GCC poison strcpy strcpyA strcpyW wcscpy _tcscpy _mbscpy StrCpy StrCpyA StrCpyW lstrcpy lstrcpyA lstrcpyW _tccpy _mbccpy
+#	pragma GCC poison strcat strcatA strcatW wcscat _tcscat _mbscat StrCat StrCatA StrCatW lstrcat lstrcatA lstrcatW StrCatBuff StrCatBuffA StrCatBuffW StrCatChainW _tccat _mbccat
+#	pragma GCC poison wnsprintf wnsprintfA wnsprintfW sprintfW sprintfA wsprintf wsprintfW wsprintfA sprintf swprintf _stprintf _snwprintf _snprintf _sntprintf
+#	pragma GCC poison wvsprintf wvsprintfA wvsprintfW vsprintf _vstprintf vswprintf
+#	pragma GCC poison _vsnprintf _vsnwprintf _vsntprintf wvnsprintf wvnsprintfA wvnsprintfW
+#	pragma GCC poison strncpy wcsncpy _tcsncpy _mbsncpy _mbsnbcpy StrCpyN StrCpyNA StrCpyNW StrNCpy strcpynA StrNCpyA StrNCpyW lstrcpyn lstrcpynA lstrcpynW
+#	pragma GCC poison strncat wcsncat _tcsncat _mbsncat _mbsnbcat StrCatN StrCatNA StrCatNW StrNCat StrNCatA StrNCatW lstrncat lstrcatnA lstrcatnW lstrcatn
+#	pragma GCC poison strtok _tcstok wcstok _mbstok
+#	pragma GCC poison makepath _tmakepath  _makepath _wmakepath
+#	pragma GCC poison _splitpath _tsplitpath _wsplitpath
+#	pragma GCC poison scanf wscanf _tscanf sscanf swscanf _stscanf snscanf snwscanf _sntscanf
+//#	pragma GCC poison _itoa _itow _i64toa _i64tow _ui64toa _ui64tot _ui64tow _ultoa _ultot _ultow
+#	pragma GCC poison gets _getts _gettws
+#	pragma GCC poison IsBadWritePtr IsBadHugeWritePtr IsBadReadPtr IsBadHugeReadPtr IsBadCodePtr IsBadStringPtr
+#	pragma GCC poison CharToOem CharToOemA CharToOemW OemToChar OemToCharA OemToCharW CharToOemBuffA CharToOemBuffW
+//#	pragma GCC poison alloca _alloca
+#	pragma GCC poison strlen wcslen _mbslen _mbstrlen StrLen lstrlen
+#	pragma GCC poison memcpy RtlCopyMemory CopyMemory
+#endif
+
+#endif  /* _INC_BANNED */
diff --git a/corec/corec/confhelper.h b/corec/corec/confhelper.h
new file mode 100644
index 0000000..fd6a811
--- /dev/null
+++ b/corec/corec/confhelper.h
@@ -0,0 +1,96 @@
+/*
+  $Id: confhelper.h 777 2011-07-03 09:13:25Z robux4 $
+
+  Copyright (c) 2010, CoreCodec, Inc.
+  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 CoreCodec, Inc. 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
+*/
+
+#ifndef __CONFIG_HELPER_H
+#define __CONFIG_HELPER_H
+
+/**** SHOULD MATCH THE ONE OF COREMAKE ****/
+
+/* force some defines */
+
+#if defined(TARGET_WINCE) || defined(TARGET_SYMBIAN)
+#undef COREMAKE_UNICODE
+#define COREMAKE_UNICODE /* platforms where Unicode is mandatory */
+#endif
+
+#if (defined(TARGET_PALMOS) && defined(IX86)) || defined(TARGET_SYMBIAN)
+#undef COREMAKE_STATIC /* platforms where dynamic libraries are not supported */
+#define COREMAKE_STATIC
+#endif
+
+#if (defined(ARM) || defined(MIPS) || defined(SH3) || defined(SH4)) && !defined(TARGET_IPHONE_SDK)
+#undef CONFIG_DYNCODE
+#define CONFIG_DYNCODE /* platforms when dynamic code can be used */
+#endif
+
+#if defined(IX86) || defined(IX86_64)
+#undef CONFIG_UNALIGNED_ACCESS
+#define CONFIG_UNALIGNED_ACCESS /* pointers can use unaligned memory */
+#endif
+
+#if defined(TARGET_WIN32) || defined(TARGET_WIN64) || defined(TARGET_WINCE) || defined(TARGET_OSX) || defined(TARGET_LINUX)
+#define CONFIG_FILEPOS_64 /* platforms where 64 bits file position/size should be favoured */
+#endif
+
+#if defined(TARGET_WINCE) || defined(TARGET_SYMBIAN) || defined(TARGET_PALMOS) || defined(ARM) || defined(MIPS)
+#define CONFIG_FIXED_POINT /* platforms where fixed point arithmetic processing should favoured */
+#endif
+
+/* forbid some defines */
+
+#if defined(TARGET_PALMOS) || defined(TARGET_LINUX) || defined(TARGET_PS2SDK)
+#undef COREMAKE_UNICODE /* platforms where Unicode is handled via UTF-8 strings */
+#endif
+
+#if defined(TARGET_PALMOS)
+#undef CONFIG_FILEPOS_64 /* platforms where 64 bits file position/size should not be used */
+#endif
+
+#if !defined(ARM) || defined(TARGET_SYMBIAN) || defined(TARGET_IPHONE)
+#undef CONFIG_WMMX /* platforms that don't support Wireless MMX CPUs/instructions */
+#endif
+
+#if !defined(ARM) || defined(TARGET_SYMBIAN) || defined(TARGET_PALMOS)
+#undef CONFIG_ARMV6 /* platforms that don't support ARMv6 CPUs/instructions */
+#endif
+
+#if !defined(IX86) || defined(TARGET_SYMBIAN)
+#undef CONFIG_MMX /* platforms that don't support MMX CPUs/instructions */
+#endif
+
+#if !defined(ARM) || (!defined(TARGET_IPHONE) && !defined(TARGET_ANDROID))
+#undef CONFIG_NEON /* platforms that don't support NEON/ARMv7 instructions */
+#endif
+
+#if !defined(POWERPC)
+#undef CONFIG_ALTIVEC
+#endif
+
+#endif /* __CONFIG_HELPER_H */
diff --git a/corec/corec/corec.h b/corec/corec/corec.h
new file mode 100644
index 0000000..e34b594
--- /dev/null
+++ b/corec/corec/corec.h
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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.
+ *
+ ****************************************************************************/
+
+#ifndef _COREC_H
+#define _COREC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER > 1000)
+#pragma once
+#pragma warning(push, 4)
+#pragma warning(disable : 4100 4710 4514 4201 4714 4115 4206 4055 4214 4998 4273 4127 4114 4512)
+#endif
+
+#include "portab.h"
+#include "memalloc.h"
+#include "err.h"
+#include "helper.h"
+
+#if defined(NDEBUG) && defined(CONFIG_DEBUGCHECKS)
+#undef CONFIG_DEBUGCHECKS
+#endif
+#if defined(NDEBUG) && defined(CONFIG_DEBUG_LEAKS)
+#undef CONFIG_DEBUG_LEAKS
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _COREC_H */
diff --git a/corec/corec/corec.proj b/corec/corec/corec.proj
new file mode 100644
index 0000000..c428d23
--- /dev/null
+++ b/corec/corec/corec.proj
@@ -0,0 +1,18 @@
+#include "*/*.proj"
+
+GROUP corec
+{
+  INCLUDE ..
+  EXPINCLUDE ..
+  DEFINE HAVE_COREC_H
+  EXPDEFINE HAVE_COREC_H
+  HEADER corec.h
+  HEADER err.h
+  HEADER helper.h
+  HEADER memalloc.h
+  HEADER portab.h
+  IF CONFIG_SAFE_C
+    HEADER banned.h
+  ENDIF
+  HEADER(!COREMAKE_CONFIG_HELPER) confhelper.h
+}
diff --git a/corec/corec/err.h b/corec/corec/err.h
new file mode 100644
index 0000000..72c0359
--- /dev/null
+++ b/corec/corec/err.h
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ERR_H
+#define __ERR_H
+
+#define ERR_ID				FOURCC('E','R','R','_')
+
+//----------------------------------------------------------------
+// error codes
+
+#define ERR_NONE			(err_t)0
+#define ERR_BUFFER_FULL		(err_t)-1  // 0xFFFFFFFF
+#define ERR_OUT_OF_MEMORY	(err_t)-2  // 0xFFFFFFFE
+#define ERR_INVALID_DATA	(err_t)-3  // 0xFFFFFFFD
+#define ERR_INVALID_PARAM	(err_t)-4  // 0xFFFFFFFC
+#define ERR_NOT_SUPPORTED	(err_t)-5  // 0xFFFFFFFB
+#define ERR_NEED_MORE_DATA	(err_t)-6  // 0xFFFFFFFA
+                       // stream added    0xFFFFFFF9
+#define ERR_FILE_NOT_FOUND	(err_t)-8  // 0xFFFFFFF8
+#define ERR_END_OF_FILE		(err_t)-9  // 0xFFFFFFF7
+#define ERR_DEVICE_ERROR	(err_t)-10 // 0xFFFFFFF6
+#define ERR_SYNCED			(err_t)-11 // 0xFFFFFFF5
+#define ERR_DATA_NOT_FOUND	(err_t)-12 // 0xFFFFFFF4
+#define ERR_PROTO_NOT_FOUND (err_t)-13 // 0xFFFFFFF3
+#define ERR_NOT_DIRECTORY	(err_t)-14 // 0xFFFFFFF2
+#define ERR_NOT_COMPATIBLE	(err_t)-15 // 0xFFFFFFF1
+#define ERR_CONNECT_FAILED	(err_t)-16 // 0xFFFFFFF0
+#define ERR_DROPPING		(err_t)-17 // 0xFFFFFFEF
+#define ERR_STOPPED			(err_t)-18 // 0xFFFFFFEE
+#define ERR_UNAUTHORIZED	(err_t)-19 // 0xFFFFFFED
+#define ERR_LOADING_HEADER	(err_t)-20 // 0xFFFFFFEC
+#define ERR_READ            (err_t)-21 // 0xFFFFFFEB
+#define ERR_WRITE           (err_t)-22 // 0xFFFFFFEA
+#define ERR_UNRESOLVED_ADDR	(err_t)-23 // 0xFFFFFFE9
+#define ERR_NO_NETWORK      (err_t)-24 // 0xFFFFFFE8
+#define ERR_TIME_OUT        (err_t)-25 // 0xFFFFFFE7
+#define ERR_KEY_NOT_UNIQUE  (err_t)-26 // 0xFFFFFFE6
+#define ERR_NOT_CONST       (err_t)-27 // 0xFFFFFFE5
+#define ERR_REDIRECTED      (err_t)-28 // 0xFFFFFFE4
+#define ERR_CANCELED        (err_t)-29 // 0xFFFFFFE3
+#define ERR_STREAM_CACHED   (err_t)-30 // 0xFFFFFFE2
+#define ERR_SERVER_ERROR    (err_t)-31 // 0xFFFFFFE1
+#define ERR_NOT_USABLE      (err_t)-32 // 0xFFFFFFE0
+
+// buffer full: data is not processed, retry later
+// need more data: data is processed, but need more to continue
+
+#endif
diff --git a/corec/corec/helper.h b/corec/corec/helper.h
new file mode 100644
index 0000000..12cb0dd
--- /dev/null
+++ b/corec/corec/helper.h
@@ -0,0 +1,293 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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.
+ *
+ ****************************************************************************/
+
+#ifndef __HELPER_H
+#define __HELPER_H
+
+#ifdef TARGET_LINUX
+#include <stddef.h>
+#define OFS(name,item) offsetof(name,item)
+#else
+#define OFS(name,item) ((uintptr_t)&(((name*)NULL)->item))
+#endif
+
+#define ALIGN64(x) (((x) + 63) & ~63)
+#define ALIGN16(x) (((x) + 15) & ~15)
+#define ALIGN8(x) (((x) + 7) & ~7)
+#define ALIGN4(x) (((x) + 3) & ~3)
+#define ALIGN2(x) (((x) + 1) & ~1)
+
+#define GET_R(x)   ((uint8_t)(((x) >> 0) & 255))
+#define GET_G(x)   ((uint8_t)(((x) >> 8) & 255))
+#define GET_B(x)   ((uint8_t)(((x) >> 16) & 255))
+
+#define SWAP32(a) ((((uint32_t)(a) >> 24) & 0x000000FF) | (((uint32_t)(a) >> 8)  & 0x0000FF00)|\
+                  (((uint32_t)(a) << 8)  & 0x00FF0000) | (((uint32_t)(a) << 24) & 0xFF000000))
+
+#define SWAP16(a) ((uint16_t)((((uint32_t)(a) >> 8) & 0xFF) | (((uint32_t)(a) << 8) & 0xFF00)))
+#define SWAP64(a) (((uint64_t)SWAP32(a) << 32) | SWAP32((uint64_t)(a)>>32))
+
+#define LSHIFT(v,n)			((v)<<(n))
+#define RSHIFT(v,n)			((v)>>(n))
+#define RLSHIFT(v,n)		(((n)>=0)?RSHIFT(v,n):LSHIFT(v,-(n)))
+#define RSHIFT_ROUND(v,n)	(((v)+(1<<(n-1)))>>(n))
+#define RSHIFT_ROUND_COND(v,n)	((n)>0 ? RSHIFT_ROUND(v,n) : v)
+
+#ifdef IS_BIG_ENDIAN
+#define INT64BE(a) (a)
+#define INT64LE(a) SWAP64(a)
+#define INT32BE(a) (a)
+#define INT32LE(a) SWAP32(a)
+#define INT16BE(a) (a)
+#define INT16LE(a) SWAP16(a)
+#else
+#define INT64LE(a) (a)
+#define INT64BE(a) SWAP64(a)
+#define INT32LE(a) (a)
+#define INT32BE(a) SWAP32(a)
+#define INT16LE(a) (a)
+#define INT16BE(a) SWAP16(a)
+#endif
+
+#define LOAD8(ptr,ofs)		(((uint8_t*)(ptr))[ofs])
+#if defined(CONFIG_UNALIGNED_ACCESS)
+#define LOAD16LE(ptr)		INT16LE(*(uint16_t*)(ptr))
+#define LOAD16BE(ptr)		INT16BE(*(uint16_t*)(ptr))
+#define LOAD32LE(ptr)		INT32LE(*(uint32_t*)(ptr))
+#define LOAD32BE(ptr)		INT32BE(*(uint32_t*)(ptr))
+#define LOAD64LE(ptr)		INT64LE(*(uint64_t*)(ptr))
+#define LOAD64BE(ptr)		INT64BE(*(uint64_t*)(ptr))
+#else
+#define LOAD16LE(ptr)		((uint16_t)((LOAD8(ptr,1)<<8)|LOAD8(ptr,0)))
+#define LOAD16BE(ptr)		((uint16_t)((LOAD8(ptr,0)<<8)|LOAD8(ptr,1)))
+#define LOAD32LE(ptr)		((LOAD8(ptr,3)<<24)|(LOAD8(ptr,2)<<16)|(LOAD8(ptr,1)<<8)|LOAD8(ptr,0))
+#define LOAD32BE(ptr)		((LOAD8(ptr,0)<<24)|(LOAD8(ptr,1)<<16)|(LOAD8(ptr,2)<<8)|LOAD8(ptr,3))
+#define LOAD64LE(ptr)		((((uint64_t)LOAD8(ptr,0))    )|(((uint64_t)LOAD8(ptr,1))<< 8)|(((uint64_t)LOAD8(ptr,2))<<16)|(((uint64_t)LOAD8(ptr,3))<<24)| \
+							 (((uint64_t)LOAD8(ptr,4))<<32)|(((uint64_t)LOAD8(ptr,5))<<40)|(((uint64_t)LOAD8(ptr,6))<<48)|(((uint64_t)LOAD8(ptr,0))<<56))
+#define LOAD64BE(ptr)		((((uint64_t)LOAD8(ptr,0))<<56)|(((uint64_t)LOAD8(ptr,1))<<48)|(((uint64_t)LOAD8(ptr,2))<<40)|(((uint64_t)LOAD8(ptr,3))<<32)| \
+							 (((uint64_t)LOAD8(ptr,4))<<24)|(((uint64_t)LOAD8(ptr,5))<<16)|(((uint64_t)LOAD8(ptr,6))<< 8)|(((uint64_t)LOAD8(ptr,0))    ))
+#endif
+
+
+#define STORE8(p, o, i)      ((uint8_t *) (p))[o] = (uint8_t) ((i) & 0xFF)
+
+#if defined(CONFIG_UNALIGNED_ACCESS) && defined(IS_BIG_ENDIAN)
+
+#define STORE16BE(p, i)      *((uint16_t*)(p))=i
+#define STORE32BE(p, i)      *((uint32_t*)(p))=i
+#define STORE64BE(p, i)      *((uint64_t*)(p))=i
+#else
+#define STORE16BE(p, i)      STORE8(p, 1, i), STORE8(p, 0, ((uint16_t)i) >> 8)
+#define STORE32BE(p, i)      STORE8(p, 3, i), STORE8(p, 2, ((uint32_t)i) >> 8), STORE8(p, 1, ((uint32_t) i) >> 16), STORE8(p, 0, ((uint32_t) i) >> 24)
+#define STORE64BE(p, i)      STORE8(p, 7, i), STORE8(p, 6, ((uint64_t)i) >> 8), STORE8(p, 5, ((uint64_t)i) >> 16), STORE8(p, 4, ((uint64_t)i) >> 24), \
+                                 STORE8(p, 3, ((uint64_t)i) >> 32), STORE8(p, 2, ((uint64_t)i) >> 40), STORE8(p, 1, ((uint64_t)i) >> 48), STORE8(p, 0, ((uint64_t)i) >> 56)
+#endif
+
+#if defined(CONFIG_UNALIGNED_ACCESS) && defined(IS_LITTLE_ENDIAN)
+#define STORE16LE(p, i)      *((uint16_t*)(p))=i
+#define STORE32LE(p, i)      *((uint32_t*)(p))=i
+#define STORE64LE(p, i)      *((uint64_t*)(p))=i
+#else
+#define STORE16LE(p, i)      STORE8(p, 0, i), STORE8(p, 1, ((uint16_t)i) >> 8)
+#define STORE32LE(p, i)      STORE8(p, 0, i), STORE8(p, 1, ((uint32_t)i) >> 8), STORE8(p, 2, ((uint32_t)i) >> 16), STORE8(p, 3, ((uint32_t)i) >> 24)
+#define STORE64LE(p, i)      STORE8(p, 0, i), STORE8(p, 1, ((uint64_t)i) >> 8), STORE8(p, 2, ((uint64_t)i) >> 16), STORE8(p, 3, ((uint64_t)i) >> 24), \
+                                 STORE8(p, 4, ((uint64_t)i) >> 32), STORE8(p, 5, ((uint64_t)i) >> 40), STORE8(p, 6, ((uint64_t)i) >> 48), STORE8(p, 7, ((uint64_t)i) >> 56)
+#endif
+
+#ifdef IS_BIG_ENDIAN
+#define LOAD16(ptr) LOAD16BE(ptr)
+#define LOAD32(ptr) LOAD32BE(ptr)
+#define LOAD64(ptr) LOAD64BE(ptr)
+#define LOAD16SW(ptr) LOAD16LE(ptr)
+#define LOAD32SW(ptr) LOAD32LE(ptr)
+#define LOAD64SW(ptr) LOAD64LE(ptr)
+#else
+#define LOAD16(ptr) LOAD16LE(ptr)
+#define LOAD32(ptr) LOAD32LE(ptr)
+#define LOAD64(ptr) LOAD64LE(ptr)
+#define LOAD16SW(ptr) LOAD16BE(ptr)
+#define LOAD32SW(ptr) LOAD32BE(ptr)
+#define LOAD64SW(ptr) LOAD64BE(ptr)
+#endif
+
+#if defined(__GNUC__) && defined(MIPS)
+#undef LOAD32
+static INLINE uint32_t LOAD32(const void* ptr) { uint32_t v; asm ("ulw %0,0(%1)\n" : "=&r" (v) : "r" (ptr)); return v; }
+#endif
+
+// a=(a+c+1)/2
+// b=(b+d+1)/2
+#define AVG32R(a,b,c,d) \
+	c^=a; \
+	d^=b; \
+	a|=c; \
+	b|=d; \
+	c &= 0xFEFEFEFE; \
+	d &= 0xFEFEFEFE; \
+	a-=c>>1; \
+	b-=d>>1; 
+
+#define AVG64R(a,b,c,d) \
+	c^=a; \
+	d^=b; \
+	a|=c; \
+	b|=d; \
+	c &= 0xFEFEFEFEFEFEFEFE; \
+	d &= 0xFEFEFEFEFEFEFEFE; \
+	a-=c>>1; \
+	b-=d>>1; 
+
+// a=(a+c)/2
+// b=(b+d)/2
+#ifdef ARM
+#define AVG32NR(a,b,c,d) \
+	c^=a; \
+	d^=b; \
+	a &= ~c; \
+	b &= ~d; \
+	c &= 0xFEFEFEFE; \
+	d &= 0xFEFEFEFE; \
+	a+=c>>1; \
+	b+=d>>1; 
+#else
+#define AVG32NR(a,b,c,d) \
+	c^=a; \
+	d^=b; \
+	a|=c; \
+	b|=d; \
+	a-=c & 0x01010101; \
+	b-=d & 0x01010101; \
+	c &= 0xFEFEFEFE; \
+	d &= 0xFEFEFEFE; \
+	a-=c>>1; \
+	b-=d>>1; 
+#endif
+
+#define AVG64NR(a,b,c,d) \
+	c^=a; \
+	d^=b; \
+	a|=c; \
+	b|=d; \
+	a-=c & 0x0101010101010101; \
+	b-=d & 0x0101010101010101; \
+	c &= 0xFEFEFEFEFEFEFEFE; \
+	d &= 0xFEFEFEFEFEFEFEFE; \
+	a-=c>>1; \
+	b-=d>>1; 
+
+#define _abs(a) (((a)>=0)?(a):-(a))
+
+static INLINE int MIDDLE(int a, int b, int c)
+{
+    int bb = b;
+
+    if (a > b)
+    {
+        bb = a;
+        a = b;
+    }
+
+    if (bb > c)
+        bb = c;
+
+    if (a > bb)
+        bb = a;
+
+    return bb;
+}
+
+static INLINE size_t _log2(uint32_t data)
+{
+	size_t i;
+	if (!data) ++data;
+	for (i=0;data;++i)
+		data >>= 1;
+    return i;
+}
+
+static INLINE int64_t Scale64(int64_t v,int64_t Num,int64_t Den)
+{
+	if (Den) 
+		return (v * Num) / Den;
+	return 0;
+}
+
+static INLINE int Scale32(int64_t v, int64_t Num, int64_t Den)
+{
+    return (int)Scale64(v,Num,Den);
+}
+
+#define SWAPVAL(type,a,b) { type __t = (a); (a)=(b); (b)=__t; }
+
+typedef int32_t datetime_t;
+
+#define INVALID_DATETIME_T  0
+#define MIN_DATETIME_T  ((datetime_t) 0xFFFFFFFF)
+#define MAX_DATETIME_T  ((datetime_t) 0x7FFFFFFF)
+
+static INLINE int Fix16Mul(int a,int b)
+{
+    return (int)(((int64_t)(a<<8)*(int64_t)(b<<8))>>32);
+}
+
+static INLINE uint32_t _ones(uint32_t x)
+{
+    x -= ((x >> 1) & 0x55555555);
+    x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
+    x = (((x >> 4) + x) & 0x0f0f0f0f);
+    x += (x >> 8);
+    x += (x >> 16);
+    return x & 0x0000003f;
+}
+
+static INLINE uint32_t _floor_log2(uint32_t x)
+{
+    x |= (x >> 1);
+    x |= (x >> 2);
+    x |= (x >> 4);
+    x |= (x >> 8);
+    x |= (x >> 16);
+    return _ones(x) - 1;
+}
+
+#if !defined(min) && !defined(NOMINMAX)
+#  define min(x,y)  ((x)>(y)?(y):(x))
+#endif
+
+#if !defined(max) && !defined(NOMINMAX)
+#  define max(x,y)  ((x)<(y)?(y):(x))
+#endif
+
+#ifndef sign
+#  define sign(x) ((x)<0?-1:1)
+#endif
+
+#define abs_diff(x,y)  ((x)>(y)?((x)-(y)):((y)-(x)))
+
+#endif
diff --git a/corec/corec/helpers/charconvert/charconvert.h b/corec/corec/helpers/charconvert/charconvert.h
new file mode 100644
index 0000000..89f433c
--- /dev/null
+++ b/corec/corec/helpers/charconvert/charconvert.h
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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.
+ *
+ ****************************************************************************/
+
+#ifndef __CHARCONVERT_H
+#define __CHARCONVERT_H
+
+#include "corec/corec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(CHARCONVERT_EXPORTS)
+#define CHARCONVERT_DLL DLLEXPORT
+#elif defined(CHARCONVERT_IMPORTS)
+#define CHARCONVERT_DLL DLLIMPORT
+#else
+#define CHARCONVERT_DLL
+#endif
+
+typedef struct charconv charconv;
+
+#define MAX_CHARSET_NAME    16
+
+#define CHARSET_DEFAULT	T("")
+#if defined(TARGET_WIN)
+#define CHARSET_WCHAR	T("UCS-2")
+#elif SIZEOF_WCHAR==4
+#define CHARSET_WCHAR	T("UTF-32")
+#elif SIZEOF_WCHAR==2
+#define CHARSET_WCHAR	T("UTF-16")
+#else
+#error unsupported wchar_t size!
+#endif
+#define CHARSET_UTF8	T("UTF-8")
+#define CHARSET_UTF16	T("UTF-16")
+
+CHARCONVERT_DLL void CharConvDefault(tchar_t* Out, size_t OutLen);
+CHARCONVERT_DLL charconv* CharConvOpen(const tchar_t* From, const tchar_t* To);
+CHARCONVERT_DLL void CharConvClose(charconv*);
+CHARCONVERT_DLL void CharConvSS(charconv*, char* Out,    size_t OutLen, const char* In);
+CHARCONVERT_DLL void CharConvWS(charconv*, wchar_t* Out, size_t OutLen, const char* In);
+CHARCONVERT_DLL void CharConvSW(charconv*, char* Out,    size_t OutLen, const wchar_t* In);
+CHARCONVERT_DLL void CharConvWW(charconv*, wchar_t* Out, size_t OutLen, const wchar_t* In);
+
+#if SIZEOF_WCHAR==2
+#define CharConvUS CharConvWS
+#define CharConvSU CharConvSW
+#define CharConvUW CharConvWW
+#define CharConvWU CharConvWW
+#else
+CHARCONVERT_DLL void CharConvUS(charconv*, utf16_t* Out, size_t OutLen, const char* In);
+CHARCONVERT_DLL void CharConvSU(charconv*, char* Out,    size_t OutLen, const utf16_t* In);
+CHARCONVERT_DLL void CharConvUW(charconv*, utf16_t* Out, size_t OutLen, const wchar_t* In);
+CHARCONVERT_DLL void CharConvWU(charconv*, wchar_t* Out, size_t OutLen, const utf16_t* In);
+#endif
+
+#ifdef UNICODE
+#define CharConvTS CharConvWS
+#define CharConvTW CharConvWW
+#define CharConvST CharConvSW
+#define CharConvWT CharConvWW
+#define CharConvTU CharConvWU
+#define CharConvUT CharConvUW
+#else
+#define CharConvTS CharConvSS
+#define CharConvTW CharConvSW
+#define CharConvST CharConvSS
+#define CharConvWT CharConvWS
+#define CharConvTU CharConvSU
+#define CharConvUT CharConvUS
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/corec/corec/helpers/charconvert/charconvert.proj b/corec/corec/helpers/charconvert/charconvert.proj
new file mode 100644
index 0000000..86a80da
--- /dev/null
+++ b/corec/corec/helpers/charconvert/charconvert.proj
@@ -0,0 +1,14 @@
+GROUP charconvert
+{
+  USE corec
+  USE str
+  SOURCE(TARGET_WIN) charconvert_win32.c
+  SOURCE(TARGET_LINUX && (!TARGET_QTOPIA || QTOPIA_WITH_ICONV)) charconvert_linux.c
+  SOURCE(TARGET_QTOPIA && !QTOPIA_WITH_ICONV) charconvert_qtopia.cpp
+  SOURCE(TARGET_PALMOS) charconvert_palmos.c
+  SOURCE(TARGET_SYMBIAN) charconvert_symbian.cpp
+  FRAMEWORK(TARGET_OSX) CoreFoundation
+  SOURCE(TARGET_OSX) charconvert_osx.c
+  SOURCE(TARGET_PS2SDK || TARGET_ANDROID) charconvert_utf8.c
+  HEADER charconvert.h
+}
diff --git a/corec/corec/helpers/charconvert/charconvert_linux.c b/corec/corec/helpers/charconvert/charconvert_linux.c
new file mode 100644
index 0000000..e8613e9
--- /dev/null
+++ b/corec/corec/helpers/charconvert/charconvert_linux.c
@@ -0,0 +1,236 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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 "charconvert.h"
+#include "corec/str/str.h"
+
+#if defined(TARGET_LINUX)
+
+#include <iconv.h>
+#include <locale.h>
+#include <wchar.h>
+#include <errno.h>
+
+#ifndef ICONV_CONST
+#if defined(__GLIBC__)
+#define ICONV_CONST
+#else
+#define ICONV_CONST const
+#endif
+#endif
+
+static tchar_t *Current = NULL;
+
+void CharConvSS(charconv* CC, char* Out, size_t OutLen, const char* In)
+{
+    if (OutLen>0)
+    {
+        ICONV_CONST char* _In = (ICONV_CONST char*)In;
+        size_t _InLen = strlen(In)+1;
+        char* _Out = Out;
+        size_t _OutLen = OutLen;
+
+        if (!CC || !_InLen || iconv((iconv_t)CC, &_In, &_InLen, &_Out, &_OutLen) == -1 || 
+             iconv((iconv_t)CC, NULL, NULL, &_Out, &_OutLen) == -1)
+        {
+            size_t n = min(strlen(In),OutLen-1);
+            memcpy(Out,In,n*sizeof(char));
+            Out[n] = 0;
+            if (CC && _InLen)
+            {
+//              DebugMessage("iconv failed: %d for '%s'",errno,In);
+              iconv((iconv_t)CC, NULL, NULL, NULL, NULL); // reset state
+            }
+        }
+        else
+            *_Out=0;
+    }
+}
+
+void CharConvWS(charconv* CC, wchar_t* Out, size_t OutLen, const char* In)
+{
+    if (OutLen>0)
+    {
+        ICONV_CONST char* _In = (ICONV_CONST char*)In;
+        size_t _InLen = strlen(In)+1;
+        char* _Out = (char*)Out;
+        size_t _OutLen = OutLen*sizeof(wchar_t);
+
+        if (!CC || !_InLen || iconv((iconv_t)CC, &_In, &_InLen, &_Out, &_OutLen) == -1 || 
+                iconv((iconv_t)CC, NULL, NULL, &_Out, &_OutLen) == -1)
+        {
+            for (;OutLen>1 && *In;++In,--OutLen,++Out)
+                *Out = (wchar_t)*In;
+            *Out = 0;
+            if (CC && _InLen) iconv((iconv_t)CC, NULL, NULL, NULL, NULL); // reset state
+        }
+        else
+            *(wchar_t*)_Out=0;
+    }
+}
+
+void CharConvSW(charconv* CC, char* Out, size_t OutLen, const wchar_t* In)
+{
+    if (OutLen>0)
+    {
+        ICONV_CONST char* _In = (ICONV_CONST char*)In;
+        size_t _InLen = wcslen(In)+1;
+        char* _Out = Out;
+        size_t _OutLen = OutLen;
+
+        if (!CC || !_InLen || iconv((iconv_t)CC, &_In, &_InLen, &_Out, &_OutLen) == -1 || 
+                    iconv((iconv_t)CC, NULL, NULL, &_Out, &_OutLen) == -1)
+        {
+            for (;OutLen>1 && *In;++In,--OutLen,++Out)
+                *Out = (char)(*In>255?'*':*In);
+            *Out = 0;	
+            if (CC && _InLen) iconv((iconv_t)CC, NULL, NULL, NULL, NULL); // reset state
+        }
+        else
+            *_Out=0;
+    }
+}
+
+void CharConvUS(charconv* CC, utf16_t* Out, size_t OutLen, const char* In)
+{
+    if (OutLen>0)
+    {
+        ICONV_CONST char* _In = (ICONV_CONST char*)In;
+        size_t _InLen = strlen(In)+1;
+        char* _Out = (char*)Out;
+        size_t _OutLen = OutLen*sizeof(utf16_t);
+
+        if (!CC || !_InLen || iconv((iconv_t)CC, &_In, &_InLen, &_Out, &_OutLen) == -1 || 
+                iconv((iconv_t)CC, NULL, NULL, &_Out, &_OutLen) == -1)
+        {
+            for (;OutLen>1 && *In;++In,--OutLen,++Out)
+                *Out = (utf16_t)*In;
+            *Out = 0;
+            if (CC && _InLen) iconv((iconv_t)CC, NULL, NULL, NULL, NULL); // reset state
+        }
+        else
+            *(utf16_t*)_Out=0;
+    }
+}
+
+void CharConvSU(charconv* CC, char* Out, size_t OutLen, const utf16_t* In)
+{
+    if (OutLen>0)
+    {
+        ICONV_CONST char* _In = (ICONV_CONST char*)In;
+        size_t _InLen = utf16len(In)+1;
+        char* _Out = Out;
+        size_t _OutLen = OutLen;
+
+        if (!CC || !_InLen || iconv((iconv_t)CC, &_In, &_InLen, &_Out, &_OutLen) == -1 || 
+                    iconv((iconv_t)CC, NULL, NULL, &_Out, &_OutLen) == -1)
+        {
+            for (;OutLen>1 && *In;++In,--OutLen,++Out)
+                *Out = (char)(*In>255?'*':*In);
+            *Out = 0;	
+            if (CC && _InLen) iconv((iconv_t)CC, NULL, NULL, NULL, NULL); // reset state
+        }
+        else
+            *_Out=0;
+    }
+}
+
+void CharConvWW(charconv* CC, wchar_t* Out, size_t OutLen, const wchar_t* In)
+{
+    if (OutLen>0)
+    {
+        ICONV_CONST char* _In = (ICONV_CONST char*)In;
+        size_t _InLen = (wcslen(In)+1)*sizeof(wchar_t);
+        char* _Out = (char*)Out;
+        size_t _OutLen = OutLen*sizeof(wchar_t);
+
+        if (!CC || !_InLen || iconv((iconv_t)CC, &_In, &_InLen, &_Out, &_OutLen) == -1 || 
+                iconv((iconv_t)CC, NULL, NULL, &_Out, &_OutLen) == -1)
+        {
+            size_t n = min(wcslen(In),OutLen-1);
+            memcpy(Out,In,n*sizeof(wchar_t));
+            Out[n] = 0;
+                if (CC && _InLen) iconv((iconv_t)CC, NULL, NULL, NULL, NULL); // reset state
+        }
+        else
+            *(wchar_t*)_Out=0;
+   }
+}
+
+static NOINLINE void GetDefault()
+{
+    if (!Current)
+    {
+        setlocale(LC_ALL,""); // set default for all
+        Current = setlocale(LC_CTYPE,"");
+        if (Current)
+            Current = strrchr(Current,'.');
+        if (Current)
+           ++Current;
+        else
+           Current = "";
+    }
+}
+
+charconv* CharConvOpen(const tchar_t* From, const tchar_t* To)
+{
+    iconv_t CC;
+
+    GetDefault();
+
+    if (!From || !From[0])
+        From = Current;
+
+    if (!To || !To[0])
+        To = Current;
+
+    if (tcsicmp(To,From)==0)
+        return NULL;
+
+    CC = iconv_open(To,From);
+    if (CC == (iconv_t)-1)
+        return NULL;
+
+    return (charconv*)CC;
+}
+
+void CharConvClose(charconv* p)
+{
+    if (p)
+        iconv_close((iconv_t)p);
+}
+
+void CharConvDefault(tchar_t* Out, size_t OutLen)
+{
+    GetDefault();
+
+    tcscpy_s(Out,OutLen,Current);
+}
+
+#endif
diff --git a/corec/corec/helpers/charconvert/charconvert_osx.c b/corec/corec/helpers/charconvert/charconvert_osx.c
new file mode 100644
index 0000000..ce27456
--- /dev/null
+++ b/corec/corec/helpers/charconvert/charconvert_osx.c
@@ -0,0 +1,272 @@
+/*****************************************************************************
+ * 
+ * Copyright (c) 2008-2010, CoreCodec, Inc.
+ * 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 CoreCodec, Inc. 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 CoreCodec, Inc. ``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 CoreCodec, Inc. 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 "charconvert.h"
+#include "corec/str/str.h"
+
+#if defined(TARGET_OSX)
+
+//#include <iconv.h>
+#include <locale.h>
+#include <wchar.h>
+#include <errno.h>
+
+#ifndef ICONV_CONST
+#if defined(__GLIBC__)
+#define ICONV_CONST
+#else
+#define ICONV_CONST const
+#endif
+#endif
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#define LOSSY_CHAR '.'
+
+static char *Current = NULL;
+
+typedef struct charconv_osx {
+    CFStringBuiltInEncodings EncFrom;
+	CFStringBuiltInEncodings EncTo;
+} charconv_osx;
+
+// char to char conversion
+void CharConvSS(charconv* Conv, char* Out, size_t OutLen, const char* In)
+{
+    if (OutLen>0)
+    {
+        charconv_osx *CC = (charconv_osx *)Conv;
+        if (CC)
+        {
+            CFStringRef TmpIn = CFStringCreateWithCString(NULL, In, CC->EncFrom);
+            CFIndex Read;
+            CFRange		r;
+            r.location = 0;
+            r.length = CFStringGetLength(TmpIn);
+            CFStringGetBytes(TmpIn, r, CC->EncTo,
+                    LOSSY_CHAR, /* no lossy conversion */
+                    0, /* not external representation */
+                    (UInt8*)Out, OutLen, &Read);
+            CFRelease(TmpIn);
+            Out[Read]=0;
+        }
+        else
+        {
+            size_t n = min(In?strlen(In):0,OutLen-1);
+            memcpy(Out,In,n*sizeof(char));
+            Out[n] = 0;
+        }
+    }
+}
+
+// char to utf16_t conversion
+void CharConvUS(charconv* Conv, utf16_t* Out, size_t OutLen, const char* In)
+{
+	if (OutLen>0)
+	{
+        // assume wchar_t is 16 bits even if it's not true
+        charconv_osx *CC = (charconv_osx *)Conv;
+        if (CC)
+        {
+            CFStringRef TmpIn = CFStringCreateWithCString(NULL, In, CC->EncFrom);
+            assert(TmpIn);
+            if (TmpIn)
+            {
+                CFIndex Read;
+                CFRange		r;
+                r.location = 0;
+                r.length = CFStringGetLength(TmpIn);
+                CFStringGetBytes(TmpIn, r, CC->EncTo,
+                        LOSSY_CHAR, /* no lossy conversion */
+                        0, /* not external representation */
+                        (UInt8*)Out, OutLen, &Read);
+                CFRelease(TmpIn);
+                memset((UInt8*)Out+Read,0,sizeof(uint16_t));
+            }
+            else
+            {
+                Out[0]=0;
+            }
+        }
+        else
+        {
+            fprintf(stderr, "Not supported yet: %s with no CC\n", __FUNCTION__);
+        }
+    }
+}
+
+// utf16_t to char conversion
+void CharConvSU(charconv* Conv, char* Out, size_t OutLen, const utf16_t* In)
+{
+	if (OutLen>0)
+	{
+        // assume wchar_t is 16 bits even if it's not true
+        CFStringEncoding EncFrom,EncTo;
+        if (Conv)
+        {
... 102649 lines suppressed ...


-- 
asterisk-scf/integration/matroska.git



More information about the asterisk-scf-commits mailing list