comparison flacenc.c @ 7864:4820bd751284 libavcodec

write actual min and max frame size to FLAC header. update regression test checksum.
author jbr
date Sun, 14 Sep 2008 22:25:50 +0000
parents f092dd630095
children 7a463923ecd1
comparison
equal deleted inserted replaced
7863:4ce4a18cae8e 7864:4820bd751284
93 PutBitContext pb; 93 PutBitContext pb;
94 int channels; 94 int channels;
95 int ch_code; 95 int ch_code;
96 int samplerate; 96 int samplerate;
97 int sr_code[2]; 97 int sr_code[2];
98 int min_framesize;
99 int min_encoded_framesize;
98 int max_framesize; 100 int max_framesize;
101 int max_encoded_framesize;
99 uint32_t frame_count; 102 uint32_t frame_count;
100 uint64_t sample_count; 103 uint64_t sample_count;
101 uint8_t md5sum[16]; 104 uint8_t md5sum[16];
102 FlacFrame frame; 105 FlacFrame frame;
103 CompressionOptions options; 106 CompressionOptions options;
131 init_put_bits(&pb, header, FLAC_STREAMINFO_SIZE); 134 init_put_bits(&pb, header, FLAC_STREAMINFO_SIZE);
132 135
133 /* streaminfo metadata block */ 136 /* streaminfo metadata block */
134 put_bits(&pb, 16, s->avctx->frame_size); 137 put_bits(&pb, 16, s->avctx->frame_size);
135 put_bits(&pb, 16, s->avctx->frame_size); 138 put_bits(&pb, 16, s->avctx->frame_size);
136 put_bits(&pb, 24, 0); 139 put_bits(&pb, 24, s->min_framesize);
137 put_bits(&pb, 24, s->max_framesize); 140 put_bits(&pb, 24, s->max_framesize);
138 put_bits(&pb, 20, s->samplerate); 141 put_bits(&pb, 20, s->samplerate);
139 put_bits(&pb, 3, s->channels-1); 142 put_bits(&pb, 3, s->channels-1);
140 put_bits(&pb, 5, 15); /* bits per sample - 1 */ 143 put_bits(&pb, 5, 15); /* bits per sample - 1 */
141 /* write 36-bit sample count in 2 put_bits() calls */ 144 /* write 36-bit sample count in 2 put_bits() calls */
372 if(s->channels == 2) { 375 if(s->channels == 2) {
373 s->max_framesize = 14 + ((s->avctx->frame_size * 33 + 7) >> 3); 376 s->max_framesize = 14 + ((s->avctx->frame_size * 33 + 7) >> 3);
374 } else { 377 } else {
375 s->max_framesize = 14 + (s->avctx->frame_size * s->channels * 2); 378 s->max_framesize = 14 + (s->avctx->frame_size * s->channels * 2);
376 } 379 }
380 s->min_encoded_framesize = 0xFFFFFF;
377 381
378 /* initialize MD5 context */ 382 /* initialize MD5 context */
379 s->md5ctx = av_malloc(av_md5_size); 383 s->md5ctx = av_malloc(av_md5_size);
380 if(!s->md5ctx) 384 if(!s->md5ctx)
381 return AVERROR_NOMEM; 385 return AVERROR_NOMEM;
1276 return 0; 1280 return 0;
1277 } 1281 }
1278 1282
1279 /* when the last block is reached, update the header in extradata */ 1283 /* when the last block is reached, update the header in extradata */
1280 if (!data) { 1284 if (!data) {
1285 s->min_framesize = s->min_encoded_framesize;
1286 s->max_framesize = s->max_encoded_framesize;
1281 av_md5_final(s->md5ctx, s->md5sum); 1287 av_md5_final(s->md5ctx, s->md5sum);
1282 write_streaminfo(s, avctx->extradata); 1288 write_streaminfo(s, avctx->extradata);
1283 return 0; 1289 return 0;
1284 } 1290 }
1285 1291
1316 } 1322 }
1317 1323
1318 s->frame_count++; 1324 s->frame_count++;
1319 s->sample_count += avctx->frame_size; 1325 s->sample_count += avctx->frame_size;
1320 update_md5_sum(s, samples); 1326 update_md5_sum(s, samples);
1327 if (out_bytes > s->max_encoded_framesize)
1328 s->max_encoded_framesize = out_bytes;
1329 if (out_bytes < s->min_encoded_framesize)
1330 s->min_encoded_framesize = out_bytes;
1321 1331
1322 return out_bytes; 1332 return out_bytes;
1323 } 1333 }
1324 1334
1325 static av_cold int flac_encode_close(AVCodecContext *avctx) 1335 static av_cold int flac_encode_close(AVCodecContext *avctx)