Mercurial > pidgin
annotate src/mediastreamer/mssync.c @ 12662:eb4841fa697c
[gaim-migrate @ 15005]
sf bug #1385691, Text field visible even when status set to "online"
Don't allow available messages for ICQ. The server doesn't support them.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 26 Dec 2005 07:43:41 +0000 |
| parents | 1c771536a032 |
| children |
| rev | line source |
|---|---|
| 12024 | 1 /* |
| 2 The mediastreamer library aims at providing modular media processing and I/O | |
| 3 for linphone, but also for any telephony application. | |
| 4 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org | |
| 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 "mssync.h" | |
| 22 #include <errno.h> | |
| 23 | |
| 24 /* TODO: | |
| 25 -define an uninit function that free the mutex | |
| 26 */ | |
| 27 | |
| 28 /** | |
| 29 * function_name:ms_sync_get_bytes_per_tick | |
| 30 * @sync: A #MSSync object. | |
| 31 * | |
| 32 * Returns the number of bytes per tick. This is a usefull information for sources, so | |
| 33 * that they can know how much data they must deliver each time they are called. | |
| 34 * | |
| 35 */ | |
| 36 | |
| 37 /* private */ | |
| 38 void ms_sync_init(MSSync *sync) | |
| 39 { | |
| 40 sync->klass=NULL; | |
| 41 sync->lock=g_mutex_new(); | |
| 42 sync->thread_cond=g_cond_new(); | |
| 43 sync->stop_cond=g_cond_new(); | |
| 44 sync->attached_filters=NULL; | |
| 45 sync->execution_list=NULL; | |
| 46 sync->filters=0; | |
| 47 sync->run=0; | |
| 48 sync->flags=0; | |
| 49 sync->samples_per_tick=0; | |
| 50 sync->ticks=0; | |
| 51 sync->time=0; | |
| 52 sync->thread=NULL; | |
| 53 } | |
| 54 | |
| 55 void ms_sync_class_init(MSSyncClass *klass) | |
| 56 { | |
| 57 klass->max_filters=0; | |
| 58 klass->synchronize=NULL; | |
| 59 klass->attach=ms_sync_attach_generic; | |
| 60 klass->detach=ms_sync_detach_generic; | |
| 61 klass->destroy=NULL; | |
| 62 } | |
| 63 | |
| 64 /* public*/ | |
| 65 | |
| 66 | |
| 67 /** | |
| 68 * ms_sync_attach: | |
| 69 * @sync: A #MSSync object. | |
| 70 * @f: A #MSFilter object. | |
| 71 * | |
| 72 * Attach a chain of filters to a synchronisation source @sync. Filter @f must be the first filter of the processing chain. | |
| 73 * In order to be run, each chain of filter must be attached to a synchronisation source, that will be responsible for scheduling | |
| 74 * the processing. Multiple chains can be attached to a single synchronisation. | |
| 75 * | |
| 76 * Returns: 0 if successfull, a negative value reprensenting the errno.h error. | |
| 77 */ | |
| 78 int ms_sync_attach(MSSync *sync,MSFilter *f) | |
| 79 { | |
| 80 gint err; | |
| 81 ms_sync_lock(sync); | |
| 82 err=sync->klass->attach(sync,f); | |
| 83 ms_sync_update(sync); | |
| 84 ms_sync_unlock(sync); | |
| 85 return(err); | |
| 86 } | |
| 87 | |
| 88 int ms_sync_attach_generic(MSSync *sync,MSFilter *f) | |
| 89 { | |
| 90 int i; | |
| 91 //printf("attr: %i\n",f->klass->attributes); | |
| 92 g_return_val_if_fail(f->klass->attributes & FILTER_IS_SOURCE,-EINVAL); | |
| 93 g_return_val_if_fail(sync->attached_filters!=NULL,-EFAULT); | |
| 94 | |
| 95 | |
| 96 /* find a free place to attach*/ | |
| 97 for (i=0;i<sync->klass->max_filters;i++) | |
| 98 { | |
| 99 if (sync->attached_filters[i]==NULL) | |
| 100 { | |
| 101 sync->attached_filters[i]=f; | |
| 102 sync->filters++; | |
| 103 ms_trace("Filter succesfully attached to sync."); | |
| 104 return 0; | |
| 105 } | |
| 106 } | |
| 107 g_warning("No more link on sync !"); | |
| 108 return(-EMLINK); | |
| 109 } | |
| 110 | |
| 111 /** | |
| 112 * ms_sync_detach: | |
| 113 * @sync: A #MSSync object. | |
| 114 * @f: A #MSFilter object. | |
| 115 * | |
| 116 * Dettach a chain of filters to a synchronisation source. Filter @f must be the first filter of the processing chain. | |
| 117 * The processing chain will no more be executed. | |
| 118 * | |
| 119 * Returns: 0 if successfull, a negative value reprensenting the errno.h error. | |
| 120 */ | |
| 121 int ms_sync_detach(MSSync *sync,MSFilter *f) | |
| 122 { | |
| 123 gint err; | |
| 124 ms_sync_lock(sync); | |
| 125 err=sync->klass->detach(sync,f); | |
| 126 ms_sync_update(sync); | |
| 127 ms_sync_unlock(sync); | |
| 128 return(err); | |
| 129 } | |
| 130 | |
| 131 int ms_sync_detach_generic(MSSync *sync,MSFilter *f) | |
| 132 { | |
| 133 int i; | |
| 134 g_return_val_if_fail(f->klass->attributes & FILTER_IS_SOURCE,-EINVAL); | |
| 135 g_return_val_if_fail(sync->attached_filters!=NULL,-EFAULT); | |
| 136 for (i=0;i<sync->filters;i++) | |
| 137 { | |
| 138 if (sync->attached_filters[i]==f) | |
| 139 { | |
| 140 sync->attached_filters[i]=NULL; | |
| 141 sync->filters--; | |
| 142 return 0; | |
| 143 } | |
| 144 } | |
| 145 return(-EMLINK); | |
| 146 } | |
| 147 | |
| 148 void ms_sync_set_samples_per_tick(MSSync *sync,gint size) | |
| 149 { | |
| 150 if (sync->samples_per_tick==0) | |
| 151 { | |
| 152 sync->samples_per_tick=size; | |
| 153 g_cond_signal(sync->thread_cond); | |
| 154 } | |
| 155 else sync->samples_per_tick=size; | |
| 156 } | |
| 157 | |
| 158 /* call the setup func of each filter attached to the graph */ | |
| 159 void ms_sync_setup(MSSync *sync) | |
| 160 { | |
| 161 GList *elem=sync->execution_list; | |
| 162 MSFilter *f; | |
| 163 while(elem!=NULL){ | |
| 164 f=(MSFilter*)elem->data; | |
| 165 if (f->klass->setup!=NULL){ | |
| 166 f->klass->setup(f,sync); | |
| 167 } | |
| 168 elem=g_list_next(elem); | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 /* call the unsetup func of each filter attached to the graph */ | |
| 173 void ms_sync_unsetup(MSSync *sync) | |
| 174 { | |
| 175 GList *elem=sync->execution_list; | |
| 176 MSFilter *f; | |
| 177 while(elem!=NULL){ | |
| 178 f=(MSFilter*)elem->data; | |
| 179 if (f->klass->unsetup!=NULL){ | |
| 180 f->klass->unsetup(f,sync); | |
| 181 } | |
| 182 elem=g_list_next(elem); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 | |
| 187 int ms_sync_uninit(MSSync *sync) | |
| 188 { | |
| 189 g_mutex_free(sync->lock); | |
| 190 g_cond_free(sync->thread_cond); | |
| 191 g_cond_free(sync->stop_cond); | |
|
12029
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
192 |
|
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
193 /* I have no idea if this is right, but nothing in media streamer is |
|
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
194 * calling this, so it should be ok. -- Gary |
|
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
195 */ |
|
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
196 return 0; |
| 12024 | 197 } |
| 198 |
