comparison vorbis_enc.c @ 8030:a512ac8fa540 libavcodec

Use of new bitstream in vorbis_enc.c. Patch by BartŠČomiej WoŠČowiec b wolowiec AT students mimuw edu pl
author benoit
date Wed, 15 Oct 2008 08:01:54 +0000
parents 88f4153caa21
children e70975d5ff80
comparison
equal deleted inserted replaced
8029:e50d7ac76945 8030:a512ac8fa540
28 #include "avcodec.h" 28 #include "avcodec.h"
29 #include "dsputil.h" 29 #include "dsputil.h"
30 #include "vorbis.h" 30 #include "vorbis.h"
31 #include "vorbis_enc_data.h" 31 #include "vorbis_enc_data.h"
32 32
33 #define BITSTREAM_WRITER_LE
34 #include "bitstream.h"
35
33 #undef NDEBUG 36 #undef NDEBUG
34 #include <assert.h> 37 #include <assert.h>
35 38
36 typedef struct { 39 typedef struct {
37 int nentries; 40 int nentries;
119 int nmodes; 122 int nmodes;
120 vorbis_mode_t * modes; 123 vorbis_mode_t * modes;
121 124
122 int64_t sample_count; 125 int64_t sample_count;
123 } venc_context_t; 126 } venc_context_t;
124
125 typedef struct {
126 int total;
127 int total_pos;
128 int pos;
129 uint8_t * buf_ptr;
130 } PutBitContext;
131
132 static inline void init_put_bits(PutBitContext * pb, uint8_t * buf, int buffer_len) {
133 pb->total = buffer_len * 8;
134 pb->total_pos = 0;
135 pb->pos = 0;
136 pb->buf_ptr = buf;
137 }
138
139 static void put_bits(PutBitContext * pb, int bits, uint64_t val) {
140 if ((pb->total_pos += bits) >= pb->total) return;
141 if (!bits) return;
142 if (pb->pos) {
143 if (pb->pos > bits) {
144 *pb->buf_ptr |= val << (8 - pb->pos);
145 pb->pos -= bits;
146 bits = 0;
147 } else {
148 *pb->buf_ptr++ |= (val << (8 - pb->pos)) & 0xFF;
149 val >>= pb->pos;
150 bits -= pb->pos;
151 pb->pos = 0;
152 }
153 }
154 for (; bits >= 8; bits -= 8) {
155 *pb->buf_ptr++ = val & 0xFF;
156 val >>= 8;
157 }
158 if (bits) {
159 *pb->buf_ptr = val;
160 pb->pos = 8 - bits;
161 }
162 }
163
164 static inline void flush_put_bits(PutBitContext * pb) {
165 }
166
167 static inline int put_bits_count(PutBitContext * pb) {
168 return pb->total_pos;
169 }
170 127
171 static inline void put_codeword(PutBitContext * pb, codebook_t * cb, int entry) { 128 static inline void put_codeword(PutBitContext * pb, codebook_t * cb, int entry) {
172 assert(entry >= 0); 129 assert(entry >= 0);
173 assert(entry < cb->nentries); 130 assert(entry < cb->nentries);
174 assert(cb->lens[entry]); 131 assert(cb->lens[entry]);