From 2226b468bbb40c6fe0dad7a6787bc0a6295c43f1 Mon Sep 17 00:00:00 2001 From: Rainer Hochecker Date: Mon, 11 Dec 2017 18:52:00 +0100 Subject: [PATCH] AE: drop null sink --- xbmc/cores/AudioEngine/CMakeLists.txt | 4 +- .../Engines/ActiveAE/ActiveAESink.cpp | 10 -- xbmc/cores/AudioEngine/Sinks/AESinkNULL.cpp | 161 ------------------ xbmc/cores/AudioEngine/Sinks/AESinkNULL.h | 54 ------ 4 files changed, 1 insertion(+), 228 deletions(-) delete mode 100644 xbmc/cores/AudioEngine/Sinks/AESinkNULL.cpp delete mode 100644 xbmc/cores/AudioEngine/Sinks/AESinkNULL.h diff --git a/xbmc/cores/AudioEngine/CMakeLists.txt b/xbmc/cores/AudioEngine/CMakeLists.txt index 372f16f1ab19f..3c08bbc8a2193 100644 --- a/xbmc/cores/AudioEngine/CMakeLists.txt +++ b/xbmc/cores/AudioEngine/CMakeLists.txt @@ -20,8 +20,7 @@ set(SOURCES AEResampleFactory.cpp Utils/AELimiter.cpp Utils/AEPackIEC61937.cpp Utils/AEStreamInfo.cpp - Utils/AEUtil.cpp - Sinks/AESinkNULL.cpp) + Utils/AEUtil.cpp) set(HEADERS AEResampleFactory.h AESinkFactory.h @@ -47,7 +46,6 @@ set(HEADERS AEResampleFactory.h Interfaces/AEStream.h Interfaces/IAudioCallback.h Interfaces/ThreadedAE.h - Sinks/AESinkNULL.h Utils/AEAudioFormat.h Utils/AEBitstreamPacker.h Utils/AEChannelData.h diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp index 3dba8c3c997a4..b0bb32a5d2adf 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp @@ -836,16 +836,6 @@ void CActiveAESink::OpenSink() m_sink = CAESinkFactory::Create(device, m_sinkFormat); } - // open NULL sink - //! @todo should not be required by ActiveAE - if (!m_sink) - { - device = "NULL:NULL"; - m_sinkFormat = m_requestedFormat; - CLog::Log(LOGDEBUG, "CActiveAESink::OpenSink - open NULL sink"); - m_sink = CAESinkFactory::Create(device, m_sinkFormat); - } - if (!m_sink) { CLog::Log(LOGERROR, "CActiveAESink::OpenSink - no sink was returned"); diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkNULL.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkNULL.cpp deleted file mode 100644 index 05327dcaf7ffc..0000000000000 --- a/xbmc/cores/AudioEngine/Sinks/AESinkNULL.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2010-2013 Team XBMC - * http://xbmc.org - * - * 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, 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 XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "system.h" - -#include -#include - -#include "AESinkNULL.h" -#include "cores/AudioEngine/Utils/AEUtil.h" -#include "utils/log.h" - -CAESinkNULL::CAESinkNULL() - : CThread("AESinkNull"), - m_draining(false), - m_sink_frameSize(0), - m_sinkbuffer_size(0), - m_sinkbuffer_level(0), - m_sinkbuffer_sec_per_byte(0) -{ -} - -CAESinkNULL::~CAESinkNULL() = default; - -bool CAESinkNULL::Initialize(AEAudioFormat &format, std::string &device) -{ - // setup for a 250ms sink feed from SoftAE - format.m_dataFormat = (format.m_dataFormat == AE_FMT_RAW) ? AE_FMT_S16NE : AE_FMT_FLOAT; - format.m_frames = format.m_sampleRate / 1000 * 250; - format.m_frameSize = format.m_channelLayout.Count() * (CAEUtil::DataFormatToBits(format.m_dataFormat) >> 3); - m_format = format; - - // setup a pretend 500ms internal buffer - m_sink_frameSize = format.m_channelLayout.Count() * CAEUtil::DataFormatToBits(format.m_dataFormat) >> 3; - m_sinkbuffer_size = m_sink_frameSize * format.m_sampleRate / 2; - m_sinkbuffer_sec_per_byte = 1.0 / (double)(m_sink_frameSize * format.m_sampleRate); - - m_draining = false; - m_wake.Reset(); - m_inited.Reset(); - Create(); - if (!m_inited.WaitMSec(100)) - { - while(!m_inited.WaitMSec(1)) - Sleep(10); - } - - return true; -} - -void CAESinkNULL::Deinitialize() -{ - // force m_bStop and set m_wake, if might be sleeping. - m_bStop = true; - StopThread(); -} - -void CAESinkNULL::GetDelay(AEDelayStatus& status) -{ - double sinkbuffer_seconds_to_empty = m_sinkbuffer_sec_per_byte * (double)m_sinkbuffer_level; - status.SetDelay(sinkbuffer_seconds_to_empty); -} - -double CAESinkNULL::GetCacheTotal() -{ - return m_sinkbuffer_sec_per_byte * (double)m_sinkbuffer_size; -} - -unsigned int CAESinkNULL::AddPackets(uint8_t **data, unsigned int frames, unsigned int offset) -{ - unsigned int max_frames = (m_sinkbuffer_size - m_sinkbuffer_level) / m_sink_frameSize; - if (frames > max_frames) - frames = max_frames; - - if (frames) - { - m_sinkbuffer_level += frames * m_sink_frameSize; - m_wake.Set(); - } - - return frames; -} - -void CAESinkNULL::Drain() -{ - m_draining = true; - m_wake.Set(); -} - -void CAESinkNULL::EnumerateDevices (AEDeviceList &devices, bool passthrough) -{ - // we never return any devices -} - -void CAESinkNULL::Process() -{ - CLog::Log(LOGDEBUG, "CAESinkNULL::Process"); - - // The object has been created and waiting to play, - m_inited.Set(); - // yield to give other threads a chance to do some work. - Sleep(0); - - SetPriority(THREAD_PRIORITY_ABOVE_NORMAL); - while (!m_bStop) - { - if (m_draining) - { - //! @todo is it correct to not take data at the appropriate rate while draining? - m_sinkbuffer_level = 0; - m_draining = false; - } - - // pretend we have a 64k audio buffer - unsigned int min_buffer_size = 64 * 1024; - unsigned int read_bytes = m_sinkbuffer_level; - if (read_bytes > min_buffer_size) - read_bytes = min_buffer_size; - - if (read_bytes > 0) - { - // drain it - m_sinkbuffer_level -= read_bytes; - - // we MUST drain at the correct audio sample rate - // or the NULL sink will not work right. So calc - // an approximate sleep time. - int frames_written = read_bytes / m_sink_frameSize; - double empty_ms = 1000.0 * (double)frames_written / m_format.m_sampleRate; - #if defined(TARGET_POSIX) - usleep(empty_ms * 1000.0); - #else - Sleep((int)empty_ms); - #endif - } - - if (m_sinkbuffer_level == 0) - { - // sleep this audio thread, we will get woken when we have audio data. - m_wake.WaitMSec(250); - } - } - SetPriority(THREAD_PRIORITY_NORMAL); -} diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkNULL.h b/xbmc/cores/AudioEngine/Sinks/AESinkNULL.h deleted file mode 100644 index 04a1ce812041a..0000000000000 --- a/xbmc/cores/AudioEngine/Sinks/AESinkNULL.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once -/* - * Copyright (C) 2010-2013 Team XBMC - * http://xbmc.org - * - * 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, 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 XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "system.h" -#include "threads/Thread.h" -#include "cores/AudioEngine/Interfaces/AESink.h" - -class CAESinkNULL : public CThread, public IAESink -{ -public: - const char *GetName() override { return "NULL"; } - - CAESinkNULL(); - ~CAESinkNULL() override; - - bool Initialize(AEAudioFormat &format, std::string &device) override; - void Deinitialize() override; - - void GetDelay(AEDelayStatus& status) override; - double GetCacheTotal() override; - unsigned int AddPackets(uint8_t **data, unsigned int frames, unsigned int offset) override; - void Drain() override; - - static void EnumerateDevices(AEDeviceList &devices, bool passthrough); -private: - void Process() override; - - CEvent m_wake; - CEvent m_inited; - volatile bool m_draining; - AEAudioFormat m_format; - unsigned int m_sink_frameSize; - unsigned int m_sinkbuffer_size; ///< total size of the buffer - unsigned int m_sinkbuffer_level; ///< current level in the buffer - double m_sinkbuffer_sec_per_byte; -};