- Unbreak build with SNDIO option [1]

- Cosmetic fix

Reported by:	starikarp@yandex.com via email [1]
This commit is contained in:
Carlos J. Puga Medina 2018-08-19 00:28:41 +00:00
parent 1ad82fd45a
commit 21b280784c
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=477549
5 changed files with 18 additions and 23 deletions

View file

@ -60,6 +60,7 @@ RUN_DEPENDS= xdg-open:devel/xdg-utils \
noto-lite>0:x11-fonts/noto-lite
ONLY_FOR_ARCHS= amd64 i386
USES= bison desktop-file-utils jpeg ninja perl5 pkgconfig \
python:2.7,build shebangfix tar:xz
USE_GL= gl

View file

@ -73,7 +73,7 @@ AudioParameters AudioManagerOpenBSD::GetInputStreamParameters(
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
kDefaultSampleRate, buffer_size);
kDefaultSampleRate, 16, buffer_size);
}
AudioManagerOpenBSD::AudioManagerOpenBSD(std::unique_ptr<AudioThread> audio_thread,
@ -130,8 +130,10 @@ AudioParameters AudioManagerOpenBSD::GetPreferredOutputStreamParameters(
ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
int sample_rate = kDefaultSampleRate;
int buffer_size = kDefaultOutputBufferSize;
int bits_per_sample = 16;
if (input_params.IsValid()) {
sample_rate = input_params.sample_rate();
bits_per_sample = input_params.bits_per_sample();
channel_layout = input_params.channel_layout();
buffer_size = std::min(buffer_size, input_params.frames_per_buffer());
}
@ -142,7 +144,7 @@ AudioParameters AudioManagerOpenBSD::GetPreferredOutputStreamParameters(
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
sample_rate, buffer_size);
sample_rate, bits_per_sample, buffer_size);
}
AudioInputStream* AudioManagerOpenBSD::MakeInputStream(

View file

@ -15,13 +15,11 @@
namespace media {
static const SampleFormat kSampleFormat = kSampleFormatS16;
void sndio_in_onmove(void *arg, int delta) {
NOTIMPLEMENTED();
SndioAudioInputStream* self = static_cast<SndioAudioInputStream*>(arg);
self->hw_delay_ = delta - self->params_.GetBytesPerFrame(kSampleFormat);
self->hw_delay_ = delta - self->params_.GetBytesPerFrame();
}
void *sndio_in_threadstart(void *arg) {
@ -38,7 +36,9 @@ SndioAudioInputStream::SndioAudioInputStream(AudioManagerBase* audio_manager,
: audio_manager_(audio_manager),
device_name_(device_name),
params_(params),
bytes_per_buffer_(params.GetBytesPerBuffer(kSampleFormat)),
bytes_per_buffer_(params.frames_per_buffer() *
(params.channels() * params.bits_per_sample()) /
8),
buffer_duration_(base::TimeDelta::FromMicroseconds(
params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond /
static_cast<float>(params.sample_rate()))),
@ -66,7 +66,7 @@ bool SndioAudioInputStream::Open() {
sio_initpar(&par);
par.rate = params_.sample_rate();
par.pchan = params_.channels();
par.bits = SampleFormatToBytesPerChannel(kSampleFormat);
par.bits = params_.bits_per_sample();
par.bps = par.bits / 8;
par.sig = sig = par.bits != 8 ? 1 : 0;
par.le = SIO_LE_NATIVE;
@ -88,7 +88,7 @@ bool SndioAudioInputStream::Open() {
if (par.rate != (unsigned int)params_.sample_rate() ||
par.pchan != (unsigned int)params_.channels() ||
par.bits != (unsigned int)SampleFormatToBytesPerChannel(kSampleFormat) ||
par.bits != (unsigned int)params_.bits_per_sample() ||
par.sig != (unsigned int)sig ||
(par.bps > 1 && par.le != SIO_LE_NATIVE) ||
(par.bits != par.bps * 8)) {
@ -162,9 +162,4 @@ bool SndioAudioInputStream::IsMuted() {
return false;
}
void SndioAudioInputStream::SetOutputDeviceForAec(
const std::string& output_device_id) {
// Not supported. Do nothing.
}
} // namespace media

View file

@ -59,7 +59,6 @@ class SndioAudioInputStream : public AgcAudioStream<AudioInputStream> {
void SetVolume(double volume) override;
double GetVolume() override;
bool IsMuted() override;
void SetOutputDeviceForAec(const std::string& output_device_id) override;
// C-linkage call-backs are friends to access private data
friend void sndio_in_onmove(void *arg, int delta);

View file

@ -11,8 +11,6 @@
namespace media {
static const SampleFormat kSampleFormat = kSampleFormatS16;
void sndio_onmove(void *arg, int delta) {
SndioAudioOutputStream* self = static_cast<SndioAudioOutputStream*>(arg);
@ -37,7 +35,7 @@ SndioAudioOutputStream::SndioAudioOutputStream(const AudioParameters& params,
: manager(manager),
params(params),
audio_bus(AudioBus::Create(params)),
bytes_per_frame(params.GetBytesPerFrame(kSampleFormat)),
bytes_per_frame(params.GetBytesPerFrame()),
state(kClosed),
mutex(PTHREAD_MUTEX_INITIALIZER) {
}
@ -59,7 +57,7 @@ bool SndioAudioOutputStream::Open() {
sio_initpar(&par);
par.rate = params.sample_rate();
par.pchan = params.channels();
par.bits = SampleFormatToBitsPerChannel(kSampleFormat);
par.bits = params.bits_per_sample();
par.bps = par.bits / 8;
par.sig = sig = par.bits != 8 ? 1 : 0;
par.le = SIO_LE_NATIVE;
@ -76,7 +74,7 @@ bool SndioAudioOutputStream::Open() {
}
if (par.rate != (unsigned int)params.sample_rate() ||
par.pchan != (unsigned int)params.channels() ||
par.bits != (unsigned int)SampleFormatToBitsPerChannel(kSampleFormat) ||
par.bits != (unsigned int)params.bits_per_sample() ||
par.sig != (unsigned int)sig ||
(par.bps > 1 && par.le != SIO_LE_NATIVE) ||
(par.bits != par.bps * 8)) {
@ -86,7 +84,7 @@ bool SndioAudioOutputStream::Open() {
state = kStopped;
volpending = 0;
vol = 0;
buffer = new char[audio_bus->frames() * params.GetBytesPerFrame(kSampleFormat)];
buffer = new char[audio_bus->frames() * params.GetBytesPerFrame()];
sio_onmove(hdl, sndio_onmove, this);
sio_onvol(hdl, sndio_onvol, this);
return true;
@ -155,16 +153,16 @@ void SndioAudioOutputStream::RealTimeThread(void) {
// Get data to play
const base::TimeDelta delay = AudioTimestampHelper::FramesToTime(hw_delay, params.sample_rate() * 1000);
count = source->OnMoreData(delay, base::TimeTicks::Now(), 0, audio_bus.get());
audio_bus->ToInterleaved(count, SampleFormatToBytesPerChannel(kSampleFormat), buffer);
audio_bus->ToInterleaved(count, params.bits_per_sample() / 8, buffer);
if (count == 0) {
// We have to submit something to the device
count = audio_bus->frames();
memset(buffer, 0, count * params.GetBytesPerFrame(kSampleFormat));
memset(buffer, 0, count * params.GetBytesPerFrame());
LOG(WARNING) << "No data to play, running empty cycle.";
}
// Submit data to the device
avail = count * params.GetBytesPerFrame(kSampleFormat);
avail = count * params.GetBytesPerFrame();
count = sio_write(hdl, buffer, avail);
if (count == 0) {
LOG(WARNING) << "Audio device disconnected.";