12024
|
1 /**
|
12050
|
2 * @file media.c Voice and Video API
|
12024
|
3 * @ingroup core
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25
|
12034
|
26 #include "internal.h"
|
|
27
|
12024
|
28 #ifdef HAVE_VV
|
|
29
|
|
30 #include "media.h"
|
|
31 #include "mediastream.h"
|
|
32 #include "msilbcdec.h"
|
|
33
|
|
34
|
|
35 /* msrtpsend.o and msrtprecv.o aren't used within the core, so
|
|
36 * the linker chooses not to link them. I want plugins to be able
|
|
37 * to depend on them, so I reference symbols from them here. */
|
|
38 static void * dummy1 = ms_rtp_send_new;
|
|
39 static void * dummy2 = ms_rtp_recv_new;
|
|
40
|
|
41 struct _GaimVoiceChat {
|
|
42 GaimConnection *gc;
|
|
43 char *name;
|
|
44
|
|
45 GaimMediaState state;
|
|
46
|
|
47 void *proto_data;
|
|
48 void *ui_data;
|
|
49
|
|
50 MSFilter *speaker;
|
|
51 MSFilter *microphone;
|
|
52 MSSync *timer;
|
|
53 };
|
|
54
|
|
55 static GaimMediaUiOps *media_ui_ops = NULL;
|
|
56
|
|
57 void gaim_media_init()
|
|
58 {
|
|
59 ms_init();
|
|
60 ms_ilbc_codec_init();
|
|
61 ms_speex_codec_init();
|
|
62 ortp_init();
|
|
63 }
|
|
64
|
|
65 GaimVoiceChat *gaim_voice_chat_new(GaimConnection *gc, const char *name)
|
|
66 {
|
|
67 GaimVoiceChat *vc = g_new0(GaimVoiceChat, 1);
|
|
68 SndCard *card;
|
|
69
|
|
70 vc->gc = gc;
|
|
71 vc->name = g_strdup(name);
|
|
72
|
|
73 card = snd_card_manager_get_card(snd_card_manager,0);
|
|
74 vc->speaker = snd_card_create_write_filter(card);
|
|
75 vc->microphone = snd_card_create_read_filter(card);
|
|
76 vc->timer = ms_timer_new();
|
|
77 ms_sync_attach(vc->timer, vc->microphone);
|
|
78 if (media_ui_ops)
|
|
79 media_ui_ops->new_voice_chat(vc);
|
|
80 return vc;
|
|
81 }
|
|
82
|
|
83
|
|
84
|
|
85 void gaim_voice_chat_destroy(GaimVoiceChat *vc)
|
|
86 {
|
|
87 if (media_ui_ops)
|
|
88 media_ui_ops->destroy(vc);
|
|
89 g_free(vc);
|
|
90 }
|
|
91
|
|
92 const char *gaim_voice_chat_get_name(GaimVoiceChat *vc)
|
|
93 {
|
|
94 return vc->name;
|
|
95 }
|
|
96
|
|
97 void gaim_voice_chat_set_name(GaimVoiceChat *vc, const char *name)
|
|
98 {
|
|
99 g_free(vc->name);
|
|
100 vc->name = g_strdup(name);
|
|
101 }
|
|
102
|
|
103 GaimConnection *gaim_voice_chat_get_connection(GaimVoiceChat *vc)
|
|
104 {
|
|
105 return vc->gc;
|
|
106 }
|
|
107
|
|
108 void *gaim_voice_chat_get_ui_data(GaimVoiceChat *vc)
|
|
109 {
|
|
110 return vc->ui_data;
|
|
111 }
|
|
112
|
|
113 void gaim_voice_chat_set_ui_data(GaimVoiceChat *vc, void *data)
|
|
114 {
|
|
115 vc->ui_data = data;
|
|
116 }
|
|
117
|
|
118 void *gaim_voice_chat_get_proto_data(GaimVoiceChat *vc)
|
|
119 {
|
|
120 return vc->proto_data;
|
|
121 }
|
|
122
|
|
123 void gaim_voice_chat_set_proto_data(GaimVoiceChat *vc, void *data)
|
|
124 {
|
|
125 vc->proto_data = data;
|
|
126 }
|
|
127
|
|
128 void gaim_media_set_ui_ops(GaimMediaUiOps *ops)
|
|
129 {
|
|
130 media_ui_ops = ops;
|
|
131 }
|
|
132
|
|
133 GaimMediaUiOps *gaim_media_get_ui_ops(void)
|
|
134 {
|
|
135 return media_ui_ops;
|
|
136 }
|
|
137
|
|
138
|
|
139 GaimMediaState gaim_voice_chat_get_state(GaimVoiceChat *vc)
|
|
140 {
|
|
141 return vc->state;
|
|
142 }
|
|
143
|
|
144 void gaim_voice_chat_accept(GaimVoiceChat *vc)
|
|
145 {
|
|
146 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
|
|
147 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
148
|
|
149 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
150
|
|
151 if (!prpl_info->media_prpl_ops || !prpl_info->media_prpl_ops->accept)
|
|
152 return;
|
|
153 prpl_info->media_prpl_ops->accept(vc);
|
|
154 }
|
|
155
|
|
156 void gaim_voice_chat_reject(GaimVoiceChat *vc)
|
|
157 {
|
|
158 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
|
|
159 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
160
|
|
161 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
162
|
|
163 if (!prpl_info->media_prpl_ops || !prpl_info->media_prpl_ops->reject)
|
|
164 return;
|
|
165 prpl_info->media_prpl_ops->reject(vc);
|
|
166 }
|
|
167
|
|
168
|
|
169 void gaim_voice_chat_terminate(GaimVoiceChat *vc)
|
|
170 {
|
|
171 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
|
|
172 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
173
|
|
174 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
175
|
|
176 if (!prpl_info->media_prpl_ops || !prpl_info->media_prpl_ops->terminate)
|
|
177 return;
|
|
178 prpl_info->media_prpl_ops->terminate(vc);
|
|
179 }
|
|
180
|
|
181
|
|
182 void gaim_voice_chat_set_state(GaimVoiceChat *vc, GaimMediaState state)
|
|
183 {
|
|
184 vc->state = state;
|
12034
|
185 printf("State: %d\n",state);
|
12024
|
186 if (media_ui_ops)
|
|
187 media_ui_ops->state_change(vc, state);
|
|
188 }
|
|
189
|
|
190 void gaim_voice_chat_get_filters(GaimVoiceChat *vc, MSFilter **microphone, MSFilter **speaker)
|
|
191 {
|
|
192 if (microphone) *microphone = vc->microphone;
|
|
193 if (speaker) *speaker = vc->speaker;
|
|
194 }
|
|
195
|
|
196 MSSync *gaim_voice_chat_get_timer(GaimVoiceChat *vc)
|
|
197 {
|
|
198 return vc->timer;
|
|
199 }
|
|
200
|
12034
|
201 void gaim_voice_chat_start_streams(GaimVoiceChat *vc)
|
12024
|
202 {
|
|
203 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
|
|
204 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
205
|
|
206 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
207
|
|
208 if (prpl_info->media_prpl_ops && prpl_info->media_prpl_ops->init_filters)
|
|
209 prpl_info->media_prpl_ops->init_filters(vc);
|
|
210
|
|
211 ms_start(vc->timer);
|
|
212 }
|
|
213
|
|
214 #endif /* HAVE_VV */
|