From 091c4ed3a718c22ebcf205abdb3f2e2bad786459 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Mon, 14 Sep 2015 13:26:07 +1000 Subject: Move Windows MMCSS related utility functions into libpbd --- libs/backends/portaudio/mmcss.cc | 180 --------------------- libs/backends/portaudio/mmcss.h | 57 ------- libs/backends/portaudio/portaudio_backend.cc | 2 +- libs/backends/portaudio/winmmemidi_input_device.cc | 3 +- .../backends/portaudio/winmmemidi_output_device.cc | 2 +- libs/backends/portaudio/wscript | 1 - 6 files changed, 3 insertions(+), 242 deletions(-) delete mode 100644 libs/backends/portaudio/mmcss.cc delete mode 100644 libs/backends/portaudio/mmcss.h (limited to 'libs/backends/portaudio') diff --git a/libs/backends/portaudio/mmcss.cc b/libs/backends/portaudio/mmcss.cc deleted file mode 100644 index 406345df34..0000000000 --- a/libs/backends/portaudio/mmcss.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2015 Tim Mayberry - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "mmcss.h" - -#include "pbd/compose.h" - -#include "debug.h" - -typedef HANDLE (WINAPI* AvSetMmThreadCharacteristicsA_t)(LPCSTR TaskName, - LPDWORD TaskIndex); - -typedef BOOL (WINAPI* AvRevertMmThreadCharacteristics_t)(HANDLE AvrtHandle); - -typedef BOOL (WINAPI* AvSetMmThreadPriority_t)( - HANDLE AvrtHandle, PBD::MMCSS::AVRT_PRIORITY Priority); - -static HMODULE avrt_dll = NULL; - -static AvSetMmThreadCharacteristicsA_t AvSetMmThreadCharacteristicsA = NULL; -static AvRevertMmThreadCharacteristics_t AvRevertMmThreadCharacteristics = NULL; -static AvSetMmThreadPriority_t AvSetMmThreadPriority = NULL; - -namespace PBD { - -namespace MMCSS { - -bool -initialize () -{ - if (avrt_dll != NULL) return true; - - avrt_dll = LoadLibraryA ("avrt.dll"); - - if (avrt_dll == NULL) { - DEBUG_THREADS ("Unable to load avrt.dll\n"); - return false; - } - bool unload_dll = false; - - AvSetMmThreadCharacteristicsA = - (AvSetMmThreadCharacteristicsA_t)GetProcAddress ( - avrt_dll, "AvSetMmThreadCharacteristicsA"); - - if (AvSetMmThreadCharacteristicsA == NULL) { - DEBUG_THREADS ("Unable to resolve AvSetMmThreadCharacteristicsA\n"); - unload_dll = true; - } - - AvRevertMmThreadCharacteristics = - (AvRevertMmThreadCharacteristics_t)GetProcAddress ( - avrt_dll, "AvRevertMmThreadCharacteristics"); - - if (AvRevertMmThreadCharacteristics == NULL) { - DEBUG_THREADS ("Unable to resolve AvRevertMmThreadCharacteristics\n"); - unload_dll = true; - } - - AvSetMmThreadPriority = (AvSetMmThreadPriority_t)GetProcAddress ( - avrt_dll, "AvSetMmThreadPriority"); - - if (AvSetMmThreadPriority == NULL) { - DEBUG_THREADS ("Unable to resolve AvSetMmThreadPriority\n"); - unload_dll = true; - } - - if (unload_dll) { - DEBUG_THREADS ( - "MMCSS Unable to resolve necessary symbols, unloading avrt.dll\n"); - deinitialize (); - } - - return true; -} - -bool -deinitialize () -{ - if (avrt_dll == NULL) return true; - - if (FreeLibrary (avrt_dll) == 0) { - DEBUG_THREADS ("Unable to unload avrt.dll\n"); - return false; - } - - avrt_dll = NULL; - - AvSetMmThreadCharacteristicsA = NULL; - AvRevertMmThreadCharacteristics = NULL; - AvSetMmThreadPriority = NULL; - - return true; -} - -bool -set_thread_characteristics (const std::string& task_name, HANDLE* task_handle) -{ - if (AvSetMmThreadCharacteristicsA == NULL) return false; - - DWORD task_index_dummy = 0; - - *task_handle = AvSetMmThreadCharacteristicsA(task_name.c_str(), &task_index_dummy); - - if (*task_handle == 0) { - DEBUG_THREADS (string_compose ("Failed to set Thread Characteristics to %1\n", - task_name)); - DWORD error = GetLastError(); - - switch (error) { - case ERROR_INVALID_TASK_INDEX: - DEBUG_THREADS("MMCSS: Invalid Task Index\n"); - break; - case ERROR_INVALID_TASK_NAME: - DEBUG_THREADS("MMCSS: Invalid Task Name\n"); - break; - case ERROR_PRIVILEGE_NOT_HELD: - DEBUG_THREADS("MMCSS: Privilege not held\n"); - break; - default: - DEBUG_THREADS("MMCSS: Unknown error setting thread characteristics\n"); - break; - } - return false; - } - - DEBUG_THREADS ( - string_compose ("Set thread characteristics to %1\n", task_name)); - - return true; -} - -bool -revert_thread_characteristics (HANDLE task_handle) -{ - if (AvRevertMmThreadCharacteristics == NULL) return false; - - if (AvRevertMmThreadCharacteristics (task_handle) == 0) { - DEBUG_THREADS ("Failed to set revert thread characteristics\n"); - return false; - } - - DEBUG_THREADS ("Reverted thread characteristics\n"); - - return true; -} - -bool -set_thread_priority (HANDLE task_handle, AVRT_PRIORITY priority) -{ - if (AvSetMmThreadPriority == NULL) return false; - - if (AvSetMmThreadPriority (task_handle, priority) == 0) { - DEBUG_THREADS ( - string_compose ("Failed to set thread priority %1\n", priority)); - return false; - } - - DEBUG_THREADS (string_compose ("Set thread priority to %1\n", priority)); - - return true; -} - -} // namespace MMCSS - -} // namespace PBD diff --git a/libs/backends/portaudio/mmcss.h b/libs/backends/portaudio/mmcss.h deleted file mode 100644 index 28dc737c4d..0000000000 --- a/libs/backends/portaudio/mmcss.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2015 Tim Mayberry - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef PBD_WINDOWS_MMCSS_H -#define PBD_WINDOWS_MMCSS_H - -#include - -#include - -namespace PBD { - -namespace MMCSS { - -enum AVRT_PRIORITY { - AVRT_PRIORITY_VERYLOW = -2, - AVRT_PRIORITY_LOW, - AVRT_PRIORITY_NORMAL, - AVRT_PRIORITY_HIGH, - AVRT_PRIORITY_CRITICAL -}; - -enum error_codes { - ERROR_INVALID_TASK_NAME = 1550, - ERROR_INVALID_TASK_INDEX = 1551 -}; - -bool initialize (); - -bool deinitialize (); - -bool set_thread_characteristics (const std::string& task_name, HANDLE *task_handle); - -bool revert_thread_characteristics (HANDLE task_handle); - -bool set_thread_priority (HANDLE, AVRT_PRIORITY); - -} // namespace MMCSS - -} // namespace PBD - -#endif // PBD_WINDOWS_MMCSS_H diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc index 973180f37f..f55d9c3131 100644 --- a/libs/backends/portaudio/portaudio_backend.cc +++ b/libs/backends/portaudio/portaudio_backend.cc @@ -33,12 +33,12 @@ #include "pbd/error.h" #include "pbd/file_utils.h" #include "pbd/windows_timer_utils.h" +#include "pbd/windows_mmcss.h" #include "ardour/filesystem_paths.h" #include "ardour/port_manager.h" #include "i18n.h" -#include "mmcss.h" #include "audio_utils.h" #include "debug.h" diff --git a/libs/backends/portaudio/winmmemidi_input_device.cc b/libs/backends/portaudio/winmmemidi_input_device.cc index 324306db12..ed9625d28b 100644 --- a/libs/backends/portaudio/winmmemidi_input_device.cc +++ b/libs/backends/portaudio/winmmemidi_input_device.cc @@ -23,11 +23,10 @@ #include "pbd/compose.h" #include "pbd/windows_timer_utils.h" +#include "pbd/windows_mmcss.h" #include "midi_util.h" -#include "mmcss.h" - #include "debug.h" static const uint32_t MIDI_BUFFER_SIZE = 32768; diff --git a/libs/backends/portaudio/winmmemidi_output_device.cc b/libs/backends/portaudio/winmmemidi_output_device.cc index 89f76f29d0..9c9b513443 100644 --- a/libs/backends/portaudio/winmmemidi_output_device.cc +++ b/libs/backends/portaudio/winmmemidi_output_device.cc @@ -23,11 +23,11 @@ #include "pbd/debug.h" #include "pbd/compose.h" #include "pbd/windows_timer_utils.h" +#include "pbd/windows_mmcss.h" #include "rt_thread.h" #include "midi_util.h" -#include "mmcss.h" #include "debug.h" // remove dup with input_device diff --git a/libs/backends/portaudio/wscript b/libs/backends/portaudio/wscript index c67490f1c7..0d679a1563 100644 --- a/libs/backends/portaudio/wscript +++ b/libs/backends/portaudio/wscript @@ -27,7 +27,6 @@ def build(bld): 'winmmemidi_input_device.cc', 'winmmemidi_output_device.cc', 'midi_util.cc', - 'mmcss.cc' ] obj.includes = ['.'] obj.name = 'portaudio_backend' -- cgit v1.2.3