MillicastSDK 1.8.4
Loading...
Searching...
No Matches
viewer.h
Go to the documentation of this file.
1#ifndef MILLICAST_API_VIEWER_H
2#define MILLICAST_API_VIEWER_H
3
12
13namespace millicast {
14
15// Forward declarations ///////////////////////////////////////////////////////
16class VideoTrack;
17class AudioTrack;
18
19// Viewer /////////////////////////////////////////////////////////////////////
20
21struct ViewerOption : public ClientOption {
22 /* multisource options */
23 struct {
24 std::optional<std::string>
26 std::optional<uint8_t>
29 std::vector<std::string>
32
33 /* forcing the media server to process frames with no delay */
35
36 /* disable receiving audio completely. This should help reduce A/V sync
37 * related delays for video only streams */
38 bool disable_audio{false};
39
40 /* set the video jitter buffer minimum delay in milliseconds. Defaults to
41 * 0*/
43};
44
51 bool is_valid;
54 std::string stream_name;
56 std::optional<std::string> token;
57 std::string account_id;
58 std::string
60};
61
68 struct Resolution {
69 int width;
70 int height;
71 };
72 std::string encoding_id;
73 int bitrate = 0;
74 std::optional<int> temporal_layer_id;
75 std::optional<int> spatial_layer_id;
77 std::optional<Resolution> layer_resolution;
79 std::optional<int> max_temporal_layer_id;
81 std::optional<int> max_spatial_layer_id;
82};
83
90 std::string track_id;
92 std::string
94 std::string mid;
95 std::optional<ViewerLayerData>
97};
98
111 virtual void on_subscribed() = 0;
112
117 virtual void on_subscribed_error(const std::string& error) = 0;
118
125 virtual void on_track(std::weak_ptr<VideoTrack> track,
126 const std::optional<std::string>& mid) = 0;
127
134 virtual void on_track(std::weak_ptr<AudioTrack> track,
135 const std::optional<std::string>& mid) = 0;
136
137 /* Broadcast events */
138
145 virtual void on_active(const std::string& stream_id,
146 const std::vector<TrackInfo>& tracks,
147 const std::optional<std::string>& source_id) = 0;
148
154 virtual void on_inactive(const std::string& stream_id,
155 const std::optional<std::string>& source_id) = 0;
156
161 virtual void on_stopped() = 0;
162
169 virtual void on_vad(const std::string& mid,
170 const std::optional<std::string>& source_id) = 0;
171
178 virtual void on_layers(const std::string& mid,
179 const std::vector<ViewerLayerData>& active_layers,
180 const std::vector<std::string>& inactive_layers) = 0;
181
189 virtual void on_frame_metadata(uint32_t ssrc,
190 uint32_t timestamp,
191 const std::vector<uint8_t>& data) {}
192};
193
194inline namespace compat {
200class MILLICAST_API Viewer : public virtual Client {
201 public:
215 virtual bool subscribe(
216 const std::optional<Viewer::Option>& options = std::nullopt) = 0;
217
223 virtual bool unsubscribe() = 0;
224
229 [[nodiscard]] virtual bool is_subscribed() const = 0;
230
238 virtual bool project(const std::string& source_id,
239 const std::vector<ProjectionData>& pdata) = 0;
240
246 virtual bool unproject(const std::vector<std::string>& mids) = 0;
247
255 virtual bool select(std::optional<LayerData> layer) = 0;
256
265 virtual bool add_remote_track(std::string_view kind) = 0;
266
273 virtual bool set_credentials(const Credentials& creds) = 0;
274 virtual bool set_credentials(Credentials&& creds) = 0;
275
280 [[nodiscard]] virtual Credentials get_credentials() const = 0;
281
287 virtual void set_listener(Viewer::Listener* listener) = 0;
288
293 static std::unique_ptr<Viewer> create();
294};
295} // namespace compat
296
297namespace promises {
303class MILLICAST_API Viewer : public virtual Client {
304 public:
315 std::optional<ViewerOption>&& options = std::nullopt) = 0;
316
322
328 [[nodiscard]] virtual Promise<bool> is_subscribed() const = 0;
329
330 // to be deprecated
331 virtual Promise<void> project(std::string&& source_id,
332 std::vector<ViewerProjectionData>&& pdata) = 0;
333
334 // to be deprecated
335 virtual Promise<void> unproject(std::vector<std::string>&& mids) = 0;
336
337 // to be deprecated
338 virtual Promise<void> select(std::optional<ViewerLayerData>&& layer) = 0;
339
340 // to be deprecated
341 virtual Promise<void> add_remote_track(std::string&& kind) = 0;
342
349
354 [[nodiscard]] virtual Promise<ViewerCredentials> get_credentials() const = 0;
355
362
369
374 static std::unique_ptr<Viewer> create();
375};
376} // namespace promises
377
378} // namespace millicast
379
380#endif /* MILLICAST_API_VIEWER_H */
Definition promise.h:45
The Client base class.
Definition client.h:194
The Viewer class. Its purpose is to receive media by subscribing to a millicast stream....
Definition viewer.h:200
virtual void set_listener(Viewer::Listener *listener)=0
set_listener : set the viewer listener to receive event from the viewer.
virtual bool set_credentials(const Credentials &creds)=0
Set the viewer credentials.
virtual bool add_remote_track(std::string_view kind)=0
Dynamically add another track to the peerconnection adn renegociate SDP locally When the track is cre...
virtual bool subscribe(const std::optional< Viewer::Option > &options=std::nullopt)=0
Subscribe to a Millicast stream. You must be connected first in order to subscribe to a stream.
virtual bool set_credentials(Credentials &&creds)=0
static std::unique_ptr< Viewer > create()
Create a new viewer.
virtual bool unsubscribe()=0
Stop receiving media from Millicast. The SDK will automatically disconnect after unsubscribe.
virtual bool unproject(const std::vector< std::string > &mids)=0
Send a command to stop the projection of a source.
virtual bool project(const std::string &source_id, const std::vector< ProjectionData > &pdata)=0
Send a command to the media server to forward a media into a specific transceiver.
virtual Credentials get_credentials() const =0
Get the current viewer credentials.
virtual bool select(std::optional< LayerData > layer)=0
Send a command to select a simulcast layer (if simulcast is enabled).
virtual bool is_subscribed() const =0
Tell whether the viewer is subscribed or not.
The Client base class.
Definition client.h:265
The Viewer class. Its purpose is to receive media by subscribing to a millicast stream....
Definition viewer.h:303
virtual Promise< void > unproject(std::vector< std::string > &&mids)=0
virtual Promise< void > select(std::optional< ViewerLayerData > &&layer)=0
virtual compat::Viewer & get_old_api()=0
Gets the synchronous API for this viewer. Note that it will be deprecated in the future.
virtual Promise< void > set_listener(ViewerListener *listener)=0
set_listener : set the viewer listener to receive event from the viewer.
virtual Promise< ViewerCredentials > get_credentials() const =0
Get the current viewer credentials.
virtual Promise< void > project(std::string &&source_id, std::vector< ViewerProjectionData > &&pdata)=0
virtual Promise< void > set_credentials(ViewerCredentials &&creds)=0
Set the viewer credentials.
static std::unique_ptr< Viewer > create()
Create a new viewer.
virtual Promise< void > subscribe(std::optional< ViewerOption > &&options=std::nullopt)=0
Subscribe to a Millicast stream. You must be connected first in order to subscribe to a stream.
virtual Promise< bool > is_subscribed() const =0
Tell if the viewer is subscribed.
virtual Promise< void > unsubscribe()=0
Stop receiving media from Millicast.
virtual Promise< void > add_remote_track(std::string &&kind)=0
#define MILLICAST_API
Definition exports.h:51
Definition capabilities.h:15
The Client Listener struct which contains methods that will be called on specific events from a Clien...
Definition client.h:70
The ClientOption struct allows to setup the millicast connection.
Definition client.h:134
The ViewerCredentials struct represent the credentials need to be able to connect and subscribe to a ...
Definition viewer.h:50
bool is_valid
Definition viewer.h:51
std::string stream_name
Definition viewer.h:54
std::string api_url
Definition viewer.h:59
std::string account_id
Definition viewer.h:57
std::optional< std::string > token
Definition viewer.h:56
Represents resolution of a video frame.
Definition viewer.h:68
int width
Definition viewer.h:69
int height
Definition viewer.h:70
The layer data is used to select a simulcast/svc layer. by sending a command to the server using the ...
Definition viewer.h:66
std::optional< Resolution > layer_resolution
The resolution of the frame for simulcast / SVC layer.
Definition viewer.h:77
std::string encoding_id
Definition viewer.h:72
std::optional< int > temporal_layer_id
Definition viewer.h:74
std::optional< int > max_temporal_layer_id
Max temporal layer to be used. Set by application when calling select.
Definition viewer.h:79
std::optional< int > max_spatial_layer_id
Max spatial layer id to be used, Set by application when calling select.
Definition viewer.h:81
std::optional< int > spatial_layer_id
Definition viewer.h:75
int bitrate
Definition viewer.h:73
The Listener struct for the Viewer class. It adds the on_subscribed event on top of the Client listen...
Definition viewer.h:105
virtual void on_stopped()=0
onStopped callback is not currently used, but is reserved for future usage.
virtual void on_track(std::weak_ptr< AudioTrack > track, const std::optional< std::string > &mid)=0
on_track is called when a remote audio track has been added.
virtual void on_frame_metadata(uint32_t ssrc, uint32_t timestamp, const std::vector< uint8_t > &data)
Called when a frame is received and not yet decoded Extract metadata embedded in the frame if any.
Definition viewer.h:189
virtual void on_track(std::weak_ptr< VideoTrack > track, const std::optional< std::string > &mid)=0
on_track is called when a remote video track has been added.
virtual void on_subscribed()=0
on_subscribed is called when the subcription to the stream is complete.
virtual void on_active(const std::string &stream_id, const std::vector< TrackInfo > &tracks, const std::optional< std::string > &source_id)=0
Called when a new source has been publishing within the new stream.
virtual void on_inactive(const std::string &stream_id, const std::optional< std::string > &source_id)=0
Called when a source has been unpublished within the stream.
virtual void on_vad(const std::string &mid, const std::optional< std::string > &source_id)=0
Called when a source id is being multiplexed into the audio track based on the voice activity level.
virtual void on_layers(const std::string &mid, const std::vector< ViewerLayerData > &active_layers, const std::vector< std::string > &inactive_layers)=0
Called when simulcast/svc layers are available.
virtual void on_subscribed_error(const std::string &error)=0
Called when an error occured while establishing the peerconnection.
Definition viewer.h:21
bool force_playout_delay
Definition viewer.h:34
std::optional< uint8_t > multiplexed_audio_track
Definition viewer.h:27
std::vector< std::string > excluded_source_id
Definition viewer.h:30
struct millicast::ViewerOption::@2 multisource
int video_jitter_minimum_delay_ms
Definition viewer.h:42
std::optional< std::string > pinned_source_id
Definition viewer.h:25
bool disable_audio
Definition viewer.h:38
The projection data is used to project a video/audio track into a specific transceiver....
Definition viewer.h:89
std::string mid
Definition viewer.h:94
std::optional< ViewerLayerData > layer
Definition viewer.h:96
std::string track_id
Definition viewer.h:90
std::string media
Definition viewer.h:93