Commit 2377472f authored by Adrien Béraud's avatar Adrien Béraud

OpenSL: prevent buffer copy, cleanup

Make AudioQueue and sample_buf non-copyable to avoid
implicit copies and memory corruption.
Fixes crashes on Android 4.4

Change-Id: I274dc5d3ecf63ea328e577e69e217f572408db57
parent c9b0a0f3
......@@ -19,6 +19,7 @@
#include "audio/audiobuffer.h"
#include "logger.h"
#include "noncopyable.h"
#include <SLES/OpenSLES.h>
#include <sys/types.h>
......@@ -146,6 +147,7 @@ public:
}
private:
NON_COPYABLE(ProducerConsumerQueue);
std::vector<T> buffer_;
// forcing cache line alignment to eliminate false sharing of the
......@@ -162,9 +164,16 @@ struct sample_buf {
size_t size_ {0}; // audio sample size (n buf) in byte
sample_buf() {}
sample_buf(size_t alloc, size_t size) : buf_(new uint8_t[alloc]), cap_(size) {}
sample_buf(sample_buf&& o) : buf_(o.buf_), cap_(o.cap_), size_(o.size_) {
o.buf_ = nullptr;
o.cap_ = 0;
o.size_ = 0;
}
~sample_buf() {
if (buf_) delete[] buf_;
}
NON_COPYABLE(sample_buf);
};
using AudioQueue = ProducerConsumerQueue<sample_buf*>;
......
......@@ -48,7 +48,6 @@ namespace ring {
// Constructor
OpenSLLayer::OpenSLLayer(const AudioPreference &pref)
: AudioLayer(pref),
audioInputDescriptor_(),
mainRingBuffer_(Manager::instance().getRingBufferPool().getRingBuffer(RingBufferPool::DEFAULT_ID))
{}
......@@ -408,25 +407,23 @@ OpenSLLayer::getCaptureDeviceList() const
SLresult res;
// Get the Audio IO DEVICE CAPABILITIES interface, implicit
RING_DBG("Get the Audio IO DEVICE CAPABILITIES interface, implicit");
res = (*engineObject_)->GetInterface(engineObject_, SL_IID_AUDIOIODEVICECAPABILITIES, (void*)&AudioIODeviceCapabilitiesItf);
SLAudioIODeviceCapabilitiesItf deviceCapabilities {nullptr};
res = (*engineObject_)->GetInterface(engineObject_, SL_IID_AUDIOIODEVICECAPABILITIES, (void*)&deviceCapabilities);
if (res != SL_RESULT_SUCCESS)
return captureDeviceList;
RING_DBG("Get the Audio IO DEVICE CAPABILITIES interface, implicit");
numInputs = MAX_NUMBER_INPUT_DEVICES;
res = (*AudioIODeviceCapabilitiesItf)->GetAvailableAudioInputs(AudioIODeviceCapabilitiesItf, &numInputs, InputDeviceIDs);
res = (*deviceCapabilities)->GetAvailableAudioInputs(deviceCapabilities, &numInputs, InputDeviceIDs);
if (res != SL_RESULT_SUCCESS)
return captureDeviceList;
// Search for either earpiece microphone or headset microphone input
// device - with a preference for the latter
for (int i = 0; i < numInputs; i++) {
res = (*AudioIODeviceCapabilitiesItf)->QueryAudioInputCapabilities(AudioIODeviceCapabilitiesItf,
SLAudioInputDescriptor audioInputDescriptor_;
res = (*deviceCapabilities)->QueryAudioInputCapabilities(deviceCapabilities,
InputDeviceIDs[i],
(SLAudioInputDescriptor_ *)&audioInputDescriptor_);
&audioInputDescriptor_);
if (res != SL_RESULT_SUCCESS)
return captureDeviceList;
......
......@@ -188,9 +188,6 @@ class OpenSLLayer : public AudioLayer {
std::vector<sample_buf> bufs_;
SLAudioIODeviceCapabilitiesItf AudioIODeviceCapabilitiesItf {nullptr};
SLAudioInputDescriptor audioInputDescriptor_;
AudioFormat hardwareFormat_ {AudioFormat::MONO()};
size_t hardwareBuffSize_ {BUFFER_SIZE};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment