Commit da5d1de6 authored by Simon Morlat's avatar Simon Morlat

enable reusing of rtp, srtp, zrtp sessions accross mediastream sessions.

parent 7111661b
......@@ -82,11 +82,30 @@ typedef struct _MediaStream MediaStream;
* */
typedef void (*media_stream_process_rtcp)(MediaStream *stream, mblk_t *m);
struct _MSMediaStreamSessions{
RtpSession *rtp_session;
srtp_t srtp_session;
OrtpZrtpContext *zrtp_context;
MSTicker *ticker;
};
typedef struct _MSMediaStreamSessions MSMediaStreamSessions;
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.
**/
struct _MediaStream {
StreamType type;
MSTicker *ticker;
RtpSession *session;
MSStreamState state;
MSMediaStreamSessions sessions;
OrtpEvQueue *evq;
MSFilter *rtprecv;
MSFilter *rtpsend;
......@@ -96,13 +115,12 @@ struct _MediaStream {
MSBitrateController *rc;
MSQualityIndicator *qi;
IceCheckList *ice_check_list;
OrtpZrtpContext *zrtp_context;
srtp_t srtp_session;
time_t start_time;
time_t last_iterate_time;
bool_t use_rc;
bool_t is_beginning;
bool_t pad[2];
bool_t owns_sessions;
bool_t pad[1];
/**
* defines encoder target network bit rate, uses #media_stream_set_network_bitrate() setter.
* */
......@@ -174,6 +192,12 @@ MS2_PUBLIC float media_stream_get_up_bw(const MediaStream *stream);
* */
MS2_PUBLIC float media_stream_get_down_bw(const MediaStream *stream);
/**
* 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);
void media_stream_iterate(MediaStream * stream);
......@@ -281,6 +305,12 @@ MS2_PUBLIC void audio_stream_play_received_dtmfs(AudioStream *st, bool_t yesno);
**/
MS2_PUBLIC AudioStream *audio_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6);
/**Creates an AudioStream object from an initialized RtpSession.
* @param rtp_session the RtpSession
* @returns a new AudioStream
**/
MS2_PUBLIC AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *sessions);
#define AUDIO_STREAM_FEATURE_PLC (1 << 0)
#define AUDIO_STREAM_FEATURE_EC (1 << 1)
#define AUDIO_STREAM_FEATURE_EQUALIZER (1 << 2)
......@@ -485,7 +515,6 @@ struct _VideoStream
int device_orientation; /* warning: meaning of this variable depends on the platform (Android, iOS, ...) */
bool_t use_preview_window;
bool_t display_filter_auto_rotate_enabled;
bool_t prepare_ongoing;
bool_t source_performs_encoding;
bool_t output_performs_decoding;
};
......@@ -494,6 +523,7 @@ typedef struct _VideoStream VideoStream;
MS2_PUBLIC VideoStream *video_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t use_ipv6);
MS2_PUBLIC VideoStream *video_stream_new_with_sessions(const MSMediaStreamSessions *sessions);
MS2_PUBLIC void video_stream_set_direction(VideoStream *vs, VideoStreamDir dir);
static inline void video_stream_enable_adaptive_bitrate_control(VideoStream *stream, bool_t enabled) {
media_stream_enable_adaptive_bitrate_control(&stream->ms, enabled);
......
......@@ -92,10 +92,10 @@ static inline void ms_debug(const char *fmt,...)
#define ms_fatal ortp_fatal
#define ms_return_val_if_fail(_expr_,_ret_)\
if (!(_expr_)) { ms_error("assert "#_expr_ "failed"); return (_ret_);}
if (!(_expr_)) { ms_fatal("assert "#_expr_ "failed"); return (_ret_);}
#define ms_return_if_fail(_expr_) \
if (!(_expr_)){ ms_error("assert "#_expr_ "failed"); return ;}
if (!(_expr_)){ ms_fatal("assert "#_expr_ "failed"); return ;}
#define ms_thread_t ortp_thread_t
#define ms_thread_create ortp_thread_create
......
......@@ -160,7 +160,7 @@ static void enc_init(MSFilter *f) {
#endif
ms_message("VP8 g_threads=%d", s->cfg.g_threads);
s->cfg.rc_undershoot_pct = 95; /* --undershoot-pct=95 */
s->cfg.g_error_resilient = 1;
s->cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT|VPX_ERROR_RESILIENT_PARTITIONS;
s->cfg.g_lag_in_frames = 0;
s->mtu=ms_get_payload_max_size()-1;/*-1 for the vp8 payload header*/
......
......@@ -87,8 +87,8 @@ static void cut_audio_stream_graph(MSAudioEndpoint *ep, bool_t is_remote){
AudioStream *st=ep->st;
/*stop the audio graph*/
ms_ticker_detach(st->ms.ticker,st->soundread);
if (!st->ec) ms_ticker_detach(st->ms.ticker,st->soundwrite);
ms_ticker_detach(st->ms.sessions.ticker,st->soundread);
if (!st->ec) ms_ticker_detach(st->ms.sessions.ticker,st->soundwrite);
ep->in_cut_point_prev.pin=0;
if (is_remote){
......@@ -121,9 +121,9 @@ static void redo_audio_stream_graph(MSAudioEndpoint *ep){
AudioStream *st=ep->st;
ms_filter_link(ep->in_cut_point_prev.filter,ep->in_cut_point_prev.pin,ep->in_cut_point.filter,ep->in_cut_point.pin);
ms_filter_link(ep->out_cut_point.filter,ep->out_cut_point.pin,st->ms.encoder,0);
ms_ticker_attach(st->ms.ticker,st->soundread);
ms_ticker_attach(st->ms.sessions.ticker,st->soundread);
if (!st->ec)
ms_ticker_attach(st->ms.ticker,st->soundwrite);
ms_ticker_attach(st->ms.sessions.ticker,st->soundwrite);
}
static int find_free_pin(MSFilter *mixer){
......
......@@ -36,7 +36,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/mscodecutils.h"
#include "private.h"
#include <sys/types.h>
#include <sys/types.h>
#ifndef WIN32
#include <sys/socket.h>
#include <netdb.h>
......@@ -117,7 +118,7 @@ static void audio_stream_process_rtcp(MediaStream *media_stream, mblk_t *m){
}
if (rb){
unsigned int ij;
float rt=rtp_session_get_round_trip_propagation(stream->ms.session);
float rt=rtp_session_get_round_trip_propagation(stream->ms.sessions.rtp_session);
float flost;
ij=report_block_get_interarrival_jitter(rb);
flost=(float)(100.0*report_block_get_fraction_lost(rb)/256.0);
......@@ -134,7 +135,7 @@ void audio_stream_iterate(AudioStream *stream){
}
bool_t audio_stream_alive(AudioStream * stream, int timeout){
const rtp_stats_t *stats=rtp_session_get_stats(stream->ms.session);
const rtp_stats_t *stats=rtp_session_get_stats(stream->ms.sessions.rtp_session);
if (stats->recv!=0){
if (stats->recv!=stream->last_packet_count){
stream->last_packet_count=stats->recv;
......@@ -152,18 +153,18 @@ bool_t audio_stream_alive(AudioStream * stream, int timeout){
/*invoked from FEC capable filters*/
static mblk_t* audio_stream_payload_picker(MSRtpPayloadPickerContext* context,unsigned int sequence_number) {
return rtp_session_pick_with_cseq(((AudioStream*)(context->filter_graph_manager))->ms.session, sequence_number);
return rtp_session_pick_with_cseq(((AudioStream*)(context->filter_graph_manager))->ms.sessions.rtp_session, sequence_number);
}
static void stop_preload_graph(AudioStream *stream){
ms_ticker_detach(stream->ms.ticker,stream->dummy);
if (stream->soundwrite) {
ms_filter_unlink(stream->dummy,0,stream->soundwrite,0);
}
ms_ticker_detach(stream->ms.sessions.ticker,stream->dummy);
if (stream->ms.voidsink) {
ms_filter_unlink(stream->dummy,0,stream->ms.voidsink,0);
ms_filter_destroy(stream->ms.voidsink);
stream->ms.voidsink=NULL;
}else if (stream->soundwrite) {
ms_filter_unlink(stream->dummy,0,stream->soundwrite,0);
}
ms_filter_destroy(stream->dummy);
stream->dummy=NULL;
......@@ -177,8 +178,8 @@ bool_t audio_stream_started(AudioStream *stream){
void audio_stream_prepare_sound(AudioStream *stream, MSSndCard *playcard, MSSndCard *captcard){
audio_stream_unprepare_sound(stream);
stream->dummy=ms_filter_new(MS_RTP_RECV_ID);
rtp_session_set_payload_type(stream->ms.session,0);
ms_filter_call_method(stream->dummy,MS_RTP_RECV_SET_SESSION,stream->ms.session);
rtp_session_set_payload_type(stream->ms.sessions.rtp_session,0);
ms_filter_call_method(stream->dummy,MS_RTP_RECV_SET_SESSION,stream->ms.sessions.rtp_session);
if (captcard && playcard){
#ifdef __ios
......@@ -193,12 +194,13 @@ void audio_stream_prepare_sound(AudioStream *stream, MSSndCard *playcard, MSSndC
stream->ms.voidsink=ms_filter_new(MS_VOID_SINK_ID);
ms_filter_link(stream->dummy,0,stream->ms.voidsink,0);
}
if (stream->ms.ticker == NULL) start_ticker(&stream->ms);
ms_ticker_attach(stream->ms.ticker,stream->dummy);
if (stream->ms.sessions.ticker == NULL) media_stream_start_ticker(&stream->ms);
ms_ticker_attach(stream->ms.sessions.ticker,stream->dummy);
stream->ms.state=MSStreamPreparing;
}
void audio_stream_unprepare_sound(AudioStream *stream){
if (stream->dummy){
if (stream->ms.state==MSStreamPreparing){
stop_preload_graph(stream);
#ifdef __ios
if (stream->soundread) ms_filter_destroy(stream->soundread);
......@@ -207,6 +209,7 @@ void audio_stream_unprepare_sound(AudioStream *stream){
stream->soundwrite=NULL;
#endif
}
stream->ms.state=MSStreamInitialized;
}
static void player_callback(void *ud, MSFilter *f, unsigned int id, void *arg){
......@@ -295,9 +298,8 @@ static float audio_stream_get_rtcp_xr_average_lq_quality_rating(unsigned long us
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)
{
RtpSession *rtps=stream->ms.session;
MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec){
RtpSession *rtps=stream->ms.sessions.rtp_session;
PayloadType *pt,*tel_ev;
int tmp;
MSConnectionHelper h;
......@@ -327,7 +329,7 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
ms_filter_call_method(stream->ms.rtpsend,MS_RTP_SEND_SET_SESSION,rtps);
stream->ms.rtprecv=ms_filter_new(MS_RTP_RECV_ID);
ms_filter_call_method(stream->ms.rtprecv,MS_RTP_RECV_SET_SESSION,rtps);
stream->ms.session=rtps;
stream->ms.sessions.rtp_session=rtps;
if((stream->features & AUDIO_STREAM_FEATURE_DTMF) != 0)
stream->dtmfgen=ms_filter_new(MS_DTMF_GEN_ID);
......@@ -542,7 +544,7 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
}
}
if (stream->ms.use_rc){
stream->ms.rc=ms_audio_bitrate_controller_new(stream->ms.session,stream->ms.encoder,0);
stream->ms.rc=ms_audio_bitrate_controller_new(stream->ms.sessions.rtp_session,stream->ms.encoder,0);
}
/* Create PLC */
......@@ -572,10 +574,10 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
}
/* create ticker */
if (stream->ms.ticker==NULL) start_ticker(&stream->ms);
else{
if (stream->ms.sessions.ticker==NULL) media_stream_start_ticker(&stream->ms);
if (stream->ms.state==MSStreamPreparing){
/*we were using the dummy preload graph, destroy it*/
if (stream->dummy) stop_preload_graph(stream);
audio_stream_unprepare_sound(stream);
}
/* and then connect all */
......@@ -629,13 +631,14 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
}
/*to make sure all preprocess are done before befre processing audio*/
ms_ticker_attach_multiple(stream->ms.ticker
ms_ticker_attach_multiple(stream->ms.sessions.ticker
,stream->soundread
,stream->ms.rtprecv
,NULL);
stream->ms.start_time=ms_time(NULL);
stream->ms.is_beginning=TRUE;
stream->ms.state=MSStreamStarted;
return 0;
}
......@@ -763,7 +766,7 @@ void audio_stream_set_features(AudioStream *st, uint32_t features){
st->features = features;
}
AudioStream *audio_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6){
AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *sessions){
AudioStream *stream=(AudioStream *)ms_new0(AudioStream,1);
MSFilterDesc *ec_desc=ms_filter_lookup_by_name("MSOslec");
......@@ -771,23 +774,23 @@ AudioStream *audio_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6){
ms_filter_reset_statistics();
stream->ms.type = AudioStreamType;
stream->ms.session=create_duplex_rtpsession(loc_rtp_port,loc_rtcp_port,ipv6);
stream->ms.sessions=*sessions;
/*some filters are created right now to allow configuration by the application before start() */
stream->ms.rtpsend=ms_filter_new(MS_RTP_SEND_ID);
stream->ms.ice_check_list=NULL;
stream->ms.qi=ms_quality_indicator_new(stream->ms.session);
stream->ms.qi=ms_quality_indicator_new(stream->ms.sessions.rtp_session);
stream->ms.process_rtcp=audio_stream_process_rtcp;
if (ec_desc!=NULL)
if (ec_desc!=NULL){
stream->ec=ms_filter_new_from_desc(ec_desc);
else
}else{
#if defined(BUILD_WEBRTC_AECM)
stream->ec=ms_filter_new(MS_WEBRTC_AEC_ID);
#else
stream->ec=ms_filter_new(MS_SPEEX_EC_ID);
#endif
}
stream->ms.evq=ortp_ev_queue_new();
rtp_session_register_event_queue(stream->ms.session,stream->ms.evq);
rtp_session_register_event_queue(stream->ms.sessions.rtp_session,stream->ms.evq);
stream->play_dtmfs=TRUE;
stream->use_gc=FALSE;
stream->use_agc=FALSE;
......@@ -796,6 +799,15 @@ AudioStream *audio_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6){
return stream;
}
AudioStream *audio_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6){
AudioStream *obj;
MSMediaStreamSessions sessions={0};
sessions.rtp_session=create_duplex_rtpsession(loc_rtp_port,loc_rtcp_port,ipv6);
obj=audio_stream_new_with_sessions(&sessions);
obj->ms.owns_sessions=TRUE;
return obj;
}
void audio_stream_play_received_dtmfs(AudioStream *st, bool_t yesno){
st->play_dtmfs=yesno;
}
......@@ -884,21 +896,21 @@ static void dismantle_local_player(AudioStream *stream){
}
void audio_stream_stop(AudioStream * stream){
if (stream->ms.ticker){
if (stream->ms.sessions.ticker){
MSConnectionHelper h;
if (stream->dummy){
stop_preload_graph(stream);
}else if (stream->ms.start_time!=0){
if (stream->ms.state==MSStreamPreparing){
audio_stream_unprepare_sound(stream);
}else if (stream->ms.state==MSStreamStarted){
ms_ticker_detach(stream->ms.ticker,stream->soundread);
ms_ticker_detach(stream->ms.ticker,stream->ms.rtprecv);
ms_ticker_detach(stream->ms.sessions.ticker,stream->soundread);
ms_ticker_detach(stream->ms.sessions.ticker,stream->ms.rtprecv);
if (stream->ms.ice_check_list != NULL) {
ice_check_list_print_route(stream->ms.ice_check_list, "Audio session's route");
stream->ms.ice_check_list = NULL;
}
rtp_stats_display(rtp_session_get_stats(stream->ms.session),
rtp_stats_display(rtp_session_get_stats(stream->ms.sessions.rtp_session),
" AUDIO SESSION'S RTP STATISTICS ");
/*dismantle the outgoing graph*/
......@@ -989,5 +1001,6 @@ float audio_stream_get_average_lq_quality_rating(AudioStream *stream) {
}
void audio_stream_enable_zrtp(AudioStream *stream, OrtpZrtpParams *params){
stream->ms.zrtp_context=ortp_zrtp_context_new(stream->ms.session, params);
if (stream->ms.sessions.zrtp_context==NULL)
stream->ms.sessions.zrtp_context=ortp_zrtp_context_new(stream->ms.sessions.rtp_session, params);
}
......@@ -851,7 +851,7 @@ static void ice_check_list_gather_candidates(IceCheckList *cl, Session_Index *si
if (sock > 0) {
check = (IceStunServerCheck *)ms_new0(IceStunServerCheck, 1);
check->sock = sock;
check->srcport = rtp_session_get_local_port(cl->rtp_session) + 1;
check->srcport = rtp_session_get_local_rtcp_port(cl->rtp_session);
check->next_transmission_time = ice_add_ms(curtime, 2 * si->index * ICE_DEFAULT_TA_DURATION + ICE_DEFAULT_TA_DURATION);
cl->stun_server_checks = ms_list_append(cl->stun_server_checks, check);
}
......@@ -1160,9 +1160,9 @@ static int ice_get_socket_from_rtp_session(const RtpSession *rtp_session, const
static int ice_get_recv_port_from_rtp_session(const RtpSession *rtp_session, const OrtpEventData *evt_data)
{
if (evt_data->info.socket_type == OrtpRTPSocket) {
return rtp_session->rtp.loc_port;
return rtp_session_get_local_port(rtp_session);
} else if (evt_data->info.socket_type == OrtpRTCPSocket) {
return rtp_session->rtp.loc_port + 1;
return rtp_session_get_local_rtcp_port(rtp_session);
} else return -1;
}
......
......@@ -64,7 +64,7 @@ static void disable_checksums(ortp_socket_t sock) {
* more easily within the MSTicker API.
*/
static void media_stream_change_decoder(MediaStream *stream, int payload) {
RtpSession *session = stream->session;
RtpSession *session = stream->sessions.rtp_session;
RtpProfile *prof = rtp_session_get_profile(session);
PayloadType *pt = rtp_profile_get_payload(prof, payload);
......@@ -97,7 +97,7 @@ static void media_stream_change_decoder(MediaStream *stream, int payload) {
ms_filter_call_method(stream->decoder, MS_FILTER_ADD_FMTP, (void *)pt->recv_fmtp);
ms_filter_link(stream->rtprecv, 0, stream->decoder, 0);
ms_filter_link(stream->decoder, 0, nextFilter, 0);
ms_filter_preprocess(stream->decoder,stream->ticker);
ms_filter_preprocess(stream->decoder,stream->sessions.ticker);
} else {
ms_warning("No decoder found for %s", pt->mime_type);
}
......@@ -146,19 +146,19 @@ RtpSession * create_duplex_rtpsession(int loc_rtp_port, int loc_rtcp_port, bool_
rtp_session_set_ssrc_changed_threshold(rtpr, 0);
rtp_session_set_rtcp_report_interval(rtpr, 2500); /* At the beginning of the session send more reports. */
disable_checksums(rtp_session_get_rtp_socket(rtpr));
return rtpr;
}
void start_ticker(MediaStream *stream) {
void media_stream_start_ticker(MediaStream *stream) {
MSTickerParams params = {0};
char name[16];
if (stream->sessions.ticker) return;
snprintf(name, sizeof(name) - 1, "%s MSTicker", media_stream_type_str(stream));
name[0] = toupper(name[0]);
params.name = name;
params.prio = __ms_get_default_prio((stream->type == VideoStreamType) ? TRUE : FALSE);
stream->ticker = ms_ticker_new_with_params(&params);
stream->sessions.ticker = ms_ticker_new_with_params(&params);
}
const char * media_stream_type_str(MediaStream *stream) {
......@@ -171,14 +171,31 @@ const char * media_stream_type_str(MediaStream *stream) {
}
}
void ms_media_stream_sessions_uninit(MSMediaStreamSessions *sessions){
if (sessions->rtp_session) {
rtp_session_destroy(sessions->rtp_session);
sessions->rtp_session=NULL;
}
if (sessions->srtp_session) {
ortp_srtp_dealloc(sessions->srtp_session);
sessions->srtp_session=NULL;
}
if (sessions->zrtp_context != NULL) {
ortp_zrtp_context_destroy(sessions->zrtp_context);
sessions->zrtp_context = NULL;
}
if (sessions->ticker){
ms_ticker_destroy(sessions->ticker);
sessions->ticker=NULL;
}
}
void media_stream_free(MediaStream *stream) {
if (stream->zrtp_context != NULL) {
ortp_zrtp_context_destroy(stream->zrtp_context);
stream->zrtp_context = NULL;
if (stream->sessions.rtp_session != NULL){
rtp_session_unregister_event_queue(stream->sessions.rtp_session, stream->evq);
}
if (stream->session != NULL) {
rtp_session_unregister_event_queue(stream->session, stream->evq);
rtp_session_destroy(stream->session);
if (stream->owns_sessions){
ms_media_stream_sessions_uninit(&stream->sessions);
}
if (stream->evq) ortp_ev_queue_destroy(stream->evq);
if (stream->rc != NULL) ms_bitrate_controller_destroy(stream->rc);
......@@ -187,27 +204,26 @@ void media_stream_free(MediaStream *stream) {
if (stream->encoder != NULL) ms_filter_destroy(stream->encoder);
if (stream->decoder != NULL) ms_filter_destroy(stream->decoder);
if (stream->voidsink != NULL) ms_filter_destroy(stream->voidsink);
if (stream->ticker != NULL) ms_ticker_destroy(stream->ticker);
if (stream->qi) ms_quality_indicator_destroy(stream->qi);
if (stream->srtp_session) ortp_srtp_dealloc(stream->srtp_session);
}
void media_stream_set_rtcp_information(MediaStream *stream, const char *cname, const char *tool) {
if (stream->session != NULL) {
rtp_session_set_source_description(stream->session, cname, NULL, NULL, NULL, NULL, tool, NULL);
if (stream->sessions.rtp_session != NULL) {
rtp_session_set_source_description(stream->sessions.rtp_session, cname, NULL, NULL, NULL, NULL, tool, NULL);
}
}
void media_stream_get_local_rtp_stats(MediaStream *stream, rtp_stats_t *lstats) {
if (stream->session) {
const rtp_stats_t *stats = rtp_session_get_stats(stream->session);
if (stream->sessions.rtp_session) {
const rtp_stats_t *stats = rtp_session_get_stats(stream->sessions.rtp_session);
memcpy(lstats, stats, sizeof(*stats));
} else memset(lstats, 0, sizeof(rtp_stats_t));
}
int media_stream_set_dscp(MediaStream *stream, int dscp) {
ms_message("Setting DSCP to %i for %s stream.", dscp, media_stream_type_str(stream));
return rtp_session_set_dscp(stream->session, dscp);
return rtp_session_set_dscp(stream->sessions.rtp_session, dscp);
}
void media_stream_enable_adaptive_bitrate_control(MediaStream *stream, bool_t enabled) {
......@@ -215,7 +231,7 @@ void media_stream_enable_adaptive_bitrate_control(MediaStream *stream, bool_t en
}
void media_stream_enable_adaptive_jittcomp(MediaStream *stream, bool_t enabled) {
rtp_session_enable_adaptive_jitter_compensation(stream->session, enabled);
rtp_session_enable_adaptive_jitter_compensation(stream->sessions.rtp_session, enabled);
}
bool_t media_stream_enable_srtp(MediaStream *stream, enum ortp_srtp_crypto_suite_t suite, const char *snd_key, const char *rcv_key) {
......@@ -226,14 +242,18 @@ bool_t media_stream_enable_srtp(MediaStream *stream, enum ortp_srtp_crypto_suite
ms_error("ortp srtp support not enabled");
return FALSE;
}
if (stream->sessions.srtp_session!=NULL){
ms_warning("media_stream_enable_srtp(): session already configured");
return FALSE;
}
ms_message("%s: %s stream snd_key='%s' rcv_key='%s'", __FUNCTION__, media_stream_type_str(stream), snd_key, rcv_key);
stream->srtp_session = ortp_srtp_create_configure_session(suite, rtp_session_get_send_ssrc(stream->session), snd_key, rcv_key);
if (!stream->srtp_session) return FALSE;
stream->sessions.srtp_session = ortp_srtp_create_configure_session(suite, rtp_session_get_send_ssrc(stream->sessions.rtp_session), snd_key, rcv_key);
if (!stream->sessions.srtp_session) return FALSE;
// TODO: check who will free rtp_tpt ?
srtp_transport_new(stream->srtp_session, &rtp_tpt, &rtcp_tpt);
rtp_session_set_transports(stream->session, rtp_tpt, rtcp_tpt);
srtp_transport_new(stream->sessions.srtp_session, &rtp_tpt, &rtcp_tpt);
rtp_session_set_transports(stream->sessions.rtp_session, rtp_tpt, rtcp_tpt);
return TRUE;
}
......@@ -261,7 +281,7 @@ bool_t ms_is_ipv6(const char *remote) {
void mediastream_payload_type_changed(RtpSession *session, unsigned long data) {
MediaStream *stream = (MediaStream *)data;
int pt = rtp_session_get_recv_payload_type(stream->session);
int pt = rtp_session_get_recv_payload_type(stream->sessions.rtp_session);
media_stream_change_decoder(stream, pt);
}
......@@ -269,16 +289,16 @@ void media_stream_iterate(MediaStream *stream){
time_t curtime=ms_time(NULL);
if (stream->is_beginning && (curtime-stream->start_time>15)){
rtp_session_set_rtcp_report_interval(stream->session,5000);
rtp_session_set_rtcp_report_interval(stream->sessions.rtp_session,5000);
stream->is_beginning=FALSE;
}
if ((curtime-stream->last_bw_sampling_time)>=1) {
/*update bandwidth stat every second more or less*/
stream->up_bw=rtp_session_compute_send_bandwidth(stream->session);
stream->down_bw=rtp_session_compute_recv_bandwidth(stream->session);
stream->up_bw=rtp_session_compute_send_bandwidth(stream->sessions.rtp_session);
stream->down_bw=rtp_session_compute_recv_bandwidth(stream->sessions.rtp_session);
stream->last_bw_sampling_time=curtime;
}
if (stream->ice_check_list) ice_check_list_process(stream->ice_check_list,stream->session);
if (stream->ice_check_list) ice_check_list_process(stream->ice_check_list,stream->sessions.rtp_session);
/*we choose to update the quality indicator as much as possible, since local statistics can be computed realtime. */
if (stream->qi && curtime>stream->last_iterate_time) ms_quality_indicator_update_local(stream->qi);
stream->last_iterate_time=curtime;
......@@ -292,14 +312,13 @@ void media_stream_iterate(MediaStream *stream){
stream->process_rtcp(stream,m);
}else if (evt==ORTP_EVENT_RTCP_PACKET_EMITTED){
ms_message("%s_stream_iterate[%p]: local statistics available\n\tLocal's current jitter buffer size:%f ms",
media_stream_type_str(stream), stream, rtp_session_get_jitter_stats(stream->session)->jitter_buffer_size_ms);
media_stream_type_str(stream), stream, rtp_session_get_jitter_stats(stream->sessions.rtp_session)->jitter_buffer_size_ms);
}else if ((evt==ORTP_EVENT_STUN_PACKET_RECEIVED)&&(stream->ice_check_list)){
ice_handle_stun_packet(stream->ice_check_list,stream->session,ortp_event_get_data(ev));
ice_handle_stun_packet(stream->ice_check_list,stream->sessions.rtp_session,ortp_event_get_data(ev));
}
ortp_event_destroy(ev);
}
}
}
float media_stream_get_quality_rating(MediaStream *stream){
......@@ -339,10 +358,15 @@ int media_stream_get_target_network_bitrate(const MediaStream *stream) {
return stream->target_bitrate;
}
MS2_PUBLIC float media_stream_get_up_bw(const MediaStream *stream) {
float media_stream_get_up_bw(const MediaStream *stream) {
return stream->up_bw;
}
MS2_PUBLIC float media_stream_get_down_bw(const MediaStream *stream) {
float media_stream_get_down_bw(const MediaStream *stream) {
return stream->down_bw;
}
void media_stream_reclaim_sessions(MediaStream *stream, MSMediaStreamSessions *sessions){
memcpy(sessions,&stream->sessions, sizeof(MSMediaStreamSessions));
stream->owns_sessions=FALSE;
}
......@@ -45,7 +45,7 @@ MSTickerPrio __ms_get_default_prio(bool_t is_video);
MEDIASTREAMER2_INTERNAL_EXPORT RtpSession * create_duplex_rtpsession(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6);
void start_ticker(MediaStream *stream);
void media_stream_start_ticker(MediaStream *stream);
void mediastream_payload_type_changed(RtpSession *session, unsigned long data);
......
This diff is collapsed.
......@@ -258,8 +258,8 @@ static void adaptive_audio_stream(int codec_payload, int initial_bitrate,int tar
ms_filter_call_method(marielle->stream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
stream_manager_start(margaux,codec_payload, marielle->local_rtp,-1,NULL,RECORDED_16K_1S_FILE);
rtp_session_enable_network_simulation(margaux->stream->ms.session,&params);
rtp_session_set_rtcp_report_interval(margaux->stream->ms.session, rtcp_interval);
rtp_session_enable_network_simulation(margaux->stream->ms.sessions.rtp_session,&params);
rtp_session_set_rtcp_report_interval(margaux->stream->ms.sessions.rtp_session, rtcp_interval);
wait_for_until(&marielle->stream->ms,&margaux->stream->ms,&marielle->stats.number_of_EndOfFile,10,rtcp_interval*max_recv_rtcp_packet);
......
......@@ -635,7 +635,7 @@ void setup_media_streams(MediastreamDatas* args) {
if (args->ice_local_candidates_nb || args->ice_remote_candidates_nb) {
args->audio->ms.ice_check_list = ice_check_list_new();
rtp_session_set_pktinfo(args->audio->ms.session,TRUE);
rtp_session_set_pktinfo(args->audio->ms.sessions.rtp_session,TRUE);
ice_session_add_check_list(args->ice_session, args->audio->ms.ice_check_list);
}
if (args->ice_local_candidates_nb) {
......@@ -693,7 +693,7 @@ void setup_media_streams(MediastreamDatas* args) {
}
#endif
args->session=args->audio->ms.session;
args->session=args->audio->ms.sessions.rtp_session;
}
if (args->enable_srtp) {
......@@ -741,7 +741,7 @@ void setup_media_streams(MediastreamDatas* args) {
args->payload,
args->jitter,cam
);
args->session=args->video->ms.session;
args->session=args->video->ms.sessions.rtp_session;
ms_filter_call_method(args->video->output,MS_VIDEO_DISPLAY_ZOOM, zoom);
if (args->enable_srtp) {
......
......@@ -77,7 +77,7 @@ int main(int argc, char *argv[]){
/* test code */
if (n==400)
{
ms_ticker_detach (vs->ms.ticker, vs->source);
ms_ticker_detach (vs->ms.sessions.ticker, vs->source);
vs->tee = ms_filter_new(MS_TEE_ID);
......@@ -88,7 +88,7 @@ int main(int argc, char *argv[]){
ms_filter_link(vs->tee,1,vs->output2,1);
//ms_filter_unlink(vs->tee,0,vs->output,0);
ms_ticker_attach (vs->ms.ticker, vs->source);
ms_ticker_attach (vs->ms.sessions.ticker, vs->source);
}
if (n==500)
......@@ -113,7 +113,7 @@ int main(int argc, char *argv[]){
}
if (n==900)
{
ms_ticker_detach (vs->ms.ticker, vs->source);
ms_ticker_detach (vs->ms.sessions.ticker, vs->source);
ms_filter_unlink(vs->pixconv,0,vs->tee,0);
ms_filter_unlink(vs->tee,0,vs->output2,0);
......@@ -124,7 +124,7 @@ int main(int argc, char *argv[]){
ms_filter_link(vs->pixconv,0, vs->output2,0);
ms_ticker_attach (vs->ms.ticker, vs->source);
ms_ticker_attach (vs->ms.sessions.ticker, vs->source);
}
}
video_preview_stop(vs);
......
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