rename device name and description to id and name

This commit is contained in:
Andrew Kelley 2015-07-30 10:26:36 -07:00
parent 12db5fd970
commit 4ba1fd91a1
10 changed files with 52 additions and 53 deletions

View file

@ -275,7 +275,6 @@ view `coverage/index.html` in a browser.
0. Allow calling functions from outside the callbacks as long as they first
call lock and then unlock when done.
0. Should pause/resume be callable from outside the callbacks?
0. device.name -> device.id, device.description -> device.name
0. clean up API and improve documentation
- make sure every function which can return an error documents which errors
it can return

View file

@ -32,8 +32,8 @@ static void print_channel_layout(const struct SoundIoChannelLayout *layout) {
static void print_device(struct SoundIoDevice *device, bool is_default) {
const char *default_str = is_default ? " (default)" : "";
const char *raw_str = device->is_raw ? " (raw)" : "";
fprintf(stderr, "%s%s%s\n", device->description, default_str, raw_str);
fprintf(stderr, " name: %s\n", device->name);
fprintf(stderr, "%s%s%s\n", device->name, default_str, raw_str);
fprintf(stderr, " id: %s\n", device->id);
if (device->probe_error) {
fprintf(stderr, " probe error: %s\n", soundio_strerror(device->probe_error));

View file

@ -149,15 +149,15 @@ static void underflow_callback(struct SoundIoOutStream *outstream) {
}
static int usage(char *exe) {
fprintf(stderr, "Usage: %s [--dummy] [--alsa] [--pulseaudio] [--jack] [--in-device name] [--out-device name]\n", exe);
fprintf(stderr, "Usage: %s [--dummy] [--alsa] [--pulseaudio] [--jack] [--in-device id] [--out-device id]\n", exe);
return 1;
}
int main(int argc, char **argv) {
char *exe = argv[0];
enum SoundIoBackend backend = SoundIoBackendNone;
char *in_device_name = NULL;
char *out_device_name = NULL;
char *in_device_id = NULL;
char *out_device_id = NULL;
for (int i = 1; i < argc; i += 1) {
char *arg = argv[i];
if (strcmp("--dummy", arg) == 0) {
@ -172,13 +172,13 @@ int main(int argc, char **argv) {
if (++i >= argc) {
return usage(exe);
} else {
in_device_name = argv[i];
in_device_id = argv[i];
}
} else if (strcmp("--out-device", arg) == 0) {
if (++i >= argc) {
return usage(exe);
} else {
out_device_name = argv[i];
out_device_id = argv[i];
}
} else {
return usage(exe);
@ -203,11 +203,11 @@ int main(int argc, char **argv) {
panic("no output device found");
int in_device_index = default_in_device_index;
if (in_device_name) {
if (in_device_id) {
bool found = false;
for (int i = 0; i < soundio_input_device_count(soundio); i += 1) {
struct SoundIoDevice *device = soundio_get_input_device(soundio, i);
if (strcmp(device->name, in_device_name) == 0) {
if (strcmp(device->id, in_device_id) == 0) {
in_device_index = i;
found = true;
soundio_device_unref(device);
@ -216,15 +216,15 @@ int main(int argc, char **argv) {
soundio_device_unref(device);
}
if (!found)
panic("invalid input device name: %s", in_device_name);
panic("invalid input device id: %s", in_device_id);
}
int out_device_index = default_out_device_index;
if (out_device_name) {
if (out_device_id) {
bool found = false;
for (int i = 0; i < soundio_output_device_count(soundio); i += 1) {
struct SoundIoDevice *device = soundio_get_output_device(soundio, i);
if (strcmp(device->name, out_device_name) == 0) {
if (strcmp(device->id, out_device_id) == 0) {
out_device_index = i;
found = true;
soundio_device_unref(device);
@ -233,7 +233,7 @@ int main(int argc, char **argv) {
soundio_device_unref(device);
}
if (!found)
panic("invalid output device name: %s", out_device_name);
panic("invalid output device id: %s", out_device_id);
}
struct SoundIoDevice *out_device = soundio_get_output_device(soundio, out_device_index);
@ -244,8 +244,8 @@ int main(int argc, char **argv) {
if (!in_device)
panic("could not get input device: out of memory");
fprintf(stderr, "Input device: %s\n", in_device->description);
fprintf(stderr, "Output device: %s\n", out_device->description);
fprintf(stderr, "Input device: %s\n", in_device->name);
fprintf(stderr, "Output device: %s\n", out_device->name);
soundio_device_sort_channel_layouts(out_device);
const struct SoundIoChannelLayout *layout = soundio_best_matching_channel_layout(

View file

@ -113,7 +113,7 @@ int main(int argc, char **argv) {
if (!device)
panic("out of memory");
fprintf(stderr, "Output device: %s\n", device->description);
fprintf(stderr, "Output device: %s\n", device->name);
struct SoundIoOutStream *outstream = soundio_outstream_create(device);
outstream->format = SoundIoFormatFloat32NE;

View file

@ -384,7 +384,7 @@ static int probe_device(SoundIoDevice *device, snd_pcm_chmap_query_t **maps) {
snd_pcm_stream_t stream = purpose_to_stream(device->purpose);
if ((err = snd_pcm_open(&handle, device->name, stream, 0)) < 0) {
if ((err = snd_pcm_open(&handle, device->id, stream, 0)) < 0) {
handle_channel_maps(device, maps);
return SoundIoErrorOpeningDevice;
}
@ -542,11 +542,11 @@ static int refresh_devices(SoundIoPrivate *si) {
device->ref_count = 1;
device->soundio = soundio;
device->is_raw = false;
device->name = strdup(name);
device->description = descr1 ?
device->id = strdup(name);
device->name = descr1 ?
soundio_alloc_sprintf(nullptr, "%s: %s", descr, descr1) : strdup(descr);
if (!device->name || !device->description) {
if (!device->id || !device->name) {
soundio_device_unref(device);
free(name);
free(descr);
@ -658,11 +658,11 @@ static int refresh_devices(SoundIoPrivate *si) {
SoundIoDevice *device = &dev->pub;
device->ref_count = 1;
device->soundio = soundio;
device->name = soundio_alloc_sprintf(nullptr, "hw:%d,%d", card_index, device_index);
device->description = soundio_alloc_sprintf(nullptr, "%s %s", card_name, device_name);
device->id = soundio_alloc_sprintf(nullptr, "hw:%d,%d", card_index, device_index);
device->name = soundio_alloc_sprintf(nullptr, "%s %s", card_name, device_name);
device->is_raw = true;
if (!device->name || !device->description) {
if (!device->id || !device->name) {
soundio_device_unref(device);
snd_ctl_close(handle);
destroy(devices_info);
@ -1124,7 +1124,7 @@ static int outstream_open_alsa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os)
snd_pcm_stream_t stream = purpose_to_stream(outstream->device->purpose);
if ((err = snd_pcm_open(&osa->handle, outstream->device->name, stream, 0)) < 0) {
if ((err = snd_pcm_open(&osa->handle, outstream->device->id, stream, 0)) < 0) {
outstream_destroy_alsa(si, os);
return SoundIoErrorOpeningDevice;
}
@ -1411,7 +1411,7 @@ static int instream_open_alsa(SoundIoPrivate *si, SoundIoInStreamPrivate *is) {
snd_pcm_stream_t stream = purpose_to_stream(instream->device->purpose);
if ((err = snd_pcm_open(&isa->handle, instream->device->name, stream, 0)) < 0) {
if ((err = snd_pcm_open(&isa->handle, instream->device->id, stream, 0)) < 0) {
instream_destroy_alsa(si, is);
return SoundIoErrorOpeningDevice;
}

View file

@ -419,9 +419,9 @@ int soundio_dummy_init(SoundIoPrivate *si) {
device->ref_count = 1;
device->soundio = soundio;
device->name = strdup("dummy-out");
device->description = strdup("Dummy Output Device");
if (!device->name || !device->description) {
device->id = strdup("dummy-out");
device->name = strdup("Dummy Output Device");
if (!device->id || !device->name) {
soundio_device_unref(device);
destroy_dummy(si);
return SoundIoErrorNoMem;
@ -468,9 +468,9 @@ int soundio_dummy_init(SoundIoPrivate *si) {
device->ref_count = 1;
device->soundio = soundio;
device->name = strdup("dummy-in");
device->description = strdup("Dummy Input Device");
if (!device->name || !device->description) {
device->id = strdup("dummy-in");
device->name = strdup("Dummy Input Device");
if (!device->id || !device->name) {
soundio_device_unref(device);
destroy_dummy(si);
return SoundIoErrorNoMem;

View file

@ -194,8 +194,8 @@ static int refresh_devices_bare(SoundIoPrivate *si) {
device->soundio = soundio;
device->is_raw = false;
device->purpose = client->purpose;
device->name = dupe_str(client->name, client->name_len);
device->description = allocate<char>(description_len);
device->id = dupe_str(client->name, client->name_len);
device->name = allocate<char>(description_len);
device->layout_count = 1;
device->layouts = create<SoundIoChannelLayout>();
device->format_count = 1;
@ -213,7 +213,7 @@ static int refresh_devices_bare(SoundIoPrivate *si) {
dj->port_count = client->port_count;
dj->ports = allocate<SoundIoDeviceJackPort>(dj->port_count);
if (!device->name || !device->description || !device->layouts || !device->formats || !dj->ports) {
if (!device->id || !device->name || !device->layouts || !device->formats || !dj->ports) {
jack_free(port_names);
soundio_device_unref(device);
destroy(devices_info);
@ -235,15 +235,15 @@ static int refresh_devices_bare(SoundIoPrivate *si) {
}
}
memcpy(device->description, client->name, client->name_len);
memcpy(&device->description[client->name_len], ": ", 2);
memcpy(device->name, client->name, client->name_len);
memcpy(&device->name[client->name_len], ": ", 2);
int index = client->name_len + 2;
for (int port_index = 0; port_index < client->port_count; port_index += 1) {
SoundIoJackPort *port = &client->ports[port_index];
memcpy(&device->description[index], port->name, port->name_len);
memcpy(&device->name[index], port->name, port->name_len);
index += port->name_len;
if (port_index + 1 < client->port_count) {
memcpy(&device->description[index], ", ", 2);
memcpy(&device->name[index], ", ", 2);
index += 2;
}
}

View file

@ -221,7 +221,7 @@ static void finish_device_query(SoundIoPrivate *si) {
for (int i = 0; i < sipa->current_devices_info->input_devices.length; i += 1) {
SoundIoDevice *device = sipa->current_devices_info->input_devices.at(i);
assert(device->purpose == SoundIoDevicePurposeInput);
if (strcmp(device->name, sipa->default_source_name) == 0) {
if (strcmp(device->id, sipa->default_source_name) == 0) {
sipa->current_devices_info->default_input_index = i;
}
}
@ -232,7 +232,7 @@ static void finish_device_query(SoundIoPrivate *si) {
for (int i = 0; i < sipa->current_devices_info->output_devices.length; i += 1) {
SoundIoDevice *device = sipa->current_devices_info->output_devices.at(i);
assert(device->purpose == SoundIoDevicePurposeOutput);
if (strcmp(device->name, sipa->default_sink_name) == 0) {
if (strcmp(device->id, sipa->default_sink_name) == 0) {
sipa->current_devices_info->default_output_index = i;
}
}
@ -265,9 +265,9 @@ static void sink_info_callback(pa_context *pulse_context, const pa_sink_info *in
device->ref_count = 1;
device->soundio = soundio;
device->name = strdup(info->name);
device->description = strdup(info->description);
if (!device->name || !device->description) {
device->id = strdup(info->name);
device->name = strdup(info->description);
if (!device->id || !device->name) {
soundio_device_unref(device);
sipa->device_query_err = SoundIoErrorNoMem;
pa_threaded_mainloop_signal(sipa->main_loop, 0);
@ -335,9 +335,9 @@ static void source_info_callback(pa_context *pulse_context, const pa_source_info
device->ref_count = 1;
device->soundio = soundio;
device->name = strdup(info->name);
device->description = strdup(info->description);
if (!device->name || !device->description) {
device->id = strdup(info->name);
device->name = strdup(info->description);
if (!device->id || !device->name) {
soundio_device_unref(device);
sipa->device_query_err = SoundIoErrorNoMem;
pa_threaded_mainloop_signal(sipa->main_loop, 0);
@ -713,7 +713,7 @@ static int outstream_start_pa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os) {
pa_stream_flags_t flags = (outstream->buffer_duration > 0.0) ? PA_STREAM_ADJUST_LATENCY : PA_STREAM_NOFLAGS;
int err = pa_stream_connect_playback(ospa->stream,
outstream->device->name, &ospa->buffer_attr,
outstream->device->id, &ospa->buffer_attr,
flags, nullptr, nullptr);
if (err) {
pa_threaded_mainloop_unlock(sipa->main_loop);
@ -917,7 +917,7 @@ static int instream_start_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is) {
pa_stream_flags_t flags = (instream->period_duration > 0.0) ? PA_STREAM_ADJUST_LATENCY : PA_STREAM_NOFLAGS;
int err = pa_stream_connect_record(ispa->stream,
instream->device->name,
instream->device->id,
&ispa->buffer_attr, flags);
if (err) {
pa_threaded_mainloop_unlock(sipa->main_loop);

View file

@ -312,8 +312,8 @@ void soundio_device_unref(struct SoundIoDevice *device) {
if (dev->destruct)
dev->destruct(dev);
free(device->id);
free(device->name);
free(device->description);
deallocate(device->formats, device->format_count);
deallocate(device->layouts, device->layout_count);

View file

@ -244,10 +244,10 @@ struct SoundIoDevice {
// Read-only. Set automatically.
struct SoundIo *soundio;
// `name` uniquely identifies this device. `description` is user-friendly
// text to describe the device. These fields are UTF-8 encoded.
// `id` is a string of bytes that uniquely identifies this device.
// `name` is user-friendly UTF-8 encoded text to describe the device.
char *id;
char *name;
char *description;
// Channel layouts are handled similarly to sample format; see those docs.
// If this information is missing due to a `probe_error`, `layouts`