From: Stefan BrĂ¼ns Date: Sat, 28 Nov 2015 15:52:08 +0000 (+0100) Subject: input/wav: initialize channel list before going into ready state X-Git-Tag: libsigrok-0.4.0~78 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=74c9a8d2bd361d59cd6eb6e20c26a37c6f4d12a1;p=libsigrok.git input/wav: initialize channel list before going into ready state The sr_input_dev_inst_get API documentation guarantees an input is fully initialized as soon as the device instance is returned. An sdi implementation should not set sdi_ready any earlier. This fixes parts of bug #387. --- diff --git a/src/input/wav.c b/src/input/wav.c index f16db3a3..f7574334 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -242,15 +242,9 @@ static int process_buffer(struct sr_input *in) struct sr_config *src; int offset, chunk_samples, total_samples, processed, max_chunk_samples; int num_samples, i; - char channelname[8]; inc = in->priv; if (!inc->started) { - for (i = 0; i < inc->num_channels; i++) { - snprintf(channelname, 8, "CH%d", i + 1); - sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname); - } - std_session_send_df_header(in->sdi, LOG_PREFIX); packet.type = SR_DF_META; @@ -310,6 +304,7 @@ static int receive(struct sr_input *in, GString *buf) { struct context *inc; int ret; + char channelname[8]; g_string_append_len(in->buf, buf->str, buf->len); @@ -329,6 +324,11 @@ static int receive(struct sr_input *in, GString *buf) else if (ret != SR_OK) return ret; + for (int i = 0; i < inc->num_channels; i++) { + snprintf(channelname, 8, "CH%d", i + 1); + sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname); + } + /* sdi is ready, notify frontend. */ in->sdi_ready = TRUE; return SR_OK;