Changeset - r25427:a21ff6ef82f6
[Not reviewed]
master
0 1 0
Rubidium - 3 years ago 2021-05-08 11:33:26
rubidium@openttd.org
Cleanup: [Fluidsynth] Remove fluid_player_join

The function fluid_player_join in the library is broken beyond compare for the
usecases it was used for (see their #872). It does not wait until it is safe
to delete the player, so it is up to the end user to ensure that.

For OpenTTD we acquire a lock before fluid_synth_write_s16 and we acquire the
same lock in the stop function. So, only one of the functions can be doing its
thing, meaning we do not need to wait for the player to be stopped as it
cannot be doing anything as we prevent that by the lock.
1 file changed with 4 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/music/fluidsynth.cpp
Show inline comments
 
@@ -163,21 +163,12 @@ void MusicDriver_FluidSynth::PlaySong(co
 

	
 
void MusicDriver_FluidSynth::StopSong()
 
{
 
	{
 
		std::lock_guard<std::mutex> lock{ _midi.synth_mutex };
 

	
 
		if (_midi.player == nullptr) return;
 

	
 
		fluid_player_stop(_midi.player);
 
	}
 
	std::lock_guard<std::mutex> lock{ _midi.synth_mutex };
 

	
 
	/* The join must be run without lock as the Music rendering needs to be
 
	 * running so FluidSynth's internals can actually stop the playing. */
 
	if (fluid_player_join(_midi.player) != FLUID_OK) {
 
		DEBUG(driver, 0, "Could not join player");
 
	}
 
	if (_midi.player == nullptr) return;
 

	
 
	std::lock_guard<std::mutex> lock{ _midi.synth_mutex };
 
	fluid_player_stop(_midi.player);
 
	/* No fluid_player_join needed */
 
	delete_fluid_player(_midi.player);
 
	fluid_synth_system_reset(_midi.synth);
 
	fluid_synth_all_sounds_off(_midi.synth, -1);
0 comments (0 inline, 0 general)