Commit 7f7befec authored by Simon Morlat's avatar Simon Morlat

extend the concept of IO descriptors for defining local input/output of...

extend the concept of IO descriptors for defining local input/output of AudioStream and VideoStream.
Big cleanup and rename many functions that were not following the usual conventions of mediastreamer2.
parent 5ca97404
......@@ -97,8 +97,6 @@ typedef enum _MSStreamState{
MSStreamStopped
}MSStreamState;
#define AudioStreamType MSAudio
#define VideoStreamType MSVideo
typedef enum MediaStreamDir{
MediaStreamSendRecv,
......@@ -293,20 +291,53 @@ typedef enum EqualizerLocation {
} EqualizerLocation;
typedef enum MSResourceType{
MSResourceInvalid,
MSResourceDefault,
MSResourceFile,
MSResourceRtp,
MSResourceCamera,
MSResourceSoundcard
}MSResourceType;
MS2_PUBLIC const char *ms_resource_type_to_string(MSResourceType type);
/**
* Structure describing the input/output of an AudioStream.
* Either fill playback_card and capture_card to use actual soundcards, or
* fill input_file and output_file to use read and record from/to wav files,
* or fill rtp_session to read/write to an RTP stream.
* Structure describing the input or the output of a MediaStream.
* type must be set to one the member of the MSResourceType enum, and the correspoding
* resource argument must be set: the file name (const char*) for MSResourceFile,
* the RtpSession for MSResourceRtp, an MSWebCam for MSResourceCamera, an MSSndCard for MSResourceSoundcard.
* @warning due to implementation, if RTP is to be used for input and output, the same RtpSession must be passed for both sides.
*/
typedef struct _AudioStreamIO {
MSSndCard *playback_card;
MSSndCard *capture_card;
const char *input_file;
const char *output_file;
RtpSession *rtp_session;
} AudioStreamIO;
typedef struct _MSMediaResource{
MSResourceType type;
union{
void *resource_arg;
const char *file;
RtpSession *session;
MSWebCam *camera;
MSSndCard *soundcard;
};
}MSMediaResource;
MS2_PUBLIC bool_t ms_media_resource_is_consistent(const MSMediaResource *r);
#define ms_media_resource_get_file(r) (((r)->type == MSResourceFile) ? (r)->file : NULL)
#define ms_media_resource_get_rtp_session(r) (((r)->type == MSResourceRtp) ? (r)->session : NULL)
#define ms_media_resource_get_camera(r) (((r)->type == MSResourceCamera) ? (r)->camera : NULL)
#define ms_media_resource_get_soundcard(r) (((r)->type == MSResourceSoundcard) ? (r)->souncard : NULL)
/**
* Structure describing the input/output of a MediaStream.
* Input and output are described as MSMediaResource.
*/
typedef struct _MSMediaStreamIO {
MSMediaResource input;
MSMediaResource output;
} MSMediaStreamIO;
#define MS_MEDIA_STREAM_IO_INITIALIZER { {0}, {0} }
MS2_PUBLIC bool_t ms_media_stream_io_is_consistent(const MSMediaStreamIO *io);
struct _AudioStream
{
......@@ -356,6 +387,7 @@ struct _AudioStream
int nchannels;
struct _VideoStream *videostream;/*the stream with which this audiostream is paired*/
bool_t play_dtmfs;
bool_t use_ec;
bool_t use_gc;
bool_t use_agc;
bool_t eq_active;
......@@ -389,13 +421,11 @@ MS2_PUBLIC int audio_stream_start_with_files (AudioStream * stream, RtpProfile *
* @param[in] rem_rtp_port The remote port where to send the encoded audio to.
* @param[in] rem_rtcp_ip The remote IP address for RTCP.
* @param[in] rem_rtcp_port The remote port for RTCP.
* @param[in] payload The payload type number used to send the audio stream. A valid PayloadType must be available at this index in the profile.
* @param[in] jitt_comp The nominal jitter buffer size in milliseconds.
* @param[in] use_ec A boolean telling whether to activate echo cancellation or not.
* @param[in] io An AudioStreamIO describing the input/output of the audio stream.
* @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.
* @param[in] io A MSMediaStreamIO describing the local input/output of the audio stream.
*/
MS2_PUBLIC int audio_stream_start_from_io(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, bool_t use_ec, AudioStreamIO *io);
const char *rem_rtcp_ip, int rem_rtcp_port, int payload_type, const MSMediaStreamIO *io);
/**
* Starts an audio stream from/to local wav files or soundcards.
......@@ -537,6 +567,11 @@ MS2_PUBLIC void audio_stream_enable_automatic_gain_control(AudioStream *stream,
* */
MS2_PUBLIC void audio_stream_set_echo_canceller_params(AudioStream *st, int tail_len_ms, int delay_ms, int framesize);
/**
* to be done before start
* */
MS2_PUBLIC void audio_stream_enable_echo_canceller(AudioStream *st, bool_t enabled);
/**
* enable adaptive rate control
* */
......@@ -712,21 +747,7 @@ typedef void (*VideoStreamRenderCallback)(void *user_pointer, const MSPicture *l
typedef void (*VideoStreamEventCallback)(void *user_pointer, const MSFilter *f, const unsigned int event_id, const void *args);
typedef enum _VideoStreamDir{
VideoStreamSendRecv,
VideoStreamSendOnly,
VideoStreamRecvOnly
}VideoStreamDir;
/**
* Structure describing the input/output of a VideoStream.
* Either fill cam to specify the camera to use as input and use the
* standard display, or fill rtp_session to read/write to an RTP stream.
*/
typedef struct _VideoStreamIO {
MSWebCam *cam;
RtpSession *rtp_session;
} VideoStreamIO;
struct _VideoStream
{
......@@ -755,7 +776,7 @@ struct _VideoStream
char *display_name;
void *window_id;
void *preview_window_id;
VideoStreamDir dir;
MediaStreamDir dir;
MSWebCam *cam;
RtpSession *rtp_io_session; /**< The RTP session used for RTP input/output. */
char *preset;
......@@ -785,7 +806,7 @@ MS2_PUBLIC VideoStream *video_stream_new(int loc_rtp_port, int loc_rtcp_port, bo
MS2_PUBLIC VideoStream *video_stream_new2(const char* ip, int loc_rtp_port, int loc_rtcp_port);
MS2_PUBLIC VideoStream *video_stream_new_with_sessions(const MSMediaStreamSessions *sessions);
MS2_PUBLIC void video_stream_set_direction(VideoStream *vs, VideoStreamDir dir);
MS2_PUBLIC void video_stream_set_direction(VideoStream *vs, MediaStreamDir dir);
static MS2_INLINE void video_stream_enable_adaptive_bitrate_control(VideoStream *stream, bool_t enabled) {
media_stream_enable_adaptive_bitrate_control(&stream->ms, enabled);
}
......@@ -797,8 +818,10 @@ MS2_PUBLIC void video_stream_set_event_callback(VideoStream *s, VideoStreamEvent
MS2_PUBLIC void video_stream_set_display_filter_name(VideoStream *s, const char *fname);
MS2_PUBLIC int video_stream_start_with_source(VideoStream *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, MSWebCam* cam, MSFilter* source);
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,
int payload, int jitt_comp, MSWebCam *device);
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, int payload, int jitt_comp, MSWebCam *device);
MS2_PUBLIC int video_stream_start_with_files(VideoStream *stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port,
const char *rem_rtcp_ip, int rem_rtcp_port, int payload_type, const char *play_file, const char *record_file);
/**
* Start a video stream according to the specified VideoStreamIO.
......@@ -809,12 +832,11 @@ MS2_PUBLIC int video_stream_start(VideoStream * stream, RtpProfile *profile, con
* @param[in] rem_rtp_port The remote port where to send the encoded video to.
* @param[in] rem_rtcp_ip The remote IP address for RTCP.
* @param[in] rem_rtcp_port The remote port for RTCP.
* @param[in] payload The payload type number used to send the video stream. A valid PayloadType must be available at this index in the profile.
* @param[in] jitt_comp The nominal jitter buffer size in milliseconds.
* @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.
* @param[in] io A VideoStreamIO describing the input/output of the video stream.
*/
MS2_PUBLIC int video_stream_start_from_io(VideoStream *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, VideoStreamIO *io);
const char *rem_rtcp_ip, int rem_rtcp_port, int payload_type, const MSMediaStreamIO *io);
MS2_PUBLIC void video_stream_prepare_video(VideoStream *stream);
MS2_PUBLIC void video_stream_unprepare_video(VideoStream *stream);
......
......@@ -27,7 +27,7 @@
extern "C"{
#endif
/* defined in mediastream.h */
struct _MSMediaStreamSessions;
typedef struct _MSMediaStreamSessions MSMediaStreamSessions;
/*
* Crypto suite used configure encrypted stream*/
......@@ -76,11 +76,11 @@ MS2_PUBLIC bool_t ms_srtp_supported(void);
* srtp session might be created/deleted depending on requirement parameter and already set keys
* @param[in/out] sessions The sessions associated to the current media stream
* @param[in] yesno If yes, any incoming/outgoing rtp packets are silently discarded.
* until key are provided using functions #media_stream_set_srtp_recv_key_b64 or #media_stream_set_srtp_recv_key
* until keys are provided using functions #media_stream_set_srtp_recv_key_b64 or #media_stream_set_srtp_recv_key
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_session_encryption_mandatory_enable(struct _MSMediaStreamSessions *sessions, bool_t yesno);
MS2_PUBLIC int ms_media_stream_sessions_set_encryption_mandatory(MSMediaStreamSessions *sessions, bool_t yesno);
/**
* Get encryption requirements.
......@@ -88,7 +88,7 @@ MS2_PUBLIC int media_stream_session_encryption_mandatory_enable(struct _MSMediaS
* @return TRUE if only encrypted rtp packet shall be sent/received
*/
MS2_PUBLIC bool_t media_stream_session_encryption_mandatory_enabled(const struct _MSMediaStreamSessions *sessions);
MS2_PUBLIC bool_t ms_media_stream_sessions_get_encryption_mandatory(const MSMediaStreamSessions *sessions);
/**
* Set srtp receiver key for the given media stream.
......@@ -99,7 +99,7 @@ MS2_PUBLIC bool_t media_stream_session_encryption_mandatory_enabled(const struct
* @param[in] key Srtp master key and master salt in a base 64 NULL terminated string
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_recv_key_b64(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key);
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_recv_key_b64(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key);
/**
* Set srtp receiver key for the given media stream.
......@@ -112,7 +112,7 @@ MS2_PUBLIC int media_stream_set_srtp_recv_key_b64(struct _MSMediaStreamSessions
* @param[in] stream_type Srtp suite is applied to RTP stream, RTCP stream or both
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_recv_key(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type);
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_recv_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type);
/**
* Set srtp sender key for the given media stream.
......@@ -123,7 +123,7 @@ MS2_PUBLIC int media_stream_set_srtp_recv_key(struct _MSMediaStreamSessions *ses
* @param[in] key Srtp master key and master salt in a base 64 NULL terminated string
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_send_key_b64(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key);
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_send_key_b64(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key);
/**
* Set srtp sender key for the given media stream.
......@@ -136,7 +136,7 @@ MS2_PUBLIC int media_stream_set_srtp_send_key_b64(struct _MSMediaStreamSessions
* @param[in] stream_type Srtp suite is applied to RTP stream, RTCP stream or both
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_send_key(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type);
MS2_PUBLIC int ms_media_stream_sessions_set_srtp_send_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type);
#ifdef __cplusplus
......
......@@ -830,20 +830,20 @@ static void shutdown_timer(CFRunLoopTimerRef timer, void *info){
static void check_unused(au_card_t *card){
if (card->read_data==NULL && card->write_data==NULL ){
if( !card->is_tester && card->shutdown_timer==NULL){
/*program the shutdown of the audio unit in a few seconds*/
CFRunLoopTimerContext ctx={0};
ctx.info=card;
card->shutdown_timer=CFRunLoopTimerCreate (
kCFAllocatorDefault,
CFAbsoluteTimeGetCurrent() + 2.5,
0,
0,
0,
shutdown_timer,
&ctx
);
CFRunLoopAddTimer(CFRunLoopGetMain(), card->shutdown_timer,kCFRunLoopCommonModes);
if (!card->is_tester && card->shutdown_timer==NULL){
/*program the shutdown of the audio unit in a few seconds*/
CFRunLoopTimerContext ctx={0};
ctx.info=card;
card->shutdown_timer=CFRunLoopTimerCreate (
kCFAllocatorDefault,
CFAbsoluteTimeGetCurrent() + 2.5,
0,
0,
0,
shutdown_timer,
&ctx
);
CFRunLoopAddTimer(CFRunLoopGetMain(), card->shutdown_timer,kCFRunLoopCommonModes);
} else if( card->is_tester ){
stop_audio_unit(card);
}
......
......@@ -499,20 +499,20 @@ static int ms_dtls_srtp_rtp_process_on_receive(struct _RtpTransportModifier *t,
/* reception(client write) key and salt +16bits padding */
memcpy(key, ctx->rtp_dtls_context->ssl.dtls_srtp_keys, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_recv_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
ms_media_stream_sessions_set_srtp_recv_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
/* emission(server write) key and salt +16bits padding */
memcpy(key, ctx->rtp_dtls_context->ssl.dtls_srtp_keys+DTLS_SRTP_KEY_LEN, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_send_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
ms_media_stream_sessions_set_srtp_send_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
} else if (ctx->role == MSDtlsSrtpRoleIsClient){ /* this enpoint act as DTLS client */
/* emission(client write) key and salt +16bits padding */
memcpy(key, ctx->rtp_dtls_context->ssl.dtls_srtp_keys, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_send_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
ms_media_stream_sessions_set_srtp_send_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
/* reception(server write) key and salt +16bits padding */
memcpy(key, ctx->rtp_dtls_context->ssl.dtls_srtp_keys+DTLS_SRTP_KEY_LEN, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_recv_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
ms_media_stream_sessions_set_srtp_recv_key(ctx->stream_sessions, agreed_srtp_protection_profile, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTP_STREAM);
}
ms_free(key);
......@@ -568,20 +568,20 @@ static int ms_dtls_srtp_rtcp_process_on_receive(struct _RtpTransportModifier *t,
/* reception(client write) key and salt +16bits padding */
memcpy(key, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_recv_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
ms_media_stream_sessions_set_srtp_recv_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
/* emission(server write) key and salt +16bits padding */
memcpy(key, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys+DTLS_SRTP_KEY_LEN, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_send_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
ms_media_stream_sessions_set_srtp_send_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
} else if (ctx->role == MSDtlsSrtpRoleIsClient){ /* this enpoint act as DTLS client */
/* emission(client write) key and salt +16bits padding */
memcpy(key, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_send_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
ms_media_stream_sessions_set_srtp_send_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
/* reception(server write) key and salt +16bits padding */
memcpy(key, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys+DTLS_SRTP_KEY_LEN, DTLS_SRTP_KEY_LEN);
memcpy(key + DTLS_SRTP_KEY_LEN, ctx->rtcp_dtls_context->ssl.dtls_srtp_keys+2*DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, DTLS_SRTP_SALT_LEN);
media_stream_set_srtp_recv_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
ms_media_stream_sessions_set_srtp_recv_key(ctx->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, DTLS_SRTP_KEY_LEN+DTLS_SRTP_SALT_LEN, MSSRTP_RTCP_STREAM);
}
ms_free(key);
......
......@@ -192,7 +192,7 @@ static void ms_srtp_transport_modifier_destroy(RtpTransportModifier *tp){
ms_free(tp);
}
static MSSrtpStreamContext* get_stream_context(struct _MSMediaStreamSessions *sessions, bool_t is_send, bool_t is_rtp) {
static MSSrtpStreamContext* get_stream_context(MSMediaStreamSessions *sessions, bool_t is_send, bool_t is_rtp) {
if (is_send && is_rtp)
return &sessions->srtp_context->send_rtp_context;
else if (is_send && !is_rtp)
......@@ -204,7 +204,7 @@ static MSSrtpStreamContext* get_stream_context(struct _MSMediaStreamSessions *se
}
static int ms_media_stream_session_fill_srtp_context(struct _MSMediaStreamSessions *sessions, bool_t is_send, bool_t is_rtp) {
static int ms_media_stream_session_fill_srtp_context(MSMediaStreamSessions *sessions, bool_t is_send, bool_t is_rtp) {
err_status_t err=0;
RtpTransport *transport=NULL;
MSSrtpStreamContext* stream_ctx = get_stream_context(sessions,is_send,is_rtp);
......@@ -244,7 +244,7 @@ end:
return err;
}
int ms_media_stream_session_fill_srtp_context_all_stream(struct _MSMediaStreamSessions *sessions) {
int ms_media_stream_sessions_fill_srtp_context_all_stream(struct _MSMediaStreamSessions *sessions) {
int err = -1;
/*check if exist before filling*/
......@@ -368,7 +368,7 @@ void ms_srtp_shutdown(void){
}
}
static int media_stream_set_srtp_key_base(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, bool_t is_send, bool_t is_rtp){
static int ms_media_stream_sessions_set_srtp_key_base(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, bool_t is_send, bool_t is_rtp){
MSSrtpStreamContext* stream_ctx;
uint32_t ssrc;
int error = -1;
......@@ -392,15 +392,15 @@ static int media_stream_set_srtp_key_base(struct _MSMediaStreamSessions *session
return 0;
}
static int media_stream_set_srtp_key(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, bool_t is_send, MSSrtpStreamType stream_type){
static int ms_media_stream_sessions_set_srtp_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, bool_t is_send, MSSrtpStreamType stream_type){
int error = 0;
if (stream_type == MSSRTP_ALL_STREAMS || stream_type == MSSRTP_RTP_STREAM) {
error=media_stream_set_srtp_key_base(sessions,suite,key,key_length,is_send,TRUE);
error=ms_media_stream_sessions_set_srtp_key_base(sessions,suite,key,key_length,is_send,TRUE);
}
if (error == 0 && (stream_type == MSSRTP_ALL_STREAMS || stream_type == MSSRTP_RTCP_STREAM)) {
error=media_stream_set_srtp_key_base(sessions,suite,key,key_length,is_send,FALSE);
error=ms_media_stream_sessions_set_srtp_key_base(sessions,suite,key,key_length,is_send,FALSE);
}
return error;
}
......@@ -413,7 +413,7 @@ bool_t ms_srtp_supported(void){
}
int media_stream_set_srtp_recv_key_b64(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
int ms_media_stream_sessions_set_srtp_recv_key_b64(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
int retval;
/* decode b64 key */
......@@ -427,14 +427,14 @@ int media_stream_set_srtp_recv_key_b64(struct _MSMediaStreamSessions *sessions,
}
/* pass decoded key to set_recv_key function */
retval = media_stream_set_srtp_recv_key(sessions, suite, key, key_length, MSSRTP_ALL_STREAMS);
retval = ms_media_stream_sessions_set_srtp_recv_key(sessions, suite, key, key_length, MSSRTP_ALL_STREAMS);
ms_free(key);
return retval;
}
bool_t media_stream_session_secured(const struct _MSMediaStreamSessions *sessions,MediaStreamDir dir) {
bool_t ms_media_stream_sessions_secured(const MSMediaStreamSessions *sessions,MediaStreamDir dir) {
if(!sessions->srtp_context)
return FALSE;
......@@ -449,10 +449,11 @@ bool_t media_stream_session_secured(const struct _MSMediaStreamSessions *session
}
int media_stream_set_srtp_recv_key(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type) {
return media_stream_set_srtp_key(sessions,suite,key,key_length,FALSE,stream_type);
int ms_media_stream_sessions_set_srtp_recv_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type) {
return ms_media_stream_sessions_set_srtp_key(sessions,suite,key,key_length,FALSE,stream_type);
}
int media_stream_set_srtp_send_key_b64(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
int ms_media_stream_sessions_set_srtp_send_key_b64(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
int retval;
/* decode b64 key */
......@@ -466,24 +467,24 @@ int media_stream_set_srtp_send_key_b64(struct _MSMediaStreamSessions *sessions,
}
/* pass decoded key to set_send_key function */
retval = media_stream_set_srtp_send_key(sessions, suite, key, key_length, MSSRTP_ALL_STREAMS);
retval = ms_media_stream_sessions_set_srtp_send_key(sessions, suite, key, key_length, MSSRTP_ALL_STREAMS);
ms_free(key);
return retval;
}
int media_stream_set_srtp_send_key(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type){
return media_stream_set_srtp_key(sessions,suite,key,key_length,TRUE,stream_type);
int ms_media_stream_sessions_set_srtp_send_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type){
return ms_media_stream_sessions_set_srtp_key(sessions,suite,key,key_length,TRUE,stream_type);
}
int media_stream_session_encryption_mandatory_enable(struct _MSMediaStreamSessions *sessions, bool_t yesno) {
/*for now, managing all stream in one time*/
int ms_media_stream_sessions_set_encryption_mandatory(MSMediaStreamSessions *sessions, bool_t yesno) {
/*for now, managing all streams in one time*/
int err;
check_and_create_srtp_context(sessions);
if (yesno) {
if ((err = ms_media_stream_session_fill_srtp_context_all_stream(sessions))) {
if ((err = ms_media_stream_sessions_fill_srtp_context_all_stream(sessions))) {
return err;;
}
}
......@@ -494,7 +495,7 @@ int media_stream_session_encryption_mandatory_enable(struct _MSMediaStreamSessio
return 0;
}
bool_t media_stream_session_encryption_mandatory_enabled(const struct _MSMediaStreamSessions *sessions) {
bool_t ms_media_stream_sessions_get_encryption_mandatory(const MSMediaStreamSessions *sessions) {
if(!sessions->srtp_context)
return FALSE;
......@@ -521,43 +522,45 @@ int ms_srtp_init(void) {
void ms_srtp_shutdown(void){
}
int media_stream_set_srtp_recv_key_b64(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
int ms_media_stream_sessions_set_srtp_recv_key_b64(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
ms_error("Unable to set srtp recv key b64: srtp support disabled in mediastreamer2");
return -1;
}
int media_stream_set_srtp_recv_key(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type){
int ms_media_stream_sessions_set_srtp_recv_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type){
ms_error("Unable to set srtp recv key: srtp support disabled in mediastreamer2");
return -1;
}
int media_stream_set_srtp_send_key_b64(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
int ms_media_stream_sessions_set_srtp_send_key_b64(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* b64_key){
ms_error("Unable to set srtp send key b64: srtp support disabled in mediastreamer2");
return -1;
}
int media_stream_set_srtp_send_key(struct _MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type){
int ms_media_stream_sessions_set_srtp_send_key(MSMediaStreamSessions *sessions, MSCryptoSuite suite, const char* key, size_t key_length, MSSrtpStreamType stream_type){
ms_error("Unable to set srtp send key: srtp support disabled in mediastreamer2");
return -1;
}
int media_stream_session_set_encryption_mandatory(struct _MSMediaStreamSessions *sessions, bool_t yesno) {
int media_stream_session_set_encryption_mandatory(MSMediaStreamSessions *sessions, bool_t yesno) {
ms_error("Unable to set srtp encryption mandatory mode: srtp support disabled in mediastreamer2");
return -1;
}
bool_t media_stream_session_get_encryption_mandatory(const struct _MSMediaStreamSessions *sessions) {
bool_t media_stream_session_get_encryption_mandatory(const MSMediaStreamSessions *sessions) {
ms_error("Unable to get srtp encryption mandatory mode: srtp support disabled in mediastreamer2");
return -1;
}
bool_t media_stream_session_secured(const struct _MSMediaStreamSessions *sessions,MediaStreamDir dir) {
bool_t ms_media_stream_sessions_secured(const MSMediaStreamSessions *sessions,MediaStreamDir dir) {
return FALSE;
}
void ms_srtp_context_delete(MSSrtpCtx* session) {
ms_error("Unable to delete srtp context [%p]: srtp support disabled in mediastreamer2",session);
}
int media_stream_session_encryption_mandatory_enable(struct _MSMediaStreamSessions *sessions, bool_t yesno) {
int ms_media_stream_sessions_set_encryption_mandatory(MSMediaStreamSessions *sessions, bool_t yesno) {
ms_error("Unable to set encryption_mandatory [%p]: srtp support disabled in mediastreamer2",sessions);
return -1;
}
......
......@@ -128,15 +128,15 @@ static int32_t ms_zrtp_srtpSecretsAvailable(void* clientData, bzrtpSrtpSecrets_t
if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS32){
if (secrets->cipherAlgo == ZRTP_CIPHER_AES3){
media_stream_set_srtp_recv_key(userData->stream_sessions, MS_AES_256_SHA1_32, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_recv_key(userData->stream_sessions, MS_AES_256_SHA1_32, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
}else{
media_stream_set_srtp_recv_key(userData->stream_sessions, MS_AES_128_SHA1_32, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_recv_key(userData->stream_sessions, MS_AES_128_SHA1_32, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
}
}else if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS80){
if (secrets->cipherAlgo == ZRTP_CIPHER_AES3){
media_stream_set_srtp_recv_key(userData->stream_sessions, MS_AES_256_SHA1_80, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_recv_key(userData->stream_sessions, MS_AES_256_SHA1_80, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
}else{
media_stream_set_srtp_recv_key(userData->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_recv_key(userData->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength), MSSRTP_ALL_STREAMS);
}
}else{
ms_fatal("unsupported auth tag");
......@@ -151,15 +151,15 @@ static int32_t ms_zrtp_srtpSecretsAvailable(void* clientData, bzrtpSrtpSecrets_t
if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS32){
if (secrets->cipherAlgo == ZRTP_CIPHER_AES3){
media_stream_set_srtp_send_key(userData->stream_sessions, MS_AES_256_SHA1_32, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_send_key(userData->stream_sessions, MS_AES_256_SHA1_32, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
}else{
media_stream_set_srtp_send_key(userData->stream_sessions, MS_AES_128_SHA1_32, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_send_key(userData->stream_sessions, MS_AES_128_SHA1_32, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
}
}else if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS80){
if (secrets->cipherAlgo == ZRTP_CIPHER_AES3){
media_stream_set_srtp_send_key(userData->stream_sessions, MS_AES_256_SHA1_80, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_send_key(userData->stream_sessions, MS_AES_256_SHA1_80, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
}else{
media_stream_set_srtp_send_key(userData->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
ms_media_stream_sessions_set_srtp_send_key(userData->stream_sessions, MS_AES_128_SHA1_80, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength), MSSRTP_ALL_STREAMS);
}
}else{
ms_fatal("unsupported auth tag");
......
......@@ -732,7 +732,7 @@ static int get_usable_telephone_event(RtpProfile *profile, int clock_rate){
}
int audio_stream_start_from_io(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, bool_t use_ec, AudioStreamIO *io) {
const char *rem_rtcp_ip, int rem_rtcp_port, int payload, const MSMediaStreamIO *io) {
RtpSession *rtps=stream->ms.sessions.rtp_session;
PayloadType *pt;
int tmp, tev_pt;
......@@ -740,6 +740,8 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
int sample_rate;
int nchannels;
bool_t has_builtin_ec=FALSE;
if (!ms_media_stream_io_is_consistent(io)) return -1;
rtp_session_set_profile(rtps,profile);
if (rem_rtp_port>0) rtp_session_set_remote_addr_full(rtps,rem_rtp_ip,rem_rtp_port,rem_rtcp_ip,rem_rtcp_port);
......@@ -749,7 +751,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
rtp_session_enable_rtcp(rtps, FALSE);
}
rtp_session_set_payload_type(rtps,payload);
rtp_session_set_jitter_compensation(rtps,jitt_comp);
if (rem_rtp_port>0)
ms_filter_call_method(stream->ms.rtpsend,MS_RTP_SEND_SET_SESSION,rtps);
......@@ -766,16 +767,16 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
if (stream->ms.state==MSStreamPreparing){
/*we were using the dummy preload graph, destroy it but keep sound filters unless no soundcard is given*/
_audio_stream_unprepare_sound(stream,io->capture_card!=NULL);
_audio_stream_unprepare_sound(stream, io->input.type == MSResourceSoundcard);
}
/* creates the local part */
if (io->capture_card!=NULL){
if (io->input.type == MSResourceSoundcard){
if (stream->soundread==NULL)
stream->soundread=ms_snd_card_create_reader(io->capture_card);
has_builtin_ec=!!(ms_snd_card_get_capabilities(io->capture_card) & MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER);
} else if (io->rtp_session != NULL) {
stream->rtp_io_session = io->rtp_session;
stream->soundread = ms_snd_card_create_reader(io->input.soundcard);
has_builtin_ec=!!(ms_snd_card_get_capabilities(io->input.soundcard) & MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER);
} else if (io->input.type == MSResourceRtp) {
stream->rtp_io_session = io->input.session;
pt = rtp_profile_get_payload(rtp_session_get_profile(stream->rtp_io_session),
rtp_session_get_recv_payload_type(stream->rtp_io_session));
stream->soundread = ms_filter_new(MS_RTP_RECV_ID);
......@@ -785,11 +786,11 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID);
stream->read_resampler=ms_filter_new(MS_RESAMPLE_ID);
}
if (io->playback_card!=NULL) {
if (io->output.type == MSResourceSoundcard) {
if (stream->soundwrite==NULL)
stream->soundwrite=ms_snd_card_create_writer(io->playback_card);
} else if (io->rtp_session != NULL) {
stream->rtp_io_session = io->rtp_session;
stream->soundwrite=ms_snd_card_create_writer(io->output.soundcard);
} else if (io->output.type == MSResourceRtp) {
stream->rtp_io_session = io->output.session;
pt = rtp_profile_get_payload(rtp_session_get_profile(stream->rtp_io_session),
rtp_session_get_send_payload_type(stream->rtp_io_session));
stream->soundwrite = ms_filter_new(MS_RTP_SEND_ID);
......@@ -832,7 +833,7 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
/* be able to use the echo canceller wich may be limited (webrtc aecm max frequency is 16000 Hz) */
// First check if we need to use the echo canceller
// Overide feature if not requested or done at sound card level
if ( ((stream->features & AUDIO_STREAM_FEATURE_EC) && !use_ec) || has_builtin_ec )
if ( ((stream->features & AUDIO_STREAM_FEATURE_EC) && !stream->use_ec) || has_builtin_ec )
stream->features &=~AUDIO_STREAM_FEATURE_EC;
/*configure the echo canceller if required */
......@@ -885,14 +886,15 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
stream->volrecv=ms_filter_new(MS_VOLUME_ID);
else
stream->volrecv=NULL;
audio_stream_enable_echo_limiter(stream,stream->el_type);
audio_stream_enable_noise_gate(stream,stream->use_ng);
if (ms_filter_implements_interface(stream->soundread,MSFilterPlayerInterface) && io->input_file){
audio_stream_play(stream,io->input_file);
if (ms_filter_implements_interface(stream->soundread,MSFilterPlayerInterface) && io->input.file){
audio_stream_play(stream,io->input.file);
}
if (ms_filter_implements_interface(stream->soundwrite,MSFilterRecorderInterface) && io->output_file){
audio_stream_record(stream,io->output_file);
if (ms_filter_implements_interface(stream->soundwrite,MSFilterRecorderInterface) && io->output.file){
audio_stream_record(stream,io->output.file);
}
if (stream->use_agc){
......@@ -925,7 +927,7 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
if (stream->ec){
if (!stream->is_ec_delay_set) {
int delay_ms=ms_snd_card_get_minimal_latency(io->capture_card);
int delay_ms=ms_snd_card_get_minimal_latency(io->input.soundcard);
ms_message("Setting echo canceller delay with value provided by soundcard: %i ms",delay_ms);
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_DELAY,&delay_ms);
} else {
......@@ -1132,12 +1134,26 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
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,
MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec){
AudioStreamIO io = { 0 };
io.playback_card = playcard;
io.capture_card = captcard;
io.input_file = infile;
io.output_file = outfile;
return audio_stream_start_from_io(stream, profile, rem_rtp_ip, rem_rtp_port, rem_rtcp_ip, rem_rtcp_port, payload, jitt_comp, use_ec, &io);
MSMediaStreamIO io = MS_MEDIA_STREAM_IO_INITIALIZER;
if (playcard){
io.output.type = MSResourceSoundcard;
io.output.soundcard = playcard;
}else{
io.output.type = MSResourceFile;
io.output.file = outfile;
}
if (captcard){
io.input.type = MSResourceSoundcard;
io.input.soundcard = captcard;
}else{
io.input.type = MSResourceFile;
io.input.file = infile;
}
if (jitt_comp != -1)
rtp_session_set_jitter_compensation(stream->ms.sessions.rtp_session, jitt_comp);
audio_stream_enable_echo_canceller(stream, use_ec);
return audio_stream_start_from_io(stream, profile, rem_rtp_ip, rem_rtp_port, rem_rtcp_ip, rem_rtcp_port, payload, &io);
}
int audio_stream_start_with_files(AudioStream *stream, RtpProfile *prof,const char *remip, int remport,
......@@ -1368,6 +1384,10 @@ void audio_stream_set_relay_session_id(AudioStream *stream, const char *id){
ms_filter_call_method(stream->ms.rtpsend, MS_RTP_SEND_SET_RELAY_SESSION_ID,(void*)id);
}
void audio_stream_enable_echo_canceller(AudioStream *st, bool_t enabled){
st->use_ec = enabled;
}
void audio_stream_set_echo_canceller_params(AudioStream *stream, int tail_len_ms, int delay_ms, int framesize){