summaryrefslogtreecommitdiff
path: root/src/media_codec_util.c
blob: 4c1b8ee4af194834f0665e327d38664692b901b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <media_codec_util.h>

void *mc_aligned_malloc(int size, int alignment)
{
    unsigned char *pMem;
    unsigned char *tmp;

    if((tmp = (unsigned char *)malloc(size + alignment)) != NULL)
    {
        pMem = (unsigned char*)((unsigned int)(tmp + alignment - 1) & (~(unsigned int)(alignment -1)));

        if(pMem == tmp)
            pMem += alignment;

        *(pMem - 1) = (unsigned int)(pMem - tmp);

        return ((void*) pMem);
    }
    return NULL;
}

void mc_aligned_free(void *mem)
{
    unsigned char *ptr;

    if(mem == NULL)
        return;

    ptr = mem;
    ptr -= *(ptr-1);

    free(ptr);
}