1 /*
2 mediastreamer2 library - modular sound and video processing and streaming
3 Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20
21 #ifndef MEDIASTREAM_H
22 #define MEDIASTREAM_H
23
24 #include <ortp/ortp.h>
25 #include <ortp/event.h>
26
27 #include <mediastreamer2/msfactory.h>
28 #include <mediastreamer2/msfilter.h>
29 #include <mediastreamer2/msticker.h>
30 #include <mediastreamer2/mssndcard.h>
31 #include <mediastreamer2/mswebcam.h>
32 #include <mediastreamer2/msvideo.h>
33 #include <mediastreamer2/bitratecontrol.h>
34 #include <mediastreamer2/qualityindicator.h>
35 #include <mediastreamer2/ice.h>
36 #include <mediastreamer2/zrtp.h>
37 #include <mediastreamer2/dtls_srtp.h>
38 #include <mediastreamer2/ms_srtp.h>
39 #include <mediastreamer2/msequalizer.h>
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /**
46 * @addtogroup ring_api
47 * @{
48 **/
49
50 struct _RingStream
51 {
52 MSTicker *ticker;
53 MSFilter *source;
54 MSFilter *gendtmf;
55 MSFilter *write_resampler;
56 MSFilter *sndwrite;
57 MSFilter *decoder;
58 int srcpin;
59 };
60
61 typedef struct _RingStream RingStream;
62
63 MS2_PUBLIC RingStream *ring_start(MSFactory *factory, const char * file, int interval, MSSndCard *sndcard);
64 MS2_PUBLIC RingStream *ring_start_with_cb(MSFactory *factory, const char * file, int interval, MSSndCard *sndcard, MSFilterNotifyFunc func, void * user_data);
65 MS2_PUBLIC void ring_stop (RingStream * stream);
66
67 /**
68 * @}
69 **/
70 /**
71 * The MediaStream is an object describing a stream (one of AudioStream or VideoStream).
72 **/
73 typedef struct _MediaStream MediaStream;
74
75 /*
76 * internal cb to process rtcp stream
77 * */
78 typedef void (*media_stream_process_rtcp_callback_t)(MediaStream *stream, mblk_t *m);
79
80 struct _MSMediaStreamSessions{
81 RtpSession *rtp_session;
82 MSSrtpCtx* srtp_context;
83 MSZrtpContext *zrtp_context;
84 MSDtlsSrtpContext *dtls_context;
85 MSTicker *ticker;
86 };
87
88 #ifndef MS_MEDIA_STREAM_SESSIONS_DEFINED
89 typedef struct _MSMediaStreamSessions MSMediaStreamSessions;
90 #define MS_MEDIA_STREAM_SESSIONS_DEFINED 1
91 #endif
92
93 MS2_PUBLIC void ms_media_stream_sessions_uninit(MSMediaStreamSessions *sessions);
94
95 typedef enum _MSStreamState{
96 MSStreamInitialized,
97 MSStreamPreparing,
98 MSStreamStarted,
99 MSStreamStopped
100 }MSStreamState;
101
102
103 typedef enum MediaStreamDir{
104 MediaStreamSendRecv,
105 MediaStreamSendOnly,
106 MediaStreamRecvOnly
107 }MediaStreamDir;
108
109 /**
110 * Base struct for both AudioStream and VideoStream structure.
111 **/
112 struct _MediaStream {
113 MSFormatType type;
114 MSStreamState state;
115 MSMediaStreamSessions sessions;
116 OrtpEvQueue *evq;
117 MSFilter *rtprecv;
118 MSFilter *rtpsend;
119 MSFilter *encoder;
120 MSFilter *decoder;
121 MSFilter *voidsink;
122 MSBitrateController *rc;
123 MSQualityIndicator *qi;
124 IceCheckList *ice_check_list;
125 time_t start_time;
126 time_t last_iterate_time;
127 uint64_t last_packet_count;
128 time_t last_packet_time;
129 MSQosAnalyzerAlgorithm rc_algorithm;
130 PayloadType *current_pt;/*doesn't need to be freed*/
131 bool_t rc_enable;
132 bool_t is_beginning;
133 bool_t owns_sessions;
134 bool_t pad;
135 /**
136 * defines encoder target network bit rate, uses #media_stream_set_target_network_bitrate() setter.
137 * */
138 int target_bitrate;
139 media_stream_process_rtcp_callback_t process_rtcp;
140 OrtpEvDispatcher *evd;
141 MSFactory *factory;
142 MSBandwidthController *bandwidth_controller;
143 };
144
145 MS2_PUBLIC void media_stream_init(MediaStream *stream, MSFactory *factory, const MSMediaStreamSessions *sessions);
146
147
148 /**
149 * @addtogroup audio_stream_api
150 * @{
151 **/
152
153 MS2_PUBLIC bool_t media_stream_started(MediaStream *stream);
154
155 MS2_PUBLIC int media_stream_join_multicast_group(MediaStream *stream, const char *ip);
156
157 MS2_PUBLIC bool_t media_stream_dtls_supported(void);
158
159 /* enable DTLS on the media stream */
160 MS2_PUBLIC void media_stream_enable_dtls(MediaStream *stream, MSDtlsSrtpParams *params);
161
162 MS2_PUBLIC void media_stream_set_rtcp_information(MediaStream *stream, const char *cname, const char *tool);
163
164 MS2_PUBLIC void media_stream_get_local_rtp_stats(MediaStream *stream, rtp_stats_t *stats);
165
166 MS2_PUBLIC int media_stream_set_dscp(MediaStream *stream, int dscp);
167
168 MS2_PUBLIC void media_stream_enable_adaptive_bitrate_control(MediaStream *stream, bool_t enabled);
169
170 MS2_PUBLIC void media_stream_set_adaptive_bitrate_algorithm(MediaStream *stream, MSQosAnalyzerAlgorithm algorithm);
171
172 MS2_PUBLIC void media_stream_enable_adaptive_jittcomp(MediaStream *stream, bool_t enabled);
173
174 MS2_PUBLIC void media_stream_set_ice_check_list(MediaStream *stream, IceCheckList *cl);
175
176 /*
177 * deprecated, use media_stream_set_srtp_recv_key and media_stream_set_srtp_send_key.
178 **/
179 MS2_PUBLIC bool_t media_stream_enable_srtp(MediaStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key);
180
181 /**
182 * @param[in] stream MediaStream object
183 * @return true if stream is encrypted
184 * */
185 MS2_PUBLIC bool_t media_stream_secured(const MediaStream *stream);
186 #define media_stream_is_secured media_stream_secured
187
188 /**
189 * Tells whether AVPF is enabled or not.
190 * @param[in] stream #MediaStream object.
191 * @return True if AVPF is enabled, false otherwise.
192 */
193 MS2_PUBLIC bool_t media_stream_avpf_enabled(const MediaStream *stream);
194
195 /**
196 * Gets the AVPF Regular RTCP report interval.
197 * @param[in] stream #MediaStream object.
198 * @return The AVPF Regular RTCP report interval in seconds.
199 */
200 MS2_PUBLIC uint16_t media_stream_get_avpf_rr_interval(const MediaStream *stream);
201
202 /**
203 * Gets the RTP session of the media stream.
204 * @param[in] stream #MediaStream object.
205 * @return The RTP session of the media stream.
206 */
207 MS2_PUBLIC RtpSession * media_stream_get_rtp_session(const MediaStream *stream);
208
209 MS2_PUBLIC const MSQualityIndicator *media_stream_get_quality_indicator(MediaStream *stream);
210 /* *
211 * returns a realtime indicator of the stream quality between 0 and 5
212 * */
213 MS2_PUBLIC float media_stream_get_quality_rating(MediaStream *stream);
214
215 MS2_PUBLIC float media_stream_get_average_quality_rating(MediaStream *stream);
216
217 MS2_PUBLIC float media_stream_get_lq_quality_rating(MediaStream *stream);
218
219 MS2_PUBLIC float media_stream_get_average_lq_quality_rating(MediaStream *stream);
220
221 /**
222 * <br>For multirate codecs like OPUS, encoder output target bitrate must be set.
223 * <br>Encoder will compute output codec bitrate from this value.
224 * <br> default value is the value corresponding the rtp PayloadType
225 * @param stream stream to apply parameter on
226 * @param target_bitrate in bit per seconds
227 * @return 0 if succeed
228 * */
229 MS2_PUBLIC int media_stream_set_target_network_bitrate(MediaStream *stream,int target_bitrate);
230
231 /**
232 * get the stream target bitrate.
233 * @param stream stream to apply parameter on
234 * @return target_bitrate in bit per seconds
235 * */
236 MS2_PUBLIC int media_stream_get_target_network_bitrate(const MediaStream *stream);
237
238 /**
239 * get current stream upload bitrate. Value is updated every seconds
240 * @param stream
241 * @return bitrate in bit per seconds
242 * */
243 MS2_PUBLIC float media_stream_get_up_bw(const MediaStream *stream);
244
245 /**
246 * get current stream download bitrate. Value is updated every seconds
247 * @param stream
248 * @return bitrate in bit per seconds
249 * */
250 MS2_PUBLIC float media_stream_get_down_bw(const MediaStream *stream);
251
252 /**
253 * get current stream rtcp upload bitrate. Value is updated every seconds
254 * @param stream
255 * @return bitrate in bit per seconds
256 * */
257 MS2_PUBLIC float media_stream_get_rtcp_up_bw(const MediaStream *stream);
258
259 /**
260 * get current stream rtcp download bitrate. Value is updated every seconds
261 * @param stream
262 * @return bitrate in bit per seconds
263 * */
264 MS2_PUBLIC float media_stream_get_rtcp_down_bw(const MediaStream *stream);
265
266 /**
267 * Returns the sessions that were used in the media stream (RTP, SRTP, ZRTP...) so that they can be re-used.
268 * As a result of calling this function, the media stream no longer owns the sessions and thus will not free them.
269 **/
270 MS2_PUBLIC void media_stream_reclaim_sessions(MediaStream *stream, MSMediaStreamSessions *sessions);
271
272
273 MS2_PUBLIC void media_stream_iterate(MediaStream * stream);
274
275 /**
276 * Returns TRUE if stream was still actively receiving packets (RTP or RTCP) in the last period specified in timeout_seconds.
277 **/
278 MS2_PUBLIC bool_t media_stream_alive(MediaStream *stream, int timeout_seconds);
279
280 /**
281 * @return current streams state
282 * */
283 MS2_PUBLIC MSStreamState media_stream_get_state(const MediaStream *stream);
284
285 MS2_PUBLIC OrtpEvDispatcher* media_stream_get_event_dispatcher(const MediaStream *stream);
286
287 typedef enum EchoLimiterType{
288 ELInactive,
289 ELControlMic,
290 ELControlFull
291 } EchoLimiterType;
292
293
294 typedef enum EqualizerLocation {
295 MSEqualizerHP = 0,
296 MSEqualizerMic
297 } EqualizerLocation;
298
299
300 typedef enum MSResourceType{
301 MSResourceInvalid,
302 MSResourceDefault,
303 MSResourceFile,
304 MSResourceRtp,
305 MSResourceCamera,
306 MSResourceSoundcard
307 }MSResourceType;
308
309 MS2_PUBLIC const char *ms_resource_type_to_string(MSResourceType type);
310
311 /**
312 * Structure describing the input or the output of a MediaStream.
313 * type must be set to one the member of the MSResourceType enum, and the correspoding
314 * resource argument must be set: the file name (const char*) for MSResourceFile,
315 * the RtpSession for MSResourceRtp, an MSWebCam for MSResourceCamera, an MSSndCard for MSResourceSoundcard.
316 * @warning due to implementation, if RTP is to be used for input and output, the same RtpSession must be passed for both sides.
317 */
318 typedef struct _MSMediaResource{
319 MSResourceType type;
320 union{
321 void *resource_arg;
322 const char *file;
323 RtpSession *session;
324 MSWebCam *camera;
325 MSSndCard *soundcard;
326 };
327 }MSMediaResource;
328
329
330 MS2_PUBLIC bool_t ms_media_resource_is_consistent(const MSMediaResource *r);
331 #define ms_media_resource_get_file(r) (((r)->type == MSResourceFile) ? (r)->file : NULL)
332 #define ms_media_resource_get_rtp_session(r) (((r)->type == MSResourceRtp) ? (r)->session : NULL)
333 #define ms_media_resource_get_camera(r) (((r)->type == MSResourceCamera) ? (r)->camera : NULL)
334 #define ms_media_resource_get_soundcard(r) (((r)->type == MSResourceSoundcard) ? (r)->souncard : NULL)
335 /**
336 * Structure describing the input/output of a MediaStream.
337 * Input and output are described as MSMediaResource.
338 */
339 typedef struct _MSMediaStreamIO {
340 MSMediaResource input;
341 MSMediaResource output;
342 } MSMediaStreamIO;
343
344 #define MS_MEDIA_STREAM_IO_INITIALIZER { {0}, {0} }
345
346 MS2_PUBLIC bool_t ms_media_stream_io_is_consistent(const MSMediaStreamIO *io);
347
348 struct _AudioStream
349 {
350 MediaStream ms;
351 MSFilter *soundread;
352 MSFilter *soundwrite;
353 MSFilter *dtmfgen;
354 MSFilter *dtmfgen_rtp;
355 MSFilter *plc;
356 MSFilter *ec;/*echo canceler*/
357 MSFilter *volsend,*volrecv; /*MSVolumes*/
358 MSFilter *local_mixer;
359 MSFilter *local_player;
360 MSFilter *local_player_resampler;
361 MSFilter *read_decoder; /* Used when the input is done via RTP */
362 MSFilter *write_encoder; /* Used when the output is done via RTP */
363 MSFilter *read_resampler;
364 MSFilter *write_resampler;
365 MSFilter *mic_equalizer;
366 MSFilter *spk_equalizer;
367 MSFilter *dummy;
368 MSFilter *recv_tee;
369 MSFilter *recorder_mixer;
370 MSFilter *recorder;
371 MSFilter *outbound_mixer;
372 struct {
373 MSFilter *resampler;
374 MSFilter *encoder;
375 MSFilter *recorder;
376 MSFilter *video_input;
377 }av_recorder;
378 struct _AVPlayer{
379 MSFilter *player;
380 MSFilter *resampler;
381 MSFilter *decoder;
382 MSFilter *video_output;
383 int audiopin;
384 int videopin;
385 bool_t plumbed;
386 }av_player;
387 MSFilter *flowcontrol;
388 RtpSession *rtp_io_session; /**< The RTP session used for RTP input/output. */
389 MSFilter *vaddtx;
390 char *recorder_file;
391 EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/
392 EqualizerLocation eq_loc;
393 uint32_t features;
394 int sample_rate;
395 int nchannels;
396 struct _VideoStream *videostream;/*the stream with which this audiostream is paired*/
397 MSAudioRoute audio_route;
398 bool_t play_dtmfs;
399 bool_t use_ec;
400 bool_t use_gc;
401 bool_t use_agc;
402
403 bool_t mic_eq_active;
404 bool_t spk_eq_active;
405 bool_t use_ng;/*noise gate*/
406 bool_t is_ec_delay_set;
407 };
408
409 /**
410 * The AudioStream holds all resources to create and run typical VoIP audiostream.
411 **/
412 typedef struct _AudioStream AudioStream;
413
414
415 /* start a thread that does sampling->encoding->rtp_sending|rtp_receiving->decoding->playing */
416 MS2_PUBLIC AudioStream *audio_stream_start(MSFactory* factory, RtpProfile * prof, int locport, const char *remip,
417 int remport, int payload_type, int jitt_comp, bool_t echo_cancel);
418
419 MS2_PUBLIC AudioStream *audio_stream_start_with_sndcards(MSFactory* factory, RtpProfile* prof, int locport, const char *remip4, int remport, int payload_type, int jitt_comp, MSSndCard *playcard,
420 MSSndCard *captcard, bool_t echocancel);
421
422 MS2_PUBLIC int audio_stream_start_with_files (AudioStream * stream, RtpProfile * prof,
423 const char *remip, int remport, int rem_rtcp_port,
424 int pt, int jitt_comp,
425 const char * infile, const char * outfile);
426
427 /**
428 * Start an audio stream according to the specified AudioStreamIO.
429 *
430 * @param[in] stream AudioStream object previously created with audio_stream_new().
431 * @param[in] profile RtpProfile object holding the PayloadType that can be used during the audio session.
432 * @param[in] rem_rtp_ip The remote IP address where to send the encoded audio to.
433 * @param[in] rem_rtp_port The remote port where to send the encoded audio to.
434 * @param[in] rem_rtcp_ip The remote IP address for RTCP.
435 * @param[in] rem_rtcp_port The remote port for RTCP.
436 * @param[in] payload_type The payload type number used to send the audio stream. A valid PayloadType must be available at this index in the profile.
437 * @param[in] io A MSMediaStreamIO describing the local input/output of the audio stream.
438 */
439 MS2_PUBLIC int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port,
440 const char *rem_rtcp_ip, int rem_rtcp_port, int payload_type, const MSMediaStreamIO *io);
441
442 /**
443 * Starts an audio stream from/to local wav files or soundcards.
444 *
445 * This method starts the processing of the audio stream, that is playing from wav file or soundcard, voice processing, encoding,
446 * sending through RTP, receiving from RTP, decoding, voice processing and wav file recording or soundcard playback.
447 *
448 *
449 * @param stream an AudioStream previously created with audio_stream_new().
450 * @param profile a RtpProfile containing all PayloadType possible during the audio session.
451 * @param rem_rtp_ip remote IP address where to send the encoded audio.
452 * @param rem_rtp_port remote IP port where to send the encoded audio.
453 * @param rem_rtcp_ip remote IP address for RTCP.
454 * @param rem_rtcp_port remote port for RTCP.
455 * @param payload payload type index to use for the sending stream. This index must point to a valid PayloadType in the RtpProfile.
456 * @param jitt_comp Nominal jitter buffer size in milliseconds.
457 * @param infile path to wav file to play out (can be NULL)
458 * @param outfile path to wav file to record into (can be NULL)
459 * @param playcard The soundcard to be used for playback (can be NULL)
460 * @param captcard The soundcard to be used for catpure. (can be NULL)
461 * @param use_ec whether echo cancellation is to be performed.
462 * @return 0 if sucessful, -1 otherwise.
463 **/
464 MS2_PUBLIC int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *rem_rtp_ip,int rem_rtp_port,
465 const char *rem_rtcp_ip, int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile,
466 MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec);
467
468
469 MS2_PUBLIC void audio_stream_play(AudioStream *st, const char *name);
470 MS2_PUBLIC void audio_stream_record(AudioStream *st, const char *name);
471
audio_stream_set_rtcp_information(AudioStream * st,const char * cname,const char * tool)472 static MS2_INLINE void audio_stream_set_rtcp_information(AudioStream *st, const char *cname, const char *tool) {
473 media_stream_set_rtcp_information(&st->ms, cname, tool);
474 }
475
476 MS2_PUBLIC void audio_stream_play_received_dtmfs(AudioStream *st, bool_t yesno);
477
478 /**
479 * Creates an AudioStream object listening on a RTP port.
480 * @param loc_rtp_port the local UDP port to listen for RTP packets.
481 * @param loc_rtcp_port the local UDP port to listen for RTCP packets
482 * @param ipv6 TRUE if ipv6 must be used.
483 * @param factory
484 * @return a new AudioStream.
485 **/
486 MS2_PUBLIC AudioStream *audio_stream_new(MSFactory* factory, int loc_rtp_port, int loc_rtcp_port, bool_t ipv6);
487
488 /**
489 * Creates an AudioStream object listening on a RTP port for a dedicated address.
490 * @param loc_ip the local ip to listen for RTP packets. Can be ::, O.O.O.O or any ip4/6 addresses
491 * @param loc_rtp_port the local UDP port to listen for RTP packets.
492 * @param loc_rtcp_port the local UDP port to listen for RTCP packets
493 * @param factory
494 * @return a new AudioStream.
495 **/
496 MS2_PUBLIC AudioStream *audio_stream_new2(MSFactory* factory, const char* ip, int loc_rtp_port, int loc_rtcp_port);
497
498
499 /**Creates an AudioStream object from initialized MSMediaStreamSessions.
500 * @param sessions the MSMediaStreamSessions
501 * @param factory the MSFActory from the core object
502 * @return a new AudioStream
503 **/
504 MS2_PUBLIC AudioStream *audio_stream_new_with_sessions(MSFactory* factory, const MSMediaStreamSessions *sessions);
505
506 #define AUDIO_STREAM_FEATURE_PLC (1 << 0)
507 #define AUDIO_STREAM_FEATURE_EC (1 << 1)
508 #define AUDIO_STREAM_FEATURE_EQUALIZER (1 << 2)
509 #define AUDIO_STREAM_FEATURE_VOL_SND (1 << 3)
510 #define AUDIO_STREAM_FEATURE_VOL_RCV (1 << 4)
511 #define AUDIO_STREAM_FEATURE_DTMF (1 << 5)
512 #define AUDIO_STREAM_FEATURE_DTMF_ECHO (1 << 6)
513 #define AUDIO_STREAM_FEATURE_MIXED_RECORDING (1 << 7)
514 #define AUDIO_STREAM_FEATURE_LOCAL_PLAYING (1 << 8)
515 #define AUDIO_STREAM_FEATURE_REMOTE_PLAYING (1 << 9)
516 #define AUDIO_STREAM_FEATURE_FLOW_CONTROL (1 << 10)
517
518 #define AUDIO_STREAM_FEATURE_ALL (\
519 AUDIO_STREAM_FEATURE_PLC | \
520 AUDIO_STREAM_FEATURE_EC | \
521 AUDIO_STREAM_FEATURE_EQUALIZER | \
522 AUDIO_STREAM_FEATURE_VOL_SND | \
523 AUDIO_STREAM_FEATURE_VOL_RCV | \
524 AUDIO_STREAM_FEATURE_DTMF | \
525 AUDIO_STREAM_FEATURE_DTMF_ECHO |\
526 AUDIO_STREAM_FEATURE_MIXED_RECORDING |\
527 AUDIO_STREAM_FEATURE_LOCAL_PLAYING | \
528 AUDIO_STREAM_FEATURE_REMOTE_PLAYING | \
529 AUDIO_STREAM_FEATURE_FLOW_CONTROL \
530 )
531
532
533 MS2_PUBLIC uint32_t audio_stream_get_features(AudioStream *st);
534 MS2_PUBLIC void audio_stream_set_features(AudioStream *st, uint32_t features);
535
536 MS2_PUBLIC void audio_stream_prepare_sound(AudioStream *st, MSSndCard *playcard, MSSndCard *captcard);
537 MS2_PUBLIC void audio_stream_unprepare_sound(AudioStream *st);
538 MS2_PUBLIC bool_t audio_stream_started(AudioStream *stream);
539 /**
540 * Starts an audio stream from local soundcards.
541 *
542 * This method starts the processing of the audio stream, that is capture from soundcard, voice processing, encoding,
543 * sending through RTP, receiving from RTP, decoding, voice processing and soundcard playback.
544 *
545 * @param stream an AudioStream previously created with audio_stream_new().
546 * @param prof a RtpProfile containing all PayloadType possible during the audio session.
547 * @param remip remote IP address where to send the encoded audio.
548 * @param remport remote IP port where to send the encoded audio
549 * @param rem_rtcp_port remote port for RTCP.
550 * @param payload_type payload type index to use for the sending stream. This index must point to a valid PayloadType in the RtpProfile.
551 * @param jitt_comp Nominal jitter buffer size in milliseconds.
552 * @param playcard The soundcard to be used for playback
553 * @param captcard The soundcard to be used for catpure.
554 * @param echo_cancel whether echo cancellation is to be performed.
555 **/
556 MS2_PUBLIC int audio_stream_start_now(AudioStream * stream, RtpProfile * prof, const char *remip, int remport, int rem_rtcp_port, int payload_type, int jitt_comp,MSSndCard *playcard, MSSndCard *captcard, bool_t echo_cancel);
557 MS2_PUBLIC void audio_stream_set_relay_session_id(AudioStream *stream, const char *relay_session_id);
558 /*returns true if we are still receiving some data from remote end in the last timeout seconds*/
559 MS2_PUBLIC bool_t audio_stream_alive(AudioStream * stream, int timeout);
560
561 /**
562 * Executes background low priority tasks related to audio processing (RTP statistics analysis).
563 * It should be called periodically, for example with an interval of 100 ms or so.
564 */
565 MS2_PUBLIC void audio_stream_iterate(AudioStream *stream);
566
567 /**
568 * enable echo-limiter dispositve: one MSVolume in input branch controls a MSVolume in the output branch
569 * */
570 MS2_PUBLIC void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type);
571
572 /**
573 * enable gain control, to be done before start()
574 * */
575 MS2_PUBLIC void audio_stream_enable_gain_control(AudioStream *stream, bool_t val);
576
577 /**
578 * enable automatic gain control, to be done before start()
579 * */
580 MS2_PUBLIC void audio_stream_enable_automatic_gain_control(AudioStream *stream, bool_t val);
581
582 /**
583 * to be done before start
584 * */
585 MS2_PUBLIC void audio_stream_set_echo_canceller_params(AudioStream *st, int tail_len_ms, int delay_ms, int framesize);
586
587
588 /**
589 * to be done before start
590 * */
591 MS2_PUBLIC void audio_stream_enable_echo_canceller(AudioStream *st, bool_t enabled);
592 /**
593 * enable adaptive rate control
594 * */
audio_stream_enable_adaptive_bitrate_control(AudioStream * stream,bool_t enabled)595 static MS2_INLINE void audio_stream_enable_adaptive_bitrate_control(AudioStream *stream, bool_t enabled) {
596 media_stream_enable_adaptive_bitrate_control(&stream->ms, enabled);
597 }
598
599 /**
600 * Enable adaptive jitter compensation
601 * */
audio_stream_enable_adaptive_jittcomp(AudioStream * stream,bool_t enabled)602 static MS2_INLINE void audio_stream_enable_adaptive_jittcomp(AudioStream *stream, bool_t enabled) {
603 media_stream_enable_adaptive_jittcomp(&stream->ms, enabled);
604 }
605
606 /**
607 * Apply a software gain on the microphone.
608 * Be note that this method neither changes the volume gain
609 * of the sound card nor the system mixer one. If you intends
610 * to control the volume gain at sound card level, you should
611 * use audio_stream_set_sound_card_input_gain() instead.
612 *
613 * @param stream The stream.
614 * @param gain_db Gain to apply in dB.
615 */
616 MS2_PUBLIC void audio_stream_set_mic_gain_db(AudioStream *stream, float gain_db);
617
618
619 /**
620 * Like audio_stream_set_mic_gain_db() excepted that the gain is specified
621 * in percentage.
622 *
623 * @param stream The stream.
624 * @param gain Gain to apply in percetage of the max supported gain.
625 */
626 MS2_PUBLIC void audio_stream_set_mic_gain(AudioStream *stream, float gain);
627
628 /**
629 * enable/disable rtp stream
630 */
631 MS2_PUBLIC void audio_stream_mute_rtp(AudioStream *stream, bool_t val);
632
633 /**
634 * Apply a gain on received RTP packets.
635 * @param stream An AudioStream.
636 * @param gain_db Gain to apply in dB.
637 */
638 MS2_PUBLIC void audio_stream_set_spk_gain_db(AudioStream *stream, float gain_db);
639
640 /**
641 * Set microphone volume gain.
642 * If the sound backend supports it, the set volume gain will be synchronized
643 * with the host system mixer. If you intended to apply a static software gain,
644 * you should use audio_stream_set_mic_gain_db() or audio_stream_set_mic_gain().
645 *
646 * @param stream The audio stream.
647 * @param gain Percentage of the max supported volume gain. Valid values are in [0.0 : 1.0].
648 */
649 MS2_PUBLIC void audio_stream_set_sound_card_input_gain(AudioStream *stream, float gain);
650
651 /**
652 * Get microphone volume gain.
653 * @param stream The audio stream.
654 * @return double Volume gain in percentage of the max suppored gain.
655 * Valid returned values are in [0.0 : 1.0]. A negative value is returned in case of failure.
656 */
657 MS2_PUBLIC float audio_stream_get_sound_card_input_gain(const AudioStream *stream);
658
659 /**
660 * Set speaker volume gain.
661 * If the sound backend supports it, the set volume gain will be synchronized
662 * with the host system mixer.
663 * @param stream The audio stream.
664 * @param gain Percentage of the max supported volume gain. Valid values are in [0.0 : 1.0].
665 */
666 MS2_PUBLIC void audio_stream_set_sound_card_output_gain(AudioStream *stream, float volume);
667
668 /**
669 * Get speaker volume gain.
670 * @param stream The audio stream.
671 * @return Volume gain in percentage of the max suppored gain.
672 * Valid returned values are in [0.0 : 1.0]. A negative value is returned in case of failure.
673 */
674 MS2_PUBLIC float audio_stream_get_sound_card_output_gain(const AudioStream *stream);
675
676 /**
677 * enable noise gate, must be done before start()
678 * */
679 MS2_PUBLIC void audio_stream_enable_noise_gate(AudioStream *stream, bool_t val);
680
681 /**
682 * Enable a parametric equalizer
683 * @param[in] stream An AudioStream
684 * @param[in] location Location of the equalizer to enable (speaker or microphone)
685 * @param[in] enabled Whether the equalizer must be enabled
686 */
687 MS2_PUBLIC void audio_stream_enable_equalizer(AudioStream *stream, EqualizerLocation location, bool_t enabled);
688
689 /**
690 * Apply a gain on a given frequency band.
691 * @param[in] stream An AudioStream
692 * @param[in] location Location of the concerned equalizer (speaker or microphone)
693 * @param[in] gain Description of the band and the gain to apply.
694 */
695 MS2_PUBLIC void audio_stream_equalizer_set_gain(AudioStream *stream, EqualizerLocation location, const MSEqualizerGain *gain);
696
697 /**
698 * stop the audio streaming thread and free everything
699 * */
700 MS2_PUBLIC void audio_stream_stop (AudioStream * stream);
701
702 /**
703 * send a dtmf
704 * */
705 MS2_PUBLIC int audio_stream_send_dtmf (AudioStream * stream, char dtmf);
706
707 MS2_PUBLIC MSFilter *audio_stream_get_local_player(AudioStream *stream);
708
709 MS2_PUBLIC int audio_stream_mixed_record_open(AudioStream *st, const char*filename);
710
711 MS2_PUBLIC int audio_stream_mixed_record_start(AudioStream *st);
712
713 MS2_PUBLIC int audio_stream_mixed_record_stop(AudioStream *st);
714
715 /**
716 * Open a player to play an audio/video file to remote end.
717 * The player is returned as a MSFilter so that application can make usual player controls on it using the MSPlayerInterface.
718 **/
719 MS2_PUBLIC MSFilter * audio_stream_open_remote_play(AudioStream *stream, const char *filename);
720
721 MS2_PUBLIC void audio_stream_close_remote_play(AudioStream *stream);
722
723 MS2_PUBLIC void audio_stream_set_default_card(int cardindex);
724
725 /* retrieve RTP statistics*/
audio_stream_get_local_rtp_stats(AudioStream * stream,rtp_stats_t * stats)726 static MS2_INLINE void audio_stream_get_local_rtp_stats(AudioStream *stream, rtp_stats_t *stats) {
727 media_stream_get_local_rtp_stats(&stream->ms, stats);
728 }
729
730 /* returns a realtime indicator of the stream quality between 0 and 5 */
731 MS2_PUBLIC float audio_stream_get_quality_rating(AudioStream *stream);
732
733 /* returns the quality rating as an average since the start of the streaming session.*/
734 MS2_PUBLIC float audio_stream_get_average_quality_rating(AudioStream *stream);
735
736 /* returns a realtime indicator of the listening quality of the stream between 0 and 5 */
737 MS2_PUBLIC float audio_stream_get_lq_quality_rating(AudioStream *stream);
738
739 /* returns the listening quality rating as an average since the start of the streaming session.*/
740 MS2_PUBLIC float audio_stream_get_average_lq_quality_rating(AudioStream *stream);
741
742 /* enable ZRTP on the audio stream */
743 MS2_PUBLIC void audio_stream_enable_zrtp(AudioStream *stream, MSZrtpParams *params);
744 MS2_PUBLIC void audio_stream_start_zrtp(AudioStream *stream);
745
746 /**
747 * return TRUE if zrtp is enabled, it does not mean that stream is encrypted, but only that zrtp is configured to know encryption status, uses #
748 * */
749 bool_t audio_stream_zrtp_enabled(const AudioStream *stream);
750
751 /* enable SRTP on the audio stream */
audio_stream_enable_srtp(AudioStream * stream,MSCryptoSuite suite,const char * snd_key,const char * rcv_key)752 static MS2_INLINE bool_t audio_stream_enable_srtp(AudioStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key) {
753 return media_stream_enable_srtp(&stream->ms, suite, snd_key, rcv_key);
754 }
755
audio_stream_set_dscp(AudioStream * stream,int dscp)756 static MS2_INLINE int audio_stream_set_dscp(AudioStream *stream, int dscp) {
757 return media_stream_set_dscp(&stream->ms, dscp);
758 }
759
760 /**
761 * Gets the RTP session of an audio stream.
762 * @param[in] stream #MediaStream object.
763 * @return The RTP session of the audio stream.
764 */
audio_stream_get_rtp_session(const AudioStream * stream)765 static MS2_INLINE RtpSession * audio_stream_get_rtp_session(const AudioStream *stream) {
766 return media_stream_get_rtp_session(&stream->ms);
767 }
768
769
770
771 /**
772 * @}
773 **/
774
775
776 /**
777 * @addtogroup video_stream_api
778 * @{
779 **/
780
781 typedef void (*VideoStreamRenderCallback)(void *user_pointer, const MSPicture *local_view, const MSPicture *remote_view);
782 typedef void (*VideoStreamEventCallback)(void *user_pointer, const MSFilter *f, const unsigned int event_id, const void *args);
783
784 struct _MediastreamVideoStat
785 {
786 int counter_rcvd_pli; /*Picture Loss Indication counter */
787 int counter_rcvd_sli;/* Slice Loss Indication counter */
788 int counter_rcvd_rpsi; /*Reference Picture Selection Indication */
789 int counter_rcvd_fir; /* Full INTRA-frame Request */
790 };
791
792 typedef struct _MediastreamVideoStat MediaStreamVideoStat;
793
794 struct _VideoStream
795 {
796 MediaStream ms;
797 MSFilter *void_source;
798 MSFilter *source;
799 MSFilter *pixconv;
800 MSFilter *sizeconv;
801 MSFilter *tee;
802 MSFilter *output;
803 MSFilter *tee2;
804 MSFilter *jpegwriter;
805 MSFilter *output2;
806 MSFilter *tee3;
807 MSFilter *recorder_output; /*can be an ItcSink to send video to the audiostream's multimedia recorder, or directly a MkvRecorder */
808 MSFilter *local_jpegwriter;
809 MSVideoSize sent_vsize;
810 MSVideoSize preview_vsize;
811 float forced_fps; /*the target fps explicitely set by application, overrides internally selected fps*/
812 float configured_fps; /*the fps that was configured to the encoder. It might be different from the one really obtained from camera.*/
813 float real_fps; /*the fps obtained from camera.*/
814 int corner; /*for selfview*/
815 VideoStreamRenderCallback rendercb;
816 void *render_pointer;
817 VideoStreamEventCallback eventcb;
818 void *event_pointer;
819 char *display_name;
820 void *window_id;
821 void *preview_window_id;
822 MediaStreamDir dir;
823 MSWebCam *cam;
824 RtpSession *rtp_io_session; /**< The RTP session used for RTP input/output. */
825 char *preset;
826 int device_orientation; /* warning: meaning of this variable depends on the platform (Android, iOS, ...) */
827 uint64_t last_reported_decoding_error_time;
828 uint64_t last_fps_check;
829 MediaStreamVideoStat ms_video_stat;
830 bool_t use_preview_window;
831 bool_t freeze_on_error;
832 bool_t display_filter_auto_rotate_enabled;
833 bool_t source_performs_encoding;
834
835 bool_t output_performs_decoding;
836 bool_t player_active;
837 bool_t staticimage_webcam_fps_optimization; /* if TRUE, the StaticImage webcam will ignore the fps target in order to save CPU time. Default is TRUE */
838 };
839
840 typedef struct _VideoStream VideoStream;
841
842
843
844 MS2_PUBLIC VideoStream *video_stream_new(MSFactory* factory, int loc_rtp_port, int loc_rtcp_port, bool_t use_ipv6);
845 /**
846 * Creates a VideoStream object listening on a RTP port for a dedicated address.
847 * @param loc_ip the local ip to listen for RTP packets. Can be ::, O.O.O.O or any ip4/6 addresses
848 * @param [in] loc_rtp_port the local UDP port to listen for RTP packets.
849 * @param [in] loc_rtcp_port the local UDP port to listen for RTCP packets
850 * @return a new VideoStream.
851 **/
852 MS2_PUBLIC VideoStream *video_stream_new2(MSFactory* factory, const char* ip, int loc_rtp_port, int loc_rtcp_port);
853
854 MS2_PUBLIC VideoStream *video_stream_new_with_sessions(MSFactory* factory, const MSMediaStreamSessions *sessions);
855 MS2_PUBLIC void video_stream_set_direction(VideoStream *vs, MediaStreamDir dir);
video_stream_enable_adaptive_bitrate_control(VideoStream * stream,bool_t enabled)856 static MS2_INLINE void video_stream_enable_adaptive_bitrate_control(VideoStream *stream, bool_t enabled) {
857 media_stream_enable_adaptive_bitrate_control(&stream->ms, enabled);
858 }
video_stream_enable_adaptive_jittcomp(VideoStream * stream,bool_t enabled)859 static MS2_INLINE void video_stream_enable_adaptive_jittcomp(VideoStream *stream, bool_t enabled) {
860 media_stream_enable_adaptive_jittcomp(&stream->ms, enabled);
861 }
862 MS2_PUBLIC void video_stream_set_render_callback(VideoStream *s, VideoStreamRenderCallback cb, void *user_pointer);
863 MS2_PUBLIC void video_stream_set_event_callback(VideoStream *s, VideoStreamEventCallback cb, void *user_pointer);
864 MS2_PUBLIC void video_stream_set_display_filter_name(VideoStream *s, const char *fname);
865 MS2_PUBLIC int video_stream_start_with_source(VideoStream *stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port,
866 const char *rem_rtcp_ip, int rem_rtcp_port, int payload, int jitt_comp, MSWebCam* cam, MSFilter* source);
867 MS2_PUBLIC int video_stream_start(VideoStream * stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port, const char *rem_rtcp_ip,
868 int rem_rtcp_port, int payload, int jitt_comp, MSWebCam *device);
869 MS2_PUBLIC int video_stream_start_with_files(VideoStream *stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port,
870 const char *rem_rtcp_ip, int rem_rtcp_port, int payload_type, const char *play_file, const char *record_file);
871
872 /**
873 * Start a video stream according to the specified VideoStreamIO.
874 *
875 * @param[in] stream VideoStream object previously created with video_stream_new().
876 * @param[in] profile RtpProfile object holding the PayloadType that can be used during the video session.
877 * @param[in] rem_rtp_ip The remote IP address where to send the encoded video to.
878 * @param[in] rem_rtp_port The remote port where to send the encoded video to.
879 * @param[in] rem_rtcp_ip The remote IP address for RTCP.
880 * @param[in] rem_rtcp_port The remote port for RTCP.
881 * @param[in] payload_type The payload type number used to send the video stream. A valid PayloadType must be available at this index in the profile.
882 * @param[in] io A VideoStreamIO describing the input/output of the video stream.
883 */
884 MS2_PUBLIC int video_stream_start_from_io(VideoStream *stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port,
885 const char *rem_rtcp_ip, int rem_rtcp_port, int payload_type, const MSMediaStreamIO *io);
886
887 MS2_PUBLIC void video_stream_prepare_video(VideoStream *stream);
888 MS2_PUBLIC void video_stream_unprepare_video(VideoStream *stream);
889
890
891 MS2_PUBLIC void video_stream_set_relay_session_id(VideoStream *stream, const char *relay_session_id);
video_stream_set_rtcp_information(VideoStream * st,const char * cname,const char * tool)892 static MS2_INLINE void video_stream_set_rtcp_information(VideoStream *st, const char *cname, const char *tool) {
893 media_stream_set_rtcp_information(&st->ms, cname, tool);
894 }
895 /*
896 * returns current MSWebCam for a given stream
897 * */
898 MS2_PUBLIC const MSWebCam * video_stream_get_camera(const VideoStream *stream);
899
900 /**
901 * Returns the current video stream source filter. Be careful, this source will be
902 * destroyed if the stream is stopped.
903 * @return current stream source
904 */
905 MS2_PUBLIC MSFilter* video_stream_get_source_filter(const VideoStream* stream);
906
907 MS2_PUBLIC void video_stream_change_camera(VideoStream *stream, MSWebCam *cam);
908
909 MS2_PUBLIC void video_stream_recreate_graph(VideoStream *stream);
910
911 /**
912 * @brief This functions changes the source filter for the passed video stream.
913 * @details This is quite the same function as \ref video_stream_change_camera, but this one
914 * allows you to pass the source filter that is created for the camera and reuse it. This gives you the
915 * ability to switch rapidly between two streams, whereas re-creating them each time would be
916 * costly (especially with webcams).
917 *
918 * @note Since the \ref video_stream_stop() will automatically destroy the source, it is
919 * advised that you use \ref video_stream_stop_keep_source() instead, so that you
920 * can manually destroy the source filters after the stream is stopped.
921 *
922 * Example usage:
923 *
924 * video_stream_start(stream, profile, [...], noWebcamDevice);
925 * // We manage the sources for the stream ourselves:
926 * MSFilter* noWebCamFilter = video_stream_get_source_filter(stream);
927 * MSFilter* frontCamFilter = ms_web_cam_create_reader(frontCamDevice);
928 *
929 * sleep(1);
930 * video_stream_change_source_filter(stream, frontCamDevice, frontCamFilter, TRUE); // will keep the previous filter
931 * sleep(1);
932 * video_stream_change_source_filter(stream, noWebcamDevice, noWebCamFilter, TRUE); // keep the previous filter
933 *
934 * sleep(1)
935 * video_stream_stop_keep_source(stream);
936 * ms_filter_destroy(noWebCamFilter);
937 * ms_filter_destroy(frontCamFilter);
938 *
939 *
940 * @param stream the video stream to modify
941 * @param cam the camera that you want to set as the new source
942 * @param cam_filter the filter for this camera. It can be obtained with ms_web_cam_create_reader(cam)
943 * @return the previous source if keep_previous_source is TRUE, otherwise NULL
944 */
945 MS2_PUBLIC MSFilter* video_stream_change_source_filter(VideoStream *stream, MSWebCam* cam, MSFilter* filter, bool_t keep_previous_source );
946
947 /**
948 * @brief This is the same function as \ref video_stream_change_source_filter() called with keep_source=1, but
949 * the new filter will be created from the MSWebcam that is passed as argument.
950 *
951 * @param stream the video stream
952 * @param cam the MSWebcam from which the new source filter should be created.
953 * @return the previous source filter
954 */
955 MS2_PUBLIC MSFilter* video_stream_change_camera_keep_previous_source(VideoStream *stream, MSWebCam *cam);
956
957
958 /* Calling video_stream_set_sent_video_size() or changing the bitrate value in the used PayloadType during a stream is running does nothing.
959 The following function allows to take into account new parameters by redrawing the sending graph*/
960 MS2_PUBLIC void video_stream_update_video_params(VideoStream *stream);
961 /*function to call periodically to handle various events */
962 MS2_PUBLIC void video_stream_iterate(VideoStream *stream);
963
964 /**
965 * Asks the video stream to send a Full-Intra Request.
966 * @param[in] stream The videostream object.
967 */
968 MS2_PUBLIC void video_stream_send_fir(VideoStream *stream);
969
970 /**
971 * Asks the video stream to generate a Video Fast Update (generally after receiving a Full-Intra Request.
972 * @param[in] stream The videostream object.
973 */
974 MS2_PUBLIC void video_stream_send_vfu(VideoStream *stream);
975
976 MS2_PUBLIC void video_stream_stop(VideoStream * stream);
977
978 /**
979 * Stop the video stream, but does not destroy the source of the video. This function
980 * can be use in conjunction with \ref video_stream_change_source_filter() to allow
981 * manual management of the source filters for a video stream.
982 * @param stream the stream to stop
983 * @return returns the source of the video stream, which you should manually destroy when appropriate.
984 */
985 MS2_PUBLIC MSFilter* video_stream_stop_keep_source(VideoStream * stream);
986
987 MS2_PUBLIC bool_t video_stream_started(VideoStream *stream);
988
989 /**
990 * Try to set the size of the video that is sent. Since this relies also on the
991 * bitrate specified, make sure to set the payload bitrate accordingly with
992 * rtp_profile_get_payload and normal_bitrate value otherwise the best
993 * possible resolution will be taken instead of the requested one.
994 * @param[in] stream The videostream for which to get the sent video size.
995 * @param[in] vsize The sent video size wished.
996 */
997 MS2_PUBLIC void video_stream_set_sent_video_size(VideoStream *stream, MSVideoSize vsize);
998
999 /**
1000 * Gets the size of the video that is sent.
1001 * @param[in] stream The videostream for which to get the sent video size.
1002 * @return The sent video size or MS_VIDEO_SIZE_UNKNOWN if not available.
1003 */
1004 MS2_PUBLIC MSVideoSize video_stream_get_sent_video_size(const VideoStream *stream);
1005
1006 /**
1007 * Gets the size of the video that is received.
1008 * @param[in] stream The videostream for which to get the received video size.
1009 * @return The received video size or MS_VIDEO_SIZE_UNKNOWN if not available.
1010 */
1011 MS2_PUBLIC MSVideoSize video_stream_get_received_video_size(const VideoStream *stream);
1012
1013 /**
1014 * Gets the framerate of the video that is sent.
1015 * @param[in] stream The videostream.
1016 * @return The actual framerate, 0 if not available..
1017 */
1018 MS2_PUBLIC float video_stream_get_sent_framerate(const VideoStream *stream);
1019
1020 /**
1021 * Gets the framerate of the video that is received.
1022 * @param[in] stream The videostream.
1023 * @return The received framerate or 0 if not available.
1024 */
1025 MS2_PUBLIC float video_stream_get_received_framerate(const VideoStream *stream);
1026
1027 /**
1028 * Returns the name of the video display filter on the current platform.
1029 **/
1030 MS2_PUBLIC const char *video_stream_get_default_video_renderer(void);
1031
1032 MS2_PUBLIC void video_stream_enable_self_view(VideoStream *stream, bool_t val);
1033 MS2_PUBLIC void * video_stream_get_native_window_id(VideoStream *stream);
1034 MS2_PUBLIC void video_stream_set_native_window_id(VideoStream *stream, void *id);
1035 MS2_PUBLIC void video_stream_set_native_preview_window_id(VideoStream *stream, void *id);
1036 MS2_PUBLIC void * video_stream_get_native_preview_window_id(VideoStream *stream);
1037 MS2_PUBLIC void video_stream_use_preview_video_window(VideoStream *stream, bool_t yesno);
1038 MS2_PUBLIC void video_stream_set_device_rotation(VideoStream *stream, int orientation);
1039 MS2_PUBLIC void video_stream_show_video(VideoStream *stream, bool_t show);
1040 MS2_PUBLIC void video_stream_set_freeze_on_error(VideoStream *stream, bool_t yesno);
1041
1042 /**
1043 * @brief Gets the camera sensor rotation.
1044 *
1045 * This is needed on some mobile platforms to get the number of degrees the camera sensor
1046 * is rotated relative to the screen.
1047 *
1048 * @param stream The video stream related to the operation
1049 * @return The camera sensor rotation in degrees (0 to 360) or -1 if it could not be retrieved
1050 */
1051 MS2_PUBLIC int video_stream_get_camera_sensor_rotation(VideoStream *stream);
1052
1053 /*provided for compatibility, use video_stream_set_direction() instead */
1054 MS2_PUBLIC int video_stream_recv_only_start(VideoStream *videostream, RtpProfile *profile, const char *addr, int port, int used_pt, int jitt_comp);
1055 MS2_PUBLIC int video_stream_send_only_start(VideoStream *videostream,
1056 RtpProfile *profile, const char *addr, int port, int rtcp_port,
1057 int used_pt, int jitt_comp, MSWebCam *device);
1058 MS2_PUBLIC void video_stream_recv_only_stop(VideoStream *vs);
1059 MS2_PUBLIC void video_stream_send_only_stop(VideoStream *vs);
1060
1061 /* enable ZRTP on the video stream using information from the audio stream */
1062 MS2_PUBLIC void video_stream_enable_zrtp(VideoStream *vstream, AudioStream *astream);
1063 MS2_PUBLIC void video_stream_start_zrtp(VideoStream *stream);
1064
1065 /* enable SRTP on the video stream */
video_stream_enable_strp(VideoStream * stream,MSCryptoSuite suite,const char * snd_key,const char * rcv_key)1066 static MS2_INLINE bool_t video_stream_enable_strp(VideoStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key) {
1067 return media_stream_enable_srtp(&stream->ms, suite, snd_key, rcv_key);
1068 }
1069
1070 /* if enabled, the display filter will internaly rotate the video, according to the device orientation */
1071 MS2_PUBLIC void video_stream_enable_display_filter_auto_rotate(VideoStream* stream, bool_t enable);
1072
1073 /* retrieve RTP statistics*/
video_stream_get_local_rtp_stats(VideoStream * stream,rtp_stats_t * stats)1074 static MS2_INLINE void video_stream_get_local_rtp_stats(VideoStream *stream, rtp_stats_t *stats) {
1075 media_stream_get_local_rtp_stats(&stream->ms, stats);
1076 }
1077
video_stream_set_dscp(VideoStream * stream,int dscp)1078 static MS2_INLINE int video_stream_set_dscp(VideoStream *stream, int dscp) {
1079 return media_stream_set_dscp(&stream->ms, dscp);
1080 }
1081
1082 /**
1083 * Gets the RTP session of a video stream.
1084 * @param[in] stream #MediaStream object.
1085 * @return The RTP session of the video stream.
1086 */
video_stream_get_rtp_session(const VideoStream * stream)1087 static MS2_INLINE RtpSession * video_stream_get_rtp_session(const VideoStream *stream) {
1088 return media_stream_get_rtp_session(&stream->ms);
1089 }
1090
1091 /**
1092 * Ask the video stream whether a decoding error should be reported (eg. to send a VFU request).
1093 * @param[in] stream The VideoStream object.
1094 * @param[in] ms The minimum interval in milliseconds between to decoding error report.
1095 * @return TRUE if the decoding error should be reported, FALSE otherwise.
1096 */
1097 MS2_PUBLIC bool_t video_stream_is_decoding_error_to_be_reported(VideoStream *stream, uint32_t ms);
1098
1099 /**
1100 * Tell the video stream that a decoding error has been reported.
1101 * @param[in] stream The VideoStream object.
1102 */
1103 MS2_PUBLIC void video_stream_decoding_error_reported(VideoStream *stream);
1104
1105 /**
1106 * Tell the video stream that a decoding error has been recovered so that new decoding can be reported sooner.
1107 * @param[in] stream The VideoStream object.
1108 */
1109 MS2_PUBLIC void video_stream_decoding_error_recovered(VideoStream *stream);
1110
1111
1112 /**
1113 * Force a resolution for the preview.
1114 * @param[in] stream The VideoStream object.
1115 * @param[in] vsize video resolution.
1116 **/
1117 MS2_PUBLIC void video_stream_set_preview_size(VideoStream *stream, MSVideoSize vsize);
1118
1119 /**
1120 * Force a resolution for the preview.
1121 * @param[in] stream The VideoStream object.
1122 * @param[in] fps the frame rate in frame/seconds. A value of zero means "use encoder default value".
1123 **/
1124 MS2_PUBLIC void video_stream_set_fps(VideoStream *stream, float fps);
1125
1126 /**
1127 * Link the audio stream with an existing video stream.
1128 * This is necessary to enable recording of audio & video into a multimedia file.
1129 */
1130 MS2_PUBLIC void audio_stream_link_video(AudioStream *stream, VideoStream *video);
1131
1132 /**
1133 * Unlink the audio stream from the video stream.
1134 * This must be done if the video stream is about to be stopped.
1135 **/
1136 MS2_PUBLIC void audio_stream_unlink_video(AudioStream *stream, VideoStream *video);
1137
1138 /**
1139 * Set a video preset to be used for the video stream.
1140 * @param[in] stream VideoStream object
1141 * @param[in] preset The name of the video preset to be used.
1142 */
1143 MS2_PUBLIC void video_stream_use_video_preset(VideoStream *stream, const char *preset);
1144
1145
1146 /**
1147 * Open a player to play a video file (mkv) to remote end.
1148 * The player is returned as a MSFilter so that application can make usual player controls on it using the MSPlayerInterface.
1149 **/
1150 MS2_PUBLIC MSFilter * video_stream_open_remote_play(VideoStream *stream, const char *filename);
1151
1152 MS2_PUBLIC void video_stream_close_remote_play(VideoStream *stream);
1153
1154 /**
1155 * Open a recorder to record the video coming from remote end into a mkv file.
1156 * This must be done before the stream is started.
1157 **/
1158 MS2_PUBLIC MSFilter * video_stream_open_remote_record(VideoStream *stream, const char *filename);
1159
1160 MS2_PUBLIC void video_stream_close_remote_record(VideoStream *stream);
1161
1162 /**
1163 * Small API to display a local preview window.
1164 **/
1165
1166 typedef VideoStream VideoPreview;
1167
1168 MS2_PUBLIC VideoPreview * video_preview_new(MSFactory *factory);
1169 #define video_preview_set_size(p,s) video_stream_set_sent_video_size(p,s)
1170 #define video_preview_set_display_filter_name(p,dt) video_stream_set_display_filter_name(p,dt)
1171 #define video_preview_set_native_window_id(p,id) video_stream_set_native_preview_window_id(p,id)
1172 #define video_preview_get_native_window_id(p) video_stream_get_native_preview_window_id(p)
1173 #define video_preview_set_fps(p,fps) video_stream_set_fps((VideoStream*)p,fps)
1174 #define video_preview_set_device_rotation(p, r) video_stream_set_device_rotation(p, r)
1175 MS2_PUBLIC void video_preview_start(VideoPreview *stream, MSWebCam *device);
1176 MS2_PUBLIC MSVideoSize video_preview_get_current_size(VideoPreview *stream);
1177 MS2_PUBLIC void video_preview_stop(VideoPreview *stream);
1178 MS2_PUBLIC void video_preview_change_camera(VideoPreview *stream, MSWebCam *cam);
1179 MS2_PUBLIC void video_preview_update_video_params(VideoPreview *stream);
1180
1181
1182 /**
1183 * Stops the video preview graph but keep the source filter for reuse.
1184 * This is useful when transitioning from a preview-only to a duplex video.
1185 * The filter needs to be passed to the #video_stream_start_with_source function,
1186 * otherwise you should destroy it.
1187 * @param[in] stream VideoPreview object
1188 * @return The source filter to be passed to the #video_stream_start_with_source function.
1189 */
1190 MS2_PUBLIC MSFilter* video_preview_stop_reuse_source(VideoPreview *stream);
1191
1192 /*
1193 * Returns the web cam descriptor for the mire kind of camera.
1194 **/
1195 MS2_PUBLIC MSWebCamDesc *ms_mire_webcam_desc_get(void);
1196
1197
1198 /**
1199 * Create an RTP session for duplex communication.
1200 * @param[in] local_ip The local IP to bind the RTP and RTCP sockets to.
1201 * @param[in] local_rtp_port The local port to bind the RTP socket to.
1202 * @param[in] local_rtcp_port The local port to bind the RTCP socket to.
1203 */
1204 MS2_PUBLIC RtpSession * ms_create_duplex_rtp_session(const char* local_ip, int loc_rtp_port, int loc_rtcp_port, int mtu);
1205
1206 /**
1207 * Asks the audio playback filter to route to the selected device (currently only used for blackberry)
1208 * @param[in] stream The AudioStream object
1209 * @param[in] route The wanted audio output device (earpiece, speaker)
1210 */
1211 MS2_PUBLIC void audio_stream_set_audio_route(AudioStream *stream, MSAudioRoute route);
1212
1213 /**
1214 * @}
1215 **/
1216
1217 /**
1218 * @addtogroup text_stream_api
1219 * @{
1220 **/
1221
1222 struct _TextStream
1223 {
1224 MediaStream ms;
1225 MSFilter *rttsource;
1226 MSFilter *rttsink;
1227 int pt_t140;
1228 int pt_red;
1229 };
1230
1231 typedef struct _TextStream TextStream;
1232
1233 /**
1234 * Creates a TextStream object listening on a RTP port.
1235 * @param loc_rtp_port the local UDP port to listen for RTP packets.
1236 * @param loc_rtcp_port the local UDP port to listen for RTCP packets
1237 * @param ipv6 TRUE if ipv6 must be used.
1238 * @param factory
1239 * @return a new TextStream.
1240 **/
1241 MS2_PUBLIC TextStream *text_stream_new(MSFactory *factory, int loc_rtp_port, int loc_rtcp_port, bool_t ipv6);
1242
1243 /**
1244 * Creates a TextStream object from initialized MSMediaStreamSessions.
1245 * @param sessions the MSMediaStreamSessions
1246 * @param factory
1247 * @return a new TextStream
1248 **/
1249 MS2_PUBLIC TextStream *text_stream_new_with_sessions(MSFactory *factory, const MSMediaStreamSessions *sessions);
1250
1251 /**
1252 * Creates a TextStream object listening on a RTP port for a dedicated address.
1253 * @param loc_ip the local ip to listen for RTP packets. Can be ::, O.O.O.O or any ip4/6 addresses
1254 * @param [in] loc_rtp_port the local UDP port to listen for RTP packets.
1255 * @param [in] loc_rtcp_port the local UDP port to listen for RTCP packets
1256 * @param factory
1257 * @return a new TextStream.
1258 **/
1259 MS2_PUBLIC TextStream *text_stream_new2(MSFactory *factory, const char* ip, int loc_rtp_port, int loc_rtcp_port);
1260
1261 /**
1262 * Starts a text stream.
1263 *
1264 * @param[in] stream TextStream object previously created with text_stream_new().
1265 * @param[in] profile RtpProfile object holding the PayloadType that can be used during the text session.
1266 * @param[in] rem_rtp_addr The remote IP address where to send the text to.
1267 * @param[in] rem_rtp_port The remote port where to send the text to.
1268 * @param[in] rem_rtcp_addr The remote IP address for RTCP.
1269 * @param[in] rem_rtcp_port The remote port for RTCP.
1270 * @param[in] payload_type The payload type number used to send the text stream. A valid PayloadType must be available at this index in the profile.
1271 * @param[in] factory
1272 */
1273 MS2_PUBLIC TextStream* text_stream_start(TextStream *stream, RtpProfile *profile, const char *rem_rtp_addr, int rem_rtp_port, const char *rem_rtcp_addr, int rem_rtcp_port,
1274 int payload_type);
1275
1276 /**
1277 * Stops the text streaming thread and free everything
1278 **/
1279 MS2_PUBLIC void text_stream_stop (TextStream * stream);
1280
1281 /**
1282 * Executes background low priority tasks related to text processing (RTP statistics analysis).
1283 * It should be called periodically, for example with an interval of 100 ms or so.
1284 *
1285 * @param[in] stream TextStream object previously created with text_stream_new().
1286 */
1287 MS2_PUBLIC void text_stream_iterate(TextStream *stream);
1288
1289 /**
1290 * Writes a character to stream in UTF-32 format.
1291 *
1292 * @param[in] stream TextStream object previously created with text_stream_new().
1293 * @param[in] i the Char in UTF-32 format.
1294 **/
1295 MS2_PUBLIC void text_stream_putchar32(TextStream *stream, uint32_t i);
1296
1297 MS2_PUBLIC void text_stream_prepare_text(TextStream *stream);
1298 MS2_PUBLIC void text_stream_unprepare_text(TextStream *stream);
1299
1300 /**
1301 * @}
1302 **/
1303
1304 #ifdef __cplusplus
1305 }
1306 #endif
1307
1308 #endif
1309