3 * Copyright (C) 2010-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
26 #include "threads/CriticalSection.h"
28 #include "cores/AudioEngine/Utils/AEAudioFormat.h"
30 typedef std::pair<std::string, std::string> AEDevice;
31 typedef std::vector<AEDevice> AEDeviceList;
33 /* forward declarations */
40 #define AE_SOUND_OFF 0 /* disable sounds */
41 #define AE_SOUND_IDLE 1 /* only play sounds while no streams are running */
42 #define AE_SOUND_ALWAYS 2 /* always play sounds */
45 #define AE_CONFIG_FIXED 1
46 #define AE_CONFIG_AUTO 2
47 #define AE_CONFIG_MATCH 3
51 AE_QUALITY_UNKNOWN = -1, /* Unset, unknown or incorrect quality level */
52 AE_QUALITY_DEFAULT = 0, /* Engine's default quality level */
54 /* Basic quality levels */
55 AE_QUALITY_LOW = 20, /* Low quality level */
56 AE_QUALITY_MID = 30, /* Standard quality level */
57 AE_QUALITY_HIGH = 50, /* Best sound processing quality */
59 /* Optional quality levels */
60 AE_QUALITY_REALLYHIGH = 100 /* Uncompromised optional quality level,
61 usually with unmeasurable and unnoticeable improvement */
70 friend class CAEFactory;
76 * Returns true when it should be possible to initialize this engine, if it returns false
77 * CAEFactory can possibly fall back to a different one
79 virtual bool CanInit() { return true; }
82 * Initializes the AudioEngine, called by CFactory when it is time to initialize the audio engine.
83 * Do not call this directly, CApplication will call this when it is ready
85 virtual bool Initialize() = 0;
88 * Called when the application needs to terminate the engine
90 virtual void Shutdown() { }
93 * Suspends output and de-initializes sink
94 * Used to avoid conflicts with external players or to reduce power consumption
95 * @return True if successful
97 virtual bool Suspend() = 0;
100 * Resumes output and re-initializes sink
101 * Used to resume output from Suspend() state above
102 * @return True if successful
104 virtual bool Resume() = 0;
107 * Get the current Suspend() state
108 * Used by players to determine if audio is being processed
109 * Default is true so players drop audio or pause if engine unloaded
110 * @return True if processing suspended
112 virtual bool IsSuspended() {return true;}
115 * Callback to alert the AudioEngine of setting changes
116 * @param setting The name of the setting that was changed
118 virtual void OnSettingsChange(const std::string& setting) {}
121 * Returns the current master volume level of the AudioEngine
122 * @return The volume level between 0.0 and 1.0
124 virtual float GetVolume() = 0;
127 * Sets the master volume level of the AudioEngine
128 * @param volume The new volume level between 0.0 and 1.0
130 virtual void SetVolume(const float volume) = 0;
133 * Set the mute state (does not affect volume level value)
134 * @param enabled The mute state
136 virtual void SetMute(const bool enabled) = 0;
139 * Get the current mute state
140 * @return The current mute state
142 virtual bool IsMuted() = 0;
145 * Sets the sound mode
146 * @param mode One of AE_SOUND_OFF, AE_SOUND_IDLE or AE_SOUND_ALWAYS
148 virtual void SetSoundMode(const int mode) = 0;
151 * Creates and returns a new IAEStream in the format specified, this function should never fail
152 * @param dataFormat The data format the incoming audio will be in (eg, AE_FMT_S16LE)
153 * @param sampleRate The sample rate of the audio data (eg, 48000)
154 * @prarm encodedSampleRate The sample rate of the encoded audio data if AE_IS_RAW(dataFormat)
155 * @param channelLayout The order of the channels in the audio data
156 * @param options A bit field of stream options (see: enum AEStreamOptions)
157 * @return a new IAEStream that will accept data in the requested format
159 virtual IAEStream *MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate, unsigned int encodedSampleRate, CAEChannelInfo channelLayout, unsigned int options = 0) = 0;
162 * This method will remove the specifyed stream from the engine.
163 * For OSX/IOS this is essential to reconfigure the audio output.
164 * @param stream The stream to be altered
167 virtual IAEStream *FreeStream(IAEStream *stream) = 0;
170 * Creates a new IAESound that is ready to play the specified file
171 * @param file The WAV file to load, this supports XBMC's VFS
172 * @return A new IAESound if the file could be loaded, otherwise NULL
174 virtual IAESound *MakeSound(const std::string &file) = 0;
177 * Free the supplied IAESound object
178 * @param sound The IAESound object to free
180 virtual void FreeSound(IAESound *sound) = 0;
183 * Callback by CApplication for Garbage Collection. This method is called by CApplication every 500ms and can be used to clean up and free no-longer used resources.
185 virtual void GarbageCollect() = 0;
188 * Enumerate the supported audio output devices
189 * @param devices The device list to append supported devices to
190 * @param passthrough True if only passthrough devices are wanted
192 virtual void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough) = 0;
195 * Returns the default audio device
196 * @param passthrough True if the default passthrough device is wanted
197 * @return the default audio device
199 virtual std::string GetDefaultDevice(bool passthrough) { return "default"; }
202 * Returns true if the AudioEngine supports AE_FMT_RAW streams for use with formats such as IEC61937
203 * @see CAEPackIEC61937::CAEPackIEC61937()
204 * @returns true if the AudioEngine is capable of RAW output
206 virtual bool SupportsRaw(AEDataFormat format) { return false; }
209 * Returns true if the AudioEngine supports drain mode which is not streaming silence when idle
210 * @returns true if the AudioEngine is capable of drain mode
212 virtual bool SupportsSilenceTimeout() { return false; }
214 virtual void RegisterAudioCallback(IAudioCallback* pCallback) {}
216 virtual void UnregisterAudioCallback() {}
219 * Returns true if AudioEngine supports specified quality level
220 * @return true if specified quality level is supported, otherwise false
222 virtual bool SupportsQualityLevel(enum AEQuality level) { return false; }
225 * AE decides whether this settings should be displayed
226 * @return true if AudioEngine wants to display this setting
228 virtual bool IsSettingVisible(const std::string &settingId) {return false; }
231 * Instruct AE to keep configuration for a specified time
232 * @param millis time for which old configuration should be kept
234 virtual void KeepConfiguration(unsigned int millis) {return; }