MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / flac_encode_init

Function flac_encode_init

libavcodec/flacenc.c:270–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269
270static av_cold int flac_encode_init(AVCodecContext *avctx)
271{
272 int freq = avctx->sample_rate;
273 int channels = avctx->ch_layout.nb_channels;
274 FlacEncodeContext *s = avctx->priv_data;
275 int i, level, ret;
276 uint8_t *streaminfo;
277
278 s->avctx = avctx;
279
280 switch (avctx->sample_fmt) {
281 case AV_SAMPLE_FMT_S16:
282 avctx->bits_per_raw_sample = 16;
283 s->bps_code = 4;
284 break;
285 case AV_SAMPLE_FMT_S32:
286 if (avctx->bits_per_raw_sample <= 24) {
287 if (avctx->bits_per_raw_sample < 24)
288 av_log(avctx, AV_LOG_WARNING, "encoding as 24 bits-per-sample\n");
289 avctx->bits_per_raw_sample = 24;
290 s->bps_code = 6;
291 } else if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
292 av_log(avctx, AV_LOG_WARNING,
293 "encoding as 24 bits-per-sample, more is considered "
294 "experimental. Add -strict experimental if you want "
295 "to encode more than 24 bits-per-sample\n");
296 avctx->bits_per_raw_sample = 24;
297 s->bps_code = 6;
298 } else {
299 avctx->bits_per_raw_sample = 32;
300 s->bps_code = 7;
301 }
302 break;
303 }
304
305 if (channels < 1 || channels > FLAC_MAX_CHANNELS) {
306 av_log(avctx, AV_LOG_ERROR, "%d channels not supported (max %d)\n",
307 channels, FLAC_MAX_CHANNELS);
308 return AVERROR(EINVAL);
309 }
310 s->channels = channels;
311
312 /* find samplerate in table */
313 if (freq < 1)
314 return AVERROR(EINVAL);
315 for (i = 1; i < 12; i++) {
316 if (freq == ff_flac_sample_rate_table[i]) {
317 s->samplerate = ff_flac_sample_rate_table[i];
318 s->sr_code[0] = i;
319 s->sr_code[1] = 0;
320 break;
321 }
322 }
323 /* if not in table, samplerate is non-standard */
324 if (i == 12) {
325 if (freq % 1000 == 0 && freq < 255000) {
326 s->sr_code[0] = 12;
327 s->sr_code[1] = freq / 1000;

Callers

nothing calls this directly

Calls 12

av_logFunction · 0.85
select_blocksizeFunction · 0.85
flac_get_max_frame_sizeFunction · 0.85
av_md5_allocFunction · 0.85
av_md5_initFunction · 0.85
ff_lpc_initFunction · 0.85
ff_bswapdsp_initFunction · 0.85
ff_flacencdsp_initFunction · 0.85
write_streaminfoFunction · 0.70
av_mallocFunction · 0.50

Tested by

no test coverage detected