~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to media_api/basiccall.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        The objective of the media_api is to construct and run the necessary processing 
 
3
        on audio and video data flows for a given call (two party call) or conference.
 
4
        Copyright (C) 2001  Sharath Udupa skuds@gmx.net
 
5
 
 
6
        This library is free software; you can redistribute it and/or
 
7
        modify it under the terms of the GNU Lesser General Public
 
8
        License as published by the Free Software Foundation; either
 
9
        version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
        This library is distributed in the hope that it will be useful,
 
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
        Lesser General Public License for more details.
 
15
 
 
16
        You should have received a copy of the GNU Lesser General Public
 
17
        License along with this library; if not, write to the Free Software
 
18
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
*/
 
20
 
 
21
#include "basiccall.h"
 
22
#include "../mediastreamer/mscodec.h"
 
23
 
 
24
#define ONESYNC 10
 
25
#define MULTISYNC 20
 
26
 
 
27
BasicCall *basic_call_new(){
 
28
        BasicCall *bc = (BasicCall*) g_malloc(sizeof(BasicCall));
 
29
        api_trace("basic_call_new: creating a basic call");
 
30
        bc->memberA = call_member_new("memberA");
 
31
        bc->memberB = call_member_new("memberB");
 
32
        return bc;
 
33
}
 
34
 
 
35
CallMember *basic_call_get_member(BasicCall *call, int member_nu){
 
36
        api_trace("basic_call_get_member: called for %d",member_nu);
 
37
        if(member_nu == MemberA){
 
38
                return call->memberA;
 
39
        }
 
40
        else if(member_nu == MemberB){
 
41
                return call->memberB;
 
42
        }
 
43
}
 
44
 
 
45
void basic_call_add_flow(BasicCall *call, MediaFlow *flow){
 
46
        api_trace("basic_call_add_flow: called for %s",flow->id);
 
47
        call->flows = g_list_append( call->flows, flow);
 
48
        return 1;
 
49
}
 
50
 
 
51
int find_mediaflow(gconstpointer llist, gconstpointer flow){
 
52
        //MediaFlow *mf = (MediaFlow *) ((BasicCallFlow*)llist)->mediaFlow;
 
53
        if(((MediaFlow*)flow)->id == ((MediaFlow*)llist)->id){
 
54
                return 0;
 
55
        }
 
56
        return 1;
 
57
}
 
58
 
 
59
int basic_call_start_flow(BasicCall *call, MediaFlow *flow){
 
60
        int i=0;
 
61
        int syncFlag=0;
 
62
        int nFlowDirections;
 
63
        MSSync *sync;
 
64
        Members *source, *destination;
 
65
        FlowDirections *fd;
 
66
        GList *elem, *selem;
 
67
        GList *snd_read = NULL, *snd_write = NULL, *filter = NULL;
 
68
        
 
69
        //Commented by Sharat
 
70
        //This is initialized in media_api.c
 
71
        //when should these functions be really called?
 
72
        //ms_init(); 
 
73
        //ortp_init(); 
 
74
        
 
75
        api_trace("basic_call_start_flow: called for flow %s", flow->id);
 
76
        
 
77
        elem = g_list_find_custom( call->flows, flow, &find_mediaflow);
 
78
        if(elem == NULL){
 
79
                api_error("basic_call_start_flow: Called for unregistered mediaflow %s", flow->id);
 
80
        }
 
81
        
 
82
        nFlowDirections = g_list_length(flow->flowDirections);
 
83
        if(flow->type == MEDIA_FLOW_VOICE){
 
84
                syncFlag = ONESYNC;
 
85
                sync = ms_timer_new();
 
86
        }
 
87
        else{
 
88
                syncFlag = MULTISYNC;
 
89
        }
 
90
 
 
91
        for(i=0;i< nFlowDirections; i++){
 
92
                
 
93
                if(syncFlag == MULTISYNC){
 
94
                        sync = ms_timer_new();
 
95
                }
 
96
                fd = (FlowDirections*)g_list_nth_data(flow->flowDirections,i);
 
97
                source = fd->source;
 
98
                destination = fd->destination;
 
99
 
 
100
                media_flow_start_fd(fd, sync);
 
101
                if(fd->type == MEDIA_FLOW_DUPLEX){
 
102
                        switch(source->tx_endpoint->protocol){
 
103
                                case MEDIA_ALSA:
 
104
                                case MEDIA_OSS:
 
105
                                        snd_read = g_list_append(snd_read, fd->recv);
 
106
                        }
 
107
                        switch(destination->rx_endpoint->protocol){
 
108
                                case MEDIA_ALSA:
 
109
                                case MEDIA_OSS:
 
110
                                        snd_write = g_list_append(snd_write, fd->play);
 
111
                        }
 
112
                        
 
113
                        switch(destination->tx_endpoint->protocol){
 
114
                                case MEDIA_ALSA:
 
115
                                case MEDIA_OSS:
 
116
                                        snd_read = g_list_append(snd_read, fd->read);
 
117
                        }
 
118
                        
 
119
                        switch(source->rx_endpoint->protocol){
 
120
                                case MEDIA_ALSA:
 
121
                                case MEDIA_OSS:
 
122
                                        snd_write = g_list_append(snd_write, fd->send);
 
123
                        }
 
124
                        
 
125
                }
 
126
                else if(fd->type == MEDIA_FLOW_HALF_DUPLEX){
 
127
                        
 
128
                        switch(source->tx_endpoint->protocol){
 
129
                                case MEDIA_ALSA:
 
130
                                case MEDIA_OSS:
 
131
                                        snd_read = g_list_append(snd_read, fd->recv);
 
132
                        }
 
133
                        switch(destination->rx_endpoint->protocol){
 
134
                                case MEDIA_ALSA:
 
135
                                case MEDIA_OSS:
 
136
                                        snd_write = g_list_append(snd_write, fd->play);
 
137
                        }
 
138
                }
 
139
                if(syncFlag == MULTISYNC){
 
140
                        flow->sync = g_list_append(flow->sync, sync);
 
141
                }
 
142
        }
 
143
        if(syncFlag == ONESYNC){
 
144
                ms_start(sync);
 
145
                flow->sync = g_list_append(flow->sync, sync);
 
146
        }
 
147
        if(syncFlag == MULTISYNC){
 
148
                selem = flow->sync;
 
149
                while(selem != NULL){
 
150
                        ms_start(selem->data);
 
151
                        selem = g_list_next(selem);
 
152
                }
 
153
        }
 
154
        filter = snd_read;
 
155
        while(filter != NULL){
 
156
                ms_sound_read_start(MS_SOUND_READ((MSFilter*)filter->data));
 
157
                filter = g_list_next(filter);
 
158
        }
 
159
 
 
160
        filter = snd_write;
 
161
        while(filter != NULL){
 
162
                ms_sound_write_start(MS_SOUND_WRITE((MSFilter*)filter->data));
 
163
                filter = g_list_next(filter);
 
164
        }
 
165
        return 1;
 
166
}
 
167
 
 
168
int basic_call_stop_flow(BasicCall *call, MediaFlow *flow){
 
169
 
 
170
}