Browse Source

alsa: limit buffer_size to 32768 frames.

In testing, the file output plugin gave a max buffer size of about 20 million
frames, which is way more than what is really needed and causes a memory
allocation error on my system.
tags/n0.9
Justin Ruggles 14 years ago
parent
commit
e35c674d13
2 changed files with 3 additions and 0 deletions
  1. +1
    -0
      libavdevice/alsa-audio-common.c
  2. +2
    -0
      libavdevice/alsa-audio.h

+ 1
- 0
libavdevice/alsa-audio-common.c View File

@@ -260,6 +260,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
} }


snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size); snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size);
buffer_size = FFMIN(buffer_size, ALSA_BUFFER_SIZE_MAX);
/* TODO: maybe use ctx->max_picture_buffer somehow */ /* TODO: maybe use ctx->max_picture_buffer somehow */
res = snd_pcm_hw_params_set_buffer_size_near(h, hw_params, &buffer_size); res = snd_pcm_hw_params_set_buffer_size_near(h, hw_params, &buffer_size);
if (res < 0) { if (res < 0) {


+ 2
- 0
libavdevice/alsa-audio.h View File

@@ -40,6 +40,8 @@
other formats */ other formats */
#define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE) #define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE)


#define ALSA_BUFFER_SIZE_MAX 32768

typedef struct { typedef struct {
AVClass *class; AVClass *class;
snd_pcm_t *h; snd_pcm_t *h;


Loading…
Cancel
Save