summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Yves Avenard <jyavenard@mythtv.org>2010-12-10 09:25:46 (GMT)
committer Jean-Yves Avenard <jyavenard@mythtv.org>2010-12-13 11:27:59 (GMT)
commit1b695d73025805dccfd86426c388945db1912469 (patch)
treec639599c237afa79eb2187ed613f827b2e175850
parent3a0bc285618a3d759af2ea0900400cb048c2cf67 (diff)
Issue we were trying to fix in SHA: 312ef27cd0d5a8b515cf0ba2587bdc2ba94aac28 were in fact related to the alsa hardware buffer size being too low. And the calculation for what the correct buffer size should be being incorrect, we never got the proper value displayed/set. For 5.1 32 bits LPCM, 48kHz a minimum buffer size should be 225kB. Alsa default is 64kB
-rw-r--r--mythtv/libs/libmyth/audiooutputalsa.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/mythtv/libs/libmyth/audiooutputalsa.cpp b/mythtv/libs/libmyth/audiooutputalsa.cpp
index 0df5828..1960c8c 100644
--- a/mythtv/libs/libmyth/audiooutputalsa.cpp
+++ b/mythtv/libs/libmyth/audiooutputalsa.cpp
@@ -94,8 +94,6 @@ AudioOutputALSA::AudioOutputALSA(const AudioSettings &settings) :
AudioOutputALSA::~AudioOutputALSA()
{
- if (pbufsize > 0)
- SetPreallocBufferSize(pbufsize);
KillAudio();
}
@@ -235,7 +233,10 @@ bool AudioOutputALSA::IncPreallocBufferSize(int buffer_time)
int cur = pfile.readAll().trimmed().toInt();
int max = mfile.readAll().trimmed().toInt();
- int size = cur * (50000 / buffer_time + 1);
+
+ int size = (samplerate / 1000) *
+ (buffer_time / 1000) *
+ output_bytes_per_frame / 1024;
VBAUDIO(QString("Prealloc buffer cur: %1 max: %3").arg(cur).arg(max));
@@ -414,7 +415,7 @@ bool AudioOutputALSA::OpenDevice()
{
// We need to increase preallocated buffer size in the driver
// Set it and try again
- if(!IncPreallocBufferSize(err))
+ if(!IncPreallocBufferSize(buffer_time))
VBERROR("Unable to sufficiently increase preallocated buffer size"
" - underruns are likely");
return OpenDevice();
@@ -647,14 +648,20 @@ int AudioOutputALSA::SetParameters(snd_pcm_t *handle, snd_pcm_format_t format,
}
/* set the buffer time */
+ dir = 0;
+ uint original_buffer_time = buffer_time;
err = snd_pcm_hw_params_set_buffer_time_near(handle, params,
&buffer_time, &dir);
CHECKERR(QString("Unable to set buffer time %1").arg(buffer_time));
// See if we need to increase the prealloc'd buffer size
// If buffer_time is too small we could underrun
- if (buffer_time < 50000 && pbufsize < 0)
+ if (buffer_time < original_buffer_time && pbufsize < 0)
+ {
+ VBAUDIO(QString("Requested %1us got %2 buffer time")
+ .arg(original_buffer_time).arg(buffer_time));
return buffer_time;
+ }
VBAUDIO(QString("Buffer time = %1 us").arg(buffer_time));