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 "mscopy.h"
|
|
23 #include <unistd.h>
|
|
24 #include <fcntl.h>
|
|
25 #include <sys/types.h>
|
|
26 #include <sys/stat.h>
|
|
27 #include <string.h>
|
|
28 #include <errno.h>
|
|
29
|
|
30 static MSCopyClass *ms_copy_class=NULL;
|
|
31
|
|
32 MSFilter * ms_copy_new(void)
|
|
33 {
|
|
34 MSCopy *r;
|
|
35
|
|
36 r=g_new(MSCopy,1);
|
|
37 ms_copy_init(r);
|
|
38 if (ms_copy_class==NULL)
|
|
39 {
|
|
40 ms_copy_class=g_new(MSCopyClass,1);
|
|
41 ms_copy_class_init(ms_copy_class);
|
|
42 }
|
|
43 MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_copy_class);
|
|
44 return(MS_FILTER(r));
|
|
45 }
|
|
46
|
|
47
|
|
48 /* FOR INTERNAL USE*/
|
|
49 void ms_copy_init(MSCopy *r)
|
|
50 {
|
|
51 ms_filter_init(MS_FILTER(r));
|
|
52 MS_FILTER(r)->infifos=r->f_inputs;
|
|
53 MS_FILTER(r)->outfifos=r->f_outputs;
|
|
54 MS_FILTER(r)->r_mingran=MSCOPY_DEF_GRAN;
|
|
55 memset(r->f_inputs,0,sizeof(MSFifo*)*MSCOPY_MAX_INPUTS);
|
|
56 memset(r->f_outputs,0,sizeof(MSFifo*)*MSCOPY_MAX_INPUTS);
|
|
57 }
|
|
58
|
|
59 void ms_copy_class_init(MSCopyClass *klass)
|
|
60 {
|
|
61 ms_filter_class_init(MS_FILTER_CLASS(klass));
|
|
62 ms_filter_class_set_name(MS_FILTER_CLASS(klass),"fifocopier");
|
|
63 MS_FILTER_CLASS(klass)->max_finputs=MSCOPY_MAX_INPUTS;
|
|
64 MS_FILTER_CLASS(klass)->max_foutputs=MSCOPY_MAX_INPUTS;
|
|
65 MS_FILTER_CLASS(klass)->r_maxgran=MSCOPY_DEF_GRAN;
|
|
66 MS_FILTER_CLASS(klass)->w_maxgran=MSCOPY_DEF_GRAN;
|
|
67 MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_copy_destroy;
|
|
68 MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_copy_process;
|
|
69 }
|
|
70
|
|
71 void ms_copy_process(MSCopy *r)
|
|
72 {
|
|
73 MSFifo *fi,*fo;
|
|
74 int err1;
|
|
75 gint gran=MS_FILTER(r)->klass->r_maxgran;
|
|
76 void *s,*d;
|
|
77
|
|
78 /* process output fifos, but there is only one for this class of filter*/
|
|
79
|
|
80 fi=r->f_inputs[0];
|
|
81 fo=r->f_outputs[0];
|
|
82 if (fi!=NULL)
|
|
83 {
|
|
84 err1=ms_fifo_get_read_ptr(fi,gran,&s);
|
|
85 if (err1>0) err1=ms_fifo_get_write_ptr(fo,gran,&d);
|
|
86 if (err1>0)
|
|
87 {
|
|
88 memcpy(d,s,gran);
|
|
89 }
|
|
90 }
|
|
91 }
|
|
92
|
|
93 void ms_copy_destroy( MSCopy *obj)
|
|
94 {
|
|
95 g_free(obj);
|
|
96 }
|