~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to mediastreamer2/include/mediastreamer2/msfilter.h

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
mediastreamer2 library - modular sound and video processing and streaming
 
3
Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)
 
4
 
 
5
This program is free software; you can redistribute it and/or
 
6
modify it under the terms of the GNU General Public License
 
7
as published by the Free Software Foundation; either version 2
 
8
of the License, or (at your option) any later version.
 
9
 
 
10
This program is distributed in the hope that it will be useful,
 
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
GNU General Public License for more details.
 
14
 
 
15
You should have received a copy of the GNU General Public License
 
16
along with this program; if not, write to the Free Software
 
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
18
*/
 
19
 
 
20
#ifndef msfilter_h
 
21
#define msfilter_h
 
22
 
 
23
#include "mscommon.h"
 
24
#include "msqueue.h"
 
25
#include "allfilters.h"
 
26
 
 
27
typedef void (*MSFilterFunc)(struct _MSFilter *f);
 
28
typedef int (*MSFilterMethodFunc)(struct _MSFilter *f, void *arg);
 
29
typedef void (*MSFilterNotifyFunc)(void *userdata , unsigned int id, void *arg);
 
30
 
 
31
struct _MSFilterMethod{
 
32
        int id;
 
33
        MSFilterMethodFunc method;
 
34
};
 
35
 
 
36
typedef struct _MSFilterMethod MSFilterMethod;
 
37
 
 
38
enum _MSFilterCategory{
 
39
        MS_FILTER_OTHER,
 
40
        MS_FILTER_ENCODER,
 
41
        MS_FILTER_DECODER
 
42
};
 
43
 
 
44
typedef enum _MSFilterCategory MSFilterCategory;
 
45
 
 
46
struct _MSFilterDesc{
 
47
        MSFilterId id;  /* the id declared in allfilters.h */
 
48
        const char *name; /* filter name */
 
49
        const char *text; /*some descriptive text*/
 
50
        MSFilterCategory category;
 
51
        const char *enc_fmt; /* must be set if MS_FILTER_ENCODER/MS_FILTER_DECODER */
 
52
        int ninputs; /*number of inputs */
 
53
        int noutputs; /*number of outputs */
 
54
        MSFilterFunc init;
 
55
        MSFilterFunc preprocess;        /* called once before processing */
 
56
        MSFilterFunc process;           /* called every tick to do the filter's job*/
 
57
        MSFilterFunc postprocess;       /*called once after processing */
 
58
        MSFilterFunc uninit;
 
59
        MSFilterMethod *methods;
 
60
};
 
61
 
 
62
typedef struct _MSFilterDesc MSFilterDesc;
 
63
 
 
64
struct _MSFilter{
 
65
        MSFilterDesc *desc;
 
66
        /*protected attributes */
 
67
        ms_mutex_t lock;
 
68
        MSQueue **inputs;
 
69
        MSQueue **outputs;
 
70
        MSFilterNotifyFunc notify;
 
71
        void *notify_ud;
 
72
        void *data;
 
73
        struct _MSTicker *ticker;
 
74
        /*private attributes */
 
75
        uint32_t last_tick;
 
76
        bool_t seen;
 
77
};
 
78
 
 
79
typedef struct _MSFilter MSFilter;
 
80
 
 
81
#ifdef __cplusplus
 
82
extern "C"{
 
83
#endif
 
84
 
 
85
/* useful for plugins only */
 
86
void ms_filter_register(MSFilterDesc *desc);
 
87
/* functions to retrieve encoders/decoders according to codec name */
 
88
MSFilterDesc * ms_filter_get_encoder(const char *mime);
 
89
MSFilterDesc * ms_filter_get_decoder(const char *mime);
 
90
MSFilter * ms_filter_create_encoder(const char *mime);
 
91
MSFilter * ms_filter_create_decoder(const char *mime);
 
92
bool_t ms_filter_codec_supported(const char *mime);
 
93
 
 
94
MSFilter *ms_filter_new(MSFilterId id);
 
95
MSFilter *ms_filter_new_from_name(const char *name);
 
96
int ms_filter_link(MSFilter *f1, int pin1, MSFilter *f2, int pin2);
 
97
int ms_filter_unlink(MSFilter *f1, int pin1, MSFilter *f2, int pin2);
 
98
int ms_filter_call_method(MSFilter *f, unsigned int id, void *arg);
 
99
int ms_filter_call_method_noarg(MSFilter *f, unsigned int id);
 
100
void ms_filter_set_notify_callback(MSFilter *f, MSFilterNotifyFunc fn, void *userdata);
 
101
MSFilterId ms_filter_get_id(MSFilter *f);
 
102
void ms_filter_destroy(MSFilter *f);
 
103
 
 
104
#ifdef __cplusplus
 
105
}
 
106
#endif
 
107
 
 
108
/* I define the id taking the lower bits of the address of the MSFilterDesc object,
 
109
the method index (_cnt_) and the argument size */
 
110
/* I hope using this to avoid type mismatch (calling a method on the wrong filter)*/
 
111
#define MS_FILTER_METHOD_ID(_id_,_cnt_,_argsize_) \
 
112
        (  (((unsigned long)(_id_)) & 0xFFFF)<<16 | (_cnt_<<8) | (_argsize_ & 0xFF ))
 
113
 
 
114
#define MS_FILTER_METHOD(_id_,_count_,_argtype_) \
 
115
        MS_FILTER_METHOD_ID(_id_,_count_,sizeof(_argtype_))
 
116
 
 
117
#define MS_FILTER_METHOD_NO_ARG(_id_,_count_) \
 
118
        MS_FILTER_METHOD_ID(_id_,_count_,0)
 
119
 
 
120
 
 
121
#define MS_FILTER_BASE_METHOD(_count_,_argtype_) \
 
122
        MS_FILTER_METHOD_ID(MS_FILTER_BASE_ID,_count_,sizeof(_argtype_))
 
123
 
 
124
#define MS_FILTER_EVENT(_id_,_count_,_argtype_) \
 
125
        MS_FILTER_METHOD_ID(_id_,_count_,sizeof(_argtype_))
 
126
 
 
127
#define MS_FILTER_EVENT_NO_ARG(_id_,_count_)\
 
128
        MS_FILTER_METHOD_ID(_id_,_count_,0)
 
129
 
 
130
/* some MSFilter base methods:*/
 
131
#define MS_FILTER_SET_SAMPLE_RATE       MS_FILTER_BASE_METHOD(0,int)
 
132
#define MS_FILTER_GET_SAMPLE_RATE       MS_FILTER_BASE_METHOD(1,int)
 
133
#define MS_FILTER_SET_BITRATE           MS_FILTER_BASE_METHOD(2,int)
 
134
#define MS_FILTER_GET_BITRATE           MS_FILTER_BASE_METHOD(3,int)
 
135
#define MS_FILTER_SET_FMTP              MS_FILTER_BASE_METHOD(4,const char)
 
136
#define MS_FILTER_GET_NCHANNELS         MS_FILTER_BASE_METHOD(5,int)
 
137
#define MS_FILTER_SET_NCHANNELS         MS_FILTER_BASE_METHOD(6,int)
 
138
#define MS_FILTER_ADD_FMTP              MS_FILTER_BASE_METHOD(7,const char)
 
139
#define MS_FILTER_ADD_ATTR              MS_FILTER_BASE_METHOD(8,const char)
 
140
#define MS_FILTER_SET_MTU               MS_FILTER_BASE_METHOD(9,int)
 
141
#define MS_FILTER_GET_MTU               MS_FILTER_BASE_METHOD(10,int)
 
142
 
 
143
 
 
144
/*private methods*/
 
145
MSFilter *ms_filter_new_from_desc(MSFilterDesc *desc);
 
146
void ms_filter_process(MSFilter *f);
 
147
void ms_filter_preprocess(MSFilter *f, struct _MSTicker *t);
 
148
void ms_filter_postprocess(MSFilter *f);
 
149
bool_t ms_filter_inputs_have_data(MSFilter *f);
 
150
void ms_filter_notify(MSFilter *f, unsigned int id, void *arg);
 
151
void ms_filter_notify_no_arg(MSFilter *f, unsigned int id);
 
152
#define ms_filter_lock(f)       ms_mutex_lock(&(f)->lock)
 
153
#define ms_filter_unlock(f)     ms_mutex_unlock(&(f)->lock)
 
154
void ms_filter_unregister_all(void);
 
155
 
 
156
/* used by awk script in Makefile.am to generate alldescs.c */
 
157
#define MS_FILTER_DESC_EXPORT(desc)
 
158
 
 
159
#endif