aboutsummaryrefslogtreecommitdiff
path: root/replay
diff options
context:
space:
mode:
authorPavel Dovgalyuk <pavel.dovgaluk@ispras.ru>2017-02-02 08:50:54 +0300
committerGerd Hoffmann <kraxel@redhat.com>2017-03-01 15:11:44 +0100
commit3d4d16f4dc101e16f643acc44dfffdbaf2a8f01c (patch)
treed30418f9f9aef197aae8e79f4e29948edb1b98b3 /replay
parente7c83a885f865128ae3cf1946f8cb538b63cbfba (diff)
replay: add record/replay for audio passthrough
This patch adds recording and replaying audio data. Is saves synchronization information for audio out and inputs from the microphone. v2: removed unneeded whitespace change Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru> Message-id: 20170202055054.4848.94901.stgit@PASHA-ISP.lan02.inno [ kraxel: add qemu/error-report.h include to fix osx build failure ] Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'replay')
-rw-r--r--replay/Makefile.objs1
-rw-r--r--replay/replay-audio.c79
-rw-r--r--replay/replay-internal.h4
3 files changed, 84 insertions, 0 deletions
diff --git a/replay/Makefile.objs b/replay/Makefile.objs
index b2afd4030a..cee6539a23 100644
--- a/replay/Makefile.objs
+++ b/replay/Makefile.objs
@@ -6,3 +6,4 @@ common-obj-y += replay-input.o
common-obj-y += replay-char.o
common-obj-y += replay-snapshot.o
common-obj-y += replay-net.o
+common-obj-y += replay-audio.o \ No newline at end of file
diff --git a/replay/replay-audio.c b/replay/replay-audio.c
new file mode 100644
index 0000000000..3d837434d4
--- /dev/null
+++ b/replay/replay-audio.c
@@ -0,0 +1,79 @@
+/*
+ * replay-audio.c
+ *
+ * Copyright (c) 2010-2017 Institute for System Programming
+ * of the Russian Academy of Sciences.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "sysemu/replay.h"
+#include "replay-internal.h"
+#include "sysemu/sysemu.h"
+#include "audio/audio.h"
+
+void replay_audio_out(int *played)
+{
+ if (replay_mode == REPLAY_MODE_RECORD) {
+ replay_save_instructions();
+ replay_mutex_lock();
+ replay_put_event(EVENT_AUDIO_OUT);
+ replay_put_dword(*played);
+ replay_mutex_unlock();
+ } else if (replay_mode == REPLAY_MODE_PLAY) {
+ replay_account_executed_instructions();
+ replay_mutex_lock();
+ if (replay_next_event_is(EVENT_AUDIO_OUT)) {
+ *played = replay_get_dword();
+ replay_finish_event();
+ replay_mutex_unlock();
+ } else {
+ replay_mutex_unlock();
+ error_report("Missing audio out event in the replay log");
+ abort();
+ }
+ }
+}
+
+void replay_audio_in(int *recorded, void *samples, int *wpos, int size)
+{
+ int pos;
+ uint64_t left, right;
+ if (replay_mode == REPLAY_MODE_RECORD) {
+ replay_save_instructions();
+ replay_mutex_lock();
+ replay_put_event(EVENT_AUDIO_IN);
+ replay_put_dword(*recorded);
+ replay_put_dword(*wpos);
+ for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
+ ; pos = (pos + 1) % size) {
+ audio_sample_to_uint64(samples, pos, &left, &right);
+ replay_put_qword(left);
+ replay_put_qword(right);
+ }
+ replay_mutex_unlock();
+ } else if (replay_mode == REPLAY_MODE_PLAY) {
+ replay_account_executed_instructions();
+ replay_mutex_lock();
+ if (replay_next_event_is(EVENT_AUDIO_IN)) {
+ *recorded = replay_get_dword();
+ *wpos = replay_get_dword();
+ for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
+ ; pos = (pos + 1) % size) {
+ left = replay_get_qword();
+ right = replay_get_qword();
+ audio_sample_from_uint64(samples, pos, left, right);
+ }
+ replay_finish_event();
+ replay_mutex_unlock();
+ } else {
+ replay_mutex_unlock();
+ error_report("Missing audio in event in the replay log");
+ abort();
+ }
+ }
+}
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
index c26d0795f2..ed66ed803c 100644
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -29,6 +29,10 @@ enum ReplayEvents {
/* for character device read all event */
EVENT_CHAR_READ_ALL,
EVENT_CHAR_READ_ALL_ERROR,
+ /* for audio out event */
+ EVENT_AUDIO_OUT,
+ /* for audio in event */
+ EVENT_AUDIO_IN,
/* for clock read/writes */
/* some of greater codes are reserved for clocks */
EVENT_CLOCK,