Commit e1e7a73c authored by Hans-Kristian Arntzen's avatar Hans-Kristian Arntzen Committed by Rémi Denis-Courmont

OSS audio output: Prefer GETODELAY over GETOSPACE.

Fix the possibly wrong assumption that we're able to accurately
calculate latency using GETOSPACE
(buffer size - available bytes to write).

New code uses GETODELAY to get latency directly but falls back to
GETOSPACE calculation should GETODELAY fail.
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent cc82de22
...@@ -553,15 +553,22 @@ static mtime_t BufferDuration( audio_output_t * p_aout ) ...@@ -553,15 +553,22 @@ static mtime_t BufferDuration( audio_output_t * p_aout )
audio_buf_info audio_buf; audio_buf_info audio_buf;
int i_bytes; int i_bytes;
/* Fill the audio_buf_info structure: #ifdef SNDCTL_DSP_GETODELAY
* - fragstotal: total number of fragments allocated if ( ioctl( p_sys->i_fd, SNDCTL_DSP_GETODELAY, &i_bytes ) < 0 )
* - fragsize: size of a fragment in bytes #endif
* - bytes: available space in bytes (includes partially used fragments) {
* Note! 'bytes' could be more than fragments*fragsize */ /* Fall back to GETOSPACE and approximate latency. */
ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf );
/* Fill the audio_buf_info structure:
/* calculate number of available fragments (not partially used ones) */ * - fragstotal: total number of fragments allocated
i_bytes = (audio_buf.fragstotal * audio_buf.fragsize) - audio_buf.bytes; * - fragsize: size of a fragment in bytes
* - bytes: available space in bytes (includes partially used fragments)
* Note! 'bytes' could be more than fragments*fragsize */
ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf );
/* calculate number of available fragments (not partially used ones) */
i_bytes = (audio_buf.fragstotal * audio_buf.fragsize) - audio_buf.bytes;
}
/* Return the fragment duration */ /* Return the fragment duration */
return (mtime_t)i_bytes * 1000000 return (mtime_t)i_bytes * 1000000
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment