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
+ 鐃緒申 33
+ 鐃緒申 34 /* msrtpsend.o and msrtprecv.o aren't used within the core, so
+ 鐃緒申 35 * the linker chooses not to link them. I want plugins to be able
+ 鐃緒申 36 * to depend on them, so I reference symbols from them here. */
+ 鐃緒申 37 static void * dummy1 = ms_rtp_send_new;
+ 鐃緒申 38 static void * dummy2 = ms_rtp_recv_new;
+ 鐃緒申 39
+ 鐃緒申 40 struct _GaimVoiceChat {
+ 鐃緒申 41 GaimConnection *gc;
+ 鐃緒申 42 char *name;
+ 鐃緒申 43
+ 鐃緒申 44 GaimMediaState state;
+ 鐃緒申 45
+ 鐃緒申 46 void *proto_data;
+ 鐃緒申 47 void *ui_data;
+ 鐃緒申 48
+ 鐃緒申 49 MSFilter *speaker;
+ 鐃緒申 50 MSFilter *microphone;
+ 鐃緒申 51 MSSync *timer;
+ 鐃緒申 52 };
+ 鐃緒申 53
+ 鐃緒申 54 static GaimMediaUiOps *media_ui_ops = NULL;
+ 鐃緒申 55
+ 鐃緒申 56 void gaim_media_init()
+ 鐃緒申 57 {
+ 鐃緒申 58 ms_init();
+ 鐃緒申 59 ms_speex_codec_init();
+ 鐃緒申 60 ortp_init();
+ 鐃緒申 61 }
+ 鐃緒申 62
+ 鐃緒申 63 GaimVoiceChat *gaim_voice_chat_new(GaimConnection *gc, const char *name)
+ 鐃緒申 64 {
+ 鐃緒申 65 GaimVoiceChat *vc = g_new0(GaimVoiceChat, 1);
+ 鐃緒申 66 SndCard *card;
+ 鐃緒申 67
+ 鐃緒申 68 vc->gc = gc;
+ 鐃緒申 69 vc->name = g_strdup(name);
+ 鐃緒申 70
+ 鐃緒申 71 card = snd_card_manager_get_card(snd_card_manager,0);
+ 鐃緒申 72 vc->speaker = snd_card_create_write_filter(card);
+ 鐃緒申 73 vc->microphone = snd_card_create_read_filter(card);
+ 鐃緒申 74 vc->timer = ms_timer_new();
+ 鐃緒申 75 ms_sync_attach(vc->timer, vc->microphone);
+ 鐃緒申 76 if (media_ui_ops)
+ 鐃緒申 77 media_ui_ops->new_voice_chat(vc);
+ 鐃緒申 78 return vc;
+ 鐃緒申 79 }
+ 鐃緒申 80
+ 鐃緒申 81
+ 鐃緒申 82
+ 鐃緒申 83 void gaim_voice_chat_destroy(GaimVoiceChat *vc)
+ 鐃緒申 84 {
+ 鐃緒申 85 if (media_ui_ops)
+ 鐃緒申 86 media_ui_ops->destroy(vc);
+ 鐃緒申 87 g_free(vc);
+ 鐃緒申 88 }
+ 鐃緒申 89
+ 鐃緒申 90 const char *gaim_voice_chat_get_name(GaimVoiceChat *vc)
+ 鐃緒申 91 {
+ 鐃緒申 92 return vc->name;
+ 鐃緒申 93 }
+ 鐃緒申 94
+ 鐃緒申 95 void gaim_voice_chat_set_name(GaimVoiceChat *vc, const char *name)
+ 鐃緒申 96 {
+ 鐃緒申 97 g_free(vc->name);
+ 鐃緒申 98 vc->name = g_strdup(name);
+ 鐃緒申 99 }
+ 鐃緒申 100
+ 鐃緒申 101 GaimConnection *gaim_voice_chat_get_connection(GaimVoiceChat *vc)
+ 鐃緒申 102 {
+ 鐃緒申 103 return vc->gc;
+ 鐃緒申 104 }
+ 鐃緒申 105
+ 鐃緒申 106 void *gaim_voice_chat_get_ui_data(GaimVoiceChat *vc)
+ 鐃緒申 107 {
+ 鐃緒申 108 return vc->ui_data;
+ 鐃緒申 109 }
+ 鐃緒申 110
+ 鐃緒申 111 void gaim_voice_chat_set_ui_data(GaimVoiceChat *vc, void *data)
+ 鐃緒申 112 {
+ 鐃緒申 113 vc->ui_data = data;
+ 鐃緒申 114 }
+ 鐃緒申 115
+ 鐃緒申 116 void *gaim_voice_chat_get_proto_data(GaimVoiceChat *vc)
+ 鐃緒申 117 {
+ 鐃緒申 118 return vc->proto_data;
+ 鐃緒申 119 }
+ 鐃緒申 120
+ 鐃緒申 121 void gaim_voice_chat_set_proto_data(GaimVoiceChat *vc, void *data)
+ 鐃緒申 122 {
+ 鐃緒申 123 vc->proto_data = data;
+ 鐃緒申 124 }
+ 鐃緒申 125
+ 鐃緒申 126 void gaim_media_set_ui_ops(GaimMediaUiOps *ops)
+ 鐃緒申 127 {
+ 鐃緒申 128 media_ui_ops = ops;
+ 鐃緒申 129 }
+ 鐃緒申 130
+ 鐃緒申 131 GaimMediaUiOps *gaim_media_get_ui_ops(void)
+ 鐃緒申 132 {
+ 鐃緒申 133 return media_ui_ops;
+ 鐃緒申 134 }
+ 鐃緒申 135
+ 鐃緒申 136
+ 鐃緒申 137 GaimMediaState gaim_voice_chat_get_state(GaimVoiceChat *vc)
+ 鐃緒申 138 {
+ 鐃緒申 139 return vc->state;
+ 鐃緒申 140 }
+ 鐃緒申 141
+ 鐃緒申 142 void gaim_voice_chat_accept(GaimVoiceChat *vc)
+ 鐃緒申 143 {
+ 鐃緒申 144 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
+ 鐃緒申 145 GaimPluginProtocolInfo *prpl_info = NULL;
+ 鐃緒申 146
+ 鐃緒申 147 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+ 鐃緒申 148
+ 鐃緒申 149 if (!prpl_info->media_prpl_ops || !prpl_info->media_prpl_ops->accept)
+ 鐃緒申 150 return;
+ 鐃緒申 151 prpl_info->media_prpl_ops->accept(vc);
+ 鐃緒申 152 }
+ 鐃緒申 153
+ 鐃緒申 154 void gaim_voice_chat_reject(GaimVoiceChat *vc)
+ 鐃緒申 155 {
+ 鐃緒申 156 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
+ 鐃緒申 157 GaimPluginProtocolInfo *prpl_info = NULL;
+ 鐃緒申 158
+ 鐃緒申 159 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+ 鐃緒申 160
+ 鐃緒申 161 if (!prpl_info->media_prpl_ops || !prpl_info->media_prpl_ops->reject)
+ 鐃緒申 162 return;
+ 鐃緒申 163 prpl_info->media_prpl_ops->reject(vc);
+ 鐃緒申 164 }
+ 鐃緒申 165
+ 鐃緒申 166
+ 鐃緒申 167 void gaim_voice_chat_terminate(GaimVoiceChat *vc)
+ 鐃緒申 168 {
+ 鐃緒申 169 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
+ 鐃緒申 170 GaimPluginProtocolInfo *prpl_info = NULL;
+ 鐃緒申 171
+ 鐃緒申 172 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+ 鐃緒申 173
+ 鐃緒申 174 if (!prpl_info->media_prpl_ops || !prpl_info->media_prpl_ops->terminate)
+ 鐃緒申 175 return;
+ 鐃緒申 176 prpl_info->media_prpl_ops->terminate(vc);
+ 鐃緒申 177 }
+ 鐃緒申 178
+ 鐃緒申 179
+ 鐃緒申 180 void gaim_voice_chat_set_state(GaimVoiceChat *vc, GaimMediaState state)
+ 鐃緒申 181 {
+ 鐃緒申 182 vc->state = state;
12034
+ 鐃緒申 183 printf("State: %d\n",state);
12024
+ 鐃緒申 184 if (media_ui_ops)
+ 鐃緒申 185 media_ui_ops->state_change(vc, state);
+ 鐃緒申 186 }
+ 鐃緒申 187
+ 鐃緒申 188 void gaim_voice_chat_get_filters(GaimVoiceChat *vc, MSFilter **microphone, MSFilter **speaker)
+ 鐃緒申 189 {
+ 鐃緒申 190 if (microphone) *microphone = vc->microphone;
+ 鐃緒申 191 if (speaker) *speaker = vc->speaker;
+ 鐃緒申 192 }
+ 鐃緒申 193
+ 鐃緒申 194 MSSync *gaim_voice_chat_get_timer(GaimVoiceChat *vc)
+ 鐃緒申 195 {
+ 鐃緒申 196 return vc->timer;
+ 鐃緒申 197 }
+ 鐃緒申 198
12034
+ 鐃緒申 199 void gaim_voice_chat_start_streams(GaimVoiceChat *vc)
12024
+ 鐃緒申 200 {
+ 鐃緒申 201 GaimConnection *gc = gaim_voice_chat_get_connection(vc);
+ 鐃緒申 202 GaimPluginProtocolInfo *prpl_info = NULL;
+ 鐃緒申 203
+ 鐃緒申 204 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+ 鐃緒申 205
+ 鐃緒申 206 if (prpl_info->media_prpl_ops && prpl_info->media_prpl_ops->init_filters)
+ 鐃緒申 207 prpl_info->media_prpl_ops->init_filters(vc);
+ 鐃緒申 208
+ 鐃緒申 209 ms_start(vc->timer);
+ 鐃緒申 210 }
+ 鐃緒申 211
+ 鐃緒申 212 #endif /* HAVE_VV */