dv_tablegen.h 3.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Header file for hardcoded DV tables
 *
 * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

23 24
#ifndef AVCODEC_DV_TABLEGEN_H
#define AVCODEC_DV_TABLEGEN_H
25 26

#include <stdint.h>
27
#include "libavutil/attributes.h"
28

29
#include "dvdata.h"
30 31

#if CONFIG_SMALL
32 33
#define DV_VLC_MAP_RUN_SIZE  15
#define DV_VLC_MAP_LEV_SIZE  23
34 35
#else
#define DV_VLC_MAP_RUN_SIZE  64
36
#define DV_VLC_MAP_LEV_SIZE 512 // FIXME sign was removed so this should be /2 but needs check
37 38 39
#endif

/* VLC encoding lookup table */
40
typedef struct dv_vlc_pair {
41 42
    uint32_t vlc;
    uint32_t size;
43
} dv_vlc_pair;
44 45 46 47 48 49 50

#if CONFIG_HARDCODED_TABLES
#define dv_vlc_map_tableinit()
#include "libavcodec/dv_tables.h"
#else
static struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE];

51
static av_cold void dv_vlc_map_tableinit(void)
52 53 54
{
    int i, j;
    for (i = 0; i < NB_DV_VLC - 1; i++) {
55 56
        if (ff_dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE)
            continue;
57
#if CONFIG_SMALL
58 59
        if (ff_dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE)
            continue;
60 61
#endif

62 63
        if (dv_vlc_map[ff_dv_vlc_run[i]][ff_dv_vlc_level[i]].size != 0)
            continue;
64

65 66 67 68
        dv_vlc_map[ff_dv_vlc_run[i]][ff_dv_vlc_level[i]].vlc  =
            ff_dv_vlc_bits[i] << (!!ff_dv_vlc_level[i]);
        dv_vlc_map[ff_dv_vlc_run[i]][ff_dv_vlc_level[i]].size =
            ff_dv_vlc_len[i]   + (!!ff_dv_vlc_level[i]);
69 70 71
    }
    for (i = 0; i < DV_VLC_MAP_RUN_SIZE; i++) {
#if CONFIG_SMALL
72 73 74 75 76 77 78 79 80
        for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) {
            if (dv_vlc_map[i][j].size == 0) {
                dv_vlc_map[i][j].vlc  = dv_vlc_map[0][j].vlc |
                                        (dv_vlc_map[i - 1][0].vlc <<
                                         dv_vlc_map[0][j].size);
                dv_vlc_map[i][j].size = dv_vlc_map[i - 1][0].size +
                                        dv_vlc_map[0][j].size;
            }
        }
81
#else
82 83 84 85 86 87 88 89 90 91 92
        for (j = 1; j < DV_VLC_MAP_LEV_SIZE / 2; j++) {
            if (dv_vlc_map[i][j].size == 0) {
                dv_vlc_map[i][j].vlc  = dv_vlc_map[0][j].vlc |
                                        (dv_vlc_map[i - 1][0].vlc <<
                                         dv_vlc_map[0][j].size);
                dv_vlc_map[i][j].size = dv_vlc_map[i - 1][0].size +
                                        dv_vlc_map[0][j].size;
            }
            dv_vlc_map[i][((uint16_t) (-j)) & 0x1ff].vlc  = dv_vlc_map[i][j].vlc | 1;
            dv_vlc_map[i][((uint16_t) (-j)) & 0x1ff].size = dv_vlc_map[i][j].size;
        }
93 94 95 96 97
#endif
    }
}
#endif /* CONFIG_HARDCODED_TABLES */

98
#endif /* AVCODEC_DV_TABLEGEN_H */