XT-Audio
XtStream.hpp
Go to the documentation of this file.
1 #ifndef XT_API_STREAM_HPP
2 #define XT_API_STREAM_HPP
3 
6 #include <xt/cpp/Core.hpp>
7 #include <xt/cpp/Error.hpp>
8 #include <xt/api/Structs.hpp>
9 #include <xt/api/Callbacks.hpp>
10 
11 #include <cstdint>
14 namespace Xt {
15 
16 using namespace Detail;
17 
18 class Stream final
19 {
20  XtStream* _s;
21  void* const _user;
22  StreamParams const _params;
23 
24  Stream(StreamParams const& params, void* user):
25  _s(nullptr), _params(params), _user(user) { }
26 
27 public:
28  ~Stream();
29  void Stop();
30  void Start();
31  bool IsRunning() const;
32  void* GetHandle() const;
33  int32_t GetFrames() const;
34  bool IsInterleaved() const;
35  Latency GetLatency() const;
36  Format const& GetFormat() const;
37 
39  friend class Device;
40  friend class Service;
41  friend void XT_CALLBACK
42  Detail::ForwardOnXRun(XtStream const* coreStream, int32_t index, void* user);
43  friend uint32_t XT_CALLBACK
44  Detail::ForwardOnBuffer(XtStream const* coreStream, XtBuffer const* coreBuffer, void* user);
45  friend void XT_CALLBACK
46  Detail::ForwardOnRunning(XtStream const* coreStream, XtBool running, uint64_t error, void* user);
48 };
49 
50 inline void
52 { Detail::HandleError(XtStreamStart(_s)); }
53 inline void
55 { Detail::HandleAssert(XtStreamStop, _s); }
56 inline
58 { Detail::HandleDestroy(XtStreamDestroy, _s); }
59 inline void*
61 { return Detail::HandleAssert(XtStreamGetHandle(_s)); }
62 inline bool
64 { return Detail::HandleAssert(XtStreamIsRunning(_s)); }
65 
66 inline int32_t
68 {
69  int32_t frames;
70  Detail::HandleError(XtStreamGetFrames(_s, &frames));
71  return frames;
72 }
73 
74 inline Latency
76 {
77  Latency latency;
78  auto coreLatency = reinterpret_cast<XtLatency*>(&latency);
79  Detail::HandleError(XtStreamGetLatency(_s, coreLatency));
80  return latency;
81 }
82 
83 inline Format const&
85 {
86  auto coreFormat = Detail::HandleAssert(XtStreamGetFormat(_s));
87  return *reinterpret_cast<Format const*>(coreFormat);
88 }
89 
90 inline bool
92 {
93  auto coreInterleaved = Detail::HandleAssert(XtStreamIsInterleaved(_s));
94  return coreInterleaved != XtFalse;
95 }
96 
97 } // namespace Xt
98 #endif // XT_API_STREAM_HPP
Definition: Structs.hpp:85
Format const & GetFormat() const
Definition: XtStream.hpp:84
bool IsInterleaved() const
Definition: XtStream.hpp:91
void * GetHandle() const
Definition: XtStream.hpp:60
Definition: Structs.hpp:25
void Stop()
Definition: XtStream.hpp:54
bool IsRunning() const
Definition: XtStream.hpp:63
~Stream()
Definition: XtStream.hpp:57
int32_t GetFrames() const
Definition: XtStream.hpp:67
Definition: XtService.hpp:23
void Start()
Definition: XtStream.hpp:51
Latency GetLatency() const
Definition: XtStream.hpp:75
Definition: Callbacks.hpp:10
Definition: XtStream.hpp:18
Definition: XtDevice.hpp:20
Definition: Structs.hpp:94