xbmc
AESinkPULSE.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/Interfaces/AESink.h"
12 #include "cores/AudioEngine/Utils/AEDeviceInfo.h"
13 #include "cores/AudioEngine/Utils/AEUtil.h"
14 #include "threads/CriticalSection.h"
15 #include "threads/SystemClock.h"
16 #include "threads/Thread.h"
17 
18 #include <atomic>
19 #include <memory>
20 
21 #include <pulse/pulseaudio.h>
22 #include <pulse/simple.h>
23 
24 class CDriverMonitor;
25 
26 class CAESinkPULSE : public IAESink
27 {
28 public:
29  const char *GetName() override { return "PULSE"; }
30 
31  CAESinkPULSE();
32  ~CAESinkPULSE() override;
33 
34  static bool Register();
35  static IAESink* Create(std::string &device, AEAudioFormat &desiredFormat);
36  static void EnumerateDevicesEx(AEDeviceInfoList &list, bool force = false);
37  static void Cleanup();
38 
39  bool Initialize(AEAudioFormat &format, std::string &device) override;
40  void Deinitialize() override;
41 
42  virtual double GetDelay() { return 0.0; }
43  void GetDelay(AEDelayStatus& status) override;
44  double GetCacheTotal() override;
45  unsigned int AddPackets(uint8_t **data, unsigned int frames, unsigned int offset) override;
46  void Drain() override;
47 
48  bool HasVolume() override { return true; }
49  void SetVolume(float volume) override;
50 
51  bool IsInitialized();
52  void UpdateInternalVolume(const pa_cvolume* nVol);
53  pa_stream* GetInternalStream();
54  pa_threaded_mainloop* GetInternalMainLoop();
55  CCriticalSection m_sec;
56  std::atomic<int> m_requestedBytes = 0;
57 
58 private:
59  void Pause(bool pause);
60  static inline bool WaitForOperation(pa_operation *op, pa_threaded_mainloop *mainloop, const char *LogEntry);
61 
62  bool m_IsAllocated;
63  bool m_passthrough;
64  bool m_IsStreamPaused;
65 
66  AEAudioFormat m_format;
67  unsigned int m_BytesPerSecond;
68  unsigned int m_BufferSize;
69  unsigned int m_Channels;
70  double m_maxLatency;
71 
72  pa_stream *m_Stream;
73  pa_cvolume m_Volume;
74  bool m_volume_needs_update;
75  uint32_t m_periodSize;
76 
77  pa_context *m_Context;
78  pa_threaded_mainloop *m_MainLoop;
79 
80  static std::unique_ptr<CDriverMonitor> m_pMonitor;
81 };
Definition: AESinkPULSE.cpp:24
Definition: AESink.h:18
The audio format structure that fully defines a stream&#39;s audio information.
Definition: AEAudioFormat.h:19
Definition: AEUtil.h:27
unsigned int AddPackets(uint8_t **data, unsigned int frames, unsigned int offset) override
Adds packets to be sent out, this routine MUST block or sleep.
Definition: AESinkPULSE.cpp:1078
Definition: AESinkPULSE.h:26