diff mbox

[2/3] wavcapture: port to FILE*

Message ID 64e1152daa17bc7ca43958e4e84fcfc2ae22b48d.1315918309.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Sept. 13, 2011, 12:52 p.m. UTC
QEMUFile * is only intended for Migration.  Using it for anything else
just adds pain and a layer of buffers for no good reason.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 audio/wavcapture.c |   38 +++++++++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 13 deletions(-)
diff mbox

Patch

diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index c64f0ef..ecdb9ec 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -3,7 +3,7 @@ 
 #include "audio.h"

 typedef struct {
-    QEMUFile *f;
+    FILE *f;
     int bytes;
     char *path;
     int freq;
@@ -40,12 +40,16 @@  static void wav_destroy (void *opaque)
         le_store (rlen, rifflen, 4);
         le_store (dlen, datalen, 4);

-        qemu_fseek (wav->f, 4, SEEK_SET);
-        qemu_put_buffer (wav->f, rlen, 4);
+        fseek (wav->f, 4, SEEK_SET);
+        if (fwrite (rlen, 1, 4, wav->f) != 4) {
+            printf("wav_destroy: short write\n");
+        }

-        qemu_fseek (wav->f, 32, SEEK_CUR);
-        qemu_put_buffer (wav->f, dlen, 4);
-        qemu_fclose (wav->f);
+        fseek (wav->f, 32, SEEK_CUR);
+        if (fwrite (dlen, 1, 4, wav->f) != 4) {
+            printf("wav_destroy: short write\n");
+        }
+        fclose (wav->f);
     }

     g_free (wav->path);
@@ -55,7 +59,9 @@  static void wav_capture (void *opaque, void *buf, int size)
 {
     WAVState *wav = opaque;

-    qemu_put_buffer (wav->f, buf, size);
+    if (fwrite (buf, size, 1, wav->f) != size) {
+        printf("wav_capture: short write\n");
+    }
     wav->bytes += size;
 }

@@ -130,7 +136,7 @@  int wav_start_capture (CaptureState *s, const char *path, int freq,
     le_store (hdr + 28, freq << shift, 4);
     le_store (hdr + 32, 1 << shift, 2);

-    wav->f = qemu_fopen (path, "wb");
+    wav->f = fopen (path, "wb");
     if (!wav->f) {
         monitor_printf(mon, "Failed to open wave file `%s'\nReason: %s\n",
                        path, strerror (errno));
@@ -143,19 +149,25 @@  int wav_start_capture (CaptureState *s, const char *path, int freq,
     wav->nchannels = nchannels;
     wav->freq = freq;

-    qemu_put_buffer (wav->f, hdr, sizeof (hdr));
+    if (fwrite (hdr, sizeof (hdr), 1, wav->f) != sizeof (hdr)) {
+        monitor_printf(mon, "wav_start_capture: short write\n");
+        goto error_free;
+    }

     cap = AUD_add_capture (&as, &ops, wav);
     if (!cap) {
         monitor_printf(mon, "Failed to add audio capture\n");
-        g_free (wav->path);
-        qemu_fclose (wav->f);
-        g_free (wav);
-        return -1;
+        goto error_free;
     }

     wav->cap = cap;
     s->opaque = wav;
     s->ops = wav_capture_ops;
     return 0;
+
+error_free:
+    g_free (wav->path);
+    fclose (wav->f);
+    g_free (wav);
+    return -1;
 }