Visitar URL original
MediaPlayer race condition in audio annunciator · Issue #3966 · ControlSystemStudio/phoebus · GitHub
Skip to content

MediaPlayer race condition in audio annunciator #3966

Open

Description

@LordIdra

I am trying to get the audio annunciator to work with a very short nag period (1 second) and a short clip (100ms) of a beep sound. I have encountered an issue where beeps are frequently missed. I traced this to what appears to be a race condition between MediaPlayer::stop and MediaPlayer::play. In speakAlone, stop is called on every alarm media player, and then play is called on the correct media player. This is all well and good except it would appear that stop does not actually appear to block until the media player status has transitioned to stopped even if the audio clip has finished playing.

Adding a log statement just before play is called e.g.

try {
    logger.log(Level.SEVERE, "grioejgoijq " + alarm.getStatus());
    alarm.play();
} catch (Exception e) {
    logger.log(Level.SEVERE, "Failed to play alarm sound", e);
}

does two things: firstly it more or less randomly logs 'PLAYING' or 'STOPPED' indicating the race condition, and secondly it stops beeps from being missed (yes - adding a log statement fixes the bug). I think this is just because there is more time for the player to stop and so by the time it gets to play it has actually been stopped.

I have looked into fixing this but really not sure how to do it in a simple way - ideally I think we'd just block until the status returns to stopped which can be done with completable futures but it feels like there should be an easier solution - so please let me know any thoughts

Activity

  1. shroffk commented on Oct 23, 2026

    @shroffk
    Member

    What is the max_alarm_duration set to?

                            sound.setStopTime(Duration.seconds(Preferences.max_alarm_duration));
    

    Do you think we should change the preference from seconds to millis? Can you try this out and let me know if it helps.

    If the above does not work then, looking at the MediaPlayer I don't see any elegant way of addressing this... completable future seems like the best of the options.

  2. LordIdra commented on Oct 26, 2026

    @LordIdra
    Author
    1. What is the max_alarm_duration set to?
                              sound.setStopTime(Duration.seconds(Preferences.max_alarm_duration));
      
      Do you think we should change the preference from seconds to millis? Can you try this out and let me know if it helps.
      If the above does not work then, looking at the MediaPlayer I don't see any elegant way of addressing this... completable future seems like the best of the options.

    Yes, I did try changing to millis initially but the stop time is clamped to the duration of the file anyway (according to setStopTime docs) so I don't think this changes anything unless you are playing a long clip which you want to cut short. The issue here is that the media player does not seek to the beginning once it has finished playing.

    I have tried to implement a fix using CompleteableFutures but the issue still happens, which implies that there is actually a bug with something lower down. I suspect it might be a driver bug or something similar, especially considering it has never been reported here and I cannot find anything relevant on the internet. So we are just going to roll the audio annunciator out, and see if this issue occurs on any other machines before proceeding with a fix.

  3. shroffk commented on Oct 26, 2026

    @shroffk
    Member

    Ah Ok,
    So we will adopt the "do nothing for now" solution.

    We can keep this open for reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions