| 1 | /* |
| 2 | * vlc.h |
| 3 | * |
| 4 | * Copyright (C) Charles 'Buck' Krasic - April 2000 |
| 5 | * Copyright (C) Erik Walthinsen - April 2000 |
| 6 | * |
| 7 | * This file is part of libdv, a free DV (IEC 61834/SMPTE 314M) |
| 8 | * codec. |
| 9 | * |
| 10 | * libdv is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU Lesser Public License as published by |
| 12 | * the Free Software Foundation; either version 2.1, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | * libdv is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Lesser Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser Public License |
| 21 | * along with libdv; see the file COPYING. If not, write to |
| 22 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | * |
| 24 | * The libdv homepage is http://libdv.sourceforge.net/. |
| 25 | */ |
| 26 | |
| 27 | #ifndef DV_VLC_H |
| 28 | #define DV_VLC_H |
| 29 | |
| 30 | #include "bitstream.h" |
| 31 | |
| 32 | #define VLC_NOBITS (-1) |
| 33 | #define VLC_ERROR (-2) |
| 34 | |
| 35 | typedef struct dv_vlc_s { |
| 36 | int8_t run; |
| 37 | int8_t len; |
| 38 | int16_t amp; |
| 39 | } dv_vlc_t; |
| 40 | |
| 41 | #if 1 |
| 42 | typedef dv_vlc_t dv_vlc_tab_t; |
| 43 | #else |
| 44 | typedef struct dv_vlc_tab_s { |
| 45 | int8_t run; |
| 46 | int8_t len; |
| 47 | int16_t amp; |
| 48 | } dv_vlc_tab_t; |
| 49 | #endif |
| 50 | |
| 51 | #ifdef __cplusplus |
| 52 | extern "C" { |
| 53 | #endif |
| 54 | |
| 55 | extern int8_t *dv_vlc_classes[]; |
| 56 | extern int dv_vlc_class_index_mask[]; |
| 57 | extern int dv_vlc_class_index_rshift[]; |
| 58 | extern const dv_vlc_tab_t dv_vlc_broken[1]; |
| 59 | extern const dv_vlc_tab_t *dv_vlc_lookups[6]; |
| 60 | extern const int dv_vlc_index_mask[6]; |
| 61 | extern const int dv_vlc_index_rshift[6]; |
| 62 | extern const int sign_lookup[2]; |
| 63 | extern const int sign_mask[17]; |
| 64 | extern const int sign_rshift[17]; |
| 65 | extern void dv_construct_vlc_table(); |
| 66 | |
| 67 | // Note we assume bits is right (lsb) aligned, 0 < maxbits < 17 |
| 68 | // This may look crazy, but there are no branches here. |
| 69 | extern void dv_decode_vlc(int bits,int maxbits, dv_vlc_t *result); |
| 70 | extern void __dv_decode_vlc(int bits, dv_vlc_t *result); |
| 71 | |
| 72 | static inline void dv_peek_vlc(bitstream_t *bs,int maxbits, dv_vlc_t *result) { |
| 73 | if(maxbits < 16) |
| 74 | dv_decode_vlc(bitstream_show(bs,16),maxbits,result); |
| 75 | else |
| 76 | __dv_decode_vlc(bitstream_show(bs,16),result); |
| 77 | } // dv_peek_vlc |
| 78 | |
| 79 | #ifdef __cplusplus |
| 80 | } |
| 81 | #endif |
| 82 | |
| 83 | #endif // DV_VLC_H |