~ubuntu-branches/ubuntu/vivid/linphone/vivid

« back to all changes in this revision

Viewing changes to media_api/mediaflow.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
#include "common.h"
 
21
#include "mediaflow.h"
 
22
#include "callmember.h"
 
23
 
 
24
 
 
25
MediaFlow *media_flow_new(char *id_string, int type){
 
26
  MediaFlow *flow = (MediaFlow *) g_malloc(sizeof(MediaFlow));  //malloc required?
 
27
  api_trace("media_flow_new: creating %s",id_string);
 
28
  flow->id = id_string;
 
29
  flow->type = type;
 
30
  flow->flowDirections = NULL;
 
31
  flow->members = NULL;
 
32
  return flow;
 
33
}
 
34
 
 
35
int media_flow_destroy(MediaFlow *flow){
 
36
        g_free(flow);
 
37
        return 1;
 
38
}
 
39
 
 
40
int media_flow_setup_fd(MediaFlow *flow, CallMember* csource, CallMember *cdestination, int direction){
 
41
        GList *source, *destination;
 
42
        char *dir;
 
43
        FlowDirections *fd = (FlowDirections *) g_malloc(sizeof(FlowDirections));
 
44
        if(direction == MEDIA_FLOW_DUPLEX) dir = "DUPLEX";
 
45
        else if(direction == MEDIA_FLOW_HALF_DUPLEX) dir = "HALF_DUPLEX";
 
46
        api_trace("media_flow_setup_fd: setting up %s flow for %s , %s",dir, csource->name, cdestination->name);
 
47
        source = g_list_find_custom(flow->members, csource, &find);
 
48
        destination =g_list_find_custom(flow->members, cdestination, &find);
 
49
        if(source == NULL){
 
50
                api_error("media_flow_setup_fd: Invalid source %s specified", csource->name);
 
51
        }
 
52
        if(destination == NULL){
 
53
                api_error("media_flow_setup_fd: Invalid destination %s specified", cdestination->name);
 
54
                //ERROR handling to be done here
 
55
        }
 
56
        fd->source = (Members*)source->data;
 
57
        fd->destination = (Members*)destination->data;
 
58
        fd->type = direction;
 
59
        flow->flowDirections = g_list_append(flow->flowDirections, fd);
 
60
        return 1;
 
61
}
 
62
 
 
63
int find(gconstpointer mem, gconstpointer cmember){
 
64
        if(!strcmp(((Members*)mem)->member->name, ((CallMember*)cmember)->name)){
 
65
                return 0;
 
66
        }
 
67
        return 1;
 
68
}
 
69
 
 
70
int media_flow_start_fd(FlowDirections *fd, MSSync *sync){
 
71
        Members *source, *destination;
 
72
        source = fd->source;
 
73
        destination = fd->destination;
 
74
        if(fd->type == MEDIA_FLOW_DUPLEX){
 
75
                fd->recv = set_MSFilter(source->tx_endpoint,1,fd);
 
76
                fd->dec = set_CODECFilter(source->member->profile, source->tx_endpoint->pt,MEDIA_API_DECODER);
 
77
                fd->play = set_MSFilter(destination->rx_endpoint,0,fd);
 
78
                
 
79
                ms_filter_add_link(fd->recv,fd->dec);
 
80
                ms_filter_add_link(fd->dec,fd->play);
 
81
                ms_sync_attach(sync, fd->recv);
 
82
                
 
83
                fd->read = set_MSFilter(destination->tx_endpoint,1,fd);
 
84
                fd->enc = set_CODECFilter(destination->member->profile, destination->tx_endpoint->pt,MEDIA_API_ENCODER);
 
85
                fd->send = set_MSFilter(source->rx_endpoint,0,fd);
 
86
                
 
87
                ms_filter_add_link(fd->read, fd->enc);
 
88
                ms_filter_add_link(fd->enc, fd->send);
 
89
                ms_sync_attach(sync, fd->read);
 
90
                
 
91
        }
 
92
        else if(fd->type == MEDIA_FLOW_HALF_DUPLEX){
 
93
        
 
94
                fd->recv = set_MSFilter(source->tx_endpoint,1,fd);
 
95
                fd->dec = set_CODECFilter(sourcec->member->profile, source->tx_endpoint->pt,MEDIA_API_DECODER);
 
96
                fd->play = set_MSFilter(destination->rx_endpoint,0,fd);
 
97
                
 
98
                ms_filter_add_link(fd->recv,fd->dec);
 
99
                ms_filter_add_link(fd->dec,fd->play);
 
100
                ms_sync_attach(sync, fd->recv); 
 
101
        }
 
102
        return 1;
 
103
}
 
104
 
 
105
 
 
106
MSFilter *set_MSFilter(EndPoint *endpoint, int type, FlowDirections *fdir){
 
107
        MSFilter *filter;
 
108
        RtpSession *rtps;
 
109
        switch(endpoint->protocol){
 
110
                case MEDIA_RTP:
 
111
                        rtps = rtp_session_new(RTP_SESSION_RECVONLY);
 
112
                        rtp_session_set_local_addr(rtps,"0.0.0.0",8000);
 
113
                        rtp_session_set_scheduling_mode(rtps,0);
 
114
                        rtp_session_set_blocking_mode(rtps,0);
 
115
                        
 
116
                        if(type == 1){
 
117
                                filter = ms_rtp_recv_new();
 
118
                                ms_rtp_recv_set_session(MS_RTP_RECV(filter), rtps);
 
119
                                fdir->rtpSessions = g_list_append(fdir->rtpSessions, rtps);
 
120
                                return filter;
 
121
                        }
 
122
                        else{
 
123
                                //ms_rtp_send_new
 
124
                        }
 
125
                case MEDIA_OSS:
 
126
                        if(type == 1){
 
127
                                filter = ms_oss_read_new();
 
128
                                ms_sound_read_set_device(MS_SOUND_READ(filter),0);
 
129
                                return filter;
 
130
                        }
 
131
                        else{
 
132
                                filter = ms_oss_write_new();
 
133
                                ms_sound_write_set_device(MS_SOUND_WRITE(filter),0);
 
134
                                return filter;
 
135
                        }
 
136
                case MEDIA_FILE:
 
137
                        if(type == 1){
 
138
                                filter = ms_read_new(endpoint->file);
 
139
                                return filter;
 
140
                        }
 
141
                        if(type == 0){
 
142
                                filter = ms_write_new(endpoint->file);
 
143
                                return filter;
 
144
                        }
 
145
 
 
146
        }
 
147
}
 
148
 
 
149
MSFilter *set_CODECFilter(RtpProfile *profile, int pt, int mode){
 
150
        PayloadType *payload;
 
151
        
 
152
        switch(mode){
 
153
                case MEDIA_API_DECODER: 
 
154
                        payload = rtp_profile_get_payload(profile, pt);
 
155
                        if(payload == NULL){
 
156
                                api_error("media_api: undefined payload in URL\n");
 
157
                                return NULL;
 
158
                        }
 
159
                        return ms_decoder_new_with_string_id(payload->mime_type);
 
160
                        
 
161
                        //Commented this to include the new RtpProfile
 
162
                        /*if(pt != -1) return ms_decoder_new_with_pt(pt);
 
163
                         *else return ms_copy_new();
 
164
                         */
 
165
                case MEDIA_API_ENCODER: 
 
166
                        
 
167
                        payload = rtp_profile_get_payload(profile, pt);
 
168
                        if(payload == NULL){
 
169
                                api_error("media_api: undefined payload in URL\n");
 
170
                                return NULL;
 
171
                        }
 
172
                        return ms_encoder_new_with_string_id(payload->mime_type);
 
173
                        /*if(pt != -1) return ms_encoder_new_with_pt(pt);
 
174
                         *else return ms_copy_new();
 
175
                         */
 
176
        }
 
177
}
 
178
        
 
179