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
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.
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.
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
21
#include "mediaflow.h"
22
#include "callmember.h"
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);
30
flow->flowDirections = NULL;
35
int media_flow_destroy(MediaFlow *flow){
40
int media_flow_setup_fd(MediaFlow *flow, CallMember* csource, CallMember *cdestination, int direction){
41
GList *source, *destination;
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);
50
api_error("media_flow_setup_fd: Invalid source %s specified", csource->name);
52
if(destination == NULL){
53
api_error("media_flow_setup_fd: Invalid destination %s specified", cdestination->name);
54
//ERROR handling to be done here
56
fd->source = (Members*)source->data;
57
fd->destination = (Members*)destination->data;
59
flow->flowDirections = g_list_append(flow->flowDirections, fd);
63
int find(gconstpointer mem, gconstpointer cmember){
64
if(!strcmp(((Members*)mem)->member->name, ((CallMember*)cmember)->name)){
70
int media_flow_start_fd(FlowDirections *fd, MSSync *sync){
71
Members *source, *destination;
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);
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);
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);
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);
92
else if(fd->type == MEDIA_FLOW_HALF_DUPLEX){
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);
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);
106
MSFilter *set_MSFilter(EndPoint *endpoint, int type, FlowDirections *fdir){
109
switch(endpoint->protocol){
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);
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);
127
filter = ms_oss_read_new();
128
ms_sound_read_set_device(MS_SOUND_READ(filter),0);
132
filter = ms_oss_write_new();
133
ms_sound_write_set_device(MS_SOUND_WRITE(filter),0);
138
filter = ms_read_new(endpoint->file);
142
filter = ms_write_new(endpoint->file);
149
MSFilter *set_CODECFilter(RtpProfile *profile, int pt, int mode){
150
PayloadType *payload;
153
case MEDIA_API_DECODER:
154
payload = rtp_profile_get_payload(profile, pt);
156
api_error("media_api: undefined payload in URL\n");
159
return ms_decoder_new_with_string_id(payload->mime_type);
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();
165
case MEDIA_API_ENCODER:
167
payload = rtp_profile_get_payload(profile, pt);
169
api_error("media_api: undefined payload in URL\n");
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();