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/>.
22 #include "../AEAudioFormat.h"
23 #include "cores/IAudioCallback.h"
27 * Bit options to pass to IAE::GetStream
29 enum AEStreamOptions {
30 AESTREAM_FORCE_RESAMPLE = 0x01, /* force resample even if rates match */
31 AESTREAM_PAUSED = 0x02, /* create the stream paused */
32 AESTREAM_AUTOSTART = 0x04 /* autostart the stream when enough data is buffered */
36 * IAEStream Stream Interface for streaming audio
43 virtual ~IAEStream() {}
47 * Returns the amount of space available in the stream
48 * @return The number of bytes AddData will consume
50 virtual unsigned int GetSpace() = 0;
53 * Add interleaved PCM data to the stream
54 * @param data The interleaved PCM data
55 * @param size The size in bytes of data, if this is > GetSpace() only up to GetSpace() bytes will be consumed
56 * @return The number of bytes consumed
58 virtual unsigned int AddData(void *data, unsigned int size) = 0;
61 * Returns the time in seconds that it will take
62 * for the next added packet to be heard from the speakers.
65 virtual double GetDelay() = 0;
68 * Returns if the stream is buffering
69 * @return True if the stream is buffering
71 virtual bool IsBuffering() = 0;
74 * Returns the time in seconds that it will take
75 * to underrun the cache if no sample is added.
78 virtual double GetCacheTime() = 0;
81 * Returns the total time in seconds of the cache
84 virtual double GetCacheTotal() = 0;
87 * Pauses the stream playback
89 virtual void Pause() = 0;
92 * Resumes the stream after pausing
94 virtual void Resume() = 0;
97 * Start draining the stream
98 * @note Once called AddData will not consume more data.
100 virtual void Drain() = 0;
103 * Returns true if the is stream draining
105 virtual bool IsDraining() = 0;
108 * Returns true if the is stream has finished draining
110 virtual bool IsDrained() = 0;
113 * Flush all buffers dropping the audio data
115 virtual void Flush() = 0;
118 * Return the stream's current volume level
119 * @return The volume level between 0.0 and 1.0
121 virtual float GetVolume() = 0;
124 * Set the stream's volume level
125 * @param volume The new volume level between 0.0 and 1.0
127 virtual void SetVolume(float volume) = 0;
130 * Returns the stream's current replay gain factor
131 * @return The replay gain factor between 0.0 and 1.0
133 virtual float GetReplayGain() = 0;
136 * Sets the stream's replay gain factor, this is used by formats such as MP3 that have attenuation information in their streams
137 * @param factor The replay gain factor
139 virtual void SetReplayGain(float factor) = 0;
142 * Gets the stream's volume amplification in linear units.
143 * @return The volume amplification factor between 1.0 and 1000.0
145 virtual float GetAmplification() = 0;
148 * Sets the stream's volume amplification in linear units.
149 * @param The volume amplification factor between 1.0 and 1000.0
151 virtual void SetAmplification(float amplify) = 0;
154 * Returns the size of one audio frame in bytes (channelCount * resolution)
155 * @return The size in bytes of one frame
157 virtual const unsigned int GetFrameSize() const = 0;
160 * Returns the number of channels the stream is configured to accept
161 * @return The channel count
163 virtual const unsigned int GetChannelCount() const = 0;
166 * 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()
167 * @return The stream's sample rate (eg, 48000)
169 virtual const unsigned int GetSampleRate() const = 0;
172 * Returns the stream's encoded sample rate if the stream is RAW
173 * @return The stream's encoded sample rate
175 virtual const unsigned int GetEncodedSampleRate() const = 0;
178 * Return the data format the stream has been configured with
179 * @return The stream's data format (eg, AE_FMT_S16LE)
181 virtual const enum AEDataFormat GetDataFormat() const = 0;
184 * Return the resample ratio
185 * @note This will return an undefined value if the stream is not resampling
186 * @return the current resample ratio or undefined if the stream is not resampling
188 virtual double GetResampleRatio() = 0;
191 * Sets the resample ratio
192 * @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
193 * @param ratio the new sample rate ratio, calculated by ((double)desiredRate / (double)GetSampleRate())
195 virtual bool SetResampleRatio(double ratio) = 0;
198 * Registers the audio callback to call with each block of data, this is used by Audio Visualizations
199 * @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
200 * @param pCallback The callback
202 virtual void RegisterAudioCallback(IAudioCallback* pCallback) = 0;
205 * Unregisters the current audio callback
207 virtual void UnRegisterAudioCallback() = 0;
210 * Fade the volume level over the specified time
211 * @param from The volume level to fade from (0.0f-1.0f) - See notes
212 * @param target The volume level to fade to (0.0f-1.0f)
213 * @param time The amount of time in milliseconds for the fade to occur
214 * @note The from parameter does not set the streams volume, it is only used to calculate the fade time properly
216 virtual void FadeVolume(float from, float target, unsigned int time) {} /* FIXME: once all the engines have these new methods */
219 * Returns if a fade is still running
220 * @return true if a fade is in progress, otherwise false
222 virtual bool IsFading() { return false; }
225 * Slave a stream to resume when this stream has drained
227 virtual void RegisterSlave(IAEStream *stream) = 0;