mediastream.h 27.1 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/


#ifndef MEDIASTREAM_H
#define MEDIASTREAM_H

24 25 26
#include <ortp/ortp.h>
#include <ortp/event.h>
#include <ortp/zrtp.h>
jehan's avatar
jehan committed
27 28
/* defined in srtp.h*/
typedef struct srtp_ctx_t *MSSrtpCtx;
29

Simon Morlat's avatar
Simon Morlat committed
30 31 32 33 34
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
#include <mediastreamer2/mssndcard.h>
#include <mediastreamer2/mswebcam.h>
#include <mediastreamer2/msvideo.h>
35 36
#include <mediastreamer2/bitratecontrol.h>
#include <mediastreamer2/qualityindicator.h>
37
#include <mediastreamer2/ice.h>
aymeric's avatar
aymeric committed
38

Ghislain MARY's avatar
Ghislain MARY committed
39

Simon Morlat's avatar
Simon Morlat committed
40 41 42
#define PAYLOAD_TYPE_FLAG_CAN_RECV	PAYLOAD_TYPE_USER_FLAG_1
#define PAYLOAD_TYPE_FLAG_CAN_SEND	PAYLOAD_TYPE_USER_FLAG_2

Ghislain MARY's avatar
Ghislain MARY committed
43 44 45 46 47

#ifdef __cplusplus
extern "C" {
#endif

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
/**
 * @addtogroup ring_api
 * @{
**/

struct _RingStream
{
	MSTicker *ticker;
	MSFilter *source;
	MSFilter *gendtmf;
	MSFilter *write_resampler;
	MSFilter *sndwrite;
};

typedef struct _RingStream RingStream;

MS2_PUBLIC RingStream *ring_start (const char * file, int interval, MSSndCard *sndcard);
MS2_PUBLIC RingStream *ring_start_with_cb(const char * file, int interval, MSSndCard *sndcard, MSFilterNotifyFunc func, void * user_data);
MS2_PUBLIC void ring_stop (RingStream * stream);

/**
 * @}
**/
jehan's avatar
jehan committed
71 72 73
/*
 * Crypto suite used configure encrypted stream*/
typedef enum _MSCryptoSuite{
Simon Morlat's avatar
Simon Morlat committed
74 75
	MS_CRYPTO_SUITE_INVALID=0,
	MS_AES_128_SHA1_80,
jehan's avatar
jehan committed
76 77 78 79 80 81
	MS_AES_128_SHA1_32,
	MS_AES_128_NO_AUTH,
	MS_NO_CIPHER_SHA1_80,
	MS_AES_256_SHA1_80,
	MS_AES_256_SHA1_32
} MSCryptoSuite;
82

Simon Morlat's avatar
Simon Morlat committed
83 84 85 86 87 88 89 90
typedef struct _MSCryptoSuiteNameParams{
	const char *name;
	const char *params;
}MSCryptoSuiteNameParams;

MS2_PUBLIC MSCryptoSuite ms_crypto_suite_build_from_name_params(const MSCryptoSuiteNameParams *nameparams);
MS2_PUBLIC int ms_crypto_suite_to_name_params(MSCryptoSuite cs, MSCryptoSuiteNameParams *nameparams);

Ghislain MARY's avatar
Ghislain MARY committed
91 92 93 94 95
typedef enum StreamType {
	AudioStreamType,
	VideoStreamType
} StreamType;

96 97
MS2_PUBLIC const char* ms_stream_type_to_string(StreamType);

98 99 100
/**
 * The MediaStream is an object describing a stream (one of AudioStream or VideoStream).
**/
jehan's avatar
jehan committed
101 102 103 104 105
typedef struct _MediaStream MediaStream;

/*
 * internal cb to process rtcp stream
 * */
106
typedef void (*media_stream_process_rtcp_callback_t)(MediaStream *stream, mblk_t *m);
jehan's avatar
jehan committed
107

108 109
struct _MSMediaStreamSessions{
	RtpSession *rtp_session;
jehan's avatar
jehan committed
110
	MSSrtpCtx srtp_session;
111 112
	OrtpZrtpContext *zrtp_context;
	MSTicker *ticker;
jehan's avatar
jehan committed
113
	bool_t is_secured;
114 115 116
};

typedef struct _MSMediaStreamSessions MSMediaStreamSessions;
jehan's avatar
jehan committed
117

118 119 120 121 122 123 124 125 126 127 128
MS2_PUBLIC void ms_media_stream_sessions_uninit(MSMediaStreamSessions *sessions);

typedef enum _MSStreamState{
	MSStreamInitialized,
	MSStreamPreparing,
	MSStreamStarted
}MSStreamState;

/**
 * Base struct for both AudioStream and VideoStream structure.
**/
Ghislain MARY's avatar
Ghislain MARY committed
129 130
struct _MediaStream {
	StreamType type;
131 132
	MSStreamState state;
	MSMediaStreamSessions sessions;
Ghislain MARY's avatar
Ghislain MARY committed
133 134 135 136 137 138 139
	OrtpEvQueue *evq;
	MSFilter *rtprecv;
	MSFilter *rtpsend;
	MSFilter *encoder;
	MSFilter *decoder;
	MSFilter *voidsink;
	MSBitrateController *rc;
140
	MSQualityIndicator *qi;
Ghislain MARY's avatar
Ghislain MARY committed
141
	IceCheckList *ice_check_list;
142 143
	time_t start_time;
	time_t last_iterate_time;
144 145
	uint64_t last_packet_count;
	time_t last_packet_time;
Ghislain MARY's avatar
Ghislain MARY committed
146
	bool_t use_rc;
147
	bool_t owns_sessions;
148
	bool_t pad;
jehan's avatar
jehan committed
149
	/**
150
	 * defines encoder target network bit rate, uses #media_stream_set_target_network_bitrate() setter.
jehan's avatar
jehan committed
151 152
	 * */
	int target_bitrate;
153
	media_stream_process_rtcp_callback_t process_rtcp;
Ghislain MARY's avatar
Ghislain MARY committed
154 155
};

jehan's avatar
jehan committed
156 157 158 159 160

/**
 * @addtogroup audio_stream_api
 * @{
**/
Ghislain MARY's avatar
Ghislain MARY committed
161

162 163
MS2_PUBLIC bool_t media_stream_srtp_supported(void);

164 165 166 167 168 169 170 171 172 173
MS2_PUBLIC void media_stream_set_rtcp_information(MediaStream *stream, const char *cname, const char *tool);

MS2_PUBLIC void media_stream_get_local_rtp_stats(MediaStream *stream, rtp_stats_t *stats);

MS2_PUBLIC int media_stream_set_dscp(MediaStream *stream, int dscp);

MS2_PUBLIC void media_stream_enable_adaptive_bitrate_control(MediaStream *stream, bool_t enabled);

MS2_PUBLIC void media_stream_enable_adaptive_jittcomp(MediaStream *stream, bool_t enabled);

174 175 176
/*
 * deprecated, use media_stream_set_srtp_recv_key and media_stream_set_srtp_send_key.
**/
jehan's avatar
jehan committed
177 178 179
MS2_PUBLIC bool_t media_stream_enable_srtp(MediaStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key);

MS2_PUBLIC int media_stream_set_srtp_recv_key(MediaStream *stream, MSCryptoSuite suite, const char* key);
180

jehan's avatar
jehan committed
181 182
MS2_PUBLIC int media_stream_set_srtp_send_key(MediaStream *stream, MSCryptoSuite suite, const char* key);
/**
183
 * @param[in] stream MediaStream object
jehan's avatar
jehan committed
184 185
 * @return true if stream is encrypted
 * */
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
MS2_PUBLIC bool_t media_stream_secured(const MediaStream *stream);
#define media_stream_is_secured media_stream_secured

/**
 * Tells whether AVPF is enabled or not.
 * @param[in] stream #MediaStream object.
 * @return True if AVPF is enabled, false otherwise.
 */
MS2_PUBLIC bool_t media_stream_avpf_enabled(const MediaStream *stream);

/**
 * Gets the AVPF Regular RTCP report interval.
 * @param[in] stream #MediaStream object.
 * @return The AVPF Regular RTCP report interval in seconds.
 */
201
MS2_PUBLIC uint16_t media_stream_get_avpf_rr_interval(const MediaStream *stream);
202 203


204
MS2_PUBLIC const MSQualityIndicator *media_stream_get_quality_indicator(MediaStream *stream);
jehan's avatar
jehan committed
205 206 207
/* *
 * returns a realtime indicator of the stream quality between 0 and 5
 * */
208
MS2_PUBLIC float media_stream_get_quality_rating(MediaStream *stream);
209

210 211
MS2_PUBLIC float media_stream_get_average_quality_rating(MediaStream *stream);

212 213 214 215
MS2_PUBLIC float media_stream_get_lq_quality_rating(MediaStream *stream);

MS2_PUBLIC float media_stream_get_average_lq_quality_rating(MediaStream *stream);

216
/**
jehan's avatar
jehan committed
217 218 219 220 221 222 223 224 225 226 227 228
 * <br>For multirate codecs like OPUS, encoder output target bitrate must be set.
 * <br>Encoder will compute output codec bitrate from this value.
 * <br> default value is the value corresponding the rtp PayloadType
 * @param stream stream to apply parameter on
 * @param target_bitrate in bit per seconds
 * @return 0 if succeed
 * */
MS2_PUBLIC int media_stream_set_target_network_bitrate(MediaStream *stream,int target_bitrate);

/**
 * get the stream target bitrate.
 * @param stream stream to apply parameter on
229
 * @return target_bitrate in bit per seconds
jehan's avatar
jehan committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
 * */
MS2_PUBLIC int media_stream_get_target_network_bitrate(const MediaStream *stream);

/**
 * get current stream  upload bitrate. Value is updated every seconds
 * @param stream
 * @return bitrate in bit per seconds
 * */
MS2_PUBLIC float media_stream_get_up_bw(const MediaStream *stream);

/**
 * get current stream download bitrate. Value is updated every seconds
 * @param stream
 * @return bitrate in bit per seconds
 * */
MS2_PUBLIC float media_stream_get_down_bw(const MediaStream *stream);

247 248 249 250 251 252
/**
 * Returns the sessions that were used in the media stream (RTP, SRTP, ZRTP...) so that they can be re-used.
 * As a result of calling this function, the media stream no longer owns the sessions and thus will not free them.
**/
MS2_PUBLIC void media_stream_reclaim_sessions(MediaStream *stream, MSMediaStreamSessions *sessions);

jehan's avatar
jehan committed
253 254 255

void media_stream_iterate(MediaStream * stream);

256 257 258 259 260
/**
 * Returns TRUE if stream was still actively receiving packets (RTP or RTCP) in the last period specified in timeout_seconds.
**/
MS2_PUBLIC bool_t media_stream_alive(MediaStream *stream, int timeout_seconds);

jehan's avatar
jehan committed
261 262 263 264
/**
 * @returns curret streams tate
 * */
MS2_PUBLIC MSStreamState media_stream_get_state(const MediaStream *stream);
265

266 267 268
typedef enum EchoLimiterType{
	ELInactive,
	ELControlMic,
269
	ELControlFull
270 271
} EchoLimiterType;

aymeric's avatar
aymeric committed
272 273
struct _AudioStream
{
Ghislain MARY's avatar
Ghislain MARY committed
274
	MediaStream ms;
aymeric's avatar
aymeric committed
275 276 277
	MSFilter *soundread;
	MSFilter *soundwrite;
	MSFilter *dtmfgen;
278
	MSFilter *dtmfgen_rtp;
Yann Diorcet's avatar
Yann Diorcet committed
279
	MSFilter *plc;
aymeric's avatar
aymeric committed
280
	MSFilter *ec;/*echo canceler*/
281
	MSFilter *volsend,*volrecv; /*MSVolumes*/
282 283 284
	MSFilter *local_mixer;
	MSFilter *local_player;
	MSFilter *local_player_resampler;
285 286
	MSFilter *read_resampler;
	MSFilter *write_resampler;
smorlat's avatar
smorlat committed
287
	MSFilter *equalizer;
Simon Morlat's avatar
Simon Morlat committed
288
	MSFilter *dummy;
289 290 291 292 293
	MSFilter *send_tee;
	MSFilter *recv_tee;
	MSFilter *recorder_mixer;
	MSFilter *recorder;
	char *recorder_file;
294
	EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/
Ghislain MARY's avatar
Ghislain MARY committed
295
	uint32_t features;
smorlat's avatar
smorlat committed
296
	bool_t play_dtmfs;
smorlat's avatar
smorlat committed
297
	bool_t use_gc;
298
	bool_t use_agc;
smorlat's avatar
smorlat committed
299
	bool_t eq_active;
300
	bool_t use_ng;/*noise gate*/
301
	bool_t is_ec_delay_set;
aymeric's avatar
aymeric committed
302 303
};

304 305 306
/**
 * The AudioStream holds all resources to create and run typical VoIP audiostream.
**/
aymeric's avatar
aymeric committed
307 308 309 310
typedef struct _AudioStream AudioStream;


/* start a thread that does sampling->encoding->rtp_sending|rtp_receiving->decoding->playing */
Simon Morlat's avatar
Simon Morlat committed
311
MS2_PUBLIC AudioStream *audio_stream_start (RtpProfile * prof, int locport, const char *remip,
aymeric's avatar
aymeric committed
312 313
				 int remport, int payload_type, int jitt_comp, bool_t echo_cancel);

Simon Morlat's avatar
Simon Morlat committed
314
MS2_PUBLIC AudioStream *audio_stream_start_with_sndcards(RtpProfile * prof, int locport, const char *remip4, int remport, int payload_type, int jitt_comp, MSSndCard *playcard, MSSndCard *captcard, bool_t echocancel);
aymeric's avatar
aymeric committed
315

316

Simon Morlat's avatar
Simon Morlat committed
317
MS2_PUBLIC int audio_stream_start_with_files (AudioStream * stream, RtpProfile * prof,
aymeric's avatar
aymeric committed
318 319 320 321
					    const char *remip, int remport, int rem_rtcp_port,
					    int pt, int jitt_comp,
					    const char * infile,  const char * outfile);

322 323
/**
 * Starts an audio stream from/to local wav files or soundcards.
324
 *
325 326
 * This method starts the processing of the audio stream, that is playing from wav file or soundcard, voice processing, encoding,
 * sending through RTP, receiving from RTP, decoding, voice processing and wav file recording or soundcard playback.
327 328
 *
 *
329
 * @param stream an AudioStream previously created with audio_stream_new().
330
 * @param profile a RtpProfile containing all PayloadType possible during the audio session.
331 332 333
 * @param rem_rtp_ip remote IP address where to send the encoded audio.
 * @param rem_rtp_port remote IP port where to send the encoded audio.
 * @param rem_rtcp_ip remote IP address for RTCP.
334
 * @param rem_rtcp_port remote port for RTCP.
335
 * @param payload payload type index to use for the sending stream. This index must point to a valid PayloadType in the RtpProfile.
336 337 338 339 340
 * @param jitt_comp Nominal jitter buffer size in milliseconds.
 * @param infile path to wav file to play out (can be NULL)
 * @param outfile path to wav file to record into (can be NULL)
 * @param playcard The soundcard to be used for playback (can be NULL)
 * @param captcard The soundcard to be used for catpure. (can be NULL)
341
 * @param use_ec whether echo cancellation is to be performed.
342 343
 * @returns 0 if sucessful, -1 otherwise.
**/
344 345
MS2_PUBLIC int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *rem_rtp_ip,int rem_rtp_port,
	const char *rem_rtcp_ip, int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile,
346 347
	MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec);

348

Simon Morlat's avatar
Simon Morlat committed
349 350
MS2_PUBLIC void audio_stream_play(AudioStream *st, const char *name);
MS2_PUBLIC void audio_stream_record(AudioStream *st, const char *name);
aymeric's avatar
aymeric committed
351

352
static inline void audio_stream_set_rtcp_information(AudioStream *st, const char *cname, const char *tool) {
Ghislain MARY's avatar
Ghislain MARY committed
353 354
	media_stream_set_rtcp_information(&st->ms, cname, tool);
}
aymeric's avatar
aymeric committed
355

Simon Morlat's avatar
Simon Morlat committed
356
MS2_PUBLIC void audio_stream_play_received_dtmfs(AudioStream *st, bool_t yesno);
smorlat's avatar
smorlat committed
357

358 359
/**
 * Creates an AudioStream object listening on a RTP port.
360 361
 * @param loc_rtp_port the local UDP port to listen for RTP packets.
 * @param loc_rtcp_port the local UDP port to listen for RTCP packets
362 363 364
 * @param ipv6 TRUE if ipv6 must be used.
 * @returns a new AudioStream.
**/
365
MS2_PUBLIC AudioStream *audio_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6);
Simon Morlat's avatar
Simon Morlat committed
366

367 368
/**Creates an AudioStream object from initialized MSMediaStreamSessions.
 * @param sessions the MSMediaStreamSessions
369 370 371 372
 * @returns a new AudioStream
**/
MS2_PUBLIC AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *sessions);

373 374 375 376 377 378 379 380
#define AUDIO_STREAM_FEATURE_PLC 		(1 << 0)
#define AUDIO_STREAM_FEATURE_EC 		(1 << 1)
#define AUDIO_STREAM_FEATURE_EQUALIZER		(1 << 2)
#define AUDIO_STREAM_FEATURE_VOL_SND 		(1 << 3)
#define AUDIO_STREAM_FEATURE_VOL_RCV 		(1 << 4)
#define AUDIO_STREAM_FEATURE_DTMF		(1 << 5)
#define AUDIO_STREAM_FEATURE_DTMF_ECHO		(1 << 6)
#define AUDIO_STREAM_FEATURE_MIXED_RECORDING	(1 << 7)
381
#define AUDIO_STREAM_FEATURE_LOCAL_PLAYING	(1 << 8)
382

Yann Diorcet's avatar
Yann Diorcet committed
383 384 385 386 387 388 389
#define AUDIO_STREAM_FEATURE_ALL	(\
					AUDIO_STREAM_FEATURE_PLC | \
					AUDIO_STREAM_FEATURE_EC | \
					AUDIO_STREAM_FEATURE_EQUALIZER | \
					AUDIO_STREAM_FEATURE_VOL_SND | \
					AUDIO_STREAM_FEATURE_VOL_RCV | \
					AUDIO_STREAM_FEATURE_DTMF | \
390
					AUDIO_STREAM_FEATURE_DTMF_ECHO |\
391 392
					AUDIO_STREAM_FEATURE_MIXED_RECORDING |\
					AUDIO_STREAM_FEATURE_LOCAL_PLAYING \
Yann Diorcet's avatar
Yann Diorcet committed
393 394
					)

395

Yann Diorcet's avatar
Yann Diorcet committed
396 397
MS2_PUBLIC uint32_t audio_stream_get_features(AudioStream *st);
MS2_PUBLIC void audio_stream_set_features(AudioStream *st, uint32_t features);
398

Simon Morlat's avatar
Simon Morlat committed
399 400 401
MS2_PUBLIC void audio_stream_prepare_sound(AudioStream *st, MSSndCard *playcard, MSSndCard *captcard);
MS2_PUBLIC void audio_stream_unprepare_sound(AudioStream *st);
MS2_PUBLIC bool_t audio_stream_started(AudioStream *stream);
402 403
/**
 * Starts an audio stream from local soundcards.
404
 *
405 406
 * This method starts the processing of the audio stream, that is capture from soundcard, voice processing, encoding,
 * sending through RTP, receiving from RTP, decoding, voice processing and soundcard playback.
407
 *
408 409 410 411 412 413 414 415 416 417 418
 * @param stream an AudioStream previously created with audio_stream_new().
 * @param prof a RtpProfile containing all PayloadType possible during the audio session.
 * @param remip remote IP address where to send the encoded audio.
 * @param remport remote IP port where to send the encoded audio
 * @param rem_rtcp_port remote port for RTCP.
 * @param payload_type payload type index to use for the sending stream. This index must point to a valid PayloadType in the RtpProfile.
 * @param jitt_comp Nominal jitter buffer size in milliseconds.
 * @param playcard The soundcard to be used for playback
 * @param captcard The soundcard to be used for catpure.
 * @param echo_cancel whether echo cancellation is to be performed.
**/
Simon Morlat's avatar
Simon Morlat committed
419 420
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);
MS2_PUBLIC void audio_stream_set_relay_session_id(AudioStream *stream, const char *relay_session_id);
aymeric's avatar
aymeric committed
421
/*returns true if we are still receiving some data from remote end in the last timeout seconds*/
Simon Morlat's avatar
Simon Morlat committed
422
MS2_PUBLIC bool_t audio_stream_alive(AudioStream * stream, int timeout);
aymeric's avatar
aymeric committed
423

424 425 426 427
/**
 * Executes background low priority tasks related to audio processing (RTP statistics analysis).
 * It should be called periodically, for example with an interval of 100 ms or so.
 */
428 429
MS2_PUBLIC void audio_stream_iterate(AudioStream *stream);

jehan's avatar
jehan committed
430 431 432
/**
 * enable echo-limiter dispositve: one MSVolume in input branch controls a MSVolume in the output branch
 * */
Simon Morlat's avatar
Simon Morlat committed
433
MS2_PUBLIC void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type);
434

jehan's avatar
jehan committed
435 436 437
/**
 * enable gain control, to be done before start()
 * */
Simon Morlat's avatar
Simon Morlat committed
438
MS2_PUBLIC void audio_stream_enable_gain_control(AudioStream *stream, bool_t val);
smorlat's avatar
smorlat committed
439

jehan's avatar
jehan committed
440 441 442
/**
 * enable automatic gain control, to be done before start()
 * */
Simon Morlat's avatar
Simon Morlat committed
443
MS2_PUBLIC void audio_stream_enable_automatic_gain_control(AudioStream *stream, bool_t val);
444

jehan's avatar
jehan committed
445 446 447
/**
 * to be done before start
 *  */
Simon Morlat's avatar
Simon Morlat committed
448
MS2_PUBLIC void audio_stream_set_echo_canceller_params(AudioStream *st, int tail_len_ms, int delay_ms, int framesize);
449

jehan's avatar
jehan committed
450 451 452
/**
 * enable adaptive rate control
 * */
453
static inline void audio_stream_enable_adaptive_bitrate_control(AudioStream *stream, bool_t enabled) {
Ghislain MARY's avatar
Ghislain MARY committed
454 455
	media_stream_enable_adaptive_bitrate_control(&stream->ms, enabled);
}
456

jehan's avatar
jehan committed
457 458 459
/**
 *  Enable adaptive jitter compensation
 *  */
460
static inline void audio_stream_enable_adaptive_jittcomp(AudioStream *stream, bool_t enabled) {
Ghislain MARY's avatar
Ghislain MARY committed
461 462
	media_stream_enable_adaptive_jittcomp(&stream->ms, enabled);
}
463

Simon Morlat's avatar
Simon Morlat committed
464
MS2_PUBLIC void audio_stream_set_mic_gain(AudioStream *stream, float gain);
smorlat's avatar
smorlat committed
465

jehan's avatar
jehan committed
466 467 468
/**
 *  enable/disable rtp stream
 *  */
Simon Morlat's avatar
Simon Morlat committed
469
MS2_PUBLIC void audio_stream_mute_rtp(AudioStream *stream, bool_t val);
Simon Morlat's avatar
Simon Morlat committed
470

jehan's avatar
jehan committed
471 472 473
/**
 * enable noise gate, must be done before start()
 * */
Simon Morlat's avatar
Simon Morlat committed
474
MS2_PUBLIC void audio_stream_enable_noise_gate(AudioStream *stream, bool_t val);
475

jehan's avatar
jehan committed
476 477 478
/**
 * enable parametric equalizer in the stream that goes to the speaker
 * */
Simon Morlat's avatar
Simon Morlat committed
479
MS2_PUBLIC void audio_stream_enable_equalizer(AudioStream *stream, bool_t enabled);
smorlat's avatar
smorlat committed
480

Simon Morlat's avatar
Simon Morlat committed
481
MS2_PUBLIC void audio_stream_equalizer_set_gain(AudioStream *stream, int frequency, float gain, int freq_width);
smorlat's avatar
smorlat committed
482

jehan's avatar
jehan committed
483 484 485
/**
 *  stop the audio streaming thread and free everything
 *  */
Simon Morlat's avatar
Simon Morlat committed
486
MS2_PUBLIC void audio_stream_stop (AudioStream * stream);
aymeric's avatar
aymeric committed
487

jehan's avatar
jehan committed
488 489 490
/**
 *  send a dtmf
 *  */
Simon Morlat's avatar
Simon Morlat committed
491
MS2_PUBLIC int audio_stream_send_dtmf (AudioStream * stream, char dtmf);
aymeric's avatar
aymeric committed
492

493 494
MS2_PUBLIC MSFilter *audio_stream_get_local_player(AudioStream *stream);

495 496 497 498 499 500
MS2_PUBLIC int audio_stream_mixed_record_open(AudioStream *st, const char*filename);

MS2_PUBLIC int audio_stream_mixed_record_start(AudioStream *st);

MS2_PUBLIC int audio_stream_mixed_record_stop(AudioStream *st);

Simon Morlat's avatar
Simon Morlat committed
501
MS2_PUBLIC void audio_stream_set_default_card(int cardindex);
aymeric's avatar
aymeric committed
502

Simon Morlat's avatar
Simon Morlat committed
503
/* retrieve RTP statistics*/
504
static inline void audio_stream_get_local_rtp_stats(AudioStream *stream, rtp_stats_t *stats) {
Ghislain MARY's avatar
Ghislain MARY committed
505 506
	media_stream_get_local_rtp_stats(&stream->ms, stats);
}
Simon Morlat's avatar
Simon Morlat committed
507

508
/* returns a realtime indicator of the stream quality between 0 and 5 */
509 510
MS2_PUBLIC float audio_stream_get_quality_rating(AudioStream *stream);

511 512
/* returns the quality rating as an average since the start of the streaming session.*/
MS2_PUBLIC float audio_stream_get_average_quality_rating(AudioStream *stream);
aymeric's avatar
aymeric committed
513

514 515 516 517 518 519
/* returns a realtime indicator of the listening quality of the stream between 0 and 5 */
MS2_PUBLIC float audio_stream_get_lq_quality_rating(AudioStream *stream);

/* returns the listening quality rating as an average since the start of the streaming session.*/
MS2_PUBLIC float audio_stream_get_average_lq_quality_rating(AudioStream *stream);

Guillaume Beraudo's avatar
Guillaume Beraudo committed
520 521
/* enable ZRTP on the audio stream */
MS2_PUBLIC void audio_stream_enable_zrtp(AudioStream *stream, OrtpZrtpParams *params);
jehan's avatar
jehan committed
522 523 524 525
/**
 * 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 #
 * */
bool_t  audio_stream_zrtp_enabled(const AudioStream *stream);
Guillaume Beraudo's avatar
Guillaume Beraudo committed
526

527
/* enable SRTP on the audio stream */
jehan's avatar
jehan committed
528
static inline bool_t audio_stream_enable_srtp(AudioStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key) {
Ghislain MARY's avatar
Ghislain MARY committed
529 530
	return media_stream_enable_srtp(&stream->ms, suite, snd_key, rcv_key);
}
Guillaume Beraudo's avatar
Guillaume Beraudo committed
531

532
static inline int audio_stream_set_dscp(AudioStream *stream, int dscp) {
Ghislain MARY's avatar
Ghislain MARY committed
533 534
	return media_stream_set_dscp(&stream->ms, dscp);
}
Simon Morlat's avatar
Simon Morlat committed
535

536 537 538 539 540 541 542 543 544
/**
 * @}
**/


/**
 * @addtogroup video_stream_api
 * @{
**/
aymeric's avatar
aymeric committed
545

546
typedef void (*VideoStreamRenderCallback)(void *user_pointer, const MSPicture *local_view, const MSPicture *remote_view);
547 548 549
typedef void (*VideoStreamEventCallback)(void *user_pointer, const MSFilter *f, const unsigned int event_id, const void *args);


550 551 552 553 554 555
typedef enum _VideoStreamDir{
	VideoStreamSendRecv,
	VideoStreamSendOnly,
	VideoStreamRecvOnly
}VideoStreamDir;

aymeric's avatar
aymeric committed
556 557
struct _VideoStream
{
Ghislain MARY's avatar
Ghislain MARY committed
558
	MediaStream ms;
aymeric's avatar
aymeric committed
559 560
	MSFilter *source;
	MSFilter *pixconv;
561
	MSFilter *sizeconv;
aymeric's avatar
aymeric committed
562 563
	MSFilter *tee;
	MSFilter *output;
564 565
	MSFilter *tee2;
	MSFilter *jpegwriter;
566
	MSFilter *output2;
smorlat's avatar
smorlat committed
567
	MSVideoSize sent_vsize;
smorlat's avatar
smorlat committed
568
	int corner; /*for selfview*/
569 570
	VideoStreamRenderCallback rendercb;
	void *render_pointer;
571 572
	VideoStreamEventCallback eventcb;
	void *event_pointer;
573
	char *display_name;
574 575
	unsigned long window_id;
	unsigned long preview_window_id;
576
	VideoStreamDir dir;
577
	MSWebCam *cam;
578
	int device_orientation; /* warning: meaning of this variable depends on the platform (Android, iOS, ...) */
Ghislain MARY's avatar
Ghislain MARY committed
579
	bool_t use_preview_window;
580
	bool_t freeze_on_error;
Ghislain MARY's avatar
Ghislain MARY committed
581
	bool_t display_filter_auto_rotate_enabled;
582 583
	bool_t source_performs_encoding;
	bool_t output_performs_decoding;
584
	uint64_t last_reported_decoding_error_time;
aymeric's avatar
aymeric committed
585 586 587
};

typedef struct _VideoStream VideoStream;
smorlat's avatar
smorlat committed
588

589

590
MS2_PUBLIC VideoStream *video_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t use_ipv6);
591
MS2_PUBLIC VideoStream *video_stream_new_with_sessions(const MSMediaStreamSessions *sessions);
Simon Morlat's avatar
Simon Morlat committed
592
MS2_PUBLIC void video_stream_set_direction(VideoStream *vs, VideoStreamDir dir);
593
static inline void video_stream_enable_adaptive_bitrate_control(VideoStream *stream, bool_t enabled) {
Ghislain MARY's avatar
Ghislain MARY committed
594 595
	media_stream_enable_adaptive_bitrate_control(&stream->ms, enabled);
}
596
static inline void video_stream_enable_adaptive_jittcomp(VideoStream *stream, bool_t enabled) {
Ghislain MARY's avatar
Ghislain MARY committed
597 598
	media_stream_enable_adaptive_jittcomp(&stream->ms, enabled);
}
Simon Morlat's avatar
Simon Morlat committed
599 600 601
MS2_PUBLIC void video_stream_set_render_callback(VideoStream *s, VideoStreamRenderCallback cb, void *user_pointer);
MS2_PUBLIC void video_stream_set_event_callback(VideoStream *s, VideoStreamEventCallback cb, void *user_pointer);
MS2_PUBLIC void video_stream_set_display_filter_name(VideoStream *s, const char *fname);
602
MS2_PUBLIC int video_stream_start(VideoStream * stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port, const char *rem_rtcp_ip, int rem_rtcp_port,
aymeric's avatar
aymeric committed
603
		int payload, int jitt_comp, MSWebCam *device);
604 605
MS2_PUBLIC void video_stream_prepare_video(VideoStream *stream);
MS2_PUBLIC void video_stream_unprepare_video(VideoStream *stream);
606 607


Simon Morlat's avatar
Simon Morlat committed
608
MS2_PUBLIC void video_stream_set_relay_session_id(VideoStream *stream, const char *relay_session_id);
609
static inline void video_stream_set_rtcp_information(VideoStream *st, const char *cname, const char *tool) {
Ghislain MARY's avatar
Ghislain MARY committed
610 611
	media_stream_set_rtcp_information(&st->ms, cname, tool);
}
Simon Morlat's avatar
Simon Morlat committed
612
MS2_PUBLIC void video_stream_change_camera(VideoStream *stream, MSWebCam *cam);
613 614
/* Calling video_stream_set_sent_video_size() or changing the bitrate value in the used PayloadType during a stream is running does nothing.
The following function allows to take into account new parameters by redrawing the sending graph*/
Simon Morlat's avatar
Simon Morlat committed
615
MS2_PUBLIC void video_stream_update_video_params(VideoStream *stream);
aymeric's avatar
aymeric committed
616
/*function to call periodically to handle various events */
Simon Morlat's avatar
Simon Morlat committed
617
MS2_PUBLIC void video_stream_iterate(VideoStream *stream);
618 619 620 621 622 623 624 625 626 627 628

/**
 * Ask the video stream to send a Full-Intra Request.
 * @param[in] stream The videostream object.
 */
MS2_PUBLIC void video_stream_send_fir(VideoStream *stream);

/**
 * Ask the video stream to generate a Video Fast Update (generally after receiving a Full-Intra Request.
 * @param[in] stream The videostream object.
 */
Simon Morlat's avatar
Simon Morlat committed
629
MS2_PUBLIC void video_stream_send_vfu(VideoStream *stream);
630

Simon Morlat's avatar
Simon Morlat committed
631 632
MS2_PUBLIC void video_stream_stop(VideoStream * stream);
MS2_PUBLIC void video_stream_set_sent_video_size(VideoStream *stream, MSVideoSize vsize);
633 634 635 636 637 638

/**
 * Gets the size of the video that is sent.
 * @param[in] stream The videostream for which to get the sent video size.
 * @return The sent video size or MS_VIDEO_SIZE_UNKNOWN if not available.
 */
Ghislain MARY's avatar
Ghislain MARY committed
639
MS2_PUBLIC MSVideoSize video_stream_get_sent_video_size(const VideoStream *stream);
640 641 642 643 644 645

/**
 * Gets the size of the video that is received.
 * @param[in] stream The videostream for which to get the received video size.
 * @return The received video size or MS_VIDEO_SIZE_UNKNOWN if not available.
 */
Ghislain MARY's avatar
Ghislain MARY committed
646
MS2_PUBLIC MSVideoSize video_stream_get_received_video_size(const VideoStream *stream);
647

Simon Morlat's avatar
Simon Morlat committed
648 649 650 651 652
/**
 * Returns the name of the video display filter on the current platform.
**/
const char *video_stream_get_default_video_renderer(void);

Simon Morlat's avatar
Simon Morlat committed
653 654 655 656 657 658
MS2_PUBLIC void video_stream_enable_self_view(VideoStream *stream, bool_t val);
MS2_PUBLIC unsigned long video_stream_get_native_window_id(VideoStream *stream);
MS2_PUBLIC void video_stream_set_native_window_id(VideoStream *stream, unsigned long id);
MS2_PUBLIC void video_stream_set_native_preview_window_id(VideoStream *stream, unsigned long id);
MS2_PUBLIC unsigned long video_stream_get_native_preview_window_id(VideoStream *stream);
MS2_PUBLIC void video_stream_use_preview_video_window(VideoStream *stream, bool_t yesno);
659
MS2_PUBLIC void video_stream_set_device_rotation(VideoStream *stream, int orientation);
660
MS2_PUBLIC void video_stream_show_video(VideoStream *stream, bool_t show);
661
MS2_PUBLIC void video_stream_set_freeze_on_error(VideoStream *stream, bool_t yesno);
662

663 664 665 666 667 668 669 670 671 672 673
/**
 * @brief Gets the camera sensor rotation.
 *
 * This is needed on some mobile platforms to get the number of degrees the camera sensor
 * is rotated relative to the screen.
 *
 * @param stream The video stream related to the operation
 * @return The camera sensor rotation in degrees (0 to 360) or -1 if it could not be retrieved
 */
MS2_PUBLIC int video_stream_get_camera_sensor_rotation(VideoStream *stream);

674
/*provided for compatibility, use video_stream_set_direction() instead */
Simon Morlat's avatar
Simon Morlat committed
675 676
MS2_PUBLIC int video_stream_recv_only_start(VideoStream *videostream, RtpProfile *profile, const char *addr, int port, int used_pt, int jitt_comp);
MS2_PUBLIC int video_stream_send_only_start(VideoStream *videostream,
677
				RtpProfile *profile, const char *addr, int port, int rtcp_port,
678
				int used_pt, int  jitt_comp, MSWebCam *device);
Simon Morlat's avatar
Simon Morlat committed
679 680
MS2_PUBLIC void video_stream_recv_only_stop(VideoStream *vs);
MS2_PUBLIC void video_stream_send_only_stop(VideoStream *vs);
aymeric's avatar
aymeric committed
681

Guillaume Beraudo's avatar
Guillaume Beraudo committed
682 683
/* enable ZRTP on the video stream using information from the audio stream */
MS2_PUBLIC void video_stream_enable_zrtp(VideoStream *vstream, AudioStream *astream, OrtpZrtpParams *param);
684

685
/* enable SRTP on the video stream */
jehan's avatar
jehan committed
686
static inline bool_t video_stream_enable_strp(VideoStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key) {
Ghislain MARY's avatar
Ghislain MARY committed
687 688 689
	return media_stream_enable_srtp(&stream->ms, suite, snd_key, rcv_key);
}

690 691
/* if enabled, the display filter will internaly rotate the video, according to the device orientation */
MS2_PUBLIC void video_stream_enable_display_filter_auto_rotate(VideoStream* stream, bool_t enable);
692

693
/* retrieve RTP statistics*/
694
static inline void video_stream_get_local_rtp_stats(VideoStream *stream, rtp_stats_t *stats) {
Ghislain MARY's avatar
Ghislain MARY committed
695 696
	media_stream_get_local_rtp_stats(&stream->ms, stats);
}
697

698
static inline int video_stream_set_dscp(VideoStream *stream, int dscp) {
Ghislain MARY's avatar
Ghislain MARY committed
699 700
	return media_stream_set_dscp(&stream->ms, dscp);
}
Simon Morlat's avatar
Simon Morlat committed
701

702 703 704 705 706 707 708 709 710 711 712 713 714 715
/**
 * Ask the video stream whether a decoding error should be reported (eg. to send a VFU request).
 * @param[in] stream The VideoStream object.
 * @param[in] ms The minimum interval in milliseconds between to decoding error report.
 * @return TRUE if the decoding error should be reported, FALSE otherwise.
 */
MS2_PUBLIC bool_t video_stream_is_decoding_error_to_be_reported(VideoStream *stream, uint32_t ms);

/**
 * Tell the video stream that a decoding error has been reported.
 * @param[in] stream The VideoStream object.
 */
MS2_PUBLIC void video_stream_decoding_error_reported(VideoStream *stream);

716 717 718 719
/**
 * Small API to display a local preview window.
**/

Simon Morlat's avatar
Simon Morlat committed
720 721
typedef VideoStream VideoPreview;

Simon Morlat's avatar
Simon Morlat committed
722
MS2_PUBLIC VideoPreview * video_preview_new();
Simon Morlat's avatar
Simon Morlat committed
723 724 725 726
#define video_preview_set_size(p,s) 							video_stream_set_sent_video_size(p,s)
#define video_preview_set_display_filter_name(p,dt)	video_stream_set_display_filter_name(p,dt)
#define video_preview_set_native_window_id(p,id)		video_stream_set_native_preview_window_id (p,id)
#define video_preview_get_native_window_id(p)			video_stream_get_native_preview_window_id (p)
Simon Morlat's avatar
Simon Morlat committed
727 728
MS2_PUBLIC void video_preview_start(VideoPreview *stream, MSWebCam *device);
MS2_PUBLIC void video_preview_stop(VideoPreview *stream);
aymeric's avatar
aymeric committed
729

730 731 732 733
/**
 * @}
**/

Simon Morlat's avatar
Simon Morlat committed
734
MS2_PUBLIC bool_t ms_is_ipv6(const char *address);
aymeric's avatar
aymeric committed
735

Guillaume Beraudo's avatar
Guillaume Beraudo committed
736

aymeric's avatar
aymeric committed
737 738 739 740 741
#ifdef __cplusplus
}
#endif

#endif