int wave_is_busy(void* theHandler) { uint32_t time; if (total_samples_sent >= 1) { wave_get_remaining_time(total_samples_sent - 1, &time); } else { time = 0; } return time != 0; }
// wave_is_busy // // DESCRIPTION: // // Returns a non-0 value if audio is being played. // // PARAMETERS: // // theHandler: the audio device file descriptor // // GLOBALS USED/MODIFIED: // // sun_audio_fd: used because some calls to wave_is_busy seem to // pass a NULL for theHandler for some odd reason // // RETURNS: // // A non-0 value if audio is being played // int wave_is_busy(void *theHandler) { (void)theHandler; // unused uint32_t time; if (total_samples_sent >= 1) wave_get_remaining_time(total_samples_sent - 1, &time); else time = 0; return time != 0; }
static int get_remaining_time(uint32_t sample, uint32_t* time_in_ms, int* stop_is_required) { ENTER("get_remaining_time"); int err = 0; *stop_is_required = 0; int i=0; for (i=0; i < MAX_ACTIVITY_CHECK && (*stop_is_required == 0); i++) { err = wave_get_remaining_time( sample, time_in_ms); if (err || wave_is_busy(NULL) || (*time_in_ms == 0)) { // if err, stream not available: quit // if wave is busy, time_in_ms is known: quit // if wave is not busy but remaining time == 0, event is reached: quit break; } // stream opened but not active // // Several possible states: // * the stream is opened but not yet started: // // wait for the start of stream // // * some samples have already been played, // ** the end of stream is reached // ** or there is an underrun // // wait for the close of stream *stop_is_required = sleep_until_timeout_or_stop_request( ACTIVITY_TIMEOUT); } return err; }