Commit 767ca135 authored by Soeren Apel's avatar Soeren Apel Committed by Uwe Hermann

demo: Properly handle low samplerates

A "low samplerate" in this case means anything where
samples_todo is less than SAMPLES_PER_FRAME. This case
wasn't handled properly before, resulting in wrong
amounts of data being sent out.
parent e0b6855b
...@@ -400,6 +400,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) ...@@ -400,6 +400,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
devc = sdi->priv; devc = sdi->priv;
devc->sent_samples = 0; devc->sent_samples = 0;
devc->sent_frame_samples = 0;
/* /*
* Determine the numbers of logic and analog channels that are * Determine the numbers of logic and analog channels that are
......
...@@ -460,9 +460,6 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data) ...@@ -460,9 +460,6 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
samples_todo = (todo_us * devc->cur_samplerate + G_USEC_PER_SEC - 1) samples_todo = (todo_us * devc->cur_samplerate + G_USEC_PER_SEC - 1)
/ G_USEC_PER_SEC; / G_USEC_PER_SEC;
if (SAMPLES_PER_FRAME > 0)
samples_todo = SAMPLES_PER_FRAME;
if (devc->limit_samples > 0) { if (devc->limit_samples > 0) {
if (devc->limit_samples < devc->sent_samples) if (devc->limit_samples < devc->sent_samples)
samples_todo = 0; samples_todo = 0;
...@@ -470,6 +467,16 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data) ...@@ -470,6 +467,16 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
samples_todo = devc->limit_samples - devc->sent_samples; samples_todo = devc->limit_samples - devc->sent_samples;
} }
if (samples_todo == 0)
return G_SOURCE_CONTINUE;
#if (SAMPLES_PER_FRAME > 0) /* Avoid "comparison < 0 always false" warning. */
/* Never send more samples than a frame can fit... */
samples_todo = MIN(samples_todo, SAMPLES_PER_FRAME);
/* ...or than we need to finish the current frame. */
samples_todo = MIN(samples_todo, SAMPLES_PER_FRAME - devc->sent_frame_samples);
#endif
/* Calculate the actual time covered by this run back from the sample /* Calculate the actual time covered by this run back from the sample
* count, rounded towards zero. This avoids getting stuck on a too-low * count, rounded towards zero. This avoids getting stuck on a too-low
* time delta with no samples being sent due to round-off. * time delta with no samples being sent due to round-off.
...@@ -520,8 +527,16 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data) ...@@ -520,8 +527,16 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
devc->sent_samples += samples_todo; devc->sent_samples += samples_todo;
devc->sent_frame_samples += samples_todo;
devc->spent_us += todo_us; devc->spent_us += todo_us;
#if (SAMPLES_PER_FRAME > 0) /* Avoid "comparison >= 0 always true" warning. */
if (devc->sent_frame_samples >= SAMPLES_PER_FRAME) {
std_session_send_frame_end(sdi);
devc->sent_frame_samples = 0;
}
#endif
if ((devc->limit_samples > 0 && devc->sent_samples >= devc->limit_samples) if ((devc->limit_samples > 0 && devc->sent_samples >= devc->limit_samples)
|| (limit_us > 0 && devc->spent_us >= limit_us)) { || (limit_us > 0 && devc->spent_us >= limit_us)) {
...@@ -540,10 +555,10 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data) ...@@ -540,10 +555,10 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
sr_dbg("Requested number of samples reached."); sr_dbg("Requested number of samples reached.");
sr_dev_acquisition_stop(sdi); sr_dev_acquisition_stop(sdi);
} else { } else {
if (SAMPLES_PER_FRAME > 0) { #if (SAMPLES_PER_FRAME > 0)
std_session_send_frame_end(sdi); if (devc->sent_frame_samples == 0)
std_session_send_frame_begin(sdi); std_session_send_frame_begin(sdi);
} #endif
} }
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
......
...@@ -41,6 +41,7 @@ struct dev_context { ...@@ -41,6 +41,7 @@ struct dev_context {
uint64_t limit_samples; uint64_t limit_samples;
uint64_t limit_msec; uint64_t limit_msec;
uint64_t sent_samples; uint64_t sent_samples;
uint64_t sent_frame_samples; /* Number of samples that were sent for current frame. */
int64_t start_us; int64_t start_us;
int64_t spent_us; int64_t spent_us;
uint64_t step; uint64_t step;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment