comparison render_sdl.c @ 1980:81df9aa2de9b

Less hacky run on audio thread mode
author Michael Pavone <pavone@retrodev.com>
date Sat, 09 May 2020 23:25:51 -0700
parents 06c25babe464
children 3537514ea206
comparison
equal deleted inserted replaced
1979:06c25babe464 1980:81df9aa2de9b
169 SDL_DestroyCond(opaque); 169 SDL_DestroyCond(opaque);
170 } 170 }
171 171
172 void render_audio_created(audio_source *source) 172 void render_audio_created(audio_source *source)
173 { 173 {
174 if (sync_src == SYNC_AUDIO && SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { 174 if (render_is_audio_sync()) {
175 SDL_PauseAudio(0); 175 SDL_PauseAudio(0);
176 } 176 }
177 if (current_system) { 177 if (current_system && sync_src == SYNC_AUDIO_THREAD) {
178 current_system->request_exit(current_system); 178 system_request_exit(current_system, 0);
179 } 179 }
180 } 180 }
181 181
182 void render_source_paused(audio_source *src, uint8_t remaining_sources) 182 void render_source_paused(audio_source *src, uint8_t remaining_sources)
183 { 183 {
184 if (sync_src == SYNC_AUDIO) { 184 if (sync_src == SYNC_AUDIO) {
185 SDL_CondSignal(audio_ready); 185 SDL_CondSignal(audio_ready);
186 } 186 }
187 if (!remaining_sources) { 187 if (!remaining_sources && render_is_audio_sync()) {
188 SDL_PauseAudio(1);
189 if (sync_src == SYNC_AUDIO_THREAD) {
190 SDL_CondSignal(frame_ready);
191 }
192 }
193 }
194
195 void render_source_resumed(audio_source *src)
196 {
197 if (render_is_audio_sync()) {
188 SDL_PauseAudio(0); 198 SDL_PauseAudio(0);
189 } 199 }
190 } 200 if (current_system && sync_src == SYNC_AUDIO_THREAD) {
191 201 system_request_exit(current_system, 0);
192 void render_source_resumed(audio_source *src)
193 {
194 if (sync_src == SYNC_AUDIO) {
195 SDL_PauseAudio(0);
196 } 202 }
197 } 203 }
198 204
199 void render_do_audio_ready(audio_source *src) 205 void render_do_audio_ready(audio_source *src)
200 { 206 {
204 src->back = tmp; 210 src->back = tmp;
205 src->front_populated = 1; 211 src->front_populated = 1;
206 src->buffer_pos = 0; 212 src->buffer_pos = 0;
207 if (all_sources_ready()) { 213 if (all_sources_ready()) {
208 //we've emulated far enough to fill the current buffer 214 //we've emulated far enough to fill the current buffer
209 current_system->request_exit(current_system); 215 system_request_exit(current_system, 0);
210 } 216 }
211 } else if (sync_src == SYNC_AUDIO) { 217 } else if (sync_src == SYNC_AUDIO) {
212 SDL_LockMutex(audio_mutex); 218 SDL_LockMutex(audio_mutex);
213 while (src->front_populated) { 219 while (src->front_populated) {
214 SDL_CondWait(src->opaque, audio_mutex); 220 SDL_CondWait(src->opaque, audio_mutex);
1698 void render_video_loop(void) 1704 void render_video_loop(void)
1699 { 1705 {
1700 if (sync_src != SYNC_AUDIO_THREAD && sync_src != SYNC_EXTERNAL) { 1706 if (sync_src != SYNC_AUDIO_THREAD && sync_src != SYNC_EXTERNAL) {
1701 return; 1707 return;
1702 } 1708 }
1703 SDL_PauseAudio(0);
1704 SDL_LockMutex(frame_mutex); 1709 SDL_LockMutex(frame_mutex);
1705 for(;;) 1710 for(;;)
1706 { 1711 {
1707 while (!frame_queue_len) 1712 while (!frame_queue_len && SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)
1708 { 1713 {
1709 SDL_CondWait(frame_ready, frame_mutex); 1714 SDL_CondWait(frame_ready, frame_mutex);
1710 } 1715 }
1711 for (int i = 0; i < frame_queue_len; i++)
1712 while (frame_queue_len) 1716 while (frame_queue_len)
1713 { 1717 {
1714 frame f = frame_queue[frame_queue_read++]; 1718 frame f = frame_queue[frame_queue_read++];
1715 frame_queue_read &= 0x3; 1719 frame_queue_read &= 0x3;
1716 frame_queue_len--; 1720 frame_queue_len--;
1717 SDL_UnlockMutex(frame_mutex); 1721 SDL_UnlockMutex(frame_mutex);
1718 process_framebuffer(f.buffer, f.which, f.width); 1722 process_framebuffer(f.buffer, f.which, f.width);
1719 release_buffer(f.buffer); 1723 release_buffer(f.buffer);
1720 SDL_LockMutex(frame_mutex); 1724 SDL_LockMutex(frame_mutex);
1725 }
1726 if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) {
1727 break;
1721 } 1728 }
1722 } 1729 }
1723 1730
1724 SDL_UnlockMutex(frame_mutex); 1731 SDL_UnlockMutex(frame_mutex);
1725 } 1732 }