(Auto)update libjingle 75610402-> 75610402
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7194 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
699c46ac57
commit
80132e4d70
@ -1,761 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/alsasoundsystem.h"
|
||||
|
||||
#include "talk/sound/sounddevicelocator.h"
|
||||
#include "talk/sound/soundinputstreaminterface.h"
|
||||
#include "talk/sound/soundoutputstreaminterface.h"
|
||||
#include "webrtc/base/common.h"
|
||||
#include "webrtc/base/logging.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/base/stringutils.h"
|
||||
#include "webrtc/base/timeutils.h"
|
||||
#include "webrtc/base/worker.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// Lookup table from the cricket format enum in soundsysteminterface.h to
|
||||
// ALSA's enums.
|
||||
static const snd_pcm_format_t kCricketFormatToAlsaFormatTable[] = {
|
||||
// The order here must match the order in soundsysteminterface.h
|
||||
SND_PCM_FORMAT_S16_LE,
|
||||
};
|
||||
|
||||
// Lookup table for the size of a single sample of a given format.
|
||||
static const size_t kCricketFormatToSampleSizeTable[] = {
|
||||
// The order here must match the order in soundsysteminterface.h
|
||||
sizeof(int16_t), // 2
|
||||
};
|
||||
|
||||
// Minimum latency we allow, in microseconds. This is more or less arbitrary,
|
||||
// but it has to be at least large enough to be able to buffer data during a
|
||||
// missed context switch, and the typical Linux scheduling quantum is 10ms.
|
||||
static const int kMinimumLatencyUsecs = 20 * 1000;
|
||||
|
||||
// The latency we'll use for kNoLatencyRequirements (chosen arbitrarily).
|
||||
static const int kDefaultLatencyUsecs = kMinimumLatencyUsecs * 2;
|
||||
|
||||
// We translate newlines in ALSA device descriptions to hyphens.
|
||||
static const char kAlsaDescriptionSearch[] = "\n";
|
||||
static const char kAlsaDescriptionReplace[] = " - ";
|
||||
|
||||
class AlsaDeviceLocator : public SoundDeviceLocator {
|
||||
public:
|
||||
AlsaDeviceLocator(const std::string &name,
|
||||
const std::string &device_name)
|
||||
: SoundDeviceLocator(name, device_name) {
|
||||
// The ALSA descriptions have newlines in them, which won't show up in
|
||||
// a drop-down box. Replace them with hyphens.
|
||||
rtc::replace_substrs(kAlsaDescriptionSearch,
|
||||
sizeof(kAlsaDescriptionSearch) - 1,
|
||||
kAlsaDescriptionReplace,
|
||||
sizeof(kAlsaDescriptionReplace) - 1,
|
||||
&name_);
|
||||
}
|
||||
|
||||
virtual SoundDeviceLocator *Copy() const {
|
||||
return new AlsaDeviceLocator(*this);
|
||||
}
|
||||
};
|
||||
|
||||
// Functionality that is common to both AlsaInputStream and AlsaOutputStream.
|
||||
class AlsaStream {
|
||||
public:
|
||||
AlsaStream(AlsaSoundSystem *alsa,
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq)
|
||||
: alsa_(alsa),
|
||||
handle_(handle),
|
||||
frame_size_(frame_size),
|
||||
wait_timeout_ms_(wait_timeout_ms),
|
||||
flags_(flags),
|
||||
freq_(freq) {
|
||||
}
|
||||
|
||||
~AlsaStream() {
|
||||
Close();
|
||||
}
|
||||
|
||||
// Waits for the stream to be ready to accept/return more data, and returns
|
||||
// how much can be written/read, or 0 if we need to Wait() again.
|
||||
snd_pcm_uframes_t Wait() {
|
||||
snd_pcm_sframes_t frames;
|
||||
// Ideally we would not use snd_pcm_wait() and instead hook snd_pcm_poll_*
|
||||
// into PhysicalSocketServer, but PhysicalSocketServer is nasty enough
|
||||
// already and the current clients of SoundSystemInterface do not run
|
||||
// anything else on their worker threads, so snd_pcm_wait() is good enough.
|
||||
frames = symbol_table()->snd_pcm_avail_update()(handle_);
|
||||
if (frames < 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_avail_update(): " << GetError(frames);
|
||||
Recover(frames);
|
||||
return 0;
|
||||
} else if (frames > 0) {
|
||||
// Already ready, so no need to wait.
|
||||
return frames;
|
||||
}
|
||||
// Else no space/data available, so must wait.
|
||||
int ready = symbol_table()->snd_pcm_wait()(handle_, wait_timeout_ms_);
|
||||
if (ready < 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_wait(): " << GetError(ready);
|
||||
Recover(ready);
|
||||
return 0;
|
||||
} else if (ready == 0) {
|
||||
// Timeout, so nothing can be written/read right now.
|
||||
// We set the timeout to twice the requested latency, so continuous
|
||||
// timeouts are indicative of a problem, so log as a warning.
|
||||
LOG(LS_WARNING) << "Timeout while waiting on stream";
|
||||
return 0;
|
||||
}
|
||||
// Else ready > 0 (i.e., 1), so it's ready. Get count.
|
||||
frames = symbol_table()->snd_pcm_avail_update()(handle_);
|
||||
if (frames < 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_avail_update(): " << GetError(frames);
|
||||
Recover(frames);
|
||||
return 0;
|
||||
} else if (frames == 0) {
|
||||
// wait() said we were ready, so this ought to have been positive. Has
|
||||
// been observed to happen in practice though.
|
||||
LOG(LS_WARNING) << "Spurious wake-up";
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
||||
int CurrentDelayUsecs() {
|
||||
if (!(flags_ & SoundSystemInterface::FLAG_REPORT_LATENCY)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
snd_pcm_sframes_t delay;
|
||||
int err = symbol_table()->snd_pcm_delay()(handle_, &delay);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_delay(): " << GetError(err);
|
||||
Recover(err);
|
||||
// We'd rather continue playout/capture with an incorrect delay than stop
|
||||
// it altogether, so return a valid value.
|
||||
return 0;
|
||||
}
|
||||
// The delay is in frames. Convert to microseconds.
|
||||
return delay * rtc::kNumMicrosecsPerSec / freq_;
|
||||
}
|
||||
|
||||
// Used to recover from certain recoverable errors, principally buffer overrun
|
||||
// or underrun (identified as EPIPE). Without calling this the stream stays
|
||||
// in the error state forever.
|
||||
bool Recover(int error) {
|
||||
int err;
|
||||
err = symbol_table()->snd_pcm_recover()(
|
||||
handle_,
|
||||
error,
|
||||
// Silent; i.e., no logging on stderr.
|
||||
1);
|
||||
if (err != 0) {
|
||||
// Docs say snd_pcm_recover returns the original error if it is not one
|
||||
// of the recoverable ones, so this log message will probably contain the
|
||||
// same error twice.
|
||||
LOG(LS_ERROR) << "Unable to recover from \"" << GetError(error) << "\": "
|
||||
<< GetError(err);
|
||||
return false;
|
||||
}
|
||||
if (error == -EPIPE && // Buffer underrun/overrun.
|
||||
symbol_table()->snd_pcm_stream()(handle_) == SND_PCM_STREAM_CAPTURE) {
|
||||
// For capture streams we also have to repeat the explicit start() to get
|
||||
// data flowing again.
|
||||
err = symbol_table()->snd_pcm_start()(handle_);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_start(): " << GetError(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Close() {
|
||||
if (handle_) {
|
||||
int err;
|
||||
err = symbol_table()->snd_pcm_drop()(handle_);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_drop(): " << GetError(err);
|
||||
// Continue anyways.
|
||||
}
|
||||
err = symbol_table()->snd_pcm_close()(handle_);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_close(): " << GetError(err);
|
||||
// Continue anyways.
|
||||
}
|
||||
handle_ = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
AlsaSymbolTable *symbol_table() {
|
||||
return &alsa_->symbol_table_;
|
||||
}
|
||||
|
||||
snd_pcm_t *handle() {
|
||||
return handle_;
|
||||
}
|
||||
|
||||
const char *GetError(int err) {
|
||||
return alsa_->GetError(err);
|
||||
}
|
||||
|
||||
size_t frame_size() {
|
||||
return frame_size_;
|
||||
}
|
||||
|
||||
private:
|
||||
AlsaSoundSystem *alsa_;
|
||||
snd_pcm_t *handle_;
|
||||
size_t frame_size_;
|
||||
int wait_timeout_ms_;
|
||||
int flags_;
|
||||
int freq_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AlsaStream);
|
||||
};
|
||||
|
||||
// Implementation of an input stream. See soundinputstreaminterface.h regarding
|
||||
// thread-safety.
|
||||
class AlsaInputStream :
|
||||
public SoundInputStreamInterface,
|
||||
private rtc::Worker {
|
||||
public:
|
||||
AlsaInputStream(AlsaSoundSystem *alsa,
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq)
|
||||
: stream_(alsa, handle, frame_size, wait_timeout_ms, flags, freq),
|
||||
buffer_size_(0) {
|
||||
}
|
||||
|
||||
virtual ~AlsaInputStream() {
|
||||
bool success = StopReading();
|
||||
// We need that to live.
|
||||
VERIFY(success);
|
||||
}
|
||||
|
||||
virtual bool StartReading() {
|
||||
return StartWork();
|
||||
}
|
||||
|
||||
virtual bool StopReading() {
|
||||
return StopWork();
|
||||
}
|
||||
|
||||
virtual bool GetVolume(int *volume) {
|
||||
// TODO: Implement this.
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool SetVolume(int volume) {
|
||||
// TODO: Implement this.
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool Close() {
|
||||
return StopReading() && stream_.Close();
|
||||
}
|
||||
|
||||
virtual int LatencyUsecs() {
|
||||
return stream_.CurrentDelayUsecs();
|
||||
}
|
||||
|
||||
private:
|
||||
// Inherited from Worker.
|
||||
virtual void OnStart() {
|
||||
HaveWork();
|
||||
}
|
||||
|
||||
// Inherited from Worker.
|
||||
virtual void OnHaveWork() {
|
||||
// Block waiting for data.
|
||||
snd_pcm_uframes_t avail = stream_.Wait();
|
||||
if (avail > 0) {
|
||||
// Data is available.
|
||||
size_t size = avail * stream_.frame_size();
|
||||
if (size > buffer_size_) {
|
||||
// Must increase buffer size.
|
||||
buffer_.reset(new char[size]);
|
||||
buffer_size_ = size;
|
||||
}
|
||||
// Read all the data.
|
||||
snd_pcm_sframes_t read = stream_.symbol_table()->snd_pcm_readi()(
|
||||
stream_.handle(),
|
||||
buffer_.get(),
|
||||
avail);
|
||||
if (read < 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_readi(): " << GetError(read);
|
||||
stream_.Recover(read);
|
||||
} else if (read == 0) {
|
||||
// Docs say this shouldn't happen.
|
||||
ASSERT(false);
|
||||
LOG(LS_ERROR) << "No data?";
|
||||
} else {
|
||||
// Got data. Pass it off to the app.
|
||||
SignalSamplesRead(buffer_.get(),
|
||||
read * stream_.frame_size(),
|
||||
this);
|
||||
}
|
||||
}
|
||||
// Check for more data with no delay, after any pending messages are
|
||||
// dispatched.
|
||||
HaveWork();
|
||||
}
|
||||
|
||||
// Inherited from Worker.
|
||||
virtual void OnStop() {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
const char *GetError(int err) {
|
||||
return stream_.GetError(err);
|
||||
}
|
||||
|
||||
AlsaStream stream_;
|
||||
rtc::scoped_ptr<char[]> buffer_;
|
||||
size_t buffer_size_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AlsaInputStream);
|
||||
};
|
||||
|
||||
// Implementation of an output stream. See soundoutputstreaminterface.h
|
||||
// regarding thread-safety.
|
||||
class AlsaOutputStream :
|
||||
public SoundOutputStreamInterface,
|
||||
private rtc::Worker {
|
||||
public:
|
||||
AlsaOutputStream(AlsaSoundSystem *alsa,
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq)
|
||||
: stream_(alsa, handle, frame_size, wait_timeout_ms, flags, freq) {
|
||||
}
|
||||
|
||||
virtual ~AlsaOutputStream() {
|
||||
bool success = DisableBufferMonitoring();
|
||||
// We need that to live.
|
||||
VERIFY(success);
|
||||
}
|
||||
|
||||
virtual bool EnableBufferMonitoring() {
|
||||
return StartWork();
|
||||
}
|
||||
|
||||
virtual bool DisableBufferMonitoring() {
|
||||
return StopWork();
|
||||
}
|
||||
|
||||
virtual bool WriteSamples(const void *sample_data,
|
||||
size_t size) {
|
||||
if (size % stream_.frame_size() != 0) {
|
||||
// No client of SoundSystemInterface does this, so let's not support it.
|
||||
// (If we wanted to support it, we'd basically just buffer the fractional
|
||||
// frame until we get more data.)
|
||||
ASSERT(false);
|
||||
LOG(LS_ERROR) << "Writes with fractional frames are not supported";
|
||||
return false;
|
||||
}
|
||||
snd_pcm_uframes_t frames = size / stream_.frame_size();
|
||||
snd_pcm_sframes_t written = stream_.symbol_table()->snd_pcm_writei()(
|
||||
stream_.handle(),
|
||||
sample_data,
|
||||
frames);
|
||||
if (written < 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_writei(): " << GetError(written);
|
||||
stream_.Recover(written);
|
||||
return false;
|
||||
} else if (static_cast<snd_pcm_uframes_t>(written) < frames) {
|
||||
// Shouldn't happen. Drop the rest of the data.
|
||||
LOG(LS_ERROR) << "Stream wrote only " << written << " of " << frames
|
||||
<< " frames!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GetVolume(int *volume) {
|
||||
// TODO: Implement this.
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool SetVolume(int volume) {
|
||||
// TODO: Implement this.
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool Close() {
|
||||
return DisableBufferMonitoring() && stream_.Close();
|
||||
}
|
||||
|
||||
virtual int LatencyUsecs() {
|
||||
return stream_.CurrentDelayUsecs();
|
||||
}
|
||||
|
||||
private:
|
||||
// Inherited from Worker.
|
||||
virtual void OnStart() {
|
||||
HaveWork();
|
||||
}
|
||||
|
||||
// Inherited from Worker.
|
||||
virtual void OnHaveWork() {
|
||||
snd_pcm_uframes_t avail = stream_.Wait();
|
||||
if (avail > 0) {
|
||||
size_t space = avail * stream_.frame_size();
|
||||
SignalBufferSpace(space, this);
|
||||
}
|
||||
HaveWork();
|
||||
}
|
||||
|
||||
// Inherited from Worker.
|
||||
virtual void OnStop() {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
const char *GetError(int err) {
|
||||
return stream_.GetError(err);
|
||||
}
|
||||
|
||||
AlsaStream stream_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AlsaOutputStream);
|
||||
};
|
||||
|
||||
AlsaSoundSystem::AlsaSoundSystem() : initialized_(false) {}
|
||||
|
||||
AlsaSoundSystem::~AlsaSoundSystem() {
|
||||
// Not really necessary, because Terminate() doesn't really do anything.
|
||||
Terminate();
|
||||
}
|
||||
|
||||
bool AlsaSoundSystem::Init() {
|
||||
if (IsInitialized()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load libasound.
|
||||
if (!symbol_table_.Load()) {
|
||||
// Very odd for a Linux machine to not have a working libasound ...
|
||||
LOG(LS_ERROR) << "Failed to load symbol table";
|
||||
return false;
|
||||
}
|
||||
|
||||
initialized_ = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AlsaSoundSystem::Terminate() {
|
||||
if (!IsInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
initialized_ = false;
|
||||
|
||||
// We do not unload the symbol table because we may need it again soon if
|
||||
// Init() is called again.
|
||||
}
|
||||
|
||||
bool AlsaSoundSystem::EnumeratePlaybackDevices(
|
||||
SoundDeviceLocatorList *devices) {
|
||||
return EnumerateDevices(devices, false);
|
||||
}
|
||||
|
||||
bool AlsaSoundSystem::EnumerateCaptureDevices(
|
||||
SoundDeviceLocatorList *devices) {
|
||||
return EnumerateDevices(devices, true);
|
||||
}
|
||||
|
||||
bool AlsaSoundSystem::GetDefaultPlaybackDevice(SoundDeviceLocator **device) {
|
||||
return GetDefaultDevice(device);
|
||||
}
|
||||
|
||||
bool AlsaSoundSystem::GetDefaultCaptureDevice(SoundDeviceLocator **device) {
|
||||
return GetDefaultDevice(device);
|
||||
}
|
||||
|
||||
SoundOutputStreamInterface *AlsaSoundSystem::OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) {
|
||||
return OpenDevice<SoundOutputStreamInterface>(
|
||||
device,
|
||||
params,
|
||||
SND_PCM_STREAM_PLAYBACK,
|
||||
&AlsaSoundSystem::StartOutputStream);
|
||||
}
|
||||
|
||||
SoundInputStreamInterface *AlsaSoundSystem::OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) {
|
||||
return OpenDevice<SoundInputStreamInterface>(
|
||||
device,
|
||||
params,
|
||||
SND_PCM_STREAM_CAPTURE,
|
||||
&AlsaSoundSystem::StartInputStream);
|
||||
}
|
||||
|
||||
const char *AlsaSoundSystem::GetName() const {
|
||||
return "ALSA";
|
||||
}
|
||||
|
||||
bool AlsaSoundSystem::EnumerateDevices(
|
||||
SoundDeviceLocatorList *devices,
|
||||
bool capture_not_playback) {
|
||||
ClearSoundDeviceLocatorList(devices);
|
||||
|
||||
if (!IsInitialized()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *type = capture_not_playback ? "Input" : "Output";
|
||||
// dmix and dsnoop are only for playback and capture, respectively, but ALSA
|
||||
// stupidly includes them in both lists.
|
||||
const char *ignore_prefix = capture_not_playback ? "dmix:" : "dsnoop:";
|
||||
// (ALSA lists many more "devices" of questionable interest, but we show them
|
||||
// just in case the weird devices may actually be desirable for some
|
||||
// users/systems.)
|
||||
const char *ignore_default = "default";
|
||||
const char *ignore_null = "null";
|
||||
const char *ignore_pulse = "pulse";
|
||||
// The 'pulse' entry has a habit of mysteriously disappearing when you query
|
||||
// a second time. Remove it from our list. (GIPS lib did the same thing.)
|
||||
int err;
|
||||
|
||||
void **hints;
|
||||
err = symbol_table_.snd_device_name_hint()(-1, // All cards
|
||||
"pcm", // Only PCM devices
|
||||
&hints);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_device_name_hint(): " << GetError(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (void **list = hints; *list != NULL; ++list) {
|
||||
char *actual_type = symbol_table_.snd_device_name_get_hint()(*list, "IOID");
|
||||
if (actual_type) { // NULL means it's both.
|
||||
bool wrong_type = (strcmp(actual_type, type) != 0);
|
||||
free(actual_type);
|
||||
if (wrong_type) {
|
||||
// Wrong type of device (i.e., input vs. output).
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
char *name = symbol_table_.snd_device_name_get_hint()(*list, "NAME");
|
||||
if (!name) {
|
||||
LOG(LS_ERROR) << "Device has no name???";
|
||||
// Skip it.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Now check if we actually want to show this device.
|
||||
if (strcmp(name, ignore_default) != 0 &&
|
||||
strcmp(name, ignore_null) != 0 &&
|
||||
strcmp(name, ignore_pulse) != 0 &&
|
||||
!rtc::starts_with(name, ignore_prefix)) {
|
||||
|
||||
// Yes, we do.
|
||||
char *desc = symbol_table_.snd_device_name_get_hint()(*list, "DESC");
|
||||
if (!desc) {
|
||||
// Virtual devices don't necessarily have descriptions. Use their names
|
||||
// instead (not pretty!).
|
||||
desc = name;
|
||||
}
|
||||
|
||||
AlsaDeviceLocator *device = new AlsaDeviceLocator(desc, name);
|
||||
|
||||
devices->push_back(device);
|
||||
|
||||
if (desc != name) {
|
||||
free(desc);
|
||||
}
|
||||
}
|
||||
|
||||
free(name);
|
||||
}
|
||||
|
||||
err = symbol_table_.snd_device_name_free_hint()(hints);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_device_name_free_hint(): " << GetError(err);
|
||||
// Continue and return true anyways, since we did get the whole list.
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AlsaSoundSystem::GetDefaultDevice(SoundDeviceLocator **device) {
|
||||
if (!IsInitialized()) {
|
||||
return false;
|
||||
}
|
||||
*device = new AlsaDeviceLocator("Default device", "default");
|
||||
return true;
|
||||
}
|
||||
|
||||
inline size_t AlsaSoundSystem::FrameSize(const OpenParams ¶ms) {
|
||||
ASSERT(static_cast<int>(params.format) <
|
||||
ARRAY_SIZE(kCricketFormatToSampleSizeTable));
|
||||
return kCricketFormatToSampleSizeTable[params.format] * params.channels;
|
||||
}
|
||||
|
||||
template <typename StreamInterface>
|
||||
StreamInterface *AlsaSoundSystem::OpenDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms,
|
||||
snd_pcm_stream_t type,
|
||||
StreamInterface *(AlsaSoundSystem::*start_fn)(
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq)) {
|
||||
|
||||
if (!IsInitialized()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
StreamInterface *stream;
|
||||
int err;
|
||||
|
||||
const char *dev = static_cast<const AlsaDeviceLocator *>(device)->
|
||||
device_name().c_str();
|
||||
|
||||
snd_pcm_t *handle = NULL;
|
||||
err = symbol_table_.snd_pcm_open()(
|
||||
&handle,
|
||||
dev,
|
||||
type,
|
||||
// No flags.
|
||||
0);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_open(" << dev << "): " << GetError(err);
|
||||
return NULL;
|
||||
}
|
||||
LOG(LS_VERBOSE) << "Opening " << dev;
|
||||
ASSERT(handle); // If open succeeded, handle ought to be valid
|
||||
|
||||
// Compute requested latency in microseconds.
|
||||
int latency;
|
||||
if (params.latency == kNoLatencyRequirements) {
|
||||
latency = kDefaultLatencyUsecs;
|
||||
} else {
|
||||
// kLowLatency is 0, so we treat it the same as a request for zero latency.
|
||||
// Compute what the user asked for.
|
||||
latency = rtc::kNumMicrosecsPerSec *
|
||||
params.latency /
|
||||
params.freq /
|
||||
FrameSize(params);
|
||||
// And this is what we'll actually use.
|
||||
latency = rtc::_max(latency, kMinimumLatencyUsecs);
|
||||
}
|
||||
|
||||
ASSERT(static_cast<int>(params.format) <
|
||||
ARRAY_SIZE(kCricketFormatToAlsaFormatTable));
|
||||
|
||||
err = symbol_table_.snd_pcm_set_params()(
|
||||
handle,
|
||||
kCricketFormatToAlsaFormatTable[params.format],
|
||||
// SoundSystemInterface only supports interleaved audio.
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED,
|
||||
params.channels,
|
||||
params.freq,
|
||||
1, // Allow ALSA to resample.
|
||||
latency);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_set_params(): " << GetError(err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = symbol_table_.snd_pcm_prepare()(handle);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_prepare(): " << GetError(err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
stream = (this->*start_fn)(
|
||||
handle,
|
||||
FrameSize(params),
|
||||
// We set the wait time to twice the requested latency, so that wait
|
||||
// timeouts should be rare.
|
||||
2 * latency / rtc::kNumMicrosecsPerMillisec,
|
||||
params.flags,
|
||||
params.freq);
|
||||
if (stream) {
|
||||
return stream;
|
||||
}
|
||||
// Else fall through.
|
||||
|
||||
fail:
|
||||
err = symbol_table_.snd_pcm_close()(handle);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_close(): " << GetError(err);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SoundOutputStreamInterface *AlsaSoundSystem::StartOutputStream(
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq) {
|
||||
// Nothing to do here but instantiate the stream.
|
||||
return new AlsaOutputStream(
|
||||
this, handle, frame_size, wait_timeout_ms, flags, freq);
|
||||
}
|
||||
|
||||
SoundInputStreamInterface *AlsaSoundSystem::StartInputStream(
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq) {
|
||||
// Output streams start automatically once enough data has been written, but
|
||||
// input streams must be started manually or else snd_pcm_wait() will never
|
||||
// return true.
|
||||
int err;
|
||||
err = symbol_table_.snd_pcm_start()(handle);
|
||||
if (err != 0) {
|
||||
LOG(LS_ERROR) << "snd_pcm_start(): " << GetError(err);
|
||||
return NULL;
|
||||
}
|
||||
return new AlsaInputStream(
|
||||
this, handle, frame_size, wait_timeout_ms, flags, freq);
|
||||
}
|
||||
|
||||
inline const char *AlsaSoundSystem::GetError(int err) {
|
||||
return symbol_table_.snd_strerror()(err);
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_ALSASOUNDSYSTEM_H_
|
||||
#define TALK_SOUND_ALSASOUNDSYSTEM_H_
|
||||
|
||||
#include "talk/sound/alsasymboltable.h"
|
||||
#include "talk/sound/soundsysteminterface.h"
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class AlsaStream;
|
||||
class AlsaInputStream;
|
||||
class AlsaOutputStream;
|
||||
|
||||
// Sound system implementation for ALSA, the predominant sound device API on
|
||||
// Linux (but typically not used directly by applications anymore).
|
||||
class AlsaSoundSystem : public SoundSystemInterface {
|
||||
friend class AlsaStream;
|
||||
friend class AlsaInputStream;
|
||||
friend class AlsaOutputStream;
|
||||
public:
|
||||
static SoundSystemInterface *Create() {
|
||||
return new AlsaSoundSystem();
|
||||
}
|
||||
|
||||
AlsaSoundSystem();
|
||||
|
||||
virtual ~AlsaSoundSystem();
|
||||
|
||||
virtual bool Init();
|
||||
virtual void Terminate();
|
||||
|
||||
virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices);
|
||||
virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices);
|
||||
|
||||
virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device);
|
||||
virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device);
|
||||
|
||||
virtual SoundOutputStreamInterface *OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
virtual SoundInputStreamInterface *OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
|
||||
virtual const char *GetName() const;
|
||||
|
||||
private:
|
||||
bool IsInitialized() { return initialized_; }
|
||||
|
||||
bool EnumerateDevices(SoundDeviceLocatorList *devices,
|
||||
bool capture_not_playback);
|
||||
|
||||
bool GetDefaultDevice(SoundDeviceLocator **device);
|
||||
|
||||
static size_t FrameSize(const OpenParams ¶ms);
|
||||
|
||||
template <typename StreamInterface>
|
||||
StreamInterface *OpenDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms,
|
||||
snd_pcm_stream_t type,
|
||||
StreamInterface *(AlsaSoundSystem::*start_fn)(
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq));
|
||||
|
||||
SoundOutputStreamInterface *StartOutputStream(
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq);
|
||||
|
||||
SoundInputStreamInterface *StartInputStream(
|
||||
snd_pcm_t *handle,
|
||||
size_t frame_size,
|
||||
int wait_timeout_ms,
|
||||
int flags,
|
||||
int freq);
|
||||
|
||||
const char *GetError(int err);
|
||||
|
||||
bool initialized_;
|
||||
AlsaSymbolTable symbol_table_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AlsaSoundSystem);
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_ALSASOUNDSYSTEM_H_
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/alsasymboltable.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
#define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME ALSA_SYMBOLS_CLASS_NAME
|
||||
#define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST ALSA_SYMBOLS_LIST
|
||||
#define LATE_BINDING_SYMBOL_TABLE_DLL_NAME "libasound.so.2"
|
||||
#include "webrtc/base/latebindingsymboltable.cc.def"
|
||||
|
||||
} // namespace cricket
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_ALSASYMBOLTABLE_H_
|
||||
#define TALK_SOUND_ALSASYMBOLTABLE_H_
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include "webrtc/base/latebindingsymboltable.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
#define ALSA_SYMBOLS_CLASS_NAME AlsaSymbolTable
|
||||
// The ALSA symbols we need, as an X-Macro list.
|
||||
// This list must contain precisely every libasound function that is used in
|
||||
// alsasoundsystem.cc.
|
||||
#define ALSA_SYMBOLS_LIST \
|
||||
X(snd_device_name_free_hint) \
|
||||
X(snd_device_name_get_hint) \
|
||||
X(snd_device_name_hint) \
|
||||
X(snd_pcm_avail_update) \
|
||||
X(snd_pcm_close) \
|
||||
X(snd_pcm_delay) \
|
||||
X(snd_pcm_drop) \
|
||||
X(snd_pcm_open) \
|
||||
X(snd_pcm_prepare) \
|
||||
X(snd_pcm_readi) \
|
||||
X(snd_pcm_recover) \
|
||||
X(snd_pcm_set_params) \
|
||||
X(snd_pcm_start) \
|
||||
X(snd_pcm_stream) \
|
||||
X(snd_pcm_wait) \
|
||||
X(snd_pcm_writei) \
|
||||
X(snd_strerror)
|
||||
|
||||
#define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME ALSA_SYMBOLS_CLASS_NAME
|
||||
#define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST ALSA_SYMBOLS_LIST
|
||||
#include "webrtc/base/latebindingsymboltable.h.def"
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_ALSASYMBOLTABLE_H_
|
@ -1,105 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_AUTOMATICALLYCHOSENSOUNDSYSTEM_H_
|
||||
#define TALK_SOUND_AUTOMATICALLYCHOSENSOUNDSYSTEM_H_
|
||||
|
||||
#include "talk/sound/soundsysteminterface.h"
|
||||
#include "talk/sound/soundsystemproxy.h"
|
||||
#include "webrtc/base/common.h"
|
||||
#include "webrtc/base/logging.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// A function type that creates an instance of a sound system implementation.
|
||||
typedef SoundSystemInterface *(*SoundSystemCreator)();
|
||||
|
||||
// An AutomaticallyChosenSoundSystem is a sound system proxy that defers to
|
||||
// an instance of the first sound system implementation in a list that
|
||||
// successfully initializes.
|
||||
template <const SoundSystemCreator kSoundSystemCreators[], int kNumSoundSystems>
|
||||
class AutomaticallyChosenSoundSystem : public SoundSystemProxy {
|
||||
public:
|
||||
// Chooses and initializes the underlying sound system.
|
||||
virtual bool Init();
|
||||
// Terminates the underlying sound system implementation, but caches it for
|
||||
// future re-use.
|
||||
virtual void Terminate();
|
||||
|
||||
virtual const char *GetName() const;
|
||||
|
||||
private:
|
||||
rtc::scoped_ptr<SoundSystemInterface> sound_systems_[kNumSoundSystems];
|
||||
};
|
||||
|
||||
template <const SoundSystemCreator kSoundSystemCreators[], int kNumSoundSystems>
|
||||
bool AutomaticallyChosenSoundSystem<kSoundSystemCreators,
|
||||
kNumSoundSystems>::Init() {
|
||||
if (wrapped_) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < kNumSoundSystems; ++i) {
|
||||
if (!sound_systems_[i].get()) {
|
||||
sound_systems_[i].reset((*kSoundSystemCreators[i])());
|
||||
}
|
||||
if (sound_systems_[i]->Init()) {
|
||||
// This is the first sound system in the list to successfully
|
||||
// initialize, so we're done.
|
||||
wrapped_ = sound_systems_[i].get();
|
||||
break;
|
||||
}
|
||||
// Else it failed to initialize, so try the remaining ones.
|
||||
}
|
||||
if (!wrapped_) {
|
||||
LOG(LS_ERROR) << "Failed to find a usable sound system";
|
||||
return false;
|
||||
}
|
||||
LOG(LS_INFO) << "Selected " << wrapped_->GetName() << " sound system";
|
||||
return true;
|
||||
}
|
||||
|
||||
template <const SoundSystemCreator kSoundSystemCreators[], int kNumSoundSystems>
|
||||
void AutomaticallyChosenSoundSystem<kSoundSystemCreators,
|
||||
kNumSoundSystems>::Terminate() {
|
||||
if (!wrapped_) {
|
||||
return;
|
||||
}
|
||||
wrapped_->Terminate();
|
||||
wrapped_ = NULL;
|
||||
// We do not free the scoped_ptrs because we may be re-init'ed soon.
|
||||
}
|
||||
|
||||
template <const SoundSystemCreator kSoundSystemCreators[], int kNumSoundSystems>
|
||||
const char *AutomaticallyChosenSoundSystem<kSoundSystemCreators,
|
||||
kNumSoundSystems>::GetName() const {
|
||||
return wrapped_ ? wrapped_->GetName() : "automatic";
|
||||
}
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_AUTOMATICALLYCHOSENSOUNDSYSTEM_H_
|
@ -1,214 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/automaticallychosensoundsystem.h"
|
||||
#include "talk/sound/nullsoundsystem.h"
|
||||
#include "webrtc/base/gunit.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class NeverFailsToFailSoundSystem : public NullSoundSystem {
|
||||
public:
|
||||
// Overrides superclass.
|
||||
virtual bool Init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static SoundSystemInterface *Create() {
|
||||
return new NeverFailsToFailSoundSystem();
|
||||
}
|
||||
};
|
||||
|
||||
class InitCheckingSoundSystem1 : public NullSoundSystem {
|
||||
public:
|
||||
// Overrides superclass.
|
||||
virtual bool Init() {
|
||||
created_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
static SoundSystemInterface *Create() {
|
||||
return new InitCheckingSoundSystem1();
|
||||
}
|
||||
|
||||
static bool created_;
|
||||
};
|
||||
|
||||
bool InitCheckingSoundSystem1::created_ = false;
|
||||
|
||||
class InitCheckingSoundSystem2 : public NullSoundSystem {
|
||||
public:
|
||||
// Overrides superclass.
|
||||
virtual bool Init() {
|
||||
created_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
static SoundSystemInterface *Create() {
|
||||
return new InitCheckingSoundSystem2();
|
||||
}
|
||||
|
||||
static bool created_;
|
||||
};
|
||||
|
||||
bool InitCheckingSoundSystem2::created_ = false;
|
||||
|
||||
class DeletionCheckingSoundSystem1 : public NeverFailsToFailSoundSystem {
|
||||
public:
|
||||
virtual ~DeletionCheckingSoundSystem1() {
|
||||
deleted_ = true;
|
||||
}
|
||||
|
||||
static SoundSystemInterface *Create() {
|
||||
return new DeletionCheckingSoundSystem1();
|
||||
}
|
||||
|
||||
static bool deleted_;
|
||||
};
|
||||
|
||||
bool DeletionCheckingSoundSystem1::deleted_ = false;
|
||||
|
||||
class DeletionCheckingSoundSystem2 : public NeverFailsToFailSoundSystem {
|
||||
public:
|
||||
virtual ~DeletionCheckingSoundSystem2() {
|
||||
deleted_ = true;
|
||||
}
|
||||
|
||||
static SoundSystemInterface *Create() {
|
||||
return new DeletionCheckingSoundSystem2();
|
||||
}
|
||||
|
||||
static bool deleted_;
|
||||
};
|
||||
|
||||
bool DeletionCheckingSoundSystem2::deleted_ = false;
|
||||
|
||||
class DeletionCheckingSoundSystem3 : public NullSoundSystem {
|
||||
public:
|
||||
virtual ~DeletionCheckingSoundSystem3() {
|
||||
deleted_ = true;
|
||||
}
|
||||
|
||||
static SoundSystemInterface *Create() {
|
||||
return new DeletionCheckingSoundSystem3();
|
||||
}
|
||||
|
||||
static bool deleted_;
|
||||
};
|
||||
|
||||
bool DeletionCheckingSoundSystem3::deleted_ = false;
|
||||
|
||||
extern const SoundSystemCreator kSingleSystemFailingCreators[] = {
|
||||
&NeverFailsToFailSoundSystem::Create,
|
||||
};
|
||||
|
||||
TEST(AutomaticallyChosenSoundSystem, SingleSystemFailing) {
|
||||
AutomaticallyChosenSoundSystem<
|
||||
kSingleSystemFailingCreators,
|
||||
ARRAY_SIZE(kSingleSystemFailingCreators)> sound_system;
|
||||
EXPECT_FALSE(sound_system.Init());
|
||||
}
|
||||
|
||||
extern const SoundSystemCreator kSingleSystemSucceedingCreators[] = {
|
||||
&NullSoundSystem::Create,
|
||||
};
|
||||
|
||||
TEST(AutomaticallyChosenSoundSystem, SingleSystemSucceeding) {
|
||||
AutomaticallyChosenSoundSystem<
|
||||
kSingleSystemSucceedingCreators,
|
||||
ARRAY_SIZE(kSingleSystemSucceedingCreators)> sound_system;
|
||||
EXPECT_TRUE(sound_system.Init());
|
||||
}
|
||||
|
||||
extern const SoundSystemCreator
|
||||
kFailedFirstSystemResultsInUsingSecondCreators[] = {
|
||||
&NeverFailsToFailSoundSystem::Create,
|
||||
&NullSoundSystem::Create,
|
||||
};
|
||||
|
||||
TEST(AutomaticallyChosenSoundSystem, FailedFirstSystemResultsInUsingSecond) {
|
||||
AutomaticallyChosenSoundSystem<
|
||||
kFailedFirstSystemResultsInUsingSecondCreators,
|
||||
ARRAY_SIZE(kFailedFirstSystemResultsInUsingSecondCreators)> sound_system;
|
||||
EXPECT_TRUE(sound_system.Init());
|
||||
}
|
||||
|
||||
extern const SoundSystemCreator kEarlierEntriesHavePriorityCreators[] = {
|
||||
&InitCheckingSoundSystem1::Create,
|
||||
&InitCheckingSoundSystem2::Create,
|
||||
};
|
||||
|
||||
TEST(AutomaticallyChosenSoundSystem, EarlierEntriesHavePriority) {
|
||||
AutomaticallyChosenSoundSystem<
|
||||
kEarlierEntriesHavePriorityCreators,
|
||||
ARRAY_SIZE(kEarlierEntriesHavePriorityCreators)> sound_system;
|
||||
InitCheckingSoundSystem1::created_ = false;
|
||||
InitCheckingSoundSystem2::created_ = false;
|
||||
EXPECT_TRUE(sound_system.Init());
|
||||
EXPECT_TRUE(InitCheckingSoundSystem1::created_);
|
||||
EXPECT_FALSE(InitCheckingSoundSystem2::created_);
|
||||
}
|
||||
|
||||
extern const SoundSystemCreator kManySoundSystemsCreators[] = {
|
||||
&NullSoundSystem::Create,
|
||||
&NullSoundSystem::Create,
|
||||
&NullSoundSystem::Create,
|
||||
&NullSoundSystem::Create,
|
||||
&NullSoundSystem::Create,
|
||||
&NullSoundSystem::Create,
|
||||
&NullSoundSystem::Create,
|
||||
};
|
||||
|
||||
TEST(AutomaticallyChosenSoundSystem, ManySoundSystems) {
|
||||
AutomaticallyChosenSoundSystem<
|
||||
kManySoundSystemsCreators,
|
||||
ARRAY_SIZE(kManySoundSystemsCreators)> sound_system;
|
||||
EXPECT_TRUE(sound_system.Init());
|
||||
}
|
||||
|
||||
extern const SoundSystemCreator kDeletesAllCreatedSoundSystemsCreators[] = {
|
||||
&DeletionCheckingSoundSystem1::Create,
|
||||
&DeletionCheckingSoundSystem2::Create,
|
||||
&DeletionCheckingSoundSystem3::Create,
|
||||
};
|
||||
|
||||
TEST(AutomaticallyChosenSoundSystem, DeletesAllCreatedSoundSystems) {
|
||||
typedef AutomaticallyChosenSoundSystem<
|
||||
kDeletesAllCreatedSoundSystemsCreators,
|
||||
ARRAY_SIZE(kDeletesAllCreatedSoundSystemsCreators)> TestSoundSystem;
|
||||
TestSoundSystem *sound_system = new TestSoundSystem();
|
||||
DeletionCheckingSoundSystem1::deleted_ = false;
|
||||
DeletionCheckingSoundSystem2::deleted_ = false;
|
||||
DeletionCheckingSoundSystem3::deleted_ = false;
|
||||
EXPECT_TRUE(sound_system->Init());
|
||||
delete sound_system;
|
||||
EXPECT_TRUE(DeletionCheckingSoundSystem1::deleted_);
|
||||
EXPECT_TRUE(DeletionCheckingSoundSystem2::deleted_);
|
||||
EXPECT_TRUE(DeletionCheckingSoundSystem3::deleted_);
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/linuxsoundsystem.h"
|
||||
|
||||
#include "talk/sound/alsasoundsystem.h"
|
||||
#include "talk/sound/pulseaudiosoundsystem.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
const SoundSystemCreator kLinuxSoundSystemCreators[] = {
|
||||
#ifdef HAVE_LIBPULSE
|
||||
&PulseAudioSoundSystem::Create,
|
||||
#endif
|
||||
&AlsaSoundSystem::Create,
|
||||
};
|
||||
|
||||
} // namespace cricket
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_LINUXSOUNDSYSTEM_H_
|
||||
#define TALK_SOUND_LINUXSOUNDSYSTEM_H_
|
||||
|
||||
#include "talk/sound/automaticallychosensoundsystem.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
extern const SoundSystemCreator kLinuxSoundSystemCreators[
|
||||
#ifdef HAVE_LIBPULSE
|
||||
2
|
||||
#else
|
||||
1
|
||||
#endif
|
||||
];
|
||||
|
||||
// The vast majority of Linux systems use ALSA for the device-level sound API,
|
||||
// but an increasing number are using PulseAudio for the application API and
|
||||
// only using ALSA internally in PulseAudio itself. But like everything on
|
||||
// Linux this is user-configurable, so we need to support both and choose the
|
||||
// right one at run-time.
|
||||
// PulseAudioSoundSystem is designed to only successfully initialize if
|
||||
// PulseAudio is installed and running, and if it is running then direct device
|
||||
// access using ALSA typically won't work, so if PulseAudioSoundSystem
|
||||
// initializes then we choose that. Otherwise we choose ALSA.
|
||||
typedef AutomaticallyChosenSoundSystem<
|
||||
kLinuxSoundSystemCreators,
|
||||
ARRAY_SIZE(kLinuxSoundSystemCreators)> LinuxSoundSystem;
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_LINUXSOUNDSYSTEM_H_
|
@ -1,174 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/nullsoundsystem.h"
|
||||
|
||||
#include "talk/sound/sounddevicelocator.h"
|
||||
#include "talk/sound/soundinputstreaminterface.h"
|
||||
#include "talk/sound/soundoutputstreaminterface.h"
|
||||
#include "webrtc/base/logging.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
class Thread;
|
||||
|
||||
}
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// Name used for the single device and the sound system itself.
|
||||
static const char kNullName[] = "null";
|
||||
|
||||
class NullSoundDeviceLocator : public SoundDeviceLocator {
|
||||
public:
|
||||
NullSoundDeviceLocator() : SoundDeviceLocator(kNullName, kNullName) {}
|
||||
|
||||
virtual SoundDeviceLocator *Copy() const {
|
||||
return new NullSoundDeviceLocator();
|
||||
}
|
||||
};
|
||||
|
||||
class NullSoundInputStream : public SoundInputStreamInterface {
|
||||
public:
|
||||
virtual bool StartReading() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool StopReading() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GetVolume(int *volume) {
|
||||
*volume = SoundSystemInterface::kMinVolume;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool SetVolume(int volume) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool Close() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual int LatencyUsecs() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class NullSoundOutputStream : public SoundOutputStreamInterface {
|
||||
public:
|
||||
virtual bool EnableBufferMonitoring() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool DisableBufferMonitoring() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool WriteSamples(const void *sample_data,
|
||||
size_t size) {
|
||||
LOG(LS_VERBOSE) << "Got " << size << " bytes of playback samples";
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GetVolume(int *volume) {
|
||||
*volume = SoundSystemInterface::kMinVolume;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool SetVolume(int volume) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool Close() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual int LatencyUsecs() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
NullSoundSystem::~NullSoundSystem() {
|
||||
}
|
||||
|
||||
bool NullSoundSystem::Init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void NullSoundSystem::Terminate() {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
bool NullSoundSystem::EnumeratePlaybackDevices(
|
||||
SoundSystemInterface::SoundDeviceLocatorList *devices) {
|
||||
ClearSoundDeviceLocatorList(devices);
|
||||
SoundDeviceLocator *device;
|
||||
GetDefaultPlaybackDevice(&device);
|
||||
devices->push_back(device);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NullSoundSystem::EnumerateCaptureDevices(
|
||||
SoundSystemInterface::SoundDeviceLocatorList *devices) {
|
||||
ClearSoundDeviceLocatorList(devices);
|
||||
SoundDeviceLocator *device;
|
||||
GetDefaultCaptureDevice(&device);
|
||||
devices->push_back(device);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NullSoundSystem::GetDefaultPlaybackDevice(
|
||||
SoundDeviceLocator **device) {
|
||||
*device = new NullSoundDeviceLocator();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NullSoundSystem::GetDefaultCaptureDevice(
|
||||
SoundDeviceLocator **device) {
|
||||
*device = new NullSoundDeviceLocator();
|
||||
return true;
|
||||
}
|
||||
|
||||
SoundOutputStreamInterface *NullSoundSystem::OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) {
|
||||
return new NullSoundOutputStream();
|
||||
}
|
||||
|
||||
SoundInputStreamInterface *NullSoundSystem::OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) {
|
||||
return new NullSoundInputStream();
|
||||
}
|
||||
|
||||
const char *NullSoundSystem::GetName() const {
|
||||
return kNullName;
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_NULLSOUNDSYSTEM_H_
|
||||
#define TALK_SOUND_NULLSOUNDSYSTEM_H_
|
||||
|
||||
#include "talk/sound/soundsysteminterface.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class SoundDeviceLocator;
|
||||
class SoundInputStreamInterface;
|
||||
class SoundOutputStreamInterface;
|
||||
|
||||
// A simple reference sound system that drops output samples and generates
|
||||
// no input samples.
|
||||
class NullSoundSystem : public SoundSystemInterface {
|
||||
public:
|
||||
static SoundSystemInterface *Create() {
|
||||
return new NullSoundSystem();
|
||||
}
|
||||
|
||||
virtual ~NullSoundSystem();
|
||||
|
||||
virtual bool Init();
|
||||
virtual void Terminate();
|
||||
|
||||
virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices);
|
||||
virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices);
|
||||
|
||||
virtual SoundOutputStreamInterface *OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
virtual SoundInputStreamInterface *OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
|
||||
virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device);
|
||||
virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device);
|
||||
|
||||
virtual const char *GetName() const;
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_NULLSOUNDSYSTEM_H_
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/nullsoundsystemfactory.h"
|
||||
|
||||
#include "talk/sound/nullsoundsystem.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
NullSoundSystemFactory::NullSoundSystemFactory() {
|
||||
}
|
||||
|
||||
NullSoundSystemFactory::~NullSoundSystemFactory() {
|
||||
}
|
||||
|
||||
bool NullSoundSystemFactory::SetupInstance() {
|
||||
instance_.reset(new NullSoundSystem());
|
||||
return true;
|
||||
}
|
||||
|
||||
void NullSoundSystemFactory::CleanupInstance() {
|
||||
instance_.reset();
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_NULLSOUNDSYSTEMFACTORY_H_
|
||||
#define TALK_SOUND_NULLSOUNDSYSTEMFACTORY_H_
|
||||
|
||||
#include "talk/sound/soundsystemfactory.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// A SoundSystemFactory that always returns a NullSoundSystem. Intended for
|
||||
// testing.
|
||||
class NullSoundSystemFactory : public SoundSystemFactory {
|
||||
public:
|
||||
NullSoundSystemFactory();
|
||||
virtual ~NullSoundSystemFactory();
|
||||
|
||||
protected:
|
||||
// Inherited from SoundSystemFactory.
|
||||
virtual bool SetupInstance();
|
||||
virtual void CleanupInstance();
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_NULLSOUNDSYSTEMFACTORY_H_
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/platformsoundsystem.h"
|
||||
|
||||
#include "webrtc/base/common.h"
|
||||
#ifdef LINUX
|
||||
#include "talk/sound/linuxsoundsystem.h"
|
||||
#else
|
||||
#include "talk/sound/nullsoundsystem.h"
|
||||
#endif
|
||||
|
||||
namespace cricket {
|
||||
|
||||
SoundSystemInterface *CreatePlatformSoundSystem() {
|
||||
#ifdef LINUX
|
||||
return new LinuxSoundSystem();
|
||||
#else
|
||||
ASSERT(false && "Not implemented");
|
||||
return new NullSoundSystem();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_PLATFORMSOUNDSYSTEM_H_
|
||||
#define TALK_SOUND_PLATFORMSOUNDSYSTEM_H_
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class SoundSystemInterface;
|
||||
|
||||
// Creates the sound system implementation for this platform.
|
||||
SoundSystemInterface *CreatePlatformSoundSystem();
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_PLATFORMSOUNDSYSTEM_H_
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/platformsoundsystemfactory.h"
|
||||
|
||||
#include "talk/sound/platformsoundsystem.h"
|
||||
#include "talk/sound/soundsysteminterface.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
PlatformSoundSystemFactory::PlatformSoundSystemFactory() {
|
||||
}
|
||||
|
||||
PlatformSoundSystemFactory::~PlatformSoundSystemFactory() {
|
||||
}
|
||||
|
||||
bool PlatformSoundSystemFactory::SetupInstance() {
|
||||
if (!instance_.get()) {
|
||||
instance_.reset(CreatePlatformSoundSystem());
|
||||
}
|
||||
if (!instance_->Init()) {
|
||||
LOG(LS_ERROR) << "Can't initialize platform's sound system";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlatformSoundSystemFactory::CleanupInstance() {
|
||||
instance_->Terminate();
|
||||
// We do not delete the sound system because we might be re-initialized soon.
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_PLATFORMSOUNDSYSTEMFACTORY_H_
|
||||
#define TALK_SOUND_PLATFORMSOUNDSYSTEMFACTORY_H_
|
||||
|
||||
#include "talk/sound/soundsystemfactory.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// A SoundSystemFactory that returns the platform's native sound system
|
||||
// implementation.
|
||||
class PlatformSoundSystemFactory : public SoundSystemFactory {
|
||||
public:
|
||||
PlatformSoundSystemFactory();
|
||||
virtual ~PlatformSoundSystemFactory();
|
||||
|
||||
protected:
|
||||
// Inherited from SoundSystemFactory.
|
||||
virtual bool SetupInstance();
|
||||
virtual void CleanupInstance();
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_PLATFORMSOUNDSYSTEMFACTORY_H_
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,194 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_PULSEAUDIOSOUNDSYSTEM_H_
|
||||
#define TALK_SOUND_PULSEAUDIOSOUNDSYSTEM_H_
|
||||
|
||||
#ifdef HAVE_LIBPULSE
|
||||
|
||||
#include "talk/sound/pulseaudiosymboltable.h"
|
||||
#include "talk/sound/soundsysteminterface.h"
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class PulseAudioInputStream;
|
||||
class PulseAudioOutputStream;
|
||||
class PulseAudioStream;
|
||||
|
||||
// Sound system implementation for PulseAudio, a cross-platform sound server
|
||||
// (but commonly used only on Linux, which is the only platform we support
|
||||
// it on).
|
||||
// Init(), Terminate(), and the destructor should never be invoked concurrently,
|
||||
// but all other methods are thread-safe.
|
||||
class PulseAudioSoundSystem : public SoundSystemInterface {
|
||||
friend class PulseAudioInputStream;
|
||||
friend class PulseAudioOutputStream;
|
||||
friend class PulseAudioStream;
|
||||
public:
|
||||
static SoundSystemInterface *Create() {
|
||||
return new PulseAudioSoundSystem();
|
||||
}
|
||||
|
||||
PulseAudioSoundSystem();
|
||||
|
||||
virtual ~PulseAudioSoundSystem();
|
||||
|
||||
virtual bool Init();
|
||||
virtual void Terminate();
|
||||
|
||||
virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices);
|
||||
virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices);
|
||||
|
||||
virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device);
|
||||
virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device);
|
||||
|
||||
virtual SoundOutputStreamInterface *OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
virtual SoundInputStreamInterface *OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
|
||||
virtual const char *GetName() const;
|
||||
|
||||
private:
|
||||
bool IsInitialized();
|
||||
|
||||
static void ConnectToPulseCallbackThunk(pa_context *context, void *userdata);
|
||||
|
||||
void OnConnectToPulseCallback(pa_context *context, bool *connect_done);
|
||||
|
||||
bool ConnectToPulse(pa_context *context);
|
||||
|
||||
pa_context *CreateNewConnection();
|
||||
|
||||
template <typename InfoStruct>
|
||||
bool EnumerateDevices(SoundDeviceLocatorList *devices,
|
||||
pa_operation *(*enumerate_fn)(
|
||||
pa_context *c,
|
||||
void (*callback_fn)(
|
||||
pa_context *c,
|
||||
const InfoStruct *i,
|
||||
int eol,
|
||||
void *userdata),
|
||||
void *userdata),
|
||||
void (*callback_fn)(
|
||||
pa_context *c,
|
||||
const InfoStruct *i,
|
||||
int eol,
|
||||
void *userdata));
|
||||
|
||||
static void EnumeratePlaybackDevicesCallbackThunk(pa_context *unused,
|
||||
const pa_sink_info *info,
|
||||
int eol,
|
||||
void *userdata);
|
||||
|
||||
static void EnumerateCaptureDevicesCallbackThunk(pa_context *unused,
|
||||
const pa_source_info *info,
|
||||
int eol,
|
||||
void *userdata);
|
||||
|
||||
void OnEnumeratePlaybackDevicesCallback(
|
||||
SoundDeviceLocatorList *devices,
|
||||
const pa_sink_info *info,
|
||||
int eol);
|
||||
|
||||
void OnEnumerateCaptureDevicesCallback(
|
||||
SoundDeviceLocatorList *devices,
|
||||
const pa_source_info *info,
|
||||
int eol);
|
||||
|
||||
template <const char *(pa_server_info::*field)>
|
||||
static void GetDefaultDeviceCallbackThunk(
|
||||
pa_context *unused,
|
||||
const pa_server_info *info,
|
||||
void *userdata);
|
||||
|
||||
template <const char *(pa_server_info::*field)>
|
||||
void OnGetDefaultDeviceCallback(
|
||||
const pa_server_info *info,
|
||||
SoundDeviceLocator **device);
|
||||
|
||||
template <const char *(pa_server_info::*field)>
|
||||
bool GetDefaultDevice(SoundDeviceLocator **device);
|
||||
|
||||
static void StreamStateChangedCallbackThunk(pa_stream *stream,
|
||||
void *userdata);
|
||||
|
||||
void OnStreamStateChangedCallback(pa_stream *stream);
|
||||
|
||||
template <typename StreamInterface>
|
||||
StreamInterface *OpenDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms,
|
||||
const char *stream_name,
|
||||
StreamInterface *(PulseAudioSoundSystem::*connect_fn)(
|
||||
pa_stream *stream,
|
||||
const char *dev,
|
||||
int flags,
|
||||
pa_stream_flags_t pa_flags,
|
||||
int latency,
|
||||
const pa_sample_spec &spec));
|
||||
|
||||
SoundOutputStreamInterface *ConnectOutputStream(
|
||||
pa_stream *stream,
|
||||
const char *dev,
|
||||
int flags,
|
||||
pa_stream_flags_t pa_flags,
|
||||
int latency,
|
||||
const pa_sample_spec &spec);
|
||||
|
||||
SoundInputStreamInterface *ConnectInputStream(
|
||||
pa_stream *stream,
|
||||
const char *dev,
|
||||
int flags,
|
||||
pa_stream_flags_t pa_flags,
|
||||
int latency,
|
||||
const pa_sample_spec &spec);
|
||||
|
||||
bool FinishOperation(pa_operation *op);
|
||||
|
||||
void Lock();
|
||||
void Unlock();
|
||||
void Wait();
|
||||
void Signal();
|
||||
|
||||
const char *LastError();
|
||||
|
||||
pa_threaded_mainloop *mainloop_;
|
||||
pa_context *context_;
|
||||
PulseAudioSymbolTable symbol_table_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PulseAudioSoundSystem);
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // HAVE_LIBPULSE
|
||||
|
||||
#endif // TALK_SOUND_PULSEAUDIOSOUNDSYSTEM_H_
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBPULSE
|
||||
|
||||
#include "talk/sound/pulseaudiosymboltable.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
#define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME PULSE_AUDIO_SYMBOLS_CLASS_NAME
|
||||
#define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST PULSE_AUDIO_SYMBOLS_LIST
|
||||
#define LATE_BINDING_SYMBOL_TABLE_DLL_NAME "libpulse.so.0"
|
||||
#include "webrtc/base/latebindingsymboltable.cc.def"
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // HAVE_LIBPULSE
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_PULSEAUDIOSYMBOLTABLE_H_
|
||||
#define TALK_SOUND_PULSEAUDIOSYMBOLTABLE_H_
|
||||
|
||||
#include <pulse/context.h>
|
||||
#include <pulse/def.h>
|
||||
#include <pulse/error.h>
|
||||
#include <pulse/introspect.h>
|
||||
#include <pulse/stream.h>
|
||||
#include <pulse/thread-mainloop.h>
|
||||
|
||||
#include "webrtc/base/latebindingsymboltable.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
#define PULSE_AUDIO_SYMBOLS_CLASS_NAME PulseAudioSymbolTable
|
||||
// The PulseAudio symbols we need, as an X-Macro list.
|
||||
// This list must contain precisely every libpulse function that is used in
|
||||
// pulseaudiosoundsystem.cc.
|
||||
#define PULSE_AUDIO_SYMBOLS_LIST \
|
||||
X(pa_bytes_per_second) \
|
||||
X(pa_context_connect) \
|
||||
X(pa_context_disconnect) \
|
||||
X(pa_context_errno) \
|
||||
X(pa_context_get_protocol_version) \
|
||||
X(pa_context_get_server_info) \
|
||||
X(pa_context_get_sink_info_list) \
|
||||
X(pa_context_get_sink_input_info) \
|
||||
X(pa_context_get_source_info_by_index) \
|
||||
X(pa_context_get_source_info_list) \
|
||||
X(pa_context_get_state) \
|
||||
X(pa_context_new) \
|
||||
X(pa_context_set_sink_input_volume) \
|
||||
X(pa_context_set_source_volume_by_index) \
|
||||
X(pa_context_set_state_callback) \
|
||||
X(pa_context_unref) \
|
||||
X(pa_cvolume_set) \
|
||||
X(pa_operation_get_state) \
|
||||
X(pa_operation_unref) \
|
||||
X(pa_stream_connect_playback) \
|
||||
X(pa_stream_connect_record) \
|
||||
X(pa_stream_disconnect) \
|
||||
X(pa_stream_drop) \
|
||||
X(pa_stream_get_device_index) \
|
||||
X(pa_stream_get_index) \
|
||||
X(pa_stream_get_latency) \
|
||||
X(pa_stream_get_sample_spec) \
|
||||
X(pa_stream_get_state) \
|
||||
X(pa_stream_new) \
|
||||
X(pa_stream_peek) \
|
||||
X(pa_stream_readable_size) \
|
||||
X(pa_stream_set_buffer_attr) \
|
||||
X(pa_stream_set_overflow_callback) \
|
||||
X(pa_stream_set_read_callback) \
|
||||
X(pa_stream_set_state_callback) \
|
||||
X(pa_stream_set_underflow_callback) \
|
||||
X(pa_stream_set_write_callback) \
|
||||
X(pa_stream_unref) \
|
||||
X(pa_stream_writable_size) \
|
||||
X(pa_stream_write) \
|
||||
X(pa_strerror) \
|
||||
X(pa_threaded_mainloop_free) \
|
||||
X(pa_threaded_mainloop_get_api) \
|
||||
X(pa_threaded_mainloop_lock) \
|
||||
X(pa_threaded_mainloop_new) \
|
||||
X(pa_threaded_mainloop_signal) \
|
||||
X(pa_threaded_mainloop_start) \
|
||||
X(pa_threaded_mainloop_stop) \
|
||||
X(pa_threaded_mainloop_unlock) \
|
||||
X(pa_threaded_mainloop_wait)
|
||||
|
||||
#define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME PULSE_AUDIO_SYMBOLS_CLASS_NAME
|
||||
#define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST PULSE_AUDIO_SYMBOLS_LIST
|
||||
#include "webrtc/base/latebindingsymboltable.h.def"
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_PULSEAUDIOSYMBOLTABLE_H_
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_SOUNDDEVICELOCATOR_H_
|
||||
#define TALK_SOUND_SOUNDDEVICELOCATOR_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// A simple container for holding the name of a device and any additional id
|
||||
// information needed to locate and open it. Implementations of
|
||||
// SoundSystemInterface must subclass this to add any id information that they
|
||||
// need.
|
||||
class SoundDeviceLocator {
|
||||
public:
|
||||
virtual ~SoundDeviceLocator() {}
|
||||
|
||||
// Human-readable name for the device.
|
||||
const std::string &name() const { return name_; }
|
||||
|
||||
// Name sound system uses to locate this device.
|
||||
const std::string &device_name() const { return device_name_; }
|
||||
|
||||
// Makes a duplicate of this locator.
|
||||
virtual SoundDeviceLocator *Copy() const = 0;
|
||||
|
||||
protected:
|
||||
SoundDeviceLocator(const std::string &name,
|
||||
const std::string &device_name)
|
||||
: name_(name), device_name_(device_name) {}
|
||||
|
||||
explicit SoundDeviceLocator(const SoundDeviceLocator &that)
|
||||
: name_(that.name_), device_name_(that.device_name_) {}
|
||||
|
||||
std::string name_;
|
||||
std::string device_name_;
|
||||
|
||||
private:
|
||||
DISALLOW_ASSIGN(SoundDeviceLocator);
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_SOUNDDEVICELOCATOR_H_
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_SOUNDINPUTSTREAMINTERFACE_H_
|
||||
#define TALK_SOUND_SOUNDINPUTSTREAMINTERFACE_H_
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/sigslot.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// Interface for consuming an input stream from a recording device.
|
||||
// Semantics and thread-safety of StartReading()/StopReading() are the same as
|
||||
// for rtc::Worker.
|
||||
class SoundInputStreamInterface {
|
||||
public:
|
||||
virtual ~SoundInputStreamInterface() {}
|
||||
|
||||
// Starts the reading of samples on the current thread.
|
||||
virtual bool StartReading() = 0;
|
||||
// Stops the reading of samples.
|
||||
virtual bool StopReading() = 0;
|
||||
|
||||
// Retrieves the current input volume for this stream. Nominal range is
|
||||
// defined by SoundSystemInterface::k(Max|Min)Volume, but values exceeding the
|
||||
// max may be possible in some implementations. This call retrieves the actual
|
||||
// volume currently in use by the OS, not a cached value from a previous
|
||||
// (Get|Set)Volume() call.
|
||||
virtual bool GetVolume(int *volume) = 0;
|
||||
|
||||
// Changes the input volume for this stream. Nominal range is defined by
|
||||
// SoundSystemInterface::k(Max|Min)Volume. The effect of exceeding kMaxVolume
|
||||
// is implementation-defined.
|
||||
virtual bool SetVolume(int volume) = 0;
|
||||
|
||||
// Closes this stream object. If currently reading then this may only be
|
||||
// called from the reading thread.
|
||||
virtual bool Close() = 0;
|
||||
|
||||
// Get the latency of the stream.
|
||||
virtual int LatencyUsecs() = 0;
|
||||
|
||||
// Notifies the consumer of new data read from the device.
|
||||
// The first parameter is a pointer to the data read, and is only valid for
|
||||
// the duration of the call.
|
||||
// The second parameter is the amount of data read in bytes (i.e., the valid
|
||||
// length of the memory pointed to).
|
||||
// The 3rd parameter is the stream that is issuing the callback.
|
||||
sigslot::signal3<const void *, size_t,
|
||||
SoundInputStreamInterface *> SignalSamplesRead;
|
||||
|
||||
protected:
|
||||
SoundInputStreamInterface() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(SoundInputStreamInterface);
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
|
||||
#define TALK_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/sigslot.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// Interface for outputting a stream to a playback device.
|
||||
// Semantics and thread-safety of EnableBufferMonitoring()/
|
||||
// DisableBufferMonitoring() are the same as for rtc::Worker.
|
||||
class SoundOutputStreamInterface {
|
||||
public:
|
||||
virtual ~SoundOutputStreamInterface() {}
|
||||
|
||||
// Enables monitoring the available buffer space on the current thread.
|
||||
virtual bool EnableBufferMonitoring() = 0;
|
||||
// Disables the monitoring.
|
||||
virtual bool DisableBufferMonitoring() = 0;
|
||||
|
||||
// Write the given samples to the devices. If currently monitoring then this
|
||||
// may only be called from the monitoring thread.
|
||||
virtual bool WriteSamples(const void *sample_data,
|
||||
size_t size) = 0;
|
||||
|
||||
// Retrieves the current output volume for this stream. Nominal range is
|
||||
// defined by SoundSystemInterface::k(Max|Min)Volume, but values exceeding the
|
||||
// max may be possible in some implementations. This call retrieves the actual
|
||||
// volume currently in use by the OS, not a cached value from a previous
|
||||
// (Get|Set)Volume() call.
|
||||
virtual bool GetVolume(int *volume) = 0;
|
||||
|
||||
// Changes the output volume for this stream. Nominal range is defined by
|
||||
// SoundSystemInterface::k(Max|Min)Volume. The effect of exceeding kMaxVolume
|
||||
// is implementation-defined.
|
||||
virtual bool SetVolume(int volume) = 0;
|
||||
|
||||
// Closes this stream object. If currently monitoring then this may only be
|
||||
// called from the monitoring thread.
|
||||
virtual bool Close() = 0;
|
||||
|
||||
// Get the latency of the stream.
|
||||
virtual int LatencyUsecs() = 0;
|
||||
|
||||
// Notifies the producer of the available buffer space for writes.
|
||||
// It fires continuously as long as the space is greater than zero.
|
||||
// The first parameter is the amount of buffer space available for data to
|
||||
// be written (i.e., the maximum amount of data that can be written right now
|
||||
// with WriteSamples() without blocking).
|
||||
// The 2nd parameter is the stream that is issuing the callback.
|
||||
sigslot::signal2<size_t, SoundOutputStreamInterface *> SignalBufferSpace;
|
||||
|
||||
protected:
|
||||
SoundOutputStreamInterface() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(SoundOutputStreamInterface);
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_SOUNDSYSTEMFACTORY_H_
|
||||
#define TALK_SOUND_SOUNDSYSTEMFACTORY_H_
|
||||
|
||||
#include "webrtc/base/referencecountedsingletonfactory.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class SoundSystemInterface;
|
||||
|
||||
typedef rtc::ReferenceCountedSingletonFactory<SoundSystemInterface>
|
||||
SoundSystemFactory;
|
||||
|
||||
typedef rtc::rcsf_ptr<SoundSystemInterface> SoundSystemHandle;
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_SOUNDSYSTEMFACTORY_H_
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/soundsysteminterface.h"
|
||||
|
||||
#include "talk/sound/sounddevicelocator.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
void SoundSystemInterface::ClearSoundDeviceLocatorList(
|
||||
SoundSystemInterface::SoundDeviceLocatorList *devices) {
|
||||
for (SoundDeviceLocatorList::iterator i = devices->begin();
|
||||
i != devices->end();
|
||||
++i) {
|
||||
if (*i) {
|
||||
delete *i;
|
||||
}
|
||||
}
|
||||
devices->clear();
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_SOUNDSYSTEMINTERFACE_H_
|
||||
#define TALK_SOUND_SOUNDSYSTEMINTERFACE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class SoundDeviceLocator;
|
||||
class SoundInputStreamInterface;
|
||||
class SoundOutputStreamInterface;
|
||||
|
||||
// Interface for a platform's sound system.
|
||||
// Implementations must guarantee thread-safety for at least the following use
|
||||
// cases:
|
||||
// 1) Concurrent enumeration and opening of devices from different threads.
|
||||
// 2) Concurrent use of different Sound(Input|Output)StreamInterface
|
||||
// instances from different threads (but concurrent use of the _same_ one from
|
||||
// different threads need not be supported).
|
||||
class SoundSystemInterface {
|
||||
public:
|
||||
typedef std::vector<SoundDeviceLocator *> SoundDeviceLocatorList;
|
||||
|
||||
enum SampleFormat {
|
||||
// Only one supported sample format at this time.
|
||||
// The values here may be used in lookup tables, so they shouldn't change.
|
||||
FORMAT_S16LE = 0,
|
||||
};
|
||||
|
||||
enum Flags {
|
||||
// Enable reporting the current stream latency in
|
||||
// Sound(Input|Output)StreamInterface. See those classes for more details.
|
||||
FLAG_REPORT_LATENCY = (1 << 0),
|
||||
};
|
||||
|
||||
struct OpenParams {
|
||||
// Format for the sound stream.
|
||||
SampleFormat format;
|
||||
// Sampling frequency in hertz.
|
||||
unsigned int freq;
|
||||
// Number of channels in the PCM stream.
|
||||
unsigned int channels;
|
||||
// Misc flags. Should be taken from the Flags enum above.
|
||||
int flags;
|
||||
// Desired latency, measured as number of bytes of sample data
|
||||
int latency;
|
||||
};
|
||||
|
||||
// Special values for the "latency" field of OpenParams.
|
||||
// Use this one to say you don't care what the latency is. The sound system
|
||||
// will optimize for other things instead.
|
||||
static const int kNoLatencyRequirements = -1;
|
||||
// Use this one to say that you want the sound system to pick an appropriate
|
||||
// small latency value. The sound system may pick the minimum allowed one, or
|
||||
// a slightly higher one in the event that the true minimum requires an
|
||||
// undesirable trade-off.
|
||||
static const int kLowLatency = 0;
|
||||
|
||||
// Max value for the volume parameters for Sound(Input|Output)StreamInterface.
|
||||
static const int kMaxVolume = 255;
|
||||
// Min value for the volume parameters for Sound(Input|Output)StreamInterface.
|
||||
static const int kMinVolume = 0;
|
||||
|
||||
// Helper for clearing a locator list and deleting the entries.
|
||||
static void ClearSoundDeviceLocatorList(SoundDeviceLocatorList *devices);
|
||||
|
||||
virtual ~SoundSystemInterface() {}
|
||||
|
||||
virtual bool Init() = 0;
|
||||
virtual void Terminate() = 0;
|
||||
|
||||
// Enumerates the available devices. (Any pre-existing locators in the lists
|
||||
// are deleted.)
|
||||
virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices) = 0;
|
||||
virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices) = 0;
|
||||
|
||||
// Gets a special locator for the default device.
|
||||
virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device) = 0;
|
||||
virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device) = 0;
|
||||
|
||||
// Opens the given device, or returns NULL on error.
|
||||
virtual SoundOutputStreamInterface *OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) = 0;
|
||||
virtual SoundInputStreamInterface *OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) = 0;
|
||||
|
||||
// A human-readable name for this sound system.
|
||||
virtual const char *GetName() const = 0;
|
||||
|
||||
protected:
|
||||
SoundSystemInterface() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(SoundSystemInterface);
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_SOUNDSYSTEMINTERFACE_H_
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "talk/sound/soundsystemproxy.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
bool SoundSystemProxy::EnumeratePlaybackDevices(
|
||||
SoundDeviceLocatorList *devices) {
|
||||
return wrapped_ ? wrapped_->EnumeratePlaybackDevices(devices) : false;
|
||||
}
|
||||
|
||||
bool SoundSystemProxy::EnumerateCaptureDevices(
|
||||
SoundDeviceLocatorList *devices) {
|
||||
return wrapped_ ? wrapped_->EnumerateCaptureDevices(devices) : false;
|
||||
}
|
||||
|
||||
bool SoundSystemProxy::GetDefaultPlaybackDevice(
|
||||
SoundDeviceLocator **device) {
|
||||
return wrapped_ ? wrapped_->GetDefaultPlaybackDevice(device) : false;
|
||||
}
|
||||
|
||||
bool SoundSystemProxy::GetDefaultCaptureDevice(
|
||||
SoundDeviceLocator **device) {
|
||||
return wrapped_ ? wrapped_->GetDefaultCaptureDevice(device) : false;
|
||||
}
|
||||
|
||||
SoundOutputStreamInterface *SoundSystemProxy::OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) {
|
||||
return wrapped_ ? wrapped_->OpenPlaybackDevice(device, params) : NULL;
|
||||
}
|
||||
|
||||
SoundInputStreamInterface *SoundSystemProxy::OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms) {
|
||||
return wrapped_ ? wrapped_->OpenCaptureDevice(device, params) : NULL;
|
||||
}
|
||||
|
||||
} // namespace cricket
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2004--2010, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TALK_SOUND_SOUNDSYSTEMPROXY_H_
|
||||
#define TALK_SOUND_SOUNDSYSTEMPROXY_H_
|
||||
|
||||
#include "talk/sound/soundsysteminterface.h"
|
||||
#include "webrtc/base/basictypes.h" // for NULL
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// A SoundSystemProxy is a sound system that defers to another one.
|
||||
// Init(), Terminate(), and GetName() are left as pure virtual, so a sub-class
|
||||
// must define them.
|
||||
class SoundSystemProxy : public SoundSystemInterface {
|
||||
public:
|
||||
SoundSystemProxy() : wrapped_(NULL) {}
|
||||
|
||||
// Each of these methods simply defers to wrapped_ if non-NULL, else fails.
|
||||
|
||||
virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices);
|
||||
virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices);
|
||||
|
||||
virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device);
|
||||
virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device);
|
||||
|
||||
virtual SoundOutputStreamInterface *OpenPlaybackDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
virtual SoundInputStreamInterface *OpenCaptureDevice(
|
||||
const SoundDeviceLocator *device,
|
||||
const OpenParams ¶ms);
|
||||
|
||||
protected:
|
||||
SoundSystemInterface *wrapped_;
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // TALK_SOUND_SOUNDSYSTEMPROXY_H_
|
Loading…
Reference in New Issue
Block a user