+ struct context *inc;
+ int ret;
+ char channelname[16];
+
+ g_string_append_len(in->buf, buf->str, buf->len);
+
+ if (in->buf->len < MIN_DATA_CHUNK_OFFSET) {
+ /*
+ * Don't even try until there's enough room
+ * for the data segment to start.
+ */
+ return SR_OK;
+ }
+
+ inc = in->priv;
+ if (!in->sdi_ready) {
+ if ((ret = parse_wav_header(in->buf, inc)) == SR_ERR_NA)
+ /* Not enough data yet. */
+ return SR_OK;
+ else if (ret != SR_OK)
+ return ret;
+
+ if (inc->create_channels) {
+ for (int i = 0; i < inc->num_channels; i++) {
+ snprintf(channelname, sizeof(channelname), "CH%d", i + 1);
+ sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname);
+ }
+ }
+
+ inc->create_channels = FALSE;
+
+ /* sdi is ready, notify frontend. */
+ in->sdi_ready = TRUE;
+ return SR_OK;
+ }
+
+ ret = process_buffer(in);
+
+ return ret;
+}
+
+static int end(struct sr_input *in)
+{
+ struct context *inc;
+ int ret;
+
+ if (in->sdi_ready)
+ ret = process_buffer(in);
+ else
+ ret = SR_OK;
+
+ inc = in->priv;
+ if (inc->started)
+ std_session_send_df_end(in->sdi);
+
+ return ret;
+}
+
+static int reset(struct sr_input *in)
+{
+ memset(in->priv, 0, sizeof(struct context));
+
+ /*
+ * We only want to create the sigrok channels once, so
+ * inc->create_channels won't be set to TRUE this time around.
+ */
+
+ g_string_truncate(in->buf, 0);