1 /*
2 * Helpers for generating hard-coded VLC tables
3 *
4 * Copyright (c) 2014 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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_TABLEPRINT_VLC_H
24 #define AVCODEC_TABLEPRINT_VLC_H
25
26 #define AVUTIL_LOG_H
27 #define av_log(a, ...) while(0)
28 #define ff_dlog(a, ...) while(0)
29 #define AVUTIL_MEM_H
30 #define av_malloc(s) NULL
31 #define av_malloc_array(a, b) NULL
32 #define av_realloc_f(p, o, n) NULL
33 #define av_free(p) while(0)
34 #define av_freep(p) while(0)
35 #define AVUTIL_INTERNAL_H
36 #define avpriv_request_sample(...)
37 #include "tableprint.h"
38 #include "vlc.h"
39 #include "libavutil/reverse.c"
40 #include "vlc.c"
41
42 // The following will have to be modified if VLCBaseType changes.
43 WRITE_1D_FUNC_ARGV(VLCElem, 3, "{ .sym =%5" PRId16 ", .len =%2"PRIi16 " }",
44 data[i].sym, data[i].len)
45
write_vlc_type(const VLC * vlc,const VLCElem * base_table,const char * base_table_name)46 static void write_vlc_type(const VLC *vlc, const VLCElem *base_table, const char *base_table_name)
47 {
48 printf(" .bits = %i,\n", vlc->bits);
49 // Unfortunately need to cast away const currently
50 printf(" .table = (VLCElem *)(%s + 0x%x),\n", base_table_name, (int)(vlc->table - base_table));
51 printf(" .table_size = 0x%x,\n", vlc->table_size);
52 printf(" .table_allocated = 0x%x,\n", vlc->table_allocated);
53 }
54
55 #define WRITE_VLC_TABLE(prefix, name) \
56 WRITE_ARRAY(prefix, VLCElem, name)
57
58 #define WRITE_VLC_TYPE(prefix, name, base_table) \
59 do { \
60 printf(prefix" VLC "#name" = {\n"); \
61 write_vlc_type(&name, base_table, #base_table); \
62 printf("};\n"); \
63 } while(0)
64
65 #define WRITE_VLC_ARRAY(prefix, name, base_table) \
66 do { \
67 int i; \
68 const size_t array_size = FF_ARRAY_ELEMS(name); \
69 printf(prefix" VLC "#name"[%"FMT"] = {{\n", \
70 array_size); \
71 for (i = 0; i < array_size; i++) { \
72 write_vlc_type(name + i, \
73 base_table, #base_table); \
74 if (i != array_size - 1) printf("}, {\n"); \
75 } \
76 printf("}};\n"); \
77 } while(0)
78
79 #endif /* AVCODEC_TABLEPRINT_VLC_H */
80