This CL refactor the audio_device.gyp to make use of the chromiurm _os suffix filter.

This CL looks big, but most of the changes are only renaming. I hope it is all right for you.

Changes include:
rename source/Windows to source/win
rename source/Linux to linux
rename source/Mac to source/mac

Also rename some files to  follow chromium standard, for examples:
from alsasymboltable.cc to alsasymboltable_linux.cc
from alsasymboltable.h to alsasymboltable_linux.h
from audio_device_linux_alsa.cc to audio_device_alsa_linux.cc
from audio_device_linux_alsa.h to audio_device_alsa_linux.h
...etc

Modified files:
audio_device.gyp and audio_device_impl.cc : 
adapt to the new file names.

Test=none
Bug=none
Review URL: http://webrtc-codereview.appspot.com/91017

git-svn-id: http://webrtc.googlecode.com/svn/trunk@347 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
xians@google.com 2011-08-11 12:41:56 +00:00
parent 8d0c98b954
commit 68efa21abc
40 changed files with 18634 additions and 106 deletions

View File

@ -24,8 +24,8 @@ LOCAL_SRC_FILES := \
audio_device_impl.cc \
Android/audio_device_android_opensles.cc \
Android/audio_device_utility_android.cc \
Dummy/audio_device_utility_dummy.cc \
Dummy/audio_device_dummy.cc
dummy/audio_device_utility_dummy.cc \
dummy/audio_device_dummy.cc
# Flags passed to both C and C++ files.
LOCAL_CFLAGS := \
@ -35,8 +35,8 @@ LOCAL_CFLAGS := \
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/Android \
$(LOCAL_PATH)/Dummy \
$(LOCAL_PATH)/Linux \
$(LOCAL_PATH)/dummy \
$(LOCAL_PATH)/linux \
$(LOCAL_PATH)/../interface \
$(LOCAL_PATH)/../../../.. \
$(LOCAL_PATH)/../../../interface \

View File

@ -23,7 +23,7 @@
'.',
'../../../interface',
'../interface',
'Dummy', # Dummy audio device
'dummy', # dummy audio device
],
'direct_dependent_settings': {
'include_dirs': [
@ -45,84 +45,45 @@
'audio_device_impl.cc',
'audio_device_impl.h',
'audio_device_config.h',
'Dummy/audio_device_dummy.cc',
'Dummy/audio_device_dummy.h',
'Dummy/audio_device_utility_dummy.cc',
'Dummy/audio_device_utility_dummy.h',
'Linux/alsasymboltable.cc',
'Linux/alsasymboltable.h',
'Linux/audio_device_linux_alsa.cc',
'Linux/audio_device_linux_alsa.h',
'Linux/audio_device_utility_linux.cc',
'Linux/audio_device_utility_linux.h',
'Linux/audio_mixer_manager_linux_alsa.cc',
'Linux/audio_mixer_manager_linux_alsa.h',
'Linux/latebindingsymboltable.cc',
'Linux/latebindingsymboltable.h',
'Mac/audio_device_mac.cc',
'Mac/audio_device_mac.h',
'Mac/audio_device_utility_mac.cc',
'Mac/audio_device_utility_mac.h',
'Mac/audio_mixer_manager_mac.cc',
'Mac/audio_mixer_manager_mac.h',
'Mac/portaudio/pa_memorybarrier.h',
'Mac/portaudio/pa_ringbuffer.c',
'Mac/portaudio/pa_ringbuffer.h',
'Windows/audio_device_utility_windows.cc',
'Windows/audio_device_utility_windows.h',
'Windows/audio_device_windows_core.cc',
'Windows/audio_device_windows_core.h',
'Windows/audio_device_windows_wave.cc',
'Windows/audio_device_windows_wave.h',
'Windows/audio_mixer_manager.cc',
'Windows/audio_mixer_manager.h',
'dummy/audio_device_dummy.cc',
'dummy/audio_device_dummy.h',
'dummy/audio_device_utility_dummy.cc',
'dummy/audio_device_utility_dummy.h',
'linux/alsasymboltable_linux.cc',
'linux/alsasymboltable_linux.h',
'linux/audio_device_alsa_linux.cc',
'linux/audio_device_alsa_linux.h',
'linux/audio_device_utility_linux.cc',
'linux/audio_device_utility_linux.h',
'linux/audio_mixer_manager_alsa_linux.cc',
'linux/audio_mixer_manager_alsa_linux.h',
'linux/latebindingsymboltable_linux.cc',
'linux/latebindingsymboltable_linux.h',
'mac/audio_device_mac.cc',
'mac/audio_device_mac.h',
'mac/audio_device_utility_mac.cc',
'mac/audio_device_utility_mac.h',
'mac/audio_mixer_manager_mac.cc',
'mac/audio_mixer_manager_mac.h',
'mac/portaudio/pa_memorybarrier.h',
'mac/portaudio/pa_ringbuffer.c',
'mac/portaudio/pa_ringbuffer.h',
'win/audio_device_utility_win.cc',
'win/audio_device_utility_win.h',
'win/audio_device_core_win.cc',
'win/audio_device_core_win.h',
'win/audio_device_wave_win.cc',
'win/audio_device_wave_win.h',
'win/audio_mixer_manager_win.cc',
'win/audio_mixer_manager_win.h',
],
'conditions': [
['OS!="linux"', {
'sources!': [
'Linux/alsasymboltable.cc',
'Linux/alsasymboltable.h',
'Linux/audio_device_linux_alsa.cc',
'Linux/audio_device_linux_alsa.h',
'Linux/audio_mixer_manager_linux_alsa.cc',
'Linux/audio_mixer_manager_linux_alsa.h',
'Linux/latebindingsymboltable.cc',
'Linux/latebindingsymboltable.h',
'Linux/audio_device_utility_linux.cc',
'Linux/audio_device_utility_linux.h',
],
}],
['OS!="mac"', {
'sources!': [
'Mac/audio_device_mac.cc',
'Mac/audio_device_mac.h',
'Mac/audio_device_utility_mac.cc',
'Mac/audio_device_utility_mac.h',
'Mac/audio_mixer_manager_mac.cc',
'Mac/audio_mixer_manager_mac.h',
'Mac/portaudio/pa_memorybarrier.h',
'Mac/portaudio/pa_ringbuffer.c',
'Mac/portaudio/pa_ringbuffer.h',
],
}],
['OS!="win"', {
'sources!': [
'Windows/audio_device_utility_windows.cc',
'Windows/audio_device_utility_windows.h',
'Windows/audio_device_windows_core.cc',
'Windows/audio_device_windows_core.h',
'Windows/audio_device_windows_wave.cc',
'Windows/audio_device_windows_wave.h',
'Windows/audio_mixer_manager.cc',
'Windows/audio_mixer_manager.h',
],
}],
['OS=="linux"', {
'defines': [
'LINUX_ALSA',
],
'include_dirs': [
'Linux',
'linux',
],
'link_settings': {
'libraries': [
@ -136,12 +97,12 @@
'LINUX_PULSE',
],
'sources': [
'Linux/audio_device_linux_pulse.cc',
'Linux/audio_device_linux_pulse.h',
'Linux/audio_mixer_manager_linux_pulse.cc',
'Linux/audio_mixer_manager_linux_pulse.h',
'Linux/pulseaudiosymboltable.cc',
'Linux/pulseaudiosymboltable.h',
'linux/audio_device_pulse_linux.cc',
'linux/audio_device_pulse_linux.h',
'linux/audio_mixer_manager_pulse_linux.cc',
'linux/audio_mixer_manager_pulse_linux.h',
'linux/pulseaudiosymboltable_linux.cc',
'linux/pulseaudiosymboltable_linux.h',
],
'link_settings': {
'libraries': [
@ -153,7 +114,7 @@
}],
['OS=="mac"', {
'include_dirs': [
'Mac',
'mac',
],
'link_settings': {
'libraries': [
@ -164,7 +125,7 @@
}],
['OS=="win"', {
'include_dirs': [
'Windows',
'win',
'../../../../../..',
],
}],

View File

@ -12,7 +12,7 @@
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H
#include "typedefs.h"
#include "resampler.h"
#include "../../../../common_audio/resampler/main/interface/resampler.h"
#include "file_wrapper.h"
#include "audio_device.h"
#include "list_wrapper.h"

View File

@ -15,10 +15,10 @@
#include "trace.h"
#if defined(_WIN32)
#include "audio_device_utility_windows.h"
#include "audio_device_windows_wave.h"
#include "audio_device_utility_win.h"
#include "audio_device_wave_win.h"
#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
#include "audio_device_windows_core.h"
#include "audio_device_core_win.h"
#endif
#elif defined(WEBRTC_ANDROID_OPENSLES)
#include <stdlib.h>
@ -31,10 +31,10 @@
#elif defined(WEBRTC_LINUX)
#include "audio_device_utility_linux.h"
#if defined(LINUX_ALSA)
#include "audio_device_linux_alsa.h"
#include "audio_device_alsa_linux.h"
#endif
#if defined(LINUX_PULSE)
#include "audio_device_linux_pulse.h"
#include "audio_device_pulse_linux.h"
#endif
#elif defined(MAC_IPHONE)
#include "audio_device_utility_iphone.h"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,178 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DUMMY_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DUMMY_H
#include <stdio.h>
#include "audio_device_generic.h"
#include "critical_section_wrapper.h"
namespace webrtc {
class EventWrapper;
class ThreadWrapper;
class AudioDeviceDummy : public AudioDeviceGeneric
{
public:
AudioDeviceDummy(const WebRtc_Word32 id);
~AudioDeviceDummy();
// Retrieve the currently utilized audio layer
virtual WebRtc_Word32 ActiveAudioLayer(AudioDeviceModule::AudioLayer& audioLayer) const;
// Main initializaton and termination
virtual WebRtc_Word32 Init();
virtual WebRtc_Word32 Terminate();
virtual bool Initialized() const;
// Device enumeration
virtual WebRtc_Word16 PlayoutDevices();
virtual WebRtc_Word16 RecordingDevices();
virtual WebRtc_Word32 PlayoutDeviceName(WebRtc_UWord16 index, WebRtc_Word8 name[kAdmMaxDeviceNameSize], WebRtc_Word8 guid[kAdmMaxGuidSize]);
virtual WebRtc_Word32 RecordingDeviceName(WebRtc_UWord16 index, WebRtc_Word8 name[kAdmMaxDeviceNameSize], WebRtc_Word8 guid[kAdmMaxGuidSize]);
// Device selection
virtual WebRtc_Word32 SetPlayoutDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetPlayoutDevice(AudioDeviceModule::WindowsDeviceType device);
virtual WebRtc_Word32 SetRecordingDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetRecordingDevice(AudioDeviceModule::WindowsDeviceType device);
// Audio transport initialization
virtual WebRtc_Word32 PlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 InitPlayout();
virtual bool PlayoutIsInitialized() const;
virtual WebRtc_Word32 RecordingIsAvailable(bool& available);
virtual WebRtc_Word32 InitRecording();
virtual bool RecordingIsInitialized() const;
// Audio transport control
virtual WebRtc_Word32 StartPlayout();
virtual WebRtc_Word32 StopPlayout();
virtual bool Playing() const;
virtual WebRtc_Word32 StartRecording();
virtual WebRtc_Word32 StopRecording();
virtual bool Recording() const;
// Microphone Automatic Gain Control (AGC)
virtual WebRtc_Word32 SetAGC(bool enable);
virtual bool AGC() const;
// Volume control based on the Windows Wave API (Windows only)
virtual WebRtc_Word32 SetWaveOutVolume(WebRtc_UWord16 volumeLeft, WebRtc_UWord16 volumeRight);
virtual WebRtc_Word32 WaveOutVolume(WebRtc_UWord16& volumeLeft, WebRtc_UWord16& volumeRight) const;
// Audio mixer initialization
virtual WebRtc_Word32 SpeakerIsAvailable(bool& available);
virtual WebRtc_Word32 InitSpeaker();
virtual bool SpeakerIsInitialized() const;
virtual WebRtc_Word32 MicrophoneIsAvailable(bool& available);
virtual WebRtc_Word32 InitMicrophone();
virtual bool MicrophoneIsInitialized() const;
// Speaker volume controls
virtual WebRtc_Word32 SpeakerVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 SpeakerVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32 SpeakerVolumeStepSize(WebRtc_UWord16& stepSize) const;
// Microphone volume controls
virtual WebRtc_Word32 MicrophoneVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxMicrophoneVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinMicrophoneVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32 MicrophoneVolumeStepSize(WebRtc_UWord16& stepSize) const;
// Speaker mute control
virtual WebRtc_Word32 SpeakerMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerMute(bool enable);
virtual WebRtc_Word32 SpeakerMute(bool& enabled) const;
// Microphone mute control
virtual WebRtc_Word32 MicrophoneMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneMute(bool enable);
virtual WebRtc_Word32 MicrophoneMute(bool& enabled) const;
// Microphone boost control
virtual WebRtc_Word32 MicrophoneBoostIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneBoost(bool enable);
virtual WebRtc_Word32 MicrophoneBoost(bool& enabled) const;
// Stereo support
virtual WebRtc_Word32 StereoPlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoPlayout(bool enable);
virtual WebRtc_Word32 StereoPlayout(bool& enabled) const;
virtual WebRtc_Word32 StereoRecordingIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoRecording(bool enable);
virtual WebRtc_Word32 StereoRecording(bool& enabled) const;
// Delay information and control
virtual WebRtc_Word32 SetPlayoutBuffer(const AudioDeviceModule::BufferType type, WebRtc_UWord16 sizeMS);
virtual WebRtc_Word32 PlayoutBuffer(AudioDeviceModule::BufferType& type, WebRtc_UWord16& sizeMS) const;
virtual WebRtc_Word32 PlayoutDelay(WebRtc_UWord16& delayMS) const;
virtual WebRtc_Word32 RecordingDelay(WebRtc_UWord16& delayMS) const;
// CPU load
virtual WebRtc_Word32 CPULoad(WebRtc_UWord16& load) const;
virtual bool PlayoutWarning() const;
virtual bool PlayoutError() const;
virtual bool RecordingWarning() const;
virtual bool RecordingError() const;
virtual void ClearPlayoutWarning();
virtual void ClearPlayoutError();
virtual void ClearRecordingWarning();
virtual void ClearRecordingError();
virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer);
private:
void Lock() { _critSect.Enter(); };
void UnLock() { _critSect.Leave(); };
static bool RecThreadFunc(void*);
static bool PlayThreadFunc(void*);
bool RecThreadProcess();
bool PlayThreadProcess();
AudioDeviceBuffer* _ptrAudioBuffer;
CriticalSectionWrapper& _critSect;
WebRtc_Word32 _id;
EventWrapper& _timeEventRec;
EventWrapper& _timeEventPlay;
EventWrapper& _recStartEvent;
EventWrapper& _playStartEvent;
ThreadWrapper* _ptrThreadRec;
ThreadWrapper* _ptrThreadPlay;
WebRtc_UWord32 _recThreadID;
WebRtc_UWord32 _playThreadID;
bool _initialized;
bool _recording;
bool _playing;
bool _recIsInitialized;
bool _playIsInitialized;
bool _speakerIsInitialized;
bool _microphoneIsInitialized;
WebRtc_Word8 _recBuffer[2*160];
FILE* _playDataFile;
};
} // namespace webrtc
#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DUMMY_H

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "audio_device_utility_dummy.h"
#include "audio_device_config.h" // DEBUG_PRINT()
#include "critical_section_wrapper.h"
#include "trace.h"
namespace webrtc
{
AudioDeviceUtilityDummy::AudioDeviceUtilityDummy(const WebRtc_Word32 id) :
_critSect(*CriticalSectionWrapper::CreateCriticalSection()),
_id(id),
_lastError(AudioDeviceModule::kAdmErrNone)
{
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id,
"%s created", __FUNCTION__);
}
AudioDeviceUtilityDummy::~AudioDeviceUtilityDummy()
{
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id,
"%s destroyed", __FUNCTION__);
{
CriticalSectionScoped lock(_critSect);
// free stuff here...
}
delete &_critSect;
}
// ============================================================================
// API
// ============================================================================
WebRtc_Word32 AudioDeviceUtilityDummy::Init()
{
WEBRTC_TRACE(kTraceModuleCall, kTraceAudioDevice, _id,
"%s", __FUNCTION__);
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
" OS info: %s", "Dummy");
return 0;
}
} // namespace webrtc

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_DUMMY_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_DUMMY_H
#include "audio_device_utility.h"
#include "audio_device.h"
namespace webrtc
{
class CriticalSectionWrapper;
class AudioDeviceUtilityDummy: public AudioDeviceUtility
{
public:
AudioDeviceUtilityDummy(const WebRtc_Word32 id);
~AudioDeviceUtilityDummy();
virtual WebRtc_Word32 Init();
private:
CriticalSectionWrapper& _critSect;
WebRtc_Word32 _id;
AudioDeviceModule::ErrorCode _lastError;
};
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_DEVICE_UTILITY_DUMMY_H_

View File

@ -0,0 +1,39 @@
/*
* 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 "alsasymboltable_linux.h"
namespace webrtc_adm_linux_alsa {
LATE_BINDING_SYMBOL_TABLE_DEFINE_BEGIN(AlsaSymbolTable, "libasound.so.2")
#define X(sym) \
LATE_BINDING_SYMBOL_TABLE_DEFINE_ENTRY(AlsaSymbolTable, sym)
ALSA_SYMBOLS_LIST
#undef X
LATE_BINDING_SYMBOL_TABLE_DEFINE_END(AlsaSymbolTable)
} // namespace webrtc_adm_linux_alsa

View File

@ -0,0 +1,144 @@
/*
* 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 WEBRTC_AUDIO_DEVICE_ALSASYMBOLTABLE_LINUX_H
#define WEBRTC_AUDIO_DEVICE_ALSASYMBOLTABLE_LINUX_H
#include "latebindingsymboltable_linux.h"
namespace webrtc_adm_linux_alsa {
// 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_resume) \
X(snd_pcm_reset) \
X(snd_pcm_state) \
X(snd_pcm_set_params) \
X(snd_pcm_start) \
X(snd_pcm_stream) \
X(snd_pcm_wait) \
X(snd_pcm_writei) \
X(snd_pcm_info_get_class) \
X(snd_pcm_info_get_subdevices_avail) \
X(snd_pcm_info_get_subdevice_name) \
X(snd_pcm_info_set_subdevice) \
X(snd_pcm_info_get_id) \
X(snd_pcm_info_set_device) \
X(snd_pcm_info_set_stream) \
X(snd_pcm_info_get_name) \
X(snd_pcm_info_get_subdevices_count) \
X(snd_pcm_info_sizeof) \
X(snd_pcm_hw_params) \
X(snd_pcm_hw_params_malloc) \
X(snd_pcm_hw_params_free) \
X(snd_pcm_hw_params_any) \
X(snd_pcm_hw_params_set_access) \
X(snd_pcm_hw_params_set_format) \
X(snd_pcm_hw_params_set_channels) \
X(snd_pcm_hw_params_set_rate_near) \
X(snd_pcm_hw_params_set_buffer_size_near) \
X(snd_card_next) \
X(snd_card_get_name) \
X(snd_config_update) \
X(snd_config_copy) \
X(snd_config_get_id) \
X(snd_ctl_open) \
X(snd_ctl_close) \
X(snd_ctl_card_info) \
X(snd_ctl_card_info_sizeof) \
X(snd_ctl_card_info_get_id) \
X(snd_ctl_card_info_get_name) \
X(snd_ctl_pcm_next_device) \
X(snd_ctl_pcm_info) \
X(snd_mixer_load) \
X(snd_mixer_free) \
X(snd_mixer_detach) \
X(snd_mixer_close) \
X(snd_mixer_open) \
X(snd_mixer_attach) \
X(snd_mixer_first_elem) \
X(snd_mixer_elem_next) \
X(snd_mixer_selem_get_name) \
X(snd_mixer_selem_is_active) \
X(snd_mixer_selem_register) \
X(snd_mixer_selem_set_playback_volume_all) \
X(snd_mixer_selem_get_playback_volume) \
X(snd_mixer_selem_has_playback_volume) \
X(snd_mixer_selem_get_playback_volume_range) \
X(snd_mixer_selem_has_playback_switch) \
X(snd_mixer_selem_get_playback_switch) \
X(snd_mixer_selem_set_playback_switch_all) \
X(snd_mixer_selem_has_capture_switch) \
X(snd_mixer_selem_get_capture_switch) \
X(snd_mixer_selem_set_capture_switch_all) \
X(snd_mixer_selem_has_capture_volume) \
X(snd_mixer_selem_set_capture_volume_all) \
X(snd_mixer_selem_get_capture_volume) \
X(snd_mixer_selem_get_capture_volume_range) \
X(snd_dlopen) \
X(snd_dlclose) \
X(snd_config) \
X(snd_config_search) \
X(snd_config_get_string) \
X(snd_config_search_definition) \
X(snd_config_get_type) \
X(snd_config_delete) \
X(snd_config_iterator_entry) \
X(snd_config_iterator_first) \
X(snd_config_iterator_next) \
X(snd_config_iterator_end) \
X(snd_config_delete_compound_members) \
X(snd_config_get_integer) \
X(snd_config_get_bool) \
X(snd_dlsym) \
X(snd_strerror) \
X(snd_lib_error) \
X(snd_lib_error_set_handler)
LATE_BINDING_SYMBOL_TABLE_DECLARE_BEGIN(AlsaSymbolTable)
#define X(sym) \
LATE_BINDING_SYMBOL_TABLE_DECLARE_ENTRY(AlsaSymbolTable, sym)
ALSA_SYMBOLS_LIST
#undef X
LATE_BINDING_SYMBOL_TABLE_DECLARE_END(AlsaSymbolTable)
} // namespace webrtc_adm_linux_alsa
#endif // WEBRTC_AUDIO_DEVICE_ALSASYMBOLTABLE_LINUX_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,284 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H
#include "audio_device_generic.h"
#include "critical_section_wrapper.h"
#include "audio_mixer_manager_alsa_linux.h"
#include <sys/soundcard.h>
#include <sys/ioctl.h>
#include <alsa/asoundlib.h>
namespace webrtc
{
class EventWrapper;
class ThreadWrapper;
// Number of continuous buffer check errors before going 0->1
const WebRtc_UWord16 THR_OLD_BUFFER_CHECK_METHOD = 30;
// Number of buffer check errors before going 1->2
const WebRtc_UWord16 THR_IGNORE_BUFFER_CHECK = 30;
// 2.7 seconds (decimal 131071)
const WebRtc_UWord32 ALSA_SNDCARD_BUFF_SIZE_REC = 0x1ffff;
// ~170 ms (decimal 8191) - enough since we only write to buffer if it contains
// less than 50 ms
const WebRtc_UWord32 ALSA_SNDCARD_BUFF_SIZE_PLAY = 0x1fff;
const WebRtc_UWord32 REC_TIMER_PERIOD_MS = 2;
const WebRtc_UWord32 PLAY_TIMER_PERIOD_MS = 5;
const WebRtc_UWord16 PLAYBACK_THRESHOLD = 50;
const WebRtc_UWord32 REC_SAMPLES_PER_MS = 48;
const WebRtc_UWord32 PLAY_SAMPLES_PER_MS = 48;
class AudioDeviceLinuxALSA : public AudioDeviceGeneric
{
public:
AudioDeviceLinuxALSA(const WebRtc_Word32 id);
~AudioDeviceLinuxALSA();
// Retrieve the currently utilized audio layer
virtual WebRtc_Word32 ActiveAudioLayer(
AudioDeviceModule::AudioLayer& audioLayer) const;
// Main initializaton and termination
virtual WebRtc_Word32 Init();
virtual WebRtc_Word32 Terminate();
virtual bool Initialized() const;
// Device enumeration
virtual WebRtc_Word16 PlayoutDevices();
virtual WebRtc_Word16 RecordingDevices();
virtual WebRtc_Word32 PlayoutDeviceName(
WebRtc_UWord16 index,
WebRtc_Word8 name[kAdmMaxDeviceNameSize],
WebRtc_Word8 guid[kAdmMaxGuidSize]);
virtual WebRtc_Word32 RecordingDeviceName(
WebRtc_UWord16 index,
WebRtc_Word8 name[kAdmMaxDeviceNameSize],
WebRtc_Word8 guid[kAdmMaxGuidSize]);
// Device selection
virtual WebRtc_Word32 SetPlayoutDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetPlayoutDevice(
AudioDeviceModule::WindowsDeviceType device);
virtual WebRtc_Word32 SetRecordingDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetRecordingDevice(
AudioDeviceModule::WindowsDeviceType device);
// Audio transport initialization
virtual WebRtc_Word32 PlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 InitPlayout();
virtual bool PlayoutIsInitialized() const;
virtual WebRtc_Word32 RecordingIsAvailable(bool& available);
virtual WebRtc_Word32 InitRecording();
virtual bool RecordingIsInitialized() const;
// Audio transport control
virtual WebRtc_Word32 StartPlayout();
virtual WebRtc_Word32 StopPlayout();
virtual bool Playing() const;
virtual WebRtc_Word32 StartRecording();
virtual WebRtc_Word32 StopRecording();
virtual bool Recording() const;
// Microphone Automatic Gain Control (AGC)
virtual WebRtc_Word32 SetAGC(bool enable);
virtual bool AGC() const;
// Volume control based on the Windows Wave API (Windows only)
virtual WebRtc_Word32 SetWaveOutVolume(WebRtc_UWord16 volumeLeft,
WebRtc_UWord16 volumeRight);
virtual WebRtc_Word32 WaveOutVolume(WebRtc_UWord16& volumeLeft,
WebRtc_UWord16& volumeRight) const;
// Audio mixer initialization
virtual WebRtc_Word32 SpeakerIsAvailable(bool& available);
virtual WebRtc_Word32 InitSpeaker();
virtual bool SpeakerIsInitialized() const;
virtual WebRtc_Word32 MicrophoneIsAvailable(bool& available);
virtual WebRtc_Word32 InitMicrophone();
virtual bool MicrophoneIsInitialized() const;
// Speaker volume controls
virtual WebRtc_Word32 SpeakerVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 SpeakerVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32 SpeakerVolumeStepSize(WebRtc_UWord16& stepSize) const;
// Microphone volume controls
virtual WebRtc_Word32 MicrophoneVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxMicrophoneVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinMicrophoneVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32 MicrophoneVolumeStepSize(
WebRtc_UWord16& stepSize) const;
// Speaker mute control
virtual WebRtc_Word32 SpeakerMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerMute(bool enable);
virtual WebRtc_Word32 SpeakerMute(bool& enabled) const;
// Microphone mute control
virtual WebRtc_Word32 MicrophoneMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneMute(bool enable);
virtual WebRtc_Word32 MicrophoneMute(bool& enabled) const;
// Microphone boost control
virtual WebRtc_Word32 MicrophoneBoostIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneBoost(bool enable);
virtual WebRtc_Word32 MicrophoneBoost(bool& enabled) const;
// Stereo support
virtual WebRtc_Word32 StereoPlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoPlayout(bool enable);
virtual WebRtc_Word32 StereoPlayout(bool& enabled) const;
virtual WebRtc_Word32 StereoRecordingIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoRecording(bool enable);
virtual WebRtc_Word32 StereoRecording(bool& enabled) const;
// Delay information and control
virtual WebRtc_Word32 SetPlayoutBuffer(
const AudioDeviceModule::BufferType type,
WebRtc_UWord16 sizeMS);
virtual WebRtc_Word32 PlayoutBuffer(
AudioDeviceModule::BufferType& type,
WebRtc_UWord16& sizeMS) const;
virtual WebRtc_Word32 PlayoutDelay(WebRtc_UWord16& delayMS) const;
virtual WebRtc_Word32 RecordingDelay(WebRtc_UWord16& delayMS) const;
// CPU load
virtual WebRtc_Word32 CPULoad(WebRtc_UWord16& load) const;
public:
virtual bool PlayoutWarning() const;
virtual bool PlayoutError() const;
virtual bool RecordingWarning() const;
virtual bool RecordingError() const;
virtual void ClearPlayoutWarning();
virtual void ClearPlayoutError();
virtual void ClearRecordingWarning();
virtual void ClearRecordingError();
public:
virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer);
private:
WebRtc_Word32 GetDevicesInfo(const WebRtc_Word32 function,
const bool playback,
const WebRtc_Word32 enumDeviceNo = 0,
char* enumDeviceName = NULL,
const WebRtc_Word32 ednLen = 0) const;
WebRtc_Word32 ErrorRecovery(WebRtc_Word32 error, snd_pcm_t* deviceHandle);
void FillPlayoutBuffer();
private:
void Lock() { _critSect.Enter(); };
void UnLock() { _critSect.Leave(); };
private:
inline WebRtc_Word32 InputSanityCheckAfterUnlockedPeriod() const;
inline WebRtc_Word32 OutputSanityCheckAfterUnlockedPeriod() const;
WebRtc_Word32 PrepareStartRecording();
WebRtc_Word32 GetPlayoutBufferDelay();
WebRtc_Word32 GetRecordingBufferDelay(bool preRead);
private:
static bool RecThreadFunc(void*);
static bool PlayThreadFunc(void*);
bool RecThreadProcess();
bool PlayThreadProcess();
private:
AudioDeviceBuffer* _ptrAudioBuffer;
CriticalSectionWrapper& _critSect;
EventWrapper& _timeEventRec;
EventWrapper& _timeEventPlay;
EventWrapper& _recStartEvent;
EventWrapper& _playStartEvent;
ThreadWrapper* _ptrThreadRec;
ThreadWrapper* _ptrThreadPlay;
WebRtc_UWord32 _recThreadID;
WebRtc_UWord32 _playThreadID;
WebRtc_Word32 _id;
AudioMixerManagerLinuxALSA _mixerManager;
WebRtc_UWord16 _inputDeviceIndex;
WebRtc_UWord16 _outputDeviceIndex;
bool _inputDeviceIsSpecified;
bool _outputDeviceIsSpecified;
snd_pcm_t* _handleRecord;
snd_pcm_t* _handlePlayout;
snd_pcm_uframes_t _recSndcardBuffsize;
snd_pcm_uframes_t _playSndcardBuffsize;
WebRtc_UWord32 _samplingFreqRec;
WebRtc_UWord32 _samplingFreqPlay;
WebRtc_UWord8 _recChannels;
WebRtc_UWord8 _playChannels;
WebRtc_UWord32 _playbackBufferSize;
WebRtc_UWord32 _recordBufferSize;
WebRtc_Word16* _recBuffer;
AudioDeviceModule::BufferType _playBufType;
private:
bool _initialized;
bool _recording;
bool _playing;
bool _recIsInitialized;
bool _playIsInitialized;
bool _startRec;
bool _stopRec;
bool _startPlay;
bool _stopPlay;
bool _AGC;
bool _buffersizeFromZeroAvail;
bool _buffersizeFromZeroDelay;
WebRtc_UWord32 _sndCardPlayDelay; // Just to store last value
WebRtc_UWord32 _previousSndCardPlayDelay; // Stores previous _sndCardPlayDelay value
WebRtc_UWord8 _delayMonitorStatePlay; // 0 normal, 1 monitor delay change (after error)
WebRtc_Word16 _largeDelayCountPlay; // Used when monitoring delay change
WebRtc_UWord32 _sndCardRecDelay;
WebRtc_UWord32 _numReadyRecSamples;
WebRtc_UWord8 _bufferCheckMethodPlay;
WebRtc_UWord8 _bufferCheckMethodRec;
WebRtc_UWord32 _bufferCheckErrorsPlay;
WebRtc_UWord32 _bufferCheckErrorsRec;
WebRtc_Word32 _lastBufferCheckValuePlay;
WebRtc_Word32 _writeErrors;
WebRtc_UWord16 _playWarning;
WebRtc_UWord16 _playError;
WebRtc_UWord16 _recWarning;
WebRtc_UWord16 _recError;
WebRtc_UWord16 _playBufDelay; // playback delay
WebRtc_UWord16 _playBufDelayFixed; // fixed playback delay
};
}
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_DEVICE_ALSA_LINUX_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,385 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_PULSE_LINUX_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_PULSE_LINUX_H
#include "audio_device_generic.h"
#include "audio_mixer_manager_pulse_linux.h"
#include "critical_section_wrapper.h"
#include <pulse/pulseaudio.h>
// Set this define to make the code behave like in GTalk/libjingle
//#define WEBRTC_PA_GTALK
// We define this flag if it's missing from our headers, because we want to be
// able to compile against old headers but still use PA_STREAM_ADJUST_LATENCY
// if run against a recent version of the library.
#ifndef PA_STREAM_ADJUST_LATENCY
#define PA_STREAM_ADJUST_LATENCY 0x2000U
#endif
#ifndef PA_STREAM_START_MUTED
#define PA_STREAM_START_MUTED 0x1000U
#endif
// Set this constant to 0 to disable latency reading
const WebRtc_UWord32 WEBRTC_PA_REPORT_LATENCY = 1;
// Constants from implementation by Tristan Schmelcher [tschmelcher@google.com]
// First PulseAudio protocol version that supports PA_STREAM_ADJUST_LATENCY.
const WebRtc_UWord32 WEBRTC_PA_ADJUST_LATENCY_PROTOCOL_VERSION = 13;
// Some timing constants for optimal operation. See
// https://tango.0pointer.de/pipermail/pulseaudio-discuss/2008-January/001170.html
// for a good explanation of some of the factors that go into this.
// Playback.
// For playback, there is a round-trip delay to fill the server-side playback
// buffer, so setting too low of a latency is a buffer underflow risk. We will
// automatically increase the latency if a buffer underflow does occur, but we
// also enforce a sane minimum at start-up time. Anything lower would be
// virtually guaranteed to underflow at least once, so there's no point in
// allowing lower latencies.
const WebRtc_UWord32 WEBRTC_PA_PLAYBACK_LATENCY_MINIMUM_MSECS = 20;
// Every time a playback stream underflows, we will reconfigure it with target
// latency that is greater by this amount.
const WebRtc_UWord32 WEBRTC_PA_PLAYBACK_LATENCY_INCREMENT_MSECS = 20;
// We also need to configure a suitable request size. Too small and we'd burn
// CPU from the overhead of transfering small amounts of data at once. Too large
// and the amount of data remaining in the buffer right before refilling it
// would be a buffer underflow risk. We set it to half of the buffer size.
const WebRtc_UWord32 WEBRTC_PA_PLAYBACK_REQUEST_FACTOR = 2;
// Capture.
// For capture, low latency is not a buffer overflow risk, but it makes us burn
// CPU from the overhead of transfering small amounts of data at once, so we set
// a recommended value that we use for the kLowLatency constant (but if the user
// explicitly requests something lower then we will honour it).
// 1ms takes about 6-7% CPU. 5ms takes about 5%. 10ms takes about 4.x%.
const WebRtc_UWord32 WEBRTC_PA_LOW_CAPTURE_LATENCY_MSECS = 10;
// There is a round-trip delay to ack the data to the server, so the
// server-side buffer needs extra space to prevent buffer overflow. 20ms is
// sufficient, but there is no penalty to making it bigger, so we make it huge.
// (750ms is libpulse's default value for the _total_ buffer size in the
// kNoLatencyRequirements case.)
const WebRtc_UWord32 WEBRTC_PA_CAPTURE_BUFFER_EXTRA_MSECS = 750;
const WebRtc_UWord32 WEBRTC_PA_MSECS_PER_SEC = 1000;
// Init _configuredLatencyRec/Play to this value to disable latency requirements
const WebRtc_Word32 WEBRTC_PA_NO_LATENCY_REQUIREMENTS = -1;
// Set this const to 1 to account for peeked and used data in latency calculation
const WebRtc_UWord32 WEBRTC_PA_CAPTURE_BUFFER_LATENCY_ADJUSTMENT = 0;
namespace webrtc
{
class EventWrapper;
class ThreadWrapper;
class AudioDeviceLinuxPulse: public AudioDeviceGeneric
{
public:
AudioDeviceLinuxPulse(const WebRtc_Word32 id);
~AudioDeviceLinuxPulse();
static bool PulseAudioIsSupported();
// Retrieve the currently utilized audio layer
virtual WebRtc_Word32
ActiveAudioLayer(AudioDeviceModule::AudioLayer& audioLayer) const;
// Main initializaton and termination
virtual WebRtc_Word32 Init();
virtual WebRtc_Word32 Terminate();
virtual bool Initialized() const;
// Device enumeration
virtual WebRtc_Word16 PlayoutDevices();
virtual WebRtc_Word16 RecordingDevices();
virtual WebRtc_Word32 PlayoutDeviceName(
WebRtc_UWord16 index,
WebRtc_Word8 name[kAdmMaxDeviceNameSize],
WebRtc_Word8 guid[kAdmMaxGuidSize]);
virtual WebRtc_Word32 RecordingDeviceName(
WebRtc_UWord16 index,
WebRtc_Word8 name[kAdmMaxDeviceNameSize],
WebRtc_Word8 guid[kAdmMaxGuidSize]);
// Device selection
virtual WebRtc_Word32 SetPlayoutDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetPlayoutDevice(
AudioDeviceModule::WindowsDeviceType device);
virtual WebRtc_Word32 SetRecordingDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetRecordingDevice(
AudioDeviceModule::WindowsDeviceType device);
// Audio transport initialization
virtual WebRtc_Word32 PlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 InitPlayout();
virtual bool PlayoutIsInitialized() const;
virtual WebRtc_Word32 RecordingIsAvailable(bool& available);
virtual WebRtc_Word32 InitRecording();
virtual bool RecordingIsInitialized() const;
// Audio transport control
virtual WebRtc_Word32 StartPlayout();
virtual WebRtc_Word32 StopPlayout();
virtual bool Playing() const;
virtual WebRtc_Word32 StartRecording();
virtual WebRtc_Word32 StopRecording();
virtual bool Recording() const;
// Microphone Automatic Gain Control (AGC)
virtual WebRtc_Word32 SetAGC(bool enable);
virtual bool AGC() const;
// Volume control based on the Windows Wave API (Windows only)
virtual WebRtc_Word32 SetWaveOutVolume(WebRtc_UWord16 volumeLeft,
WebRtc_UWord16 volumeRight);
virtual WebRtc_Word32 WaveOutVolume(WebRtc_UWord16& volumeLeft,
WebRtc_UWord16& volumeRight) const;
// Audio mixer initialization
virtual WebRtc_Word32 SpeakerIsAvailable(bool& available);
virtual WebRtc_Word32 InitSpeaker();
virtual bool SpeakerIsInitialized() const;
virtual WebRtc_Word32 MicrophoneIsAvailable(bool& available);
virtual WebRtc_Word32 InitMicrophone();
virtual bool MicrophoneIsInitialized() const;
// Speaker volume controls
virtual WebRtc_Word32 SpeakerVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 SpeakerVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32 SpeakerVolumeStepSize(WebRtc_UWord16& stepSize) const;
// Microphone volume controls
virtual WebRtc_Word32 MicrophoneVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxMicrophoneVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinMicrophoneVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32 MicrophoneVolumeStepSize(
WebRtc_UWord16& stepSize) const;
// Speaker mute control
virtual WebRtc_Word32 SpeakerMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerMute(bool enable);
virtual WebRtc_Word32 SpeakerMute(bool& enabled) const;
// Microphone mute control
virtual WebRtc_Word32 MicrophoneMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneMute(bool enable);
virtual WebRtc_Word32 MicrophoneMute(bool& enabled) const;
// Microphone boost control
virtual WebRtc_Word32 MicrophoneBoostIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneBoost(bool enable);
virtual WebRtc_Word32 MicrophoneBoost(bool& enabled) const;
// Stereo support
virtual WebRtc_Word32 StereoPlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoPlayout(bool enable);
virtual WebRtc_Word32 StereoPlayout(bool& enabled) const;
virtual WebRtc_Word32 StereoRecordingIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoRecording(bool enable);
virtual WebRtc_Word32 StereoRecording(bool& enabled) const;
// Delay information and control
virtual WebRtc_Word32
SetPlayoutBuffer(const AudioDeviceModule::BufferType type,
WebRtc_UWord16 sizeMS);
virtual WebRtc_Word32 PlayoutBuffer(AudioDeviceModule::BufferType& type,
WebRtc_UWord16& sizeMS) const;
virtual WebRtc_Word32 PlayoutDelay(WebRtc_UWord16& delayMS) const;
virtual WebRtc_Word32 RecordingDelay(WebRtc_UWord16& delayMS) const;
// CPU load
virtual WebRtc_Word32 CPULoad(WebRtc_UWord16& load) const;
public:
virtual bool PlayoutWarning() const;
virtual bool PlayoutError() const;
virtual bool RecordingWarning() const;
virtual bool RecordingError() const;
virtual void ClearPlayoutWarning();
virtual void ClearPlayoutError();
virtual void ClearRecordingWarning();
virtual void ClearRecordingError();
public:
virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer);
private:
void Lock()
{
_critSect.Enter();
}
;
void UnLock()
{
_critSect.Leave();
}
;
void WaitForOperationCompletion(pa_operation* paOperation) const;
void WaitForSuccess(pa_operation* paOperation) const;
private:
static void PaContextStateCallback(pa_context *c, void *pThis);
static void PaSinkInfoCallback(pa_context *c, const pa_sink_info *i,
int eol, void *pThis);
static void PaSourceInfoCallback(pa_context *c, const pa_source_info *i,
int eol, void *pThis);
static void PaServerInfoCallback(pa_context *c, const pa_server_info *i,
void *pThis);
static void PaStreamStateCallback(pa_stream *p, void *pThis);
void PaContextStateCallbackHandler(pa_context *c);
void PaSinkInfoCallbackHandler(const pa_sink_info *i, int eol);
void PaSourceInfoCallbackHandler(const pa_source_info *i, int eol);
void PaServerInfoCallbackHandler(const pa_server_info *i);
void PaStreamStateCallbackHandler(pa_stream *p);
void EnableWriteCallback();
void DisableWriteCallback();
static void PaStreamWriteCallback(pa_stream *unused, size_t buffer_space,
void *pThis);
void PaStreamWriteCallbackHandler(size_t buffer_space);
static void PaStreamUnderflowCallback(pa_stream *unused, void *pThis);
void PaStreamUnderflowCallbackHandler();
void EnableReadCallback();
void DisableReadCallback();
static void PaStreamReadCallback(pa_stream *unused1, size_t unused2,
void *pThis);
void PaStreamReadCallbackHandler();
static void PaStreamOverflowCallback(pa_stream *unused, void *pThis);
void PaStreamOverflowCallbackHandler();
WebRtc_Word32 LatencyUsecs(pa_stream *stream);
WebRtc_Word32 ReadRecordedData(const void* bufferData, size_t bufferSize);
WebRtc_Word32 ProcessRecordedData(WebRtc_Word8 *bufferData,
WebRtc_UWord32 bufferSizeInSamples,
WebRtc_UWord32 recDelay);
WebRtc_Word32 CheckPulseAudioVersion();
WebRtc_Word32 InitSamplingFrequency();
WebRtc_Word32 GetDefaultDeviceInfo(bool recDevice, WebRtc_Word8* name,
WebRtc_UWord16& index);
WebRtc_Word32 InitPulseAudio();
WebRtc_Word32 TerminatePulseAudio();
void PaLock();
void PaUnLock();
static bool RecThreadFunc(void*);
static bool PlayThreadFunc(void*);
bool RecThreadProcess();
bool PlayThreadProcess();
private:
AudioDeviceBuffer* _ptrAudioBuffer;
CriticalSectionWrapper& _critSect;
EventWrapper& _timeEventRec;
EventWrapper& _timeEventPlay;
EventWrapper& _recStartEvent;
EventWrapper& _playStartEvent;
ThreadWrapper* _ptrThreadPlay;
ThreadWrapper* _ptrThreadRec;
WebRtc_UWord32 _recThreadID;
WebRtc_UWord32 _playThreadID;
WebRtc_Word32 _id;
AudioMixerManagerLinuxPulse _mixerManager;
WebRtc_UWord16 _inputDeviceIndex;
WebRtc_UWord16 _outputDeviceIndex;
bool _inputDeviceIsSpecified;
bool _outputDeviceIsSpecified;
WebRtc_UWord32 _samplingFreq;
WebRtc_UWord8 _recChannels;
WebRtc_UWord8 _playChannels;
AudioDeviceModule::BufferType _playBufType;
private:
bool _initialized;
bool _recording;
bool _playing;
bool _recIsInitialized;
bool _playIsInitialized;
bool _startRec;
bool _stopRec;
bool _startPlay;
bool _stopPlay;
bool _AGC;
private:
WebRtc_UWord16 _playBufDelayFixed; // fixed playback delay
WebRtc_UWord32 _sndCardPlayDelay;
WebRtc_UWord32 _sndCardRecDelay;
WebRtc_Word32 _writeErrors;
WebRtc_UWord16 _playWarning;
WebRtc_UWord16 _playError;
WebRtc_UWord16 _recWarning;
WebRtc_UWord16 _recError;
WebRtc_UWord16 _deviceIndex;
WebRtc_Word16 _numPlayDevices;
WebRtc_Word16 _numRecDevices;
WebRtc_Word8* _playDeviceName;
WebRtc_Word8* _recDeviceName;
WebRtc_Word8* _playDisplayDeviceName;
WebRtc_Word8* _recDisplayDeviceName;
WebRtc_Word8 _paServerVersion[32];
WebRtc_Word8* _playBuffer;
size_t _playbackBufferSize;
size_t _playbackBufferUnused;
size_t _tempBufferSpace;
WebRtc_Word8* _recBuffer;
size_t _recordBufferSize;
size_t _recordBufferUsed;
const void* _tempSampleData;
size_t _tempSampleDataSize;
WebRtc_Word32 _configuredLatencyPlay;
WebRtc_Word32 _configuredLatencyRec;
// PulseAudio
WebRtc_UWord16 _paDeviceIndex;
bool _paStateChanged;
pa_threaded_mainloop* _paMainloop;
pa_mainloop_api* _paMainloopApi;
pa_context* _paContext;
pa_stream* _recStream;
pa_stream* _playStream;
WebRtc_UWord32 _recStreamFlags;
WebRtc_UWord32 _playStreamFlags;
pa_buffer_attr _playBufferAttr;
pa_buffer_attr _recBufferAttr;
};
}
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_DEVICE_PULSE_LINUX_H_

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "audio_device_utility_linux.h"
#include "audio_device_config.h" // DEBUG_PRINT()
#include "critical_section_wrapper.h"
#include "trace.h"
namespace webrtc
{
AudioDeviceUtilityLinux::AudioDeviceUtilityLinux(const WebRtc_Word32 id) :
_critSect(*CriticalSectionWrapper::CreateCriticalSection()), _id(id),
_lastError(AudioDeviceModule::kAdmErrNone)
{
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id,
"%s created", __FUNCTION__);
}
AudioDeviceUtilityLinux::~AudioDeviceUtilityLinux()
{
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id,
"%s destroyed", __FUNCTION__);
{
CriticalSectionScoped lock(_critSect);
// free stuff here...
}
delete &_critSect;
}
// ============================================================================
// API
// ============================================================================
WebRtc_Word32 AudioDeviceUtilityLinux::Init()
{
WEBRTC_TRACE(kTraceModuleCall, kTraceAudioDevice, _id,
"%s", __FUNCTION__);
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
" OS info: %s", "Linux");
return 0;
}
} // namespace webrtc

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_LINUX_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_LINUX_H
#include "audio_device_utility.h"
#include "audio_device.h"
namespace webrtc
{
class CriticalSectionWrapper;
class AudioDeviceUtilityLinux: public AudioDeviceUtility
{
public:
AudioDeviceUtilityLinux(const WebRtc_Word32 id);
~AudioDeviceUtilityLinux();
virtual WebRtc_Word32 Init();
private:
CriticalSectionWrapper& _critSect;
WebRtc_Word32 _id;
AudioDeviceModule::ErrorCode _lastError;
};
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_DEVICE_UTILITY_LINUX_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,78 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_ALSA_LINUX_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_ALSA_LINUX_H
#include "typedefs.h"
#include "audio_device.h"
#include "critical_section_wrapper.h"
#include "alsasymboltable_linux.h"
#include <alsa/asoundlib.h>
namespace webrtc
{
class AudioMixerManagerLinuxALSA
{
public:
WebRtc_Word32 OpenSpeaker(char* deviceName);
WebRtc_Word32 OpenMicrophone(char* deviceName);
WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
WebRtc_Word32 SpeakerVolume(WebRtc_UWord32& volume) const;
WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32& maxVolume) const;
WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32& minVolume) const;
WebRtc_Word32 SpeakerVolumeStepSize(WebRtc_UWord16& stepSize) const;
WebRtc_Word32 SpeakerVolumeIsAvailable(bool& available);
WebRtc_Word32 SpeakerMuteIsAvailable(bool& available);
WebRtc_Word32 SetSpeakerMute(bool enable);
WebRtc_Word32 SpeakerMute(bool& enabled) const;
WebRtc_Word32 MicrophoneMuteIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneMute(bool enable);
WebRtc_Word32 MicrophoneMute(bool& enabled) const;
WebRtc_Word32 MicrophoneBoostIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneBoost(bool enable);
WebRtc_Word32 MicrophoneBoost(bool& enabled) const;
WebRtc_Word32 MicrophoneVolumeIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32& volume) const;
WebRtc_Word32 MaxMicrophoneVolume(WebRtc_UWord32& maxVolume) const;
WebRtc_Word32 MinMicrophoneVolume(WebRtc_UWord32& minVolume) const;
WebRtc_Word32 MicrophoneVolumeStepSize(WebRtc_UWord16& stepSize) const;
WebRtc_Word32 Close();
WebRtc_Word32 CloseSpeaker();
WebRtc_Word32 CloseMicrophone();
bool SpeakerIsInitialized() const;
bool MicrophoneIsInitialized() const;
public:
AudioMixerManagerLinuxALSA(const WebRtc_Word32 id);
~AudioMixerManagerLinuxALSA();
private:
WebRtc_Word32 LoadMicMixerElement() const;
WebRtc_Word32 LoadSpeakerMixerElement() const;
void GetControlName(char *controlName, char* deviceName) const;
private:
CriticalSectionWrapper& _critSect;
WebRtc_Word32 _id;
mutable snd_mixer_t* _outputMixerHandle;
char _outputMixerStr[kAdmMaxDeviceNameSize];
mutable snd_mixer_t* _inputMixerHandle;
char _inputMixerStr[kAdmMaxDeviceNameSize];
mutable snd_mixer_elem_t* _outputMixerElement;
mutable snd_mixer_elem_t* _inputMixerElement;
};
}
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_MIXER_MANAGER_ALSA_LINUX_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_PULSE_LINUX_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_PULSE_LINUX_H
#include "typedefs.h"
#include "audio_device.h"
#include "critical_section_wrapper.h"
#include "pulseaudiosymboltable_linux.h"
#include <stdint.h>
#include <pulse/pulseaudio.h>
#ifndef UINT32_MAX
#define UINT32_MAX ((uint32_t)-1)
#endif
namespace webrtc
{
class AudioMixerManagerLinuxPulse
{
public:
WebRtc_Word32 SetPlayStream(pa_stream* playStream);
WebRtc_Word32 SetRecStream(pa_stream* recStream);
WebRtc_Word32 OpenSpeaker(WebRtc_UWord16 deviceIndex);
WebRtc_Word32 OpenMicrophone(WebRtc_UWord16 deviceIndex);
WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
WebRtc_Word32 SpeakerVolume(WebRtc_UWord32& volume) const;
WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32& maxVolume) const;
WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32& minVolume) const;
WebRtc_Word32 SpeakerVolumeStepSize(WebRtc_UWord16& stepSize) const;
WebRtc_Word32 SpeakerVolumeIsAvailable(bool& available);
WebRtc_Word32 SpeakerMuteIsAvailable(bool& available);
WebRtc_Word32 SetSpeakerMute(bool enable);
WebRtc_Word32 StereoPlayoutIsAvailable(bool& available);
WebRtc_Word32 StereoRecordingIsAvailable(bool& available);
WebRtc_Word32 SpeakerMute(bool& enabled) const;
WebRtc_Word32 MicrophoneMuteIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneMute(bool enable);
WebRtc_Word32 MicrophoneMute(bool& enabled) const;
WebRtc_Word32 MicrophoneBoostIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneBoost(bool enable);
WebRtc_Word32 MicrophoneBoost(bool& enabled) const;
WebRtc_Word32 MicrophoneVolumeIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32& volume) const;
WebRtc_Word32 MaxMicrophoneVolume(WebRtc_UWord32& maxVolume) const;
WebRtc_Word32 MinMicrophoneVolume(WebRtc_UWord32& minVolume) const;
WebRtc_Word32 MicrophoneVolumeStepSize(WebRtc_UWord16& stepSize) const;
WebRtc_Word32 SetPulseAudioObjects(pa_threaded_mainloop* mainloop,
pa_context* context);
WebRtc_Word32 Close();
WebRtc_Word32 CloseSpeaker();
WebRtc_Word32 CloseMicrophone();
bool SpeakerIsInitialized() const;
bool MicrophoneIsInitialized() const;
public:
AudioMixerManagerLinuxPulse(const WebRtc_Word32 id);
~AudioMixerManagerLinuxPulse();
private:
static void PaSinkInfoCallback(pa_context *c, const pa_sink_info *i,
int eol, void *pThis);
static void PaSinkInputInfoCallback(pa_context *c,
const pa_sink_input_info *i, int eol,
void *pThis);
static void PaSourceInfoCallback(pa_context *c, const pa_source_info *i,
int eol, void *pThis);
static void
PaSetVolumeCallback(pa_context * /*c*/, int success, void */*pThis*/);
void PaSinkInfoCallbackHandler(const pa_sink_info *i, int eol);
void PaSinkInputInfoCallbackHandler(const pa_sink_input_info *i, int eol);
void PaSourceInfoCallbackHandler(const pa_source_info *i, int eol);
void ResetCallbackVariables() const;
void WaitForOperationCompletion(pa_operation* paOperation) const;
void PaLock() const;
void PaUnLock() const;
private:
CriticalSectionWrapper& _critSect;
WebRtc_Word32 _id;
WebRtc_Word16 _paOutputDeviceIndex;
WebRtc_Word16 _paInputDeviceIndex;
pa_stream* _paPlayStream;
pa_stream* _paRecStream;
pa_threaded_mainloop* _paMainloop;
pa_context* _paContext;
mutable WebRtc_UWord32 _paVolume;
mutable WebRtc_UWord32 _paMute;
mutable WebRtc_UWord32 _paVolSteps;
bool _paSpeakerMute;
mutable WebRtc_UWord32 _paSpeakerVolume;
mutable WebRtc_UWord8 _paChannels;
bool _paObjectsSet;
mutable bool _callbackValues;
WebRtc_UWord8 _micVolChannels;
WebRtc_UWord8 _spkVolChannels;
};
}
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_MIXER_MANAGER_PULSE_LINUX_H_

View File

@ -0,0 +1,116 @@
/*
* 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 "latebindingsymboltable_linux.h"
#ifdef WEBRTC_LINUX
#include <dlfcn.h>
#endif
// TODO(grunell): Either put inside webrtc namespace or use webrtc:: instead.
using namespace webrtc;
namespace webrtc_adm_linux {
inline static const char *GetDllError() {
#ifdef WEBRTC_LINUX
char *err = dlerror();
if (err) {
return err;
} else {
return "No error";
}
#else
#error Not implemented
#endif
}
DllHandle InternalLoadDll(const char dll_name[]) {
#ifdef WEBRTC_LINUX
DllHandle handle = dlopen(dll_name, RTLD_NOW);
#else
#error Not implemented
#endif
if (handle == kInvalidDllHandle) {
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, -1,
"Can't load %s : %d", dll_name, GetDllError());
}
return handle;
}
void InternalUnloadDll(DllHandle handle) {
#ifdef WEBRTC_LINUX
if (dlclose(handle) != 0) {
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1,
"%d", GetDllError());
}
#else
#error Not implemented
#endif
}
static bool LoadSymbol(DllHandle handle,
const char *symbol_name,
void **symbol) {
#ifdef WEBRTC_LINUX
*symbol = dlsym(handle, symbol_name);
char *err = dlerror();
if (err) {
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1,
"Error loading symbol %s : %d", symbol_name, err);
return false;
} else if (!*symbol) {
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1,
"Symbol %s is NULL", symbol_name);
return false;
}
return true;
#else
#error Not implemented
#endif
}
// This routine MUST assign SOME value for every symbol, even if that value is
// NULL, or else some symbols may be left with uninitialized data that the
// caller may later interpret as a valid address.
bool InternalLoadSymbols(DllHandle handle,
int num_symbols,
const char *const symbol_names[],
void *symbols[]) {
#ifdef WEBRTC_LINUX
// Clear any old errors.
dlerror();
#endif
for (int i = 0; i < num_symbols; ++i) {
if (!LoadSymbol(handle, symbol_names[i], &symbols[i])) {
return false;
}
}
return true;
}
} // namespace webrtc_adm_linux

View File

@ -0,0 +1,195 @@
/*
* 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 WEBRTC_AUDIO_DEVICE_LATEBINDINGSYMBOLTABLE_LINUX_H
#define WEBRTC_AUDIO_DEVICE_LATEBINDINGSYMBOLTABLE_LINUX_H
#include <assert.h>
#include <stddef.h> // for NULL
#include <string.h>
#include "constructor_magic.h"
#include "trace.h"
// This file provides macros for creating "symbol table" classes to simplify the
// dynamic loading of symbols from DLLs. Currently the implementation only
// supports Linux and pure C symbols.
// See talk/sound/pulseaudiosymboltable.(h|cc) for an example.
namespace webrtc_adm_linux {
#ifdef WEBRTC_LINUX
typedef void *DllHandle;
const DllHandle kInvalidDllHandle = NULL;
#else
#error Not implemented
#endif
// These are helpers for use only by the class below.
DllHandle InternalLoadDll(const char dll_name[]);
void InternalUnloadDll(DllHandle handle);
bool InternalLoadSymbols(DllHandle handle,
int num_symbols,
const char *const symbol_names[],
void *symbols[]);
template <int SYMBOL_TABLE_SIZE,
const char kDllName[],
const char *const kSymbolNames[]>
class LateBindingSymbolTable {
public:
LateBindingSymbolTable()
: handle_(kInvalidDllHandle),
undefined_symbols_(false) {
memset(symbols_, 0, sizeof(symbols_));
}
~LateBindingSymbolTable() {
Unload();
}
static int NumSymbols() {
return SYMBOL_TABLE_SIZE;
}
// We do not use this, but we offer it for theoretical convenience.
static const char *GetSymbolName(int index) {
assert(index < NumSymbols());
return kSymbolNames[index];
}
bool IsLoaded() const {
return handle_ != kInvalidDllHandle;
}
// Loads the DLL and the symbol table. Returns true iff the DLL and symbol
// table loaded successfully.
bool Load() {
if (IsLoaded()) {
return true;
}
if (undefined_symbols_) {
// We do not attempt to load again because repeated attempts are not
// likely to succeed and DLL loading is costly.
//WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1,
// "We know there are undefined symbols");
return false;
}
handle_ = InternalLoadDll(kDllName);
if (!IsLoaded()) {
return false;
}
if (!InternalLoadSymbols(handle_, NumSymbols(), kSymbolNames, symbols_)) {
undefined_symbols_ = true;
Unload();
return false;
}
return true;
}
void Unload() {
if (!IsLoaded()) {
return;
}
InternalUnloadDll(handle_);
handle_ = kInvalidDllHandle;
memset(symbols_, 0, sizeof(symbols_));
}
// Retrieves the given symbol. NOTE: Recommended to use LATESYM_GET below
// instead of this.
void *GetSymbol(int index) const {
assert(IsLoaded());
assert(index < NumSymbols());
return symbols_[index];
}
private:
DllHandle handle_;
bool undefined_symbols_;
void *symbols_[SYMBOL_TABLE_SIZE];
DISALLOW_COPY_AND_ASSIGN(LateBindingSymbolTable);
};
// This macro must be invoked in a header to declare a symbol table class.
#define LATE_BINDING_SYMBOL_TABLE_DECLARE_BEGIN(ClassName) \
enum {
// This macro must be invoked in the header declaration once for each symbol
// (recommended to use an X-Macro to avoid duplication).
// This macro defines an enum with names built from the symbols, which
// essentially creates a hash table in the compiler from symbol names to their
// indices in the symbol table class.
#define LATE_BINDING_SYMBOL_TABLE_DECLARE_ENTRY(ClassName, sym) \
ClassName##_SYMBOL_TABLE_INDEX_##sym,
// This macro completes the header declaration.
#define LATE_BINDING_SYMBOL_TABLE_DECLARE_END(ClassName) \
ClassName##_SYMBOL_TABLE_SIZE \
}; \
\
extern const char ClassName##_kDllName[]; \
extern const char *const \
ClassName##_kSymbolNames[ClassName##_SYMBOL_TABLE_SIZE]; \
\
typedef ::webrtc_adm_linux::LateBindingSymbolTable<ClassName##_SYMBOL_TABLE_SIZE, \
ClassName##_kDllName, \
ClassName##_kSymbolNames> \
ClassName;
// This macro must be invoked in a .cc file to define a previously-declared
// symbol table class.
#define LATE_BINDING_SYMBOL_TABLE_DEFINE_BEGIN(ClassName, dllName) \
const char ClassName##_kDllName[] = dllName; \
const char *const ClassName##_kSymbolNames[ClassName##_SYMBOL_TABLE_SIZE] = {
// This macro must be invoked in the .cc definition once for each symbol
// (recommended to use an X-Macro to avoid duplication).
// This would have to use the mangled name if we were to ever support C++
// symbols.
#define LATE_BINDING_SYMBOL_TABLE_DEFINE_ENTRY(ClassName, sym) \
#sym,
#define LATE_BINDING_SYMBOL_TABLE_DEFINE_END(ClassName) \
};
// Index of a given symbol in the given symbol table class.
#define LATESYM_INDEXOF(ClassName, sym) \
(ClassName##_SYMBOL_TABLE_INDEX_##sym)
// Returns a reference to the given late-binded symbol, with the correct type.
#define LATESYM_GET(ClassName, inst, sym) \
(*reinterpret_cast<typeof(&sym)>( \
(inst)->GetSymbol(LATESYM_INDEXOF(ClassName, sym))))
} // namespace webrtc_adm_linux
#endif // WEBRTC_ADM_LATEBINDINGSYMBOLTABLE_LINUX_H

View File

@ -0,0 +1,39 @@
/*
* 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 "pulseaudiosymboltable_linux.h"
namespace webrtc_adm_linux_pulse {
LATE_BINDING_SYMBOL_TABLE_DEFINE_BEGIN(PulseAudioSymbolTable, "libpulse.so.0")
#define X(sym) \
LATE_BINDING_SYMBOL_TABLE_DEFINE_ENTRY(PulseAudioSymbolTable, sym)
PULSE_AUDIO_SYMBOLS_LIST
#undef X
LATE_BINDING_SYMBOL_TABLE_DEFINE_END(PulseAudioSymbolTable)
} // namespace webrtc_adm_linux_pulse

View File

@ -0,0 +1,104 @@
/*
* 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 WEBRTC_AUDIO_DEVICE_PULSEAUDIOSYMBOLTABLE_LINUX_H
#define WEBRTC_AUDIO_DEVICE_PULSEAUDIOSYMBOLTABLE_LINUX_H
#include "latebindingsymboltable_linux.h"
namespace webrtc_adm_linux_pulse {
// The PulseAudio symbols we need, as an X-Macro list.
// This list must contain precisely every libpulse function that is used in
// the ADM LINUX PULSE Device and Mixer classes
#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_info_by_index) \
X(pa_context_get_sink_info_by_name) \
X(pa_context_get_sink_input_info) \
X(pa_context_get_source_info_by_index) \
X(pa_context_get_source_info_by_name) \
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_sink_input_mute) \
X(pa_context_set_source_volume_by_index) \
X(pa_context_set_source_mute_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)
LATE_BINDING_SYMBOL_TABLE_DECLARE_BEGIN(PulseAudioSymbolTable)
#define X(sym) \
LATE_BINDING_SYMBOL_TABLE_DECLARE_ENTRY(PulseAudioSymbolTable, sym)
PULSE_AUDIO_SYMBOLS_LIST
#undef X
LATE_BINDING_SYMBOL_TABLE_DECLARE_END(PulseAudioSymbolTable)
} // namespace webrtc_adm_linux_pulse
#endif // WEBRTC_AUDIO_DEVICE_PULSEAUDIOSYMBOLTABLE_LINUX_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,400 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_MAC_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_MAC_H
#include "audio_device_generic.h"
#include "critical_section_wrapper.h"
#include "audio_mixer_manager_mac.h"
#include <CoreAudio/CoreAudio.h>
#include <AudioToolbox/AudioConverter.h>
#include <mach/semaphore.h>
struct PaUtilRingBuffer;
namespace webrtc
{
class EventWrapper;
class ThreadWrapper;
const WebRtc_UWord32 N_REC_SAMPLES_PER_SEC = 48000;
const WebRtc_UWord32 N_PLAY_SAMPLES_PER_SEC = 48000;
const WebRtc_UWord32 N_REC_CHANNELS = 1; // default is mono recording
const WebRtc_UWord32 N_PLAY_CHANNELS = 2; // default is stereo playout
const WebRtc_UWord32 N_DEVICE_CHANNELS = 8;
const WebRtc_UWord32 ENGINE_REC_BUF_SIZE_IN_SAMPLES = (N_REC_SAMPLES_PER_SEC
/ 100);
const WebRtc_UWord32 ENGINE_PLAY_BUF_SIZE_IN_SAMPLES = (N_PLAY_SAMPLES_PER_SEC
/ 100);
enum
{
N_BLOCKS_IO = 2
};
enum
{
N_BUFFERS_IN = 10
};
enum
{
N_BUFFERS_OUT = 3
}; // Must be at least N_BLOCKS_IO
const WebRtc_UWord32 TIMER_PERIOD_MS = (2 * 10 * N_BLOCKS_IO * 1000000);
const WebRtc_UWord32 REC_BUF_SIZE_IN_SAMPLES = (ENGINE_REC_BUF_SIZE_IN_SAMPLES
* N_DEVICE_CHANNELS * N_BUFFERS_IN);
const WebRtc_UWord32 PLAY_BUF_SIZE_IN_SAMPLES =
(ENGINE_PLAY_BUF_SIZE_IN_SAMPLES * N_PLAY_CHANNELS * N_BUFFERS_OUT);
class AudioDeviceMac: public AudioDeviceGeneric
{
public:
AudioDeviceMac(const WebRtc_Word32 id);
~AudioDeviceMac();
// Retrieve the currently utilized audio layer
virtual WebRtc_Word32
ActiveAudioLayer(AudioDeviceModule::AudioLayer& audioLayer) const;
// Main initializaton and termination
virtual WebRtc_Word32 Init();
virtual WebRtc_Word32 Terminate();
virtual bool Initialized() const;
// Device enumeration
virtual WebRtc_Word16 PlayoutDevices();
virtual WebRtc_Word16 RecordingDevices();
virtual WebRtc_Word32 PlayoutDeviceName(
WebRtc_UWord16 index,
WebRtc_Word8 name[kAdmMaxDeviceNameSize],
WebRtc_Word8 guid[kAdmMaxGuidSize]);
virtual WebRtc_Word32 RecordingDeviceName(
WebRtc_UWord16 index,
WebRtc_Word8 name[kAdmMaxDeviceNameSize],
WebRtc_Word8 guid[kAdmMaxGuidSize]);
// Device selection
virtual WebRtc_Word32 SetPlayoutDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetPlayoutDevice(
AudioDeviceModule::WindowsDeviceType device);
virtual WebRtc_Word32 SetRecordingDevice(WebRtc_UWord16 index);
virtual WebRtc_Word32 SetRecordingDevice(
AudioDeviceModule::WindowsDeviceType device);
// Audio transport initialization
virtual WebRtc_Word32 PlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 InitPlayout();
virtual bool PlayoutIsInitialized() const;
virtual WebRtc_Word32 RecordingIsAvailable(bool& available);
virtual WebRtc_Word32 InitRecording();
virtual bool RecordingIsInitialized() const;
// Audio transport control
virtual WebRtc_Word32 StartPlayout();
virtual WebRtc_Word32 StopPlayout();
virtual bool Playing() const;
virtual WebRtc_Word32 StartRecording();
virtual WebRtc_Word32 StopRecording();
virtual bool Recording() const;
// Microphone Automatic Gain Control (AGC)
virtual WebRtc_Word32 SetAGC(bool enable);
virtual bool AGC() const;
// Volume control based on the Windows Wave API (Windows only)
virtual WebRtc_Word32 SetWaveOutVolume(WebRtc_UWord16 volumeLeft,
WebRtc_UWord16 volumeRight);
virtual WebRtc_Word32 WaveOutVolume(WebRtc_UWord16& volumeLeft,
WebRtc_UWord16& volumeRight) const;
// Audio mixer initialization
virtual WebRtc_Word32 SpeakerIsAvailable(bool& available);
virtual WebRtc_Word32 InitSpeaker();
virtual bool SpeakerIsInitialized() const;
virtual WebRtc_Word32 MicrophoneIsAvailable(bool& available);
virtual WebRtc_Word32 InitMicrophone();
virtual bool MicrophoneIsInitialized() const;
// Speaker volume controls
virtual WebRtc_Word32 SpeakerVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 SpeakerVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32 SpeakerVolumeStepSize(WebRtc_UWord16& stepSize) const;
// Microphone volume controls
virtual WebRtc_Word32 MicrophoneVolumeIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
virtual WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32& volume) const;
virtual WebRtc_Word32 MaxMicrophoneVolume(WebRtc_UWord32& maxVolume) const;
virtual WebRtc_Word32 MinMicrophoneVolume(WebRtc_UWord32& minVolume) const;
virtual WebRtc_Word32
MicrophoneVolumeStepSize(WebRtc_UWord16& stepSize) const;
// Microphone mute control
virtual WebRtc_Word32 MicrophoneMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneMute(bool enable);
virtual WebRtc_Word32 MicrophoneMute(bool& enabled) const;
// Speaker mute control
virtual WebRtc_Word32 SpeakerMuteIsAvailable(bool& available);
virtual WebRtc_Word32 SetSpeakerMute(bool enable);
virtual WebRtc_Word32 SpeakerMute(bool& enabled) const;
// Microphone boost control
virtual WebRtc_Word32 MicrophoneBoostIsAvailable(bool& available);
virtual WebRtc_Word32 SetMicrophoneBoost(bool enable);
virtual WebRtc_Word32 MicrophoneBoost(bool& enabled) const;
// Stereo support
virtual WebRtc_Word32 StereoPlayoutIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoPlayout(bool enable);
virtual WebRtc_Word32 StereoPlayout(bool& enabled) const;
virtual WebRtc_Word32 StereoRecordingIsAvailable(bool& available);
virtual WebRtc_Word32 SetStereoRecording(bool enable);
virtual WebRtc_Word32 StereoRecording(bool& enabled) const;
// Delay information and control
virtual WebRtc_Word32
SetPlayoutBuffer(const AudioDeviceModule::BufferType type,
WebRtc_UWord16 sizeMS);
virtual WebRtc_Word32 PlayoutBuffer(AudioDeviceModule::BufferType& type,
WebRtc_UWord16& sizeMS) const;
virtual WebRtc_Word32 PlayoutDelay(WebRtc_UWord16& delayMS) const;
virtual WebRtc_Word32 RecordingDelay(WebRtc_UWord16& delayMS) const;
// CPU load
virtual WebRtc_Word32 CPULoad(WebRtc_UWord16& load) const;
public:
virtual bool PlayoutWarning() const;
virtual bool PlayoutError() const;
virtual bool RecordingWarning() const;
virtual bool RecordingError() const;
virtual void ClearPlayoutWarning();
virtual void ClearPlayoutError();
virtual void ClearRecordingWarning();
virtual void ClearRecordingError();
public:
virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer);
private:
void Lock()
{
_critSect.Enter();
}
;
void UnLock()
{
_critSect.Leave();
}
;
WebRtc_Word32 Id()
{
return _id;
}
static void AtomicSet32(int32_t* theValue, int32_t newValue);
static int32_t AtomicGet32(int32_t* theValue);
static void logCAMsg(const TraceLevel level,
const TraceModule module,
const WebRtc_Word32 id, const char *msg,
const char *err);
WebRtc_Word32 GetNumberDevices(const AudioObjectPropertyScope scope,
AudioDeviceID scopedDeviceIds[],
const WebRtc_UWord32 deviceListLength);
WebRtc_Word32 GetDeviceName(const AudioObjectPropertyScope scope,
const WebRtc_UWord16 index, char* name);
WebRtc_Word32 InitDevice(WebRtc_UWord16 userDeviceIndex,
AudioDeviceID& deviceId, bool isInput);
static OSStatus
objectListenerProc(AudioObjectID objectId, UInt32 numberAddresses,
const AudioObjectPropertyAddress addresses[],
void* clientData);
OSStatus
implObjectListenerProc(AudioObjectID objectId, UInt32 numberAddresses,
const AudioObjectPropertyAddress addresses[]);
WebRtc_Word32 HandleDeviceChange();
WebRtc_Word32
HandleStreamFormatChange(AudioObjectID objectId,
AudioObjectPropertyAddress propertyAddress);
WebRtc_Word32
HandleDataSourceChange(AudioObjectID objectId,
AudioObjectPropertyAddress propertyAddress);
WebRtc_Word32
HandleProcessorOverload(AudioObjectPropertyAddress propertyAddress);
private:
static OSStatus deviceIOProc(AudioDeviceID device,
const AudioTimeStamp *now,
const AudioBufferList *inputData,
const AudioTimeStamp *inputTime,
AudioBufferList *outputData,
const AudioTimeStamp* outputTime,
void *clientData);
static OSStatus
outConverterProc(AudioConverterRef audioConverter,
UInt32 *numberDataPackets, AudioBufferList *data,
AudioStreamPacketDescription **dataPacketDescription,
void *userData);
static OSStatus inDeviceIOProc(AudioDeviceID device,
const AudioTimeStamp *now,
const AudioBufferList *inputData,
const AudioTimeStamp *inputTime,
AudioBufferList *outputData,
const AudioTimeStamp *outputTime,
void *clientData);
static OSStatus
inConverterProc(AudioConverterRef audioConverter,
UInt32 *numberDataPackets, AudioBufferList *data,
AudioStreamPacketDescription **dataPacketDescription,
void *inUserData);
OSStatus implDeviceIOProc(const AudioBufferList *inputData,
const AudioTimeStamp *inputTime,
AudioBufferList *outputData,
const AudioTimeStamp *outputTime);
OSStatus implOutConverterProc(UInt32 *numberDataPackets,
AudioBufferList *data);
OSStatus implInDeviceIOProc(const AudioBufferList *inputData,
const AudioTimeStamp *inputTime);
OSStatus implInConverterProc(UInt32 *numberDataPackets,
AudioBufferList *data);
static bool RunCapture(void*);
static bool RunRender(void*);
bool CaptureWorkerThread();
bool RenderWorkerThread();
private:
AudioDeviceBuffer* _ptrAudioBuffer;
CriticalSectionWrapper& _critSect;
CriticalSectionWrapper& _critSectCb;
EventWrapper& _stopEventRec;
EventWrapper& _stopEvent;
ThreadWrapper* _captureWorkerThread;
ThreadWrapper* _renderWorkerThread;
WebRtc_UWord32 _captureWorkerThreadId;
WebRtc_UWord32 _renderWorkerThreadId;
WebRtc_Word32 _id;
AudioMixerManagerMac _mixerManager;
WebRtc_UWord16 _inputDeviceIndex;
WebRtc_UWord16 _outputDeviceIndex;
AudioDeviceID _inputDeviceID;
AudioDeviceID _outputDeviceID;
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
AudioDeviceIOProcID _inDeviceIOProcID;
AudioDeviceIOProcID _deviceIOProcID;
#endif
bool _inputDeviceIsSpecified;
bool _outputDeviceIsSpecified;
WebRtc_UWord8 _recChannels;
WebRtc_UWord8 _playChannels;
Float32* _captureBufData;
SInt16* _renderBufData;
SInt16 _renderConvertData[PLAY_BUF_SIZE_IN_SAMPLES];
AudioDeviceModule::BufferType _playBufType;
private:
bool _initialized;
bool _isShutDown;
bool _recording;
bool _playing;
bool _recIsInitialized;
bool _playIsInitialized;
bool _startRec;
bool _stopRec;
bool _stopPlay;
bool _AGC;
// Atomically set varaibles
int32_t _renderDeviceIsAlive;
int32_t _captureDeviceIsAlive;
bool _twoDevices;
bool _doStop; // For play if not shared device or play+rec if shared device
bool _doStopRec; // For rec if not shared device
bool _macBookPro;
bool _macBookProPanRight;
bool _stereoRender;
bool _stereoRenderRequested;
AudioConverterRef _captureConverter;
AudioConverterRef _renderConverter;
AudioStreamBasicDescription _outStreamFormat;
AudioStreamBasicDescription _outDesiredFormat;
AudioStreamBasicDescription _inStreamFormat;
AudioStreamBasicDescription _inDesiredFormat;
WebRtc_UWord32 _captureLatencyUs;
WebRtc_UWord32 _renderLatencyUs;
// Atomically set variables
mutable int32_t _captureDelayUs;
mutable int32_t _renderDelayUs;
WebRtc_Word32 _renderDelayOffsetSamples;
private:
WebRtc_UWord16 _playBufDelay; // playback delay
WebRtc_UWord16 _playBufDelayFixed; // fixed playback delay
WebRtc_UWord16 _playWarning;
WebRtc_UWord16 _playError;
WebRtc_UWord16 _recWarning;
WebRtc_UWord16 _recError;
PaUtilRingBuffer* _paCaptureBuffer;
PaUtilRingBuffer* _paRenderBuffer;
semaphore_t _renderSemaphore;
semaphore_t _captureSemaphore;
WebRtc_UWord32 _captureBufSizeSamples;
WebRtc_UWord32 _renderBufSizeSamples;
};
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_MAC_AUDIO_DEVICE_MAC_H_

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_MAC_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_MAC_H
#include "audio_device_utility.h"
#include "audio_device.h"
namespace webrtc
{
class CriticalSectionWrapper;
class AudioDeviceUtilityMac: public AudioDeviceUtility
{
public:
AudioDeviceUtilityMac(const WebRtc_Word32 id);
~AudioDeviceUtilityMac();
virtual WebRtc_Word32 Init();
private:
CriticalSectionWrapper& _critSect;
WebRtc_Word32 _id;
AudioDeviceModule::ErrorCode _lastError;
};
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_MAC_AUDIO_DEVICE_UTILITY_MAC_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_MAC_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_MAC_H
#include "typedefs.h"
#include "audio_device.h"
#include "critical_section_wrapper.h"
#include <CoreAudio/CoreAudio.h>
namespace webrtc {
class AudioMixerManagerMac
{
public:
WebRtc_Word32 OpenSpeaker(AudioDeviceID deviceID);
WebRtc_Word32 OpenMicrophone(AudioDeviceID deviceID);
WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
WebRtc_Word32 SpeakerVolume(WebRtc_UWord32& volume) const;
WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32& maxVolume) const;
WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32& minVolume) const;
WebRtc_Word32 SpeakerVolumeStepSize(WebRtc_UWord16& stepSize) const;
WebRtc_Word32 SpeakerVolumeIsAvailable(bool& available);
WebRtc_Word32 SpeakerMuteIsAvailable(bool& available);
WebRtc_Word32 SetSpeakerMute(bool enable);
WebRtc_Word32 SpeakerMute(bool& enabled) const;
WebRtc_Word32 StereoPlayoutIsAvailable(bool& available);
WebRtc_Word32 StereoRecordingIsAvailable(bool& available);
WebRtc_Word32 MicrophoneMuteIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneMute(bool enable);
WebRtc_Word32 MicrophoneMute(bool& enabled) const;
WebRtc_Word32 MicrophoneBoostIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneBoost(bool enable);
WebRtc_Word32 MicrophoneBoost(bool& enabled) const;
WebRtc_Word32 MicrophoneVolumeIsAvailable(bool& available);
WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32& volume) const;
WebRtc_Word32 MaxMicrophoneVolume(WebRtc_UWord32& maxVolume) const;
WebRtc_Word32 MinMicrophoneVolume(WebRtc_UWord32& minVolume) const;
WebRtc_Word32 MicrophoneVolumeStepSize(WebRtc_UWord16& stepSize) const;
WebRtc_Word32 Close();
WebRtc_Word32 CloseSpeaker();
WebRtc_Word32 CloseMicrophone();
bool SpeakerIsInitialized() const;
bool MicrophoneIsInitialized() const;
public:
AudioMixerManagerMac(const WebRtc_Word32 id);
~AudioMixerManagerMac();
private:
static void logCAMsg(const TraceLevel level,
const TraceModule module,
const WebRtc_Word32 id, const char *msg,
const char *err);
private:
CriticalSectionWrapper& _critSect;
WebRtc_Word32 _id;
AudioDeviceID _inputDeviceID;
AudioDeviceID _outputDeviceID;
WebRtc_UWord16 _noInputChannels;
WebRtc_UWord16 _noOutputChannels;
};
} //namespace webrtc
#endif // AUDIO_MIXER_MAC_H

View File

@ -0,0 +1,127 @@
/*
* $Id: pa_memorybarrier.h 1240 2007-07-17 13:05:07Z bjornroche $
* Portable Audio I/O Library
* Memory barrier utilities
*
* Author: Bjorn Roche, XO Audio, LLC
*
* This program uses the PortAudio Portable Audio Library.
* For more information see: http://www.portaudio.com
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
/**
@file pa_memorybarrier.h
@ingroup common_src
*/
/****************
* Some memory barrier primitives based on the system.
* right now only OS X, FreeBSD, and Linux are supported. In addition to providing
* memory barriers, these functions should ensure that data cached in registers
* is written out to cache where it can be snooped by other CPUs. (ie, the volatile
* keyword should not be required)
*
* the primitives that must be defined are:
*
* PaUtil_FullMemoryBarrier()
* PaUtil_ReadMemoryBarrier()
* PaUtil_WriteMemoryBarrier()
*
****************/
#if defined(__APPLE__)
# include <libkern/OSAtomic.h>
/* Here are the memory barrier functions. Mac OS X only provides
full memory barriers, so the three types of barriers are the same,
however, these barriers are superior to compiler-based ones. */
# define PaUtil_FullMemoryBarrier() OSMemoryBarrier()
# define PaUtil_ReadMemoryBarrier() OSMemoryBarrier()
# define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
#elif defined(__GNUC__)
/* GCC >= 4.1 has built-in intrinsics. We'll use those */
# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
# define PaUtil_FullMemoryBarrier() __sync_synchronize()
# define PaUtil_ReadMemoryBarrier() __sync_synchronize()
# define PaUtil_WriteMemoryBarrier() __sync_synchronize()
/* as a fallback, GCC understands volatile asm and "memory" to mean it
* should not reorder memory read/writes */
/* Note that it is not clear that any compiler actually defines __PPC__,
* it can probably removed safely. */
# elif defined( __ppc__ ) || defined( __powerpc__) || defined( __PPC__ )
# define PaUtil_FullMemoryBarrier() asm volatile("sync":::"memory")
# define PaUtil_ReadMemoryBarrier() asm volatile("sync":::"memory")
# define PaUtil_WriteMemoryBarrier() asm volatile("sync":::"memory")
# elif defined( __i386__ ) || defined( __i486__ ) || defined( __i586__ ) || \
defined( __i686__ ) || defined( __x86_64__ )
# define PaUtil_FullMemoryBarrier() asm volatile("mfence":::"memory")
# define PaUtil_ReadMemoryBarrier() asm volatile("lfence":::"memory")
# define PaUtil_WriteMemoryBarrier() asm volatile("sfence":::"memory")
# else
# ifdef ALLOW_SMP_DANGERS
# warning Memory barriers not defined on this system or system unknown
# warning For SMP safety, you should fix this.
# define PaUtil_FullMemoryBarrier()
# define PaUtil_ReadMemoryBarrier()
# define PaUtil_WriteMemoryBarrier()
# else
# error Memory barriers are not defined on this system. You can still compile by defining ALLOW_SMP_DANGERS, but SMP safety will not be guaranteed.
# endif
# endif
#elif (_MSC_VER >= 1400) && !defined(_WIN32_WCE)
# include <intrin.h>
# pragma intrinsic(_ReadWriteBarrier)
# pragma intrinsic(_ReadBarrier)
# pragma intrinsic(_WriteBarrier)
# define PaUtil_FullMemoryBarrier() _ReadWriteBarrier()
# define PaUtil_ReadMemoryBarrier() _ReadBarrier()
# define PaUtil_WriteMemoryBarrier() _WriteBarrier()
#elif defined(_WIN32_WCE)
# define PaUtil_FullMemoryBarrier()
# define PaUtil_ReadMemoryBarrier()
# define PaUtil_WriteMemoryBarrier()
#elif defined(_MSC_VER) || defined(__BORLANDC__)
# define PaUtil_FullMemoryBarrier() _asm { lock add [esp], 0 }
# define PaUtil_ReadMemoryBarrier() _asm { lock add [esp], 0 }
# define PaUtil_WriteMemoryBarrier() _asm { lock add [esp], 0 }
#else
# ifdef ALLOW_SMP_DANGERS
# warning Memory barriers not defined on this system or system unknown
# warning For SMP safety, you should fix this.
# define PaUtil_FullMemoryBarrier()
# define PaUtil_ReadMemoryBarrier()
# define PaUtil_WriteMemoryBarrier()
# else
# error Memory barriers are not defined on this system. You can still compile by defining ALLOW_SMP_DANGERS, but SMP safety will not be guaranteed.
# endif
#endif

View File

@ -0,0 +1,227 @@
/*
* $Id: pa_ringbuffer.c 1421 2009-11-18 16:09:05Z bjornroche $
* Portable Audio I/O Library
* Ring Buffer utility.
*
* Author: Phil Burk, http://www.softsynth.com
* modified for SMP safety on Mac OS X by Bjorn Roche
* modified for SMP safety on Linux by Leland Lucius
* also, allowed for const where possible
* modified for multiple-byte-sized data elements by Sven Fischer
*
* Note that this is safe only for a single-thread reader and a
* single-thread writer.
*
* This program uses the PortAudio Portable Audio Library.
* For more information see: http://www.portaudio.com
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
/**
@file
@ingroup common_src
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "pa_ringbuffer.h"
#include <string.h>
#include "pa_memorybarrier.h"
/***************************************************************************
* Initialize FIFO.
* elementCount must be power of 2, returns -1 if not.
*/
ring_buffer_size_t PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementSizeBytes, ring_buffer_size_t elementCount, void *dataPtr )
{
if( ((elementCount-1) & elementCount) != 0) return -1; /* Not Power of two. */
rbuf->bufferSize = elementCount;
rbuf->buffer = (char *)dataPtr;
PaUtil_FlushRingBuffer( rbuf );
rbuf->bigMask = (elementCount*2)-1;
rbuf->smallMask = (elementCount)-1;
rbuf->elementSizeBytes = elementSizeBytes;
return 0;
}
/***************************************************************************
** Return number of elements available for reading. */
ring_buffer_size_t PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf )
{
PaUtil_ReadMemoryBarrier();
return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
}
/***************************************************************************
** Return number of elements available for writing. */
ring_buffer_size_t PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf )
{
/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
}
/***************************************************************************
** Clear buffer. Should only be called when buffer is NOT being read. */
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
{
rbuf->writeIndex = rbuf->readIndex = 0;
}
/***************************************************************************
** Get address of region(s) to which we can write data.
** If the region is contiguous, size2 will be zero.
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or elementCount, whichever is smaller.
*/
ring_buffer_size_t PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount,
void **dataPtr1, ring_buffer_size_t *sizePtr1,
void **dataPtr2, ring_buffer_size_t *sizePtr2 )
{
ring_buffer_size_t index;
ring_buffer_size_t available = PaUtil_GetRingBufferWriteAvailable( rbuf );
if( elementCount > available ) elementCount = available;
/* Check to see if write is not contiguous. */
index = rbuf->writeIndex & rbuf->smallMask;
if( (index + elementCount) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
ring_buffer_size_t firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = elementCount - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
*sizePtr1 = elementCount;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return elementCount;
}
/***************************************************************************
*/
ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount )
{
/* we need to ensure that previous writes are seen before we update the write index */
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + elementCount) & rbuf->bigMask;
}
/***************************************************************************
** Get address of region(s) from which we can read data.
** If the region is contiguous, size2 will be zero.
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or elementCount, whichever is smaller.
*/
ring_buffer_size_t PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount,
void **dataPtr1, ring_buffer_size_t *sizePtr1,
void **dataPtr2, ring_buffer_size_t *sizePtr2 )
{
ring_buffer_size_t index;
ring_buffer_size_t available = PaUtil_GetRingBufferReadAvailable( rbuf );
if( elementCount > available ) elementCount = available;
/* Check to see if read is not contiguous. */
index = rbuf->readIndex & rbuf->smallMask;
if( (index + elementCount) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
ring_buffer_size_t firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = elementCount - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
*sizePtr1 = elementCount;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return elementCount;
}
/***************************************************************************
*/
ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount )
{
/* we need to ensure that previous writes are always seen before updating the index. */
PaUtil_WriteMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + elementCount) & rbuf->bigMask;
}
/***************************************************************************
** Return elements written. */
ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount )
{
ring_buffer_size_t size1, size2, numWritten;
void *data1, *data2;
numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
memcpy( data1, data, size1*rbuf->elementSizeBytes );
data = ((char *)data) + size1*rbuf->elementSizeBytes;
memcpy( data2, data, size2*rbuf->elementSizeBytes );
}
else
{
memcpy( data1, data, size1*rbuf->elementSizeBytes );
}
PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
return numWritten;
}
/***************************************************************************
** Return elements read. */
ring_buffer_size_t PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, ring_buffer_size_t elementCount )
{
ring_buffer_size_t size1, size2, numRead;
void *data1, *data2;
numRead = PaUtil_GetRingBufferReadRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
memcpy( data, data1, size1*rbuf->elementSizeBytes );
data = ((char *)data) + size1*rbuf->elementSizeBytes;
memcpy( data, data2, size2*rbuf->elementSizeBytes );
}
else
{
memcpy( data, data1, size1*rbuf->elementSizeBytes );
}
PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead );
return numRead;
}

View File

@ -0,0 +1,233 @@
#ifndef WEBRTC_AUDIO_DEVICE_PA_RINGBUFFER_H
#define WEBRTC_AUDIO_DEVICE_PA_RINGBUFFER_H
/*
* $Id: pa_ringbuffer.h 1421 2009-11-18 16:09:05Z bjornroche $
* Portable Audio I/O Library
* Ring Buffer utility.
*
* Author: Phil Burk, http://www.softsynth.com
* modified for SMP safety on OS X by Bjorn Roche.
* also allowed for const where possible.
* modified for multiple-byte-sized data elements by Sven Fischer
*
* Note that this is safe only for a single-thread reader
* and a single-thread writer.
*
* This program is distributed with the PortAudio Portable Audio Library.
* For more information see: http://www.portaudio.com
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
/** @file
@ingroup common_src
@brief Single-reader single-writer lock-free ring buffer
PaUtilRingBuffer is a ring buffer used to transport samples between
different execution contexts (threads, OS callbacks, interrupt handlers)
without requiring the use of any locks. This only works when there is
a single reader and a single writer (ie. one thread or callback writes
to the ring buffer, another thread or callback reads from it).
The PaUtilRingBuffer structure manages a ring buffer containing N
elements, where N must be a power of two. An element may be any size
(specified in bytes).
The memory area used to store the buffer elements must be allocated by
the client prior to calling PaUtil_InitializeRingBuffer() and must outlive
the use of the ring buffer.
*/
#if defined(__APPLE__)
#include <sys/types.h>
typedef int32_t ring_buffer_size_t;
#elif defined( __GNUC__ )
typedef long ring_buffer_size_t;
#elif (_MSC_VER >= 1400)
typedef long ring_buffer_size_t;
#elif defined(_MSC_VER) || defined(__BORLANDC__)
typedef long ring_buffer_size_t;
#else
typedef long ring_buffer_size_t;
#endif
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
typedef struct PaUtilRingBuffer
{
ring_buffer_size_t bufferSize; /**< Number of elements in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
ring_buffer_size_t writeIndex; /**< Index of next writable element. Set by PaUtil_AdvanceRingBufferWriteIndex. */
ring_buffer_size_t readIndex; /**< Index of next readable element. Set by PaUtil_AdvanceRingBufferReadIndex. */
ring_buffer_size_t bigMask; /**< Used for wrapping indices with extra bit to distinguish full/empty. */
ring_buffer_size_t smallMask; /**< Used for fitting indices to buffer. */
ring_buffer_size_t elementSizeBytes; /**< Number of bytes per element. */
char *buffer; /**< Pointer to the buffer containing the actual data. */
}PaUtilRingBuffer;
/** Initialize Ring Buffer.
@param rbuf The ring buffer.
@param elementSizeBytes The size of a single data element in bytes.
@param elementCount The number of elements in the buffer (must be power of 2).
@param dataPtr A pointer to a previously allocated area where the data
will be maintained. It must be elementCount*elementSizeBytes long.
@return -1 if elementCount is not a power of 2, otherwise 0.
*/
ring_buffer_size_t PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementSizeBytes, ring_buffer_size_t elementCount, void *dataPtr );
/** Clear buffer. Should only be called when buffer is NOT being read.
@param rbuf The ring buffer.
*/
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf );
/** Retrieve the number of elements available in the ring buffer for writing.
@param rbuf The ring buffer.
@return The number of elements available for writing.
*/
ring_buffer_size_t PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf );
/** Retrieve the number of elements available in the ring buffer for reading.
@param rbuf The ring buffer.
@return The number of elements available for reading.
*/
ring_buffer_size_t PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf );
/** Write data to the ring buffer.
@param rbuf The ring buffer.
@param data The address of new data to write to the buffer.
@param elementCount The number of elements to be written.
@return The number of elements written.
*/
ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount );
/** Read data from the ring buffer.
@param rbuf The ring buffer.
@param data The address where the data should be stored.
@param elementCount The number of elements to be read.
@return The number of elements read.
*/
ring_buffer_size_t PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, ring_buffer_size_t elementCount );
/** Get address of region(s) to which we can write data.
@param rbuf The ring buffer.
@param elementCount The number of elements desired.
@param dataPtr1 The address where the first (or only) region pointer will be
stored.
@param sizePtr1 The address where the first (or only) region length will be
stored.
@param dataPtr2 The address where the second region pointer will be stored if
the first region is too small to satisfy elementCount.
@param sizePtr2 The address where the second region length will be stored if
the first region is too small to satisfy elementCount.
@return The room available to be written or elementCount, whichever is smaller.
*/
ring_buffer_size_t PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount,
void **dataPtr1, ring_buffer_size_t *sizePtr1,
void **dataPtr2, ring_buffer_size_t *sizePtr2 );
/** Advance the write index to the next location to be written.
@param rbuf The ring buffer.
@param elementCount The number of elements to advance.
@return The new position.
*/
ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount );
/** Get address of region(s) from which we can write data.
@param rbuf The ring buffer.
@param elementCount The number of elements desired.
@param dataPtr1 The address where the first (or only) region pointer will be
stored.
@param sizePtr1 The address where the first (or only) region length will be
stored.
@param dataPtr2 The address where the second region pointer will be stored if
the first region is too small to satisfy elementCount.
@param sizePtr2 The address where the second region length will be stored if
the first region is too small to satisfy elementCount.
@return The number of elements available for reading.
*/
ring_buffer_size_t PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount,
void **dataPtr1, ring_buffer_size_t *sizePtr1,
void **dataPtr2, ring_buffer_size_t *sizePtr2 );
/** Advance the read index to the next location to be read.
@param rbuf The ring buffer.
@param elementCount The number of elements to advance.
@return The new position.
*/
ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* MODULES_AUDIO_DEVICE_MAIN_SOURCE_MAC_PORTAUDIO_PA_RINGBUFFER_H_ */

View File

@ -29,7 +29,7 @@
#ifdef WEBRTC_WINDOWS_CORE_AUDIO_BUILD
#include "audio_device_utility.h"
#include "audio_device_windows_core.h"
#include "audio_device_core_win.h"
#include "trace.h"
#include <windows.h>

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WINDOWS_CORE_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WINDOWS_CORE_H
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_CORE_WIN_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_CORE_WIN_H
#if (_MSC_VER >= 1400) // only include for VS 2005 and higher
@ -309,5 +309,5 @@ private:
} // namespace webrtc
#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WINDOWS_CORE_H
#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_CORE_WIN_H

View File

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "audio_device_utility_windows.h"
#include "audio_device_utility_win.h"
#include "audio_device_config.h"
#include "critical_section_wrapper.h"

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_WINDOWS_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_WINDOWS_H
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_WIN_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_WIN_H
#include "audio_device_utility.h"
#include "audio_device.h"
@ -38,4 +38,4 @@ private:
} // namespace webrtc
#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_WINDOWS_H
#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_UTILITY_WIN_H

View File

@ -9,7 +9,7 @@
*/
#include "audio_device_utility.h"
#include "audio_device_windows_wave.h"
#include "audio_device_wave_win.h"
#include "audio_device_config.h"
#include "trace.h"

View File

@ -8,11 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WINDOWS_WAVE_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WINDOWS_WAVE_H
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WAVE_WIN_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WAVE_WIN_H
#include "audio_device_generic.h"
#include "audio_mixer_manager.h"
#include "audio_mixer_manager_win.h"
#pragma comment( lib, "winmm.lib" )
@ -330,4 +330,4 @@ private:
} // namespace webrtc
#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WINDOWS_WAVE_H
#endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WAVE_WIN_H

View File

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "audio_mixer_manager.h"
#include "audio_mixer_manager_win.h"
#include "trace.h"
#include <strsafe.h> // StringCchCopy(), StringCchCat(), StringCchPrintf()

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_H
#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_WIN_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_WIN_H
#include "typedefs.h"
#include "audio_device.h"