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
1515
1616 2016-xx-xx - lavc 57.14.0 - avcodec.h
1717 xxxxxxx - Add AVCodecParameters and its related API.
18+ xxxxxxx - Add av_get_audio_frame_duration2().
1819
1920 2016-xx-xx - xxxxxxx - lavf 57.4.0 - avformat.h
2021 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
46864686 */
46874687 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
46884688
4689+/**
4690+ * This function is the same as av_get_audio_frame_duration(), except it works
4691+ * with AVCodecParameters instead of an AVCodecContext.
4692+ */
4693+int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
4694+
46894695
46904696 typedef struct AVBitStreamFilterContext {
46914697 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
20372037 }
20382038 }
20392039
2040−int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
2040+static 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)
20412042 {
2042− int id, sr, ch, ba, tag, bps;
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);
2043+ int bps = av_get_exact_bits_per_sample(id);
20502044
20512045 /* codecs with an exact constant bits per sample */
20522046 if (bps > 0 && ch > 0 && frame_bytes > 0)
20532047 return (frame_bytes * 8) / (bps * ch);
2054− bps = avctx->bits_per_coded_sample;
2048+ bps = bits_per_coded_sample;
20552049
20562050 /* codecs with a fixed packet duration */
20572051 switch (id) {
@@ -2155,7 +2149,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) · 97 unmodified lines
21552149 if (ba > 0) {
21562150 /* calc from frame_bytes, channels, and block_align */
21572151 int blocks = frame_bytes / ba;
2158− switch (avctx->codec_id) {
2152+ switch (id) {
21592153 case AV_CODEC_ID_ADPCM_IMA_WAV:
21602154 return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
21612155 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
21692163
21702164 if (bps > 0) {
21712165 /* calc from frame_bytes, channels, and bits_per_coded_sample */
2172− switch (avctx->codec_id) {
2166+ switch (id) {
21732167 case AV_CODEC_ID_PCM_DVD:
21742168 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
21752169 case AV_CODEC_ID_PCM_BLURAY:
@@ -2184,6 +2178,22 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) · 8 unmodified lines
21842178 return 0;
21852179 }
21862180
2181+int 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+
2189+int 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+
21872197 #if !HAVE_THREADS
21882198 int ff_thread_init(AVCodecContext *s)
21892199 {

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