From: Gerhard Sittig Date: Thu, 11 Jun 2020 15:19:01 +0000 (+0200) Subject: input: use common support to send samplerate meta packet X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f8a8d4bb70328c77021263fde8c8ca672123be42;p=libsigrok.git input: use common support to send samplerate meta packet --- diff --git a/src/input/binary.c b/src/input/binary.c index 51a64d09..631d6d38 100644 --- a/src/input/binary.c +++ b/src/input/binary.c @@ -69,9 +69,7 @@ static int init(struct sr_input *in, GHashTable *options) static int process_buffer(struct sr_input *in) { struct sr_datafeed_packet packet; - struct sr_datafeed_meta meta; struct sr_datafeed_logic logic; - struct sr_config *src; struct context *inc; gsize chunk_size, i; int chunk; @@ -81,13 +79,8 @@ static int process_buffer(struct sr_input *in) std_session_send_df_header(in->sdi); if (inc->samplerate) { - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->samplerate)); - meta.config = g_slist_append(NULL, src); - sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); + (void)sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, + g_variant_new_uint64(inc->samplerate)); } inc->started = TRUE; diff --git a/src/input/chronovu_la8.c b/src/input/chronovu_la8.c index e7b7f082..91d05b90 100644 --- a/src/input/chronovu_la8.c +++ b/src/input/chronovu_la8.c @@ -130,9 +130,7 @@ static int init(struct sr_input *in, GHashTable *options) static int process_buffer(struct sr_input *in) { struct sr_datafeed_packet packet; - struct sr_datafeed_meta meta; struct sr_datafeed_logic logic; - struct sr_config *src; struct context *inc; gsize chunk_size, i; gsize chunk; @@ -145,13 +143,8 @@ static int process_buffer(struct sr_input *in) std_session_send_df_header(in->sdi); if (inc->samplerate) { - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->samplerate)); - meta.config = g_slist_append(NULL, src); - sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); + (void)sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, + g_variant_new_uint64(inc->samplerate)); } inc->samples_remain = CHRONOVU_LA8_DATASIZE; diff --git a/src/input/csv.c b/src/input/csv.c index 3a42fc9b..ca451bc4 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -277,21 +277,13 @@ struct context { static int flush_samplerate(const struct sr_input *in) { struct context *inc; - struct sr_datafeed_packet packet; - struct sr_datafeed_meta meta; - struct sr_config *src; inc = in->priv; if (!inc->calc_samplerate && inc->samplerate) inc->calc_samplerate = inc->samplerate; if (inc->calc_samplerate && !inc->samplerate_sent) { - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->calc_samplerate)); - meta.config = g_slist_append(NULL, src); - sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); + (void)sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, + g_variant_new_uint64(inc->calc_samplerate)); inc->samplerate_sent = TRUE; } diff --git a/src/input/logicport.c b/src/input/logicport.c index e594b2ce..354330ab 100644 --- a/src/input/logicport.c +++ b/src/input/logicport.c @@ -842,8 +842,6 @@ static int send_buffer(struct sr_input *in) { struct context *inc; struct sr_datafeed_packet packet; - struct sr_datafeed_meta meta; - struct sr_config *src; struct sr_datafeed_logic logic; int rc; @@ -859,14 +857,8 @@ static int send_buffer(struct sr_input *in) } if (inc->sample_rate && !inc->rate_sent) { - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, + rc = sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->sample_rate)); - meta.config = g_slist_append(NULL, src); - rc = sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); if (rc) return rc; inc->rate_sent = TRUE; diff --git a/src/input/raw_analog.c b/src/input/raw_analog.c index 87bcaf1c..1974dc92 100644 --- a/src/input/raw_analog.c +++ b/src/input/raw_analog.c @@ -155,9 +155,6 @@ static int init(struct sr_input *in, GHashTable *options) static int process_buffer(struct sr_input *in) { struct context *inc; - struct sr_datafeed_meta meta; - struct sr_datafeed_packet packet; - struct sr_config *src; unsigned int offset, chunk_size; inc = in->priv; @@ -165,13 +162,8 @@ static int process_buffer(struct sr_input *in) std_session_send_df_header(in->sdi); if (inc->samplerate) { - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->samplerate)); - meta.config = g_slist_append(NULL, src); - sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); + (void)sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, + g_variant_new_uint64(inc->samplerate)); } inc->started = TRUE; diff --git a/src/input/trace32_ad.c b/src/input/trace32_ad.c index 46a15ca6..3a4e1cd4 100644 --- a/src/input/trace32_ad.c +++ b/src/input/trace32_ad.c @@ -407,21 +407,11 @@ static void create_channels(struct sr_input *in) static void send_metadata(struct sr_input *in) { - struct sr_datafeed_packet packet; - struct sr_datafeed_meta meta; - struct sr_config *src; struct context *inc; inc = in->priv; - - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->samplerate)); - meta.config = g_slist_append(NULL, src); - sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); - + (void)sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, + g_variant_new_uint64(inc->samplerate)); inc->meta_sent = TRUE; } diff --git a/src/input/wav.c b/src/input/wav.c index b6d55888..a6369f4d 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -253,24 +253,14 @@ static void send_chunk(const struct sr_input *in, int offset, int num_samples) static int process_buffer(struct sr_input *in) { struct context *inc; - struct sr_datafeed_packet packet; - struct sr_datafeed_meta meta; - struct sr_config *src; int offset, chunk_samples, total_samples, processed, max_chunk_samples; int num_samples, i; inc = in->priv; if (!inc->started) { std_session_send_df_header(in->sdi); - - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->samplerate)); - meta.config = g_slist_append(NULL, src); - sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); - + (void)sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, + g_variant_new_uint64(inc->samplerate)); inc->started = TRUE; }