1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 08:29:27 +02:00

Allow capture retries if time since Rescan() < 10s

The time since Rescan() of recording device is the important factor,
not the "newness" of the project.
This commit is contained in:
Steve Daulton 2018-08-12 23:47:48 +01:00
parent aeba34b152
commit 11da92d668
3 changed files with 21 additions and 3 deletions

View File

@ -408,7 +408,7 @@ TimeTrack and AudioIOListener and whether the playback is looped.
#include "Experimental.h"
#include "AudioIO.h"
#include "float_cast.h"
#include "UndoManager.h"
#include "DeviceManager.h"
#include <cfloat>
#include <math.h>
@ -1780,11 +1780,12 @@ bool AudioIO::StartPortAudioStream(double sampleRate,
int userData = 24;
int* lpUserData = (captureFormat_saved == int24Sample) ? &userData : NULL;
// (Linux, bug 1885) On first use, the device may not be ready in time, so allow retries.
// (Linux, bug 1885) After scanning devices it takes a little time for the
// ALSA device to be available, so allow retries.
// On my test machine, no more than 3 attempts are required.
unsigned int maxTries = 1;
#ifdef __WXGTK__
if (!mOwningProject->GetUndoManager()->UnsavedChanges())
if (DeviceManager::Instance()->GetTimeSinceRescan() < 10)
maxTries = 5;
#endif

View File

@ -306,8 +306,17 @@ void DeviceManager::Rescan()
}
}
m_inited = true;
mRescanTime = std::chrono::steady_clock::now();
}
float DeviceManager::GetTimeSinceRescan() {
auto now = std::chrono::steady_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::duration<float>>(now - mRescanTime);
return dur.count();
}
//private constructor - Singleton.
DeviceManager::DeviceManager()
#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
@ -317,6 +326,7 @@ DeviceManager::DeviceManager()
#endif
{
m_inited = false;
mRescanTime = std::chrono::steady_clock::now();
}
DeviceManager::~DeviceManager()

View File

@ -20,6 +20,7 @@
#include "Experimental.h"
#include <chrono>
#include <vector>
#include "wx/wx.h"
@ -55,6 +56,9 @@ class DeviceManager final
/// Assumes that DeviceManager is only used on the main thread.
void Rescan();
// Time since devices scanned in seconds.
float GetTimeSinceRescan();
DeviceSourceMap* GetDefaultOutputDevice(int hostIndex);
DeviceSourceMap* GetDefaultInputDevice(int hostIndex);
@ -68,6 +72,9 @@ class DeviceManager final
#endif
#endif
private:
std::chrono::time_point<std::chrono::steady_clock> mRescanTime;
protected:
//private constructor - Singleton.
DeviceManager();