diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/appevents.h | 1 | ||||
-rw-r--r-- | apps/buffering.c | 20 | ||||
-rw-r--r-- | apps/playback.c | 3 | ||||
-rw-r--r-- | apps/radio/radioart.c | 56 |
4 files changed, 37 insertions, 43 deletions
diff --git a/apps/appevents.h b/apps/appevents.h index 5cb0ee57b2..a11e423a90 100644 --- a/apps/appevents.h +++ b/apps/appevents.h | |||
@@ -54,6 +54,7 @@ enum { | |||
54 | BUFFER_EVENT_CLOSED, | 54 | BUFFER_EVENT_CLOSED, |
55 | BUFFER_EVENT_MOVED, | 55 | BUFFER_EVENT_MOVED, |
56 | BUFFER_EVENT_FINISHED, | 56 | BUFFER_EVENT_FINISHED, |
57 | BUFFER_EVENT_BUFFER_RESET | ||
57 | }; | 58 | }; |
58 | 59 | ||
59 | /** Generic GUI class events **/ | 60 | /** Generic GUI class events **/ |
diff --git a/apps/buffering.c b/apps/buffering.c index c47564b7e1..b5bf427079 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -389,7 +389,7 @@ static bool rm_handle(const struct memory_handle *h) | |||
389 | NULL if the handle wasn't found */ | 389 | NULL if the handle wasn't found */ |
390 | static struct memory_handle *find_handle(int handle_id) | 390 | static struct memory_handle *find_handle(int handle_id) |
391 | { | 391 | { |
392 | if (handle_id < 0) | 392 | if (handle_id < 0 || !first_handle) |
393 | return NULL; | 393 | return NULL; |
394 | 394 | ||
395 | /* simple caching because most of the time the requested handle | 395 | /* simple caching because most of the time the requested handle |
@@ -1748,12 +1748,22 @@ bool buffering_reset(char *buf, size_t buflen) | |||
1748 | thus buf and buflen must be a aligned to an integer multiple of | 1748 | thus buf and buflen must be a aligned to an integer multiple of |
1749 | the storage alignment */ | 1749 | the storage alignment */ |
1750 | 1750 | ||
1751 | buflen -= GUARD_BUFSIZE; | 1751 | if (buf) { |
1752 | buflen -= MIN(buflen, GUARD_BUFSIZE); | ||
1753 | |||
1754 | STORAGE_ALIGN_BUFFER(buf, buflen); | ||
1752 | 1755 | ||
1753 | STORAGE_ALIGN_BUFFER(buf, buflen); | 1756 | if (!buf || !buflen) |
1757 | return false; | ||
1758 | } else { | ||
1759 | buflen = 0; | ||
1760 | } | ||
1754 | 1761 | ||
1755 | if (!buf || !buflen) | 1762 | send_event(BUFFER_EVENT_BUFFER_RESET, NULL); |
1756 | return false; | 1763 | |
1764 | /* If handles weren't closed above, just do it */ | ||
1765 | while (num_handles != 0) | ||
1766 | bufclose(first_handle->id); | ||
1757 | 1767 | ||
1758 | buffer = buf; | 1768 | buffer = buf; |
1759 | buffer_len = buflen; | 1769 | buffer_len = buflen; |
diff --git a/apps/playback.c b/apps/playback.c index bd7dd813c9..21cc017aaf 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -3621,6 +3621,9 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) | |||
3621 | audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops); | 3621 | audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops); |
3622 | buf = core_get_data(audiobuf_handle); | 3622 | buf = core_get_data(audiobuf_handle); |
3623 | 3623 | ||
3624 | if (buffer_state == AUDIOBUF_STATE_INITIALIZED) | ||
3625 | buffering_reset(NULL, 0); /* mark buffer invalid */ | ||
3626 | |||
3624 | if (talk_buf || buffer_state == AUDIOBUF_STATE_TRASHED | 3627 | if (talk_buf || buffer_state == AUDIOBUF_STATE_TRASHED |
3625 | || !talk_voice_required()) | 3628 | || !talk_voice_required()) |
3626 | { | 3629 | { |
diff --git a/apps/radio/radioart.c b/apps/radio/radioart.c index 07fab814dd..53ed863b3b 100644 --- a/apps/radio/radioart.c +++ b/apps/radio/radioart.c | |||
@@ -41,10 +41,9 @@ struct radioart { | |||
41 | char name[MAX_FMPRESET_LEN+1]; | 41 | char name[MAX_FMPRESET_LEN+1]; |
42 | }; | 42 | }; |
43 | 43 | ||
44 | static char* buf; | ||
44 | static struct radioart radioart[MAX_RADIOART_IMAGES]; | 45 | static struct radioart radioart[MAX_RADIOART_IMAGES]; |
45 | #ifdef HAVE_RECORDING | 46 | |
46 | static bool allow_buffer_access = true; /* If we are recording dont touch the buffers! */ | ||
47 | #endif | ||
48 | static int find_oldest_image(void) | 47 | static int find_oldest_image(void) |
49 | { | 48 | { |
50 | int i; | 49 | int i; |
@@ -101,12 +100,10 @@ int radio_get_art_hid(struct dim *requested_dim) | |||
101 | int preset = radio_current_preset(); | 100 | int preset = radio_current_preset(); |
102 | int free_idx = -1; | 101 | int free_idx = -1; |
103 | const char* preset_name; | 102 | const char* preset_name; |
104 | if (radio_scan_mode() || preset < 0) | 103 | |
105 | return -1; | 104 | if (!buf || radio_scan_mode() || preset < 0) |
106 | #ifdef HAVE_RECORDING | ||
107 | if (!allow_buffer_access) | ||
108 | return -1; | 105 | return -1; |
109 | #endif | 106 | |
110 | preset_name = radio_get_preset_name(preset); | 107 | preset_name = radio_get_preset_name(preset); |
111 | for (int i=0; i<MAX_RADIOART_IMAGES; i++) | 108 | for (int i=0; i<MAX_RADIOART_IMAGES; i++) |
112 | { | 109 | { |
@@ -137,55 +134,38 @@ int radio_get_art_hid(struct dim *requested_dim) | |||
137 | 134 | ||
138 | return -1; | 135 | return -1; |
139 | } | 136 | } |
140 | static void playback_restarting_handler(void *data) | 137 | |
138 | static void buffer_reset_handler(void *data) | ||
141 | { | 139 | { |
142 | (void)data; | 140 | buf = NULL; |
143 | int i; | 141 | for(int i=0;i<MAX_RADIOART_IMAGES;i++) |
144 | for(i=0;i<MAX_RADIOART_IMAGES;i++) | ||
145 | { | 142 | { |
146 | if (radioart[i].handle >= 0) | 143 | if (radioart[i].handle >= 0) |
147 | bufclose(radioart[i].handle); | 144 | bufclose(radioart[i].handle); |
148 | radioart[i].handle = -1; | 145 | radioart[i].handle = -1; |
149 | radioart[i].name[0] = '\0'; | 146 | radioart[i].name[0] = '\0'; |
150 | } | 147 | } |
151 | } | 148 | |
152 | #ifdef HAVE_RECORDING | ||
153 | static void recording_started_handler(void *data) | ||
154 | { | ||
155 | (void)data; | ||
156 | allow_buffer_access = false; | ||
157 | playback_restarting_handler(NULL); | ||
158 | } | ||
159 | static void recording_stopped_handler(void *data) | ||
160 | { | ||
161 | (void)data; | 149 | (void)data; |
162 | allow_buffer_access = true; | ||
163 | } | 150 | } |
164 | #endif | ||
165 | 151 | ||
166 | void radioart_init(bool entering_screen) | 152 | void radioart_init(bool entering_screen) |
167 | { | 153 | { |
168 | int i; | ||
169 | if (entering_screen) | 154 | if (entering_screen) |
170 | { | 155 | { |
171 | for(i=0;i<MAX_RADIOART_IMAGES;i++) | ||
172 | { | ||
173 | radioart[i].handle = -1; | ||
174 | radioart[i].name[0] = '\0'; | ||
175 | } | ||
176 | add_event(PLAYBACK_EVENT_START_PLAYBACK, true, playback_restarting_handler); | ||
177 | |||
178 | /* grab control over buffering */ | 156 | /* grab control over buffering */ |
179 | char* buf; | ||
180 | size_t bufsize; | 157 | size_t bufsize; |
181 | buf = audio_get_buffer(false, &bufsize); | 158 | buf = audio_get_buffer(false, &bufsize); |
182 | buffering_reset(buf, bufsize); | 159 | buffering_reset(buf, bufsize); |
160 | /* one-shot */ | ||
161 | add_event(BUFFER_EVENT_BUFFER_RESET, true, buffer_reset_handler); | ||
183 | } | 162 | } |
184 | else | 163 | else /* init at startup */ |
185 | { | 164 | { |
186 | #if defined(HAVE_RECORDING) | 165 | for(int i=0;i<MAX_RADIOART_IMAGES;i++) |
187 | add_event(RECORDING_EVENT_START, false, recording_started_handler); | 166 | { |
188 | add_event(RECORDING_EVENT_STOP, false, recording_stopped_handler); | 167 | radioart[i].handle = -1; |
189 | #endif | 168 | radioart[i].name[0] = '\0'; |
169 | } | ||
190 | } | 170 | } |
191 | } | 171 | } |