diff options
author | Mohamed Tarek <mt@rockbox.org> | 2009-05-12 20:50:35 +0000 |
---|---|---|
committer | Mohamed Tarek <mt@rockbox.org> | 2009-05-12 20:50:35 +0000 |
commit | 49ba646d579a89d5ff0e4f3d5eea237eea22aafd (patch) | |
tree | 32aa872eb82b16c22f1915543c1512b116513209 /apps/codecs/libcook/cook.c | |
parent | 49fccaf2d925def5cc57fff4a09b98a8fe318cc8 (diff) | |
download | rockbox-49ba646d579a89d5ff0e4f3d5eea237eea22aafd.tar.gz rockbox-49ba646d579a89d5ff0e4f3d5eea237eea22aafd.zip |
-Remove all dynamic allocations, hence remove cook_decode_close() which was basically
needed for freeing allocated memory.
-Remove any ffmpeg-specific attributes (av_const,av_always_inline .. etc.).
-Move some math functions to cook_fixpoint.h - libavutil/common.h is no longer
needed.
-Remove libavutil/mem.[c/h], libavutil/common.h and libavutil/internal.h.
-Fix a warning in cookdata_fixpoint.h.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20922 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libcook/cook.c')
-rw-r--r-- | apps/codecs/libcook/cook.c | 81 |
1 files changed, 16 insertions, 65 deletions
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c index fd80c1bd2e..8caa3992bd 100644 --- a/apps/codecs/libcook/cook.c +++ b/apps/codecs/libcook/cook.c | |||
@@ -45,22 +45,12 @@ | |||
45 | #include <math.h> | 45 | #include <math.h> |
46 | #include <stddef.h> | 46 | #include <stddef.h> |
47 | #include <stdio.h> | 47 | #include <stdio.h> |
48 | #include <limits.h> | ||
49 | #include <string.h> | ||
48 | 50 | ||
49 | #include "cook.h" | 51 | #include "cook.h" |
50 | #include "cookdata.h" | 52 | #include "cookdata.h" |
51 | 53 | ||
52 | /* The following table is taken from libavutil/mathematics.c */ | ||
53 | const uint8_t ff_log2_tab[256]={ | ||
54 | 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, | ||
55 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
56 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
57 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
58 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
59 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
60 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
61 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 | ||
62 | }; | ||
63 | |||
64 | /* the different Cook versions */ | 54 | /* the different Cook versions */ |
65 | #define MONO 0x1000001 | 55 | #define MONO 0x1000001 |
66 | #define STEREO 0x1000002 | 56 | #define STEREO 0x1000002 |
@@ -112,26 +102,35 @@ static void dump_short_table(short* table, int size, int delimiter) { | |||
112 | #endif | 102 | #endif |
113 | 103 | ||
114 | /*************** init functions ***************/ | 104 | /*************** init functions ***************/ |
115 | static av_cold int init_cook_vlc_tables(COOKContext *q) { | 105 | #define VLCBUFSIZE 1500 |
106 | VLC_TYPE vlcbuf[21][VLCBUFSIZE][2]; | ||
107 | |||
108 | static int init_cook_vlc_tables(COOKContext *q) { | ||
116 | int i, result; | 109 | int i, result; |
117 | 110 | ||
118 | result = 0; | 111 | result = 0; |
119 | for (i=0 ; i<13 ; i++) { | 112 | for (i=0 ; i<13 ; i++) { |
113 | q->envelope_quant_index[i].table = vlcbuf[i]; | ||
114 | q->envelope_quant_index[i].table_allocated = VLCBUFSIZE; | ||
120 | result |= init_vlc (&q->envelope_quant_index[i], 9, 24, | 115 | result |= init_vlc (&q->envelope_quant_index[i], 9, 24, |
121 | envelope_quant_index_huffbits[i], 1, 1, | 116 | envelope_quant_index_huffbits[i], 1, 1, |
122 | envelope_quant_index_huffcodes[i], 2, 2, 0); | 117 | envelope_quant_index_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); |
123 | } | 118 | } |
124 | DEBUGF("sqvh VLC init\n"); | 119 | DEBUGF("sqvh VLC init\n"); |
125 | for (i=0 ; i<7 ; i++) { | 120 | for (i=0 ; i<7 ; i++) { |
121 | q->sqvh[i].table = vlcbuf[i+13]; | ||
122 | q->sqvh[i].table_allocated = VLCBUFSIZE; | ||
126 | result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], | 123 | result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], |
127 | cvh_huffbits[i], 1, 1, | 124 | cvh_huffbits[i], 1, 1, |
128 | cvh_huffcodes[i], 2, 2, 0); | 125 | cvh_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); |
129 | } | 126 | } |
130 | 127 | ||
131 | if (q->nb_channels==2 && q->joint_stereo==1){ | 128 | if (q->nb_channels==2 && q->joint_stereo==1){ |
129 | q->ccpl.table = vlcbuf[20]; | ||
130 | q->ccpl.table_allocated = VLCBUFSIZE; | ||
132 | result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1, | 131 | result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1, |
133 | ccpl_huffbits[q->js_vlc_bits-2], 1, 1, | 132 | ccpl_huffbits[q->js_vlc_bits-2], 1, 1, |
134 | ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0); | 133 | ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, INIT_VLC_USE_NEW_STATIC); |
135 | DEBUGF("Joint-stereo VLC used.\n"); | 134 | DEBUGF("Joint-stereo VLC used.\n"); |
136 | } | 135 | } |
137 | 136 | ||
@@ -185,35 +184,6 @@ static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes) | |||
185 | } | 184 | } |
186 | 185 | ||
187 | /** | 186 | /** |
188 | * Cook uninit | ||
189 | */ | ||
190 | |||
191 | av_cold int cook_decode_close(COOKContext *q) | ||
192 | { | ||
193 | int i; | ||
194 | //COOKContext *q = avctx->priv_data; | ||
195 | DEBUGF( "Deallocating memory.\n"); | ||
196 | |||
197 | /* Free allocated memory buffers. */ | ||
198 | av_free(q->decoded_bytes_buffer); | ||
199 | |||
200 | /* Free the VLC tables. */ | ||
201 | for (i=0 ; i<13 ; i++) { | ||
202 | free_vlc(&q->envelope_quant_index[i]); | ||
203 | } | ||
204 | for (i=0 ; i<7 ; i++) { | ||
205 | free_vlc(&q->sqvh[i]); | ||
206 | } | ||
207 | if(q->nb_channels==2 && q->joint_stereo==1 ){ | ||
208 | free_vlc(&q->ccpl); | ||
209 | } | ||
210 | |||
211 | DEBUGF("Memory deallocated.\n"); | ||
212 | |||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * Fill the gain array for the timedomain quantization. | 187 | * Fill the gain array for the timedomain quantization. |
218 | * | 188 | * |
219 | * @param q pointer to the COOKContext | 189 | * @param q pointer to the COOKContext |
@@ -739,7 +709,7 @@ static void dump_cook_context(COOKContext *q) | |||
739 | * Cook initialization | 709 | * Cook initialization |
740 | */ | 710 | */ |
741 | 711 | ||
742 | av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q) | 712 | int cook_decode_init(RMContext *rmctx, COOKContext *q) |
743 | { | 713 | { |
744 | /* cook extradata */ | 714 | /* cook extradata */ |
745 | q->cookversion = rmctx->cook_version; | 715 | q->cookversion = rmctx->cook_version; |
@@ -822,25 +792,6 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q) | |||
822 | if(q->block_align >= UINT_MAX/2) | 792 | if(q->block_align >= UINT_MAX/2) |
823 | return -1; | 793 | return -1; |
824 | 794 | ||
825 | /* Pad the databuffer with: | ||
826 | DECODE_BYTES_PAD1 or DECODE_BYTES_PAD2 for decode_bytes(), | ||
827 | INPUT_BUFFER_PADDING_SIZE, for the bitstreamreader. */ | ||
828 | |||
829 | #define INPUT_BUFFER_PADDING_SIZE 8 | ||
830 | if (q->nb_channels==2 && q->joint_stereo==0) { | ||
831 | q->decoded_bytes_buffer = | ||
832 | av_mallocz(rmctx->block_align/2 | ||
833 | + DECODE_BYTES_PAD2(q->block_align/2) | ||
834 | + INPUT_BUFFER_PADDING_SIZE); | ||
835 | } else { | ||
836 | q->decoded_bytes_buffer = | ||
837 | av_mallocz(rmctx->block_align | ||
838 | + DECODE_BYTES_PAD1(q->block_align) | ||
839 | + INPUT_BUFFER_PADDING_SIZE); | ||
840 | } | ||
841 | if (q->decoded_bytes_buffer == NULL) | ||
842 | return -1; | ||
843 | |||
844 | q->gains1.now = q->gain_1; | 795 | q->gains1.now = q->gain_1; |
845 | q->gains1.previous = q->gain_2; | 796 | q->gains1.previous = q->gain_2; |
846 | q->gains2.now = q->gain_3; | 797 | q->gains2.now = q->gain_3; |