mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
option to use ALSA default fragment number and size
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@295 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
5f647c8fef
commit
acc8b7890a
5 changed files with 41 additions and 23 deletions
9
doc/todo
9
doc/todo
|
|
@ -1,17 +1,16 @@
|
|||
*** $Id$ ***
|
||||
|
||||
*** 0.7 ****
|
||||
- per-channel volume
|
||||
- option to use default fragment size on alsa drivers
|
||||
- improve module-oss-mmap latency measurement
|
||||
- add radio module
|
||||
- make most buffer sizes dependant on the sample type
|
||||
- limit all resources
|
||||
- commenting
|
||||
- module-tunnel: use latency interpolation
|
||||
- polish for starting polypaudio as root/system-wide instance
|
||||
|
||||
** later ***
|
||||
- per-channel volume
|
||||
- improve module-oss-mmap latency measurement
|
||||
- module-tunnel: improve latency calculation
|
||||
- add radio module
|
||||
- pass meta info for hearing impaired
|
||||
- add sync API
|
||||
- X11: support for the X11 synchronization extension
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@
|
|||
#include "sample.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, struct pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *buffer_size) {
|
||||
int ret = 0;
|
||||
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, struct pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size) {
|
||||
int ret = -1;
|
||||
snd_pcm_uframes_t buffer_size;
|
||||
snd_pcm_hw_params_t *hwparams = NULL;
|
||||
static const snd_pcm_format_t format_trans[] = {
|
||||
[PA_SAMPLE_U8] = SND_PCM_FORMAT_U8,
|
||||
|
|
@ -42,21 +43,39 @@ int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, struct pa_sample_spec *ss, uint
|
|||
[PA_SAMPLE_FLOAT32LE] = SND_PCM_FORMAT_FLOAT_LE,
|
||||
[PA_SAMPLE_FLOAT32BE] = SND_PCM_FORMAT_FLOAT_BE,
|
||||
};
|
||||
|
||||
assert(pcm_handle && ss && periods && period_size);
|
||||
|
||||
if (snd_pcm_hw_params_malloc(&hwparams) < 0 ||
|
||||
snd_pcm_hw_params_any(pcm_handle, hwparams) < 0 ||
|
||||
snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0 ||
|
||||
snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[ss->format]) < 0 ||
|
||||
snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &ss->rate, NULL) < 0 ||
|
||||
snd_pcm_hw_params_set_channels(pcm_handle, hwparams, ss->channels) < 0 ||
|
||||
snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, periods, NULL) < 0 ||
|
||||
snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, buffer_size) < 0 ||
|
||||
snd_pcm_hw_params(pcm_handle, hwparams) < 0) {
|
||||
ret = -1;
|
||||
}
|
||||
(*periods > 0 && snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, periods, NULL) < 0) ||
|
||||
(*period_size > 0 && snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, period_size, NULL) < 0) ||
|
||||
snd_pcm_hw_params(pcm_handle, hwparams) < 0)
|
||||
goto finish;
|
||||
|
||||
if (snd_pcm_prepare(pcm_handle) < 0)
|
||||
goto finish;
|
||||
|
||||
if (snd_pcm_hw_params_current(pcm_handle, hwparams) < 0)
|
||||
goto finish;
|
||||
|
||||
if (snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size) < 0 ||
|
||||
snd_pcm_hw_params_get_period_size(hwparams, period_size, NULL) < 0)
|
||||
goto finish;
|
||||
|
||||
assert(buffer_size > 0 && *period_size > 0);
|
||||
*periods = buffer_size / *period_size;
|
||||
assert(*periods > 0);
|
||||
|
||||
ret = 0;
|
||||
|
||||
finish:
|
||||
if (hwparams)
|
||||
snd_pcm_hw_params_free(hwparams);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
#include "sample.h"
|
||||
#include "mainloop-api.h"
|
||||
|
||||
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, struct pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *buffer_size);
|
||||
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, struct pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size);
|
||||
|
||||
int pa_create_io_events(snd_pcm_t *pcm_handle, struct pa_mainloop_api *m, struct pa_io_event ***io_events, unsigned *n_io_events, void (*cb)(struct pa_mainloop_api*a, struct pa_io_event *e, int fd, enum pa_io_event_flags events, void *userdata), void *userdata);
|
||||
void pa_free_io_events(struct pa_mainloop_api* m, struct pa_io_event **io_sources, unsigned n_io_sources);
|
||||
|
|
|
|||
|
|
@ -174,8 +174,8 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
struct userdata *u = NULL;
|
||||
const char *dev;
|
||||
struct pa_sample_spec ss;
|
||||
unsigned periods, fragsize;
|
||||
snd_pcm_uframes_t buffer_size;
|
||||
uint32_t periods, fragsize;
|
||||
snd_pcm_uframes_t period_size;
|
||||
size_t frame_size;
|
||||
|
||||
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
||||
|
|
@ -196,7 +196,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
pa_log(__FILE__": failed to parse buffer metrics\n");
|
||||
goto fail;
|
||||
}
|
||||
buffer_size = fragsize/frame_size*periods;
|
||||
period_size = fragsize;
|
||||
|
||||
u = pa_xmalloc0(sizeof(struct userdata));
|
||||
m->userdata = u;
|
||||
|
|
@ -207,7 +207,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &buffer_size) < 0) {
|
||||
if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &period_size) < 0) {
|
||||
pa_log(__FILE__": Failed to set hardware parameters\n");
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -226,7 +226,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
}
|
||||
|
||||
u->frame_size = frame_size;
|
||||
u->fragment_size = buffer_size*u->frame_size/periods;
|
||||
u->fragment_size = period_size;
|
||||
|
||||
pa_log(__FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
|
||||
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
const char *dev;
|
||||
struct pa_sample_spec ss;
|
||||
unsigned periods, fragsize;
|
||||
snd_pcm_uframes_t buffer_size;
|
||||
snd_pcm_uframes_t period_size;
|
||||
size_t frame_size;
|
||||
|
||||
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
||||
|
|
@ -187,7 +187,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
pa_log(__FILE__": failed to parse buffer metrics\n");
|
||||
goto fail;
|
||||
}
|
||||
buffer_size = fragsize/frame_size*periods;
|
||||
period_size = fragsize;
|
||||
|
||||
u = pa_xmalloc0(sizeof(struct userdata));
|
||||
m->userdata = u;
|
||||
|
|
@ -198,7 +198,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &buffer_size) < 0) {
|
||||
if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &period_size) < 0) {
|
||||
pa_log(__FILE__": Failed to set hardware parameters\n");
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
}
|
||||
|
||||
u->frame_size = frame_size;
|
||||
u->fragment_size = buffer_size*u->frame_size/periods;
|
||||
u->fragment_size = period_size;
|
||||
|
||||
pa_log(__FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue