/**
 * Frees a PayloadType.
**/
void payload_type_destroy(PayloadType *pt)
{
	if (pt->mime_type) ortp_free(pt->mime_type);
	if (pt->recv_fmtp) ortp_free(pt->recv_fmtp);
	if (pt->send_fmtp) ortp_free(pt->send_fmtp);
	ortp_free(pt);
}
static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){
	const char *lname="undef";
	char *msg;
	struct timeval tp;
	struct tm *lt;
#ifndef _WIN32
	struct tm tmbuf;
#endif
	time_t tt;
	ortp_gettimeofday(&tp,NULL);
	tt = (time_t)tp.tv_sec;

#ifdef _WIN32
	lt = localtime(&tt);
#else
	lt = localtime_r(&tt,&tmbuf);
#endif

	if (__log_file==NULL) __log_file=stderr;
	switch(lev){
		case ORTP_DEBUG:
			lname="debug";
			break;
		case ORTP_MESSAGE:
			lname="message";
			break;
		case ORTP_WARNING:
			lname="warning";
			break;
		case ORTP_ERROR:
			lname="error";
			break;
		case ORTP_FATAL:
			lname="fatal";
			break;
		default:
			ortp_fatal("Bad level !");
	}
	msg=ortp_strdup_vprintf(fmt,args);
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
	#ifndef _UNICODE
		OutputDebugStringA(msg);
		OutputDebugStringA("\r\n");
	#else
		{
			int len=strlen(msg);
			wchar_t *tmp=(wchar_t*)ortp_malloc0((len+1)*sizeof(wchar_t));
			mbstowcs(tmp,msg,len);
			OutputDebugStringW(tmp);
			OutputDebugStringW(L"\r\n");
			ortp_free(tmp);
		}
	#endif
#endif
	fprintf(__log_file,"%i-%.2i-%.2i %.2i:%.2i:%.2i:%.3i ortp-%s-%s" ENDLINE
			,1900+lt->tm_year,1+lt->tm_mon,lt->tm_mday,lt->tm_hour,lt->tm_min,lt->tm_sec
			,(int)(tp.tv_usec/1000), lname,msg);
	fflush(__log_file);
	ortp_free(msg);
}
Exemple #3
0
static void _lp_config_destroy(LpConfig *lpconfig){
	if (lpconfig->filename!=NULL) ortp_free(lpconfig->filename);
	if (lpconfig->tmpfilename) ortp_free(lpconfig->tmpfilename);
	ms_list_for_each(lpconfig->sections,(void (*)(void*))lp_section_destroy);
	ms_list_free(lpconfig->sections);
	free(lpconfig);
}
Exemple #4
0
void _ortp_logv_flush(int dummy, ...) {
	OList *elem;
	OList *msglist;
	va_list empty_va_list;
	va_start(empty_va_list, dummy);
	ortp_mutex_lock(&__log_stored_messages_mutex);
	msglist = __log_stored_messages_list;
	__log_stored_messages_list = NULL;
	ortp_mutex_unlock(&__log_stored_messages_mutex);
	for (elem = msglist; elem != NULL; elem = o_list_next(elem)) {
		ortp_stored_log_t *l = (ortp_stored_log_t *)elem->data;
#ifdef WIN32
		ortp_logv_out(l->level, l->msg, empty_va_list);
#else
		va_list cap;
		va_copy(cap, empty_va_list);
		ortp_logv_out(l->level, l->msg, cap);
		va_end(cap);
#endif
		ortp_free(l->msg);
		ortp_free(l);
	}
	o_list_free(msglist);
	va_end(empty_va_list);
}
Exemple #5
0
static bool_t ortp_init_srtp_policy(srtp_t srtp, srtp_policy_t* policy, enum ortp_srtp_crypto_suite_t suite, ssrc_t ssrc, const char* b64_key)
{
	uint8_t* key;
	int key_size;
	err_status_t err;
	unsigned b64_key_length = strlen(b64_key);
		
	switch (suite) {
		case AES_128_SHA1_32:
			crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtp);
			// srtp doc says: not adapted to rtcp...
			crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy->rtcp);
			break;
		case AES_128_NO_AUTH:
			crypto_policy_set_aes_cm_128_null_auth(&policy->rtp);
			// srtp doc says: not adapted to rtcp...
			crypto_policy_set_aes_cm_128_null_auth(&policy->rtcp);
			break;
		case NO_CIPHER_SHA1_80:
			crypto_policy_set_null_cipher_hmac_sha1_80(&policy->rtp);
			crypto_policy_set_null_cipher_hmac_sha1_80(&policy->rtcp);
			break;
		case AES_128_SHA1_80: /*default mode*/
		default:
			crypto_policy_set_rtp_default(&policy->rtp);
			crypto_policy_set_rtcp_default(&policy->rtcp);
	}
	//b64_decode(char const *src, size_t srcLen, void *dest, size_t destSize)
	key_size = b64_decode(b64_key, b64_key_length, 0, 0);
	if (key_size != policy->rtp.cipher_key_len) {
		ortp_error("Key size (%d) doesn't match the selected srtp profile (required %d)",
			key_size,
			policy->rtp.cipher_key_len);
			return FALSE;
	}
	key = (uint8_t*) ortp_malloc0(key_size+2); /*srtp uses padding*/
	if (b64_decode(b64_key, b64_key_length, key, key_size) != key_size) {
		ortp_error("Error decoding key");
		ortp_free(key);
		return FALSE;
	}
		
	policy->ssrc = ssrc;
	policy->key = key;
	policy->next = NULL;
		
	err = ortp_srtp_add_stream(srtp, policy);
	if (err != err_status_ok) {
		ortp_error("Failed to add incoming stream to srtp session (%d)", err);
		ortp_free(key);
		return FALSE;
	}
		
	ortp_free(key);
	return TRUE;
}
OList * o_list_free(OList *list){
	OList *elem = list;
	OList *tmp;
	return_val_if_fail(list, list);
	while(elem->next!=NULL) {
		tmp = elem;
		elem = elem->next;
		ortp_free(tmp);
	}
	ortp_free(elem);
	return NULL;
}
/**
 * Sets a send parameters (fmtp) for the PayloadType.
 * This method is provided for applications using RTP with SDP, but
 * actually the ftmp information is not used for RTP processing.
**/
void payload_type_set_send_fmtp(PayloadType *pt, const char *fmtp){
	if (canWrite(pt)){
		if (pt->send_fmtp!=NULL) ortp_free(pt->send_fmtp);
		if (fmtp!=NULL) pt->send_fmtp=ortp_strdup(fmtp);
		else pt->send_fmtp=NULL;
	}
}
Exemple #8
0
void lp_section_destroy(LpSection *sec){
	ortp_free(sec->name);
	ms_list_for_each(sec->items,lp_item_destroy);
	ms_list_for_each(sec->params,lp_section_param_destroy);
	ms_list_free(sec->items);
	free(sec);
}
Exemple #9
0
static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){
	const char *lname="undef";
	char *msg;
	if (__log_file==NULL) __log_file=stderr;
	switch(lev){
		case ORTP_DEBUG:
			lname="debug";
			break;
		case ORTP_MESSAGE:
			lname="message";
			break;
		case ORTP_WARNING:
			lname="warning";
			break;
		case ORTP_ERROR:
			lname="error";
			break;
		case ORTP_FATAL:
			lname="fatal";
			break;
		default:
			ortp_fatal("Bad level !");
	}
	msg=ortp_strdup_vprintf(fmt,args);
#ifdef _MSC_VER
 	OutputDebugString(msg);
  	OutputDebugString("\r\n");
#else
	fprintf(__log_file,"ortp-%s-%s" ENDLINE,lname,msg);
	fflush(__log_file);
#endif

	ortp_free(msg);
}
Exemple #10
0
void rtp_profile_destroy(RtpProfile *prof)
{
    int i;
    PayloadType *payload;
    if (prof->name) {
        ortp_free(prof->name);
        prof->name = NULL;
    }
    for (i=0; i<RTP_PROFILE_MAX_PAYLOADS; i++)
    {
        payload=rtp_profile_get_payload(prof,i);
        if (payload!=NULL && (payload->flags & PAYLOAD_TYPE_ALLOCATED))
            payload_type_destroy(payload);
    }
    ortp_free(prof);
}
void rtp_scheduler_destroy(RtpScheduler *sched)
{
	if (sched->thread_running) rtp_scheduler_stop(sched);
	ortp_mutex_destroy(&sched->lock);
	//g_mutex_free(sched->unblock_select_mutex);
	ortp_cond_destroy(&sched->unblock_select_cond);
	ortp_free(sched);
}
OList *o_list_remove_link(OList *list, OList *elem){
	OList *ret;
	if (elem==list){
		ret=elem->next;
		elem->prev=NULL;
		elem->next=NULL;
		if (ret!=NULL) ret->prev=NULL;
		ortp_free(elem);
		return ret;
	}
	elem->prev->next=elem->next;
	if (elem->next!=NULL) elem->next->prev=elem->prev;
	elem->next=NULL;
	elem->prev=NULL;
	ortp_free(elem);
	return list;
}
Exemple #13
0
void freeb(mblk_t *mp)
{
	return_if_fail(mp->b_datap!=NULL);
	return_if_fail(mp->b_datap->db_base!=NULL);
	
	datab_unref(mp->b_datap);
	ortp_free(mp);
}	
Exemple #14
0
static inline void datab_unref(dblk_t *d){
	d->db_ref--;
	if (d->db_ref==0){
		if (d->db_freefn!=NULL)
			d->db_freefn(d->db_base);
		ortp_free(d);
	}
}
Exemple #15
0
char * ortp_strcat_vprintf(char* dst, const char *fmt, va_list ap){
	char *ret;
	unsigned long dstlen, retlen;
	
	ret=ortp_strdup_vprintf(fmt, ap);
	dstlen = strlen(dst);
	retlen = strlen(ret);

	if ((dst = ortp_realloc(dst, dstlen+retlen+1)) != NULL){
		strncat(dst,ret,retlen);
		dst[dstlen+retlen] = '\0';
		ortp_free(ret);
		return dst;
	} else {
		ortp_free(ret);
		return NULL;
	}
}
Exemple #16
0
RtpEndpoint *rtp_endpoint_new(struct sockaddr *addr, socklen_t addrlen){
	RtpEndpoint *ep=ortp_new(RtpEndpoint,1);
	if (sizeof(ep->addr)<addrlen){
		ortp_free(ep);
		ortp_fatal("Bad socklen_t size !");
		return NULL;
	}
	memcpy(&ep->addr,addr,addrlen);
	ep->addrlen=addrlen;
	return ep;
}
void payload_type_append_recv_fmtp(PayloadType *pt, const char *fmtp){
	if (canWrite(pt)){
		if (pt->recv_fmtp==NULL)
			pt->recv_fmtp=ortp_strdup(fmtp);
		else{
			char *tmp=ortp_strdup_printf("%s;%s",pt->recv_fmtp,fmtp);
			ortp_free(pt->recv_fmtp);
			pt->recv_fmtp=tmp;
		}
	}
}
Exemple #18
0
/* portable named pipes */
ortp_pipe_t ortp_server_pipe_create(const char *name){
	ortp_pipe_t h;
	char *pipename=make_pipe_name(name);
	h=CreateNamedPipe(pipename,PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,PIPE_TYPE_MESSAGE|PIPE_WAIT,1,
						32768,32768,0,NULL);
	ortp_free(pipename);
	if (h==INVALID_HANDLE_VALUE){
		ortp_error("Fail to create named pipe %s",pipename);
	}
	if (event==NULL) event=CreateEvent(NULL,TRUE,FALSE,NULL);
	return h;
}
Exemple #19
0
ortp_socket_t ortp_client_pipe_connect(const char *name){
	struct sockaddr_un sa;
	char *pipename=make_pipe_name(name);
	ortp_socket_t sock=socket(AF_UNIX,SOCK_STREAM,0);
	sa.sun_family=AF_UNIX;
	strncpy(sa.sun_path,pipename,sizeof(sa.sun_path)-1);
	ortp_free(pipename);
	if (connect(sock,(struct sockaddr*)&sa,sizeof(sa))!=0){
		close(sock);
		return -1;
	}
	return sock;
}
Exemple #20
0
ortp_pipe_t ortp_client_pipe_connect(const char *name){
	char *pipename=make_pipe_name(name);
	ortp_pipe_t hpipe = CreateFile(
         pipename,   // pipe name
         GENERIC_READ |  // read and write access
         GENERIC_WRITE,
         0,              // no sharing
         NULL,           // default security attributes
         OPEN_EXISTING,  // opens existing pipe
         0,              // default attributes
         NULL);          // no template file
	ortp_free(pipename);
	return hpipe;
}
Exemple #21
0
void ortp_shm_close(void *mem){
	OList *elem;
	for(elem=maplist;elem!=NULL;elem=elem->next){
		MapInfo *i=(MapInfo*)elem->data;
		if (i->mem==mem){
			CloseHandle(i->h);
			UnmapViewOfFile(mem);
			ortp_free(i);
			maplist=o_list_remove_link(maplist,elem);
			return;
		}
	}
	ortp_error("No shared memory at %p was found.",mem);
}
Exemple #22
0
static void spawn_linphonec(int argc, char *argv[]){
	PROCESS_INFORMATION pinfo;
	STARTUPINFO si;
	BOOL ret;
	const char *cmd = "linphoned.exe --pipe -c NUL";
	char *args_in_line = argv_to_line(argc, argv);
	char *cmd_with_args;
	
	ZeroMemory( &si, sizeof(si) );
	si.cb = sizeof(si);
	ZeroMemory( &pinfo, sizeof(pinfo) );

	if(args_in_line) {
		cmd_with_args = ortp_strdup_printf("%s %s", cmd, args_in_line);
	} else {
		cmd_with_args = ortp_strdup(cmd);
	}
	
	ret=CreateProcess(NULL, cmd_with_args,
		NULL,
		NULL,
		FALSE,
		0,
		NULL,
		NULL,
		&si,
		&pinfo);

	if(args_in_line) ortp_free(args_in_line);
	ortp_free(cmd_with_args);

	if (!ret){
		fprintf(stderr,"Spawning of linphoned.exe failed.\n");
	}else{
		WaitForInputIdle(pinfo.hProcess,1000);
	}
}
Exemple #23
0
/* portable named pipes */
ortp_socket_t ortp_server_pipe_create(const char *name){
	struct sockaddr_un sa;
	char *pipename=make_pipe_name(name);
	ortp_socket_t sock;
	sock=socket(AF_UNIX,SOCK_STREAM,0);
	sa.sun_family=AF_UNIX;
	strncpy(sa.sun_path,pipename,sizeof(sa.sun_path)-1);
	unlink(pipename);/*in case we didn't finished properly previous time */
	ortp_free(pipename);
	fchmod(sock,S_IRUSR|S_IWUSR);
	if (bind(sock,(struct sockaddr*)&sa,sizeof(sa))!=0){
		ortp_error("Failed to bind command unix socket: %s",strerror(errno));
		return -1;
	}
	listen(sock,1);
	return sock;
}
void linphonec_out(const char *fmt,...){
	char *res;
	va_list args;
	va_start (args, fmt);
	res=ortp_strdup_vprintf(fmt,args);
	va_end (args);
	printf("%s",res);
	fflush(stdout);
#if !defined(_WIN32_WCE)
	if (client_sock!=ORTP_PIPE_INVALID){
		if (ortp_pipe_write(client_sock,(uint8_t*)res,strlen(res))==-1){
			fprintf(stderr,"Fail to send output via pipe: %s",strerror(errno));
		}
	}
#endif /*_WIN32_WCE*/
	ortp_free(res);
}
Exemple #25
0
static double powerspectrum_stat_beyond8K(struct Channel *chan){
	spx_int32_t ps_size = 0;
	spx_int32_t *ps = NULL;
	double mystat = 0;
	float fftmul = 1.0 / (32768.0);
	int i;
	
	speex_preprocess_ctl(chan->speex_pp, SPEEX_PREPROCESS_GET_PSD_SIZE, &ps_size);
	ps = (spx_int32_t*)ortp_malloc(sizeof(spx_int32_t)*ps_size);
	speex_preprocess_ctl(chan->speex_pp, SPEEX_PREPROCESS_GET_PSD, ps);

	mystat = 0;
	for (i=ps_size/2;i < ps_size; i++) {
		double yp;
#if defined(__cplusplus)
		yp = sqrtf(sqrtf(static_cast<float>(ps[i]))) - 1.0f;
#else
		yp = sqrtf(sqrtf((float)(ps[i]))) - 1.0f;
#endif
		yp = yp * fftmul;
		yp = MIN(yp * 3000.0, 1.0);
		yp = (1 - yp) * (100 - 1.0f);
		mystat = yp + mystat;
	}

	mystat = (mystat*2)/ps_size;

	ortp_free(ps);

	/* values:
	Maximum: 108,064 low volume on high frequency.
	Decrease when volume increase. */

	/* return value between 0 and 108,064? */
	mystat = 108.064-mystat;

	chan->average_psd=(mystat*mystat*coef) + (1.0-coef)*chan->average_psd;
	//ms_message("average power spectrum on half highest values ONLY: stat=%.3lf", chan->average_psd);

	return mystat;
}
void CorePlugin::log(OrtpLogLevel lev, const char *fmt, va_list args) {
	const char *lname="undef";
	char *msg;
	switch(lev){
		case ORTP_DEBUG:
			lname="debug";
			break;
		case ORTP_MESSAGE:
			lname="message";
			break;
		case ORTP_WARNING:
			lname="warning";
			break;
		case ORTP_ERROR:
			lname="error";
			break;
		case ORTP_FATAL:
			lname="fatal";
			break;
		default:
			ortp_fatal("Bad level !");
	}
	msg = ortp_strdup_vprintf(fmt, args);
#ifdef DEBUG
#ifdef WIN32
	fprintf(s_log_file, FBSTRING_PluginFileName"-%s-%s\r\n", lname, msg);
	fflush(s_log_file);
#else //WIN32
	fprintf(stdout, FBSTRING_PluginFileName"-%s-%s\r\n", lname, msg);
	fflush(stdout);
#endif //WIN32
#endif //DEBUG
	CorePluginPtr plugin = s_log_plugin.lock();
	if(plugin) {
		CoreAPIPtr core = FB::ptr_cast<CoreAPI>(plugin->getRootJSAPI());
		if(core) {
			core->log(lname, msg);
		}
	}
	ortp_free(msg);
}
Exemple #27
0
static int uninit_bench(struct bench_config *bench)
{
	MSList *it;
	for(it=bench->tsessions;it!=NULL;it=bench->tsessions){
		struct test_session *ts = (struct test_session *)it->data;
		bench->tsessions = ms_list_remove_link(bench->tsessions, it);

		ms_ticker_detach(bench->ticker,ts->fplayer);
		ms_ticker_detach(bench->ticker,ts->rtprecv);

		ms_filter_call_method_noarg(ts->frecorder,MS_FILE_REC_CLOSE);

		if (strstr(bench->wavfile, ".au")==NULL)
			{
				ms_filter_unlink(ts->fplayer,0,ts->encoder,0);
				ms_filter_unlink(ts->encoder,0,ts->rtpsend,0);
			}
		else
			{
				ms_filter_unlink(ts->fplayer,0,ts->rtpsend,0);
			}

		ms_filter_unlink(ts->rtprecv,0,ts->decoder,0);
		ms_filter_unlink(ts->decoder,0,ts->frecorder,0);

		if (ts->fplayer) ms_filter_destroy(ts->fplayer);
		if (ts->encoder) ms_filter_destroy(ts->encoder);
		if (ts->rtpsend) ms_filter_destroy(ts->rtpsend);

		if (ts->rtprecv) ms_filter_destroy(ts->rtprecv);
		if (ts->decoder) ms_filter_destroy(ts->decoder);
		if (ts->frecorder) ms_filter_destroy(ts->frecorder);

		ortp_free(ts);
	}

	ms_ticker_destroy(bench->ticker);
	return 0;
}
int rtp_profile_get_payload_number_from_rtpmap(RtpProfile *profile,const char *rtpmap)
{
	int clock_rate, channels, ret;
	char* subtype = ortp_strdup( rtpmap );
	char* rate_str = NULL;
	char* chan_str = NULL;
	
	
	/* find the slash after the subtype */
	rate_str = strchr(subtype, '/');
	if (rate_str && strlen(rate_str)>1) {
		*rate_str = 0;
		rate_str++;
		
		/* Look for another slash */
		chan_str = strchr(rate_str, '/');
		if (chan_str && strlen(chan_str)>1) {
			*chan_str = 0;
			chan_str++;
		} else {
			chan_str = NULL;
		}
	} else {
		rate_str = NULL;
	}
	
	// Use default clock rate if none given	
	if (rate_str) clock_rate = atoi(rate_str);
	else clock_rate = 8000;

	// Use default number of channels if none given	
	if (chan_str) channels = atoi(chan_str);
	else channels = -1;

	//printf("Searching for payload %s at freq %i with %i channels\n",subtype,clock_rate,ch1annels);
	ret=rtp_profile_find_payload_number(profile,subtype,clock_rate,channels);
	ortp_free(subtype);
	return ret;
}
Exemple #29
0
void ortp_network_simulator_destroy(OrtpNetworkSimulatorCtx *sim){
	int drop_by_flush=sim->latency_q.q_mcount+sim->q.q_mcount;
	if (sim->total_count>0){
		ortp_message("Network simulation: destroyed. Statistics are:"
			"%d/%d(%.1f%%, param=%.1f) packets dropped by loss, "
			"%d/%d(%.1f%%) packets dropped by congestion, "
			"%d/%d(%.1f%%) packets flushed."
			, sim->drop_by_loss, sim->total_count, sim->drop_by_loss*100.f/sim->total_count, sim->params.loss_rate
			, sim->drop_by_congestion, sim->total_count, sim->drop_by_congestion*100.f/sim->total_count
			, drop_by_flush, sim->total_count, drop_by_flush*100.f/sim->total_count
		);
	}
	flushq(&sim->latency_q,0);
	flushq(&sim->q,0);
	flushq(&sim->send_q,0);
	if (sim->thread_started){
		sim->thread_started=FALSE;
		ortp_thread_join(sim->thread, NULL);
	}
	ortp_mutex_destroy(&sim->mutex);
	ortp_free(sim);
}
Exemple #30
0
void ortp_network_simulator_destroy(OrtpNetworkSimulatorCtx *sim){
	flushq(&sim->q,0);
	ortp_free(sim);
}