comparison libaf/af.c @ 7615:c67328dd459a

Adding Support for non-reentrant audio filters
author anders
date Sun, 06 Oct 2002 11:26:14 +0000
parents bf7f2bd2eb24
children faa7dad7b4b1
comparison
equal deleted inserted replaced
7614:ce6a938aa6d3 7615:c67328dd459a
39 } 39 }
40 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't find audio filter '%s'\n",name); 40 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't find audio filter '%s'\n",name);
41 return NULL; 41 return NULL;
42 } 42 }
43 43
44 /* Find filter in the dynamic filter list using it's name This
45 function is used for finding already initialized filters */
46 af_instance_t* af_get(af_stream_t* s, char* name)
47 {
48 af_instance_t* af=s->first;
49 // Find the filter
50 while(af != NULL){
51 printf("%s\n",af->info->name);
52 if(!strcmp(af->info->name,name))
53 return af;
54 af=af->next;
55 }
56 return NULL;
57 }
58
44 // Function for creating a new filter of type name 59 // Function for creating a new filter of type name
45 af_instance_t* af_create(char* name) 60 af_instance_t* af_create(af_stream_t* s, char* name)
46 { 61 {
47 // Allocate space for the new filter and reset all pointers 62 // Allocate space for the new filter and reset all pointers
48 af_instance_t* new=malloc(sizeof(af_instance_t)); 63 af_instance_t* new=malloc(sizeof(af_instance_t));
49 if(!new){ 64 if(!new){
50 mp_msg(MSGT_AFILTER,MSGL_ERR,"Could not allocate memory\n"); 65 mp_msg(MSGT_AFILTER,MSGL_ERR,"Could not allocate memory\n");
51 return NULL; 66 return NULL;
52 } 67 }
53 memset(new,0,sizeof(af_instance_t)); 68 memset(new,0,sizeof(af_instance_t));
54 69
55 // Find filter from name 70 // Find filter from name
56 new->info=af_find(name); 71 if(NULL == (new->info=af_find(name)))
57 72 return NULL;
73
74 // Make sure that the filter is not already in the list if it is non-reentrant
75 if(new->info->flags & AF_FLAGS_NOT_REENTRANT){
76 if(af_get(s,name)){
77 mp_msg(MSGT_AFILTER,MSGL_ERR,"There can only be one instance of the filter '%s' in each stream\n",name);
78 free(new);
79 return NULL;
80 }
81 }
82
58 // Initialize the new filter 83 // Initialize the new filter
59 if(new->info && (AF_OK==new->info->open(new))) 84 if(AF_OK==new->info->open(new))
60 return new; 85 return new;
61 86
62 free(new); 87 free(new);
63 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't create audio filter '%s'\n",name); 88 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't create audio filter '%s'\n",name);
64 return NULL; 89 return NULL;
68 argument. This function can be called during runtime, the return 93 argument. This function can be called during runtime, the return
69 value is the new filter */ 94 value is the new filter */
70 af_instance_t* af_prepend(af_stream_t* s, af_instance_t* af, char* name) 95 af_instance_t* af_prepend(af_stream_t* s, af_instance_t* af, char* name)
71 { 96 {
72 // Create the new filter and make sure it is OK 97 // Create the new filter and make sure it is OK
73 af_instance_t* new=af_create(name); 98 af_instance_t* new=af_create(s,name);
74 if(!new) 99 if(!new)
75 return NULL; 100 return NULL;
76 // Update pointers 101 // Update pointers
77 new->next=af; 102 new->next=af;
78 if(af){ 103 if(af){
92 argument. This function can be called during runtime, the return 117 argument. This function can be called during runtime, the return
93 value is the new filter */ 118 value is the new filter */
94 af_instance_t* af_append(af_stream_t* s, af_instance_t* af, char* name) 119 af_instance_t* af_append(af_stream_t* s, af_instance_t* af, char* name)
95 { 120 {
96 // Create the new filter and make sure it is OK 121 // Create the new filter and make sure it is OK
97 af_instance_t* new=af_create(name); 122 af_instance_t* new=af_create(s,name);
98 if(!new) 123 if(!new)
99 return NULL; 124 return NULL;
100 // Update pointers 125 // Update pointers
101 new->prev=af; 126 new->prev=af;
102 if(af){ 127 if(af){
211 af=af->next; 236 af=af->next;
212 }while(af); 237 }while(af);
213 return AF_OK; 238 return AF_OK;
214 } 239 }
215 240
216 /* Find filter in the dynamic filter list using it's name This
217 function is used for finding already initialized filters */
218 af_instance_t* af_get(af_stream_t* s, char* name)
219 {
220 af_instance_t* af=s->first;
221 while(af->next != NULL){
222 if(!strcmp(af->info->name,name))
223 return af;
224 af=af->next;
225 }
226 return NULL;
227 }
228
229 // Uninit and remove all filters 241 // Uninit and remove all filters
230 void af_uninit(af_stream_t* s) 242 void af_uninit(af_stream_t* s)
231 { 243 {
232 while(s->first) 244 while(s->first)
233 af_remove(s,s->first); 245 af_remove(s,s->first);