Revision 757d91a6

View differences:

libavcodec/vorbis_enc.c
30 30
#include "vorbis.h"
31 31
#include "vorbis_enc_data.h"
32 32

  
33
#define BITSTREAM_WRITER_LE
34
#include "bitstream.h"
35

  
33 36
#undef NDEBUG
34 37
#include <assert.h>
35 38

  
......
122 125
    int64_t sample_count;
123 126
} venc_context_t;
124 127

  
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

  
171 128
static inline void put_codeword(PutBitContext * pb, codebook_t * cb, int entry) {
172 129
    assert(entry >= 0);
173 130
    assert(entry < cb->nentries);

Also available in: Unified diff