Commit a7bb55e0 authored by Simon Morlat's avatar Simon Morlat

factorize source code around initialization and de-initialization of zrtp and dtls context

It fixes an invalid read reported by valgrind
parent 8ce8635e
......@@ -142,7 +142,7 @@ struct _MediaStream {
MSFactory *factory;
};
MS2_PUBLIC void media_stream_init(MediaStream *stream, MSFactory *factory);
MS2_PUBLIC void media_stream_init(MediaStream *stream, MSFactory *factory, const MSMediaStreamSessions *sessions);
/**
......
......@@ -86,13 +86,6 @@ static void audio_stream_free(AudioStream *stream) {
if (stream->outbound_mixer) ms_filter_destroy(stream->outbound_mixer);
if (stream->recorder_file) ms_free(stream->recorder_file);
if (stream->rtp_io_session) rtp_session_destroy(stream->rtp_io_session);
if (stream->ms.sessions.zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(stream->ms.sessions.zrtp_context, NULL);
}
if (stream->ms.sessions.dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(stream->ms.sessions.dtls_context, NULL);
}
ms_free(stream);
}
......@@ -1451,18 +1444,11 @@ AudioStream *audio_stream_new_with_sessions(MSFactory *factory, const MSMediaStr
};
stream->ms.type = MSAudio;
stream->ms.sessions = *sessions;
media_stream_init(&stream->ms,factory);
media_stream_init(&stream->ms,factory, sessions);
ms_factory_enable_statistics(factory, TRUE);
ms_factory_reset_statistics(factory);
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions));
}
if (sessions->dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(sessions->dtls_context, &(stream->ms.sessions));
}
rtp_session_resync(stream->ms.sessions.rtp_session);
/*some filters are created right now to allow configuration by the application before start() */
stream->ms.rtpsend=ms_factory_create_filter(factory, MS_RTP_SEND_ID);
......
......@@ -101,11 +101,21 @@ MSTickerPrio __ms_get_default_prio(bool_t is_video) {
}
}
void media_stream_init(MediaStream *stream, MSFactory *factory) {
void media_stream_init(MediaStream *stream, MSFactory *factory, const MSMediaStreamSessions *sessions) {
stream->sessions = *sessions;
stream->evd = ortp_ev_dispatcher_new(stream->sessions.rtp_session);
stream->evq = ortp_ev_queue_new();
stream->factory = factory; /*the factory is used later to instanciate everything in mediastreamer2.*/
rtp_session_register_event_queue(stream->sessions.rtp_session, stream->evq);
/*we give to the zrtp and dtls sessions a backpointer to all the stream sessions*/
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &stream->sessions);
}
if (sessions->dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(sessions->dtls_context, &stream->sessions);
}
}
RtpSession * ms_create_duplex_rtp_session(const char* local_ip, int loc_rtp_port, int loc_rtcp_port, int mtu) {
......@@ -171,6 +181,13 @@ void ms_media_stream_sessions_uninit(MSMediaStreamSessions *sessions){
}
void media_stream_free(MediaStream *stream) {
if (stream->sessions.zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(stream->sessions.zrtp_context, NULL);
}
if (stream->sessions.dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(stream->sessions.dtls_context, NULL);
}
if (stream->sessions.rtp_session != NULL) rtp_session_unregister_event_queue(stream->sessions.rtp_session, stream->evq);
if (stream->evq != NULL) ortp_ev_queue_destroy(stream->evq);
if (stream->evd != NULL) ortp_ev_dispatcher_destroy(stream->evd);
......
......@@ -45,18 +45,11 @@ TextStream *text_stream_new_with_sessions(MSFactory *factory, const MSMediaStrea
stream->pt_t140 = 0;
stream->ms.type = MSText;
stream->ms.sessions = *sessions;
media_stream_init(&stream->ms, factory);
media_stream_init(&stream->ms, factory, sessions);
ms_factory_enable_statistics(factory, TRUE);
ms_factory_reset_statistics(factory);
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions));
}
if (sessions->dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(sessions->dtls_context, &(stream->ms.sessions));
}
rtp_session_resync(stream->ms.sessions.rtp_session);
/*some filters are created right now to allow configuration by the application before start() */
stream->ms.rtpsend = ms_factory_create_filter(factory, MS_RTP_SEND_ID);
......
......@@ -296,13 +296,8 @@ VideoStream *video_stream_new_with_sessions(MSFactory* factory, const MSMediaStr
stream->ms.type = MSVideo;
stream->ms.sessions=*sessions;
media_stream_init(&stream->ms, factory);
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions));
}
if (sessions->dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(sessions->dtls_context, &(stream->ms.sessions));
}
media_stream_init(&stream->ms, factory, sessions);
rtp_session_resync(stream->ms.sessions.rtp_session);
stream->ms.qi=ms_quality_indicator_new(stream->ms.sessions.rtp_session);
ms_quality_indicator_set_label(stream->ms.qi,"video");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment