MillicastSDK 2.0.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
11#include <memory>
12#include <optional>
13#include <string>
14#include <vector>
15
19
20namespace millicast {
21
22// Forward declarations ///////////////////////////////////////////////////////
23class Track;
24
25// Source /////////////////////////////////////////////////////////////////////
26
31class Source {
32 friend class AudioPlayback;
33
34 public:
39 enum class Type {
40 DEVICE,
41 MONITOR,
42 APP,
43 MIC,
44 NDI,
45 DECKLINK,
46 TVOS,
47 CUSTOM
48 };
49
50 template <typename T>
51 using SourcePtr = std::shared_ptr<T>;
52
54
57 int id;
58 std::string name;
59 std::string unique_id;
60 };
61
68 template <typename T = Type>
69 T type() const;
70
76 [[nodiscard]] MILLICAST_API int id() const;
77
83 [[nodiscard]] MILLICAST_API const std::string& name() const;
84
90 [[nodiscard]] MILLICAST_API const std::string& unique_id() const;
91
98
104 [[nodiscard]] MILLICAST_API const std::string& track_name() const;
105
115 MILLICAST_API virtual std::weak_ptr<Track> start_capture() = 0;
116
124 MILLICAST_API virtual void stop_capture() = 0;
125
131 [[nodiscard]] MILLICAST_API virtual bool is_capturing() const = 0;
132
133 MILLICAST_API virtual ~Source() = default;
134
135 protected:
136 Source(const SourceInformation& information) noexcept;
137
138 private:
139 Type _type;
140 int _id;
141 std::string _name;
142 std::string _unique_id;
143 std::string _track_name;
144};
145
146// Fix specializing templates in non-namespace scope, which causes
147// issues when compiling with GCC
148template <>
149[[nodiscard]] MILLICAST_API Source::Type Source::type<Source::Type>() const;
150template <>
151[[nodiscard]] MILLICAST_API std::string Source::type<std::string>() const;
152
153// Video //////////////////////////////////////////////////////////////////////
154
159class VideoSource : public Source {
160 public:
162
167 struct Builder : public SourceInformation {
168 std::vector<VideoCapabilities>
170 MILLICAST_API Builder() noexcept = default;
176 };
177
183 [[nodiscard]] MILLICAST_API const std::vector<VideoCapabilities>&
187
193 [[nodiscard]] MILLICAST_API const VideoCapabilities& capability() const;
194
204 bool ascending,
205 const std::string& unique_device_id = ""){};
206
207 ~VideoSource() override = default;
208
209 protected:
210 using Source::Source;
211 std::vector<VideoCapabilities> _capabilities;
213};
214
215// Audio //////////////////////////////////////////////////////////////////////
216
222 public:
228 virtual void set_volume(uint32_t v) = 0;
229
237 virtual void set_num_channel(uint8_t n) = 0;
238
244 virtual void mute(bool m) = 0;
245
251 virtual uint32_t get_volume() = 0;
252
258 [[nodiscard]] virtual bool is_muted() const = 0;
259};
260
265class AudioSource : public Source, public AudioControl {
266 public:
272 struct Builder : public SourceInformation {
273 MILLICAST_API Builder() noexcept = default;
278 MILLICAST_API Ptr build() noexcept;
279 };
280
281 ~AudioSource() override = default;
282
283 protected:
284 using Source::Source;
285};
286
294class AudioPlayback : public Source, public AudioControl {
295 /* Not a capture source */
296 std::weak_ptr<Track> start_capture() override = 0;
297 void stop_capture() override = 0;
298 [[nodiscard]] bool is_capturing() const override = 0;
299
300 public:
302
307 struct Builder : public SourceInformation {
308 MILLICAST_API Builder() noexcept = default;
312 MILLICAST_API Ptr build() noexcept;
313 };
314
319 MILLICAST_API virtual void init_playback() = 0;
320
326 [[nodiscard]] MILLICAST_API virtual bool is_playing() const = 0;
327
328 protected:
329 using Source::Source;
330};
331
332// Custom source
333// ////////////////////////////////////////////////////////////////////
334
335class CustomAudioSource : public Source {
336 public:
341 struct Builder : public SourceInformation {
343
351 };
352
353 [[nodiscard]] MILLICAST_API std::weak_ptr<Track> start_capture() override = 0;
354 [[nodiscard]] MILLICAST_API bool is_capturing() const override = 0;
355 MILLICAST_API void stop_capture() override = 0;
356
363 MILLICAST_API virtual void on_audio_frame(
364 const millicast::AudioFrame& frame) = 0;
365
366 protected:
367 using Source::Source;
368};
369
370class CustomVideoSource : public Source {
371 public:
376 struct Builder : public SourceInformation {
383 };
384
385 [[nodiscard]] MILLICAST_API std::weak_ptr<Track> start_capture() override = 0;
386 [[nodiscard]] MILLICAST_API bool is_capturing() const override = 0;
387 MILLICAST_API void stop_capture() override = 0;
388
395 MILLICAST_API virtual void on_video_frame(
396 const millicast::VideoFrame& frame) = 0;
397
398 protected:
399 using Source::Source;
400};
401
402} // namespace millicast
403
404#endif /* MILLICAST_API_SOURCE_H */
The AudioControl class.
Definition source.h:221
virtual void set_volume(uint32_t v)=0
Set the microphone / speaker volume.
virtual bool is_muted() const =0
Tell whether the mic / speaker is muted or not.
virtual void mute(bool m)=0
Mute the microphone or the speakers.
virtual uint32_t get_volume()=0
Get the current volume.
virtual void set_num_channel(uint8_t n)=0
Set the number of channels to use.
The AudioPlayback class.
Definition source.h:294
Source::SourcePtr< AudioPlayback > Ptr
Definition source.h:301
The AudioSource class.
Definition source.h:265
Source::SourcePtr< AudioSource > Ptr
Definition source.h:267
Definition source.h:335
Source::SourcePtr< CustomAudioSource > Ptr
Definition source.h:337
Definition source.h:370
Source::SourcePtr< CustomVideoSource > Ptr
Definition source.h:372
The Source base class.
Definition source.h:31
MILLICAST_API int id() const
Get the id of the source.
Type
The Source type.
Definition source.h:39
virtual MILLICAST_API std::weak_ptr< Track > start_capture()=0
Start a capture from this source, this will init and start the capture device and create the correspo...
MILLICAST_API void set_track_name(std::string track_name)
Set the name of the track. The name of the track is the name used to identify the track in the SDP.
virtual MILLICAST_API bool is_capturing() const =0
Tell is the source is currently capturing.
SourcePtr< Source > Ptr
Definition source.h:53
virtual MILLICAST_API void stop_capture()=0
Stop a capture adn release the track and the underlying devices.
MILLICAST_API const std::string & name() const
Get the name of the source.
Source(const SourceInformation &information) noexcept
T type() const
Get the video source's type.
MILLICAST_API const std::string & unique_id() const
Get the source's unique_id.
std::shared_ptr< T > SourcePtr
Definition source.h:51
virtual MILLICAST_API ~Source()=default
MILLICAST_API const std::string & track_name() const
Get the name of the track. If you did not set one, it will be the default one.
The Track class represent a media sources.
Definition track.h:32
The VideoCapabilities struct.
Definition capabilities.h:145
The VideoFrame class used to described a VideoFrame.
Definition frames.h:15
The VideoSource class.
Definition source.h:159
Source::SourcePtr< VideoSource > Ptr
Definition source.h:161
MILLICAST_API void set_capability(const VideoCapabilities &capability)
Set the capability to use for the capture.
VideoCapabilities _capability
Definition source.h:212
MILLICAST_API const VideoCapabilities & capability() const
Get the current capability of the source.
~VideoSource() override=default
virtual MILLICAST_API void change_video_source(bool ascending, const std::string &unique_device_id="")
Definition source.h:203
MILLICAST_API void set_capabilities(std::vector< VideoCapabilities > &capabilities)
std::vector< VideoCapabilities > _capabilities
Definition source.h:211
#define MILLICAST_API
Definition exports.h:51
Definition capabilities.h:15
Definition error.h:209
The AudioFrame struct used to described audio data.
Definition frames.h:105
The Builder struct to build an AudioPlayback.
Definition source.h:307
MILLICAST_API Builder() noexcept=default
The Builder struct to build an audio source.
Definition source.h:272
MILLICAST_API Builder() noexcept=default
Builder struct to create a CustomSource.
Definition source.h:341
MILLICAST_API Builder() noexcept
Builder struct to create a CustomVideoSource.
Definition source.h:376
MILLICAST_API Builder() noexcept
Type type
Definition source.h:56
std::string unique_id
Definition source.h:59
int id
Definition source.h:57
std::string name
Definition source.h:58
The Builder struct to build a video source.
Definition source.h:167
std::vector< VideoCapabilities > capabilities
Definition source.h:169
MILLICAST_API Ptr build() noexcept
Create a new video source.
MILLICAST_API Builder() noexcept=default