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
|
|
22 #include "msnosync.h"
|
|
23
|
|
24 static MSNoSyncClass *ms_nosync_class=NULL;
|
|
25
|
|
26 void ms_nosync_init(MSNoSync *sync)
|
|
27 {
|
|
28 ms_sync_init(MS_SYNC(sync));
|
|
29 MS_SYNC(sync)->attached_filters=sync->filters;
|
|
30 memset(sync->filters,0,MSNOSYNC_MAX_FILTERS*sizeof(MSFilter*));
|
|
31 MS_SYNC(sync)->samples_per_tick=160;
|
|
32 sync->started=0;
|
|
33 }
|
|
34
|
|
35 void ms_nosync_class_init(MSNoSyncClass *klass)
|
|
36 {
|
|
37 ms_sync_class_init(MS_SYNC_CLASS(klass));
|
|
38 MS_SYNC_CLASS(klass)->max_filters=MSNOSYNC_MAX_FILTERS;
|
|
39 MS_SYNC_CLASS(klass)->synchronize=(MSSyncSyncFunc)ms_nosync_synchronize;
|
|
40 MS_SYNC_CLASS(klass)->destroy=(MSSyncDestroyFunc)ms_nosync_destroy;
|
|
41 /* no need to overload these function*/
|
|
42 MS_SYNC_CLASS(klass)->attach=ms_sync_attach_generic;
|
|
43 MS_SYNC_CLASS(klass)->detach=ms_sync_detach_generic;
|
|
44 }
|
|
45
|
|
46 void ms_nosync_destroy(MSNoSync *nosync)
|
|
47 {
|
|
48 g_free(nosync);
|
|
49 }
|
|
50
|
|
51 /* the synchronization function that does nothing*/
|
|
52 void ms_nosync_synchronize(MSNoSync *nosync)
|
|
53 {
|
|
54 gint32 time;
|
|
55 if (nosync->started==0){
|
|
56 gettimeofday(&nosync->start,NULL);
|
|
57 nosync->started=1;
|
|
58 }
|
|
59 gettimeofday(&nosync->current,NULL);
|
|
60 MS_SYNC(nosync)->ticks++;
|
|
61 /* update the time, we are supposed to work at 8000 Hz */
|
|
62 time=((nosync->current.tv_sec-nosync->start.tv_sec)*1000) +
|
|
63 ((nosync->current.tv_usec-nosync->start.tv_usec)/1000);
|
|
64 MS_SYNC(nosync)->time=time;
|
|
65 return;
|
|
66 }
|
|
67
|
|
68
|
|
69 MSSync *ms_nosync_new()
|
|
70 {
|
|
71 MSNoSync *nosync;
|
|
72
|
|
73 nosync=g_malloc(sizeof(MSNoSync));
|
|
74 ms_nosync_init(nosync);
|
|
75 if (ms_nosync_class==NULL)
|
|
76 {
|
|
77 ms_nosync_class=g_new(MSNoSyncClass,1);
|
|
78 ms_nosync_class_init(ms_nosync_class);
|
|
79 }
|
|
80 MS_SYNC(nosync)->klass=MS_SYNC_CLASS(ms_nosync_class);
|
|
81 return(MS_SYNC(nosync));
|
|
82 }
|