call_params.c 14.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
linphone
Copyright (C) 2010-2014  Belledonne Communications SARL

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
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 19
*/

20
#include "linphone/call_params.h"
21 22 23 24 25 26 27 28 29 30
#include "private.h"


/*******************************************************************************
 * Internal functions                                                          *
 ******************************************************************************/

SalMediaProto get_proto_from_call_params(const LinphoneCallParams *params) {
	if ((params->media_encryption == LinphoneMediaEncryptionSRTP) && params->avpf_enabled) return SalProtoRtpSavpf;
	if (params->media_encryption == LinphoneMediaEncryptionSRTP) return SalProtoRtpSavp;
johan's avatar
johan committed
31 32
	if ((params->media_encryption == LinphoneMediaEncryptionDTLS) && params->avpf_enabled) return SalProtoUdpTlsRtpSavpf;
	if (params->media_encryption == LinphoneMediaEncryptionDTLS) return SalProtoUdpTlsRtpSavp;
33 34 35 36
	if (params->avpf_enabled) return SalProtoRtpAvpf;
	return SalProtoRtpAvp;
}

37
SalStreamDir sal_dir_from_call_params_dir(LinphoneMediaDirection cpdir) {
38
	switch (cpdir) {
39
		case LinphoneMediaDirectionInactive:
40
			return SalStreamInactive;
41
		case LinphoneMediaDirectionSendOnly:
42
			return SalStreamSendOnly;
43
		case LinphoneMediaDirectionRecvOnly:
44
			return SalStreamRecvOnly;
45
		case LinphoneMediaDirectionSendRecv:
46
			return SalStreamSendRecv;
47 48 49
		case LinphoneMediaDirectionInvalid:
			ms_error("LinphoneMediaDirectionInvalid shall not be used.");
			return SalStreamInactive;
50
	}
51
	return SalStreamSendRecv;
52 53
}

54
LinphoneMediaDirection media_direction_from_sal_stream_dir(SalStreamDir dir){
55 56
	switch (dir) {
		case SalStreamInactive:
57
			return LinphoneMediaDirectionInactive;
58
		case SalStreamSendOnly:
59
			return LinphoneMediaDirectionSendOnly;
60
		case SalStreamRecvOnly:
61
			return LinphoneMediaDirectionRecvOnly;
62
		case SalStreamSendRecv:
63
			return LinphoneMediaDirectionSendRecv;
64
	}
65
	return LinphoneMediaDirectionSendRecv;
66 67
}

68 69 70 71 72 73 74 75
SalStreamDir get_audio_dir_from_call_params(const LinphoneCallParams *params) {
	return sal_dir_from_call_params_dir(linphone_call_params_get_audio_direction(params));
}

SalStreamDir get_video_dir_from_call_params(const LinphoneCallParams *params) {
	return sal_dir_from_call_params_dir(linphone_call_params_get_video_direction(params));
}

76 77 78 79 80 81 82 83 84 85
void linphone_call_params_set_custom_headers(LinphoneCallParams *params, const SalCustomHeader *ch){
	if (params->custom_headers){
		sal_custom_header_free(params->custom_headers);
		params->custom_headers = NULL;
	}
	if (ch){
		params->custom_headers = sal_custom_header_clone(ch);
	}
}

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
void linphone_call_params_set_custom_sdp_attributes(LinphoneCallParams *params, const SalCustomSdpAttribute *csa) {
	if (params->custom_sdp_attributes) {
		sal_custom_sdp_attribute_free(params->custom_sdp_attributes);
		params->custom_sdp_attributes = NULL;
	}
	if (csa) {
		params->custom_sdp_attributes = sal_custom_sdp_attribute_clone(csa);
	}
}

void linphone_call_params_set_custom_sdp_media_attributes(LinphoneCallParams *params, LinphoneStreamType type, const SalCustomSdpAttribute *csa) {
	if (params->custom_sdp_media_attributes[type]) {
		sal_custom_sdp_attribute_free(params->custom_sdp_media_attributes[type]);
		params->custom_sdp_media_attributes[type] = NULL;
	}
	if (csa) {
		params->custom_sdp_media_attributes[type] = sal_custom_sdp_attribute_clone(csa);
	}
}

106 107 108 109 110 111 112 113 114

/*******************************************************************************
 * Public functions                                                            *
 ******************************************************************************/

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);
}

115 116 117 118 119 120 121 122
void linphone_call_params_add_custom_sdp_attribute(LinphoneCallParams *params, const char *attribute_name, const char *attribute_value) {
	params->custom_sdp_attributes = sal_custom_sdp_attribute_append(params->custom_sdp_attributes, attribute_name, attribute_value);
}

void linphone_call_params_add_custom_sdp_media_attribute(LinphoneCallParams *params, LinphoneStreamType type, const char *attribute_name, const char *attribute_value) {
	params->custom_sdp_media_attributes[type] = sal_custom_sdp_attribute_append(params->custom_sdp_media_attributes[type], attribute_name, attribute_value);
}

123 124 125 126 127 128 129 130
void linphone_call_params_clear_custom_sdp_attributes(LinphoneCallParams *params) {
	linphone_call_params_set_custom_sdp_attributes(params, NULL);
}

void linphone_call_params_clear_custom_sdp_media_attributes(LinphoneCallParams *params, LinphoneStreamType type) {
	linphone_call_params_set_custom_sdp_media_attributes(params, type, NULL);
}

131
LinphoneCallParams * linphone_call_params_copy(const LinphoneCallParams *cp){
132
	return (LinphoneCallParams *)belle_sip_object_clone((const belle_sip_object_t *)cp);
133 134 135 136 137 138 139 140 141 142 143 144 145 146
}

bool_t linphone_call_params_early_media_sending_enabled(const LinphoneCallParams *cp){
	return cp->real_early_media;
}

void linphone_call_params_enable_early_media_sending(LinphoneCallParams *cp, bool_t enabled){
	cp->real_early_media=enabled;
}

void linphone_call_params_enable_low_bandwidth(LinphoneCallParams *cp, bool_t enabled){
	cp->low_bandwidth=enabled;
}

147 148 149 150 151 152
void linphone_call_params_enable_audio(LinphoneCallParams *cp, bool_t enabled){
	cp->has_audio=enabled;
	if (enabled && cp->audio_dir==LinphoneMediaDirectionInactive)
		cp->audio_dir=LinphoneMediaDirectionSendRecv;
}

153
LinphoneStatus linphone_call_params_enable_realtime_text(LinphoneCallParams *params, bool_t yesno) {
154 155 156 157
	params->realtimetext_enabled=yesno;
	return 0;
}

158 159
void linphone_call_params_enable_video(LinphoneCallParams *cp, bool_t enabled){
	cp->has_video=enabled;
Simon Morlat's avatar
Simon Morlat committed
160
	if (enabled && cp->video_dir==LinphoneMediaDirectionInactive)
161
		cp->video_dir=LinphoneMediaDirectionSendRecv;
162 163 164 165 166 167
}

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);
}

168 169 170 171 172 173 174 175
const char * linphone_call_params_get_custom_sdp_attribute(const LinphoneCallParams *params, const char *attribute_name) {
	return sal_custom_sdp_attribute_find(params->custom_sdp_attributes, attribute_name);
}

const char * linphone_call_params_get_custom_sdp_media_attribute(const LinphoneCallParams *params, LinphoneStreamType type, const char *attribute_name) {
	return sal_custom_sdp_attribute_find(params->custom_sdp_media_attributes[type], attribute_name);
}

176 177 178 179 180 181 182 183
bool_t linphone_call_params_get_local_conference_mode(const LinphoneCallParams *cp){
	return cp->in_conference;
}

LinphoneMediaEncryption linphone_call_params_get_media_encryption(const LinphoneCallParams *cp) {
	return cp->media_encryption;
}

184 185 186 187
LinphonePrivacyMask linphone_call_params_get_privacy(const LinphoneCallParams *params) {
	return params->privacy;
}

188 189 190 191 192 193 194 195
float linphone_call_params_get_received_framerate(const LinphoneCallParams *cp){
	return cp->received_fps;
}

MSVideoSize linphone_call_params_get_received_video_size(const LinphoneCallParams *cp) {
	return cp->recv_vsize;
}

196 197 198 199
const LinphoneVideoDefinition * linphone_call_params_get_received_video_definition(const LinphoneCallParams *cp) {
	return cp->recv_vdef;
}

200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
const char *linphone_call_params_get_record_file(const LinphoneCallParams *cp){
	return cp->record_file;
}

const char * linphone_call_params_get_rtp_profile(const LinphoneCallParams *cp) {
	return sal_media_proto_to_string(get_proto_from_call_params(cp));
}

float linphone_call_params_get_sent_framerate(const LinphoneCallParams *cp){
	return cp->sent_fps;
}

MSVideoSize linphone_call_params_get_sent_video_size(const LinphoneCallParams *cp) {
	return cp->sent_vsize;
}

216 217 218 219
const LinphoneVideoDefinition * linphone_call_params_get_sent_video_definition(const LinphoneCallParams *cp) {
	return cp->sent_vdef;
}

220 221 222 223
const char *linphone_call_params_get_session_name(const LinphoneCallParams *cp){
	return cp->session_name;
}

224 225 226 227 228 229 230 231 232 233 234 235 236
LinphonePayloadType *linphone_call_params_get_used_audio_payload_type(const LinphoneCallParams *cp) {
	return cp->audio_codec ? linphone_payload_type_new(NULL, cp->audio_codec) : NULL;
}

LinphonePayloadType *linphone_call_params_get_used_video_payload_type(const LinphoneCallParams *cp) {
	return cp->video_codec ? linphone_payload_type_new(NULL, cp->video_codec) : NULL;
}

LinphonePayloadType *linphone_call_params_get_used_text_payload_type(const LinphoneCallParams *cp) {
	return cp->text_codec ? linphone_payload_type_new(NULL, cp->text_codec) : NULL;
}

const OrtpPayloadType *linphone_call_params_get_used_audio_codec(const LinphoneCallParams *cp) {
237 238 239
	return cp->audio_codec;
}

240
const OrtpPayloadType *linphone_call_params_get_used_video_codec(const LinphoneCallParams *cp) {
241 242 243
	return cp->video_codec;
}

244
const OrtpPayloadType *linphone_call_params_get_used_text_codec(const LinphoneCallParams *cp) {
245 246 247 248
	return cp->text_codec;
}


249 250 251 252 253 254 255 256 257 258 259 260
bool_t linphone_call_params_low_bandwidth_enabled(const LinphoneCallParams *cp) {
	return cp->low_bandwidth;
}

void linphone_call_params_set_audio_bandwidth_limit(LinphoneCallParams *cp, int bandwidth){
	cp->audio_bw=bandwidth;
}

void linphone_call_params_set_media_encryption(LinphoneCallParams *cp, LinphoneMediaEncryption e) {
	cp->media_encryption = e;
}

261 262 263 264
void linphone_call_params_set_privacy(LinphoneCallParams *params, LinphonePrivacyMask privacy) {
	params->privacy=privacy;
}

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
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);
}

void linphone_call_params_set_session_name(LinphoneCallParams *cp, const char *name){
	if (cp->session_name){
		ms_free(cp->session_name);
		cp->session_name=NULL;
	}
	if (name) cp->session_name=ms_strdup(name);
}

281 282 283 284
bool_t linphone_call_params_audio_enabled(const LinphoneCallParams *cp){
	return cp->has_audio;
}

285 286 287 288
bool_t linphone_call_params_realtime_text_enabled(const LinphoneCallParams *params) {
	return params->realtimetext_enabled;
}

289 290 291 292
bool_t linphone_call_params_video_enabled(const LinphoneCallParams *cp){
	return cp->has_video;
}

293
LinphoneMediaDirection linphone_call_params_get_audio_direction(const LinphoneCallParams *cp) {
jehan's avatar
jehan committed
294 295 296
	return cp->audio_dir;
}

297
LinphoneMediaDirection linphone_call_params_get_video_direction(const LinphoneCallParams *cp) {
jehan's avatar
jehan committed
298 299 300
	return cp->video_dir;
}

301
void linphone_call_params_set_audio_direction(LinphoneCallParams *cp,LinphoneMediaDirection dir) {
jehan's avatar
jehan committed
302 303 304
	cp->audio_dir=dir;
}

305
void linphone_call_params_set_video_direction(LinphoneCallParams *cp,LinphoneMediaDirection dir) {
jehan's avatar
jehan committed
306 307
	cp->video_dir=dir;
}
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330


/*******************************************************************************
 * Reference and user data handling functions                                  *
 ******************************************************************************/

void *linphone_call_params_get_user_data(const LinphoneCallParams *cp) {
	return cp->user_data;
}

void linphone_call_params_set_user_data(LinphoneCallParams *cp, void *ud) {
	cp->user_data = ud;
}

LinphoneCallParams * linphone_call_params_ref(LinphoneCallParams *cp) {
	belle_sip_object_ref(cp);
	return cp;
}

void linphone_call_params_unref(LinphoneCallParams *cp) {
	belle_sip_object_unref(cp);
}

331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
void linphone_call_params_enable_audio_multicast(LinphoneCallParams *params, bool_t yesno) {
	params->audio_multicast_enabled=yesno;
}

bool_t linphone_call_params_audio_multicast_enabled(const LinphoneCallParams *params) {
	return params->audio_multicast_enabled;
}

void linphone_call_params_enable_video_multicast(LinphoneCallParams *params, bool_t yesno) {
	params->video_multicast_enabled=yesno;
}
bool_t linphone_call_params_video_multicast_enabled(const LinphoneCallParams *params) {
	return params->video_multicast_enabled;
}

346 347 348 349
/*******************************************************************************
 * Constructor and destructor functions                                        *
 ******************************************************************************/

350
static void _linphone_call_params_uninit(LinphoneCallParams *cp){
351
	unsigned int i;
352 353
	if (cp->record_file) ms_free(cp->record_file);
	if (cp->custom_headers) sal_custom_header_free(cp->custom_headers);
354 355 356 357
	if (cp->custom_sdp_attributes) sal_custom_sdp_attribute_free(cp->custom_sdp_attributes);
	for (i = 0; i < (unsigned int)LinphoneStreamTypeUnknown; i++) {
		if (cp->custom_sdp_media_attributes[i]) sal_custom_sdp_attribute_free(cp->custom_sdp_media_attributes[i]);
	}
Simon Morlat's avatar
Simon Morlat committed
358
	if (cp->session_name) ms_free(cp->session_name);
359 360
	if (cp->sent_vdef != NULL) linphone_video_definition_unref(cp->sent_vdef);
	if (cp->recv_vdef != NULL) linphone_video_definition_unref(cp->recv_vdef);
361 362
}

363 364 365
static void _linphone_call_params_clone(LinphoneCallParams *dst, const LinphoneCallParams *src) {
	unsigned int i;
	
366 367 368 369 370 371
	/*
	 * Save the belle_sip_object_t part, copy the entire structure and restore the belle_sip_object_t part
	 */
	belle_sip_object_t tmp = dst->base;
	memcpy(dst, src, sizeof(LinphoneCallParams));
	dst->base = tmp;
372 373 374

	if (src->sent_vdef) dst->sent_vdef = linphone_video_definition_ref(src->sent_vdef);
	if (src->recv_vdef) dst->recv_vdef = linphone_video_definition_ref(src->recv_vdef);
375
	if (src->record_file) dst->record_file=ms_strdup(src->record_file);
376
	if (src->session_name) dst->session_name=ms_strdup(src->session_name);
377 378 379 380 381 382 383 384 385 386
	/*
	 * The management of the custom headers is not optimal. We copy everything while ref counting would be more efficient.
	 */
	if (src->custom_headers) dst->custom_headers=sal_custom_header_clone(src->custom_headers);
	if (src->custom_sdp_attributes) dst->custom_sdp_attributes = sal_custom_sdp_attribute_clone(src->custom_sdp_attributes);
	for (i = 0; i < (unsigned int)LinphoneStreamTypeUnknown; i++) {
		if (src->custom_sdp_media_attributes[i]) dst->custom_sdp_media_attributes[i] = sal_custom_sdp_attribute_clone(src->custom_sdp_media_attributes[i]);
	}
}

387
LinphoneCallParams * linphone_call_params_new(void) {
388
	LinphoneCallParams *cp=belle_sip_object_new(LinphoneCallParams);
389 390
	cp->audio_dir=LinphoneMediaDirectionSendRecv;
	cp->video_dir=LinphoneMediaDirectionSendRecv;
391
	cp->has_audio=TRUE;
392
	cp->realtimetext_enabled = FALSE;
393
	return cp;
394 395 396 397 398 399 400 401 402 403
}

/* DEPRECATED */
void linphone_call_params_destroy(LinphoneCallParams *cp) {
	linphone_call_params_unref(cp);
}

BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneCallParams);

BELLE_SIP_INSTANCIATE_VPTR(LinphoneCallParams, belle_sip_object_t,
404 405
	(belle_sip_object_destroy_t)_linphone_call_params_uninit,
	(belle_sip_object_clone_t)_linphone_call_params_clone, // clone
406 407 408
	NULL, // marshal
	FALSE
);