mirror of
https://github.com/mpv-player/mpv
synced 2025-02-20 14:56:55 +00:00
Use a buffer of about half a second, instead of sizing it to have
a constant number of frames. This improves the behaviour at very small or large sample rates, and gets rid of lots of obsolete code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29549 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
ec7e2695a6
commit
f17ed52432
@ -1278,10 +1278,7 @@ static const char help_text[]=
|
||||
#define MSGTR_AO_ALSA_UnableToDisableResampling "[AO_ALSA] Unable to disable resampling: %s\n"
|
||||
#define MSGTR_AO_ALSA_UnableToSetSamplerate2 "[AO_ALSA] Unable to set samplerate-2: %s\n"
|
||||
#define MSGTR_AO_ALSA_UnableToSetBufferTimeNear "[AO_ALSA] Unable to set buffer time near: %s\n"
|
||||
#define MSGTR_AO_ALSA_UnableToSetPeriodTime "[AO_ALSA] Unable to set period time: %s\n"
|
||||
#define MSGTR_AO_ALSA_BufferTimePeriodTime "[AO_ALSA] buffer_time: %d, period_time :%d\n"
|
||||
#define MSGTR_AO_ALSA_UnableToGetPeriodSize "[AO ALSA] Unable to get period size: %s\n"
|
||||
#define MSGTR_AO_ALSA_UnableToSetPeriodSize "[AO ALSA] Unable to set period size(%ld): %s\n"
|
||||
#define MSGTR_AO_ALSA_UnableToSetPeriods "[AO_ALSA] Unable to set periods: %s\n"
|
||||
#define MSGTR_AO_ALSA_UnableToSetHwParameters "[AO_ALSA] Unable to set hw-parameters: %s\n"
|
||||
#define MSGTR_AO_ALSA_UnableToGetBufferSize "[AO_ALSA] Unable to get buffersize: %s\n"
|
||||
|
@ -72,11 +72,8 @@ static snd_pcm_format_t alsa_format;
|
||||
static snd_pcm_hw_params_t *alsa_hwparams;
|
||||
static snd_pcm_sw_params_t *alsa_swparams;
|
||||
|
||||
/* 16 sets buffersize to 16 * chunksize is as default 1024
|
||||
* which seems to be good avarge for most situations
|
||||
* so buffersize is 16384 frames by default */
|
||||
static int alsa_fragcount = 16;
|
||||
static snd_pcm_uframes_t chunk_size = 1024;
|
||||
static unsigned int alsa_buffer_time = 500000; /* 0.5 s */
|
||||
static unsigned int alsa_fragcount = 16;
|
||||
|
||||
static size_t bytes_per_sample;
|
||||
|
||||
@ -87,9 +84,6 @@ static int alsa_can_pause = 0;
|
||||
|
||||
#define ALSA_DEVICE_SIZE 256
|
||||
|
||||
#undef BUFFERTIME
|
||||
#define SET_CHUNKSIZE
|
||||
|
||||
static void alsa_error_handler(const char *file, int line, const char *function,
|
||||
int err, const char *format, ...)
|
||||
{
|
||||
@ -329,6 +323,7 @@ static int init(int rate_hz, int channels, int format, int flags)
|
||||
int err;
|
||||
int block;
|
||||
strarg_t device;
|
||||
snd_pcm_uframes_t chunk_size;
|
||||
snd_pcm_uframes_t bufsize;
|
||||
snd_pcm_uframes_t boundary;
|
||||
opt_t subopts[] = {
|
||||
@ -484,41 +479,6 @@ static int init(int rate_hz, int channels, int format, int flags)
|
||||
open_mode = 0;
|
||||
}
|
||||
|
||||
//sets buff/chunksize if its set manually
|
||||
if (ao_data.buffersize) {
|
||||
switch (ao_data.buffersize)
|
||||
{
|
||||
case 1:
|
||||
alsa_fragcount = 16;
|
||||
chunk_size = 512;
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: buffersize set manually to 8192\n");
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set manually to 512\n");
|
||||
break;
|
||||
case 2:
|
||||
alsa_fragcount = 8;
|
||||
chunk_size = 1024;
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: buffersize set manually to 8192\n");
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set manually to 1024\n");
|
||||
break;
|
||||
case 3:
|
||||
alsa_fragcount = 32;
|
||||
chunk_size = 512;
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: buffersize set manually to 16384\n");
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set manually to 512\n");
|
||||
break;
|
||||
case 4:
|
||||
alsa_fragcount = 16;
|
||||
chunk_size = 1024;
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: buffersize set manually to 16384\n");
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set manually to 1024\n");
|
||||
break;
|
||||
default:
|
||||
alsa_fragcount = 16;
|
||||
chunk_size = 1024;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!alsa_handler) {
|
||||
//modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC
|
||||
if ((err = try_open_device(alsa_device, open_mode, format == AF_FORMAT_AC3)) < 0)
|
||||
@ -611,57 +571,20 @@ static int init(int rate_hz, int channels, int format, int flags)
|
||||
bytes_per_sample *= ao_data.channels;
|
||||
ao_data.bps = ao_data.samplerate * bytes_per_sample;
|
||||
|
||||
#ifdef BUFFERTIME
|
||||
{
|
||||
int alsa_buffer_time = 500000; /* original 60 */
|
||||
int alsa_period_time;
|
||||
alsa_period_time = alsa_buffer_time/4;
|
||||
if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams,
|
||||
&alsa_buffer_time, NULL)) < 0)
|
||||
{
|
||||
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetBufferTimeNear,
|
||||
snd_strerror(err));
|
||||
return 0;
|
||||
} else
|
||||
alsa_buffer_time = err;
|
||||
|
||||
if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams,
|
||||
&alsa_period_time, NULL)) < 0)
|
||||
/* original: alsa_buffer_time/ao_data.bps */
|
||||
{
|
||||
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetPeriodTime,
|
||||
snd_strerror(err));
|
||||
return 0;
|
||||
}
|
||||
mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_BufferTimePeriodTime,
|
||||
alsa_buffer_time, err);
|
||||
}
|
||||
#endif//end SET_BUFFERTIME
|
||||
|
||||
#ifdef SET_CHUNKSIZE
|
||||
{
|
||||
//set chunksize
|
||||
if ((err = snd_pcm_hw_params_set_period_size_near(alsa_handler, alsa_hwparams,
|
||||
&chunk_size, NULL)) < 0)
|
||||
{
|
||||
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetPeriodSize,
|
||||
chunk_size, snd_strerror(err));
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set to %li\n", chunk_size);
|
||||
}
|
||||
if ((err = snd_pcm_hw_params_set_periods_near(alsa_handler, alsa_hwparams,
|
||||
&alsa_fragcount, NULL)) < 0) {
|
||||
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetPeriods,
|
||||
snd_strerror(err));
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
mp_msg(MSGT_AO,MSGL_V,"alsa-init: fragcount=%i\n", alsa_fragcount);
|
||||
}
|
||||
}
|
||||
#endif//end SET_CHUNKSIZE
|
||||
|
||||
/* finally install hardware parameters */
|
||||
if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user