Mercurial > mplayer.hg
comparison libaf/af_export.c @ 29263:0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
author | diego |
---|---|
date | Wed, 13 May 2009 02:58:57 +0000 |
parents | 8c706ce21c6f |
children | 76a13038105e |
comparison
equal
deleted
inserted
replaced
29262:7d545a6b8aff | 29263:0f1b5b68af32 |
---|---|
39 | 39 |
40 #include "af.h" | 40 #include "af.h" |
41 #include "get_path.h" | 41 #include "get_path.h" |
42 | 42 |
43 #define DEF_SZ 512 // default buffer size (in samples) | 43 #define DEF_SZ 512 // default buffer size (in samples) |
44 #define SHARED_FILE "mplayer-af_export" /* default file name | 44 #define SHARED_FILE "mplayer-af_export" /* default file name |
45 (relative to ~/.mplayer/ */ | 45 (relative to ~/.mplayer/ */ |
46 | 46 |
47 #define SIZE_HEADER (2 * sizeof(int) + sizeof(unsigned long long)) | 47 #define SIZE_HEADER (2 * sizeof(int) + sizeof(unsigned long long)) |
48 | 48 |
49 // Data for specific instances of this filter | 49 // Data for specific instances of this filter |
79 // unmap previous area | 79 // unmap previous area |
80 if(s->mmap_area) | 80 if(s->mmap_area) |
81 munmap(s->mmap_area, SIZE_HEADER + (af->data->bps*s->sz*af->data->nch)); | 81 munmap(s->mmap_area, SIZE_HEADER + (af->data->bps*s->sz*af->data->nch)); |
82 // close previous file descriptor | 82 // close previous file descriptor |
83 if(s->fd) | 83 if(s->fd) |
84 close(s->fd); | 84 close(s->fd); |
85 | 85 |
86 // Accept only int16_t as input format (which sucks) | 86 // Accept only int16_t as input format (which sucks) |
87 af->data->rate = ((af_data_t*)arg)->rate; | 87 af->data->rate = ((af_data_t*)arg)->rate; |
88 af->data->nch = ((af_data_t*)arg)->nch; | 88 af->data->nch = ((af_data_t*)arg)->nch; |
89 af->data->format = AF_FORMAT_S16_NE; | 89 af->data->format = AF_FORMAT_S16_NE; |
90 af->data->bps = 2; | 90 af->data->bps = 2; |
91 | 91 |
92 // If buffer length isn't set, set it to the default value | 92 // If buffer length isn't set, set it to the default value |
93 if(s->sz == 0) | 93 if(s->sz == 0) |
94 s->sz = DEF_SZ; | 94 s->sz = DEF_SZ; |
95 | 95 |
96 // Allocate new buffers (as one continuous block) | 96 // Allocate new buffers (as one continuous block) |
97 s->buf[0] = calloc(s->sz*af->data->nch, af->data->bps); | 97 s->buf[0] = calloc(s->sz*af->data->nch, af->data->bps); |
98 if(NULL == s->buf[0]) | 98 if(NULL == s->buf[0]) |
99 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Out of memory\n"); | 99 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Out of memory\n"); |
100 for(i = 1; i < af->data->nch; i++) | 100 for(i = 1; i < af->data->nch; i++) |
101 s->buf[i] = s->buf[0] + i*s->sz*af->data->bps; | 101 s->buf[i] = s->buf[0] + i*s->sz*af->data->bps; |
102 | 102 |
103 // Init memory mapping | 103 // Init memory mapping |
104 s->fd = open(s->filename, O_RDWR | O_CREAT | O_TRUNC, 0640); | 104 s->fd = open(s->filename, O_RDWR | O_CREAT | O_TRUNC, 0640); |
105 mp_msg(MSGT_AFILTER, MSGL_INFO, "[export] Exporting to file: %s\n", s->filename); | 105 mp_msg(MSGT_AFILTER, MSGL_INFO, "[export] Exporting to file: %s\n", s->filename); |
106 if(s->fd < 0) | 106 if(s->fd < 0) |
107 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Could not open/create file: %s\n", | 107 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Could not open/create file: %s\n", |
108 s->filename); | 108 s->filename); |
109 | 109 |
110 // header + buffer | 110 // header + buffer |
111 mapsize = (SIZE_HEADER + (af->data->bps * s->sz * af->data->nch)); | 111 mapsize = (SIZE_HEADER + (af->data->bps * s->sz * af->data->nch)); |
112 | 112 |
113 // grow file to needed size | 113 // grow file to needed size |
114 for(i = 0; i < mapsize; i++){ | 114 for(i = 0; i < mapsize; i++){ |
115 char null = 0; | 115 char null = 0; |
116 write(s->fd, (void*) &null, 1); | 116 write(s->fd, (void*) &null, 1); |
117 } | 117 } |
118 | 118 |
119 // mmap size | 119 // mmap size |
120 s->mmap_area = mmap(0, mapsize, PROT_READ|PROT_WRITE,MAP_SHARED, s->fd, 0); | 120 s->mmap_area = mmap(0, mapsize, PROT_READ|PROT_WRITE,MAP_SHARED, s->fd, 0); |
121 if(s->mmap_area == NULL) | 121 if(s->mmap_area == NULL) |
122 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Could not mmap file %s\n", s->filename); | 122 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Could not mmap file %s\n", s->filename); |
123 mp_msg(MSGT_AFILTER, MSGL_INFO, "[export] Memory mapped to file: %s (%p)\n", | 123 mp_msg(MSGT_AFILTER, MSGL_INFO, "[export] Memory mapped to file: %s (%p)\n", |
124 s->filename, s->mmap_area); | 124 s->filename, s->mmap_area); |
125 | 125 |
126 // Initialize header | 126 // Initialize header |
127 *((int*)s->mmap_area) = af->data->nch; | 127 *((int*)s->mmap_area) = af->data->nch; |
128 *((int*)s->mmap_area + 1) = s->sz * af->data->bps * af->data->nch; | 128 *((int*)s->mmap_area + 1) = s->sz * af->data->bps * af->data->nch; |
132 return af_test_output(af, (af_data_t*)arg); | 132 return af_test_output(af, (af_data_t*)arg); |
133 } | 133 } |
134 case AF_CONTROL_COMMAND_LINE:{ | 134 case AF_CONTROL_COMMAND_LINE:{ |
135 int i=0; | 135 int i=0; |
136 char *str = arg; | 136 char *str = arg; |
137 | 137 |
138 if (!str){ | 138 if (!str){ |
139 if(s->filename) | 139 if(s->filename) |
140 free(s->filename); | 140 free(s->filename); |
141 | 141 |
142 s->filename = get_path(SHARED_FILE); | 142 s->filename = get_path(SHARED_FILE); |
143 return AF_OK; | 143 return AF_OK; |
144 } | 144 } |
145 | 145 |
146 while((str[i]) && (str[i] != ':')) | 146 while((str[i]) && (str[i] != ':')) |
147 i++; | 147 i++; |
148 | 148 |
149 if(s->filename) | 149 if(s->filename) |
150 free(s->filename); | 150 free(s->filename); |
151 | 151 |
152 s->filename = calloc(i + 1, 1); | 152 s->filename = calloc(i + 1, 1); |
153 memcpy(s->filename, str, i); | 153 memcpy(s->filename, str, i); |
154 s->filename[i] = 0; | 154 s->filename[i] = 0; |
155 | 155 |
156 sscanf(str + i + 1, "%d", &(s->sz)); | 156 sscanf(str + i + 1, "%d", &(s->sz)); |
157 | 157 |
158 return af->control(af, AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET, &s->sz); | 158 return af->control(af, AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET, &s->sz); |
159 } | 159 } |
160 case AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET: | 160 case AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET: |
161 s->sz = * (int *) arg; | 161 s->sz = * (int *) arg; |
162 if((s->sz <= 0) || (s->sz > 2048)) | 162 if((s->sz <= 0) || (s->sz > 2048)) |
165 | 165 |
166 return AF_OK; | 166 return AF_OK; |
167 case AF_CONTROL_EXPORT_SZ | AF_CONTROL_GET: | 167 case AF_CONTROL_EXPORT_SZ | AF_CONTROL_GET: |
168 *(int*) arg = s->sz; | 168 *(int*) arg = s->sz; |
169 return AF_OK; | 169 return AF_OK; |
170 | 170 |
171 } | 171 } |
172 return AF_UNKNOWN; | 172 return AF_UNKNOWN; |
173 } | 173 } |
174 | 174 |
175 /* Free allocated memory and clean up other stuff too. | 175 /* Free allocated memory and clean up other stuff too. |
184 | 184 |
185 if(af->setup){ | 185 if(af->setup){ |
186 af_export_t* s = af->setup; | 186 af_export_t* s = af->setup; |
187 if (s->buf && s->buf[0]) | 187 if (s->buf && s->buf[0]) |
188 free(s->buf[0]); | 188 free(s->buf[0]); |
189 | 189 |
190 // Free mmaped area | 190 // Free mmaped area |
191 if(s->mmap_area) | 191 if(s->mmap_area) |
192 munmap(s->mmap_area, sizeof(af_export_t)); | 192 munmap(s->mmap_area, sizeof(af_export_t)); |
193 | 193 |
194 if(s->fd > -1) | 194 if(s->fd > -1) |
195 close(s->fd); | 195 close(s->fd); |
196 | 196 |
197 if(s->filename) | 197 if(s->filename) |
213 int16_t* a = c->audio; // Incomming sound | 213 int16_t* a = c->audio; // Incomming sound |
214 int nch = c->nch; // Number of channels | 214 int nch = c->nch; // Number of channels |
215 int len = c->len/c->bps; // Number of sample in data chunk | 215 int len = c->len/c->bps; // Number of sample in data chunk |
216 int sz = s->sz; // buffer size (in samples) | 216 int sz = s->sz; // buffer size (in samples) |
217 int flag = 0; // Set to 1 if buffer is filled | 217 int flag = 0; // Set to 1 if buffer is filled |
218 | 218 |
219 int ch, i; | 219 int ch, i; |
220 | 220 |
221 // Fill all buffers | 221 // Fill all buffers |
222 for(ch = 0; ch < nch; ch++){ | 222 for(ch = 0; ch < nch; ch++){ |
223 int wi = s->wi; // Reset write index | 223 int wi = s->wi; // Reset write index |
224 int16_t* b = s->buf[ch]; // Current buffer | 224 int16_t* b = s->buf[ch]; // Current buffer |
225 | 225 |
226 // Copy data to export buffers | 226 // Copy data to export buffers |
227 for(i = ch; i < len; i += nch){ | 227 for(i = ch; i < len; i += nch){ |
228 b[wi++] = a[i]; | 228 b[wi++] = a[i]; |
229 if(wi >= sz){ // Don't write outside the end of the buffer | 229 if(wi >= sz){ // Don't write outside the end of the buffer |
230 flag = 1; | 230 flag = 1; |
231 break; | 231 break; |
237 // Export buffer to mmaped area | 237 // Export buffer to mmaped area |
238 if(flag){ | 238 if(flag){ |
239 // update buffer in mapped area | 239 // update buffer in mapped area |
240 memcpy(s->mmap_area + SIZE_HEADER, s->buf[0], sz * c->bps * nch); | 240 memcpy(s->mmap_area + SIZE_HEADER, s->buf[0], sz * c->bps * nch); |
241 s->count++; // increment counter (to sync) | 241 s->count++; // increment counter (to sync) |
242 memcpy(s->mmap_area + SIZE_HEADER - sizeof(s->count), | 242 memcpy(s->mmap_area + SIZE_HEADER - sizeof(s->count), |
243 &(s->count), sizeof(s->count)); | 243 &(s->count), sizeof(s->count)); |
244 } | 244 } |
245 | 245 |
246 // We don't modify data, just export it | 246 // We don't modify data, just export it |
247 return data; | 247 return data; |
248 } | 248 } |
249 | 249 |
250 /* Allocate memory and set function pointers | 250 /* Allocate memory and set function pointers |
251 af audio filter instance | 251 af audio filter instance |
252 returns AF_OK or AF_ERROR | 252 returns AF_OK or AF_ERROR |
253 */ | 253 */ |
254 static int af_open( af_instance_t* af ) | 254 static int af_open( af_instance_t* af ) |
255 { | 255 { |
256 af->control = control; | 256 af->control = control; |