History

lavc: add a variant of av_get_audio_frame_duration working with AVCodecParameters

Anton Khirnov committed 12 years ago

Commit a8068341 parent 998e1b83 files · +29 −12Browse files

Unified · Split

3 files
  1. doc/APIchanges +1 −0
  2. libavcodec/avcodec.h +6 −0
  3. libavcodec/utils.c +22 −12
doc/APIchanges+1−0
@@ -15,6 +15,7 @@ API changes, most recent first: · 14 unmodified lines
15 15
162016-xx-xx - lavc 57.14.0 - avcodec.h162016-xx-xx - lavc 57.14.0 - avcodec.h
17 xxxxxxx - Add AVCodecParameters and its related API.17 xxxxxxx - Add AVCodecParameters and its related API.
18 xxxxxxx - Add av_get_audio_frame_duration2().
18 19
192016-xx-xx - xxxxxxx - lavf 57.4.0 - avformat.h202016-xx-xx - xxxxxxx - lavf 57.4.0 - avformat.h
20 Add AVFormatContext.protocol_whitelist and protocol_blacklist.21 Add AVFormatContext.protocol_whitelist and protocol_blacklist.
libavcodec/avcodec.h+6−0
@@ -4686,6 +4686,12 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id); · 4685 unmodified lines
4686 */4686 */
4687int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);4687int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
4688 4688
4689/**
4690 * This function is the same as av_get_audio_frame_duration(), except it works
4691 * with AVCodecParameters instead of an AVCodecContext.
4692 */
4693int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
4694
4689 4695
4690typedef struct AVBitStreamFilterContext {4696typedef struct AVBitStreamFilterContext {
4691 void *priv_data;4697 void *priv_data;
libavcodec/utils.c+22−12
@@ -2037,21 +2037,15 @@ int av_get_bits_per_sample(enum AVCodecID codec_id) · 2036 unmodified lines
2037 }2037 }
2038}2038}
2039 2039
2040int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)2040static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
2041 uint32_t tag, int bits_per_coded_sample, int frame_bytes)
2041{2042{
2042 int id, sr, ch, ba, tag, bps;2043 int bps = av_get_exact_bits_per_sample(id);
2043
2044 id = avctx->codec_id;
2045 sr = avctx->sample_rate;
2046 ch = avctx->channels;
2047 ba = avctx->block_align;
2048 tag = avctx->codec_tag;
2049 bps = av_get_exact_bits_per_sample(avctx->codec_id);
2050 2044
2051 /* codecs with an exact constant bits per sample */2045 /* codecs with an exact constant bits per sample */
2052 if (bps > 0 && ch > 0 && frame_bytes > 0)2046 if (bps > 0 && ch > 0 && frame_bytes > 0)
2053 return (frame_bytes * 8) / (bps * ch);2047 return (frame_bytes * 8) / (bps * ch);
2054 bps = avctx->bits_per_coded_sample;2048 bps = bits_per_coded_sample;
2055 2049
2056 /* codecs with a fixed packet duration */2050 /* codecs with a fixed packet duration */
2057 switch (id) {2051 switch (id) {
@@ -2155,7 +2149,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) · 97 unmodified lines
2155 if (ba > 0) {2149 if (ba > 0) {
2156 /* calc from frame_bytes, channels, and block_align */2150 /* calc from frame_bytes, channels, and block_align */
2157 int blocks = frame_bytes / ba;2151 int blocks = frame_bytes / ba;
2158 switch (avctx->codec_id) {2152 switch (id) {
2159 case AV_CODEC_ID_ADPCM_IMA_WAV:2153 case AV_CODEC_ID_ADPCM_IMA_WAV:
2160 return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);2154 return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
2161 case AV_CODEC_ID_ADPCM_IMA_DK3:2155 case AV_CODEC_ID_ADPCM_IMA_DK3:
@@ -2169,7 +2163,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) · 7 unmodified lines
2169 2163
2170 if (bps > 0) {2164 if (bps > 0) {
2171 /* calc from frame_bytes, channels, and bits_per_coded_sample */2165 /* calc from frame_bytes, channels, and bits_per_coded_sample */
2172 switch (avctx->codec_id) {2166 switch (id) {
2173 case AV_CODEC_ID_PCM_DVD:2167 case AV_CODEC_ID_PCM_DVD:
2174 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));2168 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2175 case AV_CODEC_ID_PCM_BLURAY:2169 case AV_CODEC_ID_PCM_BLURAY:
@@ -2184,6 +2178,22 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) · 8 unmodified lines
2184 return 0;2178 return 0;
2185}2179}
2186 2180
2181int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
2182{
2183 return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
2184 avctx->channels, avctx->block_align,
2185 avctx->codec_tag, avctx->bits_per_coded_sample,
2186 frame_bytes);
2187}
2188
2189int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
2190{
2191 return get_audio_frame_duration(par->codec_id, par->sample_rate,
2192 par->channels, par->block_align,
2193 par->codec_tag, par->bits_per_coded_sample,
2194 frame_bytes);
2195}
2196
2187#if !HAVE_THREADS2197#if !HAVE_THREADS
2188int ff_thread_init(AVCodecContext *s)2198int ff_thread_init(AVCodecContext *s)
2189{2199{

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t