[FFmpeg-devel] [PATCH] pulse: set default frame_size to 4608
Federico Simoncelli
federico.simoncelli at gmail.com
Thu Jan 2 16:36:45 CET 2014
Given the current defaults (channels = 2, sample_rate = 48000) the
frame_size is changed to 4608 in order to obtain whole numbers for
frame_duration (both 16 and 24 bits_per_sample).
frame_duration = (frame_size * 1000000 * 8) /
(sample_rate * channels * bits_per_sample)
A message has been added to warn the user when the frame duration
is not an integer.
Signed-off-by: Federico Simoncelli <fsimonce at redhat.com>
---
libavdevice/pulse_audio_dec.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index 639b381..289b91c3 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -55,6 +55,7 @@ static av_cold int pulse_read_header(AVFormatContext *s)
AVStream *st;
char *device = NULL;
int ret;
+ float frame_duration;
enum AVCodecID codec_id =
s->audio_codec_id == AV_CODEC_ID_NONE ? DEFAULT_CODEC_ID : s->audio_codec_id;
const pa_sample_spec ss = { ff_codec_id_to_pulse_format(codec_id),
@@ -93,8 +94,15 @@ static av_cold int pulse_read_header(AVFormatContext *s)
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
pd->pts = AV_NOPTS_VALUE;
- pd->frame_duration = (pd->frame_size * 1000000LL * 8) /
+ frame_duration = (pd->frame_size * 1000000.0F * 8) /
(pd->sample_rate * pd->channels * av_get_bits_per_sample(codec_id));
+ pd->frame_duration = frame_duration;
+
+ if (pd->frame_duration != frame_duration) {
+ av_log(s, AV_LOG_WARNING, "non-integer frame_duration %.1f will "
+ "produce uneven pts intervals, adjust frame_size (current "
+ "value is %i)\n", frame_duration, pd->frame_size);
+ }
return 0;
}
@@ -149,7 +157,7 @@ static const AVOption options[] = {
{ "stream_name", "set stream description", OFFSET(stream_name), AV_OPT_TYPE_STRING, {.str = "record"}, 0, 0, D },
{ "sample_rate", "set sample rate in Hz", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 1, INT_MAX, D },
{ "channels", "set number of audio channels", OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, D },
- { "frame_size", "set number of bytes per frame", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, INT_MAX, D },
+ { "frame_size", "set number of bytes per frame", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 4608}, 1, INT_MAX, D },
{ "fragment_size", "set buffering size, affects latency and cpu usage", OFFSET(fragment_size), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D },
{ NULL },
};
--
1.8.4.2
More information about the ffmpeg-devel
mailing list