Files
libopenshot/tests/AudioDeviceManager.cpp

59 lines
2.3 KiB
C++
Raw Permalink Normal View History

Refactoring Audio Device detection (don't crash on Windows, find actual sample rate and device details) (#883) * Close down ZMQ context to stop the zmq threads (related to sentry bug: OPENSHOT-3X) * Add Support for Windows 7/8.1 (#881) Adding protection around getting current sample rate for win 7, if audio device not found. Also added mutex for Singleton method. Also, making whitespace consistent on AudioPlaybackThread.cpp * Big refactor of audio device opening - with multiple sample rates attempted, for better recovery from a missing or unsupported sample rate. Debug logs added for testing. * Additional failure logging for windows audio device init * Refactor of Audio Device Initialization (#882) * Huge refactor of audio device initialization: - Attempt requested audio device first, and then iterate through all known audio types and devices, and common sample rates. The idea is to ignore an invalid default or invalid requested device, and keep looking until we find a valid one - New public method to return active, open audio device - Added methods for AudioDeviceInfo struct, to make it callable from Python - Some code clean-up and whitespace fixes - New unit tests for AudioDeviceManagerSingleton * Ignore audio device unit tests on systems with "No Driver" returned in the audio error message * Ignore audio device unit tests if any error is found during initialization (i.e. build servers don't have audio cards) * Trying to update GitHub libomp errors during build checks * Remove zmq context shutdown call, due to the method missing on newer versions of zmq.hpp * Downgrading GitHub Ubuntu latest image to Ubuntu 20.04, for compatibility with Catchv2 * Initialize all audio device manager variables correctly, and ignore unit test on low or missing sample rate systems (i.e. GitHub build servers)
2022-12-19 13:15:43 -06:00
/**
* @file
* @brief Unit tests for openshot::AudioDeviceManagerSingleton
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
// Copyright (c) 2008-2022 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "openshot_catch.h"
#include "Settings.h"
#include "Qt/AudioPlaybackThread.h"
using namespace openshot;
TEST_CASE( "Initialize Audio Device Manager Singleton", "[libopenshot][AudioDeviceManagerSingleton]" )
{
Settings::Instance()->PLAYBACK_AUDIO_DEVICE_TYPE = "";
Settings::Instance()->PLAYBACK_AUDIO_DEVICE_NAME = "";
// Invalid sample rate
AudioDeviceManagerSingleton *mng = AudioDeviceManagerSingleton::Instance(12300, 2);
double detected_sample_rate = mng->defaultSampleRate;
// Ignore systems that fail to find a valid audio device (i.e. build servers w/no sound card)
if (mng->initialise_error.empty() && detected_sample_rate >= 44100.0) {
// Verify invalid sample rate not found
CHECK(detected_sample_rate != 12300); // verify common rate is returned
mng->CloseAudioDevice();
// Valid sample rate
mng = AudioDeviceManagerSingleton::Instance(44100, 2);
CHECK(mng->defaultSampleRate == 44100);
mng->CloseAudioDevice();
// Valid device type (for Linux)
Settings::Instance()->PLAYBACK_AUDIO_DEVICE_TYPE = "ALSA";
Settings::Instance()->PLAYBACK_AUDIO_DEVICE_NAME = "Playback/recording through the PulseAudio sound server";
mng = AudioDeviceManagerSingleton::Instance(44100, 2);
if (mng->currentAudioDevice.get_name() == Settings::Instance()->PLAYBACK_AUDIO_DEVICE_NAME &&
mng->currentAudioDevice.get_type() == Settings::Instance()->PLAYBACK_AUDIO_DEVICE_TYPE) {
// Only check this device if it exists (i.e. we are on Linux with ALSA and PulseAudio)
CHECK(mng->defaultSampleRate == 44100);
mng->CloseAudioDevice();
}
// Invalid device type (for Linux)
Settings::Instance()->PLAYBACK_AUDIO_DEVICE_TYPE = "Fake Type";
Settings::Instance()->PLAYBACK_AUDIO_DEVICE_NAME = "Fake Device";
mng = AudioDeviceManagerSingleton::Instance(44100, 2);
CHECK(mng->defaultSampleRate == 44100);
mng->CloseAudioDevice();
}
}