don't access device until open() is called

and then check for a probe error.
This commit is contained in:
Andrew Kelley 2015-07-21 02:12:28 -07:00
parent 787a7164e0
commit 43d33e5a67
2 changed files with 45 additions and 19 deletions

View file

@ -238,6 +238,7 @@ view `coverage/index.html` in a browser.
## Roadmap ## Roadmap
0. ALSA: support devices that don't support mmap access (test with pulseaudio alsa default)
0. implement ALSA (Linux) backend, get examples working 0. implement ALSA (Linux) backend, get examples working
0. ALSA: poll instead of callback 0. ALSA: poll instead of callback
0. pipe record to playback example working with dummy linux, osx, windows 0. pipe record to playback example working with dummy linux, osx, windows
@ -261,7 +262,6 @@ view `coverage/index.html` in a browser.
unused to a buffer for you. unused to a buffer for you.
0. add len arguments to APIs that have char * 0. add len arguments to APIs that have char *
0. custom allocator support 0. custom allocator support
0. ALSA: support devices that don't support mmap access
0. Test in an app that needs to synchronize video to test the 0. Test in an app that needs to synchronize video to test the
latency/synchronization API. latency/synchronization API.
0. Support PulseAudio proplist properties for main context and streams 0. Support PulseAudio proplist properties for main context and streams

View file

@ -382,14 +382,6 @@ struct SoundIoOutStream *soundio_outstream_create(struct SoundIoDevice *device)
outstream->device = device; outstream->device = device;
soundio_device_ref(device); soundio_device_ref(device);
const SoundIoChannelLayout *stereo = soundio_channel_layout_get_builtin(SoundIoChannelLayoutIdStereo);
outstream->format = soundio_device_supports_format(device, SoundIoFormatFloat32NE) ?
SoundIoFormatFloat32NE : device->formats[0];
outstream->layout = soundio_device_supports_layout(device, stereo) ? *stereo : device->layouts[0];
outstream->sample_rate = clamp(device->sample_rate_min, 48000, device->sample_rate_max);
outstream->name = "SoundIo";
return outstream; return outstream;
} }
@ -397,11 +389,31 @@ int soundio_outstream_open(struct SoundIoOutStream *outstream) {
if (outstream->format <= SoundIoFormatInvalid) if (outstream->format <= SoundIoFormatInvalid)
return SoundIoErrorInvalid; return SoundIoErrorInvalid;
SoundIoDevice *device = outstream->device;
if (device->probe_error)
return device->probe_error;
if (outstream->format == SoundIoFormatInvalid) {
outstream->format = soundio_device_supports_format(device, SoundIoFormatFloat32NE) ?
SoundIoFormatFloat32NE : device->formats[0];
}
if (!outstream->layout.channel_count) {
const SoundIoChannelLayout *stereo = soundio_channel_layout_get_builtin(SoundIoChannelLayoutIdStereo);
outstream->layout = soundio_device_supports_layout(device, stereo) ? *stereo : device->layouts[0];
}
if (!outstream->sample_rate)
outstream->sample_rate = clamp(device->sample_rate_min, 48000, device->sample_rate_max);
if (!outstream->name)
outstream->name = "SoundIo";
SoundIoOutStreamPrivate *os = (SoundIoOutStreamPrivate *)outstream; SoundIoOutStreamPrivate *os = (SoundIoOutStreamPrivate *)outstream;
outstream->bytes_per_frame = soundio_get_bytes_per_frame(outstream->format, outstream->layout.channel_count); outstream->bytes_per_frame = soundio_get_bytes_per_frame(outstream->format, outstream->layout.channel_count);
outstream->bytes_per_sample = soundio_get_bytes_per_sample(outstream->format); outstream->bytes_per_sample = soundio_get_bytes_per_sample(outstream->format);
SoundIo *soundio = outstream->device->soundio; SoundIo *soundio = device->soundio;
SoundIoPrivate *si = (SoundIoPrivate *)soundio; SoundIoPrivate *si = (SoundIoPrivate *)soundio;
return si->outstream_open(si, os); return si->outstream_open(si, os);
} }
@ -444,14 +456,6 @@ struct SoundIoInStream *soundio_instream_create(struct SoundIoDevice *device) {
instream->device = device; instream->device = device;
soundio_device_ref(device); soundio_device_ref(device);
const SoundIoChannelLayout *stereo = soundio_channel_layout_get_builtin(SoundIoChannelLayoutIdStereo);
instream->format = soundio_device_supports_format(device, SoundIoFormatFloat32NE) ?
SoundIoFormatFloat32NE : device->formats[0];
instream->layout = soundio_device_supports_layout(device, stereo) ? *stereo : device->layouts[0];
instream->sample_rate = clamp(device->sample_rate_min, 48000, device->sample_rate_max);
instream->name = "SoundIo";
return instream; return instream;
} }
@ -459,9 +463,31 @@ int soundio_instream_open(struct SoundIoInStream *instream) {
if (instream->format <= SoundIoFormatInvalid) if (instream->format <= SoundIoFormatInvalid)
return SoundIoErrorInvalid; return SoundIoErrorInvalid;
SoundIoDevice *device = instream->device;
if (device->probe_error)
return device->probe_error;
if (instream->format == SoundIoFormatInvalid) {
instream->format = soundio_device_supports_format(device, SoundIoFormatFloat32NE) ?
SoundIoFormatFloat32NE : device->formats[0];
}
if (!instream->layout.channel_count) {
const SoundIoChannelLayout *stereo = soundio_channel_layout_get_builtin(SoundIoChannelLayoutIdStereo);
instream->layout = soundio_device_supports_layout(device, stereo) ? *stereo : device->layouts[0];
}
if (!instream->sample_rate)
instream->sample_rate = clamp(device->sample_rate_min, 48000, device->sample_rate_max);
if (!instream->name)
instream->name = "SoundIo";
instream->bytes_per_frame = soundio_get_bytes_per_frame(instream->format, instream->layout.channel_count); instream->bytes_per_frame = soundio_get_bytes_per_frame(instream->format, instream->layout.channel_count);
instream->bytes_per_sample = soundio_get_bytes_per_sample(instream->format); instream->bytes_per_sample = soundio_get_bytes_per_sample(instream->format);
SoundIo *soundio = instream->device->soundio; SoundIo *soundio = device->soundio;
SoundIoPrivate *si = (SoundIoPrivate *)soundio; SoundIoPrivate *si = (SoundIoPrivate *)soundio;
SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate *)instream; SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate *)instream;
return si->instream_open(si, is); return si->instream_open(si, is);