Mercurial > libavcodec.hg
comparison flacenc.c @ 7860:c11e175fc544 libavcodec
write number of samples in FLAC extradata.
based on a patch by Mathieu Velten (matmaul gmail com).
author | jbr |
---|---|
date | Sun, 14 Sep 2008 20:00:36 +0000 |
parents | 3c07ce8ac9f7 |
children | f092dd630095 |
comparison
equal
deleted
inserted
replaced
7859:48d00b406a26 | 7860:c11e175fc544 |
---|---|
94 int ch_code; | 94 int ch_code; |
95 int samplerate; | 95 int samplerate; |
96 int sr_code[2]; | 96 int sr_code[2]; |
97 int max_framesize; | 97 int max_framesize; |
98 uint32_t frame_count; | 98 uint32_t frame_count; |
99 uint64_t sample_count; | |
99 FlacFrame frame; | 100 FlacFrame frame; |
100 CompressionOptions options; | 101 CompressionOptions options; |
101 AVCodecContext *avctx; | 102 AVCodecContext *avctx; |
102 DSPContext dsp; | 103 DSPContext dsp; |
103 } FlacEncodeContext; | 104 } FlacEncodeContext; |
132 put_bits(&pb, 24, 0); | 133 put_bits(&pb, 24, 0); |
133 put_bits(&pb, 24, s->max_framesize); | 134 put_bits(&pb, 24, s->max_framesize); |
134 put_bits(&pb, 20, s->samplerate); | 135 put_bits(&pb, 20, s->samplerate); |
135 put_bits(&pb, 3, s->channels-1); | 136 put_bits(&pb, 3, s->channels-1); |
136 put_bits(&pb, 5, 15); /* bits per sample - 1 */ | 137 put_bits(&pb, 5, 15); /* bits per sample - 1 */ |
138 /* write 36-bit sample count in 2 put_bits() calls */ | |
139 put_bits(&pb, 24, (s->sample_count & 0xFFFFFF000LL) >> 12); | |
140 put_bits(&pb, 12, s->sample_count & 0x000000FFFLL); | |
137 flush_put_bits(&pb); | 141 flush_put_bits(&pb); |
138 /* total samples = 0 */ | |
139 /* MD5 signature = 0 */ | 142 /* MD5 signature = 0 */ |
140 } | 143 } |
141 | 144 |
142 /** | 145 /** |
143 * Sets blocksize based on samplerate | 146 * Sets blocksize based on samplerate |
1249 if(buf_size < s->max_framesize*2) { | 1252 if(buf_size < s->max_framesize*2) { |
1250 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); | 1253 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); |
1251 return 0; | 1254 return 0; |
1252 } | 1255 } |
1253 | 1256 |
1257 /* when the last block is reached, update the header in extradata */ | |
1258 if (!data) { | |
1259 write_streaminfo(s, avctx->extradata); | |
1260 return 0; | |
1261 } | |
1262 | |
1254 init_frame(s); | 1263 init_frame(s); |
1255 | 1264 |
1256 copy_samples(s, samples); | 1265 copy_samples(s, samples); |
1257 | 1266 |
1258 channel_decorrelation(s); | 1267 channel_decorrelation(s); |
1282 reencoded = 1; | 1291 reencoded = 1; |
1283 goto write_frame; | 1292 goto write_frame; |
1284 } | 1293 } |
1285 | 1294 |
1286 s->frame_count++; | 1295 s->frame_count++; |
1296 s->sample_count += avctx->frame_size; | |
1297 | |
1287 return out_bytes; | 1298 return out_bytes; |
1288 } | 1299 } |
1289 | 1300 |
1290 static av_cold int flac_encode_close(AVCodecContext *avctx) | 1301 static av_cold int flac_encode_close(AVCodecContext *avctx) |
1291 { | 1302 { |
1302 sizeof(FlacEncodeContext), | 1313 sizeof(FlacEncodeContext), |
1303 flac_encode_init, | 1314 flac_encode_init, |
1304 flac_encode_frame, | 1315 flac_encode_frame, |
1305 flac_encode_close, | 1316 flac_encode_close, |
1306 NULL, | 1317 NULL, |
1307 .capabilities = CODEC_CAP_SMALL_LAST_FRAME, | 1318 .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, |
1308 .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, | 1319 .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, |
1309 .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"), | 1320 .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"), |
1310 }; | 1321 }; |