Mercurial > mplayer.hg
annotate libaf/af.h @ 8045:c34100c609ee
10l
author | michael |
---|---|
date | Sat, 02 Nov 2002 16:55:23 +0000 |
parents | 1d3a3dc1f488 |
children | c0e556f9986b |
rev | line source |
---|---|
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
1 #include "control.h" |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
2 |
7568 | 3 #ifndef __aop_h__ |
4 #define __aop_h__ | |
5 | |
6 struct af_instance_s; | |
7 | |
8 // Audio data chunk | |
9 typedef struct af_data_s | |
10 { | |
11 void* audio; // data buffer | |
12 int len; // buffer length | |
13 int rate; // sample rate | |
14 int nch; // number of channels | |
15 int format; // format | |
16 int bps; // bytes per sample | |
17 } af_data_t; | |
18 | |
19 // Fraction, used to calculate buffer lengths | |
20 typedef struct frac_s | |
21 { | |
22 int n; // Numerator | |
23 int d; // Denominator | |
24 } frac_t; | |
25 | |
7615 | 26 // Flags used for defining the behavour of an audio filter |
27 #define AF_FLAGS_REENTRANT 0x00000000 | |
28 #define AF_FLAGS_NOT_REENTRANT 0x00000001 | |
29 | |
7568 | 30 /* Audio filter information not specific for current instance, but for |
31 a specific filter */ | |
32 typedef struct af_info_s | |
33 { | |
34 const char *info; | |
35 const char *name; | |
36 const char *author; | |
37 const char *comment; | |
7615 | 38 const int flags; |
7568 | 39 int (*open)(struct af_instance_s* vf); |
40 } af_info_t; | |
41 | |
42 // Linked list of audio filters | |
43 typedef struct af_instance_s | |
44 { | |
45 af_info_t* info; | |
46 int (*control)(struct af_instance_s* af, int cmd, void* arg); | |
47 void (*uninit)(struct af_instance_s* af); | |
48 af_data_t* (*play)(struct af_instance_s* af, af_data_t* data); | |
49 void* setup; // setup data for this specific instance and filter | |
50 af_data_t* data; // configuration for outgoing data stream | |
51 struct af_instance_s* next; | |
52 struct af_instance_s* prev; | |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
53 double delay; // Delay caused by the filter [ms] |
7568 | 54 frac_t mul; /* length multiplier: how much does this instance change |
55 the length of the buffer. */ | |
56 }af_instance_t; | |
57 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
58 // Initialization flags |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
59 #define AF_INIT_AUTO 0x00000000 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
60 #define AF_INIT_SLOW 0x00000001 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
61 #define AF_INIT_FAST 0x00000002 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
62 #define AF_INIT_FORCE 0x00000003 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
63 #define AF_INIT_TYPE_MASK 0x00000003 |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
64 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
65 // Configuration switches |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
66 typedef struct af_cfg_s{ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
67 int force; // Initialization type |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
68 char** list; /* list of names of plugins that are added to filter |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
69 list during first initialization of stream */ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
70 }af_cfg_t; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
71 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
72 // Current audio stream |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
73 typedef struct af_stream_s |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
74 { |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
75 // The first and last filter in the list |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
76 af_instance_t* first; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
77 af_instance_t* last; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
78 // Storage for input and output data formats |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
79 af_data_t input; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
80 af_data_t output; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
81 // Cofiguration for this stream |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
82 af_cfg_t cfg; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
83 }af_stream_t; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
84 |
7568 | 85 /********************************************* |
86 // Return values | |
87 */ | |
88 | |
89 #define AF_DETACH 2 | |
90 #define AF_OK 1 | |
91 #define AF_TRUE 1 | |
92 #define AF_FALSE 0 | |
93 #define AF_UNKNOWN -1 | |
94 #define AF_ERROR -2 | |
95 #define AF_NA -3 | |
96 | |
97 | |
98 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
99 /********************************************* |
7568 | 100 // Export functions |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
101 */ |
7568 | 102 |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
103 /* Initialize the stream "s". This function creates a new fileterlist |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
104 if nessesary according to the values set in input and output. Input |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
105 and output should contain the format of the current movie and the |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
106 formate of the preferred output respectively. The function is |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
107 reentreant i.e. if called wit an already initialized stream the |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
108 stream will be reinitialized. The return value is 0 if sucess and |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
109 -1 if failure */ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
110 int af_init(af_stream_t* s); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
111 |
7568 | 112 // Uninit and remove all filters |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
113 void af_uninit(af_stream_t* s); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
114 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
115 /* Add filter during execution. This function adds the filter "name" |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
116 to the stream s. The filter will be inserted somewhere nice in the |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
117 list of filters. The return value is a pointer to the new filter, |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
118 If the filter couldn't be added the return value is NULL. */ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
119 af_instance_t* af_add(af_stream_t* s, char* name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
120 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
121 // Uninit and remove the filter "af" |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
122 void af_remove(af_stream_t* s, af_instance_t* af); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
123 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
124 /* Find filter in the dynamic filter list using it's name This |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
125 function is used for finding already initialized filters */ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
126 af_instance_t* af_get(af_stream_t* s, char* name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
127 |
7568 | 128 // Filter data chunk through the filters in the list |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
129 af_data_t* af_play(af_stream_t* s, af_data_t* data); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
130 |
7568 | 131 /* Calculate how long the output from the filters will be given the |
7589 | 132 input length "len". The calculated length is >= the actual |
133 length */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
134 int af_outputlen(af_stream_t* s, int len); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
135 |
7568 | 136 /* Calculate how long the input to the filters should be to produce a |
137 certain output length, i.e. the return value of this function is | |
7589 | 138 the input length required to produce the output length "len". The |
139 calculated length is <= the actual length */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
140 int af_inputlen(af_stream_t* s, int len); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
141 |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
142 /* Calculate how long the input IN to the filters should be to produce |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
143 a certain output length OUT but with the following three constraints: |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
144 1. IN <= max_insize, where max_insize is the maximum possible input |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
145 block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
146 2. OUT <= max_outsize, where max_outsize is the maximum possible |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
147 output block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
148 3. If possible OUT >= len. |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
149 Return -1 in case of error */ |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
150 int af_calc_insize_constrained(af_stream_t* s, int len, |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
151 int max_outsize,int max_insize); |
7568 | 152 |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
153 /* Calculate the total delay caused by the filters */ |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
154 double af_calc_delay(af_stream_t* s); |
7568 | 155 |
156 // Helper functions and macros used inside the audio filters | |
157 | |
158 /* Helper function called by the macro with the same name only to be | |
159 called from inside filters */ | |
160 int af_resize_local_buffer(af_instance_t* af, af_data_t* data); | |
161 | |
162 /* Helper function used to calculate the exact buffer length needed | |
7589 | 163 when buffers are resized. The returned length is >= than what is |
164 needed */ | |
165 int af_lencalc(frac_t mul, af_data_t* data); | |
7568 | 166 |
167 /* Memory reallocation macro: if a local buffer is used (i.e. if the | |
168 filter doesn't operate on the incoming buffer this macro must be | |
169 called to ensure the buffer is big enough. */ | |
170 #define RESIZE_LOCAL_BUFFER(a,d)\ | |
7591 | 171 ((a->data->len < af_lencalc(a->mul,d))?af_resize_local_buffer(a,d):AF_OK) |
7568 | 172 |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
173 /* Some other useful macro definitions*/ |
7568 | 174 #ifndef min |
175 #define min(a,b)(((a)>(b))?(b):(a)) | |
176 #endif | |
177 | |
178 #ifndef max | |
179 #define max(a,b)(((a)>(b))?(a):(b)) | |
180 #endif | |
181 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
182 #ifndef clamp |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
183 #define clamp(a,min,max) (((a)>(max))?(max):(((a)<(min))?(min):(a))) |
7568 | 184 #endif |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
185 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
186 #ifndef sign |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
187 #define sign(a) (((x)>0)?(1):(-1)) |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
188 #endif |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
189 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
190 #endif |