Skip to content

fbd-dev-sound: Delay sending `ended` signal

I tried to blame gsound() and other and lamented about weird callback changes but in the end it's just the fact that signals are synchronous in glib and i didn't notice the consequences:

Remove the feedback and the associated callback data before invoking the callback (which then triggers FbdFeebackBased:ended) since we otherwise remove the data from the currently playing sound from the hash table instead of removing the data from the sound that just finished playing.

Call flow for a repeating sound before:

  on_sound_play_finished_callback()
    data->callback()
      fbd_feedback_get_ended()
        on_fb_ended()
          fbd_feedback_run()
            g_hash_table_insert(..., feedback, data)
            fbd_dev_sound_play()
              gsound_context_play_full() [async]
    g_hash_table_remove (..., data->feedback) <- removes wrong feedback

So (since the feedback is still the same but only the callback data changes) we end up removing the data from the currently playing sound from the hash table and any calls to fbd_dev_sound_stop() would fail to find data and hence not cancel the playing sound.

Call flow for a repeating sound now:

  on_sound_play_finished_callback()
    g_hash_table_remove (..., data->feedback)
    data->callback()
      fbd_feedback_get_ended()
        on_fb_ended()
          fbd_feedback_run()
            g_hash_table_insert(..., feedback, data)
            fbd_dev_sound_play()
              gsound_context_play_full() [async]

So we remove the data of the currently playing sound before adding the feedback to the hash table again. No ownership is transfered to the hash table so no cleanusp need to be changed.

Closes: #46 (closed)

Edited by Guido Gunther

Merge request reports