Statistics
| Branch: | Revision:

ffmpeg / libavcodec / amr.h @ 2912e87a

History | View | Annotate | Download (2.15 KB)

1
/*
2
 * Shared functions between AMR codecs
3
 *
4
 * Copyright (c) 2010 Marcelo Galvao Povoa
5
 *
6
 * This file is part of Libav.
7
 *
8
 * Libav is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * Libav is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with Libav; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

    
23
#ifndef AVCODEC_AMR_H
24
#define AVCODEC_AMR_H
25

    
26
#include "avcodec.h"
27

    
28
#ifdef AMR_USE_16BIT_TABLES
29
#define R_TABLE_TYPE uint16_t
30
#else
31
#define R_TABLE_TYPE uint8_t
32
#endif
33

    
34
/**
35
 * Fill the frame structure variables from bitstream by parsing the
36
 * given reordering table that uses the following format:
37
 *
38
 * Each field (16 bits) in the AMR Frame is stored as:
39
 * - one byte for the number of bits in the field
40
 * - one byte for the field index
41
 * - then, one byte for each bit of the field (from most-significant to least)
42
 *         of the position of that bit in the AMR frame.
43
 *
44
 * @param out pointer to the frame struct
45
 * @param size the size in bytes of the frame struct
46
 * @param data input bitstream after the frame header
47
 * @param ord_table the reordering table as above
48
 */
49
static inline void ff_amr_bit_reorder(uint16_t *out, int size,
50
                                      const uint8_t *data,
51
                                      const R_TABLE_TYPE *ord_table)
52
{
53
    int field_size;
54

    
55
    memset(out, 0, size);
56
    while ((field_size = *ord_table++)) {
57
        int field = 0;
58
        int field_offset = *ord_table++;
59
        while (field_size--) {
60
           int bit = *ord_table++;
61
           field <<= 1;
62
           field |= data[bit >> 3] >> (bit & 7) & 1;
63
        }
64
        out[field_offset] = field;
65
    }
66
}
67

    
68
#endif /* AVCODEC_AMR_H */