Commit 93741508 authored by Alexandre Ratchov's avatar Alexandre Ratchov Committed by Jean-Baptiste Kempf

Fix compilation and functionning of the sndio module for OpenBSD

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 24ab3b20
...@@ -54,8 +54,8 @@ static void PositionChanged (void *, int); ...@@ -54,8 +54,8 @@ static void PositionChanged (void *, int);
struct aout_sys_t struct aout_sys_t
{ {
struct sio_hdl *hdl; struct sio_hdl *hdl;
unsigned long long read_offset; int started;
unsigned long long write_offset; int delay;
unsigned rate; unsigned rate;
unsigned volume; unsigned volume;
bool mute; bool mute;
...@@ -69,21 +69,39 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -69,21 +69,39 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
sys->hdl = sio_open (NULL, SIO_PLAY, 0 /* blocking */); sys->hdl = sio_open (NULL, SIO_PLAY, 0 /* blocking */);
if (sys->hdl == NULL) if (sys->hdl == NULL)
{ {
msg_Err (obj, "cannot create audio playback stream"); msg_Err (aout, "cannot create audio playback stream");
free (sys);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
aout->sys = sys;
struct sio_par par; struct sio_par par;
sio_initpar (&par); sio_initpar (&par);
par.bits = 16; switch (fmt->i_format) {
par.bps = par.bits >> 3; case VLC_CODEC_S8:
par.sig = 1; par.bits = 8;
par.le = SIO_LE_NATIVE; par.sig = 0;
break;
case VLC_CODEC_S16N:
par.bits = 16;
par.sig = 1;
par.le = SIO_LE_NATIVE;
break;
case VLC_CODEC_S32N:
case VLC_CODEC_FL32:
case VLC_CODEC_FL64:
par.bits = 32;
par.sig = 1;
par.le = SIO_LE_NATIVE;
break;
default:
/* use a common audio format */
par.bits = 16;
par.sig = 1;
par.le = SIO_LE_NATIVE;
}
par.pchan = aout_FormatNbChannels (fmt); par.pchan = aout_FormatNbChannels (fmt);
par.rate = fmt->i_rate; par.rate = fmt->i_rate;
par.xrun = SIO_SYNC; par.round = par.rate / 50;
par.appbufsz = par.rate / 4;
if (!sio_setpar (sys->hdl, &par) || !sio_getpar (sys->hdl, &par)) if (!sio_setpar (sys->hdl, &par) || !sio_getpar (sys->hdl, &par))
{ {
...@@ -91,7 +109,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -91,7 +109,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
goto error; goto error;
} }
if (par.bps != par.bits >> 3) if (par.bps != par.bits >> 3 && !par.msb)
{ {
msg_Err (aout, "unsupported audio sample format (%u bits in %u bytes)", msg_Err (aout, "unsupported audio sample format (%u bits in %u bytes)",
par.bits, par.bps); par.bits, par.bps);
...@@ -99,23 +117,16 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -99,23 +117,16 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
} }
if (par.sig != (par.bits != 8)) if (par.sig != (par.bits != 8))
{ {
msg_Err (obj, "unsupported audio sample format (%ssigned)", msg_Err (aout, "unsupported audio sample format (%ssigned)",
par.sig ? "" : "un"); par.sig ? "" : "un");
goto error; goto error;
} }
#ifdef WORDS_BIGENDIAN if (par.bps > 1 && par.le != SIO_LE_NATIVE)
if (par.le)
{
msg_Err (obj, "unsupported audio sample format (little endian)");
goto error;
}
#else
if (!par.le)
{ {
msg_Err (obj, "unsupported audio sample format (big endian)"); msg_Err (aout, "unsupported audio sample format (%s endian)",
par.le ? "little" : "big");
goto error; goto error;
} }
#endif
switch (par.bits) switch (par.bits)
{ {
case 8: case 8:
...@@ -163,7 +174,6 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -163,7 +174,6 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
fmt->i_original_channels = fmt->i_physical_channels = chans; fmt->i_original_channels = fmt->i_physical_channels = chans;
aout_FormatPrepare (fmt); aout_FormatPrepare (fmt);
aout->sys = sys;
aout->time_get = TimeGet; aout->time_get = TimeGet;
aout->play = Play; aout->play = Play;
aout->pause = NULL; aout->pause = NULL;
...@@ -179,8 +189,8 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -179,8 +189,8 @@ static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
aout->mute_set = NULL; aout->mute_set = NULL;
} }
sys->read_offset = 0; sys->started = 0;
sys->write_offset = 0; sys->delay = 0;
sio_onmove (sys->hdl, PositionChanged, aout); sio_onmove (sys->hdl, PositionChanged, aout);
sio_start (sys->hdl); sio_start (sys->hdl);
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -190,9 +200,8 @@ error: ...@@ -190,9 +200,8 @@ error:
return VLC_EGENERIC; return VLC_EGENERIC;
} }
static void Close (vlc_object_t *obj) static void Stop (audio_output_t *aout)
{ {
audio_output_t *aout = (audio_output_t *)obj;
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
sio_close (sys->hdl); sio_close (sys->hdl);
...@@ -203,18 +212,17 @@ static void PositionChanged (void *arg, int delta) ...@@ -203,18 +212,17 @@ static void PositionChanged (void *arg, int delta)
audio_output_t *aout = arg; audio_output_t *aout = arg;
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
sys->read_offset += delta; sys->delay -= delta;
sys->started = 1;
} }
static int TimeGet (audio_output_t *aout, mtime_t *restrict delay) static int TimeGet (audio_output_t *aout, mtime_t *restrict delay)
{ {
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
long long frames = sys->write_offset - sys->read_offset;
if (frames == 0) if (!sys->started)
return -1; return -1;
*delay = (mtime_t)sys->delay * CLOCK_FREQ / sys->rate;
*delay = frames * CLOCK_FREQ / sys->rate;
return 0; return 0;
} }
...@@ -222,35 +230,20 @@ static void Play (audio_output_t *aout, block_t *block) ...@@ -222,35 +230,20 @@ static void Play (audio_output_t *aout, block_t *block)
{ {
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
sys->write_offset += block->i_nb_samples; sio_write (sys->hdl, block->p_buffer, block->i_buffer);
sys->delay += block->i_nb_samples;
while (block->i_buffer > 0 && !sio_eof (sys->hdl))
{
size_t bytes = sio_write (sys->hdl, block->p_buffer, block->i_buffer);
block->p_buffer += bytes;
block->i_buffer -= bytes;
/* Note that i_nb_samples and i_pts are not updated here. */
}
block_Release (block); block_Release (block);
} }
static void Flush (audio_output_t *aout, bool wait) static void Flush (audio_output_t *aout, bool wait)
{ {
if (wait) aout_sys_t *sys = aout->sys;
{
long long frames = sys->write_offset - sys->read_offset;
if (frames > 0) sio_stop (sys->hdl);
msleep (frames * CLOCK_FREQ / sys->rate); sys->started = 0;
} sys->delay = 0;
else sio_start (sys->hdl);
{ (void)wait;
sio_stop (sys->hdl);
sys->read_offset = 0;
sys->write_offset = 0;
sio_start (sys->hdl);
}
} }
static void VolumeChanged (void *arg, unsigned volume) static void VolumeChanged (void *arg, unsigned volume)
...@@ -267,8 +260,13 @@ static void VolumeChanged (void *arg, unsigned volume) ...@@ -267,8 +260,13 @@ static void VolumeChanged (void *arg, unsigned volume)
static int VolumeSet (audio_output_t *aout, float fvol) static int VolumeSet (audio_output_t *aout, float fvol)
{ {
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
unsigned volume = lroundf (fvol * SIO_MAXVOL); unsigned volume;
if (fvol < 0)
fvol = 0;
if (fvol > 1)
fvol = 1;
volume = lroundf (fvol * SIO_MAXVOL);
if (!sys->mute && !sio_setvol (sys->hdl, volume)) if (!sys->mute && !sio_setvol (sys->hdl, volume))
return -1; return -1;
sys->volume = volume; sys->volume = volume;
......
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