summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Yves Avenard <jyavenard@mythtv.org>2010-12-16 12:11:06 (GMT)
committer Jean-Yves Avenard <jyavenard@mythtv.org>2010-12-16 12:11:06 (GMT)
commitde60515e4c972fef9a0ee3c53c103a573d9d902d (patch)
treecfaa62417c5caab8299aca264fcf3b0cb6dec0e7
parent64d9d7c52f301bb4ddf65ef97a02e46cff810b02 (diff)
Change on how we calculate the required ALSA hardware buffer size.
Hopefully 4th time lucky. Instead of calculating what we think the size should be, use the size of the buffer ALSA allocated following our request. If less than requested, use the ratio between what we asked for and what we got, and multiply the current hardware buffer size by this value. Round it up the new nearest 64kB multiple
-rw-r--r--mythtv/libs/libmyth/audiooutputalsa.cpp42
-rw-r--r--mythtv/libs/libmyth/audiooutputalsa.h2
2 files changed, 22 insertions, 22 deletions
diff --git a/mythtv/libs/libmyth/audiooutputalsa.cpp b/mythtv/libs/libmyth/audiooutputalsa.cpp
index 4875927..6c8ca24 100644
--- a/mythtv/libs/libmyth/audiooutputalsa.cpp
+++ b/mythtv/libs/libmyth/audiooutputalsa.cpp
@@ -175,7 +175,7 @@ bool AudioOutputALSA::SetPreallocBufferSize(int size)
int card, device, subdevice;
bool ret = true;
- VBAUDIO(QString("Setting preallocated buffer size to %1").arg(size));
+ VBERROR(QString("Setting hardware audio buffer size to %1").arg(size));
if (GetPCMInfo(card, device, subdevice) < 0)
return false;
@@ -190,9 +190,10 @@ bool AudioOutputALSA::SetPreallocBufferSize(int size)
if (!pfile.open(QIODevice::ReadWrite))
{
- VBERROR(QString("Error opening %1: %2. "
- "Try to increase it with: echo %3 | sudo tee %1")
- .arg(pfile.fileName()).arg(pfile.errorString()).arg(size));
+ VBERROR(QString("Error opening %1: %2. ")
+ .arg(pfile.fileName()).arg(pfile.errorString()));
+ VBERROR(QString("Try to manually increase audio buffer with: echo %1 "
+ "| sudo tee %2").arg(size).arg(pfile.fileName()));
return false;
}
@@ -209,7 +210,7 @@ bool AudioOutputALSA::SetPreallocBufferSize(int size)
return ret;
}
-bool AudioOutputALSA::IncPreallocBufferSize(int buffer_time)
+bool AudioOutputALSA::IncPreallocBufferSize(int requested, int buffer_time)
{
int card, device, subdevice;
bool ret = true;
@@ -239,20 +240,12 @@ bool AudioOutputALSA::IncPreallocBufferSize(int buffer_time)
int cur = pfile.readAll().trimmed().toInt();
int max = mfile.readAll().trimmed().toInt();
- int size = (((samplerate / 1000) *
- (buffer_time / 1000) *
- output_bytes_per_frame / 1024) / 64 + 1) * 64;
+ int size = ((int)(cur * (float)requested / (float)buffer_time)
+ / 64 + 1) * 64;
- VBAUDIO(QString("Prealloc buffer cur: %1 max: %3").arg(cur).arg(max));
+ VBAUDIO(QString("Hardware audio buffer cur: %1 need: %2 max allowed: %3")
+ .arg(cur).arg(size).arg(max));
- if(size == cur)
- {
- pfile.close();
- mfile.close();
- ret = false;
- return ret;
- }
-
if (size > max || !size)
{
size = max;
@@ -425,8 +418,8 @@ bool AudioOutputALSA::OpenDevice()
{
// We need to increase preallocated buffer size in the driver
// Set it and try again
- if(!IncPreallocBufferSize(buffer_time))
- VBERROR("Unable to sufficiently increase preallocated buffer size"
+ if(!IncPreallocBufferSize(buffer_time, err))
+ VBERROR("Unable to sufficiently increase ALSA hardware buffer size"
" - underruns are likely");
return OpenDevice();
}
@@ -581,6 +574,13 @@ int AudioOutputALSA::GetBufferedOnSoundcard(void) const
return delay * output_bytes_per_frame;
}
+/*
+ * Set the various ALSA audio parameters.
+ * Returns:
+ * < 0 : an error occurred
+ * 0 : Succeeded
+ * > 0 : Buffer timelength returned by ALSA which is less than what we asked for
+ */
int AudioOutputALSA::SetParameters(snd_pcm_t *handle, snd_pcm_format_t format,
uint channels, uint rate, uint buffer_time,
uint period_time)
@@ -599,7 +599,7 @@ int AudioOutputALSA::SetParameters(snd_pcm_t *handle, snd_pcm_format_t format,
if (handle == NULL)
{
Error("SetParameters() called with handle == NULL!");
- return 0;
+ return -1;
}
snd_pcm_hw_params_alloca(&params);
@@ -667,7 +667,7 @@ int AudioOutputALSA::SetParameters(snd_pcm_t *handle, snd_pcm_format_t format,
// See if we need to increase the prealloc'd buffer size
// If buffer_time is too small we could underrun
// Make 10% leeway okay
- if (buffer_time * 1.10f < (float)original_buffer_time && pbufsize < 0)
+ if ((buffer_time * 1.10f < (float)original_buffer_time) && pbufsize < 0)
{
VBAUDIO(QString("Requested %1us got %2 buffer time")
.arg(original_buffer_time).arg(buffer_time));
diff --git a/mythtv/libs/libmyth/audiooutputalsa.h b/mythtv/libs/libmyth/audiooutputalsa.h
index 4ac5759..527962e 100644
--- a/mythtv/libs/libmyth/audiooutputalsa.h
+++ b/mythtv/libs/libmyth/audiooutputalsa.h
@@ -34,7 +34,7 @@ class AudioOutputALSA : public AudioOutputBase
int TryOpenDevice(int open_mode, int try_ac3);
int GetPCMInfo(int &card, int &device, int &subdevice);
bool SetPreallocBufferSize(int size);
- bool IncPreallocBufferSize(int buffer_time);
+ bool IncPreallocBufferSize(int requested, int buffer_time);
inline int SetParameters(snd_pcm_t *handle, snd_pcm_format_t format,
uint channels, uint rate, uint buffer_time,
uint period_time);