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

Function get_audio_frame_duration

libavcodec/utils.c:571–801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

569}
570
571static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
572 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
573 uint8_t * extradata, int frame_size, int frame_bytes)
574{
575 int bps = av_get_exact_bits_per_sample(id);
576 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
577
578 /* codecs with an exact constant bits per sample */
579 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
580 return (frame_bytes * 8LL) / (bps * ch);
581 bps = bits_per_coded_sample;
582
583 /* codecs with a fixed packet duration */
584 switch (id) {
585 case AV_CODEC_ID_ADPCM_ADX: return 32;
586 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
587 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
588 case AV_CODEC_ID_AMR_NB:
589 case AV_CODEC_ID_EVRC:
590 case AV_CODEC_ID_GSM:
591 case AV_CODEC_ID_QCELP:
592 case AV_CODEC_ID_RA_288: return 160;
593 case AV_CODEC_ID_AMR_WB:
594 case AV_CODEC_ID_GSM_MS: return 320;
595 case AV_CODEC_ID_MP1: return 384;
596 case AV_CODEC_ID_ATRAC1: return 512;
597 case AV_CODEC_ID_ATRAC9:
598 case AV_CODEC_ID_ATRAC3:
599 if (framecount > INT_MAX/1024)
600 return 0;
601 return 1024 * framecount;
602 case AV_CODEC_ID_ATRAC3P: return 2048;
603 case AV_CODEC_ID_MP2:
604 case AV_CODEC_ID_MUSEPACK7: return 1152;
605 case AV_CODEC_ID_AC3: return 1536;
606 case AV_CODEC_ID_FTR: return 1024;
607 }
608
609 if (sr > 0) {
610 /* calc from sample rate */
611 if (id == AV_CODEC_ID_TTA)
612 return 256ll * sr / 245;
613 else if (id == AV_CODEC_ID_DST)
614 return 588ll * sr / 44100;
615 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
616 if (sr / 22050 > 22)
617 return 0;
618 return (480 << (sr / 22050));
619 }
620
621 if (id == AV_CODEC_ID_MP3)
622 return sr <= 24000 ? 576 : 1152;
623 }
624
625 if (ba > 0) {
626 /* calc from block_align */
627 if (id == AV_CODEC_ID_SIPR) {
628 switch (ba) {

Callers 2

Calls 1

Tested by

no test coverage detected