Skip to content

Commit fa5a2b3

Browse files
committed
removed logic from linux drivers
1 parent 04476b2 commit fa5a2b3

File tree

4 files changed

+46
-306
lines changed

4 files changed

+46
-306
lines changed

src/framework/audio/driver/platform/lin/alsaaudiodriver.cpp

Lines changed: 17 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void* alsaThread(void* aParam)
6868
uint8_t* stream = (uint8_t*)data->buffer;
6969
int len = data->samples * data->channels * sizeof(float);
7070

71-
data->callback(data->userdata, stream, len);
71+
data->callback(stream, len);
7272

7373
snd_pcm_sframes_t pcm = snd_pcm_writei(data->alsaDeviceHandle, data->buffer, data->samples);
7474
if (pcm != -EPIPE) {
@@ -107,7 +107,6 @@ static void alsaCleanup()
107107

108108
AlsaAudioDriver::AlsaAudioDriver()
109109
{
110-
m_deviceId = DEFAULT_DEVICE_ID;
111110
}
112111

113112
AlsaAudioDriver::~AlsaAudioDriver()
@@ -131,18 +130,26 @@ std::string AlsaAudioDriver::name() const
131130
return "ALSA";
132131
}
133132

133+
AudioDeviceID AlsaAudioDriver::defaultDevice() const
134+
{
135+
return DEFAULT_DEVICE_ID;
136+
}
137+
134138
bool AlsaAudioDriver::open(const Spec& spec, Spec* activeSpec)
135139
{
140+
IF_ASSERT_FAILED(!spec.deviceId.empty()) {
141+
return false;
142+
}
143+
136144
s_alsaData = new ALSAData();
137145
s_alsaData->samples = spec.output.samplesPerChannel;
138146
s_alsaData->channels = spec.output.audioChannelCount;
139147
s_alsaData->callback = spec.callback;
140-
s_alsaData->userdata = spec.userdata;
141148

142149
snd_pcm_t* handle;
143-
int rc = snd_pcm_open(&handle, outputDevice().c_str(), SND_PCM_STREAM_PLAYBACK, 0);
150+
int rc = snd_pcm_open(&handle, spec.deviceId.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
144151
if (rc < 0) {
145-
LOGE() << "Unable to open device: " << outputDevice() << ", err code: " << rc;
152+
LOGE() << "Unable to open device: " << spec.deviceId << ", err code: " << rc;
146153
return false;
147154
}
148155

@@ -183,7 +190,6 @@ bool AlsaAudioDriver::open(const Spec& spec, Spec* activeSpec)
183190
//_alsaData->sampleBuffer = new short[_alsaData->samples * _alsaData->channels];
184191

185192
s_format = spec;
186-
s_format.format = Format::AudioF32;
187193
s_format.output.sampleRate = aSamplerate;
188194
m_activeSpecChanged.send(s_format);
189195

@@ -199,7 +205,7 @@ bool AlsaAudioDriver::open(const Spec& spec, Spec* activeSpec)
199205
return false;
200206
}
201207

202-
LOGI() << "Connected to " << outputDevice()
208+
LOGI() << "Connected to " << spec.deviceId
203209
<< " with bufferSize " << s_format.output.samplesPerChannel
204210
<< ", sampleRate " << s_format.output.sampleRate
205211
<< ", channels: " << s_format.output.audioChannelCount;
@@ -227,43 +233,6 @@ async::Channel<IAudioDriver::Spec> AlsaAudioDriver::activeSpecChanged() const
227233
return m_activeSpecChanged;
228234
}
229235

230-
AudioDeviceID AlsaAudioDriver::outputDevice() const
231-
{
232-
return m_deviceId;
233-
}
234-
235-
bool AlsaAudioDriver::selectOutputDevice(const AudioDeviceID& deviceId)
236-
{
237-
if (m_deviceId == deviceId) {
238-
return true;
239-
}
240-
241-
bool reopen = isOpened();
242-
close();
243-
m_deviceId = deviceId;
244-
245-
bool ok = true;
246-
if (reopen) {
247-
ok = open(s_format, &s_format);
248-
}
249-
250-
if (ok) {
251-
m_outputDeviceChanged.notify();
252-
}
253-
254-
return ok;
255-
}
256-
257-
bool AlsaAudioDriver::resetToDefaultOutputDevice()
258-
{
259-
return selectOutputDevice(DEFAULT_DEVICE_ID);
260-
}
261-
262-
async::Notification AlsaAudioDriver::outputDeviceChanged() const
263-
{
264-
return m_outputDeviceChanged;
265-
}
266-
267236
AudioDeviceList AlsaAudioDriver::availableOutputDevices() const
268237
{
269238
AudioDeviceList devices;
@@ -277,38 +246,11 @@ async::Notification AlsaAudioDriver::availableOutputDevicesChanged() const
277246
return m_availableOutputDevicesChanged;
278247
}
279248

280-
bool AlsaAudioDriver::setOutputDeviceBufferSize(unsigned int bufferSize)
249+
std::vector<samples_t> AlsaAudioDriver::availableOutputDeviceBufferSizes() const
281250
{
282-
if (s_format.output.samplesPerChannel == bufferSize) {
283-
return true;
284-
}
285-
286-
bool reopen = isOpened();
287-
close();
288-
s_format.output.samplesPerChannel = bufferSize;
289-
290-
bool ok = true;
291-
if (reopen) {
292-
ok = open(s_format, &s_format);
293-
}
251+
std::vector<samples_t> result;
294252

295-
if (ok) {
296-
m_bufferSizeChanged.notify();
297-
}
298-
299-
return ok;
300-
}
301-
302-
async::Notification AlsaAudioDriver::outputDeviceBufferSizeChanged() const
303-
{
304-
return m_bufferSizeChanged;
305-
}
306-
307-
std::vector<unsigned int> AlsaAudioDriver::availableOutputDeviceBufferSizes() const
308-
{
309-
std::vector<unsigned int> result;
310-
311-
unsigned int n = MAXIMUM_BUFFER_SIZE;
253+
samples_t n = MAXIMUM_BUFFER_SIZE;
312254
while (n >= MINIMUM_BUFFER_SIZE) {
313255
result.push_back(n);
314256
n /= 2;
@@ -319,34 +261,7 @@ std::vector<unsigned int> AlsaAudioDriver::availableOutputDeviceBufferSizes() co
319261
return result;
320262
}
321263

322-
bool AlsaAudioDriver::setOutputDeviceSampleRate(unsigned int sampleRate)
323-
{
324-
if (s_format.output.sampleRate == sampleRate) {
325-
return true;
326-
}
327-
328-
bool reopen = isOpened();
329-
close();
330-
s_format.output.sampleRate = sampleRate;
331-
332-
bool ok = true;
333-
if (reopen) {
334-
ok = open(s_format, &s_format);
335-
}
336-
337-
if (ok) {
338-
m_sampleRateChanged.notify();
339-
}
340-
341-
return ok;
342-
}
343-
344-
async::Notification AlsaAudioDriver::outputDeviceSampleRateChanged() const
345-
{
346-
return m_sampleRateChanged;
347-
}
348-
349-
std::vector<unsigned int> AlsaAudioDriver::availableOutputDeviceSampleRates() const
264+
std::vector<sample_rate_t> AlsaAudioDriver::availableOutputDeviceSampleRates() const
350265
{
351266
// ALSA API is not of any help to get sample rates supported by the driver.
352267
// (snd_pcm_hw_params_get_rate_[min|max] will return 1 to 384000 Hz)
@@ -358,11 +273,3 @@ std::vector<unsigned int> AlsaAudioDriver::availableOutputDeviceSampleRates() co
358273
96000,
359274
};
360275
}
361-
362-
void AlsaAudioDriver::resume()
363-
{
364-
}
365-
366-
void AlsaAudioDriver::suspend()
367-
{
368-
}

src/framework/audio/driver/platform/lin/alsaaudiodriver.h

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,26 @@ class AlsaAudioDriver : public IAudioDriver, public async::Asyncable
3838
void init() override;
3939

4040
std::string name() const override;
41+
42+
AudioDeviceID defaultDevice() const override;
43+
4144
bool open(const Spec& spec, Spec* activeSpec) override;
4245
void close() override;
4346
bool isOpened() const override;
4447

4548
const Spec& activeSpec() const override;
4649
async::Channel<Spec> activeSpecChanged() const override;
4750

48-
AudioDeviceID outputDevice() const override;
49-
bool selectOutputDevice(const AudioDeviceID& deviceId) override;
50-
bool resetToDefaultOutputDevice() override;
51-
async::Notification outputDeviceChanged() const override;
52-
5351
AudioDeviceList availableOutputDevices() const override;
5452
async::Notification availableOutputDevicesChanged() const override;
55-
56-
bool setOutputDeviceBufferSize(unsigned int bufferSize) override;
57-
async::Notification outputDeviceBufferSizeChanged() const override;
58-
59-
std::vector<unsigned int> availableOutputDeviceBufferSizes() const override;
60-
61-
bool setOutputDeviceSampleRate(unsigned int sampleRate) override;
62-
async::Notification outputDeviceSampleRateChanged() const override;
63-
64-
std::vector<unsigned int> availableOutputDeviceSampleRates() const override;
65-
66-
void resume() override;
67-
void suspend() override;
53+
std::vector<samples_t> availableOutputDeviceBufferSizes() const override;
54+
std::vector<sample_rate_t> availableOutputDeviceSampleRates() const override;
6855

6956
private:
7057
async::Channel<Spec> m_activeSpecChanged;
7158

72-
async::Notification m_outputDeviceChanged;
73-
7459
mutable std::mutex m_devicesMutex;
7560
AudioDevicesListener m_devicesListener;
7661
async::Notification m_availableOutputDevicesChanged;
77-
78-
std::string m_deviceId;
79-
80-
async::Notification m_bufferSizeChanged;
81-
async::Notification m_sampleRateChanged;
8262
};
8363
}

0 commit comments

Comments
 (0)