[FFmpeg-cvslog] ffplay: calculate SDL audio buffer size based on sample rate

Marton Balint git at videolan.org
Tue Jun 24 22:41:15 CEST 2014


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Sun May 25 02:41:09 2014 +0200| [1ca5c1784b1d3804e2ce4d695b53af31e2e287fc] | committer: Marton Balint

ffplay: calculate SDL audio buffer size based on sample rate

Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1ca5c1784b1d3804e2ce4d695b53af31e2e287fc
---

 ffplay.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/ffplay.c b/ffplay.c
index 018c1b4..70fdac7 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) {



More information about the ffmpeg-cvslog mailing list