diff options
Diffstat (limited to 'apps/radio/radioart.c')
-rw-r--r-- | apps/radio/radioart.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/apps/radio/radioart.c b/apps/radio/radioart.c index 76697c6017..cab6aa29ce 100644 --- a/apps/radio/radioart.c +++ b/apps/radio/radioart.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "kernel.h" | 32 | #include "kernel.h" |
33 | #include "string-extra.h" | 33 | #include "string-extra.h" |
34 | #include "filefuncs.h" | 34 | #include "filefuncs.h" |
35 | #include "core_alloc.h" | ||
35 | 36 | ||
36 | #define MAX_RADIOART_IMAGES 10 | 37 | #define MAX_RADIOART_IMAGES 10 |
37 | struct radioart { | 38 | struct radioart { |
@@ -158,14 +159,49 @@ static void buffer_reset_handler(void *data) | |||
158 | (void)data; | 159 | (void)data; |
159 | } | 160 | } |
160 | 161 | ||
162 | static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) | ||
163 | { | ||
164 | (void)start; | ||
165 | (void)old_size; | ||
166 | |||
167 | ssize_t old_size_s = old_size; | ||
168 | size_t size_hint = (hints & BUFLIB_SHRINK_SIZE_MASK); | ||
169 | ssize_t wanted_size = old_size_s - size_hint; | ||
170 | |||
171 | if (wanted_size <= 0) | ||
172 | { | ||
173 | core_free(handle); | ||
174 | buffering_reset(NULL, 0); | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | if (hints & BUFLIB_SHRINK_POS_FRONT) | ||
179 | start += size_hint; | ||
180 | |||
181 | buffering_reset(start, wanted_size); | ||
182 | core_shrink(handle, start, wanted_size); | ||
183 | buf = start; | ||
184 | |||
185 | /* one-shot */ | ||
186 | add_event(BUFFER_EVENT_BUFFER_RESET, true, buffer_reset_handler); | ||
187 | } | ||
188 | |||
189 | return BUFLIB_CB_OK; | ||
190 | } | ||
191 | |||
192 | static struct buflib_callbacks radioart_ops = { | ||
193 | .shrink_callback = shrink_callback, | ||
194 | }; | ||
195 | |||
161 | void radioart_init(bool entering_screen) | 196 | void radioart_init(bool entering_screen) |
162 | { | 197 | { |
163 | if (entering_screen) | 198 | if (entering_screen) |
164 | { | 199 | { |
165 | /* grab control over buffering */ | 200 | /* grab control over buffering */ |
166 | size_t bufsize; | 201 | size_t bufsize; |
167 | buf = audio_get_buffer(false, &bufsize); | 202 | int handle = core_alloc_maximum("radioart", &bufsize, &radioart_ops); |
168 | buffering_reset(buf, bufsize); | 203 | buffering_reset(core_get_data(handle), bufsize); |
204 | buf = core_get_data(handle); | ||
169 | /* one-shot */ | 205 | /* one-shot */ |
170 | add_event(BUFFER_EVENT_BUFFER_RESET, true, buffer_reset_handler); | 206 | add_event(BUFFER_EVENT_BUFFER_RESET, true, buffer_reset_handler); |
171 | } | 207 | } |