parent
4b2bb7c3c5
commit
47b5309104
|
@ -0,0 +1,148 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/metrics/histogram_macros.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
|
||||
#include "media/audio/openbsd/audio_manager_openbsd.h"
|
||||
|
||||
#include "media/audio/audio_device_description.h"
|
||||
#include "media/audio/audio_output_dispatcher.h"
|
||||
#include "media/audio/sndio/sndio_input.h"
|
||||
#include "media/audio/sndio/sndio_output.h"
|
||||
#include "media/base/limits.h"
|
||||
#include "media/base/media_switches.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
// Maximum number of output streams that can be open simultaneously.
|
||||
static const int kMaxOutputStreams = 4;
|
||||
|
||||
// Default sample rate for input and output streams.
|
||||
static const int kDefaultSampleRate = 48000;
|
||||
|
||||
void AddDefaultDevice(AudioDeviceNames* device_names) {
|
||||
DCHECK(device_names->empty());
|
||||
device_names->push_front(AudioDeviceName::CreateDefault());
|
||||
}
|
||||
|
||||
bool AudioManagerOpenBSD::HasAudioOutputDevices() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioManagerOpenBSD::HasAudioInputDevices() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioManagerOpenBSD::GetAudioInputDeviceNames(
|
||||
AudioDeviceNames* device_names) {
|
||||
DCHECK(device_names->empty());
|
||||
AddDefaultDevice(device_names);
|
||||
}
|
||||
|
||||
void AudioManagerOpenBSD::GetAudioOutputDeviceNames(
|
||||
AudioDeviceNames* device_names) {
|
||||
AddDefaultDevice(device_names);
|
||||
}
|
||||
|
||||
const char* AudioManagerOpenBSD::GetName() {
|
||||
return "SNDIO";
|
||||
}
|
||||
|
||||
AudioParameters AudioManagerOpenBSD::GetInputStreamParameters(
|
||||
const std::string& device_id) {
|
||||
static const int kDefaultInputBufferSize = 1024;
|
||||
|
||||
int user_buffer_size = GetUserBufferSize();
|
||||
int buffer_size = user_buffer_size ?
|
||||
user_buffer_size : kDefaultInputBufferSize;
|
||||
|
||||
return AudioParameters(
|
||||
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
|
||||
kDefaultSampleRate, buffer_size);
|
||||
}
|
||||
|
||||
AudioManagerOpenBSD::AudioManagerOpenBSD(std::unique_ptr<AudioThread> audio_thread,
|
||||
AudioLogFactory* audio_log_factory)
|
||||
: AudioManagerBase(std::move(audio_thread),
|
||||
audio_log_factory) {
|
||||
DLOG(WARNING) << "AudioManagerOpenBSD";
|
||||
SetMaxOutputStreamsAllowed(kMaxOutputStreams);
|
||||
}
|
||||
|
||||
AudioManagerOpenBSD::~AudioManagerOpenBSD() {
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream(
|
||||
const AudioParameters& params,
|
||||
const LogCallback& log_callback) {
|
||||
DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
|
||||
return MakeOutputStream(params);
|
||||
}
|
||||
|
||||
AudioOutputStream* AudioManagerOpenBSD::MakeLowLatencyOutputStream(
|
||||
const AudioParameters& params,
|
||||
const std::string& device_id,
|
||||
const LogCallback& log_callback) {
|
||||
DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!";
|
||||
DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
|
||||
return MakeOutputStream(params);
|
||||
}
|
||||
|
||||
AudioInputStream* AudioManagerOpenBSD::MakeLinearInputStream(
|
||||
const AudioParameters& params,
|
||||
const std::string& device_id,
|
||||
const LogCallback& log_callback) {
|
||||
DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
|
||||
return MakeInputStream(params);
|
||||
}
|
||||
|
||||
AudioInputStream* AudioManagerOpenBSD::MakeLowLatencyInputStream(
|
||||
const AudioParameters& params,
|
||||
const std::string& device_id,
|
||||
const LogCallback& log_callback) {
|
||||
DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
|
||||
return MakeInputStream(params);
|
||||
}
|
||||
|
||||
AudioParameters AudioManagerOpenBSD::GetPreferredOutputStreamParameters(
|
||||
const std::string& output_device_id,
|
||||
const AudioParameters& input_params) {
|
||||
// TODO(tommi): Support |output_device_id|.
|
||||
DLOG_IF(ERROR, !output_device_id.empty()) << "Not implemented!";
|
||||
static const int kDefaultOutputBufferSize = 2048;
|
||||
|
||||
ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
|
||||
int sample_rate = kDefaultSampleRate;
|
||||
int buffer_size = kDefaultOutputBufferSize;
|
||||
if (input_params.IsValid()) {
|
||||
sample_rate = input_params.sample_rate();
|
||||
channel_layout = input_params.channel_layout();
|
||||
buffer_size = std::min(buffer_size, input_params.frames_per_buffer());
|
||||
}
|
||||
|
||||
int user_buffer_size = GetUserBufferSize();
|
||||
if (user_buffer_size)
|
||||
buffer_size = user_buffer_size;
|
||||
|
||||
return AudioParameters(
|
||||
AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
|
||||
sample_rate, buffer_size);
|
||||
}
|
||||
|
||||
AudioInputStream* AudioManagerOpenBSD::MakeInputStream(
|
||||
const AudioParameters& params) {
|
||||
DLOG(WARNING) << "MakeInputStream";
|
||||
return new SndioAudioInputStream(this,
|
||||
AudioDeviceDescription::kDefaultDeviceId, params);
|
||||
}
|
||||
|
||||
AudioOutputStream* AudioManagerOpenBSD::MakeOutputStream(
|
||||
const AudioParameters& params) {
|
||||
DLOG(WARNING) << "MakeOutputStream";
|
||||
return new SndioAudioOutputStream(params, this);
|
||||
}
|
||||
|
||||
} // namespace media
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_
|
||||
#define MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "media/audio/audio_manager_base.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
class MEDIA_EXPORT AudioManagerOpenBSD : public AudioManagerBase {
|
||||
public:
|
||||
AudioManagerOpenBSD(std::unique_ptr<AudioThread> audio_thread,
|
||||
AudioLogFactory* audio_log_factory);
|
||||
~AudioManagerOpenBSD() override;
|
||||
|
||||
// Implementation of AudioManager.
|
||||
bool HasAudioOutputDevices() override;
|
||||
bool HasAudioInputDevices() override;
|
||||
void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override;
|
||||
void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override;
|
||||
AudioParameters GetInputStreamParameters(
|
||||
const std::string& device_id) override;
|
||||
const char* GetName() override;
|
||||
|
||||
// Implementation of AudioManagerBase.
|
||||
AudioOutputStream* MakeLinearOutputStream(
|
||||
const AudioParameters& params,
|
||||
const LogCallback& log_callback) override;
|
||||
AudioOutputStream* MakeLowLatencyOutputStream(
|
||||
const AudioParameters& params,
|
||||
const std::string& device_id,
|
||||
const LogCallback& log_callback) override;
|
||||
AudioInputStream* MakeLinearInputStream(
|
||||
const AudioParameters& params,
|
||||
const std::string& device_id,
|
||||
const LogCallback& log_callback) override;
|
||||
AudioInputStream* MakeLowLatencyInputStream(
|
||||
const AudioParameters& params,
|
||||
const std::string& device_id,
|
||||
const LogCallback& log_callback) override;
|
||||
|
||||
protected:
|
||||
AudioParameters GetPreferredOutputStreamParameters(
|
||||
const std::string& output_device_id,
|
||||
const AudioParameters& input_params) override;
|
||||
|
||||
private:
|
||||
// Called by MakeLinearOutputStream and MakeLowLatencyOutputStream.
|
||||
AudioOutputStream* MakeOutputStream(const AudioParameters& params);
|
||||
AudioInputStream* MakeInputStream(const AudioParameters& params);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AudioManagerOpenBSD);
|
||||
};
|
||||
|
||||
} // namespace media
|
||||
|
||||
#endif // MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_
|
|
@ -0,0 +1,201 @@
|
|||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "media/base/audio_timestamp_helper.h"
|
||||
#include "media/audio/openbsd/audio_manager_openbsd.h"
|
||||
#include "media/audio/audio_manager.h"
|
||||
#include "media/audio/sndio/sndio_input.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
static const SampleFormat kSampleFormat = kSampleFormatS16;
|
||||
|
||||
void SndioAudioInputStream::OnMoveCallback(void *arg, int delta)
|
||||
{
|
||||
SndioAudioInputStream* self = static_cast<SndioAudioInputStream*>(arg);
|
||||
|
||||
self->hw_delay += delta;
|
||||
}
|
||||
|
||||
void *SndioAudioInputStream::ThreadEntry(void *arg) {
|
||||
SndioAudioInputStream* self = static_cast<SndioAudioInputStream*>(arg);
|
||||
|
||||
self->ThreadLoop();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SndioAudioInputStream::SndioAudioInputStream(AudioManagerBase* manager,
|
||||
const std::string& device_name,
|
||||
const AudioParameters& params)
|
||||
: manager(manager),
|
||||
params(params),
|
||||
audio_bus(AudioBus::Create(params)),
|
||||
state(kClosed) {
|
||||
}
|
||||
|
||||
SndioAudioInputStream::~SndioAudioInputStream() {
|
||||
if (state != kClosed)
|
||||
Close();
|
||||
}
|
||||
|
||||
bool SndioAudioInputStream::Open() {
|
||||
struct sio_par par;
|
||||
int sig;
|
||||
|
||||
if (state != kClosed)
|
||||
return false;
|
||||
|
||||
if (params.format() != AudioParameters::AUDIO_PCM_LINEAR &&
|
||||
params.format() != AudioParameters::AUDIO_PCM_LOW_LATENCY) {
|
||||
LOG(WARNING) << "Unsupported audio format.";
|
||||
return false;
|
||||
}
|
||||
|
||||
sio_initpar(&par);
|
||||
par.rate = params.sample_rate();
|
||||
par.rchan = params.channels();
|
||||
par.bits = SampleFormatToBitsPerChannel(kSampleFormat);
|
||||
par.bps = par.bits / 8;
|
||||
par.sig = sig = par.bits != 8 ? 1 : 0;
|
||||
par.le = SIO_LE_NATIVE;
|
||||
par.appbufsz = params.frames_per_buffer();
|
||||
|
||||
hdl = sio_open(SIO_DEVANY, SIO_REC, 0);
|
||||
|
||||
if (hdl == NULL) {
|
||||
LOG(ERROR) << "Couldn't open audio device.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
|
||||
LOG(ERROR) << "Couldn't set audio parameters.";
|
||||
goto bad_close;
|
||||
}
|
||||
|
||||
if (par.rate != (unsigned int)params.sample_rate() ||
|
||||
par.rchan != (unsigned int)params.channels() ||
|
||||
par.bits != (unsigned int)SampleFormatToBitsPerChannel(kSampleFormat) ||
|
||||
par.sig != (unsigned int)sig ||
|
||||
(par.bps > 1 && par.le != SIO_LE_NATIVE) ||
|
||||
(par.bits != par.bps * 8)) {
|
||||
LOG(ERROR) << "Unsupported audio parameters.";
|
||||
goto bad_close;
|
||||
}
|
||||
state = kStopped;
|
||||
buffer = new char[audio_bus->frames() * params.GetBytesPerFrame(kSampleFormat)];
|
||||
sio_onmove(hdl, &OnMoveCallback, this);
|
||||
return true;
|
||||
bad_close:
|
||||
sio_close(hdl);
|
||||
return false;
|
||||
}
|
||||
|
||||
void SndioAudioInputStream::Start(AudioInputCallback* cb) {
|
||||
|
||||
StartAgc();
|
||||
|
||||
state = kRunning;
|
||||
hw_delay = 0;
|
||||
callback = cb;
|
||||
sio_start(hdl);
|
||||
if (pthread_create(&thread, NULL, &ThreadEntry, this) != 0) {
|
||||
LOG(ERROR) << "Failed to create real-time thread for recording.";
|
||||
sio_stop(hdl);
|
||||
state = kStopped;
|
||||
}
|
||||
}
|
||||
|
||||
void SndioAudioInputStream::Stop() {
|
||||
|
||||
if (state == kStopped)
|
||||
return;
|
||||
|
||||
state = kStopWait;
|
||||
pthread_join(thread, NULL);
|
||||
sio_stop(hdl);
|
||||
state = kStopped;
|
||||
|
||||
StopAgc();
|
||||
}
|
||||
|
||||
void SndioAudioInputStream::Close() {
|
||||
|
||||
if (state == kClosed)
|
||||
return;
|
||||
|
||||
if (state == kRunning)
|
||||
Stop();
|
||||
|
||||
state = kClosed;
|
||||
delete [] buffer;
|
||||
sio_close(hdl);
|
||||
|
||||
manager->ReleaseInputStream(this);
|
||||
}
|
||||
|
||||
double SndioAudioInputStream::GetMaxVolume() {
|
||||
// Not supported
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void SndioAudioInputStream::SetVolume(double volume) {
|
||||
// Not supported. Do nothing.
|
||||
}
|
||||
|
||||
double SndioAudioInputStream::GetVolume() {
|
||||
// Not supported.
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
bool SndioAudioInputStream::IsMuted() {
|
||||
// Not supported.
|
||||
return false;
|
||||
}
|
||||
|
||||
void SndioAudioInputStream::SetOutputDeviceForAec(
|
||||
const std::string& output_device_id) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
void SndioAudioInputStream::ThreadLoop(void) {
|
||||
size_t todo, n;
|
||||
char *data;
|
||||
unsigned int nframes;
|
||||
double normalized_volume = 0.0;
|
||||
|
||||
nframes = audio_bus->frames();
|
||||
|
||||
while (state == kRunning && !sio_eof(hdl)) {
|
||||
|
||||
GetAgcVolume(&normalized_volume);
|
||||
|
||||
// read one block
|
||||
todo = nframes * params.GetBytesPerFrame(kSampleFormat);
|
||||
data = buffer;
|
||||
while (todo > 0) {
|
||||
n = sio_read(hdl, data, todo);
|
||||
if (n == 0)
|
||||
return; // unrecoverable I/O error
|
||||
todo -= n;
|
||||
data += n;
|
||||
}
|
||||
hw_delay -= nframes;
|
||||
|
||||
// convert frames count to TimeDelta
|
||||
const base::TimeDelta delay = AudioTimestampHelper::FramesToTime(hw_delay,
|
||||
params.sample_rate());
|
||||
|
||||
// push into bus
|
||||
audio_bus->FromInterleaved(buffer, nframes, SampleFormatToBytesPerChannel(kSampleFormat));
|
||||
|
||||
// invoke callback
|
||||
callback->OnData(audio_bus.get(), base::TimeTicks::Now() - delay, 1.);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace media
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef MEDIA_AUDIO_SNDIO_SNDIO_INPUT_H_
|
||||
#define MEDIA_AUDIO_SNDIO_SNDIO_INPUT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <sndio.h>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/time/time.h"
|
||||
#include "media/audio/agc_audio_stream.h"
|
||||
#include "media/audio/audio_io.h"
|
||||
#include "media/audio/audio_device_description.h"
|
||||
#include "media/base/audio_parameters.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
class AudioManagerBase;
|
||||
|
||||
// Implementation of AudioOutputStream using sndio(7)
|
||||
class SndioAudioInputStream : public AgcAudioStream<AudioInputStream> {
|
||||
public:
|
||||
// Pass this to the constructor if you want to attempt auto-selection
|
||||
// of the audio recording device.
|
||||
static const char kAutoSelectDevice[];
|
||||
|
||||
// Create a PCM Output stream for the SNDIO device identified by
|
||||
// |device_name|. If unsure of what to use for |device_name|, use
|
||||
// |kAutoSelectDevice|.
|
||||
SndioAudioInputStream(AudioManagerBase* audio_manager,
|
||||
const std::string& device_name,
|
||||
const AudioParameters& params);
|
||||
|
||||
~SndioAudioInputStream() override;
|
||||
|
||||
// Implementation of AudioInputStream.
|
||||
bool Open() override;
|
||||
void Start(AudioInputCallback* callback) override;
|
||||
void Stop() override;
|
||||
void Close() override;
|
||||
double GetMaxVolume() override;
|
||||
void SetVolume(double volume) override;
|
||||
double GetVolume() override;
|
||||
bool IsMuted() override;
|
||||
void SetOutputDeviceForAec(const std::string& output_device_id) override;
|
||||
|
||||
private:
|
||||
|
||||
enum StreamState {
|
||||
kClosed, // Not opened yet
|
||||
kStopped, // Device opened, but not started yet
|
||||
kRunning, // Started, device playing
|
||||
kStopWait // Stopping, waiting for the real-time thread to exit
|
||||
};
|
||||
|
||||
// C-style call-backs
|
||||
static void OnMoveCallback(void *arg, int delta);
|
||||
static void* ThreadEntry(void *arg);
|
||||
|
||||
// Continuously moves data from the device to the consumer
|
||||
void ThreadLoop();
|
||||
// Our creator, the audio manager needs to be notified when we close.
|
||||
AudioManagerBase* manager;
|
||||
// Parameters of the source
|
||||
AudioParameters params;
|
||||
// We store data here for consumer
|
||||
std::unique_ptr<AudioBus> audio_bus;
|
||||
// Call-back that consumes recorded data
|
||||
AudioInputCallback* callback; // Valid during a recording session.
|
||||
// Handle of the audio device
|
||||
struct sio_hdl* hdl;
|
||||
// Current state of the stream
|
||||
enum StreamState state;
|
||||
// High priority thread running ThreadLoop()
|
||||
pthread_t thread;
|
||||
// Number of frames buffered in the hardware
|
||||
int hw_delay;
|
||||
// Temporary buffer where data is stored sndio-compatible format
|
||||
char* buffer;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SndioAudioInputStream);
|
||||
};
|
||||
|
||||
} // namespace media
|
||||
|
||||
#endif // MEDIA_AUDIO_SNDIO_SNDIO_INPUT_H_
|
|
@ -0,0 +1,183 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/time/default_tick_clock.h"
|
||||
#include "media/audio/audio_manager_base.h"
|
||||
#include "media/base/audio_timestamp_helper.h"
|
||||
#include "media/audio/sndio/sndio_output.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
static const SampleFormat kSampleFormat = kSampleFormatS16;
|
||||
|
||||
void SndioAudioOutputStream::OnMoveCallback(void *arg, int delta) {
|
||||
SndioAudioOutputStream* self = static_cast<SndioAudioOutputStream*>(arg);
|
||||
|
||||
self->hw_delay -= delta;
|
||||
}
|
||||
|
||||
void SndioAudioOutputStream::OnVolCallback(void *arg, unsigned int vol) {
|
||||
SndioAudioOutputStream* self = static_cast<SndioAudioOutputStream*>(arg);
|
||||
|
||||
self->vol = vol;
|
||||
}
|
||||
|
||||
void *SndioAudioOutputStream::ThreadEntry(void *arg) {
|
||||
SndioAudioOutputStream* self = static_cast<SndioAudioOutputStream*>(arg);
|
||||
|
||||
self->ThreadLoop();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SndioAudioOutputStream::SndioAudioOutputStream(const AudioParameters& params,
|
||||
AudioManagerBase* manager)
|
||||
: manager(manager),
|
||||
params(params),
|
||||
audio_bus(AudioBus::Create(params)),
|
||||
state(kClosed),
|
||||
mutex(PTHREAD_MUTEX_INITIALIZER) {
|
||||
}
|
||||
|
||||
SndioAudioOutputStream::~SndioAudioOutputStream() {
|
||||
if (state != kClosed)
|
||||
Close();
|
||||
}
|
||||
|
||||
bool SndioAudioOutputStream::Open() {
|
||||
struct sio_par par;
|
||||
int sig;
|
||||
|
||||
if (params.format() != AudioParameters::AUDIO_PCM_LINEAR &&
|
||||
params.format() != AudioParameters::AUDIO_PCM_LOW_LATENCY) {
|
||||
LOG(WARNING) << "Unsupported audio format.";
|
||||
return false;
|
||||
}
|
||||
sio_initpar(&par);
|
||||
par.rate = params.sample_rate();
|
||||
par.pchan = params.channels();
|
||||
par.bits = SampleFormatToBitsPerChannel(kSampleFormat);
|
||||
par.bps = par.bits / 8;
|
||||
par.sig = sig = par.bits != 8 ? 1 : 0;
|
||||
par.le = SIO_LE_NATIVE;
|
||||
par.appbufsz = params.frames_per_buffer();
|
||||
|
||||
hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
|
||||
if (hdl == NULL) {
|
||||
LOG(ERROR) << "Couldn't open audio device.";
|
||||
return false;
|
||||
}
|
||||
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
|
||||
LOG(ERROR) << "Couldn't set audio parameters.";
|
||||
goto bad_close;
|
||||
}
|
||||
if (par.rate != (unsigned int)params.sample_rate() ||
|
||||
par.pchan != (unsigned int)params.channels() ||
|
||||
par.bits != (unsigned int)SampleFormatToBitsPerChannel(kSampleFormat) ||
|
||||
par.sig != (unsigned int)sig ||
|
||||
(par.bps > 1 && par.le != SIO_LE_NATIVE) ||
|
||||
(par.bits != par.bps * 8)) {
|
||||
LOG(ERROR) << "Unsupported audio parameters.";
|
||||
goto bad_close;
|
||||
}
|
||||
state = kStopped;
|
||||
volpending = 0;
|
||||
vol = 0;
|
||||
buffer = new char[audio_bus->frames() * params.GetBytesPerFrame(kSampleFormat)];
|
||||
sio_onmove(hdl, &OnMoveCallback, this);
|
||||
sio_onvol(hdl, &OnVolCallback, this);
|
||||
return true;
|
||||
bad_close:
|
||||
sio_close(hdl);
|
||||
return false;
|
||||
}
|
||||
|
||||
void SndioAudioOutputStream::Close() {
|
||||
if (state == kClosed)
|
||||
return;
|
||||
if (state == kRunning)
|
||||
Stop();
|
||||
state = kClosed;
|
||||
delete [] buffer;
|
||||
sio_close(hdl);
|
||||
manager->ReleaseOutputStream(this); // Calls the destructor
|
||||
}
|
||||
|
||||
void SndioAudioOutputStream::Start(AudioSourceCallback* callback) {
|
||||
state = kRunning;
|
||||
hw_delay = 0;
|
||||
source = callback;
|
||||
sio_start(hdl);
|
||||
if (pthread_create(&thread, NULL, &ThreadEntry, this) != 0) {
|
||||
LOG(ERROR) << "Failed to create real-time thread.";
|
||||
sio_stop(hdl);
|
||||
state = kStopped;
|
||||
}
|
||||
}
|
||||
|
||||
void SndioAudioOutputStream::Stop() {
|
||||
if (state == kStopped)
|
||||
return;
|
||||
state = kStopWait;
|
||||
pthread_join(thread, NULL);
|
||||
sio_stop(hdl);
|
||||
state = kStopped;
|
||||
}
|
||||
|
||||
void SndioAudioOutputStream::SetVolume(double v) {
|
||||
pthread_mutex_lock(&mutex);
|
||||
vol = v * SIO_MAXVOL;
|
||||
volpending = 1;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
void SndioAudioOutputStream::GetVolume(double* v) {
|
||||
pthread_mutex_lock(&mutex);
|
||||
*v = vol * (1. / SIO_MAXVOL);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
// This stream is always used with sub second buffer sizes, where it's
|
||||
// sufficient to simply always flush upon Start().
|
||||
void SndioAudioOutputStream::Flush() {}
|
||||
|
||||
void SndioAudioOutputStream::ThreadLoop(void) {
|
||||
int avail, count, result;
|
||||
|
||||
while (state == kRunning) {
|
||||
// Update volume if needed
|
||||
pthread_mutex_lock(&mutex);
|
||||
if (volpending) {
|
||||
volpending = 0;
|
||||
sio_setvol(hdl, vol);
|
||||
}
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
// Get data to play
|
||||
const base::TimeDelta delay = AudioTimestampHelper::FramesToTime(hw_delay,
|
||||
params.sample_rate());
|
||||
count = source->OnMoreData(delay, base::TimeTicks::Now(), 0, audio_bus.get());
|
||||
audio_bus->ToInterleaved(count, SampleFormatToBytesPerChannel(kSampleFormat), buffer);
|
||||
if (count == 0) {
|
||||
// We have to submit something to the device
|
||||
count = audio_bus->frames();
|
||||
memset(buffer, 0, count * params.GetBytesPerFrame(kSampleFormat));
|
||||
LOG(WARNING) << "No data to play, running empty cycle.";
|
||||
}
|
||||
|
||||
// Submit data to the device
|
||||
avail = count * params.GetBytesPerFrame(kSampleFormat);
|
||||
result = sio_write(hdl, buffer, avail);
|
||||
if (result == 0) {
|
||||
LOG(WARNING) << "Audio device disconnected.";
|
||||
break;
|
||||
}
|
||||
|
||||
// Update hardware pointer
|
||||
hw_delay += count;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace media
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef MEDIA_AUDIO_SNDIO_SNDIO_OUTPUT_H_
|
||||
#define MEDIA_AUDIO_SNDIO_SNDIO_OUTPUT_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sndio.h>
|
||||
|
||||
#include "base/time/tick_clock.h"
|
||||
#include "base/time/time.h"
|
||||
#include "media/audio/audio_io.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
class AudioManagerBase;
|
||||
|
||||
// Implementation of AudioOutputStream using sndio(7)
|
||||
class SndioAudioOutputStream : public AudioOutputStream {
|
||||
public:
|
||||
// The manager is creating this object
|
||||
SndioAudioOutputStream(const AudioParameters& params,
|
||||
AudioManagerBase* manager);
|
||||
virtual ~SndioAudioOutputStream();
|
||||
|
||||
// Implementation of AudioOutputStream.
|
||||
bool Open() override;
|
||||
void Close() override;
|
||||
void Start(AudioSourceCallback* callback) override;
|
||||
void Stop() override;
|
||||
void SetVolume(double volume) override;
|
||||
void GetVolume(double* volume) override;
|
||||
void Flush() override;
|
||||
|
||||
friend void sndio_onmove(void *arg, int delta);
|
||||
friend void sndio_onvol(void *arg, unsigned int vol);
|
||||
friend void *sndio_threadstart(void *arg);
|
||||
|
||||
private:
|
||||
enum StreamState {
|
||||
kClosed, // Not opened yet
|
||||
kStopped, // Device opened, but not started yet
|
||||
kRunning, // Started, device playing
|
||||
kStopWait // Stopping, waiting for the real-time thread to exit
|
||||
};
|
||||
|
||||
// C-style call-backs
|
||||
static void OnMoveCallback(void *arg, int delta);
|
||||
static void OnVolCallback(void *arg, unsigned int vol);
|
||||
static void* ThreadEntry(void *arg);
|
||||
|
||||
// Continuously moves data from the producer to the device
|
||||
void ThreadLoop(void);
|
||||
|
||||
// Our creator, the audio manager needs to be notified when we close.
|
||||
AudioManagerBase* manager;
|
||||
// Parameters of the source
|
||||
AudioParameters params;
|
||||
// Source stores data here
|
||||
std::unique_ptr<AudioBus> audio_bus;
|
||||
// Call-back that produces data to play
|
||||
AudioSourceCallback* source;
|
||||
// Handle of the audio device
|
||||
struct sio_hdl* hdl;
|
||||
// Current state of the stream
|
||||
enum StreamState state;
|
||||
// High priority thread running ThreadLoop()
|
||||
pthread_t thread;
|
||||
// Protects vol, volpending and hw_delay
|
||||
pthread_mutex_t mutex;
|
||||
// Current volume in the 0..SIO_MAXVOL range
|
||||
int vol;
|
||||
// Set to 1 if volumes must be refreshed in the realtime thread
|
||||
int volpending;
|
||||
// Number of frames buffered in the hardware
|
||||
int hw_delay;
|
||||
// Temporary buffer where data is stored sndio-compatible format
|
||||
char* buffer;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SndioAudioOutputStream);
|
||||
};
|
||||
|
||||
} // namespace media
|
||||
|
||||
#endif // MEDIA_AUDIO_SNDIO_SNDIO_OUTPUT_H_
|
|
@ -0,0 +1,43 @@
|
|||
diff --git a/chromium/media/audio/linux/audio_manager_linux.cc b/chromium/media/audio/linux/audio_manager_linux.cc
|
||||
index 5d703549372..9e60b40c749 100644
|
||||
--- media/audio/linux/audio_manager_linux.cc
|
||||
+++ media/audio/linux/audio_manager_linux.cc
|
||||
@@ -20,6 +20,10 @@
|
||||
#include "media/audio/pulse/audio_manager_pulse.h"
|
||||
#include "media/audio/pulse/pulse_util.h"
|
||||
#endif
|
||||
+#if defined(USE_SNDIO)
|
||||
+#include <sndio.h>
|
||||
+#include "media/audio/openbsd/audio_manager_openbsd.h"
|
||||
+#endif
|
||||
|
||||
namespace media {
|
||||
|
||||
@@ -27,7 +31,8 @@ enum LinuxAudioIO {
|
||||
kPulse,
|
||||
kAlsa,
|
||||
kCras,
|
||||
- kAudioIOMax = kCras // Must always be equal to largest logged entry.
|
||||
+ kSndio,
|
||||
+ kAudioIOMax = kSndio // Must always be equal to largest logged entry.
|
||||
};
|
||||
|
||||
std::unique_ptr<media::AudioManager> CreateAudioManager(
|
||||
@@ -41,6 +46,17 @@ std::unique_ptr<media::AudioManager> CreateAudioManager(
|
||||
}
|
||||
#endif
|
||||
|
||||
+#if defined(USE_SNDIO)
|
||||
+ struct sio_hdl * hdl = NULL;
|
||||
+ if ((hdl=sio_open(SIO_DEVANY, SIO_PLAY, 1)) != NULL) {
|
||||
+ sio_close(hdl);
|
||||
+ UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kSndio, kAudioIOMax +1);
|
||||
+ return std::make_unique<AudioManagerOpenBSD>(std::move(audio_thread),
|
||||
+ audio_log_factory);
|
||||
+ }
|
||||
+ DVLOG(1) << "Sndio is not available on the OS";
|
||||
+#endif
|
||||
+
|
||||
#if defined(USE_PULSEAUDIO)
|
||||
pa_threaded_mainloop* pa_mainloop = nullptr;
|
||||
pa_context* pa_context = nullptr;
|
|
@ -0,0 +1,12 @@
|
|||
--- media/BUILD.gn 2020-03-24 10:16:30.000000000 +0100
|
||||
+++ - 2020-04-06 14:32:27.960817513 +0200
|
||||
@@ -65,6 +65,9 @@
|
||||
if (use_cras) {
|
||||
defines += [ "USE_CRAS" ]
|
||||
}
|
||||
+ if (use_sndio) {
|
||||
+ defines += [ "USE_SNDIO" ]
|
||||
+ }
|
||||
}
|
||||
|
||||
# Internal grouping of the configs necessary to support sub-folders having their
|
|
@ -0,0 +1,23 @@
|
|||
--- media/audio/BUILD.gn 2020-03-24 10:16:30.000000000 +0100
|
||||
+++ - 2020-04-06 14:31:28.871450217 +0200
|
||||
@@ -232,9 +232,19 @@
|
||||
deps += [ "//media/base/android:media_jni_headers" ]
|
||||
}
|
||||
|
||||
- if (is_linux) {
|
||||
+ if (is_linux && use_sndio) {
|
||||
sources += [ "linux/audio_manager_linux.cc" ]
|
||||
}
|
||||
+ if (use_sndio) {
|
||||
+ libs += [ "sndio" ]
|
||||
+ sources += [
|
||||
+ "openbsd/audio_manager_openbsd.cc",
|
||||
+ "sndio/sndio_input.cc",
|
||||
+ "sndio/sndio_input.h",
|
||||
+ "sndio/sndio_output.cc",
|
||||
+ "sndio/sndio_output.h"
|
||||
+ ]
|
||||
+ }
|
||||
|
||||
if (use_alsa) {
|
||||
libs += [ "asound" ]
|
|
@ -0,0 +1,12 @@
|
|||
--- media/media_options.gni 2020-03-24 10:16:30.000000000 +0100
|
||||
+++ - 2020-04-06 14:29:22.958630783 +0200
|
||||
@@ -114,6 +114,9 @@
|
||||
# Enables runtime selection of ALSA library for audio.
|
||||
use_alsa = false
|
||||
|
||||
+ # Enables runtime selection of sndio library for audio.
|
||||
+ use_sndio = false
|
||||
+
|
||||
# Alsa should be used on non-Android, non-Mac POSIX systems.
|
||||
# Alsa should be used on desktop Chromecast and audio-only Chromecast builds.
|
||||
if (is_posix && !is_android && !is_mac &&
|
|
@ -18,8 +18,8 @@
|
|||
#endif
|
||||
|
||||
MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
|
||||
--- qtwebengine/src/3rdparty/chromium/base/process/process_metrics_posix.cc 2017-11-28 14:06:53.000000000 +0100
|
||||
+++ qtwebengine/src/3rdparty/chromium/base/process/process_metrics_posix.cc 2018-01-27 20:48:11.571040348 +0100
|
||||
--- qtwebengine/src/3rdparty/chromium/base/process/process_metrics_posix.cc 2020-03-26 22:17:18.000000000 +0100
|
||||
++++ - 2020-04-08 13:30:26.065577091 +0200
|
||||
@@ -100,14 +100,14 @@
|
||||
malloc_statistics_t stats = {0};
|
||||
malloc_zone_statistics(nullptr, &stats);
|
||||
|
@ -27,7 +27,7 @@
|
|||
-#elif defined(OS_LINUX) || defined(OS_ANDROID)
|
||||
+#elif (defined(OS_LINUX) && defined(__GLIBC__)) || defined(OS_ANDROID)
|
||||
struct mallinfo minfo = mallinfo();
|
||||
#if defined(USE_TCMALLOC)
|
||||
#if BUILDFLAG(USE_TCMALLOC)
|
||||
return minfo.uordblks;
|
||||
#else
|
||||
return minfo.hblkhd + minfo.arena;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
|||
--- a/src/buildtools/config/linux.pri 2020-03-24 10:16:30.000000000 +0100
|
||||
+++ - 2020-04-06 14:42:50.189729758 +0200
|
||||
@@ -190,6 +190,11 @@
|
||||
} else {
|
||||
gn_args += use_alsa=false
|
||||
}
|
||||
+ qtConfig(webengine-sndio) {
|
||||
+ gn_args += use_sndio=true
|
||||
+ } else {
|
||||
+ gn_args += use_sndio=true
|
||||
+ }
|
||||
!packagesExist(libpci): gn_args += use_libpci=false
|
||||
|
||||
qtConfig(webengine-ozone-x11) {
|
|
@ -0,0 +1,56 @@
|
|||
--- a/src/core/configure.json 2020-03-24 10:16:30.000000000 +0100
|
||||
+++ - 2020-04-06 14:28:00.591236926 +0200
|
||||
@@ -21,6 +21,7 @@
|
||||
"webengine-printing-and-pdf": "boolean",
|
||||
"webengine-proprietary-codecs": "boolean",
|
||||
"webengine-pulseaudio": "boolean",
|
||||
+ "webengine-sndio": "boolean",
|
||||
"webengine-spellchecker": "boolean",
|
||||
"webengine-native-spellchecker": "boolean",
|
||||
"webengine-extensions": "boolean",
|
||||
@@ -31,6 +32,7 @@
|
||||
"webengine-kerberos": "boolean",
|
||||
"alsa": { "type": "boolean", "name": "webengine-alsa" },
|
||||
"pulseaudio": { "type": "boolean", "name": "webengine-pulseaudio" },
|
||||
+ "sndio": { "type": "boolean", "name": "webengine-sndio" },
|
||||
"ffmpeg": { "type": "enum", "name": "webengine-system-ffmpeg", "values": { "system": "yes", "qt": "no" } },
|
||||
"opus": { "type": "enum", "name": "webengine-system-opus", "values": { "system": "yes", "qt": "no" } },
|
||||
"webp": { "type": "enum", "name": "webengine-system-libwebp", "values": { "system": "yes", "qt": "no" } },
|
||||
@@ -68,7 +70,13 @@
|
||||
"sources": [
|
||||
{ "type": "pkgConfig", "args": "libpulse >= 0.9.10 libpulse-mainloop-glib" }
|
||||
]
|
||||
- }
|
||||
+ },
|
||||
+ "sndio": {
|
||||
+ "label": "sndio",
|
||||
+ "sources": [
|
||||
+ { "type": "pkgConfig", "args": "libsndio >= 1.5.0 libsndio" }
|
||||
+ ]
|
||||
+ }
|
||||
},
|
||||
"tests" : {
|
||||
"webengine-host-compiler": {
|
||||
@@ -136,6 +144,10 @@
|
||||
"condition": "libs.webengine-pulseaudio",
|
||||
"output": [ "privateFeature" ]
|
||||
},
|
||||
+ "webengine-sndio": {
|
||||
+ "label": "Use sndio",
|
||||
+ "output": [ "privateFeature" ]
|
||||
+ },
|
||||
"webengine-pepper-plugins": {
|
||||
"label": "Pepper Plugins",
|
||||
"purpose": "Enables use of Pepper Flash plugins.",
|
||||
@@ -308,6 +320,11 @@
|
||||
"condition": "config.unix"
|
||||
},
|
||||
{
|
||||
+ "type": "feature",
|
||||
+ "args": "webengine-sndio",
|
||||
+ "condition": "config.unix"
|
||||
+ },
|
||||
+ {
|
||||
"type": "feature",
|
||||
"args": "webengine-sanitizer",
|
||||
"condition": "config.sanitizer"
|
|
@ -1,7 +1,7 @@
|
|||
# Template file for 'qt5-webengine'
|
||||
pkgname=qt5-webengine
|
||||
version=5.14.2
|
||||
revision=4
|
||||
version=5.15.0
|
||||
revision=1
|
||||
archs="x86_64* i686* armv[67]* ppc64* aarch64*"
|
||||
wrksrc="qtwebengine-everywhere-src-${version}"
|
||||
build_style=qmake
|
||||
|
@ -9,26 +9,25 @@ configure_args="--
|
|||
-webengine-icu -webengine-ffmpeg -webengine-opus -webengine-webp
|
||||
-webengine-pepper-plugins -webengine-printing-and-pdf -webengine-proprietary-codecs
|
||||
-webengine-pulseaudio -webengine-spellchecker -webengine-webrtc -webengine-geolocation
|
||||
$(vopt_if snapshot '' '-no')-webengine-v8-snapshot -webengine-kerberos"
|
||||
$(vopt_if sndio '-sndio') -webengine-kerberos"
|
||||
# Rely on auto detection (fails if forced for cross builds) -webengine-alsa
|
||||
hostmakedepends="qt5-qmake gperf ninja qt5-host-tools flex pkg-config
|
||||
which perl python protobuf"
|
||||
makedepends="qt5-webchannel-devel qt5-location-devel qt5-tools-devel
|
||||
makedepends="qt5-webchannel-devel qt5-location-devel qt5-tools-devel qt5-devel
|
||||
qt5-declarative-devel libevent-devel snappy-devel icu-devel ffmpeg-devel
|
||||
libwebp-devel opus-devel cups-devel nss-devel minizip-devel libxslt-devel
|
||||
libvpx-devel re2-devel libXtst-devel libXcursor-devel libXcomposite-devel
|
||||
jsoncpp-devel harfbuzz-devel lcms2-devel protobuf-devel pulseaudio-devel
|
||||
libXrandr-devel MesaLib-devel mit-krb5-devel alsa-lib-devel"
|
||||
libXrandr-devel MesaLib-devel mit-krb5-devel alsa-lib-devel $(vopt_if sndio sndio-devel)"
|
||||
short_desc="Cross-platform application and UI framework (QT5) - WebEngine component"
|
||||
maintainer="John <johnz@posteo.net>"
|
||||
license="GPL-3.0-or-later, LGPL-3.0-or-later"
|
||||
homepage="https://qt.io/"
|
||||
distfiles="http://download.qt.io/official_releases/qt/${version%.*}/${version}/submodules/qtwebengine-everywhere-src-${version}.tar.xz"
|
||||
checksum=e169d6a75d8c397e04f843bc1b9585950fb9a001255cd18d6293f66fa8a6c947
|
||||
checksum=c38e2fda7ed1b7d5a90f26abf231ec0715d78a5bc39a94673d8e39d75f04c5df
|
||||
patch_args="-Np1"
|
||||
|
||||
build_options="snapshot"
|
||||
build_options_default="snapshot"
|
||||
build_options="sndio"
|
||||
|
||||
if [ "$CROSS_BUILD" ]; then
|
||||
hostmakedepends+=" nss-devel libevent-devel qt5-location-devel
|
||||
|
@ -114,6 +113,22 @@ _cleanup_wrksrc_leak() {
|
|||
-e "s;${wrksrc}/qtbase;/usr/lib/qt5;g" \;
|
||||
}
|
||||
|
||||
post_patch() {
|
||||
if [ "$build_option_sndio" ]; then
|
||||
mkdir -p ${wrksrc}/src/3rdparty/chromium/media/audio/{sndio,openbsd}
|
||||
cp ${FILESDIR}/sndio-files/sndio_*put.* \
|
||||
${wrksrc}/src/3rdparty/chromium/media/audio/sndio
|
||||
cp ${FILESDIR}/sndio-files/audio_manager_openbsd.* \
|
||||
${wrksrc}/src/3rdparty/chromium/media/audio/openbsd
|
||||
for f in "${FILESDIR}"/sndio-patches/*.patch; do
|
||||
cd src/3rdparty/chromium/
|
||||
echo "Applying $f"
|
||||
patch -Np0 -i "$f"
|
||||
cd "$wrksrc"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
pre_configure() {
|
||||
export PATH=${PATH/\/builddir\/.xbps-qt5-webengine\/wrappers:/}
|
||||
cp ${FILESDIR}/resolv_compat.h ${wrksrc}/src/3rdparty/chromium/net/dns
|
||||
|
@ -155,7 +170,7 @@ pre_build() {
|
|||
}
|
||||
|
||||
qt5-webengine-devel_package() {
|
||||
depends="${sourcepkg}>=${version}_${revision}"
|
||||
depends="qt5-devel>=${version} ${sourcepkg}>=${version}_${revision}"
|
||||
short_desc+=" - development files"
|
||||
pkg_install() {
|
||||
vmove usr/include
|
||||
|
|
Loading…
Reference in New Issue