22 #include "../ogg/ogg.h"
23 #include "../vorbis/codec.h"
35 #define LIMITBYTES(pos,bin) (bm->minmax_binstack[(pos)*bins*2+((bin)+bins)])
37 static long LACING_ADJUST(
long bytes){
38 int addto=bytes/255+1;
45 double lobitrate,hibitrate;
49 while(lobitrate>desired_rate && bin>0){
56 if(fabs(hibitrate-desired_rate) < fabs(lobitrate-desired_rate))bin++;
85 memset(bm,0,
sizeof(*bm));
100 long maxpackets=maxlatency/(ci->
blocksizes[0]>>1)+3;
134 for(i=0;i<maxpackets;i++)
167 memset(bm,0,
sizeof(*bm));
192 int next_head=head+1;
194 int minmax_head,new_minmax_head;
217 memcpy(&vb->
opb,&temp,
sizeof(vb->
opb));
245 memcpy(&vb->
opb,&temp,
sizeof(vb->
opb));
256 new_minmax_head=minmax_head=head;
263 if(eofflag)desired_center=0;
267 bm->
avg_binacc[i]+=LACING_ADJUST(head_ptr[i]);
277 double upper=floater_interpolate(bm,vi,bi->
queue_avgmax);
278 double lower=floater_interpolate(bm,vi,bi->
queue_avgmin);
279 double new=PACKETBLOBS/2.,slew;
282 if(upper<
new)
new=upper;
283 if(lower>
new)
new=lower;
287 if(slew<bi->avgfloat_downslew_max)
300 0x80000000UL?1:0]>>1;
329 long bin=PACKETBLOBS/2;
331 new_minmax_head=next_head;
339 while(minmax_head!=new_minmax_head){
342 0x80000000UL?1:0]>>1;
345 for(i=0;i<(
unsigned int)bins;i++){
347 LACING_ADJUST(BINBYTES(bm,minmax_head,
351 LACING_ADJUST(BINBYTES(bm,minmax_head,
362 LACING_ADJUST(BINBYTES(bm,minmax_head,actual));
388 for(limit=-1;limit>-bins+1;limit--){
389 long bitsum=limit_sum(bm,limit)*8;
391 if(bitrate<=bi->queue_hardmax)
break;
393 }
else if(bitrate<bi->queue_hardmin){
394 for(limit=1;limit<bins-1;limit++){
395 long bitsum=limit_sum(bm,limit)*8;
412 while(stackctr>newstack){
417 if(stackctr<bm->minmax_stackptr)
418 for(i=0;i<bins*2;i++)
502 memcpy(op,bm->
packets,
sizeof(*op));
513 long bytes=markers[bin];
ogg_uint32_t avg_centerdesired
ogg_uint32_t minmax_sampleacc
double avgfloat_downslew_max
ogg_uint32_t packetblob_markers[PACKETBLOBS]
int vorbis_bitrate_addblock(vorbis_block *vb)
bitrate_manager_state bms
int vorbis_bitrate_managed(vorbis_block *vb)
void vorbis_bitrate_init(vorbis_info *vi, bitrate_manager_state *bm)
ogg_uint32_t * queue_binned
oggpack_buffer * packetbuffers
double avgfloat_upslew_max
ogg_uint32_t avg_sampledesired
ogg_uint32_t minmax_sampledesired
ogg_uint32_t avg_centeracc
void vorbis_bitrate_clear(bitrate_manager_state *bm)
#define LIMITBYTES(pos, bin)
void oggpack_writeinit(oggpack_buffer *b)
long oggpack_bytes(oggpack_buffer *b)
unsigned char * oggpack_get_buffer(oggpack_buffer *b)
void oggpack_writeclear(oggpack_buffer *b)
int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op)
ogg_uint32_t avg_sampleacc
ogg_uint32_t * queue_actual