summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-08-23 13:52:32 +0300
committerAlon Levy <alevy@redhat.com>2011-08-23 17:01:14 +0300
commit2bddc6e33ce7803a2f15920270b8e6821557f7bc (patch)
tree1bf6f3ca9ed4485f9831b0d7b2dc0ab50b47bac3 /server
parentb88f23363388ffec42ba3a9d16075d9f7a0357eb (diff)
downloadspice-2bddc6e33ce7803a2f15920270b8e6821557f7bc.tar.gz
spice-2bddc6e33ce7803a2f15920270b8e6821557f7bc.tar.xz
spice-2bddc6e33ce7803a2f15920270b8e6821557f7bc.zip
server/tests/test_playback: correctly use spice_server_playback_get_buffer
and spice_server_playback_put_samples. The former retrieves a buffer from a free list with spice_server_playback_get_buffer, and should be used once via spice_server_playback_put_samples. The tester previously reused the same buffer a number of times.
Diffstat (limited to 'server')
-rw-r--r--server/tests/test_playback.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/server/tests/test_playback.c b/server/tests/test_playback.c
index 6f332a97..cb1aa9b0 100644
--- a/server/tests/test_playback.c
+++ b/server/tests/test_playback.c
@@ -5,6 +5,7 @@
#include <math.h>
#include <spice.h>
+#include "reds.h"
#include "test_util.h"
#include "basic_event_loop.h"
@@ -33,6 +34,17 @@ SpiceTimer *playback_timer;
int playback_timer_ms;
SpiceCoreInterface *core;
+static void get_frame(void)
+{
+ if (frame) {
+ return;
+ }
+ spice_server_playback_get_buffer(&playback_instance, &frame, &num_samples);
+ playback_timer_ms = num_samples
+ ? 1000 * num_samples / SPICE_INTERFACE_PLAYBACK_FREQ
+ : 100;
+}
+
void playback_timer_cb(void *opaque)
{
static int t = 0;
@@ -41,18 +53,16 @@ void playback_timer_cb(void *opaque)
int i;
struct timeval cur;
uint64_t cur_usec;
- uint32_t batches;
+ uint32_t *test_frame;
+ uint32_t test_num_samples;
+ get_frame();
if (!frame) {
- spice_server_playback_get_buffer(&playback_instance, &frame, &num_samples);
- if (frame) {
- playback_timer_ms = num_samples ? 1000*num_samples/SPICE_INTERFACE_PLAYBACK_FREQ : 100;
- } else {
- /* continue waiting until there is a channel */
- core->timer_start(playback_timer, playback_timer_ms);
- return;
- }
+ /* continue waiting until there is a channel */
+ core->timer_start(playback_timer, 100);
+ return;
}
+
/* we have a channel */
gettimeofday(&cur, NULL);
cur_usec = cur.tv_usec + cur.tv_sec * 1e6;
@@ -62,17 +72,20 @@ void playback_timer_cb(void *opaque)
samples_to_send += (cur_usec - last_sent_usec) * SPICE_INTERFACE_PLAYBACK_FREQ / 1e6;
}
last_sent_usec = cur_usec;
- batches = samples_to_send / num_samples;
+ while (samples_to_send > num_samples && frame) {
#if 0
- printf("samples_to_send = %d, batches = %d\n", samples_to_send, batches);
+ printf("samples_to_send = %d\n", samples_to_send);
#endif
- samples_to_send -= num_samples * batches;
- for (;batches > 0 ; --batches) {
+ samples_to_send -= num_samples;
for (i = 0 ; i < num_samples; ++i) {
frame[i] = (((uint16_t)((1<<14)*sin((t+i)/10))) << 16) + (((uint16_t)((1<<14)*sin((t+i)/10))));
}
t += num_samples;
- spice_server_playback_put_samples(&playback_instance, frame);
+ if (frame) {
+ spice_server_playback_put_samples(&playback_instance, frame);
+ frame = NULL;
+ }
+ get_frame();
}
core->timer_start(playback_timer, playback_timer_ms);
}