+ ctx = g_malloc0(sizeof(struct context));
+ o->internal = ctx;
+ ctx->num_enabled_channels = num_enabled_channels;
+ ctx->channel_index = g_malloc(sizeof(int) * ctx->num_enabled_channels);
+
+ /* Once more to map the enabled channels. */
+ for (i = 0, l = o->sdi->channels; l; l = l->next) {
+ ch = l->data;
+ if (ch->type != SR_CHANNEL_LOGIC)
+ continue;
+ if (!ch->enabled)
+ continue;
+ ctx->channel_index[i++] = ch->index;
+ }
+
+ return SR_OK;
+}
+
+static GString *gen_header(struct sr_output *o)
+{
+ struct context *ctx;
+ struct sr_channel *ch;
+ GVariant *gvar;
+ GString *header;
+ GSList *l;
+ time_t t;
+ int num_channels, i;
+ char *samplerate_s, *frequency_s, *timestamp;
+
+ ctx = o->internal;
+ header = g_string_sized_new(512);