Mercurial > mplayer.hg
annotate libaf/af_export.c @ 37078:7471626e943e
Relocate add_vf().
Additionally, add doxygen comment.
author | ib |
---|---|
date | Thu, 24 Apr 2014 13:31:52 +0000 |
parents | 9ffbffc4216c |
children |
rev | line source |
---|---|
28229
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
1 /* |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
2 * This audio filter exports the incoming signal to other processes |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
3 * using memory mapping. The memory mapped area contains a header: |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
4 * int nch, |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
5 * int size, |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
6 * unsigned long long counter (updated every time the contents of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
7 * the area changes), |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
8 * the rest is payload (non-interleaved). |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
9 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
10 * This file is part of MPlayer. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
11 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
12 * MPlayer is free software; you can redistribute it and/or modify |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
13 * it under the terms of the GNU General Public License as published by |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
14 * the Free Software Foundation; either version 2 of the License, or |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
15 * (at your option) any later version. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
16 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
17 * MPlayer is distributed in the hope that it will be useful, |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
20 * GNU General Public License for more details. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
21 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
22 * You should have received a copy of the GNU General Public License along |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
23 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
26181
diff
changeset
|
25 */ |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
26 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
27 #include <stdio.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
28 #include <stdlib.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
29 #include <string.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
30 #include <inttypes.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
31 #include <unistd.h> |
16982 | 32 #include "config.h" |
10908 | 33 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
34 #include <sys/types.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
35 #include <sys/mman.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
36 #include <sys/types.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
37 #include <sys/stat.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
38 #include <fcntl.h> |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
39 |
34174
a93891202051
Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents:
32537
diff
changeset
|
40 #include "mp_msg.h" |
a93891202051
Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents:
32537
diff
changeset
|
41 #include "path.h" |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
42 #include "af.h" |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
43 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
44 #define DEF_SZ 512 // default buffer size (in samples) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
45 #define SHARED_FILE "mplayer-af_export" /* default file name |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
46 (relative to ~/.mplayer/ */ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
47 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
48 #define SIZE_HEADER (2 * sizeof(int) + sizeof(unsigned long long)) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
49 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
50 // Data for specific instances of this filter |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
51 typedef struct af_export_s |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
52 { |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
53 unsigned long long count; // Used for sync |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
54 void* buf[AF_NCH]; // Buffers for storing the data before it is exported |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
55 int sz; // Size of buffer in samples |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
56 int wi; // Write index |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
57 int fd; // File descriptor to shared memory area |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
58 char* filename; // File to export data |
31542 | 59 uint8_t *mmap_area; // MMap shared area |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
60 } af_export_t; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
61 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
62 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
63 /* Initialization and runtime control |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
64 af audio filter instance |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
65 cmd control command |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
66 arg argument |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
67 */ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
68 static int control(struct af_instance_s* af, int cmd, void* arg) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
69 { |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
70 af_export_t* s = af->setup; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
71 switch (cmd){ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
72 case AF_CONTROL_REINIT:{ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
73 int i=0; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
74 int mapsize; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
75 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
76 // Free previous buffers |
35567 | 77 free(s->buf[0]); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
78 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
79 // unmap previous area |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
80 if(s->mmap_area) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
81 munmap(s->mmap_area, SIZE_HEADER + (af->data->bps*s->sz*af->data->nch)); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
82 // close previous file descriptor |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
83 if(s->fd) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
84 close(s->fd); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
85 |
11529 | 86 // Accept only int16_t as input format (which sucks) |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
87 af->data->rate = ((af_data_t*)arg)->rate; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
88 af->data->nch = ((af_data_t*)arg)->nch; |
14245 | 89 af->data->format = AF_FORMAT_S16_NE; |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
90 af->data->bps = 2; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
91 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
92 // If buffer length isn't set, set it to the default value |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
93 if(s->sz == 0) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
94 s->sz = DEF_SZ; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
95 |
11529 | 96 // Allocate new buffers (as one continuous block) |
97 s->buf[0] = calloc(s->sz*af->data->nch, af->data->bps); | |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
98 if(NULL == s->buf[0]) |
29049 | 99 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Out of memory\n"); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
100 for(i = 1; i < af->data->nch; i++) |
31542 | 101 s->buf[i] = (uint8_t *)s->buf[0] + i*s->sz*af->data->bps; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
102 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
103 // Init memory mapping |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
104 s->fd = open(s->filename, O_RDWR | O_CREAT | O_TRUNC, 0640); |
29049 | 105 mp_msg(MSGT_AFILTER, MSGL_INFO, "[export] Exporting to file: %s\n", s->filename); |
35310
7077d1aed027
Abort when opening the file failed instead of calling
reimar
parents:
34174
diff
changeset
|
106 if(s->fd < 0) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
107 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Could not open/create file: %s\n", |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
108 s->filename); |
35310
7077d1aed027
Abort when opening the file failed instead of calling
reimar
parents:
34174
diff
changeset
|
109 return AF_ERROR; |
7077d1aed027
Abort when opening the file failed instead of calling
reimar
parents:
34174
diff
changeset
|
110 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
111 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
112 // header + buffer |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
113 mapsize = (SIZE_HEADER + (af->data->bps * s->sz * af->data->nch)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
114 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
115 // grow file to needed size |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
116 for(i = 0; i < mapsize; i++){ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
117 char null = 0; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
118 write(s->fd, (void*) &null, 1); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
119 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
120 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
121 // mmap size |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
122 s->mmap_area = mmap(0, mapsize, PROT_READ|PROT_WRITE,MAP_SHARED, s->fd, 0); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
123 if(s->mmap_area == NULL) |
29049 | 124 mp_msg(MSGT_AFILTER, MSGL_FATAL, "[export] Could not mmap file %s\n", s->filename); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
125 mp_msg(MSGT_AFILTER, MSGL_INFO, "[export] Memory mapped to file: %s (%p)\n", |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
126 s->filename, s->mmap_area); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
127 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
128 // Initialize header |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
129 *((int*)s->mmap_area) = af->data->nch; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
130 *((int*)s->mmap_area + 1) = s->sz * af->data->bps * af->data->nch; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
131 msync(s->mmap_area, mapsize, MS_ASYNC); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
132 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
133 // Use test_output to return FALSE if necessary |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
134 return af_test_output(af, (af_data_t*)arg); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
135 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
136 case AF_CONTROL_COMMAND_LINE:{ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
137 int i=0; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
138 char *str = arg; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
139 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
140 if (!str){ |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31542
diff
changeset
|
141 free(s->filename); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
142 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
143 s->filename = get_path(SHARED_FILE); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
144 return AF_OK; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
145 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
146 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
147 while((str[i]) && (str[i] != ':')) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
148 i++; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
149 |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31542
diff
changeset
|
150 free(s->filename); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
151 |
18858 | 152 s->filename = calloc(i + 1, 1); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
153 memcpy(s->filename, str, i); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
154 s->filename[i] = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
155 |
11529 | 156 sscanf(str + i + 1, "%d", &(s->sz)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
157 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
158 return af->control(af, AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET, &s->sz); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
159 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
160 case AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET: |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
161 s->sz = * (int *) arg; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
162 if((s->sz <= 0) || (s->sz > 2048)) |
29049 | 163 mp_msg(MSGT_AFILTER, MSGL_ERR, "[export] Buffer size must be between" |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
164 " 1 and 2048\n" ); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
165 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
166 return AF_OK; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
167 case AF_CONTROL_EXPORT_SZ | AF_CONTROL_GET: |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
168 *(int*) arg = s->sz; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
169 return AF_OK; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
170 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
171 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
172 return AF_UNKNOWN; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
173 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
174 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
175 /* Free allocated memory and clean up other stuff too. |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
176 af audio filter instance |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
177 */ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
178 static void uninit( struct af_instance_s* af ) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
179 { |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31542
diff
changeset
|
180 free(af->data); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31542
diff
changeset
|
181 af->data = NULL; |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
182 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
183 if(af->setup){ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
184 af_export_t* s = af->setup; |
35567 | 185 free(s->buf[0]); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
186 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
187 // Free mmaped area |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
188 if(s->mmap_area) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
189 munmap(s->mmap_area, sizeof(af_export_t)); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
190 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
191 if(s->fd > -1) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
192 close(s->fd); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
193 |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31542
diff
changeset
|
194 free(s->filename); |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
195 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
196 free(af->setup); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
197 af->setup = NULL; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
198 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
199 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
200 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
201 /* Filter data through filter |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
202 af audio filter instance |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
203 data audio data |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
204 */ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
205 static af_data_t* play( struct af_instance_s* af, af_data_t* data ) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
206 { |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
207 af_data_t* c = data; // Current working data |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
208 af_export_t* s = af->setup; // Setup for this instance |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
209 int16_t* a = c->audio; // Incomming sound |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
210 int nch = c->nch; // Number of channels |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
211 int len = c->len/c->bps; // Number of sample in data chunk |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
212 int sz = s->sz; // buffer size (in samples) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
213 int flag = 0; // Set to 1 if buffer is filled |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
214 |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
215 int ch, i; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
216 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
217 // Fill all buffers |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
218 for(ch = 0; ch < nch; ch++){ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
219 int wi = s->wi; // Reset write index |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
220 int16_t* b = s->buf[ch]; // Current buffer |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
221 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
222 // Copy data to export buffers |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
223 for(i = ch; i < len; i += nch){ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
224 b[wi++] = a[i]; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
225 if(wi >= sz){ // Don't write outside the end of the buffer |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
226 flag = 1; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
227 break; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
228 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
229 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
230 s->wi = wi % s->sz; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
231 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
232 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
233 // Export buffer to mmaped area |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
234 if(flag){ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
235 // update buffer in mapped area |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
236 memcpy(s->mmap_area + SIZE_HEADER, s->buf[0], sz * c->bps * nch); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
237 s->count++; // increment counter (to sync) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
238 memcpy(s->mmap_area + SIZE_HEADER - sizeof(s->count), |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
239 &(s->count), sizeof(s->count)); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
240 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
241 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
242 // We don't modify data, just export it |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
243 return data; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
244 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
245 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
246 /* Allocate memory and set function pointers |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
247 af audio filter instance |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
248 returns AF_OK or AF_ERROR |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
249 */ |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
250 static int af_open( af_instance_t* af ) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
251 { |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
252 af->control = control; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
253 af->uninit = uninit; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
254 af->play = play; |
24888 | 255 af->mul=1; |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
256 af->data = calloc(1, sizeof(af_data_t)); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
257 af->setup = calloc(1, sizeof(af_export_t)); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
258 if((af->data == NULL) || (af->setup == NULL)) |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
259 return AF_ERROR; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
260 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
261 ((af_export_t *)af->setup)->filename = get_path(SHARED_FILE); |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
262 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
263 return AF_OK; |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
264 } |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
265 |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
266 // Description of this filter |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
267 af_info_t af_info_export = { |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
268 "Sound export filter", |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
269 "export", |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
270 "Anders; Gustavo Sverzut Barbieri <gustavo.barbieri@ic.unicamp.br>", |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
271 "", |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
272 AF_FLAGS_REENTRANT, |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
273 af_open |
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
diff
changeset
|
274 }; |