• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revision5acc6ad9e3f74b14ad92c67edf712926696858cd (tree)
Time2018-05-31 02:43:40
AuthorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[OSD][SOUND][Qt] Fix hang-up with resetting at some situations.

Change Summary

Incremental Difference

--- a/source/src/qt/osd_sound.cpp
+++ b/source/src/qt/osd_sound.cpp
@@ -36,7 +36,7 @@ void OSD_BASE::audio_callback(void *udata, Uint8 *stream, int len)
3636 spos = 0;
3737 memset(stream, 0x00, len);
3838 do {
39- SDL_SemWait(*pData->snd_apply_sem);
39+ //SDL_SemWait(*pData->snd_apply_sem);
4040 if(pData->p_config->general_sound_level < -32768) pData->p_config->general_sound_level = -32768;
4141 if(pData->p_config->general_sound_level > 32767) pData->p_config->general_sound_level = 32767;
4242 *pData->snd_total_volume = (uint8_t)(((uint32_t)(pData->p_config->general_sound_level + 32768)) >> 9);
@@ -46,7 +46,7 @@ void OSD_BASE::audio_callback(void *udata, Uint8 *stream, int len)
4646 }
4747 len2 = *(pData->sound_buffer_size) - *(pData->sound_write_pos);
4848 if(*pData->sound_exit) {
49- SDL_SemPost(*pData->snd_apply_sem);
49+ //SDL_SemPost(*pData->snd_apply_sem);
5050 return;
5151 }
5252 if(len2 >= sndlen) len2 = sndlen; // Okay
@@ -61,25 +61,27 @@ void OSD_BASE::audio_callback(void *udata, Uint8 *stream, int len)
6161 if((len2 > 0) && (sndlen > 0)){
6262 writepos = *pData->sound_write_pos;
6363 p = (Uint8 *)(*pData->sound_buf_ptr);
64- SDL_SemPost(*pData->snd_apply_sem);
64+ //SDL_SemPost(*pData->snd_apply_sem);
6565 p = &p[writepos * 2];
6666 s = &stream[spos * 2];
6767 SDL_MixAudio(s, (Uint8 *)p, len2 * 2, *(pData->snd_total_volume));
68- SDL_SemWait(*pData->snd_apply_sem);
68+ //SDL_SemWait(*pData->snd_apply_sem);
6969 *(pData->sound_data_len) -= len2;
7070 if(*(pData->sound_data_len) <= 0) *(pData->sound_data_len) = 0;
7171 *pData->sound_write_pos += len2;
72- SDL_SemPost(*pData->snd_apply_sem);
72+ //SDL_SemPost(*pData->snd_apply_sem);
7373 } else {
7474 len2 = 0;
75- SDL_SemPost(*pData->snd_apply_sem);
75+ //SDL_SemPost(*pData->snd_apply_sem);
7676 if(spos >= (len / 2)) return;
77- while(*(pData->sound_data_len) <= 0) {
78- QThread::usleep(500);
79- if(*pData->sound_exit) return;
80- }
77+ if(*(pData->sound_data_len) <= 0) return;
78+ //while(*(pData->sound_data_len) <= 0) {
79+ // QThread::usleep(500);
80+ // if(*pData->sound_exit) return;
81+ //}
8182 }
8283 spos += len2;
84+ if(*pData->sound_exit) return;
8385 } while(spos < len);
8486 }
8587
@@ -158,6 +160,7 @@ void OSD_BASE::initialize_sound(int rate, int samples)
158160 #else
159161 SDL_PauseAudio(0);
160162 #endif
163+ //SDL_SemPost(*snddata.snd_apply_sem);
161164
162165 sound_ok = sound_first_half = true;
163166 }
@@ -166,9 +169,12 @@ void OSD_BASE::release_sound()
166169 {
167170 // release SDL sound
168171 sound_exit = true;
172+ //while(SDL_SemValue(*snddata.snd_apply_sem) > 0) SDL_SemPost(*snddata.snd_apply_sem);
169173 #if defined(USE_SDL2)
174+ //SDL_PauseAudioDevice(audio_dev_id, 1);
170175 SDL_CloseAudioDevice(audio_dev_id);
171176 #else
177+ //SDL_PauseAudio(1);
172178 SDL_CloseAudio();
173179 #endif
174180 if(snd_apply_sem != NULL) {
@@ -255,6 +261,11 @@ void OSD_BASE::update_sound(int* extra_frames)
255261 size2 = 0;
256262 ptr2 = NULL;
257263 }
264+#if defined(USE_SDL2)
265+ SDL_LockAudioDevice(audio_dev_id);
266+#else
267+ SDL_LockAudio();
268+#endif
258269 if(ptr1) {
259270 my_memcpy(ptr1, sound_buffer, size1 * sizeof(Sint16));
260271 }
@@ -265,9 +276,15 @@ void OSD_BASE::update_sound(int* extra_frames)
265276 if(sound_data_len >= sound_buffer_size) sound_data_len = sound_buffer_size;
266277 sound_data_pos = sound_data_pos + ssize;
267278 if(sound_data_pos >= sound_buffer_size) sound_data_pos = sound_data_pos - sound_buffer_size;
279+ if(!sound_started) sound_started = true;
280+#if defined(USE_SDL2)
281+ SDL_UnlockAudioDevice(audio_dev_id);
282+#else
283+ SDL_UnlockAudio();
284+#endif
268285 //SDL_SemPost(*snddata.snd_apply_sem);
269286 //SDL_UnlockAudio();
270- //SDL_PauseAudioDevice(audio_dev_id, 0);
287+ SDL_PauseAudioDevice(audio_dev_id, 0);
271288 }
272289 }
273290
@@ -287,7 +304,12 @@ void OSD_BASE::mute_sound()
287304 int ssize;
288305 int pos;
289306 int pos2;
290- SDL_SemWait(*snddata.snd_apply_sem);
307+ //SDL_SemWait(*snddata.snd_apply_sem);
308+#if defined(USE_SDL2)
309+ SDL_LockAudioDevice(audio_dev_id);
310+#else
311+ SDL_LockAudio();
312+#endif
291313 ssize = sound_buffer_size / 2;
292314 pos = sound_data_pos;
293315 pos2 = pos + ssize;
@@ -309,7 +331,13 @@ void OSD_BASE::mute_sound()
309331 memset(ptr2, 0x00, size2 * sizeof(Sint16));
310332 }
311333 sound_data_pos = (sound_data_pos + ssize) % sound_buffer_size;
312- SDL_SemPost(*snddata.snd_apply_sem);
334+ //SDL_SemPost(*snddata.snd_apply_sem);
335+#if defined(USE_SDL2)
336+ SDL_UnlockAudioDevice(audio_dev_id);
337+#else
338+ SDL_UnlockAudio();
339+#endif
340+ //SDL_SemPost(*snddata.snd_apply_sem);
313341 }
314342 now_mute = true;
315343 }
@@ -317,12 +345,14 @@ void OSD_BASE::mute_sound()
317345 void OSD_BASE::stop_sound()
318346 {
319347 if(sound_ok && sound_started) {
348+ //sound_exit = true;
320349 #if defined(USE_SDL2)
321350 SDL_PauseAudioDevice(audio_dev_id, 1);
322351 #else
323352 SDL_PauseAudio(1);
324353 #endif
325354 sound_started = false;
355+ //sound_exit = false;
326356 }
327357 }
328358
Show on old repository browser