call->op=sal_op_new(lc->sal);
sal_op_set_user_pointer(call->op,call);
call->core=lc;
- linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
+ linphone_core_get_local_ip(lc,NULL,call->localip);
linphone_call_init_common(call,from,to);
- call->params=*params;
+ _linphone_call_params_copy(&call->params,params);
+ sal_op_set_custom_header(call->op,call->params.custom_headers);
+ call->params.custom_headers=NULL;
+
if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseIce) {
call->ice_session = ice_session_new();
ice_session_set_role(call->ice_session, IR_Controlling);
}
#ifdef BUILD_UPNP
if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseUpnp) {
- call->upnp_session = linphone_upnp_session_new(call);
+ if(!lc->rtp_conf.disable_upnp) {
+ call->upnp_session = linphone_upnp_session_new(call);
+ }
}
#endif //BUILD_UPNP
call->camera_active=params->has_video;
call->core=lc;
if (lc->sip_conf.ping_with_options){
- /*the following sends an option request back to the caller so that
- we get a chance to discover our nat'd address before answering.*/
- call->ping_op=sal_op_new(lc->sal);
- from_str=linphone_address_as_string_uri_only(from);
- sal_op_set_route(call->ping_op,sal_op_get_network_origin(op));
- sal_op_set_user_pointer(call->ping_op,call);
- sal_ping(call->ping_op,linphone_core_find_best_identity(lc,from,NULL),from_str);
- ms_free(from_str);
+#ifdef BUILD_UPNP
+ if (lc->upnp != NULL && linphone_core_get_firewall_policy(lc)==LinphonePolicyUseUpnp &&
+ linphone_upnp_context_get_state(lc->upnp) == LinphoneUpnpStateOk) {
+#else //BUILD_UPNP
+ {
+#endif //BUILD_UPNP
+ /*the following sends an option request back to the caller so that
+ we get a chance to discover our nat'd address before answering.*/
+ call->ping_op=sal_op_new(lc->sal);
+ from_str=linphone_address_as_string_uri_only(from);
+ sal_op_set_route(call->ping_op,sal_op_get_network_origin(op));
+ sal_op_set_user_pointer(call->ping_op,call);
+ sal_ping(call->ping_op,linphone_core_find_best_identity(lc,from,NULL),from_str);
+ ms_free(from_str);
+ }
}
linphone_address_clean(from);
- linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
+ linphone_core_get_local_ip(lc,NULL,call->localip);
linphone_call_init_common(call, from, to);
call->log->call_id=ms_strdup(sal_op_get_call_id(op)); /*must be known at that time*/
linphone_core_init_default_params(lc, &call->params);
break;
case LinphonePolicyUseUpnp:
#ifdef BUILD_UPNP
- call->upnp_session = linphone_upnp_session_new(call);
- if (call->upnp_session != NULL) {
- linphone_call_init_media_streams(call);
- if (linphone_core_update_upnp_from_remote_media_description(call, sal_call_get_remote_media_description(op))<0) {
- /* uPnP port mappings failed, proceed with the call anyway. */
- linphone_call_delete_upnp_session(call);
+ if(!lc->rtp_conf.disable_upnp) {
+ call->upnp_session = linphone_upnp_session_new(call);
+ if (call->upnp_session != NULL) {
+ linphone_call_init_media_streams(call);
+ if (linphone_core_update_upnp_from_remote_media_description(call, sal_call_get_remote_media_description(op))<0) {
+ /* uPnP port mappings failed, proceed with the call anyway. */
+ linphone_call_delete_upnp_session(call);
+ }
+ }
}
- }
#endif //BUILD_UPNP
break;
default:
if (obj->auth_token) {
ms_free(obj->auth_token);
}
-
+ linphone_call_params_uninit(&obj->params);
ms_free(obj);
}
/**
* Returns current parameters associated to the call.
**/
-const LinphoneCallParams * linphone_call_get_current_params(const LinphoneCall *call){
+const LinphoneCallParams * linphone_call_get_current_params(LinphoneCall *call){
+ if (call->params.record_file)
+ call->current_params.record_file=call->params.record_file;
return &call->current_params;
}
cp->low_bandwidth=TRUE;
}
}
+ cp->custom_headers=(SalCustomHeader*)sal_op_get_custom_header(call->op);
return cp;
}
}
#endif
}
+#ifdef VIDEO_ENABLED
+/**
+ * Request remote side to send us a Video Fast Update.
+**/
+void linphone_call_send_vfu_request(LinphoneCall *call)
+{
+ if (LinphoneCallStreamsRunning == linphone_call_get_state(call))
+ sal_call_send_vfu_request(call->op);
+}
+#endif
+
+
/**
* Take a photo of currently received video and write it into a jpeg file.
**/
cp->has_video=enabled;
}
+/**
+ * Returns the audio codec used in the call, described as a PayloadType structure.
+**/
const PayloadType* linphone_call_params_get_used_audio_codec(const LinphoneCallParams *cp) {
return cp->audio_codec;
}
+
+/**
+ * Returns the video codec used in the call, described as a PayloadType structure.
+**/
const PayloadType* linphone_call_params_get_used_video_codec(const LinphoneCallParams *cp) {
return cp->video_codec;
}
return cp->has_video;
}
+/**
+ * Returns kind of media encryption selected for the call.
+**/
enum LinphoneMediaEncryption linphone_call_params_get_media_encryption(const LinphoneCallParams *cp) {
return cp->media_encryption;
}
+/**
+ * Set requested media encryption for a call.
+**/
void linphone_call_params_set_media_encryption(LinphoneCallParams *cp, enum LinphoneMediaEncryption e) {
cp->media_encryption = e;
}
cp->real_early_media=enabled;
}
+/**
+ * Indicates whether sending of early media was enabled.
+**/
bool_t linphone_call_params_early_media_sending_enabled(const LinphoneCallParams *cp){
return cp->real_early_media;
}
cp->audio_bw=bandwidth;
}
-#ifdef VIDEO_ENABLED
-/**
- * Request remote side to send us a Video Fast Update.
-**/
-void linphone_call_send_vfu_request(LinphoneCall *call)
-{
- if (LinphoneCallStreamsRunning == linphone_call_get_state(call))
- sal_call_send_vfu_request(call->op);
+void linphone_call_params_add_custom_header(LinphoneCallParams *params, const char *header_name, const char *header_value){
+ params->custom_headers=sal_custom_header_append(params->custom_headers,header_name,header_value);
+}
+
+const char *linphone_call_params_get_custom_header(const LinphoneCallParams *params, const char *header_name){
+ return sal_custom_header_find(params->custom_headers,header_name);
+}
+
+void _linphone_call_params_copy(LinphoneCallParams *ncp, const LinphoneCallParams *cp){
+ memcpy(ncp,cp,sizeof(LinphoneCallParams));
+ if (cp->record_file) ncp->record_file=ms_strdup(cp->record_file);
+ /*
+ * The management of the custom headers is not optimal. We copy everything while ref counting would be more efficient.
+ */
+ if (cp->custom_headers) ncp->custom_headers=sal_custom_header_clone(cp->custom_headers);
}
-#endif
/**
- *
+ * Copy existing LinphoneCallParams to a new LinphoneCallParams object.
**/
LinphoneCallParams * linphone_call_params_copy(const LinphoneCallParams *cp){
LinphoneCallParams *ncp=ms_new0(LinphoneCallParams,1);
- memcpy(ncp,cp,sizeof(LinphoneCallParams));
+ _linphone_call_params_copy(ncp,cp);
return ncp;
}
+void linphone_call_params_uninit(LinphoneCallParams *p){
+ if (p->record_file) ms_free(p->record_file);
+ if (p->custom_headers) sal_custom_header_free(p->custom_headers);
+}
+
/**
- *
+ * Destroy LinphoneCallParams.
**/
void linphone_call_params_destroy(LinphoneCallParams *p){
+ linphone_call_params_uninit(p);
ms_free(p);
}
+
/**
* @}
**/
LinphoneCore *lc=call->core;
_post_configure_audio_stream(st,lc,call->audio_muted);
if (lc->vtable.dtmf_received!=NULL){
- /* replace by our default action*/
audio_stream_play_received_dtmfs(call->audiostream,FALSE);
- /*rtp_session_signal_connect(call->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);*/
}
+ if (call->record_active)
+ linphone_call_start_recording(call);
}
static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
if (captcard && stream->max_rate>0) ms_snd_card_set_preferred_sample_rate(captcard, stream->max_rate);
audio_stream_enable_adaptive_bitrate_control(call->audiostream,use_arc);
audio_stream_enable_adaptive_jittcomp(call->audiostream, linphone_core_audio_adaptive_jittcomp_enabled(lc));
+ if (!call->params.in_conference && call->params.record_file)
+ audio_stream_mixed_record_open(call->audiostream,call->params.record_file);
audio_stream_start_full(
call->audiostream,
call->audio_profile,
}
audio_stream_set_rtcp_information(call->audiostream, cname, rtcp_tool);
- /* valid local tags are > 0 */
+ /* valid local tags are > 0 */
if (stream->proto == SalProtoRtpSavp) {
- const SalStreamDescription *local_st_desc=sal_media_description_find_stream(call->localdesc,
- SalProtoRtpSavp,SalAudio);
- int crypto_idx = find_crypto_index_from_tag(local_st_desc->crypto, stream->crypto_local_tag);
-
- if (crypto_idx >= 0) {
- audio_stream_enable_srtp(
- call->audiostream,
- stream->crypto[0].algo,
- local_st_desc->crypto[crypto_idx].master_key,
- stream->crypto[0].master_key);
- call->audiostream_encrypted=TRUE;
- } else {
- ms_warning("Failed to find local crypto algo with tag: %d", stream->crypto_local_tag);
- call->audiostream_encrypted=FALSE;
- }
+ const SalStreamDescription *local_st_desc=sal_media_description_find_stream(call->localdesc,
+ SalProtoRtpSavp,SalAudio);
+ int crypto_idx = find_crypto_index_from_tag(local_st_desc->crypto, stream->crypto_local_tag);
+
+ if (crypto_idx >= 0) {
+ audio_stream_enable_srtp(
+ call->audiostream,
+ stream->crypto[0].algo,
+ local_st_desc->crypto[crypto_idx].master_key,
+ stream->crypto[0].master_key);
+ call->audiostream_encrypted=TRUE;
+ } else {
+ ms_warning("Failed to find local crypto algo with tag: %d", stream->crypto_local_tag);
+ call->audiostream_encrypted=FALSE;
+ }
}else call->audiostream_encrypted=FALSE;
if (call->params.in_conference){
/*transform the graph to connect it to the conference filter */
}
#endif //BUILD_UPNP
-static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
- audio_stream_get_local_rtp_stats (st,&log->local_stats);
- log->quality=audio_stream_get_average_quality_rating(st);
+static void linphone_call_log_fill_stats(LinphoneCallLog *log, MediaStream *st){
+ float quality=media_stream_get_average_quality_rating(st);
+ if (quality>=0){
+ if (log->quality!=-1){
+ log->quality*=quality/5.0;
+ }else log->quality=quality;
+ }
}
void linphone_call_stop_audio_stream(LinphoneCall *call) {
lp_config_set_string(call->core->config,"sound","ec_state",state_str);
}
}
- linphone_call_log_fill_stats (call->log,call->audiostream);
+ audio_stream_get_local_rtp_stats(call->audiostream,&call->log->local_stats);
+ linphone_call_log_fill_stats (call->log,(MediaStream*)call->audiostream);
if (call->endpoint){
linphone_call_remove_from_conf(call);
}
ortp_ev_queue_flush(call->videostream_app_evq);
ortp_ev_queue_destroy(call->videostream_app_evq);
call->videostream_app_evq=NULL;
+ linphone_call_log_fill_stats(call->log,(MediaStream*)call->videostream);
video_stream_stop(call->videostream);
call->videostream=NULL;
}
* active audio stream exist. Otherwise it returns the quality rating.
**/
float linphone_call_get_current_quality(LinphoneCall *call){
+ float audio_rating=-1;
+ float video_rating=-1;
+ float result;
if (call->audiostream){
- return audio_stream_get_quality_rating(call->audiostream);
+ audio_rating=media_stream_get_quality_rating((MediaStream*)call->audiostream)/5.0;
}
- return -1;
+ if (call->videostream){
+ video_rating=media_stream_get_quality_rating((MediaStream*)call->videostream)/5.0;
+ }
+ if (audio_rating<0 && video_rating<0) result=-1;
+ else if (audio_rating<0) result=video_rating*5.0;
+ else if (video_rating<0) result=audio_rating*5.0;
+ else result=audio_rating*video_rating*5.0;
+ return result;
}
/**
return -1;
}
+static void update_local_stats(LinphoneCallStats *stats, MediaStream *stream){
+ const MSQualityIndicator *qi=media_stream_get_quality_indicator(stream);
+ if (qi) {
+ stats->local_late_rate=ms_quality_indicator_get_local_late_rate(qi);
+ stats->local_loss_rate=ms_quality_indicator_get_local_loss_rate(qi);
+ }
+}
+
/**
* Access last known statistics for audio stream, for a given call.
**/
-const LinphoneCallStats *linphone_call_get_audio_stats(const LinphoneCall *call) {
- return &call->stats[LINPHONE_CALL_STATS_AUDIO];
+const LinphoneCallStats *linphone_call_get_audio_stats(LinphoneCall *call) {
+ LinphoneCallStats *stats=&call->stats[LINPHONE_CALL_STATS_AUDIO];
+ if (call->audiostream){
+ update_local_stats(stats,(MediaStream*)call->audiostream);
+ }
+ return stats;
}
/**
* Access last known statistics for video stream, for a given call.
**/
-const LinphoneCallStats *linphone_call_get_video_stats(const LinphoneCall *call) {
- return &call->stats[LINPHONE_CALL_STATS_VIDEO];
+const LinphoneCallStats *linphone_call_get_video_stats(LinphoneCall *call) {
+ LinphoneCallStats *stats=&call->stats[LINPHONE_CALL_STATS_VIDEO];
+ if (call->videostream){
+ update_local_stats(stats,(MediaStream*)call->videostream);
+ }
+ return stats;
+}
+
+/**
+ * Enable recording of the call (voice-only).
+ * This function must be used before the call parameters are assigned to the call.
+ * The call recording can be started and paused after the call is established with
+ * linphone_call_start_recording() and linphone_call_pause_recording().
+ * @param cp the call parameters
+ * @param path path and filename of the file where audio is written.
+**/
+void linphone_call_params_set_record_file(LinphoneCallParams *cp, const char *path){
+ if (cp->record_file){
+ ms_free(cp->record_file);
+ cp->record_file=NULL;
+ }
+ if (path) cp->record_file=ms_strdup(path);
}
+/**
+ * Retrieves the path for the audio recoding of the call.
+**/
+const char *linphone_call_params_get_record_file(const LinphoneCallParams *cp){
+ return cp->record_file;
+}
+
+/**
+ * Start call recording.
+ * The output file where audio is recorded must be previously specified with linphone_call_params_set_record_file().
+**/
+void linphone_call_start_recording(LinphoneCall *call){
+ if (!call->params.record_file){
+ ms_error("linphone_call_start_recording(): no output file specified. Use linphone_call_params_set_record_file().");
+ return;
+ }
+ if (call->audiostream && !call->params.in_conference){
+ audio_stream_mixed_record_start(call->audiostream);
+ }
+ call->record_active=TRUE;
+}
+
+/**
+ * Stop call recording.
+**/
+void linphone_call_stop_recording(LinphoneCall *call){
+ if (call->audiostream && !call->params.in_conference){
+ audio_stream_mixed_record_stop(call->audiostream);
+ }
+ call->record_active=FALSE;
+}
/**
* @}
if (from)
{
snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from);
- free(from);
+ ms_free(from);
}
else
{
if (lc->vtable.display_warning!=NULL)
lc->vtable.display_warning(lc,temp);
linphone_core_terminate_call(lc,call);
+ linphone_core_play_named_tone(lc,LinphoneToneCallFailed);
}
static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){
freemsg(call->stats[LINPHONE_CALL_STATS_VIDEO].received_rtcp);
call->stats[LINPHONE_CALL_STATS_VIDEO].received_rtcp = evd->packet;
evd->packet = NULL;
+ update_local_stats(&call->stats[LINPHONE_CALL_STATS_VIDEO],(MediaStream*)call->videostream);
if (lc->vtable.call_stats_updated)
lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_VIDEO]);
} else if (evt == ORTP_EVENT_RTCP_PACKET_EMITTED) {
freemsg(call->stats[LINPHONE_CALL_STATS_VIDEO].sent_rtcp);
call->stats[LINPHONE_CALL_STATS_VIDEO].sent_rtcp = evd->packet;
evd->packet = NULL;
+ update_local_stats(&call->stats[LINPHONE_CALL_STATS_VIDEO],(MediaStream*)call->videostream);
if (lc->vtable.call_stats_updated)
lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_VIDEO]);
} else if ((evt == ORTP_EVENT_ICE_SESSION_PROCESSING_FINISHED) || (evt == ORTP_EVENT_ICE_GATHERING_FINISHED)
freemsg(call->stats[LINPHONE_CALL_STATS_AUDIO].received_rtcp);
call->stats[LINPHONE_CALL_STATS_AUDIO].received_rtcp = evd->packet;
evd->packet = NULL;
+ update_local_stats(&call->stats[LINPHONE_CALL_STATS_AUDIO],(MediaStream*)call->audiostream);
if (lc->vtable.call_stats_updated)
lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_AUDIO]);
} else if (evt == ORTP_EVENT_RTCP_PACKET_EMITTED) {
freemsg(call->stats[LINPHONE_CALL_STATS_AUDIO].sent_rtcp);
call->stats[LINPHONE_CALL_STATS_AUDIO].sent_rtcp = evd->packet;
evd->packet = NULL;
+ update_local_stats(&call->stats[LINPHONE_CALL_STATS_AUDIO],(MediaStream*)call->audiostream);
if (lc->vtable.call_stats_updated)
lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_AUDIO]);
} else if ((evt == ORTP_EVENT_ICE_SESSION_PROCESSING_FINISHED) || (evt == ORTP_EVENT_ICE_GATHERING_FINISHED)