aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2014-05-25 02:41:09 +0200
committerMarton Balint <cus@passwd.hu>2014-06-24 21:59:21 +0200
commit1ca5c1784b1d3804e2ce4d695b53af31e2e287fc (patch)
tree0a18ae6720a65dd7e1bcb22eaef07672828aa5b6
parentba800defa7c8af94f30f5e655c860b6f4832131f (diff)
downloadffmpeg-1ca5c1784b1d3804e2ce4d695b53af31e2e287fc.tar.gz
ffplay: calculate SDL audio buffer size based on sample rate
Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r--ffplay.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/ffplay.c b/ffplay.c
index 018c1b4697..70fdac7a54 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -67,9 +67,11 @@ const int program_birth_year = 2003;
#define MAX_QUEUE_SIZE (15 * 1024 * 1024)
#define MIN_FRAMES 5
-/* SDL audio buffer size, in samples. Should be small to have precise
+/* Minimum SDL audio buffer size, in samples. Should be small to have precise
A/V sync as SDL does not have hardware buffer fullness info. */
-#define SDL_AUDIO_BUFFER_SIZE 1024
+#define SDL_AUDIO_MIN_BUFFER_SIZE 512
+/* Calculate actual buffer size keeping in mind not cause too frequent audio callbacks */
+#define SDL_AUDIO_MAX_CALLBACKS_PER_SEC 60
/* no AV sync correction is done if below the minimum AV sync threshold */
#define AV_SYNC_THRESHOLD_MIN 0.04
@@ -202,7 +204,7 @@ typedef struct VideoState {
AVStream *audio_st;
PacketQueue audioq;
int audio_hw_buf_size;
- uint8_t silence_buf[SDL_AUDIO_BUFFER_SIZE];
+ uint8_t silence_buf[SDL_AUDIO_MIN_BUFFER_SIZE];
uint8_t *audio_buf;
uint8_t *audio_buf1;
unsigned int audio_buf_size; /* in bytes */
@@ -2483,7 +2485,7 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
next_sample_rate_idx--;
wanted_spec.format = AUDIO_S16SYS;
wanted_spec.silence = 0;
- wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
+ wanted_spec.samples = FFMAX(SDL_AUDIO_MIN_BUFFER_SIZE, 2 << av_log2(wanted_spec.freq / SDL_AUDIO_MAX_CALLBACKS_PER_SEC));
wanted_spec.callback = sdl_audio_callback;
wanted_spec.userdata = opaque;
while (SDL_OpenAudio(&wanted_spec, &spec) < 0) {