migration: Move postcopy stuff to postcopy-ram.c
[qemu/ar7.git] / replay / replay-audio.c
blob3d837434d4952701e608e4b5c9feccea23f82ee3
1 /*
2 * replay-audio.c
4 * Copyright (c) 2010-2017 Institute for System Programming
5 * of the Russian Academy of Sciences.
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "qemu/error-report.h"
14 #include "sysemu/replay.h"
15 #include "replay-internal.h"
16 #include "sysemu/sysemu.h"
17 #include "audio/audio.h"
19 void replay_audio_out(int *played)
21 if (replay_mode == REPLAY_MODE_RECORD) {
22 replay_save_instructions();
23 replay_mutex_lock();
24 replay_put_event(EVENT_AUDIO_OUT);
25 replay_put_dword(*played);
26 replay_mutex_unlock();
27 } else if (replay_mode == REPLAY_MODE_PLAY) {
28 replay_account_executed_instructions();
29 replay_mutex_lock();
30 if (replay_next_event_is(EVENT_AUDIO_OUT)) {
31 *played = replay_get_dword();
32 replay_finish_event();
33 replay_mutex_unlock();
34 } else {
35 replay_mutex_unlock();
36 error_report("Missing audio out event in the replay log");
37 abort();
42 void replay_audio_in(int *recorded, void *samples, int *wpos, int size)
44 int pos;
45 uint64_t left, right;
46 if (replay_mode == REPLAY_MODE_RECORD) {
47 replay_save_instructions();
48 replay_mutex_lock();
49 replay_put_event(EVENT_AUDIO_IN);
50 replay_put_dword(*recorded);
51 replay_put_dword(*wpos);
52 for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
53 ; pos = (pos + 1) % size) {
54 audio_sample_to_uint64(samples, pos, &left, &right);
55 replay_put_qword(left);
56 replay_put_qword(right);
58 replay_mutex_unlock();
59 } else if (replay_mode == REPLAY_MODE_PLAY) {
60 replay_account_executed_instructions();
61 replay_mutex_lock();
62 if (replay_next_event_is(EVENT_AUDIO_IN)) {
63 *recorded = replay_get_dword();
64 *wpos = replay_get_dword();
65 for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
66 ; pos = (pos + 1) % size) {
67 left = replay_get_qword();
68 right = replay_get_qword();
69 audio_sample_from_uint64(samples, pos, left, right);
71 replay_finish_event();
72 replay_mutex_unlock();
73 } else {
74 replay_mutex_unlock();
75 error_report("Missing audio in event in the replay log");
76 abort();