kodi
AE.h
1 /*
2  * Copyright (C) 2010-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "cores/AudioEngine/Utils/AEAudioFormat.h"
12 
13 #include <cassert>
14 #include <list>
15 #include <map>
16 #include <memory>
17 #include <utility>
18 #include <vector>
19 
20 extern "C" {
21 #include <libavutil/samplefmt.h>
22 }
23 
24 typedef std::pair<std::string, std::string> AEDevice;
25 typedef std::vector<AEDevice> AEDeviceList;
26 
27 /* forward declarations */
28 class IAEStream;
29 class IAEStreamDeleter;
30 class IAESound;
31 class IAESoundDeleter;
32 class IAEPacketizer;
33 class IAudioCallback;
34 class IAEClockCallback;
35 class CAEStreamInfo;
36 
37 namespace ADDON
38 {
39 struct Interface_AudioEngine;
40 }
41 
42 /* sound options */
43 #define AE_SOUND_OFF 0
44 #define AE_SOUND_IDLE 1
45 #define AE_SOUND_ALWAYS 2
47 /* config options */
48 #define AE_CONFIG_FIXED 1
49 #define AE_CONFIG_AUTO 2
50 #define AE_CONFIG_MATCH 3
51 
52 enum AEQuality
53 {
54  AE_QUALITY_UNKNOWN = -1,
55  AE_QUALITY_DEFAULT = 0,
57  /* Basic quality levels */
58  AE_QUALITY_LOW = 20,
59  AE_QUALITY_MID = 30,
60  AE_QUALITY_HIGH = 50,
62  /* Optional quality levels */
63  AE_QUALITY_REALLYHIGH = 100,
65  AE_QUALITY_GPU = 101,
66 };
67 
69 {
70  AVSampleFormat fmt;
71  uint64_t channel_layout;
72  int channels;
73  int sample_rate;
74  int bits_per_sample;
75  int dither_bits;
76 };
77 
81 class IAE
82 {
83 protected:
84 
85  IAE() = default;
86  virtual ~IAE() = default;
87 
93  virtual void Start() = 0;
94 public:
95  using StreamPtr = std::unique_ptr<IAEStream, IAEStreamDeleter>;
96  using SoundPtr = std::unique_ptr<IAESound, IAESoundDeleter>;
97 
101  virtual void Shutdown() { }
102 
110  virtual bool Suspend() = 0;
111 
119  virtual bool Resume() = 0;
120 
129  virtual bool IsSuspended() {return true;}
130 
136  virtual float GetVolume() = 0;
137 
143  virtual void SetVolume(const float volume) = 0;
144 
150  virtual void SetMute(const bool enabled) = 0;
151 
157  virtual bool IsMuted() = 0;
158 
169  virtual StreamPtr MakeStream(AEAudioFormat& audioFormat,
170  unsigned int options = 0,
171  IAEClockCallback* clock = NULL) = 0;
172 
179  virtual SoundPtr MakeSound(const std::string& file) = 0;
180 
187  virtual void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough) = 0;
188 
196  virtual bool SupportsRaw(AEAudioFormat &format) { return false; }
197 
203  virtual bool SupportsSilenceTimeout() { return false; }
204 
210  virtual bool UsesDtsCoreFallback() { return false; }
211 
217  virtual bool HasStereoAudioChannelCount() { return false; }
218 
224  virtual bool HasHDAudioChannelCount() { return true; }
225 
226  virtual void RegisterAudioCallback(IAudioCallback* pCallback) {}
227 
228  virtual void UnregisterAudioCallback(IAudioCallback* pCallback) {}
229 
235  virtual bool SupportsQualityLevel(enum AEQuality level) { return false; }
236 
242  virtual bool IsSettingVisible(const std::string &settingId) {return false; }
243 
249  virtual void KeepConfiguration(unsigned int millis) {}
250 
254  virtual void DeviceChange() {}
255 
259  virtual void DeviceCountChange(const std::string& driver) {}
260 
267  virtual bool GetCurrentSinkFormat(AEAudioFormat &SinkFormat) { return false; }
268 
269 private:
270  friend class IAEStreamDeleter;
271  friend class IAESoundDeleter;
272  friend struct ADDON::Interface_AudioEngine;
273 
283  virtual bool FreeStream(IAEStream* stream, bool finish) = 0;
284 
290  virtual void FreeSound(IAESound* sound) = 0;
291 };
292 
294 {
295 private:
296  IAE* m_iae;
297  bool m_finish;
298 
299 public:
300  IAEStreamDeleter() : m_iae(nullptr), m_finish(true) {}
301  explicit IAEStreamDeleter(IAE& iae) : m_iae(&iae), m_finish{true} {}
302  void setFinish(bool finish) { m_finish = finish; }
303  void operator()(IAEStream* stream)
304  {
305  assert(m_iae);
306  m_iae->FreeStream(stream, m_finish);
307  }
308 };
309 
311 {
312 private:
313  IAE* m_iae;
314 
315 public:
316  IAESoundDeleter() : m_iae(nullptr) {}
317  explicit IAESoundDeleter(IAE& iae) : m_iae(&iae) {}
318  void operator()(IAESound* sound)
319  {
320  assert(m_iae);
321  m_iae->FreeSound(sound);
322  }
323 };
virtual bool HasStereoAudioChannelCount()
Returns true if the AudioEngine is currently configured for stereo audio.
Definition: AE.h:217
virtual bool SupportsQualityLevel(enum AEQuality level)
Returns true if AudioEngine supports specified quality level.
Definition: AE.h:235
Definition: AEStreamInfo.h:22
Callback interface for VideoPlayer clock needed by AE for sync.
Definition: AEStream.h:23
virtual bool SupportsRaw(AEAudioFormat &format)
Returns true if the AudioEngine supports AE_FMT_RAW streams for use with formats such as IEC61937...
Definition: AE.h:196
Definition: IAudioCallback.h:15
IAEStream Stream Interface for streaming audio.
Definition: AEStream.h:52
Definition: AESound.h:15
Definition: AudioEngine.h:19
virtual bool GetCurrentSinkFormat(AEAudioFormat &SinkFormat)
Get the current sink data format.
Definition: AE.h:267
Definition: AE.h:68
The audio format structure that fully defines a stream&#39;s audio information.
Definition: AEAudioFormat.h:19
virtual void DeviceCountChange(const std::string &driver)
Instruct AE to re-initialize, e.g. after ELD change event.
Definition: AE.h:259
virtual bool HasHDAudioChannelCount()
Returns true if the AudioEngine is currently configured for HD audio (more than 5.1)
Definition: AE.h:224
Definition: AE.h:310
virtual bool IsSettingVisible(const std::string &settingId)
AE decides whether this settings should be displayed.
Definition: AE.h:242
virtual void KeepConfiguration(unsigned int millis)
Instruct AE to keep configuration for a specified time.
Definition: AE.h:249
virtual void Shutdown()
Called when the application needs to terminate the engine.
Definition: AE.h:101
virtual void DeviceChange()
Instruct AE to re-initialize, e.g. after ELD change event.
Definition: AE.h:254
IAE Interface.
Definition: AE.h:81
Definition: Addon.cpp:39
virtual bool IsSuspended()
Get the current Suspend() state.
Definition: AE.h:129
virtual bool UsesDtsCoreFallback()
Returns true if the AudioEngine is currently configured to extract the DTS Core from DTS-HD streams...
Definition: AE.h:210
Definition: AE.h:293
virtual bool SupportsSilenceTimeout()
Returns true if the AudioEngine supports drain mode which is not streaming silence when idle...
Definition: AE.h:203