提交 a9d1cc9f 编写于 作者: P Peter Maydell

Merge remote-tracking branch 'remotes/kraxel/tags/audio-20190318-pull-request' into staging

audio: pulseaudio fixes for 4.0

# gpg: Signature made Mon 18 Mar 2019 12:08:50 GMT
# gpg:                using RSA key 4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" [full]
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>" [full]
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>" [full]
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/audio-20190318-pull-request:
  audio/paaudio: fix microphone input being unusable
  audio/paaudio: prolong and make latency configurable
  audio/paaudio: fix ignored buffer_length setting
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
...@@ -549,12 +549,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, ...@@ -549,12 +549,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
ss.channels = as->nchannels; ss.channels = as->nchannels;
ss.rate = as->freq; ss.rate = as->freq;
/* ba.tlength = pa_usec_to_bytes(ppdo->latency, &ss);
* qemu audio tick runs at 100 Hz (by default), so processing ba.minreq = -1;
* data chunks worth 10 ms of sound should be a good fit.
*/
ba.tlength = pa_usec_to_bytes (10 * 1000, &ss);
ba.minreq = pa_usec_to_bytes (5 * 1000, &ss);
ba.maxlength = -1; ba.maxlength = -1;
ba.prebuf = -1; ba.prebuf = -1;
...@@ -577,7 +573,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, ...@@ -577,7 +573,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
audio_pcm_init_info (&hw->info, &obt_as); audio_pcm_init_info (&hw->info, &obt_as);
hw->samples = pa->samples = audio_buffer_samples( hw->samples = pa->samples = audio_buffer_samples(
qapi_AudiodevPaPerDirectionOptions_base(ppdo), &obt_as, 46440); qapi_AudiodevPaPerDirectionOptions_base(ppdo),
&obt_as, ppdo->buffer_length);
pa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift); pa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
pa->rpos = hw->rpos; pa->rpos = hw->rpos;
if (!pa->pcm_buf) { if (!pa->pcm_buf) {
...@@ -608,6 +605,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) ...@@ -608,6 +605,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
{ {
int error; int error;
pa_sample_spec ss; pa_sample_spec ss;
pa_buffer_attr ba;
struct audsettings obt_as = *as; struct audsettings obt_as = *as;
PAVoiceIn *pa = (PAVoiceIn *) hw; PAVoiceIn *pa = (PAVoiceIn *) hw;
paaudio *g = pa->g = drv_opaque; paaudio *g = pa->g = drv_opaque;
...@@ -618,6 +616,11 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) ...@@ -618,6 +616,11 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
ss.channels = as->nchannels; ss.channels = as->nchannels;
ss.rate = as->freq; ss.rate = as->freq;
ba.fragsize = pa_usec_to_bytes(ppdo->latency, &ss);
ba.maxlength = -1;
ba.minreq = -1;
ba.prebuf = -1;
obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness); obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
pa->stream = qpa_simple_new ( pa->stream = qpa_simple_new (
...@@ -627,7 +630,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) ...@@ -627,7 +630,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
ppdo->has_name ? ppdo->name : NULL, ppdo->has_name ? ppdo->name : NULL,
&ss, &ss,
NULL, /* channel map */ NULL, /* channel map */
NULL, /* buffering attributes */ &ba, /* buffering attributes */
&error &error
); );
if (!pa->stream) { if (!pa->stream) {
...@@ -637,7 +640,8 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) ...@@ -637,7 +640,8 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
audio_pcm_init_info (&hw->info, &obt_as); audio_pcm_init_info (&hw->info, &obt_as);
hw->samples = pa->samples = audio_buffer_samples( hw->samples = pa->samples = audio_buffer_samples(
qapi_AudiodevPaPerDirectionOptions_base(ppdo), &obt_as, 46440); qapi_AudiodevPaPerDirectionOptions_base(ppdo),
&obt_as, ppdo->buffer_length);
pa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift); pa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
pa->wpos = hw->wpos; pa->wpos = hw->wpos;
if (!pa->pcm_buf) { if (!pa->pcm_buf) {
...@@ -809,7 +813,20 @@ static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...) ...@@ -809,7 +813,20 @@ static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
return 0; return 0;
} }
/* common */ static int qpa_validate_per_direction_opts(Audiodev *dev,
AudiodevPaPerDirectionOptions *pdo)
{
if (!pdo->has_buffer_length) {
pdo->has_buffer_length = true;
pdo->buffer_length = 46440;
}
if (!pdo->has_latency) {
pdo->has_latency = true;
pdo->latency = 15000;
}
return 1;
}
static void *qpa_audio_init(Audiodev *dev) static void *qpa_audio_init(Audiodev *dev)
{ {
paaudio *g; paaudio *g;
...@@ -836,6 +853,13 @@ static void *qpa_audio_init(Audiodev *dev) ...@@ -836,6 +853,13 @@ static void *qpa_audio_init(Audiodev *dev)
g = g_malloc(sizeof(paaudio)); g = g_malloc(sizeof(paaudio));
server = popts->has_server ? popts->server : NULL; server = popts->has_server ? popts->server : NULL;
if (!qpa_validate_per_direction_opts(dev, popts->in)) {
goto fail;
}
if (!qpa_validate_per_direction_opts(dev, popts->out)) {
goto fail;
}
g->dev = dev; g->dev = dev;
g->mainloop = NULL; g->mainloop = NULL;
g->context = NULL; g->context = NULL;
......
...@@ -206,12 +206,16 @@ ...@@ -206,12 +206,16 @@
# #
# @name: name of the sink/source to use # @name: name of the sink/source to use
# #
# @latency: latency you want PulseAudio to achieve in microseconds
# (default 15000)
#
# Since: 4.0 # Since: 4.0
## ##
{ 'struct': 'AudiodevPaPerDirectionOptions', { 'struct': 'AudiodevPaPerDirectionOptions',
'base': 'AudiodevPerDirectionOptions', 'base': 'AudiodevPerDirectionOptions',
'data': { 'data': {
'*name': 'str' } } '*name': 'str',
'*latency': 'uint32' } }
## ##
# @AudiodevPaOptions: # @AudiodevPaOptions:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册