diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2012-05-21 02:18:46 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2012-05-21 02:28:13 -0400 |
commit | 0ebfb937aaa073282415e561f8d1f150813a00fd (patch) | |
tree | ace0d47f3ee55c289a4b645986615ff9a281a1df /apps/radio | |
parent | 5f2618c363467648d96ccbc82e14df7d2194a148 (diff) | |
download | rockbox-0ebfb937aaa073282415e561f8d1f150813a00fd.tar.gz rockbox-0ebfb937aaa073282415e561f8d1f150813a00fd.zip |
Fix some lockup caused by handles not being initialized to < 0...
...by default where they would be interpreted as valid but not actually
be which would cause calls to buffering while it was not initialized.
Add BUFFER_EVENT_BUFFER_RESET to inform users of buffering that the
buffer is being reinitialized. Basically, this wraps all the
functionality being provided by three events (...START_PLAYBACK,
RECORDING_EVENT_START, RECORDING_EVENT_STOP) into one for radioart.c,
the only user of those events (perhaps remove them?) and closes some
loopholes.
Change-Id: I99ec46b9b5fb4e36605db5944c60ed986163db3a
Diffstat (limited to 'apps/radio')
-rw-r--r-- | apps/radio/radioart.c | 56 |
1 files changed, 18 insertions, 38 deletions
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 | } |