From: Soeren Apel Date: Sun, 27 Mar 2016 20:55:19 +0000 (+0200) Subject: Enable loading of session files without the unit size defined X-Git-Tag: libsigrok-0.5.0~539 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9cfc695ffe5f04622f61acb98ea4ac91c3f4ffc3;p=libsigrok.git Enable loading of session files without the unit size defined --- diff --git a/src/session_driver.c b/src/session_driver.c index 0793104b..cfa1da9d 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -127,8 +127,13 @@ static gboolean stream_session_data(struct sr_dev_inst *sdi) buf = g_malloc(CHUNKSIZE); - ret = zip_fread(vdev->capfile, buf, - CHUNKSIZE / vdev->unitsize * vdev->unitsize); + /* unitsize is not defined for purely analog session files. */ + if (vdev->unitsize) + ret = zip_fread(vdev->capfile, buf, + CHUNKSIZE / vdev->unitsize * vdev->unitsize); + else + ret = zip_fread(vdev->capfile, buf, CHUNKSIZE); + if (ret > 0) { got_data = TRUE; if (vdev->cur_analog_channel != 0) { diff --git a/src/session_file.c b/src/session_file.c index fd0dbd07..9b371206 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -212,6 +212,7 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, int unitsize; char **sections, **keys, *val; char channelname[SR_MAX_CHANNELNAME_LEN + 1]; + gboolean file_has_logic; if ((ret = sr_sessionfile_check(filename)) != SR_OK) return ret; @@ -235,6 +236,7 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, error = NULL; ret = SR_OK; + file_has_logic = FALSE; sections = g_key_file_get_groups(kf, NULL); for (i = 0; sections[i] && ret == SR_OK; i++) { if (!strcmp(sections[i], "global")) @@ -261,6 +263,7 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, sr_config_set(sdi, NULL, SR_CONF_CAPTUREFILE, g_variant_new_string(val)); g_free(val); + file_has_logic = TRUE; } g_clear_error(&error); @@ -277,7 +280,7 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, g_free(val); sr_config_set(sdi, NULL, SR_CONF_SAMPLERATE, g_variant_new_uint64(tmp_u64)); - } else if (!strcmp(keys[j], "unitsize")) { + } else if (!strcmp(keys[j], "unitsize") && file_has_logic) { unitsize = g_key_file_get_integer(kf, sections[i], keys[j], &error); if (!sdi || unitsize <= 0 || error) {