]> sigrok.org Git - libsigrok.git/blobdiff - src/input/vcd.c
input/vcd: Minor code cleanup.
[libsigrok.git] / src / input / vcd.c
index 8111c59cf757237149be9026100a4d6a0fa3c1c1..cfcecf30b21614ff62e457b88344f974aa5dd318 100644 (file)
@@ -70,6 +70,7 @@
 #define CHUNKSIZE 1024
 
 struct context {
+       gboolean started;
        gboolean got_header;
        uint64_t samplerate;
        unsigned int maxchannels;
@@ -429,7 +430,6 @@ static int init(struct sr_input *in, GHashTable *options)
        inc->skip = g_variant_get_int32(g_hash_table_lookup(options, "skip"));
        inc->skip /= inc->downsample;
 
-       /* Create a virtual device. */
        in->sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, NULL, NULL, NULL);
        in->priv = inc;
 
@@ -467,13 +467,6 @@ static int receive(const struct sr_input *in, GString *buf)
        uint64_t samplerate;
        char *p;
 
-       if (buf->len == 0) {
-               /* End of stream. */
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-               return SR_OK;
-       }
-
        g_string_append_len(in->buf, buf->str, buf->len);
 
        inc = in->priv;
@@ -485,6 +478,7 @@ static int receive(const struct sr_input *in, GString *buf)
                        return SR_ERR;
 
                std_session_send_df_header(in->sdi, LOG_PREFIX);
+               inc->started = TRUE;
 
                packet.type = SR_DF_META;
                packet.payload = &meta;
@@ -508,9 +502,16 @@ static int receive(const struct sr_input *in, GString *buf)
 
 static int cleanup(struct sr_input *in)
 {
+       struct sr_datafeed_packet packet;
        struct context *inc;
 
        inc = in->priv;
+       if (inc->started) {
+               /* End of stream. */
+               packet.type = SR_DF_END;
+               sr_session_send(in->sdi, &packet);
+       }
+
        g_slist_free_full(inc->channels, free_channel);
        g_free(inc);
        in->priv = NULL;
@@ -519,7 +520,7 @@ static int cleanup(struct sr_input *in)
 }
 
 static struct sr_option options[] = {
-       { "numchannels", "Max channels", "Maximum number of channels", NULL, NULL },
+       { "numchannels", "Number of channels", "Number of channels", NULL, NULL },
        { "skip", "Skip", "Skip until timestamp", NULL, NULL },
        { "downsample", "Downsample", "Divide samplerate by factor", NULL, NULL },
        { "compress", "Compress", "Compress idle periods longer than this value", NULL, NULL },