MillicastSDK 2.5.0
Loading...
Searching...
No Matches
source.h
Go to the documentation of this file.
1#ifndef MILLICAST_API_SOURCE_H
2#define MILLICAST_API_SOURCE_H
3
4#ifdef __cplusplus
5
13#include <memory>
14#include <optional>
15#include <string>
16#include <vector>
17
18#include "capabilities.h"
19#include "frames.h"
20#include "mc_logging.h"
21
22namespace millicast {
23
24// Forward declarations ///////////////////////////////////////////////////////
25class Track;
26
27// Source /////////////////////////////////////////////////////////////////////
28
33class Source {
34 friend class AudioPlayback;
35
36 public:
41 enum class Type {
42 DEVICE,
43 MONITOR,
44 APP,
45 MIC,
46 NDI,
47 DECKLINK,
48 TVOS,
49 CUSTOM
50 };
51
52 template <typename T>
53 using SourcePtr = std::shared_ptr<T>;
54
55 using Ptr = SourcePtr<Source>;
56
57 struct SourceInformation {
58 Type type;
59 int id;
60 std::string name;
61 std::string unique_id;
62 };
63
70 template <typename T = Type>
71 T type() const;
72
78 [[nodiscard]] MILLICAST_API int id() const;
79
85 [[nodiscard]] MILLICAST_API const std::string& name() const;
86
92 [[nodiscard]] MILLICAST_API const std::string& unique_id() const;
93
99 MILLICAST_API void set_track_name(std::string track_name);
100
106 [[nodiscard]] MILLICAST_API const std::string& track_name() const;
107
117 MILLICAST_API virtual std::weak_ptr<Track> start_capture() = 0;
118
126 MILLICAST_API virtual void stop_capture() = 0;
127
133 [[nodiscard]] MILLICAST_API virtual bool is_capturing() const = 0;
134
135 MILLICAST_API virtual ~Source() = default;
136
137 protected:
138 Source(const SourceInformation& information) noexcept;
139
140 private:
141 Type _type;
142 int _id;
143 std::string _name;
144 std::string _unique_id;
145 std::string _track_name;
146};
147
148// Fix specializing templates in non-namespace scope, which causes
149// issues when compiling with GCC
150template <>
151[[nodiscard]] MILLICAST_API Source::Type Source::type<Source::Type>() const;
152template <>
153[[nodiscard]] MILLICAST_API std::string Source::type<std::string>() const;
154
155// Video //////////////////////////////////////////////////////////////////////
156
161class VideoSource : public Source {
162 public:
163 using Ptr = Source::SourcePtr<VideoSource>;
164
169 struct Builder : public SourceInformation {
170 std::vector<VideoCapabilities>
171 capabilities;
172 MILLICAST_API Builder() noexcept = default;
177 MILLICAST_API Ptr build() noexcept;
178 };
179
185 [[nodiscard]] MILLICAST_API const std::vector<VideoCapabilities>&
186 capabilities() const;
187 MILLICAST_API void set_capabilities(
188 std::vector<VideoCapabilities>& capabilities);
189
195 [[nodiscard]] MILLICAST_API const VideoCapabilities& capability() const;
196
203 MILLICAST_API void set_capability(const VideoCapabilities& capability);
204 MILLICAST_API void set_capability(VideoCapabilities&& capability);
205 MILLICAST_API virtual void change_video_source(
206 bool ascending,
207 const std::string& unique_device_id = ""){};
208
209 ~VideoSource() override = default;
210
211 protected:
212 using Source::Source;
213 std::vector<VideoCapabilities> _capabilities;
214 VideoCapabilities _capability;
215};
216
217// Audio //////////////////////////////////////////////////////////////////////
218
223class MILLICAST_API AudioControl {
224 public:
230 virtual void set_volume(uint32_t v) = 0;
231
239 virtual void set_num_channel(uint8_t n) = 0;
240
246 virtual void mute(bool m) = 0;
247
253 virtual uint32_t get_volume() = 0;
254
260 [[nodiscard]] virtual bool is_muted() const = 0;
261};
262
267class AudioSource : public Source, public AudioControl {
268 public:
269 using Ptr = Source::SourcePtr<AudioSource>;
274 struct Builder : public SourceInformation {
275 MILLICAST_API Builder() noexcept = default;
280 MILLICAST_API Ptr build() noexcept;
281 };
282
283 ~AudioSource() override = default;
284
285 protected:
286 using Source::Source;
287};
288
296class AudioPlayback : public Source, public AudioControl {
297 /* Not a capture source */
298 std::weak_ptr<Track> start_capture() override = 0;
299 void stop_capture() override = 0;
300 [[nodiscard]] bool is_capturing() const override = 0;
301
302 public:
303 using Ptr = Source::SourcePtr<AudioPlayback>;
304
309 struct Builder : public SourceInformation {
310 MILLICAST_API Builder() noexcept = default;
314 MILLICAST_API Ptr build() noexcept;
315 };
316
321 MILLICAST_API virtual void init_playback() = 0;
322
328 [[nodiscard]] MILLICAST_API virtual bool is_playing() const = 0;
329
330 protected:
331 using Source::Source;
332};
333
334// Custom source
335// ////////////////////////////////////////////////////////////////////
336
337class CustomAudioSource : public Source {
338 public:
339 using Ptr = Source::SourcePtr<CustomAudioSource>;
343 struct Builder : public SourceInformation {
344 MILLICAST_API Builder() noexcept;
345
352 MILLICAST_API Ptr build();
353 };
354
355 [[nodiscard]] MILLICAST_API std::weak_ptr<Track> start_capture() override = 0;
356 [[nodiscard]] MILLICAST_API bool is_capturing() const override = 0;
357 MILLICAST_API void stop_capture() override = 0;
358
365 MILLICAST_API virtual void on_audio_frame(
366 const millicast::AudioFrame& frame) = 0;
367
368 protected:
369 using Source::Source;
370};
371
372class CustomVideoSource : public Source {
373 public:
374 using Ptr = Source::SourcePtr<CustomVideoSource>;
378 struct Builder : public SourceInformation {
379 MILLICAST_API Builder() noexcept;
384 MILLICAST_API Ptr build();
385 };
386
387 [[nodiscard]] MILLICAST_API std::weak_ptr<Track> start_capture() override = 0;
388 [[nodiscard]] MILLICAST_API bool is_capturing() const override = 0;
389 MILLICAST_API void stop_capture() override = 0;
390
397 MILLICAST_API virtual void on_video_frame(
398 const millicast::VideoFrame& frame) = 0;
399
400 protected:
401 using Source::Source;
402};
403
404} // namespace millicast
405
406#endif // __cplusplus
407#endif /* MILLICAST_API_SOURCE_H */
#define MILLICAST_API
Definition exports.h:51