aboutsummaryrefslogtreecommitdiffstats
path: root/libdash/source/helpers/Block.h
blob: 9f8f95777d04636e0b295425df77abb3a4efdb6e (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Block.h
 *****************************************************************************
 * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
 *
 * Email: libdash-dev@vicky.bitmovin.net
 *
 * This source code and its use and distribution, is subject to the terms
 * and conditions of the applicable license agreement.
 *****************************************************************************/

#ifndef __BLOCK_H__
#define __BLOCK_H__

#include "config.h"
#include <stddef.h>
#include <stdlib.h>

namespace dash
{
    namespace helpers
    {
        struct block_t
        {
            uint8_t *data;
            size_t  len;
            float   millisec;
            size_t  offset;
        };

        static inline block_t*  AllocBlock      (size_t len)
        {
            block_t *block  = (block_t *)malloc(sizeof(block_t));
            block->data     = new uint8_t[len];
            block->len      = len;
            block->millisec = 0;
            block->offset   = 0;
            return block;
        }
        static inline void      DeleteBlock     (block_t *block)
        {
            if(block)
            {
                delete [] block->data;
                free(block);
                block = NULL;
            }
        }
        static inline block_t*  DuplicateBlock  (block_t *block)
        {
            block_t *ret = AllocBlock(block->len);
            ret->offset  = block->offset;

            memcpy(ret->data, block->data, ret->len);

            return block;
        }
    }
}

#endif