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 #ifndef MSFILTER_H
|
|
23 #define MSFILTER_H
|
|
24
|
|
25 #include <config.h>
|
|
26
|
|
27 #ifdef HAVE_GLIB
|
|
28 #include <glib.h>
|
|
29 #include <gmodule.h>
|
|
30 #else
|
|
31 #undef VERSION
|
|
32 #undef PACKAGE
|
|
33 #include <uglib.h>
|
|
34 #endif
|
|
35
|
|
36 #include <string.h>
|
|
37 #include "msutils.h"
|
|
38 #include "msfifo.h"
|
|
39 #include "msqueue.h"
|
|
40
|
|
41 struct _MSFilter;
|
|
42 /*this is the abstract object and class for all filter types*/
|
|
43 typedef gint (*MSFilterNotifyFunc)(struct _MSFilter*, gint event, gpointer arg, gpointer userdata);
|
|
44
|
|
45 struct _MSFilter
|
|
46 {
|
|
47 struct _MSFilterClass *klass;
|
|
48 GMutex *lock;
|
|
49 guchar finputs; /* number of connected fifo inputs*/
|
|
50 guchar foutputs; /* number of connected fifo outputs*/
|
|
51 guchar qinputs; /* number of connected queue inputs*/
|
|
52 guchar qoutputs; /* number of connected queue outputs*/
|
|
53 gint min_fifo_size; /* set when linking*/
|
|
54 gint r_mingran; /* read minimum granularity (for fifos).
|
|
55 It can be zero so that the filter can accept any size of reading data*/
|
|
56 MSFifo **infifos; /*pointer to a table of pointer to input fifos*/
|
|
57 MSFifo **outfifos; /*pointer to a table of pointer to output fifos*/
|
|
58 MSQueue **inqueues; /*pointer to a table of pointer to input queues*/
|
|
59 MSQueue **outqueues; /*pointer to a table of pointer to output queues*/
|
|
60 MSFilterNotifyFunc notify_event;
|
|
61 gpointer userdata;
|
|
62 };
|
|
63
|
|
64 typedef struct _MSFilter MSFilter;
|
|
65
|
|
66 typedef enum{
|
|
67 MS_FILTER_PROPERTY_FREQ, /* value is int */
|
|
68 MS_FILTER_PROPERTY_BITRATE, /*value is int */
|
|
69 MS_FILTER_PROPERTY_CHANNELS,/*value is int */
|
|
70 MS_FILTER_PROPERTY_FMTP /* value is string */
|
|
71 }MSFilterProperty;
|
|
72
|
|
73 #define MS_FILTER_PROPERTY_STRING_MAX_SIZE 256
|
|
74
|
|
75 typedef MSFilter * (*MSFilterNewFunc)(void);
|
|
76 typedef void (*MSFilterProcessFunc)(MSFilter *);
|
|
77 typedef void (*MSFilterDestroyFunc)(MSFilter *);
|
|
78 typedef int (*MSFilterPropertyFunc)(MSFilter *,int ,void*);
|
|
79 typedef void (*MSFilterSetupFunc)(MSFilter *, void *); /*2nd arg is the sync */
|
|
80
|
|
81 typedef struct _MSFilterClass
|
|
82 {
|
|
83 struct _MSFilterInfo *info; /*pointer to a filter_info */
|
|
84 gchar *name;
|
|
85 guchar max_finputs; /* maximum number of fifo inputs*/
|
|
86 guchar max_foutputs; /* maximum number of fifo outputs*/
|
|
87 guchar max_qinputs; /* maximum number of queue inputs*/
|
|
88 guchar max_qoutputs; /* maximum number of queue outputs*/
|
|
89 gint r_maxgran; /* read maximum granularity (for fifos)*/
|
|
90 gint w_maxgran; /* write maximum granularity (for fifos)*/
|
|
91 gint r_offset; /* size of kept samples behind read pointer (for fifos)*/
|
|
92 gint w_offset; /* size of kept samples behind write pointer (for fifos)*/
|
|
93 MSFilterPropertyFunc set_property;
|
|
94 MSFilterPropertyFunc get_property;
|
|
95 MSFilterSetupFunc setup; /* called when attaching to sync */
|
|
96 void (*process)(MSFilter *filter);
|
|
97 MSFilterSetupFunc unsetup; /* called when detaching from sync */
|
|
98 void (*destroy)(MSFilter *filter);
|
|
99 guint attributes;
|
|
100 #define FILTER_HAS_FIFOS (0x0001)
|
|
101 #define FILTER_HAS_QUEUES (0x0001<<1)
|
|
102 #define FILTER_IS_SOURCE (0x0001<<2)
|
|
103 #define FILTER_IS_SINK (0x0001<<3)
|
|
104 #define FILTER_CAN_SYNC (0x0001<<4)
|
|
105 guint ref_count; /*number of object using the class*/
|
|
106 } MSFilterClass;
|
|
107
|
|
108
|
|
109
|
|
110 #define MS_FILTER(obj) ((MSFilter*)obj)
|
|
111 #define MS_FILTER_CLASS(klass) ((MSFilterClass*)klass)
|
|
112 #define MS_FILTER_GET_CLASS(obj) ((MSFilterClass*)((MS_FILTER(obj)->klass)))
|
|
113
|
|
114 void ms_filter_class_init(MSFilterClass *filterclass);
|
|
115 void ms_filter_init(MSFilter *filter);
|
|
116
|
|
117 #define ms_filter_class_set_attr(filter,flag) ((filter)->attributes|=(flag))
|
|
118 #define ms_filter_class_unset_attr(filter,flag) ((filter)->attributes&=~(flag))
|
|
119
|
|
120 #define ms_filter_class_set_name(__klass,__name) (__klass)->name=g_strdup((__name))
|
|
121 #define ms_filter_class_set_info(_klass,_info) (_klass)->info=(_info)
|
|
122 /* public*/
|
|
123
|
|
124 #define ms_filter_process(filter) ((filter)->klass->process((filter)))
|
|
125
|
|
126 #define ms_filter_lock(filter) g_mutex_lock((filter)->lock)
|
|
127 #define ms_filter_unlock(filter) g_mutex_unlock((filter)->lock)
|
|
128 /* low level connect functions */
|
|
129 int ms_filter_link(MSFilter *m1, gint pin1, MSFilter *m2,gint pin2, gint linktype);
|
|
130 int ms_filter_unlink(MSFilter *m1, gint pin1, MSFilter *m2,gint pin2,gint linktype);
|
|
131
|
|
132 /* high level connect functions */
|
|
133 int ms_filter_add_link(MSFilter *m1, MSFilter *m2);
|
|
134 int ms_filter_remove_links(MSFilter *m1, MSFilter *m2);
|
|
135
|
|
136 void ms_filter_set_notify_func(MSFilter* filter,MSFilterNotifyFunc func, gpointer userdata);
|
|
137 void ms_filter_notify_event(MSFilter *filter,gint event, gpointer arg);
|
|
138
|
|
139 int ms_filter_set_property(MSFilter *f,MSFilterProperty property, void *value);
|
|
140 int ms_filter_get_property(MSFilter *f,MSFilterProperty property, void *value);
|
|
141
|
|
142
|
|
143 gint ms_filter_fifos_have_data(MSFilter *f);
|
|
144 gint ms_filter_queues_have_data(MSFilter *f);
|
|
145
|
|
146 void ms_filter_uninit(MSFilter *obj);
|
|
147 void ms_filter_destroy(MSFilter *f);
|
|
148
|
|
149 #define ms_filter_get_mingran(f) ((f)->r_mingran)
|
|
150 #define ms_filter_set_mingran(f,gran) ((f)->r_mingran=(gran))
|
|
151
|
|
152 #define LINK_DEFAULT 0
|
|
153 #define LINK_FIFO 1
|
|
154 #define LINK_QUEUE 2
|
|
155
|
|
156
|
|
157 #define MSFILTER_VERSION(a,b,c) (((a)<<2)|((b)<<1)|(c))
|
|
158
|
|
159 enum _MSFilterType
|
|
160 {
|
|
161 MS_FILTER_DISK_IO,
|
|
162 MS_FILTER_AUDIO_CODEC,
|
|
163 MS_FILTER_VIDEO_CODEC,
|
|
164 MS_FILTER_NET_IO,
|
|
165 MS_FILTER_VIDEO_IO,
|
|
166 MS_FILTER_AUDIO_IO,
|
|
167 MS_FILTER_OTHER
|
|
168 };
|
|
169
|
|
170 typedef enum _MSFilterType MSFilterType;
|
|
171
|
|
172
|
|
173 /* find the first codec in the left part of the stream */
|
|
174 MSFilter * ms_filter_search_upstream_by_type(MSFilter *f,MSFilterType type);
|
|
175
|
|
176 struct _MSFilterInfo
|
|
177 {
|
|
178 gchar *name;
|
|
179 gint version;
|
|
180 MSFilterType type;
|
|
181 MSFilterNewFunc constructor;
|
|
182 char *description; /*some textual information*/
|
|
183 };
|
|
184
|
|
185 typedef struct _MSFilterInfo MSFilterInfo;
|
|
186
|
|
187 void ms_filter_register(MSFilterInfo *finfo);
|
|
188 void ms_filter_unregister(MSFilterInfo *finfo);
|
|
189 MSFilterInfo * ms_filter_get_by_name(const gchar *name);
|
|
190
|
|
191 MSFilter * ms_filter_new_with_name(const gchar *name);
|
|
192
|
|
193
|
|
194
|
|
195 extern GList *filter_list;
|
|
196 #define MS_FILTER_INFO(obj) ((MSFilterInfo*)obj)
|
|
197
|
|
198 void swap_buffer(gchar *buffer, gint len);
|
|
199
|
|
200
|
|
201 #endif
|