+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);
+
+ 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;
+
+ 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;
+ }
+
+ ret = process_buffer(in);
+
+ return ret;
+}
+
+static int end(struct sr_input *in)
+{
+ struct context *inc;
+ int ret;