xbmc
ActiveAESink.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/AESinkFactory.h"
12 #include "cores/AudioEngine/Engines/ActiveAE/ActiveAEBuffer.h"
13 #include "cores/AudioEngine/Interfaces/AE.h"
14 #include "cores/AudioEngine/Interfaces/AESink.h"
15 #include "threads/Event.h"
16 #include "threads/SystemClock.h"
17 #include "threads/Thread.h"
18 #include "utils/ActorProtocol.h"
19 
20 #include <utility>
21 
22 class CAEBitstreamPacker;
23 
24 namespace ActiveAE
25 {
26 using namespace Actor;
27 
28 class CEngineStats;
29 
30 struct SinkConfig
31 {
32  AEAudioFormat format;
33  CEngineStats *stats;
34  const std::string *device;
35 };
36 
37 struct SinkReply
38 {
39  AEAudioFormat format;
40  float cacheTotal;
41  float latency;
42  bool hasVolume;
43 };
44 
46 {
47 public:
48  CSinkControlProtocol(std::string name, CEvent* inEvent, CEvent* outEvent)
49  : Protocol(std::move(name), inEvent, outEvent)
50  {
51  }
52  enum OutSignal
53  {
54  CONFIGURE,
55  UNCONFIGURE,
56  STREAMING,
57  APPFOCUSED,
58  VOLUME,
59  FLUSH,
60  TIMEOUT,
61  SETSILENCETIMEOUT,
62  SETNOISETYPE,
63  };
64  enum InSignal
65  {
66  ACC,
67  ERR,
68  STATS,
69  };
70 };
71 
73 {
74 public:
75  CSinkDataProtocol(std::string name, CEvent* inEvent, CEvent* outEvent)
76  : Protocol(std::move(name), inEvent, outEvent)
77  {
78  }
79  enum OutSignal
80  {
81  SAMPLE = 0,
82  DRAIN,
83  };
84  enum InSignal
85  {
86  RETURNSAMPLE,
87  ACC,
88  };
89 };
90 
91 class CActiveAESink : private CThread
92 {
93 public:
94  explicit CActiveAESink(CEvent *inMsgEvent);
95  void EnumerateSinkList(bool force, std::string driver);
96  void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
97  void Start();
98  void Dispose();
99  AEDeviceType GetDeviceType(const std::string &device);
100  bool HasPassthroughDevice();
101  bool SupportsFormat(const std::string &device, AEAudioFormat &format);
102  bool DeviceExist(std::string driver, const std::string& device);
103  bool NeedIecPack() const { return m_needIecPack; }
104  CSinkControlProtocol m_controlPort;
105  CSinkDataProtocol m_dataPort;
106 
107 protected:
108  void Process() override;
109  void StateMachine(int signal, Protocol *port, Message *msg);
110  void PrintSinks(std::string& driver);
111  void GetDeviceFriendlyName(const std::string& device);
112  void OpenSink();
113  void ReturnBuffers();
114  void SetSilenceTimer();
115  bool NeedIECPacking();
116 
117  unsigned int OutputSamples(CSampleBuffer* samples);
118  void SwapInit(CSampleBuffer* samples);
119 
120  void GenerateNoise();
121 
122  CEvent m_outMsgEvent;
123  CEvent *m_inMsgEvent;
124  int m_state;
125  bool m_bStateMachineSelfTrigger;
126  std::chrono::milliseconds m_extTimeout;
127  std::chrono::minutes m_silenceTimeOut{std::chrono::minutes::zero()};
128  bool m_extError;
129  std::chrono::milliseconds m_extSilenceTimeout;
130  bool m_extAppFocused;
131  bool m_extStreaming;
132  XbmcThreads::EndTime<> m_extSilenceTimer;
133 
134  CSampleBuffer m_sampleOfSilence;
135  enum
136  {
137  CHECK_SWAP,
138  NEED_CONVERT,
139  NEED_BYTESWAP,
140  SKIP_SWAP,
141  } m_swapState;
142 
143  std::vector<uint8_t> m_mergeBuffer;
144 
145  std::string m_deviceFriendlyName;
146  std::string m_device;
147  std::vector<AE::AESinkInfo> m_sinkInfoList;
148  IAESink *m_sink;
149  AEAudioFormat m_sinkFormat, m_requestedFormat;
150  CEngineStats *m_stats;
151  float m_volume;
152  int m_sinkLatency;
153  CAEBitstreamPacker *m_packer;
154  bool m_needIecPack{false};
155  bool m_streamNoise;
156 };
157 
158 }
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: Thread.h:44
Definition: ActorProtocol.h:73
Definition: ActiveAESink.h:91
Definition: SystemClock.h:31
Definition: ActiveAESink.h:30
Definition: AESink.h:18
Definition: ActiveAESink.h:37
Definition: AEBitstreamPacker.h:20
Definition: ActiveAESink.h:45
Definition: Application.h:69
Definition: ActorProtocol.h:21
Definition: ActorProtocol.h:45
Definition: ActiveAESink.h:72
The audio format structure that fully defines a stream&#39;s audio information.
Definition: AEAudioFormat.h:19
Definition: ActiveAE.h:182
Definition: ActiveAEBuffer.h:45