diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/cores/AudioEngine/Interfaces | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/cores/AudioEngine/Interfaces')
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/AE.h | 323 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/AEEncoder.h | 95 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/AEResample.h | 34 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/AESink.h | 85 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/AESound.h | 44 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/AEStream.h | 272 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/IAudioCallback.h | 23 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/ThreadedAE.h | 20 |
8 files changed, 896 insertions, 0 deletions
diff --git a/xbmc/cores/AudioEngine/Interfaces/AE.h b/xbmc/cores/AudioEngine/Interfaces/AE.h new file mode 100644 index 0000000..a8562ea --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/AE.h @@ -0,0 +1,323 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "cores/AudioEngine/Utils/AEAudioFormat.h" + +#include <cassert> +#include <list> +#include <map> +#include <memory> +#include <utility> +#include <vector> + +extern "C" { +#include <libavutil/samplefmt.h> +} + +typedef std::pair<std::string, std::string> AEDevice; +typedef std::vector<AEDevice> AEDeviceList; + +/* forward declarations */ +class IAEStream; +class IAEStreamDeleter; +class IAESound; +class IAESoundDeleter; +class IAEPacketizer; +class IAudioCallback; +class IAEClockCallback; +class CAEStreamInfo; + +namespace ADDON +{ +struct Interface_AudioEngine; +} + +/* sound options */ +#define AE_SOUND_OFF 0 /*! disable sounds */ +#define AE_SOUND_IDLE 1 /*! only play sounds while no streams are running */ +#define AE_SOUND_ALWAYS 2 /*! always play sounds */ + +/* config options */ +#define AE_CONFIG_FIXED 1 +#define AE_CONFIG_AUTO 2 +#define AE_CONFIG_MATCH 3 + +enum AEQuality +{ + AE_QUALITY_UNKNOWN = -1, /*! Unset, unknown or incorrect quality level */ + AE_QUALITY_DEFAULT = 0, /*! Engine's default quality level */ + + /* Basic quality levels */ + AE_QUALITY_LOW = 20, /*! Low quality level */ + AE_QUALITY_MID = 30, /*! Standard quality level */ + AE_QUALITY_HIGH = 50, /*! Best sound processing quality */ + + /* Optional quality levels */ + AE_QUALITY_REALLYHIGH = 100, /*! Uncompromised optional quality level, + usually with unmeasurable and unnoticeable improvement */ + AE_QUALITY_GPU = 101, /*! GPU acceleration */ +}; + +struct SampleConfig +{ + AVSampleFormat fmt; + uint64_t channel_layout; + int channels; + int sample_rate; + int bits_per_sample; + int dither_bits; +}; + +/*! + * \brief IAE Interface + */ +class IAE +{ +protected: + + IAE() = default; + virtual ~IAE() = default; + + /*! + * \brief Initializes the AudioEngine, called by CFactory when it is time to initialize the audio engine. + * + * Do not call this directly, CApplication will call this when it is ready + */ + virtual void Start() = 0; +public: + using StreamPtr = std::unique_ptr<IAEStream, IAEStreamDeleter>; + using SoundPtr = std::unique_ptr<IAESound, IAESoundDeleter>; + + /*! + * \brief Called when the application needs to terminate the engine + */ + virtual void Shutdown() { } + + /*! + * \brief Suspends output and de-initializes sink + * + * Used to avoid conflicts with external players or to reduce power consumption + * + * \return True if successful + */ + virtual bool Suspend() = 0; + + /*! + * \brief Resumes output and re-initializes sink + * + * Used to resume output from Suspend() state above + * + * \return True if successful + */ + virtual bool Resume() = 0; + + /*! + * \brief Get the current Suspend() state + * + * Used by players to determine if audio is being processed + * Default is true so players drop audio or pause if engine unloaded + * + * \return True if processing suspended + */ + virtual bool IsSuspended() {return true;} + + /*! + * \brief Returns the current master volume level of the AudioEngine + * + * \return The volume level between 0.0 and 1.0 + */ + virtual float GetVolume() = 0; + + /*! + * \brief Sets the master volume level of the AudioEngine + * + * \param volume The new volume level between 0.0 and 1.0 + */ + virtual void SetVolume(const float volume) = 0; + + /*! + * \brief Set the mute state (does not affect volume level value) + * + * \param enabled The mute state + */ + virtual void SetMute(const bool enabled) = 0; + + /*! + * \brief Get the current mute state + * + * \return The current mute state + */ + virtual bool IsMuted() = 0; + + /*! + * \brief Creates and returns a new IAEStream in the format specified, this function should never fail + * + * The cleanup behaviour can be modified with the IAEStreamDeleter::setFinish method. + * Per default the behaviour is the same as calling FreeStream with true. + * + * \param audioFormat + * \param options A bit field of stream options (see: enum AEStreamOptions) + * \return a new IAEStream that will accept data in the requested format + */ + virtual StreamPtr MakeStream(AEAudioFormat& audioFormat, + unsigned int options = 0, + IAEClockCallback* clock = NULL) = 0; + + /*! + * \brief Creates a new IAESound that is ready to play the specified file + * + * \param file The WAV file to load, this supports XBMC's VFS + * \return A new IAESound if the file could be loaded, otherwise NULL + */ + virtual SoundPtr MakeSound(const std::string& file) = 0; + + /*! + * \brief Enumerate the supported audio output devices + * + * \param devices The device list to append supported devices to + * \param passthrough True if only passthrough devices are wanted + */ + virtual void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough) = 0; + + /*! + * \brief Returns true if the AudioEngine supports AE_FMT_RAW streams for use with formats such as IEC61937 + * + * \see CAEPackIEC61937::CAEPackIEC61937() + * + * \returns true if the AudioEngine is capable of RAW output + */ + virtual bool SupportsRaw(AEAudioFormat &format) { return false; } + + /*! + * \brief Returns true if the AudioEngine supports drain mode which is not streaming silence when idle + * + * \returns true if the AudioEngine is capable of drain mode + */ + virtual bool SupportsSilenceTimeout() { return false; } + + /*! + * \brief Returns true if the AudioEngine is currently configured to extract the DTS Core from DTS-HD streams + * + * \returns true if the AudioEngine is currently configured to extract the DTS Core from DTS-HD streams + */ + virtual bool UsesDtsCoreFallback() { return false; } + + /*! + * \brief Returns true if the AudioEngine is currently configured for stereo audio + * + * \returns true if the AudioEngine is currently configured for stereo audio + */ + virtual bool HasStereoAudioChannelCount() { return false; } + + /*! + * \brief Returns true if the AudioEngine is currently configured for HD audio (more than 5.1) + * + * \returns true if the AudioEngine is currently configured for HD audio (more than 5.1) + */ + virtual bool HasHDAudioChannelCount() { return true; } + + virtual void RegisterAudioCallback(IAudioCallback* pCallback) {} + + virtual void UnregisterAudioCallback(IAudioCallback* pCallback) {} + + /*! + * \brief Returns true if AudioEngine supports specified quality level + * + * \return true if specified quality level is supported, otherwise false + */ + virtual bool SupportsQualityLevel(enum AEQuality level) { return false; } + + /*! + * \brief AE decides whether this settings should be displayed + * + * \return true if AudioEngine wants to display this setting + */ + virtual bool IsSettingVisible(const std::string &settingId) {return false; } + + /*! + * \brief Instruct AE to keep configuration for a specified time + * + * \param millis time for which old configuration should be kept + */ + virtual void KeepConfiguration(unsigned int millis) {} + + /*! + * \brief Instruct AE to re-initialize, e.g. after ELD change event + */ + virtual void DeviceChange() {} + + /*! + * \brief Instruct AE to re-initialize, e.g. after ELD change event + */ + virtual void DeviceCountChange(const std::string& driver) {} + + /*! + * \brief Get the current sink data format + * + * \param Current sink data format. For more details see AEAudioFormat. + * \return Returns true on success, else false. + */ + virtual bool GetCurrentSinkFormat(AEAudioFormat &SinkFormat) { return false; } + +private: + friend class IAEStreamDeleter; + friend class IAESoundDeleter; + friend struct ADDON::Interface_AudioEngine; + + /*! + * \brief This method will remove the specified stream from the engine. + * + * For OSX/IOS this is essential to reconfigure the audio output. + * + * \param stream The stream to be altered + * \param finish if true AE will switch back to gui sound mode (if this is last stream) + * \return true on success, else false. + */ + virtual bool FreeStream(IAEStream* stream, bool finish) = 0; + + /*! + * \brief Free the supplied IAESound object + * + * \param sound The IAESound object to free + */ + virtual void FreeSound(IAESound* sound) = 0; +}; + +class IAEStreamDeleter +{ +private: + IAE* m_iae; + bool m_finish; + +public: + IAEStreamDeleter() : m_iae(nullptr), m_finish(true) {} + explicit IAEStreamDeleter(IAE& iae) : m_iae(&iae), m_finish{true} {} + void setFinish(bool finish) { m_finish = finish; } + void operator()(IAEStream* stream) + { + assert(m_iae); + m_iae->FreeStream(stream, m_finish); + } +}; + +class IAESoundDeleter +{ +private: + IAE* m_iae; + +public: + IAESoundDeleter() : m_iae(nullptr) {} + explicit IAESoundDeleter(IAE& iae) : m_iae(&iae) {} + void operator()(IAESound* sound) + { + assert(m_iae); + m_iae->FreeSound(sound); + } +}; diff --git a/xbmc/cores/AudioEngine/Interfaces/AEEncoder.h b/xbmc/cores/AudioEngine/Interfaces/AEEncoder.h new file mode 100644 index 0000000..5c207be --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/AEEncoder.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "cores/AudioEngine/Utils/AEAudioFormat.h" + +extern "C" { +#include <libavcodec/avcodec.h> +} + +/** + * IAEEncoder interface for on the fly audio compression + */ +class IAEEncoder +{ +public: + /** + * Constructor + */ + IAEEncoder() = default; + + /** + * Destructor + */ + virtual ~IAEEncoder() = default; + + /** + * Return true if the supplied format is compatible with the current open encoder. + * @param format the format to compare + * @return true if compatible, false if not + */ + virtual bool IsCompatible(const AEAudioFormat& format) = 0; + + /** + * Called to setup the encoder to accept data in the specified format + * @param format the desired audio format, may be changed to suit the encoder + * @param allow_planar_input allow engine to use with planar formats + * @return true on success, false on failure + */ + virtual bool Initialize(AEAudioFormat &format, bool allow_planar_input = false) = 0; + + /** + * Reset the encoder for new data + */ + virtual void Reset() = 0; + + /** + * Returns the bitrate of the encoder + * @return bit rate in bits per second + */ + virtual unsigned int GetBitRate() = 0; + + /** + * Returns the AVCodecID of the encoder + * @return the ffmpeg codec id + */ + virtual AVCodecID GetCodecID() = 0; + + /** + * Return the number of frames needed to encode + * @return number of frames (frames * channels = samples * bits per sample = bytes) + */ + virtual unsigned int GetFrames() = 0; + + /** + * Encodes the supplied samples into a provided buffer + * @param in the PCM samples encoder requested format + * @param in_size input buffer size + * @param output buffer + * @param out_size output buffer size + * @return size of encoded data + */ + virtual int Encode (uint8_t *in, int in_size, uint8_t *out, int out_size) = 0; + + /** + * Get the encoded data + * @param data return pointer to the buffer with the current encoded block + * @return the size in bytes of *data + */ + virtual int GetData(uint8_t **data) = 0; + + /** + * Get the delay in seconds + * @param bufferSize how much encoded data the caller has buffered to add to the delay + * @return the delay in seconds including any un-fetched encoded data + */ + virtual double GetDelay(unsigned int bufferSize) = 0; +}; + diff --git a/xbmc/cores/AudioEngine/Interfaces/AEResample.h b/xbmc/cores/AudioEngine/Interfaces/AEResample.h new file mode 100644 index 0000000..8b27b32 --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/AEResample.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "cores/AudioEngine/Interfaces/AE.h" + +namespace ActiveAE +{ + +class IAEResample +{ +public: + // return the name of this sync for logging + virtual const char *GetName() = 0; + IAEResample() = default; + virtual ~IAEResample() = default; + virtual bool Init(SampleConfig dstConfig, SampleConfig srcConfig, bool upmix, bool normalize, double centerMix, + CAEChannelInfo *remapLayout, AEQuality quality, bool force_resample) = 0; + virtual int Resample(uint8_t **dst_buffer, int dst_samples, uint8_t **src_buffer, int src_samples, double ratio) = 0; + virtual int64_t GetDelay(int64_t base) = 0; + virtual int GetBufferedSamples() = 0; + virtual bool WantsNewSamples(int samples) = 0; + virtual int CalcDstSampleCount(int src_samples, int dst_rate, int src_rate) = 0; + virtual int GetSrcBufferSize(int samples) = 0; + virtual int GetDstBufferSize(int samples) = 0; +}; + +} diff --git a/xbmc/cores/AudioEngine/Interfaces/AESink.h b/xbmc/cores/AudioEngine/Interfaces/AESink.h new file mode 100644 index 0000000..5637c69 --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/AESink.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "cores/AudioEngine/Interfaces/AE.h" // for typedef's used in derived classes +#include "cores/AudioEngine/Utils/AEAudioFormat.h" +#include "cores/AudioEngine/Utils/AEUtil.h" + +#include <stdint.h> +#include <string> + +class IAESink +{ +public: + /* return the name of this sync for logging */ + virtual const char *GetName() = 0; + + IAESink() = default; + virtual ~IAESink() = default; + + /* + The sink does NOT have to honour anything in the format struct or the device + if however it does not honour what is requested, it MUST update device/format + with what it does support. + */ + virtual bool Initialize (AEAudioFormat &format, std::string &device) = 0; + + /* + Deinitialize the sink for destruction + */ + virtual void Deinitialize() = 0; + + /* + This method returns the total time in seconds of the cache. + */ + virtual double GetCacheTotal() = 0; + + /* + This method returns latency of hardware. + */ + virtual double GetLatency() { return 0.0; } + + /*! + * @brief Adds packets to be sent out, this routine MUST block or sleep. + * @param data array of pointers to planes holding audio data + * @param frames number of audio frames in data + * @param offset offset in frames where audio data starts + * @return number of frames consumed by the sink + */ + virtual unsigned int AddPackets(uint8_t **data, unsigned int frames, unsigned int offset) = 0; + + /*! + * @brief instruct the sink to add a pause + * @param millis ms to pause + */ + virtual void AddPause(unsigned int millis) {} + + /*! + * @brief Return a timestamped status structure with delay and sink info + * @param status structure filled with sink status + */ + virtual void GetDelay(AEDelayStatus& status) = 0; + + /* + Drain the sink + */ + virtual void Drain() {} + + /* + Indicates if sink can handle volume control. + */ + virtual bool HasVolume() { return false; } + + /* + This method sets the volume control, volume ranges from 0.0 to 1.0. + */ + virtual void SetVolume(float volume) {} +}; + diff --git a/xbmc/cores/AudioEngine/Interfaces/AESound.h b/xbmc/cores/AudioEngine/Interfaces/AESound.h new file mode 100644 index 0000000..6066fa1 --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/AESound.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "cores/AudioEngine/Utils/AEAudioFormat.h" + +#include <string> + +class IAESound +{ +protected: + friend class IAE; + explicit IAESound(const std::string &filename) {} + virtual ~IAESound() = default; + +public: + /* play the sound this object represents */ + virtual void Play() = 0; + + /* stop playing the sound this object represents */ + virtual void Stop() = 0; + + /* return true if the sound is currently playing */ + virtual bool IsPlaying() = 0; + + /* set the playback channel of this sound, AE_CH_NULL for all */ + virtual void SetChannel(AEChannel channel) = 0; + + /* get the current playback channel of this sound, AE_CH_NULL for all */ + virtual AEChannel GetChannel() = 0; + + /* set the playback volume of this sound */ + virtual void SetVolume(float volume) = 0; + + /* get the current playback volume of this sound */ + virtual float GetVolume() = 0; +}; + diff --git a/xbmc/cores/AudioEngine/Interfaces/AEStream.h b/xbmc/cores/AudioEngine/Interfaces/AEStream.h new file mode 100644 index 0000000..c0f20f6 --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/AEStream.h @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "cores/AudioEngine/Utils/AEAudioFormat.h" +#include <stdint.h> + +extern "C" { +#include <libavcodec/avcodec.h> +} + +class IAudioCallback; + +/** + * Callback interface for VideoPlayer clock needed by AE for sync + */ +class IAEClockCallback +{ +public: + virtual ~IAEClockCallback() = default; + virtual double GetClock() = 0; + virtual double GetClockSpeed() { return 1.0; } +}; + +class CAESyncInfo +{ +public: + double delay; + double error; + double rr; + unsigned int errortime; + enum AESyncState + { + SYNC_OFF, + SYNC_INSYNC, + SYNC_START, + SYNC_MUTE, + SYNC_ADJUST + }; + AESyncState state; +}; + +/** + * IAEStream Stream Interface for streaming audio + */ +class IAEStream +{ +protected: + friend class IAE; + IAEStream() = default; + virtual ~IAEStream() = default; + +public: + struct ExtData + { + double pts = 0; + bool hasDownmix = false; + double centerMixLevel = 1; + }; + +public: + /** + * Returns the amount of space available in the stream + * @return The number of bytes AddData will consume + */ + virtual unsigned int GetSpace() = 0; + + /** + * Add planar or interleaved PCM data to the stream + * @param data array of pointers to the planes + * @param offset to frame in frames + * @param frames number of frames + * @param pts timestamp + * @return The number of frames consumed + */ + virtual unsigned int AddData(const uint8_t* const *data, unsigned int offset, unsigned int frames, ExtData *extData) = 0; + + /** + * Returns the time in seconds that it will take + * for the next added packet to be heard from the speakers. + * @return seconds + */ + virtual double GetDelay() = 0; + + /** + * Returns info about audio to clock synchronization + * @return CAESyncInfo + */ + virtual CAESyncInfo GetSyncInfo() = 0; + + /** + * Returns if the stream is buffering + * @return True if the stream is buffering + */ + virtual bool IsBuffering() = 0; + + /** + * Returns the time in seconds of the stream's + * cached audio samples. Engine buffers excluded. + * @return seconds + */ + virtual double GetCacheTime() = 0; + + /** + * Returns the total time in seconds of the cache + * @return seconds + */ + virtual double GetCacheTotal() = 0; + + /** + * Returns the total time in seconds of maximum delay + * @return seconds + */ + virtual double GetMaxDelay() = 0; + + /** + * Pauses the stream playback + */ + virtual void Pause() = 0; + + /** + * Resumes the stream after pausing + */ + virtual void Resume() = 0; + + /** + * Start draining the stream + * @note Once called AddData will not consume more data. + */ + virtual void Drain(bool wait) = 0; + + /** + * Returns true if the is stream draining + */ + virtual bool IsDraining() = 0; + + /** + * Returns true if the is stream has finished draining + */ + virtual bool IsDrained() = 0; + + /** + * Flush all buffers dropping the audio data + */ + virtual void Flush() = 0; + + /** + * Return the stream's current volume level + * @return The volume level between 0.0 and 1.0 + */ + virtual float GetVolume() = 0; + + /** + * Set the stream's volume level + * @param volume The new volume level between 0.0 and 1.0 + */ + virtual void SetVolume(float volume) = 0; + + /** + * Returns the stream's current replay gain factor + * @return The replay gain factor between 0.0 and 1.0 + */ + virtual float GetReplayGain() = 0; + + /** + * Sets the stream's replay gain factor, this is used by formats such as MP3 that have attenuation information in their streams + * @param factor The replay gain factor + */ + virtual void SetReplayGain(float factor) = 0; + + /** + * Gets the stream's volume amplification in linear units. + * @return The volume amplification factor between 1.0 and 1000.0 + */ + virtual float GetAmplification() = 0; + + /** + * Sets the stream's volume amplification in linear units. + * @param The volume amplification factor between 1.0 and 1000.0 + */ + virtual void SetAmplification(float amplify) = 0; + + /** + * Sets the stream ffmpeg information if present. + + @param profile + * @param matrix_encoding + * @param audio_service_type + */ + virtual void SetFFmpegInfo(int profile, enum AVMatrixEncoding matrix_encoding, enum AVAudioServiceType audio_service_type) = 0; + + /** + * Returns the size of one audio frame in bytes (channelCount * resolution) + * @return The size in bytes of one frame + */ + virtual unsigned int GetFrameSize() const = 0; + + /** + * Returns the number of channels the stream is configured to accept + * @return The channel count + */ + virtual unsigned int GetChannelCount() const = 0; + + /** + * Returns the stream's sample rate, if the stream is using a dynamic sample rate, this value will NOT reflect any changes made by calls to SetResampleRatio() + * @return The stream's sample rate (eg, 48000) + */ + virtual unsigned int GetSampleRate() const = 0; + + /** + * Return the data format the stream has been configured with + * @return The stream's data format (eg, AE_FMT_S16LE) + */ + virtual enum AEDataFormat GetDataFormat() const = 0; + + /** + * Return the resample ratio + * @note This will return an undefined value if the stream is not resampling + * @return the current resample ratio or undefined if the stream is not resampling + */ + virtual double GetResampleRatio() = 0; + + /** + * Sets the resample ratio + * @note This function may return false if the stream is not resampling, if you wish to use this be sure to set the AESTREAM_FORCE_RESAMPLE option + * @param ratio the new sample rate ratio, calculated by ((double)desiredRate / (double)GetSampleRate()) + */ + virtual void SetResampleRatio(double ratio) = 0; + + /** + * Sets the resamplling on/ff + */ + virtual void SetResampleMode(int mode) = 0; + + /** + * Registers the audio callback to call with each block of data, this is used by Audio Visualizations + * @warning Currently the callbacks require stereo float data in blocks of 512 samples, any deviation from this may crash XBMC, or cause junk to be rendered + * @param pCallback The callback + */ + virtual void RegisterAudioCallback(IAudioCallback* pCallback) = 0; + + /** + * Unregisters the current audio callback + */ + virtual void UnRegisterAudioCallback() = 0; + + /** + * Fade the volume level over the specified time + * @param from The volume level to fade from (0.0f-1.0f) - See notes + * @param target The volume level to fade to (0.0f-1.0f) + * @param time The amount of time in milliseconds for the fade to occur + * @note The from parameter does not set the streams volume, it is only used to calculate the fade time properly + */ + virtual void FadeVolume(float from, float target, unsigned int time) {} /* FIXME: once all the engines have these new methods */ + + /** + * Returns if a fade is still running + * @return true if a fade is in progress, otherwise false + */ + virtual bool IsFading() { return false; } + + /** + * Slave a stream to resume when this stream has drained + */ + virtual void RegisterSlave(IAEStream *stream) = 0; +}; + diff --git a/xbmc/cores/AudioEngine/Interfaces/IAudioCallback.h b/xbmc/cores/AudioEngine/Interfaces/IAudioCallback.h new file mode 100644 index 0000000..d8759d5 --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/IAudioCallback.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +// IAudioCallback.h: interface for the IAudioCallback class. +// +////////////////////////////////////////////////////////////////////// + +class IAudioCallback +{ +public: + IAudioCallback() = default; + virtual ~IAudioCallback() = default; + virtual void OnInitialize(int iChannels, int iSamplesPerSec, int iBitsPerSample) = 0; + virtual void OnAudioData(const float* pAudioData, unsigned int iAudioDataLength) = 0; +}; + diff --git a/xbmc/cores/AudioEngine/Interfaces/ThreadedAE.h b/xbmc/cores/AudioEngine/Interfaces/ThreadedAE.h new file mode 100644 index 0000000..336b200 --- /dev/null +++ b/xbmc/cores/AudioEngine/Interfaces/ThreadedAE.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2010-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "AE.h" +#include "threads/IRunnable.h" + +class IThreadedAE : public IAE, public IRunnable +{ +public: + virtual void Run () = 0; + virtual void Stop() = 0; +}; + |