File: basiccall.c

package info (click to toggle)
linphone 1.5.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 16,208 kB
  • ctags: 4,913
  • sloc: ansic: 49,094; sh: 9,516; makefile: 612; cpp: 347; perl: 50; sed: 16; xml: 7
file content (170 lines) | stat: -rw-r--r-- 4,813 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
	The objective of the media_api is to construct and run the necessary processing 
	on audio and video data flows for a given call (two party call) or conference.
	Copyright (C) 2001  Sharath Udupa skuds@gmx.net

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This library 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
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "basiccall.h"
#include "../mediastreamer/mscodec.h"

#define ONESYNC 10
#define MULTISYNC 20

BasicCall *basic_call_new(){
	BasicCall *bc = (BasicCall*) g_malloc(sizeof(BasicCall));
	api_trace("basic_call_new: creating a basic call");
	bc->memberA = call_member_new("memberA");
	bc->memberB = call_member_new("memberB");
	return bc;
}

CallMember *basic_call_get_member(BasicCall *call, int member_nu){
	api_trace("basic_call_get_member: called for %d",member_nu);
	if(member_nu == MemberA){
		return call->memberA;
	}
	else if(member_nu == MemberB){
		return call->memberB;
	}
}

void basic_call_add_flow(BasicCall *call, MediaFlow *flow){
	api_trace("basic_call_add_flow: called for %s",flow->id);
	call->flows = g_list_append( call->flows, flow);
	return 1;
}

int find_mediaflow(gconstpointer llist, gconstpointer flow){
	//MediaFlow *mf = (MediaFlow *) ((BasicCallFlow*)llist)->mediaFlow;
	if(((MediaFlow*)flow)->id == ((MediaFlow*)llist)->id){
		return 0;
	}
	return 1;
}

int basic_call_start_flow(BasicCall *call, MediaFlow *flow){
	int i=0;
	int syncFlag=0;
	int nFlowDirections;
	MSSync *sync;
	Members *source, *destination;
	FlowDirections *fd;
	GList *elem, *selem;
	GList *snd_read = NULL, *snd_write = NULL, *filter = NULL;
	
	//Commented by Sharat
	//This is initialized in media_api.c
	//when should these functions be really called?
	//ms_init(); 
	//ortp_init(); 
	
	api_trace("basic_call_start_flow: called for flow %s", flow->id);
	
	elem = g_list_find_custom( call->flows, flow, &find_mediaflow);
	if(elem == NULL){
		api_error("basic_call_start_flow: Called for unregistered mediaflow %s", flow->id);
	}
	
	nFlowDirections = g_list_length(flow->flowDirections);
	if(flow->type == MEDIA_FLOW_VOICE){
		syncFlag = ONESYNC;
		sync = ms_timer_new();
	}
	else{
		syncFlag = MULTISYNC;
	}

	for(i=0;i< nFlowDirections; i++){
		
		if(syncFlag == MULTISYNC){
			sync = ms_timer_new();
		}
		fd = (FlowDirections*)g_list_nth_data(flow->flowDirections,i);
		source = fd->source;
		destination = fd->destination;

		media_flow_start_fd(fd, sync);
		if(fd->type == MEDIA_FLOW_DUPLEX){
			switch(source->tx_endpoint->protocol){
				case MEDIA_ALSA:
				case MEDIA_OSS:
					snd_read = g_list_append(snd_read, fd->recv);
			}
			switch(destination->rx_endpoint->protocol){
				case MEDIA_ALSA:
				case MEDIA_OSS:
					snd_write = g_list_append(snd_write, fd->play);
			}
			
			switch(destination->tx_endpoint->protocol){
				case MEDIA_ALSA:
				case MEDIA_OSS:
					snd_read = g_list_append(snd_read, fd->read);
			}
			
			switch(source->rx_endpoint->protocol){
				case MEDIA_ALSA:
				case MEDIA_OSS:
					snd_write = g_list_append(snd_write, fd->send);
			}
			
		}
		else if(fd->type == MEDIA_FLOW_HALF_DUPLEX){
			
			switch(source->tx_endpoint->protocol){
				case MEDIA_ALSA:
				case MEDIA_OSS:
					snd_read = g_list_append(snd_read, fd->recv);
			}
			switch(destination->rx_endpoint->protocol){
				case MEDIA_ALSA:
				case MEDIA_OSS:
					snd_write = g_list_append(snd_write, fd->play);
			}
		}
		if(syncFlag == MULTISYNC){
			flow->sync = g_list_append(flow->sync, sync);
		}
	}
	if(syncFlag == ONESYNC){
		ms_start(sync);
		flow->sync = g_list_append(flow->sync, sync);
	}
	if(syncFlag == MULTISYNC){
		selem = flow->sync;
		while(selem != NULL){
			ms_start(selem->data);
			selem = g_list_next(selem);
		}
	}
	filter = snd_read;
	while(filter != NULL){
		ms_sound_read_start(MS_SOUND_READ((MSFilter*)filter->data));
		filter = g_list_next(filter);
	}

	filter = snd_write;
	while(filter != NULL){
		ms_sound_write_start(MS_SOUND_WRITE((MSFilter*)filter->data));
		filter = g_list_next(filter);
	}
	return 1;
}

int basic_call_stop_flow(BasicCall *call, MediaFlow *flow){

}