]> sigrok.org Git - libsigrok.git/commitdiff
input/wav: initialize channel list before going into ready state
authorStefan Brüns <redacted>
Sat, 28 Nov 2015 15:52:08 +0000 (16:52 +0100)
committerUwe Hermann <redacted>
Mon, 21 Dec 2015 14:37:32 +0000 (15:37 +0100)
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.

src/input/wav.c

index f16db3a396304cb63a22a11540e7753766af9670..f7574334da78e045c287a16f18e1f036da74a904 100644 (file)
@@ -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;