From: Bert Vermeulen Date: Sun, 31 Mar 2013 18:55:39 +0000 (+0200) Subject: alsa: Adjust to GVariant-based sr_config_* functions X-Git-Tag: dsupstream~194 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=aa0dbd683c58c9dd342140a4080d2aa0b95c5bb3;p=libsigrok.git alsa: Adjust to GVariant-based sr_config_* functions --- diff --git a/hardware/alsa/api.c b/hardware/alsa/api.c index e2efbf46..39ab74d1 100644 --- a/hardware/alsa/api.c +++ b/hardware/alsa/api.c @@ -27,11 +27,10 @@ #include "libsigrok-internal.h" #include "protocol.h" -static const int hwcaps[] = { +static const int32_t hwcaps[] = { SR_CONF_SAMPLERATE, SR_CONF_LIMIT_SAMPLES, SR_CONF_CONTINUOUS, - 0, }; SR_PRIV struct sr_dev_driver alsa_driver_info; @@ -124,14 +123,14 @@ static int hw_cleanup(void) return SR_OK; } -static int config_get(int id, const void **data, const struct sr_dev_inst *sdi) +static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) { struct dev_context *devc; switch (id) { case SR_CONF_SAMPLERATE: devc = sdi->priv; - *data = &devc->cur_samplerate; + *data = g_variant_new_uint64(devc->cur_samplerate); break; default: return SR_ERR_ARG; @@ -140,7 +139,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi) return SR_OK; } -static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -148,10 +147,10 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) switch (id) { case SR_CONF_SAMPLERATE: - alsa_set_samplerate(sdi, *(const uint64_t *)value); + alsa_set_samplerate(sdi, g_variant_get_uint64(data)); break; case SR_CONF_LIMIT_SAMPLES: - devc->limit_samples = *(const uint64_t *)value; + devc->limit_samples = g_variant_get_uint64(data); break; default: sr_err("Unknown capability: %d.", id); @@ -161,25 +160,35 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) return SR_OK; } -static int config_list(int key, const void **data, const struct sr_dev_inst *sdi) +static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) { struct dev_context *devc; + GVariant *gvar; + GVariantBuilder gvb; + int i; (void)sdi; switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = hwcaps; + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); break; case SR_CONF_SAMPLERATE: if (!sdi || !sdi->priv) return SR_ERR_ARG; devc = sdi->priv; - if (!devc->supp_rates.list) { + if (!devc->samplerates) { sr_err("Instance did not contain a samplerate list."); return SR_ERR_ARG; } - *data = &devc->supp_rates; + for (i = 0; devc->samplerates[i]; i++) + ; + g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); + gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), + devc->samplerates, i, sizeof(uint64_t)); + g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); + *data = g_variant_builder_end(&gvb); break; default: return SR_ERR_ARG; diff --git a/hardware/alsa/protocol.c b/hardware/alsa/protocol.c index 2d95f8cb..74326205 100644 --- a/hardware/alsa/protocol.c +++ b/hardware/alsa/protocol.c @@ -152,7 +152,7 @@ static void alsa_scan_handle_dev(GSList **devices, devc->num_probes = channels; devc->hw_params = hw_params; memcpy(devrates, hwrates, offset * sizeof(uint64_t)); - devc->supp_rates.list = devrates; + devc->samplerates = devrates; sdi->priv = devc; sdi->driver = di; @@ -294,7 +294,7 @@ SR_PRIV void alsa_dev_inst_clear(struct sr_dev_inst *sdi) return; snd_pcm_hw_params_free(devc->hw_params); - g_free((void*)devc->supp_rates.list); + g_free((void*)devc->samplerates); sr_dev_inst_free(sdi); } @@ -326,11 +326,11 @@ SR_PRIV int alsa_set_samplerate(const struct sr_dev_inst *sdi, i = 0; do { - if (newrate == devc->supp_rates.list[i]) { + if (newrate == devc->samplerates[i]) { rate = newrate; break; } - } while (devc->supp_rates.list[i++] != 0); + } while (devc->samplerates[i++] != 0); if (!rate) { sr_err("Sample rate %" PRIu64 " not supported.", newrate); diff --git a/hardware/alsa/protocol.h b/hardware/alsa/protocol.h index 92d2ba68..f7d047bb 100644 --- a/hardware/alsa/protocol.h +++ b/hardware/alsa/protocol.h @@ -43,7 +43,7 @@ struct dev_context { uint64_t limit_samples; uint64_t num_samples; uint8_t num_probes; - struct sr_samplerates supp_rates; + uint64_t *samplerates; char *hwdev; snd_pcm_t *capture_handle; snd_pcm_hw_params_t *hw_params;